aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/logic
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/omemo/src/logic')
-rw-r--r--plugins/omemo/src/logic/manager.vala26
-rw-r--r--plugins/omemo/src/logic/trust_manager.vala18
2 files changed, 21 insertions, 23 deletions
diff --git a/plugins/omemo/src/logic/manager.vala b/plugins/omemo/src/logic/manager.vala
index 0fe4fe50..b8862ab8 100644
--- a/plugins/omemo/src/logic/manager.vala
+++ b/plugins/omemo/src/logic/manager.vala
@@ -358,23 +358,21 @@ public class Manager : StreamInteractionModule, Object {
public bool can_encrypt(Entities.Conversation conversation) {
- XmppStream? stream = stream_interactor.get_stream(conversation.account);
- if (stream == null) return false;
- if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(conversation.counterpart, conversation.account)){
- Xep.Muc.Flag? flag = stream.get_flag(Xep.Muc.Flag.IDENTITY);
- if (flag == null) return false;
- 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;
- }
+ if (stream_interactor.get_module(MucManager.IDENTITY).is_public_room(conversation.account, conversation.counterpart)){
+ debug("Can't enable OMEMO for %s: Room not members-only or non-anonymous", conversation.counterpart.to_string());
+ return false;
+ }
+
+ if (stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart)){
+ 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 %s: missing keys for %s", conversation.counterpart.to_string(), jid.bare_jid.to_string());
+ return false;
}
- return true;
- } else {
- return false;
}
+ return true;
}
+
return trust_manager.is_known_address(conversation.account, conversation.counterpart.bare_jid);
}
diff --git a/plugins/omemo/src/logic/trust_manager.vala b/plugins/omemo/src/logic/trust_manager.vala
index 662cea73..7758de75 100644
--- a/plugins/omemo/src/logic/trust_manager.vala
+++ b/plugins/omemo/src/logic/trust_manager.vala
@@ -62,7 +62,7 @@ public class TrustManager {
}
}
- private StanzaNode create_encrypted_key(uint8[] key, Address address, Store store) throws GLib.Error {
+ private StanzaNode create_encrypted_key_node(uint8[] key, Address address, Store store) throws GLib.Error {
SessionCipher cipher = store.create_session_cipher(address);
CiphertextMessage device_key = cipher.encrypt(key);
StanzaNode key_node = new StanzaNode.build("key", NS_URI)
@@ -108,9 +108,9 @@ public class TrustManager {
Memory.copy(keytag, key, key.length);
Memory.copy((uint8*)keytag + key.length, tag, tag.length);
- StanzaNode header;
- StanzaNode encrypted = new StanzaNode.build("encrypted", NS_URI).add_self_xmlns()
- .put_node(header = new StanzaNode.build("header", NS_URI)
+ StanzaNode header_node;
+ StanzaNode encrypted_node = new StanzaNode.build("encrypted", NS_URI).add_self_xmlns()
+ .put_node(header_node = new StanzaNode.build("header", NS_URI)
.put_attribute("sid", module.store.local_registration_id.to_string())
.put_node(new StanzaNode.build("iv", NS_URI)
.put_node(new StanzaNode.text(Base64.encode(iv)))))
@@ -128,8 +128,8 @@ public class TrustManager {
try {
address.name = recipient.bare_jid.to_string();
address.device_id = (int) device_id;
- StanzaNode key_node = create_encrypted_key(keytag, address, module.store);
- header.put_node(key_node);
+ StanzaNode key_node = create_encrypted_key_node(keytag, address, module.store);
+ header_node.put_node(key_node);
status.other_success++;
} catch (Error e) {
if (e.code == ErrorCode.UNKNOWN) status.other_unknown++;
@@ -148,8 +148,8 @@ public class TrustManager {
if (device_id != module.store.local_registration_id) {
address.device_id = (int) device_id;
try {
- StanzaNode key_node = create_encrypted_key(keytag, address, module.store);
- header.put_node(key_node);
+ StanzaNode key_node = create_encrypted_key_node(keytag, address, module.store);
+ header_node.put_node(key_node);
status.own_success++;
} catch (Error e) {
if (e.code == ErrorCode.UNKNOWN) status.own_unknown++;
@@ -158,7 +158,7 @@ public class TrustManager {
}
}
- message.stanza.put_node(encrypted);
+ message.stanza.put_node(encrypted_node);
Xep.ExplicitEncryption.add_encryption_tag_to_message(message, NS_URI, "OMEMO");
message.body = "[This message is OMEMO encrypted]";
status.encrypted = true;