mirror of
https://github.com/vector-im/element-call.git
synced 2026-07-18 18:59:23 +00:00
E2EE for embeded mode
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
81
src/e2ee/matrixKeyProvider.ts
Normal file
81
src/e2ee/matrixKeyProvider.ts
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 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 { logger } from "@sentry/utils";
|
||||||
|
import {
|
||||||
|
BaseKeyProvider,
|
||||||
|
KeyProviderOptions,
|
||||||
|
createKeyMaterialFromString,
|
||||||
|
} from "livekit-client";
|
||||||
|
import { CallMembership } from "matrix-js-sdk/src/matrixrtc/CallMembership";
|
||||||
|
import {
|
||||||
|
MatrixRTCSession,
|
||||||
|
MatrixRTCSessionEvent,
|
||||||
|
} from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
||||||
|
|
||||||
|
export class MatrixKeyProvider extends BaseKeyProvider {
|
||||||
|
constructor(
|
||||||
|
private rtcSession: MatrixRTCSession,
|
||||||
|
keyProviderOptions: Partial<KeyProviderOptions> = {}
|
||||||
|
) {
|
||||||
|
super(keyProviderOptions);
|
||||||
|
|
||||||
|
const encryptionKey = this.rtcSession.activeEncryptionKey;
|
||||||
|
if (!encryptionKey) {
|
||||||
|
throw new Error(
|
||||||
|
"MatrixKeyProvider requires the given MatrixRTCSession to have an activeEncryptionKey"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rtcSession.on(
|
||||||
|
MatrixRTCSessionEvent.MembershipsChanged,
|
||||||
|
this.onMemberShipsChanged
|
||||||
|
);
|
||||||
|
this.rtcSession.on(
|
||||||
|
MatrixRTCSessionEvent.ActiveEncryptionKeyChanged,
|
||||||
|
this.onEncryptionKeyChanged
|
||||||
|
);
|
||||||
|
|
||||||
|
this.onEncryptionKeyChanged(encryptionKey);
|
||||||
|
this.onMemberShipsChanged([], this.rtcSession.memberships);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onEncryptionKeyChanged = async (key: string) => {
|
||||||
|
this.onSetEncryptionKey(await createKeyMaterialFromString(key), undefined);
|
||||||
|
};
|
||||||
|
|
||||||
|
private onMemberShipsChanged = async (
|
||||||
|
_: CallMembership[],
|
||||||
|
newMemberships: CallMembership[]
|
||||||
|
) => {
|
||||||
|
for (const membership of newMemberships) {
|
||||||
|
const participantId = `${membership.member.userId}:${membership.deviceId}`;
|
||||||
|
const encryptionKey = await membership.getActiveEncryptionKey();
|
||||||
|
|
||||||
|
if (!encryptionKey) {
|
||||||
|
logger.warn(
|
||||||
|
`Participant ${participantId} did not share a key over Matrix`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.onSetEncryptionKey(
|
||||||
|
await createKeyMaterialFromString(encryptionKey),
|
||||||
|
participantId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
import {
|
import {
|
||||||
ConnectionState,
|
ConnectionState,
|
||||||
E2EEOptions,
|
E2EEOptions,
|
||||||
ExternalE2EEKeyProvider,
|
|
||||||
Room,
|
Room,
|
||||||
RoomOptions,
|
RoomOptions,
|
||||||
setLogLevel,
|
setLogLevel,
|
||||||
@@ -26,6 +25,8 @@ import { useLiveKitRoom } from "@livekit/components-react";
|
|||||||
import { useEffect, useMemo, useRef } from "react";
|
import { useEffect, useMemo, useRef } from "react";
|
||||||
import E2EEWorker from "livekit-client/e2ee-worker?worker";
|
import E2EEWorker from "livekit-client/e2ee-worker?worker";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
||||||
|
import { ExternalE2EEKeyProvider } from "livekit-client/dist/src/e2ee/KeyProvider";
|
||||||
|
|
||||||
import { defaultLiveKitOptions } from "./options";
|
import { defaultLiveKitOptions } from "./options";
|
||||||
import { SFUConfig } from "./openIDSFU";
|
import { SFUConfig } from "./openIDSFU";
|
||||||
@@ -39,6 +40,7 @@ import {
|
|||||||
ECConnectionState,
|
ECConnectionState,
|
||||||
useECConnectionState,
|
useECConnectionState,
|
||||||
} from "./useECConnectionState";
|
} from "./useECConnectionState";
|
||||||
|
import { MatrixKeyProvider } from "../e2ee/matrixKeyProvider";
|
||||||
|
|
||||||
export type E2EEConfig = {
|
export type E2EEConfig = {
|
||||||
sharedKey: string;
|
sharedKey: string;
|
||||||
@@ -53,6 +55,7 @@ interface UseLivekitResult {
|
|||||||
|
|
||||||
export function useLiveKit(
|
export function useLiveKit(
|
||||||
muteStates: MuteStates,
|
muteStates: MuteStates,
|
||||||
|
rtcSession: MatrixRTCSession,
|
||||||
sfuConfig?: SFUConfig,
|
sfuConfig?: SFUConfig,
|
||||||
e2eeConfig?: E2EEConfig
|
e2eeConfig?: E2EEConfig
|
||||||
): UseLivekitResult {
|
): UseLivekitResult {
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ export function ActiveCall(props: ActiveCallProps) {
|
|||||||
const sfuConfig = useOpenIDSFU(props.client, props.rtcSession);
|
const sfuConfig = useOpenIDSFU(props.client, props.rtcSession);
|
||||||
const { livekitRoom, connState } = useLiveKit(
|
const { livekitRoom, connState } = useLiveKit(
|
||||||
props.muteStates,
|
props.muteStates,
|
||||||
|
props.rtcSession,
|
||||||
sfuConfig,
|
sfuConfig,
|
||||||
props.e2eeConfig
|
props.e2eeConfig
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user