1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Improved OMEMO logging

The most loggings has been set to debug. Just in case of error / problem the
logging should be done with log-level ERROR or WARNING.

We will see later, which loggings should be switched to log-level INFO.

This improvement has been done to find OMEMO bugs.

See also: #1070 #1530 #1538
This commit is contained in:
DebXWoody 2021-05-28 17:45:15 +02:00
parent efe4470372
commit de06cd395b
No known key found for this signature in database
GPG Key ID: CBD1B596579B7FFF
4 changed files with 84 additions and 40 deletions

View File

@ -404,10 +404,10 @@ void
omemo_start_session(const char* const barejid) omemo_start_session(const char* const barejid)
{ {
if (omemo_loaded()) { if (omemo_loaded()) {
log_info("[OMEMO] start session with %s", barejid); log_debug("[OMEMO] start session with %s", barejid);
GList* device_list = g_hash_table_lookup(omemo_ctx.device_list, barejid); GList* device_list = g_hash_table_lookup(omemo_ctx.device_list, barejid);
if (!device_list) { if (!device_list) {
log_info("[OMEMO] missing device list for %s", barejid); log_debug("[OMEMO] missing device list for %s", barejid);
omemo_devicelist_request(barejid); omemo_devicelist_request(barejid);
g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_device_list_start_session); g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_device_list_start_session);
return; return;
@ -544,11 +544,11 @@ omemo_set_device_list(const char* const from, GList* device_list)
// OMEMO trustmode ToFu // OMEMO trustmode ToFu
if (g_strcmp0(prefs_get_string(PREF_OMEMO_TRUST_MODE), "firstusage") == 0) { if (g_strcmp0(prefs_get_string(PREF_OMEMO_TRUST_MODE), "firstusage") == 0) {
log_info("[OMEMO] Checking firstusage state for %s", jid->barejid); log_debug("[OMEMO] Checking firstusage state for %s", jid->barejid);
GHashTable* trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, jid->barejid); GHashTable* trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, jid->barejid);
if (trusted) { if (trusted) {
if (g_hash_table_size(trusted) > 0) { if (g_hash_table_size(trusted) > 0) {
log_info("[OMEMO] Found trusted device for %s - skip firstusage", jid->barejid); log_debug("[OMEMO] Found trusted device for %s - skip firstusage", jid->barejid);
return; return;
} }
} else { } else {
@ -638,6 +638,7 @@ omemo_start_device_session(const char* const jid, uint32_t device_id,
const unsigned char* const signature, size_t signature_len, const unsigned char* const signature, size_t signature_len,
const unsigned char* const identity_key_raw, size_t identity_key_len) const unsigned char* const identity_key_raw, size_t identity_key_len)
{ {
log_debug("[OMEMO] Starting device session for %s with device %d", jid, device_id);
signal_protocol_address address = { signal_protocol_address address = {
.name = jid, .name = jid,
.name_len = strlen(jid), .name_len = strlen(jid),
@ -649,6 +650,7 @@ omemo_start_device_session(const char* const jid, uint32_t device_id,
_cache_device_identity(jid, device_id, identity_key); _cache_device_identity(jid, device_id, identity_key);
gboolean trusted = is_trusted_identity(&address, (uint8_t*)identity_key_raw, identity_key_len, &omemo_ctx.identity_key_store); gboolean trusted = is_trusted_identity(&address, (uint8_t*)identity_key_raw, identity_key_len, &omemo_ctx.identity_key_store);
log_debug("[OMEMO] Trust %s (%d): %d", jid, device_id, trusted);
if ((g_strcmp0(prefs_get_string(PREF_OMEMO_TRUST_MODE), "blind") == 0) && !trusted) { if ((g_strcmp0(prefs_get_string(PREF_OMEMO_TRUST_MODE), "blind") == 0) && !trusted) {
char* fp = _omemo_fingerprint(identity_key, TRUE); char* fp = _omemo_fingerprint(identity_key, TRUE);
@ -659,10 +661,12 @@ omemo_start_device_session(const char* const jid, uint32_t device_id,
} }
if (!trusted) { if (!trusted) {
log_debug("[OMEMO] We don't trust device %d for %s\n", device_id,jid);
goto out; goto out;
} }
if (!contains_session(&address, omemo_ctx.session_store)) { if (!contains_session(&address, omemo_ctx.session_store)) {
log_debug("[OMEMO] There is no Session for %s ( %d) ,... building session.", address.name, address.device_id );
int res; int res;
session_pre_key_bundle* bundle; session_pre_key_bundle* bundle;
signal_protocol_address* address; signal_protocol_address* address;
@ -701,7 +705,9 @@ omemo_start_device_session(const char* const jid, uint32_t device_id,
goto out; goto out;
} }
log_info("[OMEMO] create session with %s device %d", jid, device_id); log_debug("[OMEMO] create session with %s device %d", jid, device_id);
} else {
log_debug("[OMEMO] session with %s device %d exists", jid, device_id);
} }
out: out:
@ -734,7 +740,7 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
res = aes128gcm_encrypt(ciphertext, &ciphertext_len, tag, &tag_len, (const unsigned char* const)message, strlen(message), iv, key); res = aes128gcm_encrypt(ciphertext, &ciphertext_len, tag, &tag_len, (const unsigned char* const)message, strlen(message), iv, key);
if (res != 0) { if (res != 0) {
log_error("[OMEMO] cannot encrypt message"); log_error("[OMEMO][SEND] cannot encrypt message");
goto out; goto out;
} }
@ -770,7 +776,8 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
GList* recipient_device_id = NULL; GList* recipient_device_id = NULL;
recipient_device_id = g_hash_table_lookup(omemo_ctx.device_list, recipients_iter->data); recipient_device_id = g_hash_table_lookup(omemo_ctx.device_list, recipients_iter->data);
if (!recipient_device_id) { if (!recipient_device_id) {
log_warning("[OMEMO] cannot find device ids for %s", recipients_iter->data); log_warning("[OMEMO][SEND] cannot find device ids for %s", recipients_iter->data);
win_println(win, THEME_ERROR, "!", "Can't find a OMEMO device id for %s.\n", recipients_iter->data);
continue; continue;
} }
@ -784,16 +791,17 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
.device_id = GPOINTER_TO_INT(device_ids_iter->data) .device_id = GPOINTER_TO_INT(device_ids_iter->data)
}; };
log_debug("[OMEMO][SEND] recipients with device id %d for %s", GPOINTER_TO_INT(device_ids_iter->data), recipients_iter->data);
res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal); res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal);
if (res != 0) { if (res != SG_SUCCESS ) {
log_error("[OMEMO] cannot create cipher for %s device id %d", address.name, address.device_id); log_error("[OMEMO][SEND] cannot create cipher for %s device id %d - code: %d", address.name, address.device_id, res);
continue; continue;
} }
res = session_cipher_encrypt(cipher, key_tag, AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH, &ciphertext); res = session_cipher_encrypt(cipher, key_tag, AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH, &ciphertext);
session_cipher_free(cipher); session_cipher_free(cipher);
if (res != 0) { if (res != SG_SUCCESS ) {
log_error("[OMEMO] cannot encrypt key for %s device id %d", address.name, address.device_id); log_error("[OMEMO][SEND] cannot encrypt key for %s device id %d - code: %d", address.name, address.device_id,res);
continue; continue;
} }
signal_buffer* buffer = ciphertext_message_get_serialized(ciphertext); signal_buffer* buffer = ciphertext_message_get_serialized(ciphertext);
@ -832,7 +840,7 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
.name_len = strlen(jid->barejid), .name_len = strlen(jid->barejid),
.device_id = GPOINTER_TO_INT(device_ids_iter->data) .device_id = GPOINTER_TO_INT(device_ids_iter->data)
}; };
log_debug("[OMEMO][SEND] Sending to device %d for %s ", address.device_id, address.name);
// Don't encrypt for this device (according to // Don't encrypt for this device (according to
// <https://xmpp.org/extensions/xep-0384.html#encrypt>). // <https://xmpp.org/extensions/xep-0384.html#encrypt>).
if (address.device_id == omemo_ctx.device_id) { if (address.device_id == omemo_ctx.device_id) {
@ -841,14 +849,14 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal); res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal);
if (res != 0) { if (res != 0) {
log_error("[OMEMO] cannot create cipher for %s device id %d", address.name, address.device_id); log_error("[OMEMO][SEND] cannot create cipher for %s device id %d", address.name, address.device_id);
continue; continue;
} }
res = session_cipher_encrypt(cipher, key_tag, AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH, &ciphertext); res = session_cipher_encrypt(cipher, key_tag, AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH, &ciphertext);
session_cipher_free(cipher); session_cipher_free(cipher);
if (res != 0) { if (res != 0) {
log_error("[OMEMO] cannot encrypt key for %s device id %d", address.name, address.device_id); log_error("[OMEMO][SEND] cannot encrypt key for %s device id %d", address.name, address.device_id);
continue; continue;
} }
signal_buffer* buffer = ciphertext_message_get_serialized(ciphertext); signal_buffer* buffer = ciphertext_message_get_serialized(ciphertext);
@ -895,7 +903,7 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
Jid* sender = NULL; Jid* sender = NULL;
Jid* from = jid_create(from_jid); Jid* from = jid_create(from_jid);
if (!from) { if (!from) {
log_error("Invalid jid %s", from_jid); log_error("[OMEMO][RECV] Invalid jid %s", from_jid);
goto out; goto out;
} }
@ -910,7 +918,7 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
} }
if (!key) { if (!key) {
log_warning("[OMEMO] received a message with no corresponding key"); log_warning("[OMEMO][RECV] received a message with no corresponding key");
goto out; goto out;
} }
@ -926,7 +934,7 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
} }
g_list_free(roster); g_list_free(roster);
if (!sender) { if (!sender) {
log_warning("[OMEMO] cannot find MUC message sender fulljid"); log_warning("[OMEMO][RECV] cannot find MUC message sender fulljid");
goto out; goto out;
} }
} else { } else {
@ -943,12 +951,12 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal); res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal);
if (res != 0) { if (res != 0) {
log_error("[OMEMO] cannot create session cipher"); log_error("[OMEMO][RECV] cannot create session cipher");
goto out; goto out;
} }
if (key->prekey) { if (key->prekey) {
log_debug("[OMEMO] decrypting message with prekey"); log_debug("[OMEMO][RECV] decrypting message with prekey");
pre_key_signal_message* message; pre_key_signal_message* message;
ec_public_key* their_identity_key; ec_public_key* their_identity_key;
signal_buffer* identity_buffer = NULL; signal_buffer* identity_buffer = NULL;
@ -981,16 +989,17 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
if (res == 0) { if (res == 0) {
/* Start a new session */ /* Start a new session */
log_debug("[OMEMO][RECV] Res is 0 => omemo_bundle_request");
omemo_bundle_request(sender->barejid, sid, omemo_start_device_session_handle_bundle, free, strdup(sender->barejid)); omemo_bundle_request(sender->barejid, sid, omemo_start_device_session_handle_bundle, free, strdup(sender->barejid));
} }
} else { } else {
log_debug("[OMEMO] decrypting message with existing session"); log_debug("[OMEMO][RECV] decrypting message with existing session");
signal_message* message = NULL; signal_message* message = NULL;
res = signal_message_deserialize(&message, key->data, key->length, omemo_ctx.signal); res = signal_message_deserialize(&message, key->data, key->length, omemo_ctx.signal);
if (res < 0) { if (res < 0) {
log_error("[OMEMO] cannot deserialize message"); log_error("[OMEMO][RECV] cannot deserialize message");
} else { } else {
res = session_cipher_decrypt_signal_message(cipher, message, NULL, &plaintext_key); res = session_cipher_decrypt_signal_message(cipher, message, NULL, &plaintext_key);
*trusted = true; *trusted = true;
@ -1000,12 +1009,12 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
session_cipher_free(cipher); session_cipher_free(cipher);
if (res != 0) { if (res != 0) {
log_error("[OMEMO] cannot decrypt message key"); log_error("[OMEMO][RECV] cannot decrypt message key");
goto out; goto out;
} }
if (signal_buffer_len(plaintext_key) != AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH) { if (signal_buffer_len(plaintext_key) != AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH) {
log_error("[OMEMO] invalid key length"); log_error("[OMEMO][RECV] invalid key length");
signal_buffer_free(plaintext_key); signal_buffer_free(plaintext_key);
goto out; goto out;
} }
@ -1017,7 +1026,7 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
signal_buffer_data(plaintext_key) + AES128_GCM_KEY_LENGTH); signal_buffer_data(plaintext_key) + AES128_GCM_KEY_LENGTH);
signal_buffer_free(plaintext_key); signal_buffer_free(plaintext_key);
if (res != 0) { if (res != 0) {
log_error("[OMEMO] cannot decrypt message: %s", gcry_strerror(res)); log_error("[OMEMO][RECV] cannot decrypt message: %s", gcry_strerror(res));
free(plaintext); free(plaintext);
plaintext = NULL; plaintext = NULL;
goto out; goto out;
@ -1112,6 +1121,7 @@ omemo_is_trusted_identity(const char* const jid, const char* const fingerprint)
buffer = signal_buffer_append(buffer, fingerprint_raw, fingerprint_len); buffer = signal_buffer_append(buffer, fingerprint_raw, fingerprint_len);
gboolean trusted = is_trusted_identity(&address, signal_buffer_data(buffer), signal_buffer_len(buffer), &omemo_ctx.identity_key_store); gboolean trusted = is_trusted_identity(&address, signal_buffer_data(buffer), signal_buffer_len(buffer), &omemo_ctx.identity_key_store);
log_debug("[OMEMO] Device trusted %s (%d): %d", jid, GPOINTER_TO_INT(device_id), trusted);
free(fingerprint_raw); free(fingerprint_raw);
signal_buffer_free(buffer); signal_buffer_free(buffer);
@ -1305,17 +1315,17 @@ _omemo_log(int level, const char* message, size_t len, void* user_data)
{ {
switch (level) { switch (level) {
case SG_LOG_ERROR: case SG_LOG_ERROR:
log_error("[OMEMO] %s", message); log_error("[OMEMO][SIGNAL] %s", message);
break; break;
case SG_LOG_WARNING: case SG_LOG_WARNING:
log_warning("[OMEMO] %s", message); log_warning("[OMEMO][SIGNAL] %s", message);
break; break;
case SG_LOG_NOTICE: case SG_LOG_NOTICE:
case SG_LOG_INFO: case SG_LOG_INFO:
log_info("[OMEMO] %s", message); log_debug("[OMEMO][SIGNAL] %s", message);
break; break;
case SG_LOG_DEBUG: case SG_LOG_DEBUG:
log_debug("[OMEMO] %s", message); log_debug("[OMEMO][SIGNAL] %s", message);
break; break;
} }
} }
@ -1323,13 +1333,16 @@ _omemo_log(int level, const char* message, size_t len, void* user_data)
static gboolean static gboolean
_handle_own_device_list(const char* const jid, GList* device_list) _handle_own_device_list(const char* const jid, GList* device_list)
{ {
// We didn't find the own device id -> publish
if (!g_list_find(device_list, GINT_TO_POINTER(omemo_ctx.device_id))) { if (!g_list_find(device_list, GINT_TO_POINTER(omemo_ctx.device_id))) {
log_debug("[OMEMO] No device id for our device? publish device list...");
device_list = g_list_copy(device_list); device_list = g_list_copy(device_list);
device_list = g_list_append(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(jid), device_list); g_hash_table_insert(omemo_ctx.device_list, strdup(jid), device_list);
omemo_devicelist_publish(device_list); omemo_devicelist_publish(device_list);
} }
log_debug("[OMEMO] Request OMEMO Bundles for my devices...");
GList* device_id; GList* device_id;
for (device_id = device_list; device_id != NULL; device_id = device_id->next) { for (device_id = device_list; device_id != NULL; device_id = device_id->next) {
omemo_bundle_request(jid, GPOINTER_TO_INT(device_id->data), omemo_start_device_session_handle_bundle, free, strdup(jid)); omemo_bundle_request(jid, GPOINTER_TO_INT(device_id->data), omemo_start_device_session_handle_bundle, free, strdup(jid));
@ -1341,6 +1354,7 @@ _handle_own_device_list(const char* const jid, GList* device_list)
static gboolean static gboolean
_handle_device_list_start_session(const char* const jid, GList* device_list) _handle_device_list_start_session(const char* const jid, GList* device_list)
{ {
log_debug("[OMEMO] Start session for %s - device_list", jid);
omemo_start_session(jid); omemo_start_session(jid);
return FALSE; return FALSE;
@ -1446,7 +1460,7 @@ static gboolean
_load_identity(void) _load_identity(void)
{ {
GError* error = NULL; GError* error = NULL;
log_info("Loading OMEMO identity"); log_info("[OMEMO] Loading OMEMO identity");
/* Device ID */ /* Device ID */
error = NULL; error = NULL;
@ -1455,7 +1469,7 @@ _load_identity(void)
log_error("[OMEMO] cannot load device id: %s", error->message); log_error("[OMEMO] cannot load device id: %s", error->message);
return FALSE; return FALSE;
} }
log_info("[OMEMO] device id: %d", omemo_ctx.device_id); log_debug("[OMEMO] device id: %d", omemo_ctx.device_id);
/* Registration ID */ /* Registration ID */
error = NULL; error = NULL;
@ -1658,7 +1672,7 @@ _cache_device_identity(const char* const jid, uint32_t device_id, ec_public_key*
} }
char* fingerprint = _omemo_fingerprint(identity, FALSE); char* fingerprint = _omemo_fingerprint(identity, FALSE);
log_info("[OMEMO] cache identity for %s:%d: %s", jid, device_id, fingerprint); log_debug("[OMEMO] cache identity for %s:%d: %s", jid, device_id, fingerprint);
g_hash_table_insert(known_identities, strdup(fingerprint), GINT_TO_POINTER(device_id)); g_hash_table_insert(known_identities, strdup(fingerprint), GINT_TO_POINTER(device_id));
char* device_id_str = g_strdup_printf("%d", device_id); char* device_id_str = g_strdup_printf("%d", device_id);

View File

@ -36,6 +36,7 @@
#include <signal/signal_protocol.h> #include <signal/signal_protocol.h>
#include "config.h" #include "config.h"
#include "log.h"
#include "omemo/omemo.h" #include "omemo/omemo.h"
#include "omemo/store.h" #include "omemo/store.h"
@ -80,15 +81,19 @@ load_session(signal_buffer** record, signal_buffer** user_record,
GHashTable* session_store = (GHashTable*)user_data; GHashTable* session_store = (GHashTable*)user_data;
GHashTable* device_store = NULL; GHashTable* device_store = NULL;
log_debug("[OMEMO][STORE] Looking for %s in session_store", address->name);
device_store = g_hash_table_lookup(session_store, address->name); device_store = g_hash_table_lookup(session_store, address->name);
if (!device_store) { if (!device_store) {
*record = NULL; *record = NULL;
log_warning("[OMEMO][STORE] No device store for %s found", address->name);
return 0; return 0;
} }
log_debug("[OMEMO][STORE] Looking for device %d of %s ", address->device_id, address->name);
signal_buffer* original = g_hash_table_lookup(device_store, GINT_TO_POINTER(address->device_id)); signal_buffer* original = g_hash_table_lookup(device_store, GINT_TO_POINTER(address->device_id));
if (!original) { if (!original) {
*record = NULL; *record = NULL;
log_warning("[OMEMO][STORE] No device (%d) store for %s found", address->device_id, address->name);
return 0; return 0;
} }
*record = signal_buffer_copy(original); *record = signal_buffer_copy(original);
@ -106,6 +111,7 @@ get_sub_device_sessions(signal_int_list** sessions, const char* name,
device_store = g_hash_table_lookup(session_store, name); device_store = g_hash_table_lookup(session_store, name);
if (!device_store) { if (!device_store) {
log_debug("[OMEMO][STORE] What?");
return SG_SUCCESS; return SG_SUCCESS;
} }
@ -133,6 +139,7 @@ store_session(const signal_protocol_address* address,
GHashTable* session_store = (GHashTable*)user_data; GHashTable* session_store = (GHashTable*)user_data;
GHashTable* device_store = NULL; GHashTable* device_store = NULL;
log_debug("[OMEMO][STORE] Store session for %s (%d)", address->name, address->device_id);
device_store = g_hash_table_lookup(session_store, (void*)address->name); device_store = g_hash_table_lookup(session_store, (void*)address->name);
if (!device_store) { if (!device_store) {
device_store = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free); device_store = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
@ -161,10 +168,12 @@ contains_session(const signal_protocol_address* address, void* user_data)
device_store = g_hash_table_lookup(session_store, address->name); device_store = g_hash_table_lookup(session_store, address->name);
if (!device_store) { if (!device_store) {
log_debug("[OMEMO][STORE] No Device");
return 0; return 0;
} }
if (!g_hash_table_lookup(device_store, GINT_TO_POINTER(address->device_id))) { if (!g_hash_table_lookup(device_store, GINT_TO_POINTER(address->device_id))) {
log_debug("[OMEMO][STORE] No Session for %d ", address->device_id);
return 0; return 0;
} }
@ -200,6 +209,7 @@ delete_all_sessions(const char* name, size_t name_len, void* user_data)
device_store = g_hash_table_lookup(session_store, name); device_store = g_hash_table_lookup(session_store, name);
if (!device_store) { if (!device_store) {
log_debug("[OMEMO][STORE] No device => no delete");
return SG_SUCCESS; return SG_SUCCESS;
} }
@ -216,6 +226,7 @@ load_pre_key(signal_buffer** record, uint32_t pre_key_id, void* user_data)
original = g_hash_table_lookup(pre_key_store, GINT_TO_POINTER(pre_key_id)); original = g_hash_table_lookup(pre_key_store, GINT_TO_POINTER(pre_key_id));
if (original == NULL) { if (original == NULL) {
log_error("[OMEMO][STORE] SG_ERR_INVALID_KEY_ID");
return SG_ERR_INVALID_KEY_ID; return SG_ERR_INVALID_KEY_ID;
} }
@ -269,6 +280,7 @@ remove_pre_key(uint32_t pre_key_id, void* user_data)
if (ret > 0) { if (ret > 0) {
return SG_SUCCESS; return SG_SUCCESS;
} else { } else {
log_error("[OMEMO][STORE] SG_ERR_INVALID_KEY_ID");
return SG_ERR_INVALID_KEY_ID; return SG_ERR_INVALID_KEY_ID;
} }
} }
@ -282,6 +294,7 @@ load_signed_pre_key(signal_buffer** record, uint32_t signed_pre_key_id,
original = g_hash_table_lookup(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id)); original = g_hash_table_lookup(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id));
if (!original) { if (!original) {
log_error("[OMEMO][STORE] SG_ERR_INVALID_KEY_ID");
return SG_ERR_INVALID_KEY_ID; return SG_ERR_INVALID_KEY_ID;
} }
@ -370,6 +383,7 @@ save_identity(const signal_protocol_address* address, uint8_t* key_data,
int trusted = is_trusted_identity(address, key_data, key_len, user_data); int trusted = is_trusted_identity(address, key_data, key_len, user_data);
identity_key_store->recv = true; identity_key_store->recv = true;
if (trusted == 0) { if (trusted == 0) {
log_debug("[OMEMO][STORE] trusted 0");
/* If not trusted we just don't save the identity */ /* If not trusted we just don't save the identity */
return SG_SUCCESS; return SG_SUCCESS;
} }
@ -402,12 +416,14 @@ is_trusted_identity(const signal_protocol_address* address, uint8_t* key_data,
{ {
int ret; int ret;
identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data; identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data;
log_debug("[OMEMO][STORE] Checking trust %s (%d)", address->name, address->device_id);
GHashTable* trusted = g_hash_table_lookup(identity_key_store->trusted, address->name); GHashTable* trusted = g_hash_table_lookup(identity_key_store->trusted, address->name);
if (!trusted) { if (!trusted) {
if (identity_key_store->recv) { if (identity_key_store->recv) {
log_debug("[OMEMO][STORE] identity_key_store->recv");
return 1; return 1;
} else { } else {
log_debug("[OMEMO][STORE] !identity_key_store->recv");
return 0; return 0;
} }
} }
@ -415,13 +431,18 @@ is_trusted_identity(const signal_protocol_address* address, uint8_t* key_data,
signal_buffer* buffer = signal_buffer_create(key_data, key_len); signal_buffer* buffer = signal_buffer_create(key_data, key_len);
signal_buffer* original = g_hash_table_lookup(trusted, GINT_TO_POINTER(address->device_id)); signal_buffer* original = g_hash_table_lookup(trusted, GINT_TO_POINTER(address->device_id));
if(!original) {
log_debug("[OMEMO][STORE] original not found %s (%d)", address->name, address->device_id);
}
ret = original != NULL && signal_buffer_compare(buffer, original) == 0; ret = original != NULL && signal_buffer_compare(buffer, original) == 0;
signal_buffer_free(buffer); signal_buffer_free(buffer);
if (identity_key_store->recv) { if (identity_key_store->recv) {
log_debug("[OMEMO][STORE] 1 identity_key_store->recv");
return 1; return 1;
} else { } else {
log_debug("[OMEMO][STORE] Checking trust %s (%d): %d", address->name, address->device_id, ret);
return ret; return ret;
} }
} }

View File

@ -624,6 +624,7 @@ message_send_chat_omemo(const char* const jid, uint32_t sid, GList* keys,
xmpp_stanza_t* header = xmpp_stanza_new(ctx); xmpp_stanza_t* header = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(header, "header"); xmpp_stanza_set_name(header, "header");
char* sid_text = g_strdup_printf("%d", sid); char* sid_text = g_strdup_printf("%d", sid);
log_debug("[OMEMO] Sending from device sid %s", sid_text);
xmpp_stanza_set_attribute(header, "sid", sid_text); xmpp_stanza_set_attribute(header, "sid", sid_text);
g_free(sid_text); g_free(sid_text);
@ -634,6 +635,7 @@ message_send_chat_omemo(const char* const jid, uint32_t sid, GList* keys,
xmpp_stanza_t* key_stanza = xmpp_stanza_new(ctx); xmpp_stanza_t* key_stanza = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(key_stanza, "key"); xmpp_stanza_set_name(key_stanza, "key");
char* rid = g_strdup_printf("%d", key->device_id); char* rid = g_strdup_printf("%d", key->device_id);
log_debug("[OMEMO] Sending to device rid %s", rid == NULL ? "NULL" : rid );
xmpp_stanza_set_attribute(key_stanza, "rid", rid); xmpp_stanza_set_attribute(key_stanza, "rid", rid);
g_free(rid); g_free(rid);
if (key->prekey) { if (key->prekey) {

View File

@ -65,7 +65,7 @@ omemo_devicelist_publish(GList* device_list)
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
xmpp_stanza_t* iq = stanza_create_omemo_devicelist_publish(ctx, device_list); xmpp_stanza_t* iq = stanza_create_omemo_devicelist_publish(ctx, device_list);
log_info("[OMEMO] publish device list"); log_debug("[OMEMO] publish device list");
if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) { if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) {
stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open"); stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open");
@ -81,7 +81,7 @@ omemo_devicelist_request(const char* const jid)
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
char* id = connection_create_stanza_id(); char* id = connection_create_stanza_id();
log_info("[OMEMO] request device list for jid: %s", jid); log_debug("[OMEMO] request device list for jid: %s", jid);
xmpp_stanza_t* iq = stanza_create_omemo_devicelist_request(ctx, id, jid); xmpp_stanza_t* iq = stanza_create_omemo_devicelist_request(ctx, id, jid);
iq_id_handler_add(id, _omemo_receive_devicelist, NULL, NULL); iq_id_handler_add(id, _omemo_receive_devicelist, NULL, NULL);
@ -95,7 +95,7 @@ omemo_devicelist_request(const char* const jid)
void void
omemo_bundle_publish(gboolean first) omemo_bundle_publish(gboolean first)
{ {
log_info("[OMEMO] publish own OMEMO bundle"); log_debug("[OMEMO] publish own OMEMO bundle");
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
unsigned char* identity_key = NULL; unsigned char* identity_key = NULL;
size_t identity_key_length; size_t identity_key_length;
@ -144,7 +144,7 @@ omemo_bundle_request(const char* const jid, uint32_t device_id, ProfIqCallback f
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
char* id = connection_create_stanza_id(); char* id = connection_create_stanza_id();
log_info("[OMEMO] request omemo bundle (jid: %s, deivce: %d)", jid, device_id); log_debug("[OMEMO] request omemo bundle (jid: %s, device: %d)", jid, device_id);
xmpp_stanza_t* iq = stanza_create_omemo_bundle_request(ctx, id, jid, device_id); xmpp_stanza_t* iq = stanza_create_omemo_bundle_request(ctx, id, jid, device_id);
iq_id_handler_add(id, func, free_func, userdata); iq_id_handler_add(id, func, free_func, userdata);
@ -164,6 +164,12 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t* const stanza, void* cons
char* from = NULL; char* from = NULL;
const char* from_attr = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); const char* from_attr = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
log_debug("[OMEMO] omemo_start_device_session_handle_bundle: %s", from_attr);
const char* type = xmpp_stanza_get_type(stanza);
if ( g_strcmp0( type, "error") == 0 ) {
log_error("[OMEMO] Error to get key for a device from : %s", from_attr);
}
if (!from_attr) { if (!from_attr) {
Jid* jid = jid_create(connection_get_fulljid()); Jid* jid = jid_create(connection_get_fulljid());
@ -193,6 +199,7 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t* const stanza, void* cons
} }
uint32_t device_id = strtoul(++device_id_str, NULL, 10); uint32_t device_id = strtoul(++device_id_str, NULL, 10);
log_debug("[OMEMO] omemo_start_device_session_handle_bundle: %d", device_id);
xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items, "item"); xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items, "item");
if (!item) { if (!item) {
@ -510,7 +517,7 @@ _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata)
const char* type = xmpp_stanza_get_type(stanza); const char* type = xmpp_stanza_get_type(stanza);
if (g_strcmp0(type, STANZA_TYPE_RESULT) == 0) { if (g_strcmp0(type, STANZA_TYPE_RESULT) == 0) {
log_info("[OMEMO] bundle published successfully"); log_debug("[OMEMO] bundle published successfully");
return 0; return 0;
} }
@ -519,12 +526,12 @@ _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata)
return 0; return 0;
} }
log_info("[OMEMO] cannot publish bundle with open access model, trying to configure node"); log_debug("[OMEMO] cannot publish bundle with open access model, trying to configure node");
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
Jid* jid = jid_create(connection_get_fulljid()); Jid* jid = jid_create(connection_get_fulljid());
char* id = connection_create_stanza_id(); char* id = connection_create_stanza_id();
char* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id()); char* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id());
log_info("[OMEMO] node: %s", node); log_debug("[OMEMO] node: %s", node);
xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, jid->barejid, node); xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, jid->barejid, node);
g_free(node); g_free(node);
@ -594,7 +601,7 @@ _omemo_bundle_publish_configure_result(xmpp_stanza_t* const stanza, void* const
return 0; return 0;
} }
log_info("[OMEMO] node configured"); log_debug("[OMEMO] node configured");
// Try to publish again // Try to publish again
omemo_bundle_publish(TRUE); omemo_bundle_publish(TRUE);