Merge branch 'krille/enable-e2eerecovery' into 'main'

chore: Enable E2EE recovery by default

See merge request famedly/company/frontend/famedlysdk!915
This commit is contained in:
Krille Fear 2021-11-26 13:05:13 +00:00
commit 44934d5911
4 changed files with 9 additions and 16 deletions

View File

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

View File

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

View File

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

View File

@ -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<KeyVerificationMethod>? verificationMethods,
http.Client? httpClient,
Set<String>? 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;