/* Copyright 2019, 2020 The Matrix.org Foundation C.I.C. 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. */ import React from 'react'; import * as sdk from '../../../index'; import {verificationMethods} from 'matrix-js-sdk/src/crypto'; import VerificationQRCode from "../elements/crypto/VerificationQRCode"; import {MatrixClientPeg} from "../../../MatrixClientPeg"; import {_t} from "../../../languageHandler"; import E2EIcon from "../rooms/E2EIcon"; export default class VerificationPanel extends React.PureComponent { constructor(props) { super(props); this.state = {}; this._hasVerifier = !!props.request.verifier; } renderQRPhase() { const {member, request} = this.props; // type req: VerificationRequest // TODO change the button into a spinner when on click const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); const cli = MatrixClientPeg.get(); const crossSigningInfo = cli.getStoredCrossSigningForUser(request.otherUserId); if (!crossSigningInfo || !request.requestEvent || !request.requestEvent.getId()) { // TODO handle this error case return
request.requestEvent.getId()
; } const myKeyId = cli.getCrossSigningId(); const qrCodeKeys = [ [cli.getDeviceId(), cli.getDeviceEd25519Key()], [myKeyId, myKeyId], ]; return{_t("Ask %(displayName)s to scan your code, or open your camera to scan theirs:", { displayName: member.displayName || member.name || member.userId, }, { a: t => { t }, })}
{_t("If you can't scan the code above, verify by comparing unique emoji.")}
{_t("You've successfully verified %(displayName)s!", { displayName: member.displayName || member.name || member.userId, })}
Verify all users in a room to ensure it's secure.
Setting up SAS verification...
); } } else if (request.done) { return this.renderVerifiedPhase(); } else if (request.cancelled) { // TODO check if this matches target // TODO should this be a MODAL? returncancelled by {request.cancellingUserId}!
; } return null; } _startSAS = async () => { const verifier = this.props.request.beginKeyVerification(verificationMethods.SAS); try { await verifier.verify(); } catch (err) { console.error(err); } finally { this.setState({sasEvent: null}); } }; _onSasMatchesClick = () => { this.state.sasEvent.confirm(); }; _onSasMismatchesClick = () => { this.state.sasEvent.cancel(); }; _onVerifierShowSas = (sasEvent) => { this.setState({sasEvent}); }; _onRequestChange = async () => { const {request} = this.props; if (!this._hasVerifier && !!request.verifier) { request.verifier.on('show_sas', this._onVerifierShowSas); try { // on the requester side, this is also awaited in _startSAS, // but that's ok as verify should return the same promise. await request.verifier.verify(); } catch (err) { console.error("error verify", err); } } else if (this._hasVerifier && !request.verifier) { request.verifier.removeListener('show_sas', this._onVerifierShowSas); } this._hasVerifier = !!request.verifier; this.forceUpdate(); // TODO fix this }; componentDidMount() { this.props.request.on("change", this._onRequestChange); } componentWillUnmount() { this.props.request.off("change", this._onRequestChange); } }