From 030cc032301f24e7782ec994004fb48e76183039 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Thu, 16 Jan 2025 17:47:00 +0100 Subject: [PATCH] Remove legacy crypto support in `sync` api --- spec/integ/sliding-sync-sdk.spec.ts | 62 +---------------------------- src/client.ts | 1 - src/sliding-sync-sdk.ts | 52 ------------------------ src/sync.ts | 26 ------------ 4 files changed, 1 insertion(+), 140 deletions(-) diff --git a/spec/integ/sliding-sync-sdk.spec.ts b/spec/integ/sliding-sync-sdk.spec.ts index 643f4f7e1ba..1865e17e344 100644 --- a/spec/integ/sliding-sync-sdk.spec.ts +++ b/spec/integ/sliding-sync-sdk.spec.ts @@ -117,18 +117,13 @@ describe("SlidingSyncSdk", () => { }; // assign client/httpBackend globals - const setupClient = async (testOpts?: Partial) => { + const setupClient = async (testOpts?: Partial) => { testOpts = testOpts || {}; const syncOpts: SyncApiOptions = {}; const testClient = new TestClient(selfUserId, "DEVICE", selfAccessToken); httpBackend = testClient.httpBackend; client = testClient.client; mockSlidingSync = mockifySlidingSync(new SlidingSync("", new Map(), {}, client, 0)); - if (testOpts.withCrypto) { - httpBackend!.when("GET", "/room_keys/version").respond(404, {}); - await client!.initLegacyCrypto(); - syncOpts.cryptoCallbacks = syncOpts.crypto = client!.crypto; - } httpBackend!.when("GET", "/_matrix/client/v3/pushrules").respond(200, {}); sdk = new SlidingSyncSdk(mockSlidingSync, client, testOpts, syncOpts); }; @@ -627,61 +622,6 @@ describe("SlidingSyncSdk", () => { }); }); - describe("ExtensionE2EE", () => { - let ext: Extension; - - beforeAll(async () => { - await setupClient({ - withCrypto: true, - }); - const hasSynced = sdk!.sync(); - await httpBackend!.flushAllExpected(); - await hasSynced; - ext = findExtension("e2ee"); - }); - - afterAll(async () => { - // needed else we do some async operations in the background which can cause Jest to whine: - // "Cannot log after tests are done. Did you forget to wait for something async in your test?" - // Attempted to log "Saving device tracking data null"." - client!.crypto!.stop(); - }); - - it("gets enabled on the initial request only", () => { - expect(ext.onRequest(true)).toEqual({ - enabled: true, - }); - expect(ext.onRequest(false)).toEqual(undefined); - }); - - it("can update device lists", () => { - client!.crypto!.processDeviceLists = jest.fn(); - ext.onResponse({ - device_lists: { - changed: ["@alice:localhost"], - left: ["@bob:localhost"], - }, - }); - expect(client!.crypto!.processDeviceLists).toHaveBeenCalledWith({ - changed: ["@alice:localhost"], - left: ["@bob:localhost"], - }); - }); - - it("can update OTK counts and unused fallback keys", () => { - client!.crypto!.processKeyCounts = jest.fn(); - ext.onResponse({ - device_one_time_keys_count: { - signed_curve25519: 42, - }, - device_unused_fallback_key_types: ["signed_curve25519"], - }); - expect(client!.crypto!.processKeyCounts).toHaveBeenCalledWith({ signed_curve25519: 42 }, [ - "signed_curve25519", - ]); - }); - }); - describe("ExtensionAccountData", () => { let ext: Extension; diff --git a/src/client.ts b/src/client.ts index 0e49b16091c..280d76382c8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1554,7 +1554,6 @@ export class MatrixClient extends TypedEventEmitter { if (!this.canResetTimelineCallback) { diff --git a/src/sliding-sync-sdk.ts b/src/sliding-sync-sdk.ts index 8d63e749c6f..c8d5506aa7c 100644 --- a/src/sliding-sync-sdk.ts +++ b/src/sliding-sync-sdk.ts @@ -30,7 +30,6 @@ import { SetPresence, } from "./sync.ts"; import { MatrixEvent } from "./models/event.ts"; -import { Crypto } from "./crypto/index.ts"; import { IMinimalEvent, IRoomEvent, IStateEvent, IStrippedState, ISyncResponse } from "./sync-accumulator.ts"; import { MatrixError } from "./http-api/index.ts"; import { @@ -53,54 +52,6 @@ import { KnownMembership } from "./@types/membership.ts"; // keepAlive is successful but the server /sync fails. const FAILED_SYNC_ERROR_THRESHOLD = 3; -type ExtensionE2EERequest = { - enabled: boolean; -}; - -type ExtensionE2EEResponse = Pick< - ISyncResponse, - | "device_lists" - | "device_one_time_keys_count" - | "device_unused_fallback_key_types" - | "org.matrix.msc2732.device_unused_fallback_key_types" ->; - -class ExtensionE2EE implements Extension { - public constructor(private readonly crypto: Crypto) {} - - public name(): string { - return "e2ee"; - } - - public when(): ExtensionState { - return ExtensionState.PreProcess; - } - - public onRequest(isInitial: boolean): ExtensionE2EERequest | undefined { - if (!isInitial) { - return undefined; - } - return { - enabled: true, // this is sticky so only send it on the initial request - }; - } - - public async onResponse(data: ExtensionE2EEResponse): Promise { - // Handle device list updates - if (data.device_lists) { - await this.crypto.processDeviceLists(data.device_lists); - } - - // Handle one_time_keys_count and unused_fallback_key_types - await this.crypto.processKeyCounts( - data.device_one_time_keys_count, - data["device_unused_fallback_key_types"] || data["org.matrix.msc2732.device_unused_fallback_key_types"], - ); - - this.crypto.onSyncCompleted({}); - } -} - type ExtensionToDeviceRequest = { since?: string; limit?: number; @@ -373,9 +324,6 @@ export class SlidingSyncSdk { new ExtensionTyping(this.client), new ExtensionReceipts(this.client), ]; - if (this.syncOpts.crypto) { - extensions.push(new ExtensionE2EE(this.syncOpts.crypto)); - } extensions.forEach((ext) => { this.slidingSync.registerExtension(ext); }); diff --git a/src/sync.ts b/src/sync.ts index 37ebc9139fb..d624a54dd7b 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -59,7 +59,6 @@ import { BeaconEvent } from "./models/beacon.ts"; import { IEventsResponse } from "./@types/requests.ts"; import { UNREAD_THREAD_NOTIFICATIONS } from "./@types/sync.ts"; import { Feature, ServerSupport } from "./feature.ts"; -import { Crypto } from "./crypto/index.ts"; import { KnownMembership } from "./@types/membership.ts"; const DEBUG = true; @@ -116,13 +115,6 @@ function debuglog(...params: any[]): void { * Options passed into the constructor of SyncApi by MatrixClient */ export interface SyncApiOptions { - /** - * Crypto manager - * - * @deprecated in favour of cryptoCallbacks - */ - crypto?: Crypto; - /** * If crypto is enabled on our client, callbacks into the crypto module */ @@ -642,9 +634,6 @@ export class SyncApi { } this.opts.filter.setLazyLoadMembers(true); } - if (this.opts.lazyLoadMembers) { - this.syncOpts.crypto?.enableLazyLoading(); - } }; private storeClientOptions = async (): Promise => { @@ -880,12 +869,6 @@ export class SyncApi { catchingUp: this.catchingUp, }; - if (this.syncOpts.crypto) { - // tell the crypto module we're about to process a sync - // response - await this.syncOpts.crypto.onSyncWillProcess(syncEventData); - } - try { await this.processSyncResponse(syncEventData, data); } catch (e) { @@ -920,15 +903,6 @@ export class SyncApi { this.updateSyncState(SyncState.Syncing, syncEventData); if (this.client.store.wantsSave()) { - // We always save the device list (if it's dirty) before saving the sync data: - // this means we know the saved device list data is at least as fresh as the - // stored sync data which means we don't have to worry that we may have missed - // device changes. We can also skip the delay since we're not calling this very - // frequently (and we don't really want to delay the sync for it). - if (this.syncOpts.crypto) { - await this.syncOpts.crypto.saveDeviceList(0); - } - // tell databases that everything is now in a consistent state and can be saved. await this.client.store.save(); }