OMEMO: Rename variables, refactor can_encrypt
This commit is contained in:
parent
a7aa5130f8
commit
06db4d0aa6
|
@ -358,23 +358,21 @@ public class Manager : StreamInteractionModule, Object {
|
||||||
|
|
||||||
|
|
||||||
public bool can_encrypt(Entities.Conversation conversation) {
|
public bool can_encrypt(Entities.Conversation conversation) {
|
||||||
XmppStream? stream = stream_interactor.get_stream(conversation.account);
|
if (stream_interactor.get_module(MucManager.IDENTITY).is_public_room(conversation.account, conversation.counterpart)){
|
||||||
if (stream == null) return false;
|
debug("Can't enable OMEMO for %s: Room not members-only or non-anonymous", conversation.counterpart.to_string());
|
||||||
if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(conversation.counterpart, conversation.account)){
|
return false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
return trust_manager.is_known_address(conversation.account, conversation.counterpart.bare_jid);
|
return trust_manager.is_known_address(conversation.account, conversation.counterpart.bare_jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
SessionCipher cipher = store.create_session_cipher(address);
|
||||||
CiphertextMessage device_key = cipher.encrypt(key);
|
CiphertextMessage device_key = cipher.encrypt(key);
|
||||||
StanzaNode key_node = new StanzaNode.build("key", NS_URI)
|
StanzaNode key_node = new StanzaNode.build("key", NS_URI)
|
||||||
|
@ -108,9 +108,9 @@ public class TrustManager {
|
||||||
Memory.copy(keytag, key, key.length);
|
Memory.copy(keytag, key, key.length);
|
||||||
Memory.copy((uint8*)keytag + key.length, tag, tag.length);
|
Memory.copy((uint8*)keytag + key.length, tag, tag.length);
|
||||||
|
|
||||||
StanzaNode header;
|
StanzaNode header_node;
|
||||||
StanzaNode encrypted = new StanzaNode.build("encrypted", NS_URI).add_self_xmlns()
|
StanzaNode encrypted_node = new StanzaNode.build("encrypted", NS_URI).add_self_xmlns()
|
||||||
.put_node(header = new StanzaNode.build("header", NS_URI)
|
.put_node(header_node = new StanzaNode.build("header", NS_URI)
|
||||||
.put_attribute("sid", module.store.local_registration_id.to_string())
|
.put_attribute("sid", module.store.local_registration_id.to_string())
|
||||||
.put_node(new StanzaNode.build("iv", NS_URI)
|
.put_node(new StanzaNode.build("iv", NS_URI)
|
||||||
.put_node(new StanzaNode.text(Base64.encode(iv)))))
|
.put_node(new StanzaNode.text(Base64.encode(iv)))))
|
||||||
|
@ -128,8 +128,8 @@ public class TrustManager {
|
||||||
try {
|
try {
|
||||||
address.name = recipient.bare_jid.to_string();
|
address.name = recipient.bare_jid.to_string();
|
||||||
address.device_id = (int) device_id;
|
address.device_id = (int) device_id;
|
||||||
StanzaNode key_node = create_encrypted_key(keytag, address, module.store);
|
StanzaNode key_node = create_encrypted_key_node(keytag, address, module.store);
|
||||||
header.put_node(key_node);
|
header_node.put_node(key_node);
|
||||||
status.other_success++;
|
status.other_success++;
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
if (e.code == ErrorCode.UNKNOWN) status.other_unknown++;
|
if (e.code == ErrorCode.UNKNOWN) status.other_unknown++;
|
||||||
|
@ -148,8 +148,8 @@ public class TrustManager {
|
||||||
if (device_id != module.store.local_registration_id) {
|
if (device_id != module.store.local_registration_id) {
|
||||||
address.device_id = (int) device_id;
|
address.device_id = (int) device_id;
|
||||||
try {
|
try {
|
||||||
StanzaNode key_node = create_encrypted_key(keytag, address, module.store);
|
StanzaNode key_node = create_encrypted_key_node(keytag, address, module.store);
|
||||||
header.put_node(key_node);
|
header_node.put_node(key_node);
|
||||||
status.own_success++;
|
status.own_success++;
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
if (e.code == ErrorCode.UNKNOWN) status.own_unknown++;
|
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");
|
Xep.ExplicitEncryption.add_encryption_tag_to_message(message, NS_URI, "OMEMO");
|
||||||
message.body = "[This message is OMEMO encrypted]";
|
message.body = "[This message is OMEMO encrypted]";
|
||||||
status.encrypted = true;
|
status.encrypted = true;
|
||||||
|
|
|
@ -5,7 +5,7 @@ using Xmpp;
|
||||||
namespace Dino.Plugins.Omemo {
|
namespace Dino.Plugins.Omemo {
|
||||||
|
|
||||||
public class Bundle {
|
public class Bundle {
|
||||||
private StanzaNode? node;
|
public StanzaNode? node;
|
||||||
|
|
||||||
public Bundle(StanzaNode? node) {
|
public Bundle(StanzaNode? node) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
|
@ -85,4 +85,4 @@ public class Bundle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue