diff options
author | Paul Fariello <paul@fariello.eu> | 2021-07-06 17:47:33 +0200 |
---|---|---|
committer | Paul Fariello <paul@fariello.eu> | 2021-08-19 10:02:06 +0200 |
commit | 46fe69de9b4049c5c4bf6fddb3dfba4480b13caa (patch) | |
tree | c737d06c8295b6399eb8d28e6ed902e5e059afd1 | |
parent | 4641537721df7e89090206802f623213a9abcb1a (diff) | |
download | profani-tty-46fe69de9b4049c5c4bf6fddb3dfba4480b13caa.tar.gz |
Ensure devicelist access model is configured before updating it
-rw-r--r-- | src/omemo/omemo.c | 4 | ||||
-rw-r--r-- | src/xmpp/omemo.c | 115 | ||||
-rw-r--r-- | src/xmpp/omemo.h | 1 |
3 files changed, 96 insertions, 24 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 952fea89..05f543f6 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -386,10 +386,12 @@ omemo_publish_crypto_materials(void) char* barejid = connection_get_barejid(); + /* Ensure device list is properly configured */ + omemo_devicelist_configure_and_request(); + /* 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(barejid), _handle_own_device_list); - omemo_devicelist_request(barejid); omemo_bundle_publish(true); diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index 54cd12ad..20bf251a 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -47,12 +47,13 @@ #include "omemo/omemo.h" static int _omemo_receive_devicelist(xmpp_stanza_t* const stanza, void* const userdata); +static int _omemo_devicelist_publish_result(xmpp_stanza_t* const stanza, void* const userdata); +static int _omemo_devicelist_configure(xmpp_stanza_t* const stanza, void* const userdata); +static int _omemo_devicelist_configure_result(xmpp_stanza_t* const stanza, void* const userdata); static int _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata); static int _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdata); static int _omemo_bundle_publish_configure_result(xmpp_stanza_t* const stanza, void* const userdata); -static int _omemo_device_list_publish_result(xmpp_stanza_t* const stanza, void* const userdata); - void omemo_devicelist_subscribe(void) { @@ -69,14 +70,28 @@ omemo_devicelist_publish(GList* device_list) log_debug("[OMEMO] publish device list"); - if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) { - stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open"); - } + iq_id_handler_add(xmpp_stanza_get_id(iq), _omemo_devicelist_publish_result, NULL, NULL); + + iq_send_stanza(iq); + xmpp_stanza_release(iq); +} - iq_id_handler_add(xmpp_stanza_get_id(iq), _omemo_device_list_publish_result, NULL, NULL); +void +omemo_devicelist_configure_and_request(void) +{ + xmpp_ctx_t* const ctx = connection_get_ctx(); + char* id = connection_create_stanza_id(); + Jid* jid = jid_create(connection_get_fulljid()); + + xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, jid->barejid, STANZA_NS_OMEMO_DEVICELIST); + + iq_id_handler_add(id, _omemo_devicelist_configure, NULL, NULL); iq_send_stanza(iq); + xmpp_stanza_release(iq); + free(id); + jid_destroy(jid); } void @@ -512,6 +527,76 @@ _omemo_receive_devicelist(xmpp_stanza_t* const stanza, void* const userdata) return 1; } +static int +_omemo_devicelist_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) { + cons_show_error("Unable to publish own OMEMO device list"); + log_error("[OMEMO] Publishing device list failed"); + return 0; + } + return 0; +} + +static int +_omemo_devicelist_configure(xmpp_stanza_t* const stanza, void* const userdata) +{ + log_debug("[OMEMO] _omemo_devicelist_configure()"); + + 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"); + return 0; + } + xmpp_stanza_t* configure = xmpp_stanza_get_child_by_name(pubsub, STANZA_NAME_CONFIGURE); + if (!configure) { + log_error("[OMEMO] The stanza doesn't contain a 'configure' child"); + return 0; + } + xmpp_stanza_t* x = xmpp_stanza_get_child_by_name(configure, "x"); + if (!x) { + log_error("[OMEMO] The stanza doesn't contain an 'x' child"); + return 0; + } + + DataForm* form = form_create(x); + form_set_value(form, "pubsub#access_model", "open"); + + xmpp_ctx_t* const ctx = connection_get_ctx(); + Jid* jid = jid_create(connection_get_fulljid()); + char* id = connection_create_stanza_id(); + xmpp_stanza_t* iq = stanza_create_pubsub_configure_submit(ctx, id, jid->barejid, STANZA_NS_OMEMO_DEVICELIST, form); + + iq_id_handler_add(id, _omemo_devicelist_configure_result, NULL, NULL); + + iq_send_stanza(iq); + + xmpp_stanza_release(iq); + free(id); + jid_destroy(jid); + return 0; +} + +static int +_omemo_devicelist_configure_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] cannot configure device list to an open access model: Result error"); + return 0; + } + + log_debug("[OMEMO] node configured"); + + // Try to publish + char* barejid = connection_get_barejid(); + omemo_devicelist_request(barejid); + + return 0; +} + static int _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata) @@ -572,11 +657,7 @@ _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdat } DataForm* form = form_create(x); - char* tag = g_hash_table_lookup(form->var_to_tag, "pubsub#access_model"); - if (!tag) { - log_error("[OMEMO] cannot configure bundle to an open access model"); - return 0; - } + form_set_value(form, "pubsub#access_model", "open"); xmpp_ctx_t* const ctx = connection_get_ctx(); Jid* jid = jid_create(connection_get_fulljid()); @@ -612,15 +693,3 @@ _omemo_bundle_publish_configure_result(xmpp_stanza_t* const stanza, void* const return 0; } - -static int -_omemo_device_list_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) { - cons_show_error("Unable to publish own OMEMO device list"); - log_error("[OMEMO] Publishing device list failed"); - return 0; - } - return 0; -} diff --git a/src/xmpp/omemo.h b/src/xmpp/omemo.h index 31021ab4..9f29cb96 100644 --- a/src/xmpp/omemo.h +++ b/src/xmpp/omemo.h @@ -38,6 +38,7 @@ #include "xmpp/iq.h" void omemo_devicelist_subscribe(void); +void omemo_devicelist_configure_and_request(void); void omemo_devicelist_publish(GList* device_list); void omemo_devicelist_request(const char* const jid); void omemo_bundle_publish(gboolean first); |