diff options
Diffstat (limited to 'plugins/omemo/src/logic')
-rw-r--r-- | plugins/omemo/src/logic/database.vala | 12 | ||||
-rw-r--r-- | plugins/omemo/src/logic/manager.vala | 13 | ||||
-rw-r--r-- | plugins/omemo/src/logic/trust_manager.vala | 19 |
3 files changed, 19 insertions, 25 deletions
diff --git a/plugins/omemo/src/logic/database.vala b/plugins/omemo/src/logic/database.vala index bce1d4e6..1f9e1304 100644 --- a/plugins/omemo/src/logic/database.vala +++ b/plugins/omemo/src/logic/database.vala @@ -9,18 +9,6 @@ public class Database : Qlite.Database { private const int VERSION = 4; public class IdentityMetaTable : Table { - public enum TrustLevel { - VERIFIED, - TRUSTED, - UNTRUSTED, - UNKNOWN; - - public string to_string() { - int val = this; - return val.to_string(); - } - } - //Default to provide backwards compatability public Column<int> identity_id = new Column.Integer("identity_id") { not_null = true, min_version = 2, default = "-1" }; public Column<string> address_name = new Column.Text("address_name") { not_null = true }; diff --git a/plugins/omemo/src/logic/manager.vala b/plugins/omemo/src/logic/manager.vala index db64c3ee..0fe4fe50 100644 --- a/plugins/omemo/src/logic/manager.vala +++ b/plugins/omemo/src/logic/manager.vala @@ -248,15 +248,15 @@ public class Manager : StreamInteractionModule, Object { //Get trust information from the database if the device id is known Row device = db.identity_meta.get_device(identity_id, jid.bare_jid.to_string(), device_id); - Database.IdentityMetaTable.TrustLevel trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN; + TrustLevel trusted = TrustLevel.UNKNOWN; if (device != null) { - trusted = (Database.IdentityMetaTable.TrustLevel) device[db.identity_meta.trust_level]; + trusted = (TrustLevel) device[db.identity_meta.trust_level]; } if(untrust) { - trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN; - } else if (blind_trust && trusted == Database.IdentityMetaTable.TrustLevel.UNKNOWN) { - trusted = Database.IdentityMetaTable.TrustLevel.TRUSTED; + trusted = TrustLevel.UNKNOWN; + } else if (blind_trust && trusted == TrustLevel.UNKNOWN) { + trusted = TrustLevel.TRUSTED; } //Update the database with the appropriate trust information @@ -278,7 +278,7 @@ public class Manager : StreamInteractionModule, Object { MessageState state = message_states[msg]; - if (trusted == Database.IdentityMetaTable.TrustLevel.TRUSTED || trusted == Database.IdentityMetaTable.TrustLevel.VERIFIED) { + if (trusted == TrustLevel.TRUSTED || trusted == TrustLevel.VERIFIED) { if(account.bare_jid.equals(jid) || (msg.counterpart != null && (msg.counterpart.equals_bare(jid) || occupants.contains(jid)))) { session_created = module.start_session(stream, jid, device_id, bundle); } @@ -366,6 +366,7 @@ public class Manager : StreamInteractionModule, Object { if (flag.has_room_feature(conversation.counterpart, Xep.Muc.Feature.NON_ANONYMOUS) && flag.has_room_feature(conversation.counterpart, Xep.Muc.Feature.MEMBERS_ONLY)) { foreach(Jid jid in stream_interactor.get_module(MucManager.IDENTITY).get_offline_members(conversation.counterpart, conversation.account)) { if (!trust_manager.is_known_address(conversation.account, jid.bare_jid)) { + debug(@"Can't enable OMEMO for $(conversation.counterpart): missing keys for $(jid.bare_jid)"); return false; } } diff --git a/plugins/omemo/src/logic/trust_manager.vala b/plugins/omemo/src/logic/trust_manager.vala index d57adc35..662cea73 100644 --- a/plugins/omemo/src/logic/trust_manager.vala +++ b/plugins/omemo/src/logic/trust_manager.vala @@ -34,13 +34,15 @@ public class TrustManager { .set(db.trust.blind_trust, blind_trust).perform(); } - public void set_device_trust(Account account, Jid jid, int device_id, Database.IdentityMetaTable.TrustLevel trust_level) { + public void set_device_trust(Account account, Jid jid, int device_id, TrustLevel trust_level) { int identity_id = db.identity.get_id(account.id); db.identity_meta.update() .with(db.identity_meta.identity_id, "=", identity_id) .with(db.identity_meta.address_name, "=", jid.bare_jid.to_string()) .with(db.identity_meta.device_id, "=", device_id) .set(db.identity_meta.trust_level, trust_level).perform(); + + // Hide messages from untrusted or unknown devices string selection = null; string[] selection_args = {}; var app_db = Application.get_default().db; @@ -54,7 +56,7 @@ public class TrustManager { } if (selection != null) { app_db.content_item.update() - .set(app_db.content_item.hide, trust_level == Database.IdentityMetaTable.TrustLevel.UNTRUSTED || trust_level == Database.IdentityMetaTable.TrustLevel.UNKNOWN) + .set(app_db.content_item.hide, trust_level == TrustLevel.UNTRUSTED || trust_level == TrustLevel.UNKNOWN) .where(selection, selection_args) .perform(); } @@ -135,6 +137,8 @@ public class TrustManager { } } } + + // Encrypt the key for each own device address.name = self_jid.bare_jid.to_string(); foreach(int32 device_id in get_trusted_devices(account, self_jid)) { if (module.is_ignored_device(self_jid, device_id)) { @@ -175,7 +179,7 @@ public class TrustManager { int identity_id = db.identity.get_id(account.id); if (identity_id < 0) return devices; foreach (Row device in db.identity_meta.get_trusted_devices(identity_id, jid.bare_jid.to_string())) { - if(device[db.identity_meta.trust_level] != Database.IdentityMetaTable.TrustLevel.UNKNOWN || device[db.identity_meta.identity_key_public_base64] == null) + if(device[db.identity_meta.trust_level] != TrustLevel.UNKNOWN || device[db.identity_meta.identity_key_public_base64] == null) devices.add(device[db.identity_meta.device_id]); } return devices; @@ -214,8 +218,8 @@ public class TrustManager { } int identity_id = db.identity.get_id(conversation.account.id); - Database.IdentityMetaTable.TrustLevel trust_level = (Database.IdentityMetaTable.TrustLevel) db.identity_meta.get_device(identity_id, jid.bare_jid.to_string(), device_id)[db.identity_meta.trust_level]; - if (trust_level == Database.IdentityMetaTable.TrustLevel.UNTRUSTED || trust_level == Database.IdentityMetaTable.TrustLevel.UNKNOWN) { + TrustLevel trust_level = (TrustLevel) db.identity_meta.get_device(identity_id, jid.bare_jid.to_string(), device_id)[db.identity_meta.trust_level]; + if (trust_level == TrustLevel.UNTRUSTED || trust_level == TrustLevel.UNKNOWN) { stream_interactor.get_module(ContentItemStore.IDENTITY).set_item_hide(content_item, true); } @@ -224,7 +228,7 @@ public class TrustManager { .value(db.content_item_meta.identity_id, identity_id) .value(db.content_item_meta.address_name, jid.bare_jid.to_string()) .value(db.content_item_meta.device_id, device_id) - .value(db.content_item_meta.trusted_when_received, trust_level != Database.IdentityMetaTable.TrustLevel.UNTRUSTED) + .value(db.content_item_meta.trusted_when_received, trust_level != TrustLevel.UNTRUSTED) .perform(); } return false; @@ -281,6 +285,7 @@ public class TrustManager { if (real_jid != null) { possible_jids.add(real_jid); } else { + // If we don't know the device name (MUC history w/o MAM), test decryption with all keys with fitting device id foreach (Row row in db.identity_meta.get_with_device_id(sid)) { possible_jids.add(new Jid(row[db.identity_meta.address_name])); } @@ -320,7 +325,7 @@ public class TrustManager { continue; } - // If we figured out which real jid a message comes from due to + // If we figured out which real jid a message comes from due to decryption working, save it if (conversation.type_ == Conversation.Type.GROUPCHAT && message.real_jid == null) { message.real_jid = possible_jid; } |