about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Dockerfile.arch3
-rw-r--r--Dockerfile.debian3
-rw-r--r--Dockerfile.fedora3
-rw-r--r--Dockerfile.tumbleweed3
-rw-r--r--Dockerfile.ubuntu3
-rwxr-xr-xci-build.sh4
-rw-r--r--configure.ac10
-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
-rw-r--r--tests/unittests/ui/stub_ui.c11
14 files changed, 115 insertions, 10 deletions
diff --git a/Dockerfile.arch b/Dockerfile.arch
index 7a7b2553..d4c4e0a1 100644
--- a/Dockerfile.arch
+++ b/Dockerfile.arch
@@ -27,7 +27,8 @@ RUN pacman -Syu --noconfirm && pacman -S --needed --noconfirm \
   python \
   wget \
   sqlite \
-  gdk-pixbuf2
+  gdk-pixbuf2 \
+  qrencode
 
 RUN mkdir -p /usr/src/{stabber,profanity}
 
diff --git a/Dockerfile.debian b/Dockerfile.debian
index ae002148..6da1f414 100644
--- a/Dockerfile.debian
+++ b/Dockerfile.debian
@@ -28,7 +28,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
   python3-dev \
   python-dev-is-python3 \
   libsqlite3-dev \
-  libgdk-pixbuf-2.0-dev
+  libgdk-pixbuf-2.0-dev \
+  libqrencode-dev
 
 RUN mkdir -p /usr/src/{stabber,libstrophe,profanity}
 WORKDIR /usr/src
diff --git a/Dockerfile.fedora b/Dockerfile.fedora
index 8238fd48..b885bebb 100644
--- a/Dockerfile.fedora
+++ b/Dockerfile.fedora
@@ -35,7 +35,8 @@ RUN dnf install -y \
   readline-devel \
   openssl-devel \
   sqlite-devel \
-  gdk-pixbuf2-devel
+  gdk-pixbuf2-devel \
+  qrencode-devel
 
 # https://github.com/openSUSE/docker-containers-build/issues/26
 ENV LANG en_US.UTF-8
diff --git a/Dockerfile.tumbleweed b/Dockerfile.tumbleweed
index 8c75e8a4..5fc134dc 100644
--- a/Dockerfile.tumbleweed
+++ b/Dockerfile.tumbleweed
@@ -35,7 +35,8 @@ RUN zypper --non-interactive in --no-recommends \
   python38-devel \
   readline-devel \
   sqlite3-devel \
-  gdk-pixbuf-devel
+  gdk-pixbuf-devel \
+  qrencode-devel
 
 # https://github.com/openSUSE/docker-containers-build/issues/26
 ENV LANG en_US.UTF-8
diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu
index 6ca0d721..853544c0 100644
--- a/Dockerfile.ubuntu
+++ b/Dockerfile.ubuntu
@@ -29,7 +29,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
   python3-dev \
   python-dev-is-python3 \
   libsqlite3-dev \
-  libgdk-pixbuf-2.0-dev
+  libgdk-pixbuf-2.0-dev \
+  libqrencode-dev
 
 RUN mkdir -p /usr/src/{stabber,libstrophe,profanity}
 WORKDIR /usr/src
diff --git a/ci-build.sh b/ci-build.sh
index a26693f2..0e84cae9 100755
--- a/ci-build.sh
+++ b/ci-build.sh
@@ -44,7 +44,7 @@ case $(uname | tr '[:upper:]' '[:lower:]') in
         tests=(
         "--enable-notifications --enable-icons-and-clipboard --enable-otr --enable-pgp
         --enable-omemo --enable-plugins --enable-c-plugins
-        --enable-python-plugins --with-xscreensaver --enable-gdk-pixbuf"
+        --enable-python-plugins --with-xscreensaver --enable-omemo-qrcode --enable-gdk-pixbuf"
         "--disable-notifications --disable-icons-and-clipboard --disable-otr --disable-pgp
         --disable-omemo --disable-plugins --disable-c-plugins
         --disable-python-plugins --without-xscreensaver"
@@ -52,7 +52,7 @@ case $(uname | tr '[:upper:]' '[:lower:]') in
         "--disable-icons-and-clipboard"
         "--disable-otr"
         "--disable-pgp"
-        "--disable-omemo"
+        "--disable-omemo --disable-omemo-qrcode"
         "--disable-pgp --disable-otr"
         "--disable-pgp --disable-otr --disable-omemo"
         "--disable-plugins"
diff --git a/configure.ac b/configure.ac
index 2cf3e026..96495386 100644
--- a/configure.ac
+++ b/configure.ac
@@ -67,6 +67,8 @@ AC_ARG_ENABLE([icons-and-clipboard],
     [AS_HELP_STRING([--enable-icons-and-clipboard], [enable GTK tray icons and clipboard paste support])])
 AC_ARG_ENABLE([gdk-pixbuf],
     [AS_HELP_STRING([--enable-gdk-pixbuf], [enable GDK Pixbuf support to scale avatars before uploading])])
+AC_ARG_ENABLE([omemo-qrcode],
+    [AS_HELP_STRING([--enable-omemo-qrcode], [enable ability to display omemo qr code])])
 
 # Required dependencies
 
@@ -345,6 +347,14 @@ AS_IF([test "x$with_themes" = xno -o "x$with_themes" = xyes -o "x$with_themes" =
 AC_SUBST(THEMES_PATH)
 AM_CONDITIONAL([THEMES_INSTALL], "$THEMES_INSTALL")
 
+if test "x$enable_omemo_qrcode" != xno; then
+    PKG_CHECK_MODULES([libqrencode], [libqrencode],
+        [AC_DEFINE([HAVE_QRENCODE], [1], [Have QRencode]) LIBS="$libqrencode_LIBS $LIBS" CFLAGS="$libqrencode_CFLAGS $CFLAGS"],
+        [AS_IF([test "x$enable_qrcode" = xyes],
+               [AC_MSG_ERROR([libqrencode not found])],
+               [AC_MSG_NOTICE([librencode not found])])])
+fi
+
 ## Tests
 
 # cmocka is required only for tests, profanity shouldn't be linked with it
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);
diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c
index 768e654b..a1bb7d61 100644
--- a/tests/unittests/ui/stub_ui.c
+++ b/tests/unittests/ui/stub_ui.c
@@ -923,27 +923,38 @@ 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_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)
 {
 }
+
 void
 cons_show_incoming_room_message(const char* const nick, const char* const room, const int win_index, gboolean mention, GList* triggers, int unread, ProfWin* const window)
 {
 }
+
 void
 cons_show_incoming_message(const char* const short_from, const int win_index, int unread, ProfWin* const window)
 {