From 2214ac2d0a5bfdb66122b6c697e25f985b7b9665 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Mon, 20 Jul 2020 06:31:05 +0000 Subject: [PATCH] fixes a racing condition in key verification --- lib/encryption/utils/key_verification.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/encryption/utils/key_verification.dart b/lib/encryption/utils/key_verification.dart index 90a2479..e4a43f3 100644 --- a/lib/encryption/utils/key_verification.dart +++ b/lib/encryption/utils/key_verification.dart @@ -194,8 +194,14 @@ class KeyVerification { } } + bool _handlePayloadLock = false; + Future handlePayload(String type, Map payload, [String eventId]) async { + while (_handlePayloadLock) { + await Future.delayed(Duration(milliseconds: 50)); + } + _handlePayloadLock = true; print('[Key Verification] Received type ${type}: ' + payload.toString()); try { var thisLastStep = lastStep; @@ -307,6 +313,8 @@ class KeyVerification { if (deviceId != null) { await cancel('m.invalid_message'); } + } finally { + _handlePayloadLock = false; } } @@ -529,8 +537,8 @@ class KeyVerification { Future send(String type, Map payload) async { makePayload(payload); print('[Key Verification] Sending type ${type}: ' + payload.toString()); - print('[Key Verification] Sending to ${userId} device ${deviceId}'); if (room != null) { + print('[Key Verification] Sending to ${userId} in room ${room.id}'); if (['m.key.verification.request'].contains(type)) { payload['msgtype'] = type; payload['to'] = userId; @@ -544,6 +552,7 @@ class KeyVerification { encryption.keyVerificationManager.addRequest(this); } } else { + print('[Key Verification] Sending to ${userId} device ${deviceId}'); await client.sendToDevice( [client.userDeviceKeys[userId].deviceKeys[deviceId]], type, payload); }