2021-04-25 17:49:10 +00:00
|
|
|
using Gee;
|
2019-09-10 18:57:10 +00:00
|
|
|
using Dino.Entities;
|
|
|
|
|
2017-04-07 09:09:47 +00:00
|
|
|
extern const string GETTEXT_PACKAGE;
|
|
|
|
extern const string LOCALE_INSTALL_DIR;
|
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
namespace Dino.Plugins.Omemo {
|
2017-03-11 00:29:38 +00:00
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
public class Plugin : RootInterface, Object {
|
2018-06-11 07:48:55 +00:00
|
|
|
public const bool DEBUG = false;
|
2017-04-18 15:55:20 +00:00
|
|
|
private static Signal.Context? _context;
|
|
|
|
public static Signal.Context get_context() {
|
|
|
|
assert(_context != null);
|
|
|
|
return (!)_context;
|
|
|
|
}
|
|
|
|
public static bool ensure_context() {
|
|
|
|
lock(_context) {
|
|
|
|
try {
|
|
|
|
if (_context == null) {
|
|
|
|
_context = new Signal.Context(DEBUG);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} catch (Error e) {
|
2021-04-25 17:49:10 +00:00
|
|
|
warning("Error initializing Signal Context %s", e.message);
|
2017-04-18 15:55:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-11 00:29:38 +00:00
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
public Dino.Application app;
|
|
|
|
public Database db;
|
|
|
|
public EncryptionListEntry list_entry;
|
|
|
|
public AccountSettingsEntry settings_entry;
|
2017-05-13 15:48:13 +00:00
|
|
|
public ContactDetailsProvider contact_details_provider;
|
2018-06-11 06:11:04 +00:00
|
|
|
public DeviceNotificationPopulator device_notification_populator;
|
2018-08-09 23:45:22 +00:00
|
|
|
public OwnNotifications own_notifications;
|
|
|
|
public TrustManager trust_manager;
|
2021-04-25 17:49:10 +00:00
|
|
|
public HashMap<Account, OmemoDecryptor> decryptors = new HashMap<Account, OmemoDecryptor>(Account.hash_func, Account.equals_func);
|
|
|
|
public HashMap<Account, OmemoEncryptor> encryptors = new HashMap<Account, OmemoEncryptor>(Account.hash_func, Account.equals_func);
|
2017-03-11 00:29:38 +00:00
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
public void registered(Dino.Application app) {
|
2017-10-28 21:48:07 +00:00
|
|
|
ensure_context();
|
|
|
|
this.app = app;
|
|
|
|
this.db = new Database(Path.build_filename(Application.get_storage_dir(), "omemo.db"));
|
|
|
|
this.list_entry = new EncryptionListEntry(this);
|
|
|
|
this.settings_entry = new AccountSettingsEntry(this);
|
|
|
|
this.contact_details_provider = new ContactDetailsProvider(this);
|
2018-06-11 06:11:04 +00:00
|
|
|
this.device_notification_populator = new DeviceNotificationPopulator(this, this.app.stream_interactor);
|
2018-08-09 23:45:22 +00:00
|
|
|
this.trust_manager = new TrustManager(this.app.stream_interactor, this.db);
|
2021-04-25 17:49:10 +00:00
|
|
|
|
2017-10-28 21:48:07 +00:00
|
|
|
this.app.plugin_registry.register_encryption_list_entry(list_entry);
|
|
|
|
this.app.plugin_registry.register_account_settings_entry(settings_entry);
|
|
|
|
this.app.plugin_registry.register_contact_details_entry(contact_details_provider);
|
2018-06-19 10:52:00 +00:00
|
|
|
this.app.plugin_registry.register_notification_populator(device_notification_populator);
|
2020-03-27 18:28:13 +00:00
|
|
|
this.app.plugin_registry.register_conversation_addition_populator(new BadMessagesPopulator(this.app.stream_interactor, this));
|
2021-05-03 11:17:17 +00:00
|
|
|
this.app.plugin_registry.register_call_entryption_entry(DtlsSrtpVerificationDraft.NS_URI, new CallEncryptionEntry(db));
|
2021-04-25 17:49:10 +00:00
|
|
|
|
2017-10-28 21:48:07 +00:00
|
|
|
this.app.stream_interactor.module_manager.initialize_account_modules.connect((account, list) => {
|
2021-04-25 17:49:10 +00:00
|
|
|
Signal.Store signal_store = Plugin.get_context().create_store();
|
|
|
|
list.add(new StreamModule(signal_store));
|
|
|
|
decryptors[account] = new OmemoDecryptor(account, app.stream_interactor, trust_manager, db, signal_store);
|
|
|
|
list.add(decryptors[account]);
|
|
|
|
encryptors[account] = new OmemoEncryptor(account, trust_manager,signal_store);
|
|
|
|
list.add(encryptors[account]);
|
|
|
|
list.add(new JetOmemo.Module());
|
|
|
|
list.add(new DtlsSrtpVerificationDraft.StreamModule());
|
2018-08-09 23:45:22 +00:00
|
|
|
this.own_notifications = new OwnNotifications(this, this.app.stream_interactor, account);
|
2017-10-28 21:48:07 +00:00
|
|
|
});
|
2018-11-23 19:11:32 +00:00
|
|
|
|
2021-05-03 11:17:17 +00:00
|
|
|
app.stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(new DecryptMessageListener(decryptors));
|
2019-07-18 00:03:42 +00:00
|
|
|
app.stream_interactor.get_module(FileManager.IDENTITY).add_file_decryptor(new OmemoFileDecryptor());
|
|
|
|
app.stream_interactor.get_module(FileManager.IDENTITY).add_file_encryptor(new OmemoFileEncryptor());
|
2019-09-10 18:57:10 +00:00
|
|
|
JingleFileHelperRegistry.instance.add_encryption_helper(Encryption.OMEMO, new JetOmemo.EncryptionHelper(app.stream_interactor));
|
2019-07-18 00:03:42 +00:00
|
|
|
|
2021-04-25 17:49:10 +00:00
|
|
|
Manager.start(this.app.stream_interactor, db, trust_manager, encryptors);
|
2017-04-07 09:09:47 +00:00
|
|
|
|
2018-08-12 11:16:42 +00:00
|
|
|
SimpleAction own_keys_action = new SimpleAction("own-keys", VariantType.INT32);
|
|
|
|
own_keys_action.activate.connect((variant) => {
|
|
|
|
foreach(Dino.Entities.Account account in this.app.stream_interactor.get_accounts()) {
|
|
|
|
if(account.id == variant.get_int32()) {
|
|
|
|
ContactDetailsDialog dialog = new ContactDetailsDialog(this, account, account.bare_jid);
|
2020-10-27 14:31:39 +00:00
|
|
|
dialog.set_transient_for(((Gtk.Application) this.app).get_active_window());
|
2018-08-12 11:16:42 +00:00
|
|
|
dialog.present();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.app.add_action(own_keys_action);
|
|
|
|
|
2017-10-28 21:48:07 +00:00
|
|
|
string locales_dir;
|
|
|
|
if (app.search_path_generator != null) {
|
|
|
|
locales_dir = ((!)app.search_path_generator).get_locale_path(GETTEXT_PACKAGE, LOCALE_INSTALL_DIR);
|
|
|
|
} else {
|
|
|
|
locales_dir = LOCALE_INSTALL_DIR;
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
2017-10-28 21:48:07 +00:00
|
|
|
internationalize(GETTEXT_PACKAGE, locales_dir);
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
public void shutdown() {
|
|
|
|
// Nothing to do
|
|
|
|
}
|
2019-10-21 23:23:43 +00:00
|
|
|
|
|
|
|
public bool has_new_devices(Account account, Xmpp.Jid jid) {
|
|
|
|
int identity_id = db.identity.get_id(account.id);
|
|
|
|
if (identity_id < 0) return false;
|
|
|
|
|
|
|
|
return db.identity_meta.get_new_devices(identity_id, jid.bare_jid.to_string()).count() > 0;
|
|
|
|
}
|
2017-03-11 00:29:38 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 19:20:09 +00:00
|
|
|
}
|