Do not allow joining a call without E2EE key

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2023-08-09 13:48:38 +02:00
parent c4e5e1afb1
commit 935d2188f0
3 changed files with 26 additions and 13 deletions

View File

@@ -14,13 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { useEffect, useMemo } from "react";
import { randomString } from "matrix-js-sdk/src/randomstring";
import { useMemo } from "react";
import { useEnableE2EE } from "../settings/useSetting";
import { useLocalStorage } from "../useLocalStorage";
const getRoomSharedKeyLocalStorageKey = (roomId: string): string =>
export const getRoomSharedKeyLocalStorageKey = (roomId: string): string =>
`room-shared-key-${roomId}`;
export const useRoomSharedKey = (
@@ -30,11 +29,5 @@ export const useRoomSharedKey = (
const [e2eeEnabled] = useEnableE2EE();
const [roomSharedKey, setRoomSharedKey] = useLocalStorage(key);
useEffect(() => {
if ((roomSharedKey && roomSharedKey !== "") || !e2eeEnabled) return;
setRoomSharedKey(randomString(32));
}, [roomSharedKey, e2eeEnabled, setRoomSharedKey]);
return e2eeEnabled ? [roomSharedKey, setRoomSharedKey] : [null, null];
};

View File

@@ -17,6 +17,7 @@ limitations under the License.
import { useState, useCallback, FormEvent, FormEventHandler } from "react";
import { useHistory } from "react-router-dom";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { randomString } from "matrix-js-sdk/src/randomstring";
import { useTranslation } from "react-i18next";
import {
@@ -40,6 +41,8 @@ import { CallType, CallTypeDropdown } from "./CallTypeDropdown";
import { useOptInAnalytics } from "../settings/useSetting";
import { AnalyticsNotice } from "../analytics/AnalyticsNotice";
import { E2EEBanner } from "../E2EEBanner";
import { setLocalStorageItem } from "../useLocalStorage";
import { getRoomSharedKeyLocalStorageKey } from "../e2ee/sharedKeyManagement";
interface Props {
client: MatrixClient;
@@ -70,12 +73,15 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) {
setError(undefined);
setLoading(true);
const [roomAlias] = await createRoom(client, roomName, ptt);
const [roomAlias, roomId] = await createRoom(client, roomName, ptt);
setLocalStorageItem(
getRoomSharedKeyLocalStorageKey(roomId),
randomString(32)
);
if (roomAlias) {
history.push(`/${roomAlias.substring(1).split(":")[0]}`);
}
}
submit().catch((error) => {
if (error.errcode === "M_ROOM_IN_USE") {

View File

@@ -40,6 +40,7 @@ import { MuteStates, useMuteStates } from "./MuteStates";
import { useMediaDevices, MediaDevices } from "../livekit/MediaDevicesContext";
import { useRoomSharedKey } from "../e2ee/sharedKeyManagement";
import { PASSWORD_STRING, useUrlParams } from "../UrlParams";
import { useEnableE2EE } from "../settings/useSetting";
declare global {
interface Window {
@@ -244,6 +245,7 @@ export function GroupCallView({
}
}, [groupCall, state, leave]);
const [e2eeEnabled] = useEnableE2EE();
const [e2eeSharedKey, setE2EESharedKey] = useRoomSharedKey(
groupCall.room.roomId
);
@@ -275,6 +277,18 @@ export function GroupCallView({
groupCall.enter();
}, [groupCall]);
if (!password && !e2eeSharedKey && e2eeEnabled) {
return (
<ErrorView
error={
new Error(
"No E2EE key provided: please make sure the URL you're using to join this call has been retrieved using the in-app button."
)
}
/>
);
}
const livekitServiceURL =
groupCall.livekitServiceURL ?? Config.get().livekit?.livekit_service_url;
if (!livekitServiceURL) {