Use deviceIds/addresses instead of encodedNumbers
The getDeviceObjectsForNumber method returns device objects that contain nothing but the encodedNumber property. Instead, just deal in deviceIds until a SignalProtocolAddress is constructed to manage both the number and deviceId. // FREEBIE
This commit is contained in:
parent
95935f70ee
commit
d32a352d8a
3 changed files with 30 additions and 32 deletions
|
@ -38568,11 +38568,11 @@ OutgoingMessage.prototype = {
|
|||
},
|
||||
reloadDevicesAndSend: function(number, recurse) {
|
||||
return function() {
|
||||
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) {
|
||||
if (devicesForNumber.length == 0) {
|
||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||
if (deviceIds.length == 0) {
|
||||
return this.registerError(number, "Got empty device list when loading device keys", null);
|
||||
}
|
||||
return this.doSendMessage(number, devicesForNumber, recurse);
|
||||
return this.doSendMessage(number, deviceIds, recurse);
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
},
|
||||
|
@ -38623,14 +38623,14 @@ OutgoingMessage.prototype = {
|
|||
});
|
||||
},
|
||||
|
||||
doSendMessage: function(number, devicesForNumber, recurse) {
|
||||
doSendMessage: function(number, deviceIds, recurse) {
|
||||
var ciphers = {};
|
||||
var plaintext = this.message.toArrayBuffer();
|
||||
return Promise.all(devicesForNumber.map(function(device) {
|
||||
var address = libsignal.SignalProtocolAddress.fromString(device.encodedNumber);
|
||||
return Promise.all(deviceIds.map(function(deviceId) {
|
||||
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||
ciphers[address.getDeviceId()] = sessionCipher;
|
||||
return this.encryptToDevice(device, plaintext, sessionCipher);
|
||||
return this.encryptToDevice(address, plaintext, sessionCipher);
|
||||
}.bind(this))).then(function(jsonData) {
|
||||
return this.transmitMessage(number, jsonData, this.timestamp).then(function() {
|
||||
this.successfulNumbers[this.successfulNumbers.length] = number;
|
||||
|
@ -38664,19 +38664,19 @@ OutgoingMessage.prototype = {
|
|||
}.bind(this));
|
||||
},
|
||||
|
||||
encryptToDevice: function(device, plaintext, sessionCipher) {
|
||||
encryptToDevice: function(address, plaintext, sessionCipher) {
|
||||
return Promise.all([
|
||||
sessionCipher.encrypt(plaintext),
|
||||
sessionCipher.getRemoteRegistrationId()
|
||||
]).then(function(result) {
|
||||
return this.toJSON(device, result[0], result[1]);
|
||||
return this.toJSON(address, result[0], result[1]);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
toJSON: function(device, encryptedMsg, registrationId) {
|
||||
toJSON: function(address, encryptedMsg, registrationId) {
|
||||
var json = {
|
||||
type: encryptedMsg.type,
|
||||
destinationDeviceId: textsecure.utils.unencodeNumber(device.encodedNumber)[1],
|
||||
destinationDeviceId: address.getDeviceId(),
|
||||
destinationRegistrationId: registrationId
|
||||
};
|
||||
|
||||
|
@ -38998,11 +38998,10 @@ MessageSender.prototype = {
|
|||
proto.body = "TERMINATE";
|
||||
proto.flags = textsecure.protobuf.DataMessage.Flags.END_SESSION;
|
||||
return this.sendIndividualProto(number, proto, timestamp).then(function(res) {
|
||||
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {
|
||||
return Promise.all(devices.map(function(device) {
|
||||
console.log('closing session for', device.encodedNumber);
|
||||
|
||||
var address = libsignal.SignalProtocolAddress.fromString(device.encodedNumber);
|
||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||
return Promise.all(deviceIds.map(function(deviceId) {
|
||||
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
||||
console.log('closing session for', address.toString());
|
||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||
return sessionCipher.closeOpenSessionForDevice();
|
||||
})).then(function() {
|
||||
|
|
|
@ -34,11 +34,11 @@ OutgoingMessage.prototype = {
|
|||
},
|
||||
reloadDevicesAndSend: function(number, recurse) {
|
||||
return function() {
|
||||
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) {
|
||||
if (devicesForNumber.length == 0) {
|
||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||
if (deviceIds.length == 0) {
|
||||
return this.registerError(number, "Got empty device list when loading device keys", null);
|
||||
}
|
||||
return this.doSendMessage(number, devicesForNumber, recurse);
|
||||
return this.doSendMessage(number, deviceIds, recurse);
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
},
|
||||
|
@ -89,14 +89,14 @@ OutgoingMessage.prototype = {
|
|||
});
|
||||
},
|
||||
|
||||
doSendMessage: function(number, devicesForNumber, recurse) {
|
||||
doSendMessage: function(number, deviceIds, recurse) {
|
||||
var ciphers = {};
|
||||
var plaintext = this.message.toArrayBuffer();
|
||||
return Promise.all(devicesForNumber.map(function(device) {
|
||||
var address = libsignal.SignalProtocolAddress.fromString(device.encodedNumber);
|
||||
return Promise.all(deviceIds.map(function(deviceId) {
|
||||
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||
ciphers[address.getDeviceId()] = sessionCipher;
|
||||
return this.encryptToDevice(device, plaintext, sessionCipher);
|
||||
return this.encryptToDevice(address, plaintext, sessionCipher);
|
||||
}.bind(this))).then(function(jsonData) {
|
||||
return this.transmitMessage(number, jsonData, this.timestamp).then(function() {
|
||||
this.successfulNumbers[this.successfulNumbers.length] = number;
|
||||
|
@ -130,19 +130,19 @@ OutgoingMessage.prototype = {
|
|||
}.bind(this));
|
||||
},
|
||||
|
||||
encryptToDevice: function(device, plaintext, sessionCipher) {
|
||||
encryptToDevice: function(address, plaintext, sessionCipher) {
|
||||
return Promise.all([
|
||||
sessionCipher.encrypt(plaintext),
|
||||
sessionCipher.getRemoteRegistrationId()
|
||||
]).then(function(result) {
|
||||
return this.toJSON(device, result[0], result[1]);
|
||||
return this.toJSON(address, result[0], result[1]);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
toJSON: function(device, encryptedMsg, registrationId) {
|
||||
toJSON: function(address, encryptedMsg, registrationId) {
|
||||
var json = {
|
||||
type: encryptedMsg.type,
|
||||
destinationDeviceId: textsecure.utils.unencodeNumber(device.encodedNumber)[1],
|
||||
destinationDeviceId: address.getDeviceId(),
|
||||
destinationRegistrationId: registrationId
|
||||
};
|
||||
|
||||
|
|
|
@ -295,11 +295,10 @@ MessageSender.prototype = {
|
|||
proto.body = "TERMINATE";
|
||||
proto.flags = textsecure.protobuf.DataMessage.Flags.END_SESSION;
|
||||
return this.sendIndividualProto(number, proto, timestamp).then(function(res) {
|
||||
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {
|
||||
return Promise.all(devices.map(function(device) {
|
||||
console.log('closing session for', device.encodedNumber);
|
||||
|
||||
var address = libsignal.SignalProtocolAddress.fromString(device.encodedNumber);
|
||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||
return Promise.all(deviceIds.map(function(deviceId) {
|
||||
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
||||
console.log('closing session for', address.toString());
|
||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||
return sessionCipher.closeOpenSessionForDevice();
|
||||
})).then(function() {
|
||||
|
|
Loading…
Reference in a new issue