Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/omemo/omemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,13 @@ omemo_sessions_keyfile(void)
return omemo_ctx.sessions.keyfile;
}

static gboolean omemo_sessions_keyfile_save_disable = FALSE;

void
omemo_sessions_keyfile_save(void)
{
if (omemo_sessions_keyfile_save_disable)
return;
save_keyfile(&omemo_ctx.sessions);
}

Expand Down Expand Up @@ -766,6 +770,8 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
unsigned char* key_tag = NULL;
size_t ciphertext_len, tag_len;

omemo_sessions_keyfile_save_disable = TRUE;

ciphertext_len = strlen(message);
ciphertext = malloc(ciphertext_len);
if (!ciphertext) {
Expand All @@ -775,8 +781,8 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
tag = gcry_malloc_secure(tag_len);
key_tag = gcry_malloc_secure(AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH);

key = gcry_random_bytes_secure(AES128_GCM_KEY_LENGTH, GCRY_VERY_STRONG_RANDOM);
iv = gcry_random_bytes_secure(AES128_GCM_IV_LENGTH, GCRY_VERY_STRONG_RANDOM);
key = gcry_random_bytes_secure(AES128_GCM_KEY_LENGTH + AES128_GCM_IV_LENGTH, GCRY_VERY_STRONG_RANDOM);
iv = key + AES128_GCM_KEY_LENGTH;

res = aes128gcm_encrypt(ciphertext, &ciphertext_len, tag, &tag_len, (const unsigned char* const)message, strlen(message), iv, key);
if (res != 0) {
Expand Down Expand Up @@ -983,10 +989,11 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
}

out:
omemo_sessions_keyfile_save_disable = FALSE;
omemo_sessions_keyfile_save();
g_list_free_full(keys, (GDestroyNotify)omemo_key_free);
free(ciphertext);
gcry_free(key);
gcry_free(iv);
gcry_free(tag);
gcry_free(key_tag);

Expand Down
14 changes: 10 additions & 4 deletions src/xmpp/iq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2668,8 +2668,10 @@ _iq_mam_request(ProfChatWin* win, GDateTime* startdate, GDateTime* enddate)
if (connection_supports(XMPP_FEATURE_MAM2) == FALSE) {
log_warning("Server doesn't advertise %s feature.", XMPP_FEATURE_MAM2);
cons_show_error("Server doesn't support MAM (%s).", XMPP_FEATURE_MAM2);
g_date_time_unref(startdate);
g_date_time_unref(enddate);
if (startdate)
g_date_time_unref(startdate);
if (enddate)
g_date_time_unref(enddate);
return;
}

Expand Down Expand Up @@ -2718,8 +2720,12 @@ void
iq_mam_request(ProfChatWin* win, GDateTime* enddate)
{
ProfMessage* last_msg = log_database_get_limits_info(win->barejid, TRUE);
GDateTime* startdate = g_date_time_ref(last_msg->timestamp);
message_free(last_msg);
GDateTime* startdate = NULL;
if (last_msg) {
if (last_msg->timestamp)
startdate = g_date_time_ref(last_msg->timestamp);
message_free(last_msg);
}

// Save request for later if disco items haven't been received yet
if (!received_disco_items) {
Expand Down
Loading