From f1e22f66a3635b8e66113477ff0b51ce19c7c682 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 20 Nov 2017 17:19:23 -0800 Subject: [PATCH] Expose ability to fully delete existing sessions - for resets (#35) --- src/SessionCipher.js | 15 +++++++++++++++ src/SessionRecord.js | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/SessionCipher.js b/src/SessionCipher.js index 3ba0102..14d3f2d 100644 --- a/src/SessionCipher.js +++ b/src/SessionCipher.js @@ -398,6 +398,20 @@ SessionCipher.prototype = { return this.storage.storeSession(address, record.serialize()); }.bind(this)); }.bind(this)); + }, + deleteAllSessionsForDevice: function() { + // Used in session reset scenarios, where we really need to delete + var address = this.remoteAddress.toString(); + return Internal.SessionLock.queueJobForNumber(address, function() { + return this.getRecord(address).then(function(record) { + if (record === undefined) { + return; + } + + record.deleteAllSessions(); + return this.storage.storeSession(address, record.serialize()); + }.bind(this)); + }.bind(this)); } }; @@ -417,4 +431,5 @@ libsignal.SessionCipher = function(storage, remoteAddress, options) { this.getRemoteRegistrationId = cipher.getRemoteRegistrationId.bind(cipher); this.hasOpenSession = cipher.hasOpenSession.bind(cipher); this.closeOpenSessionForDevice = cipher.closeOpenSessionForDevice.bind(cipher); + this.deleteAllSessionsForDevice = cipher.deleteAllSessionsForDevice.bind(cipher); }; diff --git a/src/SessionRecord.js b/src/SessionRecord.js index f56cef5..6aa325c 100644 --- a/src/SessionRecord.js +++ b/src/SessionRecord.js @@ -263,6 +263,10 @@ Internal.SessionRecord = function() { delete sessions[util.toString(oldestBaseKey)]; } }, + deleteAllSessions: function() { + // Used primarily in session reset scenarios, where we really delete sessions + this.sessions = {}; + } }; return SessionRecord;