Skip to content

Fix for DTLS1.3 HRR group handling#9848

Merged
douzzer merged 1 commit intowolfSSL:masterfrom
Frauschi:dtls_hrr_group
Mar 5, 2026
Merged

Fix for DTLS1.3 HRR group handling#9848
douzzer merged 1 commit intowolfSSL:masterfrom
Frauschi:dtls_hrr_group

Conversation

@Frauschi
Copy link
Contributor

@Frauschi Frauschi commented Mar 2, 2026

When a server uses an HRR to negotiate the key exchange group to use, the selected group is advertised in the HRR key share extension. Furthermore, this group is also stored in the Cookie that is sent to the client. When the server receives the second CH, the group used in the key share extension MUST be the one of the HRR.

For stateless DTLS servers, the handling of this check had a bug. The key share group of the HRR is stored in the ssl->hrr_keyshare_group variable and is checked against the received key share of the second CH. However, in the stateless server case, another CH message may be received inbetween the two CH messages of the desired client, potentially overwriting the ssl->hrr_keyshare_group variable. This then causes handshake failures when the ssl->hrr_keyshare_group variable contains another group than the second CH message of the desired client.

To fix this, two changes are conducted:

  1. Disable the ssl->hrr_keyshare_group check for stateless DTLS 1.3 servers. As long as the server is stateless, CHs from multiple clients may be received that individually cause HRRs with different groups. For each of these clients, the HRR group is properly stored in the cookie.
  2. When a valid cookie is received from the client, the server becomes stateful. In this case, we now parse the cookie for a stored HRR group. If present, we reset the ssl->hrr_keyshare_group variable to this group to ensure the error checks succeed.

A new test is added to check for this behavior.

Identified while working on #9732.

rizlik
rizlik previously requested changes Mar 2, 2026
Copy link
Member

@julek-wolfssl julek-wolfssl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR, we don't need the ssl->hrr_keyshare_group variable anymore.

@Frauschi
Copy link
Contributor Author

Frauschi commented Mar 3, 2026

@julek-wolfssl @rizlik I addressed all your comments.

@Frauschi Frauschi requested review from julek-wolfssl and rizlik March 3, 2026 15:49
Copy link
Member

@julek-wolfssl julek-wolfssl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I still don't like this solution.

  1. It relies on the cookie appearing before the key share in the extension list as we process extensions in order in TLSX_Parse
  2. I don't like having multiple independent parsing logics.
    So my suggestion is to restore ssl->hrr_keyshare_group in RestartHandshakeHashWithCookie and move the ssl->hrr_keyshare_group check to DoTls13ClientHello after the call to TLSX_Parse. When ssl->hrr_keyshare_group != server_hello you should find the key share extension, make sure there is only one entry, and make sure it corresponds to the ssl->hrr_keyshare_group.

When a server uses a HRR to negotiate the key exchange group to use, the
selected group is advertised in the HRR key share extension.
Furthermore, this group is also stored in the Cookie that is sent to the
client. When the server receives the second CH, the group used in the
key share extension MUST be the one of the HRR.

For stateless DTLS servers, the handling of this check had a bug. The
key share group of the HRR is stored in the ssl->hrr_keyshare_group
variable and is checked against the received key share of the second CH.
However, in the stateless server case, another CH message may be
received inbetween the two CH message of the desired client, potentially
overwriting the ssl->hrr_keyshare_group variable. This then causes
handshake failures when the ssl->hrr_keyshare_group variable contains
another group than the second CH message of the desired client.

To fix this, the following changes are conducted:
1. Disable the ssl->hrr_keyshare_group check for stateless DTLS 1.3
   servers. As long as the server is stateless, CHs from multiple
   clients may be received that individually cause HRRs with different
   groups. For each of these clients, the HRR group is properly stored
   in the cookie.
2. When a valid cookie is received from the client, the server becomes
   stateful. In this case, we now parse the cookie for a stored HRR
   group in the RestartHandshakeHashWithCookie() method. If present,
   we restore the ssl->hrr_keyshare_group variable to this group to
   ensure the error checks succeed.
3. Move the check of ssl->hrr_keyshare_group of the the KeyShare
   extension parsing logic into the general TLS1.3 ClientHello parsing
   after extension handling. This ensures that the order of the cookie
   and key share extensions does not matter.

A new test is added to check for this behavior.
@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Mar 4, 2026
@douzzer douzzer added the Staged Staged for merge pending final test results and review label Mar 5, 2026
@douzzer douzzer merged commit 26e2f05 into wolfSSL:master Mar 5, 2026
448 of 449 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Staged Staged for merge pending final test results and review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants