Skip to content

Key mode: every handle does a full TLS handshake, never a resumed session - #1297

Merged
GLinnik21 merged 2 commits into
mainfrom
fix/key-mode-no-tls-session-resumption
Nov 9, 2026
Merged

GLinnik21 merged 2 commits into
mainfrom
fix/key-mode-no-tls-session-resumption

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

What broke

main CI went red with no change on our side. Run 42562310791 passed at 04:31 UTC on ubuntu-24.04; re-running the same job at 12:36 failed on ubuntu-26.04, because the ubuntu-latest label moved (runner-images#14748). Two plx_media tests fail deterministically in "host unit tests (default features)" and "(hostsim)", 1971 passed and 2 failed:

  • curlio::keymode_tests::media_seeks_and_reopens_in_key_mode_each_do_their_own_handshake at curlio_keymode_tests.rs:174: a seek in key mode
  • curlio::keymode_tests::media_key_mode_never_reuses_a_kept_alive_connection at :224: the first seek after a read to EOF

The image moved libcurl 8.5.0 / OpenSSL 3.0.13 (24.04) to libcurl 8.18.0 / OpenSSL 3.5.5 (26.04), per the runner-images readmes. In both tests the first key-mode open succeeds and the first key-mode SEEK fails.

Root cause

Key mode (#378: a wrong clock fails the certificate's dates, so the server is recognised by its remembered key) confirms the key twice: libcurl enforces CURLOPT_PINNEDPUBLICKEY, and keypin::confirm re-reads the peer's leaf key from the certificate chain libcurl keeps for CURLOPT_CERTINFO. A handshake that RESUMES a TLS session has no certificate chain, so confirm finds nothing and the attempt is refused as a pin mismatch (rc 90, seek returns false).

Evidence, read from the libcurl sources of both versions:

  • 8.18.0 lib/vtls/openssl.c, Curl_ossl_check_peer_cert: if(data->set.ssl.certinfo && !octx->reused_session) { /* ... Reused sessions do not have cert chains */ ossl_certchain(...) }. For a reused session CERTINFO is deliberately not filled.
  • 8.18.0 lib/vtls/vtls_scache.c: the session cache is data->multi->ssl_scache (or the share handle's), so every easy handle one multi runs shares it. In 8.5.0 (lib/vtls/vtls.c) it was data->state.session, per EASY handle.
  • range_io::CurlSource creates a fresh easy handle per attempt (so before 8.12 it could never find a session) but keeps ONE multi across its attempts. From 8.12 the key-mode attempt of a seek resumes the session the previous key-mode attempt left in the multi. That is why open (first handshake, nothing cached) passes and the seek fails, and why FRESH_CONNECT/FORBID_REUSE (connection reuse) did not help.
  • The control plane is unaffected today: a fresh easy handle per request, with its own internal multi, shares no cache. The shared place is keypin::apply, so it is fixed there for both planes.

It is a real product defect and not a test problem, but not a live one on the fleet: tools/fwcompat.py shows no firmware in the inventory ships libcurl 8.12+, so on today's sets the session cache is per handle. It bites on the first firmware that does, and on the Linux CI runners now.

Fix

keypin::apply also sets CURLOPT_SSL_SESSIONID_CACHE to 0, beside CURLOPT_FRESH_CONNECT and CURLOPT_FORBID_REUSE: a key-mode handle neither resumes a cached TLS session nor stores one, so it always does its own full handshake and the pin and name are checked for that request. It sits in the same fail-closed list, before VERIFYPEER is lowered, so a libcurl that refused it would leave the handle strict.

FFI/compat: an option id (LONG + 150) on the already-bound curl_easy_setopt_long, no new symbol, no DT_NEEDED, no dynlib! change. The option exists since libcurl 7.16.0; fw-compat-reviewer confirmed every firmware image in the database exports symbols of 7.18.0 or newer, and that both callers of apply fail closed on a refusal. The workflow is untouched (no runs-on change, so no build-bench table).

Tests and prose:

  • The TLS doubles count the handshakes they were asked to resume (Observed::resumed). The two red tests keep their assertions and now also assert resumed() == 0.
  • net::key_mode_session_tests puts a shared session cache (a share handle, CURL_LOCK_DATA_SSL_SESSION, libcurl 7.23+) in front of ANY libcurl: a control proves an OpenSSL-backed libcurl does resume over it, then three key-mode transfers on fresh easy handles must each confirm the key and none may resume.
  • plex/CLAUDE.md and the apply doc now name all three options and the reason.

Verification, and what could not be reproduced

  • No container runtime or Linux VM is available on the dev Mac, and building curl 8.18 + OpenSSL from downloaded source was not done (the session's permission policy blocked it), so I did NOT reproduce the failure on a 26.04 libcurl. The host libcurl is macOS SecureTransport 8.7.1, which does not resume against the rustls double even over a share handle (the new control skips there and says so); locally the tests pass before and after. The failure evidence is the deterministic CI failure on 26.04 and the libcurl source above. This PR's CI on ubuntu-latest (26.04) is the first run of the fix on the failing library; the new key-mode test is written to fail there without the fix (round 2 resumes, confirm is false).
  • make test-crate C=plx_net: test result: ok. 300 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  • make test-crate C=plx_media: test result: ok. 1973 passed; 0 failed; 84 ignored; 0 measured; 0 filtered out
  • make check-nodef: finished clean. Full make check is left to this PR's CI.
  • fw-compat-reviewer: no findings (source-only; the ELF and load matrix are CI's). doc-claim-auditor and pr-reviewer: one doc inaccuracy each, fixed in the second commit.

🤖 Generated with Claude Code

GLinnik21 and others added 2 commits November 9, 2026 15:51
…sion

`main` CI went red when `ubuntu-latest` moved from Ubuntu 24.04 (libcurl 8.5.0, OpenSSL 3.0.13) to
26.04 (libcurl 8.18.0, OpenSSL 3.5.5): `media_seeks_and_reopens_in_key_mode_each_do_their_own_handshake`
and `media_key_mode_never_reuses_a_kept_alive_connection` failed on the first key-mode seek.

Key mode confirms the remembered key itself, from the certificate chain libcurl keeps for
`CURLOPT_CERTINFO` (`keypin::confirm`). libcurl's OpenSSL backend skips that chain for a handshake
that resumed a TLS session (`Curl_ossl_check_peer_cert`: "Reused sessions do not have cert chains"),
so a resumed key-mode handshake reads as a pin mismatch (rc 90) and the seek fails closed. Before
libcurl 8.12 the session cache belonged to each easy handle, so the fresh handle every
`CurlSource` attempt gets never found one. From 8.12 it belongs to the multi handle, which the
source keeps across its attempts, so the next key-mode attempt resumed the last one's session.

`keypin::apply` (the one place both planes set up key mode) now also sets
`CURLOPT_SSL_SESSIONID_CACHE` to 0, beside `CURLOPT_FRESH_CONNECT` and `CURLOPT_FORBID_REUSE`: the
handle neither resumes a session nor leaves one. The option has existed since libcurl 7.16.0, and it
is applied before `VERIFYPEER` is lowered like the others, so a libcurl that refuses it leaves the
handle strict.

The TLS doubles now count the handshakes they were asked to resume (`Observed::resumed`), the two
failing tests assert it stays 0, and `key_mode_session_tests` puts a shared session cache in front
of any libcurl through a share handle (a control proves an OpenSSL-backed libcurl does resume over
it, then key-mode transfers prove they do not). The desktop simulator's SecureTransport libcurl
does not resume against the double, so the control skips there and the key-mode test is a
smoke check; the Linux CI runners are where it can fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on cache

Review of the previous commit: the doc claimed strict and roots-mode handles "never read a
certificate back", which is false for the control plane's learning handle. The true reasons are that a
`CurlSource` reads no chain on those handles and the control plane's fresh easy handle per request
shares no session cache. Also drop the claim that libcurl 7.53.1 keys a session by the pin (only
8.12+ does); key mode stores no session, so none can be offered to a verifying handle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit be8495d into main Nov 9, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the fix/key-mode-no-tls-session-resumption branch November 9, 2026 13:14
GLinnik21 pushed a commit that referenced this pull request Nov 10, 2026
## What broke

Two defect classes, both found in field testing on a real television (LG
webOS, armv7l) against a real PMS server (1.43.5):

1. **The retranscode stall** — the last unhandled retranscode path. #1285
   and #1286 covered the transcode *seek* (cold resume admitted at the Feed
   start door, play given back through the startup runner). The remaining
   path is the initial *drop*: a title plays direct, the quality ladder
   drops it, the retranscode lands — and then nothing plays. The log shows
   the pre-Load Play refused, and no further Play is ever attempted; the
   native buffer caps out (`BufferFull`), `pos_ms` stays 0.
2. **Codec declaration kills** — a single title kills playback: The Last
   Duel (an AAC file declared eac3 — the 7.1/AAC kill class — the video
   sink wedges under audioSync); DTS titles refused at Load (the DTS family
   declared `dca` where the demuxer says `dts`); and stale PMS declarations
   lying on **both** codec axes at once, so the one-shot corrective retry
   spent its reload without a single frame playing.

## Why

1. Since #1274 a retranscode landing starts its new stream PAUSED and hands
   the first Play to the user's Resume (the feed_pump Deferred branch) —
   never through the runner's `Operation::Play` — so
   `startup_play_commanded` stayed false. `try_prime`'s startup gate
   (`startup_controlled && !startup_play_commanded`) then blocked the
   prime's post-Load retry **forever**: `play_initial_now`'s physical Play
   landed before the Load worker's Starfish call, was refused, and the code
   never tried again — hence `BufferFull` at the native cap. The physical
   native hold (claim_hold) and the viewer pause goal were also conflated,
   which is what Changes 1-3 of the first commit untangle.
2. `fill_direct_plan` declared the PMS track's `achosen` (or the file's
   default) where the demuxer actually feeds a different codec; a
   single-axis probe on a refused start corrected only the first axis it
   hit, leaving the second mismatched — the one-shot retry then fired on a
   start that was still wrong.

## The fix

1. The Deferred branch now **latches `startup_play_commanded` before firing
   `play_initial_now`**: if the Play is refused pre-Load, the prime stays
   armed (`Held{Initial}`, `user_held` cleared, `resume_acb_pending` set)
   and `try_prime` issues it once loadCompleted has passed and both lanes
   are primed; the Accepted path mirrors `resume_acb` to the player.
   Plus Changes 1-3: the physical hold (`OpenRequest.start_paused`) is
   decoupled from the viewer pause goal (`InitialPlayback.paused`), so the
   post-Load resume path can actually run the clock.
2. **Declare what the pipeline actually feeds** (no-pick → the file's
   default codec; pick → the picked track's codec), map the DTS family to
   `dts`, and probe **BOTH** declared-codec axes in one pass so a single
   corrective reload fixes them together. One-shot, failure-path only —
   nothing in the happy path changed.

## Tests

- `plx_play_feed`: 300/300 pass; `plx_media` suite green, including the
  new 16-cell audio/video declaration matrix (the 7.1/AAC kill class).
- **Live on tv01** — The Dark Knight: 4K direct → 480p drop → retranscode
  at 16 s; the pre-Load Play was refused, then
  `primed: v=791ms a=317ms runway=0ms -> Play` fired after loadCompleted,
  ACB play=1, position advanced 31.4 s → 49.5 s through the timeline end
  with ok=1 and no BufferFull. The initial-transcode regression path
  (direct → retranscode at start) is green: pos 24.6 s → 47.8 s, ok=1.
- `make check` (cargo half), `make check-nodef` and the ARM cross-check:
  green. `make check-cargo` (clippy clean, 18 test binaries in
  parallel): 17/18 pass; the single failure
  (`app::adapters::session::tests::a_signin_after_signout_behind_a_read_only_mount_is_written`)
  did not reproduce — the full lib suite re-ran green (1281/1281, 99 s)
  and the same test passes in isolation on the sibling fifo-API branch.
  is a pre-existing harness race under this container's parallel load,
  not a regression from this branch (this diff touches play-feed, net and
  media route/pump code — no session/storage code). `make check-nodef`
  (`cargo check --lib --no-default-features --features play-uri,play-feed`):
  green. ARM cross-check (cortex-a9, NEON off, frame pointers, debuginfo):
  green. The python half of `make check` — see the host-only note
  below.
- The first CI run on this head caught a real regression the local
  default-feature gates do not cover: `check-cargo-unit-hostsim` runs the
  hostsim suite, where
  `player::pump::flight_tests::an_automatic_direct_original_recovery_flies_without_pausing_the_stream`
  was red. The claim-landing tail recorded `set_reconfigure_pause_goal(!hold)`
  for EVERY landed claim — including hold-less ones — and a hold-less
  claim (the direct Original recovery, no PMS round trip) landed on a
  paused stream. Fixed in `00e0eb37b`: the play goal is recorded only for
  claims that actually held presentation; hold-less landings fall back to
  the stream's own transport state (`feed_start_paused` reads
  `readout().paused()` when no goal is set). The held (retranscode) path
  is behaviourally unchanged — `Some(false)` before and after — so the
  live-verified 4K→480p landing is unaffected. All gates re-ran on the
  fix commit: `make check-cargo` (lint + 18/18 unit binaries, app
  1281/1281), `make check-cargo-unit-hostsim` (18/18 binaries, the
  plx_media hostsim 2332-test suite green, the previously failing flight
  test passing), `make check-nodef`, ARM cross-check.
- Rebased onto `main` (includes #1297, the key-mode TLS session-resumption
  fix — no interaction with this change).

Local note (host only, pre-existing): the python half of `make check`
carries two failures on this workstation — `ci/test_build_gc.py` (16 of 58)
and `ci/test_disk_preflight.py` (1 of 30). This container masks
`/proc/mounts` and `/proc/1`, so `lsof` cannot enumerate open files; the
`tools/disk-budget.py` liveness probe then reads `unknown` and, by design,
fails closed — every fixture tree is kept as `liveness unknown (no lsof)`.
Both tests fail identically on a clean checkout of `af607d8cd` (upstream
`main`): the environment, not this branch; CI runners have a full `/proc`.

The five codec-declaration commits and the two retranscode commits are one
verified unit: the stall fix was developed and tested on the tree with the
declaration fixes in place, and the live verification above ran with all
seven.
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