Remove duplicate identityKey from SessionRecord

This is redundant to the identity key store, and only used to check
internal consistency between sessions and the 'current' remote identity,
though there's no particular reason we can't keep sessions from previous
identity keys.
This commit is contained in:
lilia 2016-09-19 16:21:29 -07:00
parent 081b27daac
commit ffd60c7d94
5 changed files with 15 additions and 47 deletions

View File

@ -35554,13 +35554,8 @@ Internal.SessionRecord = function() {
return JSON.stringify(ensureStringed(thing)); //TODO: jquery???
}
var SessionRecord = function(identityKey, registrationId) {
var SessionRecord = function(registrationId) {
this._sessions = {};
identityKey = util.toString(identityKey);
if (typeof identityKey !== 'string') {
throw new Error('SessionRecord: Invalid identityKey');
}
this.identityKey = identityKey;
this.registrationId = registrationId;
if (this.registrationId === undefined || typeof this.registrationId !== 'number') {
@ -35570,12 +35565,12 @@ Internal.SessionRecord = function() {
SessionRecord.deserialize = function(serialized) {
var data = JSON.parse(serialized);
var record = new SessionRecord(data.identityKey, data.registrationId);
var record = new SessionRecord(data.registrationId);
record._sessions = data.sessions;
if (record._sessions === undefined || record._sessions === null || typeof record._sessions !== "object" || Array.isArray(record._sessions)) {
throw new Error("Error deserializing SessionRecord");
}
if (record.identityKey === undefined || record.registrationId === undefined) {
if (record.registrationId === undefined) {
throw new Error("Error deserializing SessionRecord");
}
return record;
@ -35585,8 +35580,7 @@ Internal.SessionRecord = function() {
serialize: function() {
return jsonThing({
sessions : this._sessions,
registrationId : this.registrationId,
identityKey : this.identityKey
registrationId : this.registrationId
});
},
haveOpenSession: function() {
@ -35654,15 +35648,6 @@ Internal.SessionRecord = function() {
this.removeOldChains(session);
if (this.identityKey === null) {
this.identityKey = session.indexInfo.remoteIdentityKey;
}
if (util.toString(this.identityKey) !== util.toString(session.indexInfo.remoteIdentityKey)) {
var e = new Error("Identity key changed at session save time");
e.identityKey = session.indexInfo.remoteIdentityKey.toArrayBuffer();
throw e;
}
sessions[util.toString(session.indexInfo.baseKey)] = session;
this.removeOldSessions();
@ -35849,14 +35834,14 @@ SessionBuilder.prototype = {
if (serialized !== undefined) {
record = Internal.SessionRecord.deserialize(serialized);
} else {
record = new Internal.SessionRecord(device.identityKey, device.registrationId);
record = new Internal.SessionRecord(device.registrationId);
}
record.archiveCurrentState();
record.updateSessionState(session, device.registrationId);
return Promise.all([
this.storage.storeSession(address, record.serialize()),
this.storage.saveIdentity(this.remoteAddress.getName(), record.identityKey)
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey)
]);
}.bind(this));
}.bind(this));
@ -36193,7 +36178,6 @@ SessionCipher.prototype = {
throw new Error("No registrationId");
}
record = new Internal.SessionRecord(
util.toString(preKeyProto.identityKey),
preKeyProto.registrationId
);
}

View File

@ -39,14 +39,14 @@ SessionBuilder.prototype = {
if (serialized !== undefined) {
record = Internal.SessionRecord.deserialize(serialized);
} else {
record = new Internal.SessionRecord(device.identityKey, device.registrationId);
record = new Internal.SessionRecord(device.registrationId);
}
record.archiveCurrentState();
record.updateSessionState(session, device.registrationId);
return Promise.all([
this.storage.storeSession(address, record.serialize()),
this.storage.saveIdentity(this.remoteAddress.getName(), record.identityKey)
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey)
]);
}.bind(this));
}.bind(this));

View File

@ -161,7 +161,6 @@ SessionCipher.prototype = {
throw new Error("No registrationId");
}
record = new Internal.SessionRecord(
util.toString(preKeyProto.identityKey),
preKeyProto.registrationId
);
}

View File

@ -55,13 +55,8 @@ Internal.SessionRecord = function() {
return JSON.stringify(ensureStringed(thing)); //TODO: jquery???
}
var SessionRecord = function(identityKey, registrationId) {
var SessionRecord = function(registrationId) {
this._sessions = {};
identityKey = util.toString(identityKey);
if (typeof identityKey !== 'string') {
throw new Error('SessionRecord: Invalid identityKey');
}
this.identityKey = identityKey;
this.registrationId = registrationId;
if (this.registrationId === undefined || typeof this.registrationId !== 'number') {
@ -71,12 +66,12 @@ Internal.SessionRecord = function() {
SessionRecord.deserialize = function(serialized) {
var data = JSON.parse(serialized);
var record = new SessionRecord(data.identityKey, data.registrationId);
var record = new SessionRecord(data.registrationId);
record._sessions = data.sessions;
if (record._sessions === undefined || record._sessions === null || typeof record._sessions !== "object" || Array.isArray(record._sessions)) {
throw new Error("Error deserializing SessionRecord");
}
if (record.identityKey === undefined || record.registrationId === undefined) {
if (record.registrationId === undefined) {
throw new Error("Error deserializing SessionRecord");
}
return record;
@ -86,8 +81,7 @@ Internal.SessionRecord = function() {
serialize: function() {
return jsonThing({
sessions : this._sessions,
registrationId : this.registrationId,
identityKey : this.identityKey
registrationId : this.registrationId
});
},
haveOpenSession: function() {
@ -155,15 +149,6 @@ Internal.SessionRecord = function() {
this.removeOldChains(session);
if (this.identityKey === null) {
this.identityKey = session.indexInfo.remoteIdentityKey;
}
if (util.toString(this.identityKey) !== util.toString(session.indexInfo.remoteIdentityKey)) {
var e = new Error("Identity key changed at session save time");
e.identityKey = session.indexInfo.remoteIdentityKey.toArrayBuffer();
throw e;
}
sessions[util.toString(session.indexInfo.baseKey)] = session;
this.removeOldSessions();

View File

@ -11,7 +11,7 @@ describe('SessionCipher', function() {
var sessionCipher = new libsignal.SessionCipher(store, address.toString());
describe('when a record exists', function() {
before(function(done) {
var record = new Internal.SessionRecord('identityKey', registrationId);
var record = new Internal.SessionRecord(registrationId);
store.storeSession(address.toString(), record.serialize()).then(done);
});
it('returns a valid registrationId', function(done) {
@ -36,7 +36,7 @@ describe('SessionCipher', function() {
var sessionCipher = new libsignal.SessionCipher(store, address.toString());
describe('registrationId is valid', function() {
before(function(done) {
var record = new Internal.SessionRecord('identityKey', 1);
var record = new Internal.SessionRecord( 1);
store.storeSession(address.toString(), record.serialize()).then(done);
});
it('returns true for a session with a valid registrationId', function(done) {
@ -47,7 +47,7 @@ describe('SessionCipher', function() {
});
describe('registrationId is null', function() {
before(function(done) {
var record = new Internal.SessionRecord('identityKey');
var record = new Internal.SessionRecord();
store.storeSession(address.toString(), record.serialize()).then(done);
});
it('returns false for a session with a null registrationId', function(done) {