Skip to content

Conversation

@rizlik
Copy link
Contributor

@rizlik rizlik commented Nov 6, 2025

Server-side accept (TLS 1.3/DTLS 1.3) could lose the early-data shortcut whenever sending the Finished flight first hit WANT_WRITE. The buffered data advanced acceptState past TLS13_ACCEPT_FINISHED_SENT as soon as it flushed, so the next wolfSSL_accept() call skipped the block that marks SERVER_FINISHED_COMPLETE and lets the application drain 0-RTT data. By keeping the FALL_THROUGH into TLS13_ACCEPT_FINISHED_SENT and only returning early while that handshake flag is still unset, we revisit the shortcut immediately after the buffered flight is delivered, preserving the intentional behaviour even under non-blocking I/O.

On the client, the same pattern showed up after SendTls13ClientHello() buffered due to WANT_WRITE: after flushing, the connect state is already CLIENT_HELLO_SENT so the early-data exit is no longer executed. We now fall through into the CLIENT_HELLO_SENT case and only short-circuit once per handshake, ensuring the reply-processing loop still executes on the retry.

@rizlik
Copy link
Contributor Author

rizlik commented Nov 6, 2025

retest this please

@rizlik rizlik force-pushed the earlydata_want_write_fixes branch 2 times, most recently from df84dc6 to 5f250bf Compare December 3, 2025 11:31
@rizlik
Copy link
Contributor Author

rizlik commented Dec 3, 2025

retest this please

1 similar comment
@rizlik
Copy link
Contributor Author

rizlik commented Dec 4, 2025

retest this please

@rizlik rizlik force-pushed the earlydata_want_write_fixes branch 3 times, most recently from 7981ba0 to 10af0e3 Compare December 4, 2025 14:52
@rizlik
Copy link
Contributor Author

rizlik commented Dec 4, 2025

retest this please

RequestAbortedException

@rizlik rizlik marked this pull request as ready for review December 4, 2025 17:27
@rizlik rizlik requested a review from Copilot December 4, 2025 17:28
@devin-ai-integration
Copy link
Contributor

🛟 Devin Lifeguard found 2 likely issues in this PR

  • no-void-functions snippet: Change wolfSSL_maybeCheckAlertOnErr to return an int (e.g. 0 on success or a negative error code) and update all call sites to check and propagate this return value instead of ignoring potential failures.
  • check-all-return-codes snippet: Capture the return value from ProcessReplyEx(), check it for an error (e.g., int rc = ProcessReplyEx(ssl, 1); if (rc != 0) ssl->error = rc;), or explicitly document with a cast to void if the result is intentionally ignored.

@rizlik
please take a look at the above issues which Devin flagged. Devin will not fix these issues automatically.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug in TLS 1.3 and DTLS 1.3 early-data handling where the ability to drain 0-RTT data was lost when handshake flights hit WANT_WRITE under non-blocking I/O. The fix restructures the handshake state machines to preserve early-data shortcuts across WANT_WRITE retries by using FALL_THROUGH and additional handShakeState checks. Additionally, it refactors error-checking code by introducing wolfSSL_maybeCheckAlertOnErr() to centralize the logic for conditionally processing alerts.

Key changes:

  • Modified client and server handshake state machines to preserve early-data behavior across WANT_WRITE retries by adding FALL_THROUGH and handShakeState guard conditions
  • Introduced wolfSSL_maybeCheckAlertOnErr() helper to replace direct ProcessReplyEx(ssl, 1) calls with proper filtering of non-blocking I/O states
  • Enhanced test coverage with mock WANT_WRITE scenarios to validate the fix

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
wolfssl/internal.h Adds declaration for new wolfSSL_maybeCheckAlertOnErr() helper function
src/tls13.c Restructures client/server handshake state machines with FALL_THROUGH to preserve early-data shortcuts; updates wolfSSL_read_early_data() to handle WANT_WRITE retries; replaces ProcessReplyEx() calls with wolfSSL_maybeCheckAlertOnErr()
src/ssl.c Replaces multiple ProcessReplyEx(ssl, 1) calls with wolfSSL_maybeCheckAlertOnErr() throughout TLS 1.2 handshake code
src/internal.c Implements wolfSSL_maybeCheckAlertOnErr() helper that filters non-blocking I/O and async states before checking alerts
tests/api/test_tls13.c Adds retry helper functions and mock WANT_WRITE callback to test early-data handling under simulated non-blocking I/O conditions; expands test matrix to cover split early data and WANT_WRITE scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rizlik rizlik assigned julek-wolfssl and unassigned rizlik Dec 4, 2025
dgarske
dgarske previously approved these changes Dec 4, 2025
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Tests pass with real async / quickassist.

@rizlik
Copy link
Contributor Author

rizlik commented Dec 4, 2025

retest this please

@rizlik
Copy link
Contributor Author

rizlik commented Dec 17, 2025

retest this please:

AgentOfflineException exception:

@rizlik rizlik force-pushed the earlydata_want_write_fixes branch from c943d14 to 14b1247 Compare December 22, 2025 09:16
@rizlik
Copy link
Contributor Author

rizlik commented Dec 22, 2025

retest this please.

AgentOfflineException

@rizlik rizlik requested a review from julek-wolfssl December 22, 2025 10:30
@rizlik rizlik assigned julek-wolfssl and unassigned rizlik Dec 22, 2025
@rizlik
Copy link
Contributor Author

rizlik commented Dec 22, 2025

retest this please

1 similar comment
@rizlik
Copy link
Contributor Author

rizlik commented Dec 22, 2025

retest this please

@rizlik rizlik assigned julek-wolfssl and unassigned rizlik Dec 22, 2025
julek-wolfssl
julek-wolfssl previously approved these changes Dec 23, 2025
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.

lgtm

@rizlik rizlik force-pushed the earlydata_want_write_fixes branch from f6336ac to bafb8e5 Compare December 23, 2025 22:32
@rizlik rizlik removed their assignment Dec 23, 2025
@dgarske
Copy link
Contributor

dgarske commented Dec 23, 2025

Jenkins retest this please. FIPS 140-3 history lost already

@dgarske dgarske merged commit 0fae0a7 into wolfSSL:master Dec 24, 2025
378 checks passed
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.

4 participants