From 756fefb09aa9cb22d1f882c51984ca6047dc236d Mon Sep 17 00:00:00 2001 From: Paul Fariello Date: Fri, 22 Feb 2019 19:57:26 +0140 Subject: Fix devicelist subscription and handle pubsub event Devicelist subscription can be done directly with caps_add feature. --- src/omemo/omemo.c | 32 ++++++++++++++++++++++---------- src/omemo/omemo.h | 4 +++- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'src/omemo') diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 080baf1b..9300c6b8 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -11,6 +11,8 @@ #include "omemo/crypto.h" #include "omemo/omemo.h" #include "ui/ui.h" +#include "xmpp/xmpp.h" +#include "xmpp/connection.h" #include "xmpp/omemo.h" static gboolean loaded; @@ -23,7 +25,7 @@ struct omemo_context_t { pthread_mutex_t lock; signal_context *signal; uint32_t device_id; - GList *device_list; + GHashTable *device_list; ratchet_identity_key_pair *identity_key_pair; uint32_t registration_id; signal_protocol_key_helper_pre_key_list_node *pre_keys_head; @@ -72,14 +74,23 @@ omemo_init(void) signal_context_set_locking_functions(omemo_ctx.signal, lock, unlock); loaded = FALSE; - omemo_ctx.device_list = NULL; + omemo_ctx.device_list = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_list_free); } void omemo_generate_crypto_materials(ProfAccount *account) { + xmpp_ctx_t * const ctx = connection_get_ctx(); + char *barejid = xmpp_jid_bare(ctx, session_get_account_name()); + + GList *device_list = g_hash_table_lookup(omemo_ctx.device_list, barejid); + g_hash_table_steal(omemo_ctx.device_list, barejid); + omemo_ctx.device_id = randombytes_uniform(0x80000000); - omemo_ctx.device_list = g_list_append(omemo_ctx.device_list, GINT_TO_POINTER(omemo_ctx.device_id)); + + device_list = g_list_append(device_list, GINT_TO_POINTER(omemo_ctx.device_id)); + g_hash_table_insert(omemo_ctx.device_list, strdup(barejid), device_list); + signal_protocol_key_helper_generate_identity_key_pair(&omemo_ctx.identity_key_pair, omemo_ctx.signal); signal_protocol_key_helper_generate_registration_id(&omemo_ctx.registration_id, 0, omemo_ctx.signal); signal_protocol_key_helper_generate_pre_keys(&omemo_ctx.pre_keys_head, randombytes_random(), 100, omemo_ctx.signal); @@ -91,7 +102,7 @@ omemo_generate_crypto_materials(ProfAccount *account) loaded = TRUE; - omemo_devicelist_publish(); + omemo_devicelist_publish(device_list); omemo_bundle_publish(); } @@ -107,12 +118,6 @@ omemo_loaded(void) return loaded; } -GList * const -omemo_device_list(void) -{ - return omemo_ctx.device_list; -} - uint32_t omemo_device_id(void) { @@ -167,6 +172,13 @@ omemo_prekeys(GList ** const prekeys, GList ** const ids, GList ** const lengths } } +void +omemo_set_device_list(const char *const jid, GList * const device_list) +{ + /* TODO handle self device_list to ensure we still are on the list */ + g_hash_table_insert(omemo_ctx.device_list, strdup(jid), device_list); +} + static void lock(void *user_data) { diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h index 20fd5d5d..ca9f7208 100644 --- a/src/omemo/omemo.h +++ b/src/omemo/omemo.h @@ -1,3 +1,5 @@ +#include + #include "config/account.h" typedef struct omemo_context_t omemo_context; @@ -5,12 +7,12 @@ typedef struct omemo_context_t omemo_context; void omemo_init(void); void omemo_generate_crypto_materials(ProfAccount *account); -GList * const omemo_device_list(void); uint32_t omemo_device_id(void); void omemo_identity_key(unsigned char **output, size_t *length); void omemo_signed_prekey(unsigned char **output, size_t *length); void omemo_signed_prekey_signature(unsigned char **output, size_t *length); void omemo_prekeys(GList ** const prekeys, GList ** const ids, GList ** const lengths); +void omemo_set_device_list(const char *const jid, GList * const device_list); void omemo_start_session(ProfAccount *account, char *barejid); gboolean omemo_loaded(void); -- cgit 1.4.1-2-gfad0 #n37'>37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167