about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2022-05-31 15:44:44 +0200
committerMichael Vetter <jubalh@iodoru.org>2022-05-31 15:44:44 +0200
commit2e85f18cd61b358c8c654a90ef64cf80af5a33c6 (patch)
tree00a599cf7b6b5d5b159de8ba626c79f2564a0447
parent754c110a34bf608bee3990e5b626203699b879d2 (diff)
downloadprofani-tty-2e85f18cd61b358c8c654a90ef64cf80af5a33c6.tar.gz
Use our omemo sid/fingerprint in qr code
Current clients sid/fingerprint will be shown in following format:
`xmpp:<user@server>?omemo-sid-<numerical-sid>=<omemo-fingerprint-hex-string>`

Fix https://github.com/profanity-im/profanity/issues/1320
-rw-r--r--src/command/cmd_funcs.c6
-rw-r--r--src/omemo/omemo.c18
-rw-r--r--src/omemo/omemo.h2
-rw-r--r--src/ui/console.c2
-rw-r--r--src/ui/ui.h2
-rw-r--r--tests/unittests/omemo/stub_omemo.c6
-rw-r--r--tests/unittests/ui/stub_ui.c2
7 files changed, 33 insertions, 5 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 1a4d4bf1..57381831 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9049,8 +9049,10 @@ cmd_omemo_qrcode(ProfWin* window, const char* const command, gchar** args)
         return TRUE;
     }
 
-    char* fingerprint = omemo_own_fingerprint(TRUE);
-    cons_show_omemo_qrcode(fingerprint);
+    char* qrstr = omemo_qrcode_str();
+    cons_show_qrcode(qrstr);
+    free(qrstr);
+
     return TRUE;
 #else
     cons_show("This version of Profanity has not been built with OMEMO support enabled");
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c
index e6d9da42..9f67d24c 100644
--- a/src/omemo/omemo.c
+++ b/src/omemo/omemo.c
@@ -1896,3 +1896,21 @@ out:
     curl_url_cleanup(url);
     return ret;
 }
+
+/* returns a string in the format `xmpp:<user@server>?omemo-sid-<numerical-sid>=<omemo-fingerprint-hex-string>`
+ * used for verification over QR codes
+ */
+char*
+omemo_qrcode_str()
+{
+    char* mybarejid = connection_get_barejid();
+    char* fingerprint = omemo_own_fingerprint(TRUE);
+    uint32_t sid = omemo_device_id();
+
+    char* qrstr = g_strdup_printf("xmpp:%s?omemo-sid-%d=%s", mybarejid, sid, fingerprint);
+
+    free(mybarejid);
+    free(fingerprint);
+
+    return qrstr;
+}
diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h
index 7e7c1f14..624bec51 100644
--- a/src/omemo/omemo.h
+++ b/src/omemo/omemo.h
@@ -105,3 +105,5 @@ char* omemo_encrypt_file(FILE* in, FILE* out, off_t file_size, int* gcry_res);
 gcry_error_t omemo_decrypt_file(FILE* in, FILE* out, off_t file_size, const char* fragment);
 void omemo_free(void* a);
 int omemo_parse_aesgcm_url(const char* aesgcm_url, char** https_url, char** fragment);
+
+char* omemo_qrcode_str();
diff --git a/src/ui/console.c b/src/ui/console.c
index 32575a15..37b2d377 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -867,7 +867,7 @@ cons_show_disco_contact_information(GHashTable* addresses)
 }
 
 void
-cons_show_omemo_qrcode(const char* const text)
+cons_show_qrcode(const char* const text)
 {
 #ifdef HAVE_QRENCODE
     static const size_t ZOOM_SIZE = 10;
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 8615045a..a7886ab3 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -280,7 +280,7 @@ 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_qrcode();
 
 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);
diff --git a/tests/unittests/omemo/stub_omemo.c b/tests/unittests/omemo/stub_omemo.c
index f7c60190..0336e1a3 100644
--- a/tests/unittests/omemo/stub_omemo.c
+++ b/tests/unittests/omemo/stub_omemo.c
@@ -120,3 +120,9 @@ omemo_device_id()
 {
     return 123;
 }
+
+char*
+omemo_qrcode_str()
+{
+    return NULL;
+}
diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c
index a1bb7d61..37323ba7 100644
--- a/tests/unittests/ui/stub_ui.c
+++ b/tests/unittests/ui/stub_ui.c
@@ -930,7 +930,7 @@ cons_show_disco_info(const char* from, GSList* identities, GSList* features)
 }
 
 void
-cons_show_omemo_qrcode(const char* const text)
+cons_show_qrcode(const char* const text)
 {
 }