You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-24 06:02:08 +03:00
Element-R: pass pickleKey in as raw key for indexeddb encryption (#12543)
* Element-R: pass pickleKey in as raw key for indexeddb encryption Currently, we pass the `pickleKey` to the rust library for use as a passphrase for encrypting its crypto store. The Rust libary then passes that passphrase through 200000 rounds of PBKDF2 to generate an encryption key, which is (deliberately) slow. However, the pickleKey is actually 32 bytes of random data (base64-encoded). By passing the raw key into the rust library, we can therefore save the PBKDF operation. Backwards-compatibility with existing sessions is maintained, because if the rust library discovers that the store was previously encrypted with a key based on a PBKDF, it will re-base64 and PBKDF the key we provide, thus reconstructing the right key. * Update src/Lifecycle.ts Co-authored-by: Florian Duros <florianduros@element.io> * Lifecycle-test: clean up test setup Rely less on the unit under test for setting up the test preconditions -- not least because we don't really want to fire up matrix clients and the like during test setup. * Factor out "encryptPickleKey" method For a start it makes it easier to grok what's going on, but also I went to use this in a test * Improve tests for `Lifecycle.restoreFromLocalStorage` --------- Co-authored-by: Florian Duros <florianduros@element.io>
This commit is contained in:
committed by
GitHub
parent
5004456d82
commit
0a01320fca
@ -217,7 +217,7 @@ describe("MatrixClientPeg", () => {
|
||||
testPeg.safeGet().store.on = emitter.on.bind(emitter);
|
||||
const platform: any = { reload: jest.fn() };
|
||||
PlatformPeg.set(platform);
|
||||
await testPeg.assign();
|
||||
await testPeg.assign({});
|
||||
emitter.emit("closed" as any);
|
||||
expect(platform.reload).toHaveBeenCalled();
|
||||
});
|
||||
@ -229,7 +229,7 @@ describe("MatrixClientPeg", () => {
|
||||
PlatformPeg.set(platform);
|
||||
testPeg.safeGet().store.on = emitter.on.bind(emitter);
|
||||
const spy = jest.spyOn(Modal, "createDialog");
|
||||
await testPeg.assign();
|
||||
await testPeg.assign({});
|
||||
emitter.emit("closed" as any);
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
@ -243,9 +243,10 @@ describe("MatrixClientPeg", () => {
|
||||
const mockInitCrypto = jest.spyOn(testPeg.safeGet(), "initCrypto").mockResolvedValue(undefined);
|
||||
const mockInitRustCrypto = jest.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined);
|
||||
|
||||
await testPeg.start();
|
||||
const cryptoStoreKey = new Uint8Array([1, 2, 3, 4]);
|
||||
await testPeg.start({ rustCryptoStoreKey: cryptoStoreKey });
|
||||
expect(mockInitCrypto).not.toHaveBeenCalled();
|
||||
expect(mockInitRustCrypto).toHaveBeenCalledTimes(1);
|
||||
expect(mockInitRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
|
||||
|
||||
// we should have stashed the setting in the settings store
|
||||
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
|
||||
@ -271,7 +272,7 @@ describe("MatrixClientPeg", () => {
|
||||
|
||||
await testPeg.start();
|
||||
expect(mockInitCrypto).toHaveBeenCalled();
|
||||
expect(mockInitRustCrypto).not.toHaveBeenCalledTimes(1);
|
||||
expect(mockInitRustCrypto).not.toHaveBeenCalled();
|
||||
|
||||
// we should have stashed the setting in the settings store
|
||||
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, false);
|
||||
|
Reference in New Issue
Block a user