From 03418bfe8bf0bc9b3d0b813021d647e54f017fe1 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Thu, 25 Nov 2021 15:35:36 +0100 Subject: [PATCH] chore: Enable E2EE recovery by default We have disabled it by default to prevent using workarounds as long time solutions and to not miss bugs. But in a federated context we can not be sure that we all Matrix clients are ever bug free and we have now the onEncryptionError Stream anyway. --- lib/encryption/encryption.dart | 5 +---- lib/encryption/key_manager.dart | 3 +-- lib/encryption/olm_manager.dart | 8 ++++---- lib/src/client.dart | 9 +++------ 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index b40a4d76..f49a175c 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -33,7 +33,6 @@ import 'utils/bootstrap.dart'; class Encryption { final Client client; final bool debug; - final bool enableE2eeRecovery; bool get enabled => olmManager.enabled; @@ -53,7 +52,6 @@ class Encryption { Encryption({ required this.client, this.debug = false, - required this.enableE2eeRecovery, }) { ssss = SSSS(this); keyManager = KeyManager(this); @@ -232,8 +230,7 @@ class Encryption { 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 (client.enableE2eeRecovery && - exception.toString() != DecryptException.unknownSession && + if (exception.toString() != DecryptException.unknownSession && (keyManager .getOutboundGroupSession(roomId) ?.outboundGroupSession diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index a531196c..8e182ab0 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -219,8 +219,7 @@ class KeyManager { void maybeAutoRequest(String roomId, String sessionId, String senderKey) { final room = client.getRoomById(roomId); final requestIdent = '$roomId|$sessionId|$senderKey'; - if (client.enableE2eeRecovery && - room != null && + if (room != null && !_requestedSessionIds.contains(requestIdent) && !client.isUnknownSession) { // do e2ee recovery diff --git a/lib/encryption/olm_manager.dart b/lib/encryption/olm_manager.dart index 155be967..05478d18 100644 --- a/lib/encryption/olm_manager.dart +++ b/lib/encryption/olm_manager.dart @@ -514,10 +514,10 @@ class OlmManager { return _decryptToDeviceEvent(event); } catch (_) { // okay, the thing errored while decrypting. It is safe to assume that the olm session is corrupt and we should generate a new one - if (client.enableE2eeRecovery) { - // ignore: unawaited_futures - runInRoot(() => restoreOlmSession(event.senderId, senderKey)); - } + + // ignore: unawaited_futures + runInRoot(() => restoreOlmSession(event.senderId, senderKey)); + rethrow; } } diff --git a/lib/src/client.dart b/lib/src/client.dart index 4ce9629e..15b1db5b 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -74,8 +74,6 @@ class Client extends MatrixApi { DatabaseApi? get database => _database; - bool enableE2eeRecovery; - @deprecated MatrixApi get api => this; @@ -120,7 +118,6 @@ class Client extends MatrixApi { /// [databaseBuilder]: A function that creates the database instance, that will be used. /// [legacyDatabaseBuilder]: Use this for your old database implementation to perform an automatic migration /// [databaseDestroyer]: A function that can be used to destroy a database instance, for example by deleting files from disk. - /// [enableE2eeRecovery]: Enable additional logic to try to recover from bad e2ee sessions /// [verificationMethods]: A set of all the verification methods this client can handle. Includes: /// KeyVerificationMethod.numbers: Compare numbers. Most basic, should be supported /// KeyVerificationMethod.emoji: Compare emojis @@ -157,7 +154,8 @@ class Client extends MatrixApi { this.databaseDestroyer, this.legacyDatabaseBuilder, this.legacyDatabaseDestroyer, - this.enableE2eeRecovery = false, + @Deprecated('This is now always enabled by default.') + bool? enableE2eeRecovery, Set? verificationMethods, http.Client? httpClient, Set? importantStateEvents, @@ -1074,8 +1072,7 @@ class Client extends MatrixApi { // make sure to throw an exception if libolm doesn't exist await olm.init(); olm.get_library_version(); - encryption = - Encryption(client: this, enableE2eeRecovery: enableE2eeRecovery); + encryption = Encryption(client: this); } catch (_) { encryption?.dispose(); encryption = null;