Repository navigation
Answer a HelloRetryRequest as uTLS does: one key share, BoringSSL padding per flight - #1
Merged
Merged
Conversation
A ClientHelloPlan is built once per connection and applied to the second ClientHello a HelloRetryRequest asks for as well. Two of its parts did not fit that flight: - A retry that names a group must carry a single key share for it (RFC 8446 section 4.1.2), the one rustls makes in retry_key_share. The plan's raw key shares and its GREASE key share were added beside it, and OpenSSL and Go's crypto/tls refuse such a ClientHello with illegal_parameter. They now belong to the first ClientHello alone; a retry that carries only a cookie repeats them, as it must repeat the key share list. - PadToHandshakeSize pads every flight to the first one's target. ClientHelloPaddingPlan::boringssl(offset) applies BoringSSL's padding rule (ssl_add_clienthello_tlsext, uTLS's BoringPaddingStyle) to each ClientHello as it is encoded: a handshake message of 256 to 511 bytes before padding is padded up to 512, or by one byte when the extension header alone would reach 512, and any other carries no padding extension. offset is added to the measured length and to the padding, for a ClientHello that many bytes shorter than the one it stands for. A HelloRetryRequest's cookie needs no change here: a planned extension order may name the cookie, and PlannedExtensionOrder drops it from a ClientHello that carries none. Tests drive a connection through a scripted HelloRetryRequest naming a group (GREASE as a raw share and through the GREASE plan), one carrying a cookie, and BoringSSL padding across both flights.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes a ClientHello shaped by a
ClientHelloPlananswer a HelloRetryRequest as uTLS answers it.xray-rust's uTLS shaping needs it; the companion PR is aimalygin/xray-rust#258. Merge with a merge commit or a fast-forward, not a squash, so the rev xray-rust pins stays in this branch's history.
What broke
A plan is built once per connection, and
emit_client_hello_for_retryapplies it to the second ClientHello as well. Against OpenSSL 3.5'ss_server, a uTLS-shaped Chrome hello on 3a131be broke in three ways:-groups P-256). The second ClientHello carried the plan's GREASE key share next to the P-256 one. RFC 8446 §4.1.2 asks for a single share from the indicated group. OpenSSL answersillegal_parameter, and so does Go's crypto/tls server ("client didn't send one key share in second ClientHello").-stateless). The planned extension order had no cookie, soset_custom_orderrefused and the second ClientHello was never built.PadToHandshakeSizepadded the second ClientHello to the first one's target. BoringSSL, and uTLS'sBoringPaddingStyle, decide the padding again from the second ClientHello's own length.Changes
Retry key shares. On a retry whose HelloRetryRequest names a group, the plan's raw key shares and its GREASE key-share position are skipped, so the second ClientHello carries rustls's single
retry_key_share. A retry that carries only a cookie keeps them, because RFC 8446 wants the first ClientHello's key share list repeated, and the plan's entries are byte-identical across flights.ClientHelloPaddingPlan::boringssl(offset). BoringSSL's padding rule (ssl_add_clienthello_tlsext) is applied to each ClientHello as it is encoded:encode_onewrites only present extensions.offsetis added to the measured length and to the padding. It serves a ClientHello that many bytes shorter than the one it imitates; xray-rust passes the bytes of the cipher suites this provider cannot negotiate. It is bounded to ±511.The cookie needs no change here. A plan's extension order may name
Cookie, andPlannedExtensionOrderalready drops it from a ClientHello that carries none, translating GREASE positions past it. xray-rust plans it where uTLS inserts it.Tests
In
client/test.rs, a connection is driven through a scripted HelloRetryRequest:a_retry_naming_a_group_sends_its_key_share_alone: GREASE as a raw share, and through the GREASE plan.a_retry_with_a_cookie_repeats_the_key_shares_and_takes_its_planned_placeboringssl_padding_follows_each_client_hellos_own_length: both flights, inside the window, at the one-byte edge, the first flight inside and the second past it, and below the window, with BoringSSL's rule restated in the test.boringssl_padding_len_is_boringssls_rule: the boundaries and the offset bound.All 311 rustls lib tests pass. Mutations on the change: 11 of 11 caught (the retry skip off, on for a cookie-only retry, raw or GREASE shares kept, the window taking 512, the edge padding no byte or off by one, the offset left out of the rule or of the padding, an empty extension outside the window, the offset bound).
xray-rust's live runs on this rev pass:
s_server -groups P-256.-statelesscloses the connection after its HelloRetryRequest even for OpenSSL's owns_client, so it judges nothing; xray-rust's scripted server checks the cookie path;curvePreferences: ["CurveP256"], so the HelloRetryRequest comes from Go itself.🤖 Generated with Claude Code