From 0283c6428f29b945fb58eed8aff5dc73b554d61a Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Mon, 15 Oct 2018 13:57:43 +1100 Subject: [PATCH] Ignore friend request messages that could not be decrypted --- libloki/libloki-protocol.js | 9 +++++++-- libtextsecure/message_receiver.js | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libloki/libloki-protocol.js b/libloki/libloki-protocol.js index 5cf9e5cfe..bc116d5bf 100644 --- a/libloki/libloki-protocol.js +++ b/libloki/libloki-protocol.js @@ -7,6 +7,7 @@ const IV_LENGTH = 16; FallBackSessionCipher = function (address) { + this.identityKeyString = address.getName(); this.pubKey = StringView.hexToArrayBuffer(address.getName()); this.encrypt = async (plaintext) => { @@ -37,11 +38,15 @@ const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); const myPrivateKey = myKeyPair.privKey; const symmetricKey = libsignal.Curve.calculateAgreement(this.pubKey, myPrivateKey); - const plaintext = await libsignal.crypto.decrypt(symmetricKey, cipherText, iv); - return plaintext; + try { + return await libsignal.crypto.decrypt(symmetricKey, cipherText, iv); + } catch(e) { + throw new FallBackDecryptionError('Could not decrypt message from ' + this.identityKeyString + ' using FallBack encryption.') + } } } window.libloki.FallBackSessionCipher = FallBackSessionCipher; + window.libloki.FallBackDecryptionError = FallBackDecryptionError; })(); \ No newline at end of file diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 6381a173c..7ece2215a 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -694,6 +694,9 @@ MessageReceiver.prototype.extend({ buffer.toArrayBuffer(), error.identityKey ); + } else { + // re-throw + throw error; } const ev = new Event('error'); ev.error = errorToThrow; @@ -820,7 +823,11 @@ MessageReceiver.prototype.extend({ handleContentMessage(envelope) { return this.decrypt(envelope, envelope.content).then(plaintext => this.innerHandleContentMessage(envelope, plaintext) - ); + ).catch(e => { + if (e instanceof libloki.FallBackDecryptionError) { + console.log(e.message + ' Ignoring message.'); + } + }); }, innerHandleContentMessage(envelope, plaintext) { const content = textsecure.protobuf.Content.decode(plaintext);