Skip to content

Commit f03a391

Browse files
authored
Prevent exception 'Unable to set up secret storage' (#2260)
1 parent e90f12e commit f03a391

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

spec/unit/crypto.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as olmlib from "../../src/crypto/olmlib";
1313
import { sleep } from "../../src/utils";
1414
import { CRYPTO_ENABLED } from "../../src/client";
1515
import { DeviceInfo } from "../../src/crypto/deviceinfo";
16+
import { logger } from '../../src/logger';
1617

1718
const Olm = global.Olm;
1819

@@ -400,4 +401,28 @@ describe("Crypto", function() {
400401
expect(aliceClient.sendToDevice.mock.calls[2][2]).not.toBe(txnId);
401402
});
402403
});
404+
405+
describe('Secret storage', function() {
406+
it("creates secret storage even if there is no keyInfo", async function() {
407+
jest.spyOn(logger, 'log').mockImplementation(() => {});
408+
jest.setTimeout(10000);
409+
const client = (new TestClient("@a:example.com", "dev")).client;
410+
await client.initCrypto();
411+
client.crypto.getSecretStorageKey = async () => null;
412+
client.crypto.isCrossSigningReady = async () => false;
413+
client.crypto.baseApis.uploadDeviceSigningKeys = () => null;
414+
client.crypto.baseApis.setAccountData = () => null;
415+
client.crypto.baseApis.uploadKeySignatures = () => null;
416+
client.crypto.baseApis.http.authedRequest = () => null;
417+
const createSecretStorageKey = async () => {
418+
return {
419+
keyInfo: undefined, // Returning undefined here used to cause a crash
420+
privateKey: Uint8Array.of(32, 33),
421+
};
422+
};
423+
await client.crypto.bootstrapSecretStorage({
424+
createSecretStorageKey,
425+
});
426+
});
427+
});
403428
});

src/crypto/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
920920
// secrets using it, in theory. We could move them to the new key but a)
921921
// that would mean we'd need to prompt for the old passphrase, and b)
922922
// it's not clear that would be the right thing to do anyway.
923-
const { keyInfo, privateKey } = await createSecretStorageKey();
923+
const { keyInfo = {} as IAddSecretStorageKeyOpts, privateKey } = await createSecretStorageKey();
924924
newKeyId = await createSSSS(keyInfo, privateKey);
925925
} else if (!storageExists && keyBackupInfo) {
926926
// we have an existing backup, but no SSSS

0 commit comments

Comments
 (0)