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.
This commit is contained in:
Krille Fear 2021-11-25 15:35:36 +01:00
parent bdb4ad4594
commit 03418bfe8b
4 changed files with 9 additions and 16 deletions

View File

@ -33,7 +33,6 @@ import 'utils/bootstrap.dart';
class Encryption { class Encryption {
final Client client; final Client client;
final bool debug; final bool debug;
final bool enableE2eeRecovery;
bool get enabled => olmManager.enabled; bool get enabled => olmManager.enabled;
@ -53,7 +52,6 @@ class Encryption {
Encryption({ Encryption({
required this.client, required this.client,
this.debug = false, this.debug = false,
required this.enableE2eeRecovery,
}) { }) {
ssss = SSSS(this); ssss = SSSS(this);
keyManager = KeyManager(this); keyManager = KeyManager(this);
@ -232,8 +230,7 @@ class Encryption {
decryptedPayload = json.decode(decryptResult.plaintext); decryptedPayload = json.decode(decryptResult.plaintext);
} catch (exception) { } catch (exception) {
// alright, if this was actually by our own outbound group session, we might as well clear it // alright, if this was actually by our own outbound group session, we might as well clear it
if (client.enableE2eeRecovery && if (exception.toString() != DecryptException.unknownSession &&
exception.toString() != DecryptException.unknownSession &&
(keyManager (keyManager
.getOutboundGroupSession(roomId) .getOutboundGroupSession(roomId)
?.outboundGroupSession ?.outboundGroupSession

View File

@ -219,8 +219,7 @@ class KeyManager {
void maybeAutoRequest(String roomId, String sessionId, String senderKey) { void maybeAutoRequest(String roomId, String sessionId, String senderKey) {
final room = client.getRoomById(roomId); final room = client.getRoomById(roomId);
final requestIdent = '$roomId|$sessionId|$senderKey'; final requestIdent = '$roomId|$sessionId|$senderKey';
if (client.enableE2eeRecovery && if (room != null &&
room != null &&
!_requestedSessionIds.contains(requestIdent) && !_requestedSessionIds.contains(requestIdent) &&
!client.isUnknownSession) { !client.isUnknownSession) {
// do e2ee recovery // do e2ee recovery

View File

@ -514,10 +514,10 @@ class OlmManager {
return _decryptToDeviceEvent(event); return _decryptToDeviceEvent(event);
} catch (_) { } 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 // 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 // ignore: unawaited_futures
runInRoot(() => restoreOlmSession(event.senderId, senderKey)); runInRoot(() => restoreOlmSession(event.senderId, senderKey));
}
rethrow; rethrow;
} }
} }

View File

@ -74,8 +74,6 @@ class Client extends MatrixApi {
DatabaseApi? get database => _database; DatabaseApi? get database => _database;
bool enableE2eeRecovery;
@deprecated @deprecated
MatrixApi get api => this; MatrixApi get api => this;
@ -120,7 +118,6 @@ class Client extends MatrixApi {
/// [databaseBuilder]: A function that creates the database instance, that will be used. /// [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 /// [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. /// [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: /// [verificationMethods]: A set of all the verification methods this client can handle. Includes:
/// KeyVerificationMethod.numbers: Compare numbers. Most basic, should be supported /// KeyVerificationMethod.numbers: Compare numbers. Most basic, should be supported
/// KeyVerificationMethod.emoji: Compare emojis /// KeyVerificationMethod.emoji: Compare emojis
@ -157,7 +154,8 @@ class Client extends MatrixApi {
this.databaseDestroyer, this.databaseDestroyer,
this.legacyDatabaseBuilder, this.legacyDatabaseBuilder,
this.legacyDatabaseDestroyer, this.legacyDatabaseDestroyer,
this.enableE2eeRecovery = false, @Deprecated('This is now always enabled by default.')
bool? enableE2eeRecovery,
Set<KeyVerificationMethod>? verificationMethods, Set<KeyVerificationMethod>? verificationMethods,
http.Client? httpClient, http.Client? httpClient,
Set<String>? importantStateEvents, Set<String>? importantStateEvents,
@ -1074,8 +1072,7 @@ class Client extends MatrixApi {
// make sure to throw an exception if libolm doesn't exist // make sure to throw an exception if libolm doesn't exist
await olm.init(); await olm.init();
olm.get_library_version(); olm.get_library_version();
encryption = encryption = Encryption(client: this);
Encryption(client: this, enableE2eeRecovery: enableE2eeRecovery);
} catch (_) { } catch (_) {
encryption?.dispose(); encryption?.dispose();
encryption = null; encryption = null;