From 832972b2556b92886fc4f75eb86f10df7230bee0 Mon Sep 17 00:00:00 2001 From: Timo Date: Mon, 19 May 2025 17:00:15 +0200 Subject: [PATCH] Alternative without `createKeyMaterialFromBuffer` --- src/e2ee/matrixKeyProvider.ts | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/e2ee/matrixKeyProvider.ts b/src/e2ee/matrixKeyProvider.ts index 9960ed62..95033f87 100644 --- a/src/e2ee/matrixKeyProvider.ts +++ b/src/e2ee/matrixKeyProvider.ts @@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE in the repository root for full details. */ -import { BaseKeyProvider, createKeyMaterialFromBuffer } from "livekit-client"; +import { BaseKeyProvider } from "livekit-client"; import { logger } from "matrix-js-sdk/lib/logger"; import { type MatrixRTCSession, @@ -44,20 +44,29 @@ export class MatrixKeyProvider extends BaseKeyProvider { encryptionKeyIndex: number, participantId: string, ): void => { - createKeyMaterialFromBuffer(encryptionKey.buffer as ArrayBuffer).then( - (keyMaterial) => { - this.onSetEncryptionKey(keyMaterial, participantId, encryptionKeyIndex); + crypto.subtle + .importKey("raw", encryptionKey, "HKDF", false, [ + "deriveBits", + "deriveKey", + ]) + .then( + (keyMaterial) => { + this.onSetEncryptionKey( + keyMaterial, + participantId, + encryptionKeyIndex, + ); - logger.debug( - `Sent new key to livekit room=${this.rtcSession?.room.roomId} participantId=${participantId} encryptionKeyIndex=${encryptionKeyIndex}`, - ); - }, - (e) => { - logger.error( - `Failed to create key material from buffer for livekit room=${this.rtcSession?.room.roomId} participantId=${participantId} encryptionKeyIndex=${encryptionKeyIndex}`, - e, - ); - }, - ); + logger.debug( + `Sent new key to livekit room=${this.rtcSession?.room.roomId} participantId=${participantId} encryptionKeyIndex=${encryptionKeyIndex}`, + ); + }, + (e) => { + logger.error( + `Failed to create key material from buffer for livekit room=${this.rtcSession?.room.roomId} participantId=${participantId} encryptionKeyIndex=${encryptionKeyIndex}`, + e, + ); + }, + ); }; }