From f24b47c44db03a8d9ba611f827e71aeb1f63d0bd Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 12 Mar 2017 14:44:09 +0100 Subject: PGP module: store data in own db, use pgp key as specified in account settings --- libdino/src/service/database.vala | 25 +--- plugins/gpgme-vala/src/gpgme_helper.vala | 13 +- plugins/openpgp/CMakeLists.txt | 5 +- plugins/openpgp/data/account_settings_item.ui | 6 +- plugins/openpgp/src/account_settings_entry.vala | 8 +- plugins/openpgp/src/account_settings_widget.vala | 100 +++++++++----- plugins/openpgp/src/database.vala | 67 +++++++++ plugins/openpgp/src/manager.vala | 4 +- plugins/openpgp/src/plugin.vala | 26 ++-- plugins/openpgp/src/stream_flag.vala | 25 ++++ plugins/openpgp/src/stream_module.vala | 166 +++++++++++++++++++++++ plugins/openpgp/src/xmpp_flag.vala | 25 ---- plugins/openpgp/src/xmpp_module.vala | 154 --------------------- 13 files changed, 370 insertions(+), 254 deletions(-) create mode 100644 plugins/openpgp/src/database.vala create mode 100644 plugins/openpgp/src/stream_flag.vala create mode 100644 plugins/openpgp/src/stream_module.vala delete mode 100644 plugins/openpgp/src/xmpp_flag.vala delete mode 100644 plugins/openpgp/src/xmpp_module.vala diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 83686424..b50581f8 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -103,16 +103,6 @@ public class Database : Qlite.Database { } } - public class PgpTable : Table { - public Column jid = new Column.Text("jid") { primary_key = true }; - public Column key = new Column.Text("key") { not_null = true }; - - protected PgpTable(Database db) { - base(db, "pgp"); - init({jid, key}); - } - } - public class EntityFeatureTable : Table { public Column entity = new Column.Text("entity"); public Column feature = new Column.Text("feature"); @@ -129,7 +119,6 @@ public class Database : Qlite.Database { public RealJidTable real_jid { get; private set; } public ConversationTable conversation { get; private set; } public AvatarTable avatar { get; private set; } - public PgpTable pgp { get; private set; } public EntityFeatureTable entity_feature { get; private set; } public Database(string fileName) { @@ -140,9 +129,8 @@ public class Database : Qlite.Database { real_jid = new RealJidTable(this); conversation = new ConversationTable(this); avatar = new AvatarTable(this); - pgp = new PgpTable(this); entity_feature = new EntityFeatureTable(this); - init({ account, jid, message, real_jid, conversation, avatar, pgp, entity_feature }); + init({ account, jid, message, real_jid, conversation, avatar, entity_feature }); } public override void migrate(long oldVersion) { @@ -420,17 +408,6 @@ public class Database : Qlite.Database { return ret; } - public void set_pgp_key(Jid jid, string key) { - pgp.insert().or("REPLACE") - .value(pgp.jid, jid.to_string()) - .value(pgp.key, key) - .perform(); - } - - public string? get_pgp_key(Jid jid) { - return pgp.select({pgp.key}).with(pgp.jid, "=", jid.to_string())[pgp.key]; - } - public void add_entity_features(string entity, ArrayList features) { foreach (string feature in features) { entity_feature.insert() diff --git a/plugins/gpgme-vala/src/gpgme_helper.vala b/plugins/gpgme-vala/src/gpgme_helper.vala index 9efa2b4c..429c96f0 100644 --- a/plugins/gpgme-vala/src/gpgme_helper.vala +++ b/plugins/gpgme-vala/src/gpgme_helper.vala @@ -28,12 +28,13 @@ public static string decrypt(string encr) throws GLib.Error { return get_string_from_data(dec_data); } -public static string sign(string plain, SigMode mode) throws GLib.Error { +public static string sign(string plain, SigMode mode, Key? key = null) throws GLib.Error { initialize(); global_mutex.lock(); 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); global_mutex.unlock(); return get_string_from_data(signed_data); @@ -76,11 +77,19 @@ public static Gee.List get_keylist(string? pattern = null, bool secret_only } 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 { initialize(); global_mutex.lock(); Context context = Context.create(); - Key key = context.get_key(sig, false); + Key key = context.get_key(sig, priv); global_mutex.unlock(); return key; } diff --git a/plugins/openpgp/CMakeLists.txt b/plugins/openpgp/CMakeLists.txt index a230872e..09a4ca7f 100644 --- a/plugins/openpgp/CMakeLists.txt +++ b/plugins/openpgp/CMakeLists.txt @@ -31,12 +31,13 @@ vala_precompile(OPENPGP_VALA_C SOURCES src/account_settings_entry.vala src/account_settings_widget.vala + src/database.vala src/encryption_list_entry.vala src/manager.vala src/plugin.vala src/register_plugin.vala - src/xmpp_flag.vala - src/xmpp_module.vala + src/stream_flag.vala + src/stream_module.vala CUSTOM_VAPIS ${CMAKE_BINARY_DIR}/exports/gpgme.vapi ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi diff --git a/plugins/openpgp/data/account_settings_item.ui b/plugins/openpgp/data/account_settings_item.ui index 95f09046..299b9a89 100644 --- a/plugins/openpgp/data/account_settings_item.ui +++ b/plugins/openpgp/data/account_settings_item.ui @@ -3,11 +3,11 @@