|
|
@ -38811,7 +38811,14 @@ OutgoingMessage.prototype = {
|
|
|
|
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
|
|
|
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
|
|
|
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
|
|
|
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
|
|
|
ciphers[address.getDeviceId()] = sessionCipher;
|
|
|
|
ciphers[address.getDeviceId()] = sessionCipher;
|
|
|
|
return this.encryptToDevice(address, paddedPlaintext, sessionCipher);
|
|
|
|
return sessionCipher.encrypt(paddedPlaintext).then(function(ciphertext) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
type : ciphertext.type,
|
|
|
|
|
|
|
|
destinationDeviceId : address.getDeviceId(),
|
|
|
|
|
|
|
|
destinationRegistrationId : ciphertext.registrationId,
|
|
|
|
|
|
|
|
content : btoa(ciphertext.body)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
}.bind(this))).then(function(jsonData) {
|
|
|
|
}.bind(this))).then(function(jsonData) {
|
|
|
|
return this.transmitMessage(number, jsonData, this.timestamp).then(function() {
|
|
|
|
return this.transmitMessage(number, jsonData, this.timestamp).then(function() {
|
|
|
|
this.successfulNumbers[this.successfulNumbers.length] = number;
|
|
|
|
this.successfulNumbers[this.successfulNumbers.length] = number;
|
|
|
@ -38845,25 +38852,6 @@ OutgoingMessage.prototype = {
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
encryptToDevice: function(address, plaintext, sessionCipher) {
|
|
|
|
|
|
|
|
return sessionCipher.encrypt(plaintext).then(function(ciphertext) {
|
|
|
|
|
|
|
|
return this.toJSON(address, ciphertext);
|
|
|
|
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toJSON: function(address, encryptedMsg) {
|
|
|
|
|
|
|
|
var json = {
|
|
|
|
|
|
|
|
type : encryptedMsg.type,
|
|
|
|
|
|
|
|
destinationDeviceId : address.getDeviceId(),
|
|
|
|
|
|
|
|
destinationRegistrationId : encryptedMsg.registrationId
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var content = btoa(encryptedMsg.body);
|
|
|
|
|
|
|
|
json.content = content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return json;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getStaleDeviceIdsForNumber: function(number) {
|
|
|
|
getStaleDeviceIdsForNumber: function(number) {
|
|
|
|
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
|
|
|
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
|
|
|
if (deviceIds.length === 0) {
|
|
|
|
if (deviceIds.length === 0) {
|
|
|
|