Enable key backup by default

When we set up cross signing, so the key backup key will be stored
locally along with the cross signing keys until the user sets up
recovery (4s). This will mean that a user can restore their backup
if they log in on a new device as long as they verify with the one
they registered on.
dbkr/key_backup_by_default
David Baker 2024-10-22 14:58:20 +01:00
parent d4cf3881bc
commit 2c7247713a
2 changed files with 17 additions and 11 deletions

View File

@ -11,7 +11,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix";
import AuthPage from "../../views/auth/AuthPage"; import AuthPage from "../../views/auth/AuthPage";
import CompleteSecurityBody from "../../views/auth/CompleteSecurityBody"; import CompleteSecurityBody from "../../views/auth/CompleteSecurityBody";
import CreateCrossSigningDialog from "../../views/dialogs/security/CreateCrossSigningDialog"; import InitialCryptoSetup from "../../views/dialogs/security/InitialCryptoSetup";
interface IProps { interface IProps {
matrixClient: MatrixClient; matrixClient: MatrixClient;
@ -25,7 +25,7 @@ export default class E2eSetup extends React.Component<IProps> {
return ( return (
<AuthPage> <AuthPage>
<CompleteSecurityBody> <CompleteSecurityBody>
<CreateCrossSigningDialog <InitialCryptoSetup
matrixClient={this.props.matrixClient} matrixClient={this.props.matrixClient}
onFinished={this.props.onFinished} onFinished={this.props.onFinished}
accountPassword={this.props.accountPassword} accountPassword={this.props.accountPassword}

View File

@ -25,14 +25,14 @@ interface Props {
} }
/* /*
* Walks the user through the process of creating a cross-signing keys. In most * Walks the user through the process of creating a cross-signing keys and setting
* cases, only a spinner is shown, but for more complex auth like SSO, the user * up message key backup. In most cases, only a spinner is shown, but for more
* may need to complete some steps to proceed. * complex auth like SSO, the user may need to complete some steps to proceed.
*/ */
const CreateCrossSigningDialog: React.FC<Props> = ({ matrixClient, accountPassword, tokenLogin, onFinished }) => { const InitialCryptoSetup: React.FC<Props> = ({ matrixClient, accountPassword, tokenLogin, onFinished }) => {
const [error, setError] = useState(false); const [error, setError] = useState(false);
const bootstrapCrossSigning = useCallback(async () => { const doSetup = useCallback(async () => {
const cryptoApi = matrixClient.getCrypto(); const cryptoApi = matrixClient.getCrypto();
if (!cryptoApi) return; if (!cryptoApi) return;
@ -40,6 +40,12 @@ const CreateCrossSigningDialog: React.FC<Props> = ({ matrixClient, accountPasswo
try { try {
await createCrossSigning(matrixClient, tokenLogin, accountPassword); await createCrossSigning(matrixClient, tokenLogin, accountPassword);
const backupInfo = await matrixClient.getKeyBackupVersion();
if (backupInfo === null) {
await cryptoApi.resetKeyBackup();
}
onFinished(true); onFinished(true);
} catch (e) { } catch (e) {
if (tokenLogin) { if (tokenLogin) {
@ -58,8 +64,8 @@ const CreateCrossSigningDialog: React.FC<Props> = ({ matrixClient, accountPasswo
}, [onFinished]); }, [onFinished]);
useEffect(() => { useEffect(() => {
bootstrapCrossSigning(); doSetup();
}, [bootstrapCrossSigning]); }, [doSetup]);
let content; let content;
if (error) { if (error) {
@ -69,7 +75,7 @@ const CreateCrossSigningDialog: React.FC<Props> = ({ matrixClient, accountPasswo
<div className="mx_Dialog_buttons"> <div className="mx_Dialog_buttons">
<DialogButtons <DialogButtons
primaryButton={_t("action|retry")} primaryButton={_t("action|retry")}
onPrimaryButtonClick={bootstrapCrossSigning} onPrimaryButtonClick={doSetup}
onCancel={onCancel} onCancel={onCancel}
/> />
</div> </div>
@ -96,4 +102,4 @@ const CreateCrossSigningDialog: React.FC<Props> = ({ matrixClient, accountPasswo
); );
}; };
export default CreateCrossSigningDialog; export default InitialCryptoSetup;