From d1114edcd40c6fe5ef9306d90a46fcbc962998a5 Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 28 Mar 2017 11:37:41 -0700 Subject: [PATCH] Update libsignal-protocol-javascript 1.1.10 // FREEBIE --- js/libtextsecure.js | 36 +++++++++++------------------ libtextsecure/libsignal-protocol.js | 36 +++++++++++------------------ 2 files changed, 26 insertions(+), 46 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index e997d2b4be..fd4427e291 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -35855,32 +35855,14 @@ Internal.SessionRecord = function() { archiveCurrentState: function() { var open_session = this.getOpenSession(); if (open_session !== undefined) { - this.closeSession(open_session); + console.log('closing session'); + open_session.indexInfo.closed = Date.now(); this.updateSessionState(open_session); } }, - closeSession: function(session) { - if (session.indexInfo.closed > -1) { - return; - } - console.log('closing session', session.indexInfo.baseKey); - - // After this has run, we can still receive messages on ratchet chains which - // were already open (unless we know we dont need them), - // but we cannot send messages or step the ratchet - - // Delete current sending ratchet - delete session[util.toString(session.currentRatchet.ephemeralKeyPair.pubKey)]; - // Move all receive ratchets to the oldRatchetList to mark them for deletion - for (var i in session) { - if (session[i].chainKey !== undefined && session[i].chainKey.key !== undefined) { - session.oldRatchetList[session.oldRatchetList.length] = { - added: Date.now(), ephemeralKey: i - }; - } - } - session.indexInfo.closed = Date.now(); - this.removeOldChains(session); + promoteState: function(session) { + console.log('promoting session'); + session.indexInfo.closed = -1; }, removeOldChains: function(session) { // Sending ratchets are always removed when we step because we never need them again @@ -36313,6 +36295,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)); @@ -36328,6 +36314,10 @@ SessionCipher.prototype = { var errors = []; return this.decryptWithSessionList(buffer, record.getSessions(), errors).then(function(result) { return this.getRecord(address).then(function(record) { + if (result.session !== record.getOpenSession()) { + record.archiveCurrentState(); + record.promoteState(result.session); + } record.updateSessionState(result.session); return this.storage.storeSession(address, record.serialize()).then(function() { return result.plaintext; diff --git a/libtextsecure/libsignal-protocol.js b/libtextsecure/libsignal-protocol.js index 9614701565..4c53122cbc 100644 --- a/libtextsecure/libsignal-protocol.js +++ b/libtextsecure/libsignal-protocol.js @@ -35718,32 +35718,14 @@ Internal.SessionRecord = function() { archiveCurrentState: function() { var open_session = this.getOpenSession(); if (open_session !== undefined) { - this.closeSession(open_session); + console.log('closing session'); + open_session.indexInfo.closed = Date.now(); this.updateSessionState(open_session); } }, - closeSession: function(session) { - if (session.indexInfo.closed > -1) { - return; - } - console.log('closing session', session.indexInfo.baseKey); - - // After this has run, we can still receive messages on ratchet chains which - // were already open (unless we know we dont need them), - // but we cannot send messages or step the ratchet - - // Delete current sending ratchet - delete session[util.toString(session.currentRatchet.ephemeralKeyPair.pubKey)]; - // Move all receive ratchets to the oldRatchetList to mark them for deletion - for (var i in session) { - if (session[i].chainKey !== undefined && session[i].chainKey.key !== undefined) { - session.oldRatchetList[session.oldRatchetList.length] = { - added: Date.now(), ephemeralKey: i - }; - } - } - session.indexInfo.closed = Date.now(); - this.removeOldChains(session); + promoteState: function(session) { + console.log('promoting session'); + session.indexInfo.closed = -1; }, removeOldChains: function(session) { // Sending ratchets are always removed when we step because we never need them again @@ -36176,6 +36158,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)); @@ -36191,6 +36177,10 @@ SessionCipher.prototype = { var errors = []; return this.decryptWithSessionList(buffer, record.getSessions(), errors).then(function(result) { return this.getRecord(address).then(function(record) { + if (result.session !== record.getOpenSession()) { + record.archiveCurrentState(); + record.promoteState(result.session); + } record.updateSessionState(result.session); return this.storage.storeSession(address, record.serialize()).then(function() { return result.plaintext;