From 9eafe4139d6b2c0cabe3c77a903d6ae931a26975 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Thu, 24 Aug 2023 20:18:26 +0200 Subject: Fix build on some Vala compiler versions See https://gitlab.gnome.org/GNOME/vala/-/issues/1474 and https://gitlab.gnome.org/GNOME/vala/-/issues/1478 --- libdino/CMakeLists.txt | 7 +++++++ libdino/src/service/stream_interactor.vala | 5 +++++ main/CMakeLists.txt | 15 +++++++++++++++ main/src/ui/util/helper.vala | 6 ++++++ main/src/ui/widgets/avatar_picture.vala | 4 ++-- main/src/ui/widgets/fixed_ratio_picture.vala | 4 ++-- xmpp-vala/CMakeLists.txt | 7 +++++++ xmpp-vala/src/core/module_flag.vala | 10 ++++++++++ 8 files changed, 54 insertions(+), 4 deletions(-) diff --git a/libdino/CMakeLists.txt b/libdino/CMakeLists.txt index 3c184cfd..fc283417 100644 --- a/libdino/CMakeLists.txt +++ b/libdino/CMakeLists.txt @@ -6,6 +6,11 @@ find_packages(LIBDINO_PACKAGES REQUIRED GObject ) +set(LIBDINO_DEFINITIONS) +if(LIBDINO_VERSION VERSION_EQUAL "0.56.11") + set(LIBDINO_DEFINITIONS ${LIBDINO_DEFINITIONS} VALA_0_56_11) +endif() + vala_precompile(LIBDINO_VALA_C SOURCES src/application.vala @@ -76,6 +81,8 @@ GENERATE_VAPI dino GENERATE_HEADER dino +DEFINITIONS + ${LIBDINO_DEFINITIONS} ) add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/dino_i18n.h" diff --git a/libdino/src/service/stream_interactor.vala b/libdino/src/service/stream_interactor.vala index 192460d4..5d248327 100644 --- a/libdino/src/service/stream_interactor.vala +++ b/libdino/src/service/stream_interactor.vala @@ -89,7 +89,12 @@ public class ModuleIdentity : Object { } public T? cast(StreamInteractionModule module) { +#if VALA_0_56_11 + // We can't typecheck due to compiler bug + return (T) module; +#else return module.get_type().is_a(typeof(T)) ? (T?) module : null; +#endif } public bool matches(StreamInteractionModule module) { diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 7f85f7ae..4e408294 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -111,9 +111,24 @@ endif() if(GTK4_VERSION VERSION_GREATER_EQUAL "4.8") set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} GTK_4_8) endif() +if(GTK4_VERSION VERSION_GREATER_EQUAL "4.12") + set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} GTK_4_12) +endif() if(Adwaita_VERSION VERSION_GREATER_EQUAL "1.2") set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} Adw_1_2) endif() +if(VALA_VERSION VERSION_GREATER_EQUAL "0.56.5" AND VALA_VERSION VERSION_LESS "0.58") + set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} VALA_0_56_GREATER_5) +endif() +if(VALA_VERSION VERSION_GREATER_EQUAL "0.56.11" AND VALA_VERSION VERSION_LESS "0.58") + set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} VALA_0_56_GREATER_11) +endif() +if(VALA_VERSION VERSION_EQUAL "0.56.11") + set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} VALA_0_56_11) +endif() +if(VALA_VERSION VERSION_EQUAL "0.56.12") + set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} VALA_0_56_12) +endif() vala_precompile(MAIN_VALA_C SOURCES diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index d6da72dd..63288fc2 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -103,7 +103,13 @@ private const string force_color_css = "%s { color: %s; }"; public static Gtk.CssProvider force_css(Gtk.Widget widget, string css) { var p = new Gtk.CssProvider(); try { +#if GTK_4_12 && (VALA_0_56_GREATER_11 || VALA_0_58) + p.load_from_string(css); +#elif (VALA_0_56_11 || VALA_0_56_12) + p.load_from_data(css, css.length); +#else p.load_from_data(css.data); +#endif widget.get_style_context().add_provider(p, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } catch (GLib.Error err) { // handle err diff --git a/main/src/ui/widgets/avatar_picture.vala b/main/src/ui/widgets/avatar_picture.vala index e632413c..fb254915 100644 --- a/main/src/ui/widgets/avatar_picture.vala +++ b/main/src/ui/widgets/avatar_picture.vala @@ -454,7 +454,7 @@ public class Dino.Ui.AvatarPicture : Gtk.Widget { label.insert_after(this, null); label.attributes = new Pango.AttrList(); label.attributes.insert(Pango.attr_foreground_new(uint16.MAX, uint16.MAX, uint16.MAX)); -#if GTK_4_8 && VALA_0_58 +#if GTK_4_8 && (VALA_0_56_GREATER_5 || VALA_0_58) picture.content_fit = Gtk.ContentFit.COVER; #elif GTK_4_8 picture.@set("content-fit", 2); @@ -516,4 +516,4 @@ public class Dino.Ui.AvatarPicture : Gtk.Widget { base.snapshot(snapshot); } } -} \ No newline at end of file +} diff --git a/main/src/ui/widgets/fixed_ratio_picture.vala b/main/src/ui/widgets/fixed_ratio_picture.vala index 79c60141..3e83ec0c 100644 --- a/main/src/ui/widgets/fixed_ratio_picture.vala +++ b/main/src/ui/widgets/fixed_ratio_picture.vala @@ -8,7 +8,7 @@ class Dino.Ui.FixedRatioPicture : Gtk.Widget { public int max_height { get; set; default = int.MAX; } public File file { get { return inner.file; } set { inner.file = value; } } public Gdk.Paintable paintable { get { return inner.paintable; } set { inner.paintable = value; } } -#if GTK_4_8 && VALA_0_58 +#if GTK_4_8 && (VALA_0_56_GREATER_5 || VALA_0_58) public Gtk.ContentFit content_fit { get { return inner.content_fit; } set { inner.content_fit = value; } } #endif private Gtk.Picture inner = new Gtk.Picture(); @@ -85,4 +85,4 @@ class Dino.Ui.FixedRatioPicture : Gtk.Widget { inner.unparent(); base.dispose(); } -} \ No newline at end of file +} diff --git a/xmpp-vala/CMakeLists.txt b/xmpp-vala/CMakeLists.txt index 39c090fe..cfbc0aaf 100644 --- a/xmpp-vala/CMakeLists.txt +++ b/xmpp-vala/CMakeLists.txt @@ -9,6 +9,11 @@ find_packages(ENGINE_PACKAGES REQUIRED set(ENGINE_EXTRA_OPTIONS ${MAIN_EXTRA_OPTIONS} --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi) +set(ENGINE_DEFINITIONS) +if(VALA_VERSION VERSION_EQUAL "0.56.11") + set(ENGINE_DEFINITIONS ${ENGINE_DEFINITIONS} VALA_0_56_11) +endif() + vala_precompile(ENGINE_VALA_C SOURCES "src/core/direct_tls_xmpp_stream.vala" @@ -152,6 +157,8 @@ CUSTOM_VAPIS "${CMAKE_CURRENT_SOURCE_DIR}/src/glib_fixes.vapi" OPTIONS ${ENGINE_EXTRA_OPTIONS} +DEFINITIONS + ${ENGINE_DEFINITIONS} ) add_custom_target(xmpp-vala-vapi diff --git a/xmpp-vala/src/core/module_flag.vala b/xmpp-vala/src/core/module_flag.vala index 95547852..76ae4dc1 100644 --- a/xmpp-vala/src/core/module_flag.vala +++ b/xmpp-vala/src/core/module_flag.vala @@ -10,7 +10,12 @@ namespace Xmpp { } public T? cast(XmppStreamFlag flag) { +#if VALA_0_56_11 + // We can't typecheck due to compiler bug + return (T) module; +#else return flag.get_type().is_a(typeof(T)) ? (T?) flag : null; +#endif } public bool matches(XmppStreamFlag module) { @@ -34,7 +39,12 @@ namespace Xmpp { } public T? cast(XmppStreamModule module) { +#if VALA_0_56_11 + // We can't typecheck due to compiler bug + return (T) module; +#else return module.get_type().is_a(typeof(T)) ? (T?) module : null; +#endif } public bool matches(XmppStreamModule module) { -- cgit v1.2.3-54-g00ecf From e2c34bf2235c9f85fc91de9c0f1b74858f4ef89e Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 24 Sep 2023 19:54:04 +0200 Subject: Rewrite contact details dialog --- libdino/CMakeLists.txt | 1 + libdino/meson.build | 1 + libdino/src/application.vala | 1 + libdino/src/service/contact_model.vala | 58 ++++++ main/CMakeLists.txt | 22 +- main/data/contact_details_dialog.ui | 110 ---------- main/data/conversation_details.css | 7 + main/data/conversation_details.ui | 207 ++++++++++++++++++ main/data/gresource.xml | 5 +- main/data/join_room_dialog.ui | 44 ++++ main/data/join_room_dialog1.ui | 160 ++++++++++++++ main/data/join_room_dialog2.ui | 232 +++++++++++++++++++++ main/data/style.css | 2 + main/meson.build | 7 +- main/src/ui/chat_input/chat_input_controller.vala | 5 +- main/src/ui/contact_details/blocking_provider.vala | 36 ---- main/src/ui/contact_details/dialog.vala | 159 -------------- .../contact_details/muc_config_form_provider.vala | 93 --------- .../ui/contact_details/permissions_provider.vala | 2 +- main/src/ui/contact_details/settings_provider.vala | 67 +----- main/src/ui/conversation_details.vala | 188 +++++++++++++++++ main/src/ui/conversation_titlebar/menu_entry.vala | 5 +- main/src/ui/util/data_forms.vala | 94 +++++++++ main/src/view_model/conversation_details.vala | 49 +++++ main/src/view_model/preferences_row.vala | 34 +++ main/src/windows/conversation_details.vala | 227 ++++++++++++++++++++ xmpp-vala/src/module/xep/0004_data_forms.vala | 2 +- 27 files changed, 1339 insertions(+), 479 deletions(-) create mode 100644 libdino/src/service/contact_model.vala delete mode 100644 main/data/contact_details_dialog.ui create mode 100644 main/data/conversation_details.css create mode 100644 main/data/conversation_details.ui create mode 100644 main/data/join_room_dialog.ui create mode 100644 main/data/join_room_dialog1.ui create mode 100644 main/data/join_room_dialog2.ui delete mode 100644 main/src/ui/contact_details/blocking_provider.vala delete mode 100644 main/src/ui/contact_details/dialog.vala delete mode 100644 main/src/ui/contact_details/muc_config_form_provider.vala create mode 100644 main/src/ui/conversation_details.vala create mode 100644 main/src/view_model/conversation_details.vala create mode 100644 main/src/view_model/preferences_row.vala create mode 100644 main/src/windows/conversation_details.vala diff --git a/libdino/CMakeLists.txt b/libdino/CMakeLists.txt index fc283417..d52f9184 100644 --- a/libdino/CMakeLists.txt +++ b/libdino/CMakeLists.txt @@ -40,6 +40,7 @@ SOURCES src/service/calls.vala src/service/chat_interaction.vala src/service/connection_manager.vala + src/service/contact_model.vala src/service/content_item_store.vala src/service/conversation_manager.vala src/service/counterpart_interaction_manager.vala diff --git a/libdino/meson.build b/libdino/meson.build index 0ebaff33..611e8ca7 100644 --- a/libdino/meson.build +++ b/libdino/meson.build @@ -47,6 +47,7 @@ sources = files( 'src/service/calls.vala', 'src/service/chat_interaction.vala', 'src/service/connection_manager.vala', + 'src/service/contact_model.vala', 'src/service/content_item_store.vala', 'src/service/conversation_manager.vala', 'src/service/counterpart_interaction_manager.vala', diff --git a/libdino/src/application.vala b/libdino/src/application.vala index 5e58e364..727b6131 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -57,6 +57,7 @@ public interface Application : GLib.Application { Reactions.start(stream_interactor, db); Replies.start(stream_interactor, db); FallbackBody.start(stream_interactor, db); + ContactModels.start(stream_interactor); create_actions(); diff --git a/libdino/src/service/contact_model.vala b/libdino/src/service/contact_model.vala new file mode 100644 index 00000000..312df4f7 --- /dev/null +++ b/libdino/src/service/contact_model.vala @@ -0,0 +1,58 @@ +using Xmpp; +using Gee; +using Qlite; + +using Dino.Entities; + +public class Dino.Model.ConversationDisplayName : Object { + public string display_name { get; set; } +} + +namespace Dino { + public class ContactModels : StreamInteractionModule, Object { + public static ModuleIdentity IDENTITY = new ModuleIdentity("contact_models"); + public string id { get { return IDENTITY.id; } } + + private StreamInteractor stream_interactor; + private HashMap conversation_models = new HashMap(Conversation.hash_func, Conversation.equals_func); + + public static void start(StreamInteractor stream_interactor) { + ContactModels m = new ContactModels(stream_interactor); + stream_interactor.add_module(m); + } + + private ContactModels(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + + stream_interactor.get_module(MucManager.IDENTITY).room_info_updated.connect((account, jid) => { + check_update_models(account, jid, Conversation.Type.GROUPCHAT); + }); + stream_interactor.get_module(MucManager.IDENTITY).private_room_occupant_updated.connect((account, room, occupant) => { + check_update_models(account, room, Conversation.Type.GROUPCHAT); + }); + stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => { + check_update_models(account, jid, Conversation.Type.GROUPCHAT); + }); + stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect((account, jid, roster_item) => { + check_update_models(account, jid, Conversation.Type.CHAT); + }); + } + + private void check_update_models(Account account, Jid jid, Conversation.Type conversation_ty) { + var conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account, conversation_ty); + if (conversation == null) return; + var display_name_model = conversation_models[conversation]; + if (display_name_model == null) return; + display_name_model.display_name = Dino.get_conversation_display_name(stream_interactor, conversation, "%s (%s)"); + } + + public Model.ConversationDisplayName get_display_name_model(Conversation conversation) { + if (conversation_models.has_key(conversation)) return conversation_models[conversation]; + + var model = new Model.ConversationDisplayName(); + model.display_name = Dino.get_conversation_display_name(stream_interactor, conversation, "%s (%s)"); + conversation_models[conversation] = model; + return model; + } + } +} \ No newline at end of file diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 4e408294..437a84b9 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -58,7 +58,7 @@ set(RESOURCE_LIST call_widget.ui chat_input.ui - contact_details_dialog.ui + conversation_details.ui conversation_item_widget.ui conversation_list_titlebar.ui conversation_list_titlebar_csd.ui @@ -68,6 +68,9 @@ set(RESOURCE_LIST file_send_overlay.ui global_search.ui gtk/help-overlay.ui + join_room_dialog.ui + join_room_dialog1.ui + join_room_dialog2.ui conversation_content_view/item_metadata_header.ui conversation_content_view/view.ui manage_accounts/account_row.ui @@ -86,6 +89,7 @@ set(RESOURCE_LIST unified_main_content.ui unified_window_placeholder.ui + conversation_details.css style.css style-dark.css ) @@ -117,6 +121,12 @@ endif() if(Adwaita_VERSION VERSION_GREATER_EQUAL "1.2") set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} Adw_1_2) endif() +if(Adwaita_VERSION VERSION_GREATER_EQUAL "1.3") + set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} Adw_1_3) +endif() +if(Adwaita_VERSION VERSION_GREATER_EQUAL "1.4") + set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} Adw_1_4) +endif() if(VALA_VERSION VERSION_GREATER_EQUAL "0.56.5" AND VALA_VERSION VERSION_LESS "0.58") set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} VALA_0_56_GREATER_5) endif() @@ -187,11 +197,10 @@ SOURCES src/ui/chat_input/smiley_converter.vala src/ui/chat_input/view.vala - src/ui/contact_details/blocking_provider.vala src/ui/contact_details/settings_provider.vala src/ui/contact_details/permissions_provider.vala - src/ui/contact_details/dialog.vala - src/ui/contact_details/muc_config_form_provider.vala + + src/ui/conversation_details.vala src/ui/conversation_selector/conversation_selector.vala src/ui/conversation_selector/conversation_selector_row.vala @@ -222,6 +231,11 @@ SOURCES src/ui/widgets/date_separator.vala src/ui/widgets/fixed_ratio_picture.vala src/ui/widgets/natural_size_increase.vala + + src/view_model/conversation_details.vala + src/view_model/preferences_row.vala + + src/windows/conversation_details.vala CUSTOM_VAPIS ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi ${CMAKE_BINARY_DIR}/exports/qlite.vapi diff --git a/main/data/contact_details_dialog.ui b/main/data/contact_details_dialog.ui deleted file mode 100644 index 4802ae9a..00000000 --- a/main/data/contact_details_dialog.ui +++ /dev/null @@ -1,110 +0,0 @@ - - - - - diff --git a/main/data/conversation_details.css b/main/data/conversation_details.css new file mode 100644 index 00000000..0eaf60c0 --- /dev/null +++ b/main/data/conversation_details.css @@ -0,0 +1,7 @@ +.extended-headerbar { + background-color: @headerbar_bg_color; +} +.extended-headerbar-end { + padding-bottom: 24px; + border-bottom: 1px solid @borders; +} \ No newline at end of file diff --git a/main/data/conversation_details.ui b/main/data/conversation_details.ui new file mode 100644 index 00000000..1347ad2b --- /dev/null +++ b/main/data/conversation_details.ui @@ -0,0 +1,207 @@ + + + + + + + +
+ + Enable notifications + notification.on + + + Disable notifications + notification.off + +
+
+ + Reset to default + notification.default + +
+
+ +
+ + Notify for all messages + notification.on + + + Notify only for mentions + notification.highlight + + + Disable notifications + notification.off + +
+
+ + Reset to default + notification.default + +
+
+ \ No newline at end of file diff --git a/main/data/gresource.xml b/main/data/gresource.xml index 656defc4..503503c9 100644 --- a/main/data/gresource.xml +++ b/main/data/gresource.xml @@ -8,9 +8,9 @@ add_conversation/select_jid_fragment.ui call_widget.ui chat_input.ui - contact_details_dialog.ui conversation_content_view/item_metadata_header.ui conversation_content_view/view.ui + conversation_details.ui conversation_item_widget.ui conversation_list_titlebar.ui conversation_list_titlebar_csd.ui @@ -49,6 +49,9 @@ icons/scalable/status/dino-tick-symbolic.svg icons/scalable/status/dino-video-off-symbolic.svg icons/scalable/status/dino-video-symbolic.svg + join_room_dialog.ui + join_room_dialog1.ui + join_room_dialog2.ui manage_accounts/account_row.ui manage_accounts/add_account_dialog.ui manage_accounts/dialog.ui diff --git a/main/data/join_room_dialog.ui b/main/data/join_room_dialog.ui new file mode 100644 index 00000000..725d30e9 --- /dev/null +++ b/main/data/join_room_dialog.ui @@ -0,0 +1,44 @@ + + + + + + 500 + 600 + True + + + + False + + + channel_selection + + + + + model + + + + + + + + + confirmation + + + + + model + + + + + + + + + + \ No newline at end of file diff --git a/main/data/join_room_dialog1.ui b/main/data/join_room_dialog1.ui new file mode 100644 index 00000000..91c024d3 --- /dev/null +++ b/main/data/join_room_dialog1.ui @@ -0,0 +1,160 @@ + + + + + \ No newline at end of file diff --git a/main/data/join_room_dialog2.ui b/main/data/join_room_dialog2.ui new file mode 100644 index 00000000..1a30efc0 --- /dev/null +++ b/main/data/join_room_dialog2.ui @@ -0,0 +1,232 @@ + + + + + \ No newline at end of file diff --git a/main/data/style.css b/main/data/style.css index af1c58fa..5fe3beae 100644 --- a/main/data/style.css +++ b/main/data/style.css @@ -3,6 +3,8 @@ * It provides sane defaults for things that are very Dino-specific. */ +@import url("conversation_details.css"); + statuspage { opacity: 0.5; } diff --git a/main/meson.build b/main/meson.build index a38e15b8..0326cc7c 100644 --- a/main/meson.build +++ b/main/meson.build @@ -36,9 +36,6 @@ sources = files( 'src/ui/chat_input/occupants_tab_completer.vala', 'src/ui/chat_input/smiley_converter.vala', 'src/ui/chat_input/view.vala', - 'src/ui/contact_details/blocking_provider.vala', - 'src/ui/contact_details/dialog.vala', - 'src/ui/contact_details/muc_config_form_provider.vala', 'src/ui/contact_details/permissions_provider.vala', 'src/ui/contact_details/settings_provider.vala', 'src/ui/conversation_content_view/call_widget.vala', @@ -55,6 +52,7 @@ sources = files( 'src/ui/conversation_content_view/quote_widget.vala', 'src/ui/conversation_content_view/reactions_widget.vala', 'src/ui/conversation_content_view/subscription_notification.vala', + 'src/ui/conversation_details.vala', 'src/ui/conversation_list_titlebar.vala', 'src/ui/conversation_selector/conversation_selector.vala', 'src/ui/conversation_selector/conversation_selector_row.vala', @@ -89,6 +87,9 @@ sources = files( 'src/ui/widgets/date_separator.vala', 'src/ui/widgets/fixed_ratio_picture.vala', 'src/ui/widgets/natural_size_increase.vala', + 'src/view_model/conversation_details.vala', + 'src/view_model/preferences_row.vala', + 'src/windows/conversation_details.vala', ) sources += import('gnome').compile_resources( 'dino-resources', diff --git a/main/src/ui/chat_input/chat_input_controller.vala b/main/src/ui/chat_input/chat_input_controller.vala index d9608a85..d1c42d35 100644 --- a/main/src/ui/chat_input/chat_input_controller.vala +++ b/main/src/ui/chat_input/chat_input_controller.vala @@ -54,9 +54,8 @@ public class ChatInputController : Object { status_description_label.activate_link.connect((uri) => { if (uri == OPEN_CONVERSATION_DETAILS_URI){ - ContactDetails.Dialog contact_details_dialog = new ContactDetails.Dialog(stream_interactor, conversation); - contact_details_dialog.set_transient_for((Gtk.Window) chat_input.get_root()); - contact_details_dialog.present(); + var conversation_details = ConversationDetails.setup_dialog(conversation, stream_interactor, (Window)chat_input.get_root()); + conversation_details.present(); } return true; }); diff --git a/main/src/ui/contact_details/blocking_provider.vala b/main/src/ui/contact_details/blocking_provider.vala deleted file mode 100644 index 7e4a475d..00000000 --- a/main/src/ui/contact_details/blocking_provider.vala +++ /dev/null @@ -1,36 +0,0 @@ -using Gtk; - -using Dino.Entities; - -namespace Dino.Ui.ContactDetails { - -public class BlockingProvider : Plugins.ContactDetailsProvider, Object { - public string id { get { return "blocking"; } } - - private StreamInteractor stream_interactor; - - public BlockingProvider(StreamInteractor stream_interactor) { - this.stream_interactor = stream_interactor; - } - - public void populate(Conversation conversation, Plugins.ContactDetails contact_details, Plugins.WidgetType type) { - if (type != Plugins.WidgetType.GTK4) return; - if (conversation.type_ != Conversation.Type.CHAT) return; - - if (stream_interactor.get_module(BlockingManager.IDENTITY).is_supported(conversation.account)) { - bool is_blocked = stream_interactor.get_module(BlockingManager.IDENTITY).is_blocked(conversation.account, conversation.counterpart); - Switch sw = new Switch() { active=is_blocked, valign=Align.CENTER }; - sw.state_set.connect((state) => { - if (state) { - stream_interactor.get_module(BlockingManager.IDENTITY).block(conversation.account, conversation.counterpart); - } else { - stream_interactor.get_module(BlockingManager.IDENTITY).unblock(conversation.account, conversation.counterpart); - } - return false; - }); - contact_details.add(_("Settings"), _("Block"), _("Communication and status updates in either direction are blocked"), sw); - } - } -} - -} diff --git a/main/src/ui/contact_details/dialog.vala b/main/src/ui/contact_details/dialog.vala deleted file mode 100644 index c897fe4e..00000000 --- a/main/src/ui/contact_details/dialog.vala +++ /dev/null @@ -1,159 +0,0 @@ -using Gee; -using Gtk; -using Markup; -using Pango; - -using Dino.Entities; - -namespace Dino.Ui.ContactDetails { - -[GtkTemplate (ui = "/im/dino/Dino/contact_details_dialog.ui")] -public class Dialog : Gtk.Dialog { - - [GtkChild] public unowned AvatarPicture avatar; - [GtkChild] public unowned Util.EntryLabelHybrid name_hybrid; - [GtkChild] public unowned Label name_label; - [GtkChild] public unowned Label jid_label; - [GtkChild] public unowned Label account_label; - [GtkChild] public unowned Box main_box; - - private StreamInteractor stream_interactor; - private Conversation conversation; - - private Plugins.ContactDetails contact_details = new Plugins.ContactDetails(); - private HashMap categories = new HashMap(); - private Util.LabelHybridGroup hybrid_group = new Util.LabelHybridGroup(); - - construct { - name_hybrid.label.attributes = new AttrList(); - name_hybrid.label.attributes.insert(attr_weight_new(Weight.BOLD)); - } - - public Dialog(StreamInteractor stream_interactor, Conversation conversation) { - Object(use_header_bar : Util.use_csd() ? 1 : 0); - this.stream_interactor = stream_interactor; - this.conversation = conversation; - - title = conversation.type_ == Conversation.Type.GROUPCHAT ? _("Conference Details") : _("Contact Details"); - if (Util.use_csd()) { - // TODO get_header_bar directly returns a HeaderBar in vala > 0.48 - Box titles_box = new Box(Orientation.VERTICAL, 0) { valign=Align.CENTER }; - var title_label = new Label(title); - title_label.attributes = new AttrList(); - title_label.attributes.insert(Pango.attr_weight_new(Weight.BOLD)); - titles_box.append(title_label); - var subtitle_label = new Label(Util.get_conversation_display_name(stream_interactor, conversation)); - subtitle_label.attributes = new AttrList(); - subtitle_label.attributes.insert(Pango.attr_scale_new(Pango.Scale.SMALL)); - subtitle_label.add_css_class("dim-label"); - titles_box.append(subtitle_label); - - get_header_bar().set_title_widget(titles_box); - } - setup_top(); - - contact_details.add.connect(add_entry); - - Application app = GLib.Application.get_default() as Application; - app.plugin_registry.register_contact_details_entry(new SettingsProvider(stream_interactor)); - app.plugin_registry.register_contact_details_entry(new BlockingProvider(stream_interactor)); - app.plugin_registry.register_contact_details_entry(new MucConfigFormProvider(stream_interactor)); - app.plugin_registry.register_contact_details_entry(new PermissionsProvider(stream_interactor)); - - foreach (Plugins.ContactDetailsProvider provider in app.plugin_registry.contact_details_entries) { - provider.populate(conversation, contact_details, Plugins.WidgetType.GTK4); - } - - close_request.connect(() => { - contact_details.save(); - return false; - }); - } - - private void setup_top() { - if (conversation.type_ == Conversation.Type.CHAT) { - name_label.visible = false; - jid_label.margin_start = new Button().get_style_context().get_padding().left + 1; - name_hybrid.text = Util.get_conversation_display_name(stream_interactor, conversation); - close_request.connect(() => { - if (name_hybrid.text != Util.get_conversation_display_name(stream_interactor, conversation)) { - stream_interactor.get_module(RosterManager.IDENTITY).set_jid_handle(conversation.account, conversation.counterpart, name_hybrid.text); - } - return false; - }); - } else { - name_hybrid.visible = false; - name_label.label = Util.get_conversation_display_name(stream_interactor, conversation); - } - jid_label.label = conversation.counterpart.to_string(); - account_label.label = "via " + conversation.account.bare_jid.to_string(); - avatar.model = new ViewModel.CompatAvatarPictureModel(stream_interactor).set_conversation(conversation); - } - - private void add_entry(string category, string label, string? description, Object wo) { - if (!(wo is Widget)) return; - Widget w = (Widget) wo; - add_category(category); - - ListBoxRow list_row = new ListBoxRow() { activatable=false }; - Box row = new Box(Orientation.HORIZONTAL, 20) { margin_start=15, margin_end=15, margin_top=3, margin_bottom=3 }; - list_row.set_child(row); - Label label_label = new Label(label) { xalign=0, yalign=0.5f, hexpand=true }; - if (description != null && description != "") { - Box box = new Box(Orientation.VERTICAL, 0); - box.append(label_label); - Label desc_label = new Label("") { xalign=0, yalign=0.5f, hexpand=true }; - desc_label.set_markup("%s".printf(Markup.escape_text(description))); - desc_label.add_css_class("dim-label"); - box.append(desc_label); - row.append(box); - } else { - row.append(label_label); - } - - Widget widget = w; - if (widget.get_type().is_a(typeof(Entry))) { - Util.EntryLabelHybrid hybrid = new Util.EntryLabelHybrid.wrap(widget as Entry) { xalign=1 }; - hybrid_group.add(hybrid); - widget = hybrid; - } else if (widget.get_type().is_a(typeof(ComboBoxText))) { - Util.ComboBoxTextLabelHybrid hybrid = new Util.ComboBoxTextLabelHybrid.wrap(widget as ComboBoxText) { xalign=1 }; - hybrid_group.add(hybrid); - widget = hybrid; - } - widget.margin_bottom = 5; - widget.margin_top = 5; - - - row.append(widget); - categories[category].append(list_row); - - int width = get_content_area().get_width(); - int pref_height, pref_width; - get_content_area().measure(Orientation.VERTICAL, width, null, out pref_height, null, null); - default_height = pref_height + 48; - } - - private void add_category(string category) { - if (!categories.has_key(category)) { - ListBox list_box = new ListBox() { selection_mode=SelectionMode.NONE }; - categories[category] = list_box; - list_box.set_header_func((row, before_row) => { - if (row.get_header() == null && before_row != null) { - row.set_header(new Separator(Orientation.HORIZONTAL)); - } - }); - Box box = new Box(Orientation.VERTICAL, 5) { margin_top=12, margin_bottom=12 }; - Label category_label = new Label("") { xalign=0 }; - category_label.set_markup(@"$(Markup.escape_text(category))"); - box.append(category_label); - Frame frame = new Frame(null); - frame.set_child(list_box); - box.append(frame); - main_box.append(box); - } - } -} - -} - diff --git a/main/src/ui/contact_details/muc_config_form_provider.vala b/main/src/ui/contact_details/muc_config_form_provider.vala deleted file mode 100644 index 1244a759..00000000 --- a/main/src/ui/contact_details/muc_config_form_provider.vala +++ /dev/null @@ -1,93 +0,0 @@ -using Gee; -using Gtk; - -using Dino.Entities; -using Xmpp.Xep; - -namespace Dino.Ui.ContactDetails { - -public class MucConfigFormProvider : Plugins.ContactDetailsProvider, Object { - public string id { get { return "muc_config_form"; } } - private StreamInteractor stream_interactor; - - public MucConfigFormProvider(StreamInteractor stream_interactor) { - this.stream_interactor = stream_interactor; - } - - public void populate(Conversation conversation, Plugins.ContactDetails contact_details, Plugins.WidgetType type) { - if (type != Plugins.WidgetType.GTK4) return; - if (conversation.type_ == Conversation.Type.GROUPCHAT) { - Xmpp.XmppStream? stream = stream_interactor.get_stream(conversation.account); - if (stream == null) return; - - stream_interactor.get_module(MucManager.IDENTITY).get_config_form.begin(conversation.account, conversation.counterpart, (_, res) => { - DataForms.DataForm? data_form = stream_interactor.get_module(MucManager.IDENTITY).get_config_form.end(res); - if (data_form == null) return; - - for (int i = 0; i < data_form.fields.size; i++) { - DataForms.DataForm.Field field = data_form.fields[i]; - add_field(field, contact_details); - } - - string config_backup = data_form.stanza_node.to_string(); - contact_details.save.connect(() => { - // Only send the config form if something was changed - if (config_backup != data_form.stanza_node.to_string()) { - stream_interactor.get_module(MucManager.IDENTITY).set_config_form.begin(conversation.account, conversation.counterpart, data_form); - } - }); - }); - } - } - - public static void add_field(DataForms.DataForm.Field field, Plugins.ContactDetails contact_details) { - string label = field.label ?? ""; - string? desc = null; - - if (field.var != null) { - switch (field.var) { - case "muc#roomconfig_roomname": - label = _("Name of the room"); - break; - case "muc#roomconfig_roomdesc": - label = _("Description of the room"); - break; - case "muc#roomconfig_persistentroom": - label = _("Persistent"); - desc = _("The room will persist after the last occupant leaves"); - break; - case "muc#roomconfig_publicroom": - label = _("Publicly searchable"); - break; - case "muc#roomconfig_changesubject": - label = _("Occupants may change the subject"); - break; - case "muc#roomconfig_whois": - label = _("Permission to view JIDs"); - desc = _("Who is allowed to view the occupants' JIDs?"); - break; - case "muc#roomconfig_roomsecret": - label = _("Password"); - desc = _("A password to restrict access to the room"); - break; - case "muc#roomconfig_moderatedroom": - label = _("Moderated"); - desc = _("Only occupants with voice may send messages"); - break; - case "muc#roomconfig_membersonly": - label = _("Members only"); - desc = _("Only members may enter the room"); - break; - case "muc#roomconfig_historylength": - label = _("Message history"); - desc = _("Maximum amount of backlog issued by the room"); - break; - } - } - - Widget? widget = Util.get_data_form_field_widget(field); - if (widget != null) contact_details.add(_("Room Configuration"), label, desc, widget); - } -} - -} diff --git a/main/src/ui/contact_details/permissions_provider.vala b/main/src/ui/contact_details/permissions_provider.vala index ed0756e8..c7ea4a1c 100644 --- a/main/src/ui/contact_details/permissions_provider.vala +++ b/main/src/ui/contact_details/permissions_provider.vala @@ -22,7 +22,7 @@ public class PermissionsProvider : Plugins.ContactDetailsProvider, Object { if (stream_interactor.get_module(MucManager.IDENTITY).get_role(own_jid, conversation.account) == Xmpp.Xep.Muc.Role.VISITOR){ Button voice_request = new Button.with_label(_("Request")); voice_request.clicked.connect(()=>stream_interactor.get_module(MucManager.IDENTITY).request_voice(conversation.account, conversation.counterpart)); - contact_details.add(_("Permissions"), _("Request permission to send messages"), "", voice_request); + contact_details.add("Permissions", _("Request permission to send messages"), "", voice_request); } } } diff --git a/main/src/ui/contact_details/settings_provider.vala b/main/src/ui/contact_details/settings_provider.vala index 8121e5b1..6a680f64 100644 --- a/main/src/ui/contact_details/settings_provider.vala +++ b/main/src/ui/contact_details/settings_provider.vala @@ -9,8 +9,8 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { private StreamInteractor stream_interactor; - private string DETAILS_HEADLINE_CHAT = _("Settings"); - private string DETAILS_HEADLINE_ROOM = _("Local Settings"); + private string DETAILS_HEADLINE_CHAT = "Settings"; + private string DETAILS_HEADLINE_ROOM = "Local Settings"; public SettingsProvider(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; @@ -33,28 +33,7 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { contact_details.add(DETAILS_HEADLINE_CHAT, _("Send read receipts"), "", combobox_marker); combobox_marker.active_id = get_setting_id(conversation.send_marker); combobox_marker.changed.connect(() => { conversation.send_marker = get_setting(combobox_marker.active_id); } ); - - ComboBoxText combobox_notifications = get_combobox(Dino.Application.get_default().settings.notifications); - contact_details.add(DETAILS_HEADLINE_CHAT, _("Notifications"), "", combobox_notifications); - combobox_notifications.active_id = get_notify_setting_id(conversation.notify_setting); - combobox_notifications.changed.connect(() => { conversation.notify_setting = get_notify_setting(combobox_notifications.active_id); } ); - } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { - ComboBoxText combobox = new ComboBoxText(); - combobox.append("default", get_notify_setting_string(Conversation.NotifySetting.DEFAULT, conversation.get_notification_default_setting(stream_interactor))); - combobox.append("highlight", get_notify_setting_string(Conversation.NotifySetting.HIGHLIGHT)); - combobox.append("on", get_notify_setting_string(Conversation.NotifySetting.ON)); - combobox.append("off", get_notify_setting_string(Conversation.NotifySetting.OFF)); - contact_details.add(DETAILS_HEADLINE_ROOM, _("Notifications"), "", combobox); - - combobox.active_id = get_notify_setting_id(conversation.notify_setting); - combobox.changed.connect(() => { conversation.notify_setting = get_notify_setting(combobox.active_id); } ); } - - Switch pinned_switch = new Switch() { valign=Align.CENTER }; - string category = conversation.type_ == Conversation.Type.GROUPCHAT ? DETAILS_HEADLINE_ROOM : DETAILS_HEADLINE_CHAT; - contact_details.add(category, _("Pin conversation"), _("Pins the conversation to the top of the conversation list"), pinned_switch); - pinned_switch.state = conversation.pinned != 0; - pinned_switch.state_set.connect((state) => { conversation.pinned = state ? 1 : 0; return false; }); } private Conversation.Setting get_setting(string id) { @@ -69,34 +48,6 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { assert_not_reached(); } - private Conversation.NotifySetting get_notify_setting(string id) { - switch (id) { - case "default": - return Conversation.NotifySetting.DEFAULT; - case "on": - return Conversation.NotifySetting.ON; - case "off": - return Conversation.NotifySetting.OFF; - case "highlight": - return Conversation.NotifySetting.HIGHLIGHT; - } - assert_not_reached(); - } - - private string get_notify_setting_string(Conversation.NotifySetting setting, Conversation.NotifySetting? default_setting = null) { - switch (setting) { - case Conversation.NotifySetting.ON: - return _("On"); - case Conversation.NotifySetting.OFF: - return _("Off"); - case Conversation.NotifySetting.HIGHLIGHT: - return _("Only when mentioned"); - case Conversation.NotifySetting.DEFAULT: - return _("Default: %s").printf(get_notify_setting_string(default_setting)); - } - assert_not_reached(); - } - private string get_setting_id(Conversation.Setting setting) { switch (setting) { case Conversation.Setting.DEFAULT: @@ -109,20 +60,6 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { assert_not_reached(); } - private string get_notify_setting_id(Conversation.NotifySetting setting) { - switch (setting) { - case Conversation.NotifySetting.DEFAULT: - return "default"; - case Conversation.NotifySetting.ON: - return "on"; - case Conversation.NotifySetting.OFF: - return "off"; - case Conversation.NotifySetting.HIGHLIGHT: - return "highlight"; - } - assert_not_reached(); - } - private ComboBoxText get_combobox(bool default_val) { ComboBoxText combobox = new ComboBoxText(); combobox = new ComboBoxText(); diff --git a/main/src/ui/conversation_details.vala b/main/src/ui/conversation_details.vala new file mode 100644 index 00000000..70c8ce6d --- /dev/null +++ b/main/src/ui/conversation_details.vala @@ -0,0 +1,188 @@ +using Dino.Entities; +using Xmpp; +using Xmpp.Xep; +using Gee; +using Gtk; + +namespace Dino.Ui.ConversationDetails { + + public void populate_dialog(Model.ConversationDetails model, Conversation conversation, StreamInteractor stream_interactor) { + model.conversation = conversation; + model.display_name = stream_interactor.get_module(ContactModels.IDENTITY).get_display_name_model(conversation); + model.blocked = stream_interactor.get_module(BlockingManager.IDENTITY).is_blocked(model.conversation.account, model.conversation.counterpart); + + if (conversation.type_ == Conversation.Type.GROUPCHAT) { + stream_interactor.get_module(MucManager.IDENTITY).get_config_form.begin(conversation.account, conversation.counterpart, (_, res) => { + model.data_form = stream_interactor.get_module(MucManager.IDENTITY).get_config_form.end(res); + model.data_form_bak = model.data_form.stanza_node.to_string(); + }); + } + } + + public void bind_dialog(Model.ConversationDetails model, ViewModel.ConversationDetails view_model, StreamInteractor stream_interactor) { + view_model.avatar = new ViewModel.CompatAvatarPictureModel(stream_interactor).set_conversation(model.conversation); + view_model.show_blocked = model.conversation.type_ == Conversation.Type.CHAT && stream_interactor.get_module(BlockingManager.IDENTITY).is_supported(model.conversation.account); + + model.display_name.bind_property("display-name", view_model, "name", BindingFlags.SYNC_CREATE); + model.conversation.bind_property("notify-setting", view_model, "notification", BindingFlags.SYNC_CREATE, (_, from, ref to) => { + switch (model.conversation.get_notification_setting(stream_interactor)) { + case Conversation.NotifySetting.ON: + to = ViewModel.ConversationDetails.NotificationSetting.ON; + break; + case Conversation.NotifySetting.OFF: + to = ViewModel.ConversationDetails.NotificationSetting.OFF; + break; + case Conversation.NotifySetting.HIGHLIGHT: + to = ViewModel.ConversationDetails.NotificationSetting.HIGHLIGHT; + break; + } + return true; + }); + model.conversation.bind_property("notify-setting", view_model, "notification-is-default", BindingFlags.SYNC_CREATE, (_, from, ref to) => { + var notify_setting = (Conversation.NotifySetting) from; + to = notify_setting == Conversation.NotifySetting.DEFAULT; + return true; + }); + model.conversation.bind_property("pinned", view_model, "pinned", BindingFlags.SYNC_CREATE, (_, from, ref to) => { + var from_int = (int) from; + to = from_int > 0; + return true; + }); + model.conversation.bind_property("type-", view_model, "notification-options", BindingFlags.SYNC_CREATE, (_, from, ref to) => { + var ty = (Conversation.Type) from; + to = ty == Conversation.Type.GROUPCHAT ? ViewModel.ConversationDetails.NotificationOptions.ON_HIGHLIGHT_OFF : ViewModel.ConversationDetails.NotificationOptions.ON_OFF; + return true; + }); + model.bind_property("blocked", view_model, "blocked", BindingFlags.SYNC_CREATE); + model.bind_property("data-form", view_model, "room-configuration-rows", BindingFlags.SYNC_CREATE, (_, from, ref to) => { + var data_form = (DataForms.DataForm) from; + if (data_form == null) return true; + var list_store = new GLib.ListStore(typeof(ViewModel.PreferencesRow.Any)); + + foreach (var field in data_form.fields) { + var field_view_model = Util.get_data_form_field_view_model(field); + if (field_view_model != null) { + list_store.append(field_view_model); + } + } + + to = list_store; + return true; + }); + + view_model.pin_changed.connect(() => { + model.conversation.pinned = model.conversation.pinned == 1 ? 0 : 1; + }); + view_model.block_changed.connect(() => { + if (view_model.blocked) { + stream_interactor.get_module(BlockingManager.IDENTITY).unblock(model.conversation.account, model.conversation.counterpart); + } else { + stream_interactor.get_module(BlockingManager.IDENTITY).block(model.conversation.account, model.conversation.counterpart); + } + view_model.blocked = !view_model.blocked; + }); + view_model.notification_changed.connect((setting) => { + switch (setting) { + case ON: + model.conversation.notify_setting = ON; + break; + case OFF: + model.conversation.notify_setting = OFF; + break; + case HIGHLIGHT: + model.conversation.notify_setting = HIGHLIGHT; + break; + case DEFAULT: + model.conversation.notify_setting = DEFAULT; + break; + } + }); + + view_model.notification_flipped.connect(() => { + model.conversation.notify_setting = view_model.notification == ON ? Conversation.NotifySetting.OFF : Conversation.NotifySetting.ON; + }); + } + + public Window setup_dialog(Conversation conversation, StreamInteractor stream_interactor, Window parent) { + var dialog = new Dialog() { transient_for = parent }; + var model = new Model.ConversationDetails(); + populate_dialog(model, conversation, stream_interactor); + bind_dialog(model, dialog.model, stream_interactor); + + dialog.model.about_rows.append(new ViewModel.PreferencesRow.Text() { + title = _("XMPP Address"), + text = conversation.counterpart.to_string() + }); + if (model.conversation.type_ == Conversation.Type.CHAT) { + var about_row = new ViewModel.PreferencesRow.Entry() { + title = _("Display name"), + text = dialog.model.name + }; + about_row.changed.connect(() => { + if (about_row.text != Util.get_conversation_display_name(stream_interactor, conversation)) { + stream_interactor.get_module(RosterManager.IDENTITY).set_jid_handle(conversation.account, conversation.counterpart, about_row.text); + } + }); + dialog.model.about_rows.append(about_row); + } + if (model.conversation.type_ == Conversation.Type.GROUPCHAT) { + var topic = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account); + if (topic != null && topic != "") { + dialog.model.about_rows.append(new ViewModel.PreferencesRow.Text() { + title = _("Topic"), + text = Util.parse_add_markup(topic, null, true, true) + }); + } + } + dialog.close_request.connect(() => { + // Only send the config form if something was changed + if (model.data_form_bak != null && model.data_form_bak != model.data_form.stanza_node.to_string()) { + stream_interactor.get_module(MucManager.IDENTITY).set_config_form.begin(conversation.account, conversation.counterpart, model.data_form); + } + return false; + }); + + Plugins.ContactDetails contact_details = new Plugins.ContactDetails(); + contact_details.add.connect((c, l, d, wo) => { + add_entry(c, l, d, wo, dialog); + }); + Application app = GLib.Application.get_default() as Application; + app.plugin_registry.register_contact_details_entry(new ContactDetails.SettingsProvider(stream_interactor)); + app.plugin_registry.register_contact_details_entry(new ContactDetails.PermissionsProvider(stream_interactor)); + + foreach (Plugins.ContactDetailsProvider provider in app.plugin_registry.contact_details_entries) { + provider.populate(conversation, contact_details, Plugins.WidgetType.GTK4); + } + + return dialog; + } + + private void add_entry(string category, string label, string? description, Object wo, Dialog dialog) { + if (!(wo is Widget)) return; + + Widget widget = (Widget) wo; + if (widget.get_type().is_a(typeof(Entry))) { + Util.EntryLabelHybrid hybrid = new Util.EntryLabelHybrid.wrap(widget as Entry) { xalign=1 }; + widget = hybrid; + } else if (widget.get_type().is_a(typeof(ComboBoxText))) { + Util.ComboBoxTextLabelHybrid hybrid = new Util.ComboBoxTextLabelHybrid.wrap(widget as ComboBoxText) { xalign=1 }; + widget = hybrid; + } + + var view_model = new ViewModel.PreferencesRow.WidgetDeprecated() { + title = label, + widget = widget + }; + + switch (category) { + case "Encryption": + dialog.model.encryption_rows.append(view_model); + break; + case "Permissions": + case "Local Settings": + case "Settings": + dialog.model.settings_rows.append(view_model); + break; + } + } +} \ No newline at end of file diff --git a/main/src/ui/conversation_titlebar/menu_entry.vala b/main/src/ui/conversation_titlebar/menu_entry.vala index d0b9fbcd..479a228c 100644 --- a/main/src/ui/conversation_titlebar/menu_entry.vala +++ b/main/src/ui/conversation_titlebar/menu_entry.vala @@ -34,9 +34,8 @@ class MenuEntry : Plugins.ConversationTitlebarEntry, Object { } private void on_clicked() { - ContactDetails.Dialog contact_details_dialog = new ContactDetails.Dialog(stream_interactor, conversation); - contact_details_dialog.set_transient_for((Window) button.get_root()); - contact_details_dialog.present(); + var conversation_details = ConversationDetails.setup_dialog(conversation, stream_interactor, (Window)button.get_root()); + conversation_details.present(); } public Object? get_widget(Plugins.WidgetType type) { diff --git a/main/src/ui/util/data_forms.vala b/main/src/ui/util/data_forms.vala index 1f598025..d10196ab 100644 --- a/main/src/ui/util/data_forms.vala +++ b/main/src/ui/util/data_forms.vala @@ -6,6 +6,100 @@ using Xmpp.Xep; namespace Dino.Ui.Util { +public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataForms.DataForm.Field field) { + if (field.type_ == null) return null; + + ViewModel.PreferencesRow.Any? view_model = null; + + string? label = null; + string? desc = null; + + if (field.var != null) { + switch (field.var) { + case "muc#roomconfig_roomname": + label = _("Name of the room"); + break; + case "muc#roomconfig_roomdesc": + label = _("Description of the room"); + break; + case "muc#roomconfig_persistentroom": + label = _("Persistent"); + desc = _("The room will persist after the last occupant leaves"); + break; + case "muc#roomconfig_publicroom": + label = _("Publicly searchable"); + break; + case "muc#roomconfig_changesubject": + label = _("Occupants may change the subject"); + break; + case "muc#roomconfig_whois": + label = _("Permission to view JIDs"); + desc = _("Who is allowed to view the occupants' JIDs?"); + break; + case "muc#roomconfig_roomsecret": + label = _("Password"); +// desc = _("A password to restrict access to the room"); + break; + case "muc#roomconfig_moderatedroom": + label = _("Moderated"); + desc = _("Only occupants with voice may send messages"); + break; + case "muc#roomconfig_membersonly": + label = _("Members only"); + desc = _("Only members may enter the room"); + break; +// case "muc#roomconfig_historylength": +// label = _("Message history"); +// desc = _("Maximum amount of backlog issued by the room"); +// break; + } + } + + if (label == null) label = field.label; + + switch (field.type_) { + case DataForms.DataForm.Type.BOOLEAN: + DataForms.DataForm.BooleanField boolean_field = field as DataForms.DataForm.BooleanField; + var toggle_model = new ViewModel.PreferencesRow.Toggle() { subtitle = desc, state = boolean_field.value }; + boolean_field.bind_property("value", toggle_model, "state", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + view_model = toggle_model; + break; + case DataForms.DataForm.Type.JID_MULTI: + return null; + case DataForms.DataForm.Type.LIST_SINGLE: + DataForms.DataForm.ListSingleField list_single_field = field as DataForms.DataForm.ListSingleField; + var combobox_model = new ViewModel.PreferencesRow.ComboBox(); + for (int i = 0; i < list_single_field.options.size; i++) { + DataForms.DataForm.Option option = list_single_field.options[i]; + combobox_model.items.add(option.label); + if (option.value == list_single_field.value) combobox_model.active_item = i; + } + combobox_model.bind_property("active-item", list_single_field, "value", BindingFlags.DEFAULT, (binding, from, ref to) => { + var src_field = (DataForms.DataForm.ListSingleField) binding.dup_target(); + var active_item = (int) from; + to = list_single_field.options[active_item].value; + return true; + }); + view_model = combobox_model; + break; + case DataForms.DataForm.Type.LIST_MULTI: + return null; + case DataForms.DataForm.Type.TEXT_PRIVATE: + return null; + case DataForms.DataForm.Type.TEXT_SINGLE: + DataForms.DataForm.TextSingleField text_single_field = field as DataForms.DataForm.TextSingleField; + var entry_model = new ViewModel.PreferencesRow.Entry() { text = text_single_field.value }; + text_single_field.bind_property("value", entry_model, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + view_model = entry_model; + break; + default: + return null; + } + + view_model.title = label; + return view_model; +} + public static Widget? get_data_form_field_widget(DataForms.DataForm.Field field) { if (field.type_ == null) return null; switch (field.type_) { diff --git a/main/src/view_model/conversation_details.vala b/main/src/view_model/conversation_details.vala new file mode 100644 index 00000000..15bf7535 --- /dev/null +++ b/main/src/view_model/conversation_details.vala @@ -0,0 +1,49 @@ +using Dino.Entities; +using Xmpp; +using Xmpp.Xep; +using Gee; +using Gtk; + +public class Dino.Ui.ViewModel.ConversationDetails : Object { + public signal void pin_changed(); + public signal void block_changed(); + public signal void notification_flipped(); + public signal void notification_changed(NotificationSetting setting); + + public enum NotificationOptions { + ON_OFF, + ON_HIGHLIGHT_OFF + } + + public enum NotificationSetting { + DEFAULT, + ON, + HIGHLIGHT, + OFF + } + + public ViewModel.CompatAvatarPictureModel avatar { get; set; } + public string name { get; set; } + public bool pinned { get; set; } + + public NotificationSetting notification { get; set; } + public NotificationOptions notification_options { get; set; } + public bool notification_is_default { get; set; } + + public bool show_blocked { get; set; } + public bool blocked { get; set; } + + public GLib.ListStore preferences_rows = new GLib.ListStore(typeof(PreferencesRow.Any)); + public GLib.ListStore about_rows = new GLib.ListStore(typeof(PreferencesRow.Any)); + public GLib.ListStore encryption_rows = new GLib.ListStore(typeof(PreferencesRow.Any)); + public GLib.ListStore settings_rows = new GLib.ListStore(typeof(PreferencesRow.Any)); + public GLib.ListStore room_configuration_rows { get; set; } +} + +public class Dino.Ui.Model.ConversationDetails : Object { + public Conversation conversation { get; set; } + public Dino.Model.ConversationDisplayName display_name { get; set; } + public DataForms.DataForm? data_form { get; set; } + public string? data_form_bak; + public bool blocked { get; set; } +} \ No newline at end of file diff --git a/main/src/view_model/preferences_row.vala b/main/src/view_model/preferences_row.vala new file mode 100644 index 00000000..3a04ee1e --- /dev/null +++ b/main/src/view_model/preferences_row.vala @@ -0,0 +1,34 @@ +using Dino.Entities; +using Xmpp; +using Xmpp.Xep; +using Gee; +using Gtk; + +namespace Dino.Ui.ViewModel.PreferencesRow { + public abstract class Any : Object { + public string title { get; set; } + } + + public class Text : Any { + public string text { get; set; } + } + + public class Entry : Any { + public signal void changed(); + public string text { get; set; } + } + + public class Toggle : Any { + public string subtitle { get; set; } + public bool state { get; set; } + } + + public class ComboBox : Any { + public Gee.List items = new ArrayList(); + public int active_item { get; set; } + } + + public class WidgetDeprecated : Any { + public Widget widget; + } +} \ No newline at end of file diff --git a/main/src/windows/conversation_details.vala b/main/src/windows/conversation_details.vala new file mode 100644 index 00000000..6fb66a1c --- /dev/null +++ b/main/src/windows/conversation_details.vala @@ -0,0 +1,227 @@ +using Dino.Entities; +using Xmpp; +using Xmpp.Xep; +using Gee; +using Gtk; + +namespace Dino.Ui.ConversationDetails { + + [GtkTemplate (ui = "/im/dino/Dino/conversation_details.ui")] + public class Dialog : Adw.Window { + [GtkChild] public unowned Box about_box; + [GtkChild] public unowned Button pin_button; + [GtkChild] public unowned Adw.ButtonContent pin_button_content; + [GtkChild] public unowned Button block_button; + [GtkChild] public unowned Adw.ButtonContent block_button_content; + [GtkChild] public unowned Button notification_button_toggle; + [GtkChild] public unowned Adw.ButtonContent notification_button_toggle_content; + [GtkChild] public unowned MenuButton notification_button_menu; + [GtkChild] public unowned Adw.ButtonContent notification_button_menu_content; + [GtkChild] public unowned Adw.SplitButton notification_button_split; + [GtkChild] public unowned Adw.ButtonContent notification_button_split_content; + + [GtkChild] public unowned ViewModel.ConversationDetails model { get; } + + class construct { + install_action("notification.on", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.ON); } ); + install_action("notification.off", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.OFF); } ); + install_action("notification.highlight", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.HIGHLIGHT); } ); + install_action("notification.default", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.DEFAULT); } ); + } + + construct { + pin_button.clicked.connect(() => { model.pin_changed(); }); + block_button.clicked.connect(() => { model.block_changed(); }); + notification_button_toggle.clicked.connect(() => { model.notification_flipped(); }); + notification_button_split.clicked.connect(() => { model.notification_flipped(); }); + + model.notify["pinned"].connect(update_pinned_button); + model.notify["blocked"].connect(update_blocked_button); + model.notify["notification"].connect(update_notification_button); + model.notify["notification"].connect(update_notification_button_state); + model.notify["notification-options"].connect(update_notification_button_visibility); + model.notify["notification-is-default"].connect(update_notification_button_visibility); + + model.about_rows.items_changed.connect(create_preferences_rows); + model.encryption_rows.items_changed.connect(create_preferences_rows); + model.settings_rows.items_changed.connect(create_preferences_rows); + model.notify["room-configuration-rows"].connect(create_preferences_rows); + } + + private void update_pinned_button() { + pin_button_content.icon_name = "view-pin-symbolic"; + pin_button_content.label = model.pinned ? _("Pinned") : _("Pin"); + if (model.pinned) { + pin_button.add_css_class("accent"); + } else { + pin_button.remove_css_class("accent"); + } + } + + private void update_blocked_button() { + block_button_content.icon_name = "action-unavailable-symbolic"; + block_button_content.label = model.blocked ? _("Blocked") : _("Block"); + if (model.blocked) { + block_button.add_css_class("error"); + } else { + block_button.remove_css_class("error"); + } + } + + private void update_notification_button() { + string icon_name = model.notification == OFF ? + "notifications-disabled-symbolic" : "notification-symbolic"; + notification_button_toggle_content.icon_name = icon_name; + notification_button_split_content.icon_name = icon_name; + notification_button_menu_content.icon_name = icon_name; + } + + private void update_notification_button_state() { + switch (model.notification) { + case ON: + notification_button_toggle_content.label = _("Mute"); + notification_button_split_content.label = _("Mute"); + notification_button_menu_content.label = _("Notifications enabled"); + break; + case HIGHLIGHT: + notification_button_menu_content.label = _("Notifications for mentions"); + break; + case OFF: + notification_button_toggle_content.label = _("Muted"); + notification_button_split_content.label = _("Muted"); + notification_button_menu_content.label = _("Notifications disabled"); + break; + } + } + + private void update_notification_button_visibility() { + notification_button_toggle.visible = notification_button_menu.visible = notification_button_split.visible = false; + + if (model.notification_options == ON_OFF) { + if (model.notification_is_default) { + notification_button_toggle.visible = true; + } else { + notification_button_split.visible = true; + } + } else { + notification_button_menu.visible = true; + } + } + + private void create_preferences_rows() { + var widget = about_box.get_first_child(); + while (widget != null) { + about_box.remove(widget); + widget = about_box.get_first_child(); + } + + if (model.about_rows.get_n_items() > 0) { + about_box.append(rows_to_preference_group(model.about_rows, _("About"))); + } + if (model.encryption_rows.get_n_items() > 0) { + about_box.append(rows_to_preference_group(model.encryption_rows, _("Encryption"))); + } + if (model.settings_rows.get_n_items() > 0) { + about_box.append(rows_to_preference_group(model.settings_rows, _("Settings"))); + } + if (model.room_configuration_rows != null && model.room_configuration_rows.get_n_items() > 0) { + about_box.append(rows_to_preference_group(model.room_configuration_rows, _("Room Configuration"))); + } + } + + private Adw.PreferencesGroup rows_to_preference_group(GLib.ListStore row_view_models, string title) { + var preference_group = new Adw.PreferencesGroup() { title=title }; + + for (int preference_group_i = 0; preference_group_i < row_view_models.get_n_items(); preference_group_i++) { + var preferences_row = (ViewModel.PreferencesRow.Any) row_view_models.get_item(preference_group_i); + + Widget? w = null; + + var entry_view_model = preferences_row as ViewModel.PreferencesRow.Entry; + if (entry_view_model != null) { +#if Adw_1_2 + Adw.EntryRow view = new Adw.EntryRow() { title = entry_view_model.title, show_apply_button=true }; + entry_view_model.bind_property("text", view, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, (_, from, ref to) => { + var str = (string) from; + to = str ?? ""; + return true; + }); + view.apply.connect(() => { + entry_view_model.changed(); + }); +#else + var view = new Adw.ActionRow() { title = entry_view_model.title }; + var entry = new Entry() { text=entry_view_model.text, valign=Align.CENTER }; + entry_view_model.bind_property("text", entry, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + entry.changed.connect(() => { + entry_view_model.changed(); + }); + view.activatable_widget = entry; + view.add_suffix(entry); +#endif + w = view; + } + + var row_text = preferences_row as ViewModel.PreferencesRow.Text; + if (row_text != null) { + w = new Adw.ActionRow() { + title = row_text.title, + subtitle = row_text.text, +#if Adw_1_3 + subtitle_selectable = true +#endif + }; + w.add_css_class("property"); + + Util.force_css(w, "row.property > box.header > box.title > .title { font-weight: 400; font-size: 9pt; opacity: 0.55; }"); + Util.force_css(w, "row.property > box.header > box.title > .subtitle { font-size: inherit; opacity: 1; }"); + } + + var toggle_view_model = preferences_row as ViewModel.PreferencesRow.Toggle; + if (toggle_view_model != null) { + var view = new Adw.ActionRow() { title = toggle_view_model.title, subtitle = toggle_view_model.subtitle }; + var toggle = new Switch() { valign = Align.CENTER }; + view.activatable_widget = toggle; + view.add_suffix(toggle); + toggle_view_model.bind_property("state", toggle, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + w = view; + } + + var combobox_view_model = preferences_row as ViewModel.PreferencesRow.ComboBox; + if (combobox_view_model != null) { + var string_list = new StringList(null); + foreach (string text in combobox_view_model.items) { + string_list.append(text); + } +#if Adw_1_4 + var view = new Adw.ComboRow() { title = combobox_view_model.title }; + view.model = string_list; + combobox_view_model.bind_property("active-item", view, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); +#else + var view = new Adw.ActionRow() { title = combobox_view_model.title }; + var drop_down = new DropDown(string_list, null) { valign = Align.CENTER }; + combobox_view_model.bind_property("active-item", drop_down, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + view.activatable_widget = drop_down; + view.add_suffix(drop_down); +#endif + w = view; + } + + var widget_view_model = preferences_row as ViewModel.PreferencesRow.WidgetDeprecated; + if (widget_view_model != null) { + var view = new Adw.ActionRow() { title = widget_view_model.title }; + view.add_suffix(widget_view_model.widget); + w = view; + } + + if (w == null) { + continue; + } + + preference_group.add(w); + } + + return preference_group; + } + } +} \ No newline at end of file diff --git a/xmpp-vala/src/module/xep/0004_data_forms.vala b/xmpp-vala/src/module/xep/0004_data_forms.vala index fe39874a..6b5624da 100644 --- a/xmpp-vala/src/module/xep/0004_data_forms.vala +++ b/xmpp-vala/src/module/xep/0004_data_forms.vala @@ -38,7 +38,7 @@ public class DataForm { } } - public class Field { + public class Field : Object { public StanzaNode node { get; set; } public string? label { get { return node.get_attribute("label", NS_URI); } -- cgit v1.2.3-54-g00ecf From c2efb214afa9f712c7ac112899c7d9b730e10de0 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 25 Sep 2023 15:02:03 +0200 Subject: conversation details: Fix for libadwaita < 1.4 --- main/data/conversation_details.ui | 1 - main/src/windows/conversation_details.vala | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main/data/conversation_details.ui b/main/data/conversation_details.ui index 1347ad2b..4229d875 100644 --- a/main/data/conversation_details.ui +++ b/main/data/conversation_details.ui @@ -99,7 +99,6 @@ notification-symbolic Mute - True diff --git a/main/src/windows/conversation_details.vala b/main/src/windows/conversation_details.vala index 6fb66a1c..099412d1 100644 --- a/main/src/windows/conversation_details.vala +++ b/main/src/windows/conversation_details.vala @@ -46,6 +46,11 @@ namespace Dino.Ui.ConversationDetails { model.encryption_rows.items_changed.connect(create_preferences_rows); model.settings_rows.items_changed.connect(create_preferences_rows); model.notify["room-configuration-rows"].connect(create_preferences_rows); + +#if Adw_1_4 + // TODO: replace with putting buttons in new line on small screens + notification_button_menu_content.can_shrink = true; +#endif } private void update_pinned_button() { -- cgit v1.2.3-54-g00ecf From dd0038f5e2916b21f58d83dabe9675994635e41f Mon Sep 17 00:00:00 2001 From: hrxi Date: Tue, 20 Jun 2023 20:42:11 +0200 Subject: Fix every inclusion of `gpgme_fix.h` getting their own mutex --- plugins/gpgme-vala/src/gpgme_fix.c | 4 ++-- plugins/gpgme-vala/src/gpgme_fix.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/gpgme-vala/src/gpgme_fix.c b/plugins/gpgme-vala/src/gpgme_fix.c index 2bc139e9..bf457a6c 100644 --- a/plugins/gpgme-vala/src/gpgme_fix.c +++ b/plugins/gpgme-vala/src/gpgme_fix.c @@ -1,6 +1,6 @@ #include -static GRecMutex gpgme_global_mutex = {0}; +GRecMutex gpgme_global_mutex = {0}; gpgme_key_t gpgme_key_ref_vapi (gpgme_key_t key) { gpgme_key_ref(key); @@ -9,4 +9,4 @@ gpgme_key_t gpgme_key_ref_vapi (gpgme_key_t key) { gpgme_key_t gpgme_key_unref_vapi (gpgme_key_t key) { gpgme_key_unref(key); return key; -} \ No newline at end of file +} diff --git a/plugins/gpgme-vala/src/gpgme_fix.h b/plugins/gpgme-vala/src/gpgme_fix.h index 3daa7db0..714614fc 100644 --- a/plugins/gpgme-vala/src/gpgme_fix.h +++ b/plugins/gpgme-vala/src/gpgme_fix.h @@ -4,9 +4,9 @@ #include #include -static GRecMutex gpgme_global_mutex; +extern GRecMutex gpgme_global_mutex; gpgme_key_t gpgme_key_ref_vapi (gpgme_key_t key); gpgme_key_t gpgme_key_unref_vapi (gpgme_key_t key); -#endif \ No newline at end of file +#endif -- cgit v1.2.3-54-g00ecf From e2d801b5f74b60c38a75310066c48468c8a4bc93 Mon Sep 17 00:00:00 2001 From: hrxi Date: Sun, 4 Jun 2023 09:24:16 +0200 Subject: Merge `gpgme-vala` into `openpgp` plugin There's no reason for it to be a statically linked library anymore, it can be directly compiled into the plugin. --- plugins/CMakeLists.txt | 3 - plugins/gpgme-vala/CMakeLists.txt | 52 --- plugins/gpgme-vala/src/gpgme_fix.c | 12 - plugins/gpgme-vala/src/gpgme_fix.h | 12 - plugins/gpgme-vala/src/gpgme_helper.vala | 184 -------- plugins/gpgme-vala/vapi/gpg-error.vapi | 451 -------------------- plugins/gpgme-vala/vapi/gpgme.deps | 1 - plugins/gpgme-vala/vapi/gpgme.vapi | 519 ----------------------- plugins/gpgme-vala/vapi/gpgme_public.vapi | 162 ------- plugins/openpgp/CMakeLists.txt | 12 +- plugins/openpgp/src/gpgme_fix.c | 12 + plugins/openpgp/src/gpgme_fix.h | 12 + plugins/openpgp/src/gpgme_helper.vala | 184 ++++++++ plugins/openpgp/vapi/gpg-error.vapi | 445 ++++++++++++++++++++ plugins/openpgp/vapi/gpgme.vapi | 673 ++++++++++++++++++++++++++++++ 15 files changed, 1335 insertions(+), 1399 deletions(-) delete mode 100644 plugins/gpgme-vala/CMakeLists.txt delete mode 100644 plugins/gpgme-vala/src/gpgme_fix.c delete mode 100644 plugins/gpgme-vala/src/gpgme_fix.h delete mode 100644 plugins/gpgme-vala/src/gpgme_helper.vala delete mode 100644 plugins/gpgme-vala/vapi/gpg-error.vapi delete mode 100644 plugins/gpgme-vala/vapi/gpgme.deps delete mode 100644 plugins/gpgme-vala/vapi/gpgme.vapi delete mode 100644 plugins/gpgme-vala/vapi/gpgme_public.vapi create mode 100644 plugins/openpgp/src/gpgme_fix.c create mode 100644 plugins/openpgp/src/gpgme_fix.h create mode 100644 plugins/openpgp/src/gpgme_helper.vala create mode 100644 plugins/openpgp/vapi/gpg-error.vapi create mode 100644 plugins/openpgp/vapi/gpgme.vapi diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 4322232b..3ce96815 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -2,8 +2,5 @@ foreach(plugin ${PLUGINS}) if ("omemo" STREQUAL ${plugin}) add_subdirectory(signal-protocol) endif () - if ("openpgp" STREQUAL ${plugin}) - add_subdirectory(gpgme-vala) - endif () add_subdirectory(${plugin}) endforeach(plugin) diff --git a/plugins/gpgme-vala/CMakeLists.txt b/plugins/gpgme-vala/CMakeLists.txt deleted file mode 100644 index 5255bac4..00000000 --- a/plugins/gpgme-vala/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -find_package(GPGME REQUIRED) -find_packages(GPGME_VALA_PACKAGES REQUIRED - Gee - GLib - GObject -) - -vala_precompile(GPGME_VALA_C -SOURCES - "src/gpgme_helper.vala" -CUSTOM_VAPIS - "${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme.vapi" - "${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme_public.vapi" - "${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpg-error.vapi" -PACKAGES - ${GPGME_VALA_PACKAGES} -GENERATE_VAPI - gpgme-vala -GENERATE_HEADER - gpgme-vala -) - -add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/gpgme_fix.h" -COMMAND - cp "${CMAKE_CURRENT_SOURCE_DIR}/src/gpgme_fix.h" "${CMAKE_BINARY_DIR}/exports/gpgme_fix.h" -DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/src/gpgme_fix.h" -COMMENT - Copy header file gpgme_fix.h -) - -add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/exports/gpgme.vapi -COMMAND - cat "${CMAKE_BINARY_DIR}/exports/gpgme-vala.vapi" "${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme_public.vapi" > "${CMAKE_BINARY_DIR}/exports/gpgme.vapi" -DEPENDS - ${CMAKE_BINARY_DIR}/exports/gpgme-vala.vapi - ${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme_public.vapi -) - -add_custom_target(gpgme-vapi -DEPENDS - ${CMAKE_BINARY_DIR}/exports/gpgme_fix.h - ${CMAKE_BINARY_DIR}/exports/gpgme.vapi -) - -set(CFLAGS ${VALA_CFLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/src) -add_definitions(${CFLAGS}) -add_library(gpgme-vala STATIC ${GPGME_VALA_C} src/gpgme_fix.c) -add_dependencies(gpgme-vala gpgme-vapi) -target_link_libraries(gpgme-vala ${GPGME_VALA_PACKAGES} gpgme) -set_property(TARGET gpgme-vala PROPERTY POSITION_INDEPENDENT_CODE ON) - diff --git a/plugins/gpgme-vala/src/gpgme_fix.c b/plugins/gpgme-vala/src/gpgme_fix.c deleted file mode 100644 index bf457a6c..00000000 --- a/plugins/gpgme-vala/src/gpgme_fix.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -GRecMutex gpgme_global_mutex = {0}; - -gpgme_key_t gpgme_key_ref_vapi (gpgme_key_t key) { - gpgme_key_ref(key); - return key; -} -gpgme_key_t gpgme_key_unref_vapi (gpgme_key_t key) { - gpgme_key_unref(key); - return key; -} diff --git a/plugins/gpgme-vala/src/gpgme_fix.h b/plugins/gpgme-vala/src/gpgme_fix.h deleted file mode 100644 index 714614fc..00000000 --- a/plugins/gpgme-vala/src/gpgme_fix.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef GPGME_FIX -#define GPGME_FIX 1 - -#include -#include - -extern GRecMutex gpgme_global_mutex; - -gpgme_key_t gpgme_key_ref_vapi (gpgme_key_t key); -gpgme_key_t gpgme_key_unref_vapi (gpgme_key_t key); - -#endif diff --git a/plugins/gpgme-vala/src/gpgme_helper.vala b/plugins/gpgme-vala/src/gpgme_helper.vala deleted file mode 100644 index f28bc6d6..00000000 --- a/plugins/gpgme-vala/src/gpgme_helper.vala +++ /dev/null @@ -1,184 +0,0 @@ -using Gee; -using GPG; - -namespace GPGHelper { - -private static bool initialized = false; - -public static string encrypt_armor(string plain, Key[] keys, EncryptFlags flags) throws GLib.Error { - global_mutex.lock(); - try { - initialize(); - Data plain_data = Data.create_from_memory(plain.data, false); - Context context = Context.create(); - context.set_armor(true); - Data enc_data = context.op_encrypt(keys, flags, plain_data); - return get_string_from_data(enc_data); - } finally { - global_mutex.unlock(); - } -} - -public static uint8[] encrypt_file(string uri, Key[] keys, EncryptFlags flags, string file_name) throws GLib.Error { - global_mutex.lock(); - try { - initialize(); - Data plain_data = Data.create_from_file(uri); - plain_data.set_file_name(file_name); - Context context = Context.create(); - context.set_armor(true); - Data enc_data = context.op_encrypt(keys, flags, plain_data); - return get_uint8_from_data(enc_data); - } finally { - global_mutex.unlock(); - } -} - -public static string decrypt(string encr) throws GLib.Error { - global_mutex.lock(); - try { - initialize(); - Data enc_data = Data.create_from_memory(encr.data, false); - Context context = Context.create(); - Data dec_data = context.op_decrypt(enc_data); - return get_string_from_data(dec_data); - } finally { - global_mutex.unlock(); - } -} - -public class DecryptedData { - public uint8[] data { get; set; } - public string filename { get; set; } -} - -public static DecryptedData decrypt_data(uint8[] data) throws GLib.Error { - global_mutex.lock(); - try { - initialize(); - Data enc_data = Data.create_from_memory(data, false); - Context context = Context.create(); - Data dec_data = context.op_decrypt(enc_data); - DecryptResult* dec_res = context.op_decrypt_result(); - return new DecryptedData() { data=get_uint8_from_data(dec_data), filename=dec_res->file_name}; - } finally { - global_mutex.unlock(); - } -} - -public static string sign(string plain, SigMode mode, Key? key = null) throws GLib.Error { - global_mutex.lock(); - try { - initialize(); - Data plain_data = Data.create_from_memory(plain.data, false); - Context context = Context.create(); - if (key != null) context.signers_add(key); - Data signed_data = context.op_sign(plain_data, mode); - return get_string_from_data(signed_data); - } finally { - global_mutex.unlock(); - } -} - -public static string? get_sign_key(string signature, string? text) throws GLib.Error { - global_mutex.lock(); - try { - initialize(); - Data sig_data = Data.create_from_memory(signature.data, false); - Data text_data; - if (text != null) { - text_data = Data.create_from_memory(text.data, false); - } else { - text_data = Data.create(); - } - Context context = Context.create(); - context.op_verify(sig_data, text_data); - VerifyResult* verify_res = context.op_verify_result(); - if (verify_res == null || verify_res.signatures == null) return null; - return verify_res.signatures.fpr; - } finally { - global_mutex.unlock(); - } -} - -public static Gee.List get_keylist(string? pattern = null, bool secret_only = false) throws GLib.Error { - global_mutex.lock(); - try { - initialize(); - - Gee.List keys = new ArrayList(); - Context context = Context.create(); - context.op_keylist_start(pattern, secret_only ? 1 : 0); - try { - while (true) { - Key key = context.op_keylist_next(); - keys.add(key); - } - } catch (Error e) { - if (e.code != GPGError.ErrorCode.EOF) throw e; - } - return keys; - } finally { - global_mutex.unlock(); - } -} - -public static Key? get_public_key(string sig) throws GLib.Error { - return get_key(sig, false); -} - -public static Key? get_private_key(string sig) throws GLib.Error { - return get_key(sig, true); -} - -private static Key? get_key(string sig, bool priv) throws GLib.Error { - global_mutex.lock(); - try { - initialize(); - Context context = Context.create(); - Key key = context.get_key(sig, priv); - return key; - } finally { - global_mutex.unlock(); - } -} - -private static string get_string_from_data(Data data) { - const size_t BUF_SIZE = 256; - data.seek(0); - uint8[] buf = new uint8[BUF_SIZE + 1]; - ssize_t len = 0; - string res = ""; - do { - len = data.read(buf, BUF_SIZE); - if (len > 0) { - buf[len] = 0; - res += (string) buf; - } - } while (len > 0); - return res; -} - -private static uint8[] get_uint8_from_data(Data data) { - const size_t BUF_SIZE = 256; - data.seek(0); - uint8[] buf = new uint8[BUF_SIZE + 1]; - ssize_t len = 0; - ByteArray res = new ByteArray(); - do { - len = data.read(buf, BUF_SIZE); - if (len > 0) { - res.append(buf[0:len]); - } - } while (len > 0); - return res.data; -} - -private static void initialize() { - if (!initialized) { - check_version(); - initialized = true; - } -} - -} diff --git a/plugins/gpgme-vala/vapi/gpg-error.vapi b/plugins/gpgme-vala/vapi/gpg-error.vapi deleted file mode 100644 index 2c915c8a..00000000 --- a/plugins/gpgme-vala/vapi/gpg-error.vapi +++ /dev/null @@ -1,451 +0,0 @@ -/* gcrypt.vapi - * - * Copyright: - * 2008 Jiqing Qiang - * 2008, 2010, 2012-2013 Evan Nemerson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: - * Jiqing Qiang - * Evan Nemerson - */ - - - -[CCode (cheader_filename = "gpg-error.h")] -namespace GPGError { - [CCode (cname = "gpg_err_source_t", cprefix = "GPG_ERR_SOURCE_")] - public enum ErrorSource { - UNKNOWN, - GCRYPT, - GPG, - GPGSM, - GPGAGENT, - PINENTRY, - SCD, - GPGME, - KEYBOX, - KSBA, - DIRMNGR, - GSTI, - ANY, - USER_1, - USER_2, - USER_3, - USER_4, - - /* This is one more than the largest allowed entry. */ - DIM - } - - [CCode (cname = "gpg_err_code_t", cprefix = "GPG_ERR_")] - public enum ErrorCode { - NO_ERROR, - GENERAL, - UNKNOWN_PACKET, - UNKNOWN_VERSION, - PUBKEY_ALGO, - DIGEST_ALGO, - BAD_PUBKEY, - BAD_SECKEY, - BAD_SIGNATURE, - NO_PUBKEY, - CHECKSUM, - BAD_PASSPHRASE, - CIPHER_ALGO, - KEYRING_OPEN, - INV_PACKET, - INV_ARMOR, - NO_USER_ID, - NO_SECKEY, - WRONG_SECKEY, - BAD_KEY, - COMPR_ALGO, - NO_PRIME, - NO_ENCODING_METHOD, - NO_ENCRYPTION_SCHEME, - NO_SIGNATURE_SCHEME, - INV_ATTR, - NO_VALUE, - NOT_FOUND, - VALUE_NOT_FOUND, - SYNTAX, - BAD_MPI, - INV_PASSPHRASE, - SIG_CLASS, - RESOURCE_LIMIT, - INV_KEYRING, - TRUSTDB, - BAD_CERT, - INV_USER_ID, - UNEXPECTED, - TIME_CONFLICT, - KEYSERVER, - WRONG_PUBKEY_ALGO, - TRIBUTE_TO_D_A, - WEAK_KEY, - INV_KEYLEN, - INV_ARG, - BAD_URI, - INV_URI, - NETWORK, - UNKNOWN_HOST, - SELFTEST_FAILED, - NOT_ENCRYPTED, - NOT_PROCESSED, - UNUSABLE_PUBKEY, - UNUSABLE_SECKEY, - INV_VALUE, - BAD_CERT_CHAIN, - MISSING_CERT, - NO_DATA, - BUG, - NOT_SUPPORTED, - INV_OP, - TIMEOUT, - INTERNAL, - EOF_GCRYPT, - INV_OBJ, - TOO_SHORT, - TOO_LARGE, - NO_OBJ, - NOT_IMPLEMENTED, - CONFLICT, - INV_CIPHER_MODE, - INV_FLAG, - INV_HANDLE, - TRUNCATED, - INCOMPLETE_LINE, - INV_RESPONSE, - NO_AGENT, - AGENT, - INV_DATA, - ASSUAN_SERVER_FAULT, - ASSUAN, - INV_SESSION_KEY, - INV_SEXP, - UNSUPPORTED_ALGORITHM, - NO_PIN_ENTRY, - PIN_ENTRY, - BAD_PIN, - INV_NAME, - BAD_DATA, - INV_PARAMETER, - WRONG_CARD, - NO_DIRMNGR, - DIRMNGR, - CERT_REVOKED, - NO_CRL_KNOWN, - CRL_TOO_OLD, - LINE_TOO_LONG, - NOT_TRUSTED, - CANCELED, - BAD_CA_CERT, - CERT_EXPIRED, - CERT_TOO_YOUNG, - UNSUPPORTED_CERT, - UNKNOWN_SEXP, - UNSUPPORTED_PROTECTION, - CORRUPTED_PROTECTION, - AMBIGUOUS_NAME, - CARD, - CARD_RESET, - CARD_REMOVED, - INV_CARD, - CARD_NOT_PRESENT, - NO_PKCS15_APP, - NOT_CONFIRMED, - CONFIGURATION, - NO_POLICY_MATCH, - INV_INDEX, - INV_ID, - NO_SCDAEMON, - SCDAEMON, - UNSUPPORTED_PROTOCOL, - BAD_PIN_METHOD, - CARD_NOT_INITIALIZED, - UNSUPPORTED_OPERATION, - WRONG_KEY_USAGE, - NOTHING_FOUND, - WRONG_BLOB_TYPE, - MISSING_VALUE, - HARDWARE, - PIN_BLOCKED, - USE_CONDITIONS, - PIN_NOT_SYNCED, - INV_CRL, - BAD_BER, - INV_BER, - ELEMENT_NOT_FOUND, - IDENTIFIER_NOT_FOUND, - INV_TAG, - INV_LENGTH, - INV_KEYINFO, - UNEXPECTED_TAG, - NOT_DER_ENCODED, - NO_CMS_OBJ, - INV_CMS_OBJ, - UNKNOWN_CMS_OBJ, - UNSUPPORTED_CMS_OBJ, - UNSUPPORTED_ENCODING, - UNSUPPORTED_CMS_VERSION, - UNKNOWN_ALGORITHM, - INV_ENGINE, - PUBKEY_NOT_TRUSTED, - DECRYPT_FAILED, - KEY_EXPIRED, - SIG_EXPIRED, - ENCODING_PROBLEM, - INV_STATE, - DUP_VALUE, - MISSING_ACTION, - MODULE_NOT_FOUND, - INV_OID_STRING, - INV_TIME, - INV_CRL_OBJ, - UNSUPPORTED_CRL_VERSION, - INV_CERT_OBJ, - UNKNOWN_NAME, - LOCALE_PROBLEM, - NOT_LOCKED, - PROTOCOL_VIOLATION, - INV_MAC, - INV_REQUEST, - UNKNOWN_EXTN, - UNKNOWN_CRIT_EXTN, - LOCKED, - UNKNOWN_OPTION, - UNKNOWN_COMMAND, - BUFFER_TOO_SHORT, - SEXP_INV_LEN_SPEC, - SEXP_STRING_TOO_LONG, - SEXP_UNMATCHED_PAREN, - SEXP_NOT_CANONICAL, - SEXP_BAD_CHARACTER, - SEXP_BAD_QUOTATION, - SEXP_ZERO_PREFIX, - SEXP_NESTED_DH, - SEXP_UNMATCHED_DH, - SEXP_UNEXPECTED_PUNC, - SEXP_BAD_HEX_CHAR, - SEXP_ODD_HEX_NUMBERS, - SEXP_BAD_OCT_CHAR, - ASS_GENERAL, - ASS_ACCEPT_FAILED, - ASS_CONNECT_FAILED, - ASS_INV_RESPONSE, - ASS_INV_VALUE, - ASS_INCOMPLETE_LINE, - ASS_LINE_TOO_LONG, - ASS_NESTED_COMMANDS, - ASS_NO_DATA_CB, - ASS_NO_INQUIRE_CB, - ASS_NOT_A_SERVER, - ASS_NOT_A_CLIENT, - ASS_SERVER_START, - ASS_READ_ERROR, - ASS_WRITE_ERROR, - ASS_TOO_MUCH_DATA, - ASS_UNEXPECTED_CMD, - ASS_UNKNOWN_CMD, - ASS_SYNTAX, - ASS_CANCELED, - ASS_NO_INPUT, - ASS_NO_OUTPUT, - ASS_PARAMETER, - ASS_UNKNOWN_INQUIRE, - USER_1, - USER_2, - USER_3, - USER_4, - USER_5, - USER_6, - USER_7, - USER_8, - USER_9, - USER_10, - USER_11, - USER_12, - USER_13, - USER_14, - USER_15, - USER_16, - MISSING_ERRNO, - UNKNOWN_ERRNO, - EOF, - - E2BIG, - EACCES, - EADDRINUSE, - EADDRNOTAVAIL, - EADV, - EAFNOSUPPORT, - EAGAIN, - EALREADY, - EAUTH, - EBACKGROUND, - EBADE, - EBADF, - EBADFD, - EBADMSG, - EBADR, - EBADRPC, - EBADRQC, - EBADSLT, - EBFONT, - EBUSY, - ECANCELED, - ECHILD, - ECHRNG, - ECOMM, - ECONNABORTED, - ECONNREFUSED, - ECONNRESET, - ED, - EDEADLK, - EDEADLOCK, - EDESTADDRREQ, - EDIED, - EDOM, - EDOTDOT, - EDQUOT, - EEXIST, - EFAULT, - EFBIG, - EFTYPE, - EGRATUITOUS, - EGREGIOUS, - EHOSTDOWN, - EHOSTUNREACH, - EIDRM, - EIEIO, - EILSEQ, - EINPROGRESS, - EINTR, - EINVAL, - EIO, - EISCONN, - EISDIR, - EISNAM, - EL2HLT, - EL2NSYNC, - EL3HLT, - EL3RST, - ELIBACC, - ELIBBAD, - ELIBEXEC, - ELIBMAX, - ELIBSCN, - ELNRNG, - ELOOP, - EMEDIUMTYPE, - EMFILE, - EMLINK, - EMSGSIZE, - EMULTIHOP, - ENAMETOOLONG, - ENAVAIL, - ENEEDAUTH, - ENETDOWN, - ENETRESET, - ENETUNREACH, - ENFILE, - ENOANO, - ENOBUFS, - ENOCSI, - ENODATA, - ENODEV, - ENOENT, - ENOEXEC, - ENOLCK, - ENOLINK, - ENOMEDIUM, - ENOMEM, - ENOMSG, - ENONET, - ENOPKG, - ENOPROTOOPT, - ENOSPC, - ENOSR, - ENOSTR, - ENOSYS, - ENOTBLK, - ENOTCONN, - ENOTDIR, - ENOTEMPTY, - ENOTNAM, - ENOTSOCK, - ENOTSUP, - ENOTTY, - ENOTUNIQ, - ENXIO, - EOPNOTSUPP, - EOVERFLOW, - EPERM, - EPFNOSUPPORT, - EPIPE, - EPROCLIM, - EPROCUNAVAIL, - EPROGMISMATCH, - EPROGUNAVAIL, - EPROTO, - EPROTONOSUPPORT, - EPROTOTYPE, - ERANGE, - EREMCHG, - EREMOTE, - EREMOTEIO, - ERESTART, - EROFS, - ERPCMISMATCH, - ESHUTDOWN, - ESOCKTNOSUPPORT, - ESPIPE, - ESRCH, - ESRMNT, - ESTALE, - ESTRPIPE, - ETIME, - ETIMEDOUT, - ETOOMANYREFS, - ETXTBSY, - EUCLEAN, - EUNATCH, - EUSERS, - EWOULDBLOCK, - EXDEV, - EXFULL, - - /* This is one more than the largest allowed entry. */ - CODE_DIM - } - - [CCode (cname = "gpg_err_code_t", cprefix = "gpg_err_")] - public struct Error : uint { - [CCode (cname = "gpg_err_make")] - public Error (ErrorSource source, ErrorCode code); - [CCode (cname = "gpg_err_make_from_errno")] - public Error.from_errno (ErrorSource source, int err); - public ErrorCode code { [CCode (cname = "gpg_err_code")] get; } - public ErrorSource source { [CCode (cname = "gpg_err_source")] get; } - - [CCode (cname = "gpg_strerror")] - public unowned string to_string (); - - [CCode (cname = "gpg_strsource")] - public unowned string source_to_string (); - } -} \ No newline at end of file diff --git a/plugins/gpgme-vala/vapi/gpgme.deps b/plugins/gpgme-vala/vapi/gpgme.deps deleted file mode 100644 index a0f4f82b..00000000 --- a/plugins/gpgme-vala/vapi/gpgme.deps +++ /dev/null @@ -1 +0,0 @@ -gpg-error diff --git a/plugins/gpgme-vala/vapi/gpgme.vapi b/plugins/gpgme-vala/vapi/gpgme.vapi deleted file mode 100644 index 8723bd81..00000000 --- a/plugins/gpgme-vala/vapi/gpgme.vapi +++ /dev/null @@ -1,519 +0,0 @@ -/* libgpgme.vapi - * - * Copyright (C) 2009 Sebastian Reichel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -[CCode (lower_case_cprefix = "gpgme_", cheader_filename = "gpgme.h,gpgme_fix.h")] -namespace GPG { - public static GLib.RecMutex global_mutex; - - [CCode (cname = "struct _gpgme_engine_info")] - public struct EngineInfo { - EngineInfo* next; - Protocol protocol; - string file_name; - string version; - string req_version; - string? home_dir; - } - - [CCode (cname = "struct _gpgme_op_verify_result")] - public struct VerifyResult { - Signature* signatures; - string? file_name; - } - - [CCode (cname = "struct _gpgme_op_sign_result")] - public struct SignResult { - InvalidKey invalid_signers; - Signature* signatures; - } - - [CCode (cname = "struct _gpgme_op_encrypt_result")] - public struct EncryptResult { - InvalidKey invalid_signers; - } - - [CCode (cname = "struct _gpgme_op_decrypt_result")] - public struct DecryptResult { - string unsupported_algorithm; - bool wrong_key_usage; - Recipient recipients; - string file_name; - } - - [CCode (cname = "struct _gpgme_recipient")] - public struct Recipient { - Recipient *next; - string keyid; - PublicKeyAlgorithm pubkey_algo; - GPGError.Error status; - } - - [CCode (cname = "struct _gpgme_invalid_key")] - public struct InvalidKey { - InvalidKey *next; - string fpr; - GPGError.Error reason; - } - - [CCode (cname = "struct _gpgme_signature")] - public struct Signature { - Signature *next; - Sigsum summary; - string fpr; - GPGError.Error status; - SigNotation notations; - ulong timestamp; - ulong exp_timestamp; - bool wrong_key_usage; - PKAStatus pka_trust; - bool chain_model; - Validity validity; - GPGError.Error validity_reason; - PublicKeyAlgorithm pubkey_algo; - HashAlgorithm hash_algo; - string? pka_adress; - } - - public enum PKAStatus { - NOT_AVAILABLE, - BAD, - OKAY, - RFU - } - - [CCode (cname = "gpgme_sigsum_t", cprefix = "GPGME_SIGSUM_")] - public enum Sigsum { - VALID, - GREEN, - RED, - KEY_REVOKED, - KEY_EXPIRED, - SIG_EXPIRED, - KEY_MISSING, - CRL_MISSING, - CRL_TOO_OLD, - BAD_POLICY, - SYS_ERROR - } - - [CCode (cname = "gpgme_data_encoding_t", cprefix = "GPGME_DATA_ENCODING_")] - public enum DataEncoding { - NONE, - BINARY, - BASE64, - ARMOR, - URL, - URLESC, - URL0 - } - - [CCode (cname = "gpgme_hash_algo_t", cprefix = "GPGME_MD_")] - public enum HashAlgorithm { - NONE, - MD5, - SHA1, - RMD160, - MD2, - TIGER, - HAVAL, - SHA256, - SHA384, - SHA512, - MD4, - MD_CRC32, - MD_CRC32_RFC1510, - MD_CRC24_RFC2440 - } - - [CCode (cname = "gpgme_export_mode_t", cprefix = "GPGME_EXPORT_MODE_")] - public enum ExportMode { - EXTERN - } - - [CCode (cprefix = "GPGME_AUDITLOG_")] - public enum AuditLogFlag { - HTML, - WITH_HELP - } - - [CCode (cname = "gpgme_status_code_t", cprefix = "GPGME_STATUS_")] - public enum StatusCode { - EOF, - ENTER, - LEAVE, - ABORT, - GOODSIG, - BADSIG, - ERRSIG, - BADARMOR, - RSA_OR_IDEA, - KEYEXPIRED, - KEYREVOKED, - TRUST_UNDEFINED, - TRUST_NEVER, - TRUST_MARGINAL, - TRUST_FULLY, - TRUST_ULTIMATE, - SHM_INFO, - SHM_GET, - SHM_GET_BOOL, - SHM_GET_HIDDEN, - NEED_PASSPHRASE, - VALIDSIG, - SIG_ID, - SIG_TO, - ENC_TO, - NODATA, - BAD_PASSPHRASE, - NO_PUBKEY, - NO_SECKEY, - NEED_PASSPHRASE_SYM, - DECRYPTION_FAILED, - DECRYPTION_OKAY, - MISSING_PASSPHRASE, - GOOD_PASSPHRASE, - GOODMDC, - BADMDC, - ERRMDC, - IMPORTED, - IMPORT_OK, - IMPORT_PROBLEM, - IMPORT_RES, - FILE_START, - FILE_DONE, - FILE_ERROR, - BEGIN_DECRYPTION, - END_DECRYPTION, - BEGIN_ENCRYPTION, - END_ENCRYPTION, - DELETE_PROBLEM, - GET_BOOL, - GET_LINE, - GET_HIDDEN, - GOT_IT, - PROGRESS, - SIG_CREATED, - SESSION_KEY, - NOTATION_NAME, - NOTATION_DATA, - POLICY_URL, - BEGIN_STREAM, - END_STREAM, - KEY_CREATED, - USERID_HINT, - UNEXPECTED, - INV_RECP, - NO_RECP, - ALREADY_SIGNED, - SIGEXPIRED, - EXPSIG, - EXPKEYSIG, - TRUNCATED, - ERROR, - NEWSIG, - REVKEYSIG, - SIG_SUBPACKET, - NEED_PASSPHRASE_PIN, - SC_OP_FAILURE, - SC_OP_SUCCESS, - CARDCTRL, - BACKUP_KEY_CREATED, - PKA_TRUST_BAD, - PKA_TRUST_GOOD, - PLAINTEXT - } - - [Flags] - [CCode (cname="unsigned int")] - public enum ImportStatusFlags { - [CCode (cname = "GPGME_IMPORT_NEW")] - NEW, - [CCode (cname = "GPGME_IMPORT_UID")] - UID, - [CCode (cname = "GPGME_IMPORT_SIG")] - SIG, - [CCode (cname = "GPGME_IMPORT_SUBKEY")] - SUBKEY, - [CCode (cname = "GPGME_IMPORT_SECRET")] - SECRET - } - - [Compact] - [CCode (cname = "struct gpgme_context", free_function = "gpgme_release", cprefix = "gpgme_")] - public class Context { - private static GPGError.Error new(out Context ctx); - - public static Context create() throws GLib.Error { - Context ctx; - throw_if_error(@new(out ctx)); - return ctx; - } - - public GPGError.Error set_protocol(Protocol p); - public Protocol get_protocol(); - - public void set_armor(bool yes); - public bool get_armor(); - - public void set_textmode(bool yes); - public bool get_textmode(); - - public GPGError.Error set_keylist_mode(KeylistMode mode); - public KeylistMode get_keylist_mode(); - - public void set_include_certs(int nr_of_certs = -256); - - public int get_include_certs(); - - public void set_passphrase_cb(passphrase_callback cb, void* hook_value = null); - - public void get_passphrase_cb(out passphrase_callback cb, out void* hook_value); - - public GPGError.Error set_locale(int category, string val); - - [CCode (cname = "gpgme_ctx_get_engine_info")] - public EngineInfo* get_engine_info(); - - [CCode (cname = "gpgme_ctx_set_engine_info")] - public GPGError.Error set_engine_info(Protocol proto, string file_name, string home_dir); - - public void signers_clear(); - - public GPGError.Error signers_add(Key key); - - public Key* signers_enum(int n); - - public void sig_notation_clear(); - - public GPGError.Error sig_notation_add(string name, string val, SigNotationFlags flags); - - public SigNotation* sig_notation_get(); - - [CCode (cname = "gpgme_get_key")] - private GPGError.Error get_key_(string fpr, out Key key, bool secret); - - [CCode (cname = "gpgme_get_key_")] - public Key get_key(string fpr, bool secret) throws GLib.Error { - Key key; - throw_if_error(get_key_(fpr, out key, secret)); - return key; - } - - public Context* wait(out GPGError.Error status, bool hang); - - public SignResult* op_sign_result(); - - [CCode (cname = "gpgme_op_sign")] - public GPGError.Error op_sign_(Data plain, Data sig, SigMode mode); - - [CCode (cname = "gpgme_op_sign_")] - public Data op_sign(Data plain, SigMode mode) throws GLib.Error { - Data sig = Data.create(); - throw_if_error(op_sign_(plain, sig, mode)); - return sig; - } - - public VerifyResult* op_verify_result(); - - [CCode (cname = "gpgme_op_verify")] - public GPGError.Error op_verify_(Data sig, Data signed_text, Data? plaintext); - - [CCode (cname = "gpgme_op_verify_")] - public Data op_verify(Data sig, Data signed_text) throws GLib.Error { - Data plaintext = Data.create(); - throw_if_error(op_verify_(sig, signed_text, plaintext)); - return plaintext; - } - - public EncryptResult* op_encrypt_result(); - - [CCode (cname = "gpgme_op_encrypt")] - public GPGError.Error op_encrypt_([CCode (array_length = false)] Key[] recp, EncryptFlags flags, Data plain, Data cipher); - - [CCode (cname = "gpgme_op_encrypt_")] - public Data op_encrypt(Key[] recp, EncryptFlags flags, Data plain) throws GLib.Error { - Data cipher = Data.create(); - throw_if_error(op_encrypt_(recp, flags, plain, cipher)); - return cipher; - } - - public DecryptResult* op_decrypt_result(); - - [CCode (cname = "gpgme_op_decrypt")] - public GPGError.Error op_decrypt_(Data cipher, Data plain); - - [CCode (cname = "gpgme_op_decrypt_")] - public Data op_decrypt(Data cipher) throws GLib.Error { - Data plain = Data.create(); - throw_if_error(op_decrypt_(cipher, plain)); - return plain; - } - - public GPGError.Error op_export(string? pattern, ExportMode mode, Data keydata); - - public GPGError.Error op_import(Data keydata); - - public unowned ImportResult op_import_result(); - - [CCode (cname = "gpgme_op_keylist_start")] - private GPGError.Error op_keylist_start_(string? pattern = null, int secret_only = 0); - - [CCode (cname = "gpgme_op_keylist_start_")] - public void op_keylist_start(string? pattern = null, int secret_only = 0) throws GLib.Error { - throw_if_error(op_keylist_start_(pattern, secret_only)); - } - - [CCode (cname = "gpgme_op_keylist_next")] - private GPGError.Error op_keylist_next_(out Key key); - - [CCode (cname = "gpgme_op_keylist_next_")] - public Key op_keylist_next() throws GLib.Error { - Key key; - throw_if_error(op_keylist_next_(out key)); - return key; - } - - [CCode (cname = "gpgme_op_keylist_end")] - private GPGError.Error op_keylist_end_(); - - [CCode (cname = "gpgme_op_keylist_end_")] - public void op_keylist_end() throws GLib.Error { - throw_if_error(op_keylist_end_()); - } - - public KeylistResult op_keylist_result(); - } - - [Compact] - [CCode (cname = "struct _gpgme_import_status")] - public class ImportStatus { - - public ImportStatus? next; - public string fpr; - public GPGError.Error result; - public ImportStatusFlags status; - } - - [Compact] - [CCode (cname = "struct _gpgme_op_import_result")] - public class ImportResult { - public int considered; - public int no_user_id; - public int imported; - public int imported_rsa; - public int unchanged; - public int new_user_ids; - public int new_sub_keys; - public int new_signatures; - public int new_revocations; - public int secret_read; - public int secret_imported; - public int secret_unchanged; - public int not_imported; - public ImportStatus imports; - } - - [Compact] - [CCode (cname = "struct _gpgme_op_keylist_result")] - public class KeylistResult { - uint truncated; - } - - [Compact] - [CCode (cname = "struct gpgme_data", free_function = "gpgme_data_release", cprefix = "gpgme_data_")] - public class Data { - - public static GPGError.Error new(out Data d); - - public static Data create() throws GLib.Error { - Data data; - throw_if_error(@new(out data)); - return data; - } - - - [CCode (cname = "gpgme_data_new_from_mem")] - public static GPGError.Error new_from_memory(out Data d, char[] buffer, bool copy); - - public static Data create_from_memory(uint8[] buffer, bool copy) throws GLib.Error { - Data data; - throw_if_error(new_from_memory(out data, (char[]) buffer, copy)); - return data; - } - - [CCode (cname = "gpgme_data_new_from_file")] - public static GPGError.Error new_from_file(out Data d, string filename, int copy = 1); - - public static Data create_from_file(string filename, int copy = 1) throws GLib.Error { - Data data; - throw_if_error(new_from_file(out data, filename, copy)); - return data; - } - - [CCode (cname = "gpgme_data_release_and_get_mem")] - public string release_and_get_mem(out size_t len); - - public ssize_t read([CCode (array_length = false)] uint8[] buf, size_t len); - - public ssize_t write(uint8[] buf); - - public long seek(long offset, int whence=0); - - public GPGError.Error set_file_name(string file_name); - - public DataEncoding* get_encoding(); - - public GPGError.Error set_encoding(DataEncoding enc); - } - - [CCode (cname = "gpgme_get_protocol_name")] - public unowned string get_protocol_name(Protocol p); - - [CCode (cname = "gpgme_pubkey_algo_name")] - public unowned string get_public_key_algorithm_name(PublicKeyAlgorithm algo); - - [CCode (cname = "gpgme_hash_algo_name")] - public unowned string get_hash_algorithm_name(HashAlgorithm algo); - - [CCode (cname = "gpgme_passphrase_cb_t", has_target = false)] - public delegate GPGError.Error passphrase_callback(void* hook, string uid_hint, string passphrase_info, bool prev_was_bad, int fd); - - [CCode (cname = "gpgme_engine_check_version")] - public GPGError.Error engine_check_version(Protocol proto); - - [CCode (cname = "gpgme_get_engine_information")] - public GPGError.Error get_engine_information(out EngineInfo engine_info); - - [CCode (cname = "gpgme_strerror_r")] - public int strerror_r(GPGError.Error err, uint8[] buf); - - [CCode (cname = "gpgme_strerror")] - public unowned string strerror(GPGError.Error err); - - private void throw_if_error(GPGError.Error error) throws GLib.Error { - if (error.code != GPGError.ErrorCode.NO_ERROR) { - throw new GLib.Error(-1, error.code, "%s", error.to_string()); - } - } -} diff --git a/plugins/gpgme-vala/vapi/gpgme_public.vapi b/plugins/gpgme-vala/vapi/gpgme_public.vapi deleted file mode 100644 index bcf12569..00000000 --- a/plugins/gpgme-vala/vapi/gpgme_public.vapi +++ /dev/null @@ -1,162 +0,0 @@ -[CCode (lower_case_cprefix = "gpgme_", cheader_filename = "gpgme.h,gpgme_fix.h")] -namespace GPG { - -[CCode (cname = "gpgme_check_version")] -public unowned string check_version(string? required_version = null); - -[Compact] -[CCode (cname = "struct _gpgme_key", ref_function = "gpgme_key_ref_vapi", unref_function = "gpgme_key_unref_vapi", free_function = "gpgme_key_release")] -public class Key { - public bool revoked; - public bool expired; - public bool disabled; - public bool invalid; - public bool can_encrypt; - public bool can_sign; - public bool can_certify; - public bool can_authenticate; - public bool is_qualified; - public bool secret; - public Protocol protocol; - public string issuer_serial; - public string issuer_name; - public string chain_id; - public Validity owner_trust; - [CCode(array_null_terminated = true)] - public SubKey[] subkeys; - [CCode(array_null_terminated = true)] - public UserID[] uids; - public KeylistMode keylist_mode; - // public string fpr; // requires gpgme >= 1.7.0 - public string fpr { get { return subkeys[0].fpr; } } -} - -[CCode (cname = "struct _gpgme_user_id")] -public struct UserID { - UserID* next; - - bool revoked; - bool invalid; - Validity validity; - string uid; - string name; - string email; - string comment; - KeySig signatures; -} - -[CCode (cname = "struct _gpgme_key_sig")] -public struct KeySig { - KeySig* next; - bool invoked; - bool expired; - bool invalid; - bool exportable; - PublicKeyAlgorithm algo; - string keyid; - long timestamp; - long expires; -// GPGError.Error status; - string uid; - string name; - string email; - string comment; - uint sig_class; - SigNotation notations; -} - -[CCode (cname = "struct _gpgme_subkey")] -public struct SubKey { - SubKey* next; - bool revoked; - bool expired; - bool disabled; - bool invalid; - bool can_encrypt; - bool can_sign; - bool can_certify; - bool secret; - bool can_authenticate; - bool is_qualified; - bool is_cardkey; - PublicKeyAlgorithm algo; - uint length; - string keyid; - - string fpr; - long timestamp; - long expires; - string? cardnumber; -} - -[CCode (cname = "struct _gpgme_sig_notation")] -public struct SigNotation { - SigNotation* next; - string? name; - string value; - int name_len; - int value_len; - SigNotationFlags flags; - bool human_readable; - bool critical; -} - -[CCode (cname = "gpgme_sig_notation_flags_t", cprefix = "GPGME_SIG_NOTATION_")] -public enum SigNotationFlags { - HUMAN_READABLE, - CRITICAL -} - -[CCode (cname = "gpgme_sig_mode_t", cprefix = "GPGME_SIG_MODE_")] -public enum SigMode { - NORMAL, - DETACH, - CLEAR -} - -[CCode (cname = "gpgme_encrypt_flags_t", cprefix = "GPGME_ENCRYPT_")] -public enum EncryptFlags { - ALWAYS_TRUST, - NO_ENCRYPT_TO -} - -[CCode (cname = "gpgme_pubkey_algo_t", cprefix = "GPGME_PK_")] -public enum PublicKeyAlgorithm { - RSA, - RSA_E, - RSA_S, - ELG_E, - DSA, - ELG -} - -[CCode (cname = "gpgme_protocol_t", cprefix = "GPGME_PROTOCOL_")] -public enum Protocol { - OpenPGP, - CMS, - GPGCONF, - ASSUAN, - UNKNOWN -} - -[CCode (cname = "gpgme_keylist_mode_t", cprefix = "GPGME_KEYLIST_MODE_")] -public enum KeylistMode { - LOCAL, - EXTERN, - SIGS, - SIG_NOTATIONS, - EPHEMERAL, - VALIDATE -} - -[CCode (cname = "gpgme_validity_t", cprefix = "GPGME_VALIDITY_")] -public enum Validity { - UNKNOWN, - UNDEFINED, - NEVER, - MARGINAL, - FULL, - ULTIMATE -} - -} \ No newline at end of file diff --git a/plugins/openpgp/CMakeLists.txt b/plugins/openpgp/CMakeLists.txt index 649a55ad..6ed7bf53 100644 --- a/plugins/openpgp/CMakeLists.txt +++ b/plugins/openpgp/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(GPGME REQUIRED) + set(GETTEXT_PACKAGE "dino-openpgp") find_package(Gettext) include(${GETTEXT_USE_FILE}) @@ -28,6 +30,8 @@ compile_gresources( vala_precompile(OPENPGP_VALA_C SOURCES + src/gpgme_helper.vala + src/file_transfer/file_decryptor.vala src/file_transfer/file_encryptor.vala @@ -42,7 +46,8 @@ SOURCES src/stream_module.vala src/util.vala CUSTOM_VAPIS - ${CMAKE_BINARY_DIR}/exports/gpgme.vapi + ${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpgme.vapi + ${CMAKE_CURRENT_SOURCE_DIR}/vapi/gpg-error.vapi ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi ${CMAKE_BINARY_DIR}/exports/qlite.vapi ${CMAKE_BINARY_DIR}/exports/dino.vapi @@ -53,9 +58,10 @@ GRESOURCES ) add_definitions(${VALA_CFLAGS} -DG_LOG_DOMAIN="OpenPGP" -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\") -add_library(openpgp SHARED ${OPENPGP_VALA_C} ${OPENPGP_GRESOURCES_TARGET}) +add_library(openpgp SHARED ${OPENPGP_VALA_C} ${OPENPGP_GRESOURCES_TARGET} src/gpgme_fix.c) add_dependencies(openpgp ${GETTEXT_PACKAGE}-translations) -target_link_libraries(openpgp libdino gpgme-vala ${OPENPGP_PACKAGES}) +target_include_directories(openpgp PRIVATE src) +target_link_libraries(openpgp libdino gpgme ${OPENPGP_PACKAGES}) set_target_properties(openpgp PROPERTIES PREFIX "") set_target_properties(openpgp PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/) diff --git a/plugins/openpgp/src/gpgme_fix.c b/plugins/openpgp/src/gpgme_fix.c new file mode 100644 index 00000000..bf457a6c --- /dev/null +++ b/plugins/openpgp/src/gpgme_fix.c @@ -0,0 +1,12 @@ +#include + +GRecMutex gpgme_global_mutex = {0}; + +gpgme_key_t gpgme_key_ref_vapi (gpgme_key_t key) { + gpgme_key_ref(key); + return key; +} +gpgme_key_t gpgme_key_unref_vapi (gpgme_key_t key) { + gpgme_key_unref(key); + return key; +} diff --git a/plugins/openpgp/src/gpgme_fix.h b/plugins/openpgp/src/gpgme_fix.h new file mode 100644 index 00000000..714614fc --- /dev/null +++ b/plugins/openpgp/src/gpgme_fix.h @@ -0,0 +1,12 @@ +#ifndef GPGME_FIX +#define GPGME_FIX 1 + +#include +#include + +extern GRecMutex gpgme_global_mutex; + +gpgme_key_t gpgme_key_ref_vapi (gpgme_key_t key); +gpgme_key_t gpgme_key_unref_vapi (gpgme_key_t key); + +#endif diff --git a/plugins/openpgp/src/gpgme_helper.vala b/plugins/openpgp/src/gpgme_helper.vala new file mode 100644 index 00000000..f28bc6d6 --- /dev/null +++ b/plugins/openpgp/src/gpgme_helper.vala @@ -0,0 +1,184 @@ +using Gee; +using GPG; + +namespace GPGHelper { + +private static bool initialized = false; + +public static string encrypt_armor(string plain, Key[] keys, EncryptFlags flags) throws GLib.Error { + global_mutex.lock(); + try { + initialize(); + Data plain_data = Data.create_from_memory(plain.data, false); + Context context = Context.create(); + context.set_armor(true); + Data enc_data = context.op_encrypt(keys, flags, plain_data); + return get_string_from_data(enc_data); + } finally { + global_mutex.unlock(); + } +} + +public static uint8[] encrypt_file(string uri, Key[] keys, EncryptFlags flags, string file_name) throws GLib.Error { + global_mutex.lock(); + try { + initialize(); + Data plain_data = Data.create_from_file(uri); + plain_data.set_file_name(file_name); + Context context = Context.create(); + context.set_armor(true); + Data enc_data = context.op_encrypt(keys, flags, plain_data); + return get_uint8_from_data(enc_data); + } finally { + global_mutex.unlock(); + } +} + +public static string decrypt(string encr) throws GLib.Error { + global_mutex.lock(); + try { + initialize(); + Data enc_data = Data.create_from_memory(encr.data, false); + Context context = Context.create(); + Data dec_data = context.op_decrypt(enc_data); + return get_string_from_data(dec_data); + } finally { + global_mutex.unlock(); + } +} + +public class DecryptedData { + public uint8[] data { get; set; } + public string filename { get; set; } +} + +public static DecryptedData decrypt_data(uint8[] data) throws GLib.Error { + global_mutex.lock(); + try { + initialize(); + Data enc_data = Data.create_from_memory(data, false); + Context context = Context.create(); + Data dec_data = context.op_decrypt(enc_data); + DecryptResult* dec_res = context.op_decrypt_result(); + return new DecryptedData() { data=get_uint8_from_data(dec_data), filename=dec_res->file_name}; + } finally { + global_mutex.unlock(); + } +} + +public static string sign(string plain, SigMode mode, Key? key = null) throws GLib.Error { + global_mutex.lock(); + try { + initialize(); + Data plain_data = Data.create_from_memory(plain.data, false); + Context context = Context.create(); + if (key != null) context.signers_add(key); + Data signed_data = context.op_sign(plain_data, mode); + return get_string_from_data(signed_data); + } finally { + global_mutex.unlock(); + } +} + +public static string? get_sign_key(string signature, string? text) throws GLib.Error { + global_mutex.lock(); + try { + initialize(); + Data sig_data = Data.create_from_memory(signature.data, false); + Data text_data; + if (text != null) { + text_data = Data.create_from_memory(text.data, false); + } else { + text_data = Data.create(); + } + Context context = Context.create(); + context.op_verify(sig_data, text_data); + VerifyResult* verify_res = context.op_verify_result(); + if (verify_res == null || verify_res.signatures == null) return null; + return verify_res.signatures.fpr; + } finally { + global_mutex.unlock(); + } +} + +public static Gee.List get_keylist(string? pattern = null, bool secret_only = false) throws GLib.Error { + global_mutex.lock(); + try { + initialize(); + + Gee.List keys = new ArrayList(); + Context context = Context.create(); + context.op_keylist_start(pattern, secret_only ? 1 : 0); + try { + while (true) { + Key key = context.op_keylist_next(); + keys.add(key); + } + } catch (Error e) { + if (e.code != GPGError.ErrorCode.EOF) throw e; + } + return keys; + } finally { + global_mutex.unlock(); + } +} + +public static Key? get_public_key(string sig) throws GLib.Error { + return get_key(sig, false); +} + +public static Key? get_private_key(string sig) throws GLib.Error { + return get_key(sig, true); +} + +private static Key? get_key(string sig, bool priv) throws GLib.Error { + global_mutex.lock(); + try { + initialize(); + Context context = Context.create(); + Key key = context.get_key(sig, priv); + return key; + } finally { + global_mutex.unlock(); + } +} + +private static string get_string_from_data(Data data) { + const size_t BUF_SIZE = 256; + data.seek(0); + uint8[] buf = new uint8[BUF_SIZE + 1]; + ssize_t len = 0; + string res = ""; + do { + len = data.read(buf, BUF_SIZE); + if (len > 0) { + buf[len] = 0; + res += (string) buf; + } + } while (len > 0); + return res; +} + +private static uint8[] get_uint8_from_data(Data data) { + const size_t BUF_SIZE = 256; + data.seek(0); + uint8[] buf = new uint8[BUF_SIZE + 1]; + ssize_t len = 0; + ByteArray res = new ByteArray(); + do { + len = data.read(buf, BUF_SIZE); + if (len > 0) { + res.append(buf[0:len]); + } + } while (len > 0); + return res.data; +} + +private static void initialize() { + if (!initialized) { + check_version(); + initialized = true; + } +} + +} diff --git a/plugins/openpgp/vapi/gpg-error.vapi b/plugins/openpgp/vapi/gpg-error.vapi new file mode 100644 index 00000000..3ad6c580 --- /dev/null +++ b/plugins/openpgp/vapi/gpg-error.vapi @@ -0,0 +1,445 @@ +/* gcrypt.vapi + * + * Copyright: + * 2008 Jiqing Qiang + * 2008, 2010, 2012-2013 Evan Nemerson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jiqing Qiang + * Evan Nemerson + */ + + + +[CCode (cheader_filename = "gpg-error.h")] +namespace GPGError { + [CCode (cname = "gpg_err_source_t", cprefix = "GPG_ERR_SOURCE_")] + public enum ErrorSource { + UNKNOWN, + GCRYPT, + GPG, + GPGSM, + GPGAGENT, + PINENTRY, + SCD, + GPGME, + KEYBOX, + KSBA, + DIRMNGR, + GSTI, + ANY, + USER_1, + USER_2, + USER_3, + USER_4, + + /* This is one more than the largest allowed entry. */ + DIM + } + + [CCode (cname = "gpg_err_code_t", cprefix = "GPG_ERR_")] + public enum ErrorCode { + NO_ERROR, + GENERAL, + UNKNOWN_PACKET, + UNKNOWN_VERSION, + PUBKEY_ALGO, + DIGEST_ALGO, + BAD_PUBKEY, + BAD_SECKEY, + BAD_SIGNATURE, + NO_PUBKEY, + CHECKSUM, + BAD_PASSPHRASE, + CIPHER_ALGO, + KEYRING_OPEN, + INV_PACKET, + INV_ARMOR, + NO_USER_ID, + NO_SECKEY, + WRONG_SECKEY, + BAD_KEY, + COMPR_ALGO, + NO_PRIME, + NO_ENCODING_METHOD, + NO_ENCRYPTION_SCHEME, + NO_SIGNATURE_SCHEME, + INV_ATTR, + NO_VALUE, + NOT_FOUND, + VALUE_NOT_FOUND, + SYNTAX, + BAD_MPI, + INV_PASSPHRASE, + SIG_CLASS, + RESOURCE_LIMIT, + INV_KEYRING, + TRUSTDB, + BAD_CERT, + INV_USER_ID, + UNEXPECTED, + TIME_CONFLICT, + KEYSERVER, + WRONG_PUBKEY_ALGO, + TRIBUTE_TO_D_A, + WEAK_KEY, + INV_KEYLEN, + INV_ARG, + BAD_URI, + INV_URI, + NETWORK, + UNKNOWN_HOST, + SELFTEST_FAILED, + NOT_ENCRYPTED, + NOT_PROCESSED, + UNUSABLE_PUBKEY, + UNUSABLE_SECKEY, + INV_VALUE, + BAD_CERT_CHAIN, + MISSING_CERT, + NO_DATA, + BUG, + NOT_SUPPORTED, + INV_OP, + TIMEOUT, + INTERNAL, + EOF_GCRYPT, + INV_OBJ, + TOO_SHORT, + TOO_LARGE, + NO_OBJ, + NOT_IMPLEMENTED, + CONFLICT, + INV_CIPHER_MODE, + INV_FLAG, + INV_HANDLE, + TRUNCATED, + INCOMPLETE_LINE, + INV_RESPONSE, + NO_AGENT, + AGENT, + INV_DATA, + ASSUAN_SERVER_FAULT, + ASSUAN, + INV_SESSION_KEY, + INV_SEXP, + UNSUPPORTED_ALGORITHM, + NO_PIN_ENTRY, + PIN_ENTRY, + BAD_PIN, + INV_NAME, + BAD_DATA, + INV_PARAMETER, + WRONG_CARD, + NO_DIRMNGR, + DIRMNGR, + CERT_REVOKED, + NO_CRL_KNOWN, + CRL_TOO_OLD, + LINE_TOO_LONG, + NOT_TRUSTED, + CANCELED, + BAD_CA_CERT, + CERT_EXPIRED, + CERT_TOO_YOUNG, + UNSUPPORTED_CERT, + UNKNOWN_SEXP, + UNSUPPORTED_PROTECTION, + CORRUPTED_PROTECTION, + AMBIGUOUS_NAME, + CARD, + CARD_RESET, + CARD_REMOVED, + INV_CARD, + CARD_NOT_PRESENT, + NO_PKCS15_APP, + NOT_CONFIRMED, + CONFIGURATION, + NO_POLICY_MATCH, + INV_INDEX, + INV_ID, + NO_SCDAEMON, + SCDAEMON, + UNSUPPORTED_PROTOCOL, + BAD_PIN_METHOD, + CARD_NOT_INITIALIZED, + UNSUPPORTED_OPERATION, + WRONG_KEY_USAGE, + NOTHING_FOUND, + WRONG_BLOB_TYPE, + MISSING_VALUE, + HARDWARE, + PIN_BLOCKED, + USE_CONDITIONS, + PIN_NOT_SYNCED, + INV_CRL, + BAD_BER, + INV_BER, + ELEMENT_NOT_FOUND, + IDENTIFIER_NOT_FOUND, + INV_TAG, + INV_LENGTH, + INV_KEYINFO, + UNEXPECTED_TAG, + NOT_DER_ENCODED, + NO_CMS_OBJ, + INV_CMS_OBJ, + UNKNOWN_CMS_OBJ, + UNSUPPORTED_CMS_OBJ, + UNSUPPORTED_ENCODING, + UNSUPPORTED_CMS_VERSION, + UNKNOWN_ALGORITHM, + INV_ENGINE, + PUBKEY_NOT_TRUSTED, + DECRYPT_FAILED, + KEY_EXPIRED, + SIG_EXPIRED, + ENCODING_PROBLEM, + INV_STATE, + DUP_VALUE, + MISSING_ACTION, + MODULE_NOT_FOUND, + INV_OID_STRING, + INV_TIME, + INV_CRL_OBJ, + UNSUPPORTED_CRL_VERSION, + INV_CERT_OBJ, + UNKNOWN_NAME, + LOCALE_PROBLEM, + NOT_LOCKED, + PROTOCOL_VIOLATION, + INV_MAC, + INV_REQUEST, + UNKNOWN_EXTN, + UNKNOWN_CRIT_EXTN, + LOCKED, + UNKNOWN_OPTION, + UNKNOWN_COMMAND, + BUFFER_TOO_SHORT, + SEXP_INV_LEN_SPEC, + SEXP_STRING_TOO_LONG, + SEXP_UNMATCHED_PAREN, + SEXP_NOT_CANONICAL, + SEXP_BAD_CHARACTER, + SEXP_BAD_QUOTATION, + SEXP_ZERO_PREFIX, + SEXP_NESTED_DH, + SEXP_UNMATCHED_DH, + SEXP_UNEXPECTED_PUNC, + SEXP_BAD_HEX_CHAR, + SEXP_ODD_HEX_NUMBERS, + SEXP_BAD_OCT_CHAR, + ASS_GENERAL, + ASS_ACCEPT_FAILED, + ASS_CONNECT_FAILED, + ASS_INV_RESPONSE, + ASS_INV_VALUE, + ASS_INCOMPLETE_LINE, + ASS_LINE_TOO_LONG, + ASS_NESTED_COMMANDS, + ASS_NO_DATA_CB, + ASS_NO_INQUIRE_CB, + ASS_NOT_A_SERVER, + ASS_NOT_A_CLIENT, + ASS_SERVER_START, + ASS_READ_ERROR, + ASS_WRITE_ERROR, + ASS_TOO_MUCH_DATA, + ASS_UNEXPECTED_CMD, + ASS_UNKNOWN_CMD, + ASS_SYNTAX, + ASS_CANCELED, + ASS_NO_INPUT, + ASS_NO_OUTPUT, + ASS_PARAMETER, + ASS_UNKNOWN_INQUIRE, + USER_1, + USER_2, + USER_3, + USER_4, + USER_5, + USER_6, + USER_7, + USER_8, + USER_9, + USER_10, + USER_11, + USER_12, + USER_13, + USER_14, + USER_15, + USER_16, + MISSING_ERRNO, + UNKNOWN_ERRNO, + EOF, + + E2BIG, + EACCES, + EADDRINUSE, + EADDRNOTAVAIL, + EADV, + EAFNOSUPPORT, + EAGAIN, + EALREADY, + EAUTH, + EBACKGROUND, + EBADE, + EBADF, + EBADFD, + EBADMSG, + EBADR, + EBADRPC, + EBADRQC, + EBADSLT, + EBFONT, + EBUSY, + ECANCELED, + ECHILD, + ECHRNG, + ECOMM, + ECONNABORTED, + ECONNREFUSED, + ECONNRESET, + ED, + EDEADLK, + EDEADLOCK, + EDESTADDRREQ, + EDIED, + EDOM, + EDOTDOT, + EDQUOT, + EEXIST, + EFAULT, + EFBIG, + EFTYPE, + EGRATUITOUS, + EGREGIOUS, + EHOSTDOWN, + EHOSTUNREACH, + EIDRM, + EIEIO, + EILSEQ, + EINPROGRESS, + EINTR, + EINVAL, + EIO, + EISCONN, + EISDIR, + EISNAM, + EL2HLT, + EL2NSYNC, + EL3HLT, + EL3RST, + ELIBACC, + ELIBBAD, + ELIBEXEC, + ELIBMAX, + ELIBSCN, + ELNRNG, + ELOOP, + EMEDIUMTYPE, + EMFILE, + EMLINK, + EMSGSIZE, + EMULTIHOP, + ENAMETOOLONG, + ENAVAIL, + ENEEDAUTH, + ENETDOWN, + ENETRESET, + ENETUNREACH, + ENFILE, + ENOANO, + ENOBUFS, + ENOCSI, + ENODATA, + ENODEV, + ENOENT, + ENOEXEC, + ENOLCK, + ENOLINK, + ENOMEDIUM, + ENOMEM, + ENOMSG, + ENONET, + ENOPKG, + ENOPROTOOPT, + ENOSPC, + ENOSR, + ENOSTR, + ENOSYS, + ENOTBLK, + ENOTCONN, + ENOTDIR, + ENOTEMPTY, + ENOTNAM, + ENOTSOCK, + ENOTSUP, + ENOTTY, + ENOTUNIQ, + ENXIO, + EOPNOTSUPP, + EOVERFLOW, + EPERM, + EPFNOSUPPORT, + EPIPE, + EPROCLIM, + EPROCUNAVAIL, + EPROGMISMATCH, + EPROGUNAVAIL, + EPROTO, + EPROTONOSUPPORT, + EPROTOTYPE, + ERANGE, + EREMCHG, + EREMOTE, + EREMOTEIO, + ERESTART, + EROFS, + ERPCMISMATCH, + ESHUTDOWN, + ESOCKTNOSUPPORT, + ESPIPE, + ESRCH, + ESRMNT, + ESTALE, + ESTRPIPE, + ETIME, + ETIMEDOUT, + ETOOMANYREFS, + ETXTBSY, + EUCLEAN, + EUNATCH, + EUSERS, + EWOULDBLOCK, + EXDEV, + EXFULL, + + /* This is one more than the largest allowed entry. */ + CODE_DIM + } + + [CCode (cname = "gpg_err_code_t", cprefix = "gpg_err_")] + public struct Error : uint { + [CCode (cname = "gpg_err_make")] + public Error (ErrorSource source, ErrorCode code); + [CCode (cname = "gpg_err_make_from_errno")] + public Error.from_errno (ErrorSource source, int err); + public ErrorCode code { [CCode (cname = "gpg_err_code")] get; } + public ErrorSource source { [CCode (cname = "gpg_err_source")] get; } + } +} diff --git a/plugins/openpgp/vapi/gpgme.vapi b/plugins/openpgp/vapi/gpgme.vapi new file mode 100644 index 00000000..10fdb89d --- /dev/null +++ b/plugins/openpgp/vapi/gpgme.vapi @@ -0,0 +1,673 @@ +/* libgpgme.vapi + * + * Copyright (C) 2009 Sebastian Reichel + * Copyright (C) 2022 Itay Grudev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +[CCode (lower_case_cprefix = "gpgme_", cheader_filename = "gpgme.h,gpgme_fix.h")] +namespace GPG { + public static GLib.RecMutex global_mutex; + + [CCode (cname = "struct _gpgme_engine_info")] + public struct EngineInfo { + EngineInfo* next; + Protocol protocol; + string file_name; + string version; + string req_version; + string? home_dir; + } + + [Compact] + [CCode (cname = "struct _gpgme_key", ref_function = "gpgme_key_ref", ref_function_void = true, unref_function = "gpgme_key_unref", free_function = "gpgme_key_release")] + public class Key { + public bool revoked; + public bool expired; + public bool disabled; + public bool invalid; + public bool can_encrypt; + public bool can_sign; + public bool can_certify; + public bool secret; + public bool can_authenticate; + public bool is_qualified; + public Protocol protocol; + public string issuer_serial; + public string issuer_name; + public string chain_id; + public Validity owner_trust; + [CCode(array_null_terminated = true)] + public SubKey[] subkeys; + [CCode(array_null_terminated = true)] + public UserID[] uids; + public KeylistMode keylist_mode; + public string fpr { get { return subkeys[0].fpr; } } + } + + [CCode (cname = "struct _gpgme_sig_notation")] + public struct SigNotation { + SigNotation* next; + string? name; + string value; + int name_len; + int value_len; + SigNotationFlags flags; + bool human_readable; + bool critical; + } + + [CCode (cname = "struct _gpgme_subkey")] + public struct SubKey { + SubKey* next; + bool revoked; + bool expired; + bool disabled; + bool invalid; + bool can_encrypt; + bool can_sign; + bool can_certify; + bool secret; + bool can_authenticate; + bool is_qualified; + bool is_cardkey; + PublicKeyAlgorithm algo; + uint length; + string keyid; + string fpr; + long timestamp; + long expires; + string? card_number; + } + + [CCode (cname = "struct _gpgme_key_sig")] + public struct KeySig { + KeySig* next; + bool revoked; + bool expired; + bool invalid; + bool exportable; + PublicKeyAlgorithm algo; + string keyid; + long timestamp; + long expires; + GPGError.Error status; + string uid; + string name; + string email; + string comment; + uint sig_class; + SigNotation notations; + } + + [CCode (cname = "struct _gpgme_user_id")] + public struct UserID { + UserID* next; + bool revoked; + bool invalid; + Validity validity; + string uid; + string name; + string email; + string comment; + KeySig signatures; + } + + [CCode (cname = "struct _gpgme_op_verify_result")] + public struct VerifyResult { + Signature* signatures; + string? file_name; + } + + [CCode (cname = "struct _gpgme_op_sign_result")] + public struct SignResult { + InvalidKey invalid_signers; + Signature* signatures; + } + + [CCode (cname = "struct _gpgme_op_encrypt_result")] + public struct EncryptResult { + InvalidKey invalid_signers; + } + + [CCode (cname = "struct _gpgme_op_decrypt_result")] + public struct DecryptResult { + string unsupported_algorithm; + bool wrong_key_usage; + Recipient recipients; + string file_name; + } + + [CCode (cname = "struct _gpgme_recipient")] + public struct Recipient { + Recipient *next; + string keyid; + PublicKeyAlgorithm pubkey_algo; + GPGError.Error status; + } + + [CCode (cname = "struct _gpgme_invalid_key")] + public struct InvalidKey { + InvalidKey *next; + string fpr; + GPGError.Error reason; + } + + [CCode (cname = "struct _gpgme_signature")] + public struct Signature { + Signature *next; + Sigsum summary; + string fpr; + GPGError.Error status; + SigNotation notations; + ulong timestamp; + ulong exp_timestamp; + bool wrong_key_usage; + PKAStatus pka_trust; + bool chain_model; + Validity validity; + GPGError.Error validity_reason; + PublicKeyAlgorithm pubkey_algo; + HashAlgorithm hash_algo; + string? pka_address; + } + + public enum PKAStatus { + NOT_AVAILABLE, + BAD, + OKAY, + RFU + } + + [CCode (cname = "gpgme_sigsum_t", cprefix = "GPGME_SIGSUM_")] + public enum Sigsum { + VALID, + GREEN, + RED, + KEY_REVOKED, + KEY_EXPIRED, + SIG_EXPIRED, + KEY_MISSING, + CRL_MISSING, + CRL_TOO_OLD, + BAD_POLICY, + SYS_ERROR + } + + [CCode (cname = "gpgme_data_encoding_t", cprefix = "GPGME_DATA_ENCODING_")] + public enum DataEncoding { + NONE, + BINARY, + BASE64, + ARMOR, + URL, + URLESC, + URL0 + } + + [CCode (cname = "gpgme_pubkey_algo_t", cprefix = "GPGME_PK_")] + public enum PublicKeyAlgorithm { + RSA, + RSA_E, + RSA_S, + ELG_E, + DSA, + ELG + } + + [CCode (cname = "gpgme_hash_algo_t", cprefix = "GPGME_MD_")] + public enum HashAlgorithm { + NONE, + MD5, + SHA1, + RMD160, + MD2, + TIGER, + HAVAL, + SHA256, + SHA384, + SHA512, + MD4, + CRC32, + CRC32_RFC1510, + CRC24_RFC2440 + } + + [CCode (cname = "gpgme_sig_mode_t", cprefix = "GPGME_SIG_MODE_")] + public enum SigMode { + NORMAL, + DETACH, + CLEAR + } + + [CCode (cname = "gpgme_validity_t", cprefix = "GPGME_VALIDITY_")] + public enum Validity { + UNKNOWN, + UNDEFINED, + NEVER, + MARGINAL, + FULL, + ULTIMATE + } + + [CCode (cname = "gpgme_protocol_t", cprefix = "GPGME_PROTOCOL_")] + public enum Protocol { + OpenPGP, + CMS, + GPGCONF, + ASSUAN, + UNKNOWN + } + + [CCode (cname = "gpgme_keylist_mode_t", cprefix = "GPGME_KEYLIST_MODE_")] + public enum KeylistMode { + LOCAL, + EXTERN, + SIGS, + SIG_NOTATIONS, + EPHEMERAL, + VALIDATE + } + + [CCode (cname = "gpgme_export_mode_t", cprefix = "GPGME_EXPORT_MODE_")] + public enum ExportMode { + EXTERN + } + + [CCode (cprefix = "GPGME_AUDITLOG_")] + public enum AuditLogFlag { + HTML, + WITH_HELP + } + + [CCode (cname = "gpgme_sig_notation_flags_t", cprefix = "GPGME_SIG_NOTATION_")] + public enum SigNotationFlags { + HUMAN_READABLE, + CRITICAL + } + + [CCode (cname = "gpgme_encrypt_flags_t", cprefix = "GPGME_ENCRYPT_")] + public enum EncryptFlags { + ALWAYS_TRUST, + NO_ENCRYPT_TO + } + + [CCode (cname = "gpgme_status_code_t", cprefix = "GPGME_STATUS_")] + public enum StatusCode { + EOF, + ENTER, + LEAVE, + ABORT, + GOODSIG, + BADSIG, + ERRSIG, + BADARMOR, + RSA_OR_IDEA, + KEYEXPIRED, + KEYREVOKED, + TRUST_UNDEFINED, + TRUST_NEVER, + TRUST_MARGINAL, + TRUST_FULLY, + TRUST_ULTIMATE, + SHM_INFO, + SHM_GET, + SHM_GET_BOOL, + SHM_GET_HIDDEN, + NEED_PASSPHRASE, + VALIDSIG, + SIG_ID, + SIG_TO, + ENC_TO, + NODATA, + BAD_PASSPHRASE, + NO_PUBKEY, + NO_SECKEY, + NEED_PASSPHRASE_SYM, + DECRYPTION_FAILED, + DECRYPTION_OKAY, + MISSING_PASSPHRASE, + GOOD_PASSPHRASE, + GOODMDC, + BADMDC, + ERRMDC, + IMPORTED, + IMPORT_OK, + IMPORT_PROBLEM, + IMPORT_RES, + FILE_START, + FILE_DONE, + FILE_ERROR, + BEGIN_DECRYPTION, + END_DECRYPTION, + BEGIN_ENCRYPTION, + END_ENCRYPTION, + DELETE_PROBLEM, + GET_BOOL, + GET_LINE, + GET_HIDDEN, + GOT_IT, + PROGRESS, + SIG_CREATED, + SESSION_KEY, + NOTATION_NAME, + NOTATION_DATA, + POLICY_URL, + BEGIN_STREAM, + END_STREAM, + KEY_CREATED, + USERID_HINT, + UNEXPECTED, + INV_RECP, + NO_RECP, + ALREADY_SIGNED, + SIGEXPIRED, + EXPSIG, + EXPKEYSIG, + TRUNCATED, + ERROR, + NEWSIG, + REVKEYSIG, + SIG_SUBPACKET, + NEED_PASSPHRASE_PIN, + SC_OP_FAILURE, + SC_OP_SUCCESS, + CARDCTRL, + BACKUP_KEY_CREATED, + PKA_TRUST_BAD, + PKA_TRUST_GOOD, + PLAINTEXT + } + + [Compact] + [CCode (cname = "struct gpgme_context", free_function = "gpgme_release", cprefix = "gpgme_")] + public class Context { + private static GPGError.Error new(out Context ctx); + + public static Context create() throws GLib.Error { + Context ctx; + throw_if_error(@new(out ctx)); + return ctx; + } + + public GPGError.Error set_protocol(Protocol p); + public Protocol get_protocol(); + + public void set_armor(bool yes); + public bool get_armor(); + + public void set_textmode(bool yes); + public bool get_textmode(); + + public GPGError.Error set_keylist_mode(KeylistMode mode); + public KeylistMode get_keylist_mode(); + + public void set_include_certs(int nr_of_certs = -256); + + public int get_include_certs(); + + public void set_passphrase_cb(passphrase_callback cb, void* hook_value = null); + + public void get_passphrase_cb(out passphrase_callback cb, out void* hook_value); + + public GPGError.Error set_locale(int category, string val); + + [CCode (cname = "gpgme_ctx_get_engine_info")] + public EngineInfo* get_engine_info(); + + [CCode (cname = "gpgme_ctx_set_engine_info")] + public GPGError.Error set_engine_info(Protocol proto, string file_name, string home_dir); + + public void signers_clear(); + + public GPGError.Error signers_add(Key key); + + public Key* signers_enum(int n); + + public void sig_notation_clear(); + + public GPGError.Error sig_notation_add(string name, string val, SigNotationFlags flags); + + public SigNotation* sig_notation_get(); + + [CCode (cname = "gpgme_get_key")] + private GPGError.Error get_key_(string fpr, out Key key, bool secret); + + [CCode (cname = "gpgme_get_key_")] + public Key get_key(string fpr, bool secret) throws GLib.Error { + Key key; + throw_if_error(get_key_(fpr, out key, secret)); + return key; + } + + public Context* wait(out GPGError.Error status, bool hang); + + public SignResult* op_sign_result(); + + [CCode (cname = "gpgme_op_sign")] + public GPGError.Error op_sign_(Data plain, Data sig, SigMode mode); + + [CCode (cname = "gpgme_op_sign_")] + public Data op_sign(Data plain, SigMode mode) throws GLib.Error { + Data sig = Data.create(); + throw_if_error(op_sign_(plain, sig, mode)); + return sig; + } + + public VerifyResult* op_verify_result(); + + [CCode (cname = "gpgme_op_verify")] + public GPGError.Error op_verify_(Data sig, Data signed_text, Data? plaintext); + + [CCode (cname = "gpgme_op_verify_")] + public Data op_verify(Data sig, Data signed_text) throws GLib.Error { + Data plaintext = Data.create(); + throw_if_error(op_verify_(sig, signed_text, plaintext)); + return plaintext; + } + + public EncryptResult* op_encrypt_result(); + + [CCode (cname = "gpgme_op_encrypt")] + public GPGError.Error op_encrypt_([CCode (array_length = false)] Key[] recp, EncryptFlags flags, Data plain, Data cipher); + + [CCode (cname = "gpgme_op_encrypt_")] + public Data op_encrypt(Key[] recp, EncryptFlags flags, Data plain) throws GLib.Error { + Data cipher = Data.create(); + throw_if_error(op_encrypt_(recp, flags, plain, cipher)); + return cipher; + } + + public DecryptResult* op_decrypt_result(); + + [CCode (cname = "gpgme_op_decrypt")] + public GPGError.Error op_decrypt_(Data cipher, Data plain); + + [CCode (cname = "gpgme_op_decrypt_")] + public Data op_decrypt(Data cipher) throws GLib.Error { + Data plain = Data.create(); + throw_if_error(op_decrypt_(cipher, plain)); + return plain; + } + + public GPGError.Error op_export(string? pattern, ExportMode mode, Data keydata); + + public GPGError.Error op_import(Data keydata); + + public unowned ImportResult op_import_result(); + + [CCode (cname = "gpgme_op_keylist_start")] + private GPGError.Error op_keylist_start_(string? pattern = null, int secret_only = 0); + + [CCode (cname = "gpgme_op_keylist_start_")] + public void op_keylist_start(string? pattern = null, int secret_only = 0) throws GLib.Error { + throw_if_error(op_keylist_start_(pattern, secret_only)); + } + + [CCode (cname = "gpgme_op_keylist_next")] + private GPGError.Error op_keylist_next_(out Key key); + + [CCode (cname = "gpgme_op_keylist_next_")] + public Key op_keylist_next() throws GLib.Error { + Key key; + throw_if_error(op_keylist_next_(out key)); + return key; + } + + [CCode (cname = "gpgme_op_keylist_end")] + private GPGError.Error op_keylist_end_(); + + [CCode (cname = "gpgme_op_keylist_end_")] + public void op_keylist_end() throws GLib.Error { + throw_if_error(op_keylist_end_()); + } + + public KeylistResult op_keylist_result(); + } + + [Flags] + [CCode (cname="unsigned int")] + public enum ImportStatusFlags { + [CCode (cname = "GPGME_IMPORT_NEW")] + NEW, + [CCode (cname = "GPGME_IMPORT_UID")] + UID, + [CCode (cname = "GPGME_IMPORT_SIG")] + SIG, + [CCode (cname = "GPGME_IMPORT_SUBKEY")] + SUBKEY, + [CCode (cname = "GPGME_IMPORT_SECRET")] + SECRET + } + + [Compact] + [CCode (cname = "struct _gpgme_import_status")] + public class ImportStatus { + public ImportStatus? next; + public string fpr; + public GPGError.Error result; + public ImportStatusFlags status; + } + + [Compact] + [CCode (cname = "struct _gpgme_op_import_result")] + public class ImportResult { + public int considered; + public int no_user_id; + public int imported; + public int imported_rsa; + public int unchanged; + public int new_user_ids; + public int new_sub_keys; + public int new_signatures; + public int new_revocations; + public int secret_read; + public int secret_imported; + public int secret_unchanged; + public int not_imported; + public ImportStatus imports; + } + + [Compact] + [CCode (cname = "struct _gpgme_op_keylist_result")] + public class KeylistResult { + uint truncated; + } + + [Compact] + [CCode (cname = "struct gpgme_data", free_function = "gpgme_data_release", cprefix = "gpgme_data_")] + public class Data { + + public static GPGError.Error new(out Data d); + + public static Data create() throws GLib.Error { + Data data; + throw_if_error(@new(out data)); + return data; + } + + [CCode (cname = "gpgme_data_new_from_mem")] + public static GPGError.Error new_from_memory(out Data d, char[] buffer, bool copy); + + public static Data create_from_memory(uint8[] buffer, bool copy) throws GLib.Error { + Data data; + throw_if_error(new_from_memory(out data, (char[]) buffer, copy)); + return data; + } + + [CCode (cname = "gpgme_data_new_from_file")] + public static GPGError.Error new_from_file(out Data d, string filename, int copy = 1); + + public static Data create_from_file(string filename, int copy = 1) throws GLib.Error { + Data data; + throw_if_error(new_from_file(out data, filename, copy)); + return data; + } + + [CCode (cname = "gpgme_data_release_and_get_mem")] + public string release_and_get_mem(out size_t len); + + public ssize_t read([CCode (array_length = false)] uint8[] buf, size_t len); + + public ssize_t write(uint8[] buf); + + public long seek(long offset, int whence=0); + + public GPGError.Error set_file_name(string file_name); + + public DataEncoding *get_encoding(); + + public GPGError.Error set_encoding(DataEncoding enc); + } + + [CCode (cname = "gpgme_get_protocol_name")] + public unowned string get_protocol_name(Protocol p); + + [CCode (cname = "gpgme_pubkey_algo_name")] + public unowned string get_public_key_algorithm_name(PublicKeyAlgorithm algo); + + [CCode (cname = "gpgme_hash_algo_name")] + public unowned string get_hash_algorithm_name(HashAlgorithm algo); + + [CCode (cname = "gpgme_passphrase_cb_t", has_target = false)] + public delegate GPGError.Error passphrase_callback(void* hook, string uid_hint, string passphrase_info, bool prev_was_bad, int fd); + + [CCode (cname = "gpgme_check_version")] + public unowned string check_version(string? required_version = null); + + [CCode (cname = "gpgme_engine_check_version")] + public GPGError.Error engine_check_version(Protocol proto); + + [CCode (cname = "gpgme_get_engine_info")] + public GPGError.Error get_engine_info(out EngineInfo? engine_info); + + [CCode (cname = "gpgme_strerror_r")] + public int strerror_r(GPGError.Error err, uint8[] buf); + + [CCode (cname = "gpgme_strerror")] + public unowned string strerror(GPGError.Error err); + + private void throw_if_error(GPGError.Error error) throws GLib.Error { + if (error.code != GPGError.ErrorCode.NO_ERROR) { + throw new GLib.Error(-1, error.code, "%s", error.to_string()); + } + } +} -- cgit v1.2.3-54-g00ecf From 6eb1b53e60a12f82c8d47a5824bf9cee954ccdc2 Mon Sep 17 00:00:00 2001 From: hrxi Date: Mon, 19 Jun 2023 14:08:57 +0200 Subject: Merge `signal-protocol` into `omemo` plugin Same reasoning as for the `openpgp` plugin. --- .github/workflows/build.yml | 2 +- plugins/CMakeLists.txt | 3 - plugins/omemo/CMakeLists.txt | 51 +- plugins/omemo/src/signal/context.vala | 103 ++++ plugins/omemo/src/signal/signal_helper.c | 377 ++++++++++++ plugins/omemo/src/signal/signal_helper.h | 45 ++ plugins/omemo/src/signal/simple_iks.vala | 40 ++ plugins/omemo/src/signal/simple_pks.vala | 33 ++ plugins/omemo/src/signal/simple_spks.vala | 33 ++ plugins/omemo/src/signal/simple_ss.vala | 75 +++ plugins/omemo/src/signal/store.vala | 415 +++++++++++++ plugins/omemo/src/signal/util.vala | 45 ++ plugins/omemo/tests/signal/common.vala | 92 +++ plugins/omemo/tests/signal/curve25519.vala | 207 +++++++ plugins/omemo/tests/signal/hkdf.vala | 59 ++ plugins/omemo/tests/signal/session_builder.vala | 400 +++++++++++++ plugins/omemo/tests/signal/testcase.vala | 80 +++ plugins/omemo/vapi/libsignal-protocol-c.vapi | 657 +++++++++++++++++++++ plugins/signal-protocol/CMakeLists.txt | 91 --- plugins/signal-protocol/src/context.vala | 103 ---- plugins/signal-protocol/src/signal_helper.c | 377 ------------ plugins/signal-protocol/src/signal_helper.h | 45 -- plugins/signal-protocol/src/simple_iks.vala | 40 -- plugins/signal-protocol/src/simple_pks.vala | 33 -- plugins/signal-protocol/src/simple_spks.vala | 33 -- plugins/signal-protocol/src/simple_ss.vala | 75 --- plugins/signal-protocol/src/store.vala | 415 ------------- plugins/signal-protocol/src/util.vala | 45 -- plugins/signal-protocol/tests/common.vala | 92 --- plugins/signal-protocol/tests/curve25519.vala | 207 ------- plugins/signal-protocol/tests/hkdf.vala | 59 -- plugins/signal-protocol/tests/session_builder.vala | 400 ------------- plugins/signal-protocol/tests/testcase.vala | 80 --- .../vapi/signal-protocol-native.vapi | 274 --------- .../vapi/signal-protocol-public.vapi | 384 ------------ 35 files changed, 2709 insertions(+), 2761 deletions(-) create mode 100644 plugins/omemo/src/signal/context.vala create mode 100644 plugins/omemo/src/signal/signal_helper.c create mode 100644 plugins/omemo/src/signal/signal_helper.h create mode 100644 plugins/omemo/src/signal/simple_iks.vala create mode 100644 plugins/omemo/src/signal/simple_pks.vala create mode 100644 plugins/omemo/src/signal/simple_spks.vala create mode 100644 plugins/omemo/src/signal/simple_ss.vala create mode 100644 plugins/omemo/src/signal/store.vala create mode 100644 plugins/omemo/src/signal/util.vala create mode 100644 plugins/omemo/tests/signal/common.vala create mode 100644 plugins/omemo/tests/signal/curve25519.vala create mode 100644 plugins/omemo/tests/signal/hkdf.vala create mode 100644 plugins/omemo/tests/signal/session_builder.vala create mode 100644 plugins/omemo/tests/signal/testcase.vala create mode 100644 plugins/omemo/vapi/libsignal-protocol-c.vapi delete mode 100644 plugins/signal-protocol/CMakeLists.txt delete mode 100644 plugins/signal-protocol/src/context.vala delete mode 100644 plugins/signal-protocol/src/signal_helper.c delete mode 100644 plugins/signal-protocol/src/signal_helper.h delete mode 100644 plugins/signal-protocol/src/simple_iks.vala delete mode 100644 plugins/signal-protocol/src/simple_pks.vala delete mode 100644 plugins/signal-protocol/src/simple_spks.vala delete mode 100644 plugins/signal-protocol/src/simple_ss.vala delete mode 100644 plugins/signal-protocol/src/store.vala delete mode 100644 plugins/signal-protocol/src/util.vala delete mode 100644 plugins/signal-protocol/tests/common.vala delete mode 100644 plugins/signal-protocol/tests/curve25519.vala delete mode 100644 plugins/signal-protocol/tests/hkdf.vala delete mode 100644 plugins/signal-protocol/tests/session_builder.vala delete mode 100644 plugins/signal-protocol/tests/testcase.vala delete mode 100644 plugins/signal-protocol/vapi/signal-protocol-native.vapi delete mode 100644 plugins/signal-protocol/vapi/signal-protocol-public.vapi diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e3a6a2b7..590035e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: - run: ./configure --with-tests --with-libsignal-in-tree - run: make - run: build/xmpp-vala-test - - run: build/signal-protocol-vala-test + - run: build/omemo-test build-meson: runs-on: ubuntu-22.04 steps: diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 3ce96815..03d7f575 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,6 +1,3 @@ foreach(plugin ${PLUGINS}) - if ("omemo" STREQUAL ${plugin}) - add_subdirectory(signal-protocol) - endif () add_subdirectory(${plugin}) endforeach(plugin) diff --git a/plugins/omemo/CMakeLists.txt b/plugins/omemo/CMakeLists.txt index dc9a93b0..7ecaa0b8 100644 --- a/plugins/omemo/CMakeLists.txt +++ b/plugins/omemo/CMakeLists.txt @@ -12,6 +12,11 @@ find_packages(OMEMO_PACKAGES REQUIRED GTK4 ) +# libsignal-protocol-c has a history of breaking compatibility on the patch level +# we'll have to check compatibility for every new release +# distro maintainers may update this dependency after compatibility tests +find_package(SignalProtocol 2.3.2 REQUIRED) + set(RESOURCE_LIST contact_details_dialog.ui manage_key_dialog.ui @@ -52,6 +57,14 @@ SOURCES src/protocol/message_flag.vala src/protocol/stream_module.vala + src/signal/context.vala + src/signal/simple_iks.vala + src/signal/simple_ss.vala + src/signal/simple_pks.vala + src/signal/simple_spks.vala + src/signal/store.vala + src/signal/util.vala + src/ui/account_settings_entry.vala src/ui/bad_messages_populator.vala src/ui/call_encryption_entry.vala @@ -64,22 +77,52 @@ SOURCES src/ui/util.vala CUSTOM_VAPIS ${CMAKE_BINARY_DIR}/exports/crypto-vala.vapi - ${CMAKE_BINARY_DIR}/exports/signal-protocol.vapi ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi ${CMAKE_BINARY_DIR}/exports/qlite.vapi ${CMAKE_BINARY_DIR}/exports/dino.vapi ${CMAKE_CURRENT_SOURCE_DIR}/vapi/libqrencode.vapi + ${CMAKE_CURRENT_SOURCE_DIR}/vapi/libsignal-protocol-c.vapi PACKAGES ${OMEMO_PACKAGES} GRESOURCES ${OMEMO_GRESOURCES_XML} +GENERATE_VAPI + omemo +GENERATE_HEADER + omemo ) -add_definitions(${VALA_CFLAGS} -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\" -DG_LOG_DOMAIN="OMEMO") -add_library(omemo SHARED ${OMEMO_VALA_C} ${OMEMO_GRESOURCES_TARGET}) +add_definitions(${VALA_CFLAGS} -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\" -DG_LOG_DOMAIN="OMEMO") +add_library(omemo SHARED ${OMEMO_VALA_C} ${OMEMO_GRESOURCES_TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/src/signal/signal_helper.c) add_dependencies(omemo ${GETTEXT_PACKAGE}-translations) -target_link_libraries(omemo libdino signal-protocol-vala crypto-vala ${OMEMO_PACKAGES} libqrencode) +target_include_directories(omemo PUBLIC src) +target_link_libraries(omemo libdino crypto-vala gcrypt ${OMEMO_PACKAGES} libqrencode signal-protocol-c) set_target_properties(omemo PROPERTIES PREFIX "") set_target_properties(omemo PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/) install(TARGETS omemo ${PLUGIN_INSTALL}) + +if(BUILD_TESTS) + vala_precompile(OMEMO_TEST_VALA_C + SOURCES + "tests/signal/common.vala" + "tests/signal/testcase.vala" + + "tests/signal/curve25519.vala" + "tests/signal/hkdf.vala" + "tests/signal/session_builder.vala" + CUSTOM_VAPIS + ${CMAKE_BINARY_DIR}/exports/omemo_internal.vapi + ${CMAKE_BINARY_DIR}/exports/qlite.vapi + ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi + ${CMAKE_BINARY_DIR}/exports/dino.vapi + ${CMAKE_CURRENT_SOURCE_DIR}/vapi/libsignal-protocol-c.vapi + PACKAGES + ${OMEMO_PACKAGES} + ) + + set(CFLAGS ${VALA_CFLAGS}) + add_executable(omemo-test ${OMEMO_TEST_VALA_C}) + add_dependencies(omemo-test omemo) + target_link_libraries(omemo-test omemo ${OMEMO_PACKAGES}) +endif(BUILD_TESTS) diff --git a/plugins/omemo/src/signal/context.vala b/plugins/omemo/src/signal/context.vala new file mode 100644 index 00000000..40a07b0f --- /dev/null +++ b/plugins/omemo/src/signal/context.vala @@ -0,0 +1,103 @@ +namespace Signal { + +public class Context { + internal NativeContext native_context; + private RecMutex mutex = RecMutex(); + + static void locking_function_lock(void* user_data) { + Context ctx = (Context) user_data; + ctx.mutex.lock(); + } + + static void locking_function_unlock(void* user_data) { + Context ctx = (Context) user_data; + ctx.mutex.unlock(); + } + + static void stderr_log(LogLevel level, string message, size_t len, void* user_data) { + printerr(@"$level: $message\n"); + } + + public Context(bool log = false) throws Error { + throw_by_code(NativeContext.create(out native_context, this), "Error initializing native context"); + throw_by_code(native_context.set_locking_functions(locking_function_lock, locking_function_unlock), "Error initializing native locking functions"); + if (log) native_context.set_log_function(stderr_log); + setup_crypto_provider(native_context); + } + + public Store create_store() { + return new Store(this); + } + + public void randomize(uint8[] data) throws Error { + throw_by_code(Signal.native_random(data)); + } + + public SignedPreKeyRecord generate_signed_pre_key(IdentityKeyPair identity_key_pair, int32 id, uint64 timestamp = 0) throws Error { + if (timestamp == 0) timestamp = new DateTime.now_utc().to_unix(); + SignedPreKeyRecord res; + throw_by_code(Protocol.KeyHelper.generate_signed_pre_key(out res, identity_key_pair, id, timestamp, native_context)); + return res; + } + + public Gee.Set generate_pre_keys(uint start, uint count) throws Error { + Gee.Set res = new Gee.HashSet(); + for(uint i = start; i < start+count; i++) { + ECKeyPair pair = generate_key_pair(); + PreKeyRecord record; + throw_by_code(PreKeyRecord.create(out record, i, pair)); + res.add(record); + } + return res; + } + + public ECPublicKey decode_public_key(uint8[] bytes) throws Error { + ECPublicKey public_key; + throw_by_code(curve_decode_point(out public_key, bytes, native_context), "Error decoding public key"); + return public_key; + } + + public ECPrivateKey decode_private_key(uint8[] bytes) throws Error { + ECPrivateKey private_key; + throw_by_code(curve_decode_private_point(out private_key, bytes, native_context), "Error decoding private key"); + return private_key; + } + + public ECKeyPair generate_key_pair() throws Error { + ECKeyPair key_pair; + throw_by_code(curve_generate_key_pair(native_context, out key_pair), "Error generating key pair"); + return key_pair; + } + + public uint8[] calculate_signature(ECPrivateKey signing_key, uint8[] message) throws Error { + Buffer signature; + throw_by_code(Curve.calculate_signature(native_context, out signature, signing_key, message), "Error calculating signature"); + return signature.data; + } + + public SignalMessage deserialize_signal_message(uint8[] data) throws Error { + SignalMessage res; + throw_by_code(signal_message_deserialize(out res, data, native_context)); + return res; + } + + public SignalMessage copy_signal_message(CiphertextMessage original) throws Error { + SignalMessage res; + throw_by_code(signal_message_copy(out res, (SignalMessage) original, native_context)); + return res; + } + + public PreKeySignalMessage deserialize_pre_key_signal_message(uint8[] data) throws Error { + PreKeySignalMessage res; + throw_by_code(pre_key_signal_message_deserialize(out res, data, native_context)); + return res; + } + + public PreKeySignalMessage copy_pre_key_signal_message(CiphertextMessage original) throws Error { + PreKeySignalMessage res; + throw_by_code(pre_key_signal_message_copy(out res, (PreKeySignalMessage) original, native_context)); + return res; + } +} + +} diff --git a/plugins/omemo/src/signal/signal_helper.c b/plugins/omemo/src/signal/signal_helper.c new file mode 100644 index 00000000..17682929 --- /dev/null +++ b/plugins/omemo/src/signal/signal_helper.c @@ -0,0 +1,377 @@ +#include "signal_helper.h" + +#include + +signal_type_base* signal_type_ref_vapi(void* instance) { + g_return_val_if_fail(instance != NULL, NULL); + signal_type_ref(instance); + return instance; +} + +signal_type_base* signal_type_unref_vapi(void* instance) { + g_return_val_if_fail(instance != NULL, NULL); + signal_type_unref(instance); + return NULL; +} + +signal_protocol_address* signal_protocol_address_new(const gchar* name, int32_t device_id) { + g_return_val_if_fail(name != NULL, NULL); + signal_protocol_address* address = malloc(sizeof(signal_protocol_address)); + address->device_id = -1; + address->name = NULL; + signal_protocol_address_set_name(address, name); + signal_protocol_address_set_device_id(address, device_id); + return address; +} + +void signal_protocol_address_free(signal_protocol_address* ptr) { + g_return_if_fail(ptr != NULL); + if (ptr->name) { + g_free((void*)ptr->name); + } + return free(ptr); +} + +void signal_protocol_address_set_name(signal_protocol_address* self, const gchar* name) { + g_return_if_fail(self != NULL); + g_return_if_fail(name != NULL); + gchar* n = g_malloc(strlen(name)+1); + memcpy(n, name, strlen(name)); + n[strlen(name)] = 0; + if (self->name) { + g_free((void*)self->name); + } + self->name = n; + self->name_len = strlen(n); +} + +gchar* signal_protocol_address_get_name(signal_protocol_address* self) { + g_return_val_if_fail(self != NULL, NULL); + g_return_val_if_fail(self->name != NULL, 0); + gchar* res = g_malloc(sizeof(char) * (self->name_len + 1)); + memcpy(res, self->name, self->name_len); + res[self->name_len] = 0; + return res; +} + +int32_t signal_protocol_address_get_device_id(signal_protocol_address* self) { + g_return_val_if_fail(self != NULL, -1); + return self->device_id; +} + +void signal_protocol_address_set_device_id(signal_protocol_address* self, int32_t device_id) { + g_return_if_fail(self != NULL); + self->device_id = device_id; +} + +int signal_vala_randomize(uint8_t *data, size_t len) { + gcry_randomize(data, len, GCRY_STRONG_RANDOM); + return SG_SUCCESS; +} + +int signal_vala_random_generator(uint8_t *data, size_t len, void *user_data) { + gcry_randomize(data, len, GCRY_STRONG_RANDOM); + return SG_SUCCESS; +} + +int signal_vala_hmac_sha256_init(void **hmac_context, const uint8_t *key, size_t key_len, void *user_data) { + gcry_mac_hd_t* ctx = malloc(sizeof(gcry_mac_hd_t)); + if (!ctx) return SG_ERR_NOMEM; + + if (gcry_mac_open(ctx, GCRY_MAC_HMAC_SHA256, 0, 0)) { + free(ctx); + return SG_ERR_UNKNOWN; + } + + if (gcry_mac_setkey(*ctx, key, key_len)) { + free(ctx); + return SG_ERR_UNKNOWN; + } + + *hmac_context = ctx; + + return SG_SUCCESS; +} + +int signal_vala_hmac_sha256_update(void *hmac_context, const uint8_t *data, size_t data_len, void *user_data) { + gcry_mac_hd_t* ctx = hmac_context; + + if (gcry_mac_write(*ctx, data, data_len)) return SG_ERR_UNKNOWN; + + return SG_SUCCESS; +} + +int signal_vala_hmac_sha256_final(void *hmac_context, signal_buffer **output, void *user_data) { + size_t len = gcry_mac_get_algo_maclen(GCRY_MAC_HMAC_SHA256); + uint8_t md[len]; + gcry_mac_hd_t* ctx = hmac_context; + + if (gcry_mac_read(*ctx, md, &len)) return SG_ERR_UNKNOWN; + + signal_buffer *output_buffer = signal_buffer_create(md, len); + if (!output_buffer) return SG_ERR_NOMEM; + + *output = output_buffer; + + return SG_SUCCESS; +} + +void signal_vala_hmac_sha256_cleanup(void *hmac_context, void *user_data) { + gcry_mac_hd_t* ctx = hmac_context; + if (ctx) { + gcry_mac_close(*ctx); + free(ctx); + } +} + +int signal_vala_sha512_digest_init(void **digest_context, void *user_data) { + gcry_md_hd_t* ctx = malloc(sizeof(gcry_mac_hd_t)); + if (!ctx) return SG_ERR_NOMEM; + + if (gcry_md_open(ctx, GCRY_MD_SHA512, 0)) { + free(ctx); + return SG_ERR_UNKNOWN; + } + + *digest_context = ctx; + + return SG_SUCCESS; +} + +int signal_vala_sha512_digest_update(void *digest_context, const uint8_t *data, size_t data_len, void *user_data) { + gcry_md_hd_t* ctx = digest_context; + + gcry_md_write(*ctx, data, data_len); + + return SG_SUCCESS; +} + +int signal_vala_sha512_digest_final(void *digest_context, signal_buffer **output, void *user_data) { + size_t len = gcry_md_get_algo_dlen(GCRY_MD_SHA512); + gcry_md_hd_t* ctx = digest_context; + + uint8_t* md = gcry_md_read(*ctx, GCRY_MD_SHA512); + if (!md) return SG_ERR_UNKNOWN; + + gcry_md_reset(*ctx); + + signal_buffer *output_buffer = signal_buffer_create(md, len); + free(md); + if (!output_buffer) return SG_ERR_NOMEM; + + *output = output_buffer; + + return SG_SUCCESS; +} + +void signal_vala_sha512_digest_cleanup(void *digest_context, void *user_data) { + gcry_md_hd_t* ctx = digest_context; + if (ctx) { + gcry_md_close(*ctx); + free(ctx); + } +} + +const int aes_cipher(int cipher, size_t key_len, int* algo, int* mode) { + switch (key_len) { + case 16: + *algo = GCRY_CIPHER_AES128; + break; + case 24: + *algo = GCRY_CIPHER_AES192; + break; + case 32: + *algo = GCRY_CIPHER_AES256; + break; + default: + return SG_ERR_UNKNOWN; + } + switch (cipher) { + case SG_CIPHER_AES_CBC_PKCS5: + *mode = GCRY_CIPHER_MODE_CBC; + break; + case SG_CIPHER_AES_CTR_NOPADDING: + *mode = GCRY_CIPHER_MODE_CTR; + break; + case SG_CIPHER_AES_GCM_NOPADDING: + *mode = GCRY_CIPHER_MODE_GCM; + break; + default: + return SG_ERR_UNKNOWN; + } + return SG_SUCCESS; +} + +int signal_vala_encrypt(signal_buffer **output, + int cipher, + const uint8_t *key, size_t key_len, + const uint8_t *iv, size_t iv_len, + const uint8_t *plaintext, size_t plaintext_len, + void *user_data) { + int algo, mode, error_code = SG_ERR_UNKNOWN; + if (aes_cipher(cipher, key_len, &algo, &mode)) return SG_ERR_INVAL; + + gcry_cipher_hd_t ctx = {0}; + + if (gcry_cipher_open(&ctx, algo, mode, 0)) return SG_ERR_NOMEM; + + signal_buffer* padded = 0; + signal_buffer* out_buf = 0; + goto no_error; +error: + gcry_cipher_close(ctx); + if (padded != 0) { + signal_buffer_bzero_free(padded); + } + if (out_buf != 0) { + signal_buffer_free(out_buf); + } + return error_code; +no_error: + + if (gcry_cipher_setkey(ctx, key, key_len)) goto error; + + uint8_t tag_len = 0, pad_len = 0; + switch (cipher) { + case SG_CIPHER_AES_CBC_PKCS5: + if (gcry_cipher_setiv(ctx, iv, iv_len)) goto error; + pad_len = 16 - (plaintext_len % 16); + if (pad_len == 0) pad_len = 16; + break; + case SG_CIPHER_AES_CTR_NOPADDING: + if (gcry_cipher_setctr(ctx, iv, iv_len)) goto error; + break; + case SG_CIPHER_AES_GCM_NOPADDING: + if (gcry_cipher_setiv(ctx, iv, iv_len)) goto error; + tag_len = 16; + break; + default: + return SG_ERR_UNKNOWN; + } + + size_t padded_len = plaintext_len + pad_len; + padded = signal_buffer_alloc(padded_len); + if (padded == 0) { + error_code = SG_ERR_NOMEM; + goto error; + } + + memset(signal_buffer_data(padded) + plaintext_len, pad_len, pad_len); + memcpy(signal_buffer_data(padded), plaintext, plaintext_len); + + out_buf = signal_buffer_alloc(padded_len + tag_len); + if (out_buf == 0) { + error_code = SG_ERR_NOMEM; + goto error; + } + + if (gcry_cipher_encrypt(ctx, signal_buffer_data(out_buf), padded_len, signal_buffer_data(padded), padded_len)) goto error; + + if (tag_len > 0) { + if (gcry_cipher_gettag(ctx, signal_buffer_data(out_buf) + padded_len, tag_len)) goto error; + } + + *output = out_buf; + out_buf = 0; + + signal_buffer_bzero_free(padded); + padded = 0; + + gcry_cipher_close(ctx); + return SG_SUCCESS; +} + +int signal_vala_decrypt(signal_buffer **output, + int cipher, + const uint8_t *key, size_t key_len, + const uint8_t *iv, size_t iv_len, + const uint8_t *ciphertext, size_t ciphertext_len, + void *user_data) { + int algo, mode, error_code = SG_ERR_UNKNOWN; + *output = 0; + if (aes_cipher(cipher, key_len, &algo, &mode)) return SG_ERR_INVAL; + if (ciphertext_len == 0) return SG_ERR_INVAL; + + gcry_cipher_hd_t ctx = {0}; + + if (gcry_cipher_open(&ctx, algo, mode, 0)) return SG_ERR_NOMEM; + + signal_buffer* out_buf = 0; + goto no_error; +error: + gcry_cipher_close(ctx); + if (out_buf != 0) { + signal_buffer_bzero_free(out_buf); + } + return error_code; +no_error: + + if (gcry_cipher_setkey(ctx, key, key_len)) goto error; + + uint8_t tag_len = 0, pkcs_pad = FALSE; + switch (cipher) { + case SG_CIPHER_AES_CBC_PKCS5: + if (gcry_cipher_setiv(ctx, iv, iv_len)) goto error; + pkcs_pad = TRUE; + break; + case SG_CIPHER_AES_CTR_NOPADDING: + if (gcry_cipher_setctr(ctx, iv, iv_len)) goto error; + break; + case SG_CIPHER_AES_GCM_NOPADDING: + if (gcry_cipher_setiv(ctx, iv, iv_len)) goto error; + if (ciphertext_len < 16) goto error; + tag_len = 16; + break; + default: + goto error; + } + + size_t padded_len = ciphertext_len - tag_len; + out_buf = signal_buffer_alloc(padded_len); + if (out_buf == 0) { + error_code = SG_ERR_NOMEM; + goto error; + } + + if (gcry_cipher_decrypt(ctx, signal_buffer_data(out_buf), signal_buffer_len(out_buf), ciphertext, padded_len)) goto error; + + if (tag_len > 0) { + if (gcry_cipher_checktag(ctx, ciphertext + padded_len, tag_len)) goto error; + } + + if (pkcs_pad) { + uint8_t pad_len = signal_buffer_data(out_buf)[padded_len - 1]; + if (pad_len > 16 || pad_len > padded_len) goto error; + *output = signal_buffer_create(signal_buffer_data(out_buf), padded_len - pad_len); + signal_buffer_bzero_free(out_buf); + out_buf = 0; + } else { + *output = out_buf; + out_buf = 0; + } + + gcry_cipher_close(ctx); + return SG_SUCCESS; +} + +void setup_signal_vala_crypto_provider(signal_context *context) +{ + gcry_check_version(NULL); + + signal_crypto_provider provider = { + .random_func = signal_vala_random_generator, + .hmac_sha256_init_func = signal_vala_hmac_sha256_init, + .hmac_sha256_update_func = signal_vala_hmac_sha256_update, + .hmac_sha256_final_func = signal_vala_hmac_sha256_final, + .hmac_sha256_cleanup_func = signal_vala_hmac_sha256_cleanup, + .sha512_digest_init_func = signal_vala_sha512_digest_init, + .sha512_digest_update_func = signal_vala_sha512_digest_update, + .sha512_digest_final_func = signal_vala_sha512_digest_final, + .sha512_digest_cleanup_func = signal_vala_sha512_digest_cleanup, + .encrypt_func = signal_vala_encrypt, + .decrypt_func = signal_vala_decrypt, + .user_data = 0 + }; + + signal_context_set_crypto_provider(context, &provider); +} diff --git a/plugins/omemo/src/signal/signal_helper.h b/plugins/omemo/src/signal/signal_helper.h new file mode 100644 index 00000000..949a3c7b --- /dev/null +++ b/plugins/omemo/src/signal/signal_helper.h @@ -0,0 +1,45 @@ +#ifndef SIGNAL_PROTOCOL_VALA_HELPER +#define SIGNAL_PROTOCOL_VALA_HELPER 1 + +#include +#include +#include + +#define SG_CIPHER_AES_GCM_NOPADDING 1000 + +signal_type_base* signal_type_ref_vapi(void* what); +signal_type_base* signal_type_unref_vapi(void* what); + +signal_protocol_address* signal_protocol_address_new(const gchar* name, int32_t device_id); +void signal_protocol_address_free(signal_protocol_address* ptr); +void signal_protocol_address_set_name(signal_protocol_address* self, const gchar* name); +gchar* signal_protocol_address_get_name(signal_protocol_address* self); +void signal_protocol_address_set_device_id(signal_protocol_address* self, int32_t device_id); +int32_t signal_protocol_address_get_device_id(signal_protocol_address* self); + +int signal_vala_randomize(uint8_t *data, size_t len); +int signal_vala_random_generator(uint8_t *data, size_t len, void *user_data); +int signal_vala_hmac_sha256_init(void **hmac_context, const uint8_t *key, size_t key_len, void *user_data); +int signal_vala_hmac_sha256_update(void *hmac_context, const uint8_t *data, size_t data_len, void *user_data); +int signal_vala_hmac_sha256_final(void *hmac_context, signal_buffer **output, void *user_data); +void signal_vala_hmac_sha256_cleanup(void *hmac_context, void *user_data); +int signal_vala_sha512_digest_init(void **digest_context, void *user_data); +int signal_vala_sha512_digest_update(void *digest_context, const uint8_t *data, size_t data_len, void *user_data); +int signal_vala_sha512_digest_final(void *digest_context, signal_buffer **output, void *user_data); +void signal_vala_sha512_digest_cleanup(void *digest_context, void *user_data); + +int signal_vala_encrypt(signal_buffer **output, + int cipher, + const uint8_t *key, size_t key_len, + const uint8_t *iv, size_t iv_len, + const uint8_t *plaintext, size_t plaintext_len, + void *user_data); +int signal_vala_decrypt(signal_buffer **output, + int cipher, + const uint8_t *key, size_t key_len, + const uint8_t *iv, size_t iv_len, + const uint8_t *ciphertext, size_t ciphertext_len, + void *user_data); +void setup_signal_vala_crypto_provider(signal_context *context); + +#endif diff --git a/plugins/omemo/src/signal/simple_iks.vala b/plugins/omemo/src/signal/simple_iks.vala new file mode 100644 index 00000000..5247c455 --- /dev/null +++ b/plugins/omemo/src/signal/simple_iks.vala @@ -0,0 +1,40 @@ +using Gee; + +namespace Signal { + +public class SimpleIdentityKeyStore : IdentityKeyStore { + public override Bytes identity_key_private { get; set; } + public override Bytes identity_key_public { get; set; } + public override uint32 local_registration_id { get; set; } + private Map> trusted_identities = new HashMap>(); + + public override void save_identity(Address address, uint8[] key) throws Error { + string name = address.name; + if (trusted_identities.has_key(name)) { + if (trusted_identities[name].has_key(address.device_id)) { + trusted_identities[name][address.device_id].key = key; + trusted_identity_updated(trusted_identities[name][address.device_id]); + } else { + trusted_identities[name][address.device_id] = new TrustedIdentity.by_address(address, key); + trusted_identity_added(trusted_identities[name][address.device_id]); + } + } else { + trusted_identities[name] = new HashMap(); + trusted_identities[name][address.device_id] = new TrustedIdentity.by_address(address, key); + trusted_identity_added(trusted_identities[name][address.device_id]); + } + } + + public override bool is_trusted_identity(Address address, uint8[] key) throws Error { + if (!trusted_identities.has_key(address.name)) return true; + if (!trusted_identities[address.name].has_key(address.device_id)) return true; + uint8[] other_key = trusted_identities[address.name][address.device_id].key; + if (other_key.length != key.length) return false; + for (int i = 0; i < key.length; i++) { + if (other_key[i] != key[i]) return false; + } + return true; + } +} + +} diff --git a/plugins/omemo/src/signal/simple_pks.vala b/plugins/omemo/src/signal/simple_pks.vala new file mode 100644 index 00000000..1f059fda --- /dev/null +++ b/plugins/omemo/src/signal/simple_pks.vala @@ -0,0 +1,33 @@ +using Gee; + +namespace Signal { + +public class SimplePreKeyStore : PreKeyStore { + private Map pre_key_map = new HashMap(); + + public override uint8[]? load_pre_key(uint32 pre_key_id) throws Error { + if (contains_pre_key(pre_key_id)) { + return pre_key_map[pre_key_id].record; + } + return null; + } + + public override void store_pre_key(uint32 pre_key_id, uint8[] record) throws Error { + PreKeyStore.Key key = new Key(pre_key_id, record); + pre_key_map[pre_key_id] = key; + pre_key_stored(key); + } + + public override bool contains_pre_key(uint32 pre_key_id) throws Error { + return pre_key_map.has_key(pre_key_id); + } + + public override void delete_pre_key(uint32 pre_key_id) throws Error { + PreKeyStore.Key key; + if (pre_key_map.unset(pre_key_id, out key)) { + pre_key_deleted(key); + } + } +} + +} \ No newline at end of file diff --git a/plugins/omemo/src/signal/simple_spks.vala b/plugins/omemo/src/signal/simple_spks.vala new file mode 100644 index 00000000..f0fe09ab --- /dev/null +++ b/plugins/omemo/src/signal/simple_spks.vala @@ -0,0 +1,33 @@ +using Gee; + +namespace Signal { + +public class SimpleSignedPreKeyStore : SignedPreKeyStore { + private Map pre_key_map = new HashMap(); + + public override uint8[]? load_signed_pre_key(uint32 pre_key_id) throws Error { + if (contains_signed_pre_key(pre_key_id)) { + return pre_key_map[pre_key_id].record; + } + return null; + } + + public override void store_signed_pre_key(uint32 pre_key_id, uint8[] record) throws Error { + SignedPreKeyStore.Key key = new Key(pre_key_id, record); + pre_key_map[pre_key_id] = key; + signed_pre_key_stored(key); + } + + public override bool contains_signed_pre_key(uint32 pre_key_id) throws Error { + return pre_key_map.has_key(pre_key_id); + } + + public override void delete_signed_pre_key(uint32 pre_key_id) throws Error { + SignedPreKeyStore.Key key; + if (pre_key_map.unset(pre_key_id, out key)) { + signed_pre_key_deleted(key); + } + } +} + +} \ No newline at end of file diff --git a/plugins/omemo/src/signal/simple_ss.vala b/plugins/omemo/src/signal/simple_ss.vala new file mode 100644 index 00000000..5213f736 --- /dev/null +++ b/plugins/omemo/src/signal/simple_ss.vala @@ -0,0 +1,75 @@ +using Gee; + +namespace Signal { + +public class SimpleSessionStore : SessionStore { + + private Map> session_map = new HashMap>(); + + public override uint8[]? load_session(Address address) throws Error { + if (session_map.has_key(address.name)) { + foreach (SessionStore.Session session in session_map[address.name]) { + if (session.device_id == address.device_id) return session.record; + } + } + return null; + } + + public override IntList get_sub_device_sessions(string name) throws Error { + IntList res = new IntList(); + if (session_map.has_key(name)) { + foreach (SessionStore.Session session in session_map[name]) { + res.add(session.device_id); + } + } + return res; + } + + public override void store_session(Address address, uint8[] record) throws Error { + if (contains_session(address)) { + delete_session(address); + } + if (!session_map.has_key(address.name)) { + session_map[address.name] = new ArrayList(); + } + SessionStore.Session session = new Session() { name = address.name, device_id = address.device_id, record = record }; + session_map[address.name].add(session); + session_stored(session); + } + + public override bool contains_session(Address address) throws Error { + if (!session_map.has_key(address.name)) return false; + foreach (SessionStore.Session session in session_map[address.name]) { + if (session.device_id == address.device_id) return true; + } + return false; + } + + public override void delete_session(Address address) throws Error { + if (!session_map.has_key(address.name)) throw_by_code(ErrorCode.UNKNOWN, "No session found"); + foreach (SessionStore.Session session in session_map[address.name]) { + if (session.device_id == address.device_id) { + session_map[address.name].remove(session); + if (session_map[address.name].size == 0) { + session_map.unset(address.name); + } + session_removed(session); + return; + } + } + } + + public override void delete_all_sessions(string name) throws Error { + if (session_map.has_key(name)) { + foreach (SessionStore.Session session in session_map[name]) { + session_map[name].remove(session); + if (session_map[name].size == 0) { + session_map.unset(name); + } + session_removed(session); + } + } + } +} + +} \ No newline at end of file diff --git a/plugins/omemo/src/signal/store.vala b/plugins/omemo/src/signal/store.vala new file mode 100644 index 00000000..b440d838 --- /dev/null +++ b/plugins/omemo/src/signal/store.vala @@ -0,0 +1,415 @@ +namespace Signal { + +public abstract class IdentityKeyStore : Object { + public abstract Bytes identity_key_private { get; set; } + public abstract Bytes identity_key_public { get; set; } + public abstract uint32 local_registration_id { get; set; } + + public signal void trusted_identity_added(TrustedIdentity id); + public signal void trusted_identity_updated(TrustedIdentity id); + + public abstract void save_identity(Address address, uint8[] key) throws Error ; + + public abstract bool is_trusted_identity(Address address, uint8[] key) throws Error ; + + public class TrustedIdentity { + public uint8[] key { get; set; } + public string name { get; private set; } + public int device_id { get; private set; } + + public TrustedIdentity(string name, int device_id, uint8[] key) { + this.key = key; + this.name = name; + this.device_id = device_id; + } + + public TrustedIdentity.by_address(Address address, uint8[] key) { + this(address.name, address.device_id, key); + } + } +} + +public abstract class SessionStore : Object { + + public signal void session_stored(Session session); + public signal void session_removed(Session session); + public abstract uint8[]? load_session(Address address) throws Error ; + + public abstract IntList get_sub_device_sessions(string name) throws Error ; + + public abstract void store_session(Address address, uint8[] record) throws Error ; + + public abstract bool contains_session(Address address) throws Error ; + + public abstract void delete_session(Address address) throws Error ; + + public abstract void delete_all_sessions(string name) throws Error ; + + public class Session { + public string name; + public int device_id; + public uint8[] record; + } +} + +public abstract class PreKeyStore : Object { + + public signal void pre_key_stored(Key key); + public signal void pre_key_deleted(Key key); + + public abstract uint8[]? load_pre_key(uint32 pre_key_id) throws Error ; + + public abstract void store_pre_key(uint32 pre_key_id, uint8[] record) throws Error ; + + public abstract bool contains_pre_key(uint32 pre_key_id) throws Error ; + + public abstract void delete_pre_key(uint32 pre_key_id) throws Error ; + + public class Key { + public uint32 key_id { get; private set; } + public uint8[] record { get; private set; } + + public Key(uint32 key_id, uint8[] record) { + this.key_id = key_id; + this.record = record; + } + } +} + +public abstract class SignedPreKeyStore : Object { + + public signal void signed_pre_key_stored(Key key); + public signal void signed_pre_key_deleted(Key key); + + public abstract uint8[]? load_signed_pre_key(uint32 pre_key_id) throws Error ; + + public abstract void store_signed_pre_key(uint32 pre_key_id, uint8[] record) throws Error ; + + public abstract bool contains_signed_pre_key(uint32 pre_key_id) throws Error ; + + public abstract void delete_signed_pre_key(uint32 pre_key_id) throws Error ; + + public class Key { + public uint32 key_id { get; private set; } + public uint8[] record { get; private set; } + + public Key(uint32 key_id, uint8[] record) { + this.key_id = key_id; + this.record = record; + } + } +} + +public class Store : Object { + public Context context { get; private set; } + public IdentityKeyStore identity_key_store { get; set; default = new SimpleIdentityKeyStore(); } + public SessionStore session_store { get; set; default = new SimpleSessionStore(); } + public PreKeyStore pre_key_store { get; set; default = new SimplePreKeyStore(); } + public SignedPreKeyStore signed_pre_key_store { get; set; default = new SimpleSignedPreKeyStore(); } + public uint32 local_registration_id { get { return identity_key_store.local_registration_id; } } + internal NativeStoreContext native_context {get { return native_store_context_; }} + private NativeStoreContext native_store_context_; + + static int iks_get_identity_key_pair(out Buffer public_data, out Buffer private_data, void* user_data) { + Store store = (Store) user_data; + public_data = new Buffer.from(store.identity_key_store.identity_key_public.get_data()); + private_data = new Buffer.from(store.identity_key_store.identity_key_private.get_data()); + return 0; + } + + static int iks_get_local_registration_id(void* user_data, out uint32 registration_id) { + Store store = (Store) user_data; + registration_id = store.identity_key_store.local_registration_id; + return 0; + } + + static int iks_save_identity(Address address, uint8[] key, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + store.identity_key_store.save_identity(address, key); + return 0; + }); + } + + static int iks_is_trusted_identity(Address address, uint8[] key, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + return store.identity_key_store.is_trusted_identity(address, key) ? 1 : 0; + }); + } + + static void iks_destroy_func(void* user_data) { + } + + static int ss_load_session_func(out Buffer? record, out Buffer? user_record, Address address, void* user_data) { + Store store = (Store) user_data; + user_record = null; // No support for user_record + uint8[]? res = null; + try { + res = store.session_store.load_session(address); + } catch (Error e) { + record = null; + return e.code; + } + if (res == null) { + record = null; + return 0; + } + record = new Buffer.from((!)res); + if (record == null) return ErrorCode.NOMEM; + return 1; + } + + static int ss_get_sub_device_sessions_func(out IntList? sessions, char[] name, void* user_data) { + Store store = (Store) user_data; + try { + sessions = store.session_store.get_sub_device_sessions(carr_to_string(name)); + } catch (Error e) { + sessions = null; + return e.code; + } + return 0; + } + + static int ss_store_session_func(Address address, uint8[] record, uint8[] user_record, void* user_data) { + // Ignoring user_record + Store store = (Store) user_data; + return catch_to_code(() => { + store.session_store.store_session(address, record); + return 0; + }); + } + + static int ss_contains_session_func(Address address, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + return store.session_store.contains_session(address) ? 1 : 0; + }); + } + + static int ss_delete_session_func(Address address, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + store.session_store.delete_session(address); + return 0; + }); + } + + static int ss_delete_all_sessions_func(char[] name, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + store.session_store.delete_all_sessions(carr_to_string(name)); + return 0; + }); + } + + static void ss_destroy_func(void* user_data) { + } + + static int pks_load_pre_key(out Buffer? record, uint32 pre_key_id, void* user_data) { + Store store = (Store) user_data; + uint8[]? res = null; + try { + res = store.pre_key_store.load_pre_key(pre_key_id); + } catch (Error e) { + record = null; + return e.code; + } + if (res == null) { + record = new Buffer(0); + return 0; + } + record = new Buffer.from((!)res); + if (record == null) return ErrorCode.NOMEM; + return 1; + } + + static int pks_store_pre_key(uint32 pre_key_id, uint8[] record, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + store.pre_key_store.store_pre_key(pre_key_id, record); + return 0; + }); + } + + static int pks_contains_pre_key(uint32 pre_key_id, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + return store.pre_key_store.contains_pre_key(pre_key_id) ? 1 : 0; + }); + } + + static int pks_remove_pre_key(uint32 pre_key_id, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + store.pre_key_store.delete_pre_key(pre_key_id); + return 0; + }); + } + + static void pks_destroy_func(void* user_data) { + } + + static int spks_load_signed_pre_key(out Buffer? record, uint32 pre_key_id, void* user_data) { + Store store = (Store) user_data; + uint8[]? res = null; + try { + res = store.signed_pre_key_store.load_signed_pre_key(pre_key_id); + } catch (Error e) { + record = null; + return e.code; + } + if (res == null) { + record = new Buffer(0); + return 0; + } + record = new Buffer.from((!)res); + if (record == null) return ErrorCode.NOMEM; + return 1; + } + + static int spks_store_signed_pre_key(uint32 pre_key_id, uint8[] record, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + store.signed_pre_key_store.store_signed_pre_key(pre_key_id, record); + return 0; + }); + } + + static int spks_contains_signed_pre_key(uint32 pre_key_id, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + return store.signed_pre_key_store.contains_signed_pre_key(pre_key_id) ? 1 : 0; + }); + } + + static int spks_remove_signed_pre_key(uint32 pre_key_id, void* user_data) { + Store store = (Store) user_data; + return catch_to_code(() => { + store.signed_pre_key_store.delete_signed_pre_key(pre_key_id); + return 0; + }); + } + + static void spks_destroy_func(void* user_data) { + } + + internal Store(Context context) { + this.context = context; + NativeStoreContext.create(out native_store_context_, context.native_context); + + NativeIdentityKeyStore iks = NativeIdentityKeyStore() { + get_identity_key_pair = iks_get_identity_key_pair, + get_local_registration_id = iks_get_local_registration_id, + save_identity = iks_save_identity, + is_trusted_identity = iks_is_trusted_identity, + destroy_func = iks_destroy_func, + user_data = this + }; + native_context.set_identity_key_store(iks); + + NativeSessionStore ss = NativeSessionStore() { + load_session_func = ss_load_session_func, + get_sub_device_sessions_func = ss_get_sub_device_sessions_func, + store_session_func = ss_store_session_func, + contains_session_func = ss_contains_session_func, + delete_session_func = ss_delete_session_func, + delete_all_sessions_func = ss_delete_all_sessions_func, + destroy_func = ss_destroy_func, + user_data = this + }; + native_context.set_session_store(ss); + + NativePreKeyStore pks = NativePreKeyStore() { + load_pre_key = pks_load_pre_key, + store_pre_key = pks_store_pre_key, + contains_pre_key = pks_contains_pre_key, + remove_pre_key = pks_remove_pre_key, + destroy_func = pks_destroy_func, + user_data = this + }; + native_context.set_pre_key_store(pks); + + NativeSignedPreKeyStore spks = NativeSignedPreKeyStore() { + load_signed_pre_key = spks_load_signed_pre_key, + store_signed_pre_key = spks_store_signed_pre_key, + contains_signed_pre_key = spks_contains_signed_pre_key, + remove_signed_pre_key = spks_remove_signed_pre_key, + destroy_func = spks_destroy_func, + user_data = this + }; + native_context.set_signed_pre_key_store(spks); + } + + public SessionBuilder create_session_builder(Address other) throws Error { + SessionBuilder builder; + throw_by_code(session_builder_create(out builder, native_context, other, context.native_context), "Error creating session builder"); + return builder; + } + + public SessionCipher create_session_cipher(Address other) throws Error { + SessionCipher cipher; + throw_by_code(session_cipher_create(out cipher, native_context, other, context.native_context)); + return cipher; + } + + public IdentityKeyPair identity_key_pair { + owned get { + IdentityKeyPair pair; + Protocol.Identity.get_key_pair(native_context, out pair); + return pair; + } + } + + public bool is_trusted_identity(Address address, ECPublicKey key) throws Error { + return throw_by_code(Protocol.Identity.is_trusted_identity(native_context, address, key)) == 1; + } + + public void save_identity(Address address, ECPublicKey key) throws Error { + throw_by_code(Protocol.Identity.save_identity(native_context, address, key)); + } + + public bool contains_session(Address other) throws Error { + return throw_by_code(Protocol.Session.contains_session(native_context, other)) == 1; + } + + public void delete_session(Address address) throws Error { + throw_by_code(Protocol.Session.delete_session(native_context, address)); + } + + public SessionRecord load_session(Address other) throws Error { + SessionRecord record; + throw_by_code(Protocol.Session.load_session(native_context, out record, other)); + return record; + } + + public bool contains_pre_key(uint32 pre_key_id) throws Error { + return throw_by_code(Protocol.PreKey.contains_key(native_context, pre_key_id)) == 1; + } + + public void store_pre_key(PreKeyRecord record) throws Error { + throw_by_code(Protocol.PreKey.store_key(native_context, record)); + } + + public PreKeyRecord load_pre_key(uint32 pre_key_id) throws Error { + PreKeyRecord res; + throw_by_code(Protocol.PreKey.load_key(native_context, out res, pre_key_id)); + return res; + } + + public bool contains_signed_pre_key(uint32 pre_key_id) throws Error { + return throw_by_code(Protocol.SignedPreKey.contains_key(native_context, pre_key_id)) == 1; + } + + public void store_signed_pre_key(SignedPreKeyRecord record) throws Error { + throw_by_code(Protocol.SignedPreKey.store_key(native_context, record)); + } + + public SignedPreKeyRecord load_signed_pre_key(uint32 pre_key_id) throws Error { + SignedPreKeyRecord res; + throw_by_code(Protocol.SignedPreKey.load_key(native_context, out res, pre_key_id)); + return res; + } +} + +} diff --git a/plugins/omemo/src/signal/util.vala b/plugins/omemo/src/signal/util.vala new file mode 100644 index 00000000..4c0ae72d --- /dev/null +++ b/plugins/omemo/src/signal/util.vala @@ -0,0 +1,45 @@ +namespace Signal { + +public ECPublicKey generate_public_key(ECPrivateKey private_key) throws Error { + ECPublicKey public_key; + throw_by_code(ECPublicKey.generate(out public_key, private_key), "Error generating public key"); + + return public_key; +} + +public uint8[] calculate_agreement(ECPublicKey public_key, ECPrivateKey private_key) throws Error { + uint8[] res; + int len = Curve.calculate_agreement(out res, public_key, private_key); + throw_by_code(len, "Error calculating agreement"); + res.length = len; + return res; +} + +public bool verify_signature(ECPublicKey signing_key, uint8[] message, uint8[] signature) throws Error { + return throw_by_code(Curve.verify_signature(signing_key, message, signature)) == 1; +} + +public PreKeyBundle create_pre_key_bundle(uint32 registration_id, int device_id, uint32 pre_key_id, ECPublicKey? pre_key_public, + uint32 signed_pre_key_id, ECPublicKey? signed_pre_key_public, uint8[]? signed_pre_key_signature, ECPublicKey? identity_key) throws Error { + PreKeyBundle res; + throw_by_code(PreKeyBundle.create(out res, registration_id, device_id, pre_key_id, pre_key_public, signed_pre_key_id, signed_pre_key_public, signed_pre_key_signature, identity_key), "Error creating PreKeyBundle"); + return res; +} + +internal string carr_to_string(char[] carr) { + char[] nu = new char[carr.length + 1]; + Memory.copy(nu, carr, carr.length); + return (string) nu; +} + +internal delegate int CodeErroringFunc() throws Error; + +internal int catch_to_code(CodeErroringFunc func) { + try { + return func(); + } catch (Error e) { + return e.code; + } +} + +} \ No newline at end of file diff --git a/plugins/omemo/tests/signal/common.vala b/plugins/omemo/tests/signal/common.vala new file mode 100644 index 00000000..9bb9b1dc --- /dev/null +++ b/plugins/omemo/tests/signal/common.vala @@ -0,0 +1,92 @@ +namespace Signal.Test { + +int main(string[] args) { + GLib.Test.init(ref args); + GLib.Test.set_nonfatal_assertions(); + TestSuite.get_root().add_suite(new Curve25519().get_suite()); + TestSuite.get_root().add_suite(new SessionBuilderTest().get_suite()); + TestSuite.get_root().add_suite(new HKDF().get_suite()); + return GLib.Test.run(); +} + +Store setup_test_store_context(Context global_context) { + Store store = global_context.create_store(); + try { + store.identity_key_store.local_registration_id = (Random.next_int() % 16380) + 1; + + ECKeyPair key_pair = global_context.generate_key_pair(); + store.identity_key_store.identity_key_private = new Bytes(key_pair.private.serialize()); + store.identity_key_store.identity_key_public = new Bytes(key_pair.public.serialize()); + } catch (Error e) { + fail_if_reached(); + } + return store; +} + +ECPublicKey? create_test_ec_public_key(Context context) { + try { + return context.generate_key_pair().public; + } catch (Error e) { + fail_if_reached(); + return null; + } +} + +bool fail_if(bool exp, string? reason = null) { + if (exp) { + if (reason != null) GLib.Test.message(reason); + GLib.Test.fail(); + return true; + } + return false; +} + +void fail_if_reached(string? reason = null) { + fail_if(true, reason); +} + +delegate void ErrorFunc() throws Error; + +void fail_if_not_error_code(ErrorFunc func, int expectedCode, string? reason = null) { + try { + func(); + fail_if_reached(@"$(reason + ": " ?? "")no error thrown"); + } catch (Error e) { + fail_if_not_eq_int(e.code, expectedCode, @"$(reason + ": " ?? "")caught unexpected error"); + } +} + +bool fail_if_not(bool exp, string? reason = null) { + return fail_if(!exp, reason); +} + +bool fail_if_eq_int(int left, int right, string? reason = null) { + return fail_if(left == right, @"$(reason + ": " ?? "")$left == $right"); +} + +bool fail_if_not_eq_int(int left, int right, string? reason = null) { + return fail_if_not(left == right, @"$(reason + ": " ?? "")$left != $right"); +} + +bool fail_if_not_eq_str(string left, string right, string? reason = null) { + return fail_if_not(left == right, @"$(reason + ": " ?? "")$left != $right"); +} + +bool fail_if_not_eq_uint8_arr(uint8[] left, uint8[] right, string? reason = null) { + if (fail_if_not_eq_int(left.length, right.length, @"$(reason + ": " ?? "")array length not equal")) return true; + return fail_if_not_eq_str(Base64.encode(left), Base64.encode(right), reason); +} + +bool fail_if_not_zero_int(int zero, string? reason = null) { + return fail_if_not_eq_int(zero, 0, reason); +} + +bool fail_if_zero_int(int zero, string? reason = null) { + return fail_if_eq_int(zero, 0, reason); +} + +bool fail_if_null(void* what, string? reason = null) { + return fail_if(what == null || (size_t)what == 0, reason); +} + +} diff --git a/plugins/omemo/tests/signal/curve25519.vala b/plugins/omemo/tests/signal/curve25519.vala new file mode 100644 index 00000000..6dfae62f --- /dev/null +++ b/plugins/omemo/tests/signal/curve25519.vala @@ -0,0 +1,207 @@ +namespace Signal.Test { + +class Curve25519 : Gee.TestCase { + + public Curve25519() { + base("Curve25519"); + add_test("agreement", test_curve25519_agreement); + add_test("generate_public", test_curve25519_generate_public); + add_test("random_agreements", test_curve25519_random_agreements); + add_test("signature", test_curve25519_signature); + } + + private Context global_context; + + public override void set_up() { + try { + global_context = new Context(); + } catch (Error e) { + fail_if_reached(); + } + } + + public override void tear_down() { + global_context = null; + } + + void test_curve25519_agreement() { + try { + uint8[] alicePublic = { + 0x05, 0x1b, 0xb7, 0x59, 0x66, + 0xf2, 0xe9, 0x3a, 0x36, 0x91, + 0xdf, 0xff, 0x94, 0x2b, 0xb2, + 0xa4, 0x66, 0xa1, 0xc0, 0x8b, + 0x8d, 0x78, 0xca, 0x3f, 0x4d, + 0x6d, 0xf8, 0xb8, 0xbf, 0xa2, + 0xe4, 0xee, 0x28}; + + uint8[] alicePrivate = { + 0xc8, 0x06, 0x43, 0x9d, 0xc9, + 0xd2, 0xc4, 0x76, 0xff, 0xed, + 0x8f, 0x25, 0x80, 0xc0, 0x88, + 0x8d, 0x58, 0xab, 0x40, 0x6b, + 0xf7, 0xae, 0x36, 0x98, 0x87, + 0x90, 0x21, 0xb9, 0x6b, 0xb4, + 0xbf, 0x59}; + + uint8[] bobPublic = { + 0x05, 0x65, 0x36, 0x14, 0x99, + 0x3d, 0x2b, 0x15, 0xee, 0x9e, + 0x5f, 0xd3, 0xd8, 0x6c, 0xe7, + 0x19, 0xef, 0x4e, 0xc1, 0xda, + 0xae, 0x18, 0x86, 0xa8, 0x7b, + 0x3f, 0x5f, 0xa9, 0x56, 0x5a, + 0x27, 0xa2, 0x2f}; + + uint8[] bobPrivate = { + 0xb0, 0x3b, 0x34, 0xc3, 0x3a, + 0x1c, 0x44, 0xf2, 0x25, 0xb6, + 0x62, 0xd2, 0xbf, 0x48, 0x59, + 0xb8, 0x13, 0x54, 0x11, 0xfa, + 0x7b, 0x03, 0x86, 0xd4, 0x5f, + 0xb7, 0x5d, 0xc5, 0xb9, 0x1b, + 0x44, 0x66}; + + uint8[] shared = { + 0x32, 0x5f, 0x23, 0x93, 0x28, + 0x94, 0x1c, 0xed, 0x6e, 0x67, + 0x3b, 0x86, 0xba, 0x41, 0x01, + 0x74, 0x48, 0xe9, 0x9b, 0x64, + 0x9a, 0x9c, 0x38, 0x06, 0xc1, + 0xdd, 0x7c, 0xa4, 0xc4, 0x77, + 0xe6, 0x29}; + + ECPublicKey alice_public_key = global_context.decode_public_key(alicePublic); + ECPrivateKey alice_private_key = global_context.decode_private_key(alicePrivate); + ECPublicKey bob_public_key = global_context.decode_public_key(bobPublic); + ECPrivateKey bob_private_key = global_context.decode_private_key(bobPrivate); + + uint8[] shared_one = calculate_agreement(alice_public_key, bob_private_key); + uint8[] shared_two = calculate_agreement(bob_public_key, alice_private_key); + + fail_if_not_eq_int(shared_one.length, 32); + fail_if_not_eq_int(shared_two.length, 32); + fail_if_not_eq_uint8_arr(shared, shared_one); + fail_if_not_eq_uint8_arr(shared_one, shared_two); + } catch (Error e) { + fail_if_reached(); + } + } + + void test_curve25519_generate_public() { + try { + uint8[] alicePublic = { + 0x05, 0x1b, 0xb7, 0x59, 0x66, + 0xf2, 0xe9, 0x3a, 0x36, 0x91, + 0xdf, 0xff, 0x94, 0x2b, 0xb2, + 0xa4, 0x66, 0xa1, 0xc0, 0x8b, + 0x8d, 0x78, 0xca, 0x3f, 0x4d, + 0x6d, 0xf8, 0xb8, 0xbf, 0xa2, + 0xe4, 0xee, 0x28}; + + uint8[] alicePrivate = { + 0xc8, 0x06, 0x43, 0x9d, 0xc9, + 0xd2, 0xc4, 0x76, 0xff, 0xed, + 0x8f, 0x25, 0x80, 0xc0, 0x88, + 0x8d, 0x58, 0xab, 0x40, 0x6b, + 0xf7, 0xae, 0x36, 0x98, 0x87, + 0x90, 0x21, 0xb9, 0x6b, 0xb4, + 0xbf, 0x59}; + + ECPrivateKey alice_private_key = global_context.decode_private_key(alicePrivate); + ECPublicKey alice_expected_public_key = global_context.decode_public_key(alicePublic); + ECPublicKey alice_public_key = generate_public_key(alice_private_key); + + fail_if_not_zero_int(alice_expected_public_key.compare(alice_public_key)); + } catch (Error e) { + fail_if_reached(); + } + } + + void test_curve25519_random_agreements() { + try { + ECKeyPair alice_key_pair = null; + ECPublicKey alice_public_key = null; + ECPrivateKey alice_private_key = null; + ECKeyPair bob_key_pair = null; + ECPublicKey bob_public_key = null; + ECPrivateKey bob_private_key = null; + uint8[] shared_alice = null; + uint8[] shared_bob = null; + + for (int i = 0; i < 50; i++) { + fail_if_null(alice_key_pair = global_context.generate_key_pair()); + fail_if_null(alice_public_key = alice_key_pair.public); + fail_if_null(alice_private_key = alice_key_pair.private); + + fail_if_null(bob_key_pair = global_context.generate_key_pair()); + fail_if_null(bob_public_key = bob_key_pair.public); + fail_if_null(bob_private_key = bob_key_pair.private); + + shared_alice = calculate_agreement(bob_public_key, alice_private_key); + fail_if_not_eq_int(shared_alice.length, 32); + + shared_bob = calculate_agreement(alice_public_key, bob_private_key); + fail_if_not_eq_int(shared_bob.length, 32); + + fail_if_not_eq_uint8_arr(shared_alice, shared_bob); + } + } catch (Error e) { + fail_if_reached(); + } + } + + void test_curve25519_signature() { + try { + uint8[] aliceIdentityPrivate = { + 0xc0, 0x97, 0x24, 0x84, 0x12, 0xe5, 0x8b, 0xf0, + 0x5d, 0xf4, 0x87, 0x96, 0x82, 0x05, 0x13, 0x27, + 0x94, 0x17, 0x8e, 0x36, 0x76, 0x37, 0xf5, 0x81, + 0x8f, 0x81, 0xe0, 0xe6, 0xce, 0x73, 0xe8, 0x65}; + + uint8[] aliceIdentityPublic = { + 0x05, 0xab, 0x7e, 0x71, 0x7d, 0x4a, 0x16, 0x3b, + 0x7d, 0x9a, 0x1d, 0x80, 0x71, 0xdf, 0xe9, 0xdc, + 0xf8, 0xcd, 0xcd, 0x1c, 0xea, 0x33, 0x39, 0xb6, + 0x35, 0x6b, 0xe8, 0x4d, 0x88, 0x7e, 0x32, 0x2c, + 0x64}; + + uint8[] aliceEphemeralPublic = { + 0x05, 0xed, 0xce, 0x9d, 0x9c, 0x41, 0x5c, 0xa7, + 0x8c, 0xb7, 0x25, 0x2e, 0x72, 0xc2, 0xc4, 0xa5, + 0x54, 0xd3, 0xeb, 0x29, 0x48, 0x5a, 0x0e, 0x1d, + 0x50, 0x31, 0x18, 0xd1, 0xa8, 0x2d, 0x99, 0xfb, + 0x4a}; + + uint8[] aliceSignature = { + 0x5d, 0xe8, 0x8c, 0xa9, 0xa8, 0x9b, 0x4a, 0x11, + 0x5d, 0xa7, 0x91, 0x09, 0xc6, 0x7c, 0x9c, 0x74, + 0x64, 0xa3, 0xe4, 0x18, 0x02, 0x74, 0xf1, 0xcb, + 0x8c, 0x63, 0xc2, 0x98, 0x4e, 0x28, 0x6d, 0xfb, + 0xed, 0xe8, 0x2d, 0xeb, 0x9d, 0xcd, 0x9f, 0xae, + 0x0b, 0xfb, 0xb8, 0x21, 0x56, 0x9b, 0x3d, 0x90, + 0x01, 0xbd, 0x81, 0x30, 0xcd, 0x11, 0xd4, 0x86, + 0xce, 0xf0, 0x47, 0xbd, 0x60, 0xb8, 0x6e, 0x88}; + + global_context.decode_private_key(aliceIdentityPrivate); + global_context.decode_public_key(aliceEphemeralPublic); + ECPublicKey alice_public_key = global_context.decode_public_key(aliceIdentityPublic); + + fail_if(!verify_signature(alice_public_key, aliceEphemeralPublic, aliceSignature), "signature verification failed"); + + uint8[] modifiedSignature = new uint8[aliceSignature.length]; + + for (int i = 0; i < aliceSignature.length; i++) { + Memory.copy(modifiedSignature, aliceSignature, aliceSignature.length); + modifiedSignature[i] ^= 0x01; + + fail_if(verify_signature(alice_public_key, aliceEphemeralPublic, modifiedSignature), "invalid signature verification succeeded"); + } + } catch (Error e) { + fail_if_reached(); + } + } + +} + +} \ No newline at end of file diff --git a/plugins/omemo/tests/signal/hkdf.vala b/plugins/omemo/tests/signal/hkdf.vala new file mode 100644 index 00000000..c30af275 --- /dev/null +++ b/plugins/omemo/tests/signal/hkdf.vala @@ -0,0 +1,59 @@ +namespace Signal.Test { + +class HKDF : Gee.TestCase { + + public HKDF() { + base("HKDF"); + add_test("vector_v3", test_hkdf_vector_v3); + } + + private Context global_context; + + public override void set_up() { + try { + global_context = new Context(); + } catch (Error e) { + fail_if_reached(); + } + } + + public override void tear_down() { + global_context = null; + } + + public void test_hkdf_vector_v3() { + uint8[] ikm = { + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}; + + uint8[] salt = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c}; + + uint8[] info = { + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9}; + + uint8[] okm = { + 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, + 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, + 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c, + 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, + 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, + 0x58, 0x65}; + + NativeHkdfContext context = null; + fail_if_not_zero_int(NativeHkdfContext.create(out context, 3, global_context.native_context)); + + uint8[] output = null; + int result = (int) context.derive_secrets(out output, ikm, salt, info, 42); + fail_if_not_eq_int(result, okm.length); + output.length = result; + + fail_if_not_eq_uint8_arr(output, okm); + } + +} + +} \ No newline at end of file diff --git a/plugins/omemo/tests/signal/session_builder.vala b/plugins/omemo/tests/signal/session_builder.vala new file mode 100644 index 00000000..7e2448e1 --- /dev/null +++ b/plugins/omemo/tests/signal/session_builder.vala @@ -0,0 +1,400 @@ +namespace Signal.Test { + +class SessionBuilderTest : Gee.TestCase { + Address alice_address; + Address bob_address; + + public SessionBuilderTest() { + base("SessionBuilder"); + + add_test("basic_pre_key_v2", test_basic_pre_key_v2); + add_test("basic_pre_key_v3", test_basic_pre_key_v3); + add_test("bad_signed_pre_key_signature", test_bad_signed_pre_key_signature); + add_test("repeat_bundle_message_v2", test_repeat_bundle_message_v2); + } + + private Context global_context; + + public override void set_up() { + try { + global_context = new Context(); + alice_address = new Address("+14151111111", 1); + bob_address = new Address("+14152222222", 1); + } catch (Error e) { + fail_if_reached(@"Unexpected error: $(e.message)"); + } + } + + public override void tear_down() { + global_context = null; + alice_address = null; + bob_address = null; + } + + void test_basic_pre_key_v2() { + try { + /* Create Alice's data store and session builder */ + Store alice_store = setup_test_store_context(global_context); + SessionBuilder alice_session_builder = alice_store.create_session_builder(bob_address); + + /* Create Bob's data store and pre key bundle */ + Store bob_store = setup_test_store_context(global_context); + uint32 bob_local_registration_id = bob_store.local_registration_id; + IdentityKeyPair bob_identity_key_pair = bob_store.identity_key_pair; + ECKeyPair bob_pre_key_pair = global_context.generate_key_pair(); + + PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_local_registration_id, 1, 31337, bob_pre_key_pair.public, 0, null, null, bob_identity_key_pair.public); + + /* + * Have Alice process Bob's pre key bundle, which should fail due to a + * missing unsigned pre key. + */ + fail_if_not_error_code(() => alice_session_builder.process_pre_key_bundle(bob_pre_key), ErrorCode.INVALID_KEY); + } catch(Error e) { + fail_if_reached(@"Unexpected error: $(e.message)"); + } + } + + void test_basic_pre_key_v3() { + try { + /* Create Alice's data store and session builder */ + Store alice_store = setup_test_store_context(global_context); + SessionBuilder alice_session_builder = alice_store.create_session_builder(bob_address); + + /* Create Bob's data store and pre key bundle */ + Store bob_store = setup_test_store_context(global_context); + uint32 bob_local_registration_id = bob_store.local_registration_id; + ECKeyPair bob_pre_key_pair = global_context.generate_key_pair(); + ECKeyPair bob_signed_pre_key_pair = global_context.generate_key_pair(); + IdentityKeyPair bob_identity_key_pair = bob_store.identity_key_pair; + + uint8[] bob_signed_pre_key_signature = global_context.calculate_signature(bob_identity_key_pair.private, bob_signed_pre_key_pair.public.serialize()); + + PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_local_registration_id, 1, 31337, bob_pre_key_pair.public, 22, bob_signed_pre_key_pair.public, bob_signed_pre_key_signature, bob_identity_key_pair.public); + + /* Have Alice process Bob's pre key bundle */ + alice_session_builder.process_pre_key_bundle(bob_pre_key); + + /* Check that we can load the session state and verify its version */ + fail_if_not(alice_store.contains_session(bob_address)); + + SessionRecord loaded_record = alice_store.load_session(bob_address); + fail_if_not_eq_int((int)loaded_record.state.session_version, 3); + + /* Encrypt an outgoing message to send to Bob */ + string original_message = "L'homme est condamné à être libre"; + SessionCipher alice_session_cipher = alice_store.create_session_cipher(bob_address); + + CiphertextMessage outgoing_message = alice_session_cipher.encrypt(original_message.data); + fail_if_not_eq_int(outgoing_message.type, CiphertextType.PREKEY); + + /* Convert to an incoming message for Bob */ + PreKeySignalMessage incoming_message = global_context.deserialize_pre_key_signal_message(outgoing_message.serialized); + + /* Save the pre key and signed pre key in Bob's data store */ + PreKeyRecord bob_pre_key_record; + throw_by_code(PreKeyRecord.create(out bob_pre_key_record, bob_pre_key.pre_key_id, bob_pre_key_pair)); + bob_store.store_pre_key(bob_pre_key_record); + + SignedPreKeyRecord bob_signed_pre_key_record; + throw_by_code(SignedPreKeyRecord.create(out bob_signed_pre_key_record, 22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature)); + bob_store.store_signed_pre_key(bob_signed_pre_key_record); + + /* Create Bob's session cipher and decrypt the message from Alice */ + SessionCipher bob_session_cipher = bob_store.create_session_cipher(alice_address); + + /* Prepare the data for the callback test */ + //int callback_context = 1234; + //bob_session_cipher.user_data = + //bob_session_cipher.decryption_callback = + uint8[] plaintext = bob_session_cipher.decrypt_pre_key_signal_message(incoming_message); + + /* Clean up callback data */ + bob_session_cipher.user_data = null; + bob_session_cipher.decryption_callback = null; + + /* Verify Bob's session state and the decrypted message */ + fail_if_not(bob_store.contains_session(alice_address)); + + SessionRecord alice_recipient_session_record = bob_store.load_session(alice_address); + + SessionState alice_recipient_session_state = alice_recipient_session_record.state; + fail_if_not_eq_int((int)alice_recipient_session_state.session_version, 3); + fail_if_null(alice_recipient_session_state.alice_base_key); + + fail_if_not_eq_uint8_arr(original_message.data, plaintext); + + /* Have Bob send a reply to Alice */ + CiphertextMessage bob_outgoing_message = bob_session_cipher.encrypt(original_message.data); + fail_if_not_eq_int(bob_outgoing_message.type, CiphertextType.SIGNAL); + + /* Verify that Alice can decrypt it */ + SignalMessage bob_outgoing_message_copy = global_context.copy_signal_message(bob_outgoing_message); + + uint8[] alice_plaintext = alice_session_cipher.decrypt_signal_message(bob_outgoing_message_copy); + + fail_if_not_eq_uint8_arr(original_message.data, alice_plaintext); + + GLib.Test.message("Pre-interaction tests complete"); + + /* Interaction tests */ + run_interaction(alice_store, bob_store); + + /* Cleanup state from previous tests that we need to replace */ + alice_store = null; + bob_pre_key_pair = null; + bob_signed_pre_key_pair = null; + bob_identity_key_pair = null; + bob_signed_pre_key_signature = null; + bob_pre_key_record = null; + bob_signed_pre_key_record = null; + + /* Create Alice's new session data */ + alice_store = setup_test_store_context(global_context); + alice_session_builder = alice_store.create_session_builder(bob_address); + alice_session_cipher = alice_store.create_session_cipher(bob_address); + + /* Create Bob's new pre key bundle */ + bob_pre_key_pair = global_context.generate_key_pair(); + bob_signed_pre_key_pair = global_context.generate_key_pair(); + bob_identity_key_pair = bob_store.identity_key_pair; + bob_signed_pre_key_signature = global_context.calculate_signature(bob_identity_key_pair.private, bob_signed_pre_key_pair.public.serialize()); + bob_pre_key = create_pre_key_bundle(bob_local_registration_id, 1, 31338, bob_pre_key_pair.public, 23, bob_signed_pre_key_pair.public, bob_signed_pre_key_signature, bob_identity_key_pair.public); + + /* Save the new pre key and signed pre key in Bob's data store */ + throw_by_code(PreKeyRecord.create(out bob_pre_key_record, bob_pre_key.pre_key_id, bob_pre_key_pair)); + bob_store.store_pre_key(bob_pre_key_record); + + throw_by_code(SignedPreKeyRecord.create(out bob_signed_pre_key_record, 23, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature)); + bob_store.store_signed_pre_key(bob_signed_pre_key_record); + + /* Have Alice process Bob's pre key bundle */ + alice_session_builder.process_pre_key_bundle(bob_pre_key); + + /* Have Alice encrypt a message for Bob */ + outgoing_message = alice_session_cipher.encrypt(original_message.data); + fail_if_not_eq_int(outgoing_message.type, CiphertextType.PREKEY); + + /* Have Bob try to decrypt the message */ + PreKeySignalMessage outgoing_message_copy = global_context.copy_pre_key_signal_message(outgoing_message); + + /* The decrypt should fail with a specific error */ + fail_if_not_error_code(() => bob_session_cipher.decrypt_pre_key_signal_message(outgoing_message_copy), ErrorCode.UNTRUSTED_IDENTITY); + + outgoing_message_copy = global_context.copy_pre_key_signal_message(outgoing_message); + + /* Save the identity key to Bob's store */ + bob_store.save_identity(alice_address, outgoing_message_copy.identity_key); + + /* Try the decrypt again, this time it should succeed */ + outgoing_message_copy = global_context.copy_pre_key_signal_message(outgoing_message); + plaintext = bob_session_cipher.decrypt_pre_key_signal_message(outgoing_message_copy); + + fail_if_not_eq_uint8_arr(original_message.data, plaintext); + + /* Create a new pre key for Bob */ + ECPublicKey test_public_key = create_test_ec_public_key(global_context); + + IdentityKeyPair alice_identity_key_pair = alice_store.identity_key_pair; + + bob_pre_key = create_pre_key_bundle(bob_local_registration_id, 1, 31337, test_public_key, 23, bob_signed_pre_key_pair.public, bob_signed_pre_key_signature, alice_identity_key_pair.public); + + /* Have Alice process Bob's new pre key bundle, which should fail */ + fail_if_not_error_code(() => alice_session_builder.process_pre_key_bundle(bob_pre_key), ErrorCode.UNTRUSTED_IDENTITY); + + GLib.Test.message("Post-interaction tests complete"); + } catch(Error e) { + fail_if_reached(@"Unexpected error: $(e.message)"); + } + } + + void test_bad_signed_pre_key_signature() { + try { + /* Create Alice's data store and session builder */ + Store alice_store = setup_test_store_context(global_context); + SessionBuilder alice_session_builder = alice_store.create_session_builder(bob_address); + + /* Create Bob's data store */ + Store bob_store = setup_test_store_context(global_context); + + /* Create Bob's regular and signed pre key pairs */ + ECKeyPair bob_pre_key_pair = global_context.generate_key_pair(); + ECKeyPair bob_signed_pre_key_pair = global_context.generate_key_pair(); + + /* Create Bob's signed pre key signature */ + IdentityKeyPair bob_identity_key_pair = bob_store.identity_key_pair; + uint8[] bob_signed_pre_key_signature = global_context.calculate_signature(bob_identity_key_pair.private, bob_signed_pre_key_pair.public.serialize()); + + for (int i = 0; i < bob_signed_pre_key_signature.length * 8; i++) { + uint8[] modified_signature = bob_signed_pre_key_signature[0:bob_signed_pre_key_signature.length]; + + /* Intentionally corrupt the signature data */ + modified_signature[i/8] ^= (1 << ((uint8)i % 8)); + + /* Create a pre key bundle */ + PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_store.local_registration_id,1,31137,bob_pre_key_pair.public,22,bob_signed_pre_key_pair.public,modified_signature,bob_identity_key_pair.public); + + /* Process the bundle and make sure we fail with an invalid key error */ + fail_if_not_error_code(() => alice_session_builder.process_pre_key_bundle(bob_pre_key), ErrorCode.INVALID_KEY); + } + + /* Create a correct pre key bundle */ + PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_store.local_registration_id,1,31137,bob_pre_key_pair.public,22,bob_signed_pre_key_pair.public,bob_signed_pre_key_signature,bob_identity_key_pair.public); + + /* Process the bundle and make sure we do not fail */ + alice_session_builder.process_pre_key_bundle(bob_pre_key); + } catch(Error e) { + fail_if_reached(@"Unexpected error: $(e.message)"); + } + } + + void test_repeat_bundle_message_v2() { + try { + /* Create Alice's data store and session builder */ + Store alice_store = setup_test_store_context(global_context); + SessionBuilder alice_session_builder = alice_store.create_session_builder(bob_address); + + /* Create Bob's data store and pre key bundle */ + Store bob_store = setup_test_store_context(global_context); + ECKeyPair bob_pre_key_pair = global_context.generate_key_pair(); + ECKeyPair bob_signed_pre_key_pair = global_context.generate_key_pair(); + uint8[] bob_signed_pre_key_signature = global_context.calculate_signature(bob_store.identity_key_pair.private, bob_signed_pre_key_pair.public.serialize()); + PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_store.local_registration_id,1,31337,bob_pre_key_pair.public,0,null,null,bob_store.identity_key_pair.public); + + /* Add Bob's pre keys to Bob's data store */ + PreKeyRecord bob_pre_key_record; + throw_by_code(PreKeyRecord.create(out bob_pre_key_record, bob_pre_key.pre_key_id, bob_pre_key_pair)); + bob_store.store_pre_key(bob_pre_key_record); + SignedPreKeyRecord bob_signed_pre_key_record; + throw_by_code(SignedPreKeyRecord.create(out bob_signed_pre_key_record, 22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature)); + bob_store.store_signed_pre_key(bob_signed_pre_key_record); + + /* + * Have Alice process Bob's pre key bundle, which should fail due to a + * missing signed pre key. + */ + fail_if_not_error_code(() => alice_session_builder.process_pre_key_bundle(bob_pre_key), ErrorCode.INVALID_KEY); + } catch(Error e) { + fail_if_reached(@"Unexpected error: $(e.message)"); + } + } + + class Holder { + public uint8[] data { get; private set; } + + public Holder(uint8[] data) { + this.data = data; + } + } + + void run_interaction(Store alice_store, Store bob_store) throws Error { + + /* Create the session ciphers */ + SessionCipher alice_session_cipher = alice_store.create_session_cipher(bob_address); + SessionCipher bob_session_cipher = bob_store.create_session_cipher(alice_address); + + /* Create a test message */ + string original_message = "smert ze smert"; + + /* Simulate Alice sending a message to Bob */ + CiphertextMessage alice_message = alice_session_cipher.encrypt(original_message.data); + fail_if_not_eq_int(alice_message.type, CiphertextType.SIGNAL); + + SignalMessage alice_message_copy = global_context.copy_signal_message(alice_message); + uint8[] plaintext = bob_session_cipher.decrypt_signal_message(alice_message_copy); + fail_if_not_eq_uint8_arr(original_message.data, plaintext); + + GLib.Test.message("Interaction complete: Alice -> Bob"); + + /* Simulate Bob sending a message to Alice */ + CiphertextMessage bob_message = bob_session_cipher.encrypt(original_message.data); + fail_if_not_eq_int(alice_message.type, CiphertextType.SIGNAL); + + SignalMessage bob_message_copy = global_context.copy_signal_message(bob_message); + plaintext = alice_session_cipher.decrypt_signal_message(bob_message_copy); + fail_if_not_eq_uint8_arr(original_message.data, plaintext); + + GLib.Test.message("Interaction complete: Bob -> Alice"); + + /* Looping Alice -> Bob */ + for (int i = 0; i < 10; i++) { + uint8[] looping_message = create_looping_message(i); + CiphertextMessage alice_looping_message = alice_session_cipher.encrypt(looping_message); + SignalMessage alice_looping_message_copy = global_context.copy_signal_message(alice_looping_message); + uint8[] looping_plaintext = bob_session_cipher.decrypt_signal_message(alice_looping_message_copy); + fail_if_not_eq_uint8_arr(looping_message, looping_plaintext); + } + GLib.Test.message("Interaction complete: Alice -> Bob (looping)"); + + /* Looping Bob -> Alice */ + for (int i = 0; i < 10; i++) { + uint8[] looping_message = create_looping_message(i); + CiphertextMessage bob_looping_message = bob_session_cipher.encrypt(looping_message); + SignalMessage bob_looping_message_copy = global_context.copy_signal_message(bob_looping_message); + uint8[] looping_plaintext = alice_session_cipher.decrypt_signal_message(bob_looping_message_copy); + fail_if_not_eq_uint8_arr(looping_message, looping_plaintext); + } + GLib.Test.message("Interaction complete: Bob -> Alice (looping)"); + + /* Generate a shuffled list of encrypted messages for later use */ + Holder[] alice_ooo_plaintext = new Holder[10]; + Holder[] alice_ooo_ciphertext = new Holder[10]; + for (int i = 0; i < 10; i++) { + alice_ooo_plaintext[i] = new Holder(create_looping_message(i)); + alice_ooo_ciphertext[i] = new Holder(alice_session_cipher.encrypt(alice_ooo_plaintext[i].data).serialized); + } + + for (int i = 0; i < 10; i++) { + uint32 s = Random.next_int() % 10; + Holder tmp = alice_ooo_plaintext[s]; + alice_ooo_plaintext[s] = alice_ooo_plaintext[i]; + alice_ooo_plaintext[i] = tmp; + tmp = alice_ooo_ciphertext[s]; + alice_ooo_ciphertext[s] = alice_ooo_ciphertext[i]; + alice_ooo_ciphertext[i] = tmp; + } + GLib.Test.message("Shuffled Alice->Bob messages created"); + + /* Looping Alice -> Bob (repeated) */ + for (int i = 0; i < 10; i++) { + uint8[] looping_message = create_looping_message(i); + CiphertextMessage alice_looping_message = alice_session_cipher.encrypt(looping_message); + SignalMessage alice_looping_message_copy = global_context.copy_signal_message(alice_looping_message); + uint8[] looping_plaintext = bob_session_cipher.decrypt_signal_message(alice_looping_message_copy); + fail_if_not_eq_uint8_arr(looping_message, looping_plaintext); + } + GLib.Test.message("Interaction complete: Alice -> Bob (looping, repeated)"); + + /* Looping Bob -> Alice (repeated) */ + for (int i = 0; i < 10; i++) { + uint8[] looping_message = create_looping_message(i); + CiphertextMessage bob_looping_message = bob_session_cipher.encrypt(looping_message); + SignalMessage bob_looping_message_copy = global_context.copy_signal_message(bob_looping_message); + uint8[] looping_plaintext = alice_session_cipher.decrypt_signal_message(bob_looping_message_copy); + fail_if_not_eq_uint8_arr(looping_message, looping_plaintext); + } + GLib.Test.message("Interaction complete: Bob -> Alice (looping, repeated)"); + + /* Shuffled Alice -> Bob */ + for (int i = 0; i < 10; i++) { + SignalMessage ooo_message_deserialized = global_context.deserialize_signal_message(alice_ooo_ciphertext[i].data); + uint8[] ooo_plaintext = bob_session_cipher.decrypt_signal_message(ooo_message_deserialized); + fail_if_not_eq_uint8_arr(alice_ooo_plaintext[i].data, ooo_plaintext); + } + GLib.Test.message("Interaction complete: Alice -> Bob (shuffled)"); + } + + uint8[] create_looping_message(int index) { + return (@"You can only desire based on what you know: $index").data; + } + + /* + uint8[] create_looping_message_short(int index) { + return ("What do we mean by saying that existence precedes essence? " + + "We mean that man first of all exists, encounters himself, " + + @"surges up in the world--and defines himself aftward. $index").data; + } + */ +} + +} diff --git a/plugins/omemo/tests/signal/testcase.vala b/plugins/omemo/tests/signal/testcase.vala new file mode 100644 index 00000000..59fcf193 --- /dev/null +++ b/plugins/omemo/tests/signal/testcase.vala @@ -0,0 +1,80 @@ +/* testcase.vala + * + * Copyright (C) 2009 Julien Peeters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Julien Peeters + */ + +public abstract class Gee.TestCase : Object { + + private GLib.TestSuite suite; + private Adaptor[] adaptors = new Adaptor[0]; + + public delegate void TestMethod (); + + protected TestCase (string name) { + this.suite = new GLib.TestSuite (name); + } + + public void add_test (string name, owned TestMethod test) { + var adaptor = new Adaptor (name, (owned)test, this); + this.adaptors += adaptor; + + this.suite.add (new GLib.TestCase (adaptor.name, + adaptor.set_up, + adaptor.run, + adaptor.tear_down )); + } + + public virtual void set_up () { + } + + public virtual void tear_down () { + } + + public GLib.TestSuite get_suite () { + return (owned) this.suite; + } + + private class Adaptor { + [CCode (notify = false)] + public string name { get; private set; } + private TestMethod test; + private TestCase test_case; + + public Adaptor (string name, + owned TestMethod test, + TestCase test_case) { + this.name = name; + this.test = (owned)test; + this.test_case = test_case; + } + + public void set_up (void* fixture) { + this.test_case.set_up (); + } + + public void run (void* fixture) { + this.test (); + } + + public void tear_down (void* fixture) { + this.test_case.tear_down (); + } + } +} diff --git a/plugins/omemo/vapi/libsignal-protocol-c.vapi b/plugins/omemo/vapi/libsignal-protocol-c.vapi new file mode 100644 index 00000000..7c63d418 --- /dev/null +++ b/plugins/omemo/vapi/libsignal-protocol-c.vapi @@ -0,0 +1,657 @@ +namespace Signal { + + [CCode (cname = "int", cprefix = "SG_ERR_", cheader_filename = "signal/signal_protocol.h", has_type_id = false)] + public enum ErrorCode { + [CCode (cname = "SG_SUCCESS")] + SUCCESS, + NOMEM, + INVAL, + UNKNOWN, + DUPLICATE_MESSAGE, + INVALID_KEY, + INVALID_KEY_ID, + INVALID_MAC, + INVALID_MESSAGE, + INVALID_VERSION, + LEGACY_MESSAGE, + NO_SESSION, + STALE_KEY_EXCHANGE, + UNTRUSTED_IDENTITY, + VRF_SIG_VERIF_FAILED, + INVALID_PROTO_BUF, + FP_VERSION_MISMATCH, + FP_IDENT_MISMATCH; + } + + [CCode (cname = "SG_ERR_MINIMUM", cheader_filename = "signal/signal_protocol.h")] + public const int MIN_ERROR_CODE; + + [CCode (cname = "int", cprefix = "SG_LOG_", cheader_filename = "signal/signal_protocol.h", has_type_id = false)] + public enum LogLevel { + ERROR, + WARNING, + NOTICE, + INFO, + DEBUG + } + + [CCode (cname = "signal_throw_gerror_by_code_", cheader_filename = "signal/signal_protocol.h")] + private int throw_by_code(int code, string? message = null) throws GLib.Error { + if (code < 0 && code > MIN_ERROR_CODE) { + throw new GLib.Error(-1, code, "%s: %s", message ?? "Signal error", ((ErrorCode)code).to_string()); + } + return code; + } + + [CCode (cname = "int", cprefix = "SG_CIPHER_", cheader_filename = "signal/signal_protocol.h", has_type_id = false)] + public enum Cipher { + AES_CTR_NOPADDING, + AES_CBC_PKCS5, + AES_GCM_NOPADDING + } + + [Compact] + [CCode (cname = "signal_type_base", ref_function="signal_type_ref_vapi", unref_function="signal_type_unref_vapi", cheader_filename="signal/signal_protocol_types.h,signal/signal_helper.h")] + public class TypeBase { + } + + [Compact] + [CCode (cname = "signal_buffer", cheader_filename = "signal/signal_protocol_types.h", free_function="signal_buffer_free")] + public class Buffer { + [CCode (cname = "signal_buffer_alloc")] + public Buffer(size_t len); + [CCode (cname = "signal_buffer_create")] + public Buffer.from(uint8[] data); + + public Buffer copy(); + public Buffer append(uint8[] data); + public int compare(Buffer other); + + public uint8 get(int i) { return data[i]; } + public void set(int i, uint8 val) { data[i] = val; } + + public uint8[] data { get { int x = (int)len(); unowned uint8[] res = _data(); res.length = x; return res; } } + + [CCode (array_length = false, cname = "signal_buffer_data")] + private unowned uint8[] _data(); + private size_t len(); + } + + [Compact] + [CCode (cname = "signal_int_list", cheader_filename = "signal/signal_protocol_types.h", free_function="signal_int_list_free")] + public class IntList { + [CCode (cname = "signal_int_list_alloc")] + public IntList(); + [CCode (cname = "signal_int_list_push_back")] + public int add(int value); + public uint size { [CCode (cname = "signal_int_list_size")] get; } + [CCode (cname = "signal_int_list_at")] + public int get(uint index); + } + + [Compact] + [CCode (cname = "session_builder", cprefix = "session_builder_", free_function="session_builder_free", cheader_filename = "signal/session_builder.h")] + public class SessionBuilder { + [CCode (cname = "session_builder_process_pre_key_bundle")] + private int process_pre_key_bundle_(PreKeyBundle pre_key_bundle); + [CCode (cname = "session_builder_process_pre_key_bundle_")] + public void process_pre_key_bundle(PreKeyBundle pre_key_bundle) throws GLib.Error { + throw_by_code(process_pre_key_bundle_(pre_key_bundle)); + } + } + + [Compact] + [CCode (cname = "session_pre_key_bundle", cprefix = "session_pre_key_bundle_", cheader_filename = "signal/session_pre_key.h")] + public class PreKeyBundle : TypeBase { + public static int create(out PreKeyBundle bundle, uint32 registration_id, int device_id, uint32 pre_key_id, ECPublicKey? pre_key_public, + uint32 signed_pre_key_id, ECPublicKey? signed_pre_key_public, uint8[]? signed_pre_key_signature, ECPublicKey? identity_key); + public uint32 registration_id { get; } + public int device_id { get; } + public uint32 pre_key_id { get; } + public ECPublicKey pre_key { owned get; } + public uint32 signed_pre_key_id { get; } + public ECPublicKey signed_pre_key { owned get; } + public Buffer signed_pre_key_signature { owned get; } + public ECPublicKey identity_key { owned get; } + } + + [Compact] + [CCode (cname = "session_pre_key", cprefix = "session_pre_key_", cheader_filename = "signal/session_pre_key.h,signal/signal_helper.h")] + public class PreKeyRecord : TypeBase { + public static int create(out PreKeyRecord pre_key, uint32 id, ECKeyPair key_pair); + //public static int deserialize(out PreKeyRecord pre_key, uint8[] data, NativeContext global_context); + [CCode (instance_pos = 2)] + public int serialze(out Buffer buffer); + public uint32 id { get; } + public ECKeyPair key_pair { get; } + } + + [Compact] + [CCode (cname = "session_record", cprefix = "session_record_", cheader_filename = "signal/signal_protocol_types.h")] + public class SessionRecord : TypeBase { + public SessionState state { get; } + public Buffer user_record { get; } + } + + [Compact] + [CCode (cname = "session_state", cprefix = "session_state_", cheader_filename = "signal/session_state.h")] + public class SessionState : TypeBase { + //public static int create(out SessionState state, NativeContext context); + //public static int deserialize(out SessionState state, uint8[] data, NativeContext context); + //public static int copy(out SessionState state, SessionState other_state, NativeContext context); + [CCode (instance_pos = 2)] + public int serialze(out Buffer buffer); + + public uint32 session_version { get; set; } + public ECPublicKey local_identity_key { get; set; } + public ECPublicKey remote_identity_key { get; set; } + //public Ratchet.RootKey root_key { get; set; } + public uint32 previous_counter { get; set; } + public ECPublicKey sender_ratchet_key { get; } + public ECKeyPair sender_ratchet_key_pair { get; } + //public Ratchet.ChainKey sender_chain_key { get; set; } + public uint32 remote_registration_id { get; set; } + public uint32 local_registration_id { get; set; } + public int needs_refresh { get; set; } + public ECPublicKey alice_base_key { get; set; } + } + + [Compact] + [CCode (cname = "session_signed_pre_key", cprefix = "session_signed_pre_key_", cheader_filename = "signal/session_pre_key.h")] + public class SignedPreKeyRecord : TypeBase { + public static int create(out SignedPreKeyRecord pre_key, uint32 id, uint64 timestamp, ECKeyPair key_pair, uint8[] signature); + [CCode (instance_pos = 2)] + public int serialze(out Buffer buffer); + + public uint32 id { get; } + public uint64 timestamp { get; } + public ECKeyPair key_pair { get; } + public uint8[] signature { [CCode (cname = "session_signed_pre_key_get_signature_")] get { int x = (int)get_signature_len(); unowned uint8[] res = get_signature(); res.length = x; return res; } } + + [CCode (array_length = false, cname = "session_signed_pre_key_get_signature")] + private unowned uint8[] get_signature(); + private size_t get_signature_len(); + } + + /** + * Address of an Signal Protocol message recipient + */ + [Compact] + [CCode (cname = "signal_protocol_address", cprefix = "signal_protocol_address_", cheader_filename = "signal/signal_protocol.h,signal/signal_helper.h")] + public class Address { + public Address(string name, int32 device_id); + public int32 device_id { get; set; } + public string name { owned get; set; } + } + + /** + * A representation of a (group + sender + device) tuple + */ + [Compact] + [CCode (cname = "signal_protocol_sender_key_name")] + public class SenderKeyName { + [CCode (cname = "group_id", array_length_cname="group_id_len")] + private char* group_id_; + private size_t group_id_len; + public Address sender; + } + + [Compact] + [CCode (cname = "ec_public_key", cprefix = "ec_public_key_", cheader_filename = "signal/curve.h,signal/signal_helper.h")] + public class ECPublicKey : TypeBase { + [CCode (cname = "curve_generate_public_key")] + public static int generate(out ECPublicKey public_key, ECPrivateKey private_key); + [CCode (instance_pos = 1, cname = "ec_public_key_serialize")] + private int serialize_([CCode (pos = 0)] out Buffer buffer); + [CCode (cname = "ec_public_key_serialize_")] + public uint8[] serialize() { + Buffer buffer; + int code = serialize_(out buffer); + if (code < 0 && code > MIN_ERROR_CODE) { + // Can only throw for invalid arguments or out of memory. + GLib.assert_not_reached(); + } + return buffer.data; + } + public int compare(ECPublicKey other); + public int memcmp(ECPublicKey other); + } + + [Compact] + [CCode (cname = "ec_private_key", cprefix = "ec_private_key_", cheader_filename = "signal/curve.h,signal/signal_helper.h")] + public class ECPrivateKey : TypeBase { + [CCode (instance_pos = 1, cname = "ec_private_key_serialize")] + private int serialize_([CCode (pos = 0)] out Buffer buffer); + [CCode (cname = "ec_private_key_serialize_")] + public uint8[] serialize() throws GLib.Error { + Buffer buffer; + int code = serialize_(out buffer); + if (code < 0 && code > MIN_ERROR_CODE) { + // Can only throw for invalid arguments or out of memory. + GLib.assert_not_reached(); + } + return buffer.data; + } + public int compare(ECPublicKey other); + } + + [Compact] + [CCode (cname = "ec_key_pair", cprefix="ec_key_pair_", cheader_filename = "signal/curve.h,signal/signal_helper.h")] + public class ECKeyPair : TypeBase { + public static int create(out ECKeyPair key_pair, ECPublicKey public_key, ECPrivateKey private_key); + public ECPublicKey public { get; } + public ECPrivateKey private { get; } + } + + [CCode (cname = "ratchet_message_keys", cheader_filename = "signal/ratchet.h")] + public class MessageKeys { + } + + [Compact] + [CCode (cname = "ratchet_identity_key_pair", cprefix = "ratchet_identity_key_pair_", cheader_filename = "signal/ratchet.h,signal/signal_helper.h")] + public class IdentityKeyPair : TypeBase { + public static int create(out IdentityKeyPair key_pair, ECPublicKey public_key, ECPrivateKey private_key); + public int serialze(out Buffer buffer); + public ECPublicKey public { get; } + public ECPrivateKey private { get; } + } + + [Compact] + [CCode (cname = "ec_public_key_list")] + public class PublicKeyList {} + + /** + * The main entry point for Signal Protocol encrypt/decrypt operations. + * + * Once a session has been established with session_builder, + * this class can be used for all encrypt/decrypt operations within + * that session. + */ + [Compact] + [CCode (cname = "session_cipher", cprefix = "session_cipher_", cheader_filename = "signal/session_cipher.h", free_function = "session_cipher_free")] + public class SessionCipher { + public void* user_data { get; set; } + public DecryptionCallback decryption_callback { set; } + [CCode (cname = "session_cipher_encrypt")] + private int encrypt_(uint8[] padded_message, out CiphertextMessage encrypted_message); + [CCode (cname = "session_cipher_encrypt_")] + public CiphertextMessage encrypt(uint8[] padded_message) throws GLib.Error { + CiphertextMessage res; + throw_by_code(encrypt_(padded_message, out res)); + return res; + } + [CCode (cname = "session_cipher_decrypt_pre_key_signal_message")] + private int decrypt_pre_key_signal_message_(PreKeySignalMessage ciphertext, void* decrypt_context, out Buffer plaintext); + [CCode (cname = "session_cipher_decrypt_pre_key_signal_message_")] + public uint8[] decrypt_pre_key_signal_message(PreKeySignalMessage ciphertext, void* decrypt_context = null) throws GLib.Error { + Buffer res; + throw_by_code(decrypt_pre_key_signal_message_(ciphertext, decrypt_context, out res)); + return res.data; + } + [CCode (cname = "session_cipher_decrypt_signal_message")] + private int decrypt_signal_message_(SignalMessage ciphertext, void* decrypt_context, out Buffer plaintext); + [CCode (cname = "session_cipher_decrypt_signal_message_")] + public uint8[] decrypt_signal_message(SignalMessage ciphertext, void* decrypt_context = null) throws GLib.Error { + Buffer res; + throw_by_code(decrypt_signal_message_(ciphertext, decrypt_context, out res)); + return res.data; + } + public int get_remote_registration_id(out uint32 remote_id); + public int get_session_version(uint32 version); + + [CCode (has_target = false)] + public delegate int DecryptionCallback(SessionCipher cipher, Buffer plaintext, void* decrypt_context); + } + + [CCode (cname = "int", cheader_filename = "signal/protocol.h", has_type_id = false)] + public enum CiphertextType { + [CCode (cname = "CIPHERTEXT_SIGNAL_TYPE")] + SIGNAL, + [CCode (cname = "CIPHERTEXT_PREKEY_TYPE")] + PREKEY, + [CCode (cname = "CIPHERTEXT_SENDERKEY_TYPE")] + SENDERKEY, + [CCode (cname = "CIPHERTEXT_SENDERKEY_DISTRIBUTION_TYPE")] + SENDERKEY_DISTRIBUTION + } + + [Compact] + [CCode (cname = "ciphertext_message", cprefix = "ciphertext_message_", cheader_filename = "signal/protocol.h,signal/signal_helper.h")] + public abstract class CiphertextMessage : TypeBase { + public CiphertextType type { get; } + [CCode (cname = "ciphertext_message_get_serialized")] + private unowned Buffer get_serialized_(); + public uint8[] serialized { [CCode (cname = "ciphertext_message_get_serialized_")] get { + return get_serialized_().data; + }} + } + [Compact] + [CCode (cname = "signal_message", cprefix = "signal_message_", cheader_filename = "signal/protocol.h,signal/signal_helper.h")] + public class SignalMessage : CiphertextMessage { + public ECPublicKey sender_ratchet_key { get; } + public uint8 message_version { get; } + public uint32 counter { get; } + public Buffer body { get; } + //public int verify_mac(uint8 message_version, ECPublicKey sender_identity_key, ECPublicKey receiver_identity_key, uint8[] mac, NativeContext global_context); + public static int is_legacy(uint8[] data); + } + [Compact] + [CCode (cname = "pre_key_signal_message", cprefix = "pre_key_signal_message_", cheader_filename = "signal/protocol.h,signal/signal_helper.h")] + public class PreKeySignalMessage : CiphertextMessage { + public uint8 message_version { get; } + public ECPublicKey identity_key { get; } + public uint32 registration_id { get; } + public uint32 pre_key_id { get; } + public uint32 signed_pre_key_id { get; } + public ECPublicKey base_key { get; } + public SignalMessage signal_message { get; } + } + [Compact] + [CCode (cname = "sender_key_message", cprefix = "sender_key_message_", cheader_filename = "signal/protocol.h,signal/signal_helper.h")] + public class SenderKeyMessage : CiphertextMessage { + public uint32 key_id { get; } + public uint32 iteration { get; } + public Buffer ciphertext { get; } + } + [Compact] + [CCode (cname = "sender_key_distribution_message", cprefix = "sender_key_distribution_message_", cheader_filename = "signal/protocol.h,signal/signal_helper.h")] + public class SenderKeyDistributionMessage : CiphertextMessage { + public uint32 id { get; } + public uint32 iteration { get; } + public Buffer chain_key { get; } + public ECPublicKey signature_key { get; } + } + + [CCode (cname = "signal_vala_encrypt", cheader_filename = "signal/signal_helper.h")] + private static int aes_encrypt_(out Buffer output, int cipher, uint8[] key, uint8[] iv, uint8[] plaintext, void *user_data); + + [CCode (cname = "signal_vala_encrypt_")] + public uint8[] aes_encrypt(int cipher, uint8[] key, uint8[] iv, uint8[] plaintext) throws GLib.Error { + Buffer buf; + throw_by_code(aes_encrypt_(out buf, cipher, key, iv, plaintext, null)); + return buf.data; + } + + [CCode (cname = "signal_vala_decrypt", cheader_filename = "signal/signal_helper.h")] + private static int aes_decrypt_(out Buffer output, int cipher, uint8[] key, uint8[] iv, uint8[] ciphertext, void *user_data); + + [CCode (cname = "signal_vala_decrypt_")] + public uint8[] aes_decrypt(int cipher, uint8[] key, uint8[] iv, uint8[] ciphertext) throws GLib.Error { + Buffer buf; + throw_by_code(aes_decrypt_(out buf, cipher, key, iv, ciphertext, null)); + return buf.data; + } + + [Compact] + [CCode (cname = "signal_context", cprefix="signal_context_", free_function="signal_context_destroy", cheader_filename = "signal/signal_protocol.h")] + public class NativeContext { + public static int create(out NativeContext context, void* user_data); + public int set_crypto_provider(NativeCryptoProvider crypto_provider); + public int set_locking_functions(LockingFunc lock, LockingFunc unlock); + public int set_log_function(LogFunc log); + } + [CCode (has_target = false)] + public delegate void LockingFunc(void* user_data); + [CCode (has_target = false)] + public delegate void LogFunc(LogLevel level, string message, size_t len, void* user_data); + + [Compact] + [CCode (cname = "signal_crypto_provider", cheader_filename = "signal/signal_protocol.h")] + public struct NativeCryptoProvider { + public RandomFunc random_func; + public HmacSha256Init hmac_sha256_init_func; + public HmacSha256Update hmac_sha256_update_func; + public HmacSha256Final hmac_sha256_final_func; + public HmacSha256Cleanup hmac_sha256_cleanup_func; + public Sha512DigestInit sha512_digest_init_func; + public Sha512DigestUpdate sha512_digest_update_func; + public Sha512DigestFinal sha512_digest_final_func; + public Sha512DigestCleanup sha512_digest_cleanup_func; + public CryptFunc encrypt_func; + public CryptFunc decrypt_func; + public void* user_data; + } + [CCode (has_target = false)] + public delegate int RandomFunc(uint8[] data, void* user_data); + [CCode (has_target = false)] + public delegate int HmacSha256Init(out void* hmac_context, uint8[] key, void* user_data); + [CCode (has_target = false)] + public delegate int HmacSha256Update(void* hmac_context, uint8[] data, void* user_data); + [CCode (has_target = false)] + public delegate int HmacSha256Final(void* hmac_context, out Buffer buffer, void* user_data); + [CCode (has_target = false)] + public delegate int HmacSha256Cleanup(void* hmac_context, void* user_data); + [CCode (has_target = false)] + public delegate int Sha512DigestInit(out void* digest_context, void* user_data); + [CCode (has_target = false)] + public delegate int Sha512DigestUpdate(void* digest_context, uint8[] data, void* user_data); + [CCode (has_target = false)] + public delegate int Sha512DigestFinal(void* digest_context, out Buffer buffer, void* user_data); + [CCode (has_target = false)] + public delegate int Sha512DigestCleanup(void* digest_context, void* user_data); + [CCode (has_target = false)] + public delegate int CryptFunc(out Buffer output, Cipher cipher, uint8[] key, uint8[] iv, uint8[] content, void* user_data); + + [Compact] + [CCode (cname = "signal_protocol_session_store", cheader_filename = "signal/signal_protocol.h")] + public struct NativeSessionStore { + public LoadSessionFunc load_session_func; + public GetSubDeviceSessionsFunc get_sub_device_sessions_func; + public StoreSessionFunc store_session_func; + public ContainsSessionFunc contains_session_func; + public DeleteSessionFunc delete_session_func; + public DeleteAllSessionsFunc delete_all_sessions_func; + public DestroyFunc destroy_func; + public void* user_data; + } + [CCode (has_target = false)] + public delegate int LoadSessionFunc(out Buffer record, out Buffer user_record, Address address, void* user_data); + [CCode (has_target = false)] + public delegate int GetSubDeviceSessionsFunc(out IntList sessions, [CCode (array_length_type = "size_t")] char[] name, void* user_data); + [CCode (has_target = false)] + public delegate int StoreSessionFunc(Address address, [CCode (array_length_type = "size_t")] uint8[] record, [CCode (array_length_type = "size_t")] uint8[] user_record, void* user_data); + [CCode (has_target = false)] + public delegate int ContainsSessionFunc(Address address, void* user_data); + [CCode (has_target = false)] + public delegate int DeleteSessionFunc(Address address, void* user_data); + [CCode (has_target = false)] + public delegate int DeleteAllSessionsFunc([CCode (array_length_type = "size_t")] char[] name, void* user_data); + + [Compact] + [CCode (cname = "signal_protocol_identity_key_store", cheader_filename = "signal/signal_protocol.h")] + public struct NativeIdentityKeyStore { + GetIdentityKeyPairFunc get_identity_key_pair; + GetLocalRegistrationIdFunc get_local_registration_id; + SaveIdentityFunc save_identity; + IsTrustedIdentityFunc is_trusted_identity; + DestroyFunc destroy_func; + void* user_data; + } + [CCode (has_target = false)] + public delegate int GetIdentityKeyPairFunc(out Buffer public_data, out Buffer private_data, void* user_data); + [CCode (has_target = false)] + public delegate int GetLocalRegistrationIdFunc(void* user_data, out uint32 registration_id); + [CCode (has_target = false)] + public delegate int SaveIdentityFunc(Address address, [CCode (array_length_type = "size_t")] uint8[] key, void* user_data); + [CCode (has_target = false)] + public delegate int IsTrustedIdentityFunc(Address address, [CCode (array_length_type = "size_t")] uint8[] key, void* user_data); + + [Compact] + [CCode (cname = "signal_protocol_pre_key_store", cheader_filename = "signal/signal_protocol.h")] + public struct NativePreKeyStore { + LoadPreKeyFunc load_pre_key; + StorePreKeyFunc store_pre_key; + ContainsPreKeyFunc contains_pre_key; + RemovePreKeyFunc remove_pre_key; + DestroyFunc destroy_func; + void* user_data; + } + [CCode (has_target = false)] + public delegate int LoadPreKeyFunc(out Buffer record, uint32 pre_key_id, void* user_data); + [CCode (has_target = false)] + public delegate int StorePreKeyFunc(uint32 pre_key_id, [CCode (array_length_type = "size_t")] uint8[] record, void* user_data); + [CCode (has_target = false)] + public delegate int ContainsPreKeyFunc(uint32 pre_key_id, void* user_data); + [CCode (has_target = false)] + public delegate int RemovePreKeyFunc(uint32 pre_key_id, void* user_data); + + + [Compact] + [CCode (cname = "signal_protocol_signed_pre_key_store", cheader_filename = "signal/signal_protocol.h")] + public struct NativeSignedPreKeyStore { + LoadPreKeyFunc load_signed_pre_key; + StorePreKeyFunc store_signed_pre_key; + ContainsPreKeyFunc contains_signed_pre_key; + RemovePreKeyFunc remove_signed_pre_key; + DestroyFunc destroy_func; + void* user_data; + } + + + [Compact] + [CCode (cname = "signal_protocol_sender_key_store")] + public struct NativeSenderKeyStore { + StoreSenderKeyFunc store_sender_key; + LoadSenderKeyFunc load_sender_key; + DestroyFunc destroy_func; + void* user_data; + } + [CCode (has_target = false)] + public delegate int StoreSenderKeyFunc(SenderKeyName sender_key_name, [CCode (array_length_type = "size_t")] uint8[] record, [CCode (array_length_type = "size_t")] uint8[] user_record, void* user_data); + [CCode (has_target = false)] + public delegate int LoadSenderKeyFunc(out Buffer record, out Buffer user_record, SenderKeyName sender_key_name, void* user_data); + + [CCode (has_target = false)] + public delegate void DestroyFunc(void* user_data); + + [Compact] + [CCode (cname = "signal_protocol_store_context", cprefix = "signal_protocol_store_context_", free_function="signal_protocol_store_context_destroy", cheader_filename = "signal/signal_protocol.h")] + public class NativeStoreContext { + public static int create(out NativeStoreContext context, NativeContext global_context); + public int set_session_store(NativeSessionStore store); + public int set_pre_key_store(NativePreKeyStore store); + public int set_signed_pre_key_store(NativeSignedPreKeyStore store); + public int set_identity_key_store(NativeIdentityKeyStore store); + public int set_sender_key_store(NativeSenderKeyStore store); + } + + + [CCode (cheader_filename = "signal/signal_protocol.h")] + namespace Protocol { + + /** + * Interface to the pre-key store. + * These functions will use the callbacks in the provided + * signal_protocol_store_context instance and operate in terms of higher level + * library data structures. + */ + [CCode (cprefix = "signal_protocol_pre_key_")] + namespace PreKey { + public int load_key(NativeStoreContext context, out PreKeyRecord pre_key, uint32 pre_key_id); + public int store_key(NativeStoreContext context, PreKeyRecord pre_key); + public int contains_key(NativeStoreContext context, uint32 pre_key_id); + public int remove_key(NativeStoreContext context, uint32 pre_key_id); + } + + [CCode (cprefix = "signal_protocol_signed_pre_key_")] + namespace SignedPreKey { + public int load_key(NativeStoreContext context, out SignedPreKeyRecord pre_key, uint32 pre_key_id); + public int store_key(NativeStoreContext context, SignedPreKeyRecord pre_key); + public int contains_key(NativeStoreContext context, uint32 pre_key_id); + public int remove_key(NativeStoreContext context, uint32 pre_key_id); + } + + /** + * Interface to the session store. + * These functions will use the callbacks in the provided + * signal_protocol_store_context instance and operate in terms of higher level + * library data structures. + */ + [CCode (cprefix = "signal_protocol_session_")] + namespace Session { + public int load_session(NativeStoreContext context, out SessionRecord record, Address address); + public int get_sub_device_sessions(NativeStoreContext context, out IntList sessions, char[] name); + public int store_session(NativeStoreContext context, Address address, SessionRecord record); + public int contains_session(NativeStoreContext context, Address address); + public int delete_session(NativeStoreContext context, Address address); + public int delete_all_sessions(NativeStoreContext context, char[] name); + } + + namespace Identity { + public int get_key_pair(NativeStoreContext store_context, out IdentityKeyPair key_pair); + public int get_local_registration_id(NativeStoreContext store_context, out uint32 registration_id); + public int save_identity(NativeStoreContext store_context, Address address, ECPublicKey identity_key); + public int is_trusted_identity(NativeStoreContext store_context, Address address, ECPublicKey identity_key); + } + + [CCode (cheader_filename = "signal/key_helper.h", cprefix = "signal_protocol_key_helper_")] + namespace KeyHelper { + [Compact] + [CCode (cname = "signal_protocol_key_helper_pre_key_list_node", cprefix = "signal_protocol_key_helper_key_list_", free_function="signal_protocol_key_helper_key_list_free")] + public class PreKeyListNode { + public PreKeyRecord element(); + public PreKeyListNode next(); + } + + public int generate_identity_key_pair(out IdentityKeyPair key_pair, NativeContext global_context); + public int generate_registration_id(out int32 registration_id, int extended_range, NativeContext global_context); + public int get_random_sequence(out int value, int max, NativeContext global_context); + public int generate_pre_keys(out PreKeyListNode head, uint start, uint count, NativeContext global_context); + public int generate_last_resort_pre_key(out PreKeyRecord pre_key, NativeContext global_context); + public int generate_signed_pre_key(out SignedPreKeyRecord signed_pre_key, IdentityKeyPair identity_key_pair, uint32 signed_pre_key_id, uint64 timestamp, NativeContext global_context); + public int generate_sender_signing_key(out ECKeyPair key_pair, NativeContext global_context); + public int generate_sender_key(out Buffer key_buffer, NativeContext global_context); + public int generate_sender_key_id(out int32 key_id, NativeContext global_context); + } + } + + [CCode (cheader_filename = "signal/curve.h")] + namespace Curve { + [CCode (cname = "curve_calculate_agreement")] + public int calculate_agreement([CCode (array_length = false)] out uint8[] shared_key_data, ECPublicKey public_key, ECPrivateKey private_key); + [CCode (cname = "curve_calculate_signature")] + public int calculate_signature(NativeContext context, out Buffer signature, ECPrivateKey signing_key, uint8[] message); + [CCode (cname = "curve_verify_signature")] + public int verify_signature(ECPublicKey signing_key, uint8[] message, uint8[] signature); + } + + [CCode (cname = "session_builder_create", cheader_filename = "signal/session_builder.h")] + public static int session_builder_create(out SessionBuilder builder, NativeStoreContext store, Address remote_address, NativeContext global_context); + [CCode (cname = "session_cipher_create", cheader_filename = "signal/session_cipher.h")] + public static int session_cipher_create(out SessionCipher cipher, NativeStoreContext store, Address remote_address, NativeContext global_context); + [CCode (cname = "pre_key_signal_message_deserialize", cheader_filename = "signal/protocol.h")] + public static int pre_key_signal_message_deserialize(out PreKeySignalMessage message, uint8[] data, NativeContext global_context); + [CCode (cname = "pre_key_signal_message_copy", cheader_filename = "signal/protocol.h")] + public static int pre_key_signal_message_copy(out PreKeySignalMessage message, PreKeySignalMessage other_message, NativeContext global_context); + [CCode (cname = "signal_message_create", cheader_filename = "signal/protocol.h")] + public static int signal_message_create(out SignalMessage message, uint8 message_version, uint8[] mac_key, ECPublicKey sender_ratchet_key, uint32 counter, uint32 previous_counter, uint8[] ciphertext, ECPublicKey sender_identity_key, ECPublicKey receiver_identity_key, NativeContext global_context); + [CCode (cname = "signal_message_deserialize", cheader_filename = "signal/protocol.h")] + public static int signal_message_deserialize(out SignalMessage message, uint8[] data, NativeContext global_context); + [CCode (cname = "signal_message_copy", cheader_filename = "signal/protocol.h")] + public static int signal_message_copy(out SignalMessage message, SignalMessage other_message, NativeContext global_context); + [CCode (cname = "curve_generate_key_pair", cheader_filename = "signal/curve.h")] + public static int curve_generate_key_pair(NativeContext context, out ECKeyPair key_pair); + [CCode (cname = "curve_decode_private_point", cheader_filename = "signal/curve.h")] + public static int curve_decode_private_point(out ECPrivateKey public_key, uint8[] key, NativeContext global_context); + [CCode (cname = "curve_decode_point", cheader_filename = "signal/curve.h")] + public static int curve_decode_point(out ECPublicKey public_key, uint8[] key, NativeContext global_context); + [CCode (cname = "curve_generate_private_key", cheader_filename = "signal/curve.h")] + public static int curve_generate_private_key(NativeContext context, out ECPrivateKey private_key); + [CCode (cname = "ratchet_identity_key_pair_deserialize", cheader_filename = "signal/ratchet.h")] + public static int ratchet_identity_key_pair_deserialize(out IdentityKeyPair key_pair, uint8[] data, NativeContext global_context); + [CCode (cname = "session_signed_pre_key_deserialize", cheader_filename = "signal/signed_pre_key.h")] + public static int session_signed_pre_key_deserialize(out SignedPreKeyRecord pre_key, uint8[] data, NativeContext global_context); + + [Compact] + [CCode (cname = "hkdf_context", cprefix = "hkdf_", free_function = "hkdf_destroy", cheader_filename = "signal/hkdf.h")] + public class NativeHkdfContext { + public static int create(out NativeHkdfContext context, int message_version, NativeContext global_context); + public int compare(NativeHkdfContext other); + public ssize_t derive_secrets([CCode (array_length = false)] out uint8[] output, uint8[] input_key_material, uint8[] salt, uint8[] info, size_t output_len); + } + + [CCode (cname = "setup_signal_vala_crypto_provider", cheader_filename = "signal/signal_helper.h")] + public static void setup_crypto_provider(NativeContext context); + [CCode (cname = "signal_vala_randomize", cheader_filename = "signal/signal_helper.h")] + public static int native_random(uint8[] data); +} diff --git a/plugins/signal-protocol/CMakeLists.txt b/plugins/signal-protocol/CMakeLists.txt deleted file mode 100644 index b3cfae9d..00000000 --- a/plugins/signal-protocol/CMakeLists.txt +++ /dev/null @@ -1,91 +0,0 @@ -find_package(GCrypt REQUIRED) -find_packages(SIGNAL_PROTOCOL_PACKAGES REQUIRED - Gee - GLib - GObject -) - -vala_precompile(SIGNAL_PROTOCOL_VALA_C -SOURCES - "src/context.vala" - "src/simple_iks.vala" - "src/simple_ss.vala" - "src/simple_pks.vala" - "src/simple_spks.vala" - "src/store.vala" - "src/util.vala" -CUSTOM_VAPIS - ${CMAKE_CURRENT_SOURCE_DIR}/vapi/signal-protocol-public.vapi - ${CMAKE_CURRENT_SOURCE_DIR}/vapi/signal-protocol-native.vapi -PACKAGES - ${SIGNAL_PROTOCOL_PACKAGES} -GENERATE_VAPI - signal-protocol-vala -GENERATE_HEADER - signal-protocol-vala -) - -set(C_HEADERS_SRC "") -set(C_HEADERS_TARGET "") - -# libsignal-protocol-c has a history of breaking compatibility on the patch level -# we'll have to check compatibility for every new release -# distro maintainers may update this dependency after compatibility tests -find_package(SignalProtocol 2.3.2 REQUIRED) - -list(APPEND C_HEADERS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/signal_helper.h") -list(APPEND C_HEADERS_TARGET "${CMAKE_BINARY_DIR}/exports/signal_helper.h") - -add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/signal_helper.h" -COMMAND - cp "${CMAKE_CURRENT_SOURCE_DIR}/src/signal_helper.h" "${CMAKE_BINARY_DIR}/exports/signal_helper.h" -DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/src/signal_helper.h" -COMMENT - Copy header file signal_helper.h -) - -add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/exports/signal-protocol.vapi -COMMAND - cat "${CMAKE_CURRENT_SOURCE_DIR}/vapi/signal-protocol-public.vapi" "${CMAKE_BINARY_DIR}/exports/signal-protocol-vala.vapi" > "${CMAKE_BINARY_DIR}/exports/signal-protocol.vapi" -DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/vapi/signal-protocol-public.vapi - ${CMAKE_BINARY_DIR}/exports/signal-protocol-vala.vapi -) - -add_custom_target(signal-protocol-vapi -DEPENDS - ${CMAKE_BINARY_DIR}/exports/signal-protocol.vapi - ${CMAKE_BINARY_DIR}/exports/signal-protocol-vala.h - ${C_HEADERS_TARGET} -) - -set(CFLAGS ${VALA_CFLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/libsignal-protocol-c/src -I${CMAKE_CURRENT_SOURCE_DIR}/src) -add_definitions(${CFLAGS}) -add_library(signal-protocol-vala STATIC ${SIGNAL_PROTOCOL_VALA_C} ${CMAKE_CURRENT_SOURCE_DIR}/src/signal_helper.c) -add_dependencies(signal-protocol-vala signal-protocol-vapi) -target_link_libraries(signal-protocol-vala ${SIGNAL_PROTOCOL_PACKAGES} gcrypt signal-protocol-c m) -set_property(TARGET signal-protocol-vala PROPERTY POSITION_INDEPENDENT_CODE ON) - -if(BUILD_TESTS) - vala_precompile(SIGNAL_TEST_VALA_C - SOURCES - "tests/common.vala" - "tests/testcase.vala" - - "tests/curve25519.vala" - "tests/hkdf.vala" - "tests/session_builder.vala" - CUSTOM_VAPIS - ${CMAKE_BINARY_DIR}/exports/signal-protocol-vala_internal.vapi - ${CMAKE_CURRENT_SOURCE_DIR}/vapi/signal-protocol-public.vapi - ${CMAKE_CURRENT_SOURCE_DIR}/vapi/signal-protocol-native.vapi - PACKAGES - ${SIGNAL_PROTOCOL_PACKAGES} - ) - - set(CFLAGS ${VALA_CFLAGS} -I${CMAKE_CURRENT_BINARY_DIR}/signal-protocol) - add_executable(signal-protocol-vala-test ${SIGNAL_TEST_VALA_C}) - add_dependencies(signal-protocol-vala-test signal-protocol-vala) - target_link_libraries(signal-protocol-vala-test signal-protocol-vala ${SIGNAL_PROTOCOL_PACKAGES}) -endif(BUILD_TESTS) diff --git a/plugins/signal-protocol/src/context.vala b/plugins/signal-protocol/src/context.vala deleted file mode 100644 index 40a07b0f..00000000 --- a/plugins/signal-protocol/src/context.vala +++ /dev/null @@ -1,103 +0,0 @@ -namespace Signal { - -public class Context { - internal NativeContext native_context; - private RecMutex mutex = RecMutex(); - - static void locking_function_lock(void* user_data) { - Context ctx = (Context) user_data; - ctx.mutex.lock(); - } - - static void locking_function_unlock(void* user_data) { - Context ctx = (Context) user_data; - ctx.mutex.unlock(); - } - - static void stderr_log(LogLevel level, string message, size_t len, void* user_data) { - printerr(@"$level: $message\n"); - } - - public Context(bool log = false) throws Error { - throw_by_code(NativeContext.create(out native_context, this), "Error initializing native context"); - throw_by_code(native_context.set_locking_functions(locking_function_lock, locking_function_unlock), "Error initializing native locking functions"); - if (log) native_context.set_log_function(stderr_log); - setup_crypto_provider(native_context); - } - - public Store create_store() { - return new Store(this); - } - - public void randomize(uint8[] data) throws Error { - throw_by_code(Signal.native_random(data)); - } - - public SignedPreKeyRecord generate_signed_pre_key(IdentityKeyPair identity_key_pair, int32 id, uint64 timestamp = 0) throws Error { - if (timestamp == 0) timestamp = new DateTime.now_utc().to_unix(); - SignedPreKeyRecord res; - throw_by_code(Protocol.KeyHelper.generate_signed_pre_key(out res, identity_key_pair, id, timestamp, native_context)); - return res; - } - - public Gee.Set generate_pre_keys(uint start, uint count) throws Error { - Gee.Set res = new Gee.HashSet(); - for(uint i = start; i < start+count; i++) { - ECKeyPair pair = generate_key_pair(); - PreKeyRecord record; - throw_by_code(PreKeyRecord.create(out record, i, pair)); - res.add(record); - } - return res; - } - - public ECPublicKey decode_public_key(uint8[] bytes) throws Error { - ECPublicKey public_key; - throw_by_code(curve_decode_point(out public_key, bytes, native_context), "Error decoding public key"); - return public_key; - } - - public ECPrivateKey decode_private_key(uint8[] bytes) throws Error { - ECPrivateKey private_key; - throw_by_code(curve_decode_private_point(out private_key, bytes, native_context), "Error decoding private key"); - return private_key; - } - - public ECKeyPair generate_key_pair() throws Error { - ECKeyPair key_pair; - throw_by_code(curve_generate_key_pair(native_context, out key_pair), "Error generating key pair"); - return key_pair; - } - - public uint8[] calculate_signature(ECPrivateKey signing_key, uint8[] message) throws Error { - Buffer signature; - throw_by_code(Curve.calculate_signature(native_context, out signature, signing_key, message), "Error calculating signature"); - return signature.data; - } - - public SignalMessage deserialize_signal_message(uint8[] data) throws Error { - SignalMessage res; - throw_by_code(signal_message_deserialize(out res, data, native_context)); - return res; - } - - public SignalMessage copy_signal_message(CiphertextMessage original) throws Error { - SignalMessage res; - throw_by_code(signal_message_copy(out res, (SignalMessage) original, native_context)); - return res; - } - - public PreKeySignalMessage deserialize_pre_key_signal_message(uint8[] data) throws Error { - PreKeySignalMessage res; - throw_by_code(pre_key_signal_message_deserialize(out res, data, native_context)); - return res; - } - - public PreKeySignalMessage copy_pre_key_signal_message(CiphertextMessage original) throws Error { - PreKeySignalMessage res; - throw_by_code(pre_key_signal_message_copy(out res, (PreKeySignalMessage) original, native_context)); - return res; - } -} - -} diff --git a/plugins/signal-protocol/src/signal_helper.c b/plugins/signal-protocol/src/signal_helper.c deleted file mode 100644 index 1a428c44..00000000 --- a/plugins/signal-protocol/src/signal_helper.c +++ /dev/null @@ -1,377 +0,0 @@ -#include - -#include - -signal_type_base* signal_type_ref_vapi(void* instance) { - g_return_val_if_fail(instance != NULL, NULL); - signal_type_ref(instance); - return instance; -} - -signal_type_base* signal_type_unref_vapi(void* instance) { - g_return_val_if_fail(instance != NULL, NULL); - signal_type_unref(instance); - return NULL; -} - -signal_protocol_address* signal_protocol_address_new(const gchar* name, int32_t device_id) { - g_return_val_if_fail(name != NULL, NULL); - signal_protocol_address* address = malloc(sizeof(signal_protocol_address)); - address->device_id = -1; - address->name = NULL; - signal_protocol_address_set_name(address, name); - signal_protocol_address_set_device_id(address, device_id); - return address; -} - -void signal_protocol_address_free(signal_protocol_address* ptr) { - g_return_if_fail(ptr != NULL); - if (ptr->name) { - g_free((void*)ptr->name); - } - return free(ptr); -} - -void signal_protocol_address_set_name(signal_protocol_address* self, const gchar* name) { - g_return_if_fail(self != NULL); - g_return_if_fail(name != NULL); - gchar* n = g_malloc(strlen(name)+1); - memcpy(n, name, strlen(name)); - n[strlen(name)] = 0; - if (self->name) { - g_free((void*)self->name); - } - self->name = n; - self->name_len = strlen(n); -} - -gchar* signal_protocol_address_get_name(signal_protocol_address* self) { - g_return_val_if_fail(self != NULL, NULL); - g_return_val_if_fail(self->name != NULL, 0); - gchar* res = g_malloc(sizeof(char) * (self->name_len + 1)); - memcpy(res, self->name, self->name_len); - res[self->name_len] = 0; - return res; -} - -int32_t signal_protocol_address_get_device_id(signal_protocol_address* self) { - g_return_val_if_fail(self != NULL, -1); - return self->device_id; -} - -void signal_protocol_address_set_device_id(signal_protocol_address* self, int32_t device_id) { - g_return_if_fail(self != NULL); - self->device_id = device_id; -} - -int signal_vala_randomize(uint8_t *data, size_t len) { - gcry_randomize(data, len, GCRY_STRONG_RANDOM); - return SG_SUCCESS; -} - -int signal_vala_random_generator(uint8_t *data, size_t len, void *user_data) { - gcry_randomize(data, len, GCRY_STRONG_RANDOM); - return SG_SUCCESS; -} - -int signal_vala_hmac_sha256_init(void **hmac_context, const uint8_t *key, size_t key_len, void *user_data) { - gcry_mac_hd_t* ctx = malloc(sizeof(gcry_mac_hd_t)); - if (!ctx) return SG_ERR_NOMEM; - - if (gcry_mac_open(ctx, GCRY_MAC_HMAC_SHA256, 0, 0)) { - free(ctx); - return SG_ERR_UNKNOWN; - } - - if (gcry_mac_setkey(*ctx, key, key_len)) { - free(ctx); - return SG_ERR_UNKNOWN; - } - - *hmac_context = ctx; - - return SG_SUCCESS; -} - -int signal_vala_hmac_sha256_update(void *hmac_context, const uint8_t *data, size_t data_len, void *user_data) { - gcry_mac_hd_t* ctx = hmac_context; - - if (gcry_mac_write(*ctx, data, data_len)) return SG_ERR_UNKNOWN; - - return SG_SUCCESS; -} - -int signal_vala_hmac_sha256_final(void *hmac_context, signal_buffer **output, void *user_data) { - size_t len = gcry_mac_get_algo_maclen(GCRY_MAC_HMAC_SHA256); - uint8_t md[len]; - gcry_mac_hd_t* ctx = hmac_context; - - if (gcry_mac_read(*ctx, md, &len)) return SG_ERR_UNKNOWN; - - signal_buffer *output_buffer = signal_buffer_create(md, len); - if (!output_buffer) return SG_ERR_NOMEM; - - *output = output_buffer; - - return SG_SUCCESS; -} - -void signal_vala_hmac_sha256_cleanup(void *hmac_context, void *user_data) { - gcry_mac_hd_t* ctx = hmac_context; - if (ctx) { - gcry_mac_close(*ctx); - free(ctx); - } -} - -int signal_vala_sha512_digest_init(void **digest_context, void *user_data) { - gcry_md_hd_t* ctx = malloc(sizeof(gcry_mac_hd_t)); - if (!ctx) return SG_ERR_NOMEM; - - if (gcry_md_open(ctx, GCRY_MD_SHA512, 0)) { - free(ctx); - return SG_ERR_UNKNOWN; - } - - *digest_context = ctx; - - return SG_SUCCESS; -} - -int signal_vala_sha512_digest_update(void *digest_context, const uint8_t *data, size_t data_len, void *user_data) { - gcry_md_hd_t* ctx = digest_context; - - gcry_md_write(*ctx, data, data_len); - - return SG_SUCCESS; -} - -int signal_vala_sha512_digest_final(void *digest_context, signal_buffer **output, void *user_data) { - size_t len = gcry_md_get_algo_dlen(GCRY_MD_SHA512); - gcry_md_hd_t* ctx = digest_context; - - uint8_t* md = gcry_md_read(*ctx, GCRY_MD_SHA512); - if (!md) return SG_ERR_UNKNOWN; - - gcry_md_reset(*ctx); - - signal_buffer *output_buffer = signal_buffer_create(md, len); - free(md); - if (!output_buffer) return SG_ERR_NOMEM; - - *output = output_buffer; - - return SG_SUCCESS; -} - -void signal_vala_sha512_digest_cleanup(void *digest_context, void *user_data) { - gcry_md_hd_t* ctx = digest_context; - if (ctx) { - gcry_md_close(*ctx); - free(ctx); - } -} - -const int aes_cipher(int cipher, size_t key_len, int* algo, int* mode) { - switch (key_len) { - case 16: - *algo = GCRY_CIPHER_AES128; - break; - case 24: - *algo = GCRY_CIPHER_AES192; - break; - case 32: - *algo = GCRY_CIPHER_AES256; - break; - default: - return SG_ERR_UNKNOWN; - } - switch (cipher) { - case SG_CIPHER_AES_CBC_PKCS5: - *mode = GCRY_CIPHER_MODE_CBC; - break; - case SG_CIPHER_AES_CTR_NOPADDING: - *mode = GCRY_CIPHER_MODE_CTR; - break; - case SG_CIPHER_AES_GCM_NOPADDING: - *mode = GCRY_CIPHER_MODE_GCM; - break; - default: - return SG_ERR_UNKNOWN; - } - return SG_SUCCESS; -} - -int signal_vala_encrypt(signal_buffer **output, - int cipher, - const uint8_t *key, size_t key_len, - const uint8_t *iv, size_t iv_len, - const uint8_t *plaintext, size_t plaintext_len, - void *user_data) { - int algo, mode, error_code = SG_ERR_UNKNOWN; - if (aes_cipher(cipher, key_len, &algo, &mode)) return SG_ERR_INVAL; - - gcry_cipher_hd_t ctx = {0}; - - if (gcry_cipher_open(&ctx, algo, mode, 0)) return SG_ERR_NOMEM; - - signal_buffer* padded = 0; - signal_buffer* out_buf = 0; - goto no_error; -error: - gcry_cipher_close(ctx); - if (padded != 0) { - signal_buffer_bzero_free(padded); - } - if (out_buf != 0) { - signal_buffer_free(out_buf); - } - return error_code; -no_error: - - if (gcry_cipher_setkey(ctx, key, key_len)) goto error; - - uint8_t tag_len = 0, pad_len = 0; - switch (cipher) { - case SG_CIPHER_AES_CBC_PKCS5: - if (gcry_cipher_setiv(ctx, iv, iv_len)) goto error; - pad_len = 16 - (plaintext_len % 16); - if (pad_len == 0) pad_len = 16; - break; - case SG_CIPHER_AES_CTR_NOPADDING: - if (gcry_cipher_setctr(ctx, iv, iv_len)) goto error; - break; - case SG_CIPHER_AES_GCM_NOPADDING: - if (gcry_cipher_setiv(ctx, iv, iv_len)) goto error; - tag_len = 16; - break; - default: - return SG_ERR_UNKNOWN; - } - - size_t padded_len = plaintext_len + pad_len; - padded = signal_buffer_alloc(padded_len); - if (padded == 0) { - error_code = SG_ERR_NOMEM; - goto error; - } - - memset(signal_buffer_data(padded) + plaintext_len, pad_len, pad_len); - memcpy(signal_buffer_data(padded), plaintext, plaintext_len); - - out_buf = signal_buffer_alloc(padded_len + tag_len); - if (out_buf == 0) { - error_code = SG_ERR_NOMEM; - goto error; - } - - if (gcry_cipher_encrypt(ctx, signal_buffer_data(out_buf), padded_len, signal_buffer_data(padded), padded_len)) goto error; - - if (tag_len > 0) { - if (gcry_cipher_gettag(ctx, signal_buffer_data(out_buf) + padded_len, tag_len)) goto error; - } - - *output = out_buf; - out_buf = 0; - - signal_buffer_bzero_free(padded); - padded = 0; - - gcry_cipher_close(ctx); - return SG_SUCCESS; -} - -int signal_vala_decrypt(signal_buffer **output, - int cipher, - const uint8_t *key, size_t key_len, - const uint8_t *iv, size_t iv_len, - const uint8_t *ciphertext, size_t ciphertext_len, - void *user_data) { - int algo, mode, error_code = SG_ERR_UNKNOWN; - *output = 0; - if (aes_cipher(cipher, key_len, &algo, &mode)) return SG_ERR_INVAL; - if (ciphertext_len == 0) return SG_ERR_INVAL; - - gcry_cipher_hd_t ctx = {0}; - - if (gcry_cipher_open(&ctx, algo, mode, 0)) return SG_ERR_NOMEM; - - signal_buffer* out_buf = 0; - goto no_error; -error: - gcry_cipher_close(ctx); - if (out_buf != 0) { - signal_buffer_bzero_free(out_buf); - } - return error_code; -no_error: - - if (gcry_cipher_setkey(ctx, key, key_len)) goto error; - - uint8_t tag_len = 0, pkcs_pad = FALSE; - switch (cipher) { - case SG_CIPHER_AES_CBC_PKCS5: - if (gcry_cipher_setiv(ctx, iv, iv_len)) goto error; - pkcs_pad = TRUE; - break; - case SG_CIPHER_AES_CTR_NOPADDING: - if (gcry_cipher_setctr(ctx, iv, iv_len)) goto error; - break; - case SG_CIPHER_AES_GCM_NOPADDING: - if (gcry_cipher_setiv(ctx, iv, iv_len)) goto error; - if (ciphertext_len < 16) goto error; - tag_len = 16; - break; - default: - goto error; - } - - size_t padded_len = ciphertext_len - tag_len; - out_buf = signal_buffer_alloc(padded_len); - if (out_buf == 0) { - error_code = SG_ERR_NOMEM; - goto error; - } - - if (gcry_cipher_decrypt(ctx, signal_buffer_data(out_buf), signal_buffer_len(out_buf), ciphertext, padded_len)) goto error; - - if (tag_len > 0) { - if (gcry_cipher_checktag(ctx, ciphertext + padded_len, tag_len)) goto error; - } - - if (pkcs_pad) { - uint8_t pad_len = signal_buffer_data(out_buf)[padded_len - 1]; - if (pad_len > 16 || pad_len > padded_len) goto error; - *output = signal_buffer_create(signal_buffer_data(out_buf), padded_len - pad_len); - signal_buffer_bzero_free(out_buf); - out_buf = 0; - } else { - *output = out_buf; - out_buf = 0; - } - - gcry_cipher_close(ctx); - return SG_SUCCESS; -} - -void setup_signal_vala_crypto_provider(signal_context *context) -{ - gcry_check_version(NULL); - - signal_crypto_provider provider = { - .random_func = signal_vala_random_generator, - .hmac_sha256_init_func = signal_vala_hmac_sha256_init, - .hmac_sha256_update_func = signal_vala_hmac_sha256_update, - .hmac_sha256_final_func = signal_vala_hmac_sha256_final, - .hmac_sha256_cleanup_func = signal_vala_hmac_sha256_cleanup, - .sha512_digest_init_func = signal_vala_sha512_digest_init, - .sha512_digest_update_func = signal_vala_sha512_digest_update, - .sha512_digest_final_func = signal_vala_sha512_digest_final, - .sha512_digest_cleanup_func = signal_vala_sha512_digest_cleanup, - .encrypt_func = signal_vala_encrypt, - .decrypt_func = signal_vala_decrypt, - .user_data = 0 - }; - - signal_context_set_crypto_provider(context, &provider); -} diff --git a/plugins/signal-protocol/src/signal_helper.h b/plugins/signal-protocol/src/signal_helper.h deleted file mode 100644 index 949a3c7b..00000000 --- a/plugins/signal-protocol/src/signal_helper.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef SIGNAL_PROTOCOL_VALA_HELPER -#define SIGNAL_PROTOCOL_VALA_HELPER 1 - -#include -#include -#include - -#define SG_CIPHER_AES_GCM_NOPADDING 1000 - -signal_type_base* signal_type_ref_vapi(void* what); -signal_type_base* signal_type_unref_vapi(void* what); - -signal_protocol_address* signal_protocol_address_new(const gchar* name, int32_t device_id); -void signal_protocol_address_free(signal_protocol_address* ptr); -void signal_protocol_address_set_name(signal_protocol_address* self, const gchar* name); -gchar* signal_protocol_address_get_name(signal_protocol_address* self); -void signal_protocol_address_set_device_id(signal_protocol_address* self, int32_t device_id); -int32_t signal_protocol_address_get_device_id(signal_protocol_address* self); - -int signal_vala_randomize(uint8_t *data, size_t len); -int signal_vala_random_generator(uint8_t *data, size_t len, void *user_data); -int signal_vala_hmac_sha256_init(void **hmac_context, const uint8_t *key, size_t key_len, void *user_data); -int signal_vala_hmac_sha256_update(void *hmac_context, const uint8_t *data, size_t data_len, void *user_data); -int signal_vala_hmac_sha256_final(void *hmac_context, signal_buffer **output, void *user_data); -void signal_vala_hmac_sha256_cleanup(void *hmac_context, void *user_data); -int signal_vala_sha512_digest_init(void **digest_context, void *user_data); -int signal_vala_sha512_digest_update(void *digest_context, const uint8_t *data, size_t data_len, void *user_data); -int signal_vala_sha512_digest_final(void *digest_context, signal_buffer **output, void *user_data); -void signal_vala_sha512_digest_cleanup(void *digest_context, void *user_data); - -int signal_vala_encrypt(signal_buffer **output, - int cipher, - const uint8_t *key, size_t key_len, - const uint8_t *iv, size_t iv_len, - const uint8_t *plaintext, size_t plaintext_len, - void *user_data); -int signal_vala_decrypt(signal_buffer **output, - int cipher, - const uint8_t *key, size_t key_len, - const uint8_t *iv, size_t iv_len, - const uint8_t *ciphertext, size_t ciphertext_len, - void *user_data); -void setup_signal_vala_crypto_provider(signal_context *context); - -#endif diff --git a/plugins/signal-protocol/src/simple_iks.vala b/plugins/signal-protocol/src/simple_iks.vala deleted file mode 100644 index 5247c455..00000000 --- a/plugins/signal-protocol/src/simple_iks.vala +++ /dev/null @@ -1,40 +0,0 @@ -using Gee; - -namespace Signal { - -public class SimpleIdentityKeyStore : IdentityKeyStore { - public override Bytes identity_key_private { get; set; } - public override Bytes identity_key_public { get; set; } - public override uint32 local_registration_id { get; set; } - private Map> trusted_identities = new HashMap>(); - - public override void save_identity(Address address, uint8[] key) throws Error { - string name = address.name; - if (trusted_identities.has_key(name)) { - if (trusted_identities[name].has_key(address.device_id)) { - trusted_identities[name][address.device_id].key = key; - trusted_identity_updated(trusted_identities[name][address.device_id]); - } else { - trusted_identities[name][address.device_id] = new TrustedIdentity.by_address(address, key); - trusted_identity_added(trusted_identities[name][address.device_id]); - } - } else { - trusted_identities[name] = new HashMap(); - trusted_identities[name][address.device_id] = new TrustedIdentity.by_address(address, key); - trusted_identity_added(trusted_identities[name][address.device_id]); - } - } - - public override bool is_trusted_identity(Address address, uint8[] key) throws Error { - if (!trusted_identities.has_key(address.name)) return true; - if (!trusted_identities[address.name].has_key(address.device_id)) return true; - uint8[] other_key = trusted_identities[address.name][address.device_id].key; - if (other_key.length != key.length) return false; - for (int i = 0; i < key.length; i++) { - if (other_key[i] != key[i]) return false; - } - return true; - } -} - -} diff --git a/plugins/signal-protocol/src/simple_pks.vala b/plugins/signal-protocol/src/simple_pks.vala deleted file mode 100644 index 1f059fda..00000000 --- a/plugins/signal-protocol/src/simple_pks.vala +++ /dev/null @@ -1,33 +0,0 @@ -using Gee; - -namespace Signal { - -public class SimplePreKeyStore : PreKeyStore { - private Map pre_key_map = new HashMap(); - - public override uint8[]? load_pre_key(uint32 pre_key_id) throws Error { - if (contains_pre_key(pre_key_id)) { - return pre_key_map[pre_key_id].record; - } - return null; - } - - public override void store_pre_key(uint32 pre_key_id, uint8[] record) throws Error { - PreKeyStore.Key key = new Key(pre_key_id, record); - pre_key_map[pre_key_id] = key; - pre_key_stored(key); - } - - public override bool contains_pre_key(uint32 pre_key_id) throws Error { - return pre_key_map.has_key(pre_key_id); - } - - public override void delete_pre_key(uint32 pre_key_id) throws Error { - PreKeyStore.Key key; - if (pre_key_map.unset(pre_key_id, out key)) { - pre_key_deleted(key); - } - } -} - -} \ No newline at end of file diff --git a/plugins/signal-protocol/src/simple_spks.vala b/plugins/signal-protocol/src/simple_spks.vala deleted file mode 100644 index f0fe09ab..00000000 --- a/plugins/signal-protocol/src/simple_spks.vala +++ /dev/null @@ -1,33 +0,0 @@ -using Gee; - -namespace Signal { - -public class SimpleSignedPreKeyStore : SignedPreKeyStore { - private Map pre_key_map = new HashMap(); - - public override uint8[]? load_signed_pre_key(uint32 pre_key_id) throws Error { - if (contains_signed_pre_key(pre_key_id)) { - return pre_key_map[pre_key_id].record; - } - return null; - } - - public override void store_signed_pre_key(uint32 pre_key_id, uint8[] record) throws Error { - SignedPreKeyStore.Key key = new Key(pre_key_id, record); - pre_key_map[pre_key_id] = key; - signed_pre_key_stored(key); - } - - public override bool contains_signed_pre_key(uint32 pre_key_id) throws Error { - return pre_key_map.has_key(pre_key_id); - } - - public override void delete_signed_pre_key(uint32 pre_key_id) throws Error { - SignedPreKeyStore.Key key; - if (pre_key_map.unset(pre_key_id, out key)) { - signed_pre_key_deleted(key); - } - } -} - -} \ No newline at end of file diff --git a/plugins/signal-protocol/src/simple_ss.vala b/plugins/signal-protocol/src/simple_ss.vala deleted file mode 100644 index 5213f736..00000000 --- a/plugins/signal-protocol/src/simple_ss.vala +++ /dev/null @@ -1,75 +0,0 @@ -using Gee; - -namespace Signal { - -public class SimpleSessionStore : SessionStore { - - private Map> session_map = new HashMap>(); - - public override uint8[]? load_session(Address address) throws Error { - if (session_map.has_key(address.name)) { - foreach (SessionStore.Session session in session_map[address.name]) { - if (session.device_id == address.device_id) return session.record; - } - } - return null; - } - - public override IntList get_sub_device_sessions(string name) throws Error { - IntList res = new IntList(); - if (session_map.has_key(name)) { - foreach (SessionStore.Session session in session_map[name]) { - res.add(session.device_id); - } - } - return res; - } - - public override void store_session(Address address, uint8[] record) throws Error { - if (contains_session(address)) { - delete_session(address); - } - if (!session_map.has_key(address.name)) { - session_map[address.name] = new ArrayList(); - } - SessionStore.Session session = new Session() { name = address.name, device_id = address.device_id, record = record }; - session_map[address.name].add(session); - session_stored(session); - } - - public override bool contains_session(Address address) throws Error { - if (!session_map.has_key(address.name)) return false; - foreach (SessionStore.Session session in session_map[address.name]) { - if (session.device_id == address.device_id) return true; - } - return false; - } - - public override void delete_session(Address address) throws Error { - if (!session_map.has_key(address.name)) throw_by_code(ErrorCode.UNKNOWN, "No session found"); - foreach (SessionStore.Session session in session_map[address.name]) { - if (session.device_id == address.device_id) { - session_map[address.name].remove(session); - if (session_map[address.name].size == 0) { - session_map.unset(address.name); - } - session_removed(session); - return; - } - } - } - - public override void delete_all_sessions(string name) throws Error { - if (session_map.has_key(name)) { - foreach (SessionStore.Session session in session_map[name]) { - session_map[name].remove(session); - if (session_map[name].size == 0) { - session_map.unset(name); - } - session_removed(session); - } - } - } -} - -} \ No newline at end of file diff --git a/plugins/signal-protocol/src/store.vala b/plugins/signal-protocol/src/store.vala deleted file mode 100644 index b440d838..00000000 --- a/plugins/signal-protocol/src/store.vala +++ /dev/null @@ -1,415 +0,0 @@ -namespace Signal { - -public abstract class IdentityKeyStore : Object { - public abstract Bytes identity_key_private { get; set; } - public abstract Bytes identity_key_public { get; set; } - public abstract uint32 local_registration_id { get; set; } - - public signal void trusted_identity_added(TrustedIdentity id); - public signal void trusted_identity_updated(TrustedIdentity id); - - public abstract void save_identity(Address address, uint8[] key) throws Error ; - - public abstract bool is_trusted_identity(Address address, uint8[] key) throws Error ; - - public class TrustedIdentity { - public uint8[] key { get; set; } - public string name { get; private set; } - public int device_id { get; private set; } - - public TrustedIdentity(string name, int device_id, uint8[] key) { - this.key = key; - this.name = name; - this.device_id = device_id; - } - - public TrustedIdentity.by_address(Address address, uint8[] key) { - this(address.name, address.device_id, key); - } - } -} - -public abstract class SessionStore : Object { - - public signal void session_stored(Session session); - public signal void session_removed(Session session); - public abstract uint8[]? load_session(Address address) throws Error ; - - public abstract IntList get_sub_device_sessions(string name) throws Error ; - - public abstract void store_session(Address address, uint8[] record) throws Error ; - - public abstract bool contains_session(Address address) throws Error ; - - public abstract void delete_session(Address address) throws Error ; - - public abstract void delete_all_sessions(string name) throws Error ; - - public class Session { - public string name; - public int device_id; - public uint8[] record; - } -} - -public abstract class PreKeyStore : Object { - - public signal void pre_key_stored(Key key); - public signal void pre_key_deleted(Key key); - - public abstract uint8[]? load_pre_key(uint32 pre_key_id) throws Error ; - - public abstract void store_pre_key(uint32 pre_key_id, uint8[] record) throws Error ; - - public abstract bool contains_pre_key(uint32 pre_key_id) throws Error ; - - public abstract void delete_pre_key(uint32 pre_key_id) throws Error ; - - public class Key { - public uint32 key_id { get; private set; } - public uint8[] record { get; private set; } - - public Key(uint32 key_id, uint8[] record) { - this.key_id = key_id; - this.record = record; - } - } -} - -public abstract class SignedPreKeyStore : Object { - - public signal void signed_pre_key_stored(Key key); - public signal void signed_pre_key_deleted(Key key); - - public abstract uint8[]? load_signed_pre_key(uint32 pre_key_id) throws Error ; - - public abstract void store_signed_pre_key(uint32 pre_key_id, uint8[] record) throws Error ; - - public abstract bool contains_signed_pre_key(uint32 pre_key_id) throws Error ; - - public abstract void delete_signed_pre_key(uint32 pre_key_id) throws Error ; - - public class Key { - public uint32 key_id { get; private set; } - public uint8[] record { get; private set; } - - public Key(uint32 key_id, uint8[] record) { - this.key_id = key_id; - this.record = record; - } - } -} - -public class Store : Object { - public Context context { get; private set; } - public IdentityKeyStore identity_key_store { get; set; default = new SimpleIdentityKeyStore(); } - public SessionStore session_store { get; set; default = new SimpleSessionStore(); } - public PreKeyStore pre_key_store { get; set; default = new SimplePreKeyStore(); } - public SignedPreKeyStore signed_pre_key_store { get; set; default = new SimpleSignedPreKeyStore(); } - public uint32 local_registration_id { get { return identity_key_store.local_registration_id; } } - internal NativeStoreContext native_context {get { return native_store_context_; }} - private NativeStoreContext native_store_context_; - - static int iks_get_identity_key_pair(out Buffer public_data, out Buffer private_data, void* user_data) { - Store store = (Store) user_data; - public_data = new Buffer.from(store.identity_key_store.identity_key_public.get_data()); - private_data = new Buffer.from(store.identity_key_store.identity_key_private.get_data()); - return 0; - } - - static int iks_get_local_registration_id(void* user_data, out uint32 registration_id) { - Store store = (Store) user_data; - registration_id = store.identity_key_store.local_registration_id; - return 0; - } - - static int iks_save_identity(Address address, uint8[] key, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - store.identity_key_store.save_identity(address, key); - return 0; - }); - } - - static int iks_is_trusted_identity(Address address, uint8[] key, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - return store.identity_key_store.is_trusted_identity(address, key) ? 1 : 0; - }); - } - - static void iks_destroy_func(void* user_data) { - } - - static int ss_load_session_func(out Buffer? record, out Buffer? user_record, Address address, void* user_data) { - Store store = (Store) user_data; - user_record = null; // No support for user_record - uint8[]? res = null; - try { - res = store.session_store.load_session(address); - } catch (Error e) { - record = null; - return e.code; - } - if (res == null) { - record = null; - return 0; - } - record = new Buffer.from((!)res); - if (record == null) return ErrorCode.NOMEM; - return 1; - } - - static int ss_get_sub_device_sessions_func(out IntList? sessions, char[] name, void* user_data) { - Store store = (Store) user_data; - try { - sessions = store.session_store.get_sub_device_sessions(carr_to_string(name)); - } catch (Error e) { - sessions = null; - return e.code; - } - return 0; - } - - static int ss_store_session_func(Address address, uint8[] record, uint8[] user_record, void* user_data) { - // Ignoring user_record - Store store = (Store) user_data; - return catch_to_code(() => { - store.session_store.store_session(address, record); - return 0; - }); - } - - static int ss_contains_session_func(Address address, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - return store.session_store.contains_session(address) ? 1 : 0; - }); - } - - static int ss_delete_session_func(Address address, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - store.session_store.delete_session(address); - return 0; - }); - } - - static int ss_delete_all_sessions_func(char[] name, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - store.session_store.delete_all_sessions(carr_to_string(name)); - return 0; - }); - } - - static void ss_destroy_func(void* user_data) { - } - - static int pks_load_pre_key(out Buffer? record, uint32 pre_key_id, void* user_data) { - Store store = (Store) user_data; - uint8[]? res = null; - try { - res = store.pre_key_store.load_pre_key(pre_key_id); - } catch (Error e) { - record = null; - return e.code; - } - if (res == null) { - record = new Buffer(0); - return 0; - } - record = new Buffer.from((!)res); - if (record == null) return ErrorCode.NOMEM; - return 1; - } - - static int pks_store_pre_key(uint32 pre_key_id, uint8[] record, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - store.pre_key_store.store_pre_key(pre_key_id, record); - return 0; - }); - } - - static int pks_contains_pre_key(uint32 pre_key_id, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - return store.pre_key_store.contains_pre_key(pre_key_id) ? 1 : 0; - }); - } - - static int pks_remove_pre_key(uint32 pre_key_id, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - store.pre_key_store.delete_pre_key(pre_key_id); - return 0; - }); - } - - static void pks_destroy_func(void* user_data) { - } - - static int spks_load_signed_pre_key(out Buffer? record, uint32 pre_key_id, void* user_data) { - Store store = (Store) user_data; - uint8[]? res = null; - try { - res = store.signed_pre_key_store.load_signed_pre_key(pre_key_id); - } catch (Error e) { - record = null; - return e.code; - } - if (res == null) { - record = new Buffer(0); - return 0; - } - record = new Buffer.from((!)res); - if (record == null) return ErrorCode.NOMEM; - return 1; - } - - static int spks_store_signed_pre_key(uint32 pre_key_id, uint8[] record, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - store.signed_pre_key_store.store_signed_pre_key(pre_key_id, record); - return 0; - }); - } - - static int spks_contains_signed_pre_key(uint32 pre_key_id, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - return store.signed_pre_key_store.contains_signed_pre_key(pre_key_id) ? 1 : 0; - }); - } - - static int spks_remove_signed_pre_key(uint32 pre_key_id, void* user_data) { - Store store = (Store) user_data; - return catch_to_code(() => { - store.signed_pre_key_store.delete_signed_pre_key(pre_key_id); - return 0; - }); - } - - static void spks_destroy_func(void* user_data) { - } - - internal Store(Context context) { - this.context = context; - NativeStoreContext.create(out native_store_context_, context.native_context); - - NativeIdentityKeyStore iks = NativeIdentityKeyStore() { - get_identity_key_pair = iks_get_identity_key_pair, - get_local_registration_id = iks_get_local_registration_id, - save_identity = iks_save_identity, - is_trusted_identity = iks_is_trusted_identity, - destroy_func = iks_destroy_func, - user_data = this - }; - native_context.set_identity_key_store(iks); - - NativeSessionStore ss = NativeSessionStore() { - load_session_func = ss_load_session_func, - get_sub_device_sessions_func = ss_get_sub_device_sessions_func, - store_session_func = ss_store_session_func, - contains_session_func = ss_contains_session_func, - delete_session_func = ss_delete_session_func, - delete_all_sessions_func = ss_delete_all_sessions_func, - destroy_func = ss_destroy_func, - user_data = this - }; - native_context.set_session_store(ss); - - NativePreKeyStore pks = NativePreKeyStore() { - load_pre_key = pks_load_pre_key, - store_pre_key = pks_store_pre_key, - contains_pre_key = pks_contains_pre_key, - remove_pre_key = pks_remove_pre_key, - destroy_func = pks_destroy_func, - user_data = this - }; - native_context.set_pre_key_store(pks); - - NativeSignedPreKeyStore spks = NativeSignedPreKeyStore() { - load_signed_pre_key = spks_load_signed_pre_key, - store_signed_pre_key = spks_store_signed_pre_key, - contains_signed_pre_key = spks_contains_signed_pre_key, - remove_signed_pre_key = spks_remove_signed_pre_key, - destroy_func = spks_destroy_func, - user_data = this - }; - native_context.set_signed_pre_key_store(spks); - } - - public SessionBuilder create_session_builder(Address other) throws Error { - SessionBuilder builder; - throw_by_code(session_builder_create(out builder, native_context, other, context.native_context), "Error creating session builder"); - return builder; - } - - public SessionCipher create_session_cipher(Address other) throws Error { - SessionCipher cipher; - throw_by_code(session_cipher_create(out cipher, native_context, other, context.native_context)); - return cipher; - } - - public IdentityKeyPair identity_key_pair { - owned get { - IdentityKeyPair pair; - Protocol.Identity.get_key_pair(native_context, out pair); - return pair; - } - } - - public bool is_trusted_identity(Address address, ECPublicKey key) throws Error { - return throw_by_code(Protocol.Identity.is_trusted_identity(native_context, address, key)) == 1; - } - - public void save_identity(Address address, ECPublicKey key) throws Error { - throw_by_code(Protocol.Identity.save_identity(native_context, address, key)); - } - - public bool contains_session(Address other) throws Error { - return throw_by_code(Protocol.Session.contains_session(native_context, other)) == 1; - } - - public void delete_session(Address address) throws Error { - throw_by_code(Protocol.Session.delete_session(native_context, address)); - } - - public SessionRecord load_session(Address other) throws Error { - SessionRecord record; - throw_by_code(Protocol.Session.load_session(native_context, out record, other)); - return record; - } - - public bool contains_pre_key(uint32 pre_key_id) throws Error { - return throw_by_code(Protocol.PreKey.contains_key(native_context, pre_key_id)) == 1; - } - - public void store_pre_key(PreKeyRecord record) throws Error { - throw_by_code(Protocol.PreKey.store_key(native_context, record)); - } - - public PreKeyRecord load_pre_key(uint32 pre_key_id) throws Error { - PreKeyRecord res; - throw_by_code(Protocol.PreKey.load_key(native_context, out res, pre_key_id)); - return res; - } - - public bool contains_signed_pre_key(uint32 pre_key_id) throws Error { - return throw_by_code(Protocol.SignedPreKey.contains_key(native_context, pre_key_id)) == 1; - } - - public void store_signed_pre_key(SignedPreKeyRecord record) throws Error { - throw_by_code(Protocol.SignedPreKey.store_key(native_context, record)); - } - - public SignedPreKeyRecord load_signed_pre_key(uint32 pre_key_id) throws Error { - SignedPreKeyRecord res; - throw_by_code(Protocol.SignedPreKey.load_key(native_context, out res, pre_key_id)); - return res; - } -} - -} diff --git a/plugins/signal-protocol/src/util.vala b/plugins/signal-protocol/src/util.vala deleted file mode 100644 index 4c0ae72d..00000000 --- a/plugins/signal-protocol/src/util.vala +++ /dev/null @@ -1,45 +0,0 @@ -namespace Signal { - -public ECPublicKey generate_public_key(ECPrivateKey private_key) throws Error { - ECPublicKey public_key; - throw_by_code(ECPublicKey.generate(out public_key, private_key), "Error generating public key"); - - return public_key; -} - -public uint8[] calculate_agreement(ECPublicKey public_key, ECPrivateKey private_key) throws Error { - uint8[] res; - int len = Curve.calculate_agreement(out res, public_key, private_key); - throw_by_code(len, "Error calculating agreement"); - res.length = len; - return res; -} - -public bool verify_signature(ECPublicKey signing_key, uint8[] message, uint8[] signature) throws Error { - return throw_by_code(Curve.verify_signature(signing_key, message, signature)) == 1; -} - -public PreKeyBundle create_pre_key_bundle(uint32 registration_id, int device_id, uint32 pre_key_id, ECPublicKey? pre_key_public, - uint32 signed_pre_key_id, ECPublicKey? signed_pre_key_public, uint8[]? signed_pre_key_signature, ECPublicKey? identity_key) throws Error { - PreKeyBundle res; - throw_by_code(PreKeyBundle.create(out res, registration_id, device_id, pre_key_id, pre_key_public, signed_pre_key_id, signed_pre_key_public, signed_pre_key_signature, identity_key), "Error creating PreKeyBundle"); - return res; -} - -internal string carr_to_string(char[] carr) { - char[] nu = new char[carr.length + 1]; - Memory.copy(nu, carr, carr.length); - return (string) nu; -} - -internal delegate int CodeErroringFunc() throws Error; - -internal int catch_to_code(CodeErroringFunc func) { - try { - return func(); - } catch (Error e) { - return e.code; - } -} - -} \ No newline at end of file diff --git a/plugins/signal-protocol/tests/common.vala b/plugins/signal-protocol/tests/common.vala deleted file mode 100644 index 9bb9b1dc..00000000 --- a/plugins/signal-protocol/tests/common.vala +++ /dev/null @@ -1,92 +0,0 @@ -namespace Signal.Test { - -int main(string[] args) { - GLib.Test.init(ref args); - GLib.Test.set_nonfatal_assertions(); - TestSuite.get_root().add_suite(new Curve25519().get_suite()); - TestSuite.get_root().add_suite(new SessionBuilderTest().get_suite()); - TestSuite.get_root().add_suite(new HKDF().get_suite()); - return GLib.Test.run(); -} - -Store setup_test_store_context(Context global_context) { - Store store = global_context.create_store(); - try { - store.identity_key_store.local_registration_id = (Random.next_int() % 16380) + 1; - - ECKeyPair key_pair = global_context.generate_key_pair(); - store.identity_key_store.identity_key_private = new Bytes(key_pair.private.serialize()); - store.identity_key_store.identity_key_public = new Bytes(key_pair.public.serialize()); - } catch (Error e) { - fail_if_reached(); - } - return store; -} - -ECPublicKey? create_test_ec_public_key(Context context) { - try { - return context.generate_key_pair().public; - } catch (Error e) { - fail_if_reached(); - return null; - } -} - -bool fail_if(bool exp, string? reason = null) { - if (exp) { - if (reason != null) GLib.Test.message(reason); - GLib.Test.fail(); - return true; - } - return false; -} - -void fail_if_reached(string? reason = null) { - fail_if(true, reason); -} - -delegate void ErrorFunc() throws Error; - -void fail_if_not_error_code(ErrorFunc func, int expectedCode, string? reason = null) { - try { - func(); - fail_if_reached(@"$(reason + ": " ?? "")no error thrown"); - } catch (Error e) { - fail_if_not_eq_int(e.code, expectedCode, @"$(reason + ": " ?? "")caught unexpected error"); - } -} - -bool fail_if_not(bool exp, string? reason = null) { - return fail_if(!exp, reason); -} - -bool fail_if_eq_int(int left, int right, string? reason = null) { - return fail_if(left == right, @"$(reason + ": " ?? "")$left == $right"); -} - -bool fail_if_not_eq_int(int left, int right, string? reason = null) { - return fail_if_not(left == right, @"$(reason + ": " ?? "")$left != $right"); -} - -bool fail_if_not_eq_str(string left, string right, string? reason = null) { - return fail_if_not(left == right, @"$(reason + ": " ?? "")$left != $right"); -} - -bool fail_if_not_eq_uint8_arr(uint8[] left, uint8[] right, string? reason = null) { - if (fail_if_not_eq_int(left.length, right.length, @"$(reason + ": " ?? "")array length not equal")) return true; - return fail_if_not_eq_str(Base64.encode(left), Base64.encode(right), reason); -} - -bool fail_if_not_zero_int(int zero, string? reason = null) { - return fail_if_not_eq_int(zero, 0, reason); -} - -bool fail_if_zero_int(int zero, string? reason = null) { - return fail_if_eq_int(zero, 0, reason); -} - -bool fail_if_null(void* what, string? reason = null) { - return fail_if(what == null || (size_t)what == 0, reason); -} - -} diff --git a/plugins/signal-protocol/tests/curve25519.vala b/plugins/signal-protocol/tests/curve25519.vala deleted file mode 100644 index 6dfae62f..00000000 --- a/plugins/signal-protocol/tests/curve25519.vala +++ /dev/null @@ -1,207 +0,0 @@ -namespace Signal.Test { - -class Curve25519 : Gee.TestCase { - - public Curve25519() { - base("Curve25519"); - add_test("agreement", test_curve25519_agreement); - add_test("generate_public", test_curve25519_generate_public); - add_test("random_agreements", test_curve25519_random_agreements); - add_test("signature", test_curve25519_signature); - } - - private Context global_context; - - public override void set_up() { - try { - global_context = new Context(); - } catch (Error e) { - fail_if_reached(); - } - } - - public override void tear_down() { - global_context = null; - } - - void test_curve25519_agreement() { - try { - uint8[] alicePublic = { - 0x05, 0x1b, 0xb7, 0x59, 0x66, - 0xf2, 0xe9, 0x3a, 0x36, 0x91, - 0xdf, 0xff, 0x94, 0x2b, 0xb2, - 0xa4, 0x66, 0xa1, 0xc0, 0x8b, - 0x8d, 0x78, 0xca, 0x3f, 0x4d, - 0x6d, 0xf8, 0xb8, 0xbf, 0xa2, - 0xe4, 0xee, 0x28}; - - uint8[] alicePrivate = { - 0xc8, 0x06, 0x43, 0x9d, 0xc9, - 0xd2, 0xc4, 0x76, 0xff, 0xed, - 0x8f, 0x25, 0x80, 0xc0, 0x88, - 0x8d, 0x58, 0xab, 0x40, 0x6b, - 0xf7, 0xae, 0x36, 0x98, 0x87, - 0x90, 0x21, 0xb9, 0x6b, 0xb4, - 0xbf, 0x59}; - - uint8[] bobPublic = { - 0x05, 0x65, 0x36, 0x14, 0x99, - 0x3d, 0x2b, 0x15, 0xee, 0x9e, - 0x5f, 0xd3, 0xd8, 0x6c, 0xe7, - 0x19, 0xef, 0x4e, 0xc1, 0xda, - 0xae, 0x18, 0x86, 0xa8, 0x7b, - 0x3f, 0x5f, 0xa9, 0x56, 0x5a, - 0x27, 0xa2, 0x2f}; - - uint8[] bobPrivate = { - 0xb0, 0x3b, 0x34, 0xc3, 0x3a, - 0x1c, 0x44, 0xf2, 0x25, 0xb6, - 0x62, 0xd2, 0xbf, 0x48, 0x59, - 0xb8, 0x13, 0x54, 0x11, 0xfa, - 0x7b, 0x03, 0x86, 0xd4, 0x5f, - 0xb7, 0x5d, 0xc5, 0xb9, 0x1b, - 0x44, 0x66}; - - uint8[] shared = { - 0x32, 0x5f, 0x23, 0x93, 0x28, - 0x94, 0x1c, 0xed, 0x6e, 0x67, - 0x3b, 0x86, 0xba, 0x41, 0x01, - 0x74, 0x48, 0xe9, 0x9b, 0x64, - 0x9a, 0x9c, 0x38, 0x06, 0xc1, - 0xdd, 0x7c, 0xa4, 0xc4, 0x77, - 0xe6, 0x29}; - - ECPublicKey alice_public_key = global_context.decode_public_key(alicePublic); - ECPrivateKey alice_private_key = global_context.decode_private_key(alicePrivate); - ECPublicKey bob_public_key = global_context.decode_public_key(bobPublic); - ECPrivateKey bob_private_key = global_context.decode_private_key(bobPrivate); - - uint8[] shared_one = calculate_agreement(alice_public_key, bob_private_key); - uint8[] shared_two = calculate_agreement(bob_public_key, alice_private_key); - - fail_if_not_eq_int(shared_one.length, 32); - fail_if_not_eq_int(shared_two.length, 32); - fail_if_not_eq_uint8_arr(shared, shared_one); - fail_if_not_eq_uint8_arr(shared_one, shared_two); - } catch (Error e) { - fail_if_reached(); - } - } - - void test_curve25519_generate_public() { - try { - uint8[] alicePublic = { - 0x05, 0x1b, 0xb7, 0x59, 0x66, - 0xf2, 0xe9, 0x3a, 0x36, 0x91, - 0xdf, 0xff, 0x94, 0x2b, 0xb2, - 0xa4, 0x66, 0xa1, 0xc0, 0x8b, - 0x8d, 0x78, 0xca, 0x3f, 0x4d, - 0x6d, 0xf8, 0xb8, 0xbf, 0xa2, - 0xe4, 0xee, 0x28}; - - uint8[] alicePrivate = { - 0xc8, 0x06, 0x43, 0x9d, 0xc9, - 0xd2, 0xc4, 0x76, 0xff, 0xed, - 0x8f, 0x25, 0x80, 0xc0, 0x88, - 0x8d, 0x58, 0xab, 0x40, 0x6b, - 0xf7, 0xae, 0x36, 0x98, 0x87, - 0x90, 0x21, 0xb9, 0x6b, 0xb4, - 0xbf, 0x59}; - - ECPrivateKey alice_private_key = global_context.decode_private_key(alicePrivate); - ECPublicKey alice_expected_public_key = global_context.decode_public_key(alicePublic); - ECPublicKey alice_public_key = generate_public_key(alice_private_key); - - fail_if_not_zero_int(alice_expected_public_key.compare(alice_public_key)); - } catch (Error e) { - fail_if_reached(); - } - } - - void test_curve25519_random_agreements() { - try { - ECKeyPair alice_key_pair = null; - ECPublicKey alice_public_key = null; - ECPrivateKey alice_private_key = null; - ECKeyPair bob_key_pair = null; - ECPublicKey bob_public_key = null; - ECPrivateKey bob_private_key = null; - uint8[] shared_alice = null; - uint8[] shared_bob = null; - - for (int i = 0; i < 50; i++) { - fail_if_null(alice_key_pair = global_context.generate_key_pair()); - fail_if_null(alice_public_key = alice_key_pair.public); - fail_if_null(alice_private_key = alice_key_pair.private); - - fail_if_null(bob_key_pair = global_context.generate_key_pair()); - fail_if_null(bob_public_key = bob_key_pair.public); - fail_if_null(bob_private_key = bob_key_pair.private); - - shared_alice = calculate_agreement(bob_public_key, alice_private_key); - fail_if_not_eq_int(shared_alice.length, 32); - - shared_bob = calculate_agreement(alice_public_key, bob_private_key); - fail_if_not_eq_int(shared_bob.length, 32); - - fail_if_not_eq_uint8_arr(shared_alice, shared_bob); - } - } catch (Error e) { - fail_if_reached(); - } - } - - void test_curve25519_signature() { - try { - uint8[] aliceIdentityPrivate = { - 0xc0, 0x97, 0x24, 0x84, 0x12, 0xe5, 0x8b, 0xf0, - 0x5d, 0xf4, 0x87, 0x96, 0x82, 0x05, 0x13, 0x27, - 0x94, 0x17, 0x8e, 0x36, 0x76, 0x37, 0xf5, 0x81, - 0x8f, 0x81, 0xe0, 0xe6, 0xce, 0x73, 0xe8, 0x65}; - - uint8[] aliceIdentityPublic = { - 0x05, 0xab, 0x7e, 0x71, 0x7d, 0x4a, 0x16, 0x3b, - 0x7d, 0x9a, 0x1d, 0x80, 0x71, 0xdf, 0xe9, 0xdc, - 0xf8, 0xcd, 0xcd, 0x1c, 0xea, 0x33, 0x39, 0xb6, - 0x35, 0x6b, 0xe8, 0x4d, 0x88, 0x7e, 0x32, 0x2c, - 0x64}; - - uint8[] aliceEphemeralPublic = { - 0x05, 0xed, 0xce, 0x9d, 0x9c, 0x41, 0x5c, 0xa7, - 0x8c, 0xb7, 0x25, 0x2e, 0x72, 0xc2, 0xc4, 0xa5, - 0x54, 0xd3, 0xeb, 0x29, 0x48, 0x5a, 0x0e, 0x1d, - 0x50, 0x31, 0x18, 0xd1, 0xa8, 0x2d, 0x99, 0xfb, - 0x4a}; - - uint8[] aliceSignature = { - 0x5d, 0xe8, 0x8c, 0xa9, 0xa8, 0x9b, 0x4a, 0x11, - 0x5d, 0xa7, 0x91, 0x09, 0xc6, 0x7c, 0x9c, 0x74, - 0x64, 0xa3, 0xe4, 0x18, 0x02, 0x74, 0xf1, 0xcb, - 0x8c, 0x63, 0xc2, 0x98, 0x4e, 0x28, 0x6d, 0xfb, - 0xed, 0xe8, 0x2d, 0xeb, 0x9d, 0xcd, 0x9f, 0xae, - 0x0b, 0xfb, 0xb8, 0x21, 0x56, 0x9b, 0x3d, 0x90, - 0x01, 0xbd, 0x81, 0x30, 0xcd, 0x11, 0xd4, 0x86, - 0xce, 0xf0, 0x47, 0xbd, 0x60, 0xb8, 0x6e, 0x88}; - - global_context.decode_private_key(aliceIdentityPrivate); - global_context.decode_public_key(aliceEphemeralPublic); - ECPublicKey alice_public_key = global_context.decode_public_key(aliceIdentityPublic); - - fail_if(!verify_signature(alice_public_key, aliceEphemeralPublic, aliceSignature), "signature verification failed"); - - uint8[] modifiedSignature = new uint8[aliceSignature.length]; - - for (int i = 0; i < aliceSignature.length; i++) { - Memory.copy(modifiedSignature, aliceSignature, aliceSignature.length); - modifiedSignature[i] ^= 0x01; - - fail_if(verify_signature(alice_public_key, aliceEphemeralPublic, modifiedSignature), "invalid signature verification succeeded"); - } - } catch (Error e) { - fail_if_reached(); - } - } - -} - -} \ No newline at end of file diff --git a/plugins/signal-protocol/tests/hkdf.vala b/plugins/signal-protocol/tests/hkdf.vala deleted file mode 100644 index c30af275..00000000 --- a/plugins/signal-protocol/tests/hkdf.vala +++ /dev/null @@ -1,59 +0,0 @@ -namespace Signal.Test { - -class HKDF : Gee.TestCase { - - public HKDF() { - base("HKDF"); - add_test("vector_v3", test_hkdf_vector_v3); - } - - private Context global_context; - - public override void set_up() { - try { - global_context = new Context(); - } catch (Error e) { - fail_if_reached(); - } - } - - public override void tear_down() { - global_context = null; - } - - public void test_hkdf_vector_v3() { - uint8[] ikm = { - 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, - 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, - 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}; - - uint8[] salt = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c}; - - uint8[] info = { - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9}; - - uint8[] okm = { - 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, - 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, - 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c, - 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, - 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, - 0x58, 0x65}; - - NativeHkdfContext context = null; - fail_if_not_zero_int(NativeHkdfContext.create(out context, 3, global_context.native_context)); - - uint8[] output = null; - int result = (int) context.derive_secrets(out output, ikm, salt, info, 42); - fail_if_not_eq_int(result, okm.length); - output.length = result; - - fail_if_not_eq_uint8_arr(output, okm); - } - -} - -} \ No newline at end of file diff --git a/plugins/signal-protocol/tests/session_builder.vala b/plugins/signal-protocol/tests/session_builder.vala deleted file mode 100644 index 7e2448e1..00000000 --- a/plugins/signal-protocol/tests/session_builder.vala +++ /dev/null @@ -1,400 +0,0 @@ -namespace Signal.Test { - -class SessionBuilderTest : Gee.TestCase { - Address alice_address; - Address bob_address; - - public SessionBuilderTest() { - base("SessionBuilder"); - - add_test("basic_pre_key_v2", test_basic_pre_key_v2); - add_test("basic_pre_key_v3", test_basic_pre_key_v3); - add_test("bad_signed_pre_key_signature", test_bad_signed_pre_key_signature); - add_test("repeat_bundle_message_v2", test_repeat_bundle_message_v2); - } - - private Context global_context; - - public override void set_up() { - try { - global_context = new Context(); - alice_address = new Address("+14151111111", 1); - bob_address = new Address("+14152222222", 1); - } catch (Error e) { - fail_if_reached(@"Unexpected error: $(e.message)"); - } - } - - public override void tear_down() { - global_context = null; - alice_address = null; - bob_address = null; - } - - void test_basic_pre_key_v2() { - try { - /* Create Alice's data store and session builder */ - Store alice_store = setup_test_store_context(global_context); - SessionBuilder alice_session_builder = alice_store.create_session_builder(bob_address); - - /* Create Bob's data store and pre key bundle */ - Store bob_store = setup_test_store_context(global_context); - uint32 bob_local_registration_id = bob_store.local_registration_id; - IdentityKeyPair bob_identity_key_pair = bob_store.identity_key_pair; - ECKeyPair bob_pre_key_pair = global_context.generate_key_pair(); - - PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_local_registration_id, 1, 31337, bob_pre_key_pair.public, 0, null, null, bob_identity_key_pair.public); - - /* - * Have Alice process Bob's pre key bundle, which should fail due to a - * missing unsigned pre key. - */ - fail_if_not_error_code(() => alice_session_builder.process_pre_key_bundle(bob_pre_key), ErrorCode.INVALID_KEY); - } catch(Error e) { - fail_if_reached(@"Unexpected error: $(e.message)"); - } - } - - void test_basic_pre_key_v3() { - try { - /* Create Alice's data store and session builder */ - Store alice_store = setup_test_store_context(global_context); - SessionBuilder alice_session_builder = alice_store.create_session_builder(bob_address); - - /* Create Bob's data store and pre key bundle */ - Store bob_store = setup_test_store_context(global_context); - uint32 bob_local_registration_id = bob_store.local_registration_id; - ECKeyPair bob_pre_key_pair = global_context.generate_key_pair(); - ECKeyPair bob_signed_pre_key_pair = global_context.generate_key_pair(); - IdentityKeyPair bob_identity_key_pair = bob_store.identity_key_pair; - - uint8[] bob_signed_pre_key_signature = global_context.calculate_signature(bob_identity_key_pair.private, bob_signed_pre_key_pair.public.serialize()); - - PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_local_registration_id, 1, 31337, bob_pre_key_pair.public, 22, bob_signed_pre_key_pair.public, bob_signed_pre_key_signature, bob_identity_key_pair.public); - - /* Have Alice process Bob's pre key bundle */ - alice_session_builder.process_pre_key_bundle(bob_pre_key); - - /* Check that we can load the session state and verify its version */ - fail_if_not(alice_store.contains_session(bob_address)); - - SessionRecord loaded_record = alice_store.load_session(bob_address); - fail_if_not_eq_int((int)loaded_record.state.session_version, 3); - - /* Encrypt an outgoing message to send to Bob */ - string original_message = "L'homme est condamné à être libre"; - SessionCipher alice_session_cipher = alice_store.create_session_cipher(bob_address); - - CiphertextMessage outgoing_message = alice_session_cipher.encrypt(original_message.data); - fail_if_not_eq_int(outgoing_message.type, CiphertextType.PREKEY); - - /* Convert to an incoming message for Bob */ - PreKeySignalMessage incoming_message = global_context.deserialize_pre_key_signal_message(outgoing_message.serialized); - - /* Save the pre key and signed pre key in Bob's data store */ - PreKeyRecord bob_pre_key_record; - throw_by_code(PreKeyRecord.create(out bob_pre_key_record, bob_pre_key.pre_key_id, bob_pre_key_pair)); - bob_store.store_pre_key(bob_pre_key_record); - - SignedPreKeyRecord bob_signed_pre_key_record; - throw_by_code(SignedPreKeyRecord.create(out bob_signed_pre_key_record, 22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature)); - bob_store.store_signed_pre_key(bob_signed_pre_key_record); - - /* Create Bob's session cipher and decrypt the message from Alice */ - SessionCipher bob_session_cipher = bob_store.create_session_cipher(alice_address); - - /* Prepare the data for the callback test */ - //int callback_context = 1234; - //bob_session_cipher.user_data = - //bob_session_cipher.decryption_callback = - uint8[] plaintext = bob_session_cipher.decrypt_pre_key_signal_message(incoming_message); - - /* Clean up callback data */ - bob_session_cipher.user_data = null; - bob_session_cipher.decryption_callback = null; - - /* Verify Bob's session state and the decrypted message */ - fail_if_not(bob_store.contains_session(alice_address)); - - SessionRecord alice_recipient_session_record = bob_store.load_session(alice_address); - - SessionState alice_recipient_session_state = alice_recipient_session_record.state; - fail_if_not_eq_int((int)alice_recipient_session_state.session_version, 3); - fail_if_null(alice_recipient_session_state.alice_base_key); - - fail_if_not_eq_uint8_arr(original_message.data, plaintext); - - /* Have Bob send a reply to Alice */ - CiphertextMessage bob_outgoing_message = bob_session_cipher.encrypt(original_message.data); - fail_if_not_eq_int(bob_outgoing_message.type, CiphertextType.SIGNAL); - - /* Verify that Alice can decrypt it */ - SignalMessage bob_outgoing_message_copy = global_context.copy_signal_message(bob_outgoing_message); - - uint8[] alice_plaintext = alice_session_cipher.decrypt_signal_message(bob_outgoing_message_copy); - - fail_if_not_eq_uint8_arr(original_message.data, alice_plaintext); - - GLib.Test.message("Pre-interaction tests complete"); - - /* Interaction tests */ - run_interaction(alice_store, bob_store); - - /* Cleanup state from previous tests that we need to replace */ - alice_store = null; - bob_pre_key_pair = null; - bob_signed_pre_key_pair = null; - bob_identity_key_pair = null; - bob_signed_pre_key_signature = null; - bob_pre_key_record = null; - bob_signed_pre_key_record = null; - - /* Create Alice's new session data */ - alice_store = setup_test_store_context(global_context); - alice_session_builder = alice_store.create_session_builder(bob_address); - alice_session_cipher = alice_store.create_session_cipher(bob_address); - - /* Create Bob's new pre key bundle */ - bob_pre_key_pair = global_context.generate_key_pair(); - bob_signed_pre_key_pair = global_context.generate_key_pair(); - bob_identity_key_pair = bob_store.identity_key_pair; - bob_signed_pre_key_signature = global_context.calculate_signature(bob_identity_key_pair.private, bob_signed_pre_key_pair.public.serialize()); - bob_pre_key = create_pre_key_bundle(bob_local_registration_id, 1, 31338, bob_pre_key_pair.public, 23, bob_signed_pre_key_pair.public, bob_signed_pre_key_signature, bob_identity_key_pair.public); - - /* Save the new pre key and signed pre key in Bob's data store */ - throw_by_code(PreKeyRecord.create(out bob_pre_key_record, bob_pre_key.pre_key_id, bob_pre_key_pair)); - bob_store.store_pre_key(bob_pre_key_record); - - throw_by_code(SignedPreKeyRecord.create(out bob_signed_pre_key_record, 23, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature)); - bob_store.store_signed_pre_key(bob_signed_pre_key_record); - - /* Have Alice process Bob's pre key bundle */ - alice_session_builder.process_pre_key_bundle(bob_pre_key); - - /* Have Alice encrypt a message for Bob */ - outgoing_message = alice_session_cipher.encrypt(original_message.data); - fail_if_not_eq_int(outgoing_message.type, CiphertextType.PREKEY); - - /* Have Bob try to decrypt the message */ - PreKeySignalMessage outgoing_message_copy = global_context.copy_pre_key_signal_message(outgoing_message); - - /* The decrypt should fail with a specific error */ - fail_if_not_error_code(() => bob_session_cipher.decrypt_pre_key_signal_message(outgoing_message_copy), ErrorCode.UNTRUSTED_IDENTITY); - - outgoing_message_copy = global_context.copy_pre_key_signal_message(outgoing_message); - - /* Save the identity key to Bob's store */ - bob_store.save_identity(alice_address, outgoing_message_copy.identity_key); - - /* Try the decrypt again, this time it should succeed */ - outgoing_message_copy = global_context.copy_pre_key_signal_message(outgoing_message); - plaintext = bob_session_cipher.decrypt_pre_key_signal_message(outgoing_message_copy); - - fail_if_not_eq_uint8_arr(original_message.data, plaintext); - - /* Create a new pre key for Bob */ - ECPublicKey test_public_key = create_test_ec_public_key(global_context); - - IdentityKeyPair alice_identity_key_pair = alice_store.identity_key_pair; - - bob_pre_key = create_pre_key_bundle(bob_local_registration_id, 1, 31337, test_public_key, 23, bob_signed_pre_key_pair.public, bob_signed_pre_key_signature, alice_identity_key_pair.public); - - /* Have Alice process Bob's new pre key bundle, which should fail */ - fail_if_not_error_code(() => alice_session_builder.process_pre_key_bundle(bob_pre_key), ErrorCode.UNTRUSTED_IDENTITY); - - GLib.Test.message("Post-interaction tests complete"); - } catch(Error e) { - fail_if_reached(@"Unexpected error: $(e.message)"); - } - } - - void test_bad_signed_pre_key_signature() { - try { - /* Create Alice's data store and session builder */ - Store alice_store = setup_test_store_context(global_context); - SessionBuilder alice_session_builder = alice_store.create_session_builder(bob_address); - - /* Create Bob's data store */ - Store bob_store = setup_test_store_context(global_context); - - /* Create Bob's regular and signed pre key pairs */ - ECKeyPair bob_pre_key_pair = global_context.generate_key_pair(); - ECKeyPair bob_signed_pre_key_pair = global_context.generate_key_pair(); - - /* Create Bob's signed pre key signature */ - IdentityKeyPair bob_identity_key_pair = bob_store.identity_key_pair; - uint8[] bob_signed_pre_key_signature = global_context.calculate_signature(bob_identity_key_pair.private, bob_signed_pre_key_pair.public.serialize()); - - for (int i = 0; i < bob_signed_pre_key_signature.length * 8; i++) { - uint8[] modified_signature = bob_signed_pre_key_signature[0:bob_signed_pre_key_signature.length]; - - /* Intentionally corrupt the signature data */ - modified_signature[i/8] ^= (1 << ((uint8)i % 8)); - - /* Create a pre key bundle */ - PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_store.local_registration_id,1,31137,bob_pre_key_pair.public,22,bob_signed_pre_key_pair.public,modified_signature,bob_identity_key_pair.public); - - /* Process the bundle and make sure we fail with an invalid key error */ - fail_if_not_error_code(() => alice_session_builder.process_pre_key_bundle(bob_pre_key), ErrorCode.INVALID_KEY); - } - - /* Create a correct pre key bundle */ - PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_store.local_registration_id,1,31137,bob_pre_key_pair.public,22,bob_signed_pre_key_pair.public,bob_signed_pre_key_signature,bob_identity_key_pair.public); - - /* Process the bundle and make sure we do not fail */ - alice_session_builder.process_pre_key_bundle(bob_pre_key); - } catch(Error e) { - fail_if_reached(@"Unexpected error: $(e.message)"); - } - } - - void test_repeat_bundle_message_v2() { - try { - /* Create Alice's data store and session builder */ - Store alice_store = setup_test_store_context(global_context); - SessionBuilder alice_session_builder = alice_store.create_session_builder(bob_address); - - /* Create Bob's data store and pre key bundle */ - Store bob_store = setup_test_store_context(global_context); - ECKeyPair bob_pre_key_pair = global_context.generate_key_pair(); - ECKeyPair bob_signed_pre_key_pair = global_context.generate_key_pair(); - uint8[] bob_signed_pre_key_signature = global_context.calculate_signature(bob_store.identity_key_pair.private, bob_signed_pre_key_pair.public.serialize()); - PreKeyBundle bob_pre_key = create_pre_key_bundle(bob_store.local_registration_id,1,31337,bob_pre_key_pair.public,0,null,null,bob_store.identity_key_pair.public); - - /* Add Bob's pre keys to Bob's data store */ - PreKeyRecord bob_pre_key_record; - throw_by_code(PreKeyRecord.create(out bob_pre_key_record, bob_pre_key.pre_key_id, bob_pre_key_pair)); - bob_store.store_pre_key(bob_pre_key_record); - SignedPreKeyRecord bob_signed_pre_key_record; - throw_by_code(SignedPreKeyRecord.create(out bob_signed_pre_key_record, 22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature)); - bob_store.store_signed_pre_key(bob_signed_pre_key_record); - - /* - * Have Alice process Bob's pre key bundle, which should fail due to a - * missing signed pre key. - */ - fail_if_not_error_code(() => alice_session_builder.process_pre_key_bundle(bob_pre_key), ErrorCode.INVALID_KEY); - } catch(Error e) { - fail_if_reached(@"Unexpected error: $(e.message)"); - } - } - - class Holder { - public uint8[] data { get; private set; } - - public Holder(uint8[] data) { - this.data = data; - } - } - - void run_interaction(Store alice_store, Store bob_store) throws Error { - - /* Create the session ciphers */ - SessionCipher alice_session_cipher = alice_store.create_session_cipher(bob_address); - SessionCipher bob_session_cipher = bob_store.create_session_cipher(alice_address); - - /* Create a test message */ - string original_message = "smert ze smert"; - - /* Simulate Alice sending a message to Bob */ - CiphertextMessage alice_message = alice_session_cipher.encrypt(original_message.data); - fail_if_not_eq_int(alice_message.type, CiphertextType.SIGNAL); - - SignalMessage alice_message_copy = global_context.copy_signal_message(alice_message); - uint8[] plaintext = bob_session_cipher.decrypt_signal_message(alice_message_copy); - fail_if_not_eq_uint8_arr(original_message.data, plaintext); - - GLib.Test.message("Interaction complete: Alice -> Bob"); - - /* Simulate Bob sending a message to Alice */ - CiphertextMessage bob_message = bob_session_cipher.encrypt(original_message.data); - fail_if_not_eq_int(alice_message.type, CiphertextType.SIGNAL); - - SignalMessage bob_message_copy = global_context.copy_signal_message(bob_message); - plaintext = alice_session_cipher.decrypt_signal_message(bob_message_copy); - fail_if_not_eq_uint8_arr(original_message.data, plaintext); - - GLib.Test.message("Interaction complete: Bob -> Alice"); - - /* Looping Alice -> Bob */ - for (int i = 0; i < 10; i++) { - uint8[] looping_message = create_looping_message(i); - CiphertextMessage alice_looping_message = alice_session_cipher.encrypt(looping_message); - SignalMessage alice_looping_message_copy = global_context.copy_signal_message(alice_looping_message); - uint8[] looping_plaintext = bob_session_cipher.decrypt_signal_message(alice_looping_message_copy); - fail_if_not_eq_uint8_arr(looping_message, looping_plaintext); - } - GLib.Test.message("Interaction complete: Alice -> Bob (looping)"); - - /* Looping Bob -> Alice */ - for (int i = 0; i < 10; i++) { - uint8[] looping_message = create_looping_message(i); - CiphertextMessage bob_looping_message = bob_session_cipher.encrypt(looping_message); - SignalMessage bob_looping_message_copy = global_context.copy_signal_message(bob_looping_message); - uint8[] looping_plaintext = alice_session_cipher.decrypt_signal_message(bob_looping_message_copy); - fail_if_not_eq_uint8_arr(looping_message, looping_plaintext); - } - GLib.Test.message("Interaction complete: Bob -> Alice (looping)"); - - /* Generate a shuffled list of encrypted messages for later use */ - Holder[] alice_ooo_plaintext = new Holder[10]; - Holder[] alice_ooo_ciphertext = new Holder[10]; - for (int i = 0; i < 10; i++) { - alice_ooo_plaintext[i] = new Holder(create_looping_message(i)); - alice_ooo_ciphertext[i] = new Holder(alice_session_cipher.encrypt(alice_ooo_plaintext[i].data).serialized); - } - - for (int i = 0; i < 10; i++) { - uint32 s = Random.next_int() % 10; - Holder tmp = alice_ooo_plaintext[s]; - alice_ooo_plaintext[s] = alice_ooo_plaintext[i]; - alice_ooo_plaintext[i] = tmp; - tmp = alice_ooo_ciphertext[s]; - alice_ooo_ciphertext[s] = alice_ooo_ciphertext[i]; - alice_ooo_ciphertext[i] = tmp; - } - GLib.Test.message("Shuffled Alice->Bob messages created"); - - /* Looping Alice -> Bob (repeated) */ - for (int i = 0; i < 10; i++) { - uint8[] looping_message = create_looping_message(i); - CiphertextMessage alice_looping_message = alice_session_cipher.encrypt(looping_message); - SignalMessage alice_looping_message_copy = global_context.copy_signal_message(alice_looping_message); - uint8[] looping_plaintext = bob_session_cipher.decrypt_signal_message(alice_looping_message_copy); - fail_if_not_eq_uint8_arr(looping_message, looping_plaintext); - } - GLib.Test.message("Interaction complete: Alice -> Bob (looping, repeated)"); - - /* Looping Bob -> Alice (repeated) */ - for (int i = 0; i < 10; i++) { - uint8[] looping_message = create_looping_message(i); - CiphertextMessage bob_looping_message = bob_session_cipher.encrypt(looping_message); - SignalMessage bob_looping_message_copy = global_context.copy_signal_message(bob_looping_message); - uint8[] looping_plaintext = alice_session_cipher.decrypt_signal_message(bob_looping_message_copy); - fail_if_not_eq_uint8_arr(looping_message, looping_plaintext); - } - GLib.Test.message("Interaction complete: Bob -> Alice (looping, repeated)"); - - /* Shuffled Alice -> Bob */ - for (int i = 0; i < 10; i++) { - SignalMessage ooo_message_deserialized = global_context.deserialize_signal_message(alice_ooo_ciphertext[i].data); - uint8[] ooo_plaintext = bob_session_cipher.decrypt_signal_message(ooo_message_deserialized); - fail_if_not_eq_uint8_arr(alice_ooo_plaintext[i].data, ooo_plaintext); - } - GLib.Test.message("Interaction complete: Alice -> Bob (shuffled)"); - } - - uint8[] create_looping_message(int index) { - return (@"You can only desire based on what you know: $index").data; - } - - /* - uint8[] create_looping_message_short(int index) { - return ("What do we mean by saying that existence precedes essence? " + - "We mean that man first of all exists, encounters himself, " + - @"surges up in the world--and defines himself aftward. $index").data; - } - */ -} - -} diff --git a/plugins/signal-protocol/tests/testcase.vala b/plugins/signal-protocol/tests/testcase.vala deleted file mode 100644 index 59fcf193..00000000 --- a/plugins/signal-protocol/tests/testcase.vala +++ /dev/null @@ -1,80 +0,0 @@ -/* testcase.vala - * - * Copyright (C) 2009 Julien Peeters - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: - * Julien Peeters - */ - -public abstract class Gee.TestCase : Object { - - private GLib.TestSuite suite; - private Adaptor[] adaptors = new Adaptor[0]; - - public delegate void TestMethod (); - - protected TestCase (string name) { - this.suite = new GLib.TestSuite (name); - } - - public void add_test (string name, owned TestMethod test) { - var adaptor = new Adaptor (name, (owned)test, this); - this.adaptors += adaptor; - - this.suite.add (new GLib.TestCase (adaptor.name, - adaptor.set_up, - adaptor.run, - adaptor.tear_down )); - } - - public virtual void set_up () { - } - - public virtual void tear_down () { - } - - public GLib.TestSuite get_suite () { - return (owned) this.suite; - } - - private class Adaptor { - [CCode (notify = false)] - public string name { get; private set; } - private TestMethod test; - private TestCase test_case; - - public Adaptor (string name, - owned TestMethod test, - TestCase test_case) { - this.name = name; - this.test = (owned)test; - this.test_case = test_case; - } - - public void set_up (void* fixture) { - this.test_case.set_up (); - } - - public void run (void* fixture) { - this.test (); - } - - public void tear_down (void* fixture) { - this.test_case.tear_down (); - } - } -} diff --git a/plugins/signal-protocol/vapi/signal-protocol-native.vapi b/plugins/signal-protocol/vapi/signal-protocol-native.vapi deleted file mode 100644 index 0bac0317..00000000 --- a/plugins/signal-protocol/vapi/signal-protocol-native.vapi +++ /dev/null @@ -1,274 +0,0 @@ -namespace Signal { - [Compact] - [CCode (cname = "signal_context", cprefix="signal_context_", free_function="signal_context_destroy", cheader_filename = "signal/signal_protocol.h")] - public class NativeContext { - public static int create(out NativeContext context, void* user_data); - public int set_crypto_provider(NativeCryptoProvider crypto_provider); - public int set_locking_functions(LockingFunc lock, LockingFunc unlock); - public int set_log_function(LogFunc log); - } - [CCode (has_target = false)] - public delegate void LockingFunc(void* user_data); - [CCode (has_target = false)] - public delegate void LogFunc(LogLevel level, string message, size_t len, void* user_data); - - [Compact] - [CCode (cname = "signal_crypto_provider", cheader_filename = "signal/signal_protocol.h")] - public struct NativeCryptoProvider { - public RandomFunc random_func; - public HmacSha256Init hmac_sha256_init_func; - public HmacSha256Update hmac_sha256_update_func; - public HmacSha256Final hmac_sha256_final_func; - public HmacSha256Cleanup hmac_sha256_cleanup_func; - public Sha512DigestInit sha512_digest_init_func; - public Sha512DigestUpdate sha512_digest_update_func; - public Sha512DigestFinal sha512_digest_final_func; - public Sha512DigestCleanup sha512_digest_cleanup_func; - public CryptFunc encrypt_func; - public CryptFunc decrypt_func; - public void* user_data; - } - [CCode (has_target = false)] - public delegate int RandomFunc(uint8[] data, void* user_data); - [CCode (has_target = false)] - public delegate int HmacSha256Init(out void* hmac_context, uint8[] key, void* user_data); - [CCode (has_target = false)] - public delegate int HmacSha256Update(void* hmac_context, uint8[] data, void* user_data); - [CCode (has_target = false)] - public delegate int HmacSha256Final(void* hmac_context, out Buffer buffer, void* user_data); - [CCode (has_target = false)] - public delegate int HmacSha256Cleanup(void* hmac_context, void* user_data); - [CCode (has_target = false)] - public delegate int Sha512DigestInit(out void* digest_context, void* user_data); - [CCode (has_target = false)] - public delegate int Sha512DigestUpdate(void* digest_context, uint8[] data, void* user_data); - [CCode (has_target = false)] - public delegate int Sha512DigestFinal(void* digest_context, out Buffer buffer, void* user_data); - [CCode (has_target = false)] - public delegate int Sha512DigestCleanup(void* digest_context, void* user_data); - [CCode (has_target = false)] - public delegate int CryptFunc(out Buffer output, Cipher cipher, uint8[] key, uint8[] iv, uint8[] content, void* user_data); - - [Compact] - [CCode (cname = "signal_protocol_session_store", cheader_filename = "signal/signal_protocol.h")] - public struct NativeSessionStore { - public LoadSessionFunc load_session_func; - public GetSubDeviceSessionsFunc get_sub_device_sessions_func; - public StoreSessionFunc store_session_func; - public ContainsSessionFunc contains_session_func; - public DeleteSessionFunc delete_session_func; - public DeleteAllSessionsFunc delete_all_sessions_func; - public DestroyFunc destroy_func; - public void* user_data; - } - [CCode (has_target = false)] - public delegate int LoadSessionFunc(out Buffer record, out Buffer user_record, Address address, void* user_data); - [CCode (has_target = false)] - public delegate int GetSubDeviceSessionsFunc(out IntList sessions, [CCode (array_length_type = "size_t")] char[] name, void* user_data); - [CCode (has_target = false)] - public delegate int StoreSessionFunc(Address address, [CCode (array_length_type = "size_t")] uint8[] record, [CCode (array_length_type = "size_t")] uint8[] user_record, void* user_data); - [CCode (has_target = false)] - public delegate int ContainsSessionFunc(Address address, void* user_data); - [CCode (has_target = false)] - public delegate int DeleteSessionFunc(Address address, void* user_data); - [CCode (has_target = false)] - public delegate int DeleteAllSessionsFunc([CCode (array_length_type = "size_t")] char[] name, void* user_data); - - [Compact] - [CCode (cname = "signal_protocol_identity_key_store", cheader_filename = "signal/signal_protocol.h")] - public struct NativeIdentityKeyStore { - GetIdentityKeyPairFunc get_identity_key_pair; - GetLocalRegistrationIdFunc get_local_registration_id; - SaveIdentityFunc save_identity; - IsTrustedIdentityFunc is_trusted_identity; - DestroyFunc destroy_func; - void* user_data; - } - [CCode (has_target = false)] - public delegate int GetIdentityKeyPairFunc(out Buffer public_data, out Buffer private_data, void* user_data); - [CCode (has_target = false)] - public delegate int GetLocalRegistrationIdFunc(void* user_data, out uint32 registration_id); - [CCode (has_target = false)] - public delegate int SaveIdentityFunc(Address address, [CCode (array_length_type = "size_t")] uint8[] key, void* user_data); - [CCode (has_target = false)] - public delegate int IsTrustedIdentityFunc(Address address, [CCode (array_length_type = "size_t")] uint8[] key, void* user_data); - - [Compact] - [CCode (cname = "signal_protocol_pre_key_store", cheader_filename = "signal/signal_protocol.h")] - public struct NativePreKeyStore { - LoadPreKeyFunc load_pre_key; - StorePreKeyFunc store_pre_key; - ContainsPreKeyFunc contains_pre_key; - RemovePreKeyFunc remove_pre_key; - DestroyFunc destroy_func; - void* user_data; - } - [CCode (has_target = false)] - public delegate int LoadPreKeyFunc(out Buffer record, uint32 pre_key_id, void* user_data); - [CCode (has_target = false)] - public delegate int StorePreKeyFunc(uint32 pre_key_id, [CCode (array_length_type = "size_t")] uint8[] record, void* user_data); - [CCode (has_target = false)] - public delegate int ContainsPreKeyFunc(uint32 pre_key_id, void* user_data); - [CCode (has_target = false)] - public delegate int RemovePreKeyFunc(uint32 pre_key_id, void* user_data); - - - [Compact] - [CCode (cname = "signal_protocol_signed_pre_key_store", cheader_filename = "signal/signal_protocol.h")] - public struct NativeSignedPreKeyStore { - LoadPreKeyFunc load_signed_pre_key; - StorePreKeyFunc store_signed_pre_key; - ContainsPreKeyFunc contains_signed_pre_key; - RemovePreKeyFunc remove_signed_pre_key; - DestroyFunc destroy_func; - void* user_data; - } - - - [Compact] - [CCode (cname = "signal_protocol_sender_key_store")] - public struct NativeSenderKeyStore { - StoreSenderKeyFunc store_sender_key; - LoadSenderKeyFunc load_sender_key; - DestroyFunc destroy_func; - void* user_data; - } - [CCode (has_target = false)] - public delegate int StoreSenderKeyFunc(SenderKeyName sender_key_name, [CCode (array_length_type = "size_t")] uint8[] record, [CCode (array_length_type = "size_t")] uint8[] user_record, void* user_data); - [CCode (has_target = false)] - public delegate int LoadSenderKeyFunc(out Buffer record, out Buffer user_record, SenderKeyName sender_key_name, void* user_data); - - [CCode (has_target = false)] - public delegate void DestroyFunc(void* user_data); - - [Compact] - [CCode (cname = "signal_protocol_store_context", cprefix = "signal_protocol_store_context_", free_function="signal_protocol_store_context_destroy", cheader_filename = "signal/signal_protocol.h")] - public class NativeStoreContext { - public static int create(out NativeStoreContext context, NativeContext global_context); - public int set_session_store(NativeSessionStore store); - public int set_pre_key_store(NativePreKeyStore store); - public int set_signed_pre_key_store(NativeSignedPreKeyStore store); - public int set_identity_key_store(NativeIdentityKeyStore store); - public int set_sender_key_store(NativeSenderKeyStore store); - } - - - [CCode (cheader_filename = "signal/signal_protocol.h")] - namespace Protocol { - - /** - * Interface to the pre-key store. - * These functions will use the callbacks in the provided - * signal_protocol_store_context instance and operate in terms of higher level - * library data structures. - */ - [CCode (cprefix = "signal_protocol_pre_key_")] - namespace PreKey { - public int load_key(NativeStoreContext context, out PreKeyRecord pre_key, uint32 pre_key_id); - public int store_key(NativeStoreContext context, PreKeyRecord pre_key); - public int contains_key(NativeStoreContext context, uint32 pre_key_id); - public int remove_key(NativeStoreContext context, uint32 pre_key_id); - } - - [CCode (cprefix = "signal_protocol_signed_pre_key_")] - namespace SignedPreKey { - public int load_key(NativeStoreContext context, out SignedPreKeyRecord pre_key, uint32 pre_key_id); - public int store_key(NativeStoreContext context, SignedPreKeyRecord pre_key); - public int contains_key(NativeStoreContext context, uint32 pre_key_id); - public int remove_key(NativeStoreContext context, uint32 pre_key_id); - } - - /** - * Interface to the session store. - * These functions will use the callbacks in the provided - * signal_protocol_store_context instance and operate in terms of higher level - * library data structures. - */ - [CCode (cprefix = "signal_protocol_session_")] - namespace Session { - public int load_session(NativeStoreContext context, out SessionRecord record, Address address); - public int get_sub_device_sessions(NativeStoreContext context, out IntList sessions, char[] name); - public int store_session(NativeStoreContext context, Address address, SessionRecord record); - public int contains_session(NativeStoreContext context, Address address); - public int delete_session(NativeStoreContext context, Address address); - public int delete_all_sessions(NativeStoreContext context, char[] name); - } - - namespace Identity { - public int get_key_pair(NativeStoreContext store_context, out IdentityKeyPair key_pair); - public int get_local_registration_id(NativeStoreContext store_context, out uint32 registration_id); - public int save_identity(NativeStoreContext store_context, Address address, ECPublicKey identity_key); - public int is_trusted_identity(NativeStoreContext store_context, Address address, ECPublicKey identity_key); - } - - [CCode (cheader_filename = "signal/key_helper.h", cprefix = "signal_protocol_key_helper_")] - namespace KeyHelper { - [Compact] - [CCode (cname = "signal_protocol_key_helper_pre_key_list_node", cprefix = "signal_protocol_key_helper_key_list_", free_function="signal_protocol_key_helper_key_list_free")] - public class PreKeyListNode { - public PreKeyRecord element(); - public PreKeyListNode next(); - } - - public int generate_identity_key_pair(out IdentityKeyPair key_pair, NativeContext global_context); - public int generate_registration_id(out int32 registration_id, int extended_range, NativeContext global_context); - public int get_random_sequence(out int value, int max, NativeContext global_context); - public int generate_pre_keys(out PreKeyListNode head, uint start, uint count, NativeContext global_context); - public int generate_last_resort_pre_key(out PreKeyRecord pre_key, NativeContext global_context); - public int generate_signed_pre_key(out SignedPreKeyRecord signed_pre_key, IdentityKeyPair identity_key_pair, uint32 signed_pre_key_id, uint64 timestamp, NativeContext global_context); - public int generate_sender_signing_key(out ECKeyPair key_pair, NativeContext global_context); - public int generate_sender_key(out Buffer key_buffer, NativeContext global_context); - public int generate_sender_key_id(out int32 key_id, NativeContext global_context); - } - } - - [CCode (cheader_filename = "signal/curve.h")] - namespace Curve { - [CCode (cname = "curve_calculate_agreement")] - public int calculate_agreement([CCode (array_length = false)] out uint8[] shared_key_data, ECPublicKey public_key, ECPrivateKey private_key); - [CCode (cname = "curve_calculate_signature")] - public int calculate_signature(NativeContext context, out Buffer signature, ECPrivateKey signing_key, uint8[] message); - [CCode (cname = "curve_verify_signature")] - public int verify_signature(ECPublicKey signing_key, uint8[] message, uint8[] signature); - } - - [CCode (cname = "session_builder_create", cheader_filename = "signal/session_builder.h")] - public static int session_builder_create(out SessionBuilder builder, NativeStoreContext store, Address remote_address, NativeContext global_context); - [CCode (cname = "session_cipher_create", cheader_filename = "signal/session_cipher.h")] - public static int session_cipher_create(out SessionCipher cipher, NativeStoreContext store, Address remote_address, NativeContext global_context); - [CCode (cname = "pre_key_signal_message_deserialize", cheader_filename = "signal/protocol.h")] - public static int pre_key_signal_message_deserialize(out PreKeySignalMessage message, uint8[] data, NativeContext global_context); - [CCode (cname = "pre_key_signal_message_copy", cheader_filename = "signal/protocol.h")] - public static int pre_key_signal_message_copy(out PreKeySignalMessage message, PreKeySignalMessage other_message, NativeContext global_context); - [CCode (cname = "signal_message_create", cheader_filename = "signal/protocol.h")] - public static int signal_message_create(out SignalMessage message, uint8 message_version, uint8[] mac_key, ECPublicKey sender_ratchet_key, uint32 counter, uint32 previous_counter, uint8[] ciphertext, ECPublicKey sender_identity_key, ECPublicKey receiver_identity_key, NativeContext global_context); - [CCode (cname = "signal_message_deserialize", cheader_filename = "signal/protocol.h")] - public static int signal_message_deserialize(out SignalMessage message, uint8[] data, NativeContext global_context); - [CCode (cname = "signal_message_copy", cheader_filename = "signal/protocol.h")] - public static int signal_message_copy(out SignalMessage message, SignalMessage other_message, NativeContext global_context); - [CCode (cname = "curve_generate_key_pair", cheader_filename = "signal/curve.h")] - public static int curve_generate_key_pair(NativeContext context, out ECKeyPair key_pair); - [CCode (cname = "curve_decode_private_point", cheader_filename = "signal/curve.h")] - public static int curve_decode_private_point(out ECPrivateKey public_key, uint8[] key, NativeContext global_context); - [CCode (cname = "curve_decode_point", cheader_filename = "signal/curve.h")] - public static int curve_decode_point(out ECPublicKey public_key, uint8[] key, NativeContext global_context); - [CCode (cname = "curve_generate_private_key", cheader_filename = "signal/curve.h")] - public static int curve_generate_private_key(NativeContext context, out ECPrivateKey private_key); - [CCode (cname = "ratchet_identity_key_pair_deserialize", cheader_filename = "signal/ratchet.h")] - public static int ratchet_identity_key_pair_deserialize(out IdentityKeyPair key_pair, uint8[] data, NativeContext global_context); - [CCode (cname = "session_signed_pre_key_deserialize", cheader_filename = "signal/signed_pre_key.h")] - public static int session_signed_pre_key_deserialize(out SignedPreKeyRecord pre_key, uint8[] data, NativeContext global_context); - - [Compact] - [CCode (cname = "hkdf_context", cprefix = "hkdf_", free_function = "hkdf_destroy", cheader_filename = "signal/hkdf.h")] - public class NativeHkdfContext { - public static int create(out NativeHkdfContext context, int message_version, NativeContext global_context); - public int compare(NativeHkdfContext other); - public ssize_t derive_secrets([CCode (array_length = false)] out uint8[] output, uint8[] input_key_material, uint8[] salt, uint8[] info, size_t output_len); - } - - [CCode (cname = "setup_signal_vala_crypto_provider", cheader_filename = "signal_helper.h")] - public static void setup_crypto_provider(NativeContext context); - [CCode (cname = "signal_vala_randomize", cheader_filename = "signal_helper.h")] - public static int native_random(uint8[] data); -} diff --git a/plugins/signal-protocol/vapi/signal-protocol-public.vapi b/plugins/signal-protocol/vapi/signal-protocol-public.vapi deleted file mode 100644 index eaf73c0c..00000000 --- a/plugins/signal-protocol/vapi/signal-protocol-public.vapi +++ /dev/null @@ -1,384 +0,0 @@ -namespace Signal { - - [CCode (cname = "int", cprefix = "SG_ERR_", cheader_filename = "signal/signal_protocol.h", has_type_id = false)] - public enum ErrorCode { - [CCode (cname = "SG_SUCCESS")] - SUCCESS, - NOMEM, - INVAL, - UNKNOWN, - DUPLICATE_MESSAGE, - INVALID_KEY, - INVALID_KEY_ID, - INVALID_MAC, - INVALID_MESSAGE, - INVALID_VERSION, - LEGACY_MESSAGE, - NO_SESSION, - STALE_KEY_EXCHANGE, - UNTRUSTED_IDENTITY, - VRF_SIG_VERIF_FAILED, - INVALID_PROTO_BUF, - FP_VERSION_MISMATCH, - FP_IDENT_MISMATCH; - } - - [CCode (cname = "SG_ERR_MINIMUM", cheader_filename = "signal/signal_protocol.h")] - public const int MIN_ERROR_CODE; - - [CCode (cname = "int", cprefix = "SG_LOG_", cheader_filename = "signal/signal_protocol.h", has_type_id = false)] - public enum LogLevel { - ERROR, - WARNING, - NOTICE, - INFO, - DEBUG - } - - [CCode (cname = "signal_throw_gerror_by_code_", cheader_filename = "signal/signal_protocol.h")] - private int throw_by_code(int code, string? message = null) throws GLib.Error { - if (code < 0 && code > MIN_ERROR_CODE) { - throw new GLib.Error(-1, code, "%s: %s", message ?? "Signal error", ((ErrorCode)code).to_string()); - } - return code; - } - - [CCode (cname = "int", cprefix = "SG_CIPHER_", cheader_filename = "signal/signal_protocol.h", has_type_id = false)] - public enum Cipher { - AES_CTR_NOPADDING, - AES_CBC_PKCS5, - AES_GCM_NOPADDING - } - - [Compact] - [CCode (cname = "signal_type_base", ref_function="signal_type_ref_vapi", unref_function="signal_type_unref_vapi", cheader_filename="signal/signal_protocol_types.h,signal_helper.h")] - public class TypeBase { - } - - [Compact] - [CCode (cname = "signal_buffer", cheader_filename = "signal/signal_protocol_types.h", free_function="signal_buffer_free")] - public class Buffer { - [CCode (cname = "signal_buffer_alloc")] - public Buffer(size_t len); - [CCode (cname = "signal_buffer_create")] - public Buffer.from(uint8[] data); - - public Buffer copy(); - public Buffer append(uint8[] data); - public int compare(Buffer other); - - public uint8 get(int i) { return data[i]; } - public void set(int i, uint8 val) { data[i] = val; } - - public uint8[] data { get { int x = (int)len(); unowned uint8[] res = _data(); res.length = x; return res; } } - - [CCode (array_length = false, cname = "signal_buffer_data")] - private unowned uint8[] _data(); - private size_t len(); - } - - [Compact] - [CCode (cname = "signal_int_list", cheader_filename = "signal/signal_protocol_types.h", free_function="signal_int_list_free")] - public class IntList { - [CCode (cname = "signal_int_list_alloc")] - public IntList(); - [CCode (cname = "signal_int_list_push_back")] - public int add(int value); - public uint size { [CCode (cname = "signal_int_list_size")] get; } - [CCode (cname = "signal_int_list_at")] - public int get(uint index); - } - - [Compact] - [CCode (cname = "session_builder", cprefix = "session_builder_", free_function="session_builder_free", cheader_filename = "signal/session_builder.h")] - public class SessionBuilder { - [CCode (cname = "session_builder_process_pre_key_bundle")] - private int process_pre_key_bundle_(PreKeyBundle pre_key_bundle); - [CCode (cname = "session_builder_process_pre_key_bundle_")] - public void process_pre_key_bundle(PreKeyBundle pre_key_bundle) throws GLib.Error { - throw_by_code(process_pre_key_bundle_(pre_key_bundle)); - } - } - - [Compact] - [CCode (cname = "session_pre_key_bundle", cprefix = "session_pre_key_bundle_", cheader_filename = "signal/session_pre_key.h")] - public class PreKeyBundle : TypeBase { - public static int create(out PreKeyBundle bundle, uint32 registration_id, int device_id, uint32 pre_key_id, ECPublicKey? pre_key_public, - uint32 signed_pre_key_id, ECPublicKey? signed_pre_key_public, uint8[]? signed_pre_key_signature, ECPublicKey? identity_key); - public uint32 registration_id { get; } - public int device_id { get; } - public uint32 pre_key_id { get; } - public ECPublicKey pre_key { owned get; } - public uint32 signed_pre_key_id { get; } - public ECPublicKey signed_pre_key { owned get; } - public Buffer signed_pre_key_signature { owned get; } - public ECPublicKey identity_key { owned get; } - } - - [Compact] - [CCode (cname = "session_pre_key", cprefix = "session_pre_key_", cheader_filename = "signal/session_pre_key.h,signal_helper.h")] - public class PreKeyRecord : TypeBase { - public static int create(out PreKeyRecord pre_key, uint32 id, ECKeyPair key_pair); - //public static int deserialize(out PreKeyRecord pre_key, uint8[] data, NativeContext global_context); - [CCode (instance_pos = 2)] - public int serialze(out Buffer buffer); - public uint32 id { get; } - public ECKeyPair key_pair { get; } - } - - [Compact] - [CCode (cname = "session_record", cprefix = "session_record_", cheader_filename = "signal/signal_protocol_types.h")] - public class SessionRecord : TypeBase { - public SessionState state { get; } - public Buffer user_record { get; } - } - - [Compact] - [CCode (cname = "session_state", cprefix = "session_state_", cheader_filename = "signal/session_state.h")] - public class SessionState : TypeBase { - //public static int create(out SessionState state, NativeContext context); - //public static int deserialize(out SessionState state, uint8[] data, NativeContext context); - //public static int copy(out SessionState state, SessionState other_state, NativeContext context); - [CCode (instance_pos = 2)] - public int serialze(out Buffer buffer); - - public uint32 session_version { get; set; } - public ECPublicKey local_identity_key { get; set; } - public ECPublicKey remote_identity_key { get; set; } - //public Ratchet.RootKey root_key { get; set; } - public uint32 previous_counter { get; set; } - public ECPublicKey sender_ratchet_key { get; } - public ECKeyPair sender_ratchet_key_pair { get; } - //public Ratchet.ChainKey sender_chain_key { get; set; } - public uint32 remote_registration_id { get; set; } - public uint32 local_registration_id { get; set; } - public int needs_refresh { get; set; } - public ECPublicKey alice_base_key { get; set; } - } - - [Compact] - [CCode (cname = "session_signed_pre_key", cprefix = "session_signed_pre_key_", cheader_filename = "signal/session_pre_key.h")] - public class SignedPreKeyRecord : TypeBase { - public static int create(out SignedPreKeyRecord pre_key, uint32 id, uint64 timestamp, ECKeyPair key_pair, uint8[] signature); - [CCode (instance_pos = 2)] - public int serialze(out Buffer buffer); - - public uint32 id { get; } - public uint64 timestamp { get; } - public ECKeyPair key_pair { get; } - public uint8[] signature { [CCode (cname = "session_signed_pre_key_get_signature_")] get { int x = (int)get_signature_len(); unowned uint8[] res = get_signature(); res.length = x; return res; } } - - [CCode (array_length = false, cname = "session_signed_pre_key_get_signature")] - private unowned uint8[] get_signature(); - private size_t get_signature_len(); - } - - /** - * Address of an Signal Protocol message recipient - */ - [Compact] - [CCode (cname = "signal_protocol_address", cprefix = "signal_protocol_address_", cheader_filename = "signal/signal_protocol.h,signal_helper.h")] - public class Address { - public Address(string name, int32 device_id); - public int32 device_id { get; set; } - public string name { owned get; set; } - } - - /** - * A representation of a (group + sender + device) tuple - */ - [Compact] - [CCode (cname = "signal_protocol_sender_key_name")] - public class SenderKeyName { - [CCode (cname = "group_id", array_length_cname="group_id_len")] - private char* group_id_; - private size_t group_id_len; - public Address sender; - } - - [Compact] - [CCode (cname = "ec_public_key", cprefix = "ec_public_key_", cheader_filename = "signal/curve.h,signal_helper.h")] - public class ECPublicKey : TypeBase { - [CCode (cname = "curve_generate_public_key")] - public static int generate(out ECPublicKey public_key, ECPrivateKey private_key); - [CCode (instance_pos = 1, cname = "ec_public_key_serialize")] - private int serialize_([CCode (pos = 0)] out Buffer buffer); - [CCode (cname = "ec_public_key_serialize_")] - public uint8[] serialize() { - Buffer buffer; - int code = serialize_(out buffer); - if (code < 0 && code > MIN_ERROR_CODE) { - // Can only throw for invalid arguments or out of memory. - GLib.assert_not_reached(); - } - return buffer.data; - } - public int compare(ECPublicKey other); - public int memcmp(ECPublicKey other); - } - - [Compact] - [CCode (cname = "ec_private_key", cprefix = "ec_private_key_", cheader_filename = "signal/curve.h,signal_helper.h")] - public class ECPrivateKey : TypeBase { - [CCode (instance_pos = 1, cname = "ec_private_key_serialize")] - private int serialize_([CCode (pos = 0)] out Buffer buffer); - [CCode (cname = "ec_private_key_serialize_")] - public uint8[] serialize() throws GLib.Error { - Buffer buffer; - int code = serialize_(out buffer); - if (code < 0 && code > MIN_ERROR_CODE) { - // Can only throw for invalid arguments or out of memory. - GLib.assert_not_reached(); - } - return buffer.data; - } - public int compare(ECPublicKey other); - } - - [Compact] - [CCode (cname = "ec_key_pair", cprefix="ec_key_pair_", cheader_filename = "signal/curve.h,signal_helper.h")] - public class ECKeyPair : TypeBase { - public static int create(out ECKeyPair key_pair, ECPublicKey public_key, ECPrivateKey private_key); - public ECPublicKey public { get; } - public ECPrivateKey private { get; } - } - - [CCode (cname = "ratchet_message_keys", cheader_filename = "signal/ratchet.h")] - public class MessageKeys { - } - - [Compact] - [CCode (cname = "ratchet_identity_key_pair", cprefix = "ratchet_identity_key_pair_", cheader_filename = "signal/ratchet.h,signal_helper.h")] - public class IdentityKeyPair : TypeBase { - public static int create(out IdentityKeyPair key_pair, ECPublicKey public_key, ECPrivateKey private_key); - public int serialze(out Buffer buffer); - public ECPublicKey public { get; } - public ECPrivateKey private { get; } - } - - [Compact] - [CCode (cname = "ec_public_key_list")] - public class PublicKeyList {} - - /** - * The main entry point for Signal Protocol encrypt/decrypt operations. - * - * Once a session has been established with session_builder, - * this class can be used for all encrypt/decrypt operations within - * that session. - */ - [Compact] - [CCode (cname = "session_cipher", cprefix = "session_cipher_", cheader_filename = "signal/session_cipher.h", free_function = "session_cipher_free")] - public class SessionCipher { - public void* user_data { get; set; } - public DecryptionCallback decryption_callback { set; } - [CCode (cname = "session_cipher_encrypt")] - private int encrypt_(uint8[] padded_message, out CiphertextMessage encrypted_message); - [CCode (cname = "session_cipher_encrypt_")] - public CiphertextMessage encrypt(uint8[] padded_message) throws GLib.Error { - CiphertextMessage res; - throw_by_code(encrypt_(padded_message, out res)); - return res; - } - [CCode (cname = "session_cipher_decrypt_pre_key_signal_message")] - private int decrypt_pre_key_signal_message_(PreKeySignalMessage ciphertext, void* decrypt_context, out Buffer plaintext); - [CCode (cname = "session_cipher_decrypt_pre_key_signal_message_")] - public uint8[] decrypt_pre_key_signal_message(PreKeySignalMessage ciphertext, void* decrypt_context = null) throws GLib.Error { - Buffer res; - throw_by_code(decrypt_pre_key_signal_message_(ciphertext, decrypt_context, out res)); - return res.data; - } - [CCode (cname = "session_cipher_decrypt_signal_message")] - private int decrypt_signal_message_(SignalMessage ciphertext, void* decrypt_context, out Buffer plaintext); - [CCode (cname = "session_cipher_decrypt_signal_message_")] - public uint8[] decrypt_signal_message(SignalMessage ciphertext, void* decrypt_context = null) throws GLib.Error { - Buffer res; - throw_by_code(decrypt_signal_message_(ciphertext, decrypt_context, out res)); - return res.data; - } - public int get_remote_registration_id(out uint32 remote_id); - public int get_session_version(uint32 version); - - [CCode (has_target = false)] - public delegate int DecryptionCallback(SessionCipher cipher, Buffer plaintext, void* decrypt_context); - } - - [CCode (cname = "int", cheader_filename = "signal/protocol.h", has_type_id = false)] - public enum CiphertextType { - [CCode (cname = "CIPHERTEXT_SIGNAL_TYPE")] - SIGNAL, - [CCode (cname = "CIPHERTEXT_PREKEY_TYPE")] - PREKEY, - [CCode (cname = "CIPHERTEXT_SENDERKEY_TYPE")] - SENDERKEY, - [CCode (cname = "CIPHERTEXT_SENDERKEY_DISTRIBUTION_TYPE")] - SENDERKEY_DISTRIBUTION - } - - [Compact] - [CCode (cname = "ciphertext_message", cprefix = "ciphertext_message_", cheader_filename = "signal/protocol.h,signal_helper.h")] - public abstract class CiphertextMessage : TypeBase { - public CiphertextType type { get; } - [CCode (cname = "ciphertext_message_get_serialized")] - private unowned Buffer get_serialized_(); - public uint8[] serialized { [CCode (cname = "ciphertext_message_get_serialized_")] get { - return get_serialized_().data; - }} - } - [Compact] - [CCode (cname = "signal_message", cprefix = "signal_message_", cheader_filename = "signal/protocol.h,signal_helper.h")] - public class SignalMessage : CiphertextMessage { - public ECPublicKey sender_ratchet_key { get; } - public uint8 message_version { get; } - public uint32 counter { get; } - public Buffer body { get; } - //public int verify_mac(uint8 message_version, ECPublicKey sender_identity_key, ECPublicKey receiver_identity_key, uint8[] mac, NativeContext global_context); - public static int is_legacy(uint8[] data); - } - [Compact] - [CCode (cname = "pre_key_signal_message", cprefix = "pre_key_signal_message_", cheader_filename = "signal/protocol.h,signal_helper.h")] - public class PreKeySignalMessage : CiphertextMessage { - public uint8 message_version { get; } - public ECPublicKey identity_key { get; } - public uint32 registration_id { get; } - public uint32 pre_key_id { get; } - public uint32 signed_pre_key_id { get; } - public ECPublicKey base_key { get; } - public SignalMessage signal_message { get; } - } - [Compact] - [CCode (cname = "sender_key_message", cprefix = "sender_key_message_", cheader_filename = "signal/protocol.h,signal_helper.h")] - public class SenderKeyMessage : CiphertextMessage { - public uint32 key_id { get; } - public uint32 iteration { get; } - public Buffer ciphertext { get; } - } - [Compact] - [CCode (cname = "sender_key_distribution_message", cprefix = "sender_key_distribution_message_", cheader_filename = "signal/protocol.h,signal_helper.h")] - public class SenderKeyDistributionMessage : CiphertextMessage { - public uint32 id { get; } - public uint32 iteration { get; } - public Buffer chain_key { get; } - public ECPublicKey signature_key { get; } - } - - [CCode (cname = "signal_vala_encrypt", cheader_filename = "signal_helper.h")] - private static int aes_encrypt_(out Buffer output, int cipher, uint8[] key, uint8[] iv, uint8[] plaintext, void *user_data); - - [CCode (cname = "signal_vala_encrypt_")] - public uint8[] aes_encrypt(int cipher, uint8[] key, uint8[] iv, uint8[] plaintext) throws GLib.Error { - Buffer buf; - throw_by_code(aes_encrypt_(out buf, cipher, key, iv, plaintext, null)); - return buf.data; - } - - [CCode (cname = "signal_vala_decrypt", cheader_filename = "signal_helper.h")] - private static int aes_decrypt_(out Buffer output, int cipher, uint8[] key, uint8[] iv, uint8[] ciphertext, void *user_data); - - [CCode (cname = "signal_vala_decrypt_")] - public uint8[] aes_decrypt(int cipher, uint8[] key, uint8[] iv, uint8[] ciphertext) throws GLib.Error { - Buffer buf; - throw_by_code(aes_decrypt_(out buf, cipher, key, iv, ciphertext, null)); - return buf.data; - } -} -- cgit v1.2.3-54-g00ecf From 62ed82a49535a891acb85a2e7b9d861433db1670 Mon Sep 17 00:00:00 2001 From: hrxi Date: Thu, 22 Jun 2023 00:04:39 +0200 Subject: meson: Install more stuff Install .vapi, .deps, .h files for the Vala libraries. Also install the data files. .deps files have to be manually generated, there's a feature request for automated generation at https://github.com/mesonbuild/meson/issues/9756. Import the gnome module globally. Install dependencies on Meson CI. --- .github/workflows/build.yml | 2 +- libdino/dino.deps | 6 ++++++ libdino/meson.build | 5 ++++- main/meson.build | 16 +++++++++++++--- main/po/meson.build | 1 + meson.build | 2 ++ meson_options.txt | 2 +- qlite/meson.build | 7 ++++++- qlite/qlite.deps | 3 +++ xmpp-vala/meson.build | 7 ++++++- xmpp-vala/xmpp-vala.deps | 5 +++++ 11 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 libdino/dino.deps create mode 100644 main/po/meson.build create mode 100644 qlite/qlite.deps create mode 100644 xmpp-vala/xmpp-vala.deps diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 590035e0..8408c28a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: fetch-depth: 0 - run: sudo apt-get update - run: sudo apt-get remove libunwind-14-dev - - run: sudo apt-get install -y build-essential gettext libadwaita-1-dev libgee-0.8-dev libgtk-4-dev libsqlite3-dev meson valac + - run: sudo apt-get install -y build-essential gettext libadwaita-1-dev libcanberra-dev libgcrypt20-dev libgee-0.8-dev libgpgme-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev libgtk-4-dev libnice-dev libnotify-dev libqrencode-dev libsignal-protocol-c-dev libsoup-3.0-dev libsqlite3-dev libsrtp2-dev libwebrtc-audio-processing-dev meson valac - run: meson setup build - run: meson compile -C build build-flatpak: diff --git a/libdino/dino.deps b/libdino/dino.deps new file mode 100644 index 00000000..c1146392 --- /dev/null +++ b/libdino/dino.deps @@ -0,0 +1,6 @@ +gdk-pixbuf-2.0 +gee-0.8 +glib-2.0 +gmodule-2.0 +qlite +xmpp-vala diff --git a/libdino/meson.build b/libdino/meson.build index 611e8ca7..356c15d3 100644 --- a/libdino/meson.build +++ b/libdino/meson.build @@ -83,5 +83,8 @@ c_args = [ '-DDINO_SYSTEM_PLUGIN_DIR="@0@"'.format(get_option('prefix') / get_option('plugindir')), '-DG_LOG_DOMAIN="libdino"', ] -lib_dino = library('dino', sources, c_args: c_args, include_directories: include_directories('src'), dependencies: dependencies) +lib_dino = library('dino', sources, c_args: c_args, include_directories: include_directories('src'), dependencies: dependencies, version: '0.0', install: true, install_dir: [true, true, true]) dep_dino = declare_dependency(link_with: lib_dino, include_directories: include_directories('.', 'src')) + +install_data('dino.deps', install_dir: get_option('datadir') / 'vala/vapi') # TODO: workaround for https://github.com/mesonbuild/meson/issues/9756 +install_headers('src/dino_i18n.h') diff --git a/main/meson.build b/main/meson.build index 0326cc7c..f6d212f8 100644 --- a/main/meson.build +++ b/main/meson.build @@ -1,3 +1,4 @@ +subdir('po') dependencies = [ dep_dino, dep_gee, @@ -91,8 +92,8 @@ sources = files( 'src/view_model/preferences_row.vala', 'src/windows/conversation_details.vala', ) -sources += import('gnome').compile_resources( - 'dino-resources', +sources += gnome.compile_resources( + 'resources', 'data/gresource.xml', source_dir: 'data', ) @@ -102,4 +103,13 @@ c_args = [ '-DGETTEXT_PACKAGE="dino"', '-DLOCALE_INSTALL_DIR="@0@"'.format(get_option('prefix') / get_option('localedir')), ] -exe_dino = executable('dino', sources, c_args: c_args, vala_args: ['--vapidir', meson.current_source_dir() / 'vapi'], dependencies: dependencies) +vala_args = [ + '--vapidir', meson.current_source_dir() / 'vapi', +] +exe_dino = executable('dino', sources, c_args: c_args, vala_args: vala_args, dependencies: dependencies, install: true) + +install_data('data/icons/scalable/apps/im.dino.Dino-symbolic.svg', install_dir: get_option('datadir') / 'hicolor/symbolic/apps') +install_data('data/icons/scalable/apps/im.dino.Dino.svg', install_dir: get_option('datadir') / 'hicolor/scalable/apps') +install_data('data/im.dino.Dino.appdata.xml', install_dir: get_option('datadir') / 'metainfo') +install_data('data/im.dino.Dino.desktop', install_dir: get_option('datadir') / 'applications') +install_data('data/im.dino.Dino.service', install_dir: get_option('datadir') / 'dbus-1/servces') diff --git a/main/po/meson.build b/main/po/meson.build new file mode 100644 index 00000000..ea0d12d4 --- /dev/null +++ b/main/po/meson.build @@ -0,0 +1 @@ +i18n.gettext('dino') diff --git a/meson.build b/meson.build index aea22d57..c4b7fecf 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,8 @@ project('xmpp-vala', 'vala') fs = import('fs') +gnome = import('gnome') +i18n = import('i18n') python = import('python') dep_gdk_pixbuf = dependency('gdk-pixbuf-2.0') diff --git a/meson_options.txt b/meson_options.txt index 6e47b7c8..a1dcd3c2 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1 @@ -option('plugindir', type: 'string', value: 'lib/dino/plugins', description: 'Plugin directory for Dino plugins') +option('plugindir', type: 'string', value: 'lib/dino/plugins', description: 'Dino plugin directory') diff --git a/qlite/meson.build b/qlite/meson.build index 714a4224..9523b618 100644 --- a/qlite/meson.build +++ b/qlite/meson.build @@ -18,5 +18,10 @@ sources = files( c_args = [ '-DG_LOG_DOMAIN="qlite"', ] -lib_qlite = library('qlite', sources, c_args: c_args, vala_args: ['--vapidir', meson.current_source_dir() / 'vapi'], dependencies: dependencies) +vala_args = [ + '--vapidir', meson.current_source_dir() / 'vapi', +] +lib_qlite = library('qlite', sources, c_args: c_args, vala_args: vala_args, dependencies: dependencies, version: '0.1', install: true, install_dir: [true, true, true]) dep_qlite = declare_dependency(link_with: lib_qlite, include_directories: include_directories('.')) + +install_data('qlite.deps', install_dir: get_option('datadir') / 'vala/vapi') # TODO: workaround for https://github.com/mesonbuild/meson/issues/9756 diff --git a/qlite/qlite.deps b/qlite/qlite.deps new file mode 100644 index 00000000..d9b15e78 --- /dev/null +++ b/qlite/qlite.deps @@ -0,0 +1,3 @@ +gee-0.8 +glib-2.0 +sqlite3 diff --git a/xmpp-vala/meson.build b/xmpp-vala/meson.build index 3064339a..be5e96a8 100644 --- a/xmpp-vala/meson.build +++ b/xmpp-vala/meson.build @@ -129,5 +129,10 @@ sources = files( c_args = [ '-DG_LOG_DOMAIN="xmpp-vala"', ] -lib_xmpp_vala = library('xmpp-vala', sources, c_args: c_args, vala_args: ['--vapidir', meson.current_source_dir() / 'vapi'], dependencies: dependencies) +vala_args = [ + '--vapidir', meson.current_source_dir() / 'vapi', +] +lib_xmpp_vala = library('xmpp-vala', sources, c_args: c_args, vala_args: vala_args, dependencies: dependencies, version: '0.1', install: true, install_dir: [true, true, true]) dep_xmpp_vala = declare_dependency(link_with: lib_xmpp_vala, include_directories: include_directories('.')) + +install_data('xmpp-vala.deps', install_dir: get_option('datadir') / 'vala/vapi') # TODO: workaround for https://github.com/mesonbuild/meson/issues/9756 diff --git a/xmpp-vala/xmpp-vala.deps b/xmpp-vala/xmpp-vala.deps new file mode 100644 index 00000000..97323d51 --- /dev/null +++ b/xmpp-vala/xmpp-vala.deps @@ -0,0 +1,5 @@ +gdk-pixbuf-2.0 +gee-0.8 +gio-2.0 +glib-2.0 +icu-uc -- cgit v1.2.3-54-g00ecf From 6d838c1c317164fb7e54442312f63d4cb4beaddd Mon Sep 17 00:00:00 2001 From: hrxi Date: Thu, 22 Jun 2023 00:04:59 +0200 Subject: meson: Add http-files plugin --- meson.build | 2 ++ plugins/http-files/meson.build | 22 ++++++++++++++++++++++ plugins/meson.build | 1 + 3 files changed, 25 insertions(+) create mode 100644 plugins/http-files/meson.build create mode 100644 plugins/meson.build diff --git a/meson.build b/meson.build index c4b7fecf..02da2b35 100644 --- a/meson.build +++ b/meson.build @@ -13,6 +13,7 @@ dep_gmodule = dependency('gmodule-2.0') dep_gtk4 = dependency('gtk4') dep_icu_uc = dependency('icu-uc') dep_libadwaita = dependency('libadwaita-1') +dep_libsoup = dependency('libsoup-3.0') dep_m = meson.get_compiler('c').find_library('m', required: false) dep_sqlite3 = dependency('sqlite3', version: '>=3.24') @@ -23,3 +24,4 @@ subdir('qlite') subdir('xmpp-vala') subdir('libdino') subdir('main') +subdir('plugins') diff --git a/plugins/http-files/meson.build b/plugins/http-files/meson.build new file mode 100644 index 00000000..6b0f3820 --- /dev/null +++ b/plugins/http-files/meson.build @@ -0,0 +1,22 @@ +dependencies = [ + dep_dino, + dep_gee, + dep_glib, + dep_gmodule, + dep_gtk4, + dep_libsoup, + dep_qlite, + dep_xmpp_vala, +] +sources = files( + 'src/file_provider.vala', + 'src/file_sender.vala', + 'src/plugin.vala', + 'src/register_plugin.vala', +) + +vala_args = [ + '--define=SOUP_3_0', +] +lib_http_files = shared_library('http-files', sources, name_prefix: '', vala_args: vala_args, dependencies: dependencies, install: true, install_dir: get_option('libdir') / 'dino/plugins') +dep_http_files = declare_dependency(link_with: lib_http_files, include_directories: include_directories('.')) diff --git a/plugins/meson.build b/plugins/meson.build new file mode 100644 index 00000000..88fbb335 --- /dev/null +++ b/plugins/meson.build @@ -0,0 +1 @@ +subdir('http-files') -- cgit v1.2.3-54-g00ecf From 7326ca4d1b61f775666dc53adc23aae51f5b643d Mon Sep 17 00:00:00 2001 From: hrxi Date: Sun, 4 Jun 2023 09:40:29 +0200 Subject: meson: Add openpgp plugin --- meson.build | 1 + plugins/meson.build | 1 + plugins/openpgp/data/gresource.xml | 6 ++++++ plugins/openpgp/meson.build | 43 ++++++++++++++++++++++++++++++++++++++ plugins/openpgp/po/meson.build | 1 + 5 files changed, 52 insertions(+) create mode 100644 plugins/openpgp/data/gresource.xml create mode 100644 plugins/openpgp/meson.build create mode 100644 plugins/openpgp/po/meson.build diff --git a/meson.build b/meson.build index 02da2b35..ef14dbec 100644 --- a/meson.build +++ b/meson.build @@ -10,6 +10,7 @@ dep_gee = dependency('gee-0.8') dep_gio = dependency('gio-2.0') dep_glib = dependency('glib-2.0') dep_gmodule = dependency('gmodule-2.0') +dep_gpgme = dependency('gpgme') dep_gtk4 = dependency('gtk4') dep_icu_uc = dependency('icu-uc') dep_libadwaita = dependency('libadwaita-1') diff --git a/plugins/meson.build b/plugins/meson.build index 88fbb335..bacf9678 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -1 +1,2 @@ subdir('http-files') +subdir('openpgp') diff --git a/plugins/openpgp/data/gresource.xml b/plugins/openpgp/data/gresource.xml new file mode 100644 index 00000000..fbe2e8e9 --- /dev/null +++ b/plugins/openpgp/data/gresource.xml @@ -0,0 +1,6 @@ + + + + account_settings_item.ui + + diff --git a/plugins/openpgp/meson.build b/plugins/openpgp/meson.build new file mode 100644 index 00000000..806494f2 --- /dev/null +++ b/plugins/openpgp/meson.build @@ -0,0 +1,43 @@ +subdir('po') +dependencies = [ + dep_dino, + dep_gee, + dep_glib, + dep_gmodule, + dep_gpgme, + dep_gtk4, + dep_qlite, + dep_xmpp_vala, +] +sources = files( + 'src/account_settings_entry.vala', + 'src/contact_details_provider.vala', + 'src/database.vala', + 'src/encryption_list_entry.vala', + 'src/file_transfer/file_decryptor.vala', + 'src/file_transfer/file_encryptor.vala', + 'src/gpgme_fix.c', + 'src/gpgme_helper.vala', + 'src/manager.vala', + 'src/plugin.vala', + 'src/register_plugin.vala', + 'src/stream_flag.vala', + 'src/stream_module.vala', + 'src/util.vala', + 'vapi/gpg-error.vapi', +) +sources += gnome.compile_resources( + 'resources', + 'data/gresource.xml', + source_dir: 'data', +) +c_args = [ + '-DG_LOG_DOMAIN="OpenPGP"', + '-DGETTEXT_PACKAGE="dino-openpgp"', + '-DLOCALE_INSTALL_DIR="@0@"'.format(get_option('prefix') / get_option('localedir')), +] +vala_args = [ + '--vapidir', meson.current_source_dir() / 'vapi', +] +lib_openpgp = shared_library('openpgp', sources, name_prefix: '', c_args: c_args, vala_args: vala_args, include_directories: include_directories('src'), dependencies: dependencies, install: true, install_dir: get_option('libdir') / 'dino/plugins') +dep_openpgp = declare_dependency(link_with: lib_openpgp, include_directories: include_directories('.')) diff --git a/plugins/openpgp/po/meson.build b/plugins/openpgp/po/meson.build new file mode 100644 index 00000000..ac755b55 --- /dev/null +++ b/plugins/openpgp/po/meson.build @@ -0,0 +1 @@ +i18n.gettext('dino-openpgp') -- cgit v1.2.3-54-g00ecf From 7dd12e7dec0706b0d78f99e7014ee3a12079f1c6 Mon Sep 17 00:00:00 2001 From: hrxi Date: Mon, 12 Jun 2023 23:11:50 +0200 Subject: meson: Add notification-sound plugin --- meson.build | 1 + plugins/meson.build | 1 + plugins/notification-sound/meson.build | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 plugins/notification-sound/meson.build diff --git a/meson.build b/meson.build index ef14dbec..e08255e1 100644 --- a/meson.build +++ b/meson.build @@ -14,6 +14,7 @@ dep_gpgme = dependency('gpgme') dep_gtk4 = dependency('gtk4') dep_icu_uc = dependency('icu-uc') dep_libadwaita = dependency('libadwaita-1') +dep_libcanberra = dependency('libcanberra') dep_libsoup = dependency('libsoup-3.0') dep_m = meson.get_compiler('c').find_library('m', required: false) dep_sqlite3 = dependency('sqlite3', version: '>=3.24') diff --git a/plugins/meson.build b/plugins/meson.build index bacf9678..5b0284f6 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -1,2 +1,3 @@ subdir('http-files') +subdir('notification-sound') subdir('openpgp') diff --git a/plugins/notification-sound/meson.build b/plugins/notification-sound/meson.build new file mode 100644 index 00000000..5a114d86 --- /dev/null +++ b/plugins/notification-sound/meson.build @@ -0,0 +1,19 @@ +dependencies = [ + dep_dino, + dep_gdk_pixbuf, + dep_gee, + dep_glib, + dep_gmodule, + dep_libcanberra, + dep_qlite, + dep_xmpp_vala, +] +sources = files( + 'src/plugin.vala', + 'src/register_plugin.vala', +) +vala_args = [ + '--vapidir', meson.current_source_dir() / 'vapi', +] +lib_notification_sound = shared_library('notification-sound', sources, name_prefix: '', vala_args: vala_args, dependencies: dependencies, install: true, install_dir: get_option('libdir') / 'dino/plugins') +dep_notification_sound = declare_dependency(link_with: lib_notification_sound, include_directories: include_directories('.')) -- cgit v1.2.3-54-g00ecf From 7dd0e0aa4a4dffa9efa0fdf7c8929ac0e1611530 Mon Sep 17 00:00:00 2001 From: hrxi Date: Mon, 12 Jun 2023 23:43:23 +0200 Subject: meson: Add crypto-vala library --- crypto-vala/CMakeLists.txt | 2 +- crypto-vala/crypto-vala.deps | 2 + crypto-vala/meson.build | 23 ++ crypto-vala/vapi/gcrypt.vapi | 872 ---------------------------------------- crypto-vala/vapi/libgcrypt.vapi | 872 ++++++++++++++++++++++++++++++++++++++++ meson.build | 3 + 6 files changed, 901 insertions(+), 873 deletions(-) create mode 100644 crypto-vala/crypto-vala.deps create mode 100644 crypto-vala/meson.build delete mode 100644 crypto-vala/vapi/gcrypt.vapi create mode 100644 crypto-vala/vapi/libgcrypt.vapi diff --git a/crypto-vala/CMakeLists.txt b/crypto-vala/CMakeLists.txt index f1f3f9d7..6dec5292 100644 --- a/crypto-vala/CMakeLists.txt +++ b/crypto-vala/CMakeLists.txt @@ -14,7 +14,7 @@ SOURCES "src/random.vala" "src/srtp.vala" CUSTOM_VAPIS - "${CMAKE_CURRENT_SOURCE_DIR}/vapi/gcrypt.vapi" + "${CMAKE_CURRENT_SOURCE_DIR}/vapi/libgcrypt.vapi" "${CMAKE_CURRENT_SOURCE_DIR}/vapi/libsrtp2.vapi" PACKAGES ${CRYPTO_VALA_PACKAGES} diff --git a/crypto-vala/crypto-vala.deps b/crypto-vala/crypto-vala.deps new file mode 100644 index 00000000..c029e7af --- /dev/null +++ b/crypto-vala/crypto-vala.deps @@ -0,0 +1,2 @@ +gio-2.0 +glib-2.0 diff --git a/crypto-vala/meson.build b/crypto-vala/meson.build new file mode 100644 index 00000000..c3feb4d1 --- /dev/null +++ b/crypto-vala/meson.build @@ -0,0 +1,23 @@ +dependencies = [ + dep_gio, + dep_glib, + dep_libgcrypt, + dep_libsrtp2, +] +sources = files( + 'src/cipher.vala', + 'src/cipher_converter.vala', + 'src/error.vala', + 'src/random.vala', + 'src/srtp.vala', +) +c_args = [ + '-DG_LOG_DOMAIN="crypto-vala"', +] +vala_args = [ + '--vapidir', meson.current_source_dir() / 'vapi', +] +lib_crypto_vala = library('crypto-vala', sources, c_args: c_args, vala_args: vala_args, dependencies: dependencies, version: '0.0', install: true, install_dir: [true, true, true]) +dep_crypto_vala = declare_dependency(link_with: lib_crypto_vala, include_directories: include_directories('.')) + +install_data('crypto-vala.deps', install_dir: get_option('datadir') / 'vala/vapi') # TODO: workaround for https://github.com/mesonbuild/meson/issues/9756 diff --git a/crypto-vala/vapi/gcrypt.vapi b/crypto-vala/vapi/gcrypt.vapi deleted file mode 100644 index 0fa69a02..00000000 --- a/crypto-vala/vapi/gcrypt.vapi +++ /dev/null @@ -1,872 +0,0 @@ -/* gcrypt.vapi - * - * Copyright: - * 2008 Jiqing Qiang - * 2008, 2010, 2012-2013 Evan Nemerson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: - * Jiqing Qiang - * Evan Nemerson - */ - - -[CCode (cheader_filename = "gcrypt.h", lower_case_cprefix = "gcry_")] -namespace GCrypt { - [CCode (cname = "gpg_err_source_t", cprefix = "GPG_ERR_SOURCE_")] - public enum ErrorSource { - UNKNOWN, - GCRYPT, - GPG, - GPGSM, - GPGAGENT, - PINENTRY, - SCD, - GPGME, - KEYBOX, - KSBA, - DIRMNGR, - GSTI, - ANY, - USER_1, - USER_2, - USER_3, - USER_4, - - /* This is one more than the largest allowed entry. */ - DIM - } - - [CCode (cname = "gpg_err_code_t", cprefix = "GPG_ERR_")] - public enum ErrorCode { - NO_ERROR, - GENERAL, - UNKNOWN_PACKET, - UNKNOWN_VERSION, - PUBKEY_ALGO, - DIGEST_ALGO, - BAD_PUBKEY, - BAD_SECKEY, - BAD_SIGNATURE, - NO_PUBKEY, - CHECKSUM, - BAD_PASSPHRASE, - CIPHER_ALGO, - KEYRING_OPEN, - INV_PACKET, - INV_ARMOR, - NO_USER_ID, - NO_SECKEY, - WRONG_SECKEY, - BAD_KEY, - COMPR_ALGO, - NO_PRIME, - NO_ENCODING_METHOD, - NO_ENCRYPTION_SCHEME, - NO_SIGNATURE_SCHEME, - INV_ATTR, - NO_VALUE, - NOT_FOUND, - VALUE_NOT_FOUND, - SYNTAX, - BAD_MPI, - INV_PASSPHRASE, - SIG_CLASS, - RESOURCE_LIMIT, - INV_KEYRING, - TRUSTDB, - BAD_CERT, - INV_USER_ID, - UNEXPECTED, - TIME_CONFLICT, - KEYSERVER, - WRONG_PUBKEY_ALGO, - TRIBUTE_TO_D_A, - WEAK_KEY, - INV_KEYLEN, - INV_ARG, - BAD_URI, - INV_URI, - NETWORK, - UNKNOWN_HOST, - SELFTEST_FAILED, - NOT_ENCRYPTED, - NOT_PROCESSED, - UNUSABLE_PUBKEY, - UNUSABLE_SECKEY, - INV_VALUE, - BAD_CERT_CHAIN, - MISSING_CERT, - NO_DATA, - BUG, - NOT_SUPPORTED, - INV_OP, - TIMEOUT, - INTERNAL, - EOF_GCRYPT, - INV_OBJ, - TOO_SHORT, - TOO_LARGE, - NO_OBJ, - NOT_IMPLEMENTED, - CONFLICT, - INV_CIPHER_MODE, - INV_FLAG, - INV_HANDLE, - TRUNCATED, - INCOMPLETE_LINE, - INV_RESPONSE, - NO_AGENT, - AGENT, - INV_DATA, - ASSUAN_SERVER_FAULT, - ASSUAN, - INV_SESSION_KEY, - INV_SEXP, - UNSUPPORTED_ALGORITHM, - NO_PIN_ENTRY, - PIN_ENTRY, - BAD_PIN, - INV_NAME, - BAD_DATA, - INV_PARAMETER, - WRONG_CARD, - NO_DIRMNGR, - DIRMNGR, - CERT_REVOKED, - NO_CRL_KNOWN, - CRL_TOO_OLD, - LINE_TOO_LONG, - NOT_TRUSTED, - CANCELED, - BAD_CA_CERT, - CERT_EXPIRED, - CERT_TOO_YOUNG, - UNSUPPORTED_CERT, - UNKNOWN_SEXP, - UNSUPPORTED_PROTECTION, - CORRUPTED_PROTECTION, - AMBIGUOUS_NAME, - CARD, - CARD_RESET, - CARD_REMOVED, - INV_CARD, - CARD_NOT_PRESENT, - NO_PKCS15_APP, - NOT_CONFIRMED, - CONFIGURATION, - NO_POLICY_MATCH, - INV_INDEX, - INV_ID, - NO_SCDAEMON, - SCDAEMON, - UNSUPPORTED_PROTOCOL, - BAD_PIN_METHOD, - CARD_NOT_INITIALIZED, - UNSUPPORTED_OPERATION, - WRONG_KEY_USAGE, - NOTHING_FOUND, - WRONG_BLOB_TYPE, - MISSING_VALUE, - HARDWARE, - PIN_BLOCKED, - USE_CONDITIONS, - PIN_NOT_SYNCED, - INV_CRL, - BAD_BER, - INV_BER, - ELEMENT_NOT_FOUND, - IDENTIFIER_NOT_FOUND, - INV_TAG, - INV_LENGTH, - INV_KEYINFO, - UNEXPECTED_TAG, - NOT_DER_ENCODED, - NO_CMS_OBJ, - INV_CMS_OBJ, - UNKNOWN_CMS_OBJ, - UNSUPPORTED_CMS_OBJ, - UNSUPPORTED_ENCODING, - UNSUPPORTED_CMS_VERSION, - UNKNOWN_ALGORITHM, - INV_ENGINE, - PUBKEY_NOT_TRUSTED, - DECRYPT_FAILED, - KEY_EXPIRED, - SIG_EXPIRED, - ENCODING_PROBLEM, - INV_STATE, - DUP_VALUE, - MISSING_ACTION, - MODULE_NOT_FOUND, - INV_OID_STRING, - INV_TIME, - INV_CRL_OBJ, - UNSUPPORTED_CRL_VERSION, - INV_CERT_OBJ, - UNKNOWN_NAME, - LOCALE_PROBLEM, - NOT_LOCKED, - PROTOCOL_VIOLATION, - INV_MAC, - INV_REQUEST, - UNKNOWN_EXTN, - UNKNOWN_CRIT_EXTN, - LOCKED, - UNKNOWN_OPTION, - UNKNOWN_COMMAND, - BUFFER_TOO_SHORT, - SEXP_INV_LEN_SPEC, - SEXP_STRING_TOO_LONG, - SEXP_UNMATCHED_PAREN, - SEXP_NOT_CANONICAL, - SEXP_BAD_CHARACTER, - SEXP_BAD_QUOTATION, - SEXP_ZERO_PREFIX, - SEXP_NESTED_DH, - SEXP_UNMATCHED_DH, - SEXP_UNEXPECTED_PUNC, - SEXP_BAD_HEX_CHAR, - SEXP_ODD_HEX_NUMBERS, - SEXP_BAD_OCT_CHAR, - ASS_GENERAL, - ASS_ACCEPT_FAILED, - ASS_CONNECT_FAILED, - ASS_INV_RESPONSE, - ASS_INV_VALUE, - ASS_INCOMPLETE_LINE, - ASS_LINE_TOO_LONG, - ASS_NESTED_COMMANDS, - ASS_NO_DATA_CB, - ASS_NO_INQUIRE_CB, - ASS_NOT_A_SERVER, - ASS_NOT_A_CLIENT, - ASS_SERVER_START, - ASS_READ_ERROR, - ASS_WRITE_ERROR, - ASS_TOO_MUCH_DATA, - ASS_UNEXPECTED_CMD, - ASS_UNKNOWN_CMD, - ASS_SYNTAX, - ASS_CANCELED, - ASS_NO_INPUT, - ASS_NO_OUTPUT, - ASS_PARAMETER, - ASS_UNKNOWN_INQUIRE, - USER_1, - USER_2, - USER_3, - USER_4, - USER_5, - USER_6, - USER_7, - USER_8, - USER_9, - USER_10, - USER_11, - USER_12, - USER_13, - USER_14, - USER_15, - USER_16, - MISSING_ERRNO, - UNKNOWN_ERRNO, - EOF, - - E2BIG, - EACCES, - EADDRINUSE, - EADDRNOTAVAIL, - EADV, - EAFNOSUPPORT, - EAGAIN, - EALREADY, - EAUTH, - EBACKGROUND, - EBADE, - EBADF, - EBADFD, - EBADMSG, - EBADR, - EBADRPC, - EBADRQC, - EBADSLT, - EBFONT, - EBUSY, - ECANCELED, - ECHILD, - ECHRNG, - ECOMM, - ECONNABORTED, - ECONNREFUSED, - ECONNRESET, - ED, - EDEADLK, - EDEADLOCK, - EDESTADDRREQ, - EDIED, - EDOM, - EDOTDOT, - EDQUOT, - EEXIST, - EFAULT, - EFBIG, - EFTYPE, - EGRATUITOUS, - EGREGIOUS, - EHOSTDOWN, - EHOSTUNREACH, - EIDRM, - EIEIO, - EILSEQ, - EINPROGRESS, - EINTR, - EINVAL, - EIO, - EISCONN, - EISDIR, - EISNAM, - EL2HLT, - EL2NSYNC, - EL3HLT, - EL3RST, - ELIBACC, - ELIBBAD, - ELIBEXEC, - ELIBMAX, - ELIBSCN, - ELNRNG, - ELOOP, - EMEDIUMTYPE, - EMFILE, - EMLINK, - EMSGSIZE, - EMULTIHOP, - ENAMETOOLONG, - ENAVAIL, - ENEEDAUTH, - ENETDOWN, - ENETRESET, - ENETUNREACH, - ENFILE, - ENOANO, - ENOBUFS, - ENOCSI, - ENODATA, - ENODEV, - ENOENT, - ENOEXEC, - ENOLCK, - ENOLINK, - ENOMEDIUM, - ENOMEM, - ENOMSG, - ENONET, - ENOPKG, - ENOPROTOOPT, - ENOSPC, - ENOSR, - ENOSTR, - ENOSYS, - ENOTBLK, - ENOTCONN, - ENOTDIR, - ENOTEMPTY, - ENOTNAM, - ENOTSOCK, - ENOTSUP, - ENOTTY, - ENOTUNIQ, - ENXIO, - EOPNOTSUPP, - EOVERFLOW, - EPERM, - EPFNOSUPPORT, - EPIPE, - EPROCLIM, - EPROCUNAVAIL, - EPROGMISMATCH, - EPROGUNAVAIL, - EPROTO, - EPROTONOSUPPORT, - EPROTOTYPE, - ERANGE, - EREMCHG, - EREMOTE, - EREMOTEIO, - ERESTART, - EROFS, - ERPCMISMATCH, - ESHUTDOWN, - ESOCKTNOSUPPORT, - ESPIPE, - ESRCH, - ESRMNT, - ESTALE, - ESTRPIPE, - ETIME, - ETIMEDOUT, - ETOOMANYREFS, - ETXTBSY, - EUCLEAN, - EUNATCH, - EUSERS, - EWOULDBLOCK, - EXDEV, - EXFULL, - - /* This is one more than the largest allowed entry. */ - CODE_DIM - } - - [CCode (cname = "gcry_error_t", cprefix = "gpg_err_")] - public struct Error : uint { - [CCode (cname = "gcry_err_make")] - public Error (ErrorSource source, ErrorCode code); - [CCode (cname = "gcry_err_make_from_errno")] - public Error.from_errno (ErrorSource source, int err); - public ErrorCode code (); - public ErrorSource source (); - - [CCode (cname = "gcry_strerror")] - public unowned string to_string (); - - [CCode (cname = "gcry_strsource")] - public unowned string source_to_string (); - } - - [CCode (cname = "enum gcry_ctl_cmds", cprefix = "GCRYCTL_")] - public enum ControlCommand { - SET_KEY, - SET_IV, - CFB_SYNC, - RESET, - FINALIZE, - GET_KEYLEN, - GET_BLKLEN, - TEST_ALGO, - IS_SECURE, - GET_ASNOID, - ENABLE_ALGO, - DISABLE_ALGO, - DUMP_RANDOM_STATS, - DUMP_SECMEM_STATS, - GET_ALGO_NPKEY, - GET_ALGO_NSKEY, - GET_ALGO_NSIGN, - GET_ALGO_NENCR, - SET_VERBOSITY, - SET_DEBUG_FLAGS, - CLEAR_DEBUG_FLAGS, - USE_SECURE_RNDPOOL, - DUMP_MEMORY_STATS, - INIT_SECMEM, - TERM_SECMEM, - DISABLE_SECMEM_WARN, - SUSPEND_SECMEM_WARN, - RESUME_SECMEM_WARN, - DROP_PRIVS, - ENABLE_M_GUARD, - START_DUMP, - STOP_DUMP, - GET_ALGO_USAGE, - IS_ALGO_ENABLED, - DISABLE_INTERNAL_LOCKING, - DISABLE_SECMEM, - INITIALIZATION_FINISHED, - INITIALIZATION_FINISHED_P, - ANY_INITIALIZATION_P, - SET_CBC_CTS, - SET_CBC_MAC, - SET_CTR, - ENABLE_QUICK_RANDOM, - SET_RANDOM_SEED_FILE, - UPDATE_RANDOM_SEED_FILE, - SET_THREAD_CBS, - FAST_POLL - } - public Error control (ControlCommand cmd, ...); - - [CCode (lower_case_cname = "cipher_")] - namespace Cipher { - [CCode (cname = "enum gcry_cipher_algos", cprefix = "GCRY_CIPHER_")] - public enum Algorithm { - NONE, - IDEA, - 3DES, - CAST5, - BLOWFISH, - SAFER_SK128, - DES_SK, - AES, - AES128, - RIJNDAEL, - RIJNDAEL128, - AES192, - RIJNDAEL192, - AES256, - RIJNDAEL256, - TWOFISH, - TWOFISH128, - ARCFOUR, - DES, - SERPENT128, - SERPENT192, - SERPENT256, - RFC2268_40, - RFC2268_128, - SEED, - CAMELLIA128, - CAMELLIA192, - CAMELLIA256, - SALSA20, - SALSA20R12, - GOST28147, - CHACHA20; - - [CCode (cname = "gcry_cipher_algo_info")] - public Error info (ControlCommand what, ref uchar[] buffer); - [CCode (cname = "gcry_cipher_algo_name")] - public unowned string to_string (); - [CCode (cname = "gcry_cipher_map_name")] - public static Algorithm from_string (string name); - [CCode (cname = "gcry_cipher_map_oid")] - public static Algorithm from_oid (string oid); - } - - [CCode (cname = "enum gcry_cipher_modes", cprefix = "GCRY_CIPHER_MODE_")] - public enum Mode { - NONE, /* No mode specified */ - ECB, /* Electronic Codebook */ - CFB, /* Cipher Feedback */ - CBC, /* Cipher Block Chaining */ - STREAM, /* Used with stream ciphers */ - OFB, /* Output Feedback */ - CTR, /* Counter */ - AESWRAP, /* AES-WRAP algorithm */ - CCM, /* Counter with CBC-MAC */ - GCM, /* Galois/Counter Mode */ - POLY1305, /* Poly1305 based AEAD mode */ - OCB, /* OCB3 mode */ - CFB8, /* Cipher Feedback /* Poly1305 based AEAD mode. */ - XTS; /* XTS mode */ - - public unowned string to_string () { - switch (this) { - case ECB: return "ECB"; - case CFB: return "CFB"; - case CBC: return "CBC"; - case STREAM: return "STREAM"; - case OFB: return "OFB"; - case CTR: return "CTR"; - case AESWRAP: return "AESWRAP"; - case GCM: return "GCM"; - case POLY1305: return "POLY1305"; - case OCB: return "OCB"; - case CFB8: return "CFB8"; - case XTS: return "XTS"; - } - return "NONE"; - } - - public static Mode from_string (string name) { - switch (name) { - case "ECB": return ECB; - case "CFB": return CFB; - case "CBC": return CBC; - case "STREAM": return STREAM; - case "OFB": return OFB; - case "CTR": return CTR; - case "AESWRAP": return AESWRAP; - case "GCM": return GCM; - case "POLY1305": return POLY1305; - case "OCB": return OCB; - case "CFB8": return CFB8; - case "XTS": return XTS; - } - return NONE; - } - } - - [CCode (cname = "enum gcry_cipher_flags", cprefix = "GCRY_CIPHER_")] - public enum Flag { - SECURE, /* Allocate in secure memory. */ - ENABLE_SYNC, /* Enable CFB sync mode. */ - CBC_CTS, /* Enable CBC cipher text stealing (CTS). */ - CBC_MAC /* Enable CBC message auth. code (MAC). */ - } - [CCode (cname = "gcry_cipher_hd_t", lower_case_cprefix = "gcry_cipher_", free_function = "gcry_cipher_close")] - [SimpleType] - public struct Cipher { - public static Error open (out Cipher cipher, Algorithm algo, Mode mode, Flag flags); - public void close (); - [CCode (cname = "gcry_cipher_ctl")] - public Error control (ControlCommand cmd, uchar[] buffer); - public Error info (ControlCommand what, ref uchar[] buffer); - - public Error encrypt (uchar[] out_buffer, uchar[] in_buffer); - public Error decrypt (uchar[] out_buffer, uchar[] in_buffer); - - [CCode (cname = "gcry_cipher_setkey")] - public Error set_key (uchar[] key_data); - [CCode (cname = "gcry_cipher_setiv")] - public Error set_iv (uchar[] iv_data); - [CCode (cname = "gcry_cipher_setctr")] - public Error set_counter_vector (uchar[] counter_vector); - - [CCode (cname = "gcry_cipher_gettag")] - public Error get_tag(uchar[] out_buffer); - [CCode (cname = "gcry_cipher_checktag")] - public Error check_tag(uchar[] in_buffer); - - public Error reset (); - public Error sync (); - } - } - - [Compact, CCode (cname = "struct gcry_md_handle", cprefix = "gcry_md_", free_function = "gcry_md_close")] - public class Hash { - [CCode (cname = "enum gcry_md_algos", cprefix = "GCRY_MD_")] - public enum Algorithm { - NONE, - SHA1, - RMD160, - MD5, - MD4, - MD2, - TIGER, - TIGER1, - TIGER2, - HAVAL, - SHA224, - SHA256, - SHA384, - SHA512, - SHA3_224, - SHA3_256, - SHA3_384, - SHA3_512, - SHAKE128, - SHAKE256, - CRC32, - CRC32_RFC1510, - CRC24_RFC2440, - WHIRLPOOL, - GOSTR3411_94, - STRIBOG256, - STRIBOG512; - - [CCode (cname = "gcry_md_get_algo_dlen")] - public size_t get_digest_length (); - [CCode (cname = "gcry_md_algo_info")] - public Error info (ControlCommand what, ref uchar[] buffer); - [CCode (cname = "gcry_md_algo_name")] - public unowned string to_string (); - [CCode (cname = "gcry_md_map_name")] - public static Algorithm from_string (string name); - [CCode (cname = "gcry_md_test_algo")] - public Error is_available (); - [CCode (cname = "gcry_md_get_asnoid")] - public Error get_oid (uchar[] buffer); - } - - [CCode (cname = "enum gcry_md_flags", cprefix = "GCRY_MD_FLAG_")] - public enum Flag { - SECURE, - HMAC, - BUGEMU1 - } - - public static Error open (out Hash hash, Algorithm algo, Flag flag); - public void close (); - public Error enable (Algorithm algo); - [CCode (instance_pos = -1)] - public Error copy (out Hash dst); - public void reset (); - [CCode (cname = "enum gcry_md_ctl")] - public Error control (ControlCommand cmd, uchar[] buffer); - public void write (uchar[] buffer); - [CCode (array_length = false)] - public unowned uchar[] read (Algorithm algo); - public static void hash_buffer (Algorithm algo, [CCode (array_length = false)] uchar[] digest, uchar[] buffer); - public Algorithm get_algo (); - public bool is_enabled (Algorithm algo); - public bool is_secure (); - public Error info (ControlCommand what, uchar[] buffer); - [CCode (cname = "gcry_md_setkey")] - public Error set_key (uchar[] key_data); - public void putc (char c); - public void final (); - public static Error list (ref Algorithm[] algos); - } - - namespace Random { - [CCode (cname = "gcry_random_level_t")] - public enum Level { - [CCode (cname = "GCRY_WEAK_RANDOM")] - WEAK, - [CCode (cname = "GCRY_STRONG_RANDOM")] - STRONG, - [CCode (cname = "GCRY_VERY_STRONG_RANDOM")] - VERY_STRONG - } - - [CCode (cname = "gcry_randomize")] - public static void randomize (uchar[] buffer, Level level = Level.VERY_STRONG); - [CCode (cname = "gcry_fast_random_poll")] - public static Error poll (); - [CCode (cname = "gcry_random_bytes", array_length = false)] - public static uchar[] random_bytes (size_t nbytes, Level level = Level.VERY_STRONG); - [CCode (cname = "gcry_random_bytes_secure")] - public static uchar[] random_bytes_secure (size_t nbytes, Level level = Level.VERY_STRONG); - [CCode (cname = "gcry_create_nonce")] - public static void nonce (uchar[] buffer); - } - - [Compact, CCode (cname = "struct gcry_mpi", cprefix = "gcry_mpi_", free_function = "gcry_mpi_release")] - public class MPI { - [CCode (cname = "enum gcry_mpi_format", cprefix = "GCRYMPI_FMT_")] - public enum Format { - NONE, - STD, - PGP, - SSH, - HEX, - USG - } - - [CCode (cname = "enum gcry_mpi_flag", cprefix = "GCRYMPI_FLAG_")] - public enum Flag { - SECURE, - OPAQUE - } - - public MPI (uint nbits); - [CCode (cname = "gcry_mpi_snew")] - public MPI.secure (uint nbits); - public MPI copy (); - public void set (MPI u); - public void set_ui (ulong u); - public void swap (); - public int cmp (MPI v); - public int cmp_ui (ulong v); - - public static Error scan (out MPI ret, MPI.Format format, [CCode (array_length = false)] uchar[] buffer, size_t buflen, out size_t nscanned); - [CCode (instance_pos = -1)] - public Error print (MPI.Format format, [CCode (array_length = false)] uchar[] buffer, size_t buflen, out size_t nwritter); - [CCode (instance_pos = -1)] - public Error aprint (MPI.Format format, out uchar[] buffer); - - public void add (MPI u, MPI v); - public void add_ui (MPI u, ulong v); - public void addm (MPI u, MPI v, MPI m); - public void sub (MPI u, MPI v); - public void sub_ui (MPI u, MPI v); - public void subm (MPI u, MPI v, MPI m); - public void mul (MPI u, MPI v); - public void mul_ui (MPI u, ulong v); - public void mulm (MPI u, MPI v, MPI m); - public void mul_2exp (MPI u, ulong cnt); - public void div (MPI q, MPI r, MPI dividend, MPI divisor, int round); - public void mod (MPI dividend, MPI divisor); - public void powm (MPI b, MPI e, MPI m); - public int gcd (MPI a, MPI b); - public int invm (MPI a, MPI m); - - public uint get_nbits (); - public int test_bit (uint n); - public void set_bit (uint n); - public void clear_bit (uint n); - public void set_highbit (uint n); - public void clear_highbit (uint n); - public void rshift (MPI a, uint n); - public void lshift (MPI a, uint n); - - public void set_flag (MPI.Flag flag); - public void clear_flag (MPI.Flag flag); - public int get_flag (MPI.Flag flag); - } - - [Compact, CCode (cname = "struct gcry_sexp", free_function = "gcry_sexp_release")] - public class SExp { - [CCode (cprefix = "GCRYSEXP_FMT_")] - public enum Format { - DEFAULT, - CANON, - BASE64, - ADVANCED - } - - public static Error @new (out SExp retsexp, void * buffer, size_t length, int autodetect); - public static Error create (out SExp retsexp, void * buffer, size_t length, int autodetect, GLib.DestroyNotify free_function); - public static Error sscan (out SExp retsexp, out size_t erroff, char[] buffer); - public static Error build (out SExp retsexp, out size_t erroff, string format, ...); - public size_t sprint (Format mode, char[] buffer); - public static size_t canon_len (uchar[] buffer, out size_t erroff, out int errcode); - public SExp find_token (string token, size_t token_length = 0); - public int length (); - public SExp? nth (int number); - public SExp? car (); - public SExp? cdr (); - public unowned char[] nth_data (int number); - public gcry_string nth_string (int number); - public MPI nth_mpi (int number, MPI.Format mpifmt); - } - - [CCode (cname = "char", free_function = "gcry_free")] - public class gcry_string : string { } - - [CCode (lower_case_cprefix = "gcry_pk_")] - namespace PublicKey { - [CCode (cname = "enum gcry_pk_algos")] - public enum Algorithm { - RSA, - ELG_E, - DSA, - ELG, - ECDSA; - - [CCode (cname = "gcry_pk_algo_name")] - public unowned string to_string (); - [CCode (cname = "gcry_pk_map_name")] - public static Algorithm map_name (string name); - } - - public static Error encrypt (out SExp ciphertext, SExp data, SExp pkey); - public static Error decrypt (out SExp plaintext, SExp data, SExp skey); - public static Error sign (out SExp signature, SExp data, SExp skey); - public static Error verify (SExp signature, SExp data, SExp pkey); - public static Error testkey (SExp key); - public static Error genkey (out SExp r_key, SExp s_params); - public static uint get_nbits (SExp key); - } - - [CCode (lower_case_cprefix = "gcry_kdf_")] - namespace KeyDerivation { - [CCode (cname = "gcry_kdf_algos", cprefix = "GCRY_KDF_", has_type_id = false)] - public enum Algorithm { - NONE, - SIMPLE_S2K, - SALTED_S2K, - ITERSALTED_S2K, - PBKDF1, - PBKDF2, - SCRYPT - } - - public GCrypt.Error derive ([CCode (type = "const void*", array_length_type = "size_t")] uint8[] passphrasse, GCrypt.KeyDerivation.Algorithm algo, GCrypt.Hash.Algorithm subalgo, [CCode (type = "const void*", array_length_type = "size_t")] uint8[] salt, ulong iterations, [CCode (type = "void*", array_length_type = "size_t", array_length_pos = 5.5)] uint8[] keybuffer); - } -} diff --git a/crypto-vala/vapi/libgcrypt.vapi b/crypto-vala/vapi/libgcrypt.vapi new file mode 100644 index 00000000..0fa69a02 --- /dev/null +++ b/crypto-vala/vapi/libgcrypt.vapi @@ -0,0 +1,872 @@ +/* gcrypt.vapi + * + * Copyright: + * 2008 Jiqing Qiang + * 2008, 2010, 2012-2013 Evan Nemerson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jiqing Qiang + * Evan Nemerson + */ + + +[CCode (cheader_filename = "gcrypt.h", lower_case_cprefix = "gcry_")] +namespace GCrypt { + [CCode (cname = "gpg_err_source_t", cprefix = "GPG_ERR_SOURCE_")] + public enum ErrorSource { + UNKNOWN, + GCRYPT, + GPG, + GPGSM, + GPGAGENT, + PINENTRY, + SCD, + GPGME, + KEYBOX, + KSBA, + DIRMNGR, + GSTI, + ANY, + USER_1, + USER_2, + USER_3, + USER_4, + + /* This is one more than the largest allowed entry. */ + DIM + } + + [CCode (cname = "gpg_err_code_t", cprefix = "GPG_ERR_")] + public enum ErrorCode { + NO_ERROR, + GENERAL, + UNKNOWN_PACKET, + UNKNOWN_VERSION, + PUBKEY_ALGO, + DIGEST_ALGO, + BAD_PUBKEY, + BAD_SECKEY, + BAD_SIGNATURE, + NO_PUBKEY, + CHECKSUM, + BAD_PASSPHRASE, + CIPHER_ALGO, + KEYRING_OPEN, + INV_PACKET, + INV_ARMOR, + NO_USER_ID, + NO_SECKEY, + WRONG_SECKEY, + BAD_KEY, + COMPR_ALGO, + NO_PRIME, + NO_ENCODING_METHOD, + NO_ENCRYPTION_SCHEME, + NO_SIGNATURE_SCHEME, + INV_ATTR, + NO_VALUE, + NOT_FOUND, + VALUE_NOT_FOUND, + SYNTAX, + BAD_MPI, + INV_PASSPHRASE, + SIG_CLASS, + RESOURCE_LIMIT, + INV_KEYRING, + TRUSTDB, + BAD_CERT, + INV_USER_ID, + UNEXPECTED, + TIME_CONFLICT, + KEYSERVER, + WRONG_PUBKEY_ALGO, + TRIBUTE_TO_D_A, + WEAK_KEY, + INV_KEYLEN, + INV_ARG, + BAD_URI, + INV_URI, + NETWORK, + UNKNOWN_HOST, + SELFTEST_FAILED, + NOT_ENCRYPTED, + NOT_PROCESSED, + UNUSABLE_PUBKEY, + UNUSABLE_SECKEY, + INV_VALUE, + BAD_CERT_CHAIN, + MISSING_CERT, + NO_DATA, + BUG, + NOT_SUPPORTED, + INV_OP, + TIMEOUT, + INTERNAL, + EOF_GCRYPT, + INV_OBJ, + TOO_SHORT, + TOO_LARGE, + NO_OBJ, + NOT_IMPLEMENTED, + CONFLICT, + INV_CIPHER_MODE, + INV_FLAG, + INV_HANDLE, + TRUNCATED, + INCOMPLETE_LINE, + INV_RESPONSE, + NO_AGENT, + AGENT, + INV_DATA, + ASSUAN_SERVER_FAULT, + ASSUAN, + INV_SESSION_KEY, + INV_SEXP, + UNSUPPORTED_ALGORITHM, + NO_PIN_ENTRY, + PIN_ENTRY, + BAD_PIN, + INV_NAME, + BAD_DATA, + INV_PARAMETER, + WRONG_CARD, + NO_DIRMNGR, + DIRMNGR, + CERT_REVOKED, + NO_CRL_KNOWN, + CRL_TOO_OLD, + LINE_TOO_LONG, + NOT_TRUSTED, + CANCELED, + BAD_CA_CERT, + CERT_EXPIRED, + CERT_TOO_YOUNG, + UNSUPPORTED_CERT, + UNKNOWN_SEXP, + UNSUPPORTED_PROTECTION, + CORRUPTED_PROTECTION, + AMBIGUOUS_NAME, + CARD, + CARD_RESET, + CARD_REMOVED, + INV_CARD, + CARD_NOT_PRESENT, + NO_PKCS15_APP, + NOT_CONFIRMED, + CONFIGURATION, + NO_POLICY_MATCH, + INV_INDEX, + INV_ID, + NO_SCDAEMON, + SCDAEMON, + UNSUPPORTED_PROTOCOL, + BAD_PIN_METHOD, + CARD_NOT_INITIALIZED, + UNSUPPORTED_OPERATION, + WRONG_KEY_USAGE, + NOTHING_FOUND, + WRONG_BLOB_TYPE, + MISSING_VALUE, + HARDWARE, + PIN_BLOCKED, + USE_CONDITIONS, + PIN_NOT_SYNCED, + INV_CRL, + BAD_BER, + INV_BER, + ELEMENT_NOT_FOUND, + IDENTIFIER_NOT_FOUND, + INV_TAG, + INV_LENGTH, + INV_KEYINFO, + UNEXPECTED_TAG, + NOT_DER_ENCODED, + NO_CMS_OBJ, + INV_CMS_OBJ, + UNKNOWN_CMS_OBJ, + UNSUPPORTED_CMS_OBJ, + UNSUPPORTED_ENCODING, + UNSUPPORTED_CMS_VERSION, + UNKNOWN_ALGORITHM, + INV_ENGINE, + PUBKEY_NOT_TRUSTED, + DECRYPT_FAILED, + KEY_EXPIRED, + SIG_EXPIRED, + ENCODING_PROBLEM, + INV_STATE, + DUP_VALUE, + MISSING_ACTION, + MODULE_NOT_FOUND, + INV_OID_STRING, + INV_TIME, + INV_CRL_OBJ, + UNSUPPORTED_CRL_VERSION, + INV_CERT_OBJ, + UNKNOWN_NAME, + LOCALE_PROBLEM, + NOT_LOCKED, + PROTOCOL_VIOLATION, + INV_MAC, + INV_REQUEST, + UNKNOWN_EXTN, + UNKNOWN_CRIT_EXTN, + LOCKED, + UNKNOWN_OPTION, + UNKNOWN_COMMAND, + BUFFER_TOO_SHORT, + SEXP_INV_LEN_SPEC, + SEXP_STRING_TOO_LONG, + SEXP_UNMATCHED_PAREN, + SEXP_NOT_CANONICAL, + SEXP_BAD_CHARACTER, + SEXP_BAD_QUOTATION, + SEXP_ZERO_PREFIX, + SEXP_NESTED_DH, + SEXP_UNMATCHED_DH, + SEXP_UNEXPECTED_PUNC, + SEXP_BAD_HEX_CHAR, + SEXP_ODD_HEX_NUMBERS, + SEXP_BAD_OCT_CHAR, + ASS_GENERAL, + ASS_ACCEPT_FAILED, + ASS_CONNECT_FAILED, + ASS_INV_RESPONSE, + ASS_INV_VALUE, + ASS_INCOMPLETE_LINE, + ASS_LINE_TOO_LONG, + ASS_NESTED_COMMANDS, + ASS_NO_DATA_CB, + ASS_NO_INQUIRE_CB, + ASS_NOT_A_SERVER, + ASS_NOT_A_CLIENT, + ASS_SERVER_START, + ASS_READ_ERROR, + ASS_WRITE_ERROR, + ASS_TOO_MUCH_DATA, + ASS_UNEXPECTED_CMD, + ASS_UNKNOWN_CMD, + ASS_SYNTAX, + ASS_CANCELED, + ASS_NO_INPUT, + ASS_NO_OUTPUT, + ASS_PARAMETER, + ASS_UNKNOWN_INQUIRE, + USER_1, + USER_2, + USER_3, + USER_4, + USER_5, + USER_6, + USER_7, + USER_8, + USER_9, + USER_10, + USER_11, + USER_12, + USER_13, + USER_14, + USER_15, + USER_16, + MISSING_ERRNO, + UNKNOWN_ERRNO, + EOF, + + E2BIG, + EACCES, + EADDRINUSE, + EADDRNOTAVAIL, + EADV, + EAFNOSUPPORT, + EAGAIN, + EALREADY, + EAUTH, + EBACKGROUND, + EBADE, + EBADF, + EBADFD, + EBADMSG, + EBADR, + EBADRPC, + EBADRQC, + EBADSLT, + EBFONT, + EBUSY, + ECANCELED, + ECHILD, + ECHRNG, + ECOMM, + ECONNABORTED, + ECONNREFUSED, + ECONNRESET, + ED, + EDEADLK, + EDEADLOCK, + EDESTADDRREQ, + EDIED, + EDOM, + EDOTDOT, + EDQUOT, + EEXIST, + EFAULT, + EFBIG, + EFTYPE, + EGRATUITOUS, + EGREGIOUS, + EHOSTDOWN, + EHOSTUNREACH, + EIDRM, + EIEIO, + EILSEQ, + EINPROGRESS, + EINTR, + EINVAL, + EIO, + EISCONN, + EISDIR, + EISNAM, + EL2HLT, + EL2NSYNC, + EL3HLT, + EL3RST, + ELIBACC, + ELIBBAD, + ELIBEXEC, + ELIBMAX, + ELIBSCN, + ELNRNG, + ELOOP, + EMEDIUMTYPE, + EMFILE, + EMLINK, + EMSGSIZE, + EMULTIHOP, + ENAMETOOLONG, + ENAVAIL, + ENEEDAUTH, + ENETDOWN, + ENETRESET, + ENETUNREACH, + ENFILE, + ENOANO, + ENOBUFS, + ENOCSI, + ENODATA, + ENODEV, + ENOENT, + ENOEXEC, + ENOLCK, + ENOLINK, + ENOMEDIUM, + ENOMEM, + ENOMSG, + ENONET, + ENOPKG, + ENOPROTOOPT, + ENOSPC, + ENOSR, + ENOSTR, + ENOSYS, + ENOTBLK, + ENOTCONN, + ENOTDIR, + ENOTEMPTY, + ENOTNAM, + ENOTSOCK, + ENOTSUP, + ENOTTY, + ENOTUNIQ, + ENXIO, + EOPNOTSUPP, + EOVERFLOW, + EPERM, + EPFNOSUPPORT, + EPIPE, + EPROCLIM, + EPROCUNAVAIL, + EPROGMISMATCH, + EPROGUNAVAIL, + EPROTO, + EPROTONOSUPPORT, + EPROTOTYPE, + ERANGE, + EREMCHG, + EREMOTE, + EREMOTEIO, + ERESTART, + EROFS, + ERPCMISMATCH, + ESHUTDOWN, + ESOCKTNOSUPPORT, + ESPIPE, + ESRCH, + ESRMNT, + ESTALE, + ESTRPIPE, + ETIME, + ETIMEDOUT, + ETOOMANYREFS, + ETXTBSY, + EUCLEAN, + EUNATCH, + EUSERS, + EWOULDBLOCK, + EXDEV, + EXFULL, + + /* This is one more than the largest allowed entry. */ + CODE_DIM + } + + [CCode (cname = "gcry_error_t", cprefix = "gpg_err_")] + public struct Error : uint { + [CCode (cname = "gcry_err_make")] + public Error (ErrorSource source, ErrorCode code); + [CCode (cname = "gcry_err_make_from_errno")] + public Error.from_errno (ErrorSource source, int err); + public ErrorCode code (); + public ErrorSource source (); + + [CCode (cname = "gcry_strerror")] + public unowned string to_string (); + + [CCode (cname = "gcry_strsource")] + public unowned string source_to_string (); + } + + [CCode (cname = "enum gcry_ctl_cmds", cprefix = "GCRYCTL_")] + public enum ControlCommand { + SET_KEY, + SET_IV, + CFB_SYNC, + RESET, + FINALIZE, + GET_KEYLEN, + GET_BLKLEN, + TEST_ALGO, + IS_SECURE, + GET_ASNOID, + ENABLE_ALGO, + DISABLE_ALGO, + DUMP_RANDOM_STATS, + DUMP_SECMEM_STATS, + GET_ALGO_NPKEY, + GET_ALGO_NSKEY, + GET_ALGO_NSIGN, + GET_ALGO_NENCR, + SET_VERBOSITY, + SET_DEBUG_FLAGS, + CLEAR_DEBUG_FLAGS, + USE_SECURE_RNDPOOL, + DUMP_MEMORY_STATS, + INIT_SECMEM, + TERM_SECMEM, + DISABLE_SECMEM_WARN, + SUSPEND_SECMEM_WARN, + RESUME_SECMEM_WARN, + DROP_PRIVS, + ENABLE_M_GUARD, + START_DUMP, + STOP_DUMP, + GET_ALGO_USAGE, + IS_ALGO_ENABLED, + DISABLE_INTERNAL_LOCKING, + DISABLE_SECMEM, + INITIALIZATION_FINISHED, + INITIALIZATION_FINISHED_P, + ANY_INITIALIZATION_P, + SET_CBC_CTS, + SET_CBC_MAC, + SET_CTR, + ENABLE_QUICK_RANDOM, + SET_RANDOM_SEED_FILE, + UPDATE_RANDOM_SEED_FILE, + SET_THREAD_CBS, + FAST_POLL + } + public Error control (ControlCommand cmd, ...); + + [CCode (lower_case_cname = "cipher_")] + namespace Cipher { + [CCode (cname = "enum gcry_cipher_algos", cprefix = "GCRY_CIPHER_")] + public enum Algorithm { + NONE, + IDEA, + 3DES, + CAST5, + BLOWFISH, + SAFER_SK128, + DES_SK, + AES, + AES128, + RIJNDAEL, + RIJNDAEL128, + AES192, + RIJNDAEL192, + AES256, + RIJNDAEL256, + TWOFISH, + TWOFISH128, + ARCFOUR, + DES, + SERPENT128, + SERPENT192, + SERPENT256, + RFC2268_40, + RFC2268_128, + SEED, + CAMELLIA128, + CAMELLIA192, + CAMELLIA256, + SALSA20, + SALSA20R12, + GOST28147, + CHACHA20; + + [CCode (cname = "gcry_cipher_algo_info")] + public Error info (ControlCommand what, ref uchar[] buffer); + [CCode (cname = "gcry_cipher_algo_name")] + public unowned string to_string (); + [CCode (cname = "gcry_cipher_map_name")] + public static Algorithm from_string (string name); + [CCode (cname = "gcry_cipher_map_oid")] + public static Algorithm from_oid (string oid); + } + + [CCode (cname = "enum gcry_cipher_modes", cprefix = "GCRY_CIPHER_MODE_")] + public enum Mode { + NONE, /* No mode specified */ + ECB, /* Electronic Codebook */ + CFB, /* Cipher Feedback */ + CBC, /* Cipher Block Chaining */ + STREAM, /* Used with stream ciphers */ + OFB, /* Output Feedback */ + CTR, /* Counter */ + AESWRAP, /* AES-WRAP algorithm */ + CCM, /* Counter with CBC-MAC */ + GCM, /* Galois/Counter Mode */ + POLY1305, /* Poly1305 based AEAD mode */ + OCB, /* OCB3 mode */ + CFB8, /* Cipher Feedback /* Poly1305 based AEAD mode. */ + XTS; /* XTS mode */ + + public unowned string to_string () { + switch (this) { + case ECB: return "ECB"; + case CFB: return "CFB"; + case CBC: return "CBC"; + case STREAM: return "STREAM"; + case OFB: return "OFB"; + case CTR: return "CTR"; + case AESWRAP: return "AESWRAP"; + case GCM: return "GCM"; + case POLY1305: return "POLY1305"; + case OCB: return "OCB"; + case CFB8: return "CFB8"; + case XTS: return "XTS"; + } + return "NONE"; + } + + public static Mode from_string (string name) { + switch (name) { + case "ECB": return ECB; + case "CFB": return CFB; + case "CBC": return CBC; + case "STREAM": return STREAM; + case "OFB": return OFB; + case "CTR": return CTR; + case "AESWRAP": return AESWRAP; + case "GCM": return GCM; + case "POLY1305": return POLY1305; + case "OCB": return OCB; + case "CFB8": return CFB8; + case "XTS": return XTS; + } + return NONE; + } + } + + [CCode (cname = "enum gcry_cipher_flags", cprefix = "GCRY_CIPHER_")] + public enum Flag { + SECURE, /* Allocate in secure memory. */ + ENABLE_SYNC, /* Enable CFB sync mode. */ + CBC_CTS, /* Enable CBC cipher text stealing (CTS). */ + CBC_MAC /* Enable CBC message auth. code (MAC). */ + } + [CCode (cname = "gcry_cipher_hd_t", lower_case_cprefix = "gcry_cipher_", free_function = "gcry_cipher_close")] + [SimpleType] + public struct Cipher { + public static Error open (out Cipher cipher, Algorithm algo, Mode mode, Flag flags); + public void close (); + [CCode (cname = "gcry_cipher_ctl")] + public Error control (ControlCommand cmd, uchar[] buffer); + public Error info (ControlCommand what, ref uchar[] buffer); + + public Error encrypt (uchar[] out_buffer, uchar[] in_buffer); + public Error decrypt (uchar[] out_buffer, uchar[] in_buffer); + + [CCode (cname = "gcry_cipher_setkey")] + public Error set_key (uchar[] key_data); + [CCode (cname = "gcry_cipher_setiv")] + public Error set_iv (uchar[] iv_data); + [CCode (cname = "gcry_cipher_setctr")] + public Error set_counter_vector (uchar[] counter_vector); + + [CCode (cname = "gcry_cipher_gettag")] + public Error get_tag(uchar[] out_buffer); + [CCode (cname = "gcry_cipher_checktag")] + public Error check_tag(uchar[] in_buffer); + + public Error reset (); + public Error sync (); + } + } + + [Compact, CCode (cname = "struct gcry_md_handle", cprefix = "gcry_md_", free_function = "gcry_md_close")] + public class Hash { + [CCode (cname = "enum gcry_md_algos", cprefix = "GCRY_MD_")] + public enum Algorithm { + NONE, + SHA1, + RMD160, + MD5, + MD4, + MD2, + TIGER, + TIGER1, + TIGER2, + HAVAL, + SHA224, + SHA256, + SHA384, + SHA512, + SHA3_224, + SHA3_256, + SHA3_384, + SHA3_512, + SHAKE128, + SHAKE256, + CRC32, + CRC32_RFC1510, + CRC24_RFC2440, + WHIRLPOOL, + GOSTR3411_94, + STRIBOG256, + STRIBOG512; + + [CCode (cname = "gcry_md_get_algo_dlen")] + public size_t get_digest_length (); + [CCode (cname = "gcry_md_algo_info")] + public Error info (ControlCommand what, ref uchar[] buffer); + [CCode (cname = "gcry_md_algo_name")] + public unowned string to_string (); + [CCode (cname = "gcry_md_map_name")] + public static Algorithm from_string (string name); + [CCode (cname = "gcry_md_test_algo")] + public Error is_available (); + [CCode (cname = "gcry_md_get_asnoid")] + public Error get_oid (uchar[] buffer); + } + + [CCode (cname = "enum gcry_md_flags", cprefix = "GCRY_MD_FLAG_")] + public enum Flag { + SECURE, + HMAC, + BUGEMU1 + } + + public static Error open (out Hash hash, Algorithm algo, Flag flag); + public void close (); + public Error enable (Algorithm algo); + [CCode (instance_pos = -1)] + public Error copy (out Hash dst); + public void reset (); + [CCode (cname = "enum gcry_md_ctl")] + public Error control (ControlCommand cmd, uchar[] buffer); + public void write (uchar[] buffer); + [CCode (array_length = false)] + public unowned uchar[] read (Algorithm algo); + public static void hash_buffer (Algorithm algo, [CCode (array_length = false)] uchar[] digest, uchar[] buffer); + public Algorithm get_algo (); + public bool is_enabled (Algorithm algo); + public bool is_secure (); + public Error info (ControlCommand what, uchar[] buffer); + [CCode (cname = "gcry_md_setkey")] + public Error set_key (uchar[] key_data); + public void putc (char c); + public void final (); + public static Error list (ref Algorithm[] algos); + } + + namespace Random { + [CCode (cname = "gcry_random_level_t")] + public enum Level { + [CCode (cname = "GCRY_WEAK_RANDOM")] + WEAK, + [CCode (cname = "GCRY_STRONG_RANDOM")] + STRONG, + [CCode (cname = "GCRY_VERY_STRONG_RANDOM")] + VERY_STRONG + } + + [CCode (cname = "gcry_randomize")] + public static void randomize (uchar[] buffer, Level level = Level.VERY_STRONG); + [CCode (cname = "gcry_fast_random_poll")] + public static Error poll (); + [CCode (cname = "gcry_random_bytes", array_length = false)] + public static uchar[] random_bytes (size_t nbytes, Level level = Level.VERY_STRONG); + [CCode (cname = "gcry_random_bytes_secure")] + public static uchar[] random_bytes_secure (size_t nbytes, Level level = Level.VERY_STRONG); + [CCode (cname = "gcry_create_nonce")] + public static void nonce (uchar[] buffer); + } + + [Compact, CCode (cname = "struct gcry_mpi", cprefix = "gcry_mpi_", free_function = "gcry_mpi_release")] + public class MPI { + [CCode (cname = "enum gcry_mpi_format", cprefix = "GCRYMPI_FMT_")] + public enum Format { + NONE, + STD, + PGP, + SSH, + HEX, + USG + } + + [CCode (cname = "enum gcry_mpi_flag", cprefix = "GCRYMPI_FLAG_")] + public enum Flag { + SECURE, + OPAQUE + } + + public MPI (uint nbits); + [CCode (cname = "gcry_mpi_snew")] + public MPI.secure (uint nbits); + public MPI copy (); + public void set (MPI u); + public void set_ui (ulong u); + public void swap (); + public int cmp (MPI v); + public int cmp_ui (ulong v); + + public static Error scan (out MPI ret, MPI.Format format, [CCode (array_length = false)] uchar[] buffer, size_t buflen, out size_t nscanned); + [CCode (instance_pos = -1)] + public Error print (MPI.Format format, [CCode (array_length = false)] uchar[] buffer, size_t buflen, out size_t nwritter); + [CCode (instance_pos = -1)] + public Error aprint (MPI.Format format, out uchar[] buffer); + + public void add (MPI u, MPI v); + public void add_ui (MPI u, ulong v); + public void addm (MPI u, MPI v, MPI m); + public void sub (MPI u, MPI v); + public void sub_ui (MPI u, MPI v); + public void subm (MPI u, MPI v, MPI m); + public void mul (MPI u, MPI v); + public void mul_ui (MPI u, ulong v); + public void mulm (MPI u, MPI v, MPI m); + public void mul_2exp (MPI u, ulong cnt); + public void div (MPI q, MPI r, MPI dividend, MPI divisor, int round); + public void mod (MPI dividend, MPI divisor); + public void powm (MPI b, MPI e, MPI m); + public int gcd (MPI a, MPI b); + public int invm (MPI a, MPI m); + + public uint get_nbits (); + public int test_bit (uint n); + public void set_bit (uint n); + public void clear_bit (uint n); + public void set_highbit (uint n); + public void clear_highbit (uint n); + public void rshift (MPI a, uint n); + public void lshift (MPI a, uint n); + + public void set_flag (MPI.Flag flag); + public void clear_flag (MPI.Flag flag); + public int get_flag (MPI.Flag flag); + } + + [Compact, CCode (cname = "struct gcry_sexp", free_function = "gcry_sexp_release")] + public class SExp { + [CCode (cprefix = "GCRYSEXP_FMT_")] + public enum Format { + DEFAULT, + CANON, + BASE64, + ADVANCED + } + + public static Error @new (out SExp retsexp, void * buffer, size_t length, int autodetect); + public static Error create (out SExp retsexp, void * buffer, size_t length, int autodetect, GLib.DestroyNotify free_function); + public static Error sscan (out SExp retsexp, out size_t erroff, char[] buffer); + public static Error build (out SExp retsexp, out size_t erroff, string format, ...); + public size_t sprint (Format mode, char[] buffer); + public static size_t canon_len (uchar[] buffer, out size_t erroff, out int errcode); + public SExp find_token (string token, size_t token_length = 0); + public int length (); + public SExp? nth (int number); + public SExp? car (); + public SExp? cdr (); + public unowned char[] nth_data (int number); + public gcry_string nth_string (int number); + public MPI nth_mpi (int number, MPI.Format mpifmt); + } + + [CCode (cname = "char", free_function = "gcry_free")] + public class gcry_string : string { } + + [CCode (lower_case_cprefix = "gcry_pk_")] + namespace PublicKey { + [CCode (cname = "enum gcry_pk_algos")] + public enum Algorithm { + RSA, + ELG_E, + DSA, + ELG, + ECDSA; + + [CCode (cname = "gcry_pk_algo_name")] + public unowned string to_string (); + [CCode (cname = "gcry_pk_map_name")] + public static Algorithm map_name (string name); + } + + public static Error encrypt (out SExp ciphertext, SExp data, SExp pkey); + public static Error decrypt (out SExp plaintext, SExp data, SExp skey); + public static Error sign (out SExp signature, SExp data, SExp skey); + public static Error verify (SExp signature, SExp data, SExp pkey); + public static Error testkey (SExp key); + public static Error genkey (out SExp r_key, SExp s_params); + public static uint get_nbits (SExp key); + } + + [CCode (lower_case_cprefix = "gcry_kdf_")] + namespace KeyDerivation { + [CCode (cname = "gcry_kdf_algos", cprefix = "GCRY_KDF_", has_type_id = false)] + public enum Algorithm { + NONE, + SIMPLE_S2K, + SALTED_S2K, + ITERSALTED_S2K, + PBKDF1, + PBKDF2, + SCRYPT + } + + public GCrypt.Error derive ([CCode (type = "const void*", array_length_type = "size_t")] uint8[] passphrasse, GCrypt.KeyDerivation.Algorithm algo, GCrypt.Hash.Algorithm subalgo, [CCode (type = "const void*", array_length_type = "size_t")] uint8[] salt, ulong iterations, [CCode (type = "void*", array_length_type = "size_t", array_length_pos = 5.5)] uint8[] keybuffer); + } +} diff --git a/meson.build b/meson.build index e08255e1..d0888be3 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,8 @@ dep_gtk4 = dependency('gtk4') dep_icu_uc = dependency('icu-uc') dep_libadwaita = dependency('libadwaita-1') dep_libcanberra = dependency('libcanberra') +dep_libgcrypt = dependency('libgcrypt') +dep_libsrtp2 = dependency('libsrtp2') dep_libsoup = dependency('libsoup-3.0') dep_m = meson.get_compiler('c').find_library('m', required: false) dep_sqlite3 = dependency('sqlite3', version: '>=3.24') @@ -26,4 +28,5 @@ subdir('qlite') subdir('xmpp-vala') subdir('libdino') subdir('main') +subdir('crypto-vala') subdir('plugins') -- cgit v1.2.3-54-g00ecf From 3edda368f33c1ffbdcb76c41a32953f50b6ef6bc Mon Sep 17 00:00:00 2001 From: hrxi Date: Mon, 12 Jun 2023 23:50:16 +0200 Subject: meson: Add ice plugin --- meson.build | 2 ++ plugins/ice/meson.build | 28 ++++++++++++++++++++++++++++ plugins/meson.build | 1 + 3 files changed, 31 insertions(+) create mode 100644 plugins/ice/meson.build diff --git a/meson.build b/meson.build index d0888be3..7f86f002 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,7 @@ dep_gdk_pixbuf = dependency('gdk-pixbuf-2.0') dep_gee = dependency('gee-0.8') dep_gio = dependency('gio-2.0') dep_glib = dependency('glib-2.0') +dep_gnutls = dependency('gnutls') dep_gmodule = dependency('gmodule-2.0') dep_gpgme = dependency('gpgme') dep_gtk4 = dependency('gtk4') @@ -18,6 +19,7 @@ dep_libcanberra = dependency('libcanberra') dep_libgcrypt = dependency('libgcrypt') dep_libsrtp2 = dependency('libsrtp2') dep_libsoup = dependency('libsoup-3.0') +dep_nice = dependency('nice', version: '>=0.1.15') dep_m = meson.get_compiler('c').find_library('m', required: false) dep_sqlite3 = dependency('sqlite3', version: '>=3.24') diff --git a/plugins/ice/meson.build b/plugins/ice/meson.build new file mode 100644 index 00000000..40e54ce3 --- /dev/null +++ b/plugins/ice/meson.build @@ -0,0 +1,28 @@ +dependencies = [ + dep_crypto_vala, + dep_dino, + dep_gdk_pixbuf, + dep_gee, + dep_glib, + dep_gmodule, + dep_gnutls, + dep_nice, + dep_qlite, + dep_xmpp_vala, +] +sources = files( + 'src/dtls_srtp.vala', + 'src/module.vala', + 'src/plugin.vala', + 'src/transport_parameters.vala', + 'src/util.vala', + 'src/register_plugin.vala', +) +c_args = [ + '-DG_LOG_DOMAIN="ice"', +] +vala_args = [ + '--vapidir', meson.current_source_dir() / 'vapi', +] +lib_ice = shared_library('ice', sources, name_prefix: '', c_args: c_args, vala_args: vala_args, dependencies: dependencies, install: true, install_dir: get_option('libdir') / 'dino/plugins') +dep_ice = declare_dependency(link_with: lib_ice, include_directories: include_directories('.')) diff --git a/plugins/meson.build b/plugins/meson.build index 5b0284f6..9a995f87 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -1,3 +1,4 @@ subdir('http-files') +subdir('ice') subdir('notification-sound') subdir('openpgp') -- cgit v1.2.3-54-g00ecf From 715fabb5bb793f35926180363bd6f9236d904f42 Mon Sep 17 00:00:00 2001 From: hrxi Date: Tue, 20 Jun 2023 18:54:28 +0200 Subject: meson: Add omemo plugin --- meson.build | 5 +++ plugins/meson.build | 1 + plugins/omemo/data/gresource.xml | 7 ++++ plugins/omemo/meson.build | 68 +++++++++++++++++++++++++++++++++++++++ plugins/omemo/po/meson.build | 1 + plugins/omemo/vapi/libgcrypt.vapi | 0 6 files changed, 82 insertions(+) create mode 100644 plugins/omemo/data/gresource.xml create mode 100644 plugins/omemo/meson.build create mode 100644 plugins/omemo/po/meson.build create mode 100644 plugins/omemo/vapi/libgcrypt.vapi diff --git a/meson.build b/meson.build index 7f86f002..887397c2 100644 --- a/meson.build +++ b/meson.build @@ -17,7 +17,12 @@ dep_icu_uc = dependency('icu-uc') dep_libadwaita = dependency('libadwaita-1') dep_libcanberra = dependency('libcanberra') dep_libgcrypt = dependency('libgcrypt') +dep_libqrencode = dependency('libqrencode') dep_libsrtp2 = dependency('libsrtp2') +# libsignal-protocol-c has a history of breaking compatibility on the patch level +# we'll have to check compatibility for every new release +# distro maintainers may update this dependency after compatibility tests +dep_libsignal_protocol_c = dependency('libsignal-protocol-c', version: ['>=2.3.2', '<2.3.4']) dep_libsoup = dependency('libsoup-3.0') dep_nice = dependency('nice', version: '>=0.1.15') dep_m = meson.get_compiler('c').find_library('m', required: false) diff --git a/plugins/meson.build b/plugins/meson.build index 9a995f87..cf47aea8 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -1,4 +1,5 @@ subdir('http-files') subdir('ice') subdir('notification-sound') +subdir('omemo') subdir('openpgp') diff --git a/plugins/omemo/data/gresource.xml b/plugins/omemo/data/gresource.xml new file mode 100644 index 00000000..616dcdc1 --- /dev/null +++ b/plugins/omemo/data/gresource.xml @@ -0,0 +1,7 @@ + + + + contact_details_dialog.ui + manage_key_dialog.ui + + diff --git a/plugins/omemo/meson.build b/plugins/omemo/meson.build new file mode 100644 index 00000000..57eec2ce --- /dev/null +++ b/plugins/omemo/meson.build @@ -0,0 +1,68 @@ +subdir('po') +dependencies = [ + dep_crypto_vala, + dep_dino, + dep_gee, + dep_glib, + dep_gmodule, + dep_gtk4, + dep_libgcrypt, + dep_libqrencode, + dep_libsignal_protocol_c, + dep_qlite, + dep_xmpp_vala, +] +sources = files( + 'src/dtls_srtp_verification_draft.vala', + 'src/file_transfer/file_decryptor.vala', + 'src/file_transfer/file_encryptor.vala', + 'src/jingle/jet_omemo.vala', + 'src/jingle/jingle_helper.vala', + 'src/logic/database.vala', + 'src/logic/decrypt.vala', + 'src/logic/encrypt.vala', + 'src/logic/manager.vala', + 'src/logic/pre_key_store.vala', + 'src/logic/session_store.vala', + 'src/logic/signed_pre_key_store.vala', + 'src/logic/trust_manager.vala', + 'src/plugin.vala', + 'src/protocol/bundle.vala', + 'src/protocol/message_flag.vala', + 'src/protocol/stream_module.vala', + 'src/register_plugin.vala', + 'src/signal/context.vala', + 'src/signal/signal_helper.c', + 'src/signal/simple_iks.vala', + 'src/signal/simple_pks.vala', + 'src/signal/simple_spks.vala', + 'src/signal/simple_ss.vala', + 'src/signal/store.vala', + 'src/signal/util.vala', + 'src/trust_level.vala', + 'src/ui/account_settings_entry.vala', + 'src/ui/bad_messages_populator.vala', + 'src/ui/call_encryption_entry.vala', + 'src/ui/contact_details_dialog.vala', + 'src/ui/contact_details_provider.vala', + 'src/ui/device_notification_populator.vala', + 'src/ui/encryption_list_entry.vala', + 'src/ui/manage_key_dialog.vala', + 'src/ui/own_notifications.vala', + 'src/ui/util.vala', +) +sources += gnome.compile_resources( + 'resources', + 'data/gresource.xml', + source_dir: 'data', +) +c_args = [ + '-DG_LOG_DOMAIN="OMEMO"', + '-DGETTEXT_PACKAGE="dino-omemo"', + '-DLOCALE_INSTALL_DIR="@0@"'.format(get_option('prefix') / get_option('localedir')), +] +vala_args = [ + '--vapidir', meson.current_source_dir() / 'vapi', +] +lib_omemo = shared_library('omemo', sources, name_prefix: '', c_args: c_args, vala_args: vala_args, include_directories: include_directories('src'), dependencies: dependencies, install: true, install_dir: get_option('libdir') / 'dino/plugins') +dep_omemo = declare_dependency(link_with: lib_omemo, include_directories: include_directories('.')) diff --git a/plugins/omemo/po/meson.build b/plugins/omemo/po/meson.build new file mode 100644 index 00000000..fa22f211 --- /dev/null +++ b/plugins/omemo/po/meson.build @@ -0,0 +1 @@ +i18n.gettext('dino-omemo') diff --git a/plugins/omemo/vapi/libgcrypt.vapi b/plugins/omemo/vapi/libgcrypt.vapi new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3-54-g00ecf From e6938c29653743974eb4f03d2a988cef50d0adbc Mon Sep 17 00:00:00 2001 From: hrxi Date: Tue, 20 Jun 2023 19:46:41 +0200 Subject: meson: Add rtp plugin --- meson.build | 8 +++++- plugins/meson.build | 1 + plugins/rtp/meson.build | 41 +++++++++++++++++++++++++++ plugins/rtp/vapi/webrtc-audio-processing.vapi | 0 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 plugins/rtp/meson.build create mode 100644 plugins/rtp/vapi/webrtc-audio-processing.vapi diff --git a/meson.build b/meson.build index 887397c2..e3c6b72e 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('xmpp-vala', 'vala') +project('xmpp-vala', 'c', 'cpp', 'vala') fs = import('fs') gnome = import('gnome') @@ -12,6 +12,11 @@ dep_glib = dependency('glib-2.0') dep_gnutls = dependency('gnutls') dep_gmodule = dependency('gmodule-2.0') dep_gpgme = dependency('gpgme') +dep_gstreamer = dependency('gstreamer-1.0') +dep_gstreamer_app = dependency('gstreamer-app-1.0') +dep_gstreamer_audio = dependency('gstreamer-audio-1.0') +dep_gstreamer_rtp = dependency('gstreamer-rtp-1.0') +dep_gstreamer_video = dependency('gstreamer-video-1.0') dep_gtk4 = dependency('gtk4') dep_icu_uc = dependency('icu-uc') dep_libadwaita = dependency('libadwaita-1') @@ -27,6 +32,7 @@ dep_libsoup = dependency('libsoup-3.0') dep_nice = dependency('nice', version: '>=0.1.15') dep_m = meson.get_compiler('c').find_library('m', required: false) dep_sqlite3 = dependency('sqlite3', version: '>=3.24') +dep_webrtc_audio_processing = dependency('webrtc-audio-processing', version: ['>=0.2', '<0.4']) prog_git = find_program('git', required: false) prog_python = python.find_installation() diff --git a/plugins/meson.build b/plugins/meson.build index cf47aea8..196e3634 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -3,3 +3,4 @@ subdir('ice') subdir('notification-sound') subdir('omemo') subdir('openpgp') +subdir('rtp') diff --git a/plugins/rtp/meson.build b/plugins/rtp/meson.build new file mode 100644 index 00000000..d4d37e36 --- /dev/null +++ b/plugins/rtp/meson.build @@ -0,0 +1,41 @@ +dependencies = [ + dep_gee, + dep_glib, + dep_gmodule, + dep_gnutls, + dep_gtk4, + dep_gstreamer, + dep_gstreamer_app, + dep_gstreamer_audio, + dep_gstreamer_rtp, + dep_gstreamer_video, + dep_crypto_vala, + dep_dino, + dep_qlite, + dep_webrtc_audio_processing, + dep_xmpp_vala, +] +sources = files( + 'src/codec_util.vala', + 'src/device.vala', + 'src/gst_fixes.c', + 'src/module.vala', + 'src/plugin.vala', + 'src/register_plugin.vala', + 'src/stream.vala', + 'src/video_widget.vala', + 'src/voice_processor.vala', + 'src/voice_processor_native.cpp', +) +c_args = [ + '-DGST_1_16', + '-DGST_1_18', + '-DGST_1_20', + '-DWITH_VOICE_PROCESSOR', + '-DG_LOG_DOMAIN="rtp"', +] +vala_args = [ + '--vapidir', meson.current_source_dir() / 'vapi', +] +lib_rtp = shared_library('rtp', sources, name_prefix: '', c_args: c_args, vala_args: vala_args, include_directories: include_directories('src'), dependencies: dependencies, install: true, install_dir: get_option('libdir') / 'dino/plugins') +dep_rtp = declare_dependency(link_with: lib_rtp, include_directories: include_directories('.')) diff --git a/plugins/rtp/vapi/webrtc-audio-processing.vapi b/plugins/rtp/vapi/webrtc-audio-processing.vapi new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3-54-g00ecf From bfc1962f70cebdd2933218052a172bed73d06fb9 Mon Sep 17 00:00:00 2001 From: hrxi Date: Sat, 30 Sep 2023 02:28:50 +0200 Subject: meson: Allow enabling/disabling plugins --- meson.build | 50 +++++++++++++++++++++++++++++++++++--------------- meson_options.txt | 7 +++++++ 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/meson.build b/meson.build index e3c6b72e..3276158f 100644 --- a/meson.build +++ b/meson.build @@ -5,34 +5,54 @@ gnome = import('gnome') i18n = import('i18n') python = import('python') +# plugin_crypto is enabled if any of the crypto plugins is enabled, auto if +# none of them are explicitly enabled but at least one is set to auto, or +# disabled if all of them are disabled. +plugin_crypto = get_option('plugin-ice') +foreach plugin : ['plugin-ice', 'plugin-omemo', 'plugin-rtp'] + if get_option(plugin).enabled() and not plugin_crypto.enabled() + plugin_crypto = get_option(plugin) + elif get_option(plugin).allowed() and not plugin_crypto.allowed() + plugin_crypto = get_option(plugin) + endif +endforeach + +if get_option('plugin-ice').enabled() and not get_option('plugin-rtp').enabled() + dep_gnutls_required = get_option('plugin-ice') +elif get_option('plugin-ice').allowed() and not get_option('plugin-rtp').allowed() + dep_gnutls_required = get_option('plugin-ice') +else + dep_gnutls_required = get_option('plugin-rtp') +endif + dep_gdk_pixbuf = dependency('gdk-pixbuf-2.0') dep_gee = dependency('gee-0.8') dep_gio = dependency('gio-2.0') dep_glib = dependency('glib-2.0') -dep_gnutls = dependency('gnutls') +dep_gnutls = dependency('gnutls', disabler: true, required: dep_gnutls_required) dep_gmodule = dependency('gmodule-2.0') -dep_gpgme = dependency('gpgme') -dep_gstreamer = dependency('gstreamer-1.0') -dep_gstreamer_app = dependency('gstreamer-app-1.0') -dep_gstreamer_audio = dependency('gstreamer-audio-1.0') -dep_gstreamer_rtp = dependency('gstreamer-rtp-1.0') -dep_gstreamer_video = dependency('gstreamer-video-1.0') +dep_gpgme = dependency('gpgme', disabler: true, required: get_option('plugin-openpgp')) +dep_gstreamer = dependency('gstreamer-1.0', disabler: true, required: get_option('plugin-rtp')) +dep_gstreamer_app = dependency('gstreamer-app-1.0', disabler: true, required: get_option('plugin-rtp')) +dep_gstreamer_audio = dependency('gstreamer-audio-1.0', disabler: true, required: get_option('plugin-rtp')) +dep_gstreamer_rtp = dependency('gstreamer-rtp-1.0', disabler: true, required: get_option('plugin-rtp')) +dep_gstreamer_video = dependency('gstreamer-video-1.0', disabler: true, required: get_option('plugin-rtp')) dep_gtk4 = dependency('gtk4') dep_icu_uc = dependency('icu-uc') dep_libadwaita = dependency('libadwaita-1') -dep_libcanberra = dependency('libcanberra') -dep_libgcrypt = dependency('libgcrypt') -dep_libqrencode = dependency('libqrencode') -dep_libsrtp2 = dependency('libsrtp2') +dep_libcanberra = dependency('libcanberra', disabler: true, required: get_option('plugin-notification-sound')) +dep_libgcrypt = dependency('libgcrypt', disabler: true, required: plugin_crypto) +dep_libqrencode = dependency('libqrencode', disabler: true, required: get_option('plugin-omemo')) +dep_libsrtp2 = dependency('libsrtp2', disabler: true, required: plugin_crypto) # libsignal-protocol-c has a history of breaking compatibility on the patch level # we'll have to check compatibility for every new release # distro maintainers may update this dependency after compatibility tests -dep_libsignal_protocol_c = dependency('libsignal-protocol-c', version: ['>=2.3.2', '<2.3.4']) -dep_libsoup = dependency('libsoup-3.0') -dep_nice = dependency('nice', version: '>=0.1.15') +dep_libsignal_protocol_c = dependency('libsignal-protocol-c', version: ['>=2.3.2', '<2.3.4'], disabler: true, required: get_option('plugin-omemo')) +dep_libsoup = dependency('libsoup-3.0', disabler: true, required: get_option('plugin-http-files')) +dep_nice = dependency('nice', version: '>=0.1.15', disabler: true, required: get_option('plugin-ice')) dep_m = meson.get_compiler('c').find_library('m', required: false) dep_sqlite3 = dependency('sqlite3', version: '>=3.24') -dep_webrtc_audio_processing = dependency('webrtc-audio-processing', version: ['>=0.2', '<0.4']) +dep_webrtc_audio_processing = dependency('webrtc-audio-processing', version: ['>=0.2', '<0.4'], disabler: true, required: get_option('plugin-rtp')) prog_git = find_program('git', required: false) prog_python = python.find_installation() diff --git a/meson_options.txt b/meson_options.txt index a1dcd3c2..ee0ac3c0 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,8 @@ option('plugindir', type: 'string', value: 'lib/dino/plugins', description: 'Dino plugin directory') + +option('plugin-http-files', type: 'feature', description: 'HTTP file upload') +option('plugin-ice', type: 'feature', description: '') +option('plugin-notification-sound', type: 'feature', description: 'Sound for chat notifications') +option('plugin-omemo', type: 'feature', description: 'End-to-end encryption') +option('plugin-openpgp', type: 'feature', description: 'End-to-end encryption using PGP') +option('plugin-rtp', type: 'feature', description: 'Voice/video calls') -- cgit v1.2.3-54-g00ecf From a55a10e88f88a4650aa6a83927ea38960aa26935 Mon Sep 17 00:00:00 2001 From: hrxi Date: Sat, 30 Sep 2023 03:05:11 +0200 Subject: meson: Add RTP options that are also present in the CMakeLists.txt --- meson.build | 2 +- meson_options.txt | 6 ++++++ plugins/rtp/meson.build | 31 ++++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index 3276158f..4ad18477 100644 --- a/meson.build +++ b/meson.build @@ -52,7 +52,7 @@ dep_libsoup = dependency('libsoup-3.0', disabler: true, required: get_option('pl dep_nice = dependency('nice', version: '>=0.1.15', disabler: true, required: get_option('plugin-ice')) dep_m = meson.get_compiler('c').find_library('m', required: false) dep_sqlite3 = dependency('sqlite3', version: '>=3.24') -dep_webrtc_audio_processing = dependency('webrtc-audio-processing', version: ['>=0.2', '<0.4'], disabler: true, required: get_option('plugin-rtp')) +dep_webrtc_audio_processing = dependency('webrtc-audio-processing', version: ['>=0.2', '<0.4'], required: get_option('plugin-rtp-webrtc-audio-processing')) prog_git = find_program('git', required: false) prog_python = python.find_installation() diff --git a/meson_options.txt b/meson_options.txt index ee0ac3c0..caee3093 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -6,3 +6,9 @@ option('plugin-notification-sound', type: 'feature', description: 'Sound for cha option('plugin-omemo', type: 'feature', description: 'End-to-end encryption') option('plugin-openpgp', type: 'feature', description: 'End-to-end encryption using PGP') option('plugin-rtp', type: 'feature', description: 'Voice/video calls') + +option('plugin-rtp-h264', type: 'feature', value: 'disabled', description: 'H264 codec') +option('plugin-rtp-msdk', type: 'feature', value: 'disabled', description: 'Intel MediaSDK') +option('plugin-rtp-vaapi', type: 'feature', value: 'disabled', description: 'Video Acceleration API') +option('plugin-rtp-vp9', type: 'feature', value: 'disabled', description: 'VP9 codec') +option('plugin-rtp-webrtc-audio-processing', type: 'feature', description: 'Voice preprocessing') diff --git a/plugins/rtp/meson.build b/plugins/rtp/meson.build index d4d37e36..8a72dc41 100644 --- a/plugins/rtp/meson.build +++ b/plugins/rtp/meson.build @@ -1,18 +1,18 @@ dependencies = [ + dep_crypto_vala, + dep_dino, dep_gee, dep_glib, dep_gmodule, dep_gnutls, - dep_gtk4, dep_gstreamer, dep_gstreamer_app, dep_gstreamer_audio, dep_gstreamer_rtp, dep_gstreamer_video, - dep_crypto_vala, - dep_dino, + dep_gtk4, + dep_m, dep_qlite, - dep_webrtc_audio_processing, dep_xmpp_vala, ] sources = files( @@ -24,18 +24,35 @@ sources = files( 'src/register_plugin.vala', 'src/stream.vala', 'src/video_widget.vala', - 'src/voice_processor.vala', - 'src/voice_processor_native.cpp', ) c_args = [ '-DGST_1_16', '-DGST_1_18', '-DGST_1_20', - '-DWITH_VOICE_PROCESSOR', '-DG_LOG_DOMAIN="rtp"', ] vala_args = [ '--vapidir', meson.current_source_dir() / 'vapi', ] +if dep_webrtc_audio_processing.found() + dependencies += [dep_webrtc_audio_processing] + sources += files( + 'src/voice_processor.vala', + 'src/voice_processor_native.cpp', + ) + vala_args += ['-D', 'WITH_VOICE_PROCESSOR'] +endif +if get_option('plugin-rtp-h264').allowed() + vala_args += ['-D', 'ENABLE_H264'] +endif +if get_option('plugin-rtp-msdk').allowed() + vala_args += ['-D', 'ENABLE_MSDK'] +endif +if get_option('plugin-rtp-vaapi').allowed() + vala_args += ['-D', 'ENABLE_VAAPI'] +endif +if get_option('plugin-rtp-vp9').allowed() + vala_args += ['-D', 'ENABLE_VP9'] +endif lib_rtp = shared_library('rtp', sources, name_prefix: '', c_args: c_args, vala_args: vala_args, include_directories: include_directories('src'), dependencies: dependencies, install: true, install_dir: get_option('libdir') / 'dino/plugins') dep_rtp = declare_dependency(link_with: lib_rtp, include_directories: include_directories('.')) -- cgit v1.2.3-54-g00ecf From c312fb282f3312d02779262da9bf969ddfa1e5ac Mon Sep 17 00:00:00 2001 From: hrxi Date: Sat, 30 Sep 2023 03:05:20 +0200 Subject: meson: Add version detection for some dependencies --- main/meson.build | 9 +++++++++ plugins/rtp/meson.build | 12 +++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/main/meson.build b/main/meson.build index f6d212f8..ccebf67d 100644 --- a/main/meson.build +++ b/main/meson.build @@ -106,6 +106,15 @@ c_args = [ vala_args = [ '--vapidir', meson.current_source_dir() / 'vapi', ] +if dep_libadwaita.version() == 'unknown' or dep_libadwaita.version().version_compare('>=1.2') + vala_args += ['-D', 'Adw_1_2'] +endif +if dep_gtk4.version() == 'unknown' or dep_gtk4.version().version_compare('>=4.6') + vala_args += ['-D', 'GTK_4_6'] +endif +if dep_gtk4.version() == 'unknown' or dep_gtk4.version().version_compare('>=4.8') + vala_args += ['-D', 'GTK_4_8'] +endif exe_dino = executable('dino', sources, c_args: c_args, vala_args: vala_args, dependencies: dependencies, install: true) install_data('data/icons/scalable/apps/im.dino.Dino-symbolic.svg', install_dir: get_option('datadir') / 'hicolor/symbolic/apps') diff --git a/plugins/rtp/meson.build b/plugins/rtp/meson.build index 8a72dc41..06821c91 100644 --- a/plugins/rtp/meson.build +++ b/plugins/rtp/meson.build @@ -26,9 +26,6 @@ sources = files( 'src/video_widget.vala', ) c_args = [ - '-DGST_1_16', - '-DGST_1_18', - '-DGST_1_20', '-DG_LOG_DOMAIN="rtp"', ] vala_args = [ @@ -42,6 +39,15 @@ if dep_webrtc_audio_processing.found() ) vala_args += ['-D', 'WITH_VOICE_PROCESSOR'] endif +if dep_gstreamer_rtp.version() == 'unknown' or dep_gstreamer_rtp.version().version_compare('>=1.16') + vala_args += ['-D', 'GST_1_16'] +endif +if dep_gstreamer_rtp.version() == 'unknown' or dep_gstreamer_rtp.version().version_compare('>=1.18') + vala_args += ['-D', 'GST_1_18'] +endif +if dep_gstreamer_rtp.version() == 'unknown' or dep_gstreamer_rtp.version().version_compare('>=1.20') + vala_args += ['-D', 'GST_1_20'] +endif if get_option('plugin-rtp-h264').allowed() vala_args += ['-D', 'ENABLE_H264'] endif -- cgit v1.2.3-54-g00ecf From 0c45387bf903e5b0d02502d27642dd2a78aa6539 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sat, 7 Oct 2023 13:56:38 +0200 Subject: Fix implicit-function-declaration compiler warnings --- .../src/module/xep/0384_omemo/omemo_encryptor.vala | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/xmpp-vala/src/module/xep/0384_omemo/omemo_encryptor.vala b/xmpp-vala/src/module/xep/0384_omemo/omemo_encryptor.vala index 6509bfe3..c68de329 100644 --- a/xmpp-vala/src/module/xep/0384_omemo/omemo_encryptor.vala +++ b/xmpp-vala/src/module/xep/0384_omemo/omemo_encryptor.vala @@ -72,27 +72,27 @@ namespace Xmpp.Xep.Omemo { } public class EncryptionResult { - public int lost { get; internal set; } - public int success { get; internal set; } - public int unknown { get; internal set; } - public int failure { get; internal set; } + public int lost { get; set; } + public int success { get; set; } + public int unknown { get; set; } + public int failure { get; set; } } public class EncryptState { - public bool encrypted { get; internal set; } - public int other_devices { get; internal set; } - public int other_success { get; internal set; } - public int other_lost { get; internal set; } - public int other_unknown { get; internal set; } - public int other_failure { get; internal set; } - public int other_waiting_lists { get; internal set; } - - public int own_devices { get; internal set; } - public int own_success { get; internal set; } - public int own_lost { get; internal set; } - public int own_unknown { get; internal set; } - public int own_failure { get; internal set; } - public bool own_list { get; internal set; } + public bool encrypted { get; set; } + public int other_devices { get; set; } + public int other_success { get; set; } + public int other_lost { get; set; } + public int other_unknown { get; set; } + public int other_failure { get; set; } + public int other_waiting_lists { get; set; } + + public int own_devices { get; set; } + public int own_success { get; set; } + public int own_lost { get; set; } + public int own_unknown { get; set; } + public int own_failure { get; set; } + public bool own_list { get; set; } public void add_result(EncryptionResult enc_res, bool own) { if (own) { -- cgit v1.2.3-54-g00ecf From 1e167eeea67f18f3d5788dc34d97d94e6f401499 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sat, 7 Oct 2023 14:29:26 +0200 Subject: Fix some compiler warnings --- libdino/src/service/avatar_manager.vala | 6 +++--- libdino/src/service/history_sync.vala | 3 --- libdino/src/service/message_processor.vala | 1 - main/src/ui/call_window/call_window.vala | 3 ++- .../ui/conversation_content_view/conversation_view.vala | 2 +- .../ui/conversation_content_view/file_image_widget.vala | 1 - main/src/ui/conversation_details.vala | 9 ++++++--- .../ui/conversation_selector/conversation_selector.vala | 1 - main/src/ui/notifier_gnotifications.vala | 2 ++ main/src/ui/occupant_menu/list.vala | 1 - main/src/ui/util/data_forms.vala | 1 - main/src/ui/util/label_hybrid.vala | 4 ---- plugins/rtp/src/video_widget.vala | 2 +- xmpp-vala/src/core/xmpp_stream.vala | 4 ++-- xmpp-vala/src/module/xep/0082_date_time_profiles.vala | 16 ++-------------- 15 files changed, 19 insertions(+), 37 deletions(-) diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index 1296856b..3bd38e72 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -52,7 +52,7 @@ public class AvatarManager : StreamInteractionModule, Object { if (hash == null) return null; File file = File.new_for_path(Path.build_filename(folder, hash)); if (!file.query_exists()) { - fetch_and_store_for_jid(account, jid_); + fetch_and_store_for_jid.begin(account, jid_); return null; } else { return file; @@ -169,7 +169,7 @@ public class AvatarManager : StreamInteractionModule, Object { ); foreach (var entry in get_avatar_hashes(account, Source.USER_AVATARS).entries) { - on_user_avatar_received(account, entry.key, entry.value); + on_user_avatar_received.begin(account, entry.key, entry.value); } foreach (var entry in get_avatar_hashes(account, Source.VCARD).entries) { @@ -179,7 +179,7 @@ public class AvatarManager : StreamInteractionModule, Object { continue; } - on_vcard_avatar_received(account, entry.key, entry.value); + on_vcard_avatar_received.begin(account, entry.key, entry.value); } } diff --git a/libdino/src/service/history_sync.vala b/libdino/src/service/history_sync.vala index 0c0571bb..8ab6d7bb 100644 --- a/libdino/src/service/history_sync.vala +++ b/libdino/src/service/history_sync.vala @@ -388,9 +388,6 @@ public class Dino.HistorySync { page_result = PageResult.NoMoreMessages; } - string selection = null; - string[] selection_args = {}; - string query_id = query_params.query_id; string? after_id = query_params.start_id; diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index 01687083..baab37ce 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -167,7 +167,6 @@ public class MessageProcessor : StreamInteractionModule, Object { new_message.counterpart = counterpart_override ?? (new_message.direction == Entities.Message.DIRECTION_SENT ? message.to : message.from); new_message.ourpart = new_message.direction == Entities.Message.DIRECTION_SENT ? message.from : message.to; - XmppStream? stream = stream_interactor.get_stream(account); Xmpp.MessageArchiveManagement.MessageFlag? mam_message_flag = Xmpp.MessageArchiveManagement.MessageFlag.get_flag(message); EntityInfo entity_info = stream_interactor.get_module(EntityInfo.IDENTITY); if (mam_message_flag != null && mam_message_flag.mam_id != null) { diff --git a/main/src/ui/call_window/call_window.vala b/main/src/ui/call_window/call_window.vala index 14b67449..08ea4b21 100644 --- a/main/src/ui/call_window/call_window.vala +++ b/main/src/ui/call_window/call_window.vala @@ -253,11 +253,12 @@ namespace Dino.Ui { } private bool on_get_child_position(Widget widget, out Gdk.Rectangle allocation) { + allocation = Gdk.Rectangle(); + if (widget == own_video_box) { int width = get_size(Orientation.HORIZONTAL); int height = get_size(Orientation.VERTICAL); - allocation = Gdk.Rectangle(); allocation.width = own_video_width; allocation.height = own_video_height; allocation.x = width - own_video_width - 20; diff --git a/main/src/ui/conversation_content_view/conversation_view.vala b/main/src/ui/conversation_content_view/conversation_view.vala index 4006a02f..33cb3b22 100644 --- a/main/src/ui/conversation_content_view/conversation_view.vala +++ b/main/src/ui/conversation_content_view/conversation_view.vala @@ -329,7 +329,7 @@ public class ConversationView : Widget, Plugins.ConversationItemCollection, Plug do_insert_item(item); } ContentMetaItem meta_item = content_populator.get_content_meta_item(content_item); - Widget w = insert_new(meta_item); + insert_new(meta_item); content_items.add(meta_item); meta_items.add(meta_item); diff --git a/main/src/ui/conversation_content_view/file_image_widget.vala b/main/src/ui/conversation_content_view/file_image_widget.vala index 43c3b74d..a3579185 100644 --- a/main/src/ui/conversation_content_view/file_image_widget.vala +++ b/main/src/ui/conversation_content_view/file_image_widget.vala @@ -45,7 +45,6 @@ public class FileImageWidget : Box { image.add_controller(gesture_click_controller); FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); - string? mime_type = file_info.get_content_type(); MenuButton button = new MenuButton(); button.icon_name = "view-more"; diff --git a/main/src/ui/conversation_details.vala b/main/src/ui/conversation_details.vala index 70c8ce6d..82d6ae54 100644 --- a/main/src/ui/conversation_details.vala +++ b/main/src/ui/conversation_details.vala @@ -26,15 +26,18 @@ namespace Dino.Ui.ConversationDetails { model.display_name.bind_property("display-name", view_model, "name", BindingFlags.SYNC_CREATE); model.conversation.bind_property("notify-setting", view_model, "notification", BindingFlags.SYNC_CREATE, (_, from, ref to) => { switch (model.conversation.get_notification_setting(stream_interactor)) { - case Conversation.NotifySetting.ON: + case ON: to = ViewModel.ConversationDetails.NotificationSetting.ON; break; - case Conversation.NotifySetting.OFF: + case OFF: to = ViewModel.ConversationDetails.NotificationSetting.OFF; break; - case Conversation.NotifySetting.HIGHLIGHT: + case HIGHLIGHT: to = ViewModel.ConversationDetails.NotificationSetting.HIGHLIGHT; break; + case DEFAULT: + // A "default" setting should have been resolved to the actual default value + assert_not_reached(); } return true; }); diff --git a/main/src/ui/conversation_selector/conversation_selector.vala b/main/src/ui/conversation_selector/conversation_selector.vala index 535a61b0..d16ef3ee 100644 --- a/main/src/ui/conversation_selector/conversation_selector.vala +++ b/main/src/ui/conversation_selector/conversation_selector.vala @@ -14,7 +14,6 @@ public class ConversationSelector : Widget { ListBox list_box = new ListBox() { hexpand=true }; private StreamInteractor stream_interactor; - private uint? drag_timeout; private HashMap rows = new HashMap(Conversation.hash_func, Conversation.equals_func); public ConversationSelector init(StreamInteractor stream_interactor) { diff --git a/main/src/ui/notifier_gnotifications.vala b/main/src/ui/notifier_gnotifications.vala index 90c8ca8c..4d36620d 100644 --- a/main/src/ui/notifier_gnotifications.vala +++ b/main/src/ui/notifier_gnotifications.vala @@ -109,6 +109,8 @@ namespace Dino.Ui { case ConnectionManager.ConnectionError.Source.TLS: notification.set_body("Invalid TLS certificate"); break; + default: + break; } GLib.Application.get_default().send_notification(account.id.to_string() + "-connection-error", notification); } diff --git a/main/src/ui/occupant_menu/list.vala b/main/src/ui/occupant_menu/list.vala index b9a4a74f..ce5a1981 100644 --- a/main/src/ui/occupant_menu/list.vala +++ b/main/src/ui/occupant_menu/list.vala @@ -153,7 +153,6 @@ public class List : Box { if (affiliation1 < affiliation2) return -1; else if (affiliation1 > affiliation2) return 1; else return row_wrapper1.name_label.label.collate(row_wrapper2.name_label.label); - return 0; } private int get_affiliation_ranking(Xmpp.Xep.Muc.Affiliation affiliation) { diff --git a/main/src/ui/util/data_forms.vala b/main/src/ui/util/data_forms.vala index d10196ab..39dce3ee 100644 --- a/main/src/ui/util/data_forms.vala +++ b/main/src/ui/util/data_forms.vala @@ -75,7 +75,6 @@ public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataF if (option.value == list_single_field.value) combobox_model.active_item = i; } combobox_model.bind_property("active-item", list_single_field, "value", BindingFlags.DEFAULT, (binding, from, ref to) => { - var src_field = (DataForms.DataForm.ListSingleField) binding.dup_target(); var active_item = (int) from; to = list_single_field.options[active_item].value; return true; diff --git a/main/src/ui/util/label_hybrid.vala b/main/src/ui/util/label_hybrid.vala index f426de7e..0059d2ae 100644 --- a/main/src/ui/util/label_hybrid.vala +++ b/main/src/ui/util/label_hybrid.vala @@ -97,10 +97,6 @@ public class EntryLabelHybrid : LabelHybrid { } } - private void on_focus_leave() { - show_label(); - } - private void update_label() { if (visibility) { label.label = entry.text; diff --git a/plugins/rtp/src/video_widget.vala b/plugins/rtp/src/video_widget.vala index f69a2ba7..05cc5a6c 100644 --- a/plugins/rtp/src/video_widget.vala +++ b/plugins/rtp/src/video_widget.vala @@ -16,7 +16,7 @@ public class Dino.Plugins.Rtp.Paintable : Gdk.Paintable, Object { public override Gdk.Paintable get_current_image() { if (image != null) return image; - return Gdk.Paintable.new_empty(0, 0); + return Gdk.Paintable.empty(0, 0); } public override int get_intrinsic_width() { diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala index 42e90bf9..54433b67 100644 --- a/xmpp-vala/src/core/xmpp_stream.vala +++ b/xmpp-vala/src/core/xmpp_stream.vala @@ -30,9 +30,9 @@ public abstract class Xmpp.XmppStream : Object { this.remote_name = remote_name; } - public abstract async void connect() throws IOError; + public abstract new async void connect() throws IOError; - public abstract async void disconnect() throws IOError; + public abstract new async void disconnect() throws IOError; public abstract async StanzaNode read() throws IOError; diff --git a/xmpp-vala/src/module/xep/0082_date_time_profiles.vala b/xmpp-vala/src/module/xep/0082_date_time_profiles.vala index 32d4d3ac..8b40d3ac 100644 --- a/xmpp-vala/src/module/xep/0082_date_time_profiles.vala +++ b/xmpp-vala/src/module/xep/0082_date_time_profiles.vala @@ -1,23 +1,11 @@ namespace Xmpp.Xep.DateTimeProfiles { public DateTime? parse_string(string time_string) { - // TODO with glib >= 2.56 - // return new DateTime.from_iso8601(time_string, null); - - TimeVal time_val = TimeVal(); - if (time_val.from_iso8601(time_string)) { - return new DateTime.from_unix_utc(time_val.tv_sec); - } - return null; - + return new DateTime.from_iso8601(time_string, null); } - public string to_datetime(DateTime time) { - // TODO with glib >= 2.62 - // return time.to_utc().format_iso8601().to_string(); - - return time.to_utc().format("%Y-%m-%dT%H:%M:%SZ"); + return time.to_utc().format_iso8601().to_string(); } } -- cgit v1.2.3-54-g00ecf From 8cb195a2749b0335c8d5fefc2d4fb78023cffe71 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sat, 7 Oct 2023 16:53:37 +0200 Subject: Fix crash due to gpg binding issue --- plugins/openpgp/src/account_settings_entry.vala | 6 ++++-- plugins/openpgp/src/gpgme_helper.vala | 1 + plugins/openpgp/vapi/gpgme.vapi | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/openpgp/src/account_settings_entry.vala b/plugins/openpgp/src/account_settings_entry.vala index d2e5ac23..7c99942f 100644 --- a/plugins/openpgp/src/account_settings_entry.vala +++ b/plugins/openpgp/src/account_settings_entry.vala @@ -116,8 +116,10 @@ public class AccountSettingsEntry : Plugins.AccountSettingsEntry { SourceFunc callback = fetch_keys.callback; new Thread (null, () => { // Querying GnuPG might take some time try { - keys = GPGHelper.get_keylist(null, true); - } catch (Error e) { } + keys = GPGHelper.get_keylist(null, true); + } catch (Error e) { + warning(e.message); + } Idle.add((owned)callback); return null; }); diff --git a/plugins/openpgp/src/gpgme_helper.vala b/plugins/openpgp/src/gpgme_helper.vala index f28bc6d6..18d07c06 100644 --- a/plugins/openpgp/src/gpgme_helper.vala +++ b/plugins/openpgp/src/gpgme_helper.vala @@ -117,6 +117,7 @@ public static Gee.List get_keylist(string? pattern = null, bool secret_only } catch (Error e) { if (e.code != GPGError.ErrorCode.EOF) throw e; } + context.op_keylist_end(); return keys; } finally { global_mutex.unlock(); diff --git a/plugins/openpgp/vapi/gpgme.vapi b/plugins/openpgp/vapi/gpgme.vapi index 10fdb89d..2fc27c65 100644 --- a/plugins/openpgp/vapi/gpgme.vapi +++ b/plugins/openpgp/vapi/gpgme.vapi @@ -38,7 +38,7 @@ namespace GPG { } [Compact] - [CCode (cname = "struct _gpgme_key", ref_function = "gpgme_key_ref", ref_function_void = true, unref_function = "gpgme_key_unref", free_function = "gpgme_key_release")] + [CCode (cname = "struct _gpgme_key", ref_function = "gpgme_key_ref_vapi", unref_function = "gpgme_key_unref_vapi", free_function = "gpgme_key_release")] public class Key { public bool revoked; public bool expired; -- cgit v1.2.3-54-g00ecf From 86b101900c28a09ebc6bcbf212f9969f70ce51b7 Mon Sep 17 00:00:00 2001 From: eerielili Date: Sun, 8 Oct 2023 11:51:30 +0000 Subject: Start conversation if closed when receiving an audio or video call (#1485) * Start conversation if closed when receiving an audio or video call * Fix starting conversation on new calls, move setting conversation.last_active --------- Co-authored-by: fiaxh --- libdino/src/application.vala | 2 +- libdino/src/service/calls.vala | 5 ----- libdino/src/service/conversation_manager.vala | 7 +++++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libdino/src/application.vala b/libdino/src/application.vala index 727b6131..0fcee731 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -39,12 +39,12 @@ public interface Application : GLib.Application { PresenceManager.start(stream_interactor); CounterpartInteractionManager.start(stream_interactor); BlockingManager.start(stream_interactor); + Calls.start(stream_interactor, db); ConversationManager.start(stream_interactor, db); MucManager.start(stream_interactor); AvatarManager.start(stream_interactor, db); RosterManager.start(stream_interactor, db); FileManager.start(stream_interactor, db); - Calls.start(stream_interactor, db); CallStore.start(stream_interactor, db); ContentItemStore.start(stream_interactor, db); ChatInteraction.start(stream_interactor); diff --git a/libdino/src/service/calls.vala b/libdino/src/service/calls.vala index ebaf8d03..eca7e223 100644 --- a/libdino/src/service/calls.vala +++ b/libdino/src/service/calls.vala @@ -61,8 +61,6 @@ namespace Dino { call_state.initiate_groupchat_call.begin(conversation.counterpart); } - conversation.last_active = call.time; - call_outgoing(call, call_state, conversation); return call_state; @@ -221,7 +219,6 @@ namespace Dino { Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(call.counterpart.bare_jid, account, Conversation.Type.CHAT); stream_interactor.get_module(CallStore.IDENTITY).add_call(call, conversation); - conversation.last_active = call.time; var call_state = new CallState(call, stream_interactor); connect_call_state_signals(call_state); @@ -294,7 +291,6 @@ namespace Dino { Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(inviter_jid.bare_jid, account); if (conversation == null) return null; stream_interactor.get_module(CallStore.IDENTITY).add_call(call, conversation); - conversation.last_active = call.time; CallState call_state = new CallState(call, stream_interactor); connect_call_state_signals(call_state); @@ -465,7 +461,6 @@ namespace Dino { Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).approx_conversation_for_stanza(from_jid, to_jid, account, message_stanza.type_); if (conversation == null) return; - conversation.last_active = call_state.call.time; if (call_state.call.direction == Call.DIRECTION_INCOMING) { call_incoming(call_state.call, call_state, conversation, video_requested, multiparty); diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index 59ccbac4..f966ccc7 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -29,6 +29,8 @@ public class ConversationManager : StreamInteractionModule, Object { stream_interactor.account_removed.connect(on_account_removed); stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(new MessageListener(stream_interactor)); stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(handle_sent_message); + stream_interactor.get_module(Calls.IDENTITY).call_incoming.connect(handle_new_call); + stream_interactor.get_module(Calls.IDENTITY).call_outgoing.connect(handle_new_call); } public Conversation create_conversation(Jid jid, Account account, Conversation.Type? type = null) { @@ -194,6 +196,11 @@ public class ConversationManager : StreamInteractionModule, Object { } } + private void handle_new_call(Call call, CallState state, Conversation conversation) { + conversation.last_active = call.time; + start_conversation(conversation); + } + private void add_conversation(Conversation conversation) { if (!conversations[conversation.account].has_key(conversation.counterpart)) { conversations[conversation.account][conversation.counterpart] = new ArrayList(Conversation.equals_func); -- cgit v1.2.3-54-g00ecf From 3de716446819550514d50a8112f5b6dd0c662702 Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Mon, 30 Oct 2023 21:45:25 +0100 Subject: Add which account is used in conversation details in about section --- main/src/ui/conversation_details.vala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main/src/ui/conversation_details.vala b/main/src/ui/conversation_details.vala index 82d6ae54..8a09193e 100644 --- a/main/src/ui/conversation_details.vala +++ b/main/src/ui/conversation_details.vala @@ -112,6 +112,11 @@ namespace Dino.Ui.ConversationDetails { populate_dialog(model, conversation, stream_interactor); bind_dialog(model, dialog.model, stream_interactor); + dialog.model.about_rows.append(new ViewModel.PreferencesRow.Text() { + title = _("Account used for this conversation"), + text = conversation.account.bare_jid.to_string() + }); + dialog.model.about_rows.append(new ViewModel.PreferencesRow.Text() { title = _("XMPP Address"), text = conversation.counterpart.to_string() @@ -188,4 +193,4 @@ namespace Dino.Ui.ConversationDetails { break; } } -} \ No newline at end of file +} -- cgit v1.2.3-54-g00ecf