@@ -19609,7 +19609,8 @@ int DoApplicationData(WOLFSSL* ssl, byte* input, word32* inOutIdx, int sniff)
1960919609 return BUFFER_ERROR;
1961019610 }
1961119611#ifdef WOLFSSL_EARLY_DATA
19612- if (ssl->earlyData > early_data_ext) {
19612+ if (ssl->options.side == WOLFSSL_SERVER_END &&
19613+ ssl->earlyData > early_data_ext) {
1961319614 if (ssl->earlyDataSz + dataSz > ssl->options.maxEarlyDataSz) {
1961419615 if (sniff == NO_SNIFF) {
1961519616 SendAlert(ssl, alert_fatal, unexpected_message);
@@ -19649,11 +19650,14 @@ int DoApplicationData(WOLFSSL* ssl, byte* input, word32* inOutIdx, int sniff)
1964919650#endif
1965019651
1965119652 *inOutIdx = idx;
19653+ #ifdef WOLFSSL_DTLS13
19654+ if (ssl->options.connectState == WAIT_FINISHED_ACK) {
19655+ /* DTLS 1.3 is waiting for an ACK but we can still return app data. */
19656+ return APP_DATA_READY;
19657+ }
19658+ #endif
1965219659#ifdef HAVE_SECURE_RENEGOTIATION
1965319660 if (IsSCR(ssl)) {
19654- /* Reset the processReply state since
19655- * we finished processing this message. */
19656- ssl->options.processReply = doProcessInit;
1965719661 /* If we are in a secure renegotiation then APP DATA is treated
1965819662 * differently */
1965919663 return APP_DATA_READY;
@@ -20246,7 +20250,7 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2024620250#endif
2024720251
2024820252 if (ssl->error != 0 && ssl->error != WANT_READ && ssl->error != WANT_WRITE
20249- #ifdef HAVE_SECURE_RENEGOTIATION
20253+ #if defined( HAVE_SECURE_RENEGOTIATION) || defined(WOLFSSL_DTLS13)
2025020254 && ssl->error != APP_DATA_READY
2025120255 #endif
2025220256 #ifdef WOLFSSL_ASYNC_CRYPT
@@ -21213,7 +21217,13 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2121321217 &ssl->buffers.inputBuffer.idx,
2121421218 NO_SNIFF)) != 0) {
2121521219 WOLFSSL_ERROR(ret);
21216- return ret;
21220+ #if defined(WOLFSSL_DTLS13) || \
21221+ defined(HAVE_SECURE_RENEGOTIATION)
21222+ /* Not really an error. We will return after cleaning
21223+ * up the processReply state. */
21224+ if (ret != APP_DATA_READY)
21225+ #endif
21226+ return ret;
2121721227 }
2121821228 break;
2121921229
@@ -21270,9 +21280,18 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2127021280 /* input exhausted */
2127121281 if (ssl->buffers.inputBuffer.idx >= ssl->buffers.inputBuffer.length
2127221282#ifdef WOLFSSL_DTLS
21273- /* If app data was processed then return now to avoid
21274- * dropping any app data. */
21275- || (ssl->options.dtls && ssl->curRL.type == application_data)
21283+ || (ssl->options.dtls &&
21284+ /* If app data was processed then return now to avoid
21285+ * dropping any app data. */
21286+ (ssl->curRL.type == application_data ||
21287+ /* client: if we processed a finished message, return to
21288+ * allow higher layers to establish the crypto
21289+ * parameters of the connection. The remaining data
21290+ * may be app data that we would drop without the
21291+ * crypto setup. */
21292+ (ssl->options.side == WOLFSSL_CLIENT_END &&
21293+ ssl->options.serverState == SERVER_FINISHED_COMPLETE &&
21294+ ssl->options.handShakeState != HANDSHAKE_DONE)))
2127621295#endif
2127721296 ) {
2127821297 /* Shrink input buffer when we successfully finish record
@@ -21327,6 +21346,11 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2132721346 * by higher layers. */
2132821347 if (ret != 0)
2132921348 return ret;
21349+ #endif
21350+ #if defined(WOLFSSL_DTLS13) || defined(HAVE_SECURE_RENEGOTIATION)
21351+ /* Signal to user that we have application data ready to read */
21352+ if (ret == APP_DATA_READY)
21353+ return ret;
2133021354#endif
2133121355 /* It is safe to shrink the input buffer here now. local vars will
2133221356 * be reset to the new starting value. */
@@ -23598,6 +23622,12 @@ int SendData(WOLFSSL* ssl, const void* data, int sz)
2359823622 groupMsgs = 1;
2359923623 #endif
2360023624 }
23625+ else if (IsAtLeastTLSv1_3(ssl->version) &&
23626+ ssl->options.side == WOLFSSL_SERVER_END &&
23627+ ssl->options.acceptState >= TLS13_ACCEPT_FINISHED_SENT) {
23628+ /* We can send data without waiting on peer finished msg */
23629+ WOLFSSL_MSG("server sending data before receiving client finished");
23630+ }
2360123631 else
2360223632#endif
2360323633 if (ssl->options.handShakeState != HANDSHAKE_DONE && !IsSCR(ssl)) {
@@ -23835,7 +23865,7 @@ int ReceiveData(WOLFSSL* ssl, byte* output, int sz, int peek)
2383523865#ifdef WOLFSSL_ASYNC_CRYPT
2383623866 && ssl->error != WC_PENDING_E
2383723867#endif
23838- #ifdef HAVE_SECURE_RENEGOTIATION
23868+ #if defined( HAVE_SECURE_RENEGOTIATION) || defined(WOLFSSL_DTLS13)
2383923869 && ssl->error != APP_DATA_READY
2384023870#endif
2384123871 ) {
0 commit comments