From cf83976b51dd103a17b75dd77f326f64166199bc Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 30 May 2022 18:04:36 +0200 Subject: Add basic qrcode functions --- src/command/cmd_ac.c | 1 + src/command/cmd_defs.c | 3 ++- src/command/cmd_funcs.c | 12 ++++++++++++ src/command/cmd_funcs.h | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/command') 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..ac226544 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, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 2a8331d1..29c8a29a 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9035,6 +9035,18 @@ 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 + cons_show_omemo_qrcode("some text from me"); + 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) { 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); -- cgit 1.4.1-2-gfad0 From 9a9a97868d0366408d7a310de3fa7158a294854e Mon Sep 17 00:00:00 2001 From: swirl Date: Fri, 27 May 2022 15:25:28 -0400 Subject: implement working OMEMO QR code TODO: We need to find a way to switch the colors of the QR code, so that more QR readers can detect it, without "blending" the edges of the QR code with the surrounding terminal window. Signed-off-by: swirl --- src/command/cmd_funcs.c | 14 +++++++++++++- src/ui/console.c | 13 ++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/command') diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 29c8a29a..81293c15 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9039,7 +9039,18 @@ gboolean cmd_omemo_qrcode(ProfWin* window, const char* const command, gchar** args) { #ifdef HAVE_OMEMO - cons_show_omemo_qrcode("some text from me"); + 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"); @@ -9767,3 +9778,4 @@ cmd_mood(ProfWin* window, const char* const command, gchar** args) } return TRUE; } + diff --git a/src/ui/console.c b/src/ui/console.c index ae1f796d..e0b0fa4d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -878,18 +878,16 @@ cons_show_omemo_qrcode(const char* const text) ProfWin* console = wins_get_console(); + char buf[(width * 4) + 1]; + memset(buf, 0, sizeof buf); for (size_t y = 0; y < width; y+=ZOOM_SIZE) { - //size_t y_index = y * width; for (size_t x = 0; x < width; x+=ZOOM_SIZE) { - if (x==0) { - win_print(console, THEME_DEFAULT, "", "%s", (*data & 1) ? "A" : "B"); - } else { - win_append(console, THEME_DEFAULT, "", "%s", (*data & 1) ? "A" : "B"); - } + strcat(buf, (*data & 1) ? "\u2588\u2588" : "\u2800\u2800"); data++; } - win_println(console, THEME_DEFAULT, "", ""); + win_println(console, THEME_DEFAULT, "", "%s", buf); + memset(buf, 0, sizeof buf); } QRcode_free(qrcode); @@ -2928,3 +2926,4 @@ cons_remove_alert(ProfWin* window) g_list_free_full(item, g_free); free(win_name); } + -- cgit 1.4.1-2-gfad0 From d64cb38240bd6db10135b6007f42dab6851ca559 Mon Sep 17 00:00:00 2001 From: swirl Date: Fri, 27 May 2022 15:45:38 -0400 Subject: Reverse QR code colors and add padding All QR scanners should be able to recognize this, as it is now the correct color with some padding to prevent blending. Signed-off-by: swirl --- src/command/cmd_funcs.c | 1 - src/ui/console.c | 26 +++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/command') diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 81293c15..1a4d4bf1 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9778,4 +9778,3 @@ cmd_mood(ProfWin* window, const char* const command, gchar** args) } return TRUE; } - diff --git a/src/ui/console.c b/src/ui/console.c index e0b0fa4d..89c3cf29 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -871,24 +871,37 @@ 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); + QRcode* qrcode = QRcode_encodeString(text, 0, QR_ECLEVEL_L, QR_MODE_8, 1); int width = (qrcode->width * ZOOM_SIZE); - unsigned char *data = qrcode->data; + unsigned char* data = qrcode->data; ProfWin* console = wins_get_console(); char buf[(width * 4) + 1]; memset(buf, 0, sizeof buf); - 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"); + + 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++; } - win_println(console, THEME_DEFAULT, "", "%s", buf); + + // 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); #endif @@ -2926,4 +2939,3 @@ cons_remove_alert(ProfWin* window) g_list_free_full(item, g_free); free(win_name); } - -- cgit 1.4.1-2-gfad0 From 42fb8f86d9b3d1fd3c51a942f4d2fe17c9dc0b79 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Sun, 29 May 2022 17:51:33 +0200 Subject: Add command help for omemo qrcode --- src/command/cmd_defs.c | 6 ++++-- src/ui/console.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/command') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index ac226544..411de396 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2328,7 +2328,8 @@ static struct cmd_t command_defs[] = { "/omemo 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( @@ -2345,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/ui/console.c b/src/ui/console.c index 89c3cf29..32575a15 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -904,6 +904,8 @@ cons_show_omemo_qrcode(const char* const text) win_println(console, THEME_DEFAULT, "", "%s", tmp); QRcode_free(qrcode); +#else + cons_show("This version of Profanity has not been built with libqrencode"); #endif } -- cgit 1.4.1-2-gfad0