From e14cc3a34e4a5eaf06861176480f9bc783ba399d Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Fri, 3 Oct 2025 08:28:02 +1000 Subject: [PATCH 1/6] TLS 1.3 Cookie Hash: use stronger hash if no SHA-256 Order of preference, based on algorithms compiled in, to use with HMAC for TLS 1.3 cookie: 1. SHA-256 2. SHA-384 3. SHA-512 4. SM3 Make code compile and unittest pass when SHA-256 not compiled in. Certificates used for testing require SHA-256 so handshake testing fails. --- src/tls13.c | 53 +++++++++++++++++++++++++------------- tests/api.c | 56 ++++++++++++++++++++++++++++------------- tests/api/test_dtls.c | 3 ++- tests/api/test_pkcs12.c | 4 ++- tests/api/test_rsa.c | 5 ++-- wolfcrypt/test/test.c | 13 +++++++++- wolfssl/internal.h | 2 +- 7 files changed, 96 insertions(+), 40 deletions(-) diff --git a/src/tls13.c b/src/tls13.c index 76a6b3977..90a409f45 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -306,7 +306,7 @@ static int DeriveKeyMsg(WOLFSSL* ssl, byte* output, int outputLen, int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG); switch (hashAlgo) { -#ifndef NO_WOLFSSL_SHA256 +#ifndef NO_SHA256 case sha256_mac: ret = wc_InitSha256_ex(&digest.sha256, ssl->heap, ssl->devId); if (ret == 0) { @@ -3601,14 +3601,21 @@ int CreateCookieExt(const WOLFSSL* ssl, byte* hash, word16 hashSz, cookieSz += OPAQUE16_LEN; } -#if !defined(NO_SHA) && defined(NO_SHA256) - cookieType = SHA; - macSz = WC_SHA_DIGEST_SIZE; -#endif /* NO_SHA */ #ifndef NO_SHA256 cookieType = WC_SHA256; macSz = WC_SHA256_DIGEST_SIZE; -#endif /* NO_SHA256 */ +#elif defined(WOLFSSL_SHA384) + cookieType = WC_SHA384; + macSz = WC_SHA384_DIGEST_SIZE; +#elif defined(WOLFSSL_TLS13_SHA512) + cookieType = WC_SHA512; + macSz = WC_SHA512_DIGEST_SIZE; +#elif defined(WOLFSSL_SM3) + cookieType = WC_SM3; + macSz = WC_SM3_DIGEST_SIZE; +#else + #error "No digest to available to use with HMAC for cookies." +#endif /* NO_SHA */ ret = wc_HmacInit(&cookieHmac, ssl->heap, ssl->devId); if (ret == 0) { @@ -6456,14 +6463,21 @@ int TlsCheckCookie(const WOLFSSL* ssl, const byte* cookie, word16 cookieSz) return COOKIE_ERROR; } -#if !defined(NO_SHA) && defined(NO_SHA256) - cookieType = SHA; - macSz = WC_SHA_DIGEST_SIZE; -#endif /* NO_SHA */ #ifndef NO_SHA256 cookieType = WC_SHA256; macSz = WC_SHA256_DIGEST_SIZE; -#endif /* NO_SHA256 */ +#elif defined(WOLFSSL_SHA384) + cookieType = WC_SHA384; + macSz = WC_SHA384_DIGEST_SIZE; +#elif defined(WOLFSSL_TLS13_SHA512) + cookieType = WC_SHA512; + macSz = WC_SHA512_DIGEST_SIZE; +#elif defined(WOLFSSL_SM3) + cookieType = WC_SM3; + macSz = WC_SM3_DIGEST_SIZE; +#else + #error "No digest to available to use with HMAC for cookies." +#endif /* NO_SHA */ if (cookieSz < ssl->specs.hash_size + macSz) return HRR_COOKIE_ERROR; @@ -8389,7 +8403,7 @@ int CreateRSAEncodedSig(byte* sig, byte* sigData, int sigDataSz, /* Digest the signature data. */ switch (hashAlgo) { -#ifndef NO_WOLFSSL_SHA256 +#ifndef NO_SHA256 case sha256_mac: ret = wc_InitSha256(&digest.sha256); if (ret == 0) { @@ -8454,7 +8468,7 @@ static int CreateECCEncodedSig(byte* sigData, int sigDataSz, int hashAlgo) /* Digest the signature data. */ switch (hashAlgo) { -#ifndef NO_WOLFSSL_SHA256 +#ifndef NO_SHA256 case sha256_mac: ret = wc_InitSha256(&digest.sha256); if (ret == 0) { @@ -13608,12 +13622,17 @@ int wolfSSL_send_hrr_cookie(WOLFSSL* ssl, const unsigned char* secret, return SIDE_ERROR; if (secretSz == 0) { - #if !defined(NO_SHA) && defined(NO_SHA256) - secretSz = WC_SHA_DIGEST_SIZE; - #endif /* NO_SHA */ #ifndef NO_SHA256 secretSz = WC_SHA256_DIGEST_SIZE; - #endif /* NO_SHA256 */ + #elif defined(WOLFSSL_SHA384) + secretSz = WC_SHA384_DIGEST_SIZE; + #elif defined(WOLFSSL_TLS13_SHA512) + secretSz = WC_SHA512_DIGEST_SIZE; + #elif defined(WOLFSSL_SM3) + secretSz = WC_SM3_DIGEST_SIZE; + #else + #error "No digest to available to use with HMAC for cookies." + #endif /* NO_SHA */ } if (secretSz != ssl->buffers.tls13CookieSecret.length) { diff --git a/tests/api.c b/tests/api.c index c22d02456..347eb4fd2 100644 --- a/tests/api.c +++ b/tests/api.c @@ -3172,7 +3172,8 @@ static int test_wolfSSL_CertManagerLoadCABufferType(void) { EXPECT_DECLS; #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_TLS) && \ - !defined(NO_RSA) && !defined(WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION) + !defined(NO_RSA) && !defined(NO_SHA256) && \ + !defined(WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION) #if defined(WOLFSSL_PEM_TO_DER) const char* ca_cert = "./certs/ca-cert.pem"; const char* int1_cert = "./certs/intermediate/ca-int-cert.pem"; @@ -5125,12 +5126,14 @@ static int test_wolfSSL_CertRsaPss(void) (HAVE_FIPS_VERSION > 2))) && (!defined(HAVE_SELFTEST) || \ (defined(HAVE_SELFTEST_VERSION) && (HAVE_SELFTEST_VERSION > 2))) XFILE f = XBADFILE; +#ifndef NO_SHA256 const char* rsaPssSha256Cert = "./certs/rsapss/ca-rsapss.der"; #ifdef WOLFSSL_PEM_TO_DER const char* rsaPssRootSha256Cert = "./certs/rsapss/root-rsapss.pem"; #else const char* rsaPssRootSha256Cert = "./certs/rsapss/root-rsapss.der"; #endif +#endif #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \ RSA_MAX_SIZE >= 3072 const char* rsaPssSha384Cert = "./certs/rsapss/ca-3072-rsapss.der"; @@ -5148,13 +5151,16 @@ static int test_wolfSSL_CertRsaPss(void) WOLFSSL_CERT_MANAGER* cm = NULL; ExpectNotNull(cm = wolfSSL_CertManagerNew()); +#ifndef NO_SHA256 ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha256Cert, NULL)); +#endif #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072 ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha384Cert, NULL)); #endif +#ifndef NO_SHA256 ExpectTrue((f = XFOPEN(rsaPssSha256Cert, "rb")) != XBADFILE); ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0); if (f != XBADFILE) { @@ -5164,6 +5170,7 @@ static int test_wolfSSL_CertRsaPss(void) wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL); ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0); wc_FreeDecodedCert(&cert); +#endif #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \ RSA_MAX_SIZE >= 3072 @@ -5177,6 +5184,9 @@ static int test_wolfSSL_CertRsaPss(void) #endif wolfSSL_CertManagerFree(cm); + + (void)buf; + (void)bytes; #endif return EXPECT_RESULT(); @@ -9455,6 +9465,8 @@ cleanup: static int test_wolfSSL_read_write(void) { + EXPECT_DECLS; +#ifndef NO_SHA256 /* The unit testing for read and write shall happen simultaneously, since * one can't do anything with one without the other. (Except for a failure * test case.) This function will call all the others that will set up, @@ -9478,7 +9490,6 @@ static int test_wolfSSL_read_write(void) func_args client_args; func_args server_args; THREAD_TYPE serverThread; - EXPECT_DECLS; XMEMSET(&client_args, 0, sizeof(func_args)); XMEMSET(&server_args, 0, sizeof(func_args)); @@ -9510,7 +9521,7 @@ static int test_wolfSSL_read_write(void) #ifdef WOLFSSL_TIRTOS fdOpenSession(Task_self()); #endif - +#endif return EXPECT_RESULT(); } @@ -25149,7 +25160,8 @@ static int test_wolfSSL_check_domain(void) } #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */ -#if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(OPENSSL_COMPATIBLE_DEFAULTS) +#if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_SHA256) static const char* dn = NULL; static int test_wolfSSL_check_domain_basic_client_ssl(WOLFSSL* ssl) { @@ -27846,8 +27858,8 @@ static int test_wolfSSL_SESSION(void) { EXPECT_DECLS; #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ - !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \ - !defined(NO_SESSION_CACHE) + !defined(NO_RSA) && !defined(NO_SHA256) && \ + defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE) WOLFSSL* ssl = NULL; WOLFSSL_CTX* ctx = NULL; WOLFSSL_SESSION* sess = NULL; @@ -37634,7 +37646,7 @@ static int test_X509_LOOKUP_add_dir(void) *----------------------------------------------------------------------------*/ #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \ !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM) -#if !defined(NO_RSA) || defined(HAVE_ECC) +#if (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_SHA256) /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */ #ifndef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION static int verify_sig_cm(const char* ca, byte* cert_buf, size_t cert_sz, @@ -42012,6 +42024,7 @@ static int test_wolfSSL_dtls_stateless(void) #ifdef HAVE_CERT_CHAIN_VALIDATION #ifndef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION #ifdef WOLFSSL_PEM_TO_DER +#ifndef NO_SHA256 static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA) { int ret; @@ -42189,10 +42202,12 @@ static int test_chainJ(WOLFSSL_CERT_MANAGER* cm) return ret; } +#endif static int test_various_pathlen_chains(void) { EXPECT_DECLS; +#ifndef NO_SHA256 WOLFSSL_CERT_MANAGER* cm = NULL; /* Test chain G (large chain with varying pathLens) */ @@ -42245,6 +42260,7 @@ static int test_various_pathlen_chains(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); +#endif return EXPECT_RESULT(); } @@ -47276,7 +47292,8 @@ static int test_dtls13_bad_epoch_ch(void) (!defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \ !defined(NO_DES3))) || !defined(WOLFSSL_NO_TLS12)) && \ !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ - defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE) + defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + !defined(NO_SESSION_CACHE) && !defined(NO_SHA256) static int test_short_session_id_ssl_ready(WOLFSSL* ssl) { EXPECT_DECLS; @@ -48581,8 +48598,9 @@ static int test_certreq_sighash_algos(void) EXPECT_DECLS; #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ !defined(WOLFSSL_MAX_STRENGTH) && defined(HAVE_ECC) && \ - defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \ - defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_TLS12) + !defined(NO_SHA256) && defined(WOLFSSL_SHA384) && \ + defined(WOLFSSL_AES_256) && defined(HAVE_AES_CBC) && \ + !defined(WOLFSSL_NO_TLS12) WOLFSSL_CTX *ctx_c = NULL; WOLFSSL_CTX *ctx_s = NULL; WOLFSSL *ssl_c = NULL; @@ -49447,7 +49465,8 @@ static int test_self_signed_stapling(void) static int test_tls_multi_handshakes_one_record(void) { EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + !defined(WOLFSSL_NO_TLS12) && !defined(NO_SHA256) struct test_memio_ctx test_ctx; WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; WOLFSSL *ssl_c = NULL, *ssl_s = NULL; @@ -49652,7 +49671,8 @@ static int test_read_write_hs(void) { EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + !defined(WOLFSSL_NO_TLS12) && !defined(NO_SHA256) WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL; WOLFSSL *ssl_s = NULL, *ssl_c = NULL; struct test_memio_ctx test_ctx; @@ -49931,7 +49951,8 @@ static int test_get_signature_nid(void) } #ifndef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION -#if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) +#if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + !defined(NO_SHA256) static word32 test_tls_cert_store_unchanged_HashCaTable(Signer** caTable) { #ifndef NO_MD5 @@ -50024,7 +50045,8 @@ static int test_tls_cert_store_unchanged_ssl_ready(WOLFSSL* ssl) static int test_tls_cert_store_unchanged(void) { EXPECT_DECLS; -#if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) +#if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + !defined(NO_SHA256) test_ssl_cbf client_cbf; test_ssl_cbf server_cbf; int i; @@ -50255,7 +50277,7 @@ static int test_wolfSSL_SSLDisableRead(void) static int test_wolfSSL_inject(void) { EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_SHA256) size_t i; struct { method_provider client_meth; @@ -50683,6 +50705,7 @@ TEST_CASE testCases[] = { #endif TEST_DECL(test_EVP_PKEY_rsa), + TEST_DECL(test_wc_RsaPSS_DigitalSignVerify), TEST_DECL(test_EVP_PKEY_ec), TEST_DECL(test_wolfSSL_EVP_PKEY_encrypt), TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_rsa), @@ -51026,7 +51049,6 @@ TEST_CASE testCases[] = { defined(WOLFSSL_PEM_TO_DER) TEST_DECL(test_various_pathlen_chains), #endif -TEST_DECL(test_wc_RsaPSS_DigitalSignVerify), /********************************* * SSL/TLS API tests @@ -51072,7 +51094,7 @@ TEST_DECL(test_wc_RsaPSS_DigitalSignVerify), #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \ !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM) && \ !defined(WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION) && \ - (!defined(NO_RSA) || defined(HAVE_ECC)) + (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_SHA256) /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */ /* Bad certificate signature tests */ TEST_DECL(test_EccSigFailure_cm), diff --git a/tests/api/test_dtls.c b/tests/api/test_dtls.c index 9d7d2b0f2..979214566 100644 --- a/tests/api/test_dtls.c +++ b/tests/api/test_dtls.c @@ -1247,7 +1247,8 @@ int test_dtls_record_cross_boundaries(void) } #endif /* defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) */ -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + !defined(WOLFSSL_NO_TLS12) && !defined(NO_SHA256) /* This test that the DTLS record boundary check doesn't interfere with TLS * records processing */ int test_records_span_network_boundaries(void) diff --git a/tests/api/test_pkcs12.c b/tests/api/test_pkcs12.c index b71b2a166..4dfb3cfbc 100644 --- a/tests/api/test_pkcs12.c +++ b/tests/api/test_pkcs12.c @@ -42,7 +42,7 @@ int test_wc_i2d_PKCS12(void) EXPECT_DECLS; #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \ && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ - && !defined(NO_AES) && !defined(NO_SHA) + && !defined(NO_AES) && !defined(NO_SHA) && !defined(NO_SHA256) WC_PKCS12* pkcs12 = NULL; unsigned char der[FOURK_BUF * 2]; unsigned char* pt; @@ -163,6 +163,7 @@ int test_wc_PKCS12_create(void) { EXPECT_DECLS; +#ifndef NO_SHA256 EXPECT_TEST(test_wc_PKCS12_create_once(-1, -1)); #if !defined(NO_RC4) && !defined(NO_SHA) EXPECT_TEST(test_wc_PKCS12_create_once(PBE_SHA1_RC4_128, PBE_SHA1_RC4_128)); @@ -187,6 +188,7 @@ int test_wc_PKCS12_create(void) #if defined(HAVE_AES_CBC) && !defined(NO_AES) && !defined(NO_AES_256) && \ !defined(NO_SHA) && defined(WOLFSSL_ASN_TEMPLATE) && !defined(NO_DES3) EXPECT_TEST(test_wc_PKCS12_create_once(PBE_AES256_CBC, PBE_SHA1_DES3)); +#endif #endif (void) test_wc_PKCS12_create_once; diff --git a/tests/api/test_rsa.c b/tests/api/test_rsa.c index 895ca78a7..97354217e 100644 --- a/tests/api/test_rsa.c +++ b/tests/api/test_rsa.c @@ -106,8 +106,9 @@ int test_wc_RsaPrivateKeyDecode(void) int test_wc_RsaPublicKeyDecode(void) { EXPECT_DECLS; -#if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024) || \ - defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS) +#if !defined(NO_RSA) && !defined(NO_SHA256) && \ + (defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)) && \ + !defined(HAVE_FIPS) RsaKey keyPub; byte* tmp = NULL; word32 idx = 0; diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index d784115a9..f27b42d25 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -18611,7 +18611,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void) 0xa1, 0x80, 0x18, 0x3a, 0x07, 0xdf, 0xae, 0x17 }; - byte output[WC_SHA256_DIGEST_SIZE * 4]; + byte output[32 * 4]; wc_test_ret_t ret; WOLFSSL_ENTER("random_test"); @@ -20628,7 +20628,9 @@ static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key) #ifdef WOLFSSL_SHA224 WC_MGF1SHA224, #endif +#ifndef NO_SHA256 WC_MGF1SHA256, +#endif #ifdef WOLFSSL_SHA384 WC_MGF1SHA384, #endif @@ -20643,7 +20645,9 @@ static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key) #ifdef WOLFSSL_SHA224 WC_HASH_TYPE_SHA224, #endif +#ifndef NO_SHA256 WC_HASH_TYPE_SHA256, +#endif #ifdef WOLFSSL_SHA384 WC_HASH_TYPE_SHA384, #endif @@ -28297,6 +28301,7 @@ typedef struct { * serverHelloRandom, serverFinishedRandom, and clietnFinishedRandom * hashed together. */ static const Tls13KdfTestVector tls13KdfTestVectors[] = { +#ifndef NO_SHA256 { /* 1 */ WC_HASH_TYPE_SHA256, 35, 35, { /* PSK */ @@ -28520,6 +28525,7 @@ static const Tls13KdfTestVector tls13KdfTestVectors[] = { 0xa5, 0x7c, 0x50, 0x14, 0xfd, 0xe7, 0x5f, 0x8b, 0xd3, 0x2f, 0xdc, 0x9b, 0xa9, 0x93, 0x22, 0x19, 0xe6, 0xf2, 0x0c, 0xd8 } }, +#endif #ifdef WOLFSSL_SHA384 { /* 26 */ WC_HASH_TYPE_SHA384, 35, 35, @@ -32339,6 +32345,7 @@ done: !defined(NO_ECC_SIGN) static wc_test_ret_t ecc_sig_test(WC_RNG* rng, ecc_key* key) { +#ifndef NO_SHA256 wc_test_ret_t ret; word32 sigSz; int size; @@ -32383,6 +32390,10 @@ static wc_test_ret_t ecc_sig_test(WC_RNG* rng, ecc_key* key) if (ret != 0) return WC_TEST_RET_ENC_EC(ret); TEST_SLEEP(); +#else + (void)rng; + (void)key; +#endif return 0; } diff --git a/wolfssl/internal.h b/wolfssl/internal.h index 0faf0bdc4..e4b4729c6 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -4459,7 +4459,7 @@ WOLFSSL_LOCAL int BuildCertHashes(const WOLFSSL* ssl, Hashes* hashes); #ifdef WOLFSSL_TLS13 typedef union Digest { -#ifndef NO_WOLFSSL_SHA256 +#ifndef NO_SHA256 wc_Sha256 sha256; #endif #ifdef WOLFSSL_SHA384 From 2adae90a5defc5e63f4fb05accd2f5c6fae69cad Mon Sep 17 00:00:00 2001 From: effbiae Date: Fri, 3 Oct 2025 11:41:03 +1000 Subject: [PATCH 2/6] refactor to BuildMsgOrHashOutput --- src/internal.c | 318 ++++++++++++++----------------------------------- 1 file changed, 91 insertions(+), 227 deletions(-) diff --git a/src/internal.c b/src/internal.c index 1834fdee4..75a58707e 100644 --- a/src/internal.c +++ b/src/internal.c @@ -24503,6 +24503,77 @@ int cipherExtraData(WOLFSSL* ssl) #ifndef WOLFSSL_NO_TLS12 +static int BuildMsgOrHashOutput(WOLFSSL* ssl, byte* output, int* sendSz, + int inputSz, enum HandShakeType type, + const char *name) +{ + int ret = 0; + if (IsEncryptionOn(ssl, 1)) { + byte* input; + int recordHeaderSz = RECORD_HEADER_SZ; + + if (ssl->options.dtls) + recordHeaderSz += DTLS_RECORD_EXTRA; + inputSz -= recordHeaderSz; + if (inputSz <= 0) { + WOLFSSL_MSG("Bad inputSz"); + return BUFFER_E; + } + input = (byte*)XMALLOC((size_t)inputSz, ssl->heap, + DYNAMIC_TYPE_IN_BUFFER); + if (input == NULL) + return MEMORY_E; + + XMEMCPY(input, output + recordHeaderSz, (size_t)(inputSz)); + #ifdef WOLFSSL_DTLS + if (IsDtlsNotSctpMode(ssl) && + (ret = DtlsMsgPoolSave(ssl, input, (word32)inputSz, + type)) != 0) { + XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); + return ret; + } + #else + (void)type; + #endif + *sendSz = BuildMessage(ssl, output, *sendSz, input, inputSz, + handshake, 1, 0, 0, CUR_ORDER); + XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); + + if (*sendSz < 0) + return *sendSz; + } else { + if (type == certificate_request) + *sendSz = inputSz; + #ifdef WOLFSSL_DTLS + if (IsDtlsNotSctpMode(ssl)) { + ret = DtlsMsgPoolSave(ssl, output, (word32)*sendSz, type); + if (ret != 0) + return ret; + } + if (ssl->options.dtls) + DtlsSEQIncrement(ssl, CUR_ORDER); + #endif + ret = HashOutput(ssl, output, *sendSz, 0); + if (ret != 0) + return ret; + } +#if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA) + if (ssl->hsInfoOn) + AddPacketName(ssl, name); + if (ssl->toInfoOn) { + ret = AddPacketInfo(ssl, name, handshake, output, + *sendSz, WRITE_PROTO, 0, ssl->heap); + if (ret != 0) + return ret; + } +#else + (void)name; +#endif + ssl->buffers.outputBuffer.length += (word32)*sendSz; + ssl->options.buildingMsg = 0; + return 0; +} + #ifndef NO_CERTS #if (!defined(NO_WOLFSSL_SERVER) || !defined(WOLFSSL_NO_CLIENT_AUTH)) && \ @@ -24821,6 +24892,7 @@ int SendCertificate(WOLFSSL* ssl) } #endif /* !NO_TLS && (!NO_WOLFSSL_SERVER || !WOLFSSL_NO_CLIENT_AUTH) */ + #if !defined(NO_TLS) /* handle generation of certificate_request (13) */ int SendCertificateRequest(WOLFSSL* ssl) @@ -24954,75 +25026,16 @@ int SendCertificateRequest(WOLFSSL* ssl) names = names->next; } #endif - (void)i; + ret = BuildMsgOrHashOutput(ssl, output, &sendSz, i, certificate_request, + "CertificateRequest"); + if (ret != 0) + return ret; - if (IsEncryptionOn(ssl, 1)) { - byte* input = NULL; - int inputSz = (int)i; /* build msg adds rec hdr */ - int recordHeaderSz = RECORD_HEADER_SZ; - - if (ssl->options.dtls) - recordHeaderSz += DTLS_RECORD_EXTRA; - inputSz -= recordHeaderSz; - - if (inputSz <= 0) { - WOLFSSL_MSG("Send Cert Req bad inputSz"); - return BUFFER_E; - } - - input = (byte*)XMALLOC((size_t)inputSz, ssl->heap, - DYNAMIC_TYPE_IN_BUFFER); - if (input == NULL) - return MEMORY_E; - - XMEMCPY(input, output + recordHeaderSz, (size_t)(inputSz)); - #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl) && - (ret = DtlsMsgPoolSave(ssl, input, (word32)inputSz, - certificate_request)) != 0) { - XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); - return ret; - } - #endif - sendSz = BuildMessage(ssl, output, sendSz, input, inputSz, - handshake, 1, 0, 0, CUR_ORDER); - XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); - - if (sendSz < 0) - return sendSz; - } else { - sendSz = (int)i; - #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl)) { - if ((ret = DtlsMsgPoolSave(ssl, output, (word32)sendSz, - certificate_request)) != 0) - return ret; - } - if (ssl->options.dtls) - DtlsSEQIncrement(ssl, CUR_ORDER); - #endif - ret = HashOutput(ssl, output, sendSz, 0); - if (ret != 0) - return ret; - } - - #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA) - if (ssl->hsInfoOn) - AddPacketName(ssl, "CertificateRequest"); - if (ssl->toInfoOn) { - ret = AddPacketInfo(ssl, "CertificateRequest", handshake, output, - sendSz, WRITE_PROTO, 0, ssl->heap); - if (ret != 0) - return ret; - } - #endif - ssl->buffers.outputBuffer.length += (word32)sendSz; if (ssl->options.groupMessages) ret = 0; else ret = SendBuffered(ssl); - ssl->options.buildingMsg = 0; WOLFSSL_LEAVE("SendCertificateRequest", ret); WOLFSSL_END(WC_FUNC_CERTIFICATE_REQUEST_SEND); @@ -31007,47 +31020,10 @@ static int HashSkeData(WOLFSSL* ssl, enum wc_HashType hashType, } #endif /* HAVE_TLS_EXTENSIONS */ - if (IsEncryptionOn(ssl, 1)) { - byte* input; - int inputSz = (int)idx; /* build msg adds rec hdr */ - int recordHeaderSz = RECORD_HEADER_SZ; - - if (ssl->options.dtls) - recordHeaderSz += DTLS_RECORD_EXTRA; - inputSz -= recordHeaderSz; - input = (byte*)XMALLOC((size_t)inputSz, ssl->heap, - DYNAMIC_TYPE_IN_BUFFER); - if (input == NULL) - return MEMORY_E; - - XMEMCPY(input, output + recordHeaderSz, (size_t)(inputSz)); - #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl) && - (ret = DtlsMsgPoolSave(ssl, input, (word32)inputSz, - client_hello)) != 0) { - XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); - return ret; - } - #endif - sendSz = BuildMessage(ssl, output, sendSz, input, inputSz, - handshake, 1, 0, 0, CUR_ORDER); - XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); - - if (sendSz < 0) - return sendSz; - } else { - #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl)) { - if ((ret = DtlsMsgPoolSave(ssl, output, (word32)sendSz, client_hello)) != 0) - return ret; - } - if (ssl->options.dtls) - DtlsSEQIncrement(ssl, CUR_ORDER); - #endif - ret = HashOutput(ssl, output, sendSz, 0); - if (ret != 0) - return ret; - } + ret = BuildMsgOrHashOutput(ssl, output, &sendSz, idx, client_hello, + "ClientHello"); + if (ret != 0) + return ret; ssl->options.clientState = CLIENT_HELLO_COMPLETE; #ifdef OPENSSL_EXTRA @@ -31056,20 +31032,6 @@ static int HashSkeData(WOLFSSL* ssl, enum wc_HashType hashType, ssl->CBIS(ssl, WOLFSSL_CB_CONNECT_LOOP, WOLFSSL_SUCCESS); #endif -#if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA) - if (ssl->hsInfoOn) AddPacketName(ssl, "ClientHello"); - if (ssl->toInfoOn) { - ret = AddPacketInfo(ssl, "ClientHello", handshake, output, sendSz, - WRITE_PROTO, 0, ssl->heap); - if (ret != 0) - return ret; - } -#endif - - ssl->options.buildingMsg = 0; - - ssl->buffers.outputBuffer.length += (word32)sendSz; - ret = SendBuffered(ssl); WOLFSSL_LEAVE("SendClientHello", ret); @@ -35538,61 +35500,12 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, #endif #endif - if (IsEncryptionOn(ssl, 1)) { - byte* input; - int inputSz = (int)idx; /* build msg adds rec hdr */ - int recordHeaderSz = RECORD_HEADER_SZ; - - if (ssl->options.dtls) - recordHeaderSz += DTLS_RECORD_EXTRA; - inputSz -= recordHeaderSz; - input = (byte*)XMALLOC((size_t)inputSz, ssl->heap, - DYNAMIC_TYPE_IN_BUFFER); - if (input == NULL) - return MEMORY_E; - - XMEMCPY(input, output + recordHeaderSz, (size_t)(inputSz)); - #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl) && - (ret = DtlsMsgPoolSave(ssl, input, (word32)inputSz, server_hello)) != 0) { - XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); - return ret; - } - #endif - sendSz = BuildMessage(ssl, output, sendSz, input, inputSz, - handshake, 1, 0, 0, CUR_ORDER); - XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); - - if (sendSz < 0) - return sendSz; - } else { - #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl)) { - if ((ret = DtlsMsgPoolSave(ssl, output, (word32)sendSz, server_hello)) != 0) - return ret; - } - if (ssl->options.dtls) - DtlsSEQIncrement(ssl, CUR_ORDER); - #endif - ret = HashOutput(ssl, output, sendSz, 0); - if (ret != 0) - return ret; - } - - #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA) - if (ssl->hsInfoOn) - AddPacketName(ssl, "ServerHello"); - if (ssl->toInfoOn) { - ret = AddPacketInfo(ssl, "ServerHello", handshake, output, sendSz, - WRITE_PROTO, 0, ssl->heap); - if (ret != 0) - return ret; - } - #endif + ret = BuildMsgOrHashOutput(ssl, output, &sendSz, idx, server_hello, + "ServerHello"); + if (ret != 0) + return ret; ssl->options.serverState = SERVER_HELLO_COMPLETE; - ssl->options.buildingMsg = 0; - ssl->buffers.outputBuffer.length += (word32)sendSz; if (ssl->options.groupMessages) ret = 0; @@ -39081,64 +38994,15 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, /* get output buffer */ output = GetOutputBuffer(ssl); AddHeaders(output, 0, server_hello_done, ssl); + ret = BuildMsgOrHashOutput(ssl, output, &sendSz, + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ + + (ssl->options.dtls ? + DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA : 0), + server_hello_done, "ServerHelloDone"); + if (ret != 0) + return ret; - if (IsEncryptionOn(ssl, 1)) { - byte* input; - int inputSz = HANDSHAKE_HEADER_SZ; /* build msg adds rec hdr */ - int recordHeaderSz = RECORD_HEADER_SZ; - - if (ssl->options.dtls) { - recordHeaderSz += DTLS_RECORD_EXTRA; - inputSz += DTLS_HANDSHAKE_EXTRA; - } - - input = (byte*)XMALLOC((size_t)inputSz, ssl->heap, - DYNAMIC_TYPE_IN_BUFFER); - if (input == NULL) - return MEMORY_E; - - XMEMCPY(input, output + recordHeaderSz, (size_t)(inputSz)); - #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl) && - (ret = DtlsMsgPoolSave(ssl, input, (word32)inputSz, server_hello_done)) != 0) { - XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); - return ret; - } - #endif - sendSz = BuildMessage(ssl, output, sendSz, input, inputSz, - handshake, 1, 0, 0, CUR_ORDER); - XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); - - if (sendSz < 0) - return sendSz; - } else { - #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl)) { - if ((ret = DtlsMsgPoolSave(ssl, output, (word32)sendSz, server_hello_done)) != 0) - return ret; - } - if (ssl->options.dtls) - DtlsSEQIncrement(ssl, CUR_ORDER); - #endif - ret = HashOutput(ssl, output, sendSz, 0); - if (ret != 0) - return ret; - } - - #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA) - if (ssl->hsInfoOn) - AddPacketName(ssl, "ServerHelloDone"); - if (ssl->toInfoOn) { - ret = AddPacketInfo(ssl, "ServerHelloDone", handshake, output, - sendSz, WRITE_PROTO, 0, ssl->heap); - if (ret != 0) - return ret; - } - #endif ssl->options.serverState = SERVER_HELLODONE_COMPLETE; - ssl->options.buildingMsg = 0; - - ssl->buffers.outputBuffer.length += (word32)sendSz; ret = SendBuffered(ssl); From cd0d98601676da4e7d3b81646c8e96cf882eac63 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Wed, 1 Oct 2025 13:21:28 +0200 Subject: [PATCH 3/6] Reset DTLS 1.3 timeout --- src/internal.c | 7 ++++- tests/api.c | 1 + tests/api/test_dtls.c | 59 +++++++++++++++++++++++++++++++++++++++++++ tests/api/test_dtls.h | 1 + 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/internal.c b/src/internal.c index 153a746fb..2397e5b00 100644 --- a/src/internal.c +++ b/src/internal.c @@ -22799,7 +22799,12 @@ default: return ZERO_RETURN; } #endif /* WOLFSSL_EARLY_DATA */ - + if (ret == 0 || + ret == WC_NO_ERR_TRACE(WC_PENDING_E)) { + /* Reset timeout as we have received a valid + * DTLS handshake message */ + ssl->dtls_timeout = ssl->dtls_timeout_init; + } } #endif /* WOLFSSL_DTLS13 */ } diff --git a/tests/api.c b/tests/api.c index 252e16182..58957793a 100644 --- a/tests/api.c +++ b/tests/api.c @@ -51407,6 +51407,7 @@ TEST_DECL(test_wc_RsaPSS_DigitalSignVerify), TEST_DECL(test_dtls_bogus_finished_epoch_zero), TEST_DECL(test_dtls_replay), TEST_DECL(test_dtls_srtp), + TEST_DECL(test_dtls_timeout), TEST_DECL(test_dtls13_ack_order), TEST_DECL(test_dtls_version_checking), TEST_DECL(test_ocsp_status_callback), diff --git a/tests/api/test_dtls.c b/tests/api/test_dtls.c index 9d7d2b0f2..1287a2c8f 100644 --- a/tests/api/test_dtls.c +++ b/tests/api/test_dtls.c @@ -1637,3 +1637,62 @@ int test_dtls_srtp(void) return EXPECT_RESULT(); } #endif + +int test_dtls_timeout(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) + size_t i; + struct { + method_provider client_meth; + method_provider server_meth; + } params[] = { +#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13) + { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method }, +#endif +#if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_DTLS) + { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method }, +#endif +#if !defined(NO_OLD_TLS) && defined(WOLFSSL_DTLS) + { wolfDTLSv1_client_method, wolfDTLSv1_server_method }, +#endif + }; + + for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) { + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + params[i].client_meth, params[i].server_meth), 0); + ExpectIntEQ(wolfSSL_dtls_set_timeout_max(ssl_c, 2), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); +#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13) + /* will return 0 when not 1.3 */ + if (wolfSSL_dtls13_use_quick_timeout(ssl_c)) + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); +#endif + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); +#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13) + /* will return 0 when not 1.3 */ + if (wolfSSL_dtls13_use_quick_timeout(ssl_c)) + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); +#endif + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_s); + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_s); + wolfSSL_CTX_free(ctx_c); + } +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_dtls.h b/tests/api/test_dtls.h index caff1a19b..2532e472e 100644 --- a/tests/api/test_dtls.h +++ b/tests/api/test_dtls.h @@ -41,4 +41,5 @@ int test_dtls_drop_client_ack(void); int test_dtls_bogus_finished_epoch_zero(void); int test_dtls_replay(void); int test_dtls_srtp(void); +int test_dtls_timeout(void); #endif /* TESTS_API_DTLS_H */ From f6be6c8b6dac470f14a1be8eca9b47b0c43f4142 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Mon, 6 Oct 2025 18:23:08 +0200 Subject: [PATCH 4/6] Add timeout assertions to DTLS test --- tests/api/test_dtls.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/api/test_dtls.c b/tests/api/test_dtls.c index 1287a2c8f..610f98690 100644 --- a/tests/api/test_dtls.c +++ b/tests/api/test_dtls.c @@ -1676,16 +1676,19 @@ int test_dtls_timeout(void) ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_get_current_timeout(ssl_c), 2); ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(wolfSSL_dtls_get_current_timeout(ssl_c), 1); #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13) /* will return 0 when not 1.3 */ if (wolfSSL_dtls13_use_quick_timeout(ssl_c)) ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_get_current_timeout(ssl_c), 2); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); wolfSSL_free(ssl_s); From 1237a5468f7fa0f50f856c11806b469fa52bbcd7 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Tue, 7 Oct 2025 09:20:46 -0600 Subject: [PATCH 5/6] coverity warnings on test case, CID 549270 and 549271 --- tests/api/test_pkcs7.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/api/test_pkcs7.c b/tests/api/test_pkcs7.c index ec4f7f333..08999c235 100644 --- a/tests/api/test_pkcs7.c +++ b/tests/api/test_pkcs7.c @@ -2163,10 +2163,10 @@ int test_wc_PKCS7_DecodeEnvelopedData_multiple_recipients(void) byte decodedData[8192]; ExpectTrue((f = XFOPEN(testFile, "rb")) != XBADFILE); - testDerBufferSz = XFREAD(testDerBuffer, 1, - sizeof(testDerBuffer), f); - ExpectIntNE(testDerBufferSz, 0); if (f != XBADFILE) { + testDerBufferSz = XFREAD(testDerBuffer, 1, + sizeof(testDerBuffer), f); + ExpectIntGT(testDerBufferSz, 0); XFCLOSE(f); f = XBADFILE; } @@ -2188,6 +2188,7 @@ int test_wc_PKCS7_DecodeEnvelopedData_multiple_recipients(void) ExpectIntGT(ret, 0); #endif wc_PKCS7_Free(pkcs7); + pkcs7 = NULL; } /* test with client cert recipient */ @@ -2207,6 +2208,7 @@ int test_wc_PKCS7_DecodeEnvelopedData_multiple_recipients(void) ExpectIntGT(ret, 0); #endif wc_PKCS7_Free(pkcs7); + pkcs7 = NULL; } /* test with ca cert recipient (which should fail) */ @@ -2222,6 +2224,7 @@ int test_wc_PKCS7_DecodeEnvelopedData_multiple_recipients(void) (word32)testDerBufferSz, decodedData, sizeof(decodedData)); ExpectIntLT(ret, 0); wc_PKCS7_Free(pkcs7); + pkcs7 = NULL; } return EXPECT_RESULT(); From 5069d977eda0ecd127c5dbcfeba55fec349f8b15 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Tue, 7 Oct 2025 12:44:47 +0200 Subject: [PATCH 6/6] testsuite_test: reset `ready` in between uses This should fix the constant intermittent failures in GH CI. --- testsuite/testsuite.c | 5 ++++- wolfssl/test.h | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 93986b6e5..fb65c4642 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -197,8 +197,11 @@ int testsuite_test(int argc, char** argv) #else simple_test(&server_args); #endif - if (server_args.return_code != 0) return server_args.return_code; + if (server_args.return_code != 0) + return server_args.return_code; #if !defined(NETOS) + FreeTcpReady(&ready); + InitTcpReady(&ready); /* Echo input wolfSSL client server test */ #ifdef HAVE_STACK_SIZE StackSizeCheck_launch(&server_args, echoserver_test, &serverThread, diff --git a/wolfssl/test.h b/wolfssl/test.h index b73e03437..0c1f208cf 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -1535,6 +1535,7 @@ static WC_INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port, int udp, int sctp, WOLFSSL* ssl) { SOCKADDR_IN_T addr; + fprintf(stderr, "connecting to %s:%d\n", ip, port); build_addr(&addr, ip, port, udp, sctp); if (udp) { wolfSSL_dtls_set_peer(ssl, &addr, sizeof(addr)); @@ -1542,8 +1543,10 @@ static WC_INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port, tcp_socket(sockfd, udp, sctp); if (!udp) { - if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) + if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) { + perror("connect"); err_sys_with_errno("tcp connect failed"); + } } } @@ -1555,7 +1558,7 @@ static WC_INLINE void udp_connect(SOCKET_T* sockfd, const char* ip, word16 port) SOCKADDR_IN_T addr; build_addr(&addr, ip, port, 1, 0); if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) - err_sys_with_errno("tcp connect failed"); + err_sys_with_errno("udp connect failed"); } @@ -1692,6 +1695,7 @@ static WC_INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr, } } #endif + fprintf(stderr, "listening on port %d\n", *port); }