# Fix TLS 1.2 client key exchange to use negotiated named group \(\#25007\) · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/9c3e09cbeea79a05db965e82e12ac5bec640a66c)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 9c3e09cbeea79a05db965e82e12ac5bec640a66c

Requested commit: 9c3e09cbeea79a05db965e82e12ac5bec640a66c

Commit: 9c3e09cbeea79a05db965e82e12ac5bec640a66c

Tree: dda85b69f1ddefb3e6c2ab812e1884cd86715266

Author: Frank Denis

Committer: Alex Rønne Petersen

## Message

```
Fix TLS 1.2 client key exchange to use negotiated named group (#25007)

The TLS 1.2 implementation was incorrectly hardcoded to always send the
secp256r1 public key in the client key exchange message, regardless of
which elliptic curve the server actually negotiated.

This caused TLS handshake failures with servers that preferred other curves
like X25519.

This fix:

- Tracks the negotiated named group from the server key exchange message
- Dynamically selects the correct public key (X25519, secp256r1, or
  secp384r1) based on what the server negotiated
- Properly constructs the client key exchange message with the
  appropriate key size for each curve type

Fixes TLS 1.2 connections to servers like ziglang.freetls.fastly.net
that prefer X25519 over secp256r1.

```

## Parents

- [a4cb63665812384376e7730fb7c394b6a38c57f8](https://git.cafe/gitcafe/zig/commit/a4cb63665812384376e7730fb7c394b6a38c57f8?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/9c3e09cbeea79a05db965e82e12ac5bec640a66c?format=markdown)
