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

View File

@ -177,11 +177,15 @@ export default class EncryptionRoom {
// Create an encrypted key for this room based on users
encryptRoomKey = async () => {
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);
}
};
// Encrypt the room key to each user in

View File

@ -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
}