From eddc5902354c459d324dce47955860efb2be202f Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 19 Aug 2024 10:27:46 +0100 Subject: [PATCH 1/2] Use rust crypto Taken from https://github.com/element-hq/element-call/pull/2467/commits/d25cf28d0085b3c686001193d74351e09ad6b301 --- package.json | 1 - src/@types/global.d.ts | 5 ----- src/initializer.tsx | 14 -------------- src/matrix-utils.ts | 5 +---- src/olm.ts | 29 ----------------------------- yarn.lock | 4 ---- 6 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 src/olm.ts diff --git a/package.json b/package.json index 425b27879..4e2c2ac23 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "@juggle/resize-observer": "^3.3.1", "@livekit/components-core": "^0.11.0", "@livekit/components-react": "^2.0.0", - "@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz", "@opentelemetry/api": "^1.4.0", "@opentelemetry/context-zone": "^1.9.1", "@opentelemetry/exporter-jaeger": "^1.9.1", diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index f27c273e5..ad0f65704 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -23,11 +23,6 @@ declare global { webkitFullscreenElement: HTMLElement | null; } - interface Window { - // TODO: https://gitlab.matrix.org/matrix-org/olm/-/issues/10 - OLM_OPTIONS: Record; - } - interface HTMLElement { // Safari only supports this prefixed, so tell the type system about it webkitRequestFullscreen: () => void; diff --git a/src/initializer.tsx b/src/initializer.tsx index f7e57ba9b..42a84663b 100644 --- a/src/initializer.tsx +++ b/src/initializer.tsx @@ -32,8 +32,6 @@ enum LoadState { } class DependencyLoadStates { - // TODO: decide where olm should be initialized (see TODO comment below) - // olm: LoadState = LoadState.None; public config: LoadState = LoadState.None; public sentry: LoadState = LoadState.None; public openTelemetry: LoadState = LoadState.None; @@ -128,18 +126,6 @@ export class Initializer { private loadStates = new DependencyLoadStates(); private initStep(resolve: (value: void | PromiseLike) => void): void { - // TODO: Olm is initialized with the client currently (see `initClient()` and `olm.ts`) - // we need to decide if we want to init it here or keep it in initClient - // if (this.loadStates.olm === LoadState.None) { - // this.loadStates.olm = LoadState.Loading; - // // TODO: https://gitlab.matrix.org/matrix-org/olm/-/issues/10 - // window.OLM_OPTIONS = {}; - // Olm.init({ locateFile: () => olmWasmPath }).then(() => { - // this.loadStates.olm = LoadState.Loaded; - // this.initStep(resolve); - // }); - // } - // config if (this.loadStates.config === LoadState.None) { this.loadStates.config = LoadState.Loading; diff --git a/src/matrix-utils.ts b/src/matrix-utils.ts index c6fe954d1..169048703 100644 --- a/src/matrix-utils.ts +++ b/src/matrix-utils.ts @@ -34,7 +34,6 @@ import type { MatrixClient } from "matrix-js-sdk/src/client"; import type { Room } from "matrix-js-sdk/src/models/room"; import IndexedDBWorker from "./IndexedDBWorker?worker"; import { generateUrlSearchParams, getUrlParams } from "./UrlParams"; -import { loadOlm } from "./olm"; import { Config } from "./config/Config"; import { E2eeType } from "./e2ee/e2eeType"; import { EncryptionSystem, saveKeyForRoom } from "./e2ee/sharedKeyManagement"; @@ -97,8 +96,6 @@ export async function initClient( clientOptions: ICreateClientOpts, restore: boolean, ): Promise { - await loadOlm(); - let indexedDB: IDBFactory | undefined; try { indexedDB = window.indexedDB; @@ -198,7 +195,7 @@ export async function initClient( await client.store.startup(); } - await client.initCrypto(); + await client.initRustCrypto(); client.setGlobalErrorOnUnknownDevices(false); // Once startClient is called, syncs are run asynchronously. // Also, sync completion is communicated only via events. diff --git a/src/olm.ts b/src/olm.ts deleted file mode 100644 index 0ee0b2443..000000000 --- a/src/olm.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2022 New Vector Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -import Olm from "@matrix-org/olm"; -import olmWasmPath from "@matrix-org/olm/olm.wasm?url"; - -// https://gitlab.matrix.org/matrix-org/olm/-/issues/10 -window.OLM_OPTIONS = {}; - -let olmLoaded: Promise | null = null; - -/** - * Loads Olm, if not already loaded. - */ -export const loadOlm = (): Promise => - (olmLoaded ??= Olm.init({ locateFile: () => olmWasmPath })); diff --git a/yarn.lock b/yarn.lock index 4bafebf7d..81032bf77 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1924,10 +1924,6 @@ resolved "https://registry.yarnpkg.com/@matrix-org/olm/-/olm-3.2.15.tgz#55f3c1b70a21bbee3f9195cecd6846b1083451ec" integrity sha512-S7lOrndAK9/8qOtaTq/WhttJC/o4GAzdfK0MUPpo8ApzsJEC0QjtwrkC3KBXdFP1cD1MXi/mlKR7aaoVMKgs6Q== -"@matrix-org/olm@https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz": - version "3.2.14" - resolved "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz#acd96c00a881d0f462e1f97a56c73742c8dbc984" - "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" From 36ce21d7accf13e3f3c9e8a6a198e376147f1750 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 19 Aug 2024 10:40:09 +0100 Subject: [PATCH 2/2] Show crypto version in developer settings --- public/locales/en-GB/app.json | 3 ++- src/settings/SettingsModal.tsx | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/public/locales/en-GB/app.json b/public/locales/en-GB/app.json index abca4ba21..acecfc4fe 100644 --- a/public/locales/en-GB/app.json +++ b/public/locales/en-GB/app.json @@ -59,6 +59,7 @@ "username": "Username", "video": "Video" }, + "crypto_version": "Crypto version: {{version}}", "device_id": "Device ID: {{id}}", "disconnected_banner": "Connectivity to the server has been lost.", "full_screen_view_description": "<0>Submitting debug logs will help us track down the problem.", @@ -156,7 +157,7 @@ "unauthenticated_view_eula_caption": "By clicking \"Go\", you agree to our <2>End User Licensing Agreement (EULA)", "unauthenticated_view_login_button": "Login to your account", "unmute_microphone_button_label": "Unmute microphone", - "version": "Version: {{version}}", + "version": "{{productName}} version: {{version}}", "video_tile": { "always_show": "Always show", "change_fit_contain": "Fit to frame", diff --git a/src/settings/SettingsModal.tsx b/src/settings/SettingsModal.tsx index ae1bfed6d..6763cc5d2 100644 --- a/src/settings/SettingsModal.tsx +++ b/src/settings/SettingsModal.tsx @@ -241,9 +241,15 @@ export const SettingsModal: FC = ({ >

{t("version", { + productName: import.meta.env.VITE_PRODUCT_NAME || "Element Call", version: import.meta.env.VITE_APP_VERSION || "dev", })}

+

+ {t("crypto_version", { + version: client.getCrypto()?.getVersion() || "unknown", + })} +

{t("matrix_id", { id: client.getUserId() || "unknown",