Differentiate between E2EE and non-E2EE rooms by alias presence

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2023-08-11 17:00:05 +02:00
parent edfae0138c
commit 22690c4a0b
3 changed files with 55 additions and 13 deletions

View File

@@ -38,7 +38,7 @@ import { JoinExistingCallModal } from "./JoinExistingCallModal";
import { Caption, Title } from "../typography/Typography"; import { Caption, Title } from "../typography/Typography";
import { Form } from "../form/Form"; import { Form } from "../form/Form";
import { CallType, CallTypeDropdown } from "./CallTypeDropdown"; import { CallType, CallTypeDropdown } from "./CallTypeDropdown";
import { useOptInAnalytics } from "../settings/useSetting"; import { useEnableE2EE, useOptInAnalytics } from "../settings/useSetting";
import { AnalyticsNotice } from "../analytics/AnalyticsNotice"; import { AnalyticsNotice } from "../analytics/AnalyticsNotice";
import { E2EEBanner } from "../E2EEBanner"; import { E2EEBanner } from "../E2EEBanner";
import { setLocalStorageItem } from "../useLocalStorage"; import { setLocalStorageItem } from "../useLocalStorage";
@@ -57,6 +57,7 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) {
const history = useHistory(); const history = useHistory();
const { t } = useTranslation(); const { t } = useTranslation();
const { modalState, modalProps } = useModalTriggerState(); const { modalState, modalProps } = useModalTriggerState();
const [e2eeEnabled] = useEnableE2EE();
const onSubmit: FormEventHandler<HTMLFormElement> = useCallback( const onSubmit: FormEventHandler<HTMLFormElement> = useCallback(
(e: FormEvent) => { (e: FormEvent) => {
@@ -73,12 +74,16 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) {
setError(undefined); setError(undefined);
setLoading(true); setLoading(true);
const [roomAlias, roomId] = await createRoom(client, roomName, ptt); const roomId = (
await createRoom(client, roomName, ptt, e2eeEnabled ?? false)
)[1];
setLocalStorageItem( if (e2eeEnabled) {
getRoomSharedKeyLocalStorageKey(roomId), setLocalStorageItem(
randomString(32) getRoomSharedKeyLocalStorageKey(roomId),
); randomString(32)
);
}
history.push(`/room/#?roomId=${roomId}`); history.push(`/room/#?roomId=${roomId}`);
} }
@@ -96,7 +101,7 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) {
} }
}); });
}, },
[client, history, modalState, callType] [client, history, modalState, callType, e2eeEnabled]
); );
const recentRooms = useGroupCallRooms(client); const recentRooms = useGroupCallRooms(client);

View File

@@ -40,9 +40,11 @@ import styles from "./UnauthenticatedView.module.css";
import commonStyles from "./common.module.css"; import commonStyles from "./common.module.css";
import { generateRandomName } from "../auth/generateRandomName"; import { generateRandomName } from "../auth/generateRandomName";
import { AnalyticsNotice } from "../analytics/AnalyticsNotice"; import { AnalyticsNotice } from "../analytics/AnalyticsNotice";
import { useOptInAnalytics } from "../settings/useSetting"; import { useEnableE2EE, useOptInAnalytics } from "../settings/useSetting";
import { Config } from "../config/Config"; import { Config } from "../config/Config";
import { E2EEBanner } from "../E2EEBanner"; import { E2EEBanner } from "../E2EEBanner";
import { getRoomSharedKeyLocalStorageKey } from "../e2ee/sharedKeyManagement";
import { setLocalStorageItem } from "../useLocalStorage";
export const UnauthenticatedView: FC = () => { export const UnauthenticatedView: FC = () => {
const { setClient } = useClient(); const { setClient } = useClient();
@@ -58,6 +60,8 @@ export const UnauthenticatedView: FC = () => {
const history = useHistory(); const history = useHistory();
const { t } = useTranslation(); const { t } = useTranslation();
const [e2eeEnabled] = useEnableE2EE();
const onSubmit: FormEventHandler<HTMLFormElement> = useCallback( const onSubmit: FormEventHandler<HTMLFormElement> = useCallback(
(e) => { (e) => {
e.preventDefault(); e.preventDefault();
@@ -79,9 +83,18 @@ export const UnauthenticatedView: FC = () => {
true true
); );
let roomAlias: string; let roomId: string;
try { try {
[roomAlias] = await createRoom(client, roomName, ptt); roomId = (
await createRoom(client, roomName, ptt, e2eeEnabled ?? false)
)[1];
if (e2eeEnabled) {
setLocalStorageItem(
getRoomSharedKeyLocalStorageKey(roomId),
randomString(32)
);
}
} catch (error) { } catch (error) {
if (!setClient) { if (!setClient) {
throw error; throw error;
@@ -120,7 +133,16 @@ export const UnauthenticatedView: FC = () => {
reset(); reset();
}); });
}, },
[register, reset, execute, history, callType, modalState, setClient] [
register,
reset,
execute,
history,
callType,
modalState,
setClient,
e2eeEnabled,
]
); );
const callNameLabel = const callNameLabel =

View File

@@ -25,12 +25,16 @@ import { logger } from "matrix-js-sdk/src/logger";
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client"; import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { SyncState } from "matrix-js-sdk/src/sync"; import { SyncState } from "matrix-js-sdk/src/sync";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { randomString } from "matrix-js-sdk/src/randomstring";
import type { Room } from "matrix-js-sdk/src/models/room"; import type { Room } from "matrix-js-sdk/src/models/room";
import type { GroupCall } from "matrix-js-sdk/src/webrtc/groupCall"; import type { GroupCall } from "matrix-js-sdk/src/webrtc/groupCall";
import { setLocalStorageItem } from "../useLocalStorage";
import { isLocalRoomId, createRoom, roomNameFromRoomId } from "../matrix-utils"; import { isLocalRoomId, createRoom, roomNameFromRoomId } from "../matrix-utils";
import { translatedError } from "../TranslatedError"; import { translatedError } from "../TranslatedError";
import { widget } from "../widget"; import { widget } from "../widget";
import { useEnableE2EE } from "../settings/useSetting";
import { getRoomSharedKeyLocalStorageKey } from "../e2ee/sharedKeyManagement";
const STATS_COLLECT_INTERVAL_TIME_MS = 10000; const STATS_COLLECT_INTERVAL_TIME_MS = 10000;
@@ -67,6 +71,8 @@ export const useLoadGroupCall = (
const { t } = useTranslation(); const { t } = useTranslation();
const [state, setState] = useState<GroupCallStatus>({ kind: "loading" }); const [state, setState] = useState<GroupCallStatus>({ kind: "loading" });
const [e2eeEnabled] = useEnableE2EE();
useEffect(() => { useEffect(() => {
const fetchOrCreateRoom = async (): Promise<Room> => { const fetchOrCreateRoom = async (): Promise<Room> => {
try { try {
@@ -104,8 +110,17 @@ export const useLoadGroupCall = (
const [, roomId] = await createRoom( const [, roomId] = await createRoom(
client, client,
roomNameFromRoomId(roomIdOrAlias), roomNameFromRoomId(roomIdOrAlias),
createPtt createPtt,
e2eeEnabled ?? false
); );
if (e2eeEnabled) {
setLocalStorageItem(
getRoomSharedKeyLocalStorageKey(roomId),
randomString(32)
);
}
// likewise, wait for the room // likewise, wait for the room
await client.waitUntilRoomReadyForGroupCalls(roomId); await client.waitUntilRoomReadyForGroupCalls(roomId);
return client.getRoom(roomId)!; return client.getRoom(roomId)!;
@@ -194,7 +209,7 @@ export const useLoadGroupCall = (
.then(fetchOrCreateGroupCall) .then(fetchOrCreateGroupCall)
.then((groupCall) => setState({ kind: "loaded", groupCall })) .then((groupCall) => setState({ kind: "loaded", groupCall }))
.catch((error) => setState({ kind: "failed", error })); .catch((error) => setState({ kind: "failed", error }));
}, [client, roomIdOrAlias, viaServers, createPtt, t]); }, [client, roomIdOrAlias, viaServers, createPtt, t, e2eeEnabled]);
return state; return state;
}; };