2019-11-28 16:45:29 +00:00
|
|
|
/*
|
2020-01-20 20:35:21 +00:00
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
2019-11-28 16:45:29 +00: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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2022-03-01 20:42:05 +00:00
|
|
|
import { ClientEvent, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
2021-12-09 09:10:23 +00:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2022-02-22 12:18:08 +00:00
|
|
|
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
2019-11-28 16:45:29 +00:00
|
|
|
|
2021-06-29 13:11:58 +01:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2019-11-28 16:45:29 +00:00
|
|
|
import { _t } from "../../../languageHandler";
|
2020-02-07 14:55:01 +00:00
|
|
|
import Modal from "../../../Modal";
|
2020-09-03 16:47:56 +01:00
|
|
|
import Spinner from "../elements/Spinner";
|
2020-09-08 18:01:56 +01:00
|
|
|
import InteractiveAuthDialog from "../dialogs/InteractiveAuthDialog";
|
2020-09-10 13:56:07 +01:00
|
|
|
import ConfirmDestroyCrossSigningDialog from "../dialogs/security/ConfirmDestroyCrossSigningDialog";
|
2021-08-18 19:22:42 +01:00
|
|
|
import SetupEncryptionDialog from "../dialogs/security/SetupEncryptionDialog";
|
|
|
|
|
import { accessSecretStorage } from "../../../SecurityManager";
|
2021-11-08 11:27:52 +01:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2021-10-15 16:30:53 +02:00
|
|
|
|
2021-08-13 18:07:58 +01:00
|
|
|
interface IState {
|
|
|
|
|
error?: Error;
|
|
|
|
|
crossSigningPublicKeysOnDevice?: boolean;
|
|
|
|
|
crossSigningPrivateKeysInStorage?: boolean;
|
|
|
|
|
masterPrivateKeyCached?: boolean;
|
|
|
|
|
selfSigningPrivateKeyCached?: boolean;
|
|
|
|
|
userSigningPrivateKeyCached?: boolean;
|
|
|
|
|
homeserverSupportsCrossSigning?: boolean;
|
|
|
|
|
crossSigningReady?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default class CrossSigningPanel extends React.PureComponent<{}, IState> {
|
|
|
|
|
private unmounted = false;
|
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(props) {
|
2019-11-28 16:45:29 +00:00
|
|
|
super(props);
|
2019-12-05 15:05:28 +00:00
|
|
|
|
2021-08-13 18:07:58 +01:00
|
|
|
this.state = {};
|
2019-11-28 16:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentDidMount(): void {
|
2019-12-02 14:34:32 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
2022-02-22 12:18:08 +00:00
|
|
|
cli.on(ClientEvent.AccountData, this.onAccountData);
|
|
|
|
|
cli.on(CryptoEvent.UserTrustStatusChanged, this.onStatusChanged);
|
|
|
|
|
cli.on(CryptoEvent.KeysChanged, this.onStatusChanged);
|
2021-08-13 18:07:58 +01:00
|
|
|
this.getUpdatedStatus();
|
2019-12-02 14:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentWillUnmount(): void {
|
2021-08-13 18:07:58 +01:00
|
|
|
this.unmounted = true;
|
2019-12-02 14:34:32 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
if (!cli) return;
|
2022-02-22 12:18:08 +00:00
|
|
|
cli.removeListener(ClientEvent.AccountData, this.onAccountData);
|
|
|
|
|
cli.removeListener(CryptoEvent.UserTrustStatusChanged, this.onStatusChanged);
|
|
|
|
|
cli.removeListener(CryptoEvent.KeysChanged, this.onStatusChanged);
|
2019-12-02 14:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-13 18:18:48 +01:00
|
|
|
private onAccountData = (event: MatrixEvent): void => {
|
2019-12-02 14:34:32 +00:00
|
|
|
const type = event.getType();
|
|
|
|
|
if (type.startsWith("m.cross_signing") || type.startsWith("m.secret_storage")) {
|
2021-08-13 18:07:58 +01:00
|
|
|
this.getUpdatedStatus();
|
2019-12-02 14:34:32 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onBootstrapClick = (): void => {
|
2021-08-18 19:22:42 +01:00
|
|
|
if (this.state.crossSigningPrivateKeysInStorage) {
|
2022-06-14 17:51:51 +01:00
|
|
|
Modal.createDialog(SetupEncryptionDialog, {}, null, /* priority = */ false, /* static = */ true);
|
2021-08-18 19:22:42 +01:00
|
|
|
} else {
|
|
|
|
|
// Trigger the flow to set up secure backup, which is what this will do when in
|
|
|
|
|
// the appropriate state.
|
|
|
|
|
accessSecretStorage();
|
|
|
|
|
}
|
2020-03-19 20:40:08 +00:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onStatusChanged = (): void => {
|
2021-08-13 18:07:58 +01:00
|
|
|
this.getUpdatedStatus();
|
2019-12-12 15:42:27 +00:00
|
|
|
};
|
|
|
|
|
|
2021-08-13 18:07:58 +01:00
|
|
|
private async getUpdatedStatus(): Promise<void> {
|
2019-11-28 16:45:29 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
2020-03-24 15:50:08 +00:00
|
|
|
const pkCache = cli.getCrossSigningCacheCallbacks();
|
2021-06-23 14:47:24 +01:00
|
|
|
const crossSigning = cli.crypto.crossSigningInfo;
|
|
|
|
|
const secretStorage = cli.crypto.secretStorage;
|
2021-08-13 18:07:58 +01:00
|
|
|
const crossSigningPublicKeysOnDevice = Boolean(crossSigning.getId());
|
|
|
|
|
const crossSigningPrivateKeysInStorage = Boolean(await crossSigning.isStoredInSecretStorage(secretStorage));
|
2021-09-21 17:48:09 +02:00
|
|
|
const masterPrivateKeyCached = !!(pkCache && (await pkCache.getCrossSigningKeyCache("master")));
|
|
|
|
|
const selfSigningPrivateKeyCached = !!(pkCache && (await pkCache.getCrossSigningKeyCache("self_signing")));
|
|
|
|
|
const userSigningPrivateKeyCached = !!(pkCache && (await pkCache.getCrossSigningKeyCache("user_signing")));
|
2020-02-24 15:04:34 +00:00
|
|
|
const homeserverSupportsCrossSigning = await cli.doesServerSupportUnstableFeature(
|
|
|
|
|
"org.matrix.e2e_cross_signing",
|
|
|
|
|
);
|
2020-03-24 13:03:07 +00:00
|
|
|
const crossSigningReady = await cli.isCrossSigningReady();
|
2019-11-28 16:45:29 +00:00
|
|
|
|
2020-01-20 20:35:21 +00:00
|
|
|
this.setState({
|
2019-11-28 16:45:29 +00:00
|
|
|
crossSigningPublicKeysOnDevice,
|
|
|
|
|
crossSigningPrivateKeysInStorage,
|
2020-08-06 15:25:33 +01:00
|
|
|
masterPrivateKeyCached,
|
2020-03-24 15:50:08 +00:00
|
|
|
selfSigningPrivateKeyCached,
|
|
|
|
|
userSigningPrivateKeyCached,
|
2020-02-24 15:04:34 +00:00
|
|
|
homeserverSupportsCrossSigning,
|
2020-03-23 18:36:37 +00:00
|
|
|
crossSigningReady,
|
2020-01-20 20:35:21 +00:00
|
|
|
});
|
2019-11-28 16:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-05 15:05:28 +00:00
|
|
|
/**
|
2020-09-08 18:01:56 +01:00
|
|
|
* Bootstrapping cross-signing take one of these paths:
|
|
|
|
|
* 1. Create cross-signing keys locally and store in secret storage (if it
|
|
|
|
|
* already exists on the account).
|
2019-12-05 15:05:28 +00:00
|
|
|
* 2. Access existing secret storage by requesting passphrase and accessing
|
|
|
|
|
* cross-signing keys as needed.
|
|
|
|
|
* 3. All keys are loaded and there's nothing to do.
|
2020-03-25 14:21:17 +00:00
|
|
|
* @param {bool} [forceReset] Bootstrap again even if keys already present
|
2019-12-05 15:05:28 +00:00
|
|
|
*/
|
2021-08-13 18:07:58 +01:00
|
|
|
private bootstrapCrossSigning = async ({ forceReset = false }): Promise<void> => {
|
|
|
|
|
this.setState({ error: undefined });
|
2019-11-28 16:45:29 +00:00
|
|
|
try {
|
2020-09-08 18:01:56 +01:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
await cli.bootstrapCrossSigning({
|
2023-01-12 13:25:14 +00:00
|
|
|
authUploadDeviceSigningKeys: async (makeRequest): Promise<void> => {
|
2022-06-14 17:51:51 +01:00
|
|
|
const { finished } = Modal.createDialog(InteractiveAuthDialog, {
|
|
|
|
|
title: _t("Setting up keys"),
|
|
|
|
|
matrixClient: cli,
|
|
|
|
|
makeRequest,
|
|
|
|
|
});
|
2020-09-08 18:01:56 +01:00
|
|
|
const [confirmed] = await finished;
|
|
|
|
|
if (!confirmed) {
|
|
|
|
|
throw new Error("Cross-signing key upload auth canceled");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
setupNewCrossSigning: forceReset,
|
|
|
|
|
});
|
2019-11-28 16:45:29 +00:00
|
|
|
} catch (e) {
|
2019-12-02 14:22:47 +00:00
|
|
|
this.setState({ error: e });
|
2021-10-15 16:30:53 +02:00
|
|
|
logger.error("Error bootstrapping cross-signing", e);
|
2019-11-28 16:45:29 +00:00
|
|
|
}
|
2021-08-13 18:07:58 +01:00
|
|
|
if (this.unmounted) return;
|
|
|
|
|
this.getUpdatedStatus();
|
|
|
|
|
};
|
2019-11-28 16:45:29 +00:00
|
|
|
|
2021-08-13 18:07:58 +01:00
|
|
|
private resetCrossSigning = (): void => {
|
2020-05-06 14:42:03 -06:00
|
|
|
Modal.createDialog(ConfirmDestroyCrossSigningDialog, {
|
2020-09-08 18:01:56 +01:00
|
|
|
onFinished: (act) => {
|
|
|
|
|
if (!act) return;
|
2021-08-13 18:07:58 +01:00
|
|
|
this.bootstrapCrossSigning({ forceReset: true });
|
2020-09-08 18:01:56 +01:00
|
|
|
},
|
2020-02-07 14:55:01 +00:00
|
|
|
});
|
2021-08-13 18:07:58 +01:00
|
|
|
};
|
2020-02-07 14:55:01 +00:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public render(): JSX.Element {
|
2019-11-28 16:45:29 +00:00
|
|
|
const {
|
2019-12-02 14:22:47 +00:00
|
|
|
error,
|
2019-11-28 16:45:29 +00:00
|
|
|
crossSigningPublicKeysOnDevice,
|
|
|
|
|
crossSigningPrivateKeysInStorage,
|
2020-08-06 15:25:33 +01:00
|
|
|
masterPrivateKeyCached,
|
2020-03-24 15:50:08 +00:00
|
|
|
selfSigningPrivateKeyCached,
|
|
|
|
|
userSigningPrivateKeyCached,
|
2020-02-24 15:04:34 +00:00
|
|
|
homeserverSupportsCrossSigning,
|
2020-03-23 18:36:37 +00:00
|
|
|
crossSigningReady,
|
2019-11-28 16:45:29 +00:00
|
|
|
} = this.state;
|
|
|
|
|
|
2019-12-02 14:22:47 +00:00
|
|
|
let errorSection;
|
|
|
|
|
if (error) {
|
2021-07-19 22:43:11 +01:00
|
|
|
errorSection = <div className="error">{error.toString()}</div>;
|
2019-12-02 14:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-12 14:27:57 +00:00
|
|
|
let summarisedStatus;
|
2020-03-23 18:36:37 +00:00
|
|
|
if (homeserverSupportsCrossSigning === undefined) {
|
2020-09-03 13:23:50 +01:00
|
|
|
summarisedStatus = <Spinner />;
|
2020-03-23 18:36:37 +00:00
|
|
|
} else if (!homeserverSupportsCrossSigning) {
|
2020-02-24 15:04:34 +00:00
|
|
|
summarisedStatus = <p>{_t("Your homeserver does not support cross-signing.")}</p>;
|
2021-08-18 19:22:42 +01:00
|
|
|
} else if (crossSigningReady && crossSigningPrivateKeysInStorage) {
|
2020-09-08 14:10:34 +01:00
|
|
|
summarisedStatus = <p>✅ {_t("Cross-signing is ready for use.")}</p>;
|
2021-08-18 19:22:42 +01:00
|
|
|
} else if (crossSigningReady && !crossSigningPrivateKeysInStorage) {
|
|
|
|
|
summarisedStatus = <p>⚠️ {_t("Cross-signing is ready but keys are not backed up.")}</p>;
|
2019-12-12 14:27:57 +00:00
|
|
|
} else if (crossSigningPrivateKeysInStorage) {
|
2021-07-19 22:43:11 +01:00
|
|
|
summarisedStatus = (
|
|
|
|
|
<p>
|
|
|
|
|
{_t(
|
2020-08-21 18:22:05 +01:00
|
|
|
"Your account has a cross-signing identity in secret storage, " +
|
|
|
|
|
"but it is not yet trusted by this session.",
|
2021-07-19 22:43:11 +01:00
|
|
|
)}
|
|
|
|
|
</p>
|
|
|
|
|
);
|
2019-12-12 14:27:57 +00:00
|
|
|
} else {
|
2020-09-08 14:10:34 +01:00
|
|
|
summarisedStatus = <p>{_t("Cross-signing is not set up.")}</p>;
|
2019-12-12 14:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 14:30:12 +01:00
|
|
|
const keysExistAnywhere =
|
2020-09-16 13:20:45 +01:00
|
|
|
crossSigningPublicKeysOnDevice ||
|
2020-06-24 14:30:12 +01:00
|
|
|
crossSigningPrivateKeysInStorage ||
|
2020-09-16 13:20:45 +01:00
|
|
|
masterPrivateKeyCached ||
|
|
|
|
|
selfSigningPrivateKeyCached ||
|
|
|
|
|
userSigningPrivateKeyCached;
|
2020-06-24 14:30:12 +01:00
|
|
|
const keysExistEverywhere =
|
2020-09-16 13:20:45 +01:00
|
|
|
crossSigningPublicKeysOnDevice &&
|
2020-06-24 14:30:12 +01:00
|
|
|
crossSigningPrivateKeysInStorage &&
|
2020-09-16 13:20:45 +01:00
|
|
|
masterPrivateKeyCached &&
|
|
|
|
|
selfSigningPrivateKeyCached &&
|
|
|
|
|
userSigningPrivateKeyCached;
|
2020-06-24 14:30:12 +01:00
|
|
|
|
2020-09-11 14:09:54 +01:00
|
|
|
const actions = [];
|
|
|
|
|
|
|
|
|
|
// TODO: determine how better to expose this to users in addition to prompts at login/toast
|
|
|
|
|
if (!keysExistEverywhere && homeserverSupportsCrossSigning) {
|
2021-08-18 19:22:42 +01:00
|
|
|
let buttonCaption = _t("Set up Secure Backup");
|
|
|
|
|
if (crossSigningPrivateKeysInStorage) {
|
|
|
|
|
buttonCaption = _t("Verify this session");
|
|
|
|
|
}
|
2020-09-11 14:09:54 +01:00
|
|
|
actions.push(
|
2021-08-13 18:07:58 +01:00
|
|
|
<AccessibleButton key="setup" kind="primary" onClick={this.onBootstrapClick}>
|
2021-08-18 19:22:42 +01:00
|
|
|
{buttonCaption}
|
2020-09-11 14:09:54 +01:00
|
|
|
</AccessibleButton>,
|
2020-02-24 15:04:34 +00:00
|
|
|
);
|
2020-02-25 11:23:51 +00:00
|
|
|
}
|
2020-05-27 10:28:25 +01:00
|
|
|
|
2020-09-11 14:09:54 +01:00
|
|
|
if (keysExistAnywhere) {
|
|
|
|
|
actions.push(
|
2021-08-13 18:07:58 +01:00
|
|
|
<AccessibleButton key="reset" kind="danger" onClick={this.resetCrossSigning}>
|
2021-07-19 22:43:11 +01:00
|
|
|
{_t("Reset")}
|
2020-09-11 14:09:54 +01:00
|
|
|
</AccessibleButton>,
|
2020-02-24 15:04:34 +00:00
|
|
|
);
|
2020-02-11 15:56:32 +00:00
|
|
|
}
|
2019-12-12 14:27:57 +00:00
|
|
|
|
2020-09-11 14:09:54 +01:00
|
|
|
let actionRow;
|
|
|
|
|
if (actions.length) {
|
|
|
|
|
actionRow = <div className="mx_CrossSigningPanel_buttonRow">{actions}</div>;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 16:45:29 +00:00
|
|
|
return (
|
|
|
|
|
<div>
|
2021-07-19 22:43:11 +01:00
|
|
|
{summarisedStatus}
|
2019-12-12 14:27:57 +00:00
|
|
|
<details>
|
2021-07-19 22:43:11 +01:00
|
|
|
<summary>{_t("Advanced")}</summary>
|
2019-12-12 14:27:57 +00:00
|
|
|
<table className="mx_CrossSigningPanel_statusList">
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
2021-07-19 22:43:11 +01:00
|
|
|
<td>{_t("Cross-signing public keys:")}</td>
|
|
|
|
|
<td>{crossSigningPublicKeysOnDevice ? _t("in memory") : _t("not found")}</td>
|
2019-12-12 14:27:57 +00:00
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2021-07-19 22:43:11 +01:00
|
|
|
<td>{_t("Cross-signing private keys:")}</td>
|
|
|
|
|
<td>
|
|
|
|
|
{crossSigningPrivateKeysInStorage
|
|
|
|
|
? _t("in secret storage")
|
|
|
|
|
: _t("not found in storage")}
|
|
|
|
|
</td>
|
2019-12-12 14:27:57 +00:00
|
|
|
</tr>
|
2020-08-06 15:25:33 +01:00
|
|
|
<tr>
|
2021-07-19 22:43:11 +01:00
|
|
|
<td>{_t("Master private key:")}</td>
|
|
|
|
|
<td>{masterPrivateKeyCached ? _t("cached locally") : _t("not found locally")}</td>
|
2020-08-06 15:25:33 +01:00
|
|
|
</tr>
|
2020-03-24 15:50:08 +00:00
|
|
|
<tr>
|
2021-07-19 22:43:11 +01:00
|
|
|
<td>{_t("Self signing private key:")}</td>
|
|
|
|
|
<td>{selfSigningPrivateKeyCached ? _t("cached locally") : _t("not found locally")}</td>
|
2020-03-24 15:50:08 +00:00
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2021-07-19 22:43:11 +01:00
|
|
|
<td>{_t("User signing private key:")}</td>
|
|
|
|
|
<td>{userSigningPrivateKeyCached ? _t("cached locally") : _t("not found locally")}</td>
|
2020-03-24 15:50:08 +00:00
|
|
|
</tr>
|
2020-02-24 15:04:34 +00:00
|
|
|
<tr>
|
2021-07-19 22:43:11 +01:00
|
|
|
<td>{_t("Homeserver feature support:")}</td>
|
|
|
|
|
<td>{homeserverSupportsCrossSigning ? _t("exists") : _t("not found")}</td>
|
2020-02-24 15:04:34 +00:00
|
|
|
</tr>
|
2021-04-27 17:23:27 +02:00
|
|
|
</tbody>
|
|
|
|
|
</table>
|
2019-12-12 14:27:57 +00:00
|
|
|
</details>
|
2021-07-19 22:43:11 +01:00
|
|
|
{errorSection}
|
|
|
|
|
{actionRow}
|
2019-11-28 16:45:29 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|