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
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.