Add support for device dehydration v2 (#12316)
* rehydrate/dehydrate device if configured in well-known * add handling for dehydrated devices * some fixes * schedule dehydration * improve display of own dehydrated device * created dehydrated device when creating or resetting SSSS * some UI tweaks * reorder strings * lint * remove statement for testing * add playwright test * lint and fix broken test * update to new dehydration API * some fixes from review * try to fix test error * remove unneeded debug line * apply changes from review * add Jest tests * fix typo Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> * don't need Object.assign Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
6392759bec
commit
31373399f9
18 changed files with 823 additions and 8 deletions
|
@ -40,9 +40,12 @@ describe("SetupEncryptionStore", () => {
|
|||
client = mocked(stubClient());
|
||||
mockCrypto = {
|
||||
bootstrapCrossSigning: jest.fn(),
|
||||
getCrossSigningKeyId: jest.fn(),
|
||||
getVerificationRequestsToDeviceInProgress: jest.fn().mockReturnValue([]),
|
||||
getUserDeviceInfo: jest.fn(),
|
||||
getDeviceVerificationStatus: jest.fn(),
|
||||
isDehydrationSupported: jest.fn().mockResolvedValue(false),
|
||||
startDehydration: jest.fn(),
|
||||
} as unknown as Mocked<CryptoApi>;
|
||||
client.getCrypto.mockReturnValue(mockCrypto);
|
||||
|
||||
|
@ -101,7 +104,7 @@ describe("SetupEncryptionStore", () => {
|
|||
expect(setupEncryptionStore.hasDevicesToVerifyAgainst).toBe(true);
|
||||
});
|
||||
|
||||
it("should ignore the dehydrated device", async () => {
|
||||
it("should ignore the MSC2697 dehydrated device", async () => {
|
||||
mockSecretStorage.isStored.mockResolvedValue({ sskeyid: {} as SecretStorageKeyDescriptionAesV1 });
|
||||
|
||||
client.getDehydratedDevice.mockResolvedValue({ device_id: "dehydrated" } as IDehydratedDevice);
|
||||
|
@ -123,6 +126,27 @@ describe("SetupEncryptionStore", () => {
|
|||
expect(mockCrypto.getDeviceVerificationStatus).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should ignore the MSC3812 dehydrated device", async () => {
|
||||
mockSecretStorage.isStored.mockResolvedValue({ sskeyid: {} as SecretStorageKeyDescriptionAesV1 });
|
||||
|
||||
const fakeDevice = new Device({
|
||||
deviceId: "dehydrated",
|
||||
userId: "",
|
||||
algorithms: [],
|
||||
keys: new Map([["curve25519:dehydrated", "identityKey"]]),
|
||||
dehydrated: true,
|
||||
});
|
||||
mockCrypto.getUserDeviceInfo.mockResolvedValue(
|
||||
new Map([[client.getSafeUserId(), new Map([[fakeDevice.deviceId, fakeDevice]])]]),
|
||||
);
|
||||
|
||||
setupEncryptionStore.start();
|
||||
await emitPromise(setupEncryptionStore, "update");
|
||||
|
||||
expect(setupEncryptionStore.hasDevicesToVerifyAgainst).toBe(false);
|
||||
expect(mockCrypto.getDeviceVerificationStatus).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should correctly handle getUserDeviceInfo() returning an empty map", async () => {
|
||||
mockSecretStorage.isStored.mockResolvedValue({ sskeyid: {} as SecretStorageKeyDescriptionAesV1 });
|
||||
mockCrypto.getUserDeviceInfo.mockResolvedValue(new Map());
|
||||
|
@ -133,6 +157,39 @@ describe("SetupEncryptionStore", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("usePassPhrase", () => {
|
||||
it("should use dehydration when enabled", async () => {
|
||||
// mocks for cross-signing and secret storage
|
||||
mockSecretStorage.isStored.mockResolvedValue({ sskeyid: {} as SecretStorageKeyDescriptionAesV1 });
|
||||
mockCrypto.getUserDeviceInfo.mockResolvedValue(new Map());
|
||||
mockCrypto.getDeviceVerificationStatus.mockResolvedValue(
|
||||
new DeviceVerificationStatus({ signedByOwner: true }),
|
||||
);
|
||||
mocked(accessSecretStorage).mockImplementation(async (func?: () => Promise<void>) => {
|
||||
await func!();
|
||||
});
|
||||
|
||||
// mocks for dehydration
|
||||
mockCrypto.isDehydrationSupported.mockResolvedValue(true);
|
||||
const dehydrationPromise = new Promise<void>((resolve) => {
|
||||
// Dehydration gets processed in the background, after
|
||||
// `usePassPhrase` returns, so we need to use a promise to make
|
||||
// sure that it is called.
|
||||
mockCrypto.startDehydration.mockImplementation(async () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
client.waitForClientWellKnown.mockResolvedValue({ "org.matrix.msc3814": true });
|
||||
|
||||
setupEncryptionStore.start();
|
||||
await emitPromise(setupEncryptionStore, "update");
|
||||
|
||||
await setupEncryptionStore.usePassPhrase();
|
||||
|
||||
await dehydrationPromise;
|
||||
});
|
||||
});
|
||||
|
||||
it("resetConfirm should work with a cached account password", async () => {
|
||||
const makeRequest = jest.fn();
|
||||
mockCrypto.bootstrapCrossSigning.mockImplementation(async (opts: IBootstrapCrossSigningOpts) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue