parent
686bfa3157
commit
179f73db3a
|
|
@ -262,19 +262,25 @@ class OlmManager {
|
||||||
final haveFallbackKeys = encryption.isMinOlmVersion(3, 2, 0);
|
final haveFallbackKeys = encryption.isMinOlmVersion(3, 2, 0);
|
||||||
// Check if there are at least half of max_number_of_one_time_keys left on the server
|
// Check if there are at least half of max_number_of_one_time_keys left on the server
|
||||||
// and generate and upload more if not.
|
// and generate and upload more if not.
|
||||||
if ((countJson != null &&
|
|
||||||
((countJson.containsKey('signed_curve25519') &&
|
// If the server did not send us a count, assume it is 0
|
||||||
countJson['signed_curve25519'] <
|
final keyCount = countJson?.tryGet<int>('signed_curve25519', 0) ?? 0;
|
||||||
(_olmAccount.max_number_of_one_time_keys() / 2)) ||
|
|
||||||
!countJson.containsKey('signed_curve25519'))) ||
|
// If the server does not support fallback keys, it will not tell us about them.
|
||||||
(haveFallbackKeys &&
|
// If the server supports them but has no key, upload a new one.
|
||||||
unusedFallbackKeyTypes?.contains('signed_curve25519') == false)) {
|
var unusedFallbackKey = true;
|
||||||
|
if (unusedFallbackKeyTypes?.contains('signed_curve25519') == false) {
|
||||||
|
unusedFallbackKey = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only upload keys if they are less than half of the max or we have no unused fallback key
|
||||||
|
if (keyCount < (_olmAccount.max_number_of_one_time_keys() / 2) ||
|
||||||
|
!unusedFallbackKey) {
|
||||||
uploadKeys(
|
uploadKeys(
|
||||||
oldKeyCount:
|
oldKeyCount: keyCount < (_olmAccount.max_number_of_one_time_keys() / 2)
|
||||||
countJson != null ? (countJson['signed_curve25519'] ?? 0) : null,
|
? keyCount
|
||||||
unusedFallbackKey: haveFallbackKeys
|
|
||||||
? unusedFallbackKeyTypes?.contains('signed_curve25519')
|
|
||||||
: null,
|
: null,
|
||||||
|
unusedFallbackKey: haveFallbackKeys ? unusedFallbackKey : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1184,9 +1184,7 @@ class Client extends MatrixApi {
|
||||||
if (sync.deviceLists != null) {
|
if (sync.deviceLists != null) {
|
||||||
await _handleDeviceListsEvents(sync.deviceLists);
|
await _handleDeviceListsEvents(sync.deviceLists);
|
||||||
}
|
}
|
||||||
if ((sync.deviceUnusedFallbackKeyTypes != null ||
|
if (encryptionEnabled) {
|
||||||
sync.deviceOneTimeKeysCount != null) &&
|
|
||||||
encryptionEnabled) {
|
|
||||||
encryption.handleDeviceOneTimeKeysCount(
|
encryption.handleDeviceOneTimeKeysCount(
|
||||||
sync.deviceOneTimeKeysCount, sync.deviceUnusedFallbackKeyTypes);
|
sync.deviceOneTimeKeysCount, sync.deviceUnusedFallbackKeyTypes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -614,8 +614,9 @@ void main() {
|
||||||
expect(client2.deviceID, client1.deviceID);
|
expect(client2.deviceID, client1.deviceID);
|
||||||
expect(client2.deviceName, client1.deviceName);
|
expect(client2.deviceName, client1.deviceName);
|
||||||
if (client2.encryptionEnabled) {
|
if (client2.encryptionEnabled) {
|
||||||
expect(client2.encryption.pickledOlmAccount,
|
expect(client2.encryption.fingerprintKey,
|
||||||
client1.encryption.pickledOlmAccount);
|
client1.encryption.fingerprintKey);
|
||||||
|
expect(client2.encryption.identityKey, client1.encryption.identityKey);
|
||||||
expect(client2.rooms[1].id, client1.rooms[1].id);
|
expect(client2.rooms[1].id, client1.rooms[1].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,13 +112,14 @@ void main() {
|
||||||
FakeMatrixApi.calledEndpoints.containsKey('/client/r0/keys/upload'),
|
FakeMatrixApi.calledEndpoints.containsKey('/client/r0/keys/upload'),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
|
// this will upload keys because we assume the key count is 0, if the server doesn't send one
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
client.encryption.olmManager
|
client.encryption.olmManager
|
||||||
.handleDeviceOneTimeKeysCount(null, ['signed_curve25519']);
|
.handleDeviceOneTimeKeysCount(null, ['signed_curve25519']);
|
||||||
await Future.delayed(Duration(milliseconds: 50));
|
await Future.delayed(Duration(milliseconds: 50));
|
||||||
expect(
|
expect(
|
||||||
FakeMatrixApi.calledEndpoints.containsKey('/client/r0/keys/upload'),
|
FakeMatrixApi.calledEndpoints.containsKey('/client/r0/keys/upload'),
|
||||||
false);
|
true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('restoreOlmSession', () async {
|
test('restoreOlmSession', () async {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue