2019-12-16 18:16:22 +01:00
|
|
|
/*
|
2020-01-24 16:16:46 +00:00
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
2019-12-16 18:16:22 +01:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-01-29 07:53:45 +00:00
|
|
|
import React from "react";
|
2022-02-22 12:18:08 +00:00
|
|
|
import {
|
2024-03-25 17:44:45 +00:00
|
|
|
ShowQrCodeCallbacks,
|
|
|
|
|
ShowSasCallbacks,
|
2023-06-14 15:35:32 +01:00
|
|
|
VerificationPhase as Phase,
|
2023-06-23 13:38:06 +01:00
|
|
|
VerificationRequest,
|
2022-02-22 12:18:08 +00:00
|
|
|
VerificationRequestEvent,
|
2024-03-22 12:28:13 +00:00
|
|
|
VerifierEvent,
|
2023-06-14 15:35:32 +01:00
|
|
|
} from "matrix-js-sdk/src/crypto-api";
|
2024-03-25 17:44:45 +00:00
|
|
|
import { Device, RoomMember, User } from "matrix-js-sdk/src/matrix";
|
2021-10-22 17:23:32 -05:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2024-03-25 17:44:45 +00:00
|
|
|
import { VerificationMethod } from "matrix-js-sdk/src/types";
|
2020-02-14 13:48:18 +01:00
|
|
|
|
2021-10-22 17:23:32 -05:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2020-01-17 19:53:33 -07:00
|
|
|
import VerificationQRCode from "../elements/crypto/VerificationQRCode";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2020-07-10 19:07:11 +01:00
|
|
|
import SdkConfig from "../../../SdkConfig";
|
2021-09-21 08:18:49 +02:00
|
|
|
import E2EIcon, { E2EState } from "../rooms/E2EIcon";
|
2020-01-28 11:13:09 +00:00
|
|
|
import Spinner from "../elements/Spinner";
|
2021-07-03 10:44:03 +02:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
|
|
|
|
import VerificationShowSas from "../verification/VerificationShowSas";
|
2023-06-28 13:39:34 +01:00
|
|
|
import { getDeviceCryptoInfo } from "../../../utils/crypto/deviceInfo";
|
2019-12-16 18:16:22 +01:00
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
interface IProps {
|
|
|
|
|
layout: string;
|
|
|
|
|
request: VerificationRequest;
|
2021-06-17 14:06:03 +01:00
|
|
|
member: RoomMember | User;
|
2023-03-22 12:15:26 +00:00
|
|
|
phase?: Phase;
|
2020-07-18 23:51:46 +05:30
|
|
|
onClose: () => void;
|
|
|
|
|
isRoomEncrypted: boolean;
|
|
|
|
|
inDialog: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
2023-07-13 14:55:55 +01:00
|
|
|
/**
|
|
|
|
|
* The data for the QR code to display.
|
|
|
|
|
*
|
|
|
|
|
* We attempt to calculate this once the verification request transitions into the "Ready" phase. If the other
|
|
|
|
|
* side cannot scan QR codes, it will remain `undefined`.
|
|
|
|
|
*/
|
|
|
|
|
qrCodeBytes: Buffer | undefined;
|
|
|
|
|
|
2023-06-07 14:05:23 +01:00
|
|
|
sasEvent: ShowSasCallbacks | null;
|
2020-07-18 23:51:46 +05:30
|
|
|
emojiButtonClicked?: boolean;
|
|
|
|
|
reciprocateButtonClicked?: boolean;
|
2023-06-07 14:05:23 +01:00
|
|
|
reciprocateQREvent: ShowQrCodeCallbacks | null;
|
2023-06-23 13:38:06 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Details of the other device involved in the transaction.
|
|
|
|
|
*
|
|
|
|
|
* `undefined` if there is not (yet) another device in the transaction, or if we do not know about it.
|
|
|
|
|
*/
|
|
|
|
|
otherDeviceDetails?: Device;
|
2020-07-18 23:51:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default class VerificationPanel extends React.PureComponent<IProps, IState> {
|
|
|
|
|
private hasVerifier: boolean;
|
|
|
|
|
|
2023-06-23 13:38:06 +01:00
|
|
|
/** have we yet tried to check the other device's info */
|
|
|
|
|
private haveCheckedDevice = false;
|
|
|
|
|
|
2023-07-13 14:55:55 +01:00
|
|
|
/** have we yet tried to get the QR code */
|
|
|
|
|
private haveFetchedQRCode = false;
|
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(props: IProps) {
|
2019-12-16 18:16:22 +01:00
|
|
|
super(props);
|
2023-07-13 14:55:55 +01:00
|
|
|
this.state = { qrCodeBytes: undefined, sasEvent: null, reciprocateQREvent: null };
|
2020-07-18 23:51:46 +05:30
|
|
|
this.hasVerifier = false;
|
2019-12-16 18:16:22 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private renderQRPhase(): JSX.Element {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { member, request } = this.props;
|
2024-03-25 17:44:45 +00:00
|
|
|
const showSAS: boolean = request.otherPartySupportsMethod(VerificationMethod.Sas);
|
|
|
|
|
const showQR: boolean = request.otherPartySupportsMethod(VerificationMethod.ScanQrCode);
|
2020-07-10 19:07:11 +01:00
|
|
|
const brand = SdkConfig.get().brand;
|
2020-01-24 16:41:43 +00:00
|
|
|
|
2023-03-22 12:15:26 +00:00
|
|
|
const noCommonMethodError: JSX.Element | null =
|
2023-09-07 10:37:09 +01:00
|
|
|
!showSAS && !showQR ? <p>{_t("encryption|verification|no_support_qr_emoji", { brand })}</p> : null;
|
2020-02-14 13:48:18 +01:00
|
|
|
|
2020-01-31 15:04:44 +00:00
|
|
|
if (this.props.layout === "dialog") {
|
|
|
|
|
// HACK: This is a terrible idea.
|
2023-03-16 11:07:29 +00:00
|
|
|
let qrBlockDialog: JSX.Element | undefined;
|
|
|
|
|
let sasBlockDialog: JSX.Element | undefined;
|
2023-07-13 14:55:55 +01:00
|
|
|
if (showQR) {
|
2020-07-18 23:52:41 +05:30
|
|
|
qrBlockDialog = (
|
2020-02-14 13:48:18 +01:00
|
|
|
<div className="mx_VerificationPanel_QRPhase_startOption">
|
2023-09-07 10:37:09 +01:00
|
|
|
<p>{_t("encryption|verification|qr_prompt")}</p>
|
2023-07-13 14:55:55 +01:00
|
|
|
<VerificationQRCode qrCodeBytes={this.state.qrCodeBytes} />
|
2020-02-14 13:48:18 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
2020-01-31 15:04:44 +00:00
|
|
|
}
|
2020-02-14 13:48:18 +01:00
|
|
|
if (showSAS) {
|
2020-08-29 01:11:08 +01:00
|
|
|
sasBlockDialog = (
|
|
|
|
|
<div className="mx_VerificationPanel_QRPhase_startOption">
|
2023-09-07 10:37:09 +01:00
|
|
|
<p>{_t("encryption|verification|sas_prompt")}</p>
|
2020-08-29 01:11:08 +01:00
|
|
|
<span className="mx_VerificationPanel_QRPhase_helpText">
|
2023-09-07 10:37:09 +01:00
|
|
|
{_t("encryption|verification|sas_description")}
|
2020-08-29 01:11:08 +01:00
|
|
|
</span>
|
|
|
|
|
<AccessibleButton
|
|
|
|
|
disabled={this.state.emojiButtonClicked}
|
|
|
|
|
onClick={this.startSAS}
|
|
|
|
|
kind="primary"
|
|
|
|
|
>
|
2023-08-22 20:55:15 +01:00
|
|
|
{_t("action|start")}
|
2020-08-29 01:11:08 +01:00
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2020-02-14 13:48:18 +01:00
|
|
|
}
|
2020-07-18 23:52:41 +05:30
|
|
|
const or =
|
|
|
|
|
qrBlockDialog && sasBlockDialog ? (
|
2022-09-06 13:27:36 +01:00
|
|
|
<div className="mx_VerificationPanel_QRPhase_betweenText">
|
2023-09-07 10:37:09 +01:00
|
|
|
{_t("encryption|verification|qr_or_sas", {
|
2022-09-06 13:27:36 +01:00
|
|
|
emojiCompare: "",
|
|
|
|
|
qrCode: "",
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
) : null;
|
2020-01-31 15:04:44 +00:00
|
|
|
return (
|
|
|
|
|
<div>
|
2023-09-07 10:37:09 +01:00
|
|
|
{_t("encryption|verification|qr_or_sas_header")}
|
2020-02-10 14:20:54 +01:00
|
|
|
<div className="mx_VerificationPanel_QRPhase_startOptions">
|
2021-07-19 22:43:11 +01:00
|
|
|
{qrBlockDialog}
|
|
|
|
|
{or}
|
|
|
|
|
{sasBlockDialog}
|
|
|
|
|
{noCommonMethodError}
|
2020-01-31 15:04:44 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-16 11:07:29 +00:00
|
|
|
let qrBlock: JSX.Element | undefined;
|
2023-07-13 14:55:55 +01:00
|
|
|
if (showQR) {
|
2020-02-14 13:48:18 +01:00
|
|
|
qrBlock = (
|
|
|
|
|
<div className="mx_UserInfo_container">
|
2023-10-02 13:52:27 +01:00
|
|
|
<h3>{_t("encryption|verification|scan_qr")}</h3>
|
2021-07-19 22:43:11 +01:00
|
|
|
<p>
|
2023-10-02 13:52:27 +01:00
|
|
|
{_t("encryption|verification|scan_qr_explainer", {
|
2021-06-17 14:06:03 +01:00
|
|
|
displayName: (member as User).displayName || (member as RoomMember).name || member.userId,
|
2021-07-19 22:43:11 +01:00
|
|
|
})}
|
|
|
|
|
</p>
|
2020-01-24 16:41:43 +00:00
|
|
|
|
2020-01-27 17:17:05 +00:00
|
|
|
<div className="mx_VerificationPanel_qrCode">
|
2023-07-13 14:55:55 +01:00
|
|
|
<VerificationQRCode qrCodeBytes={this.state.qrCodeBytes} />
|
2022-12-12 12:24:14 +01:00
|
|
|
</div>
|
2020-01-27 17:17:05 +00:00
|
|
|
</div>
|
2020-02-14 13:48:18 +01:00
|
|
|
);
|
|
|
|
|
}
|
2020-01-24 16:16:46 +00:00
|
|
|
|
2023-03-16 11:07:29 +00:00
|
|
|
let sasBlock: JSX.Element | undefined;
|
2020-02-14 13:48:18 +01:00
|
|
|
if (showSAS) {
|
2020-03-31 15:46:41 +02:00
|
|
|
const disabled = this.state.emojiButtonClicked;
|
2020-03-31 15:46:11 +02:00
|
|
|
const sasLabel = showQR
|
2023-10-02 13:52:27 +01:00
|
|
|
? _t("encryption|verification|verify_emoji_prompt_qr")
|
|
|
|
|
: _t("encryption|verification|verify_emoji_prompt");
|
2020-04-17 14:31:33 -06:00
|
|
|
|
|
|
|
|
// Note: mx_VerificationPanel_verifyByEmojiButton is for the end-to-end tests
|
2020-02-14 13:48:18 +01:00
|
|
|
sasBlock = (
|
|
|
|
|
<div className="mx_UserInfo_container">
|
2023-10-02 13:52:27 +01:00
|
|
|
<h3>{_t("encryption|verification|verify_emoji")}</h3>
|
2021-07-19 22:43:11 +01:00
|
|
|
<p>{sasLabel}</p>
|
2020-04-17 14:31:33 -06:00
|
|
|
<AccessibleButton
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
kind="primary"
|
|
|
|
|
className="mx_UserInfo_wideButton mx_VerificationPanel_verifyByEmojiButton"
|
2020-07-18 23:51:46 +05:30
|
|
|
onClick={this.startSAS}
|
2020-04-17 14:31:33 -06:00
|
|
|
>
|
2023-10-02 13:52:27 +01:00
|
|
|
{_t("encryption|verification|verify_emoji")}
|
2020-03-31 15:46:41 +02:00
|
|
|
</AccessibleButton>
|
2020-02-14 13:48:18 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const noCommonMethodBlock = noCommonMethodError ? (
|
2021-07-19 22:43:11 +01:00
|
|
|
<div className="mx_UserInfo_container">{noCommonMethodError}</div>
|
2020-08-29 01:11:08 +01:00
|
|
|
) : null;
|
2020-02-14 13:48:18 +01:00
|
|
|
|
|
|
|
|
// TODO: add way to open camera to scan a QR code
|
|
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
2021-07-19 22:43:11 +01:00
|
|
|
{qrBlock}
|
|
|
|
|
{sasBlock}
|
|
|
|
|
{noCommonMethodBlock}
|
2020-01-24 16:16:46 +00:00
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
2019-12-20 21:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onReciprocateYesClick = (): void => {
|
2023-03-16 11:07:29 +00:00
|
|
|
if (!this.state.reciprocateQREvent) return;
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ reciprocateButtonClicked: true });
|
2023-03-22 12:15:26 +00:00
|
|
|
this.state.reciprocateQREvent?.confirm();
|
2020-04-02 13:00:45 +02:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onReciprocateNoClick = (): void => {
|
2023-03-16 11:07:29 +00:00
|
|
|
if (!this.state.reciprocateQREvent) return;
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ reciprocateButtonClicked: true });
|
2023-03-22 12:15:26 +00:00
|
|
|
this.state.reciprocateQREvent?.cancel();
|
2020-04-02 13:00:45 +02:00
|
|
|
};
|
|
|
|
|
|
2023-06-23 13:38:06 +01:00
|
|
|
/**
|
|
|
|
|
* Get details of the other device involved in the verification, if we haven't before, and store in the state.
|
|
|
|
|
*/
|
|
|
|
|
private async maybeGetOtherDevice(): Promise<void> {
|
|
|
|
|
if (this.haveCheckedDevice) return;
|
|
|
|
|
|
|
|
|
|
const client = MatrixClientPeg.safeGet();
|
2023-06-14 15:35:32 +01:00
|
|
|
const deviceId = this.props.request?.otherDeviceId;
|
2023-06-23 13:38:06 +01:00
|
|
|
const userId = client.getUserId();
|
|
|
|
|
if (!deviceId || !userId) {
|
|
|
|
|
return;
|
2023-03-22 12:15:26 +00:00
|
|
|
}
|
2023-06-23 13:38:06 +01:00
|
|
|
this.haveCheckedDevice = true;
|
2023-06-28 13:39:34 +01:00
|
|
|
this.setState({ otherDeviceDetails: await getDeviceCryptoInfo(client, userId, deviceId) });
|
2020-05-12 11:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private renderQRReciprocatePhase(): JSX.Element {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { member, request } = this.props;
|
2020-04-02 17:12:10 +02:00
|
|
|
const description = request.isSelfVerification
|
2023-10-02 13:52:27 +01:00
|
|
|
? _t("encryption|verification|qr_reciprocate_same_shield_device")
|
|
|
|
|
: _t("encryption|verification|qr_reciprocate_same_shield_user", {
|
2021-06-17 14:06:03 +01:00
|
|
|
displayName: (member as User).displayName || (member as RoomMember).name || member.userId,
|
2020-04-02 16:42:39 +02:00
|
|
|
});
|
2020-07-18 23:51:46 +05:30
|
|
|
let body: JSX.Element;
|
2020-03-31 15:46:41 +02:00
|
|
|
if (this.state.reciprocateQREvent) {
|
2020-08-03 16:02:26 +01:00
|
|
|
// Element Web doesn't support scanning yet, so assume here we're the client being scanned.
|
2020-03-31 15:46:41 +02:00
|
|
|
body = (
|
|
|
|
|
<React.Fragment>
|
2021-07-19 22:43:11 +01:00
|
|
|
<p>{description}</p>
|
2021-09-21 08:18:49 +02:00
|
|
|
<E2EIcon isUser={true} status={E2EState.Verified} size={128} hideTooltip={true} />
|
2020-04-02 13:00:45 +02:00
|
|
|
<div className="mx_VerificationPanel_reciprocateButtons">
|
2021-06-21 14:16:37 +01:00
|
|
|
<AccessibleButton
|
2021-06-22 10:18:09 +01:00
|
|
|
kind="danger"
|
2020-04-02 13:00:45 +02:00
|
|
|
disabled={this.state.reciprocateButtonClicked}
|
2021-06-22 10:18:09 +01:00
|
|
|
onClick={this.onReciprocateNoClick}
|
|
|
|
|
>
|
2023-08-22 20:55:15 +01:00
|
|
|
{_t("action|no")}
|
2021-06-22 10:18:09 +01:00
|
|
|
</AccessibleButton>
|
2021-06-21 14:16:37 +01:00
|
|
|
<AccessibleButton
|
2021-06-22 10:18:09 +01:00
|
|
|
kind="primary"
|
2020-04-02 13:00:45 +02:00
|
|
|
disabled={this.state.reciprocateButtonClicked}
|
2021-06-22 10:18:09 +01:00
|
|
|
onClick={this.onReciprocateYesClick}
|
|
|
|
|
>
|
2023-08-22 20:55:15 +01:00
|
|
|
{_t("action|yes")}
|
2021-06-22 10:18:09 +01:00
|
|
|
</AccessibleButton>
|
2020-04-02 13:00:45 +02:00
|
|
|
</div>
|
2020-03-31 15:46:41 +02:00
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2020-04-02 13:00:45 +02:00
|
|
|
body = (
|
|
|
|
|
<p>
|
|
|
|
|
<Spinner />
|
|
|
|
|
</p>
|
|
|
|
|
);
|
2020-03-31 15:46:41 +02:00
|
|
|
}
|
2020-04-02 12:54:14 +02:00
|
|
|
return (
|
|
|
|
|
<div className="mx_UserInfo_container mx_VerificationPanel_reciprocate_section">
|
2023-10-02 13:52:27 +01:00
|
|
|
<h3>{_t("encryption|verification|scan_qr")}</h3>
|
2020-03-31 15:46:41 +02:00
|
|
|
{body}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private renderVerifiedPhase(): JSX.Element {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { member, request } = this.props;
|
2019-12-16 18:16:22 +01:00
|
|
|
|
2023-03-16 11:07:29 +00:00
|
|
|
let text: string | undefined;
|
2020-04-03 17:04:29 +02:00
|
|
|
if (!request.isSelfVerification) {
|
|
|
|
|
if (this.props.isRoomEncrypted) {
|
2023-10-02 13:52:27 +01:00
|
|
|
text = _t("encryption|verification|prompt_encrypted");
|
2020-04-03 17:04:29 +02:00
|
|
|
} else {
|
2023-10-02 13:52:27 +01:00
|
|
|
text = _t("encryption|verification|prompt_unencrypted");
|
2020-04-03 17:04:29 +02:00
|
|
|
}
|
2020-03-25 22:38:11 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
let description: string;
|
2020-05-12 11:05:30 +01:00
|
|
|
if (request.isSelfVerification) {
|
2023-06-23 13:38:06 +01:00
|
|
|
const device = this.state.otherDeviceDetails;
|
2020-05-12 11:05:30 +01:00
|
|
|
if (!device) {
|
2020-05-12 11:14:05 +01:00
|
|
|
// This can happen if the device is logged out while we're still showing verification
|
|
|
|
|
// UI for it.
|
2023-06-07 15:43:44 +01:00
|
|
|
logger.warn("Verified device we don't know about: " + this.props.request.otherDeviceId);
|
2023-10-02 13:52:27 +01:00
|
|
|
description = _t("encryption|verification|successful_own_device");
|
2020-05-12 12:42:16 +01:00
|
|
|
} else {
|
2023-10-02 13:52:27 +01:00
|
|
|
description = _t("encryption|verification|successful_device", {
|
2023-06-23 13:38:06 +01:00
|
|
|
deviceName: device.displayName,
|
|
|
|
|
deviceId: device.deviceId,
|
2020-05-12 12:42:16 +01:00
|
|
|
});
|
2020-05-12 11:05:30 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2023-10-02 13:52:27 +01:00
|
|
|
description = _t("encryption|verification|successful_user", {
|
2021-06-17 14:06:03 +01:00
|
|
|
displayName: (member as User).displayName || (member as RoomMember).name || member.userId,
|
2020-04-03 17:03:37 +02:00
|
|
|
});
|
2020-05-12 11:05:30 +01:00
|
|
|
}
|
2020-04-03 17:03:37 +02:00
|
|
|
|
2020-01-24 16:16:46 +00:00
|
|
|
return (
|
|
|
|
|
<div className="mx_UserInfo_container mx_VerificationPanel_verified_section">
|
2021-07-19 22:43:11 +01:00
|
|
|
<p>{description}</p>
|
2021-09-21 08:18:49 +02:00
|
|
|
<E2EIcon isUser={true} status={E2EState.Verified} size={128} hideTooltip={true} />
|
2020-04-03 17:04:29 +02:00
|
|
|
{text ? <p>{text}</p> : null}
|
2020-01-29 14:11:50 +00:00
|
|
|
<AccessibleButton kind="primary" className="mx_UserInfo_wideButton" onClick={this.props.onClose}>
|
2023-08-23 11:57:22 +01:00
|
|
|
{_t("action|got_it")}
|
2020-01-28 11:13:09 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private renderCancelledPhase(): JSX.Element {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { member, request } = this.props;
|
2020-01-28 11:13:09 +00:00
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
let startAgainInstruction: string;
|
2020-04-03 17:04:29 +02:00
|
|
|
if (request.isSelfVerification) {
|
2023-10-02 13:52:27 +01:00
|
|
|
startAgainInstruction = _t("encryption|verification|prompt_self");
|
2020-04-03 17:04:29 +02:00
|
|
|
} else {
|
2023-10-02 13:52:27 +01:00
|
|
|
startAgainInstruction = _t("encryption|verification|prompt_user");
|
2020-04-03 17:04:29 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
let text: string;
|
2020-01-28 11:13:09 +00:00
|
|
|
if (request.cancellationCode === "m.timeout") {
|
2023-10-02 13:52:27 +01:00
|
|
|
text = _t("encryption|verification|timed_out") + ` ${startAgainInstruction}`;
|
2020-01-28 11:13:09 +00:00
|
|
|
} else if (request.cancellingUserId === request.otherUserId) {
|
2020-04-03 17:04:29 +02:00
|
|
|
if (request.isSelfVerification) {
|
2023-10-02 13:52:27 +01:00
|
|
|
text = _t("encryption|verification|cancelled_self");
|
2020-04-03 17:04:29 +02:00
|
|
|
} else {
|
2023-10-02 13:52:27 +01:00
|
|
|
text = _t("encryption|verification|cancelled_user", {
|
2021-06-17 14:06:03 +01:00
|
|
|
displayName: (member as User).displayName || (member as RoomMember).name || member.userId,
|
2020-04-03 17:04:29 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
text = `${text} ${startAgainInstruction}`;
|
2020-01-28 11:13:09 +00:00
|
|
|
} else {
|
2023-10-02 13:52:27 +01:00
|
|
|
text = _t("encryption|verification|cancelled") + ` ${startAgainInstruction}`;
|
2020-01-28 11:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_UserInfo_container">
|
2023-08-22 18:47:33 +01:00
|
|
|
<h3>{_t("common|verification_cancelled")}</h3>
|
2020-01-28 11:13:09 +00:00
|
|
|
<p>{text}</p>
|
|
|
|
|
|
2020-01-29 14:11:50 +00:00
|
|
|
<AccessibleButton kind="primary" className="mx_UserInfo_wideButton" onClick={this.props.onClose}>
|
2023-08-23 11:57:22 +01:00
|
|
|
{_t("action|got_it")}
|
2020-01-24 16:16:46 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { member, phase, request } = this.props;
|
2020-01-24 16:16:46 +00:00
|
|
|
|
2021-06-17 14:06:03 +01:00
|
|
|
const displayName = (member as User).displayName || (member as RoomMember).name || member.userId;
|
2020-01-24 16:16:46 +00:00
|
|
|
|
2020-01-29 08:00:32 +00:00
|
|
|
switch (phase) {
|
2021-09-08 12:34:44 +01:00
|
|
|
case Phase.Ready:
|
2020-01-28 11:13:09 +00:00
|
|
|
return this.renderQRPhase();
|
2021-09-08 12:34:44 +01:00
|
|
|
case Phase.Started:
|
2020-03-31 15:46:41 +02:00
|
|
|
switch (request.chosenMethod) {
|
2024-03-25 17:44:45 +00:00
|
|
|
case VerificationMethod.Reciprocate:
|
2020-03-31 15:46:41 +02:00
|
|
|
return this.renderQRReciprocatePhase();
|
2024-03-25 17:44:45 +00:00
|
|
|
case VerificationMethod.Sas: {
|
2020-03-31 15:46:41 +02:00
|
|
|
const emojis = this.state.sasEvent ? (
|
|
|
|
|
<VerificationShowSas
|
|
|
|
|
displayName={displayName}
|
2023-06-23 13:38:06 +01:00
|
|
|
otherDeviceDetails={this.state.otherDeviceDetails}
|
2020-03-31 15:46:41 +02:00
|
|
|
sas={this.state.sasEvent.sas}
|
2020-07-18 23:51:46 +05:30
|
|
|
onCancel={this.onSasMismatchesClick}
|
|
|
|
|
onDone={this.onSasMatchesClick}
|
2020-03-31 15:46:41 +02:00
|
|
|
inDialog={this.props.inDialog}
|
2020-04-02 18:28:14 +02:00
|
|
|
isSelf={request.isSelfVerification}
|
2020-03-31 15:46:41 +02:00
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<Spinner />
|
|
|
|
|
);
|
|
|
|
|
return <div className="mx_UserInfo_container">{emojis}</div>;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
2020-01-28 11:13:09 +00:00
|
|
|
}
|
2021-09-08 12:34:44 +01:00
|
|
|
case Phase.Done:
|
2020-01-28 11:13:09 +00:00
|
|
|
return this.renderVerifiedPhase();
|
2021-09-08 12:34:44 +01:00
|
|
|
case Phase.Cancelled:
|
2020-01-28 11:13:09 +00:00
|
|
|
return this.renderCancelledPhase();
|
2019-12-16 18:16:22 +01:00
|
|
|
}
|
2021-10-15 16:30:53 +02:00
|
|
|
logger.error("VerificationPanel unhandled phase:", phase);
|
2020-01-24 16:16:46 +00:00
|
|
|
return null;
|
2019-12-16 18:16:22 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private startSAS = async (): Promise<void> => {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ emojiButtonClicked: true });
|
2024-03-25 17:44:45 +00:00
|
|
|
await this.props.request.startVerification(VerificationMethod.Sas);
|
2019-12-16 18:16:22 +01:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onSasMatchesClick = (): void => {
|
2023-03-16 11:07:29 +00:00
|
|
|
this.state.sasEvent?.confirm();
|
2019-12-16 18:16:22 +01:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onSasMismatchesClick = (): void => {
|
2023-03-16 11:07:29 +00:00
|
|
|
this.state.sasEvent?.mismatch();
|
2019-12-16 18:16:22 +01:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private updateVerifierState = (): void => {
|
2023-06-07 14:05:23 +01:00
|
|
|
// this method is only called once we know there is a verifier.
|
|
|
|
|
const verifier = this.props.request.verifier!;
|
|
|
|
|
const sasEvent = verifier.getShowSasCallbacks();
|
|
|
|
|
const reciprocateQREvent = verifier.getReciprocateQrCodeCallbacks();
|
|
|
|
|
verifier.off(VerifierEvent.ShowSas, this.updateVerifierState);
|
|
|
|
|
verifier.off(VerifierEvent.ShowReciprocateQr, this.updateVerifierState);
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ sasEvent, reciprocateQREvent });
|
2019-12-16 18:16:22 +01:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onRequestChange = async (): Promise<void> => {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { request } = this.props;
|
2023-06-23 13:38:06 +01:00
|
|
|
|
|
|
|
|
// if we have a device ID and did not have one before, fetch the device's details
|
|
|
|
|
this.maybeGetOtherDevice();
|
|
|
|
|
|
2023-07-13 14:55:55 +01:00
|
|
|
// if we have had a reply from the other side (ie, the phase is "ready") and we have not
|
|
|
|
|
// yet done so, fetch the QR code
|
|
|
|
|
if (request.phase === Phase.Ready && !this.haveFetchedQRCode) {
|
|
|
|
|
this.haveFetchedQRCode = true;
|
|
|
|
|
request.generateQRCode().then(
|
|
|
|
|
(buf) => {
|
|
|
|
|
this.setState({ qrCodeBytes: buf });
|
|
|
|
|
},
|
|
|
|
|
(error) => {
|
|
|
|
|
console.error("Error generating QR code:", error);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
const hadVerifier = this.hasVerifier;
|
|
|
|
|
this.hasVerifier = !!request.verifier;
|
|
|
|
|
if (!hadVerifier && this.hasVerifier) {
|
2023-05-26 10:29:32 +01:00
|
|
|
request.verifier?.on(VerifierEvent.ShowSas, this.updateVerifierState);
|
|
|
|
|
request.verifier?.on(VerifierEvent.ShowReciprocateQr, this.updateVerifierState);
|
2019-12-18 17:26:54 +00:00
|
|
|
try {
|
2020-07-18 23:51:46 +05:30
|
|
|
// on the requester side, this is also awaited in startSAS,
|
2019-12-19 16:28:23 +00:00
|
|
|
// but that's ok as verify should return the same promise.
|
2023-03-22 12:15:26 +00:00
|
|
|
await request.verifier?.verify();
|
2019-12-18 17:26:54 +00:00
|
|
|
} catch (err) {
|
2021-10-15 16:30:53 +02:00
|
|
|
logger.error("error verify", err);
|
2019-12-18 17:26:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-12-16 18:16:22 +01:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentDidMount(): void {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { request } = this.props;
|
2022-02-22 12:18:08 +00:00
|
|
|
request.on(VerificationRequestEvent.Change, this.onRequestChange);
|
2020-02-13 14:32:33 +01:00
|
|
|
if (request.verifier) {
|
2023-06-07 14:05:23 +01:00
|
|
|
const sasEvent = request.verifier.getShowSasCallbacks();
|
|
|
|
|
const reciprocateQREvent = request.verifier.getReciprocateQrCodeCallbacks();
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ sasEvent, reciprocateQREvent });
|
2020-02-13 14:32:33 +01:00
|
|
|
}
|
2020-07-18 23:51:46 +05:30
|
|
|
this.onRequestChange();
|
2019-12-16 18:16:22 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentWillUnmount(): void {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { request } = this.props;
|
2020-02-24 13:48:41 +01:00
|
|
|
if (request.verifier) {
|
2023-05-26 10:29:32 +01:00
|
|
|
request.verifier.off(VerifierEvent.ShowSas, this.updateVerifierState);
|
|
|
|
|
request.verifier.off(VerifierEvent.ShowReciprocateQr, this.updateVerifierState);
|
2020-02-24 13:48:41 +01:00
|
|
|
}
|
2022-02-22 12:18:08 +00:00
|
|
|
request.off(VerificationRequestEvent.Change, this.onRequestChange);
|
2019-12-16 18:16:22 +01:00
|
|
|
}
|
|
|
|
|
}
|