1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-07-21 18:24:14 -04:00

Automatically starts OMEMO if one identity is trusted

This commit is contained in:
Paul Fariello 2019-04-09 08:22:35 +03:20
parent 25eb138d0b
commit 0bc660400b
4 changed files with 86 additions and 12 deletions

View File

@ -2150,17 +2150,67 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args)
}
ui_focus_win((ProfWin*)chatwin);
#ifdef HAVE_OMEMO
#ifndef HAVE_LIBOTR
if (omemo_is_trusted_jid(barejid)) {
omemo_start_session(barejid);
chatwin->is_omemo = TRUE;
}
if (msg) {
cl_ev_send_msg(chatwin, msg, NULL);
} else {
#ifdef HAVE_LIBOTR
if (otr_is_secure(barejid)) {
chatwin_otr_secured(chatwin, otr_is_trusted(barejid));
}
#endif
}
return TRUE;
#endif
#endif
#ifdef HAVE_OMEMO
#ifdef HAVE_LIBOTR
if (omemo_is_trusted_jid(barejid) && otr_is_secure(barejid)) {
win_println(window, THEME_DEFAULT, '!', "Chat could be either OMEMO or OTR encrypted. Use '/omemo start %s' or '/otr start %s' to start a session.", usr, usr);
return TRUE;
} else if (omemo_is_trusted_jid(barejid)) {
omemo_start_session(barejid);
chatwin->is_omemo = TRUE;
}
if (msg) {
cl_ev_send_msg(chatwin, msg, NULL);
} else {
if (otr_is_secure(barejid)) {
chatwin_otr_secured(chatwin, otr_is_trusted(barejid));
}
}
return TRUE;
#endif
#endif
#ifndef HAVE_OMEMO
#ifdef HAVE_LIBOTR
if (msg) {
cl_ev_send_msg(chatwin, msg, NULL);
} else {
if (otr_is_secure(barejid)) {
chatwin_otr_secured(chatwin, otr_is_trusted(barejid));
}
}
return TRUE;
#endif
#endif
#ifndef HAVE_OMEMO
#ifndef HAVE_LIBOTR
if (msg) {
cl_ev_send_msg(chatwin, msg, NULL);
}
return TRUE;
#endif
#endif
}
}

View File

@ -909,6 +909,21 @@ omemo_known_device_identities(const char *const jid)
return g_hash_table_get_keys(known_identities);
}
gboolean
omemo_is_trusted_jid(const char *const jid)
{
GHashTable *trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, jid);
if (!trusted) {
return FALSE;
}
if (g_hash_table_size(trusted) > 0) {
return TRUE;
}
return FALSE;
}
gboolean
omemo_is_trusted_identity(const char *const jid, const char *const fingerprint)
{
@ -1262,6 +1277,13 @@ _load_trust(void)
if (groups) {
int i;
for (i = 0; groups[i] != NULL; i++) {
GHashTable *trusted;
trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, groups[i]);
if (!trusted) {
trusted = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
g_hash_table_insert(omemo_ctx.identity_key_store.trusted, strdup(groups[i]), trusted);
}
keys = g_key_file_get_keys(omemo_ctx.trust_keyfile, groups[i], NULL, NULL);
int j;
@ -1273,11 +1295,6 @@ _load_trust(void)
signal_buffer *buffer = signal_buffer_create(key, key_len);
g_free(key);
uint32_t device_id = strtoul(keys[j], NULL, 10);
GHashTable *trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, groups[i]);
if (!trusted) {
trusted = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
g_hash_table_insert(omemo_ctx.identity_key_store.trusted, strdup(groups[i]), trusted);
}
g_hash_table_insert(trusted, GINT_TO_POINTER(device_id), buffer);
}
g_strfreev(keys);
@ -1299,7 +1316,7 @@ _load_sessions(void)
device_store = g_hash_table_lookup(omemo_ctx.session_store, groups[i]);
if (!device_store) {
device_store = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
g_hash_table_insert(omemo_ctx.session_store, groups[i], device_store);
g_hash_table_insert(omemo_ctx.session_store, strdup(groups[i]), device_store);
}
char **keys = g_key_file_get_keys(omemo_ctx.sessions_keyfile, groups[i], NULL, NULL);

View File

@ -40,6 +40,7 @@ char *omemo_own_fingerprint(gboolean formatted);
void omemo_trust(const char *const jid, const char *const fingerprint);
void omemo_untrust(const char *const jid, const char *const fingerprint);
GList *omemo_known_device_identities(const char *const jid);
gboolean omemo_is_trusted_jid(const char *const jid);
gboolean omemo_is_trusted_identity(const char *const jid, const char *const fingerprint);
char *omemo_fingerprint_autocomplete(const char *const search_str, gboolean previous);
void omemo_fingerprint_autocomplete_reset(void);

View File

@ -21,6 +21,12 @@ omemo_format_fingerprint(const char *const fingerprint)
void omemo_generate_crypto_materials(ProfAccount *account) {}
gboolean
omemo_is_trusted_jid(const char *const jid)
{
return TRUE;
}
gboolean
omemo_is_trusted_identity(const char *const jid, const char *const fingerprint)
{