From 20fe944c2d2ef790e93abd6f36e10489802465ab Mon Sep 17 00:00:00 2001 From: Samuel Hand Date: Wed, 4 Jul 2018 21:26:14 +0100 Subject: [PATCH] Add a toggle switch for key management --- plugins/omemo/data/contact_details_dialog.ui | 26 ++++++++++++++++-- plugins/omemo/src/contact_details_dialog.vala | 27 +++++++++++++++++++ plugins/omemo/src/manager.vala | 1 - 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/plugins/omemo/data/contact_details_dialog.ui b/plugins/omemo/data/contact_details_dialog.ui index ceac2179..4844fdb9 100644 --- a/plugins/omemo/data/contact_details_dialog.ui +++ b/plugins/omemo/data/contact_details_dialog.ui @@ -9,6 +9,27 @@ True 40 40 + + + 12 + horizontal + True + + + True + start + True + Enable Key Management + + + + + True + end + + + + 12 @@ -107,7 +128,8 @@ - + + diff --git a/plugins/omemo/src/contact_details_dialog.vala b/plugins/omemo/src/contact_details_dialog.vala index 6bf2c83e..af0d165b 100644 --- a/plugins/omemo/src/contact_details_dialog.vala +++ b/plugins/omemo/src/contact_details_dialog.vala @@ -13,6 +13,8 @@ public class ContactDetailsDialog : Gtk.Dialog { private Account account; private Jid jid; + private Gee.List toggles; + [GtkChild] private Grid fingerprints; [GtkChild] private Box fingerprints_prompt_label; [GtkChild] private Frame fingerprints_prompt_container; @@ -20,6 +22,7 @@ public class ContactDetailsDialog : Gtk.Dialog { [GtkChild] private Box fingerprints_verified_label; [GtkChild] private Frame fingerprints_verified_container; [GtkChild] private Grid fingerprints_verified; + [GtkChild] private Switch key_mgmnt; private void set_device_trust(Row device, bool trust) { @@ -48,6 +51,7 @@ public class ContactDetailsDialog : Gtk.Dialog { return false; }); + toggles.add(tgl); fingerprints.attach(lbl, 0, row); fingerprints.attach(tgl, 1, row); @@ -59,6 +63,8 @@ public class ContactDetailsDialog : Gtk.Dialog { this.account = account; this.jid = jid; + toggles = new ArrayList(); + int i = 0; foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).with(plugin.db.identity_meta.trusted_identity, "!=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).with(plugin.db.identity_meta.trusted_identity, "!=", Database.IdentityMetaTable.TrustLevel.VERIFIED)) { if (device[plugin.db.identity_meta.identity_key_public_base64] == null) { @@ -90,6 +96,7 @@ public class ContactDetailsDialog : Gtk.Dialog { fingerprints_prompt.remove(box); fingerprints_prompt.remove(lbl); + toggles.remove(box); j--; add_fingerprint(device, i, Database.IdentityMetaTable.TrustLevel.TRUSTED); @@ -108,6 +115,7 @@ public class ContactDetailsDialog : Gtk.Dialog { fingerprints_prompt.remove(box); fingerprints_prompt.remove(lbl); + toggles.remove(box); j--; add_fingerprint(device, i, Database.IdentityMetaTable.TrustLevel.UNTRUSTED); @@ -122,6 +130,7 @@ public class ContactDetailsDialog : Gtk.Dialog { box.pack_start(no); box.get_style_context().add_class("linked"); + toggles.add(box); fingerprints_prompt.attach(lbl, 0, j); fingerprints_prompt.attach(box, 1, j); @@ -148,6 +157,7 @@ public class ContactDetailsDialog : Gtk.Dialog { fingerprints_verified.remove(no); fingerprints_verified.remove(lbl); + toggles.remove(no); k--; add_fingerprint(device, i, Database.IdentityMetaTable.TrustLevel.UNTRUSTED); @@ -159,6 +169,7 @@ public class ContactDetailsDialog : Gtk.Dialog { }); box.pack_end(no); + toggles.add(no); fingerprints_verified.attach(lbl, 0, k); fingerprints_verified.attach(box, 1, k); @@ -169,6 +180,22 @@ public class ContactDetailsDialog : Gtk.Dialog { fingerprints_verified_label.visible = true; fingerprints_verified_container.visible = true; } + + bool blind_trust = plugin.db.trust.get_blind_trust(account.id, jid.bare_jid.to_string()); + key_mgmnt.set_active(!blind_trust); + foreach(Widget tgl in toggles){ + tgl.set_sensitive(!blind_trust); + } + + key_mgmnt.state_set.connect((active) => { + plugin.db.trust.update().with(plugin.db.trust.identity_id, "=", account.id).with(plugin.db.trust.address_name, "=", jid.bare_jid.to_string()).set(plugin.db.trust.blind_trust, !active).perform(); + foreach(Widget tgl in toggles){ + tgl.set_sensitive(active); + } + + return false; + }); + } } diff --git a/plugins/omemo/src/manager.vala b/plugins/omemo/src/manager.vala index 938c8631..dffe9fc2 100644 --- a/plugins/omemo/src/manager.vala +++ b/plugins/omemo/src/manager.vala @@ -218,7 +218,6 @@ public class Manager : StreamInteractionModule, Object { if(module == null) return; HashSet send_now = new HashSet(); - bool session_needed = false; lock (message_states) { foreach (Entities.Message msg in message_states.keys) { bool session_created = true;