2020-03-10 18:31:40 +03:00
|
|
|
/*
|
|
|
|
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 {MatrixClientPeg} from './MatrixClientPeg';
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from "./dispatcher/dispatcher";
|
2020-03-10 18:31:40 +03:00
|
|
|
import Modal from './Modal';
|
|
|
|
import * as sdk from './index';
|
|
|
|
import { _t } from './languageHandler';
|
|
|
|
import {RIGHT_PANEL_PHASES} from "./stores/RightPanelStorePhases";
|
|
|
|
import {findDMForUser} from './createRoom';
|
|
|
|
import {accessSecretStorage} from './CrossSigningManager';
|
2020-03-11 17:52:48 +03:00
|
|
|
import {verificationMethods} from 'matrix-js-sdk/src/crypto';
|
2020-03-10 18:31:40 +03:00
|
|
|
|
2020-03-11 12:11:54 +03:00
|
|
|
async function enable4SIfNeeded() {
|
2020-03-10 18:31:40 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2020-05-27 12:28:25 +03:00
|
|
|
if (!cli.isCryptoEnabled()) {
|
2020-03-10 18:31:40 +03:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-10 20:40:24 +03:00
|
|
|
const usk = cli.getCrossSigningId("user_signing");
|
|
|
|
if (!usk) {
|
2020-03-10 18:31:40 +03:00
|
|
|
await accessSecretStorage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:31:23 +03:00
|
|
|
function UntrustedDeviceDialog(props) {
|
|
|
|
const {device, user, onFinished} = props;
|
|
|
|
const BaseDialog = sdk.getComponent("dialogs.BaseDialog");
|
|
|
|
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
|
2020-05-05 11:23:39 +03:00
|
|
|
let askToVerifyText;
|
|
|
|
let newSessionText;
|
|
|
|
|
|
|
|
if (MatrixClientPeg.get().getUserId() === user.userId) {
|
|
|
|
newSessionText = _t("You signed in to a new session without verifying it:");
|
|
|
|
askToVerifyText = _t("Verify your other session using one of the options below.");
|
|
|
|
} else {
|
|
|
|
newSessionText = _t("%(name)s (%(userId)s) signed in to a new session without verifying it:",
|
|
|
|
{name: user.displayName, userId: user.userId});
|
|
|
|
askToVerifyText = _t("Ask this user to verify their session, or manually verify it below.");
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:31:23 +03:00
|
|
|
return <BaseDialog
|
|
|
|
onFinished={onFinished}
|
|
|
|
headerImage={require("../res/img/e2e/warning.svg")}
|
|
|
|
title={_t("Not Trusted")}>
|
|
|
|
<div className="mx_Dialog_content" id='mx_Dialog_content'>
|
2020-05-05 11:23:39 +03:00
|
|
|
<p>{newSessionText}</p>
|
2020-03-19 18:31:23 +03:00
|
|
|
<p>{device.getDisplayName()} ({device.deviceId})</p>
|
2020-05-05 11:23:39 +03:00
|
|
|
<p>{askToVerifyText}</p>
|
2020-03-19 18:31:23 +03:00
|
|
|
</div>
|
|
|
|
<div className='mx_Dialog_buttons'>
|
2020-03-20 17:30:17 +03:00
|
|
|
<AccessibleButton element="button" kind="secondary" onClick={() => onFinished("legacy")}>{_t("Manually Verify by Text")}</AccessibleButton>
|
|
|
|
<AccessibleButton element="button" kind="secondary" onClick={() => onFinished("sas")}>{_t("Interactively verify by Emoji")}</AccessibleButton>
|
2020-03-19 18:31:23 +03:00
|
|
|
<AccessibleButton kind="primary" onClick={() => onFinished()}>{_t("Done")}</AccessibleButton>
|
|
|
|
</div>
|
|
|
|
</BaseDialog>;
|
|
|
|
}
|
|
|
|
|
2020-03-10 18:31:40 +03:00
|
|
|
export async function verifyDevice(user, device) {
|
2020-04-14 18:53:33 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
// if cross-signing is not explicitly disabled, check if it should be enabled first.
|
|
|
|
if (cli.getCryptoTrustCrossSignedDevices()) {
|
|
|
|
if (!await enable4SIfNeeded()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-10 18:31:40 +03:00
|
|
|
}
|
2020-04-27 22:31:14 +03:00
|
|
|
|
2020-04-28 20:35:16 +03:00
|
|
|
Modal.createTrackedDialog("Verification warning", "unverified session", UntrustedDeviceDialog, {
|
|
|
|
user,
|
|
|
|
device,
|
|
|
|
onFinished: async (action) => {
|
|
|
|
if (action === "sas") {
|
|
|
|
const verificationRequestPromise = cli.legacyDeviceVerification(
|
|
|
|
user.userId,
|
|
|
|
device.deviceId,
|
|
|
|
verificationMethods.SAS,
|
|
|
|
);
|
|
|
|
dis.dispatch({
|
|
|
|
action: "set_right_panel_phase",
|
|
|
|
phase: RIGHT_PANEL_PHASES.EncryptionPanel,
|
|
|
|
refireParams: {member: user, verificationRequestPromise},
|
|
|
|
});
|
|
|
|
} else if (action === "legacy") {
|
|
|
|
const ManualDeviceKeyVerificationDialog =
|
|
|
|
sdk.getComponent("dialogs.ManualDeviceKeyVerificationDialog");
|
|
|
|
Modal.createTrackedDialog("Legacy verify session", "legacy verify session",
|
|
|
|
ManualDeviceKeyVerificationDialog,
|
|
|
|
{
|
|
|
|
userId: user.userId,
|
|
|
|
device,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2020-03-10 18:31:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function legacyVerifyUser(user) {
|
|
|
|
const cli = MatrixClientPeg.get();
|
2020-04-14 18:53:33 +03:00
|
|
|
// if cross-signing is not explicitly disabled, check if it should be enabled first.
|
|
|
|
if (cli.getCryptoTrustCrossSignedDevices()) {
|
|
|
|
if (!await enable4SIfNeeded()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-04-01 11:32:27 +03:00
|
|
|
const verificationRequestPromise = cli.requestVerification(user.userId);
|
2020-03-10 18:31:40 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: "set_right_panel_phase",
|
|
|
|
phase: RIGHT_PANEL_PHASES.EncryptionPanel,
|
|
|
|
refireParams: {member: user, verificationRequestPromise},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function verifyUser(user) {
|
|
|
|
if (!await enable4SIfNeeded()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-26 19:31:31 +03:00
|
|
|
const existingRequest = pendingVerificationRequestForUser(user);
|
2020-03-10 18:31:40 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: "set_right_panel_phase",
|
|
|
|
phase: RIGHT_PANEL_PHASES.EncryptionPanel,
|
|
|
|
refireParams: {
|
|
|
|
member: user,
|
|
|
|
verificationRequest: existingRequest,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-03-26 19:31:31 +03:00
|
|
|
|
|
|
|
export function pendingVerificationRequestForUser(user) {
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const dmRoom = findDMForUser(cli, user.userId);
|
|
|
|
if (dmRoom) {
|
|
|
|
return cli.findVerificationRequestDMInProgress(dmRoom.roomId);
|
|
|
|
}
|
|
|
|
}
|