diff options
Diffstat (limited to 'src/omemo')
-rw-r--r-- | src/omemo/omemo.c | 32 | ||||
-rw-r--r-- | src/omemo/omemo.h | 4 |
2 files changed, 25 insertions, 11 deletions
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 <glib.h> + #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); |