Clear old sessions for a device when its identity changes
This commit is contained in:
parent
ee00f080f4
commit
b45ace4d58
23
dist/libsignal-protocol.js
vendored
23
dist/libsignal-protocol.js
vendored
@ -35762,6 +35762,17 @@ Internal.SessionRecord = function() {
|
|||||||
delete sessions[util.toString(oldestBaseKey)];
|
delete sessions[util.toString(oldestBaseKey)];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
removePreviousSessions: function() {
|
||||||
|
var sessions = this.sessions;
|
||||||
|
for (var key in sessions) {
|
||||||
|
if (sessions[key].indexInfo.closed === -1) {
|
||||||
|
var newSessions = {};
|
||||||
|
newSessions[key] = sessions[key];
|
||||||
|
this.sessions = newSessions;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return SessionRecord;
|
return SessionRecord;
|
||||||
@ -35857,7 +35868,11 @@ SessionBuilder.prototype = {
|
|||||||
record.updateSessionState(session);
|
record.updateSessionState(session);
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
this.storage.storeSession(address, record.serialize()),
|
this.storage.storeSession(address, record.serialize()),
|
||||||
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey)
|
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey).then(function(changed) {
|
||||||
|
if (changed) {
|
||||||
|
return record.removePreviousSessions();
|
||||||
|
}
|
||||||
|
}.bind(this))
|
||||||
]);
|
]);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
@ -35914,7 +35929,11 @@ SessionBuilder.prototype = {
|
|||||||
// end of decryptWhisperMessage ... to ensure that the sender
|
// end of decryptWhisperMessage ... to ensure that the sender
|
||||||
// actually holds the private keys for all reported pubkeys
|
// actually holds the private keys for all reported pubkeys
|
||||||
record.updateSessionState(new_session);
|
record.updateSessionState(new_session);
|
||||||
return this.storage.saveIdentity(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function() {
|
return this.storage.saveIdentity(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function(changed) {
|
||||||
|
if (changed) {
|
||||||
|
return record.removePreviousSessions();
|
||||||
|
}
|
||||||
|
}).then(function() {
|
||||||
return message.preKeyId;
|
return message.preKeyId;
|
||||||
});
|
});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|||||||
@ -51,7 +51,11 @@ SessionBuilder.prototype = {
|
|||||||
record.updateSessionState(session);
|
record.updateSessionState(session);
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
this.storage.storeSession(address, record.serialize()),
|
this.storage.storeSession(address, record.serialize()),
|
||||||
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey)
|
this.storage.saveIdentity(this.remoteAddress.getName(), session.indexInfo.remoteIdentityKey).then(function(changed) {
|
||||||
|
if (changed) {
|
||||||
|
return record.removePreviousSessions();
|
||||||
|
}
|
||||||
|
}.bind(this))
|
||||||
]);
|
]);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
@ -108,7 +112,11 @@ SessionBuilder.prototype = {
|
|||||||
// end of decryptWhisperMessage ... to ensure that the sender
|
// end of decryptWhisperMessage ... to ensure that the sender
|
||||||
// actually holds the private keys for all reported pubkeys
|
// actually holds the private keys for all reported pubkeys
|
||||||
record.updateSessionState(new_session);
|
record.updateSessionState(new_session);
|
||||||
return this.storage.saveIdentity(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function() {
|
return this.storage.saveIdentity(this.remoteAddress.getName(), message.identityKey.toArrayBuffer()).then(function(changed) {
|
||||||
|
if (changed) {
|
||||||
|
return record.removePreviousSessions();
|
||||||
|
}
|
||||||
|
}).then(function() {
|
||||||
return message.preKeyId;
|
return message.preKeyId;
|
||||||
});
|
});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|||||||
@ -263,6 +263,17 @@ Internal.SessionRecord = function() {
|
|||||||
delete sessions[util.toString(oldestBaseKey)];
|
delete sessions[util.toString(oldestBaseKey)];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
removePreviousSessions: function() {
|
||||||
|
var sessions = this.sessions;
|
||||||
|
for (var key in sessions) {
|
||||||
|
if (sessions[key].indexInfo.closed === -1) {
|
||||||
|
var newSessions = {};
|
||||||
|
newSessions[key] = sessions[key];
|
||||||
|
this.sessions = newSessions;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return SessionRecord;
|
return SessionRecord;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user