fix: accidental OTK uploads on internal fakeSync

This commit is contained in:
Nicolas Werner 2021-08-02 20:51:18 +02:00
parent 0d72d20cf9
commit 162436cc8d
2 changed files with 16 additions and 2 deletions

View File

@ -274,6 +274,14 @@ class OlmManager {
unusedFallbackKey = false;
}
// fixup accidental too many uploads. We delete only one of them so that the server has time to update the counts and because we will get rate limited anyway.
if (keyCount > _olmAccount.max_number_of_one_time_keys()) {
final requestingKeysFrom = {
client.userID: {client.deviceID: 'signed_curve25519'}
};
client.claimKeys(requestingKeysFrom, timeout: 10000);
}
// 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) {

View File

@ -1091,7 +1091,7 @@ class Client extends MatrixApi {
}
if (database != null) {
_currentTransaction = database.transaction(() async {
await handleSync(syncResp);
await _handleSync(syncResp);
if (prevBatch != syncResp.nextBatch) {
await database.storePrevBatch(syncResp.nextBatch, id);
}
@ -1099,7 +1099,7 @@ class Client extends MatrixApi {
await _currentTransaction;
onSyncStatus.add(SyncStatusUpdate(SyncStatus.cleaningUp));
} else {
await handleSync(syncResp);
await _handleSync(syncResp);
}
if (_disposed || _aborted) return;
if (prevBatch == null) {
@ -1145,6 +1145,12 @@ class Client extends MatrixApi {
/// Use this method only for testing utilities!
Future<void> handleSync(SyncUpdate sync, {bool sortAtTheEnd = false}) async {
// ensure we don't upload keys because someone forgot to set a key count
sync.deviceOneTimeKeysCount ??= {'signed_curve25519': 100};
await _handleSync(sync, sortAtTheEnd: sortAtTheEnd);
}
Future<void> _handleSync(SyncUpdate sync, {bool sortAtTheEnd = false}) async {
if (sync.toDevice != null) {
await _handleToDeviceEvents(sync.toDevice);
}