Encrypt subscription

This commit is contained in:
Diego Mello 2024-03-07 14:44:06 -03:00
parent 7cc5511bc1
commit eeb6647133
3 changed files with 16 additions and 4 deletions

View File

@ -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 // Decrypt a subscription lastMessage
decryptSubscription = async (subscription: Partial<ISubscription>) => { decryptSubscription = async (subscription: Partial<ISubscription>) => {
// If the subscription doesn't have a lastMessage just return // If the subscription doesn't have a lastMessage just return

View File

@ -177,10 +177,14 @@ export default class EncryptionRoom {
// Create an encrypted key for this room based on users // Create an encrypted key for this room based on users
encryptRoomKey = async () => { encryptRoomKey = async () => {
const result = await Services.e2eGetUsersOfRoomWithoutKey(this.roomId); try {
if (result.success) { const result = await Services.e2eGetUsersOfRoomWithoutKey(this.roomId);
const { users } = result; if (result.success) {
await Promise.all(users.map(user => this.encryptRoomKeyForUser(user))); const { users } = result;
await Promise.all(users.map(user => this.encryptRoomKeyForUser(user)));
}
} catch (e) {
log(e);
} }
}; };

View File

@ -9,6 +9,7 @@ import I18n from '../i18n';
import { events, logEvent } from '../lib/methods/helpers/log'; import { events, logEvent } from '../lib/methods/helpers/log';
import { goRoom } from '../lib/methods/helpers/goRoom'; import { goRoom } from '../lib/methods/helpers/goRoom';
import { Services } from '../lib/services'; import { Services } from '../lib/services';
import { Encryption } from '../lib/encryption';
const handleRequest = function* handleRequest({ data }) { const handleRequest = function* handleRequest({ data }) {
try { try {
@ -65,6 +66,10 @@ const handleRequest = function* handleRequest({ data }) {
Object.assign(s, sub); Object.assign(s, sub);
}); });
}); });
if (data.encrypted) {
Encryption.encryptSubscription(sub.rid);
}
} catch { } catch {
// do nothing // do nothing
} }