Skip to content

Commit 58ae1cd

Browse files
committed
fix: Skip decryption when ratchet exceeded.
1 parent 0eb920d commit 58ae1cd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/src/e2ee.worker/e2ee.cryptor.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class FrameCryptor {
159159
CryptorError lastError = CryptorError.kNew;
160160
final DedicatedWorkerGlobalScope worker;
161161
int currentKeyIndex = 0;
162-
162+
bool hasValidKey = false;
163163
Completer? _ratchetCompleter;
164164

165165
List<KeySet?> cryptoKeyRing = List.filled(KEYRING_SIZE, null);
@@ -242,6 +242,7 @@ class FrameCryptor {
242242
keyOptions.ratchetSalt,
243243
);
244244
await setKeySetFromMaterial(keySet, keyIndex);
245+
hasValidKey = true;
245246
}
246247

247248
Future<void> setKeySetFromMaterial(KeySet keySet, int keyIndex) async {
@@ -526,7 +527,7 @@ class FrameCryptor {
526527
var initialKeySet = getKeySet(keyIndex);
527528
initialKeyIndex = keyIndex;
528529

529-
if (initialKeySet == null) {
530+
if (initialKeySet == null || !hasValidKey) {
530531
if (lastError != CryptorError.kMissingKey) {
531532
lastError = CryptorError.kMissingKey;
532533
postMessage({
@@ -635,6 +636,7 @@ class FrameCryptor {
635636
/// yet and ratcheting, of course, did not solve the problem. So if we fail RATCHET_WINDOW_SIZE times,
636637
/// we come back to the initial key.
637638
await setKeySetFromMaterial(initialKeySet!, initialKeyIndex);
639+
hasValidKey = false;
638640
}
639641
}
640642
}

0 commit comments

Comments
 (0)