2020-03-24 15:57:04 +01:00
|
|
|
|
/*
|
2021-07-01 13:45:33 +01:00
|
|
|
|
Copyright 2020-2021 The Matrix.org Foundation C.I.C.
|
2020-03-24 15:57:04 +01: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';
|
2020-06-19 17:17:04 +01:00
|
|
|
|
import { _t } from '../../../languageHandler';
|
2020-03-24 15:57:04 +01:00
|
|
|
|
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
2021-03-08 04:43:59 +00:00
|
|
|
|
import Modal from '../../../Modal';
|
|
|
|
|
|
import VerificationRequestDialog from '../../views/dialogs/VerificationRequestDialog';
|
2021-06-18 14:05:12 +01:00
|
|
|
|
import { SetupEncryptionStore, Phase } from '../../../stores/SetupEncryptionStore';
|
2021-06-29 13:11:58 +01:00
|
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-07-01 13:45:33 +01:00
|
|
|
|
import { ISecretStorageKeyInfo } from 'matrix-js-sdk';
|
2021-07-01 15:11:18 +01:00
|
|
|
|
import EncryptionPanel from "../../views/right_panel/EncryptionPanel";
|
2021-07-01 13:49:58 +01:00
|
|
|
|
import AccessibleButton from '../../views/elements/AccessibleButton';
|
|
|
|
|
|
import Spinner from '../../views/elements/Spinner';
|
2021-07-01 13:55:57 +01:00
|
|
|
|
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
|
|
|
|
|
|
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
2020-03-24 15:57:04 +01:00
|
|
|
|
|
2021-07-01 13:45:33 +01:00
|
|
|
|
function keyHasPassphrase(keyInfo: ISecretStorageKeyInfo): boolean {
|
|
|
|
|
|
return Boolean(
|
2020-06-23 15:24:02 +01:00
|
|
|
|
keyInfo.passphrase &&
|
|
|
|
|
|
keyInfo.passphrase.salt &&
|
2021-07-01 15:11:18 +01:00
|
|
|
|
keyInfo.passphrase.iterations,
|
2020-06-23 15:24:02 +01:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-01 13:45:33 +01:00
|
|
|
|
interface IProps {
|
|
|
|
|
|
onFinished: (boolean) => void;
|
|
|
|
|
|
}
|
2020-03-24 15:57:04 +01:00
|
|
|
|
|
2021-07-01 13:45:33 +01:00
|
|
|
|
interface IState {
|
|
|
|
|
|
phase: Phase;
|
2021-07-01 13:55:57 +01:00
|
|
|
|
verificationRequest: VerificationRequest;
|
|
|
|
|
|
backupInfo: IKeyBackupInfo;
|
2021-07-01 13:45:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@replaceableComponent("structures.auth.SetupEncryptionBody")
|
|
|
|
|
|
export default class SetupEncryptionBody extends React.Component<IProps, IState> {
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
|
super(props);
|
2020-03-24 15:57:04 +01:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2021-07-01 13:49:58 +01:00
|
|
|
|
store.on("update", this.onStoreUpdate);
|
2020-03-24 15:57:04 +01:00
|
|
|
|
store.start();
|
|
|
|
|
|
this.state = {
|
|
|
|
|
|
phase: store.phase,
|
|
|
|
|
|
// this serves dual purpose as the object for the request logic and
|
2020-03-25 13:40:09 +01:00
|
|
|
|
// the presence of it indicating that we're in 'verify mode'.
|
2020-03-24 15:57:04 +01:00
|
|
|
|
// Because of the latter, it lives in the state.
|
|
|
|
|
|
verificationRequest: store.verificationRequest,
|
|
|
|
|
|
backupInfo: store.backupInfo,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
private onStoreUpdate = () => {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2021-06-18 14:05:12 +01:00
|
|
|
|
if (store.phase === Phase.Finished) {
|
2021-07-01 13:45:33 +01:00
|
|
|
|
this.props.onFinished(true);
|
2020-03-24 15:57:04 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
phase: store.phase,
|
|
|
|
|
|
verificationRequest: store.verificationRequest,
|
|
|
|
|
|
backupInfo: store.backupInfo,
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
public componentWillUnmount() {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2021-07-01 13:49:58 +01:00
|
|
|
|
store.off("update", this.onStoreUpdate);
|
2020-03-24 15:57:04 +01:00
|
|
|
|
store.stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
private onUsePassphraseClick = async () => {
|
2020-06-02 17:55:27 +01:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2020-06-18 09:35:11 +01:00
|
|
|
|
store.usePassPhrase();
|
2021-07-01 15:11:18 +01:00
|
|
|
|
};
|
2020-03-24 15:57:04 +01:00
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
private onVerifyClick = () => {
|
2021-03-08 04:43:59 +00:00
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
|
const userId = cli.getUserId();
|
|
|
|
|
|
const requestPromise = cli.requestVerification(userId);
|
|
|
|
|
|
|
|
|
|
|
|
this.props.onFinished(true);
|
|
|
|
|
|
Modal.createTrackedDialog('New Session Verification', 'Starting dialog', VerificationRequestDialog, {
|
|
|
|
|
|
verificationRequestPromise: requestPromise,
|
|
|
|
|
|
member: cli.getUser(userId),
|
|
|
|
|
|
onFinished: async () => {
|
|
|
|
|
|
const request = await requestPromise;
|
|
|
|
|
|
request.cancel();
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
2021-07-01 15:11:18 +01:00
|
|
|
|
};
|
2021-03-08 04:43:59 +00:00
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
private onSkipClick = () => {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
|
store.skip();
|
2021-07-01 15:11:18 +01:00
|
|
|
|
};
|
2020-03-24 15:57:04 +01:00
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
private onSkipConfirmClick = () => {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
|
store.skipConfirm();
|
2021-07-01 15:11:18 +01:00
|
|
|
|
};
|
2020-03-24 15:57:04 +01:00
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
private onSkipBackClick = () => {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
|
store.returnAfterSkip();
|
2021-07-01 15:11:18 +01:00
|
|
|
|
};
|
2020-03-24 15:57:04 +01:00
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
private onDoneClick = () => {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
|
store.done();
|
2021-07-01 15:11:18 +01:00
|
|
|
|
};
|
2020-03-24 15:57:04 +01:00
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
private onEncryptionPanelClose = () => {
|
2021-07-01 13:45:33 +01:00
|
|
|
|
this.props.onFinished(false);
|
2021-07-01 15:11:18 +01:00
|
|
|
|
};
|
2021-07-01 13:45:33 +01:00
|
|
|
|
|
2021-07-01 13:49:58 +01:00
|
|
|
|
public render() {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
const {
|
|
|
|
|
|
phase,
|
|
|
|
|
|
} = this.state;
|
|
|
|
|
|
|
|
|
|
|
|
if (this.state.verificationRequest) {
|
|
|
|
|
|
return <EncryptionPanel
|
|
|
|
|
|
layout="dialog"
|
|
|
|
|
|
verificationRequest={this.state.verificationRequest}
|
2021-07-01 13:45:33 +01:00
|
|
|
|
onClose={this.onEncryptionPanelClose}
|
2020-03-24 15:57:04 +01:00
|
|
|
|
member={MatrixClientPeg.get().getUser(this.state.verificationRequest.otherUserId)}
|
2021-07-01 13:45:33 +01:00
|
|
|
|
isRoomEncrypted={false}
|
2020-03-24 15:57:04 +01:00
|
|
|
|
/>;
|
2021-06-18 14:05:12 +01:00
|
|
|
|
} else if (phase === Phase.Intro) {
|
2020-06-02 16:32:15 +01:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
|
let recoveryKeyPrompt;
|
2020-06-05 16:40:20 +01:00
|
|
|
|
if (store.keyInfo && keyHasPassphrase(store.keyInfo)) {
|
2021-01-12 16:04:43 -06:00
|
|
|
|
recoveryKeyPrompt = _t("Use Security Key or Phrase");
|
2020-06-05 16:40:20 +01:00
|
|
|
|
} else if (store.keyInfo) {
|
2021-01-04 19:17:12 -06:00
|
|
|
|
recoveryKeyPrompt = _t("Use Security Key");
|
2020-06-02 16:32:15 +01:00
|
|
|
|
}
|
2020-06-05 16:40:20 +01:00
|
|
|
|
|
|
|
|
|
|
let useRecoveryKeyButton;
|
|
|
|
|
|
if (recoveryKeyPrompt) {
|
2021-07-01 13:49:58 +01:00
|
|
|
|
useRecoveryKeyButton = <AccessibleButton kind="link" onClick={this.onUsePassphraseClick}>
|
2020-06-05 16:40:20 +01:00
|
|
|
|
{recoveryKeyPrompt}
|
|
|
|
|
|
</AccessibleButton>;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-08 04:43:59 +00:00
|
|
|
|
let verifyButton;
|
|
|
|
|
|
if (store.hasDevicesToVerifyAgainst) {
|
2021-07-01 13:49:58 +01:00
|
|
|
|
verifyButton = <AccessibleButton kind="primary" onClick={this.onVerifyClick}>
|
2021-03-26 11:13:39 +00:00
|
|
|
|
{ _t("Use another login") }
|
2021-03-08 04:43:59 +00:00
|
|
|
|
</AccessibleButton>;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-24 15:57:04 +01:00
|
|
|
|
return (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p>{_t(
|
2021-03-26 11:13:39 +00:00
|
|
|
|
"Verify your identity to access encrypted messages and prove your identity to others.",
|
2020-03-24 15:57:04 +01:00
|
|
|
|
)}</p>
|
2020-04-22 22:32:02 +01:00
|
|
|
|
|
2020-03-24 15:57:04 +01:00
|
|
|
|
<div className="mx_CompleteSecurity_actionRow">
|
2021-03-08 04:43:59 +00:00
|
|
|
|
{verifyButton}
|
2020-06-05 16:40:20 +01:00
|
|
|
|
{useRecoveryKeyButton}
|
2020-04-22 22:32:02 +01:00
|
|
|
|
<AccessibleButton kind="danger" onClick={this.onSkipClick}>
|
2020-03-24 15:57:04 +01:00
|
|
|
|
{_t("Skip")}
|
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
2021-06-18 14:05:12 +01:00
|
|
|
|
} else if (phase === Phase.Done) {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
let message;
|
|
|
|
|
|
if (this.state.backupInfo) {
|
|
|
|
|
|
message = <p>{_t(
|
|
|
|
|
|
"Your new session is now verified. It has access to your " +
|
|
|
|
|
|
"encrypted messages, and other users will see it as trusted.",
|
|
|
|
|
|
)}</p>;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
message = <p>{_t(
|
|
|
|
|
|
"Your new session is now verified. Other users will see it as trusted.",
|
|
|
|
|
|
)}</p>;
|
|
|
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div>
|
2020-04-22 22:32:02 +01:00
|
|
|
|
<div className="mx_CompleteSecurity_heroIcon mx_E2EIcon_verified" />
|
2020-03-24 15:57:04 +01:00
|
|
|
|
{message}
|
|
|
|
|
|
<div className="mx_CompleteSecurity_actionRow">
|
|
|
|
|
|
<AccessibleButton
|
|
|
|
|
|
kind="primary"
|
|
|
|
|
|
onClick={this.onDoneClick}
|
|
|
|
|
|
>
|
|
|
|
|
|
{_t("Done")}
|
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
2021-06-18 14:05:12 +01:00
|
|
|
|
} else if (phase === Phase.ConfirmSkip) {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
return (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p>{_t(
|
2021-03-26 11:13:39 +00:00
|
|
|
|
"Without verifying, you won’t have access to all your messages " +
|
|
|
|
|
|
"and may appear as untrusted to others.",
|
2020-03-24 15:57:04 +01:00
|
|
|
|
)}</p>
|
|
|
|
|
|
<div className="mx_CompleteSecurity_actionRow">
|
|
|
|
|
|
<AccessibleButton
|
|
|
|
|
|
className="warning"
|
|
|
|
|
|
kind="secondary"
|
|
|
|
|
|
onClick={this.onSkipConfirmClick}
|
|
|
|
|
|
>
|
|
|
|
|
|
{_t("Skip")}
|
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
|
<AccessibleButton
|
|
|
|
|
|
kind="danger"
|
|
|
|
|
|
onClick={this.onSkipBackClick}
|
|
|
|
|
|
>
|
|
|
|
|
|
{_t("Go Back")}
|
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
2021-06-18 14:05:12 +01:00
|
|
|
|
} else if (phase === Phase.Busy || phase === Phase.Loading) {
|
2020-03-24 15:57:04 +01:00
|
|
|
|
return <Spinner />;
|
|
|
|
|
|
} else {
|
2020-03-25 13:07:07 +01:00
|
|
|
|
console.log(`SetupEncryptionBody: Unknown phase ${phase}`);
|
2020-03-24 15:57:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|