From 33b0b4642000166ca7f8033ac5ff2e2c6e7b4671 Mon Sep 17 00:00:00 2001 From: Paul Fariello Date: Fri, 15 Mar 2019 18:47:43 +0140 Subject: Fix prekey handling after first use libsignal will remove prekey on its own. --- src/omemo/omemo.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/omemo') diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 7850dad9..23892c02 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -675,21 +675,20 @@ omemo_on_message_recv(const char *const from, uint32_t sid, pre_key_signal_message_deserialize(&message, key->data, key->length, omemo_ctx.signal); + res = session_cipher_decrypt_pre_key_signal_message(cipher, message, NULL, &plaintext_key); /* Replace used pre_key in bundle */ uint32_t pre_key_id = pre_key_signal_message_get_pre_key_id(message); - g_hash_table_remove(omemo_ctx.pre_key_store, GINT_TO_POINTER(pre_key_id)); ec_key_pair *ec_pair; session_pre_key *new_pre_key; curve_generate_key_pair(omemo_ctx.signal, &ec_pair); session_pre_key_create(&new_pre_key, pre_key_id, ec_pair); - g_hash_table_insert(omemo_ctx.pre_key_store, GINT_TO_POINTER(pre_key_id), new_pre_key); + signal_protocol_pre_key_store_key(omemo_ctx.store, new_pre_key); omemo_bundle_publish(); - /* Start a new session */ - omemo_bundle_request(from, sid, omemo_start_device_session_handle_bundle, free, strdup(from)); - - /* Try to decrypt message anyway, it will fail */ - res = session_cipher_decrypt_pre_key_signal_message(cipher, message, NULL, &plaintext_key); + if (res == 0) { + /* Start a new session */ + omemo_bundle_request(from, sid, omemo_start_device_session_handle_bundle, free, strdup(from)); + } } else { log_debug("OMEMO: decrypting message with existing session"); signal_message *message; @@ -697,7 +696,7 @@ omemo_on_message_recv(const char *const from, uint32_t sid, res = session_cipher_decrypt_signal_message(cipher, message, NULL, &plaintext_key); } if (res != 0) { - log_debug("OMEMO: cannot to decrypt message key"); + log_error("OMEMO: cannot decrypt message key"); return NULL; } -- cgit 1.4.1-2-gfad0