From 302e770a98c8fc024bf3dae4266dc034a8e14d09 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 15 May 2022 15:29:15 +0200 Subject: Show modal dialog to select default encryption if unknown --- libdino/src/entity/conversation.vala | 2 +- main/CMakeLists.txt | 1 + main/data/default_encryption_dialog.ui | 125 ++++++++++++++++++++++++++ main/src/ui/conversation_view_controller.vala | 63 +++++++++++++ 4 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 main/data/default_encryption_dialog.ui diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala index 9376dca9..57f0037d 100644 --- a/libdino/src/entity/conversation.vala +++ b/libdino/src/entity/conversation.vala @@ -33,7 +33,7 @@ public class Conversation : Object { } } } - public Encryption encryption { get; set; default = Encryption.NONE; } + public Encryption encryption { get; set; default = Encryption.UNKNOWN; } public Message? read_up_to { get; set; } public int read_up_to_item { get; set; default=-1; } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 2326253c..765188ec 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -64,6 +64,7 @@ set(RESOURCE_LIST conversation_list_titlebar_csd.ui conversation_row.ui conversation_view.ui + default_encryption_dialog.ui file_default_widget.ui file_send_overlay.ui emojichooser.ui diff --git a/main/data/default_encryption_dialog.ui b/main/data/default_encryption_dialog.ui new file mode 100644 index 00000000..81e794ae --- /dev/null +++ b/main/data/default_encryption_dialog.ui @@ -0,0 +1,125 @@ + + + + + + False + True + 320 + 260 + dialog + + + + + + False + vertical + + + False + end + + + OK + True + True + True + + + True + True + 0 + + + + + False + False + 0 + + + + + True + False + vertical + + + True + False + 10 + 10 + No default end-to-end encryption method has been previously selected for this conversation. XMPP defines some XEP for end-to-end encryption that Dino supports. + +It is strongly recommended that one of the following end-to-end encryption methods below is selected before sending a message. + +TAKE INTO ACCOUNT UNENCRYPTED CONVERSATIONS COULD BE READ BY THIRD PARTIES. + +These settings can be later changed from the Settings menu. + True + + + True + False + 0 + + + + + OMEMO (XEP-0384) + True + True + False + True + True + + + False + False + 1 + + + + + OpenPGP (XEP-0027) + True + True + False + True + True + omemo + + + False + False + 2 + + + + + Unencrypted (not recommended) + True + True + False + True + True + omemo + + + False + False + 3 + + + + + True + True + 2 + + + + + + diff --git a/main/src/ui/conversation_view_controller.vala b/main/src/ui/conversation_view_controller.vala index bd52c50c..7cea3212 100644 --- a/main/src/ui/conversation_view_controller.vala +++ b/main/src/ui/conversation_view_controller.vala @@ -110,6 +110,67 @@ public class ConversationViewController : Object { ((Gtk.Window)view.get_toplevel()).add_accel_group(accel_group); } + private void update_conversation_encryption(Conversation? conversation) { + if (conversation == null) { + return; + } + + bool visible = false; + + // FIXME duplicate logic from encryption_button.vala + switch (conversation.type_) { + case Conversation.Type.CHAT: + visible = true; + break; + case Conversation.Type.GROUPCHAT_PM: + visible = false; + break; + case Conversation.Type.GROUPCHAT: + visible = stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart); + break; + } + + if (visible && conversation.encryption == UNKNOWN) { + Dino.Entities.Settings settings = Dino.Application.get_default().settings; + + if (settings.default_encryption == UNKNOWN) { + var selection_dialog_builder = new Builder.from_resource("/im/dino/Dino/default_encryption_dialog.ui"); + var selection_dialog = selection_dialog_builder.get_object("dialog") as Dialog; + var omemo_radio = selection_dialog_builder.get_object("omemo") as RadioButton; + var openpgp_radio = selection_dialog_builder.get_object("openpgp") as RadioButton; + var none_radio = selection_dialog_builder.get_object("none") as RadioButton; + var accept_button = selection_dialog_builder.get_object("accept_button") as Button; + Encryption selected_default = UNKNOWN; + + accept_button.clicked.connect(() => { + if (omemo_radio.active) {selected_default = OMEMO;} + else if (openpgp_radio.active) {selected_default = PGP;} + else if (none_radio.active) {selected_default = NONE;} + + selection_dialog.response(selected_default); + selection_dialog.close(); + }); + + selection_dialog.run(); + conversation.encryption = selected_default; + + if (selected_default != NONE) { + settings.default_encryption = selected_default; + } + else { + // Set conversation as unencrypted, but keep + // default encryption setting as undecided. + } + } + else { + conversation.encryption = settings.default_encryption; + } + } + else if (!visible) { + conversation.encryption = Encryption.NONE; + } + } + public void select_conversation(Conversation? conversation, bool default_initialize_conversation) { if (this.conversation != null) { conversation.notify["encryption"].disconnect(update_file_upload_status); @@ -120,6 +181,8 @@ public class ConversationViewController : Object { this.conversation = conversation; + update_conversation_encryption(conversation); + conversation.notify["encryption"].connect(update_file_upload_status); chat_input_controller.set_conversation(conversation); -- cgit v1.2.3