From 2b1ada772256a9a661eabedf723702af5f6bfa83 Mon Sep 17 00:00:00 2001 From: Maximilian Wuttke Date: Tue, 9 Mar 2021 17:48:29 +0100 Subject: [OMEMO]: Fix bundle publishing Use the following options in `omemo_bundle_publish()`: - "pubsub#persist_items" = "true" - "pubsub#access_model" = "open" The same options are also used in Gajim. I've tested this on two different servers. The bundle was successfully added as a new PEP node. Test cases: 1. Normal use on my main account 2. Log in into a fresh tesst account on a different server 3. `/omemo clear_device_list`. In this case, the client(s) may have to be restarted. Note: In `_omemo_bundle_publish_result`, there's a route that is taken when the bundle publish stanza failed. In this case, the node is configured manually, i.e. the access_model is set to 'open'. I have manually tested this case, but this case didn't naturally occur for me. Note: The option "pubsub#max_items=max" is REQUIRED for the bundle publication, as per XEP-0384. However, this is not done in other clients (I've checked the source code of Gajim and Conversations), and it is also not supported by Prosody. Cf. . --- src/xmpp/omemo.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index b51335b5..917e6f19 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -63,11 +63,10 @@ omemo_devicelist_publish(GList* device_list) xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_stanza_t* iq = stanza_create_omemo_devicelist_publish(ctx, device_list); - log_debug("[OMEMO] omemo_devicelist_publish()"); + log_info("[OMEMO] publish device list"); if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) { stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open"); - // stanza_attach_publish_options(ctx, iq, "pubsub#max_items", "max"); } iq_send_stanza(iq); @@ -80,6 +79,8 @@ omemo_devicelist_request(const char* const jid) xmpp_ctx_t* const ctx = connection_get_ctx(); char* id = connection_create_stanza_id(); + log_info("[OMEMO] request device list for jid: %s", jid); + xmpp_stanza_t* iq = stanza_create_omemo_devicelist_request(ctx, id, jid); iq_id_handler_add(id, _omemo_receive_devicelist, NULL, NULL); @@ -92,7 +93,7 @@ omemo_devicelist_request(const char* const jid) void omemo_bundle_publish(gboolean first) { - log_info("[OMEMO] publish omemo bundle"); + log_info("[OMEMO] publish own OMEMO bundle"); xmpp_ctx_t* const ctx = connection_get_ctx(); unsigned char* identity_key = NULL; size_t identity_key_length; @@ -102,8 +103,6 @@ omemo_bundle_publish(gboolean first) size_t signed_prekey_signature_length; GList *prekeys = NULL, *ids = NULL, *lengths = NULL; - log_debug("OMEMO: omemo_bundle_publish()"); - omemo_identity_key(&identity_key, &identity_key_length); omemo_signed_prekey(&signed_prekey, &signed_prekey_length); omemo_signed_prekey_signature(&signed_prekey_signature, &signed_prekey_signature_length); @@ -120,7 +119,10 @@ omemo_bundle_publish(gboolean first) g_list_free(ids); if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) { - stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open"); + stanza_attach_publish_options_va(ctx, iq, + 4, // 2 * number of key-value pairs + "pubsub#persist_items", "true", + "pubsub#access_model", "open"); } iq_id_handler_add(id, _omemo_bundle_publish_result, NULL, GINT_TO_POINTER(first)); @@ -140,6 +142,8 @@ omemo_bundle_request(const char* const jid, uint32_t device_id, ProfIqCallback f xmpp_ctx_t* const ctx = connection_get_ctx(); char* id = connection_create_stanza_id(); + log_info("[OMEMO] request omemo bundle (jid: %s, deivce: %d)", jid, device_id); + xmpp_stanza_t* iq = stanza_create_omemo_bundle_request(ctx, id, jid, device_id); iq_id_handler_add(id, func, free_func, userdata); @@ -495,6 +499,7 @@ _omemo_receive_devicelist(xmpp_stanza_t* const stanza, void* const userdata) return 1; } + static int _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata) { @@ -502,8 +507,8 @@ _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata) const char* type = xmpp_stanza_get_type(stanza); - if (g_strcmp0(type, STANZA_TYPE_ERROR) != 0) { - log_error("[OMEMO] Error for bundle publish"); + if (g_strcmp0(type, STANZA_TYPE_RESULT) == 0) { + log_info("[OMEMO] bundle published successfully"); return 0; } @@ -524,9 +529,7 @@ _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata) iq_id_handler_add(id, _omemo_bundle_publish_configure, NULL, userdata); - log_debug("[OMEMO] _omemo_bundle_publish_result(): sending pubsub conf request"); iq_send_stanza(iq); - log_debug("[OMEMO] _omemo_bundle_publish_result(): sent pubsub conf request"); xmpp_stanza_release(iq); free(id); @@ -539,7 +542,6 @@ _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdat { log_debug("[OMEMO] _omemo_bundle_publish_configure()"); - /* TODO handle error */ xmpp_stanza_t* pubsub = xmpp_stanza_get_child_by_name(stanza, "pubsub"); if (!pubsub) { log_error("[OMEMO] The stanza doesn't contain a 'pubsub' child"); @@ -562,7 +564,6 @@ _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdat log_error("[OMEMO] cannot configure bundle to an open access model"); return 0; } - form_set_value(form, tag, "open"); xmpp_ctx_t* const ctx = connection_get_ctx(); Jid* jid = jid_create(connection_get_fulljid()); @@ -575,8 +576,6 @@ _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdat iq_send_stanza(iq); - log_debug("[OMEMO] _omemo_bundle_publish_configure() done"); - xmpp_stanza_release(iq); free(id); jid_destroy(jid); @@ -593,6 +592,9 @@ _omemo_bundle_publish_configure_result(xmpp_stanza_t* const stanza, void* const return 0; } + log_info("[OMEMO] node configured"); + + // Try to publish again omemo_bundle_publish(TRUE); return 0; -- cgit 1.4.1-2-gfad0