Merge branch 'client-fix-logs' into 'master'

[Client] Dont create new inbound session when session matches

See merge request famedly/famedlysdk!214
This commit is contained in:
Christian Pauly 2020-02-20 15:29:16 +00:00
commit 5a4c484db6
2 changed files with 17 additions and 4 deletions

View file

@ -1025,7 +1025,10 @@ class Client {
try {
toDeviceEvent = decryptToDeviceEvent(toDeviceEvent);
} catch (e) {
print("[LibOlm] Could not decrypt to device event: " + e.toString());
print(
"[LibOlm] Could not decrypt to device event from ${toDeviceEvent.sender}: " +
e.toString());
print(toDeviceEvent.sender);
toDeviceEvent = ToDeviceEvent.fromJson(events[i]);
}
}
@ -1320,7 +1323,9 @@ class Client {
Room room = getRoomById(toDeviceEvent.content["room_id"]);
if (room != null && toDeviceEvent.content["session_id"] is String) {
final String sessionId = toDeviceEvent.content["session_id"];
room.setSessionKey(sessionId, toDeviceEvent.content);
if (room != null) {
room.setSessionKey(sessionId, toDeviceEvent.content);
}
}
break;
}
@ -1570,7 +1575,11 @@ class Client {
List<olm.Session> existingSessions = olmSessions[senderKey];
if (existingSessions != null) {
for (olm.Session session in existingSessions) {
if ((type == 0 && session.matches_inbound(body) == 1) || type == 1) {
if (type == 0 && session.matches_inbound(body) != 0) {
plaintext = session.decrypt(type, body);
storeOlmSession(senderKey, session);
break;
} else if (type == 1) {
try {
plaintext = session.decrypt(type, body);
storeOlmSession(senderKey, session);
@ -1679,6 +1688,7 @@ class Client {
};
final olm.EncryptResult encryptResult =
existingSessions.first.encrypt(json.encode(payload));
storeOlmSession(device.curve25519Key, existingSessions.first);
encryptedMessage["ciphertext"][device.curve25519Key] = {
"type": encryptResult.type,
"body": encryptResult.body,

View file

@ -836,7 +836,7 @@ class Room {
.getItem("/clients/${client.deviceID}/rooms/${this.id}/session_keys");
if (sessionKeysPickle?.isNotEmpty ?? false) {
final Map<String, dynamic> map = json.decode(sessionKeysPickle);
this._sessionKeys = {};
if (this._sessionKeys == null) this._sessionKeys = {};
for (var entry in map.entries) {
try {
this._sessionKeys[entry.key] =
@ -848,6 +848,9 @@ class Room {
}
}
}
await client.storeAPI?.setItem(
"/clients/${client.deviceID}/rooms/${this.id}/session_keys",
json.encode(sessionKeys));
_fullyRestored = true;
}