From 2602cbf7852fa4317d961316b601a383b9077079 Mon Sep 17 00:00:00 2001 From: Paul Fariello Date: Tue, 19 Feb 2019 20:03:50 +0140 Subject: Move OMEMO initialization to profanity intialization Also store identity keys into account --- src/omemo/omemo.c | 24 ++++++++++++++++++++---- src/omemo/omemo.h | 3 ++- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'src/omemo') diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 96e07d1c..1b2998b0 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -8,6 +8,7 @@ static void lock(void *user_data); static void unlock(void *user_data); +static void omemo_load_crypto_materials(ProfAccount *account); struct omemo_context_t { pthread_mutexattr_t attr; @@ -15,8 +16,9 @@ struct omemo_context_t { }; void -omemo_init(ProfAccount *account) +omemo_init(void) { + log_info("Initialising OMEMO"); signal_context *signal_ctx; omemo_context *ctx = malloc(sizeof(omemo_context)); signal_crypto_provider crypto_provider = { @@ -35,7 +37,7 @@ omemo_init(ProfAccount *account) }; if (omemo_crypto_init() != 0) { - cons_show("Error initializing Omemo crypto"); + cons_show("Error initializing OMEMO crypto"); } pthread_mutexattr_init(&ctx->attr); @@ -43,18 +45,32 @@ omemo_init(ProfAccount *account) pthread_mutex_init(&ctx->lock, &ctx->attr); if (signal_context_create(&signal_ctx, ctx) != 0) { - cons_show("Error initializing Omemo context"); + cons_show("Error initializing OMEMO context"); return; } if (signal_context_set_crypto_provider(signal_ctx, &crypto_provider) != 0) { - cons_show("Error initializing Omemo crypto"); + cons_show("Error initializing OMEMO crypto"); return; } signal_context_set_locking_functions(signal_ctx, lock, unlock); } +void +omemo_generate_crypto_materials(ProfAccount *account) +{ + ratchet_identity_key_pair *identity_key_pair; + uint32_t registration_id; + signal_protocol_key_helper_pre_key_list_node *pre_keys_head; + session_signed_pre_key *signed_pre_key; + + signal_protocol_key_helper_generate_identity_key_pair(&identity_key_pair, global_context); + signal_protocol_key_helper_generate_registration_id(®istration_id, 0, global_context); + signal_protocol_key_helper_generate_pre_keys(&pre_keys_head, start_id, 100, global_context); + signal_protocol_key_helper_generate_signed_pre_key(&signed_pre_key, identity_key_pair, 5, timestamp, global_context); +} + static void lock(void *user_data) { diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h index d34b90bf..825529b1 100644 --- a/src/omemo/omemo.h +++ b/src/omemo/omemo.h @@ -2,4 +2,5 @@ typedef struct omemo_context_t omemo_context; -void omemo_init(ProfAccount *account); +void omemo_init(void); +void omemo_generate_crypto_materials(ProfAccount *account); -- cgit 1.4.1-2-gfad0