From 8c748251813e49ff317e57c503a89a1ee024caed Mon Sep 17 00:00:00 2001 From: td <152161658+td-famedly@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:27:45 +0530 Subject: [PATCH] fix: ignore unable to parse frames completely (#530) --- pubspec.lock | 16 ++++------------ web/e2ee.cryptor.dart | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index b3a6d560..60f1615b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -129,14 +129,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.3" - cryptography: - dependency: "direct main" - description: - name: cryptography - sha256: d146b76d33d94548cf035233fbc2f4338c1242fa119013bead807d033fc4ae05 - url: "https://pub.dev" - source: hosted - version: "2.7.0" dart_style: dependency: transitive description: @@ -149,10 +141,10 @@ packages: dependency: "direct main" description: name: dart_webrtc - sha256: fe4db21dc389b99e04cb7bf43bc927dba2e42768d4c28211b66a4b5a16e4d516 + sha256: d663abfe6ed95afadcb64083e364aa16dbeaadead193bb03047cf6913e57b65e url: "https://pub.dev" source: hosted - version: "1.4.5" + version: "1.4.6+hotfix.1" dbus: dependency: transitive description: @@ -236,10 +228,10 @@ packages: dependency: "direct main" description: name: flutter_webrtc - sha256: "1c61bc08d14be57ac28e9e540c44b8b1b9ab1b25bbdb66a8c658e61a3211cc5d" + sha256: fd5f115a08dcdc00b988bea3003c956f1b60a78a61d899cbddfb44f5d0e44d4a url: "https://pub.dev" source: hosted - version: "0.10.7" + version: "0.10.8" glob: dependency: transitive description: diff --git a/web/e2ee.cryptor.dart b/web/e2ee.cryptor.dart index f97fb5ce..da8c25a4 100644 --- a/web/e2ee.cryptor.dart +++ b/web/e2ee.cryptor.dart @@ -258,9 +258,11 @@ class FrameCryptor { })); try { readable.pipeThrough(transformer).pipeTo(writable); - } catch (e) { - logger.warning('e ${e.toString()}'); + } catch (e, s) { + logger.warning('kInternalError: e ${e.toString()} s ${s.toString()}'); if (lastError != CryptorError.kInternalError) { + logger.info( + 'cryptorState changed from $lastError to kInternalError because ${e.toString()}, ${s.toString()}'); lastError = CryptorError.kInternalError; postMessage({ 'type': 'cryptorState', @@ -327,6 +329,7 @@ class FrameCryptor { if (secretKey == null) { if (lastError != CryptorError.kMissingKey) { + logger.info('cryptorState changed from $lastError to kMissingKey'); lastError = CryptorError.kMissingKey; postMessage({ 'type': 'cryptorState', @@ -377,6 +380,7 @@ class FrameCryptor { controller.enqueue(frame); if (lastError != CryptorError.kOk) { + logger.info('cryptorState changed from $lastError to kOk'); lastError = CryptorError.kOk; postMessage({ 'type': 'cryptorState', @@ -391,9 +395,11 @@ class FrameCryptor { logger.finer( 'encrypto kind $kind,codec $codec headerLength: $headerLength, timestamp: ${frame.timestamp}, ssrc: ${metaData.synchronizationSource}, data length: ${buffer.length}, encrypted length: ${finalBuffer.toBytes().length}, iv $iv'); - } catch (e) { - logger.warning('encrypt: e ${e.toString()}'); + } catch (e, s) { + logger.warning('kEncryptError: e ${e.toString()}, s: ${s.toString()}'); if (lastError != CryptorError.kEncryptError) { + logger.info( + 'cryptorState changed from $lastError to kEncryptError because ${e.toString()}, ${s.toString()}'); lastError = CryptorError.kEncryptError; postMessage({ 'type': 'cryptorState', @@ -460,14 +466,21 @@ class FrameCryptor { var headerLength = kind == 'video' ? getUnencryptedBytes(frame, codec) : 1; var metaData = frame.getMetadata(); + Uint8List frameTrailer, iv; + int ivLength, keyIndex; + try { + frameTrailer = buffer.sublist(buffer.length - 2); + ivLength = frameTrailer[0]; + keyIndex = frameTrailer[1]; + iv = buffer.sublist(buffer.length - ivLength - 2, buffer.length - 2); - var frameTrailer = buffer.sublist(buffer.length - 2); - var ivLength = frameTrailer[0]; - var keyIndex = frameTrailer[1]; - var iv = buffer.sublist(buffer.length - ivLength - 2, buffer.length - 2); - - initialKeySet = keyHandler.getKeySet(keyIndex); - initialKeyIndex = keyIndex; + initialKeySet = keyHandler.getKeySet(keyIndex); + initialKeyIndex = keyIndex; + } catch (e) { + logger.finest( + 'getting frameTrailer or iv failed, ignoring frame completely'); + return; + } /// missingKey flow: /// tries to decrypt once, fails, tries to ratchet once and decrypt again, @@ -477,6 +490,7 @@ class FrameCryptor { /// to throw missingkeys faster lower your failureTolerance if (initialKeySet == null || !keyHandler.hasValidKey) { if (lastError != CryptorError.kMissingKey) { + logger.info('cryptorState changed from $lastError to kMissingKey'); lastError = CryptorError.kMissingKey; postMessage({ 'type': 'cryptorState', @@ -526,6 +540,7 @@ class FrameCryptor { logger.finer( 'ratchetKey: lastError != CryptorError.kKeyRatcheted, reset state to kKeyRatcheted'); + logger.info('cryptorState changed from $lastError to kKeyRatcheted'); lastError = CryptorError.kKeyRatcheted; postMessage({ 'type': 'cryptorState', @@ -584,6 +599,7 @@ class FrameCryptor { controller.enqueue(frame); if (lastError != CryptorError.kOk) { + logger.info('cryptorState changed from $lastError to kOk'); lastError = CryptorError.kOk; postMessage({ 'type': 'cryptorState', @@ -598,8 +614,11 @@ class FrameCryptor { logger.finer( 'decrypto kind $kind,codec $codec headerLength: $headerLength, timestamp: ${frame.timestamp}, ssrc: ${metaData.synchronizationSource}, data length: ${buffer.length}, decrypted length: ${finalBuffer.toBytes().length}, keyindex $keyIndex iv $iv'); - } catch (e) { + } catch (e, s) { + logger.warning('kDecryptError ${e.toString()}, s: ${s.toString()}'); if (lastError != CryptorError.kDecryptError) { + logger.info( + 'cryptorState changed from $lastError to kDecryptError ${e.toString()}, ${s.toString()}'); lastError = CryptorError.kDecryptError; postMessage({ 'type': 'cryptorState',