index : matrix-js-sdk

My fork of matrix-js-sdk

diff options
context:
space:
mode:
authorBruno Windels <[email protected]>2020-06-26 12:53:11 +0000
committerGitHub <[email protected]>2020-06-26 12:53:11 +0000
commit68c7273f56d5e88b9af783c396963d03e2de4a92 (patch)
treeab1760e101036ce35d49bc9d58c199620952d234
parent8134eedd934296ebc99cca7d7b03710f05892bde (diff)
parent8b56ff4effcb121b4b1f391b080eaa6bdb83bc17 (diff)
downloadmatrix-js-sdk-68c7273f56d5e88b9af783c396963d03e2de4a92.tar.gz
Merge pull request #1414 from matrix-org/bwindels/fixbootstraperror
Ask general crypto callbacks for 4S privkey if operation adapter doesn't have it yet
-rw-r--r--src/crypto/EncryptionSetup.js21
-rw-r--r--src/crypto/index.js6
2 files changed, 22 insertions, 5 deletions
diff --git a/src/crypto/EncryptionSetup.js b/src/crypto/EncryptionSetup.js
index 38aee333..69a047db 100644
--- a/src/crypto/EncryptionSetup.js
+++ b/src/crypto/EncryptionSetup.js
@@ -18,11 +18,12 @@ import {
export class EncryptionSetupBuilder {
/**
* @param {Object.<String, MatrixEvent>} accountData pre-existing account data, will only be read, not written.
+ * @param {CryptoCallbacks} delegateCryptoCallbacks crypto callbacks to delegate to if the key isn't in cache yet
*/
- constructor(accountData) {
+ constructor(accountData, delegateCryptoCallbacks) {
this.accountDataClientAdapter = new AccountDataClientAdapter(accountData);
this.crossSigningCallbacks = new CrossSigningCallbacks();
- this.ssssCryptoCallbacks = new SSSSCryptoCallbacks();
+ this.ssssCryptoCallbacks = new SSSSCryptoCallbacks(delegateCryptoCallbacks);
this._crossSigningKeys = null;
this._keySignatures = null;
@@ -308,17 +309,29 @@ class CrossSigningCallbacks {
* the SecretStorage crypto callbacks
*/
class SSSSCryptoCallbacks {
- constructor() {
+ constructor(delegateCryptoCallbacks) {
this._privateKeys = new Map();
+ this._delegateCryptoCallbacks = delegateCryptoCallbacks;
}
- getSecretStorageKey({ keys }, name) {
+ async getSecretStorageKey({ keys }, name) {
for (const keyId of Object.keys(keys)) {
const privateKey = this._privateKeys.get(keyId);
if (privateKey) {
return [keyId, privateKey];
}
}
+ // if we don't have the key cached yet, ask
+ // for it to the general crypto callbacks and cache it
+ if (this._delegateCryptoCallbacks) {
+ const result = await this._delegateCryptoCallbacks.
+ getSecretStorageKey({keys}, name);
+ if (result) {
+ const [keyId, privateKey] = result;
+ this._privateKeys.set(keyId, privateKey);
+ }
+ return result;
+ }
}
addPrivateKey(keyId, privKey) {
diff --git a/src/crypto/index.js b/src/crypto/index.js
index 1c92b4fe..caaaba5e 100644
--- a/src/crypto/index.js
+++ b/src/crypto/index.js
@@ -483,7 +483,11 @@ Crypto.prototype.bootstrapSecretStorage = async function({
getKeyBackupPassphrase,
} = {}) {
logger.log("Bootstrapping Secure Secret Storage");
- const builder = new EncryptionSetupBuilder(this._baseApis.store.accountData);
+ const delegateCryptoCallbacks = this._baseApis._cryptoCallbacks;
+ const builder = new EncryptionSetupBuilder(
+ this._baseApis.store.accountData,
+ delegateCryptoCallbacks,
+ );
const secretStorage = new SecretStorage(
builder.accountDataClientAdapter,
builder.ssssCryptoCallbacks);