diff --git a/src/bio.c b/src/bio.c index 266debb34..914059db9 100644 --- a/src/bio.c +++ b/src/bio.c @@ -353,14 +353,9 @@ int wolfSSL_BIO_read(WOLFSSL_BIO* bio, void* buf, int len) * (cannot be used with WOLFSSL_USER_IO) */ bio->flags &= ~WOLFSSL_BIO_FLAG_RETRY; ret = wolfIO_Recv(bio->num, (char*)buf, len, 0); - if (ret < 0) { -#ifdef USE_WINDOWS_API - if (WSAGetLastError() == WSAEWOULDBLOCK) - bio->flags |= WOLFSSL_BIO_FLAG_RETRY; -#else - if (errno == EAGAIN) - bio->flags |= WOLFSSL_BIO_FLAG_RETRY; -#endif + if (ret == WC_NO_ERR_TRACE(SOCKET_NODATA)) { + bio->flags |= WOLFSSL_BIO_FLAG_RETRY; + ret = WOLFSSL_BIO_ERROR; } #else ret = NOT_COMPILED_IN; @@ -379,14 +374,9 @@ int wolfSSL_BIO_read(WOLFSSL_BIO* bio, void* buf, int len) wolfSSL_BIO_ADDR_clear(&bio->peer_addr); ret = wolfIO_RecvFrom(bio->num, &bio->peer_addr, (char*)buf, len, 0); } - if ((ret < 0) && (ret != WC_NO_ERR_TRACE(MEMORY_E))) { -#ifdef USE_WINDOWS_API - if (WSAGetLastError() == WSAEWOULDBLOCK) - bio->flags |= WOLFSSL_BIO_FLAG_RETRY; -#else - if (errno == EAGAIN) - bio->flags |= WOLFSSL_BIO_FLAG_RETRY; -#endif + if (ret == WC_NO_ERR_TRACE(SOCKET_NODATA)) { + bio->flags |= WOLFSSL_BIO_FLAG_RETRY; + ret = WOLFSSL_BIO_ERROR; } #else ret = NOT_COMPILED_IN; @@ -782,13 +772,10 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len) * (cannot be used with WOLFSSL_USER_IO) */ bio->flags &= ~WOLFSSL_BIO_FLAG_RETRY; ret = wolfIO_Send(bio->num, (char*)data, len, 0); -#ifdef USE_WINDOWS_API - if (WSAGetLastError() == WSAEWOULDBLOCK) + if (ret == WC_NO_ERR_TRACE(SOCKET_NODATA)) { bio->flags |= WOLFSSL_BIO_FLAG_RETRY; -#else - if (errno == EAGAIN) - bio->flags |= WOLFSSL_BIO_FLAG_RETRY; -#endif + ret = WOLFSSL_BIO_ERROR; + } #else ret = NOT_COMPILED_IN; #endif @@ -806,14 +793,9 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len) ret = SOCKET_ERROR_E; else ret = wolfIO_SendTo(bio->num, &bio->peer_addr, (char*)data, len, 0); - if (ret < 0) { -#ifdef USE_WINDOWS_API - if (WSAGetLastError() == WSAEWOULDBLOCK) - bio->flags |= WOLFSSL_BIO_FLAG_RETRY; -#else - if (errno == EAGAIN) - bio->flags |= WOLFSSL_BIO_FLAG_RETRY; -#endif + if (ret == WC_NO_ERR_TRACE(SOCKET_NODATA)) { + bio->flags |= WOLFSSL_BIO_FLAG_RETRY; + ret = WOLFSSL_BIO_ERROR; } #else ret = NOT_COMPILED_IN; diff --git a/src/ssl_load.c b/src/ssl_load.c index 269002c1f..bab9b1df2 100644 --- a/src/ssl_load.c +++ b/src/ssl_load.c @@ -2891,7 +2891,6 @@ int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file, * @return 1 on success. * @return 0 on failure. */ -WOLFSSL_API int wolfSSL_CTX_load_verify_locations_compat(WOLFSSL_CTX* ctx, const char* file, const char* path) { diff --git a/src/wolfio.c b/src/wolfio.c index c9e92846b..fbb5f28e2 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -177,7 +177,7 @@ static WC_INLINE int wolfSSL_LastError(int err) #elif defined(EBSNET) return xn_getlasterror(); #elif defined(WOLFSSL_LINUXKM) || defined(WOLFSSL_EMNET) - return err; /* Return provided error value */ + return -err; /* Return provided error value */ #elif defined(FUSION_RTOS) #include return FCL_GET_ERRNO; @@ -1100,6 +1100,21 @@ int wolfIO_Recv(SOCKET_T sd, char *buf, int sz, int rdFlags) recvd = (int)RECV_FUNCTION(sd, buf, (size_t)sz, rdFlags); recvd = TranslateReturnCode(recvd, (int)sd); + if (recvd < 0) { + int last_err = wolfSSL_LastError(recvd); + if ((last_err == SOCKET_EWOULDBLOCK) +#if SOCKET_EWOULDBLOCK != SOCKET_EAGAIN + || (last_err == SOCKET_EAGAIN) +#endif +#ifdef SOCKET_ETIMEDOUT + || (last_err == SOCKET_ETIMEDOUT) +#endif + ) + { + return SOCKET_NODATA; + } + } + return recvd; } @@ -1110,6 +1125,21 @@ int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags) sent = (int)SEND_FUNCTION(sd, buf, (size_t)sz, wrFlags); sent = TranslateReturnCode(sent, (int)sd); + if (sent < 0) { + int last_err = wolfSSL_LastError(sent); + if ((last_err == SOCKET_EWOULDBLOCK) +#if SOCKET_EWOULDBLOCK != SOCKET_EAGAIN + || (last_err == SOCKET_EAGAIN) +#endif +#ifdef SOCKET_ETIMEDOUT + || (last_err == SOCKET_ETIMEDOUT) +#endif + ) + { + return SOCKET_NODATA; + } + } + return sent; } @@ -1120,9 +1150,26 @@ int wolfIO_RecvFrom(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int int recvd; socklen_t addr_len = (socklen_t)sizeof(*addr); - recvd = (int)DTLS_RECVFROM_FUNCTION(sd, buf, (size_t)sz, rdFlags, addr ? &addr->sa : NULL, addr ? &addr_len : 0); + recvd = (int)DTLS_RECVFROM_FUNCTION(sd, buf, (size_t)sz, rdFlags, + addr ? &addr->sa : NULL, + addr ? &addr_len : 0); recvd = TranslateReturnCode(recvd, (int)sd); + if (recvd < 0) { + int last_err = wolfSSL_LastError(recvd); + if ((last_err == SOCKET_EWOULDBLOCK) +#if SOCKET_EWOULDBLOCK != SOCKET_EAGAIN + || (last_err == SOCKET_EAGAIN) +#endif +#ifdef SOCKET_ETIMEDOUT + || (last_err == SOCKET_ETIMEDOUT) +#endif + ) + { + return SOCKET_NODATA; + } + } + return recvd; } @@ -1130,9 +1177,26 @@ int wolfIO_SendTo(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int wr { int sent; - sent = (int)DTLS_SENDTO_FUNCTION(sd, buf, (size_t)sz, wrFlags, addr ? &addr->sa : NULL, addr ? wolfSSL_BIO_ADDR_size(addr) : 0); + sent = (int)DTLS_SENDTO_FUNCTION(sd, buf, (size_t)sz, wrFlags, + addr ? &addr->sa : NULL, + addr ? wolfSSL_BIO_ADDR_size(addr) : 0); sent = TranslateReturnCode(sent, (int)sd); + if (sent < 0) { + int last_err = wolfSSL_LastError(sent); + if ((last_err == SOCKET_EWOULDBLOCK) +#if SOCKET_EWOULDBLOCK != SOCKET_EAGAIN + || (last_err == SOCKET_EAGAIN) +#endif +#ifdef SOCKET_ETIMEDOUT + || (last_err == SOCKET_ETIMEDOUT) +#endif + ) + { + return SOCKET_NODATA; + } + } + return sent; } diff --git a/tests/api.c b/tests/api.c index af15b89a3..60fc29ef1 100644 --- a/tests/api.c +++ b/tests/api.c @@ -56986,9 +56986,7 @@ static int test_wolfSSL_BIO_datagram(void) static const struct timeval timeout = { 0, 250000 }; #endif -#ifdef USE_WINDOWS_API - WSAStartup(); -#endif + StartTCP(); if (EXPECT_SUCCESS()) { fd1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 624ffc9cc..678422d19 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -13775,7 +13775,7 @@ static int GetRDN(DecodedCert* cert, char* full, word32* idx, int* nid, * @param [in, out] cert Decoded certificate object. * @param [out] full Buffer to hold full name as a string. * @param [out] hash Buffer to hold hash of name. - * @param [in] nameType ISSUER or SUBJECT. + * @param [in] nameType ASN_ISSUER or ASN_SUBJECT. * @param [in] input Buffer holding certificate name. * @param [in, out] inOutIdx On in, start of certificate name. * On out, start of ASN.1 item after cert name. diff --git a/wolfssl/error-ssl.h b/wolfssl/error-ssl.h index 64edf75c3..724d7de00 100644 --- a/wolfssl/error-ssl.h +++ b/wolfssl/error-ssl.h @@ -185,8 +185,8 @@ enum wolfSSL_ErrorCodes { DTLS_CID_ERROR = -454, /* Wrong or missing CID */ DTLS_TOO_MANY_FRAGMENTS_E = -455, /* Received too many fragments */ QUIC_WRONG_ENC_LEVEL = -456, /* QUIC data received on wrong encryption level */ + DUPLICATE_TLS_EXT_E = -457, /* Duplicate TLS extension in msg. */ - SOCKET_NOT_CONNECTED_E = -458, /* Socket has no associated peer. */ /* add strings to wolfSSL_ERR_reason_error_string in internal.c !!!!! */ /* begin negotiation parameter errors */ diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index 712942b02..eb8b20989 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -208,6 +208,7 @@ #endif #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK #define SOCKET_EAGAIN WSAETIMEDOUT + #define SOCKET_ETIMEDOUT WSAETIMEDOUT #define SOCKET_ECONNRESET WSAECONNRESET #define SOCKET_EINTR WSAEINTR #define SOCKET_EPIPE WSAEPIPE @@ -312,6 +313,7 @@ #elif defined(WOLFSSL_LWIP_NATIVE) #define SOCKET_EWOULDBLOCK ERR_WOULDBLOCK #define SOCKET_EAGAIN ERR_WOULDBLOCK + #define SOCKET_TIMEDOUT ERR_TIMEOUT #define SOCKET_ECONNRESET ERR_RST #define SOCKET_EINTR ERR_CLSD #define SOCKET_EPIPE ERR_CLSD @@ -329,6 +331,7 @@ #else #define SOCKET_EWOULDBLOCK EWOULDBLOCK #define SOCKET_EAGAIN EAGAIN + #define SOCKET_ETIMEDOUT ETIMEDOUT #define SOCKET_ECONNRESET ECONNRESET #define SOCKET_EINTR EINTR #define SOCKET_EPIPE EPIPE @@ -514,6 +517,7 @@ WOLFSSL_API int wolfIO_RecvFrom(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, FNS_CLOSE(s, &err); \ } while(0) #endif + #define StartTCP() WC_DO_NOTHING #else #ifndef CloseSocket #define CloseSocket(s) close(s)