Skip to content

DTLS 1.3: resend HelloRetryRequest on a stateful server - #12224

Open
mattia-moffa wants to merge 3 commits into
wolfSSL:masterfrom
mattia-moffa:20261120-dtls-issue12136
Open

mattia-moffa wants to merge 3 commits into
wolfSSL:masterfrom
mattia-moffa:20261120-dtls-issue12136

Conversation

@mattia-moffa

Copy link
Copy Markdown
Member

Description

With the HRR cookie disabled the server kept no copy of the HRR, so when it was lost the retransmitted ClientHello was simply answered with an ACK and the handshake stalled until the client gave up.

This buffers the HRR when on a stateful (no-cookie) server, flushes the ACK list when sending it and clears it from the buffer once the next ClientHello arrives.

Fixes #12136

Testing

./configure --enable-dtls13
make
./tests/unit.test -test_dtls13_hrr_lost

Checklist

  • added tests

With the HRR cookie disabled the server kept no copy of the HRR, so when
it was lost the retransmitted ClientHello was simply answered with an
ACK and the handshake stalled until the client gave up.

This buffers the HRR when on a stateful (no-cookie) server, flushes the
ACK list when sending it and clears it from the buffer once the next
ClientHello arrives.

Fixes wolfSSL#12136
@mattia-moffa mattia-moffa self-assigned this Nov 21, 2026
Copilot AI balanced review requested due to automatic review settings November 21, 2026 04:12
@mattia-moffa
mattia-moffa marked this pull request as ready for review November 21, 2026 04:12
@github-actions

Copy link
Copy Markdown

retest this please

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Duplicate ClientHellos still trigger ACKs while an HRR is buffered, potentially stalling the handshake if both HRR transmissions are lost; ACK suppression and regression coverage for this loss scenario are needed.

1 open issue
What changed in this PR

Addresses #12136 by enabling stateful DTLS 1.3 servers with HRR cookies disabled to retain and retransmit a lost HelloRetryRequest.

Changes:

  • Buffers stateful HRRs, clears pending ACKs when sending them, and clears retransmission buffers when the next ClientHello arrives.
  • Adds loss-recovery tests for cookie-enabled servers and stateful servers using client- or server-triggered retransmission.
  • Extends test helpers to recognize HRRs in both TLS and DTLS records.
File Description
tests/​utils.h Declares the raw-record HRR detection helper.
tests/​utils.c Adds DTLS-aware HRR detection and reuses it in the existing helper.
tests/​api/​test_dtls.h Declares and registers the HRR loss test.
tests/​api/​test_dtls.c Tests HRR loss recovery, buffer cleanup, and subsequent data exchange.
src/​dtls13.c Updates HRR buffering, ACK cleanup, and next-flight buffer clearing.

Review effort: Balanced

Comment thread src/dtls13.c
Comment on lines +2166 to 2167
handshakeType == hello_retry_request)
Dtls13RtxFlushAcks(ssl);

@mattia-moffa mattia-moffa Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

a duplicate ClientHello still schedules an ACK before the buffered HRR is resent. If the ACK arrives but both the original and retransmitted HRR are lost, the client stops retransmitting its ClientHello

This part is true

so a server relying on client retransmissions stalls again

This part is not. The server's timer will fire and cause a retransmission of the HelloRetryRequest. A non-blocking server that never calls wolfSSL_dtls_got_timeout will stall, but it will also stall on ServerHello, so it would be a problematic server anyway.

I added a test to check that the server's timer recovers the handshake in this case.

Sending an ACK followed by a HelloRetryRequest is superfluous but not really a problem. Suppressing the ACK only while an HelloRetryRequest is buffered would be possible, but a bit of a hack, since the server currently ACKs every duplicate message during the handshake anyway, e.g. a duplicate ClientHello while ServerHello is buffered for retransmission.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +64 B (+0.0%, 199,588 B / 1,048,576 B, total: 19% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,864 B (+4.9%, 296,444 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@mattia-moffa

Copy link
Copy Markdown
Member Author

Jenkins retest this please

@rizlik rizlik self-assigned this Nov 25, 2026
rizlik
rizlik previously approved these changes Nov 25, 2026

@rizlik rizlik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work, thanks.
Optional: add a test case with a fragmented CH1, using cookie off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DTLS 1.3: with the HRR cookie disabled, a lost HelloRetryRequest is never resent and the handshake fails (-308)

3 participants