about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_ac.c1
-rw-r--r--src/command/cmd_defs.c9
-rw-r--r--src/command/cmd_funcs.c23
-rw-r--r--src/command/cmd_funcs.h1
-rw-r--r--src/ui/console.c47
-rw-r--r--src/ui/ui.h4
6 files changed, 82 insertions, 3 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 9fc70a1d..531d189b 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -700,6 +700,7 @@ cmd_ac_init(void)
     autocomplete_add(omemo_ac, "policy");
     autocomplete_add(omemo_ac, "trustmode");
     autocomplete_add(omemo_ac, "char");
+    autocomplete_add(omemo_ac, "qrcode");
 
     omemo_log_ac = autocomplete_new();
     autocomplete_add(omemo_log_ac, "on");
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 57d90226..411de396 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2312,7 +2312,8 @@ static struct cmd_t command_defs[] = {
             { "fingerprint", cmd_omemo_fingerprint },
             { "char", cmd_omemo_char },
             { "policy", cmd_omemo_policy },
-            { "clear_device_list", cmd_omemo_clear_device_list })
+            { "clear_device_list", cmd_omemo_clear_device_list },
+            { "qrcode", cmd_omemo_qrcode })
         CMD_NOMAINFUNC
         CMD_TAGS(
             CMD_TAG_CHAT,
@@ -2327,7 +2328,8 @@ static struct cmd_t command_defs[] = {
             "/omemo char <char>",
             "/omemo trustmode manual|firstusage|blind",
             "/omemo policy manual|automatic|always",
-            "/omemo clear_device_list")
+            "/omemo clear_device_list",
+            "/omemo qrcode")
         CMD_DESC(
             "OMEMO commands to manage keys, and perform encryption during chat sessions.")
         CMD_ARGS(
@@ -2344,7 +2346,8 @@ static struct cmd_t command_defs[] = {
             { "policy manual",           "Set the global OMEMO policy to manual, OMEMO sessions must be started manually." },
             { "policy automatic",        "Set the global OMEMO policy to opportunistic, an OMEMO session will be attempted upon starting a conversation." },
             { "policy always",           "Set the global OMEMO policy to always, an error will be displayed if an OMEMO session cannot be initiated upon starting a conversation." },
-            { "clear_device_list",       "Clear your own device list on server side. Each client will reannounce itself when connected back."})
+            { "clear_device_list",       "Clear your own device list on server side. Each client will reannounce itself when connected back."},
+            { "qrcode",                  "Display QR code of your OMEMO fingerprint"})
         CMD_EXAMPLES(
             "/omemo gen",
             "/omemo start odin@valhalla.edda",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 2a8331d1..1a4d4bf1 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9036,6 +9036,29 @@ cmd_omemo_policy(ProfWin* window, const char* const command, gchar** args)
 }
 
 gboolean
+cmd_omemo_qrcode(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(TRUE);
+    cons_show_omemo_qrcode(fingerprint);
+    return TRUE;
+#else
+    cons_show("This version of Profanity has not been built with OMEMO support enabled");
+    return TRUE;
+#endif
+}
+
+gboolean
 cmd_save(ProfWin* window, const char* const command, gchar** args)
 {
     log_info("Saving preferences to configuration file");
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index 621dd1c6..adc6793d 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -227,6 +227,7 @@ gboolean cmd_omemo_untrust(ProfWin* window, const char* const command, gchar** a
 gboolean cmd_omemo_trust_mode(ProfWin* window, const char* const command, gchar** args);
 gboolean cmd_omemo_policy(ProfWin* window, const char* const command, gchar** args);
 gboolean cmd_omemo_clear_device_list(ProfWin* window, const char* const command, gchar** args);
+gboolean cmd_omemo_qrcode(ProfWin* window, const char* const command, gchar** args);
 
 gboolean cmd_save(ProfWin* window, const char* const command, gchar** args);
 gboolean cmd_reload(ProfWin* window, const char* const command, gchar** args);
diff --git a/src/ui/console.c b/src/ui/console.c
index 3e7a0844..32575a15 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -48,6 +48,10 @@
 #include <curses.h>
 #endif
 
+#ifdef HAVE_QRENCODE
+#include <qrencode.h>
+#endif
+
 #include "common.h"
 #include "log.h"
 #include "config/preferences.h"
@@ -863,6 +867,49 @@ cons_show_disco_contact_information(GHashTable* addresses)
 }
 
 void
+cons_show_omemo_qrcode(const char* const text)
+{
+#ifdef HAVE_QRENCODE
+    static const size_t ZOOM_SIZE = 10;
+    QRcode* qrcode = QRcode_encodeString(text, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
+
+    int width = (qrcode->width * ZOOM_SIZE);
+    unsigned char* data = qrcode->data;
+
+    ProfWin* console = wins_get_console();
+
+    char buf[(width * 4) + 1];
+    memset(buf, 0, sizeof buf);
+
+    char tmp[(width * 4) + 5];
+    memset(tmp, 0, sizeof tmp);
+
+    for (int i = 0; i < width + 2 * ZOOM_SIZE; i += ZOOM_SIZE) {
+        strcat(tmp, "\u2588\u2588");
+    }
+
+    win_println(console, THEME_DEFAULT, "", tmp);
+    for (size_t y = 0; y < width; y += ZOOM_SIZE) {
+        for (size_t x = 0; x < width; x += ZOOM_SIZE) {
+            strcat(buf, !(*data & 1) ? "\u2588\u2588" : "\u2800\u2800");
+
+            data++;
+        }
+
+        // The extra squares are for padding, so that the QR code doesn't
+        // "blend in" with the rest of the terminal window.
+        win_println(console, THEME_DEFAULT, "", "\u2588\u2588%s\u2588\u2588", buf);
+        memset(buf, 0, sizeof buf);
+    }
+    win_println(console, THEME_DEFAULT, "", "%s", tmp);
+
+    QRcode_free(qrcode);
+#else
+    cons_show("This version of Profanity has not been built with libqrencode");
+#endif
+}
+
+void
 cons_show_status(const char* const barejid)
 {
     ProfWin* console = wins_get_console();
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 5f31354f..8615045a 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -277,7 +277,11 @@ void cons_show_bookmarks(const GList* list);
 void cons_show_bookmarks_ignore(gchar** list, gsize len);
 void cons_show_disco_items(GSList* items, const char* const jid);
 void cons_show_disco_info(const char* from, GSList* identities, GSList* features);
+
 void cons_show_disco_contact_information(GHashTable* addresses);
+
+void cons_show_omemo_qrcode(const char* const text);
+
 void cons_show_room_invite(const char* const invitor, const char* const room, const char* const reason);
 void cons_check_version(gboolean not_available_msg);
 void cons_show_typing(const char* const barejid);