From e1a496f231619c7c2dde03f6b5be35cb9e89e4c2 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 9 Apr 2020 17:30:10 +0100 Subject: [PATCH] Pass along key backup for bootstrap If we ask for the key backup key early in creating secret storage to ensure we trust the backup, then we stash it to ensure it's available to bootstrap as well without prompting again. Fixes https://github.com/vector-im/riot-web/issues/12958 --- src/CrossSigningManager.js | 2 +- .../CreateSecretStorageDialog.js | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/CrossSigningManager.js b/src/CrossSigningManager.js index 1bcf1ba706..07ec776bd1 100644 --- a/src/CrossSigningManager.js +++ b/src/CrossSigningManager.js @@ -185,7 +185,7 @@ export async function promptForBackupPassphrase() { const RestoreKeyBackupDialog = sdk.getComponent('dialogs.keybackup.RestoreKeyBackupDialog'); const { finished } = Modal.createTrackedDialog('Restore Backup', '', RestoreKeyBackupDialog, { - showSummary: false, keyCallback: k => key = k, + showSummary: false, keyCallback: k => key = k, }, null, /* priority = */ false, /* static = */ true); const success = await finished; diff --git a/src/async-components/views/dialogs/secretstorage/CreateSecretStorageDialog.js b/src/async-components/views/dialogs/secretstorage/CreateSecretStorageDialog.js index 01a2856df0..d63db617d5 100644 --- a/src/async-components/views/dialogs/secretstorage/CreateSecretStorageDialog.js +++ b/src/async-components/views/dialogs/secretstorage/CreateSecretStorageDialog.js @@ -70,6 +70,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent { this._recoveryKey = null; this._recoveryKeyNode = null; this._setZxcvbnResultTimeout = null; + this._backupKey = null; this.state = { phase: PHASE_LOADING, @@ -243,7 +244,15 @@ export default class CreateSecretStorageDialog extends React.PureComponent { createSecretStorageKey: async () => this._recoveryKey, keyBackupInfo: this.state.backupInfo, setupNewKeyBackup: !this.state.backupInfo && this.state.useKeyBackup, - getKeyBackupPassphrase: promptForBackupPassphrase, + getKeyBackupPassphrase: () => { + // We may already have the backup key if we earlier went + // through the restore backup path, so pass it along + // rather than prompting again. + if (this._backupKey) { + return this._backupKey; + } + return promptForBackupPassphrase(); + }, }); } this.setState({ @@ -272,10 +281,18 @@ export default class CreateSecretStorageDialog extends React.PureComponent { } _restoreBackup = async () => { + // It's possible we'll need the backup key later on for bootstrapping, + // so let's stash it here, rather than prompting for it twice. + const keyCallback = k => this._backupKey = k; + const RestoreKeyBackupDialog = sdk.getComponent('dialogs.keybackup.RestoreKeyBackupDialog'); const { finished } = Modal.createTrackedDialog( - 'Restore Backup', '', RestoreKeyBackupDialog, {showSummary: false}, null, - /* priority = */ false, /* static = */ false, + 'Restore Backup', '', RestoreKeyBackupDialog, + { + showSummary: false, + keyCallback, + }, + null, /* priority = */ false, /* static = */ false, ); await finished;