aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Hand <samuel.hand@openmailbox.org>2018-07-09 14:16:23 +0100
committerSamuel Hand <samuel.hand@openmailbox.org>2018-07-09 14:16:23 +0100
commitacbc5710d083e69f887b0b5a15e48b7d10b48190 (patch)
tree60ee5229c936b5b0b82c162248554645e1798e8e
parentf3c82094cd5d232226907f61f6d58402f99e10db (diff)
downloaddino-acbc5710d083e69f887b0b5a15e48b7d10b48190.tar.gz
dino-acbc5710d083e69f887b0b5a15e48b7d10b48190.zip
Enable key management for own keys
-rw-r--r--plugins/omemo/CMakeLists.txt2
-rw-r--r--plugins/omemo/data/account_settings_dialog.ui124
-rw-r--r--plugins/omemo/data/contact_details_dialog.ui40
-rw-r--r--plugins/omemo/src/account_settings_dialog.vala54
-rw-r--r--plugins/omemo/src/account_settings_widget.vala2
-rw-r--r--plugins/omemo/src/contact_details_dialog.vala44
-rw-r--r--plugins/omemo/src/manager.vala9
7 files changed, 90 insertions, 185 deletions
diff --git a/plugins/omemo/CMakeLists.txt b/plugins/omemo/CMakeLists.txt
index bcec941b..1c049588 100644
--- a/plugins/omemo/CMakeLists.txt
+++ b/plugins/omemo/CMakeLists.txt
@@ -12,7 +12,6 @@ find_packages(OMEMO_PACKAGES REQUIRED
)
set(RESOURCE_LIST
- account_settings_dialog.ui
contact_details_dialog.ui
)
@@ -28,7 +27,6 @@ compile_gresources(
vala_precompile(OMEMO_VALA_C
SOURCES
- src/account_settings_dialog.vala
src/account_settings_entry.vala
src/account_settings_widget.vala
src/bundle.vala
diff --git a/plugins/omemo/data/account_settings_dialog.ui b/plugins/omemo/data/account_settings_dialog.ui
deleted file mode 100644
index 31996d05..00000000
--- a/plugins/omemo/data/account_settings_dialog.ui
+++ /dev/null
@@ -1,124 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<interface>
- <template class="DinoPluginsOmemoAccountSettingsDialog">
- <property name="modal">True</property>
- <property name="title" translatable="yes">OMEMO Keys</property>
- <child internal-child="vbox">
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="margin-left">40</property>
- <property name="margin-right">40</property>
- <child>
- <object class="GtkBox">
- <property name="margin-top">12</property>
- <property name="orientation">horizontal</property>
- <property name="visible">True</property>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Own fingerprint</property>
- <property name="xalign">0</property>
- <property name="yalign">1</property>
- <property name="hexpand">True</property>
- <property name="margin-bottom">2</property>
- <attributes>
- <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
- </attributes>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="copy_button">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <style>
- <class name="flat"/>
- </style>
- <signal name="clicked" handler="copy_button_clicked"/>
- <child>
- <object class="GtkImage">
- <property name="icon-name">edit-copy-symbolic</property>
- <property name="icon-size">1</property>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
- <!--<child>
- <object class="GtkButton" id="qr_button">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="sensitive">False</property>
- <style>
- <class name="flat"/>
- </style>
- <child>
- <object class="GtkImage">
- <property name="icon-name">camera-photo-symbolic</property>
- <property name="icon-size">1</property>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>-->
- </object>
- </child>
- <child>
- <object class="GtkFrame">
- <property name="visible">True</property>
- <child>
- <object class="GtkListBox">
- <property name="visible">True</property>
- <property name="selection-mode">none</property>
- <child>
- <object class="GtkLabel" id="own_fingerprint">
- <property name="visible">True</property>
- <property name="margin">8</property>
- <property name="label">...</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkLabel">
- <property name="margin-top">12</property>
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Other devices</property>
- <property name="margin-bottom">2</property>
- <attributes>
- <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
- </attributes>
- </object>
- </child>
- <child>
- <object class="GtkFrame">
- <property name="visible">True</property>
- <property name="margin-bottom">18</property>
- <child>
- <object class="GtkScrolledWindow">
- <property name="hscrollbar_policy">never</property>
- <property name="vscrollbar_policy">never</property>
- <property name="visible">True</property>
- <child>
- <object class="GtkListBox" id="other_list">
- <property name="visible">True</property>
- <property name="selection-mode">none</property>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="margin">8</property>
- <property name="label" translatable="yes">- None -</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- </template>
-</interface> \ No newline at end of file
diff --git a/plugins/omemo/data/contact_details_dialog.ui b/plugins/omemo/data/contact_details_dialog.ui
index 4844fdb9..4dadbb6a 100644
--- a/plugins/omemo/data/contact_details_dialog.ui
+++ b/plugins/omemo/data/contact_details_dialog.ui
@@ -10,6 +10,46 @@
<property name="margin-left">40</property>
<property name="margin-right">40</property>
<child>
+ <object class="GtkBox" id="own_fingerprint_label">
+ <property name="margin-top">12</property>
+ <property name="orientation">horizontal</property>
+ <property name="visible">False</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Own fingerprint</property>
+ <property name="xalign">0</property>
+ <property name="yalign">1</property>
+ <property name="hexpand">True</property>
+ <property name="margin-bottom">2</property>
+ <attributes>
+ <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkFrame" id="own_fingerprint_container">
+ <property name="visible">False</property>
+ <property name="margin-bottom">18</property>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="hscrollbar_policy">never</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <property name="visible">True</property>
+ <property name="propagate_natural_height">True</property>
+ <child>
+ <object class="GtkGrid" id="own_fingerprint">
+ <property name="visible">True</property>
+ <property name="vexpand">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
<object class="GtkBox">
<property name="margin-top">12</property>
<property name="orientation">horizontal</property>
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) {