diff --git a/libtextsecure/libsignal-protocol.js b/libtextsecure/libsignal-protocol.js index a9a47a80b..ee354ba58 100644 --- a/libtextsecure/libsignal-protocol.js +++ b/libtextsecure/libsignal-protocol.js @@ -36182,6 +36182,9 @@ SessionCipher.prototype = { if (!record) { throw new Error("No record for device " + address); } + if (!record.getSessions() || record.getSessions().length === 0) { + throw new Error("No sessions for device " + address); + } var errors = []; return this.decryptWithSessionList(buffer, record.getSessions(), errors).then(function(result) { return this.getRecord(address).then(function(record) { diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index 9e5431965..d849421c0 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -166,7 +166,6 @@ async function decryptUnidentifiedSender( const { sender: source } = error || {}; if (source) { - // tslint:disable-next-line: no-shadowed-variable const blocked = await isBlocked(source.getName()); if (blocked) { window.log.info( @@ -176,6 +175,14 @@ async function decryptUnidentifiedSender( return null; } + if (error.message.startsWith('No sessions for device ')) { + // Receives a message from a specific device but we did not have a session with him. + // We trigger a session request. + await SessionProtocol.sendSessionRequestIfNeeded( + PubKey.cast(source.getName()) + ); + } + // eslint-disable no-param-reassign envelope.source = source.getName(); envelope.sourceDevice = source.getDeviceId();