1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add OMEMO fingerprint command

This commit is contained in:
Paul Fariello 2019-03-07 19:04:33 +01:40
parent 55407ee15f
commit b3be504e84
6 changed files with 90 additions and 3 deletions

View File

@ -579,6 +579,7 @@ cmd_ac_init(void)
omemo_ac = autocomplete_new();
autocomplete_add(omemo_ac, "gen");
autocomplete_add(omemo_ac, "start");
autocomplete_add(omemo_ac, "fingerprint");
connect_property_ac = autocomplete_new();
autocomplete_add(connect_property_ac, "server");

View File

@ -2334,19 +2334,22 @@ static struct cmd_t command_defs[] =
parse_args, 1, 2, NULL,
CMD_SUBFUNCS(
{ "gen", cmd_omemo_gen },
{ "start", cmd_omemo_start })
{ "start", cmd_omemo_start },
{ "fingerprint", cmd_omemo_fingerprint })
CMD_NOMAINFUNC
CMD_TAGS(
CMD_TAG_CHAT,
CMD_TAG_UI)
CMD_SYN(
"/omemo gen",
"/omemo start [<contact>]")
"/omemo start [<contact>]",
"/omemo fingerprint")
CMD_DESC(
"Omemo commands to manage keys, and perform encryption during chat sessions.")
CMD_ARGS(
{ "gen", "Generate OMEMO crytographic materials for current account." },
{ "start [<contact>]", "Start an OMEMO session with contact, or current recipient if omitted." })
{ "start [<contact>]", "Start an OMEMO session with contact, or current recipient if omitted." },
{ "fingerprint", "Show current device fingerprint." })
CMD_EXAMPLES(
"/omemo gen",
"/omemo start buddy@buddychat.org")

View File

@ -7988,3 +7988,31 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
return TRUE;
#endif
}
gboolean
cmd_omemo_fingerprint(ProfWin *window, const char *const command, gchar **args)
{
#ifdef HAVE_OMEMO
if (connection_get_status() != JABBER_CONNECTED) {
cons_show("You must be connected with an account to load OMEMO information.");
return TRUE;
}
if (!omemo_loaded()) {
win_println(window, THEME_DEFAULT, '!', "You have not generated or loaded a cryptographic materials, use '/omemo gen'");
return TRUE;
}
char *fingerprint = omemo_own_fingerprint();
char *formated_fingerprint = omemo_format_fingerprint(fingerprint);
cons_show("%s", formated_fingerprint);
free(fingerprint);
free(formated_fingerprint);
return TRUE;
#else
cons_show("This version of Profanity has not been built with OMEMO support enabled");
return TRUE;
#endif
}

View File

@ -216,5 +216,6 @@ gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args);
gboolean cmd_omemo_gen(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_omemo_start(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_omemo_fingerprint(ProfWin *window, const char *const command, gchar **args);
#endif

View File

@ -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)
{

View File

@ -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);