Skip to content

Commit

Permalink
Merge pull request #1312 from matrix-org/bwindels/fixresetkeys
Browse files Browse the repository at this point in the history
Clear cross-signing keys when detecting the keys have changed
  • Loading branch information
bwindels authored Apr 9, 2020
2 parents bad09fe + 70071ee commit d1c9030
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/crypto/CrossSigning.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ 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) {
Expand Down
21 changes: 15 additions & 6 deletions src/crypto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1145,13 +1145,18 @@ 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);
// 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);
Expand Down Expand Up @@ -1307,7 +1312,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) => {
Expand Down

0 comments on commit d1c9030

Please sign in to comment.