Skip to content

HelloRetryRequest as uTLS answers it: one key share, the cookie's place, padding per flight (stacked on #256) - #258

Merged
aimalygin merged 1 commit into
mainfrom
claude/hrr-retry-shaping
Nov 10, 2026
Merged

aimalygin merged 1 commit into
mainfrom
claude/hrr-retry-shaping

Conversation

@aimalygin

Copy link
Copy Markdown
Owner

Stacked on #256 (base: claude/xray-v26-11-9-ech-grease-length); the coordinator retargets it to main once #256 is merged. It pins shaped-rustls ca91d48c from aimalygin/shaped-rustls#1. On 2026-11-10 the owner allowed changing the fork to fix this in 0.10.0. Merging needs the owner's word, together with the fork PR.

What broke

A uTLS-shaped hello mishandled a HelloRetryRequest. Against OpenSSL 3.5.9's s_server, results on main before #252 (7b58fa5) and on #256 alike:

  • A retry that names a group (-groups P-256). Every Chrome profile's second ClientHello kept the GREASE key share next to the P-256 one. RFC 8446 §4.1.2 asks for the requested share alone. OpenSSL answered illegal_parameter, and Go's crypto/tls server refuses the same.
  • A retry carrying a cookie. The planned extension order had no cookie, so rustls refused to build the second ClientHello.
  • Padding. The second ClientHello was padded to the first one's target. uTLS recomputes BoringSSL's padding from its own length.

uTLS keeps the requested share alone, inserts the cookie at p.Intn(len(Extensions) - 2), anywhere but the last two places, and pads by the second ClientHello's length (handshake_client_tls13.go). It takes a server sharing no key share group with the profile, or one sending a cookie, to ask for a retry; for the Chrome profiles that means neither X25519 nor X25519MLKEM768. A server held to P-256, such as a FIPS-only one, broke every Chrome-shaped handshake.

Changes

  • The fork (ca91d48c):
    • a retry that names a group skips the plan's raw key shares and its GREASE key share;
    • ClientHelloPaddingPlan::boringssl(offset) applies BoringSSL's rule to each ClientHello as it is encoded.
  • The cookie, which needs no fork change:
    • HelloDraws draws the cookie's place as uTLS's p.Intn(n - 2) does.
    • planned_extensions puts 0x002c there in this hello's extension list: the drawn order plus the ALPN extension the http/1.1 override appends.
    • The planned order and the GREASE positions both read that one list.
    • shaped-rustls drops the entry from a ClientHello that carries no cookie, so first-flight bytes are unchanged; every byte-exact oracle fixture passes.
  • Padding:
    • boringssl(offset) with offset = 2 × (suites the provider filters) − 7 for the supported_versions rustls adds to a TLS-1.2-era hello. Every other extension is as long as uTLS's.
    • Chrome ECH GREASE length per connection, padding as BoringSSL pads #256's utls_unpadded_len, which modelled the server name, the ALPN list and the ECH draw, is gone: the fork measures each ClientHello.
  • The ALPN override is counted once, in that list, for the order, the GREASE positions and the cookie's place alike.

Tests

  • tests/utls_hello_retry_tests.rs, a scripted server sending hand-built HelloRetryRequests:
    • Naming P-256, for chrome, 133, 131, 120 and 120_pq: the second ClientHello carries the P-256 share alone.
    • A cookie alone, for chrome, 133, and randomizednoalpn with the http/1.1 override (which appends ALPN):
      • the cookie is echoed and the key shares are unchanged;
      • over 512 retries each, the cookie takes exactly the places 0..n-2;
      • a client that cannot build its second ClientHello fails the test within ten seconds instead of hanging.
    • Chrome 120's padding per flight, after either retry, with BoringSSL's rule restated: with the 186-byte ECH, padded, then unpadded after P-256 (+28 bytes) and padded after a cookie (+10).
  • utls_shaping:
    • the_padding_offset_brings_our_hellos_to_utls_lengths: our unpadded length plus the offset equals uTLS's, for all 30 committed oracle hellos, each ECH length and the http/1.1 override's shapes included;
    • the_padding_offset_counts_filtered_suites_and_the_added_supported_versions;
    • the BoringSSL sweep over every padded profile (server names of 1 to 253 bytes, IP literals, a trailing dot, with and without the override) now runs on the fork's per-flight mode.
  • Mutations: 8 of 8 caught (the cookie's place reaching the second-to-last place or stuck first, the cookie never planned, the override's ALPN left out, the filtered suites counted once, the supported_versions term dropped, no offset, GREASE positions counted without the cookie) on this side and 11 of 11 in the fork.
  • Live:
    • OpenSSL 3.5.9 s_server -groups P-256 (ignored test, XRAY_HRR_OPENSSL): chrome, 133, 131 and 120 complete. Before the fix every Chrome profile got illegal_parameter.
    • Xray-core v26.11.9's TLS inbound with curvePreferences: ["CurveP256"] (new ignored test; the HelloRetryRequest comes from Go itself): 16 flows each for chrome, 133, 131 and 120.
    • s_server -stateless is not used. It is the only s_server mode that sends a cookie, but it closes the connection after its HelloRetryRequest for OpenSSL's own s_client too, so it cannot judge the cookie path. The scripted test covers that path.
  • fmt, clippy and rustdoc -D warnings are clean. The full workspace test against the fork commit passes: 143 test binaries, 3830 tests, none failed.

Docs

🤖 Generated with Claude Code

A HelloRetryRequest broke a uTLS-shaped hello in three ways (OpenSSL 3.5's
s_server, on main before #252 as on #256): the second ClientHello kept the
GREASE key share next to the one the server asked for, which OpenSSL and
Go's crypto/tls refuse with illegal_parameter; a cookie could not be placed,
so the second ClientHello was never built; and the padding kept the first
flight's target.

Pins shaped-rustls ca91d48c (aimalygin/shaped-rustls claude/hrr-retry-shaping):
a retry that names a group gets rustls's single key share, without the
plan's raw and GREASE shares, and ClientHelloPaddingPlan::boringssl(offset)
applies BoringSSL's rule to every ClientHello. Here:

- The cookie: HelloDraws draws its place as uTLS's p.Intn(len(Extensions)
  - 2), and planned_extensions puts 0x002c there in the hello's extension
  list (the drawn order plus an ALPN extension the http/1.1 override
  appends); the order and the GREASE positions read that one list.
  shaped-rustls drops the entry from a ClientHello carrying no cookie, so
  first-flight bytes are unchanged.
- Padding: boringssl(offset) with offset = 2 x the suites the provider
  filters - 7 for the supported_versions rustls adds to a TLS-1.2-era
  hello. utls_unpadded_len, which modelled the server name, the ALPN list
  and the ECH draw for the first flight, goes: the fork measures each
  ClientHello.

Tests: a scripted HelloRetryRequest server (a group: the requested share
alone; a cookie: echoed at every place but the last two over 512 retries,
the key shares unchanged; Chrome 120 padded per flight); the offset against
all 30 committed uTLS hellos; the BoringSSL sweep on the per-flight mode.
Live, ignored: OpenSSL s_server -groups P-256, and Xray-core's TLS inbound
held to P-256. Docs and CHANGELOG describe the retry.
@aimalygin
aimalygin changed the base branch from claude/xray-v26-11-9-ech-grease-length to main November 10, 2026 16:18
@aimalygin
aimalygin merged commit f1e79d7 into main Nov 10, 2026
16 checks passed
aimalygin pushed a commit that referenced this pull request Nov 10, 2026
@aimalygin
aimalygin deleted the claude/hrr-retry-shaping branch November 15, 2026 18:48
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