1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Merge pull request #1054 from paulfariello/hotfix/omemo_disconnect_while_not_loaded

Don't touch OMEMO cryto keys on disconnect if OMEMO wasn't loaded
This commit is contained in:
Michael Vetter 2019-04-15 10:42:40 +02:00 committed by GitHub
commit a22ddb3306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,7 @@ static gboolean loaded;
static void _generate_pre_keys(int count); static void _generate_pre_keys(int count);
static void _generate_signed_pre_key(void); static void _generate_signed_pre_key(void);
static void _load_identity(void); static gboolean _load_identity(void);
static void _load_trust(void); static void _load_trust(void);
static void _load_sessions(void); static void _load_sessions(void);
static void _lock(void *user_data); static void _lock(void *user_data);
@ -217,7 +217,9 @@ omemo_on_connect(ProfAccount *account)
omemo_ctx.sessions_keyfile = g_key_file_new(); omemo_ctx.sessions_keyfile = g_key_file_new();
if (g_key_file_load_from_file(omemo_ctx.identity_keyfile, omemo_ctx.identity_filename->str, G_KEY_FILE_KEEP_COMMENTS, &error)) { if (g_key_file_load_from_file(omemo_ctx.identity_keyfile, omemo_ctx.identity_filename->str, G_KEY_FILE_KEEP_COMMENTS, &error)) {
_load_identity(); if (!_load_identity()) {
return;
}
} else if (error->code != G_FILE_ERROR_NOENT) { } else if (error->code != G_FILE_ERROR_NOENT) {
log_warning("OMEMO: error loading identity from: %s, %s", omemo_ctx.identity_filename->str, error->message); log_warning("OMEMO: error loading identity from: %s, %s", omemo_ctx.identity_filename->str, error->message);
return; return;
@ -241,17 +243,11 @@ omemo_on_connect(ProfAccount *account)
void void
omemo_on_disconnect(void) omemo_on_disconnect(void)
{ {
signal_protocol_signed_pre_key_remove_key(omemo_ctx.store, omemo_ctx.signed_pre_key_id); if (!loaded) {
_g_hash_table_free(omemo_ctx.signed_pre_key_store); return;
GHashTableIter iter;
gpointer id;
g_hash_table_iter_init(&iter, omemo_ctx.pre_key_store);
while (g_hash_table_iter_next(&iter, &id, NULL)) {
signal_protocol_pre_key_remove_key(omemo_ctx.store, GPOINTER_TO_INT(id));
} }
_g_hash_table_free(omemo_ctx.signed_pre_key_store);
_g_hash_table_free(omemo_ctx.pre_key_store); _g_hash_table_free(omemo_ctx.pre_key_store);
g_string_free(omemo_ctx.identity_filename, TRUE); g_string_free(omemo_ctx.identity_filename, TRUE);
@ -1201,26 +1197,49 @@ omemo_fingerprint_autocomplete_reset(void)
autocomplete_reset(omemo_ctx.fingerprint_ac); autocomplete_reset(omemo_ctx.fingerprint_ac);
} }
static void static gboolean
_load_identity(void) _load_identity(void)
{ {
GError *error = NULL;
log_info("Loading OMEMO identity"); log_info("Loading OMEMO identity");
/* Device ID */ /* Device ID */
omemo_ctx.device_id = g_key_file_get_uint64(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_DEVICE_ID, NULL); error = NULL;
omemo_ctx.device_id = g_key_file_get_uint64(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_DEVICE_ID, &error);
if (error != NULL) {
log_error("OMEMO: cannot load device id: %s", error->message);
return FALSE;
}
log_info("OMEMO: device id: %d", omemo_ctx.device_id); log_info("OMEMO: device id: %d", omemo_ctx.device_id);
/* Registration ID */ /* Registration ID */
omemo_ctx.registration_id = g_key_file_get_uint64(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_REGISTRATION_ID, NULL); error = NULL;
omemo_ctx.registration_id = g_key_file_get_uint64(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_REGISTRATION_ID, &error);
if (error != NULL) {
log_error("OMEMO: cannot load registration id: %s", error->message);
return FALSE;
}
/* Identity key */ /* Identity key */
char *identity_key_public_b64 = g_key_file_get_string(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_IDENTITY_KEY_PUBLIC, NULL); error = NULL;
char *identity_key_public_b64 = g_key_file_get_string(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_IDENTITY_KEY_PUBLIC, &error);
if (!identity_key_public_b64) {
log_error("OMEMO: cannot load identity public key: %s", error->message);
return FALSE;
}
size_t identity_key_public_len; size_t identity_key_public_len;
unsigned char *identity_key_public = g_base64_decode(identity_key_public_b64, &identity_key_public_len); unsigned char *identity_key_public = g_base64_decode(identity_key_public_b64, &identity_key_public_len);
g_free(identity_key_public_b64); g_free(identity_key_public_b64);
omemo_ctx.identity_key_store.public = signal_buffer_create(identity_key_public, identity_key_public_len); omemo_ctx.identity_key_store.public = signal_buffer_create(identity_key_public, identity_key_public_len);
char *identity_key_private_b64 = g_key_file_get_string(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_IDENTITY_KEY_PRIVATE, NULL); error = NULL;
char *identity_key_private_b64 = g_key_file_get_string(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_IDENTITY_KEY_PRIVATE, &error);
if (!identity_key_private_b64) {
log_error("OMEMO: cannot load identity private key: %s", error->message);
return FALSE;
}
size_t identity_key_private_len; size_t identity_key_private_len;
unsigned char *identity_key_private = g_base64_decode(identity_key_private_b64, &identity_key_private_len); unsigned char *identity_key_private = g_base64_decode(identity_key_private_b64, &identity_key_private_len);
g_free(identity_key_private_b64); g_free(identity_key_private_b64);
@ -1284,6 +1303,8 @@ _load_identity(void)
omemo_identity_keyfile_save(); omemo_identity_keyfile_save();
omemo_start_sessions(); omemo_start_sessions();
return TRUE;
} }
static void static void