Skip to content

Commit

Permalink
Additional logging in unusual error cases
Browse files Browse the repository at this point in the history
* Add more logging with 'Over 5000 messages into future' error
* When a Bad MAC error happens on decrypt, print out more info
* Fix loggin
  • Loading branch information
scottnonnenberg-signal authored and kenpowers-signal committed Nov 11, 2019
1 parent 5e8ee73 commit c930b6c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions libtextsecure/libsignal-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand All @@ -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) {
Expand Down

0 comments on commit c930b6c

Please sign in to comment.