about summary refs log tree commit diff stats
path: root/src/omemo
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2019-04-08 20:29:25 +0320
committerPaul Fariello <paul@fariello.eu>2019-04-10 17:23:46 +0200
commit4ad6904216fa5917f202a0f1bfe3d4712559aeae (patch)
treedda2dadc3bc5f12f5b6df0b8b27da77d87606ac2 /src/omemo
parentedbc15fa2b36d9e131707d7d58b79caec917e7f5 (diff)
downloadprofani-tty-4ad6904216fa5917f202a0f1bfe3d4712559aeae.tar.gz
Wait for discovery end to publish omemo devicelist and bundle
Add sv_ev_connection_features_received for that purpose
Diffstat (limited to 'src/omemo')
-rw-r--r--src/omemo/omemo.c21
-rw-r--r--src/omemo/omemo.h1
2 files changed, 15 insertions, 7 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c
index d580ed51..a20dc109 100644
--- a/src/omemo/omemo.c
+++ b/src/omemo/omemo.c
@@ -27,7 +27,6 @@
 
 static gboolean loaded;
 
-static void _omemo_publish_crypto_materials(ProfAccount *account);
 static void _generate_pre_keys(int count);
 static void _generate_signed_pre_key(void);
 static void _load_identity(void);
@@ -212,7 +211,6 @@ omemo_on_connect(ProfAccount *account)
 
     if (g_key_file_load_from_file(omemo_ctx.identity_keyfile, omemo_ctx.identity_filename->str, G_KEY_FILE_KEEP_COMMENTS, &error)) {
         _load_identity();
-        _omemo_publish_crypto_materials(account);
     } else if (error->code != G_FILE_ERROR_NOENT) {
         log_warning("OMEMO: error loading identity from: %s, %s", omemo_ctx.identity_filename->str, error->message);
         return;
@@ -291,18 +289,27 @@ omemo_generate_crypto_materials(ProfAccount *account)
 
     loaded = TRUE;
 
-    _omemo_publish_crypto_materials(account);
+    omemo_publish_crypto_materials();
 }
 
-static void
-_omemo_publish_crypto_materials(ProfAccount *account)
+void
+omemo_publish_crypto_materials(void)
 {
+    if (loaded != TRUE) {
+        log_error("OMEMO: cannot publish crypto materials before they are generated");
+        return;
+    }
+
+    Jid *jid = jid_create(connection_get_fulljid());
+
     /* Ensure we get our current device list, and it gets updated with our
      * device_id */
-    g_hash_table_insert(omemo_ctx.device_list_handler, strdup(account->jid), _handle_own_device_list);
-    omemo_devicelist_request(account->jid);
+    g_hash_table_insert(omemo_ctx.device_list_handler, strdup(jid->barejid), _handle_own_device_list);
+    omemo_devicelist_request(jid->barejid);
 
     omemo_bundle_publish(true);
+
+    jid_destroy(jid);
 }
 
 void
diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h
index bbd59b77..72e27429 100644
--- a/src/omemo/omemo.h
+++ b/src/omemo/omemo.h
@@ -21,6 +21,7 @@ void omemo_on_connect(ProfAccount *account);
 void omemo_on_disconnect(void);
 void omemo_generate_crypto_materials(ProfAccount *account);
 void omemo_key_free(omemo_key_t *key);
+void omemo_publish_crypto_materials(void);
 
 uint32_t omemo_device_id(void);
 void omemo_identity_key(unsigned char **output, size_t *length);