about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2019-03-25 18:30:46 +0140
committerPaul Fariello <paul@fariello.eu>2019-04-10 17:12:31 +0200
commit3d8f47a72416ff4b1ca64bf66071a62e4661d036 (patch)
tree30e1c31082a27c263b374b76ce508e6869852c6c /src/command
parent2fd2ca208cf9c191453f923722df3b9630ba9ff5 (diff)
downloadprofani-tty-3d8f47a72416ff4b1ca64bf66071a62e4661d036.tar.gz
Use /omemo fingerprint to show contact fingerprints
Don't print fingerprints when they are received
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_ac.c5
-rw-r--r--src/command/cmd_defs.c4
-rw-r--r--src/command/cmd_funcs.c46
3 files changed, 50 insertions, 5 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 86ef6ba9..9584543e 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -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;
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 311b404e..5a3e6873 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -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",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index d254960d..fcbb10b8 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -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