2020-03-24 17:57:04 +03:00
|
|
|
|
/*
|
|
|
|
|
Copyright 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 PropTypes from 'prop-types';
|
2020-06-19 19:17:04 +03:00
|
|
|
|
import { _t } from '../../../languageHandler';
|
2020-03-24 17:57:04 +03:00
|
|
|
|
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
2021-03-08 07:43:59 +03:00
|
|
|
|
import Modal from '../../../Modal';
|
|
|
|
|
import VerificationRequestDialog from '../../views/dialogs/VerificationRequestDialog';
|
2020-03-24 17:57:04 +03:00
|
|
|
|
import * as sdk from '../../../index';
|
|
|
|
|
import {
|
|
|
|
|
SetupEncryptionStore,
|
2021-03-09 02:28:44 +03:00
|
|
|
|
PHASE_LOADING,
|
2020-03-24 17:57:04 +03:00
|
|
|
|
PHASE_INTRO,
|
|
|
|
|
PHASE_BUSY,
|
|
|
|
|
PHASE_DONE,
|
|
|
|
|
PHASE_CONFIRM_SKIP,
|
|
|
|
|
PHASE_FINISHED,
|
|
|
|
|
} from '../../../stores/SetupEncryptionStore';
|
2021-03-09 05:35:10 +03:00
|
|
|
|
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
2020-03-24 17:57:04 +03:00
|
|
|
|
|
2020-06-23 17:24:02 +03:00
|
|
|
|
function keyHasPassphrase(keyInfo) {
|
|
|
|
|
return (
|
|
|
|
|
keyInfo.passphrase &&
|
|
|
|
|
keyInfo.passphrase.salt &&
|
|
|
|
|
keyInfo.passphrase.iterations
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 05:35:10 +03:00
|
|
|
|
@replaceableComponent("structures.auth.SetupEncryptionBody")
|
2020-03-24 17:57:04 +03:00
|
|
|
|
export default class SetupEncryptionBody extends React.Component {
|
|
|
|
|
static propTypes = {
|
|
|
|
|
onFinished: PropTypes.func.isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.on("update", this._onStoreUpdate);
|
|
|
|
|
store.start();
|
|
|
|
|
this.state = {
|
|
|
|
|
phase: store.phase,
|
|
|
|
|
// this serves dual purpose as the object for the request logic and
|
2020-03-25 15:40:09 +03:00
|
|
|
|
// the presence of it indicating that we're in 'verify mode'.
|
2020-03-24 17:57:04 +03:00
|
|
|
|
// Because of the latter, it lives in the state.
|
|
|
|
|
verificationRequest: store.verificationRequest,
|
|
|
|
|
backupInfo: store.backupInfo,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_onStoreUpdate = () => {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
if (store.phase === PHASE_FINISHED) {
|
|
|
|
|
this.props.onFinished();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.setState({
|
|
|
|
|
phase: store.phase,
|
|
|
|
|
verificationRequest: store.verificationRequest,
|
|
|
|
|
backupInfo: store.backupInfo,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.off("update", this._onStoreUpdate);
|
|
|
|
|
store.stop();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 11:35:11 +03:00
|
|
|
|
_onUsePassphraseClick = async () => {
|
2020-06-02 19:55:27 +03:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2020-06-18 11:35:11 +03:00
|
|
|
|
store.usePassPhrase();
|
2020-03-24 17:57:04 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 07:43:59 +03:00
|
|
|
|
_onVerifyClick = () => {
|
|
|
|
|
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();
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 17:57:04 +03:00
|
|
|
|
onSkipClick = () => {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.skip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSkipConfirmClick = () => {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.skipConfirm();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSkipBackClick = () => {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.returnAfterSkip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDoneClick = () => {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.done();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
phase,
|
|
|
|
|
} = this.state;
|
|
|
|
|
|
|
|
|
|
if (this.state.verificationRequest) {
|
|
|
|
|
const EncryptionPanel = sdk.getComponent("views.right_panel.EncryptionPanel");
|
|
|
|
|
return <EncryptionPanel
|
|
|
|
|
layout="dialog"
|
|
|
|
|
verificationRequest={this.state.verificationRequest}
|
|
|
|
|
onClose={this.props.onFinished}
|
|
|
|
|
member={MatrixClientPeg.get().getUser(this.state.verificationRequest.otherUserId)}
|
|
|
|
|
/>;
|
|
|
|
|
} else if (phase === PHASE_INTRO) {
|
2020-06-02 18:32:15 +03:00
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
let recoveryKeyPrompt;
|
2020-06-05 18:40:20 +03:00
|
|
|
|
if (store.keyInfo && keyHasPassphrase(store.keyInfo)) {
|
2021-01-13 01:04:43 +03:00
|
|
|
|
recoveryKeyPrompt = _t("Use Security Key or Phrase");
|
2020-06-05 18:40:20 +03:00
|
|
|
|
} else if (store.keyInfo) {
|
2021-01-05 04:17:12 +03:00
|
|
|
|
recoveryKeyPrompt = _t("Use Security Key");
|
2020-06-02 18:32:15 +03:00
|
|
|
|
}
|
2020-06-05 18:40:20 +03:00
|
|
|
|
|
|
|
|
|
let useRecoveryKeyButton;
|
|
|
|
|
if (recoveryKeyPrompt) {
|
2020-06-19 18:50:29 +03:00
|
|
|
|
useRecoveryKeyButton = <AccessibleButton kind="link" onClick={this._onUsePassphraseClick}>
|
2020-06-05 18:40:20 +03:00
|
|
|
|
{recoveryKeyPrompt}
|
|
|
|
|
</AccessibleButton>;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 07:43:59 +03:00
|
|
|
|
let verifyButton;
|
|
|
|
|
if (store.hasDevicesToVerifyAgainst) {
|
|
|
|
|
verifyButton = <AccessibleButton kind="primary" onClick={this._onVerifyClick}>
|
2021-03-26 14:13:39 +03:00
|
|
|
|
{ _t("Use another login") }
|
2021-03-08 07:43:59 +03:00
|
|
|
|
</AccessibleButton>;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 17:57:04 +03:00
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<p>{_t(
|
2021-03-26 14:13:39 +03:00
|
|
|
|
"Verify your identity to access encrypted messages and prove your identity to others.",
|
2020-04-23 00:32:02 +03:00
|
|
|
|
)}</p>
|
|
|
|
|
|
2020-03-24 17:57:04 +03:00
|
|
|
|
<div className="mx_CompleteSecurity_actionRow">
|
2021-03-08 07:43:59 +03:00
|
|
|
|
{verifyButton}
|
2020-06-05 18:40:20 +03:00
|
|
|
|
{useRecoveryKeyButton}
|
2020-04-23 00:32:02 +03:00
|
|
|
|
<AccessibleButton kind="danger" onClick={this.onSkipClick}>
|
2020-03-24 17:57:04 +03:00
|
|
|
|
{_t("Skip")}
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else if (phase === PHASE_DONE) {
|
|
|
|
|
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-23 00:32:02 +03:00
|
|
|
|
<div className="mx_CompleteSecurity_heroIcon mx_E2EIcon_verified" />
|
2020-03-24 17:57:04 +03:00
|
|
|
|
{message}
|
|
|
|
|
<div className="mx_CompleteSecurity_actionRow">
|
|
|
|
|
<AccessibleButton
|
|
|
|
|
kind="primary"
|
|
|
|
|
onClick={this.onDoneClick}
|
|
|
|
|
>
|
|
|
|
|
{_t("Done")}
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else if (phase === PHASE_CONFIRM_SKIP) {
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<p>{_t(
|
2021-03-26 14:13:39 +03:00
|
|
|
|
"Without verifying, you won’t have access to all your messages " +
|
|
|
|
|
"and may appear as untrusted to others.",
|
2020-03-24 17:57:04 +03: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-03-09 02:28:44 +03:00
|
|
|
|
} else if (phase === PHASE_BUSY || phase === PHASE_LOADING) {
|
2020-03-24 17:57:04 +03:00
|
|
|
|
const Spinner = sdk.getComponent('views.elements.Spinner');
|
|
|
|
|
return <Spinner />;
|
|
|
|
|
} else {
|
2020-03-25 15:07:07 +03:00
|
|
|
|
console.log(`SetupEncryptionBody: Unknown phase ${phase}`);
|
2020-03-24 17:57:04 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|