OMEMO: Include XEP-0380 EME tag in encrypted messages

This commit is contained in:
JC Brand 2021-07-05 14:56:20 +02:00
parent 06460507d4
commit bff714f24c
5 changed files with 26 additions and 5 deletions

View File

@ -48,6 +48,7 @@ Strophe.addNamespace('CARBONS', 'urn:xmpp:carbons:2');
Strophe.addNamespace('CHATSTATES', 'http://jabber.org/protocol/chatstates');
Strophe.addNamespace('CSI', 'urn:xmpp:csi:0');
Strophe.addNamespace('DELAY', 'urn:xmpp:delay');
Strophe.addNamespace('EME', 'urn:xmpp:eme:0');
Strophe.addNamespace('FASTEN', 'urn:xmpp:fasten:0');
Strophe.addNamespace('FORWARD', 'urn:xmpp:forward:0');
Strophe.addNamespace('HINTS', 'urn:xmpp:hints');

View File

@ -48,13 +48,29 @@ export function getStanzaIDs (stanza, original_stanza) {
}
export function getEncryptionAttributes (stanza, _converse) {
const eme_tag = sizzle(`encryption[xmlns="${Strophe.NS.EME}"]`, stanza).pop();
const namespace = eme_tag?.getAttribute('namespace');
const attrs = {};
if (namespace) {
attrs.is_encrypted = true;
attrs.encryption_namespace = namespace;
if (namespace !== Strophe.NS.OMEMO) {
// Found an encrypted message, but it's not OMEMO
return attrs;
}
}
const encrypted = sizzle(`encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).pop();
const attrs = { 'is_encrypted': !!encrypted };
if (!eme_tag) {
attrs.is_encrypted = !!encrypted;
}
if (!encrypted || api.settings.get('clear_cache_on_logout')) {
return attrs;
}
const header = encrypted.querySelector('header');
attrs['encrypted'] = { 'device_id': header.getAttribute('sid') };
attrs.encrypted = { 'device_id': header.getAttribute('sid') };
const device_id = _converse.omemo_store?.get('device_id');
const key = device_id && sizzle(`key[rid="${device_id}"]`, encrypted).pop();

View File

@ -57,8 +57,8 @@ describe("The OMEMO module", function() {
type="result">
<slot xmlns="urn:xmpp:http:upload:0">
<put url="https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/secret.txt">
<header name="Authorization">Basic Base64String==</header>
<header name="Cookie">foo=bar; user=romeo</header>
<header name="Authorization">Basic Base64String==</header>
<header name="Cookie">foo=bar; user=romeo</header>
</put>
<get url="${url}" />
</slot>
@ -139,6 +139,7 @@ describe("The OMEMO module", function() {
`<payload>${sent_stanza.querySelector('payload').textContent}</payload>`+
`</encrypted>`+
`<store xmlns="urn:xmpp:hints"/>`+
`<encryption namespace="eu.siacs.conversations.axolotl" xmlns="urn:xmpp:eme:0"/>`+
`</message>`);
const link_el = await u.waitUntil(() => view.querySelector('.chat-msg__media'));

View File

@ -106,6 +106,7 @@ describe("The OMEMO module", function() {
`<payload>${sent_stanza.querySelector("payload").textContent}</payload>`+
`</encrypted>`+
`<store xmlns="urn:xmpp:hints"/>`+
`<encryption namespace="eu.siacs.conversations.axolotl" xmlns="urn:xmpp:eme:0"/>`+
`</message>`);
// Test reception of an encrypted message
@ -293,6 +294,7 @@ describe("The OMEMO module", function() {
`<payload>${sent_stanza.querySelector("payload").textContent}</payload>`+
`</encrypted>`+
`<store xmlns="urn:xmpp:hints"/>`+
`<encryption namespace="eu.siacs.conversations.axolotl" xmlns="urn:xmpp:eme:0"/>`+
`</message>`);
}));

View File

@ -762,7 +762,8 @@ export function createOMEMOMessageStanza (chatbox, message, devices) {
.then(dicts => addKeysToMessageStanza(stanza, dicts, obj.iv))
.then(stanza => {
stanza.c('payload').t(obj.payload).up().up();
stanza.c('store', { 'xmlns': Strophe.NS.HINTS });
stanza.c('store', { 'xmlns': Strophe.NS.HINTS }).up();
stanza.c('encryption', { 'xmlns': Strophe.NS.EME, namespace: Strophe.NS.OMEMO });
return stanza;
});
});