diff --git a/src/crypto/index.js b/src/crypto/index.js index a81243f75..c9df7d10a 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -375,7 +375,7 @@ Crypto.prototype.bootstrapSecretStorage = async function({ "creating new keys", ); this._baseApis._cryptoCallbacks.saveCrossSigningKeys = - keys => crossSigningPrivateKeys = keys; + keys => Object.assign(crossSigningPrivateKeys, keys); this._baseApis._cryptoCallbacks.getCrossSigningKey = name => crossSigningPrivateKeys[name]; await this.resetCrossSigningKeys( @@ -468,7 +468,15 @@ Crypto.prototype.bootstrapSecretStorage = async function({ } } } finally { - this._baseApis._cryptoCallbacks = appCallbacks; + // Restore the original callbacks. NB. we must do this by manipulating + // the same object since the CrossSigning class has a reference to the + // object, so if we assign the object here then our callbacks will change + // but the instances of the CrossSigning class will be left with our + // random, otherwise dead closures. + for (const cb of Object.keys(this._baseApis._cryptoCallbacks)) { + delete this._baseApis._cryptoCallbacks[cb]; + } + Object.assign(this._baseApis._cryptoCallbacks, appCallbacks); } logger.log("Secure Secret Storage ready");