diff options
author | Paul Fariello <paul@fariello.eu> | 2019-03-07 19:04:33 +0140 |
---|---|---|
committer | Paul Fariello <paul@fariello.eu> | 2019-04-10 16:31:45 +0200 |
commit | b3be504e841be55f917a3841d9cddf4ce076cc04 (patch) | |
tree | e71af15a8308cc2dc10007008867f2f89548b0f2 /src/omemo | |
parent | 55407ee15f0ebdf93c076ae5ea28ec865497b121 (diff) | |
download | profani-tty-b3be504e841be55f917a3841d9cddf4ce076cc04.tar.gz |
Add OMEMO fingerprint command
Diffstat (limited to 'src/omemo')
-rw-r--r-- | src/omemo/omemo.c | 51 | ||||
-rw-r--r-- | src/omemo/omemo.h | 3 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 3a771b6b..b293022f 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -679,6 +679,57 @@ omemo_on_message_recv(const char *const from, uint32_t sid, } +char * +omemo_format_fingerprint(const char *const fingerprint) +{ + char *output = malloc(strlen(fingerprint) + strlen(fingerprint) / 8 + 1); + + int i, j; + for (i = 0, j = 0; i < strlen(fingerprint); i++) { + if (i > 0 && i % 8 == 0) { + output[j++] = '-'; + } + output[j++] = fingerprint[i]; + } + + output[strlen(fingerprint) + strlen(fingerprint) / 8] = '\0'; + + return output; +} + +char * +omemo_own_fingerprint() +{ + signal_buffer *public = omemo_ctx.identity_key_store.public; + /* Skip first byte corresponding to signal base type */ + return omemo_fingerprint(signal_buffer_data(public) + 1, signal_buffer_len(public) - 1); +} + +char * +omemo_fingerprint(const unsigned char *const identity_key_public, size_t len) +{ + int i; + char *fingerprint = malloc(len * 2 + 1); + + for (i = 0; i < len; i++) { + fingerprint[i * 2] = (identity_key_public[i] & 0xf0) >> 4; + fingerprint[i * 2] += 0x30; + if (fingerprint[i * 2] > 0x39) { + fingerprint[i * 2] += 0x27; + } + + fingerprint[(i * 2) + 1] = identity_key_public[i] & 0x0f; + fingerprint[(i * 2) + 1] += 0x30; + if (fingerprint[(i * 2) + 1] > 0x39) { + fingerprint[(i * 2) + 1] += 0x27; + } + } + + fingerprint[len * 2] = '\0'; + + return fingerprint; +} + static void lock(void *user_data) { diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h index ef43617d..88c6d27c 100644 --- a/src/omemo/omemo.h +++ b/src/omemo/omemo.h @@ -28,6 +28,9 @@ void omemo_prekeys(GList **prekeys, GList **ids, GList **lengths); void omemo_set_device_list(const char *const jid, GList * device_list); GKeyFile *omemo_sessions_keyfile(void); void omemo_sessions_keyfile_save(void); +char *omemo_fingerprint(const unsigned char *const identity_key_public, size_t len); +char *omemo_format_fingerprint(const char *const fingerprint); +char *omemo_own_fingerprint(); void omemo_start_session(const char *const barejid); void omemo_start_device_session(const char *const jid, uint32_t device_id, GList *prekeys, uint32_t signed_prekey_id, const unsigned char *const signed_prekey, size_t signed_prekey_len, const unsigned char *const signature, size_t signature_len, const unsigned char *const identity_key, size_t identity_key_len); |