From 1a5898eb30fe3266d9e753ab035f6d732a0a70a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 4 Aug 2023 13:39:59 +0200 Subject: [PATCH] Get E2EE password from the URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/UrlParams.ts | 18 +++++++++++++++++- src/room/LobbyView.tsx | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/UrlParams.ts b/src/UrlParams.ts index 700c8154..80f91de0 100644 --- a/src/UrlParams.ts +++ b/src/UrlParams.ts @@ -19,6 +19,8 @@ import { useLocation } from "react-router-dom"; import { Config } from "./config/Config"; +const PASSWORD_STRING = "?password="; + interface UrlParams { roomAlias: string | null; roomId: string | null; @@ -86,6 +88,10 @@ interface UrlParams { * user's homeserver doesn't provide any. */ allowIceFallback: boolean; + /** + * E2EE password + */ + password: string | null; } /** @@ -103,8 +109,17 @@ export const getUrlParams = ( hash = window.location.hash ): UrlParams => { let roomAlias: string | null = null; + let password: string | null = null; + + const passwordIndex = hash.indexOf(PASSWORD_STRING); + const passwordStart = + passwordIndex === -1 ? null : passwordIndex + PASSWORD_STRING.length; + if (passwordStart) { + password = hash.substring(passwordStart); + } + if (!ignoreRoomAlias) { - if (hash === "") { + if (hash === "" || hash.startsWith("#" + PASSWORD_STRING)) { roomAlias = pathname.substring(1); // Strip the "/" // Delete "/room/", if present @@ -164,6 +179,7 @@ export const getUrlParams = ( return { roomAlias, roomId, + password, viaServers: getAllParams("via"), isEmbedded: hasParam("embed"), preload: hasParam("preload"), diff --git a/src/room/LobbyView.tsx b/src/room/LobbyView.tsx index e1edadd5..53bc170b 100644 --- a/src/room/LobbyView.tsx +++ b/src/room/LobbyView.tsx @@ -36,6 +36,7 @@ import { E2EEConfig } from "../livekit/useLiveKit"; import { InputField } from "../input/Input"; import { useEnableE2EE } from "../settings/useSetting"; import { MuteStates } from "./MuteStates"; +import { useUrlParams } from "../UrlParams"; interface Props { matrixInfo: MatrixInfo; @@ -52,6 +53,8 @@ export const LobbyView: FC = ({ isEmbedded, hideHeader, }) => { + const { password } = useUrlParams(); + const { t } = useTranslation(); useLocationNavigation(); @@ -65,7 +68,7 @@ export const LobbyView: FC = ({ }, [joinCallButtonRef]); const [e2eeSharedKey, setE2EESharedKey] = useState( - undefined + password ?? undefined ); const onE2EESharedKeyChanged = useCallback(