Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c9de12e

Browse files
authored
Merge pull request #4240 from matrix-org/bwindels/bringbacklegacyverif
Bring back legacy verification by comparing public device keys
2 parents 519c7f9 + 39bd1da commit c9de12e

File tree

3 files changed

+137
-27
lines changed

3 files changed

+137
-27
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Copyright 2016 OpenMarket Ltd
3+
Copyright 2017 Vector Creations Ltd
4+
Copyright 2019 New Vector Ltd
5+
Copyright 2019 Michael Telatynski <[email protected]>
6+
Copyright 2020 The Matrix.org Foundation C.I.C.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
*/
20+
21+
import React from 'react';
22+
import PropTypes from 'prop-types';
23+
import {MatrixClientPeg} from '../../../MatrixClientPeg';
24+
import * as sdk from '../../../index';
25+
import * as FormattingUtils from '../../../utils/FormattingUtils';
26+
import { _t } from '../../../languageHandler';
27+
28+
export default class ManualDeviceKeyVerificationDialog extends React.Component {
29+
static propTypes = {
30+
userId: PropTypes.string.isRequired,
31+
device: PropTypes.object.isRequired,
32+
onFinished: PropTypes.func.isRequired,
33+
};
34+
35+
_onCancelClick = () => {
36+
this.props.onFinished(false);
37+
}
38+
39+
_onLegacyFinished = (confirm) => {
40+
if (confirm) {
41+
MatrixClientPeg.get().setDeviceVerified(
42+
this.props.userId, this.props.device.deviceId, true,
43+
);
44+
}
45+
this.props.onFinished(confirm);
46+
}
47+
48+
render() {
49+
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
50+
51+
let text;
52+
if (MatrixClientPeg.get().getUserId() === this.props.userId) {
53+
text = _t("Confirm by comparing the following with the User Settings in your other session:");
54+
} else {
55+
text = _t("Confirm this user's session by comparing the following with their User Settings:");
56+
}
57+
58+
const key = FormattingUtils.formatCryptoKey(this.props.device.getFingerprint());
59+
const body = (
60+
<div>
61+
<p>
62+
{ text }
63+
</p>
64+
<div className="mx_DeviceVerifyDialog_cryptoSection">
65+
<ul>
66+
<li><label>{ _t("Session name") }:</label> <span>{ this.props.device.getDisplayName() }</span></li>
67+
<li><label>{ _t("Session ID") }:</label> <span><code>{ this.props.device.deviceId }</code></span></li>
68+
<li><label>{ _t("Session key") }:</label> <span><code><b>{ key }</b></code></span></li>
69+
</ul>
70+
</div>
71+
<p>
72+
{ _t("If they don't match, the security of your communication may be compromised.") }
73+
</p>
74+
</div>
75+
);
76+
77+
return (
78+
<QuestionDialog
79+
title={_t("Verify session")}
80+
description={body}
81+
button={_t("Verify session")}
82+
onFinished={this._onLegacyFinished}
83+
/>
84+
);
85+
}
86+
}

src/i18n/strings/en_EN.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@
294294
"Not Trusted": "Not Trusted",
295295
"%(name)s (%(userId)s) signed in to a new session without verifying it:": "%(name)s (%(userId)s) signed in to a new session without verifying it:",
296296
"Ask this user to verify their session, or manually verify it below.": "Ask this user to verify their session, or manually verify it below.",
297+
"Manually Verify by Text": "Manually Verify by Text",
298+
"Interactively verify by Emoji": "Interactively verify by Emoji",
297299
"Done": "Done",
298-
"Manually Verify": "Manually Verify",
299300
"%(displayName)s is typing …": "%(displayName)s is typing …",
300301
"%(names)s and %(count)s others are typing …|other": "%(names)s and %(count)s others are typing …",
301302
"%(names)s and %(count)s others are typing …|one": "%(names)s and one other is typing …",
@@ -1613,6 +1614,9 @@
16131614
"Manually export keys": "Manually export keys",
16141615
"You'll lose access to your encrypted messages": "You'll lose access to your encrypted messages",
16151616
"Are you sure you want to sign out?": "Are you sure you want to sign out?",
1617+
"Confirm by comparing the following with the User Settings in your other session:": "Confirm by comparing the following with the User Settings in your other session:",
1618+
"Confirm this user's session by comparing the following with their User Settings:": "Confirm this user's session by comparing the following with their User Settings:",
1619+
"If they don't match, the security of your communication may be compromised.": "If they don't match, the security of your communication may be compromised.",
16161620
"Your homeserver doesn't seem to support this feature.": "Your homeserver doesn't seem to support this feature.",
16171621
"Message edits": "Message edits",
16181622
"Your account is not secure": "Your account is not secure",

src/verification.js

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,58 @@ async function enable4SIfNeeded() {
3939
return true;
4040
}
4141

42+
function UntrustedDeviceDialog(props) {
43+
const {device, user, onFinished} = props;
44+
const BaseDialog = sdk.getComponent("dialogs.BaseDialog");
45+
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
46+
return <BaseDialog
47+
onFinished={onFinished}
48+
headerImage={require("../res/img/e2e/warning.svg")}
49+
title={_t("Not Trusted")}>
50+
<div className="mx_Dialog_content" id='mx_Dialog_content'>
51+
<p>{_t("%(name)s (%(userId)s) signed in to a new session without verifying it:", {name: user.displayName, userId: user.userId})}</p>
52+
<p>{device.getDisplayName()} ({device.deviceId})</p>
53+
<p>{_t("Ask this user to verify their session, or manually verify it below.")}</p>
54+
</div>
55+
<div className='mx_Dialog_buttons'>
56+
<AccessibleButton element="button" kind="secondary" onClick={() => onFinished("legacy")}>{_t("Manually Verify by Text")}</AccessibleButton>
57+
<AccessibleButton element="button" kind="secondary" onClick={() => onFinished("sas")}>{_t("Interactively verify by Emoji")}</AccessibleButton>
58+
<AccessibleButton kind="primary" onClick={() => onFinished()}>{_t("Done")}</AccessibleButton>
59+
</div>
60+
</BaseDialog>;
61+
}
62+
4263
export async function verifyDevice(user, device) {
4364
if (!await enable4SIfNeeded()) {
4465
return;
4566
}
46-
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
47-
Modal.createTrackedDialog("Verification warning", "unverified session", QuestionDialog, {
48-
headerImage: require("../res/img/e2e/warning.svg"),
49-
title: _t("Not Trusted"),
50-
description: <div>
51-
<p>{_t("%(name)s (%(userId)s) signed in to a new session without verifying it:", {name: user.displayName, userId: user.userId})}</p>
52-
<p>{device.getDisplayName()} ({device.deviceId})</p>
53-
<p>{_t("Ask this user to verify their session, or manually verify it below.")}</p>
54-
</div>,
55-
onFinished: async (doneClicked) => {
56-
const manuallyVerifyClicked = !doneClicked;
57-
if (!manuallyVerifyClicked) {
58-
return;
67+
Modal.createTrackedDialog("Verification warning", "unverified session", UntrustedDeviceDialog, {
68+
user,
69+
device,
70+
onFinished: async (action) => {
71+
if (action === "sas") {
72+
const cli = MatrixClientPeg.get();
73+
const verificationRequestPromise = cli.legacyDeviceVerification(
74+
user.userId,
75+
device.deviceId,
76+
verificationMethods.SAS,
77+
);
78+
dis.dispatch({
79+
action: "set_right_panel_phase",
80+
phase: RIGHT_PANEL_PHASES.EncryptionPanel,
81+
refireParams: {member: user, verificationRequestPromise},
82+
});
83+
} else if (action === "legacy") {
84+
const ManualDeviceKeyVerificationDialog = sdk.getComponent("dialogs.ManualDeviceKeyVerificationDialog");
85+
Modal.createTrackedDialog("Legacy verify session", "legacy verify session",
86+
ManualDeviceKeyVerificationDialog,
87+
{
88+
userId: user.userId,
89+
device,
90+
},
91+
);
5992
}
60-
const cli = MatrixClientPeg.get();
61-
const verificationRequestPromise = cli.legacyDeviceVerification(
62-
user.userId,
63-
device.deviceId,
64-
verificationMethods.SAS,
65-
);
66-
dis.dispatch({
67-
action: "set_right_panel_phase",
68-
phase: RIGHT_PANEL_PHASES.EncryptionPanel,
69-
refireParams: {member: user, verificationRequestPromise},
70-
});
7193
},
72-
primaryButton: _t("Done"),
73-
cancelButton: _t("Manually Verify"),
7494
});
7595
}
7696

0 commit comments

Comments
 (0)