Skip to content

fix(sni,http2): hash TLS cache keys and prevent HTTP/2 timeout connection poisoning (F4) - #8

Open
Derrors wants to merge 1 commit into
masterfrom
fix/f4-sni-key-hygiene-and-http2-poisoning
Open

Derrors wants to merge 1 commit into
masterfrom
fix/f4-sni-key-hygiene-and-http2-poisoning

Conversation

@Derrors

@Derrors Derrors commented Dec 6, 2026

Copy link
Copy Markdown
Owner

Summary

Implements Track F4 hardening in Derrors/idevice without adding any new dependencies or breaking public APIs:

  1. TLS cache private-key hygiene (idevice/src/sni.rs):
    • Replace raw (device_cert, host_cert, host_key) byte buffers in TlsConfigKey with a constant-time-compared, domain-separated, length-prefixed SHA-256 digest ([u8; 32]).
    • Use a self-contained FIPS 180-4 SHA-256 hasher (works across aws-lc, ring, rustcrypto, and wasm32 without coupling rustls to optional sha2) that volatile-zeroizes its state and message block buffers on drop.
    • Raw host_private_key PEM bytes are no longer cloned into or retained by the process-global OnceLock TLS config cache.
    • Add unit tests: sha256_matches_nist_vectors and tls_config_key_isolates_fields_and_distinguishes_host_key_rotation.
  2. HTTP/2 cancel-safe writes & timeout connection-poisoning guard (idevice/src/xpc/http2/mod.rs):
    • Persist outbound frame bytes in a cancel-safe write_buf / write_pos buffer drained via AsyncWriteExt::write so cancelling pump() / read() mid-write (e.g. poll ticks or flow-control timeouts) never tears a SETTINGS ACK, PING ACK, or coalesced WINDOW_UPDATE frame on the wire.
    • Track poisoned: bool on Http2Client: once a multi-frame payload starts queuing chunks, any flow-control timeout, external future cancellation, or error before completion — as well as any transport write/read error, EOF, malformed frame, or flow-control window overflow — poisons the connection so all subsequent calls fail fast with BrokenPipe rather than corrupting the peer stream.
    • Keep pre-send flow-control timeouts at offset == 0 non-poisoning (zero payload bytes sent, cancel-safe write_buf keeps framing intact) so the connection remains reusable once the peer replenishes its window.
    • Record finished_file_transfer_streams only when END_STREAM is actually queued.
    • Add unit tests: partial_send_timeout_poisons_connection_against_subsequent_calls, zero_byte_send_timeout_keeps_connection_usable_after_window_recovers, cancelled_multi_frame_send_poisons_connection, and cancelled_pump_write_preserves_partial_frame_without_tearing.

Test plan

  • Rust 1.99.1 cargo fmt -p idevice -- --check
  • Rust 1.99.1 cargo clippy -p idevice --no-default-features --features "ring,full" --tests -- -D warnings (0 warnings)
  • Rust 1.99.1 cargo test -p idevice --no-default-features --features "ring,full" --lib (115 passed / 0 failed)
  • Rust 1.89.0 MSRV cargo check -p idevice --no-default-features --features "ring,full" --tests & --features "ring"

🤖 Generated with Claude Code

…tion poisoning

- `idevice/src/sni.rs`: replace raw `(device_cert, host_cert, host_key)`
  bytes in `TlsConfigKey` with a constant-time-compared, domain-separated,
  length-prefixed SHA-256 digest (`[u8; 32]`) using a zero-dependency
  FIPS 180-4 hasher that volatile-zeroizes its state and block buffer on
  drop. Raw `host_private_key` PEM bytes are no longer retained in the
  process-global `OnceLock` TLS config cache.
- `idevice/src/xpc/http2/mod.rs`:
  - Persist outbound frame bytes in a cancel-safe `write_buf` / `write_pos`
    buffer drained via `AsyncWriteExt::write`, so cancelling `pump()` /
    `read()` (e.g. poll ticks or flow-control timeouts) mid-write never
    tears a control frame (`SETTINGS` ACK, `PING` ACK, `WINDOW_UPDATE`) on
    the wire.
  - Track `poisoned: bool` on `Http2Client`: once a multi-frame payload
    starts queuing chunks, any flow-control timeout, external cancellation,
    or error before completion (as well as any transport write/read error,
    EOF, malformed frame, or flow-control window overflow) poisons the
    connection so subsequent calls fail fast with `BrokenPipe` instead of
    appending onto a truncated stream. Pre-send timeouts at `offset == 0`
    leave the connection clean and reusable once the window recovers.
  - Record `finished_file_transfer_streams` only when `END_STREAM` is
    actually queued.
- Add unit tests covering NIST SHA-256 vectors, length-prefix isolation and
  host key rotation cache misses, partial-send timeout poisoning, zero-byte
  timeout recovery, external multi-frame cancellation poisoning, and
  cancel-safe mid-frame `pump()` write resumption.

Co-Authored-By: Claude Code <noreply@anthropic.com>
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