Do not rely on deviceObject.sessions anywhere in sendmessage

This commit is contained in:
Matt Corallo 2015-03-24 17:39:14 -07:00 committed by lilia
parent 6c0f3ff1f0
commit e33c6fddda
3 changed files with 30 additions and 6 deletions

View file

@ -38059,6 +38059,7 @@ window.axolotl.sessions = {
return undefined;
return device.sessions;
},
putSessionsForDevice: function(encodedNumber, sessions) {
var device = textsecure.storage.devices.getDeviceObject(encodedNumber);
if (device === undefined) {
@ -38072,6 +38073,13 @@ window.axolotl.sessions = {
device.sessions = sessions;
return textsecure.storage.devices.saveDeviceObject(device);
},
haveOpenSessionForDevice: function(encodedNumber) {
var sessions = textsecure.storage.sessions.getSessionsForNumber(encodedNumber);
if (sessions === undefined || !sessions.haveOpenSession())
return false;
return true;
},
};
window.textsecure.storage.devices = {
@ -39440,9 +39448,11 @@ window.textsecure.messaging = function() {
return new Promise(function() { throw new Error("Mismatched relays for number " + number); });
}
var registrationId = deviceObjectList[i].registrationId;
if (registrationId === undefined) // ie this isnt a first-send-keyful deviceObject
registrationId = textsecure.storage.sessions.getSessionsForNumber(deviceObjectList[i].encodedNumber).registrationId;
return textsecure.protocol_wrapper.encryptMessageFor(deviceObjectList[i], message).then(function(encryptedMsg) {
textsecure.storage.devices.removeTempKeysFromDevice(deviceObjectList[i].encodedNumber);
var registrationId = deviceObjectList[i].registrationId || deviceObjectList[i].sessions.registrationId;
jsonData[i] = {
type: encryptedMsg.type,
@ -39470,7 +39480,9 @@ window.textsecure.messaging = function() {
var doUpdate = false;
for (var i in devicesForNumber) {
var registrationId = devicesForNumber[i].registrationId || devicesForNumber[i].sessions.registrationId;
var registrationId = deviceObjectList[i].registrationId;
if (registrationId === undefined) // ie this isnt a first-send-keyful deviceObject
registrationId = textsecure.storage.sessions.getSessionsForNumber(deviceObjectList[i].encodedNumber).registrationId;
if (textsecure.storage.groups.needUpdateByDeviceRegistrationId(groupId, number, devicesForNumber[i].encodedNumber, registrationId))
doUpdate = true;
}
@ -39582,7 +39594,7 @@ window.textsecure.messaging = function() {
var promises = [];
for (var j in devicesForNumber)
if (devicesForNumber[j].sessions === undefined || !devicesForNumber[j].sessions.haveOpenSession())
if (!textsecure.storage.sessions.haveOpenSessionForDevice(devicesForNumber[j].encodedNumber))
promises[promises.length] = getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(devicesForNumber[j].encodedNumber)[1])]);
Promise.all(promises).then(function() {

View file

@ -67,9 +67,11 @@ window.textsecure.messaging = function() {
return new Promise(function() { throw new Error("Mismatched relays for number " + number); });
}
var registrationId = deviceObjectList[i].registrationId;
if (registrationId === undefined) // ie this isnt a first-send-keyful deviceObject
registrationId = textsecure.storage.sessions.getSessionsForNumber(deviceObjectList[i].encodedNumber).registrationId;
return textsecure.protocol_wrapper.encryptMessageFor(deviceObjectList[i], message).then(function(encryptedMsg) {
textsecure.storage.devices.removeTempKeysFromDevice(deviceObjectList[i].encodedNumber);
var registrationId = deviceObjectList[i].registrationId || deviceObjectList[i].sessions.registrationId;
jsonData[i] = {
type: encryptedMsg.type,
@ -97,7 +99,9 @@ window.textsecure.messaging = function() {
var doUpdate = false;
for (var i in devicesForNumber) {
var registrationId = devicesForNumber[i].registrationId || devicesForNumber[i].sessions.registrationId;
var registrationId = deviceObjectList[i].registrationId;
if (registrationId === undefined) // ie this isnt a first-send-keyful deviceObject
registrationId = textsecure.storage.sessions.getSessionsForNumber(deviceObjectList[i].encodedNumber).registrationId;
if (textsecure.storage.groups.needUpdateByDeviceRegistrationId(groupId, number, devicesForNumber[i].encodedNumber, registrationId))
doUpdate = true;
}
@ -209,7 +213,7 @@ window.textsecure.messaging = function() {
var promises = [];
for (var j in devicesForNumber)
if (devicesForNumber[j].sessions === undefined || !devicesForNumber[j].sessions.haveOpenSession())
if (!textsecure.storage.sessions.haveOpenSessionForDevice(devicesForNumber[j].encodedNumber))
promises[promises.length] = getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(devicesForNumber[j].encodedNumber)[1])]);
Promise.all(promises).then(function() {

View file

@ -30,6 +30,7 @@
return undefined;
return device.sessions;
},
putSessionsForDevice: function(encodedNumber, sessions) {
var device = textsecure.storage.devices.getDeviceObject(encodedNumber);
if (device === undefined) {
@ -43,6 +44,13 @@
device.sessions = sessions;
return textsecure.storage.devices.saveDeviceObject(device);
},
haveOpenSessionForDevice: function(encodedNumber) {
var sessions = textsecure.storage.sessions.getSessionsForNumber(encodedNumber);
if (sessions === undefined || !sessions.haveOpenSession())
return false;
return true;
},
};
window.textsecure.storage.devices = {