From 519d3ec31b4f7cd4acd2788c43250c3df7ddfb93 Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 10 May 2016 18:19:05 -0700 Subject: [PATCH] Update libsignal-protocol // FREEBIE --- js/libtextsecure.js | 32 ++++++++--------------------- libtextsecure/libsignal-protocol.js | 32 ++++++++--------------------- 2 files changed, 16 insertions(+), 48 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index db99ca17c..7ff41142e 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -34608,7 +34608,7 @@ window.libsignal.protocol = function(storage_interface) { throw new Error("Expected plaintext to be an ArrayBuffer"); } - var ourIdentityKey, myRegistrationId, record, session, hadSession; + var ourIdentityKey, myRegistrationId, record, session; return Promise.all([ storage_interface.getIdentityKeyPair(), storage_interface.getLocalRegistrationId(), @@ -34617,29 +34617,13 @@ window.libsignal.protocol = function(storage_interface) { ourIdentityKey = results[0]; myRegistrationId = results[1]; record = results[2]; - if (record) { - session = record.getOpenSession(); + if (!record) { + throw new Error("No record for " + deviceObject.encodedNumber); } - - hadSession = session !== undefined; - - if (session === undefined) { - var address = SignalProtocolAddress.fromString(deviceObject.encodedNumber); - var builder = new SessionBuilder(storage_interface, address); - - return builder.processPreKey(deviceObject); + session = record.getOpenSession(); + if (!session) { + throw new Error("No session to encrypt message for " + deviceObject.encodedNumber); } - }).then(function() { - return getRecord(deviceObject.encodedNumber).then(function(refreshed) { - record = refreshed; - if (!record) { - throw new Error("No record for " + deviceObject.encodedNumber); - } - session = record.getOpenSession(); - if (!session) { - throw new Error("No session to encrypt message for " + deviceObject.encodedNumber); - } - }); }).then(function doEncryptPushMessageContent() { var msg = new Internal.protobuf.WhisperMessage(); @@ -35208,7 +35192,7 @@ SessionBuilder.prototype = { record.updateSessionState(session, device.registrationId); return Promise.all([ this.storage.storeSession(address, record.serialize()), - this.storage.putIdentityKey(address, record.identityKey) + this.storage.putIdentityKey(this.remoteAddress.getName(), record.identityKey) ]); }.bind(this)); }.bind(this)); @@ -35268,7 +35252,7 @@ SessionBuilder.prototype = { // end of decryptWhisperMessage ... to ensure that the sender // actually holds the private keys for all reported pubkeys record.updateSessionState(new_session, message.registrationId); - return this.storage.putIdentityKey(this.remoteAddress.toString(), message.identityKey.toArrayBuffer()).then(function() { + return this.storage.putIdentityKey(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function() { return message.preKeyId; }); }.bind(this)); diff --git a/libtextsecure/libsignal-protocol.js b/libtextsecure/libsignal-protocol.js index c2c40087b..a130456f3 100644 --- a/libtextsecure/libsignal-protocol.js +++ b/libtextsecure/libsignal-protocol.js @@ -34494,7 +34494,7 @@ window.libsignal.protocol = function(storage_interface) { throw new Error("Expected plaintext to be an ArrayBuffer"); } - var ourIdentityKey, myRegistrationId, record, session, hadSession; + var ourIdentityKey, myRegistrationId, record, session; return Promise.all([ storage_interface.getIdentityKeyPair(), storage_interface.getLocalRegistrationId(), @@ -34503,29 +34503,13 @@ window.libsignal.protocol = function(storage_interface) { ourIdentityKey = results[0]; myRegistrationId = results[1]; record = results[2]; - if (record) { - session = record.getOpenSession(); + if (!record) { + throw new Error("No record for " + deviceObject.encodedNumber); } - - hadSession = session !== undefined; - - if (session === undefined) { - var address = SignalProtocolAddress.fromString(deviceObject.encodedNumber); - var builder = new SessionBuilder(storage_interface, address); - - return builder.processPreKey(deviceObject); + session = record.getOpenSession(); + if (!session) { + throw new Error("No session to encrypt message for " + deviceObject.encodedNumber); } - }).then(function() { - return getRecord(deviceObject.encodedNumber).then(function(refreshed) { - record = refreshed; - if (!record) { - throw new Error("No record for " + deviceObject.encodedNumber); - } - session = record.getOpenSession(); - if (!session) { - throw new Error("No session to encrypt message for " + deviceObject.encodedNumber); - } - }); }).then(function doEncryptPushMessageContent() { var msg = new Internal.protobuf.WhisperMessage(); @@ -35094,7 +35078,7 @@ SessionBuilder.prototype = { record.updateSessionState(session, device.registrationId); return Promise.all([ this.storage.storeSession(address, record.serialize()), - this.storage.putIdentityKey(address, record.identityKey) + this.storage.putIdentityKey(this.remoteAddress.getName(), record.identityKey) ]); }.bind(this)); }.bind(this)); @@ -35154,7 +35138,7 @@ SessionBuilder.prototype = { // end of decryptWhisperMessage ... to ensure that the sender // actually holds the private keys for all reported pubkeys record.updateSessionState(new_session, message.registrationId); - return this.storage.putIdentityKey(this.remoteAddress.toString(), message.identityKey.toArrayBuffer()).then(function() { + return this.storage.putIdentityKey(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function() { return message.preKeyId; }); }.bind(this));