Merge pull request #3966 from matrix-org/dbkr/restore_key_backup_in_complete_security

Restore key backup in Complete Security dialog
This commit is contained in:
David Baker 2020-01-29 09:55:50 +00:00 committed by GitHub
commit fa1f2cd7e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View file

@ -22,8 +22,9 @@ import { MatrixClientPeg } from '../../../MatrixClientPeg';
import { accessSecretStorage } from '../../../CrossSigningManager'; import { accessSecretStorage } from '../../../CrossSigningManager';
const PHASE_INTRO = 0; const PHASE_INTRO = 0;
const PHASE_DONE = 1; const PHASE_BUSY = 1;
const PHASE_CONFIRM_SKIP = 2; const PHASE_DONE = 2;
const PHASE_CONFIRM_SKIP = 3;
export default class CompleteSecurity extends React.Component { export default class CompleteSecurity extends React.Component {
static propTypes = { static propTypes = {
@ -39,6 +40,7 @@ export default class CompleteSecurity extends React.Component {
// the presence of it insidicating that we're in 'verify mode'. // the presence of it insidicating that we're in 'verify mode'.
// Because of the latter, it lives in the state. // Because of the latter, it lives in the state.
verificationRequest: null, verificationRequest: null,
backupInfo: null,
}; };
MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest); MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest);
} }
@ -53,10 +55,16 @@ export default class CompleteSecurity extends React.Component {
} }
onStartClick = async () => { onStartClick = async () => {
this.setState({
phase: PHASE_BUSY,
});
const cli = MatrixClientPeg.get(); const cli = MatrixClientPeg.get();
const backupInfo = await cli.getKeyBackupVersion();
this.setState({backupInfo});
try { try {
await accessSecretStorage(async () => { await accessSecretStorage(async () => {
await cli.checkOwnCrossSigningTrust(); await cli.checkOwnCrossSigningTrust();
if (backupInfo) await cli.restoreKeyBackupWithSecretStorage(backupInfo);
}); });
if (cli.getCrossSigningId()) { if (cli.getCrossSigningId()) {
@ -66,6 +74,9 @@ export default class CompleteSecurity extends React.Component {
} }
} catch (e) { } catch (e) {
// this will throw if the user hits cancel, so ignore // this will throw if the user hits cancel, so ignore
this.setState({
phase: PHASE_INTRO,
});
} }
} }
@ -155,13 +166,21 @@ export default class CompleteSecurity extends React.Component {
} else if (phase === PHASE_DONE) { } else if (phase === PHASE_DONE) {
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_verified"></span>; icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_verified"></span>;
title = _t("Session verified"); title = _t("Session verified");
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>;
}
body = ( body = (
<div> <div>
<div className="mx_CompleteSecurity_heroIcon mx_E2EIcon_verified"></div> <div className="mx_CompleteSecurity_heroIcon mx_E2EIcon_verified"></div>
<p>{_t( {message}
"Your new session is now verified. It has access to your " +
"encrypted messages, and other users will see it as trusted.",
)}</p>
<div className="mx_CompleteSecurity_actionRow"> <div className="mx_CompleteSecurity_actionRow">
<AccessibleButton <AccessibleButton
kind="primary" kind="primary"
@ -198,6 +217,11 @@ export default class CompleteSecurity extends React.Component {
</div> </div>
</div> </div>
); );
} else if (phase === PHASE_BUSY) {
const Spinner = sdk.getComponent('views.elements.Spinner');
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning"></span>;
title = '';
body = <Spinner />;
} else { } else {
throw new Error(`Unknown phase ${phase}`); throw new Error(`Unknown phase ${phase}`);
} }

View file

@ -1912,6 +1912,7 @@
"Start": "Start", "Start": "Start",
"Session verified": "Session verified", "Session verified": "Session verified",
"Your new session is now verified. It has access to your encrypted messages, and other users will see it as trusted.": "Your new session is now verified. It has access to your encrypted messages, and other users will see it as trusted.", "Your new session is now verified. It has access to your encrypted messages, and other users will see it as trusted.": "Your new session is now verified. It has access to your encrypted messages, and other users will see it as trusted.",
"Your new session is now verified. Other users will see it as trusted.": "Your new session is now verified. Other users will see it as trusted.",
"Done": "Done", "Done": "Done",
"Without completing security on this device, it wont have access to encrypted messages.": "Without completing security on this device, it wont have access to encrypted messages.", "Without completing security on this device, it wont have access to encrypted messages.": "Without completing security on this device, it wont have access to encrypted messages.",
"Go Back": "Go Back", "Go Back": "Go Back",