Skip to content

v0.1.68-2: security, stability, HTTP/2 & XPC performance, and P2 API overhaul - #3

Merged
Derrors merged 6 commits into
masterfrom
feat/v0.1.68-2
Dec 5, 2026
Merged

Derrors merged 6 commits into
masterfrom
feat/v0.1.68-2

Conversation

@Derrors

@Derrors Derrors commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Summary

Comprehensive fork upgrade (feat/v0.1.68-2 -> target tag v0.1.68-2 after review and two-device real hardware regression) addressing all P0/P1/P2 audit items:

P0 — Security & Stability

  1. HTTP/2 RFC 9113 hardening (76644c0):
    • Mask reserved high bit (0x7FFF_FFFF) on stream_id and WINDOW_UPDATE increment; handle PADDED DATA frames.
    • Ignore unknown SETTINGS parameters (RFC 9113 §6.5.2) and unknown/unused frame types (PRIORITY, PUSH_PROMISE, CONTINUATION, extensions); parse PING and auto-reply PING ACK.
    • Slice outbound DATA frames to min(remaining, 16384, conn_win, stream_win) (fixing InitialWindowSize < 16384 deadlock), flush queued frames before waiting, and bound flow-control wait with a configurable timeout (30s default).
  2. rsa 0.9 -> 0.10.0 & x509-cert 0.2 -> 0.3.1 + Credential Debug redaction (dab5582):
    • Eliminates RUSTSEC-2023-0071 (Marvin Attack) in idevice using sha2_011 (0.11.3, skipping yanked 0.11.2) and a custom BuilderProfile reproducing exact iOS lockdownd certificate extensions and subjects ("" / CN=Device). Removes unused dep:rsa from remote_pairing.
    • Manual Debug redacting private keys / escrow_bag / alt_irk on PairingFile (both rustls & openssl cfgs), RawPairingFile, CaReturn, and RpPairingFile; stops logging raw RpPairingFile plist dicts.
    • Removes .unwrap() on ca::generate_certificates in LockdownClient.
  3. Wire-length bounds, panic elimination & HEVC wraparound (69735c0):
    • 64 MiB cap on post-auth read_plist_value, XPCMessage::decode, AfcPacketHeader, and DVT Message::from_reader; 4 MiB cap on os_trace_relay.
    • Eliminates todo!() / .unwrap() in XPCObject::from(plist::Value), adds XPC depth cap (64), check-before-alloc for String/Data/Array/Dictionary and DVT Aux::read_exact_vec, bit-op padding, checked arithmetic across AFC / DVT / XPC / os_trace_relay.
    • Fixes HevcDepacketizer reorder gap-skip across 16-bit RTP sequence wraparound (RFC 1982 modular distance + stale key pruning).
  4. NetworkSession liveness & timeouts (b90a140):
    • TCP keepalive (15s idle / 5s interval / 3 retries) and Linux TCP_USER_TIMEOUT (30s) via socket2 (native only), 10s default connect timeout, configurable set_connect_timeout / set_retry_backoff.
  5. Collision-free install staging (b90a140):
    • Unique PublicStaging/<stem>-<hex>.<ext> staging paths preserving .ipa/.ipcc/.app extensions; cleans stale remote_name doc comments.

P1 — Performance & Resource Efficiency

  • Threshold-coalesced WINDOW_UPDATE (76644c0): (win / 4).clamp(16 KiB, 256 KiB) capped at win / 2 (256 KiB on RemoteXPC 1 MiB window), written in one 26-byte write+flush, skipping stream updates on END_STREAM/RST_STREAM.
  • Zero-copy XPCObject::into_plist(self) + dict.remove("image") (69735c0): eliminates two multi-MiB buffer clones per screenshot.
  • Per-device bounded Arc<rustls::ClientConfig> cache & connect_service_socket dedup (b90a140): keyed by (device_cert, host_cert, host_private_key) (LRU 16) to keep distinct devices' session caches isolated under shared SNI "Device"; single get_pairing_file() per connect; UniqueDeviceID fetched only for com.apple.mobilebackup2; new LockdownClient::start_service_stream.
  • Unconditional CoreDeviceProxy::with_mtu & connect_with_mtu (b90a140).

P2 — Public APIs Eliminating iphone-control Workarounds (7e1def8)

  • Standalone os_trace_relay Cargo feature (syslog_relay implies it), os_trace_relay::stream_flags, and OsTraceRelayClient::start_trace_with_flags.
  • AppServiceClient::launch_application_with_payload_url.
  • PasteboardServiceClient::set_items + PasteboardSourceMetadata + PasteboardWriteItem.
  • Structured utils::ns_error::NsErrorInfo with recursive NSKeyedArchive Uid resolution through NSError / NSUserInfo / NSUnderlyingError, wired into CoreDeviceError::DeviceError, PasteboardPayload::Error, and both XCT_UI_INIT_DID_FAIL & XCT_DID_FAIL_BOOTSTRAP.
  • dvt::message::PayloadHeader::{return_value, with_msg_type, msg_type}.

Verification

  • cargo fmt -p idevice -- --check — clean
  • cargo clippy -p idevice --features full --lib --tests -- -D warnings — 0 warnings
  • cargo clippy -p idevice --no-default-features --features ring,pair,os_trace_relay,core_device,dvt,xctest,tunnel_tcp_stack,usbmuxd,tcp,display_stream,afc,heartbeat,installation_proxy,mobile_image_mounter,tss,screenshotr,springboardservices,wda,rsd,xpc --lib -- -D warnings — 0 warnings
  • cargo check -p idevice --no-default-features --features ring,os_trace_relay & ring,pair — clean
  • cargo test -p idevice --features full --lib — 92 passed, 0 failed (+23 new unit tests)
  • cargo test -p idevice --features full --test paired_tls — 8 passed, 0 failed

🤖 Generated with Claude Code

Derrors and others added 6 commits December 5, 2026 16:24
…esced WINDOW_UPDATE

- Mask the reserved high bit on HTTP/2 stream IDs and WINDOW_UPDATE
  increments (RFC 9113 §4.1, §6.9), and handle PADDED DATA frames.
- Ignore unknown SETTINGS parameters (RFC 9113 §6.5.2) and unknown/unused
  frame types (PRIORITY, PUSH_PROMISE, CONTINUATION, extensions) instead of
  tearing down the connection; parse PING frames and auto-reply PING ACK.
- Slice outbound DATA frames to `min(remaining, 16384, conn_win, stream_win)`
  so peers advertising `InitialWindowSize < 16384` (or a partially consumed
  window) never deadlock, flush queued frames before waiting, and bound
  flow-control waits with a configurable timeout (30s default).
- Coalesce inbound WINDOW_UPDATE frames to a per-window threshold
  `(win / 4).clamp(16 KiB, 256 KiB)` (capped at `win / 2`) written in one
  contiguous 26-byte write+flush, and skip stream WINDOW_UPDATE after
  END_STREAM / RST_STREAM.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…dact credential Debug output

- Upgrade `rsa` 0.9 -> 0.10 (`pkcs1v15`) and `x509-cert` 0.2 -> 0.3 with
  `sha2_011` (`sha2` 0.11.3, skipping yanked 0.11.2) for the `pair` feature,
  eliminating `RUSTSEC-2023-0071` (Marvin Attack). Preserve exact iOS
  lockdownd certificate extensions (SKI, BasicConstraints ca=true, KeyUsage,
  empty host CA subject and `CN=Device` subject) via a custom
  `BuilderProfile`. Remove unused `dep:rsa` from `remote_pairing`.
- Replace derived `Debug` on `PairingFile` (both rustls and openssl cfgs),
  `RawPairingFile`, and `CaReturn` with manual impls redacting private keys
  and `escrow_bag`; redact `e_private_key` and `alt_irk` in `RpPairingFile`
  `Debug` and stop logging raw `RpPairingFile` plist dictionaries.
- Replace `.unwrap()` on `ca::generate_certificates` in `LockdownClient`
  with an `IdeviceError::UnexpectedResponse` propagation.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…PC->plist, and fix HEVC wraparound

- Cap post-auth plist length in `Idevice::read_plist_value` to 64 MiB.
- Harden XPC wire format (`xpc/format.rs`, `xpc/mod.rs`):
  - Replace `todo!()` / `.unwrap()` in `From<plist::Value>` with full
    `Date`/`Uid`/`UInt64` handling and safe `Date` encoding.
  - Bound `XPCMessage::decode` `body_len` (64 MiB) with checked `+ 24`,
    cap container recursion depth at 64, check remaining cursor bytes
    before allocating `String`/`Data`/`Array`/`Dictionary`, replace
    float padding with `(4 - (len & 3)) & 3` and stack zeros, and check
    `wrapper_len` addition in `strip_xpc_wrapper_prefix`.
  - Add consuming `XPCObject::into_plist(self)` and use it in
    `RemoteXpcClient::recv_any`/`recv_from_channel` + `dict.remove("image")`
    in `ScreenCaptureServiceClient::take_screenshot` to eliminate two
    multi-MiB clones per screenshot.
- Validate `AfcPacketHeader` (`entire_len <= 64 MiB`, checked subtraction
  for `header_payload_len >= 40` and `entire_len >= header_payload_len`).
- Harden DVT `Message::from_reader` & `Aux::from_bytes` (`fragment_count > 0`,
  `fragment_id < fragment_count`, max 4096 fragments / 64 MiB message,
  checked slicing/arithmetic, and check-before-alloc in `read_exact_vec`).
- Bound `os_trace_relay` packet length (4 MiB) and replace unchecked
  `- 1` slices with `take_cstr` (`strip_suffix(b"\0")`).
- Fix `HevcDepacketizer` reorder gap-skip to pick the earliest buffered
  key in modular 16-bit sequence order (RFC 1982) instead of numeric min,
  and prune stale keys behind the jump.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…TLS cache, and CoreDeviceProxy MTU API

- NetworkSession (`network_session.rs`): enable TCP keepalive (15s idle /
  5s interval / 3 retries) and Linux `TCP_USER_TIMEOUT` (30s) via `socket2`
  (native targets only), add a 10s default connect timeout, and expose
  `set_connect_timeout` / `set_retry_backoff`.
- Installation helpers (`utils/installation/helpers.rs`, `mod.rs`): generate
  unique `PublicStaging/<stem>-<hex>.<ext>` paths per upload so concurrent
  installs/retries never collide, and remove stale `remote_name` docs.
- Per-device TLS config cache (`sni.rs`, `lib.rs`): cache `Arc<ClientConfig>`
  keyed by `(device_cert, host_cert, host_private_key)` (bounded LRU of 16)
  to avoid rebuilding verifiers/keys per connect while keeping distinct
  devices' rustls session caches isolated despite shared SNI `"Device"`.
- Service connect dedup (`lib.rs`, `services/lockdown.rs`): fetch the
  pairing file once per `connect_service_socket`, query `UniqueDeviceID`
  only for `com.apple.mobilebackup2`, and add `LockdownClient::start_service_stream`.
- CoreDeviceProxy (`services/core_device_proxy.rs`): expose `pub with_mtu`
  and unconditional `pub connect_with_mtu(provider, mtu)`.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…d set_items, structured NSError, DVT return_value)

- `os_trace_relay`: add standalone `os_trace_relay` Cargo feature (with
  `syslog_relay` implying it for backwards compatibility), expose
  `os_trace_relay::stream_flags` (`DEFAULT`, `LIVE`, bit constants), and
  add `OsTraceRelayClient::start_trace_with_flags(pid, message_filter, stream_flags)`.
- `AppServiceClient`: add `launch_application_with_payload_url` inserting
  `options.payloadURL = { relative: url }` when provided.
- `PasteboardServiceClient`: add `PasteboardSourceMetadata`,
  `PasteboardWriteItem`, and `set_items` so callers can restore multi-item
  / multi-UTI clipboards and pass `sourceMetadata` for local-only writes
  (avoiding Universal Clipboard broadcast).
- `utils::ns_error`: add structured `NsErrorInfo` + recursive
  `NSKeyedArchive` Uid resolver that follows references through custom
  `NSError` objects and nested `NSUserInfo` / `NSUnderlyingError` chains;
  wire it into `CoreDeviceError::DeviceError`, `PasteboardPayload::Error`,
  and both `XCT_UI_INIT_DID_FAIL` & `XCT_DID_FAIL_BOOTSTRAP` in `dvt::xctest`.
- `dvt::message::PayloadHeader`: add `return_value()` (`msg_type = 3`),
  `with_msg_type(u8)`, and `msg_type() -> u8`.
- Apply `cargo fmt` polish, `TlsConfigCache` type alias in `sni.rs`, and
  fix private intra-doc link on `CoreDeviceProxy::connect_with_mtu`.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…ardening

- HTTP/2: reject stream_id 0 on DATA and RST_STREAM (RFC 9113 §6.1/§6.4),
  force stream_id 0 on SETTINGS ACK (§6.5), enforce 2^31-1 flow-control
  window ceiling on WINDOW_UPDATE and SETTINGS deltas (§6.9.1/§6.9.2), and
  clamp available send window before casting to usize (prevents 32-bit
  truncation to 0).
- utils::ns_error: add MAX_ARCHIVE_NODES (4096) visit budget to block DAG
  amplification bombs within MAX_ARCHIVE_DEPTH, and unwrap CoreDevice Swift
  Codable {"string": "..."} / {"error": ...} userInfo wrappers.
- dvt/process_control & message: route launch_app and launch_with_options
  error reporting through utils::ns_error (removing private
  extract_ns_error_message and gating xctest-only helpers), use wrapping_neg
  for i32::MIN channel negation, read DVT fragments directly into packet_data
  without doubling peak memory, and bound Aux::from_bytes cursor to body_end.
- xpc/format & os_trace_relay & core_device_proxy: cap initial XPC container
  preallocation at 4096 entries, bound create_archive chunk reads at 64 MiB,
  and use saturating_sub(60) when computing jktcp MSS from arbitrary MTU.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Derrors
Derrors merged commit ef8fbee into master Dec 5, 2026
2 checks passed
@Derrors
Derrors deleted the feat/v0.1.68-2 branch December 5, 2026 09: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