Clear session store when re-registering

When we re-register, our deviceId might change, which makes our sessions
are no longer valid since the recipient will see us as a new device.

Fixes #388
pull/749/head
lilia 10 years ago
parent a52d35bb1b
commit 80d32103d1

@ -228,6 +228,13 @@
}); });
}); });
}, },
clearSessionStore: function() {
return new Promise(function(resolve) {
var sessions = new SessionCollection();
sessions.sync('delete', sessions, {}).always(resolve);
});
},
getIdentityKey: function(identifier) { getIdentityKey: function(identifier) {
if (identifier === null || identifier === undefined) if (identifier === null || identifier === undefined)
throw new Error("Tried to get identity key for undefined/null key"); throw new Error("Tried to get identity key for undefined/null key");

@ -39204,21 +39204,24 @@ var TextSecureServer = (function() {
return this.server.confirmCode( return this.server.confirmCode(
number, verificationCode, password, signalingKey, registrationId, deviceName number, verificationCode, password, signalingKey, registrationId, deviceName
).then(function(response) { ).then(function(response) {
textsecure.storage.remove('identityKey'); return textsecure.storage.axolotl.clearSessionStore().then(function() {
textsecure.storage.remove('signaling_key'); textsecure.storage.remove('identityKey');
textsecure.storage.remove('password'); textsecure.storage.remove('signaling_key');
textsecure.storage.remove('registrationId'); textsecure.storage.remove('password');
textsecure.storage.remove('number_id'); textsecure.storage.remove('registrationId');
textsecure.storage.remove('regionCode'); textsecure.storage.remove('number_id');
textsecure.storage.remove('device_name');
textsecure.storage.put('identityKey', identityKeyPair); textsecure.storage.remove('regionCode');
textsecure.storage.put('signaling_key', signalingKey);
textsecure.storage.put('password', password); textsecure.storage.put('identityKey', identityKeyPair);
textsecure.storage.put('registrationId', registrationId); textsecure.storage.put('signaling_key', signalingKey);
textsecure.storage.put('password', password);
textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1, deviceName); textsecure.storage.put('registrationId', registrationId);
textsecure.storage.put('regionCode', libphonenumber.util.getRegionCodeForNumber(number));
this.server.username = textsecure.storage.get('number_id'); textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1, deviceName);
textsecure.storage.put('regionCode', libphonenumber.util.getRegionCodeForNumber(number));
this.server.username = textsecure.storage.get('number_id');
}.bind(this));
}.bind(this)); }.bind(this));
}, },
generateKeys: function (count, progressCallback) { generateKeys: function (count, progressCallback) {

@ -97,21 +97,24 @@
return this.server.confirmCode( return this.server.confirmCode(
number, verificationCode, password, signalingKey, registrationId, deviceName number, verificationCode, password, signalingKey, registrationId, deviceName
).then(function(response) { ).then(function(response) {
textsecure.storage.remove('identityKey'); return textsecure.storage.axolotl.clearSessionStore().then(function() {
textsecure.storage.remove('signaling_key'); textsecure.storage.remove('identityKey');
textsecure.storage.remove('password'); textsecure.storage.remove('signaling_key');
textsecure.storage.remove('registrationId'); textsecure.storage.remove('password');
textsecure.storage.remove('number_id'); textsecure.storage.remove('registrationId');
textsecure.storage.remove('regionCode'); textsecure.storage.remove('number_id');
textsecure.storage.remove('device_name');
textsecure.storage.remove('regionCode');
textsecure.storage.put('identityKey', identityKeyPair); textsecure.storage.put('identityKey', identityKeyPair);
textsecure.storage.put('signaling_key', signalingKey); textsecure.storage.put('signaling_key', signalingKey);
textsecure.storage.put('password', password); textsecure.storage.put('password', password);
textsecure.storage.put('registrationId', registrationId); textsecure.storage.put('registrationId', registrationId);
textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1, deviceName); textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1, deviceName);
textsecure.storage.put('regionCode', libphonenumber.util.getRegionCodeForNumber(number)); textsecure.storage.put('regionCode', libphonenumber.util.getRegionCodeForNumber(number));
this.server.username = textsecure.storage.get('number_id'); this.server.username = textsecure.storage.get('number_id');
}.bind(this));
}.bind(this)); }.bind(this));
}, },
generateKeys: function (count, progressCallback) { generateKeys: function (count, progressCallback) {

@ -114,6 +114,17 @@ describe("AxolotlStore", function() {
}); });
}).then(done,done); }).then(done,done);
}); });
it ('clears the session store', function(done) {
var testRecord = "an opaque string";
store.putSession(identifier + '.1', testRecord).then(function() {
return store.clearSessionStore().then(function() {
return store.getSession(identifier + '.1').then(function(record) {
assert.isUndefined(record);
});
});
}).then(done,done);
});
it('returns deviceIds for a number', function(done) { it('returns deviceIds for a number', function(done) {
var testRecord = "an opaque string"; var testRecord = "an opaque string";
var devices = [1, 2, 3].map(function(deviceId) { var devices = [1, 2, 3].map(function(deviceId) {

Loading…
Cancel
Save