mirror of
https://github.com/Discreetly/frontend.git
synced 2026-01-09 21:08:02 -05:00
salt based on roomId for encrypted room messages
This commit is contained in:
@@ -39,12 +39,12 @@ function getSalt(): Uint8Array {
|
||||
* @param {string} password - The password to derive the encryption key from.
|
||||
* @returns {Promise<CryptoKey>} - Returns the derived key as a Promise.
|
||||
*/
|
||||
export async function deriveKey(password: string): Promise<CryptoKey> {
|
||||
export async function deriveKey(password: string, saltString?: string): Promise<CryptoKey> {
|
||||
// TextEncoder will be used for converting strings to byte arrays
|
||||
const textEncoder = new TextEncoder();
|
||||
|
||||
// Salt for PBKDF2 stored in local storage
|
||||
const salt = getSalt();
|
||||
const salt = saltString ? textEncoder.encode(saltString) : getSalt();
|
||||
|
||||
// Importing the password as a cryptographic key
|
||||
const passwordKey = await window.crypto.subtle.importKey(
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
throw new Error('ROOM IS ENCRYPTED BUT NO PASSWORD WAS FOUND');
|
||||
}
|
||||
if (!$roomKeyStore[roomId]) {
|
||||
key = await deriveKey($roomPassStore[roomId].password);
|
||||
key = await deriveKey($roomPassStore[roomId].password, roomId);
|
||||
$roomKeyStore[roomId] = key;
|
||||
} else {
|
||||
key = $roomKeyStore[roomId];
|
||||
|
||||
Reference in New Issue
Block a user