Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Commit cee3b82

Browse files
committed
Remove removePreviousSessions
This reverts commit b45ace4 and parts of 2657f00. The purpose of the deletes was so that a session with a different identity key couldn't get "resurrected" after an identity switch. But if the validate/save action is happening for every encrypt/decrypt, then it shouldn't be possible for an old identity to get invisibly resurrected. Furthermore, at the application level we would clear sessions for all devices on the affected number, but libsignal-protocol operates on a per-device basis, so it can only perform what amounts to an incomplete removal.
1 parent e68e17c commit cee3b82

File tree

4 files changed

+8
-62
lines changed

4 files changed

+8
-62
lines changed

dist/libsignal-protocol.js

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35762,17 +35762,6 @@ Internal.SessionRecord = function() {
3576235762
delete sessions[util.toString(oldestBaseKey)];
3576335763
}
3576435764
},
35765-
removePreviousSessions: function() {
35766-
var sessions = this.sessions;
35767-
for (var key in sessions) {
35768-
if (sessions[key].indexInfo.closed === -1) {
35769-
var newSessions = {};
35770-
newSessions[key] = sessions[key];
35771-
this.sessions = newSessions;
35772-
return;
35773-
}
35774-
}
35775-
},
3577635765
};
3577735766

3577835767
return SessionRecord;
@@ -35868,11 +35857,7 @@ SessionBuilder.prototype = {
3586835857
record.updateSessionState(session);
3586935858
return Promise.all([
3587035859
this.storage.storeSession(address, record.serialize()),
35871-
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey).then(function(changed) {
35872-
if (changed) {
35873-
return record.removePreviousSessions();
35874-
}
35875-
}.bind(this))
35860+
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey)
3587635861
]);
3587735862
}.bind(this));
3587835863
}.bind(this));
@@ -35929,11 +35914,7 @@ SessionBuilder.prototype = {
3592935914
// end of decryptWhisperMessage ... to ensure that the sender
3593035915
// actually holds the private keys for all reported pubkeys
3593135916
record.updateSessionState(new_session);
35932-
return this.storage.saveIdentity(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function(changed) {
35933-
if (changed) {
35934-
return record.removePreviousSessions();
35935-
}
35936-
}).then(function() {
35917+
return this.storage.saveIdentity(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function() {
3593735918
return message.preKeyId;
3593835919
});
3593935920
}.bind(this));
@@ -36136,11 +36117,7 @@ SessionCipher.prototype = {
3613636117
throw new Error('Identity key changed');
3613736118
}
3613836119
}).then(function() {
36139-
return this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey).then(function(changed) {
36140-
if (changed) {
36141-
return record.removePreviousSessions();
36142-
}
36143-
});
36120+
return this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey);
3614436121
}.bind(this)).then(function() {
3614536122
record.updateSessionState(session);
3614636123
return this.storage.storeSession(address, record.serialize()).then(function() {
@@ -36222,11 +36199,7 @@ SessionCipher.prototype = {
3622236199
throw new Error('Identity key changed');
3622336200
}
3622436201
}).then(function() {
36225-
return this.storage.saveIdentity(this.remoteAddress.getName(), result.session.indexInfo.remoteIdentityKey).then(function(changed) {
36226-
if (changed) {
36227-
return record.removePreviousSessions();
36228-
}
36229-
});
36202+
return this.storage.saveIdentity(this.remoteAddress.getName(), result.session.indexInfo.remoteIdentityKey);
3623036203
}.bind(this)).then(function() {
3623136204
record.updateSessionState(result.session);
3623236205
return this.storage.storeSession(address, record.serialize()).then(function() {

src/SessionBuilder.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ SessionBuilder.prototype = {
5151
record.updateSessionState(session);
5252
return Promise.all([
5353
this.storage.storeSession(address, record.serialize()),
54-
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey).then(function(changed) {
55-
if (changed) {
56-
return record.removePreviousSessions();
57-
}
58-
}.bind(this))
54+
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey)
5955
]);
6056
}.bind(this));
6157
}.bind(this));
@@ -112,11 +108,7 @@ SessionBuilder.prototype = {
112108
// end of decryptWhisperMessage ... to ensure that the sender
113109
// actually holds the private keys for all reported pubkeys
114110
record.updateSessionState(new_session);
115-
return this.storage.saveIdentity(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function(changed) {
116-
if (changed) {
117-
return record.removePreviousSessions();
118-
}
119-
}).then(function() {
111+
return this.storage.saveIdentity(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function() {
120112
return message.preKeyId;
121113
});
122114
}.bind(this));

src/SessionCipher.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ SessionCipher.prototype = {
8383
throw new Error('Identity key changed');
8484
}
8585
}).then(function() {
86-
return this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey).then(function(changed) {
87-
if (changed) {
88-
return record.removePreviousSessions();
89-
}
90-
});
86+
return this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey);
9187
}.bind(this)).then(function() {
9288
record.updateSessionState(session);
9389
return this.storage.storeSession(address, record.serialize()).then(function() {
@@ -169,11 +165,7 @@ SessionCipher.prototype = {
169165
throw new Error('Identity key changed');
170166
}
171167
}).then(function() {
172-
return this.storage.saveIdentity(this.remoteAddress.getName(), result.session.indexInfo.remoteIdentityKey).then(function(changed) {
173-
if (changed) {
174-
return record.removePreviousSessions();
175-
}
176-
});
168+
return this.storage.saveIdentity(this.remoteAddress.getName(), result.session.indexInfo.remoteIdentityKey);
177169
}.bind(this)).then(function() {
178170
record.updateSessionState(result.session);
179171
return this.storage.storeSession(address, record.serialize()).then(function() {

src/SessionRecord.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,6 @@ Internal.SessionRecord = function() {
263263
delete sessions[util.toString(oldestBaseKey)];
264264
}
265265
},
266-
removePreviousSessions: function() {
267-
var sessions = this.sessions;
268-
for (var key in sessions) {
269-
if (sessions[key].indexInfo.closed === -1) {
270-
var newSessions = {};
271-
newSessions[key] = sessions[key];
272-
this.sessions = newSessions;
273-
return;
274-
}
275-
}
276-
},
277266
};
278267

279268
return SessionRecord;

0 commit comments

Comments
 (0)