Move PGP support into plugin
This commit is contained in:
parent
63fffcddce
commit
7e1ecb34cb
|
@ -22,7 +22,6 @@ set (GLOBAL_DEBUG_FLAGS -g)
|
|||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GLOBAL_DEBUG_FLAGS}")
|
||||
set (VALA_CFLAGS -Wno-deprecated-declarations -Wno-incompatible-pointer-types -Wno-int-conversion -Wno-discarded-qualifiers)
|
||||
|
||||
add_subdirectory(gpgme-vala)
|
||||
add_subdirectory(qlite)
|
||||
add_subdirectory(xmpp-vala)
|
||||
add_subdirectory(libdino)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
find_package(Vala REQUIRED)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
include(${VALA_USE_FILE})
|
||||
include(GlibCompileResourcesSupport)
|
||||
|
||||
set(LIBDINO_PACKAGES
|
||||
gee-0.8
|
||||
|
@ -14,28 +13,10 @@ set(LIBDINO_PACKAGES
|
|||
|
||||
pkg_check_modules(LIBDINO REQUIRED ${LIBDINO_PACKAGES})
|
||||
|
||||
set(RESOURCE_LIST
|
||||
pgp_stack.ui
|
||||
)
|
||||
|
||||
compile_gresources(
|
||||
LIBDINO_GRESOURCES_TARGET
|
||||
LIBDINO_GRESOURCES_XML
|
||||
TARGET ${CMAKE_CURRENT_BINARY_DIR}/resources/resources.c
|
||||
TYPE EMBED_C
|
||||
RESOURCES ${RESOURCE_LIST}
|
||||
PREFIX /org/dino-im
|
||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
)
|
||||
|
||||
vala_precompile(LIBDINO_VALA_C
|
||||
SOURCES
|
||||
src/application.vala
|
||||
|
||||
src/plugin/interfaces.vala
|
||||
src/plugin/loader.vala
|
||||
src/plugin/registry.vala
|
||||
|
||||
src/dbus/login1.vala
|
||||
src/dbus/networkmanager.vala
|
||||
src/dbus/upower.vala
|
||||
|
@ -46,6 +27,10 @@ SOURCES
|
|||
src/entity/message.vala
|
||||
src/entity/encryption.vala
|
||||
|
||||
src/plugin/interfaces.vala
|
||||
src/plugin/loader.vala
|
||||
src/plugin/registry.vala
|
||||
|
||||
src/service/avatar_manager.vala
|
||||
src/service/avatar_storage.vala
|
||||
src/service/chat_interaction.vala
|
||||
|
@ -57,7 +42,6 @@ SOURCES
|
|||
src/service/message_manager.vala
|
||||
src/service/module_manager.vala
|
||||
src/service/muc_manager.vala
|
||||
src/service/pgp_manager.vala
|
||||
src/service/presence_manager.vala
|
||||
src/service/roster_manager.vala
|
||||
src/service/stream_interactor.vala
|
||||
|
@ -66,15 +50,12 @@ SOURCES
|
|||
CUSTOM_VAPIS
|
||||
"${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi"
|
||||
"${CMAKE_BINARY_DIR}/exports/qlite.vapi"
|
||||
"${CMAKE_BINARY_DIR}/exports/gpgme.vapi"
|
||||
PACKAGES
|
||||
${LIBDINO_PACKAGES}
|
||||
GENERATE_VAPI
|
||||
dino
|
||||
GENERATE_HEADER
|
||||
dino
|
||||
GRESOURCES
|
||||
${LIBDINO_GRESOURCES_XML}
|
||||
OPTIONS
|
||||
--target-glib=2.38
|
||||
${GLOBAL_DEBUG_FLAGS}
|
||||
|
@ -83,9 +64,9 @@ OPTIONS
|
|||
|
||||
set(CFLAGS ${VALA_CFLAGS} ${LIBDINO_CFLAGS})
|
||||
add_definitions(${CFLAGS})
|
||||
add_library(libdino SHARED ${LIBDINO_VALA_C} ${LIBDINO_GRESOURCES_TARGET})
|
||||
add_dependencies(libdino xmpp-vala-vapi qlite-vapi gpgme-vapi)
|
||||
target_link_libraries(libdino xmpp-vala qlite gpgme-vala ${LIBDINO_LIBRARIES} -lm)
|
||||
add_library(libdino SHARED ${LIBDINO_VALA_C})
|
||||
add_dependencies(libdino xmpp-vala-vapi qlite-vapi)
|
||||
target_link_libraries(libdino xmpp-vala qlite ${LIBDINO_LIBRARIES} -lm)
|
||||
set_target_properties(libdino PROPERTIES PREFIX "")
|
||||
|
||||
add_custom_target(dino-vapi
|
||||
|
|
|
@ -17,7 +17,6 @@ public class Dino.Application : Gtk.Application {
|
|||
CounterpartInteractionManager.start(stream_interaction);
|
||||
PresenceManager.start(stream_interaction);
|
||||
MucManager.start(stream_interaction);
|
||||
PgpManager.start(stream_interaction, db);
|
||||
RosterManager.start(stream_interaction);
|
||||
ConversationManager.start(stream_interaction, db);
|
||||
ChatInteraction.start(stream_interaction);
|
||||
|
|
|
@ -63,7 +63,6 @@ public class ModuleManager {
|
|||
module_map[account].add(new Xmpp.Message.Module());
|
||||
module_map[account].add(new Xep.MessageCarbons.Module());
|
||||
module_map[account].add(new Xep.Muc.Module());
|
||||
module_map[account].add(new Xep.Pgp.Module());
|
||||
module_map[account].add(new Xep.Pubsub.Module());
|
||||
module_map[account].add(new Xep.EntityCapabilities.Module(entity_capabilities_storage));
|
||||
module_map[account].add(new Xep.UserAvatars.Module(avatar_storage));
|
||||
|
|
|
@ -1,176 +0,0 @@
|
|||
using Gee;
|
||||
using Xmpp;
|
||||
|
||||
using Xmpp;
|
||||
using Dino.Entities;
|
||||
|
||||
namespace Dino {
|
||||
public class PgpManager : StreamInteractionModule, Object {
|
||||
public const string id = "pgp_manager";
|
||||
|
||||
public const string MESSAGE_ENCRYPTED = "pgp";
|
||||
|
||||
private StreamInteractor stream_interactor;
|
||||
private Database db;
|
||||
private HashMap<Jid, string> pgp_key_ids = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func);
|
||||
|
||||
public static void start(StreamInteractor stream_interactor, Database db) {
|
||||
PgpManager m = new PgpManager(stream_interactor, db);
|
||||
stream_interactor.add_module(m);
|
||||
|
||||
Plugins.Registry plugin_registry = (GLib.Application.get_default() as Application).plugin_registry;
|
||||
plugin_registry.register_encryption_list_entry(new EncryptionListEntry(m));
|
||||
plugin_registry.register_account_settings_entry(new AccountSettingsEntry(m));
|
||||
}
|
||||
|
||||
private class AccountSettingsEntry : Plugins.AccountSettingsEntry {
|
||||
private PgpManager pgp_manager;
|
||||
|
||||
public AccountSettingsEntry(PgpManager pgp_manager) {
|
||||
this.pgp_manager = pgp_manager;
|
||||
}
|
||||
|
||||
public override string id { get {
|
||||
return "pgp_key_picker";
|
||||
}}
|
||||
|
||||
public override string name { get {
|
||||
return "OpenPGP";
|
||||
}}
|
||||
|
||||
public override Plugins.AccountSettingsWidget get_widget() {
|
||||
return new AccountSettingsWidget();
|
||||
}
|
||||
}
|
||||
|
||||
[GtkTemplate (ui = "/org/dino-im/pgp_stack.ui")]
|
||||
private class AccountSettingsWidget : Gtk.Stack, Plugins.AccountSettingsWidget {
|
||||
[GtkChild] private Gtk.Label pgp_label;
|
||||
[GtkChild] private Gtk.Button pgp_button;
|
||||
[GtkChild] private Gtk.ComboBox pgp_combobox;
|
||||
|
||||
private Gtk.ListStore list_store = new Gtk.ListStore(2, typeof(string), typeof(string?));
|
||||
|
||||
public AccountSettingsWidget() {
|
||||
Gtk.CellRendererText renderer = new Gtk.CellRendererText();
|
||||
renderer.set_padding(0, 0);
|
||||
pgp_combobox.pack_start(renderer, true);
|
||||
pgp_combobox.add_attribute(renderer, "markup", 0);
|
||||
pgp_button.clicked.connect(() => { activated(); this.set_visible_child_name("entry"); pgp_combobox.popup(); });
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
this.set_visible_child_name("label");
|
||||
}
|
||||
|
||||
private void key_changed() {
|
||||
Gtk.TreeIter selected;
|
||||
pgp_combobox.get_active_iter(out selected);
|
||||
Value text;
|
||||
list_store.get_value(selected, 0, out text);
|
||||
pgp_label.set_markup((string) text);
|
||||
deactivate();
|
||||
}
|
||||
|
||||
public void set_account(Account account) {
|
||||
populate_pgp_combobox(account);
|
||||
}
|
||||
|
||||
private void populate_pgp_combobox(Account account) {
|
||||
pgp_combobox.changed.disconnect(key_changed);
|
||||
|
||||
Gtk.TreeIter iter;
|
||||
pgp_combobox.set_model(list_store);
|
||||
|
||||
list_store.clear();
|
||||
list_store.append(out iter);
|
||||
pgp_label.set_markup("Disabled\n<span font='9'>Select key</span>");
|
||||
list_store.set(iter, 0, "Disabled\n<span font='9'>Select key</span>", 1, null);
|
||||
Gee.List<GPG.Key> list = GPGHelper.get_keylist(null, true);
|
||||
foreach (GPG.Key key in list) {
|
||||
list_store.append(out iter);
|
||||
list_store.set(iter, 0, @"<span font='11'>$(Markup.escape_text(key.uids[0].uid))</span>\n<span font='9'>0x$(Markup.escape_text(key.fpr[0:16]))</span>");
|
||||
list_store.set(iter, 1, key.fpr);
|
||||
}
|
||||
|
||||
pgp_combobox.set_active(0);
|
||||
pgp_combobox.changed.connect(key_changed);
|
||||
}
|
||||
}
|
||||
|
||||
private class EncryptionListEntry : Plugins.EncryptionListEntry, Object {
|
||||
private PgpManager pgp_manager;
|
||||
|
||||
public EncryptionListEntry(PgpManager pgp_manager) {
|
||||
this.pgp_manager = pgp_manager;
|
||||
}
|
||||
|
||||
public Entities.Encryption encryption { get {
|
||||
return Encryption.PGP;
|
||||
}}
|
||||
|
||||
public string name { get {
|
||||
return "OpenPGP";
|
||||
}}
|
||||
|
||||
public bool can_encrypt(Entities.Conversation conversation) {
|
||||
return pgp_manager.pgp_key_ids.has_key(conversation.counterpart);
|
||||
}
|
||||
}
|
||||
|
||||
private PgpManager(StreamInteractor stream_interactor, Database db) {
|
||||
this.stream_interactor = stream_interactor;
|
||||
this.db = db;
|
||||
|
||||
stream_interactor.account_added.connect(on_account_added);
|
||||
MessageManager.get_instance(stream_interactor).pre_message_received.connect(on_pre_message_received);
|
||||
MessageManager.get_instance(stream_interactor).pre_message_send.connect(on_pre_message_send);
|
||||
}
|
||||
|
||||
private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
|
||||
if (Xep.Pgp.MessageFlag.get_flag(message_stanza) != null && Xep.Pgp.MessageFlag.get_flag(message_stanza).decrypted) {
|
||||
message.encryption = Encryption.PGP;
|
||||
}
|
||||
}
|
||||
|
||||
private void on_pre_message_send(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
|
||||
if (message.encryption == Encryption.PGP) {
|
||||
string? key_id = get_key_id(conversation.account, message.counterpart);
|
||||
bool encrypted = false;
|
||||
if (key_id != null) {
|
||||
encrypted = stream_interactor.get_stream(conversation.account).get_module(Xep.Pgp.Module.IDENTITY).encrypt(message_stanza, key_id);
|
||||
}
|
||||
if (!encrypted) {
|
||||
message.marked = Entities.Message.Marked.WONTSEND;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string? get_key_id(Account account, Jid jid) {
|
||||
return db.get_pgp_key(jid);
|
||||
}
|
||||
|
||||
public static PgpManager? get_instance(StreamInteractor stream_interactor) {
|
||||
return (PgpManager) stream_interactor.get_module(id);
|
||||
}
|
||||
|
||||
internal string get_id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private void on_account_added(Account account) {
|
||||
stream_interactor.module_manager.get_module(account, Xep.Pgp.Module.IDENTITY).received_jid_key_id.connect((stream, jid, key_id) => {
|
||||
on_jid_key_received(account, new Jid(jid), key_id);
|
||||
});
|
||||
}
|
||||
|
||||
private void on_jid_key_received(Account account, Jid jid, string key_id) {
|
||||
if (!pgp_key_ids.has_key(jid) || pgp_key_ids[jid] != key_id) {
|
||||
if (!MucManager.get_instance(stream_interactor).is_groupchat_occupant(jid, account)) {
|
||||
db.set_pgp_key(jid.bare_jid, key_id);
|
||||
}
|
||||
}
|
||||
pgp_key_ids[jid] = key_id;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ include(GlibCompileResourcesSupport)
|
|||
|
||||
set(MAIN_PACKAGES
|
||||
gee-0.8
|
||||
gio-2.0
|
||||
glib-2.0
|
||||
gtk+-3.0
|
||||
gmodule-2.0
|
||||
|
|
|
@ -7,7 +7,7 @@ void main(string[] args) {
|
|||
Gtk.init(ref args);
|
||||
Dino.Ui.Application app = new Dino.Ui.Application();
|
||||
Plugins.Loader loader = new Plugins.Loader();
|
||||
foreach(string plugin in new string[]{"omemo"}) {
|
||||
foreach(string plugin in new string[]{"omemo", "openpgp"}) {
|
||||
try {
|
||||
loader.load(plugin, app);
|
||||
} catch (Plugins.Error e) {
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
add_subdirectory(gpgme-vala)
|
||||
add_subdirectory(omemo)
|
||||
add_subdirectory(openpgp)
|
||||
add_subdirectory(signal-protocol)
|
||||
|
|
|
@ -30,8 +30,9 @@ OPTIONS
|
|||
|
||||
set(CFLAGS ${VALA_CFLAGS} ${GPGME_VALA_CFLAGS} ${GPGME_CFLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
add_definitions(${CFLAGS})
|
||||
add_library(gpgme-vala SHARED ${GPGME_VALA_C} src/gpgme_fix.c)
|
||||
add_library(gpgme-vala ${GPGME_VALA_C} src/gpgme_fix.c)
|
||||
target_link_libraries(gpgme-vala ${GPGME_VALA_LIBRARIES} ${GPGME_LIBRARIES})
|
||||
set_property(TARGET gpgme-vala PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/gpgme_fix.h"
|
||||
COMMAND
|
|
@ -4,7 +4,6 @@ include(${VALA_USE_FILE})
|
|||
|
||||
set(OMEMO_PACKAGES
|
||||
gee-0.8
|
||||
gio-2.0
|
||||
glib-2.0
|
||||
gtk+-3.0
|
||||
gmodule-2.0
|
||||
|
|
61
plugins/openpgp/CMakeLists.txt
Normal file
61
plugins/openpgp/CMakeLists.txt
Normal file
|
@ -0,0 +1,61 @@
|
|||
find_package(Vala REQUIRED)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
include(${VALA_USE_FILE})
|
||||
include(GlibCompileResourcesSupport)
|
||||
|
||||
set(OPENPGP_PACKAGES
|
||||
gee-0.8
|
||||
glib-2.0
|
||||
gtk+-3.0
|
||||
gmodule-2.0
|
||||
sqlite3
|
||||
)
|
||||
|
||||
pkg_check_modules(OPENPGP REQUIRED ${OPENPGP_PACKAGES})
|
||||
|
||||
set(RESOURCE_LIST
|
||||
account_settings_item.ui
|
||||
)
|
||||
|
||||
compile_gresources(
|
||||
OPENPGP_GRESOURCES_TARGET
|
||||
OPENPGP_GRESOURCES_XML
|
||||
TARGET ${CMAKE_CURRENT_BINARY_DIR}/resources/resources.c
|
||||
TYPE EMBED_C
|
||||
RESOURCES ${RESOURCE_LIST}
|
||||
PREFIX /org/dino-im
|
||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||
)
|
||||
|
||||
vala_precompile(OPENPGP_VALA_C
|
||||
SOURCES
|
||||
src/account_settings_entry.vala
|
||||
src/account_settings_widget.vala
|
||||
src/encryption_list_entry.vala
|
||||
src/manager.vala
|
||||
src/plugin.vala
|
||||
src/register_plugin.vala
|
||||
src/xmpp_flag.vala
|
||||
src/xmpp_module.vala
|
||||
CUSTOM_VAPIS
|
||||
${CMAKE_BINARY_DIR}/exports/gpgme.vapi
|
||||
${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi
|
||||
${CMAKE_BINARY_DIR}/exports/qlite.vapi
|
||||
${CMAKE_BINARY_DIR}/exports/dino.vapi
|
||||
PACKAGES
|
||||
${OPENPGP_PACKAGES}
|
||||
GRESOURCES
|
||||
${OPENPGP_GRESOURCES_XML}
|
||||
OPTIONS
|
||||
--target-glib=2.38
|
||||
${GLOBAL_DEBUG_FLAGS}
|
||||
--thread
|
||||
)
|
||||
|
||||
set(CFLAGS ${VALA_CFLAGS} ${OPENPGP_CFLAGS})
|
||||
add_definitions(${CFLAGS})
|
||||
add_library(openpgp SHARED ${OPENPGP_VALA_C} ${OPENPGP_GRESOURCES_TARGET})
|
||||
add_dependencies(openpgp dino-vapi gpgme-vapi)
|
||||
target_link_libraries(openpgp libdino gpgme-vala)
|
||||
set_target_properties(openpgp PROPERTIES PREFIX "")
|
||||
set_target_properties(openpgp PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/)
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="DinoPgpManagerAccountSettingsWidget">
|
||||
<template class="DinoPluginsOpenPgpAccountSettingsWidget">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="pgp_button">
|
18
plugins/openpgp/src/account_settings_entry.vala
Normal file
18
plugins/openpgp/src/account_settings_entry.vala
Normal file
|
@ -0,0 +1,18 @@
|
|||
namespace Dino.Plugins.OpenPgp {
|
||||
|
||||
public class AccountSettingsEntry : Plugins.AccountSettingsEntry {
|
||||
|
||||
public override string id { get {
|
||||
return "pgp_key_picker";
|
||||
}}
|
||||
|
||||
public override string name { get {
|
||||
return "OpenPGP";
|
||||
}}
|
||||
|
||||
public override Plugins.AccountSettingsWidget get_widget() {
|
||||
return new AccountSettingsWidget();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
61
plugins/openpgp/src/account_settings_widget.vala
Normal file
61
plugins/openpgp/src/account_settings_widget.vala
Normal file
|
@ -0,0 +1,61 @@
|
|||
using Dino.Entities;
|
||||
|
||||
namespace Dino.Plugins.OpenPgp {
|
||||
|
||||
[GtkTemplate (ui = "/org/dino-im/account_settings_item.ui")]
|
||||
|
||||
private class AccountSettingsWidget : Gtk.Stack, Plugins.AccountSettingsWidget {
|
||||
[GtkChild] private Gtk.Label pgp_label;
|
||||
[GtkChild] private Gtk.Button pgp_button;
|
||||
[GtkChild] private Gtk.ComboBox pgp_combobox;
|
||||
|
||||
private Gtk.ListStore list_store = new Gtk.ListStore(2, typeof(string), typeof(string?));
|
||||
|
||||
public AccountSettingsWidget() {
|
||||
Gtk.CellRendererText renderer = new Gtk.CellRendererText();
|
||||
renderer.set_padding(0, 0);
|
||||
pgp_combobox.pack_start(renderer, true);
|
||||
pgp_combobox.add_attribute(renderer, "markup", 0);
|
||||
pgp_button.clicked.connect(() => { activated(); this.set_visible_child_name("entry"); pgp_combobox.popup(); });
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
this.set_visible_child_name("label");
|
||||
}
|
||||
|
||||
private void key_changed() {
|
||||
Gtk.TreeIter selected;
|
||||
pgp_combobox.get_active_iter(out selected);
|
||||
Value text;
|
||||
list_store.get_value(selected, 0, out text);
|
||||
pgp_label.set_markup((string) text);
|
||||
deactivate();
|
||||
}
|
||||
|
||||
public void set_account(Account account) {
|
||||
populate_pgp_combobox(account);
|
||||
}
|
||||
|
||||
private void populate_pgp_combobox(Account account) {
|
||||
pgp_combobox.changed.disconnect(key_changed);
|
||||
|
||||
Gtk.TreeIter iter;
|
||||
pgp_combobox.set_model(list_store);
|
||||
|
||||
list_store.clear();
|
||||
list_store.append(out iter);
|
||||
pgp_label.set_markup("Disabled\n<span font='9'>Select key</span>");
|
||||
list_store.set(iter, 0, "Disabled\n<span font='9'>Select key</span>", 1, null);
|
||||
Gee.List<GPG.Key> list = GPGHelper.get_keylist(null, true);
|
||||
foreach (GPG.Key key in list) {
|
||||
list_store.append(out iter);
|
||||
list_store.set(iter, 0, @"<span font='11'>$(Markup.escape_text(key.uids[0].uid))</span>\n<span font='9'>0x$(Markup.escape_text(key.fpr[0:16]))</span>");
|
||||
list_store.set(iter, 1, key.fpr);
|
||||
}
|
||||
|
||||
pgp_combobox.set_active(0);
|
||||
pgp_combobox.changed.connect(key_changed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
26
plugins/openpgp/src/encryption_list_entry.vala
Normal file
26
plugins/openpgp/src/encryption_list_entry.vala
Normal file
|
@ -0,0 +1,26 @@
|
|||
using Dino.Entities;
|
||||
|
||||
namespace Dino.Plugins.OpenPgp {
|
||||
|
||||
private class EncryptionListEntry : Plugins.EncryptionListEntry, Object {
|
||||
|
||||
private StreamInteractor stream_interactor;
|
||||
|
||||
public EncryptionListEntry(StreamInteractor stream_interactor) {
|
||||
this.stream_interactor = stream_interactor;
|
||||
}
|
||||
|
||||
public Entities.Encryption encryption { get {
|
||||
return Encryption.PGP;
|
||||
}}
|
||||
|
||||
public string name { get {
|
||||
return "OpenPGP";
|
||||
}}
|
||||
|
||||
public bool can_encrypt(Entities.Conversation conversation) {
|
||||
return Manager.get_instance(stream_interactor).get_key_id(conversation.account, conversation.counterpart) != null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
78
plugins/openpgp/src/manager.vala
Normal file
78
plugins/openpgp/src/manager.vala
Normal file
|
@ -0,0 +1,78 @@
|
|||
using Gee;
|
||||
using Xmpp;
|
||||
|
||||
using Xmpp;
|
||||
using Dino.Entities;
|
||||
|
||||
namespace Dino.Plugins.OpenPgp {
|
||||
|
||||
public class Manager : StreamInteractionModule, Object {
|
||||
public const string id = "pgp_manager";
|
||||
|
||||
public const string MESSAGE_ENCRYPTED = "pgp";
|
||||
|
||||
private StreamInteractor stream_interactor;
|
||||
private Database db;
|
||||
private HashMap<Jid, string> pgp_key_ids = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func);
|
||||
|
||||
public static void start(StreamInteractor stream_interactor, Database db) {
|
||||
Manager m = new Manager(stream_interactor, db);
|
||||
stream_interactor.add_module(m);
|
||||
}
|
||||
|
||||
private Manager(StreamInteractor stream_interactor, Database db) {
|
||||
this.stream_interactor = stream_interactor;
|
||||
this.db = db;
|
||||
|
||||
stream_interactor.account_added.connect(on_account_added);
|
||||
MessageManager.get_instance(stream_interactor).pre_message_received.connect(on_pre_message_received);
|
||||
MessageManager.get_instance(stream_interactor).pre_message_send.connect(on_pre_message_send);
|
||||
}
|
||||
|
||||
private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
|
||||
if (MessageFlag.get_flag(message_stanza) != null && MessageFlag.get_flag(message_stanza).decrypted) {
|
||||
message.encryption = Encryption.PGP;
|
||||
}
|
||||
}
|
||||
|
||||
private void on_pre_message_send(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
|
||||
if (message.encryption == Encryption.PGP) {
|
||||
string? key_id = get_key_id(conversation.account, message.counterpart);
|
||||
bool encrypted = false;
|
||||
if (key_id != null) {
|
||||
encrypted = stream_interactor.get_stream(conversation.account).get_module(Module.IDENTITY).encrypt(message_stanza, key_id);
|
||||
}
|
||||
if (!encrypted) {
|
||||
message.marked = Entities.Message.Marked.WONTSEND;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string? get_key_id(Account account, Jid jid) {
|
||||
return db.get_pgp_key(jid);
|
||||
}
|
||||
|
||||
public static Manager? get_instance(StreamInteractor stream_interactor) {
|
||||
return (Manager) stream_interactor.get_module(id);
|
||||
}
|
||||
|
||||
internal string get_id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private void on_account_added(Account account) {
|
||||
stream_interactor.module_manager.get_module(account, Module.IDENTITY).received_jid_key_id.connect((stream, jid, key_id) => {
|
||||
on_jid_key_received(account, new Jid(jid), key_id);
|
||||
});
|
||||
}
|
||||
|
||||
private void on_jid_key_received(Account account, Jid jid, string key_id) {
|
||||
if (!pgp_key_ids.has_key(jid) || pgp_key_ids[jid] != key_id) {
|
||||
if (!MucManager.get_instance(stream_interactor).is_groupchat_occupant(jid, account)) {
|
||||
db.set_pgp_key(jid.bare_jid, key_id);
|
||||
}
|
||||
}
|
||||
pgp_key_ids[jid] = key_id;
|
||||
}
|
||||
}
|
||||
}
|
29
plugins/openpgp/src/plugin.vala
Normal file
29
plugins/openpgp/src/plugin.vala
Normal file
|
@ -0,0 +1,29 @@
|
|||
namespace Dino.Plugins.OpenPgp {
|
||||
|
||||
public class Plugin : Plugins.RootInterface, Object {
|
||||
public Dino.Application app;
|
||||
public Database db;
|
||||
|
||||
private Module module;
|
||||
private EncryptionListEntry list_entry;
|
||||
private AccountSettingsEntry settings_entry;
|
||||
|
||||
public void registered(Dino.Application app) {
|
||||
this.app = app;
|
||||
this.module = new Module();
|
||||
this.list_entry = new EncryptionListEntry(app.stream_interaction);
|
||||
this.settings_entry = new AccountSettingsEntry();
|
||||
app.plugin_registry.register_encryption_list_entry(list_entry);
|
||||
app.plugin_registry.register_account_settings_entry(settings_entry);
|
||||
app.stream_interaction.module_manager.initialize_account_modules.connect((account, list) => {
|
||||
list.add(new Module());
|
||||
});
|
||||
Manager.start(app.stream_interaction, app.db);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
}
|
3
plugins/openpgp/src/register_plugin.vala
Normal file
3
plugins/openpgp/src/register_plugin.vala
Normal file
|
@ -0,0 +1,3 @@
|
|||
public Type register_plugin(Module module) {
|
||||
return typeof (Dino.Plugins.OpenPgp.Plugin);
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
using Gee;
|
||||
|
||||
using Xmpp;
|
||||
using Xmpp.Core;
|
||||
|
||||
namespace Xmpp.Xep.Pgp {
|
||||
namespace Dino.Plugins.OpenPgp {
|
||||
|
||||
public class Flag : XmppStreamFlag {
|
||||
public const string ID = "pgp";
|
|
@ -1,8 +1,9 @@
|
|||
using GPG;
|
||||
|
||||
using Xmpp;
|
||||
using Xmpp.Core;
|
||||
|
||||
namespace Xmpp.Xep.Pgp {
|
||||
namespace Dino.Plugins.OpenPgp {
|
||||
private const string NS_URI = "jabber:x";
|
||||
private const string NS_URI_ENCRYPTED = NS_URI + ":encrypted";
|
||||
private const string NS_URI_SIGNED = NS_URI + ":signed";
|
|
@ -41,8 +41,6 @@ SOURCES
|
|||
"src/module/tls.vala"
|
||||
"src/module/util.vala"
|
||||
|
||||
"src/module/xep/0027_pgp/flag.vala"
|
||||
"src/module/xep/0027_pgp/module.vala"
|
||||
"src/module/xep/0030_service_discovery/flag.vala"
|
||||
"src/module/xep/0030_service_discovery/info_result.vala"
|
||||
"src/module/xep/0030_service_discovery/items_result.vala"
|
||||
|
@ -66,7 +64,6 @@ SOURCES
|
|||
"src/module/xep/pixbuf_storage.vala"
|
||||
CUSTOM_VAPIS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/vapi/uuid.vapi"
|
||||
"${CMAKE_BINARY_DIR}/exports/gpgme.vapi"
|
||||
PACKAGES
|
||||
${ENGINE_PACKAGES}
|
||||
GENERATE_VAPI
|
||||
|
@ -82,8 +79,7 @@ OPTIONS
|
|||
set(CFLAGS ${VALA_CFLAGS} ${ENGINE_CFLAGS} ${GPGME_CFLAGS} ${LIBUUID_CFLAGS})
|
||||
add_definitions(${CFLAGS})
|
||||
add_library(xmpp-vala SHARED ${ENGINE_VALA_C})
|
||||
add_dependencies(xmpp-vala gpgme-vapi)
|
||||
target_link_libraries(xmpp-vala gpgme-vala ${ENGINE_LIBRARIES} ${GPGME_LIBRARIES} ${LIBUUID_LIBRARIES})
|
||||
target_link_libraries(xmpp-vala ${ENGINE_LIBRARIES} ${GPGME_LIBRARIES} ${LIBUUID_LIBRARIES})
|
||||
|
||||
add_custom_target(xmpp-vala-vapi
|
||||
DEPENDS
|
||||
|
|
Loading…
Reference in a new issue