From 73435389ed2274c01c77a5fdbc7bea92ec00f817 Mon Sep 17 00:00:00 2001 From: Anthony Hu Date: Mon, 20 Jun 2022 16:33:04 -0400 Subject: [PATCH 1/6] Fix missing WOLFSSL_DTLS in Micrium build --- src/wolfio.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/wolfio.c b/src/wolfio.c index 34a0742fc..8f1c13050 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -2182,20 +2182,24 @@ int MicriumReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx) NET_SOCK_ADDR_LEN peerSz = sizeof(peer); NET_SOCK_RTN_CODE ret; NET_ERR err; - int dtls_timeout = wolfSSL_dtls_get_current_timeout(ssl); WOLFSSL_ENTER("MicriumReceiveFrom()"); - if (ssl->options.handShakeDone) - dtls_timeout = 0; +#ifdef WOLFSSL_DTLS + { + int dtls_timeout = wolfSSL_dtls_get_current_timeout(ssl); + if (ssl->options.handShakeDone) + dtls_timeout = 0; - if (!wolfSSL_dtls_get_using_nonblock(ssl)) { - /* needs timeout in milliseconds */ - NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout * 1000, &err); - if (err != NET_SOCK_ERR_NONE) { - WOLFSSL_MSG("NetSock_CfgTimeoutRxQ_Set failed"); + if (!wolfSSL_dtls_get_using_nonblock(ssl)) { + /* needs timeout in milliseconds */ + NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout * 1000, &err); + if (err != NET_SOCK_ERR_NONE) { + WOLFSSL_MSG("NetSock_CfgTimeoutRxQ_Set failed"); + } } } +#endif ret = NetSock_RxDataFrom(sd, buf, sz, ssl->rflags, &peer, &peerSz, 0, 0, 0, &err); From 1e84d1eb678c886d776f11018fa862d9946d8dfe Mon Sep 17 00:00:00 2001 From: Anthony Hu Date: Tue, 21 Jun 2022 10:22:44 -0400 Subject: [PATCH 2/6] Change inspired by Rizlik review comments. --- src/wolfio.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/wolfio.c b/src/wolfio.c index 8f1c13050..42762922e 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -2188,18 +2188,38 @@ int MicriumReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx) #ifdef WOLFSSL_DTLS { int dtls_timeout = wolfSSL_dtls_get_current_timeout(ssl); - if (ssl->options.handShakeDone) + /* Don't use ssl->options.handShakeDone since it is true even if + * we are in the process of renegotiation */ + byte doDtlsTimeout = ssl->options.handShakeState != HANDSHAKE_DONE; + + #ifdef WOLFSSL_DTLS13 + if (ssl->options.dtls && IsAtLeastTLSv1_3(ssl->version)) { + if ( + doDtlsTimeout = + doDtlsTimeout || ssl->dtls13Rtx.rtxRecords != NULL || + (ssl->dtls13FastTimeout && ssl->dtls13Rtx.seenRecords != NULL); + } + #endif /* WOLFSSL_DTLS13 */ + + if (!doDtlsTimeout) dtls_timeout = 0; if (!wolfSSL_dtls_get_using_nonblock(ssl)) { /* needs timeout in milliseconds */ + #ifdef WOLFSSL_DTLS13 + if (wolfSSL_dtls13_use_quick_timeout(ssl) && + IsAtLeastTLSv1_3(ssl->version) && (dtls_timeout >= 4)) { + dtls_timeout = dtls_timeout / 4; + } + #endif /* WOLFSSL_DTLS13 */ + NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout * 1000, &err); if (err != NET_SOCK_ERR_NONE) { WOLFSSL_MSG("NetSock_CfgTimeoutRxQ_Set failed"); } } } -#endif +#endif /* WOLFSSL_DTLS */ ret = NetSock_RxDataFrom(sd, buf, sz, ssl->rflags, &peer, &peerSz, 0, 0, 0, &err); From ff4eabb17fdd1e93d94bb8ca4f8fbed542715982 Mon Sep 17 00:00:00 2001 From: Anthony Hu Date: Tue, 21 Jun 2022 10:42:20 -0400 Subject: [PATCH 3/6] same fix to MicriumReceive --- src/wolfio.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/wolfio.c b/src/wolfio.c index 42762922e..875811aa1 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -2128,20 +2128,40 @@ int MicriumReceive(WOLFSSL *ssl, char *buf, int sz, void *ctx) NET_SOCK_RTN_CODE ret; NET_ERR err; -#ifdef WOLFSSL_DTLS + #ifdef WOLFSSL_DTLS { int dtls_timeout = wolfSSL_dtls_get_current_timeout(ssl); - if (wolfSSL_dtls(ssl) - && !wolfSSL_dtls_get_using_nonblock(ssl) - && dtls_timeout != 0) { + /* Don't use ssl->options.handShakeDone since it is true even if + * we are in the process of renegotiation */ + byte doDtlsTimeout = ssl->options.handShakeState != HANDSHAKE_DONE; + #ifdef WOLFSSL_DTLS13 + if (ssl->options.dtls && IsAtLeastTLSv1_3(ssl->version)) { + if ( + doDtlsTimeout = + doDtlsTimeout || ssl->dtls13Rtx.rtxRecords != NULL || + (ssl->dtls13FastTimeout && ssl->dtls13Rtx.seenRecords != NULL); + } + #endif /* WOLFSSL_DTLS13 */ + + if (!doDtlsTimeout) + dtls_timeout = 0; + + if (!wolfSSL_dtls_get_using_nonblock(ssl)) { /* needs timeout in milliseconds */ + #ifdef WOLFSSL_DTLS13 + if (wolfSSL_dtls13_use_quick_timeout(ssl) && + IsAtLeastTLSv1_3(ssl->version) && (dtls_timeout >= 4)) { + dtls_timeout = dtls_timeout / 4; + } + #endif /* WOLFSSL_DTLS13 */ + NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout * 1000, &err); if (err != NET_SOCK_ERR_NONE) { WOLFSSL_MSG("NetSock_CfgTimeoutRxQ_Set failed"); } } } -#endif + #endif ret = NetSock_RxData(sd, buf, sz, ssl->rflags, &err); if (ret < 0) { From f05bcb30e014237f873d8a17bc75ba1b2819ab94 Mon Sep 17 00:00:00 2001 From: Anthony Hu Date: Tue, 21 Jun 2022 10:48:48 -0400 Subject: [PATCH 4/6] div by 4 in milliseconds --- src/wolfio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wolfio.c b/src/wolfio.c index 875811aa1..89dad8116 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -2150,12 +2150,12 @@ int MicriumReceive(WOLFSSL *ssl, char *buf, int sz, void *ctx) /* needs timeout in milliseconds */ #ifdef WOLFSSL_DTLS13 if (wolfSSL_dtls13_use_quick_timeout(ssl) && - IsAtLeastTLSv1_3(ssl->version) && (dtls_timeout >= 4)) { - dtls_timeout = dtls_timeout / 4; + IsAtLeastTLSv1_3(ssl->version)) { + dtls_timeout = (1000 * dtls_timeout) / 4; } #endif /* WOLFSSL_DTLS13 */ - NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout * 1000, &err); + NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout, &err); if (err != NET_SOCK_ERR_NONE) { WOLFSSL_MSG("NetSock_CfgTimeoutRxQ_Set failed"); } @@ -2228,12 +2228,12 @@ int MicriumReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx) /* needs timeout in milliseconds */ #ifdef WOLFSSL_DTLS13 if (wolfSSL_dtls13_use_quick_timeout(ssl) && - IsAtLeastTLSv1_3(ssl->version) && (dtls_timeout >= 4)) { - dtls_timeout = dtls_timeout / 4; + IsAtLeastTLSv1_3(ssl->version)) { + dtls_timeout = (1000 * dtls_timeout) / 4; } #endif /* WOLFSSL_DTLS13 */ - NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout * 1000, &err); + NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout, &err); if (err != NET_SOCK_ERR_NONE) { WOLFSSL_MSG("NetSock_CfgTimeoutRxQ_Set failed"); } From beddc777d4a5f68c090eba703dfc00bdf73736fb Mon Sep 17 00:00:00 2001 From: Anthony Hu Date: Tue, 21 Jun 2022 11:07:19 -0400 Subject: [PATCH 5/6] milliseconds not only for DTLS13 --- src/wolfio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wolfio.c b/src/wolfio.c index 89dad8116..2e6b58426 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -2152,9 +2152,9 @@ int MicriumReceive(WOLFSSL *ssl, char *buf, int sz, void *ctx) if (wolfSSL_dtls13_use_quick_timeout(ssl) && IsAtLeastTLSv1_3(ssl->version)) { dtls_timeout = (1000 * dtls_timeout) / 4; - } + } else #endif /* WOLFSSL_DTLS13 */ - + dtls_timeout = 1000 * dtls_timeout; NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout, &err); if (err != NET_SOCK_ERR_NONE) { WOLFSSL_MSG("NetSock_CfgTimeoutRxQ_Set failed"); @@ -2230,9 +2230,9 @@ int MicriumReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx) if (wolfSSL_dtls13_use_quick_timeout(ssl) && IsAtLeastTLSv1_3(ssl->version)) { dtls_timeout = (1000 * dtls_timeout) / 4; - } + } else #endif /* WOLFSSL_DTLS13 */ - + dtls_timeout = 1000 * dtls_timeout; NetSock_CfgTimeoutRxQ_Set(sd, dtls_timeout, &err); if (err != NET_SOCK_ERR_NONE) { WOLFSSL_MSG("NetSock_CfgTimeoutRxQ_Set failed"); From 099afe4419ca7d36a559b23f14c6d2d89478f271 Mon Sep 17 00:00:00 2001 From: Anthony Hu Date: Tue, 21 Jun 2022 11:33:08 -0400 Subject: [PATCH 6/6] errant if --- src/wolfio.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wolfio.c b/src/wolfio.c index 2e6b58426..70c6217ca 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -2136,7 +2136,6 @@ int MicriumReceive(WOLFSSL *ssl, char *buf, int sz, void *ctx) byte doDtlsTimeout = ssl->options.handShakeState != HANDSHAKE_DONE; #ifdef WOLFSSL_DTLS13 if (ssl->options.dtls && IsAtLeastTLSv1_3(ssl->version)) { - if ( doDtlsTimeout = doDtlsTimeout || ssl->dtls13Rtx.rtxRecords != NULL || (ssl->dtls13FastTimeout && ssl->dtls13Rtx.seenRecords != NULL); @@ -2214,7 +2213,6 @@ int MicriumReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx) #ifdef WOLFSSL_DTLS13 if (ssl->options.dtls && IsAtLeastTLSv1_3(ssl->version)) { - if ( doDtlsTimeout = doDtlsTimeout || ssl->dtls13Rtx.rtxRecords != NULL || (ssl->dtls13FastTimeout && ssl->dtls13Rtx.seenRecords != NULL);