Prompt for recovery key on login rather than passphrase

Only show passphrase options at all if the user has a passphrase on
their SSSS key.
This commit is contained in:
David Baker 2020-06-02 16:32:15 +01:00
parent 631184c661
commit e06ba2003b
9 changed files with 224 additions and 20 deletions

View file

@ -30,6 +30,8 @@ import {encodeBase64} from "matrix-js-sdk/src/crypto/olmlib";
// operation ends.
let secretStorageKeys = {};
let secretStorageBeingAccessed = false;
// Stores the 'passphraseOnly' option for the active storage access operation
let passphraseOnlyOption = null;
function isCachingAllowed() {
return (
@ -99,6 +101,7 @@ async function getSecretStorageKey({ keys: keyInfos }, ssssItemName) {
const key = await inputToKey(input);
return await MatrixClientPeg.get().checkSecretStorageKey(key, info);
},
passphraseOnly: passphraseOnlyOption,
},
/* className= */ null,
/* isPriorityModal= */ false,
@ -213,19 +216,27 @@ export async function promptForBackupPassphrase() {
*
* @param {Function} [func] An operation to perform once secret storage has been
* bootstrapped. Optional.
* @param {bool} [forceReset] Reset secret storage even if it's already set up
* @param {object} [opts] Named options
* @param {bool} [opts.forceReset] Reset secret storage even if it's already set up
* @param {object} [opts.withKeys] Map of key ID to key for SSSS keys that the client
* already has available. If a key is not supplied here, the user will be prompted.
* @param {bool} [opts.passphraseOnly] If true, do not prompt for recovery key or to reset keys
*/
export async function accessSecretStorage(func = async () => { }, forceReset = false) {
export async function accessSecretStorage(
func = async () => { }, opts = {},
) {
const cli = MatrixClientPeg.get();
secretStorageBeingAccessed = true;
passphraseOnlyOption = opts.passphraseOnly;
secretStorageKeys = Object.assign({}, opts.withKeys || {});
try {
if (!await cli.hasSecretStorageKey() || forceReset) {
if (!await cli.hasSecretStorageKey() || opts.forceReset) {
// This dialog calls bootstrap itself after guiding the user through
// passphrase creation.
const { finished } = Modal.createTrackedDialogAsync('Create Secret Storage dialog', '',
import("./async-components/views/dialogs/secretstorage/CreateSecretStorageDialog"),
{
force: forceReset,
force: opts.forceReset,
},
null, /* priority = */ false, /* static = */ true,
);
@ -263,5 +274,6 @@ export async function accessSecretStorage(func = async () => { }, forceReset = f
if (!isCachingAllowed()) {
secretStorageKeys = {};
}
passphraseOnlyOption = null;
}
}