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";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { verificationMethods } from "matrix-js-sdk/src/crypto";
|
2022-02-22 12:18:08 +00:00
|
|
|
import { QrCodeEvent, ReciprocateQRCode, SCAN_QR_CODE_METHOD } from "matrix-js-sdk/src/crypto/verification/QRCode";
|
|
|
|
|
import {
|
|
|
|
|
Phase,
|
|
|
|
|
VerificationRequest,
|
|
|
|
|
VerificationRequestEvent,
|
|
|
|
|
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
2021-06-17 14:06:03 +01:00
|
|
|
import { User } from "matrix-js-sdk/src/models/user";
|
2022-02-22 12:18:08 +00:00
|
|
|
import { SAS, SasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
|
2021-10-22 17:23:32 -05:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
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";
|
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;
|
2021-09-08 12:34:44 +01:00
|
|
|
phase: Phase;
|
2020-07-18 23:51:46 +05:30
|
|
|
onClose: () => void;
|
|
|
|
|
isRoomEncrypted: boolean;
|
|
|
|
|
inDialog: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
2021-09-08 12:34:44 +01:00
|
|
|
sasEvent?: SAS["sasEvent"];
|
2020-07-18 23:51:46 +05:30
|
|
|
emojiButtonClicked?: boolean;
|
|
|
|
|
reciprocateButtonClicked?: boolean;
|
2021-09-08 12:34:44 +01:00
|
|
|
reciprocateQREvent?: ReciprocateQRCode["reciprocateQREvent"];
|
2020-07-18 23:51:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default class VerificationPanel extends React.PureComponent<IProps, IState> {
|
|
|
|
|
private hasVerifier: boolean;
|
|
|
|
|
|
|
|
|
|
constructor(props: IProps) {
|
2019-12-16 18:16:22 +01:00
|
|
|
super(props);
|
2020-03-31 15:46:11 +02:00
|
|
|
this.state = {};
|
2020-07-18 23:51:46 +05:30
|
|
|
this.hasVerifier = false;
|
2019-12-16 18:16:22 +01:00
|
|
|
}
|
|
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
private renderQRPhase() {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { member, request } = this.props;
|
2020-07-18 23:51:46 +05:30
|
|
|
const showSAS: boolean = request.otherPartySupportsMethod(verificationMethods.SAS);
|
|
|
|
|
const showQR: boolean = request.otherPartySupportsMethod(SCAN_QR_CODE_METHOD);
|
2020-07-10 19:07:11 +01:00
|
|
|
const brand = SdkConfig.get().brand;
|
2020-01-24 16:41:43 +00:00
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
const noCommonMethodError: JSX.Element =
|
|
|
|
|
!showSAS && !showQR ? (
|
2021-07-19 22:43:11 +01:00
|
|
|
<p>
|
|
|
|
|
{_t(
|
2022-01-06 16:57:49 -05:00
|
|
|
"The device you are trying to verify doesn't support scanning a " +
|
2020-07-10 19:07:11 +01:00
|
|
|
"QR code or emoji verification, which is what %(brand)s supports. Try " +
|
|
|
|
|
"with a different client.",
|
|
|
|
|
{ brand },
|
2021-07-19 22:43:11 +01:00
|
|
|
)}
|
|
|
|
|
</p>
|
2020-02-14 13:48:18 +01:00
|
|
|
) : null;
|
|
|
|
|
|
2020-01-31 15:04:44 +00:00
|
|
|
if (this.props.layout === "dialog") {
|
|
|
|
|
// HACK: This is a terrible idea.
|
2020-07-18 23:52:41 +05:30
|
|
|
let qrBlockDialog: JSX.Element;
|
|
|
|
|
let sasBlockDialog: JSX.Element;
|
2020-02-14 13:48:18 +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">
|
2021-07-19 22:43:11 +01:00
|
|
|
<p>{_t("Scan this unique code")}</p>
|
2020-03-31 15:46:11 +02:00
|
|
|
<VerificationQRCode qrCodeData={request.qrCodeData} />
|
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">
|
2021-07-19 22:43:11 +01:00
|
|
|
<p>{_t("Compare unique emoji")}</p>
|
2020-08-29 01:11:08 +01:00
|
|
|
<span className="mx_VerificationPanel_QRPhase_helpText">
|
2021-07-19 22:43:11 +01:00
|
|
|
{_t("Compare a unique set of emoji if you don't have a camera on either device")}
|
2020-08-29 01:11:08 +01:00
|
|
|
</span>
|
|
|
|
|
<AccessibleButton
|
|
|
|
|
disabled={this.state.emojiButtonClicked}
|
|
|
|
|
onClick={this.startSAS}
|
|
|
|
|
kind="primary"
|
|
|
|
|
>
|
2021-07-19 22:43:11 +01:00
|
|
|
{_t("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">
|
|
|
|
|
{_t("%(qrCode)s or %(emojiCompare)s", {
|
|
|
|
|
emojiCompare: "",
|
|
|
|
|
qrCode: "",
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
) : null;
|
2020-01-31 15:04:44 +00:00
|
|
|
return (
|
|
|
|
|
<div>
|
2022-01-06 16:57:49 -05:00
|
|
|
{_t("Verify this device by completing one of the following:")}
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
let qrBlock: JSX.Element;
|
2020-03-31 15:46:11 +02:00
|
|
|
if (showQR) {
|
2020-02-14 13:48:18 +01:00
|
|
|
qrBlock = (
|
|
|
|
|
<div className="mx_UserInfo_container">
|
2021-07-19 22:43:11 +01:00
|
|
|
<h3>{_t("Verify by scanning")}</h3>
|
|
|
|
|
<p>
|
|
|
|
|
{_t("Ask %(displayName)s to scan your code:", {
|
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">
|
2020-03-31 15:46:11 +02:00
|
|
|
<VerificationQRCode qrCodeData={request.qrCodeData} />
|
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
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
let sasBlock: JSX.Element;
|
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
|
2020-02-14 13:48:18 +01:00
|
|
|
? _t("If you can't scan the code above, verify by comparing unique emoji.")
|
|
|
|
|
: _t("Verify by comparing unique emoji.");
|
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">
|
2021-07-19 22:43:11 +01:00
|
|
|
<h3>{_t("Verify by emoji")}</h3>
|
|
|
|
|
<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
|
|
|
>
|
2021-07-19 22:43:11 +01:00
|
|
|
{_t("Verify by 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
|
|
|
}
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
private onReciprocateYesClick = () => {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ reciprocateButtonClicked: true });
|
2020-04-02 13:00:45 +02:00
|
|
|
this.state.reciprocateQREvent.confirm();
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
private onReciprocateNoClick = () => {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ reciprocateButtonClicked: true });
|
2020-04-02 13:00:45 +02:00
|
|
|
this.state.reciprocateQREvent.cancel();
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
private getDevice() {
|
2020-05-12 11:05:30 +01:00
|
|
|
const deviceId = this.props.request && this.props.request.channel.deviceId;
|
|
|
|
|
return MatrixClientPeg.get().getStoredDevice(MatrixClientPeg.get().getUserId(), deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
private renderQRReciprocatePhase() {
|
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
|
2022-01-06 16:57:49 -05:00
|
|
|
? _t("Almost there! Is your other device showing the same shield?")
|
2020-04-02 16:42:39 +02:00
|
|
|
: _t("Almost there! Is %(displayName)s showing the same shield?", {
|
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}
|
|
|
|
|
>
|
|
|
|
|
{_t("No")}
|
|
|
|
|
</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}
|
|
|
|
|
>
|
|
|
|
|
{_t("Yes")}
|
|
|
|
|
</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">
|
2021-07-19 22:43:11 +01:00
|
|
|
<h3>{_t("Verify by scanning")}</h3>
|
2020-03-31 15:46:41 +02:00
|
|
|
{body}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
private renderVerifiedPhase() {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { member, request } = this.props;
|
2019-12-16 18:16:22 +01:00
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
let text: string;
|
2020-04-03 17:04:29 +02:00
|
|
|
if (!request.isSelfVerification) {
|
|
|
|
|
if (this.props.isRoomEncrypted) {
|
|
|
|
|
text = _t("Verify all users in a room to ensure it's secure.");
|
|
|
|
|
} else {
|
2021-10-29 21:59:21 -04:00
|
|
|
text = _t("In encrypted rooms, verify all users to ensure it's secure.");
|
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) {
|
2020-07-18 23:51:46 +05:30
|
|
|
const device = this.getDevice();
|
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.
|
2021-10-15 16:31:29 +02:00
|
|
|
logger.warn("Verified device we don't know about: " + this.props.request.channel.deviceId);
|
2020-05-12 12:42:16 +01:00
|
|
|
description = _t("You've successfully verified your device!");
|
|
|
|
|
} else {
|
|
|
|
|
description = _t("You've successfully verified %(deviceName)s (%(deviceId)s)!", {
|
|
|
|
|
deviceName: device ? device.getDisplayName() : "",
|
|
|
|
|
deviceId: this.props.request.channel.deviceId,
|
|
|
|
|
});
|
2020-05-12 11:05:30 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
description = _t("You've successfully verified %(displayName)s!", {
|
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}>
|
2021-07-19 22:43:11 +01:00
|
|
|
{_t("Got it")}
|
2020-01-28 11:13:09 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
private renderCancelledPhase() {
|
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) {
|
|
|
|
|
startAgainInstruction = _t("Start verification again from the notification.");
|
|
|
|
|
} else {
|
|
|
|
|
startAgainInstruction = _t("Start verification again from their profile.");
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
let text: string;
|
2020-01-28 11:13:09 +00:00
|
|
|
if (request.cancellationCode === "m.timeout") {
|
2020-04-03 17:04:29 +02:00
|
|
|
text = _t("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) {
|
2022-01-06 16:57:49 -05:00
|
|
|
text = _t("You cancelled verification on your other device.");
|
2020-04-03 17:04:29 +02:00
|
|
|
} else {
|
|
|
|
|
text = _t("%(displayName)s cancelled verification.", {
|
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 {
|
2020-04-03 17:04:29 +02:00
|
|
|
text = _t("You cancelled verification.") + ` ${startAgainInstruction}`;
|
2020-01-28 11:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_UserInfo_container">
|
2021-07-19 22:43:11 +01:00
|
|
|
<h3>{_t("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}>
|
2021-07-19 22:43:11 +01:00
|
|
|
{_t("Got it")}
|
2020-01-24 16:16:46 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
public render() {
|
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) {
|
|
|
|
|
case verificationMethods.RECIPROCATE_QR_CODE:
|
|
|
|
|
return this.renderQRReciprocatePhase();
|
|
|
|
|
case verificationMethods.SAS: {
|
|
|
|
|
const emojis = this.state.sasEvent ? (
|
|
|
|
|
<VerificationShowSas
|
|
|
|
|
displayName={displayName}
|
2020-07-18 23:51:46 +05:30
|
|
|
device={this.getDevice()}
|
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
|
|
|
}
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
private startSAS = async () => {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ emojiButtonClicked: true });
|
2019-12-16 18:16:22 +01:00
|
|
|
const verifier = this.props.request.beginKeyVerification(verificationMethods.SAS);
|
|
|
|
|
try {
|
2019-12-18 17:26:54 +00:00
|
|
|
await verifier.verify();
|
2019-12-19 16:08:53 +00:00
|
|
|
} catch (err) {
|
2021-10-15 16:30:53 +02:00
|
|
|
logger.error(err);
|
2019-12-16 18:16:22 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
private onSasMatchesClick = () => {
|
2019-12-16 18:16:22 +01:00
|
|
|
this.state.sasEvent.confirm();
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
private onSasMismatchesClick = () => {
|
2020-01-28 11:13:09 +00:00
|
|
|
this.state.sasEvent.mismatch();
|
2019-12-16 18:16:22 +01:00
|
|
|
};
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
private updateVerifierState = () => {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { request } = this.props;
|
2021-09-08 12:34:44 +01:00
|
|
|
const sasEvent = (request.verifier as SAS).sasEvent;
|
|
|
|
|
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
|
2022-02-22 12:18:08 +00:00
|
|
|
request.verifier.off(SasEvent.ShowSas, this.updateVerifierState);
|
|
|
|
|
request.verifier.off(QrCodeEvent.ShowReciprocateQr, this.updateVerifierState);
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ sasEvent, reciprocateQREvent });
|
2019-12-16 18:16:22 +01:00
|
|
|
};
|
|
|
|
|
|
2020-07-18 23:51:46 +05:30
|
|
|
private onRequestChange = async () => {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { request } = this.props;
|
2020-07-18 23:51:46 +05:30
|
|
|
const hadVerifier = this.hasVerifier;
|
|
|
|
|
this.hasVerifier = !!request.verifier;
|
|
|
|
|
if (!hadVerifier && this.hasVerifier) {
|
2022-02-22 12:18:08 +00:00
|
|
|
request.verifier.on(SasEvent.ShowSas, this.updateVerifierState);
|
|
|
|
|
request.verifier.on(QrCodeEvent.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.
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
public componentDidMount() {
|
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) {
|
2021-09-08 12:34:44 +01:00
|
|
|
const sasEvent = (request.verifier as SAS).sasEvent;
|
|
|
|
|
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
|
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
|
|
|
}
|
|
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
public componentWillUnmount() {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { request } = this.props;
|
2020-02-24 13:48:41 +01:00
|
|
|
if (request.verifier) {
|
2022-02-22 12:18:08 +00:00
|
|
|
request.verifier.off(SasEvent.ShowSas, this.updateVerifierState);
|
|
|
|
|
request.verifier.off(QrCodeEvent.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
|
|
|
}
|
|
|
|
|
}
|