From e68031019b39bbcb5711b0935b3f63072aeb108e Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 28 Apr 2016 15:51:22 -0700 Subject: [PATCH] Integrate libsignal.SessionCipher Bypass the old protocolInstance wrapper methods and use the shiny new SessionCipher class directly. // FREEBIE --- js/libtextsecure.js | 14 ++++++++++---- libtextsecure/protocol_wrapper.js | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index abdd64ce..b13af23d 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -35434,9 +35434,11 @@ libsignal.SessionCipher = function(storage, remoteAddress) { window.textsecure = window.textsecure || {}; window.textsecure.protocol_wrapper = { - decryptWhisperMessage: function(fromAddress, blob) { + decryptWhisperMessage: function(fromAddress, message) { return queueJobForNumber(fromAddress, function() { - return protocolInstance.decryptWhisperMessage(fromAddress, blob.toArrayBuffer()); + var address = libsignal.SignalProtocolAddress.fromString(fromAddress); + var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address); + return sessionCipher.decryptWhisperMessage(message.toArrayBuffer()); }); }, closeOpenSessionForDevice: function(encodedNumber) { @@ -35446,7 +35448,9 @@ libsignal.SessionCipher = function(storage, remoteAddress) { }, encryptMessageFor: function(deviceObject, pushMessageContent) { return queueJobForNumber(deviceObject.encodedNumber, function() { - return protocolInstance.encryptMessageFor(deviceObject, pushMessageContent); + var address = libsignal.SignalProtocolAddress.fromString(deviceObject.encodedNumber); + var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address); + return sessionCipher.encrypt(pushMessageContent); }); }, startWorker: function() { @@ -35477,7 +35481,9 @@ libsignal.SessionCipher = function(storage, remoteAddress) { throw new Error("Incompatible version byte"); } return queueJobForNumber(from, function() { - return protocolInstance.handlePreKeyWhisperMessage(from, blob).catch(function(e) { + var address = libsignal.SignalProtocolAddress.fromString(from); + var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address); + return sessionCipher.decryptPreKeyWhisperMessage(blob).catch(function(e) { if (e.message === 'Unknown identity key') { blob.reset(); // restore the version byte. diff --git a/libtextsecure/protocol_wrapper.js b/libtextsecure/protocol_wrapper.js index b6ec5599..21644713 100644 --- a/libtextsecure/protocol_wrapper.js +++ b/libtextsecure/protocol_wrapper.js @@ -28,9 +28,11 @@ window.textsecure = window.textsecure || {}; window.textsecure.protocol_wrapper = { - decryptWhisperMessage: function(fromAddress, blob) { + decryptWhisperMessage: function(fromAddress, message) { return queueJobForNumber(fromAddress, function() { - return protocolInstance.decryptWhisperMessage(fromAddress, blob.toArrayBuffer()); + var address = libsignal.SignalProtocolAddress.fromString(fromAddress); + var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address); + return sessionCipher.decryptWhisperMessage(message.toArrayBuffer()); }); }, closeOpenSessionForDevice: function(encodedNumber) { @@ -40,7 +42,9 @@ }, encryptMessageFor: function(deviceObject, pushMessageContent) { return queueJobForNumber(deviceObject.encodedNumber, function() { - return protocolInstance.encryptMessageFor(deviceObject, pushMessageContent); + var address = libsignal.SignalProtocolAddress.fromString(deviceObject.encodedNumber); + var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address); + return sessionCipher.encrypt(pushMessageContent); }); }, startWorker: function() { @@ -71,7 +75,9 @@ throw new Error("Incompatible version byte"); } return queueJobForNumber(from, function() { - return protocolInstance.handlePreKeyWhisperMessage(from, blob).catch(function(e) { + var address = libsignal.SignalProtocolAddress.fromString(from); + var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address); + return sessionCipher.decryptPreKeyWhisperMessage(blob).catch(function(e) { if (e.message === 'Unknown identity key') { blob.reset(); // restore the version byte.