From eeb6647133598abda240d937992d1efa75a08174 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 7 Mar 2024 14:44:06 -0300 Subject: [PATCH] Encrypt subscription --- app/lib/encryption/encryption.ts | 3 +++ app/lib/encryption/room.ts | 12 ++++++++---- app/sagas/createChannel.js | 5 +++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/lib/encryption/encryption.ts b/app/lib/encryption/encryption.ts index 05071d074..8cfd43d9a 100644 --- a/app/lib/encryption/encryption.ts +++ b/app/lib/encryption/encryption.ts @@ -349,6 +349,9 @@ class Encryption { } }; + // Creating the instance is enough to generate room e2ee key + encryptSubscription = (rid: string) => this.getRoomInstance(rid as string); + // Decrypt a subscription lastMessage decryptSubscription = async (subscription: Partial) => { // If the subscription doesn't have a lastMessage just return diff --git a/app/lib/encryption/room.ts b/app/lib/encryption/room.ts index 090582a81..2088e70a2 100644 --- a/app/lib/encryption/room.ts +++ b/app/lib/encryption/room.ts @@ -177,10 +177,14 @@ export default class EncryptionRoom { // Create an encrypted key for this room based on users encryptRoomKey = async () => { - const result = await Services.e2eGetUsersOfRoomWithoutKey(this.roomId); - if (result.success) { - const { users } = result; - await Promise.all(users.map(user => this.encryptRoomKeyForUser(user))); + try { + const result = await Services.e2eGetUsersOfRoomWithoutKey(this.roomId); + if (result.success) { + const { users } = result; + await Promise.all(users.map(user => this.encryptRoomKeyForUser(user))); + } + } catch (e) { + log(e); } }; diff --git a/app/sagas/createChannel.js b/app/sagas/createChannel.js index ed81d82ac..fe81c717d 100644 --- a/app/sagas/createChannel.js +++ b/app/sagas/createChannel.js @@ -9,6 +9,7 @@ import I18n from '../i18n'; import { events, logEvent } from '../lib/methods/helpers/log'; import { goRoom } from '../lib/methods/helpers/goRoom'; import { Services } from '../lib/services'; +import { Encryption } from '../lib/encryption'; const handleRequest = function* handleRequest({ data }) { try { @@ -65,6 +66,10 @@ const handleRequest = function* handleRequest({ data }) { Object.assign(s, sub); }); }); + + if (data.encrypted) { + Encryption.encryptSubscription(sub.rid); + } } catch { // do nothing }