Integrate libsignal.SessionCipher

Bypass the old protocolInstance wrapper methods and use the shiny new
SessionCipher class directly.

// FREEBIE
This commit is contained in:
lilia 2016-04-28 15:51:22 -07:00
parent b19ec6c05b
commit e68031019b
2 changed files with 20 additions and 8 deletions

View file

@ -35434,9 +35434,11 @@ libsignal.SessionCipher = function(storage, remoteAddress) {
window.textsecure = window.textsecure || {}; window.textsecure = window.textsecure || {};
window.textsecure.protocol_wrapper = { window.textsecure.protocol_wrapper = {
decryptWhisperMessage: function(fromAddress, blob) { decryptWhisperMessage: function(fromAddress, message) {
return queueJobForNumber(fromAddress, function() { 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) { closeOpenSessionForDevice: function(encodedNumber) {
@ -35446,7 +35448,9 @@ libsignal.SessionCipher = function(storage, remoteAddress) {
}, },
encryptMessageFor: function(deviceObject, pushMessageContent) { encryptMessageFor: function(deviceObject, pushMessageContent) {
return queueJobForNumber(deviceObject.encodedNumber, function() { 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() { startWorker: function() {
@ -35477,7 +35481,9 @@ libsignal.SessionCipher = function(storage, remoteAddress) {
throw new Error("Incompatible version byte"); throw new Error("Incompatible version byte");
} }
return queueJobForNumber(from, function() { 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') { if (e.message === 'Unknown identity key') {
blob.reset(); // restore the version byte. blob.reset(); // restore the version byte.

View file

@ -28,9 +28,11 @@
window.textsecure = window.textsecure || {}; window.textsecure = window.textsecure || {};
window.textsecure.protocol_wrapper = { window.textsecure.protocol_wrapper = {
decryptWhisperMessage: function(fromAddress, blob) { decryptWhisperMessage: function(fromAddress, message) {
return queueJobForNumber(fromAddress, function() { 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) { closeOpenSessionForDevice: function(encodedNumber) {
@ -40,7 +42,9 @@
}, },
encryptMessageFor: function(deviceObject, pushMessageContent) { encryptMessageFor: function(deviceObject, pushMessageContent) {
return queueJobForNumber(deviceObject.encodedNumber, function() { 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() { startWorker: function() {
@ -71,7 +75,9 @@
throw new Error("Incompatible version byte"); throw new Error("Incompatible version byte");
} }
return queueJobForNumber(from, function() { 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') { if (e.message === 'Unknown identity key') {
blob.reset(); // restore the version byte. blob.reset(); // restore the version byte.