Skip to content

Commit a1c8790

Browse files
committed
wolfssl: preserve early-data handling across WANT_WRITE retries
The early-data logic setups "early" exits in Accept/Connect state machine so that the data exchanged during the handshake can be delivered to the caller. After the caller process the data, it usually calls Accept/Connect again to cotinue the handshake. Under non-blocking I/O there is the chance that these early exits are skipped, this commit fixes that. Server-side accept (TLS 1.3/DTLS 1.3) could skip the early-data shortcut whenever sending the Finished flight first hit WANT_WRITE: when Accept is called again and the data is eventually flushed into the I/O layer the accept state is advanced past TLS13_ACCEPT_FINISHED_SENT, 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.
1 parent 0a0c430 commit a1c8790

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/tls13.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13396,8 +13396,12 @@ int wolfSSL_connect_TLSv13(WOLFSSL* ssl)
1339613396

1339713397
ssl->options.connectState = CLIENT_HELLO_SENT;
1339813398
WOLFSSL_MSG("TLSv13 connect state: CLIENT_HELLO_SENT");
13399+
FALL_THROUGH;
13400+
13401+
case CLIENT_HELLO_SENT:
1339913402
#ifdef WOLFSSL_EARLY_DATA
13400-
if (ssl->earlyData != no_early_data) {
13403+
if (ssl->earlyData != no_early_data &&
13404+
ssl->options.handShakeState != CLIENT_HELLO_COMPLETE) {
1340113405
#if defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
1340213406
if (!ssl->options.dtls && ssl->options.tls13MiddleBoxCompat) {
1340313407
if ((ssl->error = SendChangeCipher(ssl)) != 0) {
@@ -13411,9 +13415,6 @@ int wolfSSL_connect_TLSv13(WOLFSSL* ssl)
1341113415
return WOLFSSL_SUCCESS;
1341213416
}
1341313417
#endif
13414-
FALL_THROUGH;
13415-
13416-
case CLIENT_HELLO_SENT:
1341713418
/* Get the response/s from the server. */
1341813419
while (ssl->options.serverState <
1341913420
SERVER_HELLOVERIFYREQUEST_COMPLETE) {
@@ -14736,15 +14737,16 @@ int wolfSSL_accept_TLSv13(WOLFSSL* ssl)
1473614737

1473714738
ssl->options.acceptState = TLS13_ACCEPT_FINISHED_SENT;
1473814739
WOLFSSL_MSG("accept state ACCEPT_FINISHED_SENT");
14740+
FALL_THROUGH;
14741+
14742+
case TLS13_ACCEPT_FINISHED_SENT:
1473914743
#ifdef WOLFSSL_EARLY_DATA
14740-
if (ssl->earlyData != no_early_data) {
14744+
if (ssl->earlyData != no_early_data &&
14745+
ssl->options.handShakeState != SERVER_FINISHED_COMPLETE) {
1474114746
ssl->options.handShakeState = SERVER_FINISHED_COMPLETE;
1474214747
return WOLFSSL_SUCCESS;
1474314748
}
1474414749
#endif
14745-
FALL_THROUGH;
14746-
14747-
case TLS13_ACCEPT_FINISHED_SENT :
1474814750
#ifdef HAVE_SESSION_TICKET
1474914751
#ifdef WOLFSSL_TLS13_TICKET_BEFORE_FINISHED
1475014752
if (!ssl->options.verifyPeer && !ssl->options.noTicketTls13 &&

0 commit comments

Comments
 (0)