Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Cleanup tasks in SecurityManager/SetupEncryptionStore (#12764)
Browse files Browse the repository at this point in the history
* Remove call to no-op `checkOwnCrossSigningTrust`

this is a no-op on rust crypto

* inline `SecurityManager.isCachingAllowed`

Since #4789, this has just
been an obscure way to write a test of a local variable.

* Remove unused `CreateSecretStorageOpts.getKeyBackupPassphrase` parameter

This is unused on rust crypto (cf matrix-org/matrix-js-sdk#4313)
  • Loading branch information
richvdh authored Jul 13, 2024
1 parent db95f26 commit 3480001
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 53 deletions.
39 changes: 5 additions & 34 deletions src/SecurityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { MatrixClientPeg } from "./MatrixClientPeg";
import { _t } from "./languageHandler";
import { isSecureBackupRequired } from "./utils/WellKnownUtils";
import AccessSecretStorageDialog, { KeyParams } from "./components/views/dialogs/security/AccessSecretStorageDialog";
import RestoreKeyBackupDialog from "./components/views/dialogs/security/RestoreKeyBackupDialog";
import SettingsStore from "./settings/SettingsStore";
import { ModuleRunner } from "./modules/ModuleRunner";
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
Expand All @@ -45,10 +44,6 @@ let dehydrationCache: {
keyInfo?: SecretStorage.SecretStorageKeyDescription;
} = {};

function isCachingAllowed(): boolean {
return secretStorageBeingAccessed;
}

/**
* This can be used by other components to check if secret storage access is in
* progress, so that we can e.g. avoid intermittently showing toasts during
Expand Down Expand Up @@ -118,7 +113,7 @@ async function getSecretStorageKey({
}

// Check the in-memory cache
if (isCachingAllowed() && secretStorageKeys[keyId]) {
if (secretStorageBeingAccessed && secretStorageKeys[keyId]) {
return [keyId, secretStorageKeys[keyId]];
}

Expand Down Expand Up @@ -226,7 +221,7 @@ function cacheSecretStorageKey(
keyInfo: SecretStorage.SecretStorageKeyDescription,
key: Uint8Array,
): void {
if (isCachingAllowed()) {
if (secretStorageBeingAccessed) {
secretStorageKeys[keyId] = key;
secretStorageKeyInfo[keyId] = keyInfo;
}
Expand Down Expand Up @@ -278,26 +273,6 @@ export const crossSigningCallbacks: ICryptoCallbacks = {
getDehydrationKey,
};

export async function promptForBackupPassphrase(): Promise<Uint8Array> {
let key!: Uint8Array;

const { finished } = Modal.createDialog(
RestoreKeyBackupDialog,
{
showSummary: false,
keyCallback: (k: Uint8Array) => (key = k),
},
undefined,
/* priority = */ false,
/* static = */ true,
);

const success = await finished;
if (!success) throw new Error("Key backup prompt cancelled");

return key;
}

/**
* Carry out an operation that may require multiple accesses to secret storage, caching the key.
*
Expand All @@ -313,10 +288,8 @@ export async function withSecretStorageKeyCache<T>(func: () => Promise<T>): Prom
} finally {
// Clear secret storage key cache now that work is complete
secretStorageBeingAccessed = false;
if (!isCachingAllowed()) {
secretStorageKeys = {};
secretStorageKeyInfo = {};
}
secretStorageKeys = {};
secretStorageKeyInfo = {};
}
}

Expand Down Expand Up @@ -395,9 +368,7 @@ async function doAccessSecretStorage(func: () => Promise<void>, forceReset: bool
}
},
});
await crypto.bootstrapSecretStorage({
getKeyBackupPassphrase: promptForBackupPassphrase,
});
await crypto.bootstrapSecretStorage({});

const keyId = Object.keys(secretStorageKeys)[0];
if (keyId && SettingsStore.getValue("feature_dehydration")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { BackupTrustInfo, GeneratedSecretStorageKey, KeyBackupInfo } from "matri
import { MatrixClientPeg } from "../../../../MatrixClientPeg";
import { _t, _td } from "../../../../languageHandler";
import Modal from "../../../../Modal";
import { promptForBackupPassphrase } from "../../../../SecurityManager";
import { copyNode } from "../../../../utils/strings";
import { SSOAuthEntry } from "../../../../components/views/auth/InteractiveAuthEntryComponents";
import PassphraseField from "../../../../components/views/auth/PassphraseField";
Expand Down Expand Up @@ -123,7 +122,6 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
forceReset: false,
};
private recoveryKey?: GeneratedSecretStorageKey;
private backupKey?: Uint8Array;
private recoveryKeyNode = createRef<HTMLElement>();
private passphraseField = createRef<Field>();

Expand Down Expand Up @@ -384,15 +382,6 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
createSecretStorageKey: async () => this.recoveryKey!,
keyBackupInfo: this.state.backupInfo!,
setupNewKeyBackup: !this.state.backupInfo,
getKeyBackupPassphrase: async (): Promise<Uint8Array> => {
// We may already have the backup key if we earlier went
// through the restore backup path, so pass it along
// rather than prompting again.
if (this.backupKey) {
return this.backupKey;
}
return promptForBackupPassphrase();
},
});
}
await initialiseDehydration(true);
Expand Down Expand Up @@ -424,11 +413,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
};

private restoreBackup = async (): Promise<void> => {
// It's possible we'll need the backup key later on for bootstrapping,
// so let's stash it here, rather than prompting for it twice.
const keyCallback = (k: Uint8Array): void => {
this.backupKey = k;
};
const keyCallback = (k: Uint8Array): void => {};

const { finished } = Modal.createDialog(
RestoreKeyBackupDialog,
Expand Down
2 changes: 0 additions & 2 deletions src/stores/SetupEncryptionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ export class SetupEncryptionStore extends EventEmitter {
// in the background.
await new Promise((resolve: (value?: unknown) => void, reject: (reason?: any) => void) => {
accessSecretStorage(async (): Promise<void> => {
await cli.checkOwnCrossSigningTrust();

// The remaining tasks (device dehydration and restoring
// key backup) may take some time due to processing many
// to-device messages in the case of device dehydration, or
Expand Down
1 change: 0 additions & 1 deletion test/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export function createTestClient(): MatrixClient {
bootstrapCrossSigning: jest.fn(),
hasSecretStorageKey: jest.fn(),
getKeyBackupVersion: jest.fn(),
checkOwnCrossSigningTrust: jest.fn(),

secretStorage: {
get: jest.fn(),
Expand Down

0 comments on commit 3480001

Please sign in to comment.