Skip to content

Fix audio nonce reuse, PipeWire capture bursts and the flaky end-to-end test - #8

Closed
rhaist wants to merge 1 commit into
mainfrom
fix-nonce-pipewire-ci
Closed

rhaist wants to merge 1 commit into
mainfrom
fix-nonce-pipewire-ci

Conversation

@rhaist

@rhaist rhaist commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Found while testing podbeam on Debian 14 with PipeWire 1.6 against a real HomePod.

Fixes

  • Audio nonce reuse (security). The ChaCha20-Poly1305 nonce for audio packets was the 16-bit RTP seq. It wraps after 65,536 packets (8 min 43 s) while the session key stays the same, so every session over 9 minutes reused nonces. Now a 64-bit counter from a random start. The fake HomePod records every nonce; the end-to-end test asserts they are distinct and wider than 16 bits (fails with the old code: "audio nonce is only 16 bits").
  • Choppy audio on PipeWire. Capture used the server's default fragment size; pipewire-pulse delivered ~136 ms chunks, more than the 100 ms Cushion maximum, so the queue ran dry ~6×/s (58–59 dropouts per 10 s, real hardware sink, no network loss). Now 10 ms fragments: 1 dropout at start-up, buffer settles at 15–20 ms. pulse_monitor_capture now asserts chunks < 50 ms (fails without the fix: 171 ms).
  • CI red on main. end_to_end_against_fake_homepod started its 2.5 s stop timer before pairing, which is slow in debug builds, so the first keep-alive never went out ("no keep-alive"). The timer now starts when streaming begins. CPU-heavy tests share an RwLock the end-to-end test takes exclusively, so they no longer starve it into gaps (seen as 995/1008 Hz tone failures). 8/8 debug runs green locally, 4/4 on 2 cores.

Also

  • Comments on values that look like secrets but are public (RFC 5054 prime, transient PIN 3939, HKDF labels, shk, test vectors), for reviewers.
  • README: Linux → real HomePod streaming is now tested.

Tested

  • cargo fmt --check, cargo clippy --locked --all-targets -- -D warnings, cargo test (debug and release), both ignored Pulse tests against PipeWire.
  • Real HomePod from Debian/PipeWire: discovery, pairing, streaming with the new nonce, volume following.
  • Not tested: Windows. CI still runs real PulseAudio, not PipeWire, so it cannot reproduce the chunk-size bug.

🤖 Generated with Claude Code

…nd test

- Audio encryption: the ChaCha20-Poly1305 nonce was the 16-bit RTP seq,
  which wraps after 65,536 packets (8 min 43 s) under the same session key.
  Use a 64-bit counter from a random start instead. The fake HomePod now
  records every nonce and the end-to-end test asserts they are distinct
  and wider than 16 bits.
- Linux capture: request 10 ms fragments. With the server default,
  pipewire-pulse delivered ~136 ms chunks, more than the 100 ms Cushion
  can hold, so the queue ran dry ~6 times a second (58 dropouts per 10 s
  on Debian/PipeWire 1.6). pulse_monitor_capture now asserts chunks stay
  under 50 ms; it fails without the fix (171 ms) and passes with it.
- end_to_end_against_fake_homepod (red on main in CI): start the 2.5 s
  stop timer when streaming begins, not before pairing, which is slow in
  debug builds and left no time for the first keep-alive. CPU-heavy tests
  now share a lock that the real-time end-to-end test takes alone, so
  they no longer starve it into gaps in the tone.
- Comments on the values that look like secrets but are public: the
  RFC 5054 prime, the transient PIN, HKDF labels, shk, test vectors.
- README: streaming from Linux to a real HomePod is now tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rhaist

rhaist commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Merged into main locally instead (952f48e).

@rhaist rhaist closed this Nov 9, 2026
@rhaist
rhaist deleted the fix-nonce-pipewire-ci branch November 9, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant