Skip to content

Commit 810f714

Browse files
authored
Remove legacy crypto (#4653)
* Remove deprecated calls in `webrtc/call.ts` * Throw error when legacy call was used * Remove `MatrixClient.initLegacyCrypto` (#4620) * Remove `MatrixClient.initLegacyCrypto` * Remove `MatrixClient.initLegacyCrypto` in README.md * Remove tests using `MatrixClient.initLegacyCrypto` * Remove legacy crypto support in `sync` api (#4622) * Remove deprecated `DeviceInfo` in `webrtc/call.ts` (#4654) * chore(legacy call): Remove `DeviceInfo` usage * refactor(legacy call): throw `GroupCallUnknownDeviceError` at the end of `initOpponentCrypto` * Remove deprecated methods and attributes of `MatrixClient` (#4659) * feat(legacy crypto)!: remove deprecated methods of `MatrixClient` * test(legacy crypto): update existing tests to not use legacy crypto - `Embedded.spec.ts`: casting since `encryptAndSendToDevices` is removed from `MatrixClient`. - `room.spec.ts`: remove deprecated usage of `MatrixClient.crypto` - `matrix-client.spec.ts` & `matrix-client-methods.spec.ts`: remove calls of deprecated methods of `MatrixClient` * test(legacy crypto): remove test files using `MatrixClient` deprecated methods * test(legacy crypto): update existing integ tests to run successfully * feat(legacy crypto!): remove `ICreateClientOpts.deviceToImport`. `ICreateClientOpts.deviceToImport` was used in the legacy cryto. The rust crypto doesn't support to import devices in this way. * feat(legacy crypto!): remove `{get,set}GlobalErrorOnUnknownDevices` `globalErrorOnUnknownDevices` is not used in the rust-crypto. The API is marked as unstable, we can remove it. * Remove usage of legacy crypto in `event.ts` (#4666) * feat(legacy crypto!): remove legacy crypto usage in `event.ts` * test(legacy crypto): update event.spec.ts to not use legacy crypto types * Remove legacy crypto export in `matrix.ts` (#4667) * feat(legacy crypto!): remove legacy crypto export in `matrix.ts` * test(legacy crypto): update `megolm-backup.spec.ts` to import directly `CryptoApi` * Remove usage of legacy crypto in integ tests (#4669) * Clean up legacy stores (#4663) * feat(legacy crypto!): keep legacy methods used in lib olm migration The rust cryto needs these legacy stores in order to do the migration from the legacy crypto to the rust crypto. We keep the following methods of the stores: - Used in `libolm_migration.ts`. - Needed in the legacy store tests. - Needed in the rust crypto test migration. * feat(legacy crypto): extract legacy crypto types in legacy stores In order to be able to delete the legacy crypto, these stores shouldn't rely on the legacy crypto. We need to extract the used types. * feat(crypto store): remove `CryptoStore` functions used only by tests * test(crypto store): use legacy `MemoryStore` type * Remove deprecated methods of `CryptoBackend` (#4671) * feat(CryptoBackend)!: remove deprecated methods * feat(rust-crypto)!: remove deprecated methods of `CryptoBackend` * test(rust-crypto): remove tests of deprecated methods of `CryptoBackend` * Remove usage of legacy crypto in `embedded.ts` (#4668) The interface of `encryptAndSendToDevices` changes because `DeviceInfo` is from the legacy crypto. In fact `encryptAndSendToDevices` only need pairs of userId and deviceId. * Remove legacy crypto files (#4672) * fix(legacy store): fix legacy store typing In #4663, the storeXXX methods were removed of the CryptoStore interface but they are used internally by IndexedDBCryptoStore. * feat(legacy crypto)!: remove content of `crypto/*` except legacy stores * test(legacy crypto): remove `spec/unit/crypto/*` except legacy store tests * refactor: remove unused types * doc: fix broken link * doc: remove link tag when typedoc is unable to find the CryptoApi * Clean up integ test after legacy crypto removal (#4682) * test(crypto): remove `newBackendOnly` test closure * test(crypto): fix duplicate test name * test(crypto): remove `oldBackendOnly` test closure * test(crypto): remove `rust-sdk` comparison * test(crypto): remove iteration on `CRYPTO_BACKEND` * test(crypto): remove old legacy comments and tests * test(crypto): fix documentations and removed unused expect * Restore broken link to `CryptoApi` (#4692) * chore: fix linting and formatting due to merge * Remove unused crypto type and missing doc (#4696) * chore(crypto): remove unused types * doc(crypto): add missing link * test(call): add test when crypto is enabled
1 parent 6b93e11 commit 810f714

File tree

92 files changed

+676
-31836
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+676
-31836
lines changed

Diff for: .eslintrc.cjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ module.exports = {
8686
// Disabled tests are a reality for now but as soon as all of the xits are
8787
// eliminated, we should enforce this.
8888
"jest/no-disabled-tests": "off",
89-
// Also treat "oldBackendOnly" as a test function.
9089
// Used in some crypto tests.
9190
"jest/no-standalone-expect": [
9291
"error",
9392
{
94-
additionalTestBlockFunctions: ["beforeAll", "beforeEach", "oldBackendOnly", "newBackendOnly"],
93+
additionalTestBlockFunctions: ["beforeAll", "beforeEach"],
9594
},
9695
],
9796
},

Diff for: README.md

-2
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ Then visit `http://localhost:8005` to see the API docs.
307307

308308
## Initialization
309309

310-
**Do not use `matrixClient.initLegacyCrypto()`. This method is deprecated and no longer maintained.**
311-
312310
To initialize the end-to-end encryption support in the matrix client:
313311

314312
```javascript

Diff for: spec/TestClient.ts

-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import MockHttpBackend from "matrix-mock-request";
2626

2727
import type { IDeviceKeys, IOneTimeKey } from "../src/@types/crypto";
2828
import type { IE2EKeyReceiver } from "./test-utils/E2EKeyReceiver";
29-
import { LocalStorageCryptoStore } from "../src/crypto/store/localStorage-crypto-store";
3029
import { logger } from "../src/logger";
3130
import { syncPromise } from "./test-utils/test-utils";
3231
import { createClient, type IStartClientOpts } from "../src/matrix";
@@ -36,7 +35,6 @@ import {
3635
type MatrixClient,
3736
PendingEventOrdering,
3837
} from "../src/client";
39-
import { MockStorageApi } from "./MockStorageApi";
4038
import { type IKeysUploadResponse, type IUploadKeysRequest } from "../src/client";
4139
import { type ISyncResponder } from "./test-utils/SyncResponder";
4240

@@ -60,10 +58,6 @@ export class TestClient implements IE2EKeyReceiver, ISyncResponder {
6058
sessionStoreBackend?: Storage,
6159
options?: Partial<ICreateClientOpts>,
6260
) {
63-
if (sessionStoreBackend === undefined) {
64-
sessionStoreBackend = new MockStorageApi() as unknown as Storage;
65-
}
66-
6761
this.httpBackend = new MockHttpBackend();
6862

6963
const fullOptions: ICreateClientOpts = {
@@ -74,10 +68,6 @@ export class TestClient implements IE2EKeyReceiver, ISyncResponder {
7468
fetchFn: this.httpBackend.fetchFn as typeof globalThis.fetch,
7569
...options,
7670
};
77-
if (!fullOptions.cryptoStore) {
78-
// expose this so the tests can get to it
79-
fullOptions.cryptoStore = new LocalStorageCryptoStore(sessionStoreBackend);
80-
}
8171
this.client = createClient(fullOptions);
8272

8373
this.deviceKeys = null;

Diff for: spec/integ/crypto/cross-signing.spec.ts

+8-15
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import fetchMock from "fetch-mock-jest";
1818
import "fake-indexeddb/auto";
1919
import { IDBFactory } from "fake-indexeddb";
2020

21-
import { CRYPTO_BACKENDS, type InitCrypto, syncPromise } from "../../test-utils/test-utils";
22-
import { type AuthDict, createClient, CryptoEvent, type MatrixClient } from "../../../src";
21+
import { syncPromise } from "../../test-utils/test-utils";
22+
import { type AuthDict, createClient, type MatrixClient } from "../../../src";
2323
import { mockInitialApiRequests, mockSetupCrossSigningRequests } from "../../test-utils/mockEndpoints";
2424
import encryptAESSecretStorageItem from "../../../src/utils/encryptAESSecretStorageItem.ts";
2525
import { type CryptoCallbacks, CrossSigningKey } from "../../../src/crypto-api";
@@ -37,6 +37,7 @@ import {
3737
import * as testData from "../../test-utils/test-data";
3838
import { E2EKeyResponder } from "../../test-utils/E2EKeyResponder";
3939
import { AccountDataAccumulator } from "../../test-utils/AccountDataAccumulator";
40+
import { CryptoEvent } from "../../../src/crypto-api";
4041

4142
afterEach(() => {
4243
// reset fake-indexeddb after each test, to make sure we don't leak connections
@@ -54,11 +55,7 @@ const TEST_DEVICE_ID = "xzcvb";
5455
* These tests work by intercepting HTTP requests via fetch-mock rather than mocking out bits of the client, so as
5556
* to provide the most effective integration tests possible.
5657
*/
57-
describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: string, initCrypto: InitCrypto) => {
58-
// newBackendOnly is the opposite to `oldBackendOnly`: it will skip the test if we are running against the legacy
59-
// backend. Once we drop support for legacy crypto, it will go away.
60-
const newBackendOnly = backend === "rust-sdk" ? test : test.skip;
61-
58+
describe("cross-signing", () => {
6259
let aliceClient: MatrixClient;
6360

6461
/** an object which intercepts `/sync` requests from {@link #aliceClient} */
@@ -107,7 +104,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
107104
body: { errcode: "M_NOT_FOUND" },
108105
});
109106

110-
await initCrypto(aliceClient);
107+
await aliceClient.initRustCrypto();
111108
},
112109
/* it can take a while to initialise the crypto library on the first pass, so bump up the timeout. */
113110
10000,
@@ -162,7 +159,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
162159
);
163160
});
164161

165-
newBackendOnly("get cross signing keys from secret storage and import them", async () => {
162+
it("get cross signing keys from secret storage and import them", async () => {
166163
// Return public cross signing keys
167164
e2eKeyResponder.addCrossSigningData(SIGNED_CROSS_SIGNING_KEYS_DATA);
168165

@@ -263,7 +260,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
263260
expect(calls.length).toEqual(0);
264261
});
265262

266-
newBackendOnly("will upload existing cross-signing keys to an established secret storage", async () => {
263+
it("will upload existing cross-signing keys to an established secret storage", async () => {
267264
// This rather obscure codepath covers the case that:
268265
// - 4S is set up and working
269266
// - our device has private cross-signing keys, but has not published them to 4S
@@ -420,9 +417,8 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
420417
function awaitCrossSigningKeysUpload() {
421418
return new Promise<any>((resolve) => {
422419
fetchMock.post(
423-
// legacy crypto uses /unstable/; /v3/ is correct
424420
{
425-
url: new RegExp("/_matrix/client/(unstable|v3)/keys/device_signing/upload"),
421+
url: new RegExp("/_matrix/client/v3/keys/device_signing/upload"),
426422
name: "upload-keys",
427423
},
428424
(url, options) => {
@@ -475,9 +471,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
475471
await aliceClient.startClient();
476472
await syncPromise(aliceClient);
477473

478-
// Wait for legacy crypto to find the device
479-
await jest.advanceTimersByTimeAsync(10);
480-
481474
const devices = await aliceClient.getCrypto()!.getUserDeviceInfo([aliceClient.getSafeUserId()]);
482475
expect(devices.get(aliceClient.getSafeUserId())!.has(testData.TEST_DEVICE_ID)).toBeTruthy();
483476
});

0 commit comments

Comments
 (0)