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

Use /omemo fingerprint to show contact fingerprints

Don't print fingerprints when they are received
This commit is contained in:
Paul Fariello 2019-03-25 18:30:46 +01:40
parent 2fd2ca208c
commit 3d8f47a724
5 changed files with 96 additions and 32 deletions

View File

@ -2153,6 +2153,11 @@ _omemo_autocomplete(ProfWin *window, const char *const input, gboolean previous)
}
}
found = autocomplete_param_with_func(input, "/omemo fingerprint", roster_contact_autocomplete, previous);
if (found) {
return found;
}
found = autocomplete_param_with_ac(input, "/omemo log", omemo_log_ac, TRUE, previous);
if (found) {
return found;

View File

@ -2350,7 +2350,7 @@ static struct cmd_t command_defs[] =
"/omemo start [<contact>]",
"/omemo trust [<contact>] <fingerprint>",
"/omemo end",
"/omemo fingerprint")
"/omemo fingerprint [<contact>]")
CMD_DESC(
"Omemo commands to manage keys, and perform encryption during chat sessions.")
CMD_ARGS(
@ -2359,7 +2359,7 @@ static struct cmd_t command_defs[] =
{ "end", "End the current OMEMO session," },
{ "log on|off", "Enable or disable plaintext logging of OMEMO encrypted messages." },
{ "log redact", "Log OMEMO encrypted messages, but replace the contents with [redacted]. This is the default." },
{ "fingerprint", "Show current device fingerprint." })
{ "fingerprint", "Show contact fingerprints." })
CMD_EXAMPLES(
"/omemo gen",
"/omemo start buddy@buddychat.org",

View File

@ -8080,9 +8080,49 @@ cmd_omemo_fingerprint(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
char *fingerprint = omemo_own_fingerprint(TRUE);
cons_show("%s", fingerprint);
free(fingerprint);
Jid *jid;
if (!args[1]) {
if (window->type == WIN_CONSOLE) {
char *fingerprint = omemo_own_fingerprint(TRUE);
cons_show("Your OMEMO fingerprint: %s", fingerprint);
free(fingerprint);
return TRUE;
} else if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)window;
jid = jid_create(chatwin->barejid);
} else {
win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to print fingerprint without providing the contact.");
return TRUE;
}
} else {
jid = jid_create(args[1]);
if (!jid) {
cons_show("%s is not a valid jid", args[1]);
return TRUE;
}
}
GList *fingerprints = omemo_known_device_identities(jid->barejid);
GList *fingerprint;
if (!fingerprints) {
win_println(window, THEME_DEFAULT, '-', "There is no known fingerprints for %s", jid->barejid);
return TRUE;
}
for (fingerprint = fingerprints; fingerprint != NULL; fingerprint = fingerprint->next) {
char *formatted_fingerprint = omemo_format_fingerprint(fingerprint->data);
gboolean trusted = omemo_is_trusted_identity(jid->barejid, fingerprint->data);
win_println(window, THEME_DEFAULT, '-', "%s's OMEMO fingerprint: %s%s", jid->barejid, formatted_fingerprint, trusted ? " (trusted)" : "");
free(formatted_fingerprint);
}
g_list_free(fingerprints);
win_println(window, THEME_DEFAULT, '-', "You can trust it with '/omemo trust <fingerprint>'");
win_println(window, THEME_DEFAULT, '-', "You can untrust it with '/omemo untrust <fingerprint>'");
return TRUE;
#else

View File

@ -496,32 +496,6 @@ omemo_start_device_session(const char *const jid, uint32_t device_id,
gboolean trusted = is_trusted_identity(&address, (uint8_t *)identity_key_raw, identity_key_len, &omemo_ctx.identity_key_store);
Jid *ownjid = jid_create(connection_get_fulljid());
if (g_strcmp0(jid, ownjid->barejid) == 0) {
char *fingerprint = omemo_fingerprint(identity_key, TRUE);
cons_show("Available device identity for %s: %s%s", ownjid->barejid, fingerprint, trusted ? " (trusted)" : "");
if (trusted) {
cons_show("You can untrust it with '/omemo untrust %s <fingerprint>'", ownjid->barejid);
} else {
cons_show("You can trust it with '/omemo trust %s <fingerprint>'", ownjid->barejid);
}
free(fingerprint);
}
ProfChatWin *chatwin = wins_get_chat(jid);
if (chatwin) {
char *fingerprint = omemo_fingerprint(identity_key, TRUE);
win_println((ProfWin *)chatwin, THEME_DEFAULT, '-', "Available device identity: %s%s", fingerprint, trusted ? " (trusted)" : "");
if (trusted) {
win_println((ProfWin *)chatwin, THEME_DEFAULT, '-', "You can untrust it with '/omemo untrust <fingerprint>'");
} else {
win_println((ProfWin *)chatwin, THEME_DEFAULT, '-', "You can trust it with '/omemo trust <fingerprint>'");
}
free(fingerprint);
}
if (!trusted) {
goto out;
}
@ -570,7 +544,6 @@ omemo_start_device_session(const char *const jid, uint32_t device_id,
out:
SIGNAL_UNREF(identity_key);
jid_destroy(ownjid);
}
char *
@ -884,6 +857,50 @@ omemo_own_fingerprint(gboolean formatted)
return omemo_fingerprint(identity, formatted);
}
GList *
omemo_known_device_identities(const char *const jid)
{
GHashTable *known_identities = g_hash_table_lookup(omemo_ctx.known_devices, jid);
if (!known_identities) {
return NULL;
}
return g_hash_table_get_keys(known_identities);
}
gboolean
omemo_is_trusted_identity(const char *const jid, const char *const fingerprint)
{
GHashTable *known_identities = g_hash_table_lookup(omemo_ctx.known_devices, jid);
if (!known_identities) {
return FALSE;
}
void *device_id = g_hash_table_lookup(known_identities, fingerprint);
if (!device_id) {
return FALSE;
}
signal_protocol_address address = {
.name = jid,
.name_len = strlen(jid),
.device_id = GPOINTER_TO_INT(device_id),
};
size_t fingerprint_len;
unsigned char *fingerprint_raw = omemo_fingerprint_decode(fingerprint, &fingerprint_len);
unsigned char djb_type[] = {'\x05'};
signal_buffer *buffer = signal_buffer_create(djb_type, 1);
buffer = signal_buffer_append(buffer, fingerprint_raw, fingerprint_len);
gboolean trusted = is_trusted_identity(&address, signal_buffer_data(buffer), signal_buffer_len(buffer), &omemo_ctx.identity_key_store);
free(fingerprint_raw);
signal_buffer_free(buffer);
return trusted;
}
static char *
omemo_fingerprint(ec_public_key *identity, gboolean formatted)
{

View File

@ -36,6 +36,8 @@ char *omemo_format_fingerprint(const char *const fingerprint);
char *omemo_own_fingerprint(gboolean formatted);
void omemo_trust(const char *const jid, const char *const fingerprint);
void omemo_untrust(const char *const jid, const char *const fingerprint);
GList *omemo_known_device_identities(const char *const jid);
gboolean omemo_is_trusted_identity(const char *const jid, const char *const fingerprint);
void omemo_start_session(const char *const barejid);
void omemo_start_muc_sessions(const char *const roomjid);