diff --git a/dist/libsignal-protocol.js b/dist/libsignal-protocol.js index f5e6a02..5d0f1b6 100644 --- a/dist/libsignal-protocol.js +++ b/dist/libsignal-protocol.js @@ -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 ); } diff --git a/src/SessionBuilder.js b/src/SessionBuilder.js index 9895360..bfe1971 100644 --- a/src/SessionBuilder.js +++ b/src/SessionBuilder.js @@ -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)); diff --git a/src/SessionCipher.js b/src/SessionCipher.js index 5c6b914..076e85c 100644 --- a/src/SessionCipher.js +++ b/src/SessionCipher.js @@ -161,7 +161,6 @@ SessionCipher.prototype = { throw new Error("No registrationId"); } record = new Internal.SessionRecord( - util.toString(preKeyProto.identityKey), preKeyProto.registrationId ); } diff --git a/src/SessionRecord.js b/src/SessionRecord.js index b42546a..0a6a2e9 100644 --- a/src/SessionRecord.js +++ b/src/SessionRecord.js @@ -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(); diff --git a/test/SessionCipherTest.js b/test/SessionCipherTest.js index 96c5c92..88bd8fc 100644 --- a/test/SessionCipherTest.js +++ b/test/SessionCipherTest.js @@ -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) {