From 5fcf2ea66f978ef682348df503a21ea5debe90aa Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 23 Jun 2016 14:17:01 -0700 Subject: [PATCH] Update libsignal-protocol v1.1.1 // FREEBIE --- js/libtextsecure.js | 32 +++-------------------------- libtextsecure/libsignal-protocol.js | 32 +++-------------------------- 2 files changed, 6 insertions(+), 58 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 3dfd25a3d031..5d85d45bd4d5 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -35830,8 +35830,8 @@ Internal.SessionRecord = function() { removeOldChains: function(session) { // Sending ratchets are always removed when we step because we never need them again // Receiving ratchets are added to the oldRatchetList, which we parse - // here and remove all but the last four. - while (session.oldRatchetList.length > 4) { + // here and remove all but the last five. + while (session.oldRatchetList.length > 5) { var index = 0; var oldest = session.oldRatchetList[0]; for (var i = 0; i < session.oldRatchetList.length; i++) { @@ -36228,16 +36228,6 @@ SessionCipher.prototype = { }); }.bind(this)); }, - getPaddedMessageLength: function(messageLength) { - var messageLengthWithTerminator = messageLength + 1; - var messagePartCount = Math.floor(messageLengthWithTerminator / 160); - - if (messageLengthWithTerminator % 160 !== 0) { - messagePartCount++; - } - - return messagePartCount * 160; - }, decryptWhisperMessage: function(buffer, encoding) { buffer = dcodeIO.ByteBuffer.wrap(buffer, encoding).toArrayBuffer(); return Internal.SessionLock.queueJobForNumber(this.remoteAddress.toString(), function() { @@ -36343,7 +36333,7 @@ SessionCipher.prototype = { macInput[33*2] = (3 << 4) | 3; macInput.set(new Uint8Array(messageProto), 33*2 + 1); - return this.verifyMAC(macInput.buffer, keys[1], mac, 8); + return Internal.verifyMAC(macInput.buffer, keys[1], mac, 8); }.bind(this)).then(function() { return Internal.crypto.decrypt(keys[0], message.ciphertext.toArrayBuffer(), keys[2].slice(0, 16)); }); @@ -36436,22 +36426,6 @@ SessionCipher.prototype = { }); }); }, - verifyMAC: function(data, key, mac, length) { - return Internal.crypto.sign(key, data).then(function(calculated_mac) { - if (mac.byteLength != length || calculated_mac.byteLength < length) { - throw new Error("Bad MAC length"); - } - var a = new Uint8Array(calculated_mac); - var b = new Uint8Array(mac); - var result = 0; - for (var i=0; i < mac.byteLength; ++i) { - result = result | (a[i] ^ b[i]); - } - if (result !== 0) { - throw new Error("Bad MAC"); - } - }); - }, getRemoteRegistrationId: function() { return Internal.SessionLock.queueJobForNumber(this.remoteAddress.toString(), function() { return this.getRecord(this.remoteAddress.toString()).then(function(record) { diff --git a/libtextsecure/libsignal-protocol.js b/libtextsecure/libsignal-protocol.js index b967b0c53b3f..335fb5342797 100644 --- a/libtextsecure/libsignal-protocol.js +++ b/libtextsecure/libsignal-protocol.js @@ -35706,8 +35706,8 @@ Internal.SessionRecord = function() { removeOldChains: function(session) { // Sending ratchets are always removed when we step because we never need them again // Receiving ratchets are added to the oldRatchetList, which we parse - // here and remove all but the last four. - while (session.oldRatchetList.length > 4) { + // here and remove all but the last five. + while (session.oldRatchetList.length > 5) { var index = 0; var oldest = session.oldRatchetList[0]; for (var i = 0; i < session.oldRatchetList.length; i++) { @@ -36104,16 +36104,6 @@ SessionCipher.prototype = { }); }.bind(this)); }, - getPaddedMessageLength: function(messageLength) { - var messageLengthWithTerminator = messageLength + 1; - var messagePartCount = Math.floor(messageLengthWithTerminator / 160); - - if (messageLengthWithTerminator % 160 !== 0) { - messagePartCount++; - } - - return messagePartCount * 160; - }, decryptWhisperMessage: function(buffer, encoding) { buffer = dcodeIO.ByteBuffer.wrap(buffer, encoding).toArrayBuffer(); return Internal.SessionLock.queueJobForNumber(this.remoteAddress.toString(), function() { @@ -36219,7 +36209,7 @@ SessionCipher.prototype = { macInput[33*2] = (3 << 4) | 3; macInput.set(new Uint8Array(messageProto), 33*2 + 1); - return this.verifyMAC(macInput.buffer, keys[1], mac, 8); + return Internal.verifyMAC(macInput.buffer, keys[1], mac, 8); }.bind(this)).then(function() { return Internal.crypto.decrypt(keys[0], message.ciphertext.toArrayBuffer(), keys[2].slice(0, 16)); }); @@ -36312,22 +36302,6 @@ SessionCipher.prototype = { }); }); }, - verifyMAC: function(data, key, mac, length) { - return Internal.crypto.sign(key, data).then(function(calculated_mac) { - if (mac.byteLength != length || calculated_mac.byteLength < length) { - throw new Error("Bad MAC length"); - } - var a = new Uint8Array(calculated_mac); - var b = new Uint8Array(mac); - var result = 0; - for (var i=0; i < mac.byteLength; ++i) { - result = result | (a[i] ^ b[i]); - } - if (result !== 0) { - throw new Error("Bad MAC"); - } - }); - }, getRemoteRegistrationId: function() { return Internal.SessionLock.queueJobForNumber(this.remoteAddress.toString(), function() { return this.getRecord(this.remoteAddress.toString()).then(function(record) {