Compare commits

...

4 Commits

Author SHA1 Message Date
David Baker
e9798441f7 Merge remote-tracking branch 'origin/livekit' into dbkr/use_secure_random 2023-10-06 16:18:53 +01:00
David Baker
bc36acafc8 Merge pull request #1704 from vector-im/dbkr/refactor_room_create
Refactor room creation code a little
2023-10-06 16:18:18 +01:00
David Baker
87d5062d34 Don't use js-sdk's base64 encode function
It uses the NodeJS Buffer global which presumably is provided by
Webpack in element-web but isn't here, apparently.
2023-10-05 17:57:23 +01:00
David Baker
d373081db1 Generate call passwords with secure RNG 2023-10-05 17:32:43 +01:00

View File

@@ -28,7 +28,6 @@ import {
GroupCallIntent,
GroupCallType,
} from "matrix-js-sdk/src/webrtc/groupCall";
import { randomString } from "matrix-js-sdk/src/randomstring";
import type { MatrixClient } from "matrix-js-sdk/src/client";
import type { Room } from "matrix-js-sdk/src/models/room";
@@ -74,6 +73,14 @@ function waitForSync(client: MatrixClient) {
});
}
function secureRandomString(entropyBytes: number): string {
const key = new Uint8Array(entropyBytes);
crypto.getRandomValues(key);
return btoa(
key.reduce((acc, current) => acc + String.fromCharCode(current), "")
).replace(/=*$/, "");
}
/**
* Initialises and returns a new standalone Matrix Client.
* If true is passed for the 'restore' parameter, a check will be made
@@ -347,7 +354,7 @@ export async function createRoom(
let password;
if (e2ee) {
password = randomString(32);
password = secureRandomString(16);
setLocalStorageItem(
getRoomSharedKeyLocalStorageKey(result.room_id),
password