2019-12-10 19:53:51 +03:00
|
|
|
|
/*
|
2020-01-24 14:45:39 +03:00
|
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
2019-12-10 19:53:51 +03: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-24 19:16:46 +03:00
|
|
|
|
import React, {useCallback, useEffect, useState} from 'react';
|
|
|
|
|
|
2019-12-16 20:16:22 +03:00
|
|
|
|
import EncryptionInfo from "./EncryptionInfo";
|
|
|
|
|
import VerificationPanel from "./VerificationPanel";
|
2020-01-17 17:50:27 +03:00
|
|
|
|
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
2019-12-19 19:43:10 +03:00
|
|
|
|
import {ensureDMExists} from "../../../createRoom";
|
2020-01-24 19:16:46 +03:00
|
|
|
|
import {useEventEmitter} from "../../../hooks/useEventEmitter";
|
2020-01-28 14:13:09 +03:00
|
|
|
|
import Modal from "../../../Modal";
|
|
|
|
|
import {PHASE_REQUESTED} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
|
|
|
|
import * as sdk from "../../../index";
|
|
|
|
|
import {_t} from "../../../languageHandler";
|
2020-01-24 19:16:46 +03:00
|
|
|
|
|
2020-01-28 14:13:09 +03:00
|
|
|
|
// cancellation codes which constitute a key mismatch
|
|
|
|
|
const MISMATCHES = ["m.key_mismatch", "m.user_error", "m.mismatched_sas"];
|
|
|
|
|
|
|
|
|
|
const EncryptionPanel = ({verificationRequest, member, onClose}) => {
|
2020-01-24 19:16:46 +03:00
|
|
|
|
const [request, setRequest] = useState(verificationRequest);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setRequest(verificationRequest);
|
|
|
|
|
}, [verificationRequest]);
|
|
|
|
|
|
2020-01-28 14:13:09 +03:00
|
|
|
|
const [phase, setPhase] = useState(false);
|
2020-01-24 19:16:46 +03:00
|
|
|
|
const changeHandler = useCallback(() => {
|
2020-01-28 14:13:09 +03:00
|
|
|
|
// handle transitions -> cancelled for mismatches which fire a modal instead of showing a card
|
|
|
|
|
if (request && request.cancelled && MISMATCHES.includes(request.cancellationCode)) {
|
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
|
Modal.createTrackedDialog("Verification failed", "insecure", ErrorDialog, {
|
|
|
|
|
headerImage: require("../../../../res/img/e2e/warning.svg"),
|
|
|
|
|
title: _t("Your messages are not secure"),
|
|
|
|
|
description: <div>
|
|
|
|
|
{_t("One of the following may be compromised:")}
|
|
|
|
|
<ul>
|
|
|
|
|
<li>{_t("Your homeserver")}</li>
|
|
|
|
|
<li>{_t("The homeserver the user you’re verifying is connected to")}</li>
|
|
|
|
|
<li>{_t("Yours, or the other users’ internet connection")}</li>
|
|
|
|
|
<li>{_t("Yours, or the other users’ device")}</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>,
|
|
|
|
|
onFinished: onClose,
|
|
|
|
|
});
|
|
|
|
|
return; // don't update phase here as we will be transitioning away from this view shortly
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request) {
|
|
|
|
|
setPhase(request.phase);
|
|
|
|
|
}
|
|
|
|
|
}, [onClose, request]);
|
2020-01-24 19:16:46 +03:00
|
|
|
|
useEventEmitter(request, "change", changeHandler);
|
|
|
|
|
|
|
|
|
|
const onStartVerification = useCallback(async () => {
|
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
const roomId = await ensureDMExists(cli, member.userId);
|
|
|
|
|
const verificationRequest = await cli.requestVerificationDM(member.userId, roomId);
|
|
|
|
|
setRequest(verificationRequest);
|
|
|
|
|
}, [member.userId]);
|
|
|
|
|
|
2020-01-28 14:13:09 +03:00
|
|
|
|
const requested = request && phase === PHASE_REQUESTED;
|
|
|
|
|
if (!request || requested) {
|
|
|
|
|
return <EncryptionInfo onStartVerification={onStartVerification} member={member} pending={requested} />;
|
2020-01-24 19:16:46 +03:00
|
|
|
|
} else {
|
2020-01-28 14:13:09 +03:00
|
|
|
|
return (
|
|
|
|
|
<VerificationPanel
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
member={member}
|
|
|
|
|
request={request}
|
|
|
|
|
key={request.channel.transactionId}
|
|
|
|
|
phase={phase} />
|
|
|
|
|
);
|
2019-12-19 19:08:53 +03:00
|
|
|
|
}
|
2020-01-24 19:16:46 +03:00
|
|
|
|
};
|
|
|
|
|
EncryptionPanel.propTypes = {
|
2019-12-19 19:08:53 +03:00
|
|
|
|
|
2020-01-24 19:16:46 +03:00
|
|
|
|
};
|
2019-12-16 20:16:22 +03:00
|
|
|
|
|
2020-01-24 19:16:46 +03:00
|
|
|
|
export default EncryptionPanel;
|