Skip to content

Commit 3ca6ac7

Browse files
committed
Fixes #1524 Don't include own device in OMEMO message
This change reverts the significant part of 1dfdb36 I can't say that I understand why libsignal throws `Error: Invalid signature` when you try to build a session for your own (sending) device, but given that messages can only be decrypted once, I guess it isn't really necessary to encrypt for your own device, since you already have the plaintext. In addition I've added some error handling so that we can recover gracefully when session building fails for a subset of devices.
1 parent fa3c660 commit 3ca6ac7

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

CHANGES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- #1494: Trim whitespace around messages
4242
- #1495: Mentions should always include a URI attribute
4343
- #1502: Fatal error when using prebind
44+
- #1524: OMEMO libsignal-protocol.js Invalid signature
4445
- #1532: Converse reloads on enter pressed in the filter box
4546
- #1538: Allow adding self as contact
4647
- #1550: Legitimate carbons being blocked due to erroneous forgery check
@@ -50,8 +51,8 @@
5051
- #1575: MUC invitation autocomplete list doesn't appear
5152
- #1576: Converse gets stuck with spinner when logging out with `auto_login` set to `true`
5253
- #1579: Trim spaces at the beginning and end of a JID (when adding contact)
53-
- #1586: Not possible to kick someone with a space in their nickname
5454
- #1585: Upload files by pasting from clipboard
55+
- #1586: Not possible to kick someone with a space in their nickname
5556

5657
### Breaking changes
5758

spec/omemo.js

-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
`<encrypted xmlns="eu.siacs.conversations.axolotl">`+
180180
`<header sid="123456789">`+
181181
`<key rid="482886413b977930064a5888b92134fe">YzFwaDNSNzNYNw==</key>`+
182-
`<key rid="123456789">YzFwaDNSNzNYNw==</key>`+
183182
`<key rid="555">YzFwaDNSNzNYNw==</key>`+
184183
`<iv>${sent_stanza.nodeTree.querySelector("iv").textContent}</iv>`+
185184
`</header>`+
@@ -370,7 +369,6 @@
370369
`<encrypted xmlns="eu.siacs.conversations.axolotl">`+
371370
`<header sid="123456789">`+
372371
`<key rid="482886413b977930064a5888b92134fe">YzFwaDNSNzNYNw==</key>`+
373-
`<key rid="123456789">YzFwaDNSNzNYNw==</key>`+
374372
`<key rid="4e30f35051b7b8b42abe083742187228">YzFwaDNSNzNYNw==</key>`+
375373
`<iv>${sent_stanza.nodeTree.querySelector("iv").textContent}</iv>`+
376374
`</header>`+

src/converse-omemo.js

+33-10
Original file line numberDiff line numberDiff line change
@@ -545,34 +545,57 @@ converse.plugins.add('converse-omemo', {
545545
});
546546
}
547547

548-
function getSession (device) {
548+
async function getSession (device) {
549549
const address = new libsignal.SignalProtocolAddress(device.get('jid'), device.get('id'));
550-
return _converse.omemo_store.loadSession(address.toString()).then(session => {
551-
if (session) {
552-
return Promise.resolve();
553-
} else {
554-
return buildSession(device);
550+
const session = await _converse.omemo_store.loadSession(address.toString());
551+
if (session) {
552+
return Promise.resolve(session);
553+
} else {
554+
try {
555+
const session = await buildSession(device);
556+
return session;
557+
} catch (e) {
558+
_converse.log(
559+
`Could not build an OMEMO session for device ${device.get('id')}`,
560+
Strophe.LogLevel.ERROR
561+
);
562+
_converse.log(e, Strophe.LogLevel.ERROR);
563+
return null;
555564
}
556-
});
565+
}
557566
}
558567

559568
_converse.getBundlesAndBuildSessions = async function (chatbox) {
569+
const no_devices_err = __("Sorry, no devices found to which we can send an OMEMO encrypted message.");
560570
let devices;
561571
if (chatbox.get('type') === _converse.CHATROOMS_TYPE) {
562572
const collections = await Promise.all(chatbox.occupants.map(o => getDevicesForContact(o.get('jid'))));
563573
devices = collections.reduce((a, b) => _.concat(a, b.models), []);
564574
} else if (chatbox.get('type') === _converse.PRIVATE_CHAT_TYPE) {
565575
const their_devices = await getDevicesForContact(chatbox.get('jid'));
566576
if (their_devices.length === 0) {
567-
const err = new Error(__("Sorry, we aren't able to fetch any devices to send an OMEMO encrypted message to."));
577+
const err = new Error(no_devices_err);
568578
err.user_facing = true;
569579
throw err;
570580
}
571581
const own_devices = _converse.devicelists.get(_converse.bare_jid).devices;
572-
devices = _.concat(own_devices.models, their_devices.models);
582+
devices = [...own_devices.models, ...their_devices.models];
573583
}
584+
// Filter out our own device
585+
const id = _converse.omemo_store.get('device_id');
586+
devices = devices.filter(d => d.get('id') !== id);
587+
574588
await Promise.all(devices.map(d => d.getBundle()));
575-
await Promise.all(devices.map(d => getSession(d)));
589+
const sessions = await Promise.all(devices.map(d => getSession(d)));
590+
if (sessions.includes(null)) {
591+
// We couldn't build a session for certain devices.
592+
devices = devices.filter(d => sessions[devices.indexOf(d)]);
593+
if (devices.length === 0) {
594+
const err = new Error(no_devices_err);
595+
err.user_facing = true;
596+
throw err;
597+
}
598+
}
576599
return devices;
577600
}
578601

0 commit comments

Comments
 (0)