2018-06-11 06:11:04 +00:00
|
|
|
using Gtk;
|
|
|
|
using Xmpp;
|
|
|
|
using Gee;
|
|
|
|
using Qlite;
|
|
|
|
using Dino.Entities;
|
2018-08-08 20:57:24 +00:00
|
|
|
using Qrencode;
|
|
|
|
using Gdk;
|
2018-06-11 06:11:04 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-10-09 21:32:03 +00:00
|
|
|
[GtkChild] private Label automatically_accept_new_label;
|
2018-11-10 16:24:48 +00:00
|
|
|
[GtkChild] private Label automatically_accept_new_descr;
|
2019-10-09 21:32:03 +00:00
|
|
|
[GtkChild] private Label own_key_label;
|
|
|
|
[GtkChild] private Label new_keys_label;
|
|
|
|
[GtkChild] private Label associated_keys_label;
|
2018-08-03 18:07:23 +00:00
|
|
|
[GtkChild] private Box own_fingerprint_container;
|
2018-08-09 23:45:22 +00:00
|
|
|
[GtkChild] private Label own_fingerprint_label;
|
2018-08-03 18:07:23 +00:00
|
|
|
[GtkChild] private Box new_keys_container;
|
2018-08-09 23:45:22 +00:00
|
|
|
[GtkChild] private ListBox new_keys_listbox;
|
2018-08-03 18:07:23 +00:00
|
|
|
[GtkChild] private Box keys_container;
|
2018-08-09 23:45:22 +00:00
|
|
|
[GtkChild] private ListBox keys_listbox;
|
|
|
|
[GtkChild] private Switch auto_accept_switch;
|
|
|
|
[GtkChild] private Button copy_button;
|
|
|
|
[GtkChild] private Button show_qrcode_button;
|
|
|
|
[GtkChild] private Image qrcode_image;
|
2018-08-08 20:57:24 +00:00
|
|
|
[GtkChild] private Popover qrcode_popover;
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2019-10-09 21:32:03 +00:00
|
|
|
construct {
|
|
|
|
// If we set the strings in the .ui file, they don't get translated
|
|
|
|
title = _("OMEMO Key Management");
|
|
|
|
automatically_accept_new_label.label = _("Automatically accept new keys");
|
|
|
|
automatically_accept_new_descr.label = _("When this contact adds new encryption keys to their account, automatically accept them.");
|
|
|
|
own_key_label.label = _("Own key");
|
|
|
|
new_keys_label.label = _("New keys");
|
|
|
|
associated_keys_label.label = _("Associated keys");
|
|
|
|
}
|
|
|
|
|
2018-08-09 14:29:15 +00:00
|
|
|
public ContactDetailsDialog(Plugin plugin, Account account, Jid jid) {
|
2019-02-20 22:08:30 +00:00
|
|
|
Object(use_header_bar : Environment.get_variable("GTK_CSD") != "0" ? 1 : 0);
|
2018-08-09 14:29:15 +00:00
|
|
|
this.plugin = plugin;
|
|
|
|
this.account = account;
|
|
|
|
this.jid = jid;
|
|
|
|
|
2019-02-20 22:08:30 +00:00
|
|
|
if (Environment.get_variable("GTK_CSD") != "0") {
|
|
|
|
(get_header_bar() as HeaderBar).set_subtitle(jid.bare_jid.to_string());
|
|
|
|
}
|
2018-08-09 14:29:15 +00:00
|
|
|
|
2018-08-12 10:04:40 +00:00
|
|
|
int identity_id = plugin.db.identity.get_id(account.id);
|
|
|
|
if (identity_id < 0) return;
|
2018-08-09 14:29:15 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
// Dialog opened from the account settings menu
|
|
|
|
// Show the fingerprint for this device separately with buttons for a qrcode and to copy
|
2018-08-09 14:29:15 +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-11-10 16:24:48 +00:00
|
|
|
automatically_accept_new_descr.label = _("When you add new encryption keys to your account, automatically accept them.");
|
|
|
|
|
2018-08-09 14:29:15 +00:00
|
|
|
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);
|
2018-08-09 23:45:22 +00:00
|
|
|
own_fingerprint_label.set_markup(fingerprint_markup(fingerprint));
|
2018-08-09 14:29:15 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
copy_button.clicked.connect(() => {Clipboard.get_default(get_display()).set_text(fingerprint, fingerprint.length);});
|
2018-08-09 14:29:15 +00:00
|
|
|
|
|
|
|
int sid = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.device_id];
|
2018-11-11 19:30:07 +00:00
|
|
|
Pixbuf qr_pixbuf = new QRcode(@"xmpp:$(account.bare_jid)?omemo-sid-$(sid)=$(fingerprint)", 2).to_pixbuf();
|
|
|
|
qr_pixbuf = qr_pixbuf.scale_simple(150, 150, InterpType.NEAREST);
|
|
|
|
|
|
|
|
Pixbuf pixbuf = new Pixbuf(
|
|
|
|
qr_pixbuf.colorspace,
|
|
|
|
qr_pixbuf.has_alpha,
|
|
|
|
qr_pixbuf.bits_per_sample,
|
|
|
|
170,
|
|
|
|
170
|
|
|
|
);
|
|
|
|
pixbuf.fill(uint32.MAX);
|
|
|
|
qr_pixbuf.copy_area(0, 0, 150, 150, pixbuf, 10, 10);
|
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
qrcode_image.set_from_pixbuf(pixbuf);
|
|
|
|
show_qrcode_button.clicked.connect(qrcode_popover.popup);
|
2018-08-09 14:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
new_keys_listbox.set_header_func(header_function);
|
2018-08-09 14:29:15 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
keys_listbox.set_header_func(header_function);
|
2018-08-09 14:29:15 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
//Show any new devices for which the user must decide whether to accept or reject
|
2018-08-12 10:04:40 +00:00
|
|
|
foreach (Row device in plugin.db.identity_meta.get_new_devices(identity_id, jid.to_string())) {
|
2018-08-09 14:29:15 +00:00
|
|
|
add_new_fingerprint(device);
|
|
|
|
}
|
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
//Show the normal devicelist
|
2018-08-12 10:04:40 +00:00
|
|
|
foreach (Row device in plugin.db.identity_meta.get_known_devices(identity_id, jid.to_string())) {
|
2018-08-09 14:29:15 +00:00
|
|
|
if(own && device[plugin.db.identity_meta.device_id] == own_id) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 18:41:41 +00:00
|
|
|
add_fingerprint(device, (TrustLevel) device[plugin.db.identity_meta.trust_level]);
|
2018-08-09 14:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 10:04:40 +00:00
|
|
|
auto_accept_switch.set_active(plugin.db.trust.get_blind_trust(identity_id, jid.bare_jid.to_string()));
|
2018-08-09 14:29:15 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
auto_accept_switch.state_set.connect((active) => {
|
|
|
|
plugin.trust_manager.set_blind_trust(account, jid, active);
|
2018-08-09 14:29:15 +00:00
|
|
|
|
|
|
|
if (active) {
|
|
|
|
new_keys_container.visible = false;
|
|
|
|
|
2018-08-12 10:04:40 +00:00
|
|
|
foreach (Row device in plugin.db.identity_meta.get_new_devices(identity_id, jid.to_string())) {
|
2019-05-16 18:41:41 +00:00
|
|
|
plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], TrustLevel.TRUSTED);
|
|
|
|
add_fingerprint(device, TrustLevel.TRUSTED);
|
2018-08-09 14:29:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
private void header_function(ListBoxRow row, ListBoxRow? before) {
|
|
|
|
if (row.get_header() == null && before != null) {
|
|
|
|
row.set_header(new Separator(Orientation.HORIZONTAL));
|
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 00:06:59 +00:00
|
|
|
private void set_row(int trust, bool now_active, Image img, Label status_lbl, Label lbl, ListBoxRow lbr){
|
2018-08-03 18:07:23 +00:00
|
|
|
switch(trust) {
|
2019-05-16 18:41:41 +00:00
|
|
|
case TrustLevel.TRUSTED:
|
2018-08-03 18:07:23 +00:00
|
|
|
img.icon_name = "emblem-ok-symbolic";
|
2018-08-10 11:47:56 +00:00
|
|
|
status_lbl.set_markup("<span color='#1A63D9'>%s</span>".printf(_("Accepted")));
|
2018-08-11 14:54:14 +00:00
|
|
|
lbl.get_style_context().remove_class("dim-label");
|
2018-08-03 18:07:23 +00:00
|
|
|
break;
|
2019-05-16 18:41:41 +00:00
|
|
|
case TrustLevel.UNTRUSTED:
|
2018-08-03 18:07:23 +00:00
|
|
|
img.icon_name = "action-unavailable-symbolic";
|
2018-08-10 11:47:56 +00:00
|
|
|
status_lbl.set_markup("<span color='#D91900'>%s</span>".printf(_("Rejected")));
|
2018-08-03 18:07:23 +00:00
|
|
|
lbl.get_style_context().add_class("dim-label");
|
|
|
|
break;
|
2019-05-16 18:41:41 +00:00
|
|
|
case TrustLevel.VERIFIED:
|
2018-08-03 18:07:23 +00:00
|
|
|
img.icon_name = "security-high-symbolic";
|
2018-08-10 11:47:56 +00:00
|
|
|
status_lbl.set_markup("<span color='#1A63D9'>%s</span>".printf(_("Verified")));
|
2018-08-11 14:54:14 +00:00
|
|
|
lbl.get_style_context().remove_class("dim-label");
|
2018-08-03 18:07:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-07 00:06:59 +00:00
|
|
|
if (!now_active) {
|
2018-11-09 16:42:23 +00:00
|
|
|
img.icon_name = "appointment-missed-symbolic";
|
2018-08-10 11:47:56 +00:00
|
|
|
status_lbl.set_markup("<span color='#8b8e8f'>%s</span>".printf(_("Unused")));
|
2018-08-07 00:06:59 +00:00
|
|
|
lbr.activatable = false;
|
2018-08-03 18:07:23 +00:00
|
|
|
}
|
2018-08-07 00:06:59 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 18:41:41 +00:00
|
|
|
private void add_fingerprint(Row device, TrustLevel trust) {
|
2018-08-07 00:06:59 +00:00
|
|
|
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 };
|
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
Box status_box = new Box(Gtk.Orientation.HORIZONTAL, 5) { visible = true, hexpand = true };
|
2018-08-07 00:06:59 +00:00
|
|
|
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 };
|
|
|
|
|
|
|
|
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 };
|
|
|
|
|
|
|
|
set_row(trust, device[plugin.db.identity_meta.now_active], img, status_lbl, lbl, lbr);
|
2018-08-03 18:07:23 +00:00
|
|
|
|
|
|
|
box.add(lbl);
|
2018-08-09 23:45:22 +00:00
|
|
|
box.add(status_box);
|
2018-08-03 18:07:23 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
status_box.add(status_lbl);
|
|
|
|
status_box.add(img);
|
2018-08-03 18:07:23 +00:00
|
|
|
|
|
|
|
lbr.add(box);
|
2018-08-09 23:45:22 +00:00
|
|
|
keys_listbox.add(lbr);
|
2018-08-03 18:07:23 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
//Row clicked - pull the most up to date device info from the database and show the manage window
|
|
|
|
keys_listbox.row_activated.connect((row) => {
|
2018-08-03 18:07:23 +00:00
|
|
|
if(row == lbr) {
|
2018-08-09 23:45:22 +00:00
|
|
|
Row updated_device = plugin.db.identity_meta.get_device(device[plugin.db.identity_meta.identity_id], device[plugin.db.identity_meta.address_name], device[plugin.db.identity_meta.device_id]);
|
2018-08-03 18:07:23 +00:00
|
|
|
ManageKeyDialog manage_dialog = new ManageKeyDialog(updated_device, plugin.db);
|
2018-08-08 20:57:24 +00:00
|
|
|
manage_dialog.set_transient_for((Gtk.Window) get_toplevel());
|
2018-08-03 18:07:23 +00:00
|
|
|
manage_dialog.present();
|
2018-08-07 00:06:59 +00:00
|
|
|
manage_dialog.response.connect((response) => {
|
|
|
|
set_row(response, device[plugin.db.identity_meta.now_active], img, status_lbl, lbl, lbr);
|
|
|
|
update_device(response, device);
|
|
|
|
});
|
2018-08-03 18:07:23 +00:00
|
|
|
}
|
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-07 00:06:59 +00:00
|
|
|
private void update_device(int response, Row device){
|
2018-08-03 18:07:23 +00:00
|
|
|
switch (response) {
|
2019-05-16 18:41:41 +00:00
|
|
|
case TrustLevel.TRUSTED:
|
|
|
|
plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], TrustLevel.TRUSTED);
|
2018-08-03 18:07:23 +00:00
|
|
|
break;
|
2019-05-16 18:41:41 +00:00
|
|
|
case TrustLevel.UNTRUSTED:
|
|
|
|
plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], TrustLevel.UNTRUSTED);
|
2018-08-03 18:07:23 +00:00
|
|
|
break;
|
2019-05-16 18:41:41 +00:00
|
|
|
case TrustLevel.VERIFIED:
|
|
|
|
plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], TrustLevel.VERIFIED);
|
2018-08-09 23:45:22 +00:00
|
|
|
plugin.trust_manager.set_blind_trust(account, jid, false);
|
|
|
|
auto_accept_switch.set_active(false);
|
2018-08-03 18:07:23 +00:00
|
|
|
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-09 23:45:22 +00:00
|
|
|
Box control_box = new Box(Gtk.Orientation.HORIZONTAL, 0) { visible = true, hexpand = true };
|
2018-07-09 13:16:23 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
Button yes_button = new Button() { visible = true, valign = Align.CENTER, hexpand = true };
|
|
|
|
yes_button.image = new Image.from_icon_name("emblem-ok-symbolic", IconSize.BUTTON);
|
|
|
|
yes_button.get_style_context().add_class("suggested-action");
|
2018-07-09 13:16:23 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
Button no_button = new Button() { visible = true, valign = Align.CENTER, hexpand = true };
|
|
|
|
no_button.image = new Image.from_icon_name("action-unavailable-symbolic", IconSize.BUTTON);
|
|
|
|
no_button.get_style_context().add_class("destructive-action");
|
2018-07-09 13:16:23 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
yes_button.clicked.connect(() => {
|
2019-05-16 18:41:41 +00:00
|
|
|
plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], TrustLevel.TRUSTED);
|
|
|
|
add_fingerprint(device, TrustLevel.TRUSTED);
|
2018-08-09 23:45:22 +00:00
|
|
|
new_keys_listbox.remove(lbr);
|
|
|
|
if (new_keys_listbox.get_children().length() < 1) new_keys_container.visible = false;
|
2018-08-03 18:07:23 +00:00
|
|
|
});
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
no_button.clicked.connect(() => {
|
2019-05-16 18:41:41 +00:00
|
|
|
plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], TrustLevel.UNTRUSTED);
|
|
|
|
add_fingerprint(device, TrustLevel.UNTRUSTED);
|
2018-08-09 23:45:22 +00:00
|
|
|
new_keys_listbox.remove(lbr);
|
|
|
|
if (new_keys_listbox.get_children().length() < 1) new_keys_container.visible = false;
|
2018-08-03 18:07:23 +00:00
|
|
|
});
|
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-09 23:45:22 +00:00
|
|
|
control_box.add(yes_button);
|
|
|
|
control_box.add(no_button);
|
|
|
|
control_box.get_style_context().add_class("linked");
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-09 23:45:22 +00:00
|
|
|
box.add(control_box);
|
2018-06-11 06:11:04 +00:00
|
|
|
|
2018-08-03 18:07:23 +00:00
|
|
|
lbr.add(box);
|
2018-08-09 23:45:22 +00:00
|
|
|
new_keys_listbox.add(lbr);
|
2018-08-03 18:07:23 +00:00
|
|
|
}
|
2018-06-11 06:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|