From 55626cd08ff046d1e04b5ccd5ed0858ea49052fc Mon Sep 17 00:00:00 2001 From: Tony Olagbaiye Date: Thu, 8 Jul 2021 04:19:49 +0100 Subject: [PATCH] change muc --- README.org | 6 ++++-- connection.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- omemo.c | 2 -- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/README.org b/README.org index a6770c9..37728fd 100644 --- a/README.org +++ b/README.org @@ -16,7 +16,7 @@ [[https://github.com/bqv/weechat-xmpp/issues?q=is:issue+is:closed][file:https://img.shields.io/github/issues-closed/bqv/weechat-xmpp.svg]] [[https://github.com/bqv/weechat-xmpp/blob/master/LICENSE][file:https://img.shields.io/github/license/bqv/weechat-xmpp.svg]] [[https://github.com/bqv/weechat-extras/][file:https://img.shields.io/badge/weechat--extras-xmpp-blue.svg]] -[[https://github.com/bqv/weechat-extras/][file:https://inverse.chat/badge.svg?room=weechat@conference.hmm.st]] +[[https://github.com/bqv/weechat-extras/][file:https://inverse.chat/badge.svg?room=weechat@muc.xa0.uk]] | Status: | XMPP for power users and digital masochists | | Location: | [[http://github.com/bqv/weechat-xmpp]] | @@ -115,8 +115,10 @@ * [ ] OMEMO (libsignal-protocol-c / axc) * [ ] Presence * [X] Disco - * [ ] Disco response + * [X] Disco response * [ ] Key Generation / storage (secured_data?) + * [X] Generation + * [ ] Storage * [ ] Messages * [ ] [#C] MUC PMs * [ ] [#A] Send typing notifications diff --git a/connection.c b/connection.c index b1d35a9..d534ce2 100644 --- a/connection.c +++ b/connection.c @@ -697,7 +697,57 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status, xmpp_send(conn, children[0]); xmpp_stanza_release(children[0]); - omemo__init(&account->omemo, 0, NULL); + struct t_hashtable *variables = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + weechat_hashtable_set(variables, "account", account->name); + char *dev_str = weechat_string_eval_expression( + "${sec.data.xmpp_device_${account}}", + NULL, variables, NULL); + char *b64_id = weechat_string_eval_expression( + "${sec.data.xmpp_identity_${account}}", + NULL, variables, NULL); + weechat_hashtable_free(variables); + uint32_t dev_id = dev_str[0] ? atoi(dev_str) : 0; + uint8_t identity[128]; + if (b64_id) + weechat_string_base_decode(64, b64_id, (char*)identity); + struct t_identity id_key = { + .key = b64_id ? identity : NULL, + .length = 4, + }; + + omemo__init(&account->omemo, dev_id, &id_key); + + char account_id[64] = {0}; + snprintf(account_id, sizeof(account_id), "%d", account->omemo->device_id); + if (weechat_strcasecmp(dev_str, account_id) != 0) + { + char **command = weechat_string_dyn_alloc(256); + weechat_string_dyn_concat(command, "/secure set ", -1); + weechat_string_dyn_concat(command, "xmpp_device_", -1); + weechat_string_dyn_concat(command, account->name, -1); + weechat_string_dyn_concat(command, " ", -1); + weechat_string_dyn_concat(command, account_id, -1); + weechat_command(account->buffer, *command); + weechat_string_dyn_free(command, 1); + } + char account_key[64] = {0}; + weechat_string_base_encode(64, (char*)account->omemo->identity.key, + account->omemo->identity.length, account_key); + if (memcmp(identity, account->omemo->identity.key, + account->omemo->identity.length) != 0) + { + char **command = weechat_string_dyn_alloc(256); + weechat_string_dyn_concat(command, "/secure set ", -1); + weechat_string_dyn_concat(command, "xmpp_identity_", -1); + weechat_string_dyn_concat(command, account->name, -1); + weechat_string_dyn_concat(command, " ", -1); + weechat_string_dyn_concat(command, account_id, -1); + weechat_command(account->buffer, *command); + weechat_string_dyn_free(command, 1); + } } else { diff --git a/omemo.c b/omemo.c index 6ce67d7..d331bf1 100644 --- a/omemo.c +++ b/omemo.c @@ -9,8 +9,6 @@ void omemo__init(struct t_omemo **omemo, uint32_t device, struct t_identity *identity) { - const char* ns_devicelist = "eu.siacs.conversations.axolotl.devicelist"; - const char* ft_devicelist = "eu.siacs.conversations.axolotl.devicelist+notify"; int rc; srandom(time(NULL));