From b01ac22eb993a2300af0c70aec29f33bb4b26212 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 27 Mar 2017 17:01:55 -0700 Subject: [PATCH] Fix bad mac on repeated deliveries `MessageCounterError` is the expected result of repeated deliveries. Error handling in decryptWithSessionList should immediately return such an error if it occurs. Previous to this change, a Bad MAC error to be returned instead of a MessageCounterError, if the message in question was encrypted for a closed session. --- dist/libsignal-protocol.js | 4 ++++ src/SessionCipher.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/dist/libsignal-protocol.js b/dist/libsignal-protocol.js index 9614701..2fd65a4 100644 --- a/dist/libsignal-protocol.js +++ b/dist/libsignal-protocol.js @@ -36176,6 +36176,10 @@ SessionCipher.prototype = { return this.doDecryptWhisperMessage(buffer, session).then(function(plaintext) { return { plaintext: plaintext, session: session }; }).catch(function(e) { + if (e.name === 'MessageCounterError') { + return Promise.reject(e); + } + errors.push(e); return this.decryptWithSessionList(buffer, sessionList, errors); }.bind(this)); diff --git a/src/SessionCipher.js b/src/SessionCipher.js index 334dee8..b9871e7 100644 --- a/src/SessionCipher.js +++ b/src/SessionCipher.js @@ -124,6 +124,10 @@ SessionCipher.prototype = { return this.doDecryptWhisperMessage(buffer, session).then(function(plaintext) { return { plaintext: plaintext, session: session }; }).catch(function(e) { + if (e.name === 'MessageCounterError') { + return Promise.reject(e); + } + errors.push(e); return this.decryptWithSessionList(buffer, sessionList, errors); }.bind(this));