aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/manager.vala
diff options
context:
space:
mode:
authorSamuel Hand <samuel.hand@openmailbox.org>2018-06-11 07:11:04 +0100
committerSamuel Hand <samuel.hand@openmailbox.org>2018-06-11 07:11:22 +0100
commit40c6835600cc6ebcb816f9aee4a6540ef8e362f0 (patch)
treea3bcbb33edeb469e1b7c17241a5cc40189287056 /plugins/omemo/src/manager.vala
parent630df3a2ee3ac5086ab15ecbb4da88e0e2e9c82d (diff)
downloaddino-40c6835600cc6ebcb816f9aee4a6540ef8e362f0.tar.gz
dino-40c6835600cc6ebcb816f9aee4a6540ef8e362f0.zip
Add trust management utilities to the omemo plugin
Diffstat (limited to 'plugins/omemo/src/manager.vala')
-rw-r--r--plugins/omemo/src/manager.vala76
1 files changed, 74 insertions, 2 deletions
diff --git a/plugins/omemo/src/manager.vala b/plugins/omemo/src/manager.vala
index eb0c6378..3047410c 100644
--- a/plugins/omemo/src/manager.vala
+++ b/plugins/omemo/src/manager.vala
@@ -116,6 +116,7 @@ public class Manager : StreamInteractionModule, Object {
if (!state.will_send_now) {
if (message.marked == Entities.Message.Marked.WONTSEND) {
if (Plugin.DEBUG) print(@"OMEMO: message was not sent: $state\n");
+ message_states.unset(message);
} else {
if (Plugin.DEBUG) print(@"OMEMO: message will be delayed: $state\n");
@@ -206,7 +207,7 @@ public class Manager : StreamInteractionModule, Object {
return;
}
ArrayList<int32> device_list = module.get_device_list(jid);
- db.identity_meta.insert_device_list(jid.bare_jid.to_string(), device_list);
+ db.identity_meta.insert_device_list(account.id, jid.bare_jid.to_string(), device_list);
int inc = 0;
foreach (Row row in db.identity_meta.with_address(jid.bare_jid.to_string()).with_null(db.identity_meta.identity_key_public_base64)) {
module.fetch_bundle(stream, Jid.parse(row[db.identity_meta.address_name]), row[db.identity_meta.device_id]);
@@ -215,10 +216,81 @@ public class Manager : StreamInteractionModule, Object {
if (inc > 0) {
if (Plugin.DEBUG) print(@"OMEMO: new bundles $inc/$(device_list.size) for $jid\n");
}
+
+ if(db.trust.select().with(db.trust.identity_id, "=", account.id).with(db.trust.address_name, " =", jid.bare_jid.to_string()).count() == 0)
+ db.trust.insert().value(db.trust.identity_id, account.id).value(db.trust.address_name, jid .bare_jid.to_string()).value(db.trust.blind_trust, true).perform();
+
}
public void on_bundle_fetched(Account account, Jid jid, int32 device_id, Bundle bundle) {
- db.identity_meta.insert_device_bundle(jid.bare_jid.to_string(), device_id, bundle);
+ bool blind_trust = db.trust.get_blind_trust(account.id, jid.bare_jid.to_string());
+
+ bool untrust = !(blind_trust || db.identity_meta.with_address(jid.bare_jid.to_string())
+ .with(db.identity_meta.identity_id, "=", account.id)
+ .with(db.identity_meta.device_id, "=", device_id)
+ .with(db.identity_meta.identity_key_public_base64, "=", Base64.encode(bundle.identity_key.serialize()))
+ .count() > 0);
+
+ bool? trusted = null;
+ foreach(Row row in db.identity_meta.with_address(jid.bare_jid.to_string())
+ .with(db.identity_meta.identity_id, "=", account.id)
+ .with(db.identity_meta.device_id, "=", device_id)) {
+ trusted = row[db.identity_meta.trusted_identity];
+ break;
+ }
+
+ if(db.identity_meta.with_address(jid.bare_jid.to_string())
+ .with(db.identity_meta.identity_id, "=", account.id)
+ .with(db.identity_meta.device_id, "=", device_id)
+ .with_null(db.identity_meta.trusted_identity).count() > 0)
+ trusted = null;
+
+ if(untrust)
+ trusted = null;
+ else if (blind_trust && trusted == null)
+ trusted = true;
+
+ db.identity_meta.insert_device_bundle(account.id, jid.bare_jid.to_string(), device_id, bundle, trusted);
+
+ if(trusted == null)
+ trusted = false;
+
+ XmppStream? stream = stream_interactor.get_stream(account);
+ if(stream == null) return;
+ StreamModule? module = ((!)stream).get_module(StreamModule.IDENTITY);
+ if(module == null) return;
+
+ HashSet<Entities.Message> send_now = new HashSet<Entities.Message>();
+ bool session_needed = false;
+ lock (message_states) {
+ foreach (Entities.Message msg in message_states.keys) {
+ bool session_created = true;
+ if (!msg.account.equals(account)) continue;
+ MessageState state = message_states[msg];
+
+ if (trusted != true) {
+ module.untrust_device(jid, device_id);
+ } else {
+ if(account.bare_jid.equals(jid) || (msg.counterpart != null && msg.counterpart.equals_bare(jid)))
+ session_created = module.create_session_if_needed(stream, jid, device_id, bundle);
+ }
+ if (account.bare_jid.equals(jid) && session_created) {
+ state.waiting_own_sessions--;
+ } else if (msg.counterpart != null && msg.counterpart.equals_bare(jid) && session_created) {
+ state.waiting_other_sessions--;
+ }
+ if (state.should_retry_now()){
+ send_now.add(msg);
+ state.active_send_attempt = true;
+ }
+ }
+ }
+ foreach (Entities.Message msg in send_now) {
+ if (msg.counterpart == null) continue;
+ Entities.Conversation? conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation((!)msg.counterpart, account);
+ if (conv == null) continue;
+ stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(msg, (!)conv, true);
+ }
}
private void on_store_created(Account account, Store store) {