Generate call passwords with secure RNG
This commit is contained in:
@@ -28,7 +28,7 @@ import {
|
|||||||
GroupCallIntent,
|
GroupCallIntent,
|
||||||
GroupCallType,
|
GroupCallType,
|
||||||
} from "matrix-js-sdk/src/webrtc/groupCall";
|
} from "matrix-js-sdk/src/webrtc/groupCall";
|
||||||
import { randomString } from "matrix-js-sdk/src/randomstring";
|
import { encodeUnpaddedBase64 } from "matrix-js-sdk/src/common-crypto/base64";
|
||||||
|
|
||||||
import type { MatrixClient } from "matrix-js-sdk/src/client";
|
import type { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import type { Room } from "matrix-js-sdk/src/models/room";
|
import type { Room } from "matrix-js-sdk/src/models/room";
|
||||||
@@ -74,6 +74,12 @@ function waitForSync(client: MatrixClient) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function secureRandomString(entropyBytes: number): string {
|
||||||
|
const key = new Uint8Array(entropyBytes);
|
||||||
|
crypto.getRandomValues(key);
|
||||||
|
return encodeUnpaddedBase64(key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialises and returns a new standalone Matrix Client.
|
* Initialises and returns a new standalone Matrix Client.
|
||||||
* If true is passed for the 'restore' parameter, a check will be made
|
* If true is passed for the 'restore' parameter, a check will be made
|
||||||
@@ -347,7 +353,7 @@ export async function createRoom(
|
|||||||
|
|
||||||
let password;
|
let password;
|
||||||
if (e2ee) {
|
if (e2ee) {
|
||||||
password = randomString(32);
|
password = secureRandomString(16);
|
||||||
setLocalStorageItem(
|
setLocalStorageItem(
|
||||||
getRoomSharedKeyLocalStorageKey(result.room_id),
|
getRoomSharedKeyLocalStorageKey(result.room_id),
|
||||||
password
|
password
|
||||||
|
|||||||
Reference in New Issue
Block a user