Remove getRegistrationId and encryptMessageFor from protocol_wrapper
We can now use protocol classes like SessionCipher directly because it supports per-device read/write serialization internally. // FREEBIE
This commit is contained in:
parent
284cf5be3a
commit
843036f0ce
4 changed files with 18 additions and 44 deletions
|
@ -35505,13 +35505,6 @@ Internal.SessionLock.queueJobForNumber = function queueJobForNumber(number, runJ
|
||||||
return protocolInstance.closeOpenSessionForDevice(encodedNumber);
|
return protocolInstance.closeOpenSessionForDevice(encodedNumber);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
encryptMessageFor: function(deviceObject, pushMessageContent) {
|
|
||||||
return queueJobForNumber(deviceObject.encodedNumber, function() {
|
|
||||||
var address = libsignal.SignalProtocolAddress.fromString(deviceObject.encodedNumber);
|
|
||||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
|
||||||
return sessionCipher.encrypt(pushMessageContent);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
startWorker: function() {
|
startWorker: function() {
|
||||||
protocolInstance.startWorker('/js/libsignal-protocol-worker.js');
|
protocolInstance.startWorker('/js/libsignal-protocol-worker.js');
|
||||||
},
|
},
|
||||||
|
@ -35526,11 +35519,6 @@ Internal.SessionLock.queueJobForNumber = function queueJobForNumber(number, runJ
|
||||||
return protocolInstance.hasOpenSession(encodedNumber);
|
return protocolInstance.hasOpenSession(encodedNumber);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getRegistrationId: function(encodedNumber) {
|
|
||||||
return queueJobForNumber(encodedNumber, function() {
|
|
||||||
return protocolInstance.getRegistrationId(encodedNumber);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
handlePreKeyWhisperMessage: function(from, blob) {
|
handlePreKeyWhisperMessage: function(from, blob) {
|
||||||
console.log('prekey whisper message');
|
console.log('prekey whisper message');
|
||||||
blob.mark();
|
blob.mark();
|
||||||
|
@ -35824,12 +35812,7 @@ Internal.SessionLock.queueJobForNumber = function queueJobForNumber(number, runJ
|
||||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||||
return Promise.all(deviceIds.map(function(deviceId) {
|
return Promise.all(deviceIds.map(function(deviceId) {
|
||||||
var address = new libsignal.SignalProtocolAddress(number, deviceId).toString();
|
var address = new libsignal.SignalProtocolAddress(number, deviceId).toString();
|
||||||
return textsecure.protocol_wrapper.getRegistrationId(address).then(function(registrationId) {
|
return { encodedNumber : address };
|
||||||
return {
|
|
||||||
encodedNumber : address,
|
|
||||||
registrationId : registrationId
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -37619,17 +37602,21 @@ OutgoingMessage.prototype = {
|
||||||
encryptToDevices: function(deviceObjectList) {
|
encryptToDevices: function(deviceObjectList) {
|
||||||
var plaintext = this.message.toArrayBuffer();
|
var plaintext = this.message.toArrayBuffer();
|
||||||
return Promise.all(deviceObjectList.map(function(device) {
|
return Promise.all(deviceObjectList.map(function(device) {
|
||||||
return textsecure.protocol_wrapper.encryptMessageFor(device, plaintext).then(function(encryptedMsg) {
|
var address = libsignal.SignalProtocolAddress.fromString(device.encodedNumber);
|
||||||
return this.toJSON(device, encryptedMsg);
|
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||||
|
return sessionCipher.encrypt(plaintext).then(function(encryptedMsg) {
|
||||||
|
return sessionCipher.getRemoteRegistrationId().then(function(registrationId) {
|
||||||
|
return this.toJSON(device, encryptedMsg, registrationId);
|
||||||
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this)));
|
}.bind(this)));
|
||||||
},
|
},
|
||||||
|
|
||||||
toJSON: function(device, encryptedMsg) {
|
toJSON: function(device, encryptedMsg, registrationId) {
|
||||||
var json = {
|
var json = {
|
||||||
type: encryptedMsg.type,
|
type: encryptedMsg.type,
|
||||||
destinationDeviceId: textsecure.utils.unencodeNumber(device.encodedNumber)[1],
|
destinationDeviceId: textsecure.utils.unencodeNumber(device.encodedNumber)[1],
|
||||||
destinationRegistrationId: device.registrationId
|
destinationRegistrationId: registrationId
|
||||||
};
|
};
|
||||||
|
|
||||||
if (device.relay !== undefined) {
|
if (device.relay !== undefined) {
|
||||||
|
|
|
@ -130,17 +130,21 @@ OutgoingMessage.prototype = {
|
||||||
encryptToDevices: function(deviceObjectList) {
|
encryptToDevices: function(deviceObjectList) {
|
||||||
var plaintext = this.message.toArrayBuffer();
|
var plaintext = this.message.toArrayBuffer();
|
||||||
return Promise.all(deviceObjectList.map(function(device) {
|
return Promise.all(deviceObjectList.map(function(device) {
|
||||||
return textsecure.protocol_wrapper.encryptMessageFor(device, plaintext).then(function(encryptedMsg) {
|
var address = libsignal.SignalProtocolAddress.fromString(device.encodedNumber);
|
||||||
return this.toJSON(device, encryptedMsg);
|
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||||
|
return sessionCipher.encrypt(plaintext).then(function(encryptedMsg) {
|
||||||
|
return sessionCipher.getRemoteRegistrationId().then(function(registrationId) {
|
||||||
|
return this.toJSON(device, encryptedMsg, registrationId);
|
||||||
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this)));
|
}.bind(this)));
|
||||||
},
|
},
|
||||||
|
|
||||||
toJSON: function(device, encryptedMsg) {
|
toJSON: function(device, encryptedMsg, registrationId) {
|
||||||
var json = {
|
var json = {
|
||||||
type: encryptedMsg.type,
|
type: encryptedMsg.type,
|
||||||
destinationDeviceId: textsecure.utils.unencodeNumber(device.encodedNumber)[1],
|
destinationDeviceId: textsecure.utils.unencodeNumber(device.encodedNumber)[1],
|
||||||
destinationRegistrationId: device.registrationId
|
destinationRegistrationId: registrationId
|
||||||
};
|
};
|
||||||
|
|
||||||
if (device.relay !== undefined) {
|
if (device.relay !== undefined) {
|
||||||
|
|
|
@ -40,13 +40,6 @@
|
||||||
return protocolInstance.closeOpenSessionForDevice(encodedNumber);
|
return protocolInstance.closeOpenSessionForDevice(encodedNumber);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
encryptMessageFor: function(deviceObject, pushMessageContent) {
|
|
||||||
return queueJobForNumber(deviceObject.encodedNumber, function() {
|
|
||||||
var address = libsignal.SignalProtocolAddress.fromString(deviceObject.encodedNumber);
|
|
||||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
|
||||||
return sessionCipher.encrypt(pushMessageContent);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
startWorker: function() {
|
startWorker: function() {
|
||||||
protocolInstance.startWorker('/js/libsignal-protocol-worker.js');
|
protocolInstance.startWorker('/js/libsignal-protocol-worker.js');
|
||||||
},
|
},
|
||||||
|
@ -61,11 +54,6 @@
|
||||||
return protocolInstance.hasOpenSession(encodedNumber);
|
return protocolInstance.hasOpenSession(encodedNumber);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getRegistrationId: function(encodedNumber) {
|
|
||||||
return queueJobForNumber(encodedNumber, function() {
|
|
||||||
return protocolInstance.getRegistrationId(encodedNumber);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
handlePreKeyWhisperMessage: function(from, blob) {
|
handlePreKeyWhisperMessage: function(from, blob) {
|
||||||
console.log('prekey whisper message');
|
console.log('prekey whisper message');
|
||||||
blob.mark();
|
blob.mark();
|
||||||
|
|
|
@ -38,12 +38,7 @@
|
||||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||||
return Promise.all(deviceIds.map(function(deviceId) {
|
return Promise.all(deviceIds.map(function(deviceId) {
|
||||||
var address = new libsignal.SignalProtocolAddress(number, deviceId).toString();
|
var address = new libsignal.SignalProtocolAddress(number, deviceId).toString();
|
||||||
return textsecure.protocol_wrapper.getRegistrationId(address).then(function(registrationId) {
|
return { encodedNumber : address };
|
||||||
return {
|
|
||||||
encodedNumber : address,
|
|
||||||
registrationId : registrationId
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue