From c930b6c349b762e6b6fb87b00feecffd9d3b2fad Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 11 Nov 2019 09:59:09 -0800 Subject: [PATCH] Additional logging in unusual error cases * Add more logging with 'Over 5000 messages into future' error * When a Bad MAC error happens on decrypt, print out more info * Fix loggin --- libtextsecure/libsignal-protocol.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libtextsecure/libsignal-protocol.js b/libtextsecure/libsignal-protocol.js index d9549ad123..b43f3cef99 100644 --- a/libtextsecure/libsignal-protocol.js +++ b/libtextsecure/libsignal-protocol.js @@ -36297,14 +36297,27 @@ SessionCipher.prototype = { }); }.bind(this)).then(function(keys) { return this.storage.getIdentityKeyPair().then(function(ourIdentityKey) { + var remoteIdentityKey = util.toArrayBuffer(session.indexInfo.remoteIdentityKey); + var ourPubKey = util.toArrayBuffer(ourIdentityKey.pubKey); var macInput = new Uint8Array(messageProto.byteLength + 33*2 + 1); - macInput.set(new Uint8Array(util.toArrayBuffer(session.indexInfo.remoteIdentityKey))); - macInput.set(new Uint8Array(util.toArrayBuffer(ourIdentityKey.pubKey)), 33); + macInput.set(new Uint8Array(remoteIdentityKey)); + macInput.set(new Uint8Array(ourPubKey), 33); macInput[33*2] = (3 << 4) | 3; macInput.set(new Uint8Array(messageProto), 33*2 + 1); - return Internal.verifyMAC(macInput.buffer, keys[1], mac, 8); + return Internal.verifyMAC(macInput.buffer, keys[1], mac, 8).catch(function(error) { + function logArrayBuffer(name, arrayBuffer) { + console.log('Bad MAC: ' + name + ' - truthy: ' + Boolean(arrayBuffer) +', length: ' + (arrayBuffer ? arrayBuffer.byteLength : 'NaN')); + } + + logArrayBuffer('ourPubKey', ourPubKey); + logArrayBuffer('remoteIdentityKey', remoteIdentityKey); + logArrayBuffer('messageProto', messageProto); + logArrayBuffer('mac', mac); + + throw error; + }); }.bind(this)).then(function() { return Internal.crypto.decrypt(keys[0], message.ciphertext.toArrayBuffer(), keys[2].slice(0, 16)); }); @@ -36319,7 +36332,7 @@ SessionCipher.prototype = { } if (counter - chain.chainKey.counter > 5000) { - throw new Error('Over 5000 messages into the future!'); + throw new Error('Over 5000 messages into the future! New: ' + counter + ', Existing: ' + chain.chainKey.counter); } if (chain.chainKey.key === undefined) {