From 5624cf5ceb45c553a5bd21499fcd3cdf51b0734a Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 2 Jun 2020 17:55:27 +0100 Subject: [PATCH] Add option to reset keys to the encryption setup screen --- .../structures/auth/_CompleteSecurity.scss | 4 ++++ .../CreateSecretStorageDialog.js | 24 +++++++++++++++++-- .../structures/auth/SetupEncryptionBody.js | 15 ++++++++++++ src/stores/SetupEncryptionStore.js | 9 +++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/res/css/structures/auth/_CompleteSecurity.scss b/res/css/structures/auth/_CompleteSecurity.scss index 7dba57305f..7ea78befb4 100644 --- a/res/css/structures/auth/_CompleteSecurity.scss +++ b/res/css/structures/auth/_CompleteSecurity.scss @@ -102,3 +102,7 @@ limitations under the License. } } } + +.mx_CompleteSecurity_resetText { + padding-top: 20px; +} diff --git a/src/async-components/views/dialogs/secretstorage/CreateSecretStorageDialog.js b/src/async-components/views/dialogs/secretstorage/CreateSecretStorageDialog.js index 2147f2c8a8..a7114d9a73 100644 --- a/src/async-components/views/dialogs/secretstorage/CreateSecretStorageDialog.js +++ b/src/async-components/views/dialogs/secretstorage/CreateSecretStorageDialog.js @@ -359,6 +359,14 @@ export default class CreateSecretStorageDialog extends React.PureComponent { this.setState({phase: PHASE_CONFIRM_SKIP}); } + _onGoBackClick = () => { + if (this.state.backupInfo && !this.props.force) { + this.setState({phase: PHASE_MIGRATE}); + } else { + this.setState({phase: PHASE_INTRO}); + } + } + _onAccountPasswordChange = (e) => { this.setState({ accountPassword: e.target.value, @@ -492,6 +500,18 @@ export default class CreateSecretStorageDialog extends React.PureComponent { _renderPhaseIntro() { const DialogButtons = sdk.getComponent('views.elements.DialogButtons'); + + let cancelButton; + if (this.props.force) { + // if this is a forced key reset then aborting will just leave the old keys + // in place, and is thereforece just 'cancel' + cancelButton = ; + } else { + // if it's setting up from scratch then aborting leaves the user without + // crypto set up, so they skipping the setup. + cancelButton = ; + } + return

{_t( "Create a Recovery Key to store encryption keys & secrets with your account data. " + @@ -502,7 +522,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent { onPrimaryButtonClick={this._onIntroContinueClick} hasCancel={false} > - + {cancelButton}

; @@ -516,7 +536,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent { "access to encrypted messages.", )} diff --git a/src/components/structures/auth/SetupEncryptionBody.js b/src/components/structures/auth/SetupEncryptionBody.js index cc454b865f..bc83e6e939 100644 --- a/src/components/structures/auth/SetupEncryptionBody.js +++ b/src/components/structures/auth/SetupEncryptionBody.js @@ -83,6 +83,11 @@ export default class SetupEncryptionBody extends React.Component { store.stop(); } + _onResetClick = () => { + const store = SetupEncryptionStore.sharedInstance(); + store.startKeyReset(); + } + _onUseRecoveryKeyClick = async () => { const store = SetupEncryptionStore.sharedInstance(); store.useRecoveryKey(); @@ -226,6 +231,16 @@ export default class SetupEncryptionBody extends React.Component { {_t("Skip")} +
{_t( + "If you've forgotten your recovery key you can " + + "", {}, { + button: sub => + {sub} + , + }, + )}
); } else if (phase === PHASE_RECOVERY_KEY) { diff --git a/src/stores/SetupEncryptionStore.js b/src/stores/SetupEncryptionStore.js index 8c081e1da9..cc64e24a03 100644 --- a/src/stores/SetupEncryptionStore.js +++ b/src/stores/SetupEncryptionStore.js @@ -81,6 +81,15 @@ export class SetupEncryptionStore extends EventEmitter { this.emit("update"); } + async startKeyReset() { + try { + await accessSecretStorage(() => {}, {forceReset: true}); + // If the keys are reset, the trust status event will fire and we'll change state + } catch (e) { + // dialog was cancelled - stay on the current screen + } + } + async useRecoveryKey() { this.phase = PHASE_RECOVERY_KEY; this.emit("update");