Enforce Secure Backup completion when requested by HS

This removes all buttons to escape the Secure Backup setup flow when the
matching `.well-known` setting is set by homeserver.

Part of https://github.com/vector-im/element-web/issues/14954
pull/21833/head
J. Ryan Stinnett 2020-08-14 18:06:35 +01:00
parent 941cbc47c8
commit 1932505d3b
3 changed files with 23 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import { deriveKey } from 'matrix-js-sdk/src/crypto/key_passphrase';
import { decodeRecoveryKey } from 'matrix-js-sdk/src/crypto/recoverykey'; import { decodeRecoveryKey } from 'matrix-js-sdk/src/crypto/recoverykey';
import { _t } from './languageHandler'; import { _t } from './languageHandler';
import {encodeBase64} from "matrix-js-sdk/src/crypto/olmlib"; import {encodeBase64} from "matrix-js-sdk/src/crypto/olmlib";
import { isSecureBackupRequired } from './utils/WellKnownUtils';
// This stores the secret storage private keys in memory for the JS SDK. This is // This stores the secret storage private keys in memory for the JS SDK. This is
// only meant to act as a cache to avoid prompting the user multiple times // only meant to act as a cache to avoid prompting the user multiple times
@ -208,7 +209,18 @@ export async function accessSecretStorage(func = async () => { }, forceReset = f
{ {
force: forceReset, force: forceReset,
}, },
null, /* priority = */ false, /* static = */ true, null,
/* priority = */ false,
/* static = */ true,
/* options = */ {
onBeforeClose(reason) {
// If Secure Backup is required, you cannot leave the modal.
if (reason === "backgroundClick") {
return !isSecureBackupRequired();
}
return true;
},
},
); );
const [confirmed] = await finished; const [confirmed] = await finished;
if (!confirmed) { if (!confirmed) {

View File

@ -30,6 +30,7 @@ import StyledRadioButton from '../../../../components/views/elements/StyledRadio
import AccessibleButton from "../../../../components/views/elements/AccessibleButton"; import AccessibleButton from "../../../../components/views/elements/AccessibleButton";
import DialogButtons from "../../../../components/views/elements/DialogButtons"; import DialogButtons from "../../../../components/views/elements/DialogButtons";
import InlineSpinner from "../../../../components/views/elements/InlineSpinner"; import InlineSpinner from "../../../../components/views/elements/InlineSpinner";
import { isSecureBackupRequired } from '../../../../utils/WellKnownUtils';
const PHASE_LOADING = 0; const PHASE_LOADING = 0;
const PHASE_LOADERROR = 1; const PHASE_LOADERROR = 1;
@ -85,8 +86,8 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
canUploadKeysWithPasswordOnly: null, canUploadKeysWithPasswordOnly: null,
accountPassword: props.accountPassword || "", accountPassword: props.accountPassword || "",
accountPasswordCorrect: null, accountPasswordCorrect: null,
passPhraseKeySelected: CREATE_STORAGE_OPTION_KEY, passPhraseKeySelected: CREATE_STORAGE_OPTION_KEY,
canSkip: !isSecureBackupRequired(),
}; };
this._passphraseField = createRef(); this._passphraseField = createRef();
@ -470,7 +471,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
primaryButton={_t("Continue")} primaryButton={_t("Continue")}
onPrimaryButtonClick={this._onChooseKeyPassphraseFormSubmit} onPrimaryButtonClick={this._onChooseKeyPassphraseFormSubmit}
onCancel={this._onCancelClick} onCancel={this._onCancelClick}
hasCancel={true} hasCancel={this.state.canSkip}
/> />
</form>; </form>;
} }
@ -687,7 +688,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
<div className="mx_Dialog_buttons"> <div className="mx_Dialog_buttons">
<DialogButtons primaryButton={_t('Retry')} <DialogButtons primaryButton={_t('Retry')}
onPrimaryButtonClick={this._onLoadRetryClick} onPrimaryButtonClick={this._onLoadRetryClick}
hasCancel={true} hasCancel={this.state.canSkip}
onCancel={this._onCancel} onCancel={this._onCancel}
/> />
</div> </div>
@ -742,7 +743,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
<div className="mx_Dialog_buttons"> <div className="mx_Dialog_buttons">
<DialogButtons primaryButton={_t('Retry')} <DialogButtons primaryButton={_t('Retry')}
onPrimaryButtonClick={this._bootstrapSecretStorage} onPrimaryButtonClick={this._bootstrapSecretStorage}
hasCancel={true} hasCancel={this.state.canSkip}
onCancel={this._onCancel} onCancel={this._onCancel}
/> />
</div> </div>

View File

@ -33,3 +33,8 @@ export function getE2EEWellKnown(): IE2EEWellKnown {
} }
return null; return null;
} }
export function isSecureBackupRequired(): boolean {
const wellKnown = getE2EEWellKnown();
return wellKnown && wellKnown["secure_backup_required"] === true;
}