diff --git a/apps/meteor/app/e2e/client/helper.js b/apps/meteor/app/e2e/client/helper.js index 49b157c5ccf4..ddf49b262b91 100644 --- a/apps/meteor/app/e2e/client/helper.js +++ b/apps/meteor/app/e2e/client/helper.js @@ -146,3 +146,10 @@ export async function generateMnemonicPhrase(n, sep = ' ') { } return result.join(sep); } + +export async function createSha256Hash(data) { + const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(data)); + return Array.from(new Uint8Array(hash)) + .map((b) => b.toString(16).padStart(2, '0')) + .join(''); +} diff --git a/apps/meteor/app/e2e/client/rocketchat.e2e.room.js b/apps/meteor/app/e2e/client/rocketchat.e2e.room.js index 5b8423e5e647..1b2357067028 100644 --- a/apps/meteor/app/e2e/client/rocketchat.e2e.room.js +++ b/apps/meteor/app/e2e/client/rocketchat.e2e.room.js @@ -1,6 +1,5 @@ import { Base64 } from '@rocket.chat/base64'; import { Emitter } from '@rocket.chat/emitter'; -import { Random } from '@rocket.chat/random'; import EJSON from 'ejson'; import { RoomManager } from '../../../client/lib/RoomManager'; @@ -25,6 +24,7 @@ import { readFileAsArrayBuffer, encryptAESCTR, generateAESCTRKey, + createSha256Hash, } from './helper'; import { log, logError } from './logger'; import { e2e } from './rocketchat.e2e'; @@ -285,7 +285,7 @@ export class E2ERoom extends Emitter { // When a new e2e room is created, it will be initialized without an e2e key id // This will prevent new rooms from storing `undefined` as the keyid if (!this.keyID) { - this.keyID = this.roomKeyId || Random.id(12); + this.keyID = this.roomKeyId || (await createSha256Hash(this.sessionKeyExportedString)).slice(0, 12); } // Import session key for use. @@ -314,7 +314,7 @@ export class E2ERoom extends Emitter { try { const sessionKeyExported = await exportJWKKey(this.groupSessionKey); this.sessionKeyExportedString = JSON.stringify(sessionKeyExported); - this.keyID = Random.id(12); + this.keyID = (await createSha256Hash(this.sessionKeyExportedString)).slice(0, 12); await sdk.call('e2e.setRoomKeyID', this.roomId, this.keyID); await this.encryptKeyForOtherParticipants();