Repository navigation
fix: keep private keys for secondary key shares - #416
Open
thesinakamali wants to merge 3 commits into
Open
thesinakamali wants to merge 3 commits into
thesinakamali wants to merge 3 commits into
Conversation
TaiLerV
pushed a commit
to TaiLerV/Xray-core-up
that referenced
this pull request
Oct 13, 2026
uTLS keeps the private key of the first classical key share only. Firefox fingerprints send key shares for X25519 and then P-256, so against a server that selects P-256 (AWS s2n and FIPS policies, BoringSSL, Go and RHEL in FIPS mode, P-256-first nginx configurations) the client failed with "tls: invalid server key share", sending an illegal_parameter alert in cleartext right after the ServerHello, where Firefox goes on (refraction-networking/utls#402). Take uTLS from the fork github.com/Jolymmiles/utls, branch fix/keep-secondary-key-shares: the pinned upstream commit aa6edf4b11af plus a backport of refraction-networking/utls#416, which keeps the keys of the later classical key shares by group and uses the one the server selected. The ClientHello of every fingerprint is unchanged (snapshot tests), and the REALITY client still authenticates with the first classical key. The health test's Firefox cells against a P-256-only server now pass. The randomized presets still send no P-256 key share; the reason is now that Chrome sends none, not uTLS's lost key.
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.
When a ClientHelloSpec offers more than one classical key share (e.g., the Firefox profiles send X25519 and P-256), ApplyPreset generates a private key for each but only keeps the first in
KeyShareKeys.Ecdhe. If the server selects the second curve,clientSharedSecretruns ECDH with the wrong private key and the handshake fails with "tls: invalid server key share". Fix by storing the additional private keys in a newKeyShareKeys.EcdheFallbackmap keyed byCurveID, and havingecdhKeyExchangeselect the key matching the server's chosen group.The first commit fixes a related issue where
ApplyPresetunconditionally resetKeyShareKeysto an empty struct. WhenBuildHandshakeStateWithoutSessionis called beforeBuildHandshakeState, the spec is reused and the key shares are already populated, so the second call discarded the private keys that matched the public shares already in theClientHello. Only initializeKeyShareKeyswhen it is nil.The second commit fixes the secondary key share bug and adds a test that does an in-process handshake with
HelloFirefox_105/120/148against a server withCurvePreferences = CurveP256. It fails with "invalid server key share" without the fix and negotiates P-256 with no HRR with it.