1
0
Fork 0

Merge pull request #1568 from profanity-im/feature/1320-omemo-qrcode

Show OMEMO QR Code
This commit is contained in:
Michael Vetter 2022-05-31 09:11:53 +02:00 committed by GitHub
commit 754c110a34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 115 additions and 10 deletions

View File

@ -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}

View File

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

View File

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

View File

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

View File

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

View File

@ -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"

View File

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

View File

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

View File

@ -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",

View File

@ -9035,6 +9035,29 @@ cmd_omemo_policy(ProfWin* window, const char* const command, gchar** args)
#endif
}
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)
{

View File

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

View File

@ -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"
@ -862,6 +866,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)
{

View File

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

View File

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