From 9e1ba992e3d97664e801e10a5346f65de9bf6c8b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Apr 2020 12:24:29 +0200 Subject: [PATCH 1/4] Clear cross-signing keys when detecting the keys have changed --- src/crypto/CrossSigning.js | 5 +++++ src/crypto/index.js | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/crypto/CrossSigning.js b/src/crypto/CrossSigning.js index c0633e958af..732f6070e51 100644 --- a/src/crypto/CrossSigning.js +++ b/src/crypto/CrossSigning.js @@ -310,6 +310,11 @@ export class CrossSigningInfo extends EventEmitter { } } + /** unsets the keys, used when another session has reset the keys, to disable cross-signing */ + clearKeys() { + this.keys = {}; + } + setKeys(keys) { const signingKeys = {}; if (keys.master) { diff --git a/src/crypto/index.js b/src/crypto/index.js index b8b02fba3f2..cf8f874f26c 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -1145,13 +1145,17 @@ Crypto.prototype._onDeviceListUserCrossSigningUpdated = async function(userId) { // If it's not changed, just make sure everything is up to date await this.checkOwnCrossSigningTrust(); } else { - this.emit("crossSigning.keysChanged", {}); // We'll now be in a state where cross-signing on the account is not trusted // because our locally stored cross-signing keys will not match the ones - // on the server for our account. The app must call checkOwnCrossSigningTrust() - // to fix this. - // XXX: Do we need to do something to emit events saying every device has become - // untrusted? + // on the server for our account. So we clear our own stored cross-signing keys, + // effectively disabling cross-signing until the user gets verified by the device + // that reset the keys + this._storeTrustedSelfKeys(null); + // XXX this event doesn't seem to be used anywhere + // the DeviceListener in react-sdl does recheck though, + // as `crypto.devicesUpdated`` and `accountData` are + // emitted on the client when this case happens. + this.emit("crossSigning.keysChanged", {}); } } else { await this._checkDeviceVerifications(userId); @@ -1307,7 +1311,11 @@ Crypto.prototype.checkOwnCrossSigningTrust = async function() { * @param {object} keys The new trusted set of keys */ Crypto.prototype._storeTrustedSelfKeys = async function(keys) { - this._crossSigningInfo.setKeys(keys); + if (keys) { + this._crossSigningInfo.setKeys(keys); + } else { + this._crossSigningInfo.clearKeys(); + } await this._cryptoStore.doTxn( 'readwrite', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => { From c8fb4af369133c8994a85d643be2af14fb2cb754 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Apr 2020 13:13:17 +0200 Subject: [PATCH 2/4] fix comment style --- src/crypto/CrossSigning.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/crypto/CrossSigning.js b/src/crypto/CrossSigning.js index 732f6070e51..6d86d1bd9ce 100644 --- a/src/crypto/CrossSigning.js +++ b/src/crypto/CrossSigning.js @@ -310,7 +310,9 @@ export class CrossSigningInfo extends EventEmitter { } } - /** unsets the keys, used when another session has reset the keys, to disable cross-signing */ + /** + * unsets the keys, used when another session has reset the keys, to disable cross-signing + */ clearKeys() { this.keys = {}; } From 65dd56f53a13fc6495a47c487527c0736d3f77ad Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Apr 2020 13:27:13 +0200 Subject: [PATCH 3/4] remove obsolete comment --- src/crypto/index.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/crypto/index.js b/src/crypto/index.js index cf8f874f26c..ebe5bcd714d 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -1151,10 +1151,6 @@ Crypto.prototype._onDeviceListUserCrossSigningUpdated = async function(userId) { // effectively disabling cross-signing until the user gets verified by the device // that reset the keys this._storeTrustedSelfKeys(null); - // XXX this event doesn't seem to be used anywhere - // the DeviceListener in react-sdl does recheck though, - // as `crypto.devicesUpdated`` and `accountData` are - // emitted on the client when this case happens. this.emit("crossSigning.keysChanged", {}); } } else { From 70071eef410f5fc09dabea76847c0d02afc638a0 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Apr 2020 14:09:51 +0200 Subject: [PATCH 4/4] also emit user trust has changed --- src/crypto/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/crypto/index.js b/src/crypto/index.js index ebe5bcd714d..29123ee7f16 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -1151,7 +1151,12 @@ Crypto.prototype._onDeviceListUserCrossSigningUpdated = async function(userId) { // effectively disabling cross-signing until the user gets verified by the device // that reset the keys this._storeTrustedSelfKeys(null); + // emit cross-signing has been disabled this.emit("crossSigning.keysChanged", {}); + // as the trust for our own user has changed, + // also emit an event for this + this.emit("userTrustStatusChanged", + this._userId, this.checkUserTrust(userId)); } } else { await this._checkDeviceVerifications(userId);