2018-06-11 06:11:04 +00:00
|
|
|
using Gtk;
|
|
|
|
using Xmpp;
|
|
|
|
using Gee;
|
|
|
|
using Qlite;
|
|
|
|
using Dino.Entities;
|
|
|
|
|
|
|
|
namespace Dino.Plugins.Omemo {
|
|
|
|
|
|
|
|
[GtkTemplate (ui = "/im/dino/Dino/omemo/contact_details_dialog.ui")]
|
|
|
|
public class ContactDetailsDialog : Gtk.Dialog {
|
|
|
|
|
|
|
|
private Plugin plugin;
|
|
|
|
private Account account;
|
|
|
|
private Jid jid;
|
2018-07-09 13:16:23 +00:00
|
|
|
private bool own = false;
|
|
|
|
private int own_id = 0;
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
[GtkChild] private Box own_fingerprint_container;
|
|
|
|
[GtkChild] private Label own_fingerprint;
|
|
|
|
[GtkChild] private Box new_keys_container;
|
|
|
|
[GtkChild] private ListBox new_keys;
|
|
|
|
[GtkChild] private Box keys_container;
|
|
|
|
[GtkChild] private ListBox keys;
|
|
|
|
[GtkChild] private Switch auto_accept;
|
|
|
|
[GtkChild] private Button copy;
|
2018-06-11 06:11:04 +00:00
|
|
|
|
|
|
|
private void set_device_trust(Row device, bool trust) {
|
2018-06-19 10:26:31 +00:00
|
|
|
Database.IdentityMetaTable.TrustLevel trust_level = trust ? Database.IdentityMetaTable.TrustLevel.TRUSTED : Database.IdentityMetaTable.TrustLevel.UNTRUSTED;
|
2018-06-11 06:11:04 +00:00
|
|
|
plugin.db.identity_meta.update()
|
|
|
|
.with(plugin.db.identity_meta.identity_id, "=", account.id)
|
|
|
|
.with(plugin.db.identity_meta.address_name, "=", device[plugin.db.identity_meta.address_name])
|
|
|
|
.with(plugin.db.identity_meta.device_id, "=", device[plugin.db.identity_meta.device_id])
|
2018-07-06 19:14:51 +00:00
|
|
|
.set(plugin.db.identity_meta.trust_level, trust_level).perform();
|
2018-06-11 06:11:04 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
private void add_fingerprint(Row device, Database.IdentityMetaTable.TrustLevel trust) {
|
|
|
|
keys_container.visible = true;
|
|
|
|
|
|
|
|
ListBoxRow lbr = new ListBoxRow() { visible = true, activatable = true, hexpand = true };
|
|
|
|
Box box = new Box(Gtk.Orientation.HORIZONTAL, 40) { visible = true, margin_start = 20, margin_end = 20, margin_top = 14, margin_bottom = 14, hexpand = true };
|
|
|
|
|
|
|
|
Box status = new Box(Gtk.Orientation.HORIZONTAL, 5) { visible = true, hexpand = true };
|
|
|
|
Label status_lbl = new Label(null) { visible = true, hexpand = true, xalign = 0 };
|
|
|
|
|
|
|
|
Image img = new Image() { visible = true, halign = Align.END, icon_size = IconSize.BUTTON };
|
|
|
|
|
2018-06-11 06:11:04 +00:00
|
|
|
string res = fingerprint_markup(fingerprint_from_base64(device[plugin.db.identity_meta.identity_key_public_base64]));
|
|
|
|
Label lbl = new Label(res)
|
2018-08-03 18:07:23 +00:00
|
|
|
{ use_markup=true, justify=Justification.RIGHT, visible=true, halign = Align.START, valign = Align.CENTER, hexpand = false };
|
|
|
|
|
|
|
|
switch(trust) {
|
|
|
|
case Database.IdentityMetaTable.TrustLevel.TRUSTED:
|
|
|
|
img.icon_name = "emblem-ok-symbolic";
|
|
|
|
status_lbl.set_markup("<span size='large' color='#1A63D9'>Accepted</span>");
|
|
|
|
break;
|
|
|
|
case Database.IdentityMetaTable.TrustLevel.UNTRUSTED:
|
|
|
|
img.icon_name = "action-unavailable-symbolic";
|
|
|
|
status_lbl.set_markup("<span size='large' color='#D91900'>Rejected</span>");
|
|
|
|
lbl.get_style_context().add_class("dim-label");
|
|
|
|
break;
|
|
|
|
case Database.IdentityMetaTable.TrustLevel.VERIFIED:
|
|
|
|
img.icon_name = "security-high-symbolic";
|
|
|
|
status_lbl.set_markup("<span size='large' color='#1A63D9'>Verified</span>");
|
|
|
|
break;
|
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
if (!device[plugin.db.identity_meta.now_active]) {
|
|
|
|
img.icon_name= "appointment-missed-symbolic";
|
|
|
|
status_lbl.set_markup("<span size='large' color='#8b8e8f'>Unused</span>");
|
|
|
|
}
|
|
|
|
|
|
|
|
box.add(lbl);
|
|
|
|
box.add(status);
|
|
|
|
|
|
|
|
status.add(status_lbl);
|
|
|
|
status.add(img);
|
|
|
|
|
|
|
|
lbr.add(box);
|
|
|
|
keys.add(lbr);
|
|
|
|
|
|
|
|
keys.row_activated.connect((row) => {
|
|
|
|
if(row == lbr) {
|
|
|
|
Row updated_device = plugin.db.identity_meta.with_address(device[plugin.db.identity_meta.identity_id], device[plugin.db.identity_meta.address_name]).with(plugin.db.identity_meta.device_id, "=", device[plugin.db.identity_meta.device_id]).single().row().inner;
|
|
|
|
ManageKeyDialog manage_dialog = new ManageKeyDialog(updated_device, plugin.db);
|
|
|
|
manage_dialog.set_transient_for((Window) get_toplevel());
|
|
|
|
manage_dialog.present();
|
|
|
|
manage_dialog.response.connect((response) => update_row(response, img, lbl, status_lbl, device));
|
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
});
|
2018-08-03 18:07:23 +00:00
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
private void update_row(int response, Image img, Label lbl, Label status_lbl, Row device){
|
|
|
|
switch (response) {
|
|
|
|
case Database.IdentityMetaTable.TrustLevel.TRUSTED:
|
|
|
|
img.icon_name = "emblem-ok-symbolic";
|
|
|
|
status_lbl.set_markup("<span size='large' color='#1A63D9'>Accepted</span>");
|
|
|
|
lbl.get_style_context().remove_class("dim-label");
|
|
|
|
set_device_trust(device, true);
|
|
|
|
break;
|
|
|
|
case Database.IdentityMetaTable.TrustLevel.UNTRUSTED:
|
|
|
|
img.icon_name = "action-unavailable-symbolic";
|
|
|
|
status_lbl.set_markup("<span size='large' color='#D91900'>Rejected</span>");
|
|
|
|
lbl.get_style_context().add_class("dim-label");
|
|
|
|
set_device_trust(device, false);
|
|
|
|
break;
|
|
|
|
case Database.IdentityMetaTable.TrustLevel.VERIFIED:
|
|
|
|
img.icon_name = "security-high-symbolic";
|
|
|
|
status_lbl.set_markup("<span size='large' color='#1A63D9'>Verified</span>");
|
|
|
|
lbl.get_style_context().remove_class("dim-label");
|
|
|
|
plugin.db.identity_meta.update()
|
|
|
|
.with(plugin.db.identity_meta.identity_id, "=", account.id)
|
|
|
|
.with(plugin.db.identity_meta.address_name, "=", device[plugin.db.identity_meta.address_name])
|
|
|
|
.with(plugin.db.identity_meta.device_id, "=", device[plugin.db.identity_meta.device_id])
|
|
|
|
.set(plugin.db.identity_meta.trust_level, Database.IdentityMetaTable.TrustLevel.VERIFIED).perform();
|
|
|
|
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, false).perform();
|
|
|
|
auto_accept.set_active(false);
|
|
|
|
break;
|
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
private void add_new_fingerprint(Row device){
|
|
|
|
new_keys_container.visible = true;
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
ListBoxRow lbr = new ListBoxRow() { visible = true, activatable = false, hexpand = true };
|
|
|
|
Box box = new Box(Gtk.Orientation.HORIZONTAL, 40) { visible = true, margin_start = 20, margin_end = 20, margin_top = 14, margin_bottom = 14, hexpand = true };
|
2018-07-04 20:26:14 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
Box control = new Box(Gtk.Orientation.HORIZONTAL, 0) { visible = true, hexpand = true };
|
2018-07-09 13:16:23 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
Button yes = new Button() { visible = true, valign = Align.CENTER, hexpand = true };
|
|
|
|
yes.image = new Image.from_icon_name("emblem-ok-symbolic", IconSize.BUTTON);
|
|
|
|
yes.get_style_context().add_class("suggested-action");
|
2018-07-09 13:16:23 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
Button no = new Button() { visible = true, valign = Align.CENTER, hexpand = true };
|
|
|
|
no.image = new Image.from_icon_name("action-unavailable-symbolic", IconSize.BUTTON);
|
|
|
|
no.get_style_context().add_class("destructive-action");
|
2018-07-09 13:16:23 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
yes.clicked.connect(() => {
|
|
|
|
set_device_trust(device, true);
|
|
|
|
add_fingerprint(device, Database.IdentityMetaTable.TrustLevel.TRUSTED);
|
|
|
|
new_keys.remove(lbr);
|
|
|
|
if (new_keys.get_children().length() < 1) new_keys_container.visible = false;
|
|
|
|
});
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
no.clicked.connect(() => {
|
|
|
|
set_device_trust(device, false);
|
|
|
|
add_fingerprint(device, Database.IdentityMetaTable.TrustLevel.UNTRUSTED);
|
|
|
|
new_keys.remove(lbr);
|
|
|
|
if (new_keys.get_children().length() < 1) new_keys_container.visible = false;
|
|
|
|
});
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
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, halign = Align.START, valign = Align.CENTER, hexpand = false };
|
2018-06-11 06:11:04 +00:00
|
|
|
|
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
box.add(lbl);
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
control.add(yes);
|
|
|
|
control.add(no);
|
|
|
|
control.get_style_context().add_class("linked");
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
box.add(control);
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
lbr.add(box);
|
|
|
|
new_keys.add(lbr);
|
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
public ContactDetailsDialog(Plugin plugin, Account account, Jid jid) {
|
|
|
|
Object(use_header_bar : 1);
|
|
|
|
this.plugin = plugin;
|
|
|
|
this.account = account;
|
|
|
|
this.jid = jid;
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
(get_header_bar() as HeaderBar).set_subtitle(jid.bare_jid.to_string());
|
2018-06-11 06:11:04 +00:00
|
|
|
|
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
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];
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
own_fingerprint_container.visible = true;
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
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);
|
|
|
|
own_fingerprint.set_markup(fingerprint_markup(fingerprint));
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
copy.clicked.connect(() => {Clipboard.get_default(get_display()).set_text(fingerprint, fingerprint.length);});
|
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
new_keys.set_header_func((row, before_row) => {
|
|
|
|
if (row.get_header() == null && before_row != null) {
|
|
|
|
row.set_header(new Separator(Orientation.HORIZONTAL));
|
|
|
|
}
|
|
|
|
});
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
keys.set_header_func((row, before_row) => {
|
|
|
|
if (row.get_header() == null && before_row != null) {
|
|
|
|
row.set_header(new Separator(Orientation.HORIZONTAL));
|
|
|
|
}
|
|
|
|
});
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
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).without_null(plugin.db.identity_meta.identity_key_public_base64)) {
|
|
|
|
add_new_fingerprint(device);
|
2018-06-11 06:11:04 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
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).without_null(plugin.db.identity_meta.identity_key_public_base64)) {
|
2018-07-09 13:16:23 +00:00
|
|
|
if(own && device[plugin.db.identity_meta.device_id] == own_id) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-03 18:07:23 +00:00
|
|
|
add_fingerprint(device, (Database.IdentityMetaTable.TrustLevel) device[plugin.db.identity_meta.trust_level]);
|
2018-06-19 10:52:00 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
}
|
2018-06-19 10:52:00 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
auto_accept.set_active(plugin.db.trust.get_blind_trust(account.id, jid.bare_jid.to_string()));
|
2018-06-19 10:52:00 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
auto_accept.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();
|
2018-06-19 10:52:00 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
if (active) {
|
|
|
|
new_keys_container.visible = false;
|
2018-06-19 10:52:00 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
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).without_null(plugin.db.identity_meta.identity_key_public_base64)) {
|
|
|
|
set_device_trust(device, true);
|
|
|
|
add_fingerprint(device, Database.IdentityMetaTable.TrustLevel.TRUSTED);
|
2018-06-19 10:52:00 +00:00
|
|
|
}
|
2018-07-04 20:26:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2018-06-11 06:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|