From aa83bc1dabebd4b581cd2d6e4b498e2df9989fed Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 28 Jun 2017 17:30:35 -1000 Subject: [PATCH] Ensure all sessions are archived on profile fetch If the key has changed, saveIdentity will archive sibling sessions, but not the session for the device it was called on. Therefore we have to archive that one by hand. Also switch from saving the identity of an OutgoingIdentityKeyError to just triggering a profile fetch, mostly for consistency, simplicity, and DRYness. // FREEBIE --- js/models/conversations.js | 13 +++++++++++-- js/models/messages.js | 14 ++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index c905ea917..5fec2d96f 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -583,8 +583,17 @@ var identityKey = dcodeIO.ByteBuffer.wrap(profile.identityKey, 'base64').toArrayBuffer(); return textsecure.storage.protocol.saveIdentity( - id, identityKey, false - ); + id + '.1', identityKey, false + ).then(function(changed) { + if (changed) { + // save identity will close all sessions except for .1, so we + // must close that one manually. + var address = new libsignal.SignalProtocolAddress(id, 1); + console.log('closing session for', address.toString()); + var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address); + return sessionCipher.closeOpenSessionForDevice(); + } + }); }); }, diff --git a/js/models/messages.js b/js/models/messages.js index 76d3029be..7903443bf 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -225,10 +225,9 @@ if (result.name === 'SignedPreKeyRotationError') { promises.push(getAccountManager().rotateSignedPreKey()); } - else if (result.name === 'OutgoingIdentityKeyError' && result.identityKey) { - promises.push(textsecure.storage.protocol.saveIdentity( - result.number, result.identityKey, false - )); + else if (result.name === 'OutgoingIdentityKeyError') { + var c = ConversationController.get(result.number); + promises.push(c.getProfiles()); } } else { this.saveErrors(result.errors); @@ -237,10 +236,9 @@ promises.push(this.sendSyncMessage()); } promises = promises.concat(_.map(result.errors, function(error) { - if (error.name === 'OutgoingIdentityKeyError' && error.identityKey) { - return textsecure.storage.protocol.saveIdentity( - error.number, error.identityKey, false - ); + if (error.name === 'OutgoingIdentityKeyError') { + var c = ConversationController.get(error.number); + promises.push(c.getProfiles()); } })); }