fix: remove BLE packet deduplication causing chacha20poly1305 auth failure#1
Open
dfx01 wants to merge 1 commit into
Open
Conversation
…h failure The seenPackets deduplication logic in BLEConnectionContext incorrectly dropped legitimate BLE packets whose content happened to match previously seen packets. In the Noise Protocol (chacha20poly1305), encrypted packets can legitimately have identical content (e.g. short ACK/response frames). When real packets were silently dropped, the Noise cipher's read buffer became incomplete, causing MAC verification to fail with: panic: chacha20poly1305: message authentication failed The fix removes the content-based deduplication entirely. BLE at the CoreBluetooth layer does not deliver duplicate notifications — the didUpdateValueFor delegate is only called once per actual peripheral notification, so deduplication at this layer is both incorrect and unnecessary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
The
seenPacketsdeduplication logic inBLEConnectionContextincorrectly drops legitimate BLE packets whose payload happens to match a previously received packet.In the Noise Protocol (which uses chacha20poly1305), encrypted packets can legitimately produce identical 64-byte payloads — for example short ACK or response frames. When such a packet was silently dropped, the Noise cipher's read buffer became incomplete and MAC verification failed:
This manifests specifically when calling
GetETHAddress(and likely other operations) after a successful connection and channel hash verification, because those later calls are more likely to produce short encrypted response frames.Fix
Remove the content-based deduplication entirely from
didUpdateValueFor.CoreBluetooth's
didUpdateValueFordelegate is only called once per actual peripheral notification — it does not deliver duplicate notifications. Deduplication at this layer is therefore both incorrect (breaks the Noise cipher) and unnecessary (CoreBluetooth already handles it at the BLE stack level).Changes
seenPackets: Set<Data>field fromBLEConnectionContextdidUpdateValueForctx.seenPackets.removeAll()fromclearReadBuffer()Testing
The fix allows
GetETHAddressand other post-pairing operations to complete successfully by ensuring all BLE packets reach the Noise cipher in order.