Get E2EE password from the URL

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2023-08-04 13:39:59 +02:00
parent 264e34f1b0
commit 1a5898eb30
2 changed files with 21 additions and 2 deletions

View File

@@ -19,6 +19,8 @@ import { useLocation } from "react-router-dom";
import { Config } from "./config/Config"; import { Config } from "./config/Config";
const PASSWORD_STRING = "?password=";
interface UrlParams { interface UrlParams {
roomAlias: string | null; roomAlias: string | null;
roomId: string | null; roomId: string | null;
@@ -86,6 +88,10 @@ interface UrlParams {
* user's homeserver doesn't provide any. * user's homeserver doesn't provide any.
*/ */
allowIceFallback: boolean; allowIceFallback: boolean;
/**
* E2EE password
*/
password: string | null;
} }
/** /**
@@ -103,8 +109,17 @@ export const getUrlParams = (
hash = window.location.hash hash = window.location.hash
): UrlParams => { ): UrlParams => {
let roomAlias: string | null = null; 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 (!ignoreRoomAlias) {
if (hash === "") { if (hash === "" || hash.startsWith("#" + PASSWORD_STRING)) {
roomAlias = pathname.substring(1); // Strip the "/" roomAlias = pathname.substring(1); // Strip the "/"
// Delete "/room/", if present // Delete "/room/", if present
@@ -164,6 +179,7 @@ export const getUrlParams = (
return { return {
roomAlias, roomAlias,
roomId, roomId,
password,
viaServers: getAllParams("via"), viaServers: getAllParams("via"),
isEmbedded: hasParam("embed"), isEmbedded: hasParam("embed"),
preload: hasParam("preload"), preload: hasParam("preload"),

View File

@@ -36,6 +36,7 @@ import { E2EEConfig } from "../livekit/useLiveKit";
import { InputField } from "../input/Input"; import { InputField } from "../input/Input";
import { useEnableE2EE } from "../settings/useSetting"; 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;
@@ -52,6 +53,8 @@ export const LobbyView: FC<Props> = ({
isEmbedded, isEmbedded,
hideHeader, hideHeader,
}) => { }) => {
const { password } = useUrlParams();
const { t } = useTranslation(); const { t } = useTranslation();
useLocationNavigation(); useLocationNavigation();
@@ -65,7 +68,7 @@ export const LobbyView: FC<Props> = ({
}, [joinCallButtonRef]); }, [joinCallButtonRef]);
const [e2eeSharedKey, setE2EESharedKey] = useState<string | undefined>( const [e2eeSharedKey, setE2EESharedKey] = useState<string | undefined>(
undefined password ?? undefined
); );
const onE2EESharedKeyChanged = useCallback( const onE2EESharedKeyChanged = useCallback(