Merge branch 'soru/e2ee-recovery-option' into 'master'

make e2ee recovery logic optional

See merge request famedly/famedlysdk!315
This commit is contained in:
Christian Pauly 2020-05-20 08:31:47 +00:00
commit 73904a95e3
2 changed files with 10 additions and 3 deletions

View File

@ -77,7 +77,14 @@ class Client {
Database database; 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) { onLoginStateChanged.stream.listen((loginState) {
print('LoginState: ${loginState.toString()}'); print('LoginState: ${loginState.toString()}');
}); });

View File

@ -1814,7 +1814,7 @@ class Room {
final session = await client.database.getDbInboundGroupSession(client.id, id, sessionId); final session = await client.database.getDbInboundGroupSession(client.id, id, sessionId);
if (session == null) { if (session == null) {
// no session found, let's request it! // 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)); unawaited(requestSessionKey(sessionId, senderKey));
_requestedSessionIds.add(sessionId); _requestedSessionIds.add(sessionId);
} }
@ -1876,7 +1876,7 @@ class Room {
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 ((_outboundGroupSession?.session_id() ?? '') == event.content['session_id']) { if (client.enableE2eeRecovery && (_outboundGroupSession?.session_id() ?? '') == event.content['session_id']) {
clearOutboundGroupSession(wipe: true); clearOutboundGroupSession(wipe: true);
} }
if (exception.toString() == DecryptError.UNKNOWN_SESSION) { if (exception.toString() == DecryptError.UNKNOWN_SESSION) {