mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-02 19:49:23 +00:00
WIP ratcheting
This commit is contained in:
@@ -99,10 +99,10 @@
|
|||||||
"i18next-parser": "^9.1.0",
|
"i18next-parser": "^9.1.0",
|
||||||
"jsdom": "^26.0.0",
|
"jsdom": "^26.0.0",
|
||||||
"knip": "^5.27.2",
|
"knip": "^5.27.2",
|
||||||
"livekit-client": "^2.11.3",
|
"livekit-client": "github:BillCarsonFr/client-sdk-js#4ac197085ee063f66b48d8ec24c88b2321fcbf9e",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"loglevel": "^1.9.1",
|
"loglevel": "^1.9.1",
|
||||||
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#19b1b901f575755d29d1fe03ca48cbf7c1cae05c",
|
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#44d1a860a1c56a0d4193aa7dcd09e10822398a4d",
|
||||||
"matrix-widget-api": "1.11.0",
|
"matrix-widget-api": "1.11.0",
|
||||||
"normalize.css": "^8.0.1",
|
"normalize.css": "^8.0.1",
|
||||||
"observable-hooks": "^4.2.3",
|
"observable-hooks": "^4.2.3",
|
||||||
|
|||||||
@@ -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.
|
Please see LICENSE in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BaseKeyProvider, createKeyMaterialFromBuffer } from "livekit-client";
|
import { BaseKeyProvider, createKeyMaterialFromBuffer, importKey, KeyProviderEvent } from "livekit-client";
|
||||||
import { logger } from "matrix-js-sdk/lib/logger";
|
import { logger } from "matrix-js-sdk/lib/logger";
|
||||||
import {
|
import {
|
||||||
type MatrixRTCSession,
|
type MatrixRTCSession,
|
||||||
@@ -15,8 +15,22 @@ import {
|
|||||||
export class MatrixKeyProvider extends BaseKeyProvider {
|
export class MatrixKeyProvider extends BaseKeyProvider {
|
||||||
private rtcSession?: MatrixRTCSession;
|
private rtcSession?: MatrixRTCSession;
|
||||||
|
|
||||||
|
private readonly onKeyRatchetComplete: (material: ArrayBuffer, keyIndex?: number) => void;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super({ ratchetWindowSize: 10, keyringSize: 256 });
|
super({ ratchetWindowSize: 10, keyringSize: 10 });
|
||||||
|
|
||||||
|
this.onKeyRatchetComplete = (material: ArrayBuffer, keyIndex?: number): void => {
|
||||||
|
logger.debug(`key ratcheted event received for index `, keyIndex );
|
||||||
|
this.rtcSession?.onOwnKeyRatcheted(material, keyIndex).catch((e) => {
|
||||||
|
logger.error(
|
||||||
|
`Failed to ratchet key for livekit room=${this.rtcSession?.room.roomId} keyIndex=${keyIndex}`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.on(KeyProviderEvent.RatchetRequestCompleted, this.onKeyRatchetComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setRTCSession(rtcSession: MatrixRTCSession): void {
|
public setRTCSession(rtcSession: MatrixRTCSession): void {
|
||||||
@@ -25,6 +39,11 @@ export class MatrixKeyProvider extends BaseKeyProvider {
|
|||||||
MatrixRTCSessionEvent.EncryptionKeyChanged,
|
MatrixRTCSessionEvent.EncryptionKeyChanged,
|
||||||
this.onEncryptionKeyChanged,
|
this.onEncryptionKeyChanged,
|
||||||
);
|
);
|
||||||
|
this.rtcSession.off(
|
||||||
|
MatrixRTCSessionEvent.EncryptionKeyQueryRatchetStep,
|
||||||
|
this.doRatchetKey,
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rtcSession = rtcSession;
|
this.rtcSession = rtcSession;
|
||||||
@@ -34,17 +53,27 @@ export class MatrixKeyProvider extends BaseKeyProvider {
|
|||||||
this.onEncryptionKeyChanged,
|
this.onEncryptionKeyChanged,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.rtcSession.on(
|
||||||
|
MatrixRTCSessionEvent.EncryptionKeyQueryRatchetStep,
|
||||||
|
this.doRatchetKey,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// The new session could be aware of keys of which the old session wasn't,
|
// The new session could be aware of keys of which the old session wasn't,
|
||||||
// so emit key changed events
|
// so emit key changed events
|
||||||
this.rtcSession.reemitEncryptionKeys();
|
this.rtcSession.reemitEncryptionKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private doRatchetKey = (participantId:string, keyIndex:number): void => {
|
||||||
|
this.ratchetKey(participantId, keyIndex);
|
||||||
|
}
|
||||||
|
|
||||||
private onEncryptionKeyChanged = (
|
private onEncryptionKeyChanged = (
|
||||||
encryptionKey: Uint8Array,
|
encryptionKey: Uint8Array,
|
||||||
encryptionKeyIndex: number,
|
encryptionKeyIndex: number,
|
||||||
participantId: string,
|
participantId: string,
|
||||||
): void => {
|
): void => {
|
||||||
createKeyMaterialFromBuffer(encryptionKey).then(
|
importKey(encryptionKey, "HKDF", 'derive').then(
|
||||||
(keyMaterial) => {
|
(keyMaterial) => {
|
||||||
this.onSetEncryptionKey(keyMaterial, participantId, encryptionKeyIndex);
|
this.onSetEncryptionKey(keyMaterial, participantId, encryptionKeyIndex);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user