diff options
author | Samuel Hand <samuel.hand@openmailbox.org> | 2018-07-09 14:16:23 +0100 |
---|---|---|
committer | Samuel Hand <samuel.hand@openmailbox.org> | 2018-07-09 14:16:23 +0100 |
commit | acbc5710d083e69f887b0b5a15e48b7d10b48190 (patch) | |
tree | 60ee5229c936b5b0b82c162248554645e1798e8e /plugins/omemo/src | |
parent | f3c82094cd5d232226907f61f6d58402f99e10db (diff) | |
download | dino-acbc5710d083e69f887b0b5a15e48b7d10b48190.tar.gz dino-acbc5710d083e69f887b0b5a15e48b7d10b48190.zip |
Enable key management for own keys
Diffstat (limited to 'plugins/omemo/src')
-rw-r--r-- | plugins/omemo/src/account_settings_dialog.vala | 54 | ||||
-rw-r--r-- | plugins/omemo/src/account_settings_widget.vala | 2 | ||||
-rw-r--r-- | plugins/omemo/src/contact_details_dialog.vala | 44 | ||||
-rw-r--r-- | plugins/omemo/src/manager.vala | 9 |
4 files changed, 50 insertions, 59 deletions
diff --git a/plugins/omemo/src/account_settings_dialog.vala b/plugins/omemo/src/account_settings_dialog.vala deleted file mode 100644 index 76357dbb..00000000 --- a/plugins/omemo/src/account_settings_dialog.vala +++ /dev/null @@ -1,54 +0,0 @@ -using Gtk; -using Qlite; -using Dino.Entities; - -namespace Dino.Plugins.Omemo { - -[GtkTemplate (ui = "/im/dino/Dino/omemo/account_settings_dialog.ui")] -public class AccountSettingsDialog : Gtk.Dialog { - - private Plugin plugin; - private Account account; - private string fingerprint; - - [GtkChild] private Label own_fingerprint; - [GtkChild] private ListBox other_list; - - public AccountSettingsDialog(Plugin plugin, Account account) { - Object(use_header_bar : 1); - this.plugin = plugin; - this.account = account; - - string own_b64 = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.identity_key_public_base64]; - fingerprint = fingerprint_from_base64(own_b64); - own_fingerprint.set_markup(fingerprint_markup(fingerprint)); - - int own_id = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.device_id]; - - int i = 0; - foreach (Row row in plugin.db.identity_meta.with_address(account.id, account.bare_jid.to_string())) { - if (row[plugin.db.identity_meta.device_id] == own_id) continue; - if (i == 0) { - other_list.foreach((widget) => { widget.destroy(); }); - } - string? other_b64 = row[plugin.db.identity_meta.identity_key_public_base64]; - Label lbl = new Label(other_b64 != null ? fingerprint_markup(fingerprint_from_base64(other_b64)) : _("Unknown device (0x%.8x)").printf(row[plugin.db.identity_meta.device_id])) { use_markup = true, visible = true, margin = 8, selectable=true }; - if (row[plugin.db.identity_meta.now_active] && other_b64 != null) { - other_list.insert(lbl, 0); - } else { - lbl.sensitive = false; - other_list.insert(lbl, i); - } - i++; - } - } - - [GtkCallback] - public void copy_button_clicked() { - Clipboard.get_default(get_display()).set_text(fingerprint, fingerprint.length); - } - - -} - -} diff --git a/plugins/omemo/src/account_settings_widget.vala b/plugins/omemo/src/account_settings_widget.vala index 6db193fc..6148da56 100644 --- a/plugins/omemo/src/account_settings_widget.vala +++ b/plugins/omemo/src/account_settings_widget.vala @@ -27,7 +27,7 @@ public class AccountSettingWidget : Plugins.AccountSettingsWidget, Box { btn.valign = Align.CENTER; btn.clicked.connect(() => { activated(); - AccountSettingsDialog dialog = new AccountSettingsDialog(plugin, account); + ContactDetailsDialog dialog = new ContactDetailsDialog(plugin, account, account.bare_jid); dialog.set_transient_for((Window) get_toplevel()); dialog.present(); }); diff --git a/plugins/omemo/src/contact_details_dialog.vala b/plugins/omemo/src/contact_details_dialog.vala index aa1b2a5f..70bf1dd7 100644 --- a/plugins/omemo/src/contact_details_dialog.vala +++ b/plugins/omemo/src/contact_details_dialog.vala @@ -12,10 +12,15 @@ public class ContactDetailsDialog : Gtk.Dialog { private Plugin plugin; private Account account; private Jid jid; + private bool own = false; + private int own_id = 0; private Gee.List<Widget> toggles; [GtkChild] private Grid fingerprints; + [GtkChild] private Box own_fingerprint_label; + [GtkChild] private Frame own_fingerprint_container; + [GtkChild] private Grid own_fingerprint; [GtkChild] private Box fingerprints_prompt_label; [GtkChild] private Frame fingerprints_prompt_container; [GtkChild] private Grid fingerprints_prompt; @@ -33,10 +38,12 @@ public class ContactDetailsDialog : Gtk.Dialog { .with(plugin.db.identity_meta.device_id, "=", device[plugin.db.identity_meta.device_id]) .set(plugin.db.identity_meta.trust_level, trust_level).perform(); - if(!trust) { - plugin.app.stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).untrust_device(jid, device[plugin.db.identity_meta.device_id]); - } else { - plugin.app.stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).trust_device(jid, device[plugin.db.identity_meta.device_id]); + if (!own) { + if(!trust) { + plugin.app.stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).untrust_device(jid, device[plugin.db.identity_meta.device_id]); + } else { + plugin.app.stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).trust_device(jid, device[plugin.db.identity_meta.device_id]); + } } } @@ -65,11 +72,34 @@ public class ContactDetailsDialog : Gtk.Dialog { toggles = new ArrayList<Widget>(); + if(jid.equals(account.bare_jid)) { + own = true; + own_id = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.device_id]; + own_fingerprint_label.visible = true; + own_fingerprint_container.visible = true; + string own_b64 = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.identity_key_public_base64]; + string fingerprint = fingerprint_from_base64(own_b64); + Label lbl = new Label(fingerprint_markup(fingerprint)) + { use_markup=true, justify=Justification.RIGHT, visible=true, margin = 8, halign = Align.START }; + + Box box = new Box(Gtk.Orientation.HORIZONTAL, 0) { visible = true, valign = Align.CENTER, hexpand = true, margin = 8 }; + + Button copy = new Button() { visible = true, valign = Align.CENTER, halign = Align.END, hexpand = false }; + copy.image = new Image.from_icon_name("edit-copy-symbolic", IconSize.BUTTON); + copy.clicked.connect(() => {Clipboard.get_default(get_display()).set_text(fingerprint, fingerprint.length);}); + box.pack_start(lbl); + box.pack_end(copy); + own_fingerprint.attach(box, 0, 0); + } + int i = 0; foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).with(plugin.db.identity_meta.trust_level, "!=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).with(plugin.db.identity_meta.trust_level, "!=", Database.IdentityMetaTable.TrustLevel.VERIFIED)) { if (device[plugin.db.identity_meta.identity_key_public_base64] == null) { continue; } + if(own && device[plugin.db.identity_meta.device_id] == own_id) { + continue; + } add_fingerprint(device, i, (Database.IdentityMetaTable.TrustLevel) device[plugin.db.identity_meta.trust_level]); i++; @@ -81,6 +111,9 @@ public class ContactDetailsDialog : Gtk.Dialog { if (device[plugin.db.identity_meta.identity_key_public_base64] == null) { continue; } + if(own && device[plugin.db.identity_meta.device_id] == own_id) { + continue; + } string res = fingerprint_markup(fingerprint_from_base64(device[plugin.db.identity_meta.identity_key_public_base64])); Label lbl = new Label(res) @@ -143,6 +176,9 @@ public class ContactDetailsDialog : Gtk.Dialog { int k = 0; foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).without_null(plugin.db.identity_meta.identity_key_public_base64).with(plugin.db.identity_meta.trust_level, "=", Database.IdentityMetaTable.TrustLevel.VERIFIED)) { + if(own && device[plugin.db.identity_meta.device_id] == own_id) { + continue; + } string res = fingerprint_markup(fingerprint_from_base64(device[plugin.db.identity_meta.identity_key_public_base64])); Label lbl = new Label(res) { use_markup=true, justify=Justification.RIGHT, visible=true, margin = 8, halign = Align.START }; diff --git a/plugins/omemo/src/manager.vala b/plugins/omemo/src/manager.vala index e1f3ee56..2f641196 100644 --- a/plugins/omemo/src/manager.vala +++ b/plugins/omemo/src/manager.vala @@ -98,6 +98,15 @@ public class Manager : StreamInteractionModule, Object { return; } StreamModule module = (!)module_; + + foreach (Row row in db.identity_meta.with_address(conversation.account.id, conversation.account.bare_jid.to_string())){ + if(row[db.identity_meta.trust_level] == Database.IdentityMetaTable.TrustLevel.TRUSTED || row[db.identity_meta.trust_level] == Database.IdentityMetaTable.TrustLevel.VERIFIED){ + module.trust_device(conversation.account.bare_jid, row[db.identity_meta.device_id]); + } else { + module.untrust_device(conversation.account.bare_jid, row[db.identity_meta.device_id]); + } + } + EncryptState enc_state = module.encrypt(message_stanza, conversation.account.bare_jid); MessageState state; lock (message_states) { |