Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule dehydration on reload #29021

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/MatrixClientPeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,16 @@ class MatrixClientPegClass implements IMatrixClientPeg {

setDeviceIsolationMode(this.matrixClient, SettingsStore.getValue("feature_exclude_insecure_devices"));

// TODO: device dehydration and whathaveyou
// Start dehydration. This code is only for the case where the client
// gets restarted, so we only do this if we already have the dehydration
// key cached, and we don't have to try to rehydrate a device. If this
// is a new login, we will start dehydration after Secret Storage is
// unlocked.
const crypto = this.matrixClient.getCrypto();
if (await crypto?.isDehydrationSupported()) {
await crypto!.startDehydration({ onlyIfKeyCached: true, rehydrate: false });
}

return;
}

Expand Down
7 changes: 7 additions & 0 deletions test/unit-tests/MatrixClientPeg-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ describe("MatrixClientPeg", () => {

it("should initialise the rust crypto library by default", async () => {
const mockInitRustCrypto = jest.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined);
const mockStartDehydration = jest.fn();
jest.spyOn(testPeg.safeGet(), "getCrypto").mockReturnValue({
isDehydrationSupported: jest.fn().mockResolvedValue(true),
startDehydration: mockStartDehydration,
setDeviceIsolationMode: jest.fn(),
} as any);

const cryptoStoreKey = new Uint8Array([1, 2, 3, 4]);
await testPeg.start({ rustCryptoStoreKey: cryptoStoreKey });
expect(mockInitRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
expect(mockStartDehydration).toHaveBeenCalledWith({ onlyIfKeyCached: true, rehydrate: false });
});

it("Should migrate existing login", async () => {
Expand Down
2 changes: 2 additions & 0 deletions test/unit-tests/components/structures/MatrixChat-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe("<MatrixChat />", () => {
getCrypto: jest.fn().mockReturnValue({
getVerificationRequestsToDeviceInProgress: jest.fn().mockReturnValue([]),
isCrossSigningReady: jest.fn().mockReturnValue(false),
isDehydrationSupported: jest.fn().mockReturnValue(false),
getUserDeviceInfo: jest.fn().mockReturnValue(new Map()),
getUserVerificationStatus: jest.fn().mockResolvedValue(new UserVerificationStatus(false, false, false)),
getVersion: jest.fn().mockReturnValue("1"),
Expand Down Expand Up @@ -1006,6 +1007,7 @@ describe("<MatrixChat />", () => {
resetKeyBackup: jest.fn(),
isEncryptionEnabledInRoom: jest.fn().mockResolvedValue(false),
checkKeyBackupAndEnable: jest.fn().mockResolvedValue(null),
isDehydrationSupported: jest.fn().mockReturnValue(false),
};
loginClient.getCrypto.mockReturnValue(mockCrypto as any);
});
Expand Down
Loading