Remove tempKeys
Now that we simply establish and save a session via SessionBuilder rather than saving the keys to pass in during encrypt, we can stop caching them in memory in between the identity key check and the encryption step. // FREEBIE
This commit is contained in:
parent
e2dbd90533
commit
78cdc0cb52
3 changed files with 22 additions and 70 deletions
|
@ -35674,18 +35674,9 @@ libsignal.SessionBuilder = SessionBuilder;
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
window.textsecure.storage = window.textsecure.storage || {};
|
window.textsecure.storage = window.textsecure.storage || {};
|
||||||
|
|
||||||
var tempKeys = {};
|
|
||||||
|
|
||||||
window.textsecure.storage.devices = {
|
window.textsecure.storage.devices = {
|
||||||
saveKeysToDeviceObject: function(deviceObject) {
|
saveKeysToDeviceObject: function(deviceObject) {
|
||||||
return textsecure.protocol_wrapper.processPreKey(deviceObject).then(function() {
|
return textsecure.protocol_wrapper.processPreKey(deviceObject);
|
||||||
tempKeys[deviceObject.encodedNumber] = deviceObject;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
removeTempKeysFromDevice: function(encodedNumber) {
|
|
||||||
delete tempKeys[encodedNumber];
|
|
||||||
return Promise.resolve();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getStaleDeviceIdsForNumber: function(number) {
|
getStaleDeviceIdsForNumber: function(number) {
|
||||||
|
@ -35695,9 +35686,9 @@ libsignal.SessionBuilder = SessionBuilder;
|
||||||
}
|
}
|
||||||
var updateDevices = [];
|
var updateDevices = [];
|
||||||
return Promise.all(deviceIds.map(function(deviceId) {
|
return Promise.all(deviceIds.map(function(deviceId) {
|
||||||
var encodedNumber = number + '.' + deviceId;
|
var address = new libsignal.SignalProtocolAddress(number, deviceId).toString();
|
||||||
return textsecure.protocol_wrapper.hasOpenSession(encodedNumber).then(function(hasSession) {
|
return textsecure.protocol_wrapper.hasOpenSession(address).then(function(hasSession) {
|
||||||
if (!hasSession && !tempKeys[encodedNumber]) {
|
if (!hasSession) {
|
||||||
updateDevices.push(deviceId);
|
updateDevices.push(deviceId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -35712,24 +35703,13 @@ libsignal.SessionBuilder = SessionBuilder;
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||||
// Add pending devices from tempKeys
|
|
||||||
for (var encodedNumber in tempKeys) {
|
|
||||||
var deviceNumber = textsecure.utils.unencodeNumber(encodedNumber)[0];
|
|
||||||
var deviceId = parseInt(textsecure.utils.unencodeNumber(encodedNumber)[1]);
|
|
||||||
if (deviceNumber === number && deviceIds.indexOf(deviceId) < 0) {
|
|
||||||
deviceIds.push(deviceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Promise.all(deviceIds.map(function(deviceId) {
|
return Promise.all(deviceIds.map(function(deviceId) {
|
||||||
var encodedNumber = number + '.' + deviceId;
|
var address = new libsignal.SignalProtocolAddress(number, deviceId).toString();
|
||||||
var deviceObject = tempKeys[encodedNumber] || {};
|
return textsecure.protocol_wrapper.getRegistrationId(address).then(function(registrationId) {
|
||||||
deviceObject.encodedNumber = encodedNumber;
|
return {
|
||||||
deviceObject.identityKey = identityKey;
|
encodedNumber : address,
|
||||||
return textsecure.protocol_wrapper.getRegistrationId(encodedNumber).then(function(registrationId) {
|
registrationId : registrationId
|
||||||
if (deviceObject.registrationId === undefined) {
|
};
|
||||||
deviceObject.registrationId = registrationId;
|
|
||||||
}
|
|
||||||
return deviceObject;
|
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
@ -35741,7 +35721,6 @@ libsignal.SessionBuilder = SessionBuilder;
|
||||||
for (var j in deviceIdsToRemove) {
|
for (var j in deviceIdsToRemove) {
|
||||||
promise = promise.then(function() {
|
promise = promise.then(function() {
|
||||||
var encodedNumber = number + "." + deviceIdsToRemove[j];
|
var encodedNumber = number + "." + deviceIdsToRemove[j];
|
||||||
delete tempKeys[encodedNumber];
|
|
||||||
return textsecure.storage.protocol.removeSession(encodedNumber);
|
return textsecure.storage.protocol.removeSession(encodedNumber);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -37522,10 +37501,7 @@ OutgoingMessage.prototype = {
|
||||||
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) {
|
return textsecure.protocol_wrapper.encryptMessageFor(device, plaintext).then(function(encryptedMsg) {
|
||||||
var json = this.toJSON(device, encryptedMsg);
|
return this.toJSON(device, encryptedMsg);
|
||||||
return textsecure.storage.devices.removeTempKeysFromDevice(device.encodedNumber).then(function() {
|
|
||||||
return json;
|
|
||||||
});
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this)));
|
}.bind(this)));
|
||||||
},
|
},
|
||||||
|
|
|
@ -131,10 +131,7 @@ OutgoingMessage.prototype = {
|
||||||
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) {
|
return textsecure.protocol_wrapper.encryptMessageFor(device, plaintext).then(function(encryptedMsg) {
|
||||||
var json = this.toJSON(device, encryptedMsg);
|
return this.toJSON(device, encryptedMsg);
|
||||||
return textsecure.storage.devices.removeTempKeysFromDevice(device.encodedNumber).then(function() {
|
|
||||||
return json;
|
|
||||||
});
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this)));
|
}.bind(this)));
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,18 +11,9 @@
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
window.textsecure.storage = window.textsecure.storage || {};
|
window.textsecure.storage = window.textsecure.storage || {};
|
||||||
|
|
||||||
var tempKeys = {};
|
|
||||||
|
|
||||||
window.textsecure.storage.devices = {
|
window.textsecure.storage.devices = {
|
||||||
saveKeysToDeviceObject: function(deviceObject) {
|
saveKeysToDeviceObject: function(deviceObject) {
|
||||||
return textsecure.protocol_wrapper.processPreKey(deviceObject).then(function() {
|
return textsecure.protocol_wrapper.processPreKey(deviceObject);
|
||||||
tempKeys[deviceObject.encodedNumber] = deviceObject;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
removeTempKeysFromDevice: function(encodedNumber) {
|
|
||||||
delete tempKeys[encodedNumber];
|
|
||||||
return Promise.resolve();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getStaleDeviceIdsForNumber: function(number) {
|
getStaleDeviceIdsForNumber: function(number) {
|
||||||
|
@ -32,9 +23,9 @@
|
||||||
}
|
}
|
||||||
var updateDevices = [];
|
var updateDevices = [];
|
||||||
return Promise.all(deviceIds.map(function(deviceId) {
|
return Promise.all(deviceIds.map(function(deviceId) {
|
||||||
var encodedNumber = number + '.' + deviceId;
|
var address = new libsignal.SignalProtocolAddress(number, deviceId).toString();
|
||||||
return textsecure.protocol_wrapper.hasOpenSession(encodedNumber).then(function(hasSession) {
|
return textsecure.protocol_wrapper.hasOpenSession(address).then(function(hasSession) {
|
||||||
if (!hasSession && !tempKeys[encodedNumber]) {
|
if (!hasSession) {
|
||||||
updateDevices.push(deviceId);
|
updateDevices.push(deviceId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -49,24 +40,13 @@
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||||
// Add pending devices from tempKeys
|
|
||||||
for (var encodedNumber in tempKeys) {
|
|
||||||
var deviceNumber = textsecure.utils.unencodeNumber(encodedNumber)[0];
|
|
||||||
var deviceId = parseInt(textsecure.utils.unencodeNumber(encodedNumber)[1]);
|
|
||||||
if (deviceNumber === number && deviceIds.indexOf(deviceId) < 0) {
|
|
||||||
deviceIds.push(deviceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Promise.all(deviceIds.map(function(deviceId) {
|
return Promise.all(deviceIds.map(function(deviceId) {
|
||||||
var encodedNumber = number + '.' + deviceId;
|
var address = new libsignal.SignalProtocolAddress(number, deviceId).toString();
|
||||||
var deviceObject = tempKeys[encodedNumber] || {};
|
return textsecure.protocol_wrapper.getRegistrationId(address).then(function(registrationId) {
|
||||||
deviceObject.encodedNumber = encodedNumber;
|
return {
|
||||||
deviceObject.identityKey = identityKey;
|
encodedNumber : address,
|
||||||
return textsecure.protocol_wrapper.getRegistrationId(encodedNumber).then(function(registrationId) {
|
registrationId : registrationId
|
||||||
if (deviceObject.registrationId === undefined) {
|
};
|
||||||
deviceObject.registrationId = registrationId;
|
|
||||||
}
|
|
||||||
return deviceObject;
|
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
@ -78,7 +58,6 @@
|
||||||
for (var j in deviceIdsToRemove) {
|
for (var j in deviceIdsToRemove) {
|
||||||
promise = promise.then(function() {
|
promise = promise.then(function() {
|
||||||
var encodedNumber = number + "." + deviceIdsToRemove[j];
|
var encodedNumber = number + "." + deviceIdsToRemove[j];
|
||||||
delete tempKeys[encodedNumber];
|
|
||||||
return textsecure.storage.protocol.removeSession(encodedNumber);
|
return textsecure.storage.protocol.removeSession(encodedNumber);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue