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. Replaces https://github.com/element-hq/element-web/pull/28267
This commit is contained in:
parent
c07883ef05
commit
b2601b1728
8 changed files with 78 additions and 19 deletions
|
@ -23,11 +23,11 @@ import InteractiveAuthDialog from "./components/views/dialogs/InteractiveAuthDia
|
||||||
async function canUploadKeysWithPasswordOnly(cli: MatrixClient): Promise<boolean> {
|
async function canUploadKeysWithPasswordOnly(cli: MatrixClient): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await cli.uploadDeviceSigningKeys(undefined, {} as CrossSigningKeys);
|
await cli.uploadDeviceSigningKeys(undefined, {} as CrossSigningKeys);
|
||||||
// We should never get here: the server should always require
|
// If we get here, it's because the server is allowing us to upload keys without
|
||||||
// UI auth to upload device signing keys. If we do, we upload
|
// auth the first time due to MSC3967. Therefore, yes, we can upload keys
|
||||||
// no keys which would be a no-op.
|
// (with or without password, technically, but that's fine).
|
||||||
logger.log("uploadDeviceSigningKeys unexpectedly succeeded without UI auth!");
|
logger.log("uploadDeviceSigningKeys unexpectedly succeeded without UI auth!");
|
||||||
return false;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!(error instanceof MatrixError) || !error.data || !error.data.flows) {
|
if (!(error instanceof MatrixError) || !error.data || !error.data.flows) {
|
||||||
logger.log("uploadDeviceSigningKeys advertised no flows!");
|
logger.log("uploadDeviceSigningKeys advertised no flows!");
|
||||||
|
|
|
@ -295,13 +295,20 @@ export default class DeviceListener {
|
||||||
await crypto.getUserDeviceInfo([cli.getSafeUserId()]);
|
await crypto.getUserDeviceInfo([cli.getSafeUserId()]);
|
||||||
|
|
||||||
// cross signing isn't enabled - nag to enable it
|
// cross signing isn't enabled - nag to enable it
|
||||||
// There are 2 different toasts for:
|
// There are 3 different toasts for:
|
||||||
if (!(await crypto.getCrossSigningKeyId()) && (await crypto.userHasCrossSigningKeys())) {
|
if (!(await crypto.getCrossSigningKeyId()) && (await crypto.userHasCrossSigningKeys())) {
|
||||||
// Cross-signing on account but this device doesn't trust the master key (verify this session)
|
// Toast 1. Cross-signing on account but this device doesn't trust the master key (verify this session)
|
||||||
showSetupEncryptionToast(SetupKind.VERIFY_THIS_SESSION);
|
showSetupEncryptionToast(SetupKind.VERIFY_THIS_SESSION);
|
||||||
this.checkKeyBackupStatus();
|
this.checkKeyBackupStatus();
|
||||||
} else {
|
} else {
|
||||||
// No cross-signing or key backup on account (set up encryption)
|
const backupInfo = await this.getKeyBackupInfo();
|
||||||
|
if (backupInfo) {
|
||||||
|
// Toast 2: Key backup is enabled but recovery (4S) is not set up: prompt user to set up recovery.
|
||||||
|
// Since we now enable key backup at registration time, this will be the common case for
|
||||||
|
// new users.
|
||||||
|
showSetupEncryptionToast(SetupKind.SET_UP_RECOVERY);
|
||||||
|
} else {
|
||||||
|
// Toast 3: No cross-signing or key backup on account (set up encryption)
|
||||||
await cli.waitForClientWellKnown();
|
await cli.waitForClientWellKnown();
|
||||||
if (isSecureBackupRequired(cli) && isLoggedIn()) {
|
if (isSecureBackupRequired(cli) && isLoggedIn()) {
|
||||||
// If we're meant to set up, and Secure Backup is required,
|
// If we're meant to set up, and Secure Backup is required,
|
||||||
|
@ -313,6 +320,7 @@ export default class DeviceListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This needs to be done after awaiting on getUserDeviceInfo() above, so
|
// This needs to be done after awaiting on getUserDeviceInfo() above, so
|
||||||
// we make sure we get the devices after the fetch is done.
|
// we make sure we get the devices after the fetch is done.
|
||||||
|
|
|
@ -914,6 +914,9 @@
|
||||||
"warning": "If you didn't remove the recovery method, an attacker may be trying to access your account. Change your account password and set a new recovery method immediately in Settings."
|
"warning": "If you didn't remove the recovery method, an attacker may be trying to access your account. Change your account password and set a new recovery method immediately in Settings."
|
||||||
},
|
},
|
||||||
"reset_all_button": "Forgotten or lost all recovery methods? <a>Reset all</a>",
|
"reset_all_button": "Forgotten or lost all recovery methods? <a>Reset all</a>",
|
||||||
|
"set_up_recovery": "Set up recovery",
|
||||||
|
"set_up_recovery_later": "Not now",
|
||||||
|
"set_up_recovery_toast_description": "Generate a recovery key that can be used to restore your encrypted message history in case you lose access to your devices.",
|
||||||
"set_up_toast_description": "Safeguard against losing access to encrypted messages & data",
|
"set_up_toast_description": "Safeguard against losing access to encrypted messages & data",
|
||||||
"set_up_toast_title": "Set up Secure Backup",
|
"set_up_toast_title": "Set up Secure Backup",
|
||||||
"setup_secure_backup": {
|
"setup_secure_backup": {
|
||||||
|
|
|
@ -116,6 +116,11 @@ export class InitialCryptoSetupStore extends EventEmitter {
|
||||||
try {
|
try {
|
||||||
await createCrossSigning(this.client, this.isTokenLogin, this.stores.accountPasswordStore.getPassword());
|
await createCrossSigning(this.client, this.isTokenLogin, this.stores.accountPasswordStore.getPassword());
|
||||||
|
|
||||||
|
const backupInfo = await cryptoApi.getKeyBackupInfo();
|
||||||
|
if (backupInfo === null) {
|
||||||
|
await cryptoApi.resetKeyBackup();
|
||||||
|
}
|
||||||
|
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
this.status = "complete";
|
this.status = "complete";
|
||||||
|
|
|
@ -23,15 +23,19 @@ const getTitle = (kind: Kind): string => {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case Kind.SET_UP_ENCRYPTION:
|
case Kind.SET_UP_ENCRYPTION:
|
||||||
return _t("encryption|set_up_toast_title");
|
return _t("encryption|set_up_toast_title");
|
||||||
|
case Kind.SET_UP_RECOVERY:
|
||||||
|
return _t("encryption|set_up_recovery");
|
||||||
case Kind.VERIFY_THIS_SESSION:
|
case Kind.VERIFY_THIS_SESSION:
|
||||||
return _t("encryption|verify_toast_title");
|
return _t("encryption|verify_toast_title");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getIcon = (kind: Kind): string => {
|
const getIcon = (kind: Kind): string | undefined => {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case Kind.SET_UP_ENCRYPTION:
|
case Kind.SET_UP_ENCRYPTION:
|
||||||
return "secure_backup";
|
return "secure_backup";
|
||||||
|
case Kind.SET_UP_RECOVERY:
|
||||||
|
return undefined;
|
||||||
case Kind.VERIFY_THIS_SESSION:
|
case Kind.VERIFY_THIS_SESSION:
|
||||||
return "verification_warning";
|
return "verification_warning";
|
||||||
}
|
}
|
||||||
|
@ -41,15 +45,29 @@ const getSetupCaption = (kind: Kind): string => {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case Kind.SET_UP_ENCRYPTION:
|
case Kind.SET_UP_ENCRYPTION:
|
||||||
return _t("action|continue");
|
return _t("action|continue");
|
||||||
|
case Kind.SET_UP_RECOVERY:
|
||||||
|
return _t("action|continue");
|
||||||
case Kind.VERIFY_THIS_SESSION:
|
case Kind.VERIFY_THIS_SESSION:
|
||||||
return _t("action|verify");
|
return _t("action|verify");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSecondaryButtonLabel = (kind: Kind): string => {
|
||||||
|
switch (kind) {
|
||||||
|
case Kind.SET_UP_RECOVERY:
|
||||||
|
return _t("encryption|set_up_recovery_later");
|
||||||
|
case Kind.SET_UP_ENCRYPTION:
|
||||||
|
case Kind.VERIFY_THIS_SESSION:
|
||||||
|
return _t("encryption|verification|unverified_sessions_toast_reject");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getDescription = (kind: Kind): string => {
|
const getDescription = (kind: Kind): string => {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case Kind.SET_UP_ENCRYPTION:
|
case Kind.SET_UP_ENCRYPTION:
|
||||||
return _t("encryption|set_up_toast_description");
|
return _t("encryption|set_up_toast_description");
|
||||||
|
case Kind.SET_UP_RECOVERY:
|
||||||
|
return _t("encryption|set_up_recovery_toast_description");
|
||||||
case Kind.VERIFY_THIS_SESSION:
|
case Kind.VERIFY_THIS_SESSION:
|
||||||
return _t("encryption|verify_toast_description");
|
return _t("encryption|verify_toast_description");
|
||||||
}
|
}
|
||||||
|
@ -57,6 +75,7 @@ const getDescription = (kind: Kind): string => {
|
||||||
|
|
||||||
export enum Kind {
|
export enum Kind {
|
||||||
SET_UP_ENCRYPTION = "set_up_encryption",
|
SET_UP_ENCRYPTION = "set_up_encryption",
|
||||||
|
SET_UP_RECOVERY = "set_up_recovery",
|
||||||
VERIFY_THIS_SESSION = "verify_this_session",
|
VERIFY_THIS_SESSION = "verify_this_session",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +120,8 @@ export const showToast = (kind: Kind): void => {
|
||||||
description: getDescription(kind),
|
description: getDescription(kind),
|
||||||
primaryLabel: getSetupCaption(kind),
|
primaryLabel: getSetupCaption(kind),
|
||||||
onPrimaryClick: onAccept,
|
onPrimaryClick: onAccept,
|
||||||
secondaryLabel: _t("encryption|verification|unverified_sessions_toast_reject"),
|
secondaryLabel: getSecondaryButtonLabel(kind),
|
||||||
onSecondaryClick: onReject,
|
onSecondaryClick: onReject,
|
||||||
destructive: "secondary",
|
|
||||||
},
|
},
|
||||||
component: GenericToast,
|
component: GenericToast,
|
||||||
priority: kind === Kind.VERIFY_THIS_SESSION ? 95 : 40,
|
priority: kind === Kind.VERIFY_THIS_SESSION ? 95 : 40,
|
||||||
|
|
|
@ -352,13 +352,13 @@ describe("DeviceListener", () => {
|
||||||
mockCrypto!.getCrossSigningKeyId.mockResolvedValue("abc");
|
mockCrypto!.getCrossSigningKeyId.mockResolvedValue("abc");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows set up encryption toast when user has a key backup available", async () => {
|
it("shows set up recovery toast when user has a key backup available", async () => {
|
||||||
// non falsy response
|
// non falsy response
|
||||||
mockCrypto.getKeyBackupInfo.mockResolvedValue({} as unknown as KeyBackupInfo);
|
mockCrypto.getKeyBackupInfo.mockResolvedValue({} as unknown as KeyBackupInfo);
|
||||||
await createAndStart();
|
await createAndStart();
|
||||||
|
|
||||||
expect(SetupEncryptionToast.showToast).toHaveBeenCalledWith(
|
expect(SetupEncryptionToast.showToast).toHaveBeenCalledWith(
|
||||||
SetupEncryptionToast.Kind.SET_UP_ENCRYPTION,
|
SetupEncryptionToast.Kind.SET_UP_RECOVERY,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1003,6 +1003,7 @@ describe("<MatrixChat />", () => {
|
||||||
userHasCrossSigningKeys: jest.fn().mockResolvedValue(false),
|
userHasCrossSigningKeys: jest.fn().mockResolvedValue(false),
|
||||||
// This needs to not finish immediately because we need to test the screen appears
|
// This needs to not finish immediately because we need to test the screen appears
|
||||||
bootstrapCrossSigning: jest.fn().mockImplementation(() => bootstrapDeferred.promise),
|
bootstrapCrossSigning: jest.fn().mockImplementation(() => bootstrapDeferred.promise),
|
||||||
|
resetKeyBackup: jest.fn(),
|
||||||
isEncryptionEnabledInRoom: jest.fn().mockResolvedValue(false),
|
isEncryptionEnabledInRoom: jest.fn().mockResolvedValue(false),
|
||||||
};
|
};
|
||||||
loginClient.getCrypto.mockReturnValue(mockCrypto as any);
|
loginClient.getCrypto.mockReturnValue(mockCrypto as any);
|
||||||
|
|
24
test/unit-tests/toasts/SetupEncryptionToast-test.tsx
Normal file
24
test/unit-tests/toasts/SetupEncryptionToast-test.tsx
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
Copyright 2024 New Vector Ltd.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||||
|
Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { render, screen } from "jest-matrix-react";
|
||||||
|
|
||||||
|
import ToastContainer from "../../../src/components/structures/ToastContainer";
|
||||||
|
import { Kind, showToast } from "../../../src/toasts/SetupEncryptionToast";
|
||||||
|
|
||||||
|
describe("SetupEncryptionToast", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
render(<ToastContainer />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render the se up recovery toast", async () => {
|
||||||
|
showToast(Kind.SET_UP_RECOVERY);
|
||||||
|
|
||||||
|
await expect(screen.findByText("Set up recovery")).resolves.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue