about summary refs log tree commit diff stats
path: root/src/omemo
diff options
context:
space:
mode:
Diffstat (limited to 'src/omemo')
-rw-r--r--src/omemo/omemo.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c
index 495842bf..8c7a1276 100644
--- a/src/omemo/omemo.c
+++ b/src/omemo/omemo.c
@@ -542,6 +542,34 @@ omemo_set_device_list(const char* const from, GList* device_list)
         }
     }
 
+    // OMEMO trustmode ToFu
+    if (g_strcmp0(prefs_get_string(PREF_OMEMO_TRUST_MODE), "firstusage") == 0) {
+        log_info("[OMEMO] Checking firstusage state for %s", jid->barejid);
+        GHashTable* trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, jid->barejid);
+        if (trusted) {
+            if (g_hash_table_size(trusted) > 0) {
+                log_info("[OMEMO] Found trusted device for %s - skip firstusage", jid->barejid);
+                return;
+            }
+        } else {
+            if (device_list) {
+                cons_show("OMEMO: No trusted devices found for %s", jid->barejid);
+                GList* device_id;
+                for (device_id = device_list; device_id != NULL; device_id = device_id->next) {
+                    GHashTable* known_identities = g_hash_table_lookup(omemo_ctx.known_devices, jid->barejid);
+                    if (known_identities) {
+                        GList* fp = NULL;
+                        for (fp = g_hash_table_get_keys(known_identities); fp != NULL; fp = fp->next) {
+                            if (device_id->data == g_hash_table_lookup(known_identities, fp->data)) {
+                                cons_show("OMEMO: Adding firstusage trust for %s device %d - Fingerprint %s", jid->barejid, device_id->data, omemo_format_fingerprint(fp->data));
+                                omemo_trust(jid->barejid, omemo_format_fingerprint(fp->data));
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
     jid_destroy(jid);
 }
 
@@ -622,6 +650,14 @@ omemo_start_device_session(const char* const jid, uint32_t device_id,
 
     gboolean trusted = is_trusted_identity(&address, (uint8_t*)identity_key_raw, identity_key_len, &omemo_ctx.identity_key_store);
 
+    if ((g_strcmp0(prefs_get_string(PREF_OMEMO_TRUST_MODE), "blind") == 0) && !trusted) {
+        char* fp = _omemo_fingerprint(identity_key, TRUE);
+        cons_show("Blind trust for %s device %d (%s)", jid, device_id, fp);
+        omemo_trust(jid, fp);
+        free(fp);
+        trusted = TRUE;
+    }
+
     if (!trusted) {
         goto out;
     }