From d184be2d22b07bfc7c4e1e6d63ef62d254b21430 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 8 Sep 2020 11:09:09 +0200 Subject: [PATCH] rotate outbound megolm session when somebody leaves the room --- src/matrix/e2ee/RoomEncryption.js | 3 +++ src/matrix/e2ee/megolm/Encryption.js | 4 ++++ src/matrix/room/members/RoomMember.js | 4 ++++ src/matrix/storage/idb/stores/OutboundGroupSessionStore.js | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/src/matrix/e2ee/RoomEncryption.js b/src/matrix/e2ee/RoomEncryption.js index 7d540784..190852d3 100644 --- a/src/matrix/e2ee/RoomEncryption.js +++ b/src/matrix/e2ee/RoomEncryption.js @@ -45,6 +45,9 @@ export class RoomEncryption { } async writeMemberChanges(memberChanges, txn) { + if (memberChanges.some(m => m.hasLeft)) { + this._megolmEncryption.discardOutboundSession(this._room.id, txn); + } return await this._deviceTracker.writeMemberChanges(this._room, memberChanges, txn); } diff --git a/src/matrix/e2ee/megolm/Encryption.js b/src/matrix/e2ee/megolm/Encryption.js index d3c613f6..9b7df4eb 100644 --- a/src/matrix/e2ee/megolm/Encryption.js +++ b/src/matrix/e2ee/megolm/Encryption.js @@ -26,6 +26,10 @@ export class Encryption { this._ownDeviceId = ownDeviceId; } + discardOutboundSession(roomId, txn) { + txn.outboundGroupSessions.remove(roomId); + } + /** * Encrypts a message with megolm * @param {string} roomId diff --git a/src/matrix/room/members/RoomMember.js b/src/matrix/room/members/RoomMember.js index 954de0a4..6b13c721 100644 --- a/src/matrix/room/members/RoomMember.js +++ b/src/matrix/room/members/RoomMember.js @@ -134,4 +134,8 @@ export class MemberChange { get membership() { return this._memberEvent.content?.membership; } + + get hasLeft() { + return this.previousMembership === "join" && this.membership !== "join"; + } } diff --git a/src/matrix/storage/idb/stores/OutboundGroupSessionStore.js b/src/matrix/storage/idb/stores/OutboundGroupSessionStore.js index ef9224be..9710765f 100644 --- a/src/matrix/storage/idb/stores/OutboundGroupSessionStore.js +++ b/src/matrix/storage/idb/stores/OutboundGroupSessionStore.js @@ -19,6 +19,10 @@ export class OutboundGroupSessionStore { this._store = store; } + remove(roomId) { + this._store.delete(roomId); + } + get(roomId) { return this._store.get(roomId); }