From a3fc73dfc1b020f6e4e27cf0597feeae45d6e887 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Wed, 20 May 2020 10:24:48 +0200 Subject: [PATCH] make e2ee recovery logic optional --- lib/src/client.dart | 9 ++++++++- lib/src/room.dart | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index f66ac06..8f7a396 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -77,7 +77,14 @@ class Client { Database database; - Client(this.clientName, {this.debug = false, this.database}) { + bool enableE2eeRecovery; + + /// Create a client + /// clientName = unique identifier of this client + /// debug: Print debug output? + /// database: The database instance to use + /// enableE2eeRecovery: Enable additional logic to try to recover from bad e2ee sessions + Client(this.clientName, {this.debug = false, this.database, this.enableE2eeRecovery = false}) { onLoginStateChanged.stream.listen((loginState) { print('LoginState: ${loginState.toString()}'); }); diff --git a/lib/src/room.dart b/lib/src/room.dart index 18a9b7d..8b80e55 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1814,7 +1814,7 @@ class Room { final session = await client.database.getDbInboundGroupSession(client.id, id, sessionId); if (session == null) { // no session found, let's request it! - if (!_requestedSessionIds.contains(sessionId) && senderKey != null) { + if (client.enableE2eeRecovery && !_requestedSessionIds.contains(sessionId) && senderKey != null) { unawaited(requestSessionKey(sessionId, senderKey)); _requestedSessionIds.add(sessionId); } @@ -1876,7 +1876,7 @@ class Room { decryptedPayload = json.decode(decryptResult.plaintext); } catch (exception) { // alright, if this was actually by our own outbound group session, we might as well clear it - if ((_outboundGroupSession?.session_id() ?? '') == event.content['session_id']) { + if (client.enableE2eeRecovery && (_outboundGroupSession?.session_id() ?? '') == event.content['session_id']) { clearOutboundGroupSession(wipe: true); } if (exception.toString() == DecryptError.UNKNOWN_SESSION) {