Skip to content

Commit 9095ebd

Browse files
uhoregrichvdh
andauthored
Avoid using accessSecretStorage to create 4S (#30244)
* remove resetCrossSigning flag, which is no longer in use * drop unnecessary check for cross-signing The only place where verifyUser is called already checks that cross-signing is set up. (The function name is also incorrect, since it checks for the cross-signing key, and not for 4S.) * avoid calling accessSecretStorage to set up cross-signing or 4S Send the user to the Encryption settings tab instead * only create secret storage when specifically asked to * deprecate using accessSecretStorage to create new 4S * also remove the obsolete snapshot * add tests * Tweak comment Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
1 parent 66d7c6a commit 9095ebd

17 files changed

Lines changed: 87 additions & 651 deletions

File tree

res/css/_components.pcss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@
177177
@import "./views/dialogs/_WidgetCapabilitiesPromptDialog.pcss";
178178
@import "./views/dialogs/security/_AccessSecretStorageDialog.pcss";
179179
@import "./views/dialogs/security/_CreateCrossSigningDialog.pcss";
180-
@import "./views/dialogs/security/_CreateKeyBackupDialog.pcss";
181180
@import "./views/dialogs/security/_CreateSecretStorageDialog.pcss";
182181
@import "./views/dialogs/security/_KeyBackupFailedDialog.pcss";
183182
@import "./views/dialogs/security/_RestoreKeyBackupDialog.pcss";

res/css/views/dialogs/security/_CreateKeyBackupDialog.pcss

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/SecurityManager.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,11 @@ export async function withSecretStorageKeyCache<T>(func: () => Promise<T>): Prom
176176
}
177177

178178
export interface AccessSecretStorageOpts {
179-
/** Reset secret storage even if it's already set up. */
179+
/**
180+
* Reset secret storage even if it's already set up.
181+
* @deprecated send the user to the Encryption settings tab to reset secret storage
182+
*/
180183
forceReset?: boolean;
181-
/** Create new cross-signing keys. Only applicable if `forceReset` is `true`. */
182-
resetCrossSigning?: boolean;
183184
}
184185

185186
/**
@@ -189,8 +190,8 @@ export interface AccessSecretStorageOpts {
189190
* provided function.
190191
*
191192
* Bootstrapping secret storage may take one of these paths:
192-
* 1. Create secret storage from a passphrase and store cross-signing keys
193-
* in secret storage.
193+
* 1. (Only if `opts.forceReset` is set) create secret storage from a passphrase
194+
* and store cross-signing keys in secret storage.
194195
* 2. Access existing secret storage by requesting passphrase and accessing
195196
* cross-signing keys as needed.
196197
* 3. All keys are loaded and there's nothing to do.
@@ -199,6 +200,8 @@ export interface AccessSecretStorageOpts {
199200
* to ensure the user is prompted only once for their secret storage
200201
* passphrase. The cache is then cleared once the provided function completes.
201202
*
203+
* Throws an error if secret storage is not set up (and `opts.forceReset` is not set)
204+
*
202205
* @param {Function} [func] An operation to perform once secret storage has been
203206
* bootstrapped. Optional.
204207
* @param [opts] The options to use when accessing secret storage.
@@ -219,16 +222,8 @@ async function doAccessSecretStorage(func: () => Promise<void>, opts: AccessSecr
219222
throw new Error("End-to-end encryption is disabled - unable to access secret storage.");
220223
}
221224

222-
let createNew = false;
223225
if (opts.forceReset) {
224226
logger.debug("accessSecretStorage: resetting 4S");
225-
createNew = true;
226-
} else if (!(await cli.secretStorage.hasKey())) {
227-
logger.debug("accessSecretStorage: no 4S key configured, creating a new one");
228-
createNew = true;
229-
}
230-
231-
if (createNew) {
232227
// This dialog calls bootstrap itself after guiding the user through
233228
// passphrase creation.
234229
const { finished } = Modal.createDialog(
@@ -251,6 +246,9 @@ async function doAccessSecretStorage(func: () => Promise<void>, opts: AccessSecr
251246
if (!confirmed) {
252247
throw new Error("Secret storage creation canceled");
253248
}
249+
} else if (!(await cli.secretStorage.hasKey())) {
250+
logger.debug("accessSecretStorage: no 4S key configured");
251+
throw new Error("Secret storage has not been created yet.");
254252
} else {
255253
logger.debug("accessSecretStorage: bootstrapCrossSigning");
256254
await crypto.bootstrapCrossSigning({

src/async-components/views/dialogs/security/CreateKeyBackupDialog.tsx

Lines changed: 0 additions & 186 deletions
This file was deleted.

src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const PASSWORD_MIN_SCORE = 4; // So secure, many characters, much complex, wow,
5656

5757
interface IProps {
5858
forceReset?: boolean;
59-
resetCrossSigning?: boolean;
6059
onFinished(ok?: boolean): void;
6160
}
6261

@@ -80,11 +79,12 @@ interface IState {
8079
* If the user already has a key backup, follows a "migration" flow (aka "Upgrade your encryption") which
8180
* prompts the user to enter their backup decryption password (a Curve25519 private key, possibly derived
8281
* from a passphrase), and uses that as the (AES) 4S encryption key.
82+
*
83+
* @deprecated send the user to EncryptionUserSettingsTab instead
8384
*/
8485
export default class CreateSecretStorageDialog extends React.PureComponent<IProps, IState> {
8586
public static defaultProps: Partial<IProps> = {
8687
forceReset: false,
87-
resetCrossSigning: false,
8888
};
8989
private recoveryKey?: GeneratedSecretStorageKey;
9090
private recoveryKeyNode = createRef<HTMLElement>();
@@ -211,7 +211,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
211211
private bootstrapSecretStorage = async (): Promise<void> => {
212212
const cli = MatrixClientPeg.safeGet();
213213
const crypto = cli.getCrypto()!;
214-
const { forceReset, resetCrossSigning } = this.props;
214+
const { forceReset } = this.props;
215215

216216
let backupInfo;
217217
// First, unless we know we want to do a reset, we see if there is an existing key backup
@@ -246,13 +246,6 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
246246
createSecretStorageKey: async () => this.recoveryKey!,
247247
setupNewSecretStorage: true,
248248
});
249-
if (resetCrossSigning) {
250-
logger.log("Resetting cross signing");
251-
await crypto.bootstrapCrossSigning({
252-
authUploadDeviceSigningKeys: this.doBootstrapUIAuth,
253-
setupNewCrossSigning: true,
254-
});
255-
}
256249
logger.log("Resetting key backup");
257250
await crypto.resetKeyBackup();
258251
} else {

0 commit comments

Comments
 (0)