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
No known key found for this signature in database
GPG Key ID: D1D45825D60C24D2
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";
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"),

View File

@ -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<Props> = ({
isEmbedded,
hideHeader,
}) => {
const { password } = useUrlParams();
const { t } = useTranslation();
useLocationNavigation();
@ -65,7 +68,7 @@ export const LobbyView: FC<Props> = ({
}, [joinCallButtonRef]);
const [e2eeSharedKey, setE2EESharedKey] = useState<string | undefined>(
undefined
password ?? undefined
);
const onE2EESharedKeyChanged = useCallback(