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

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

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

Visibility: public

Requested revision: 12a58087a423e33dd5fc8daa5c9fb556fe93f7a9

Requested commit: 12a58087a423e33dd5fc8daa5c9fb556fe93f7a9

Commit: 12a58087a423e33dd5fc8daa5c9fb556fe93f7a9

Tree: e941d6830db99ccba93546c626594f2a0b7e3010

Author: Frank Denis

Committer: GitHub

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

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

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