Skip to content

Commit b496601

Browse files
authored
Add an extra consistency check in bootstrapCrossSigning (#4629)
* Add an extra consistency check in `bootstrapCrossSigning` check that `importCrossSigningKeys` has actually worked * Update src/rust-crypto/CrossSigningIdentity.ts * declare type in @types, instead of in source
1 parent ce60162 commit b496601

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/@types/matrix-sdk-crypto-wasm.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ declare module "@matrix-org/matrix-sdk-crypto-wasm" {
2020
interface OlmMachine {
2121
importSecretsBundle(bundle: RustSdkCryptoJs.SecretsBundle): Promise<void>;
2222
exportSecretsBundle(): Promise<RustSdkCryptoJs.SecretsBundle>;
23+
importCrossSigningKeys(
24+
master_key?: string,
25+
self_signing_key?: string,
26+
user_signing_key?: string,
27+
): Promise<RustSdkCryptoJs.CrossSigningStatus>;
2328
}
2429

2530
interface SecretsBundle {

src/rust-crypto/CrossSigningIdentity.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,18 @@ export class CrossSigningIdentity {
8787
"bootstrapCrossSigning: Cross-signing private keys not found locally, but they are available " +
8888
"in secret storage, reading storage and caching locally",
8989
);
90-
await this.olmMachine.importCrossSigningKeys(
90+
const status = await this.olmMachine.importCrossSigningKeys(
9191
masterKeyFromSecretStorage,
9292
selfSigningKeyFromSecretStorage,
9393
userSigningKeyFromSecretStorage,
9494
);
9595

96+
// Check that `importCrossSigningKeys` worked correctly (for example, it will fail silently if the
97+
// public keys are not available).
98+
if (!status.hasMaster || !status.hasSelfSigning || !status.hasUserSigning) {
99+
throw new Error("importCrossSigningKeys failed to import the keys");
100+
}
101+
96102
// Get the current device
97103
const device: RustSdkCryptoJs.Device = await this.olmMachine.getDevice(
98104
this.olmMachine.userId,

0 commit comments

Comments
 (0)