2020-03-24 15:57:04 +01:00
|
|
|
/*
|
2025-04-30 11:08:38 +01:00
|
|
|
Copyright 2024, 2025 New Vector Ltd.
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
2020-03-24 15:57:04 +01:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-03-24 15:57:04 +01:00
|
|
|
*/
|
|
|
|
|
|
2025-03-27 10:43:58 +00:00
|
|
|
import React, { type JSX } from "react";
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type KeyBackupInfo, type VerificationRequest } from "matrix-js-sdk/src/crypto-api";
|
2021-10-22 17:23:32 -05:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2025-09-12 14:37:14 -04:00
|
|
|
import DevicesIcon from "@vector-im/compound-design-tokens/assets/web/icons/devices";
|
|
|
|
|
import LockIcon from "@vector-im/compound-design-tokens/assets/web/icons/lock-solid";
|
|
|
|
|
import { Button } from "@vector-im/compound-web";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2020-06-19 17:17:04 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2020-03-24 15:57:04 +01:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2021-03-08 04:43:59 +00:00
|
|
|
import Modal from "../../../Modal";
|
|
|
|
|
import VerificationRequestDialog from "../../views/dialogs/VerificationRequestDialog";
|
2021-06-18 14:05:12 +01:00
|
|
|
import { SetupEncryptionStore, Phase } from "../../../stores/SetupEncryptionStore";
|
2021-07-01 15:11:18 +01:00
|
|
|
import EncryptionPanel from "../../views/right_panel/EncryptionPanel";
|
2025-09-12 14:37:14 -04:00
|
|
|
import AccessibleButton from "../../views/elements/AccessibleButton";
|
2021-07-01 13:49:58 +01:00
|
|
|
import Spinner from "../../views/elements/Spinner";
|
2025-04-30 11:08:38 +01:00
|
|
|
import { ResetIdentityDialog } from "../../views/dialogs/ResetIdentityDialog";
|
2025-09-12 14:37:14 -04:00
|
|
|
import { EncryptionCard } from "../../views/settings/encryption/EncryptionCard";
|
|
|
|
|
import { EncryptionCardButtons } from "../../views/settings/encryption/EncryptionCardButtons";
|
|
|
|
|
import { EncryptionCardEmphasisedContent } from "../../views/settings/encryption/EncryptionCardEmphasisedContent";
|
|
|
|
|
import ExternalLink from "../../views/elements/ExternalLink";
|
|
|
|
|
import dispatcher from "../../../dispatcher/dispatcher";
|
2020-06-23 15:24:02 +01:00
|
|
|
|
2021-07-01 13:45:33 +01:00
|
|
|
interface IProps {
|
2021-10-29 18:11:39 -04:00
|
|
|
onFinished: () => void;
|
2025-09-12 14:37:14 -04:00
|
|
|
/**
|
|
|
|
|
* Offer the user an option to log out, instead of setting up encryption.
|
|
|
|
|
*
|
|
|
|
|
* This is used when this component is shown when the user is initially
|
|
|
|
|
* prompted to set up encryption, before the user is shown the main chat
|
|
|
|
|
* interface.
|
|
|
|
|
*
|
|
|
|
|
* Defaults to `false` if omitted.
|
|
|
|
|
*/
|
|
|
|
|
allowLogout?: boolean;
|
2021-07-01 13:45:33 +01:00
|
|
|
}
|
2020-03-24 15:57:04 +01:00
|
|
|
|
2021-07-01 13:45:33 +01:00
|
|
|
interface IState {
|
2023-05-16 14:25:43 +01:00
|
|
|
phase?: Phase;
|
2023-03-31 09:26:15 +01:00
|
|
|
verificationRequest: VerificationRequest | null;
|
2024-07-04 16:50:07 +01:00
|
|
|
backupInfo: KeyBackupInfo | null;
|
2021-07-01 13:45:33 +01:00
|
|
|
}
|
|
|
|
|
|
2025-09-12 14:37:14 -04:00
|
|
|
/**
|
|
|
|
|
* Component to set up encryption by verifying the current device.
|
|
|
|
|
*/
|
2021-07-01 13:45:33 +01:00
|
|
|
export default class SetupEncryptionBody extends React.Component<IProps, IState> {
|
2023-02-13 11:39:16 +00:00
|
|
|
public constructor(props: IProps) {
|
2021-07-01 13:45:33 +01:00
|
|
|
super(props);
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.start();
|
|
|
|
|
this.state = {
|
|
|
|
|
phase: store.phase,
|
|
|
|
|
// this serves dual purpose as the object for the request logic and
|
2020-03-25 13:40:09 +01:00
|
|
|
// the presence of it indicating that we're in 'verify mode'.
|
2020-03-24 15:57:04 +01:00
|
|
|
// Because of the latter, it lives in the state.
|
|
|
|
|
verificationRequest: store.verificationRequest,
|
|
|
|
|
backupInfo: store.backupInfo,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 17:39:08 +00:00
|
|
|
public componentDidMount(): void {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.on("update", this.onStoreUpdate);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onStoreUpdate = (): void => {
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2021-06-18 14:05:12 +01:00
|
|
|
if (store.phase === Phase.Finished) {
|
2021-10-29 18:11:39 -04:00
|
|
|
this.props.onFinished();
|
2020-03-24 15:57:04 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.setState({
|
|
|
|
|
phase: store.phase,
|
|
|
|
|
verificationRequest: store.verificationRequest,
|
|
|
|
|
backupInfo: store.backupInfo,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentWillUnmount(): void {
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2021-07-01 13:49:58 +01:00
|
|
|
store.off("update", this.onStoreUpdate);
|
2020-03-24 15:57:04 +01:00
|
|
|
store.stop();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onUsePassphraseClick = async (): Promise<void> => {
|
2020-06-02 17:55:27 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2020-06-18 09:35:11 +01:00
|
|
|
store.usePassPhrase();
|
2021-07-01 15:11:18 +01:00
|
|
|
};
|
2020-03-24 15:57:04 +01:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onVerifyClick = (): void => {
|
2023-06-15 15:11:49 +01:00
|
|
|
const cli = MatrixClientPeg.safeGet();
|
2023-03-10 14:55:06 +00:00
|
|
|
const userId = cli.getSafeUserId();
|
2023-06-16 11:27:56 +01:00
|
|
|
const requestPromise = cli.getCrypto()!.requestOwnUserVerification();
|
2021-03-08 04:43:59 +00:00
|
|
|
|
2021-10-29 18:11:39 -04:00
|
|
|
// We need to call onFinished now to close this dialog, and
|
|
|
|
|
// again later to signal that the verification is complete.
|
|
|
|
|
this.props.onFinished();
|
2025-04-30 16:56:21 +01:00
|
|
|
const { finished: verificationFinished } = Modal.createDialog(VerificationRequestDialog, {
|
2021-03-08 04:43:59 +00:00
|
|
|
verificationRequestPromise: requestPromise,
|
2023-03-31 09:26:15 +01:00
|
|
|
member: cli.getUser(userId) ?? undefined,
|
2025-04-30 16:56:21 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
verificationFinished.then(async () => {
|
|
|
|
|
const request = await requestPromise;
|
|
|
|
|
request.cancel();
|
|
|
|
|
this.props.onFinished();
|
2021-03-08 04:43:59 +00:00
|
|
|
});
|
2021-07-01 15:11:18 +01:00
|
|
|
};
|
2021-03-08 04:43:59 +00:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onSkipConfirmClick = (): void => {
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.skipConfirm();
|
2021-07-01 15:11:18 +01:00
|
|
|
};
|
2020-03-24 15:57:04 +01:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onSkipBackClick = (): void => {
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.returnAfterSkip();
|
2021-07-01 15:11:18 +01:00
|
|
|
};
|
2020-03-24 15:57:04 +01:00
|
|
|
|
2025-09-12 14:37:14 -04:00
|
|
|
private onCantConfirmClick = (): void => {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2025-04-30 11:08:38 +01:00
|
|
|
Modal.createDialog(ResetIdentityDialog, {
|
|
|
|
|
onReset: () => {
|
|
|
|
|
// The user completed the reset process - close this dialog
|
|
|
|
|
this.props.onFinished();
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.done();
|
|
|
|
|
},
|
2025-09-12 14:37:14 -04:00
|
|
|
variant: store.lostKeys() ? "no_verification_method" : "confirm",
|
2025-04-30 11:08:38 +01:00
|
|
|
});
|
2021-09-08 13:55:31 -04:00
|
|
|
};
|
|
|
|
|
|
2025-09-12 14:37:14 -04:00
|
|
|
private onSignOutClick = (): void => {
|
|
|
|
|
dispatcher.dispatch({ action: "logout" });
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onDoneClick = (): void => {
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.done();
|
2021-07-01 15:11:18 +01:00
|
|
|
};
|
2020-03-24 15:57:04 +01:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onEncryptionPanelClose = (): void => {
|
2021-10-29 18:11:39 -04:00
|
|
|
this.props.onFinished();
|
2021-07-01 15:11:18 +01:00
|
|
|
};
|
2021-07-01 13:45:33 +01:00
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2023-06-15 15:11:49 +01:00
|
|
|
const cli = MatrixClientPeg.safeGet();
|
2025-09-12 14:37:14 -04:00
|
|
|
const { phase } = this.state;
|
2020-03-24 15:57:04 +01:00
|
|
|
|
2023-03-31 09:26:15 +01:00
|
|
|
if (this.state.verificationRequest && cli.getUser(this.state.verificationRequest.otherUserId)) {
|
2020-03-24 15:57:04 +01:00
|
|
|
return (
|
|
|
|
|
<EncryptionPanel
|
|
|
|
|
layout="dialog"
|
|
|
|
|
verificationRequest={this.state.verificationRequest}
|
2021-07-01 13:45:33 +01:00
|
|
|
onClose={this.onEncryptionPanelClose}
|
2023-03-31 09:26:15 +01:00
|
|
|
member={cli.getUser(this.state.verificationRequest.otherUserId)!}
|
2021-07-01 13:45:33 +01:00
|
|
|
isRoomEncrypted={false}
|
2020-03-24 15:57:04 +01:00
|
|
|
/>
|
|
|
|
|
);
|
2021-06-18 14:05:12 +01:00
|
|
|
} else if (phase === Phase.Intro) {
|
2025-09-12 14:37:14 -04:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2020-06-05 16:40:20 +01:00
|
|
|
|
2025-09-12 14:37:14 -04:00
|
|
|
let verifyButton;
|
|
|
|
|
if (store.hasDevicesToVerifyAgainst) {
|
|
|
|
|
verifyButton = (
|
|
|
|
|
<Button kind="primary" onClick={this.onVerifyClick}>
|
|
|
|
|
<DevicesIcon /> {_t("encryption|verification|use_another_device")}
|
|
|
|
|
</Button>
|
2021-09-08 13:55:31 -04:00
|
|
|
);
|
|
|
|
|
}
|
2025-09-12 14:37:14 -04:00
|
|
|
|
|
|
|
|
let useRecoveryKeyButton;
|
|
|
|
|
if (store.keyInfo) {
|
|
|
|
|
useRecoveryKeyButton = (
|
|
|
|
|
<Button kind="primary" onClick={this.onUsePassphraseClick}>
|
|
|
|
|
{_t("encryption|verification|use_recovery_key")}
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let signOutButton;
|
|
|
|
|
if (this.props.allowLogout) {
|
|
|
|
|
signOutButton = (
|
|
|
|
|
<Button kind="tertiary" onClick={this.onSignOutClick}>
|
|
|
|
|
{_t("action|sign_out")}
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<EncryptionCard
|
|
|
|
|
title={_t("encryption|verification|confirm_identity_title")}
|
|
|
|
|
Icon={LockIcon}
|
|
|
|
|
className="mx_EncryptionCard_noBorder mx_SetupEncryptionBody"
|
|
|
|
|
>
|
|
|
|
|
<EncryptionCardEmphasisedContent>
|
|
|
|
|
<span>{_t("encryption|verification|confirm_identity_description")}</span>
|
|
|
|
|
<span>
|
|
|
|
|
<ExternalLink href="https://element.io/help#encryption-device-verification">
|
|
|
|
|
{_t("action|learn_more")}
|
|
|
|
|
</ExternalLink>
|
|
|
|
|
</span>
|
|
|
|
|
</EncryptionCardEmphasisedContent>
|
|
|
|
|
<EncryptionCardButtons>
|
|
|
|
|
{verifyButton}
|
|
|
|
|
{useRecoveryKeyButton}
|
|
|
|
|
<Button kind="secondary" onClick={this.onCantConfirmClick}>
|
|
|
|
|
{_t("encryption|verification|cant_confirm")}
|
|
|
|
|
</Button>
|
|
|
|
|
{signOutButton}
|
|
|
|
|
</EncryptionCardButtons>
|
|
|
|
|
</EncryptionCard>
|
|
|
|
|
);
|
2021-06-18 14:05:12 +01:00
|
|
|
} else if (phase === Phase.Done) {
|
2023-03-10 14:55:06 +00:00
|
|
|
let message: JSX.Element;
|
2020-03-24 15:57:04 +01:00
|
|
|
if (this.state.backupInfo) {
|
2023-09-28 12:51:30 +05:30
|
|
|
message = <p>{_t("encryption|verification|verification_success_with_backup")}</p>;
|
2020-03-24 15:57:04 +01:00
|
|
|
} else {
|
2023-09-28 12:51:30 +05:30
|
|
|
message = <p>{_t("encryption|verification|verification_success_without_backup")}</p>;
|
2020-03-24 15:57:04 +01:00
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2020-04-22 22:32:02 +01:00
|
|
|
<div className="mx_CompleteSecurity_heroIcon mx_E2EIcon_verified" />
|
2021-07-19 22:43:11 +01:00
|
|
|
{message}
|
2020-03-24 15:57:04 +01:00
|
|
|
<div className="mx_CompleteSecurity_actionRow">
|
|
|
|
|
<AccessibleButton kind="primary" onClick={this.onDoneClick}>
|
2023-08-22 20:55:15 +01:00
|
|
|
{_t("action|done")}
|
2020-03-24 15:57:04 +01:00
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2021-06-18 14:05:12 +01:00
|
|
|
} else if (phase === Phase.ConfirmSkip) {
|
2020-03-24 15:57:04 +01:00
|
|
|
return (
|
|
|
|
|
<div>
|
2023-09-28 12:51:30 +05:30
|
|
|
<p>{_t("encryption|verification|verification_skip_warning")}</p>
|
2020-03-24 15:57:04 +01:00
|
|
|
<div className="mx_CompleteSecurity_actionRow">
|
|
|
|
|
<AccessibleButton kind="danger_outline" onClick={this.onSkipConfirmClick}>
|
2023-09-28 12:51:30 +05:30
|
|
|
{_t("encryption|verification|verify_later")}
|
2020-03-24 15:57:04 +01:00
|
|
|
</AccessibleButton>
|
|
|
|
|
<AccessibleButton kind="primary" onClick={this.onSkipBackClick}>
|
2023-08-23 11:57:22 +01:00
|
|
|
{_t("action|go_back")}
|
2020-03-24 15:57:04 +01:00
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2021-06-18 14:05:12 +01:00
|
|
|
} else if (phase === Phase.Busy || phase === Phase.Loading) {
|
2020-03-24 15:57:04 +01:00
|
|
|
return <Spinner />;
|
|
|
|
|
} else {
|
2021-09-21 17:48:09 +02:00
|
|
|
logger.log(`SetupEncryptionBody: Unknown phase ${phase}`);
|
2020-03-24 15:57:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|