Skip to content

Report WANT_WRITE from a blocked TLS 1.3 post-handshake auth response - #12014

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/pha-block
Open

yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/pha-block

Conversation

@yosuke-wolfssl

@yosuke-wolfssl yosuke-wolfssl commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A TLS 1.3 client answers a post-handshake CertificateRequest from inside wolfSSL_read(). When the socket will not take the Certificate / CertificateVerify / Finished flight, the WANT_WRITE is rewritten to the fatal POST_HAND_AUTH_ERROR (-504):

Client Result
reads only every later read is refused; the queued flight never leaves and the server waits forever
writes next wolfSSL_negotiate() finishes the flight, then the next read fails with LENGTH_ERROR: the CertificateRequest record was left half-processed

Fix (src/tls13.c)

  • DoTls13HandShakeMsgType() passes WANT_WRITE from the post-handshake wolfSSL_connect_TLSv13() call through, as it already did for WC_PENDING_E.
  • DoProcessReplyEx() (src/internal.c) finishes the CertificateRequest record for WANT_WRITE as well as WC_PENDING_E: it either resumes at the next message or skips the padding. This block was async-only before.

The caller now sees WOLFSSL_ERROR_WANT_WRITE, and the next wolfSSL_read() or wolfSSL_write() finishes the flight through wolfSSL_negotiate().

Tests

test_tls13_pha_want_write: a blocked TLS 1.3 PHA response, retried once by wolfSSL_read() and once by wolfSSL_write(). The server must accept the certificate, and the client must then read the server's data.

Verification

  • Negative controls: reverting the tls13.c or the internal.c change makes the test fail.
  • Full --api, 0 failures: --enable-tls13 --enable-postauth --enable-sessioncerts (686 passed); --enable-all --enable-writedup --enable-asynccrypt --enable-asynccrypt-sw (2550 passed).

Not in this PR

  • DTLS 1.3: a blocked PHA response still returns POST_HAND_AUTH_ERROR. Resuming it on DTLS also needs _Dtls13HandshakeRecv() to count the message as processed (Ack DTLS 1.3 handshake message when response hits WANT_WRITE #11768) and DoProcessReplyEx() to keep WANT_WRITE when more records follow in the same datagram. Follow-up.
  • Untested branch: a CertificateRequest followed by another message in the same record (the runProcessingOneMessage path). The code was reviewed, but building that record needs a hand-crafted encrypted record.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Nov 5, 2026
Copilot AI balanced review requested due to automatic review settings November 5, 2026 06:34
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

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

Without WOLFSSL_ASYNC_CRYPT, coalesced DTLS records can lose WANT_WRITE after CertificateRequest, allowing an ACK to overwrite the result or a NewSessionTicket to fail with OUT_OF_ORDER_E.

1 open issue
What changed in this PR

This PR updates wolfSSL’s TLS 1.3 and DTLS 1.3 post-handshake authentication handling so blocked responses report WANT_WRITE and can resume on a later read or write.

Changes:

  • Preserve WANT_WRITE instead of converting it to a fatal authentication error.
  • Complete record bookkeeping and DTLS acknowledgment processing when a response blocks.
  • Add regression tests for read/write retries and a second authentication request.
File Description
tests/​api/​test_tls13.h Declares and registers the regression test.
tests/​api/​test_tls13.c Tests blocked responses and retries for TLS and DTLS.
src/​tls13.c Preserves WANT_WRITE from authentication responses.
src/​internal.c Extends record completion handling to blocked responses.
src/​dtls13.c Acknowledges and marks requests processed before returning WANT_WRITE.

Review effort: Balanced

Comment thread src/dtls13.c Resolved
@yosuke-wolfssl
yosuke-wolfssl force-pushed the fix/pha-block branch 2 times, most recently from df41376 to 8df7f18 Compare November 5, 2026 06:54
@yosuke-wolfssl

Copy link
Copy Markdown
Contributor Author

@claude review

@yosuke-wolfssl yosuke-wolfssl changed the title Report WANT_WRITE from a blocked TLS 1.3 / DTLS 1.3 post-handshake auth response Report WANT_WRITE from a blocked TLS 1.3 post-handshake auth response Nov 5, 2026

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12014

Scan targets checked: wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_tls13.h
Coverage: 2 of 3 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_tls13.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

Comment thread src/tls13.c Resolved
SparkiDev
SparkiDev previously approved these changes Nov 6, 2026
@SparkiDev
SparkiDev requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 6, 2026 05:44
@SparkiDev

Copy link
Copy Markdown
Contributor

@claude review

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

The regression test can pass without completed server-side PHA because WANT_READ and application-data exchange do not prove authentication success, so it needs explicit assertions for the peer certificate, peer verification, and Finished receipt.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread tests/api/test_tls13.c Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12014

Scan targets checked: wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_tls13.h
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

- DoTls13HandShakeMsgType() returns WANT_WRITE from the client's
  post-handshake auth wolfSSL_connect_TLSv13() call instead of
  POST_HAND_AUTH_ERROR for TLS only.
- DoProcessReplyEx() finishes the CertificateRequest record for a
  WANT_WRITE as well as a WC_PENDING_E from that call
- Add test_tls13_pha_want_write.
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.

5 participants