Store shared keys in local storage
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
20
src/e2ee/sharedKeyManagement.ts
Normal file
20
src/e2ee/sharedKeyManagement.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
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 { useSetting } from "../settings/useSetting";
|
||||||
|
|
||||||
|
export const useRoomSharedKey = (roomId: string, initialValue?: string) =>
|
||||||
|
useSetting(`room-shared-key-${roomId}`, initialValue);
|
||||||
@@ -32,13 +32,14 @@ import { CallEndedView } from "./CallEndedView";
|
|||||||
import { useSentryGroupCallHandler } from "./useSentryGroupCallHandler";
|
import { useSentryGroupCallHandler } from "./useSentryGroupCallHandler";
|
||||||
import { PosthogAnalytics } from "../analytics/PosthogAnalytics";
|
import { PosthogAnalytics } from "../analytics/PosthogAnalytics";
|
||||||
import { useProfile } from "../profile/useProfile";
|
import { useProfile } from "../profile/useProfile";
|
||||||
import { E2EEConfig } from "../livekit/useLiveKit";
|
|
||||||
import { findDeviceByName } from "../media-utils";
|
import { findDeviceByName } from "../media-utils";
|
||||||
import { OpenIDLoader } from "../livekit/OpenIDLoader";
|
import { OpenIDLoader } from "../livekit/OpenIDLoader";
|
||||||
import { ActiveCall } from "./InCallView";
|
import { ActiveCall } from "./InCallView";
|
||||||
import { Config } from "../config/Config";
|
import { Config } from "../config/Config";
|
||||||
import { MuteStates, useMuteStates } from "./MuteStates";
|
import { MuteStates, useMuteStates } from "./MuteStates";
|
||||||
import { useMediaDevices, MediaDevices } from "../livekit/MediaDevicesContext";
|
import { useMediaDevices, MediaDevices } from "../livekit/MediaDevicesContext";
|
||||||
|
import { useRoomSharedKey } from "../e2ee/sharedKeyManagement";
|
||||||
|
import { useUrlParams } from "../UrlParams";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -73,6 +74,8 @@ export function GroupCallView({
|
|||||||
otelGroupCallMembership,
|
otelGroupCallMembership,
|
||||||
} = useGroupCall(groupCall, client);
|
} = useGroupCall(groupCall, client);
|
||||||
|
|
||||||
|
const { password } = useUrlParams();
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -241,8 +244,31 @@ export function GroupCallView({
|
|||||||
}
|
}
|
||||||
}, [groupCall, state, leave]);
|
}, [groupCall, state, leave]);
|
||||||
|
|
||||||
const [e2eeConfig, setE2EEConfig] = useState<E2EEConfig | undefined>(
|
const [e2eeSharedKey, setE2EESharedKey] = useRoomSharedKey(
|
||||||
undefined
|
groupCall.room.roomId,
|
||||||
|
password ?? undefined
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!password || password === e2eeSharedKey) return;
|
||||||
|
|
||||||
|
setE2EESharedKey(password);
|
||||||
|
}, [password, e2eeSharedKey, setE2EESharedKey]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const originalHash = location.hash;
|
||||||
|
let hash = originalHash === "" ? "#" : originalHash;
|
||||||
|
hash = hash.split("?password=")[0];
|
||||||
|
hash += `?password=${e2eeSharedKey ?? ""}`;
|
||||||
|
|
||||||
|
if (originalHash !== hash) {
|
||||||
|
location.replace(hash);
|
||||||
|
}
|
||||||
|
}, [e2eeSharedKey]);
|
||||||
|
|
||||||
|
const e2eeConfig = useMemo(
|
||||||
|
() => (e2eeSharedKey ? { sharedKey: e2eeSharedKey } : undefined),
|
||||||
|
[e2eeSharedKey]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onReconnect = useCallback(() => {
|
const onReconnect = useCallback(() => {
|
||||||
@@ -319,10 +345,7 @@ export function GroupCallView({
|
|||||||
<LobbyView
|
<LobbyView
|
||||||
matrixInfo={matrixInfo}
|
matrixInfo={matrixInfo}
|
||||||
muteStates={muteStates}
|
muteStates={muteStates}
|
||||||
onEnter={(e2eeConfig?: E2EEConfig) => {
|
onEnter={() => enter()}
|
||||||
setE2EEConfig(e2eeConfig);
|
|
||||||
enter();
|
|
||||||
}}
|
|
||||||
isEmbedded={isEmbedded}
|
isEmbedded={isEmbedded}
|
||||||
hideHeader={hideHeader}
|
hideHeader={hideHeader}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -14,14 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { useRef, useEffect, FC } from "react";
|
||||||
useRef,
|
|
||||||
useEffect,
|
|
||||||
useState,
|
|
||||||
useCallback,
|
|
||||||
ChangeEvent,
|
|
||||||
FC,
|
|
||||||
} from "react";
|
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import styles from "./LobbyView.module.css";
|
import styles from "./LobbyView.module.css";
|
||||||
@@ -32,16 +25,12 @@ import { UserMenuContainer } from "../UserMenuContainer";
|
|||||||
import { Body, Link } from "../typography/Typography";
|
import { Body, Link } from "../typography/Typography";
|
||||||
import { useLocationNavigation } from "../useLocationNavigation";
|
import { useLocationNavigation } from "../useLocationNavigation";
|
||||||
import { MatrixInfo, VideoPreview } from "./VideoPreview";
|
import { MatrixInfo, VideoPreview } from "./VideoPreview";
|
||||||
import { E2EEConfig } from "../livekit/useLiveKit";
|
|
||||||
import { InputField } from "../input/Input";
|
|
||||||
import { useEnableE2EE } from "../settings/useSetting";
|
|
||||||
import { MuteStates } from "./MuteStates";
|
import { MuteStates } from "./MuteStates";
|
||||||
import { useUrlParams } from "../UrlParams";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
matrixInfo: MatrixInfo;
|
matrixInfo: MatrixInfo;
|
||||||
muteStates: MuteStates;
|
muteStates: MuteStates;
|
||||||
onEnter: (e2eeConfig?: E2EEConfig) => void;
|
onEnter: () => void;
|
||||||
isEmbedded: boolean;
|
isEmbedded: boolean;
|
||||||
hideHeader: boolean;
|
hideHeader: boolean;
|
||||||
}
|
}
|
||||||
@@ -53,13 +42,9 @@ export const LobbyView: FC<Props> = ({
|
|||||||
isEmbedded,
|
isEmbedded,
|
||||||
hideHeader,
|
hideHeader,
|
||||||
}) => {
|
}) => {
|
||||||
const { password } = useUrlParams();
|
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
useLocationNavigation();
|
useLocationNavigation();
|
||||||
|
|
||||||
const [enableE2EE] = useEnableE2EE();
|
|
||||||
|
|
||||||
const joinCallButtonRef = useRef<HTMLButtonElement>(null);
|
const joinCallButtonRef = useRef<HTMLButtonElement>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (joinCallButtonRef.current) {
|
if (joinCallButtonRef.current) {
|
||||||
@@ -67,29 +52,6 @@ export const LobbyView: FC<Props> = ({
|
|||||||
}
|
}
|
||||||
}, [joinCallButtonRef]);
|
}, [joinCallButtonRef]);
|
||||||
|
|
||||||
const [e2eeSharedKey, setE2EESharedKey] = useState<string | undefined>(
|
|
||||||
password ?? undefined
|
|
||||||
);
|
|
||||||
|
|
||||||
const onE2EESharedKeyChanged = useCallback(
|
|
||||||
(event: ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const value = event.target.value;
|
|
||||||
setE2EESharedKey(value === "" ? undefined : value);
|
|
||||||
},
|
|
||||||
[setE2EESharedKey]
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const originalHash = location.hash;
|
|
||||||
let hash = originalHash === "" ? "#" : originalHash;
|
|
||||||
hash = hash.split("?password=")[0];
|
|
||||||
hash += `?password=${e2eeSharedKey ?? ""}`;
|
|
||||||
|
|
||||||
if (originalHash !== hash) {
|
|
||||||
location.replace(hash);
|
|
||||||
}
|
|
||||||
}, [e2eeSharedKey]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.room}>
|
<div className={styles.room}>
|
||||||
{!hideHeader && (
|
{!hideHeader && (
|
||||||
@@ -105,25 +67,12 @@ export const LobbyView: FC<Props> = ({
|
|||||||
<div className={styles.joinRoom}>
|
<div className={styles.joinRoom}>
|
||||||
<div className={styles.joinRoomContent}>
|
<div className={styles.joinRoomContent}>
|
||||||
<VideoPreview matrixInfo={matrixInfo} muteStates={muteStates} />
|
<VideoPreview matrixInfo={matrixInfo} muteStates={muteStates} />
|
||||||
{enableE2EE && (
|
|
||||||
<InputField
|
|
||||||
className={styles.passwordField}
|
|
||||||
label={t("Password (if none, E2EE is disabled)")}
|
|
||||||
type="text"
|
|
||||||
onChange={onE2EESharedKeyChanged}
|
|
||||||
value={e2eeSharedKey}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Trans>
|
<Trans>
|
||||||
<Button
|
<Button
|
||||||
ref={joinCallButtonRef}
|
ref={joinCallButtonRef}
|
||||||
className={styles.copyButton}
|
className={styles.copyButton}
|
||||||
size="lg"
|
size="lg"
|
||||||
onPress={() =>
|
onPress={() => onEnter()}
|
||||||
onEnter(
|
|
||||||
e2eeSharedKey ? { sharedKey: e2eeSharedKey } : undefined
|
|
||||||
)
|
|
||||||
}
|
|
||||||
data-testid="lobby_joinCall"
|
data-testid="lobby_joinCall"
|
||||||
>
|
>
|
||||||
Join call now
|
Join call now
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const getSettingKey = (name: string): string => {
|
|||||||
return `matrix-setting-${name}`;
|
return `matrix-setting-${name}`;
|
||||||
};
|
};
|
||||||
// Like useState, but reads from and persists the value to localStorage
|
// Like useState, but reads from and persists the value to localStorage
|
||||||
const useSetting = <T>(name: string, defaultValue: T): Setting<T> => {
|
export const useSetting = <T>(name: string, defaultValue: T): Setting<T> => {
|
||||||
const key = useMemo(() => getSettingKey(name), [name]);
|
const key = useMemo(() => getSettingKey(name), [name]);
|
||||||
|
|
||||||
const [value, setValue] = useState<T>(() => {
|
const [value, setValue] = useState<T>(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user