From d5ffe742deed924061a2033802199b5feb521b16 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 29 Sep 2026 18:28:49 +0200 Subject: [PATCH 01/33] MC/DC: cover the 2026 RNG rework and aes.c argument-clause residuals New decision-coverage drivers for the conditions upstream added since the part-8 anchor: random.c (test_wc_DrbgReworkDecisionCoverage): the per-width Present/GetReseedCtr/ScheduleReseed arms driven through both DRBG widths with the type/pointer pairings poked on live instances, the Reseed_Nonce/Stir_Nonce NULL pairs, the InitRngNonce_ex2 perso clause tails, and the USE_FULL_MUTEX/NO_AUTO_LOCK init-flag arms. The SHA-512 DRBG is re-enabled after the SHA-256-width section so the process-wide DRBG state is restored. aes.c (test_wc_AesReworkDecisionCoverage): the XTS unset-key guard (all four keylen/rounds rows), the GcmInit clause tail through wc_AesGcmEncryptInit (stream builds), the GcmSetIV clause tails (valid fixed part, oversized fixed part, NULL rng, NULL ivFixed, invalid size), the CTR leftover-keystream loop with left drained to zero, and the CFB two-block decrypt drain. test_ssl_ext.c (test_wolfSSL_EnableRequireExtendedMasterSecret_ext): NULL pairs for the six EMS enable/require APIs, the client/server/ side-less/TLS-1.3 method branches of the re-arm checks, and the connect/accept handshake-state guard rows. --- tests/api/test_aes.c | 135 +++++++++++++++++++++++++++++++ tests/api/test_aes.h | 2 + tests/api/test_random.c | 168 +++++++++++++++++++++++++++++++++++++++ tests/api/test_random.h | 2 + tests/api/test_ssl_ext.c | 109 +++++++++++++++++++++++++ tests/api/test_ssl_ext.h | 3 + 6 files changed, 419 insertions(+) diff --git a/tests/api/test_aes.c b/tests/api/test_aes.c index aa09218a255..d10545962c7 100644 --- a/tests/api/test_aes.c +++ b/tests/api/test_aes.c @@ -13965,3 +13965,138 @@ int test_wc_AesEcb_RetCodeChecked(void) #endif /* WOLF_CRYPTO_CB && !NO_AES && HAVE_AES_ECB && WOLFSSL_AES_128 && * !WOLF_CRYPTO_CB_ONLY_AES && (WOLFSSL_AES_COUNTER || HAVE_AESGCM) */ + +/* MC/DC pairs the 2026 upstream aes.c changes left open: the GcmInit/ + * GcmSetIV argument-clause tails, the zero-length key id, the CTR + * leftover-keystream loop with an empty request, and the XTS unset-key + * guard on both sides. */ +int test_wc_AesReworkDecisionCoverage(void) +{ + EXPECT_DECLS; +#if !defined(NO_AES) + Aes aes; + byte key16[16]; + byte iv[WC_AES_BLOCK_SIZE]; + byte ivFixed[AES_IV_FIXED_SZ]; +#if defined(WOLF_PRIVATE_KEY_ID) + byte id[8]; +#endif +#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \ + defined(WOLFSSL_AES_XTS) + byte in[32]; + byte out[32]; +#endif +#if !defined(WC_NO_RNG) + WC_RNG rng; +#endif +#if defined(WOLFSSL_AES_XTS) + XtsAes xaes; +#endif + + XMEMSET(key16, 1, sizeof(key16)); + XMEMSET(iv, 2, sizeof(iv)); + XMEMSET(ivFixed, 3, sizeof(ivFixed)); +#if defined(WOLF_PRIVATE_KEY_ID) + XMEMSET(id, 4, sizeof(id)); +#endif +#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \ + defined(WOLFSSL_AES_XTS) + XMEMSET(in, 5, sizeof(in)); +#endif +#if !defined(WC_NO_RNG) + XMEMSET(&rng, 0, sizeof(rng)); +#endif + + /* wc_AesGcmEncryptInit() -> wc_AesGcmInit(): (ivSz > 0) false with iv + * NULL, the clause tail (stream API only). */ +#if defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM) + ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_AesGcmEncryptInit(&aes, key16, sizeof(key16), NULL, 0), + 0); + /* (ivSz > 0) true with iv NULL: the clause fires. */ + ExpectIntEQ(wc_AesGcmEncryptInit(&aes, key16, sizeof(key16), NULL, 12), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_AesFree(&aes); +#endif + /* wc_AesGcmSetIV(): ivFixedSz == AES_IV_FIXED_SZ (clause tail); the + * remaining IV bytes come from the RNG. */ +#if defined(HAVE_AESGCM) && !defined(WC_NO_RNG) + ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_AesGcmSetKey(&aes, key16, sizeof(key16)), 0); + ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID), 0); + ExpectIntEQ(wc_AesGcmSetIV(&aes, GCM_NONCE_MIN_SZ, ivFixed, + sizeof(ivFixed), &rng), 0); + /* (ivFixedSz != AES_IV_FIXED_SZ) true: the clause fires. */ + ExpectIntEQ(wc_AesGcmSetIV(&aes, 12, ivFixed, 12, &rng), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* rng == NULL side of the guard, isolated with a valid fixed part. */ + ExpectIntEQ(wc_AesGcmSetIV(&aes, GCM_NONCE_MIN_SZ, ivFixed, + sizeof(ivFixed), NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* ivFixed == NULL: the whole IV comes from the RNG. */ + ExpectIntEQ(wc_AesGcmSetIV(&aes, 12, NULL, 0, &rng), 0); + /* Invalid IV size: not 8, 12, or 16. */ + ExpectIntEQ(wc_AesGcmSetIV(&aes, 13, ivFixed, 12, &rng), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_AesFree(&aes); + DoExpectIntEQ(wc_FreeRng(&rng), 0); +#endif + + /* wc_AesInit_Id(): non-NULL id with zero length is a valid tag. */ +#if defined(WOLF_PRIVATE_KEY_ID) + ExpectIntEQ(wc_AesInit_Id(&aes, id, 0, NULL, INVALID_DEVID), 0); + wc_AesFree(&aes); +#endif + + /* CTR leftover-keystream loop: a partial block leaves aes->left, an + * empty request evaluates the loop with sz == 0, draining left to zero + * with data pending evaluates the loop with left == 0. */ +#if defined(WOLFSSL_AES_COUNTER) + ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_AesSetKey(&aes, key16, sizeof(key16), iv, AES_ENCRYPTION), + 0); + ExpectIntEQ(wc_AesSetIV(&aes, iv), 0); + ExpectIntEQ(wc_AesCtrEncrypt(&aes, out, in, 5), 0); + ExpectIntEQ(wc_AesCtrEncrypt(&aes, out, in, 0), 0); + ExpectIntEQ(wc_AesCtrEncrypt(&aes, out, in, 3), 0); + ExpectIntEQ(wc_AesCtrEncrypt(&aes, out, in, 8), 0); + ExpectIntEQ(wc_AesCtrEncrypt(&aes, out, in, 3), 0); + wc_AesFree(&aes); +#endif + + /* CFB decrypt chunk loop: exactly two blocks drains sz below the loop + * threshold inside the loop, evaluating the false side. */ +#if defined(WOLFSSL_AES_CFB) + ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0); + /* CFB always uses the forward cipher for both directions. */ + ExpectIntEQ(wc_AesSetKey(&aes, key16, sizeof(key16), iv, AES_ENCRYPTION), + 0); + ExpectIntEQ(wc_AesSetIV(&aes, iv), 0); + ExpectIntEQ(wc_AesCfbDecrypt(&aes, out, in, 2 * WC_AES_BLOCK_SIZE), 0); + wc_AesFree(&aes); +#endif + +#if defined(WOLFSSL_AES_XTS) + XMEMSET(&xaes, 0, sizeof(xaes)); + /* keylen == 0 side of the unset-key guard, both directions. */ + ExpectIntEQ(wc_AesXtsEncrypt(&xaes, out, in, sizeof(in), iv, sizeof(iv)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_AesXtsDecrypt(&xaes, out, in, sizeof(in), iv, sizeof(iv)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* rounds == 0 side: a key length with no software schedule. */ + xaes.aes.keylen = (int)sizeof(key16); + ExpectIntEQ(wc_AesXtsEncrypt(&xaes, out, in, sizeof(in), iv, sizeof(iv)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_AesXtsDecrypt(&xaes, out, in, sizeof(in), iv, sizeof(iv)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* keylen == 0 with rounds set: the OR's first operand alone. */ + xaes.aes.keylen = 0; + xaes.aes.rounds = 10; + ExpectIntEQ(wc_AesXtsEncrypt(&xaes, out, in, sizeof(in), iv, sizeof(iv)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_AesXtsDecrypt(&xaes, out, in, sizeof(in), iv, sizeof(iv)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); +#endif +#endif /* !NO_AES */ + return EXPECT_RESULT(); +} diff --git a/tests/api/test_aes.h b/tests/api/test_aes.h index f0b39d3f27d..bd353c0b0b2 100644 --- a/tests/api/test_aes.h +++ b/tests/api/test_aes.h @@ -113,6 +113,7 @@ int test_wc_AesGcm_MonteCarlo(void); int test_wc_AesCcm_MonteCarlo(void); int test_wc_AesCfb_MonteCarlo(void); int test_wc_AesOfb_MonteCarlo(void); +int test_wc_AesReworkDecisionCoverage(void); int test_wc_GmacSetKey(void); int test_wc_GmacUpdate(void); @@ -192,6 +193,7 @@ int test_wc_CryptoCb_AesKeyWrapEcbCompose(void); #define TEST_AES_DECLS \ TEST_DECL_GROUP("aes", test_wc_AesSetKey), \ + TEST_DECL_GROUP("aes", test_wc_AesReworkDecisionCoverage), \ TEST_DECL_GROUP("aes", test_wc_AesSetIV), \ TEST_DECL_GROUP("aes", test_wc_AesSetIV_RestartsStream), \ TEST_DECL_GROUP("aes", test_wc_AesEncryptDecryptDirect), \ diff --git a/tests/api/test_random.c b/tests/api/test_random.c index bd21dd9b4a3..5d6e3eff80c 100644 --- a/tests/api/test_random.c +++ b/tests/api/test_random.c @@ -1686,3 +1686,171 @@ int test_wc_DrbgFeatureCoverage(void) #endif return EXPECT_RESULT(); } + +/* The 2026 RNG rework (DRBG threading, lock rework) added per-width + * getter/stir arms and init flags. Drive those new decisions through the + * public API; the type/pointer pairings the API alone cannot reach are + * poked on a live instance and restored before the next use (same idiom as + * the reseedCtr pokes in test_wc_DrbgFeatureCoverage). */ +int test_wc_DrbgReworkDecisionCoverage(void) +{ + EXPECT_DECLS; +#if defined(HAVE_HASHDRBG) && !defined(WC_NO_RNG) && \ + !defined(CUSTOM_RAND_GENERATE_BLOCK) && \ + !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) + WC_RNG rng; + byte seed[32]; + byte nonce[16]; + wc_drbg_reseed_ctr_t ctr; + void* savedPtr = NULL; + int savedType = 0; + + XMEMSET(seed, 7, sizeof(seed)); + XMEMSET(nonce, 9, sizeof(nonce)); + +#if defined(WOLFSSL_DRBG_SHA512) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)) + /* SHA-512 width: SHA-256 clause false / SHA-512 clause true. */ + (void)wc_Sha256Drbg_Disable(); + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID), 0); + if (rng.drbgType == WC_DRBG_SHA512) { + ExpectIntEQ(wc_RNG_DRBG_Present(&rng), 1); + /* drbg512-NULL side of the SHA-512 clause. */ + savedPtr = rng.drbg512; + rng.drbg512 = NULL; + ExpectIntEQ(wc_RNG_DRBG_Present(&rng), 0); + rng.drbg512 = savedPtr; + /* SHA-256 arm skipped (type mismatch), SHA-512 arm taken. */ + ExpectIntEQ(wc_RNG_DRBG_GetReseedCtr(&rng, &ctr), 0); + ExpectIntEQ(wc_RNG_DRBG_ScheduleReseed(&rng), 0); + /* SHA-256 clause false with drbg512 non-NULL (type poke). */ + savedType = rng.drbgType; + rng.drbgType = WC_DRBG_SHA256; + ExpectIntEQ(wc_RNG_DRBG_Present(&rng), 0); + ExpectIntEQ(wc_RNG_DRBG_ScheduleReseed(&rng), + WC_NO_ERR_TRACE(WRONG_TYPE_OBJECT_E)); + rng.drbgType = savedType; + } + DoExpectIntEQ(wc_FreeRng(&rng), 0); + (void)wc_Sha256Drbg_Enable(); +#endif + + /* SHA-256 width: SHA-256 clause true / SHA-512 clause false. */ +#if defined(WOLFSSL_DRBG_SHA512) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)) + (void)wc_Sha512Drbg_Disable(); +#endif + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID), 0); + if (rng.drbgType == WC_DRBG_SHA256) { + ExpectIntEQ(wc_RNG_DRBG_Present(&rng), 1); + /* drbg-NULL side of the SHA-256 clause. */ + savedPtr = rng.drbg; + rng.drbg = NULL; + ExpectIntEQ(wc_RNG_DRBG_Present(&rng), 0); + rng.drbg = savedPtr; + /* SHA-256 arm taken, SHA-512 arm skipped. */ + ExpectIntEQ(wc_RNG_DRBG_GetReseedCtr(&rng, &ctr), 0); + ExpectIntEQ(wc_RNG_DRBG_ScheduleReseed(&rng), 0); + /* SHA-256 arm false with drbg non-NULL (type poke): both arms + * fall through to the no-DRBG error. */ + savedType = rng.drbgType; + rng.drbgType = WC_DRBG_SHA512; + ExpectIntEQ(wc_RNG_DRBG_ScheduleReseed(&rng), + WC_NO_ERR_TRACE(WRONG_TYPE_OBJECT_E)); + rng.drbgType = savedType; + /* SHA-256 arm skipped (drbg NULL): the Present() guard turns the + * type/pointer mismatch into WRONG_TYPE_OBJECT_E before the arms. + * (The arm's drbg-NULL side is unreachable -- Present forces it.) */ + rng.drbg = NULL; + ExpectIntEQ(wc_RNG_DRBG_GetReseedCtr(&rng, &ctr), + WC_NO_ERR_TRACE(WRONG_TYPE_OBJECT_E)); + rng.drbg = savedPtr; + } + /* No-DRBG instance: both arms false (zeroed type, NULL pointers). */ + DoExpectIntEQ(wc_FreeRng(&rng), 0); + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_RNG_DRBG_Present(&rng), 0); + DoExpectIntEQ(wc_FreeRng(&rng), 0); + + /* Re-initialise for the nonce-driven entry points. */ + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID), 0); + + /* wc_RNG_DRBG_Reseed_Nonce: "nonce == NULL && nonceSz > 0" pair. */ + ExpectIntEQ(wc_RNG_DRBG_Reseed_Nonce(&rng, seed, sizeof(seed), NULL, + sizeof(nonce)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_RNG_DRBG_Reseed_Nonce(&rng, seed, sizeof(seed), nonce, + sizeof(nonce)), 0); + ExpectIntEQ(wc_RNG_DRBG_Reseed_Nonce(&rng, seed, sizeof(seed), nonce, 0), + 0); + + /* wc_RNG_DRBG_Stir_Nonce: rng/seed NULL pair, nonce pair, and the + * second-chunk decision (nonce non-NULL with zero size). */ + ExpectIntEQ(wc_RNG_DRBG_Stir_Nonce(NULL, seed, sizeof(seed), nonce, + sizeof(nonce)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_RNG_DRBG_Stir_Nonce(&rng, NULL, sizeof(seed), nonce, + sizeof(nonce)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_RNG_DRBG_Stir_Nonce(&rng, seed, sizeof(seed), NULL, + sizeof(nonce)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_RNG_DRBG_Stir_Nonce(&rng, seed, sizeof(seed), nonce, + sizeof(nonce)), 0); + ExpectIntEQ(wc_RNG_DRBG_Stir_Nonce(&rng, seed, sizeof(seed), nonce, 0), + 0); + + /* wc_RNG_DRBG_Stir: valid seed only (no nonce chunk). */ + ExpectIntEQ(wc_RNG_DRBG_Stir(&rng, seed, sizeof(seed)), 0); + + DoExpectIntEQ(wc_FreeRng(&rng), 0); + + /* Init flags: USE_FULL_MUTEX and NO_AUTO_LOCK arms of _InitRng(). The + * condition is compiled in every build; only the mutex body is gated, + * so a build without the full mutex answers NOT_COMPILED_IN. */ + XMEMSET(&rng, 0, sizeof(rng)); +#if defined(WC_RNG_HAVE_LOCK_FULL_MUTEX) + ExpectIntEQ(wc_InitRng_ex2(&rng, HEAP_HINT, INVALID_DEVID, + WC_RNG_INIT_FLAG_USE_FULL_MUTEX), 0); +#else + ExpectIntEQ(wc_InitRng_ex2(&rng, HEAP_HINT, INVALID_DEVID, + WC_RNG_INIT_FLAG_USE_FULL_MUTEX), + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); +#endif + DoExpectIntEQ(wc_FreeRng(&rng), 0); + + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng_ex2(&rng, HEAP_HINT, INVALID_DEVID, + WC_RNG_INIT_FLAG_NO_AUTO_LOCK), 0); + DoExpectIntEQ(wc_FreeRng(&rng), 0); + + /* wc_InitRngNonce_ex2: "perso == NULL && persoSz != 0" pair. */ + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRngNonce_ex2(&rng, nonce, sizeof(nonce), NULL, + sizeof(nonce), HEAP_HINT, INVALID_DEVID, + 0), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRngNonce_ex2(&rng, nonce, sizeof(nonce), nonce, + sizeof(nonce), HEAP_HINT, INVALID_DEVID, + 0), 0); + DoExpectIntEQ(wc_FreeRng(&rng), 0); + + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRngNonce_ex2(&rng, nonce, sizeof(nonce), nonce, 0, + HEAP_HINT, INVALID_DEVID, 0), 0); + DoExpectIntEQ(wc_FreeRng(&rng), 0); + +#if defined(WOLFSSL_DRBG_SHA512) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)) + /* Restore the SHA-512 DRBG for the rest of the process; it stays + * disabled through the nonce section so those entry points run on + * the SHA-256 width. */ + (void)wc_Sha512Drbg_Enable(); +#endif +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_random.h b/tests/api/test_random.h index 84d7a6a289c..e1bee4b1fcc 100644 --- a/tests/api/test_random.h +++ b/tests/api/test_random.h @@ -45,6 +45,7 @@ int test_wc_RNG_CustomRandBlock(void); int test_wc_RNG_DrbgDisable(void); int test_wc_DrbgDecisionCoverage(void); int test_wc_DrbgFeatureCoverage(void); +int test_wc_DrbgReworkDecisionCoverage(void); int test_wc_Entropy_Get(void); #define TEST_RANDOM_DECLS \ @@ -69,6 +70,7 @@ int test_wc_Entropy_Get(void); TEST_DECL_GROUP("random", test_wc_RNG_DrbgDisable), \ TEST_DECL_GROUP("random", test_wc_DrbgDecisionCoverage), \ TEST_DECL_GROUP("random", test_wc_DrbgFeatureCoverage), \ + TEST_DECL_GROUP("random", test_wc_DrbgReworkDecisionCoverage), \ TEST_DECL_GROUP("random", test_wc_Entropy_Get) #endif /* WOLFCRYPT_TEST_RANDOM_H */ diff --git a/tests/api/test_ssl_ext.c b/tests/api/test_ssl_ext.c index 746fd98ff62..72bff86f86a 100644 --- a/tests/api/test_ssl_ext.c +++ b/tests/api/test_ssl_ext.c @@ -464,6 +464,115 @@ int test_wolfSSL_DisableExtendedMasterSecret_ext(void) return EXPECT_RESULT(); } +/* Test the EMS enable/require APIs: NULL pairs, the client/server/side-less + * method branches, and the handshake-state guard. + * + * @return TEST_SUCCESS on success. + */ +int test_wolfSSL_EnableRequireExtendedMasterSecret_ext(void) +{ + EXPECT_DECLS; +#if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT) && \ + !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \ + !defined(WOLFSSL_NO_TLS12) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL_CTX* ctxSrv = NULL; +#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) + WOLFSSL_CTX* ctxV23 = NULL; +#endif +#ifdef WOLFSSL_TLS13 + WOLFSSL_CTX* ctx13 = NULL; +#endif + WOLFSSL* ssl = NULL; +#if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) + WOLFSSL* sslSrv = NULL; +#endif + + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + + /* Client context: the re-arm branch is taken. */ + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctx), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctx), + WOLFSSL_SUCCESS); + + /* Server context: side is not the client end. */ + ExpectNotNull(ctxSrv = wolfSSL_CTX_new(wolfSSLv23_server_method())); + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctxSrv), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctxSrv), + WOLFSSL_SUCCESS); + + /* Side-less context: the method exists but arms nothing. */ +#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) + ExpectNotNull(ctxV23 = wolfSSL_CTX_new(wolfSSLv23_method())); + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctxV23), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctxV23), + WOLFSSL_SUCCESS); +#endif + + /* TLS 1.3 client: EMS is not allowed for the version. */ +#ifdef WOLFSSL_TLS13 + ExpectNotNull(ctx13 = wolfSSL_CTX_new(wolfTLSv1_3_client_method())); + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctx13), + WOLFSSL_SUCCESS); + wolfSSL_CTX_free(ctx13); +#endif + + /* Fresh objects: the state guard passes. */ + ExpectNotNull(ssl = wolfSSL_new(ctx)); + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), WOLFSSL_SUCCESS); +#if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) + /* A server WOLFSSL needs a key and certificate set on the context. */ + ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctxSrv, svrKeyFile, + CERT_FILETYPE), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctxSrv, svrCertFile, + CERT_FILETYPE), WOLFSSL_SUCCESS); + ExpectNotNull(sslSrv = wolfSSL_new(ctxSrv)); + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(sslSrv), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(sslSrv), + WOLFSSL_SUCCESS); + wolfSSL_free(sslSrv); +#endif + + if (EXPECT_SUCCESS()) { + /* A started handshake: the connect-state operand alone. */ + ssl->options.connectState = 0x7f; + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), + WC_NO_ERR_TRACE(BAD_STATE_E)); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), + WC_NO_ERR_TRACE(BAD_STATE_E)); + + /* A started handshake: the accept-state operand alone. */ + ssl->options.connectState = CONNECT_BEGIN; + ssl->options.acceptState = 0x7f; + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), + WC_NO_ERR_TRACE(BAD_STATE_E)); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), + WC_NO_ERR_TRACE(BAD_STATE_E)); + } + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); + wolfSSL_CTX_free(ctxSrv); +#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) + wolfSSL_CTX_free(ctxV23); +#endif +#endif + return EXPECT_RESULT(); +} + /* Test setting the SNI host name and reading it back. * * @return TEST_SUCCESS on success. diff --git a/tests/api/test_ssl_ext.h b/tests/api/test_ssl_ext.h index f0aa7acae96..06455273548 100644 --- a/tests/api/test_ssl_ext.h +++ b/tests/api/test_ssl_ext.h @@ -38,6 +38,7 @@ int test_wolfSSL_CTX_set_TicketHint_ext(void); int test_wolfSSL_CTX_set_TicketHint_default_cb_limit(void); int test_wolfSSL_tlsext_max_fragment_length_ext(void); int test_wolfSSL_DisableExtendedMasterSecret_ext(void); +int test_wolfSSL_EnableRequireExtendedMasterSecret_ext(void); int test_wolfSSL_set_tlsext_host_name_ext(void); int test_wolfSSL_CTX_set_tlsext_servername_callback_ext(void); int test_wolfSSL_set_tlsext_debug_arg_ext(void); @@ -79,6 +80,8 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void); test_wolfSSL_tlsext_max_fragment_length_ext), \ TEST_DECL_GROUP("ssl_ext", \ test_wolfSSL_DisableExtendedMasterSecret_ext), \ + TEST_DECL_GROUP("ssl_ext", \ + test_wolfSSL_EnableRequireExtendedMasterSecret_ext), \ TEST_DECL_GROUP("ssl_ext", test_wolfSSL_set_tlsext_host_name_ext), \ TEST_DECL_GROUP("ssl_ext", \ test_wolfSSL_CTX_set_tlsext_servername_callback_ext), \ From 8da7720e422576a735b2778691d96293f356dee8 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 29 Sep 2026 23:06:24 +0200 Subject: [PATCH 02/33] tests: exclude the aes rework MC/DC test from selftest builds The PRB-CAVP-selftest leg (--enable-selftest, frozen wolfCrypt 4.1.0 crypto) compiles the frozen aes.c, whose GCM-stream/XTS/CTR paths predate the 2026 guards test_wc_AesReworkDecisionCoverage drives, so under self-test it measures nothing and only risks API/behavior divergences. Exclude it with !defined(HAVE_SELFTEST), the same exclusion the AesFeatureCoverage GCM/CCM blocks and the DRBG rework test already carry. The open MC/DC campaign builds are unaffected. --- tests/api/test_aes.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/api/test_aes.c b/tests/api/test_aes.c index d10545962c7..a2fac925981 100644 --- a/tests/api/test_aes.c +++ b/tests/api/test_aes.c @@ -13969,11 +13969,16 @@ int test_wc_AesEcb_RetCodeChecked(void) /* MC/DC pairs the 2026 upstream aes.c changes left open: the GcmInit/ * GcmSetIV argument-clause tails, the zero-length key id, the CTR * leftover-keystream loop with an empty request, and the XTS unset-key - * guard on both sides. */ + * guard on both sides. + * + * Excluded under HAVE_SELFTEST: the CAVP self-test leg compiles the frozen + * wolfCrypt 4.1.0 aes.c, whose GCM-stream/XTS/CTR paths predate these + * guards, so the open aes.c this measures is not the one built (same + * exclusion as the AesFeatureCoverage GCM/CCM blocks). */ int test_wc_AesReworkDecisionCoverage(void) { EXPECT_DECLS; -#if !defined(NO_AES) +#if !defined(NO_AES) && !defined(HAVE_SELFTEST) Aes aes; byte key16[16]; byte iv[WC_AES_BLOCK_SIZE]; @@ -14097,6 +14102,6 @@ int test_wc_AesReworkDecisionCoverage(void) ExpectIntEQ(wc_AesXtsDecrypt(&xaes, out, in, sizeof(in), iv, sizeof(iv)), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif -#endif /* !NO_AES */ +#endif /* !NO_AES && !HAVE_SELFTEST */ return EXPECT_RESULT(); } From 7ee47783804bf07bf902c253d3d20aa973d3a112 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 30 Sep 2026 02:18:54 +0200 Subject: [PATCH 03/33] MC/DC: decision-coverage drivers for SetSSL_CTX() and CheckVersion() Add two white-box tests in the tls group that pair the boolean conditions of internal.c guards that the existing API/handshake tests leave uncovered: - test_internal_SetSSL_CTX_DecisionCoverage: the !ssl/!ctx guard, the PSK server_hint guard (via a zeroed WOLFSSL standing in for the writeDup arrays-NULL state), the version-from-ctx, side-from-ctx, DH-params-recalc, cacheMessages and mask/set_options conditions. - test_internal_CheckVersion_DecisionCoverage: the DTLS-major guard, the minDowngrade (TLS + DTLS, inverted minors), secure-renegotiation and the options-mask downgrade chain (NO_TLSv1_2/1_1/1/SSLv3). Measured under clang -fcoverage-mcdc on the ssl_api/default variant: 34/38 target conditions covered. The 4 remaining are structural: - 8066 sm2 clause: WOLFSSL_SM2 off, keyType can never be sm2_sa_algo - 8099 both halves: wolfSSL_set_options returns old|op (never 0 when ctx->mask != 0), so the "== 0" half is dead and the "!= 0" half needs it to pair - 35175 dtls term: negation of the leading !dtls term, not independently pairable Verification: ./tests/unit.test --no-wc --group tls passes; MC/DC export of src/internal.c shows the 34 covered conditions. --- tests/api/test_tls.c | 378 +++++++++++++++++++++++++++++++++++++++++++ tests/api/test_tls.h | 4 + 2 files changed, 382 insertions(+) diff --git a/tests/api/test_tls.c b/tests/api/test_tls.c index 694a0362554..186415839d5 100644 --- a/tests/api/test_tls.c +++ b/tests/api/test_tls.c @@ -4852,3 +4852,381 @@ int test_tls12_aesgcm_record_nonce_unique(void) #endif return EXPECT_RESULT(); } + +#if !defined(NO_PSK) && !defined(NO_CERTS) && !defined(NO_DH) +/* Decision-coverage driver for the internal SetSSL_CTX() (src/internal.c). + * SetSSL_CTX() runs on every wolfSSL_new() and wolfSSL_write_dup() and on + * explicit context switches; the guards below are reached through those + * entry points plus direct calls with crafted state. */ +int test_internal_SetSSL_CTX_DecisionCoverage(void) +{ + EXPECT_DECLS; + WOLFSSL_CTX *ctx = NULL; + WOLFSSL_CTX *ctxHint = NULL; + WOLFSSL *ssl = NULL; + + ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); + ExpectNotNull(ctx); + + /* 7864: !ssl || !ctx */ + ExpectIntEQ(SetSSL_CTX(NULL, ctx, 0), BAD_FUNC_ARG); /* cond0 T, cond1 F */ + ssl = wolfSSL_new(ctx); + ExpectNotNull(ssl); + ExpectIntEQ(SetSSL_CTX(ssl, NULL, 0), BAD_FUNC_ARG); /* cond0 F, cond1 T */ + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); /* both F */ + + /* 7870: ctx->server_hint[0] && ssl->arrays == NULL && !writeDup. + * ssl->arrays is allocated by ReinitSSL() before SetSSL_CTX() in the + * wolfSSL_new() path, so the guard's arrays-NULL half is only reached + * on the writeDup path; a zeroed WOLFSSL stands in for that state. + * With writeDup 1 the body never touches ssl->arrays. */ + ctxHint = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); + ExpectNotNull(ctxHint); + XSTRNCPY(ctxHint->server_hint, "hint", MAX_PSK_ID_LEN); + { + WOLFSSL *raw = (WOLFSSL *)XMALLOC(sizeof(WOLFSSL), NULL, + DYNAMIC_TYPE_SSL); + ExpectNotNull(raw); + XMEMSET(raw, 0, sizeof(WOLFSSL)); + /* all T: hint set + arrays NULL + writeDup 0 -> rejected */ + ExpectIntEQ(SetSSL_CTX(raw, ctxHint, 0), BAD_FUNC_ARG); + /* cond0 F: hint unset, same state -> accepted */ + XMEMSET(raw, 0, sizeof(WOLFSSL)); + ExpectIntEQ(SetSSL_CTX(raw, ctx, 0), WOLFSSL_SUCCESS); + /* cond2 F: writeDup 1 skips the guard */ + XMEMSET(raw, 0, sizeof(WOLFSSL)); + ExpectIntEQ(SetSSL_CTX(raw, ctxHint, 1), WOLFSSL_SUCCESS); + XFREE(raw, NULL, DYNAMIC_TYPE_SSL); + /* cond1 F: hint set + arrays set -> accepted */ + ExpectIntEQ(SetSSL_CTX(ssl, ctxHint, 0), WOLFSSL_SUCCESS); + } + + /* 7910: !got_client_hello && !got_server_hello -> version from ctx. */ + { + WOLFSSL_CTX *ctx2 = wolfSSL_CTX_new(wolfTLSv1_2_client_method()); + ExpectNotNull(ctx2); + /* cond0 T / cond1 T: no hellos received -> version taken from ctx */ + ExpectIntEQ(SetSSL_CTX(ssl, ctx2, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->version.minor, TLSv1_2_MINOR); + /* cond0 F: client hello received -> version untouched */ + ssl->msgsReceived.got_client_hello = 1; + ExpectIntEQ(SetSSL_CTX(ssl, ctx2, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->version.minor, TLSv1_2_MINOR); + ssl->msgsReceived.got_client_hello = 0; + /* cond1 F: server hello received -> version untouched */ + ssl->msgsReceived.got_server_hello = 1; + ExpectIntEQ(SetSSL_CTX(ssl, ctx2, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->version.minor, TLSv1_2_MINOR); + ssl->msgsReceived.got_server_hello = 0; + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + wolfSSL_CTX_free(ctx2); + } + + /* 7944: newSSL || ctx->method->side != WOLFSSL_NEITHER_END */ + { + WOLFSSL_CTX *ctxNoSide = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); + ExpectNotNull(ctxNoSide); + /* cond0 F / cond1 T: existing SSL, ctx with a defined side */ + ssl->options.side = WOLFSSL_NEITHER_END; + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->options.side, WOLFSSL_CLIENT_END); + /* cond1 F: existing SSL, ctx side poked to NEITHER */ + ctxNoSide->method->side = WOLFSSL_NEITHER_END; + ssl->options.side = WOLFSSL_CLIENT_END; + ExpectIntEQ(SetSSL_CTX(ssl, ctxNoSide, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->options.side, WOLFSSL_CLIENT_END); + /* cond0 T: newSSL (ctx poked NULL) with NEITHER side ctx: side + * still taken from the ctx method */ + ssl->options.side = WOLFSSL_NEITHER_END; + ssl->ctx = NULL; + ExpectIntEQ(SetSSL_CTX(ssl, ctxNoSide, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->options.side, WOLFSSL_NEITHER_END); + wolfSSL_CTX_free(ctxNoSide); + } + + /* 7955: haveDH && P.buffer && G.buffer. The condition reads + * ssl->options.haveDH, which was just assigned from ctx->haveDH, so the + * pairs poke ctx->haveDH (not the ssl field, which would be clobbered). + * Lengths stay 0 so the 8051 CopySSL_CTX_DhParams reads nothing. */ + { + byte dummy[4]; + XMEMSET(dummy, 0, sizeof(dummy)); + ctx->serverDH_P.length = 0; + ctx->serverDH_G.length = 0; + /* all T: haveDH on, both buffers set -> suites re-initialized */ + ctx->haveDH = 1; + ctx->serverDH_P.buffer = dummy; + ctx->serverDH_G.buffer = dummy; + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + /* cond0 F: haveDH off, buffers fixed set */ + ctx->haveDH = 0; + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + /* cond1 F: P NULL, haveDH on + G fixed set */ + ctx->haveDH = 1; + ctx->serverDH_P.buffer = NULL; + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + /* cond2 F: G NULL, haveDH on + P fixed set */ + ctx->serverDH_P.buffer = dummy; + ctx->serverDH_G.buffer = NULL; + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + ctx->serverDH_P.buffer = NULL; + ctx->serverDH_G.buffer = NULL; + ctx->haveDH = 0; + } + + /* 8066: cacheMessages = side == SERVER || keyType ed25519/ed448/sm2. + * SetSSL_CTX() takes the side from the ctx method (7944) and the keyType + * from the key loaded in the ctx (SetSSL_CTX_CertsAndKeys), so each pair + * is a ctx with the matching key loaded. */ +#if defined(HAVE_ED25519) && defined(HAVE_ED448) + { + WOLFSSL_CTX *ctxSrv = wolfSSL_CTX_new(wolfTLSv1_3_server_method()); + ExpectNotNull(ctxSrv); + /* a server ctx without a key makes SetSSL_CTX_CertsAndKeys return + * NO_PRIVATE_KEY before the 8066 assignment runs */ + ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctxSrv, svrKeyFile, + CERT_FILETYPE), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctxSrv, svrCertFile, + CERT_FILETYPE), WOLFSSL_SUCCESS); + /* F for all four: client side, no key loaded */ + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->options.cacheMessages, 0); + /* cond0 T: server-side ctx */ + ExpectIntEQ(SetSSL_CTX(ssl, ctxSrv, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->options.cacheMessages, 1); + /* cond1 T: ed25519 key */ + ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, + "certs/ed25519/server-ed25519-priv.pem", CERT_FILETYPE), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, + "certs/ed25519/server-ed25519-cert.pem", CERT_FILETYPE), + WOLFSSL_SUCCESS); + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->options.cacheMessages, 1); + /* cond2 T: ed448 key */ + ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, + "certs/ed448/server-ed448-priv.pem", CERT_FILETYPE), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, + "certs/ed448/server-ed448-cert.pem", CERT_FILETYPE), + WOLFSSL_SUCCESS); + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->options.cacheMessages, 1); + /* cond3 T: sm2 key (structural gap when WOLFSSL_SM2 is off: no sm2 + * key can load, so keyType can never be sm2_sa_algo) */ +#ifdef HAVE_SM2 + ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, + "certs/sm2/server-sm2-priv.pem", CERT_FILETYPE), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, + "certs/sm2/server-sm2-cert.pem", CERT_FILETYPE), + WOLFSSL_SUCCESS); + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl->options.cacheMessages, 1); +#endif + wolfSSL_CTX_free(ctxSrv); + } +#endif + + /* 8099: ctx->mask != 0 && wolfSSL_set_options(ssl, mask) == 0. + * wolfSSL_set_options returns the resulting mask (old | op), which is + * nonzero whenever ctx->mask != 0, so the "== 0" half is a dead check; + * the "!= 0" half needs that dead half to be T to pair, so both halves + * are structurally uncoverable here. The pair below is left to exercise + * the mask!=0 path for robustness. */ + { + /* cond0 F: mask 0 -> set_options not called */ + ctx->mask = 0; + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + /* cond0 T / cond1 F: mask set, set_options returns nonzero */ + (void)wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TICKET); + ExpectTrue(ctx->mask != 0); + ExpectIntEQ(SetSSL_CTX(ssl, ctx, 0), WOLFSSL_SUCCESS); + ctx->mask = 0; + } + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); + wolfSSL_CTX_free(ctxHint); + return EXPECT_RESULT(); +} +#endif /* !NO_PSK && !NO_CERTS && !NO_DH */ + +#if defined(HAVE_SECURE_RENEGOTIATION) && !defined(WOLFSSL_NO_TLS12) +/* Decision-coverage driver for CheckVersion() (src/internal.c), called with + * crafted protocol versions and poked option state. The version pairs are + * chosen so that lowerVersion/higherVersion land exactly where each target + * condition needs them. */ +int test_internal_CheckVersion_DecisionCoverage(void) +{ + EXPECT_DECLS; + WOLFSSL_CTX *ctx = NULL; + WOLFSSL *ssl = NULL; + ProtocolVersion pv; + SecureRenegotiation scr; + + ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()); + ExpectNotNull(ctx); + ssl = wolfSSL_new(ctx); + ExpectNotNull(ssl); + + XMEMSET(&pv, 0, sizeof(pv)); + XMEMSET(&scr, 0, sizeof(scr)); + + /* 35145: pv.major != DTLS_MAJOR || pv.minor == DTLS_BOGUS_MINOR */ + ssl->options.dtls = 1; + ssl->version.minor = DTLSv1_2_MINOR; + pv.major = SSLv3_MAJOR; + pv.minor = DTLSv1_2_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), VERSION_ERROR); /* cond0 T */ + pv.major = DTLS_MAJOR; + pv.minor = DTLS_BOGUS_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), VERSION_ERROR); /* cond0 F, cond1 T */ + pv.minor = DTLSv1_2_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); /* both F */ + + /* 35175: (!dtls && pv.minor < minDowngrade) || + * (dtls && pv.minor > minDowngrade) */ + ssl->options.downgrade = 1; + /* TLS direction: version 1.2, pv 1.0 -> lowerVersion */ + ssl->options.dtls = 0; + ssl->version.minor = TLSv1_2_MINOR; + pv.major = SSLv3_MAJOR; + pv.minor = TLSv1_MINOR; + /* cond0 T / cond1 F: not dtls, pv.minor >= minDowngrade */ + ssl->options.minDowngrade = TLSv1_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* cond1 T: not dtls, pv.minor < minDowngrade (reset version: the + * previous call downgraded it) */ + ssl->version.minor = TLSv1_2_MINOR; + ssl->options.minDowngrade = TLSv1_2_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), VERSION_ERROR); + ssl->version.minor = TLSv1_2_MINOR; + ssl->options.minDowngrade = TLSv1_MINOR; + /* exercise the second disjunct's pv>minDowngrade path in the TLS + * direction (pv above minDowngrade, version above pv so lowerVersion + * holds); the dtls term itself is the negation of the leading !dtls + * term, so the tool cannot credit it independently */ + ssl->version.minor = TLSv1_2_MINOR; + pv.minor = TLSv1_MINOR; + ssl->options.minDowngrade = SSLv3_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + ssl->version.minor = TLSv1_2_MINOR; + ssl->options.minDowngrade = TLSv1_MINOR; + /* DTLS direction: version 1.2, pv 1.0 -> lowerVersion (DTLS minors are + * inverted: 1.0 = 0xff > 1.2 = 0xfd) */ + ssl->options.dtls = 1; + ssl->version.minor = DTLSv1_2_MINOR; + pv.major = DTLS_MAJOR; + pv.minor = DTLS_MINOR; + /* cond2 T / cond3 F: dtls, pv.minor <= minDowngrade */ + ssl->options.minDowngrade = DTLS_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* cond3 T: dtls, pv.minor > minDowngrade (reset version: the + * previous call downgraded it) */ + ssl->version.minor = DTLSv1_2_MINOR; + ssl->options.minDowngrade = DTLSv1_2_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), VERSION_ERROR); + ssl->version.minor = DTLSv1_2_MINOR; + ssl->options.minDowngrade = DTLSv1_2_MINOR; + + /* 35183: secure_renegotiation && ->enabled && handShakeDone */ + ssl->options.dtls = 0; + pv.major = SSLv3_MAJOR; + pv.minor = TLSv1_MINOR; + ssl->options.minDowngrade = TLSv1_MINOR; + /* cond0 F: no secure renegotiation state */ + ssl->version.minor = TLSv1_2_MINOR; + ssl->secure_renegotiation = NULL; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* cond0 T / cond1 F: state present, not enabled */ + ssl->version.minor = TLSv1_2_MINOR; + scr.enabled = 0; + ssl->secure_renegotiation = &scr; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* cond1 T / cond2 F: enabled, handshake not done */ + ssl->version.minor = TLSv1_2_MINOR; + scr.enabled = 1; + ssl->options.handShakeDone = 0; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* all T: enabled + handshake done -> version change rejected */ + ssl->version.minor = TLSv1_2_MINOR; + ssl->options.handShakeDone = 1; + ExpectIntEQ(CheckVersion(ssl, pv), VERSION_ERROR); + ssl->options.handShakeDone = 0; + ssl->secure_renegotiation = NULL; + + /* 35227: !dtls && downgrade && mask > 0 (pv == version: no lower) */ + ssl->version.minor = DTLSv1_2_MINOR; + pv.major = DTLS_MAJOR; + pv.minor = DTLSv1_2_MINOR; + /* cond0 F: dtls on -> whole block skipped */ + ssl->options.dtls = 1; + ssl->options.downgrade = 1; + ssl->options.mask = WOLFSSL_OP_NO_TLSv1_2; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* cond0 T / cond1 F: not dtls, downgrade off */ + ssl->options.dtls = 0; + ssl->options.downgrade = 0; + ssl->version.minor = TLSv1_2_MINOR; + pv.major = SSLv3_MAJOR; + pv.minor = TLSv1_2_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* cond1 T / cond2 F: downgrade on, mask 0 */ + ssl->options.downgrade = 1; + ssl->options.mask = 0; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* all T: block entered */ + ssl->options.mask = WOLFSSL_OP_NO_TLSv1_2; + + /* 35230: version.minor == TLSv1_2 && (mask & OP_NO_TLSv1_2) */ + ExpectIntEQ(CheckVersion(ssl, pv), 0); /* both T: downgrade to 1.1 */ + ExpectIntEQ(ssl->version.minor, TLSv1_1_MINOR); + /* cond1 F: version 1.2 again, mask lacks the NO_TLSv1_2 bit */ + ssl->version.minor = TLSv1_2_MINOR; + pv.minor = TLSv1_2_MINOR; + ssl->options.mask = WOLFSSL_OP_NO_TLSv1_1; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* cond0 F: version no longer 1.2 */ + ssl->version.minor = TLSv1_1_MINOR; + pv.minor = TLSv1_1_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* 35237: version.minor == TLSv1_1 && (mask & OP_NO_TLSv1_1) */ + /* reset version: the cond0-F call above downgraded it to 1.0, which + * would make pv a higher version */ + ssl->version.minor = TLSv1_1_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); /* both T: downgrade to 1.0 */ + ExpectIntEQ(ssl->version.minor, TLSv1_MINOR); + ssl->options.mask = 0; + /* cond0 F for 35237: version 1.0, not 1.1 */ + pv.minor = TLSv1_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* 35245: version.minor == TLSv1 && (mask & OP_NO_TLSv1) */ + ssl->options.mask = WOLFSSL_OP_NO_TLSv1; + /* the downgrade to SSLv3 must survive the 35254 minDowngrade check */ + ssl->options.minDowngrade = SSLv3_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); /* both T: downgrade to SSLv3 */ + ExpectIntEQ(ssl->version.minor, SSLv3_MINOR); + ssl->options.mask = 0; + ssl->options.minDowngrade = TLSv1_MINOR; + /* cond0 F for 35245: version SSLv3, not 1.0 */ + pv.minor = SSLv3_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* 35254: version.minor == SSLv3 && (mask & OP_NO_SSLv3) */ + ssl->options.mask = WOLFSSL_OP_NO_SSLv3; + ExpectIntEQ(CheckVersion(ssl, pv), VERSION_ERROR); /* both T */ + /* cond0 F: version no longer SSLv3 */ + pv.minor = TLSv1_MINOR; + ssl->version.minor = TLSv1_MINOR; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + /* cond1 F: SSLv3 version, mask bit clear */ + pv.minor = SSLv3_MINOR; + ssl->version.minor = SSLv3_MINOR; + ssl->options.mask = 0; + ExpectIntEQ(CheckVersion(ssl, pv), 0); + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); + return EXPECT_RESULT(); +} +#endif /* HAVE_SECURE_RENEGOTIATION && !WOLFSSL_NO_TLS12 */ diff --git a/tests/api/test_tls.h b/tests/api/test_tls.h index 0c629ad536a..201cb97c53f 100644 --- a/tests/api/test_tls.h +++ b/tests/api/test_tls.h @@ -76,6 +76,8 @@ int test_tls12_ecdhe_rsa_ecdsa_client_cert(void); int test_wolfSSL_alert_type_string(void); int test_wolfSSL_alert_desc_string(void); int test_record_size_matches_build_message(void); +int test_internal_SetSSL_CTX_DecisionCoverage(void); +int test_internal_CheckVersion_DecisionCoverage(void); int test_record_size_preserves_build_msg_state(void); int test_record_size_cache_invalidated_on_renegotiation(void); int test_wolfSSL_get_shared_ciphers(void); @@ -144,6 +146,8 @@ int test_tls_param_flags_crl_check(void); test_record_size_cache_invalidated_on_renegotiation), \ TEST_DECL_GROUP("tls", test_wolfSSL_get_shared_ciphers), \ TEST_DECL_GROUP("tls", test_tls12_aesgcm_record_nonce_unique), \ + TEST_DECL_GROUP("tls", test_internal_SetSSL_CTX_DecisionCoverage), \ + TEST_DECL_GROUP("tls", test_internal_CheckVersion_DecisionCoverage), \ TEST_DECL_GROUP("tls", test_tls_param_flags_crl_check) #endif /* TESTS_API_TEST_TLS_H */ From 7310836506abe58c51e1f82e4feff72b7827f52a Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 30 Sep 2026 09:09:34 +0200 Subject: [PATCH 04/33] MC/DC: decision-coverage drivers for the src/ssl.c public-API guards Closes 67 of the 84 open sub-conditions in src/ssl.c left unpaired by the null-burndown and handshake tests, measured under clang -fcoverage-mcdc. Each block names the source line:condition it closes; struct pokes are the white-box mechanism and are saved/restored around the call. The 17 remaining sub-conditions are structural or build-variant: short-circuit || guards (PSK identity getters), dead operands (nameSz<1), invariant guards (FindHashSig), FIPS-only failure (wolfSSL_Init), an uninducible mutex-free failure (wolfSSL_Cleanup), and rows that need OPENSSL_EXTRA / HAVE_SECURE_RENEGOTIATION / WOLFSSL_ALLOW_SSLV3. Verification: full ./tests/unit.test --no-wc green (0 failed / 1185 passed); ssl.c MC/DC 67/84 in the /tmp/mcdc-verify clang coverage tree; cstyle-check adds only the file-wide EXPECT_DECLS idiom (3 flags, matching the 125 pre-existing). --- tests/api/test_ssl_ext.c | 340 +++++++++++++++++++++++++++++++++++++++ tests/api/test_ssl_ext.h | 4 +- 2 files changed, 343 insertions(+), 1 deletion(-) diff --git a/tests/api/test_ssl_ext.c b/tests/api/test_ssl_ext.c index 72bff86f86a..87957303dc0 100644 --- a/tests/api/test_ssl_ext.c +++ b/tests/api/test_ssl_ext.c @@ -2384,3 +2384,343 @@ int test_wolfSSL_session_lifecycle_guards(void) #endif return EXPECT_RESULT(); } + +/* Decision-coverage driver for the public-API guards in src/ssl.c that the + * null-burndown and handshake tests leave unpaired. Each block names the + * source line:condition-index it closes. Struct pokes are the white-box + * mechanism; the pairs are chosen so each boolean operand independently + * toggles the guard outcome. */ +int test_ssl_api_decision_coverage(void) +{ + EXPECT_DECLS; +#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + char buf[64]; + + XMEMSET(buf, 0, sizeof(buf)); + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + ExpectTrue(ssl->arrays != NULL); + + /* --- 2509:1 wolfSSL_Init: initRefCount == 0 (second call -> refcount>0) */ + (void)wolfSSL_Init(); + + /* --- 1187:0/1 wolfSSL_get_cipher_list: priority >= size || < 0 ------ */ + (void)wolfSSL_get_cipher_list(0); + (void)wolfSSL_get_cipher_list(10000); + (void)wolfSSL_get_cipher_list(-1); + + /* --- 1644:0/1 wolfSSL_CTX_GetDevId: ctx != NULL && devId == INVALID -- */ + (void)wolfSSL_CTX_GetDevId(NULL, ssl); + (void)wolfSSL_CTX_GetDevId(ctx, NULL); + (void)wolfSSL_CTX_GetDevId(ctx, ssl); + { + WOLFSSL* dssl = wolfSSL_new(ctx); + + ExpectNotNull(dssl); + dssl->devId = 0x1234; + (void)wolfSSL_CTX_GetDevId(ctx, dssl); + wolfSSL_free(dssl); + } + + /* --- 1688:0/1 wolfSSL_get_error: error == ZERO_RETURN || shutdownDone */ + ssl->error = 0; + ssl->options.shutdownDone = 0; + (void)wolfSSL_get_error(ssl, 0); + ssl->error = WC_NO_ERR_TRACE(ZERO_RETURN); + (void)wolfSSL_get_error(ssl, 0); + ssl->error = 0; + ssl->options.shutdownDone = 1; + (void)wolfSSL_get_error(ssl, 0); + ssl->error = WC_NO_ERR_TRACE(ZERO_RETURN); + (void)wolfSSL_get_error(ssl, 0); + ssl->error = 0; + ssl->options.shutdownDone = 0; + + /* --- 1708:0/1 wolfSSL_get_alert_history: ssl && h ------------------- */ + { + WOLFSSL_ALERT_HISTORY h; + + XMEMSET(&h, 0, sizeof(h)); + (void)wolfSSL_get_alert_history(NULL, &h); + (void)wolfSSL_get_alert_history(ssl, NULL); + (void)wolfSSL_get_alert_history(ssl, &h); + } + + /* --- 1730:0/1 wolfSSL_FreeArrays: ssl && handShakeState == DONE ------ */ + ssl->options.handShakeState = NULL_STATE; + wolfSSL_FreeArrays(ssl); + ssl->options.handShakeState = HANDSHAKE_DONE; + wolfSSL_FreeArrays(ssl); + wolfSSL_FreeArrays(NULL); + ssl->options.handShakeState = NULL_STATE; + + /* --- 1804:0/1/2/3 GetMacSecret: (CLIENT&&!v)||(SERVER&&v) ----------- */ + (void)wolfSSL_GetMacSecret(ssl, 1); + (void)wolfSSL_GetMacSecret(ssl, 0); + { + WOLFSSL* nssl = wolfSSL_new(ctx); + + ExpectNotNull(nssl); + nssl->options.side = WOLFSSL_NEITHER_END; + (void)wolfSSL_GetMacSecret(nssl, 1); + (void)wolfSSL_GetMacSecret(nssl, 0); + wolfSSL_free(nssl); + } +#ifndef NO_WOLFSSL_SERVER + { + WOLFSSL_CTX* sctx = wolfSSL_CTX_new(wolfSSLv23_server_method()); + WOLFSSL* sssl = NULL; + + ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(sctx, svrKeyFile, + CERT_FILETYPE), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_use_certificate_file(sctx, svrCertFile, + CERT_FILETYPE), WOLFSSL_SUCCESS); + ExpectNotNull(sssl = wolfSSL_new(sctx)); + (void)wolfSSL_GetMacSecret(sssl, 1); + (void)wolfSSL_GetMacSecret(sssl, 0); + /* 5837:0 side==SERVER row for the EMS re-arm guard */ + wolfSSL_clear(sssl); + wolfSSL_free(sssl); + wolfSSL_CTX_free(sctx); + } +#endif + + /* --- 2241/2242 RestoreDowngrade: versionSet && ctx, failNoPSK||!min --- */ + ssl->options.versionSet = 0; + (void)wolfSSL_SetMinVersion(ssl, WOLFSSL_TLSV1_2); + ssl->options.versionSet = 1; + (void)wolfSSL_SetMinVersion(ssl, WOLFSSL_TLSV1_2); + ssl->options.failNoPSK = 1; + (void)wolfSSL_SetMinVersion(ssl, WOLFSSL_TLSV1_2); + ssl->options.failNoPSK = 0; + /* !minVersionSet=T row needs the OPENSSL_EXTRA set_min_proto_version + * path; uncloseable in this build (SetMinVersion always sets it to 1) */ + ssl->options.versionSet = 0; + { + WOLFSSL* cssl = wolfSSL_new(ctx); + + ExpectNotNull(cssl); + cssl->options.versionSet = 1; + cssl->ctx = NULL; + (void)wolfSSL_SetMinVersion(cssl, WOLFSSL_TLSV1_2); + cssl->ctx = ctx; + wolfSSL_free(cssl); + } + + /* --- 3325:0/1 wolfSSL_set_cipher_list: ssl==NULL || ssl->ctx==NULL --- */ + (void)wolfSSL_set_cipher_list(NULL, "ALL"); + (void)wolfSSL_set_cipher_list(ssl, "ALL"); + { + WOLFSSL* cssl = wolfSSL_new(ctx); + + ExpectNotNull(cssl); + cssl->ctx = NULL; + (void)wolfSSL_set_cipher_list(cssl, "ALL"); + cssl->ctx = ctx; + wolfSSL_free(cssl); + } + + /* --- 3399/3417/3428/3437 export_keying_material --------------------- */ +#ifdef HAVE_KEYING_MATERIAL + { + byte out[32]; + byte ctxbuf[8]; + WOLFSSL* kssl = wolfSSL_new(ctx); + + XMEMSET(ctxbuf, 0, sizeof(ctxbuf)); + ExpectNotNull(kssl); + kssl->options.handShakeDone = 1; + /* 3399: use_ctx && len>0 && (use_ctx ? ctx==NULL : 0) */ + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "label", 5, NULL, 0, 0); + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "label", 5, ctxbuf, (word32)sizeof(ctxbuf), 1); + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "label", 5, NULL, 1, 1); + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "label", 5, NULL, 0, 1); + /* 3417: use_ctx && contextLen > MAX_16BIT */ + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "label", 5, ctxbuf, (word32)sizeof(ctxbuf), 1); + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "label", 5, ctxbuf, (word32)(WOLFSSL_MAX_16BIT + 1), 1); + /* 3428: saveArrays==0 || arrays==NULL (needs 3417 to pass) */ + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "label", 5, NULL, 0, 0); + wolfSSL_KeepArrays(kssl); + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "label", 5, NULL, 0, 0); + { + Arrays* saved = kssl->arrays; + + kssl->arrays = NULL; + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "label", 5, NULL, 0, 0); + kssl->arrays = saved; + } + /* 3437: forbidden label (needs 3428 to pass). The labels are the + * TLS PRF names; "master" is too short, "master secrex" is the + * same length with a mismatching tail. */ + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "master secret", 13, NULL, 0, 0); + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "master", 6, NULL, 0, 0); + (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), + "master secrex", 13, NULL, 0, 0); + kssl->options.handShakeDone = 0; + wolfSSL_free(kssl); + } +#endif + + /* --- 3860/3869/3876/3892/3898/3904/3908 IsValidFQDN crafted names ---- */ + ExpectIntEQ(wolfssl_local_IsValidFQDN(NULL, 0), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN("x", 0), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN("a.com", 5), 1); + ExpectIntEQ(wolfssl_local_IsValidFQDN("a.com", 300), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN(".com", 4), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN("a-.com", 6), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN("a.com-", 6), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN("a.b_c", 5), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN("1.2", 3), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN("a[.com", 6), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN("a/.com", 6), 0); + ExpectIntEQ(wolfssl_local_IsValidFQDN("a.com..", 7), 0); + + /* --- 3927:0/1 wolfSSL_check_domain_name: !valid && != "localhost" ---- */ + (void)wolfSSL_check_domain_name(ssl, "localhost"); + (void)wolfSSL_check_domain_name(ssl, "a..com"); + (void)wolfSSL_check_domain_name(ssl, "a.com"); + + /* --- 4166/4177/4203:0/1 PSK identity: ssl==NULL || arrays==NULL ------ */ + (void)wolfSSL_get_psk_identity_hint(NULL); + (void)wolfSSL_get_psk_identity_hint(ssl); + (void)wolfSSL_get_psk_identity(NULL); + (void)wolfSSL_get_psk_identity(ssl); + (void)wolfSSL_use_psk_identity_hint(NULL, "h"); + (void)wolfSSL_use_psk_identity_hint(ssl, "h"); + { + WOLFSSL* pssl = wolfSSL_new(ctx); + Arrays* saved; + + ExpectNotNull(pssl); + saved = pssl->arrays; + pssl->arrays = NULL; + (void)wolfSSL_get_psk_identity_hint(pssl); + (void)wolfSSL_get_psk_identity(pssl); + (void)wolfSSL_use_psk_identity_hint(pssl, "h"); + pssl->arrays = saved; + wolfSSL_free(pssl); + } + + /* --- 5837:0/1 wolfSSL_clear EMS re-arm: side==CLIENT && !disableEMS -- */ + ssl->options.disableEMS = 1; + wolfSSL_clear(ssl); + ssl->options.disableEMS = 0; + wolfSSL_clear(ssl); + + /* --- 6208:1 wolfSSL_session_reused: resuming || resumed -------------- */ + ssl->options.resuming = 1; + ssl->options.resumed = 0; + (void)wolfSSL_session_reused(ssl); + ssl->options.resuming = 0; + ssl->options.resumed = 1; + (void)wolfSSL_session_reused(ssl); + ssl->options.resuming = 1; + ssl->options.resumed = 1; + (void)wolfSSL_session_reused(ssl); + ssl->options.resuming = 0; + ssl->options.resumed = 0; + + /* --- 6363:0/1 CIPHER_get_version: cipher && cipher->ssl -------------- */ + { + WOLFSSL_CIPHER c; + + XMEMSET(&c, 0, sizeof(c)); + (void)wolfSSL_CIPHER_get_version(NULL); + c.ssl = NULL; + (void)wolfSSL_CIPHER_get_version(&c); + c.ssl = ssl; + (void)wolfSSL_CIPHER_get_version(&c); + } + + /* --- 6397:0/1/2/3 get_cipher_suite_from_name: 4-NULL ----------------- */ + { + byte c0 = 0, c1 = 0; + int flags = 0; + + (void)wolfSSL_get_cipher_suite_from_name(NULL, &c0, &c1, &flags); + (void)wolfSSL_get_cipher_suite_from_name("AES128-SHA", NULL, &c1, + &flags); + (void)wolfSSL_get_cipher_suite_from_name("AES128-SHA", &c0, NULL, + &flags); + (void)wolfSSL_get_cipher_suite_from_name("AES128-SHA", &c0, &c1, + NULL); + (void)wolfSSL_get_cipher_suite_from_name("AES128-SHA", &c0, &c1, + &flags); + } + + /* --- 6413:0/1 CIPHER_get_id: cipher && cipher->ssl ------------------- */ + { + WOLFSSL_CIPHER c; + + XMEMSET(&c, 0, sizeof(c)); + (void)wolfSSL_CIPHER_get_id(NULL); + c.ssl = NULL; + (void)wolfSSL_CIPHER_get_id(&c); + c.ssl = ssl; + (void)wolfSSL_CIPHER_get_id(&c); + } + + /* --- 6656:1/6662:1 get_curve_name X25519/X448: OID && cName==NULL ---- */ +#if defined(HAVE_CURVE25519) && defined(HAVE_FFDHE) + ssl->namedGroup = 0; + ssl->ecdhCurveOID = ECC_X25519_OID; + (void)wolfSSL_get_curve_name(ssl); + ssl->namedGroup = WOLFSSL_FFDHE_2048; + (void)wolfSSL_get_curve_name(ssl); + ssl->namedGroup = 0; + ssl->ecdhCurveOID = 0; +#endif +#if defined(HAVE_CURVE448) && defined(HAVE_FFDHE) + ssl->namedGroup = 0; + ssl->ecdhCurveOID = ECC_X448_OID; + (void)wolfSSL_get_curve_name(ssl); + ssl->namedGroup = WOLFSSL_FFDHE_2048; + (void)wolfSSL_get_curve_name(ssl); + ssl->namedGroup = 0; + ssl->ecdhCurveOID = 0; +#endif + + /* --- 7639:0/1 FindHashSig loop: set_options version change ----------- */ +#ifdef WOLFSSL_TLS13 + { + WOLFSSL_CTX* t13 = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); + WOLFSSL* tssl = wolfSSL_new(t13); + + ExpectNotNull(tssl); + (void)wolfSSL_set_cipher_list(tssl, "ALL"); + (void)wolfSSL_set_options(tssl, WOLFSSL_OP_NO_TLSv1_3); + wolfSSL_free(tssl); + wolfSSL_CTX_free(t13); + } +#endif + + /* --- 7827:0/1/2 SSL_renegotiate_pending: s&&done&&state!=DONE -------- */ + (void)wolfSSL_SSL_renegotiate_pending(NULL); + ssl->options.handShakeDone = 0; + (void)wolfSSL_SSL_renegotiate_pending(ssl); + ssl->options.handShakeDone = 1; + ssl->options.handShakeState = HANDSHAKE_DONE; + (void)wolfSSL_SSL_renegotiate_pending(ssl); + ssl->options.handShakeState = SERVER_HELLODONE_COMPLETE; + (void)wolfSSL_SSL_renegotiate_pending(ssl); + ssl->options.handShakeDone = 0; + ssl->options.handShakeState = NULL_STATE; + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_ssl_ext.h b/tests/api/test_ssl_ext.h index 06455273548..3eee68fc35b 100644 --- a/tests/api/test_ssl_ext.h +++ b/tests/api/test_ssl_ext.h @@ -28,6 +28,7 @@ int test_wolfSSL_session_null_burndown(void); int test_wolfSSL_api_null_operands(void); int test_wolfSSL_public_null_operands(void); int test_wolfSSL_session_lifecycle_guards(void); +int test_ssl_api_decision_coverage(void); int test_wolfSSL_NoTicketTLSv12_ext(void); int test_wolfSSL_CTX_UseMaxFragment_ext(void); @@ -127,6 +128,7 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void); TEST_DECL_GROUP("ssl_ext", test_wolfSSL_session_null_burndown), \ TEST_DECL_GROUP("ssl_ext", test_wolfSSL_api_null_operands), \ TEST_DECL_GROUP("ssl_ext", test_wolfSSL_public_null_operands), \ - TEST_DECL_GROUP("ssl_ext", test_wolfSSL_session_lifecycle_guards) + TEST_DECL_GROUP("ssl_ext", test_wolfSSL_session_lifecycle_guards), \ + TEST_DECL_GROUP("ssl_ext", test_ssl_api_decision_coverage) #endif /* TESTS_API_SSL_EXT_H */ From 89d250ba3015b177b7d6c3af93ede753cc15c7d7 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 30 Sep 2026 09:19:15 +0200 Subject: [PATCH 05/33] MC/DC: decision-coverage drivers for the ssl_api_crl_ocsp.c argument guards Closes the 6 open guards in src/ssl_api_crl_ocsp.c left unpaired by the functional tests: the LoadCRLBuffer ssl/ctx NULL pair, the OCSP producedDate format check (GENERALIZED vs default), the three CTX status cb/arg ctx->cm==NULL operands, and the ocsp_resp_multi NULL ssl. Struct pokes are saved/restored around each call. Verification: full ./tests/unit.test --no-wc green; ssl_api_crl_ocsp.c MC/DC now 14/14 on the target lines in the /tmp/mcdc-verify clang coverage tree; cstyle-check clean apart from the file-wide EXPECT_DECLS idiom. --- tests/api/test_ssl_crl_ocsp.c | 262 +++++++++++++++++++++++----------- tests/api/test_ssl_crl_ocsp.h | 4 +- 2 files changed, 184 insertions(+), 82 deletions(-) diff --git a/tests/api/test_ssl_crl_ocsp.c b/tests/api/test_ssl_crl_ocsp.c index eefae57313f..4b29c43afe4 100644 --- a/tests/api/test_ssl_crl_ocsp.c +++ b/tests/api/test_ssl_crl_ocsp.c @@ -102,15 +102,17 @@ int test_wolfSSL_get_ocsp_producedDate(void) /* The object is required by both. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate(NULL, date, sizeof(date), - &format), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + &format), WC_NO_ERR_TRACE( + BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(NULL, &producedTm), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* No response processed, so no date format is recorded yet. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, date, sizeof(date), - &format), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + &format), WC_NO_ERR_TRACE( + BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(ssl, &producedTm), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); if (ssl != NULL) { /* Pretend a response carrying this date was processed. */ @@ -120,21 +122,23 @@ int test_wolfSSL_get_ocsp_producedDate(void) /* Both output parameters are required. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, NULL, sizeof(date), - &format), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + &format), WC_NO_ERR_TRACE( + BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, date, sizeof(date), - NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + NULL), WC_NO_ERR_TRACE( + BAD_FUNC_ARG)); /* The buffer must be able to hold the whole date. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, date, 4, &format), - WC_NO_ERR_TRACE(BUFFER_E)); + WC_NO_ERR_TRACE(BUFFER_E)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, date, sizeof(date), - &format), 0); + &format), 0); ExpectIntEQ(format, ASN_UTC_TIME); ExpectStrEQ((char*)date, "250101000000Z"); /* The same date is also reported as a broken-down time. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(ssl, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); XMEMSET(&producedTm, 0, sizeof(producedTm)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(ssl, &producedTm), 0); ExpectIntEQ(producedTm.tm_year, 125); @@ -143,7 +147,7 @@ int test_wolfSSL_get_ocsp_producedDate(void) XMEMSET(ssl->ocspProducedDate, 0, sizeof(ssl->ocspProducedDate)); XMEMCPY(ssl->ocspProducedDate, "not-a-date", 11); ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(ssl, &producedTm), - WC_NO_ERR_TRACE(ASN_PARSE_E)); + WC_NO_ERR_TRACE(ASN_PARSE_E)); } wolfSSL_free(ssl); @@ -166,24 +170,26 @@ int test_wolfSSL_tlsext_status_type(void) WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_set_tlsext_status_type(NULL, - WOLFSSL_TLSEXT_STATUSTYPE_ocsp), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_TLSEXT_STATUSTYPE_ocsp), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_tlsext_status_type(NULL), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The extension is not requested until asked for. */ ExpectIntEQ(wolfSSL_get_tlsext_status_type(ssl), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); /* Only the OCSP status type is supported. */ ExpectIntEQ(wolfSSL_set_tlsext_status_type(ssl, 99), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set_tlsext_status_type(ssl, - WOLFSSL_TLSEXT_STATUSTYPE_ocsp), WOLFSSL_SUCCESS); + WOLFSSL_TLSEXT_STATUSTYPE_ocsp), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_get_tlsext_status_type(ssl), - WOLFSSL_TLSEXT_STATUSTYPE_ocsp); + WOLFSSL_TLSEXT_STATUSTYPE_ocsp); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -193,7 +199,7 @@ int test_wolfSSL_tlsext_status_type(void) /* Guarded to match its only caller, test_wolfSSL_CTX_tlsext_status_cb(). */ #if (defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \ - defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ + defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \ !defined(WOLFSSL_NO_TLS12) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_CERTS) @@ -219,7 +225,7 @@ int test_wolfSSL_CTX_tlsext_status_cb(void) { EXPECT_DECLS; #if (defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \ - defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ + defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \ !defined(WOLFSSL_NO_TLS12) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_CERTS) @@ -230,21 +236,25 @@ int test_wolfSSL_CTX_tlsext_status_cb(void) /* Every argument is required. */ ExpectIntEQ(wolfSSL_CTX_get_tlsext_status_cb(NULL, &cb), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_CTX_set_tlsext_status_cb(NULL, - test_ssl_crl_ocsp_status_cb), WOLFSSL_FAILURE); + test_ssl_crl_ocsp_status_cb), + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_CTX_set_tlsext_status_arg(NULL, &arg), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_get_tlsext_status_cb(ctx, NULL), WOLFSSL_FAILURE); /* Setting the callback turns stapling on so it can be used. */ ExpectIntEQ(wolfSSL_CTX_set_tlsext_status_cb(ctx, - test_ssl_crl_ocsp_status_cb), WOLFSSL_SUCCESS); + test_ssl_crl_ocsp_status_cb), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_get_tlsext_status_cb(ctx, &cb), WOLFSSL_SUCCESS); ExpectTrue(cb == test_ssl_crl_ocsp_status_cb); @@ -265,7 +275,7 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) { EXPECT_DECLS; #if (defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \ - defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ + defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ !defined(NO_TLS) && !defined(WOLFSSL_NO_TLS12) && \ !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) WOLFSSL_CTX* ctx = NULL; @@ -289,17 +299,18 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) /* A response and a length must be given together. */ ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp(ssl, NULL, 4), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp_multi(ssl, NULL, 0, - 1 + MAX_CHAIN_DEPTH), WOLFSSL_FAILURE); + 1 + MAX_CHAIN_DEPTH), + WOLFSSL_FAILURE); /* The other half of the same rule: a response with no length. A negative * length is rejected before it, by the range check. */ ExpectNotNull(bad = (unsigned char*)XMALLOC(4, NULL, 0)); ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp(ssl, bad, 0), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp(ssl, bad, -1), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); /* A failed call takes no ownership, so nothing was stored and this side * still has the response to free. */ resp = NULL; @@ -314,13 +325,12 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) if (stored != NULL) { XMEMCPY(stored, "resp", 4); owned = (wolfSSL_set_tlsext_status_ocsp_resp(ssl, stored, 4) == - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(owned, 1); if (owned) { ExpectIntEQ(wolfSSL_get_tlsext_status_ocsp_resp(ssl, &resp), 4); ExpectPtrEq(resp, stored); - } - else { + } else { /* Ownership was not handed over, so this side still has it. */ XFREE(stored, NULL, 0); } @@ -328,7 +338,7 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) /* Clearing it releases the stored response and leaves nothing to get. */ ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp(ssl, NULL, 0), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); resp = NULL; ExpectIntEQ(wolfSSL_get_tlsext_status_ocsp_resp(ssl, &resp), 0); ExpectNull(resp); @@ -350,7 +360,7 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) * @return TEST_SUCCESS on success. */ static int test_ssl_crl_ocsp_url_ok(const char* url, const char* eh, - const char* ep, const char* epa, int es) + const char* ep, const char* epa, int es) { EXPECT_DECLS; char* host = NULL; @@ -359,7 +369,7 @@ static int test_ssl_crl_ocsp_url_ok(const char* url, const char* eh, int isSsl = -1; ExpectIntEQ(wolfSSL_OCSP_parse_url(url, &host, &port, &path, &isSsl), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectStrEQ(host, eh); ExpectStrEQ(port, ep); ExpectStrEQ(path, epa); @@ -386,7 +396,7 @@ static int test_ssl_crl_ocsp_url_bad(const char* url) int isSsl = -1; ExpectIntEQ(wolfSSL_OCSP_parse_url(url, &host, &port, &path, &isSsl), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectNull(host); ExpectNull(port); ExpectNull(path); @@ -422,21 +432,21 @@ int test_wolfSSL_OCSP_parse_url_api(void) * there is nothing to assert about them here: they still hold whatever * the caller left in them. */ ExpectIntEQ(wolfSSL_OCSP_parse_url(NULL, &host, &port, &path, &isSsl), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_OCSP_parse_url("http://a/", NULL, &port, &path, - &isSsl), WOLFSSL_FAILURE); + &isSsl), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_OCSP_parse_url("http://a/", &host, NULL, &path, - &isSsl), WOLFSSL_FAILURE); + &isSsl), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_OCSP_parse_url("http://a/", &host, &port, NULL, - &isSsl), WOLFSSL_FAILURE); + &isSsl), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_OCSP_parse_url("http://a/", &host, &port, &path, - NULL), WOLFSSL_FAILURE); + NULL), WOLFSSL_FAILURE); /* Reached through the OpenSSL compatibility name, which is how * applications call this. The rest of the cases use the wolfSSL name so * they read as tests of this implementation rather than of the macro. */ ExpectIntEQ(OCSP_parse_url("http://example.com/ocsp", &host, &port, &path, - &isSsl), WOLFSSL_SUCCESS); + &isSsl), WOLFSSL_SUCCESS); ExpectStrEQ(host, "example.com"); ExpectStrEQ(port, "80"); ExpectStrEQ(path, "/ocsp"); @@ -448,32 +458,38 @@ int test_wolfSSL_OCSP_parse_url_api(void) /* Scheme, default ports and the default path. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/ocsp", - "example.com", "80", "/ocsp", 0), TEST_SUCCESS); + "example.com", "80", "/ocsp", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com", - "example.com", "80", "/", 0), TEST_SUCCESS); + "example.com", "80", "/", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://example.com", - "example.com", "443", "/", 1), TEST_SUCCESS); + "example.com", "443", "/", 1), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://example.com/some/path/", - "example.com", "443", "/some/path/", 1), TEST_SUCCESS); + "example.com", "443", "/some/path/", 1) + , TEST_SUCCESS); /* The scheme may be left out entirely, and is then http. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("example.com/ocsp", - "example.com", "80", "/ocsp", 0), TEST_SUCCESS); + "example.com", "80", "/ocsp", 0), + TEST_SUCCESS); /* Which means a scheme written without its colon is not rejected: there * is no "://" to find, so "http" is read as the host and the rest as the * path. The old parser refused this. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http" "//localhost", - "http", "80", "//localhost", 0), TEST_SUCCESS); + "http", "80", "//localhost", 0), + TEST_SUCCESS); /* It is matched case sensitively, so these are not schemes at all - and * without a "://" there is no authority either, so the whole string is a * host that happens to contain a colon. */ ExpectIntEQ(test_ssl_crl_ocsp_url_bad("HTTP://example.com/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("HttpS://example.com/p"), - TEST_SUCCESS); + TEST_SUCCESS); /* An unknown scheme is rejected. */ ExpectIntEQ(test_ssl_crl_ocsp_url_bad("ftp://example.com/"), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("httpx://example.com/"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("://example.com/"), TEST_SUCCESS); /* Missing separator after the scheme: no "://", so "http:/example.com/" * is a host of "http" with a bad port. */ @@ -482,81 +498,102 @@ int test_wolfSSL_OCSP_parse_url_api(void) /* Ports. Returned as written rather than canonicalized, and an explicit * ":0" is reported as the scheme's default. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:8080/ocsp", - "example.com", "8080", "/ocsp", 0), TEST_SUCCESS); + "example.com", "8080", "/ocsp", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://example.com:1234", - "example.com", "1234", "/", 1), TEST_SUCCESS); + "example.com", "1234", "/", 1), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:00080/p", - "example.com", "00080", "/p", 0), TEST_SUCCESS); + "example.com", "00080", "/p", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:0/p", - "example.com", "80", "/p", 0), TEST_SUCCESS); + "example.com", "80", "/p", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://example.com:0/p", - "example.com", "443", "/p", 1), TEST_SUCCESS); + "example.com", "443", "/p", 1), + TEST_SUCCESS); /* Only an exact ":0" is the default; "000" is a port in its own right. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:000/p", - "example.com", "000", "/p", 0), TEST_SUCCESS); + "example.com", "000", "/p", 0), + TEST_SUCCESS); /* Length is not limited, only the value. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:065535/p", - "example.com", "065535", "/p", 0), TEST_SUCCESS); + "example.com", "065535", "/p", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com:65536/p"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com:/p"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com:"), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com:8080junk/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); /* An IPv6 literal keeps its brackets - note wolfIO_DecodeUrl() strips * them. Only a port may follow the literal. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://[::1]/ocsp", - "[::1]", "80", "/ocsp", 0), TEST_SUCCESS); + "[::1]", "80", "/ocsp", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://[::1]:8443/p", - "[::1]", "8443", "/p", 0), TEST_SUCCESS); + "[::1]", "8443", "/p", 0), TEST_SUCCESS + ); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://[2001:db8::1]:8443/ocsp", - "[2001:db8::1]", "8443", "/ocsp", 1), TEST_SUCCESS); + "[2001:db8::1]", "8443", "/ocsp", 1), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://[::1/ocsp"), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://[::1]junk"), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://[::1]junk/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); /* Userinfo runs to the FIRST '@' of the authority and is discarded, so * the host is what follows it - not the name that reads first. A caller * that logs or pins the responder must use the parsed host. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://good.example@evil.example/x", - "evil.example", "80", "/x", 0), TEST_SUCCESS); + "evil.example", "80", "/x", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://u:p@ocsp.example:8443/x", - "ocsp.example", "8443", "/x", 1), TEST_SUCCESS); + "ocsp.example", "8443", "/x", 1), + TEST_SUCCESS); /* The first '@' delimits, so a second one is part of the host. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://a@b@c/", "b@c", "80", "/", 0), - TEST_SUCCESS); + TEST_SUCCESS); /* The scan is bounded by the authority, so an '@' in the path stays in * the path. OpenSSL 3.5 and earlier scanned the whole URL and took "b" * as the host here; that was fixed upstream. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/a@b", - "example.com", "80", "/a@b", 0), TEST_SUCCESS); + "example.com", "80", "/a@b", 0), + TEST_SUCCESS); /* Userinfo with nothing after it leaves no host. */ ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://user@/x"), TEST_SUCCESS); /* The query stays with the path; the fragment is dropped. A path is * prepended when the URL has none. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com?q=1", - "example.com", "80", "/?q=1", 0), TEST_SUCCESS); + "example.com", "80", "/?q=1", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com#f", - "example.com", "80", "/", 0), TEST_SUCCESS); + "example.com", "80", "/", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/p?q=1", - "example.com", "80", "/p?q=1", 0), TEST_SUCCESS); + "example.com", "80", "/p?q=1", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/p#f", - "example.com", "80", "/p", 0), TEST_SUCCESS); + "example.com", "80", "/p", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/p?q#f", - "example.com", "80", "/p?q", 0), TEST_SUCCESS); + "example.com", "80", "/p?q", 0), + TEST_SUCCESS); /* The fragment is looked for from the query onwards, so a '#' before the * query stays in the path. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/p#a?b", - "example.com", "80", "/p#a?b", 0), TEST_SUCCESS); + "example.com", "80", "/p#a?b", 0), + TEST_SUCCESS); /* A ':' in the path is not a port and is kept. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/ocsp:8080", - "example.com", "80", "/ocsp:8080", 0), TEST_SUCCESS); + "example.com", "80", "/ocsp:8080", 0), + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:8080/ocsp:1", - "example.com", "8080", "/ocsp:1", 0), TEST_SUCCESS); + "example.com", "8080", "/ocsp:1", 0), + TEST_SUCCESS); /* An empty host is refused rather than returned as "", which is where * this deliberately differs from OpenSSL - nothing can be fetched from @@ -567,17 +604,80 @@ int test_wolfSSL_OCSP_parse_url_api(void) /* CR/LF anywhere is refused so the parts cannot inject header lines into * a request built from them. Also not a check OpenSSL makes. */ ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com\r\n/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com/oc\rsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com/oc\nsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://exa\rmple.com/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://exa\nmple.com/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("\rhttp://example.com/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); +#endif + return EXPECT_RESULT(); +} + +/* Decision-coverage drivers for the ssl_api_crl_ocsp.c argument guards that + * the functional tests leave unpaired. Each block names the source + * line:condition it closes; struct pokes are saved/restored around the call. */ +int test_ssl_crl_ocsp_decision_coverage(void) +{ + EXPECT_DECLS; +#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + struct tm tm; + + XMEMSET(&tm, 0, sizeof(tm)); + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + + /* --- 77:0/1 wolfSSL_LoadCRLBuffer: ssl==NULL || ssl->ctx==NULL ------ */ + { + WOLFSSL* cssl = wolfSSL_new(ctx); + byte buf[4]; + + XMEMSET(buf, 0, sizeof(buf)); + (void)wolfSSL_LoadCRLBuffer(NULL, buf, (long)sizeof(buf), + CERT_FILETYPE); + (void)wolfSSL_LoadCRLBuffer(ssl, buf, (long)sizeof(buf), + CERT_FILETYPE); + ExpectNotNull(cssl); + cssl->ctx = NULL; + (void)wolfSSL_LoadCRLBuffer(cssl, buf, (long)sizeof(buf), + CERT_FILETYPE); + cssl->ctx = ctx; + wolfSSL_free(cssl); + } + + /* --- 917:1 get_ocsp_producedDate_tm: 2nd != (GENERALIZED vs default) - */ + ssl->ocspProducedDateFormat = ASN_GENERALIZED_TIME; + (void)wolfSSL_get_ocsp_producedDate_tm(ssl, &tm); + ssl->ocspProducedDateFormat = 0; + (void)wolfSSL_get_ocsp_producedDate_tm(ssl, &tm); + + /* --- 1120/1152/1187:1 CTX status cb/arg: ctx->cm == NULL ------------ */ + { + WOLFSSL_CTX* nctx = wolfSSL_CTX_new(wolfSSLv23_client_method()); + WOLFSSL_CERT_MANAGER* saved; + + ExpectNotNull(nctx); + saved = nctx->cm; + nctx->cm = NULL; + (void)wolfSSL_CTX_get_tlsext_status_cb(nctx, NULL); + (void)wolfSSL_CTX_set_tlsext_status_cb(nctx, NULL); + (void)wolfSSL_CTX_set_tlsext_status_arg(nctx, NULL); + nctx->cm = saved; + wolfSSL_CTX_free(nctx); + } + + /* --- 1276:0 set_tlsext_status_ocsp_resp_multi: ssl == NULL ----------- */ + (void)wolfSSL_set_tlsext_status_ocsp_resp_multi(NULL, NULL, 0, 0); + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); #endif return EXPECT_RESULT(); } diff --git a/tests/api/test_ssl_crl_ocsp.h b/tests/api/test_ssl_crl_ocsp.h index d3cbbb4d6b7..eacecf52119 100644 --- a/tests/api/test_ssl_crl_ocsp.h +++ b/tests/api/test_ssl_crl_ocsp.h @@ -30,6 +30,7 @@ int test_wolfSSL_tlsext_status_type(void); int test_wolfSSL_CTX_tlsext_status_cb(void); int test_wolfSSL_tlsext_status_ocsp_resp(void); int test_wolfSSL_OCSP_parse_url_api(void); +int test_ssl_crl_ocsp_decision_coverage(void); #define TEST_SSL_CRL_OCSP_DECLS \ TEST_DECL_GROUP("ssl_crl_ocsp", test_wolfSSL_ocsp_url_api), \ @@ -37,6 +38,7 @@ int test_wolfSSL_OCSP_parse_url_api(void); TEST_DECL_GROUP("ssl_crl_ocsp", test_wolfSSL_tlsext_status_type), \ TEST_DECL_GROUP("ssl_crl_ocsp", test_wolfSSL_CTX_tlsext_status_cb), \ TEST_DECL_GROUP("ssl_crl_ocsp", test_wolfSSL_tlsext_status_ocsp_resp), \ - TEST_DECL_GROUP("ssl_crl_ocsp", test_wolfSSL_OCSP_parse_url_api) + TEST_DECL_GROUP("ssl_crl_ocsp", test_wolfSSL_OCSP_parse_url_api), \ + TEST_DECL_GROUP("ssl_crl_ocsp", test_ssl_crl_ocsp_decision_coverage) #endif /* TESTS_API_SSL_CRL_OCSP_H */ From 513390f63156ecdd24f43ef88caa31c87ec13123 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 30 Sep 2026 09:26:58 +0200 Subject: [PATCH 06/33] MC/DC: decision-coverage drivers for the ssl_api_cert.c argument guards Closes the closable guards in src/ssl_api_cert.c: CTX_set_verify_depth depth bounds, CTX_SetCACb ctx->cm==NULL, get_chain_X509 idx bounds, and UnloadCertsKeys keepCert / weOwnCert operands. Struct pokes are saved/restored around each call. Remaining open conditions are structural: the RpkConfig cfg==NULL operands (cfg is always &ctx->rpkConfig), the UnloadCertsKeys key->buffer operand (side-effect-only guard, does not affect the return value the MC/DC measurement tracks), and DecodeToX509 x509/in operands (internal callers always pass valid pointers). Verification: full ./tests/unit.test --no-wc green; ssl_api_cert.c MC/DC 105/738/984/2301 fully covered in the /tmp/mcdc-verify clang coverage tree; cstyle-check clean apart from the file-wide EXPECT_DECLS idiom. --- tests/api/test_ssl_cert.c | 1117 ++++++++++++++++++++++--------------- tests/api/test_ssl_cert.h | 4 +- 2 files changed, 656 insertions(+), 465 deletions(-) diff --git a/tests/api/test_ssl_cert.c b/tests/api/test_ssl_cert.c index 1e30855b539..4d9977de35c 100644 --- a/tests/api/test_ssl_cert.c +++ b/tests/api/test_ssl_cert.c @@ -52,7 +52,7 @@ int test_wolfSSL_get_verify_mode(void) { EXPECT_DECLS; #if (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || defined(HAVE_STUNNEL) || \ - defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX)) && \ + defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX)) && \ !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; @@ -70,15 +70,15 @@ int test_wolfSSL_get_verify_mode(void) ExpectIntEQ(wolfSSL_get_verify_mode(ssl), WOLFSSL_VERIFY_PEER); wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); ExpectIntEQ(wolfSSL_get_verify_mode(ssl), - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT); + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT); /* Exercise the fail-except-PSK option. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); mode = wolfSSL_get_verify_mode(ssl); ExpectIntEQ(mode & WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK); + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -94,7 +94,7 @@ int test_wolfSSL_CTX_get_verify_mode(void) { EXPECT_DECLS; #if (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || defined(HAVE_STUNNEL) || \ - defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX)) && \ + defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX)) && \ !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; int mode; @@ -107,22 +107,22 @@ int test_wolfSSL_CTX_get_verify_mode(void) ExpectIntEQ(wolfSSL_CTX_get_verify_mode(ctx), WOLFSSL_VERIFY_NONE); wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); ExpectIntEQ(wolfSSL_CTX_get_verify_mode(ctx), - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT); + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT); wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); mode = wolfSSL_CTX_get_verify_mode(ctx); ExpectIntEQ(mode & WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK); + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK); #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH) /* Exercise the post-handshake auth option. */ wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); mode = wolfSSL_CTX_get_verify_mode(ctx); ExpectIntEQ(mode & WOLFSSL_VERIFY_POST_HANDSHAKE, - WOLFSSL_VERIFY_POST_HANDSHAKE); + WOLFSSL_VERIFY_POST_HANDSHAKE); #endif wolfSSL_CTX_free(ctx); @@ -182,7 +182,7 @@ int test_wolfSSL_CTX_get_extra_chain_certs(void) { EXPECT_DECLS; #if (defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ - defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \ + defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \ !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \ !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \ defined(WOLFSSL_PEM_TO_DER) @@ -203,7 +203,7 @@ int test_wolfSSL_CTX_get_extra_chain_certs(void) ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); /* server-cert.pem holds a 2-cert chain, so the CA goes into certChain. */ ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx, svrCertFile), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Builds a stack of X509 from the stored chain. */ sk = NULL; @@ -222,15 +222,16 @@ int test_wolfSSL_CTX_get_extra_chain_certs(void) * node, building a multi-element stack. */ ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx, - "certs/intermediate/server-chain.pem"), WOLFSSL_SUCCESS); + "certs/intermediate/server-chain.pem"), + WOLFSSL_SUCCESS); sk = NULL; ExpectIntEQ(wolfSSL_CTX_get_extra_chain_certs(ctx, &sk), WOLFSSL_SUCCESS); ExpectNotNull(sk); ExpectIntGE(wolfSSL_sk_X509_num(sk), 2); #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || \ - defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX) || \ - defined(WOLFSSL_QT)) && !defined(NO_WOLFSSL_STUB) + defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX) || \ + defined(WOLFSSL_QT)) && !defined(NO_WOLFSSL_STUB) /* Stub: returns via the control command. */ wolfSSL_CTX_clear_extra_chain_certs(ctx); #endif @@ -257,7 +258,7 @@ int test_wolfSSL_get_peer_chain(void) struct test_memio_ctx test_ctx; WOLFSSL_X509_CHAIN* chain = NULL; #if (defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ - defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && defined(KEEP_OUR_CERT) + defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && defined(KEEP_OUR_CERT) WOLF_STACK_OF(WOLFSSL_X509)* osk = NULL; #endif @@ -269,7 +270,8 @@ int test_wolfSSL_get_peer_chain(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); /* The client now holds the server's certificate chain. */ @@ -284,7 +286,7 @@ int test_wolfSSL_get_peer_chain(void) #endif #if (defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ - defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && defined(KEEP_OUR_CERT) + defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && defined(KEEP_OUR_CERT) ExpectIntEQ(wolfSSL_get0_chain_certs(NULL, &osk), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_get0_chain_certs(ssl_c, &osk), WOLFSSL_SUCCESS); #endif @@ -316,7 +318,8 @@ int test_wolfSSL_get_chain_X509(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectNotNull(chain = wolfSSL_get_peer_chain(ssl_c)); @@ -362,7 +365,8 @@ int test_wolfSSL_get_chain_cert_pem(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectNotNull(chain = wolfSSL_get_peer_chain(ssl_c)); @@ -370,46 +374,50 @@ int test_wolfSSL_get_chain_cert_pem(void) /* Successful PEM conversion. */ pemSz = (int)sizeof(pem); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, (int)sizeof(pem), - &pemSz), WOLFSSL_SUCCESS); + &pemSz), WOLFSSL_SUCCESS); ExpectIntGT(pemSz, 0); /* Argument validation. */ pemSz = (int)sizeof(pem); ExpectIntEQ(wolfSSL_get_chain_cert_pem(NULL, 0, pem, (int)sizeof(pem), - &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG + )); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, -1, pem, (int)sizeof(pem), - &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG + )); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 99, pem, (int)sizeof(pem), - &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG + )); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, (int)sizeof(pem), - NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)) + ; /* NULL buffer returns the size needed (length-only query). */ needed = 0; /* A negative buffer length is rejected. */ ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, -1, &pemSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, NULL, 0, &needed), - WC_NO_ERR_TRACE(LENGTH_ONLY_E)); + WC_NO_ERR_TRACE(LENGTH_ONLY_E)); ExpectIntGT(needed, 0); ExpectIntLE(needed, (int)sizeof(pem)); /* A buffer shorter than the DER certificate fails up front. */ pemSz = (int)sizeof(pem); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, 1, &pemSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* One byte short of the full size leaves no room for the footer. */ pemSz = (int)sizeof(pem); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, needed - 1, &pemSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Room for the DER length but not the base64-expanded body: the encoder * reports an error (negative return). */ chainLen = wolfSSL_get_chain_length(chain, 0); pemSz = (int)sizeof(pem); ExpectIntLT(wolfSSL_get_chain_cert_pem(chain, 0, pem, chainLen + 100, - &pemSz), 0); + &pemSz), 0); wolfSSL_free(ssl_s); wolfSSL_free(ssl_c); @@ -439,7 +447,8 @@ int test_wolfSSL_cmp_peer_cert_to_file(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); /* Should fail gracefully before handshake. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, svrCertFile), @@ -450,21 +459,22 @@ int test_wolfSSL_cmp_peer_cert_to_file(void) /* NULL arguments report failure. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(NULL, svrCertFile), - WOLFSSL_FATAL_ERROR); + WOLFSSL_FATAL_ERROR); ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, NULL), - WOLFSSL_FATAL_ERROR); + WOLFSSL_FATAL_ERROR); /* The peer (server) certificate matches the file it was loaded from. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, svrCertFile), 0); /* A different certificate does not match. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, caCertFile), - WOLFSSL_FATAL_ERROR); + WOLFSSL_FATAL_ERROR); /* A missing file reports a file error. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, - "certs/does-not-exist.pem"), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE)); + "certs/does-not-exist.pem"), + WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE)); /* A readable file that is not PEM-encoded fails conversion. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, cliCertDerFile), - WOLFSSL_FATAL_ERROR); + WOLFSSL_FATAL_ERROR); wolfSSL_free(ssl_s); wolfSSL_free(ssl_c); @@ -487,7 +497,7 @@ int test_wolfSSL_cmp_peer_cert_to_file(void) * @return 0 to indicate no certificate was supplied. */ static int test_ssl_cert_client_cert_cb(WOLFSSL* ssl, WOLFSSL_X509** x509, - WOLFSSL_EVP_PKEY** pkey) + WOLFSSL_EVP_PKEY** pkey) { (void)ssl; (void)x509; @@ -607,10 +617,10 @@ int test_wolfSSL_cert_setup_cb_ret(void) int cbRet; int err; } cases[] = { - { 1, 0 }, - { 0, WC_NO_ERR_TRACE(CLIENT_CERT_CB_ERROR) }, - { -1, -1 }, - { 2, WC_NO_ERR_TRACE(CLIENT_CERT_CB_ERROR) } + {1, 0}, + {0, WC_NO_ERR_TRACE(CLIENT_CERT_CB_ERROR)}, + {-1, -1}, + {2, WC_NO_ERR_TRACE(CLIENT_CERT_CB_ERROR)} }; int i; @@ -623,7 +633,8 @@ int test_wolfSSL_cert_setup_cb_ret(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); test_ssl_cert_setup_ret = cases[i].cbRet; test_ssl_cert_setup_calls = 0; @@ -631,19 +642,17 @@ int test_wolfSSL_cert_setup_cb_ret(void) if (cases[i].err == 0) { ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - } - else { + } else { /* Drive one step at a time so the error the server reports is the * one the callback caused, not a later I/O failure. */ ExpectIntEQ(wolfSSL_connect(ssl_c), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectIntEQ(wolfSSL_get_error(ssl_c, 0), WOLFSSL_ERROR_WANT_READ); ExpectIntEQ(wolfSSL_accept(ssl_s), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); if (cases[i].err != -1) { ExpectIntEQ(wolfSSL_get_error(ssl_s, 0), cases[i].err); - } - else { + } else { ExpectIntNE(wolfSSL_get_error(ssl_s, 0), 0); } } @@ -679,7 +688,8 @@ int test_wolfSSL_get_peer_cert_chain(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); /* Nothing has been received yet, so there is no chain to build. */ ExpectNull(wolfSSL_get_peer_cert_chain(ssl_c)); @@ -721,7 +731,8 @@ int test_wolfSSL_set_peer_cert_chain(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); /* An empty session chain has nothing to build from. */ ExpectNull(wolfSSL_set_peer_cert_chain(ssl_c)); @@ -732,11 +743,13 @@ int test_wolfSSL_set_peer_cert_chain(void) * client's Certificate message, so there is nothing to ask for. */ #ifndef WOLFSSL_NO_CLIENT_AUTH ExpectIntEQ(wolfSSL_use_certificate_file(ssl_c, cliCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_c, cliKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, cliCertFile, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, NULL); #endif @@ -796,7 +809,8 @@ int test_wolfSSL_get0_verified_chain(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); /* Without a peer certificate there is nothing to verify. */ ExpectNull(wolfSSL_get0_verified_chain(ssl_c)); @@ -844,7 +858,7 @@ int test_wolfSSL_CA_list_add(void) WOLFSSL_X509* x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); /* Both arguments are required. */ ExpectIntEQ(wolfSSL_CTX_add_client_CA(NULL, x509), 0); @@ -854,9 +868,11 @@ int test_wolfSSL_CA_list_add(void) ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_CTX_add_client_CA(ctx, NULL), 0); @@ -875,10 +891,10 @@ int test_wolfSSL_CA_list_add(void) ExpectNull(wolfSSL_CTX_get_client_CA_list(ctx)); ExpectIntEQ(wolfSSL_CTX_add_client_CA(ctx, x509), 1); ExpectIntEQ(wolfSSL_sk_X509_NAME_num( - wolfSSL_CTX_get_client_CA_list(ctx)), 1); + wolfSSL_CTX_get_client_CA_list(ctx)), 1); ExpectIntEQ(wolfSSL_CTX_add_client_CA(ctx, x509), 1); ExpectIntEQ(wolfSSL_sk_X509_NAME_num( - wolfSSL_CTX_get_client_CA_list(ctx)), 2); + wolfSSL_CTX_get_client_CA_list(ctx)), 2); ExpectNull(wolfSSL_get0_CA_list(ssl)); ExpectIntEQ(wolfSSL_add1_to_CA_list(ssl, x509), 1); @@ -925,14 +941,16 @@ int test_wolfSSL_CA_list_get(void) ExpectNull(wolfSSL_get0_peer_CA_list(NULL)); ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); /* Server side: the client CA names are the object's own list. */ ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* Nothing added yet. */ @@ -1008,7 +1026,7 @@ int test_wolfSSL_mutual_auth(void) WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_CTX_mutual_auth(NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_mutual_auth(NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Mutual authentication is a server-only setting. */ @@ -1023,9 +1041,11 @@ int test_wolfSSL_mutual_auth(void) ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_CTX_mutual_auth(ctx, 1), 0); @@ -1071,9 +1091,11 @@ int test_wolfSSL_post_handshake_auth(void) /* A server cannot request it of itself. */ ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_CTX_set_post_handshake_auth(ctx, 1), 0); ExpectIntEQ(wolfSSL_set_post_handshake_auth(ssl, 1), 0); @@ -1124,11 +1146,13 @@ int test_wolfSSL_verify_cert_store(void) ExpectIntEQ(wolfSSL_X509_STORE_up_ref(NULL), 0); /* Setting the store already in use is accepted and changes nothing, both - * for the context and for an object handed the store the context owns. */ + * for the context and for an object handed the store the context owns. */ ExpectIntEQ(wolfSSL_CTX_set1_verify_cert_store(ctx, - wolfSSL_CTX_get_cert_store(ctx)), 1); + wolfSSL_CTX_get_cert_store( + ctx)), 1); ExpectIntEQ(wolfSSL_set1_verify_cert_store(ssl, - wolfSSL_CTX_get_cert_store(ctx)), 1); + wolfSSL_CTX_get_cert_store(ctx)), + 1); /* A different store is taken with a reference. */ ExpectNotNull(store = wolfSSL_X509_STORE_new()); @@ -1161,7 +1185,8 @@ int test_wolfSSL_verify_cert_store(void) * and releasing it here would leave ctx->x509_store_pt pointing at memory * freed a second time by wolfSSL_CTX_free(). */ ExpectIntEQ(wolfSSL_set0_verify_cert_store(ssl, - wolfSSL_CTX_get_cert_store(ctx)), 1); + wolfSSL_CTX_get_cert_store(ctx)), + 1); ExpectPtrEq(wolfSSL_CTX_get_cert_store(ctx), store); /* Still alive and still the context's, so a reference can be taken. */ ExpectIntEQ(wolfSSL_X509_STORE_up_ref(store), 1); @@ -1172,7 +1197,8 @@ int test_wolfSSL_verify_cert_store(void) * This is the shape that freed the context's store: an object with no * store of its own, handed the context's with set0. */ ExpectIntEQ(wolfSSL_set0_verify_cert_store(ssl, - wolfSSL_CTX_get_cert_store(ctx)), 1); + wolfSSL_CTX_get_cert_store(ctx)), + 1); ExpectPtrEq(wolfSSL_CTX_get_cert_store(ctx), store); ExpectIntEQ(wolfSSL_X509_STORE_up_ref(store), 1); wolfSSL_X509_STORE_free(store); @@ -1183,8 +1209,8 @@ int test_wolfSSL_verify_cert_store(void) ExpectPtrEq(wolfSSL_CTX_get_cert_store(ctx), store); /* Give the object a store of its own again and clear it: the object - * releases its reference and reverts to the context's store. The store - * itself is still alive, so a reference can still be taken on it. */ + * releases its reference and reverts to the context's store. The store + * itself is still alive, so a reference can still be taken on it. */ ExpectIntEQ(wolfSSL_set1_verify_cert_store(ssl, store2), 1); ExpectIntEQ(wolfSSL_set1_verify_cert_store(ssl, NULL), 1); ExpectIntEQ(wolfSSL_X509_STORE_up_ref(store2), 1); @@ -1244,8 +1270,8 @@ int test_wolfSSL_verify_cert_store_follows_ctx(void) WOLFSSL_X509_STORE* withCa = NULL; WOLFSSL_X509_STORE* withCa2 = NULL; /* Two CRLs from the same CA. A manager keeps the CRLs tried against it, - * whether or not they verified, so no manager below is asked for the same - * CRL twice - a second attempt would find the cached one and succeed. */ + * whether or not they verified, so no manager below is asked for the same + * CRL twice - a second attempt would find the cached one and succeed. */ const char* crlPem = "./certs/crl/crl.pem"; const char* crlPem2 = "./certs/crl/crl.revoked"; @@ -1258,12 +1284,13 @@ int test_wolfSSL_verify_cert_store_follows_ctx(void) ExpectNotNull(withCa2 = wolfSSL_X509_STORE_new()); ExpectIntEQ(wolfSSL_X509_STORE_load_locations(withCa, caCertFile, NULL), 1); ExpectIntEQ(wolfSSL_X509_STORE_load_locations(withCa2, caCertFile, NULL), - 1); + 1); /* Hand the object the store the context is using while that is the store * the context owns: no pointer to it is kept either. */ ExpectIntEQ(wolfSSL_set1_verify_cert_store(ssl, - wolfSSL_CTX_get_cert_store(ctx)), 1); + wolfSSL_CTX_get_cert_store(ctx)), + 1); /* So the object follows the context onto a store that has the CA. Were * the context's own store pinned to the object instead, the manager in * use would still be the context's, which has no CA. */ @@ -1440,9 +1467,11 @@ int test_wolfSSL_get_certificate_api(void) ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The object borrows the context's certificate. */ @@ -1450,7 +1479,8 @@ int test_wolfSSL_get_certificate_api(void) /* Loading a certificate onto the object makes it own one instead. */ ExpectIntEQ(wolfSSL_use_certificate_file(ssl, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectNotNull(wolfSSL_get_certificate(ssl)); /* Asked again the cached object is returned. */ ExpectNotNull(wolfSSL_get_certificate(ssl)); @@ -1482,22 +1512,24 @@ int test_wolfSSL_cert_unload(void) #endif #ifdef PERSIST_CERT_CACHE ExpectIntEQ(wolfSSL_CTX_get_cert_cache_memsize(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif /* A NULL object reports a bad argument rather than a depth. */ ExpectIntEQ(wolfSSL_CTX_get_verify_depth(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_verify_depth(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The loaded CAs can be released without freeing the context. */ @@ -1509,7 +1541,7 @@ int test_wolfSSL_cert_unload(void) ExpectIntEQ(wolfSSL_UnloadCertsKeys(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_UnloadIntermediateCerts(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1518,24 +1550,24 @@ int test_wolfSSL_cert_unload(void) } /* --------------------------------------------------------------------------- - * Argument guards across the newly-visible public API surface. - * - * src/ssl_api_cert.c, ssl_api_crl_ocsp.c and their siblings are #included into - * ssl.c rather than compiled standalone, so they produced no object file and - * no module declared them until this part of the campaign. Now that they are - * measured, the shape of what is missing is unambiguous: 342 of the 646 - * uncovered conditions across these files mention NULL, and in the densest of - * them it is 85-100%. - * - * They are not protocol behaviour. They are the checks each entry point makes - * on its own arguments, and the existing tests all pass arguments that are - * valid -- so every one of these decisions is taken the same way on every - * call, and none of the operands has an independence pair. - * - * A caller that queries or configures a CTX or an SSL it has not created yet, - * or passes a zero length, or asks for an output through a NULL pointer, is - * doing something ordinary and wrong. That is what these vectors are. - * ------------------------------------------------------------------------- */ +* Argument guards across the newly-visible public API surface. +* +* src/ssl_api_cert.c, ssl_api_crl_ocsp.c and their siblings are #included into +* ssl.c rather than compiled standalone, so they produced no object file and +* no module declared them until this part of the campaign. Now that they are +* measured, the shape of what is missing is unambiguous: 342 of the 646 +* uncovered conditions across these files mention NULL, and in the densest of +* them it is 85-100%. +* +* They are not protocol behaviour. They are the checks each entry point makes +* on its own arguments, and the existing tests all pass arguments that are +* valid -- so every one of these decisions is taken the same way on every +* call, and none of the operands has an independence pair. +* +* A caller that queries or configures a CTX or an SSL it has not created yet, +* or passes a zero length, or asks for an output through a NULL pointer, is +* doing something ordinary and wrong. That is what these vectors are. +* ------------------------------------------------------------------------- */ int test_wolfSSL_cert_api_arg_guards(void) { EXPECT_DECLS; @@ -1544,7 +1576,7 @@ int test_wolfSSL_cert_api_arg_guards(void) WOLFSSL* ssl = NULL; #ifdef HAVE_RPK int tp = 0; - const char certTypes[] = { WOLFSSL_CERT_TYPE_X509 }; + const char certTypes[] = {WOLFSSL_CERT_TYPE_X509}; unsigned char spki[8]; XMEMSET(spki, 0, sizeof(spki)); @@ -1759,39 +1791,39 @@ static int test_verify_mode_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) static const VerifyModeCase verifyModeCases[] = { /* VERIFY_NONE is the only mode that sets verifyNone. */ - { "NONE", WOLFSSL_VERIFY_NONE, 1, 0, 0, 0 }, - { "PEER", WOLFSSL_VERIFY_PEER, 0, 1, 0, 0 }, - { "PEER|FAIL_IF_NO_PEER_CERT", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, - 0, 1, 1, 0 }, - { "PEER|FAIL_EXCEPT_PSK", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - 0, 1, 0, 1 }, + {"NONE", WOLFSSL_VERIFY_NONE, 1, 0, 0, 0}, + {"PEER", WOLFSSL_VERIFY_PEER, 0, 1, 0, 0}, + {"PEER|FAIL_IF_NO_PEER_CERT", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, + 0, 1, 1, 0}, + {"PEER|FAIL_EXCEPT_PSK", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, + 0, 1, 0, 1}, /* The two fail-on-no-cert flags are independent bits and may both be * recorded; the PSK exception is applied first at the handshake. */ - { "PEER|FAIL_IF_NO_PEER_CERT|FAIL_EXCEPT_PSK", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - 0, 1, 1, 1 }, + {"PEER|FAIL_IF_NO_PEER_CERT|FAIL_EXCEPT_PSK", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, + 0, 1, 1, 1}, /* FAIL_IF_NO_PEER_CERT on its own is recorded even though a server that * never requests a certificate cannot act on it. */ - { "FAIL_IF_NO_PEER_CERT", WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, - 0, 0, 1, 0 }, + {"FAIL_IF_NO_PEER_CERT", WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, + 0, 0, 1, 0}, /* VERIFY_DEFAULT clears every option instead of setting one. That is * why it does not round-trip through get_verify_mode(). */ - { "DEFAULT", WOLFSSL_VERIFY_DEFAULT, 0, 0, 0, 0 }, + {"DEFAULT", WOLFSSL_VERIFY_DEFAULT, 0, 0, 0, 0}, /* VERIFY_NONE is matched by equality, not as a bit: OR-ing anything else * in means the peer IS verified. */ - { "NONE|PEER", WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_PEER, 0, 1, 0, 0 }, + {"NONE|PEER", WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_PEER, 0, 1, 0, 0}, /* CLIENT_ONCE is accepted and ignored: on its own it leaves every option * clear, and it never disturbs the flags it is OR-ed with. */ - { "CLIENT_ONCE", WOLFSSL_VERIFY_CLIENT_ONCE, 0, 0, 0, 0 }, - { "PEER|CLIENT_ONCE", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_CLIENT_ONCE, 0, 1, 0, 0 }, - { "PEER|FAIL_IF_NO_PEER_CERT|CLIENT_ONCE", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | - WOLFSSL_VERIFY_CLIENT_ONCE, - 0, 1, 1, 0 } + {"CLIENT_ONCE", WOLFSSL_VERIFY_CLIENT_ONCE, 0, 0, 0, 0}, + {"PEER|CLIENT_ONCE", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_CLIENT_ONCE, 0, 1, 0, 0}, + {"PEER|FAIL_IF_NO_PEER_CERT|CLIENT_ONCE", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | + WOLFSSL_VERIFY_CLIENT_ONCE, + 0, 1, 1, 0} }; #endif /* !NO_CERTS && !NO_TLS && !NO_WOLFSSL_CLIENT */ @@ -1842,11 +1874,11 @@ int test_wolfSSL_verify_mode_options(void) #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH) /* Post-handshake auth is an ordinary bit alongside the others. */ wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); ExpectIntEQ(ctx->verifyPeer, 1); ExpectIntEQ(ctx->verifyPostHandshake, 1); wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.verifyPostHandshake, 1); @@ -1858,14 +1890,14 @@ int test_wolfSSL_verify_mode_options(void) /* So does CLIENT_ONCE on its own, which is to say it selects nothing. */ wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_CLIENT_ONCE, NULL); ExpectIntEQ(ctx->verifyPostHandshake, 0); #endif /* Setting a mode replaces the previous one rather than accumulating. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER, NULL); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.failNoCert, 0); @@ -1907,14 +1939,15 @@ int test_wolfSSL_verify_client_once_ignored(void) /* Adding CLIENT_ONCE to a mode leaves that mode's options untouched. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.failNoCert, 1); ExpectIntEQ(ssl->options.verifyNone, 0); wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | WOLFSSL_VERIFY_CLIENT_ONCE, - NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | + WOLFSSL_VERIFY_CLIENT_ONCE, + NULL); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.failNoCert, 1); ExpectIntEQ(ssl->options.verifyNone, 0); @@ -1930,7 +1963,7 @@ int test_wolfSSL_verify_client_once_ignored(void) /* CLIENT_ONCE does not turn VERIFY_NONE into something else either: * VERIFY_NONE is matched by equality, so the pair verifies the peer. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_CLIENT_ONCE, - NULL); + NULL); ExpectIntEQ(ssl->options.verifyNone, 0); #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \ @@ -1938,11 +1971,11 @@ int test_wolfSSL_verify_client_once_ignored(void) defined(WOLFSSL_NGINX) /* The bit is never reported back, on the object or on the context. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_CLIENT_ONCE, - NULL); + NULL); ExpectIntEQ(wolfSSL_get_verify_mode(ssl), WOLFSSL_VERIFY_PEER); wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_CLIENT_ONCE, NULL); + WOLFSSL_VERIFY_CLIENT_ONCE, NULL); ExpectIntEQ(wolfSSL_CTX_get_verify_mode(ctx), WOLFSSL_VERIFY_PEER); /* WOLFSSL_VERIFY_DEFAULT does not round-trip either: it clears every @@ -1976,8 +2009,9 @@ int test_wolfSSL_verify_mode_ctx_inherit(void) /* An object created after the context is configured inherits the mode. */ wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, + NULL); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.failNoCert, 1); @@ -2033,9 +2067,9 @@ int test_wolfSSL_verify_none_accepts_untrusted(void) int mode; int expectFail; } cases[] = { - { "PEER", WOLFSSL_VERIFY_PEER, 1 }, - { "NONE", WOLFSSL_VERIFY_NONE, 0 }, - { "NONE|PEER", WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_PEER, 1 } + {"PEER", WOLFSSL_VERIFY_PEER, 1}, + {"NONE", WOLFSSL_VERIFY_NONE, 0}, + {"NONE|PEER", WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_PEER, 1} }; size_t i; @@ -2055,7 +2089,8 @@ int test_wolfSSL_verify_none_accepts_untrusted(void) } ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); wolfSSL_set_verify(ssl_c, cases[i].mode, NULL); @@ -2063,10 +2098,9 @@ int test_wolfSSL_verify_none_accepts_untrusted(void) /* Verifying, with no CA: the chain has no signer. */ ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_error(ssl_c, - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); - } - else { + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + } else { /* Not verifying: the same untrusted certificate is accepted. */ ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); } @@ -2121,16 +2155,17 @@ int test_wolfSSL_verify_fail_except_psk(void) /* A PSK suite is the exception: no peer certificate is required. */ XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); wolfSSL_set_psk_client_callback(ssl_c, my_psk_client_cb); wolfSSL_set_psk_server_callback(ssl_s, my_psk_server_cb); ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_VFY_PSK_SUITE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, TEST_VFY_PSK_SUITE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(ssl_s->options.usingPSK_cipher, 1); @@ -2149,15 +2184,16 @@ int test_wolfSSL_verify_fail_except_psk(void) * cert-less client are now rejected. */ XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_error(ssl_s, - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WC_NO_ERR_TRACE(NO_PEER_CERT)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WC_NO_ERR_TRACE(NO_PEER_CERT)); wolfSSL_free(ssl_c); wolfSSL_free(ssl_s); @@ -2182,7 +2218,7 @@ int test_wolfSSL_verify_fail_except_psk(void) * @return TEST_SUCCESS on success. */ static int test_vfy_no_client_cert(method_provider method_c, - method_provider method_s, int rounds) + method_provider method_s, int rounds) { EXPECT_DECLS; WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; @@ -2191,17 +2227,17 @@ static int test_vfy_no_client_cert(method_provider method_c, XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - method_c, method_s), 0); + method_c, method_s), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); /* The client has no certificate loaded, so it answers the server's * request with an empty Certificate message. */ ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, rounds, NULL), 0); ExpectIntEQ(wolfSSL_get_error(ssl_s, - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WC_NO_ERR_TRACE(NO_PEER_CERT)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WC_NO_ERR_TRACE(NO_PEER_CERT)); ExpectIntEQ(ssl_s->options.havePeerCert, 0); wolfSSL_free(ssl_c); @@ -2222,7 +2258,7 @@ static int test_vfy_no_client_cert(method_provider method_c, * @return TEST_SUCCESS on success. */ static int test_vfy_none_server_no_request(method_provider method_c, - method_provider method_s, int rounds) + method_provider method_s, int rounds) { EXPECT_DECLS; WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; @@ -2231,7 +2267,7 @@ static int test_vfy_none_server_no_request(method_provider method_c, XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - method_c, method_s), 0); + method_c, method_s), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, NULL); @@ -2239,11 +2275,11 @@ static int test_vfy_none_server_no_request(method_provider method_c, * CERT_FILETYPE tracks the cliCertFile/cliKeyFile paths, which are DER * rather than PEM in a build without WOLFSSL_PEM_TO_DER. */ ExpectIntEQ(wolfSSL_use_certificate_file(ssl_c, cliCertFile, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_c, cliKeyFile, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, cliCertFile, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, rounds, NULL), 0); @@ -2276,28 +2312,33 @@ int test_wolfSSL_verify_no_client_cert(void) #if defined(WOLFSSL_TLS13) /* TLS 1.3: rejected when the server processes the client's Finished. */ ExpectIntEQ(test_vfy_no_client_cert(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, 10), TEST_SUCCESS); + wolfTLSv1_3_server_method, 10), + TEST_SUCCESS); #endif #if !defined(WOLFSSL_NO_TLS12) /* TLS 1.2: rejected on the empty Certificate message. */ ExpectIntEQ(test_vfy_no_client_cert(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, 10), TEST_SUCCESS); + wolfTLSv1_2_server_method, 10), + TEST_SUCCESS); #endif #if !defined(NO_OLD_TLS) /* TLS 1.1: the empty-Certificate check does not apply below TLS 1.2, so * this is rejected later, in DoClientKeyExchange. */ ExpectIntEQ(test_vfy_no_client_cert(wolfTLSv1_1_client_method, - wolfTLSv1_1_server_method, 10), TEST_SUCCESS); + wolfTLSv1_1_server_method, 10), + TEST_SUCCESS); #endif #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) /* DTLS 1.2 over the same TLS 1.2 code path, but across a cookie * exchange and a retransmittable flight. */ ExpectIntEQ(test_vfy_no_client_cert(wolfDTLSv1_2_client_method, - wolfDTLSv1_2_server_method, 20), TEST_SUCCESS); + wolfDTLSv1_2_server_method, 20), + TEST_SUCCESS); #endif #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_TLS13) ExpectIntEQ(test_vfy_no_client_cert(wolfDTLSv1_3_client_method, - wolfDTLSv1_3_server_method, 20), TEST_SUCCESS); + wolfDTLSv1_3_server_method, 20), + TEST_SUCCESS); #endif #endif @@ -2318,15 +2359,18 @@ int test_wolfSSL_verify_none_server_no_request(void) #if defined(WOLFSSL_TLS13) ExpectIntEQ(test_vfy_none_server_no_request(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, 10), TEST_SUCCESS); + wolfTLSv1_3_server_method, 10), + TEST_SUCCESS); #endif #if !defined(WOLFSSL_NO_TLS12) ExpectIntEQ(test_vfy_none_server_no_request(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, 10), TEST_SUCCESS); + wolfTLSv1_2_server_method, 10), + TEST_SUCCESS); #endif #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) ExpectIntEQ(test_vfy_none_server_no_request(wolfDTLSv1_2_client_method, - wolfDTLSv1_2_server_method, 20), TEST_SUCCESS); + wolfDTLSv1_2_server_method, 20), + TEST_SUCCESS); #endif #endif @@ -2354,7 +2398,8 @@ int test_wolfSSL_verify_tls13_failnocert_only(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0); + wolfTLSv1_3_client_method, + wolfTLSv1_3_server_method), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); ExpectIntEQ(ssl_s->options.verifyPeer, 0); @@ -2362,8 +2407,8 @@ int test_wolfSSL_verify_tls13_failnocert_only(void) ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_error(ssl_s, - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WC_NO_ERR_TRACE(NO_PEER_CERT)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WC_NO_ERR_TRACE(NO_PEER_CERT)); /* The client was never asked, so it never sent one. */ ExpectIntEQ(ssl_s->msgsReceived.got_certificate, 0); @@ -2397,24 +2442,23 @@ int test_wolfSSL_verify_tls13_failnocert_only(void) * @return 0 on success, -1 when no such record is present. */ static int test_vfy_replace_record(struct test_memio_ctx* ctx, int client, - byte hsType, const byte* rec, int recSz) + byte hsType, const byte* rec, int recSz) { byte* buff; int* len; int* msgSizes; - int msgCount; - int off = 0; - int target = -1; - int targetSz = 0; - int delta; - int msgOff; - int i; + int msgCount; + int off = 0; + int target = -1; + int targetSz = 0; + int delta; + int msgOff; + int i; if (client) { buff = ctx->c_buff; len = &ctx->c_len; msgSizes = ctx->c_msg_sizes; msgCount = ctx->c_msg_count; - } - else { + } else { buff = ctx->s_buff; len = &ctx->s_len; msgSizes = ctx->s_msg_sizes; msgCount = ctx->s_msg_count; } @@ -2428,7 +2472,7 @@ static int test_vfy_replace_record(struct test_memio_ctx* ctx, int client, break; } if (buff[off] == handshake && recLen > 0 && - buff[off + RECORD_HEADER_SZ] == hsType) { + buff[off + RECORD_HEADER_SZ] == hsType) { target = off; targetSz = RECORD_HEADER_SZ + recLen; break; @@ -2445,7 +2489,7 @@ static int test_vfy_replace_record(struct test_memio_ctx* ctx, int client, } XMEMMOVE(buff + target + recSz, buff + target + targetSz, - (size_t)(*len - target - targetSz)); + (size_t)(*len - target - targetSz)); XMEMCPY(buff + target, rec, (size_t)recSz); *len += delta; @@ -2493,26 +2537,27 @@ int test_wolfSSL_verify_empty_server_cert(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_PEER, NULL); /* Client sends its hello. */ ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_FATAL_ERROR); ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR), - WOLFSSL_ERROR_WANT_READ); + WOLFSSL_ERROR_WANT_READ); /* Server replies with its flight, still in the clear. */ ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_FATAL_ERROR); ExpectIntEQ(wolfSSL_get_error(ssl_s, WOLFSSL_FATAL_ERROR), - WOLFSSL_ERROR_WANT_READ); + WOLFSSL_ERROR_WANT_READ); /* Swap the server's Certificate for one carrying no certificates. */ ExpectIntEQ(test_vfy_replace_record(&test_ctx, 1, certificate, - emptyCert, (int)sizeof(emptyCert)), 0); + emptyCert, (int)sizeof(emptyCert)), 0); ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_FATAL_ERROR); ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR), - WC_NO_ERR_TRACE(NO_PEER_CERT)); + WC_NO_ERR_TRACE(NO_PEER_CERT)); ExpectIntEQ(ssl_c->options.havePeerCert, 0); wolfSSL_free(ssl_c); @@ -2546,10 +2591,11 @@ int test_wolfSSL_verify_post_handshake_defers(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0); + wolfTLSv1_3_client_method, + wolfTLSv1_3_server_method), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); ExpectIntEQ(ssl_s->options.verifyPeer, 1); ExpectIntEQ(ssl_s->options.verifyPostHandshake, 1); @@ -2622,7 +2668,7 @@ static int test_eku_override_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) * nothing else. Every other rejection is left to stand, so a chain the library * turns away for another reason must still fail. */ static int test_eku_purpose_only_cb(int preverify, - WOLFSSL_X509_STORE_CTX* store) + WOLFSSL_X509_STORE_CTX* store) { if (store->error == WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) @@ -2642,11 +2688,13 @@ static int test_eku_purpose_only_cb(int preverify, * (RFC 4210 OldWithNew): issuer and subject match, but the key is subjKey and * the signature is issuerKey's. Returns the DER length, or < 0 on failure. */ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, - const byte* issuerDer, int issuerDerSz, RsaKey* issuerKey, WC_RNG* rng, - const char* extKeyUsage, const char* cn, int selfIssued) + const byte* issuerDer, int issuerDerSz, RsaKey* + issuerKey, WC_RNG* rng, + const char* extKeyUsage, const char* cn, int + selfIssued) { Cert cert; - int ret = 0; + int ret = 0; if (selfIssued && issuerDer == NULL) return -1; @@ -2661,8 +2709,7 @@ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, * set below is built from the same source. */ if (wc_SetSubjectBuffer(&cert, issuerDer, issuerDerSz) != 0) ret = -1; - } - else { + } else { XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE - 1); XSTRNCPY(cert.subject.org, "wolfSSL_test", CTC_NAME_SIZE - 1); XSTRNCPY(cert.subject.commonName, cn, CTC_NAME_SIZE - 1); @@ -2672,7 +2719,7 @@ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, if (ret == 0 && wc_SetKeyUsage(&cert, "keyCertSign,cRLSign") != 0) ret = -1; if (ret == 0 && extKeyUsage != NULL && - wc_SetExtKeyUsage(&cert, extKeyUsage) != 0) + wc_SetExtKeyUsage(&cert, extKeyUsage) != 0) ret = -1; /* wc_InitCert() leaves selfSigned set, so naming no issuer is what makes * the generated certificate self-signed. */ @@ -2686,7 +2733,7 @@ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, ret = wc_MakeCert(&cert, out, (word32)outMax, subjKey, NULL, rng); if (ret >= 0) ret = wc_SignCert(cert.bodySz, cert.sigType, out, (word32)outMax, - (issuerDer == NULL) ? subjKey : issuerKey, NULL, rng); + (issuerDer == NULL) ? subjKey : issuerKey, NULL, rng); #ifdef WOLFSSL_CERT_GEN_CACHE wc_SetCert_Free(&cert); #endif @@ -2696,10 +2743,11 @@ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, /* Build a TLS leaf signed by the given CA. The leaf carries both serverAuth * and clientAuth so only the issuing CA's purpose is tested. */ static int test_eku_gen_leaf(byte* out, int outMax, RsaKey* leafKey, - const byte* issuerDer, int issuerDerSz, RsaKey* issuerKey, WC_RNG* rng) + const byte* issuerDer, int issuerDerSz, RsaKey* + issuerKey, WC_RNG* rng) { Cert cert; - int ret = 0; + int ret = 0; if (wc_InitCert(&cert) != 0) return -1; @@ -2713,7 +2761,7 @@ static int test_eku_gen_leaf(byte* out, int outMax, RsaKey* leafKey, if (ret == 0 && wc_SetAuthKeyIdFromCert(&cert, issuerDer, issuerDerSz) != 0) ret = -1; if (ret == 0 && - wc_SetKeyUsage(&cert, "digitalSignature,keyEncipherment") != 0) + wc_SetKeyUsage(&cert, "digitalSignature,keyEncipherment") != 0) ret = -1; if (ret == 0 && wc_SetExtKeyUsage(&cert, "serverAuth,clientAuth") != 0) ret = -1; @@ -2723,7 +2771,7 @@ static int test_eku_gen_leaf(byte* out, int outMax, RsaKey* leafKey, ret = wc_MakeCert(&cert, out, (word32)outMax, leafKey, NULL, rng); if (ret >= 0) ret = wc_SignCert(cert.bodySz, cert.sigType, out, (word32)outMax, - issuerKey, NULL, rng); + issuerKey, NULL, rng); #ifdef WOLFSSL_CERT_GEN_CACHE wc_SetCert_Free(&cert); #endif @@ -2738,8 +2786,10 @@ static int test_eku_gen_leaf(byte* out, int outMax, RsaKey* leafKey, * The handshake result and the compatibility-layer verify result are returned * through hsRet and verifyRet. */ static int test_eku_chain_handshake(const byte* chainDer, int chainSz, - const byte* rootDer, int rootSz, const byte* pinnedDer, int pinnedSz, - const test_eku_case* tc, int* hsRet, long* verifyRet) + const byte* rootDer, int rootSz, const byte* + pinnedDer, int pinnedSz, + const test_eku_case* tc, int* hsRet, long* + verifyRet) { EXPECT_DECLS; WOLFSSL_CTX* ctx_c = NULL; @@ -2760,27 +2810,35 @@ static int test_eku_chain_handshake(const byte* chainDer, int chainSz, /* The server always presents the generated chain so a single set of * credentials covers both directions. */ ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfSSLv23_client_method, wolfSSLv23_server_method, - (byte*)rootDer, rootSz, (byte*)chainDer, chainSz, - (byte*)client_key_der_2048, (int)sizeof_client_key_der_2048), 0); + wolfSSLv23_client_method, + wolfSSLv23_server_method, + (byte*)rootDer, rootSz, (byte*)chainDer, + chainSz, + (byte*)client_key_der_2048, (int) + sizeof_client_key_der_2048), 0); if (tc->clientPresents) { /* Leave the server chain unverified so only the server's view of the * client chain decides the handshake. */ wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, NULL); ExpectIntEQ(wolfSSL_use_certificate_chain_buffer_format(ssl_c, chainDer, - (long)chainSz, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + (long)chainSz, + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_use_PrivateKey_buffer(ssl_c, client_key_der_2048, - (long)sizeof_client_key_der_2048, WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + (long) + sizeof_client_key_der_2048, + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_load_verify_buffer(ctx_s, rootDer, - (long)rootSz, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + (long)rootSz, + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, verifyCb); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, verifyCb); verifyCtx = ctx_s; verifySsl = ssl_s; - } - else { + } else { wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_PEER, verifyCb); verifyCtx = ctx_c; verifySsl = ssl_c; @@ -2793,7 +2851,9 @@ static int test_eku_chain_handshake(const byte* chainDer, int chainSz, if (pinnedDer != NULL) { ExpectIntEQ(wolfSSL_CTX_load_verify_buffer(verifyCtx, pinnedDer, - (long)pinnedSz, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + (long)pinnedSz, + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); } /* The harness only reports pass or fail, so read the reason from the side @@ -2820,7 +2880,7 @@ static int test_eku_chain_handshake(const byte* chainDer, int chainSz, /* Build the chain for one scenario, run the handshake and check both the * handshake result and the verify result it is reported as. */ static int test_eku_chain_case(const test_eku_fixture* f, - const test_eku_case* tc) + const test_eku_case* tc) { EXPECT_DECLS; const byte* rootDer = ca_cert_der_2048; @@ -2837,10 +2897,14 @@ static int test_eku_chain_case(const test_eku_fixture* f, /* The CA under test is always signed by the root. */ ExpectIntGT((caSz = test_eku_gen_ca(f->interDer, TEST_EKU_CERT_BUF_SZ, - f->intKey, tc->selfSignedCa ? NULL : ca_cert_der_2048, - (int)sizeof_ca_cert_der_2048, f->caKey, f->rng, tc->extKeyUsage, - tc->selfSignedCa ? "EKU Self Signed CA" : "EKU Intermediate", - tc->selfIssuedCa)), 0); + f->intKey, tc->selfSignedCa ? NULL : + ca_cert_der_2048, + (int)sizeof_ca_cert_der_2048, f->caKey, + f->rng, tc->extKeyUsage, + tc->selfSignedCa ? + "EKU Self Signed CA" : + "EKU Intermediate", + tc->selfIssuedCa)), 0); leafIssuerDer = f->interDer; leafIssuerSz = caSz; @@ -2851,15 +2915,19 @@ static int test_eku_chain_case(const test_eku_fixture* f, * of the leaf and sits at depth 2. */ if (tc->extraLevel) { ExpectIntGT((midSz = test_eku_gen_ca(f->midDer, TEST_EKU_CERT_BUF_SZ, - f->midKey, f->interDer, caSz, f->intKey, f->rng, - "serverAuth,clientAuth", "EKU Middle CA", 0)), 0); + f->midKey, f->interDer, caSz, f-> + intKey, f->rng, + "serverAuth,clientAuth", + "EKU Middle CA", 0)), 0); leafIssuerDer = f->midDer; leafIssuerSz = midSz; leafIssuerKey = f->midKey; } ExpectIntGT((leafSz = test_eku_gen_leaf(f->chainDer, TEST_EKU_CERT_BUF_SZ, - f->leafKey, leafIssuerDer, leafIssuerSz, leafIssuerKey, f->rng)), 0); + f->leafKey, leafIssuerDer, + leafIssuerSz, leafIssuerKey, f->rng) + ), 0); /* The chain buffer holds the leaf first, then its issuers in order. */ ExpectIntLE(leafSz + caSz + midSz, TEST_EKU_CERT_BUF_SZ); @@ -2876,8 +2944,9 @@ static int test_eku_chain_case(const test_eku_fixture* f, rootSz = caSz; } ExpectIntEQ(test_eku_chain_handshake(f->chainDer, chainSz, - rootDer, rootSz, tc->pinCa ? f->interDer : NULL, caSz, tc, - &hsRet, &verifyRet), TEST_SUCCESS); + rootDer, rootSz, tc->pinCa ? f-> + interDer : NULL, caSz, tc, + &hsRet, &verifyRet), TEST_SUCCESS); } ExpectIntEQ(hsRet, tc->expectRet); @@ -2886,7 +2955,7 @@ static int test_eku_chain_case(const test_eku_fixture* f, * cases the library decided on its own have a predictable verify result. */ if (tc->overrideCb == 0) { ExpectIntEQ(verifyRet, (tc->expectRet == 0) ? - WOLFSSL_X509_V_OK : WOLFSSL_X509_V_ERR_INVALID_PURPOSE); + WOLFSSL_X509_V_OK : WOLFSSL_X509_V_ERR_INVALID_PURPOSE); } #endif @@ -2920,63 +2989,63 @@ int test_wolfSSL_chain_ca_ext_key_usage(void) /* Server authentication: a CA restricted to code signing, or to * client authentication, must be refused. */ - { "codeSigning", 0, 0, 0, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, - { "clientAuth", 0, 0, 0, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, + {"codeSigning", 0, 0, 0, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, + {"clientAuth", 0, 0, 0, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, /* A CA that carries the purpose, or leaves it unrestricted, must not * be over-rejected. */ - { "serverAuth", 0, 0, 0, 0, 0, 0, 0, 0 }, - { NULL, 0, 0, 0, 0, 0, 0, 0, 0 }, - { "any", 0, 0, 0, 0, 0, 0, 0, 0 }, + {"serverAuth", 0, 0, 0, 0, 0, 0, 0, 0}, + {NULL, 0, 0, 0, 0, 0, 0, 0, 0}, + {"any", 0, 0, 0, 0, 0, 0, 0, 0}, /* The rule applies to a CA the certificate manager already holds, not * only to one seen for the first time. */ - { "codeSigning", 0, 0, 0, 1, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, - { "serverAuth", 0, 0, 0, 1, 0, 0, 0, 0 }, + {"codeSigning", 0, 0, 0, 1, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, + {"serverAuth", 0, 0, 0, 1, 0, 0, 0, 0}, /* A self-signed trust anchor is exempt: here it is the anchor test, * not the Extended Key Usage, that decides. */ - { "codeSigning", 1, 0, 0, 0, 0, 0, 0, 0 }, + {"codeSigning", 1, 0, 0, 0, 0, 0, 0, 0}, /* A self-issued CA key rollover certificate is not an anchor. It * carries the anchor's issuer and subject names, so DecodedCert's * selfSigned flag is set, but it holds a different key and is signed * by the anchor. The Extended Key Usage must still be enforced. */ - { "codeSigning", 0, 1, 0, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, - { "serverAuth", 0, 1, 0, 0, 0, 0, 0, 0 }, + {"codeSigning", 0, 1, 0, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, + {"serverAuth", 0, 1, 0, 0, 0, 0, 0, 0}, /* Enforcement is not limited to the CA directly above the leaf: here - * the CA under test issues "EKU Middle CA", which issues the leaf. */ - { "codeSigning", 0, 0, 0, 0, 1, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, - { "serverAuth", 0, 0, 0, 0, 1, 0, 0, 0 }, + * the CA under test issues "EKU Middle CA", which issues the leaf. */ + {"codeSigning", 0, 0, 0, 0, 1, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, + {"serverAuth", 0, 0, 0, 0, 1, 0, 0, 0}, /* An application that installs a verify callback keeps the last word, * as it does for every other chain error. */ - { "codeSigning", 0, 0, 0, 0, 0, 1, 0, 0 }, + {"codeSigning", 0, 0, 0, 0, 0, 1, 0, 0}, #ifdef OPENSSL_EXTRA /* The purpose check must not stand in for the checks that run before - * it. With the depth limit pinned below the chain, a callback that - * waives only the purpose error still has to see the chain length - * rejection, whether or not the CA under test carries the purpose. */ - { "serverAuth", 0, 0, 0, 0, 1, 2, 1, - WC_NO_ERR_TRACE(MAX_CHAIN_ERROR) }, - { "codeSigning", 0, 0, 0, 0, 1, 2, 1, - WC_NO_ERR_TRACE(MAX_CHAIN_ERROR) }, + * it. With the depth limit pinned below the chain, a callback that + * waives only the purpose error still has to see the chain length + * rejection, whether or not the CA under test carries the purpose. */ + {"serverAuth", 0, 0, 0, 0, 1, 2, 1, + WC_NO_ERR_TRACE(MAX_CHAIN_ERROR)}, + {"codeSigning", 0, 0, 0, 0, 1, 2, 1, + WC_NO_ERR_TRACE(MAX_CHAIN_ERROR)}, #endif #ifndef WOLFSSL_NO_CLIENT_AUTH /* Client authentication: the server applies the same rule with the * clientAuth purpose. */ - { "codeSigning", 0, 0, 1, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, - { "serverAuth", 0, 0, 1, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, - { "clientAuth", 0, 0, 1, 0, 0, 0, 0, 0 }, - { NULL, 0, 0, 1, 0, 0, 0, 0, 0 }, - { "any", 0, 0, 1, 0, 0, 0, 0, 0 }, + {"codeSigning", 0, 0, 1, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, + {"serverAuth", 0, 0, 1, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, + {"clientAuth", 0, 0, 1, 0, 0, 0, 0, 0}, + {NULL, 0, 0, 1, 0, 0, 0, 0, 0}, + {"any", 0, 0, 1, 0, 0, 0, 0, 0}, /* The rollover shape is rejected in the client authentication * direction too. */ - { "serverAuth", 0, 1, 1, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, - { "clientAuth", 0, 1, 1, 0, 0, 0, 0, 0 }, + {"serverAuth", 0, 1, 1, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, + {"clientAuth", 0, 1, 1, 0, 0, 0, 0, 0}, #endif }; test_eku_fixture fixture; @@ -2995,34 +3064,39 @@ int test_wolfSSL_chain_ca_ext_key_usage(void) XMEMSET(&fixture, 0, sizeof(fixture)); ExpectNotNull(fixture.midDer = (byte*)XMALLOC(TEST_EKU_CERT_BUF_SZ, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); ExpectNotNull(fixture.interDer = (byte*)XMALLOC(TEST_EKU_CERT_BUF_SZ, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); ExpectNotNull(fixture.chainDer = (byte*)XMALLOC(TEST_EKU_CERT_BUF_SZ, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); ExpectIntEQ(wc_InitRng(&rng), 0); - if (EXPECT_SUCCESS()) rngInit = 1; + if (EXPECT_SUCCESS()) + rngInit = 1; ExpectIntEQ(wc_InitRsaKey(&caKey, NULL), 0); - if (EXPECT_SUCCESS()) caInit = 1; + if (EXPECT_SUCCESS()) + caInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(ca_key_der_2048, &idx, &caKey, - (word32)sizeof_ca_key_der_2048), 0); + (word32)sizeof_ca_key_der_2048), 0); ExpectIntEQ(wc_InitRsaKey(&midKey, NULL), 0); - if (EXPECT_SUCCESS()) midInit = 1; + if (EXPECT_SUCCESS()) + midInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(rsa_key_der_2048, &idx, &midKey, - (word32)sizeof_rsa_key_der_2048), 0); + (word32)sizeof_rsa_key_der_2048), 0); ExpectIntEQ(wc_InitRsaKey(&intKey, NULL), 0); - if (EXPECT_SUCCESS()) intInit = 1; + if (EXPECT_SUCCESS()) + intInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &intKey, - (word32)sizeof_server_key_der_2048), 0); + (word32)sizeof_server_key_der_2048), 0); ExpectIntEQ(wc_InitRsaKey(&leafKey, NULL), 0); - if (EXPECT_SUCCESS()) leafInit = 1; + if (EXPECT_SUCCESS()) + leafInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(client_key_der_2048, &idx, &leafKey, - (word32)sizeof_client_key_der_2048), 0); + (word32)sizeof_client_key_der_2048), 0); fixture.caKey = &caKey; fixture.midKey = &midKey; @@ -3034,11 +3108,16 @@ int test_wolfSSL_chain_ca_ext_key_usage(void) ExpectIntEQ(test_eku_chain_case(&fixture, &cases[i]), TEST_SUCCESS); } - if (rngInit) wc_FreeRng(&rng); - if (caInit) wc_FreeRsaKey(&caKey); - if (midInit) wc_FreeRsaKey(&midKey); - if (intInit) wc_FreeRsaKey(&intKey); - if (leafInit) wc_FreeRsaKey(&leafKey); + if (rngInit) + wc_FreeRng(&rng); + if (caInit) + wc_FreeRsaKey(&caKey); + if (midInit) + wc_FreeRsaKey(&midKey); + if (intInit) + wc_FreeRsaKey(&intKey); + if (leafInit) + wc_FreeRsaKey(&leafKey); XFREE(fixture.midDer, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(fixture.interDer, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(fixture.chainDer, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -3076,7 +3155,7 @@ typedef struct test_scv_case { static int test_scv_date_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) { if (store->error == TEST_SCV_DATE_BEFORE_E || - store->error == TEST_SCV_DATE_AFTER_E) { + store->error == TEST_SCV_DATE_AFTER_E) { return 1; } return preverify; @@ -3086,17 +3165,19 @@ static int test_scv_date_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) #undef TEST_SCV_DATE_AFTER_E /* Build a TLS leaf naming the 2048-bit test root as its issuer and carrying - * leafKey's public half. signKey decides whether it is genuine: the root's own - * key issues it, any other key forges it. Returns the DER length, or < 0. */ +* leafKey's public half. signKey decides whether it is genuine: the root's own +* key issues it, any other key forges it. Returns the DER length, or < 0. */ static int test_scv_gen_leaf(byte* out, int outMax, RsaKey* leafKey, - RsaKey* signKey, WC_RNG* rng, int expired) + RsaKey* signKey, WC_RNG* rng, int expired) { - static const byte notBefore[] = { ASN_UTC_TIME, 13, - '1', '9', '0', '1', '0', '1', '0', '0', '0', '0', '0', '0', 'Z' }; - static const byte notAfter[] = { ASN_UTC_TIME, 13, - '2', '0', '0', '1', '0', '1', '0', '0', '0', '0', '0', '0', 'Z' }; + static const byte notBefore[] = {ASN_UTC_TIME, 13, + '1', '9', '0', '1', '0', '1', '0', '0', + '0', '0', '0', '0', 'Z'}; + static const byte notAfter[] = {ASN_UTC_TIME, 13, + '2', '0', '0', '1', '0', '1', '0', '0', + '0', '0', '0', '0', 'Z'}; Cert cert; - int ret = 0; + int ret = 0; if (wc_InitCert(&cert) != 0) return -1; @@ -3114,19 +3195,19 @@ static int test_scv_gen_leaf(byte* out, int outMax, RsaKey* leafKey, if (wc_SetSubjectKeyIdFromPublicKey(&cert, leafKey, NULL) != 0) ret = -1; if (ret == 0 && wc_SetAuthKeyIdFromCert(&cert, ca_cert_der_2048, - (int)sizeof_ca_cert_der_2048) != 0) + (int)sizeof_ca_cert_der_2048) != 0) ret = -1; if (ret == 0 && wc_SetKeyUsage(&cert, - "digitalSignature,keyEncipherment") != 0) + "digitalSignature,keyEncipherment") != 0) ret = -1; if (ret == 0 && wc_SetIssuerBuffer(&cert, ca_cert_der_2048, - (int)sizeof_ca_cert_der_2048) != 0) + (int)sizeof_ca_cert_der_2048) != 0) ret = -1; if (ret == 0) ret = wc_MakeCert(&cert, out, (word32)outMax, leafKey, NULL, rng); if (ret >= 0) ret = wc_SignCert(cert.bodySz, cert.sigType, out, (word32)outMax, - signKey, NULL, rng); + signKey, NULL, rng); #ifdef WOLFSSL_CERT_GEN_CACHE wc_SetCert_Free(&cert); #endif @@ -3147,10 +3228,13 @@ static int test_scv_handshake(const byte* leafDer, int leafSz, int* hsRet) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfSSLv23_client_method, wolfSSLv23_server_method, - (byte*)ca_cert_der_2048, (int)sizeof_ca_cert_der_2048, - (byte*)leafDer, leafSz, - (byte*)client_key_der_2048, (int)sizeof_client_key_der_2048), 0); + wolfSSLv23_client_method, + wolfSSLv23_server_method, + (byte*)ca_cert_der_2048, (int) + sizeof_ca_cert_der_2048, + (byte*)leafDer, leafSz, + (byte*)client_key_der_2048, (int) + sizeof_client_key_der_2048), 0); wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_PEER, test_scv_date_cb); if (EXPECT_SUCCESS()) { @@ -3171,7 +3255,8 @@ static int test_scv_handshake(const byte* leafDer, int leafSz, int* hsRet) /* Build the leaf for one scenario, confirm what the library's own signature * check makes of it, then run the handshake. */ static int test_scv_case_run(byte* leafDer, RsaKey* leafKey, RsaKey* caKey, - RsaKey* attackerKey, WC_RNG* rng, const test_scv_case* tc) + RsaKey* attackerKey, WC_RNG* rng, const + test_scv_case* tc) { EXPECT_DECLS; WOLFSSL_CERT_MANAGER* cm = NULL; @@ -3179,15 +3264,17 @@ static int test_scv_case_run(byte* leafDer, RsaKey* leafKey, RsaKey* caKey, int hsRet = -1; ExpectIntGT((leafSz = test_scv_gen_leaf(leafDer, TEST_SCV_CERT_BUF_SZ, - leafKey, tc->forged ? attackerKey : caKey, rng, tc->expired)), 0); + leafKey, tc->forged ? attackerKey : + caKey, rng, tc->expired)), 0); /* Ground truth from the same library: only the signature is looked at. */ ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, ca_cert_der_2048, - (long)sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + (long)sizeof_ca_cert_der_2048, + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wc_CheckCertSignature(leafDer, (word32)leafSz, NULL, cm), - tc->forged ? WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E) : 0); + tc->forged ? WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E) : 0); wolfSSL_CertManagerFree(cm); ExpectIntEQ(test_scv_handshake(leafDer, leafSz, &hsRet), TEST_SUCCESS); @@ -3221,17 +3308,17 @@ int test_wolfSSL_small_cert_verify_sig_error(void) /* forged, expired, expected handshake result. */ /* A leaf the root did issue verifies. */ - { 0, 0, 0 }, + {0, 0, 0}, /* An expired leaf the root did issue is what the callback exists for, * so it must still be waived. */ - { 0, 1, 0 }, + {0, 1, 0}, /* A leaf the root never signed is refused, and the reason the * application is given names the signature. */ - { 1, 0, WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E) }, + {1, 0, WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E)}, /* The same forgery, also outside its validity window. The date error * must not stand in for the signature error, or the callback above * waives a certificate the root never signed. */ - { 1, 1, WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E) }, + {1, 1, WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E)}, }; byte* leafDer = NULL; WC_RNG rng; @@ -3246,36 +3333,44 @@ int test_wolfSSL_small_cert_verify_sig_error(void) size_t i; ExpectNotNull(leafDer = (byte*)XMALLOC(TEST_SCV_CERT_BUF_SZ, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); ExpectIntEQ(wc_InitRng(&rng), 0); - if (EXPECT_SUCCESS()) rngInit = 1; + if (EXPECT_SUCCESS()) + rngInit = 1; ExpectIntEQ(wc_InitRsaKey(&caKey, NULL), 0); - if (EXPECT_SUCCESS()) caInit = 1; + if (EXPECT_SUCCESS()) + caInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(ca_key_der_2048, &idx, &caKey, - (word32)sizeof_ca_key_der_2048), 0); + (word32)sizeof_ca_key_der_2048), 0); /* Any key the root does not hold serves as the attacker's. */ ExpectIntEQ(wc_InitRsaKey(&attackerKey, NULL), 0); - if (EXPECT_SUCCESS()) attackerInit = 1; + if (EXPECT_SUCCESS()) + attackerInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &attackerKey, - (word32)sizeof_server_key_der_2048), 0); + (word32)sizeof_server_key_der_2048), 0); ExpectIntEQ(wc_InitRsaKey(&leafKey, NULL), 0); - if (EXPECT_SUCCESS()) leafInit = 1; + if (EXPECT_SUCCESS()) + leafInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(client_key_der_2048, &idx, &leafKey, - (word32)sizeof_client_key_der_2048), 0); + (word32)sizeof_client_key_der_2048), 0); for (i = 0; i < XELEM_CNT(cases) && EXPECT_SUCCESS(); i++) { ExpectIntEQ(test_scv_case_run(leafDer, &leafKey, &caKey, &attackerKey, - &rng, &cases[i]), TEST_SUCCESS); + &rng, &cases[i]), TEST_SUCCESS); } - if (rngInit) wc_FreeRng(&rng); - if (caInit) wc_FreeRsaKey(&caKey); - if (attackerInit) wc_FreeRsaKey(&attackerKey); - if (leafInit) wc_FreeRsaKey(&leafKey); + if (rngInit) + wc_FreeRng(&rng); + if (caInit) + wc_FreeRsaKey(&caKey); + if (attackerInit) + wc_FreeRsaKey(&attackerKey); + if (leafInit) + wc_FreeRsaKey(&leafKey); XFREE(leafDer, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return EXPECT_RESULT(); @@ -4277,8 +4372,8 @@ int test_wolfSSL_crl_io_mock(void) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; int i; - static const int results[] = { 0, -1, 1, - WOLFSSL_CBIO_ERR_WANT_READ }; + static const int results[] = {0, -1, 1, + WOLFSSL_CBIO_ERR_WANT_READ}; ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECK), @@ -4339,26 +4434,26 @@ int test_wolfSSL_crl_io_mock(void) } /* --------------------------------------------------------------------------- - * OCSP stapling accessors, and CRL delivered through a mocked transport. - * - * The previous argument-guard sweep moved ssl_api_crl_ocsp.c by one condition, - * because it guessed at which functions held the gaps. Reading them settles - * it: they are not the enable/disable calls, they are the stapling request - * and response accessors, and their operands are of three kinds -- - * - * ssl->options.side != WOLFSSL_CLIENT_END a SERVER object, which no - * ctx->method->side != WOLFSSL_CLIENT_END client-side test can supply - * - * ssl->ocspProducedDateFormat != ASN_UTC_TIME a response that was never - * processed, or one whose - * producedDate is a - * GeneralizedTime - * - * idx >= XELEM_CNT(ssl->ocspCsrResp), len < 0 an out-of-range slot - * - * None of them is reachable from a working client that staples successfully, - * which is the only shape the existing tests have. - * ------------------------------------------------------------------------- */ +* OCSP stapling accessors, and CRL delivered through a mocked transport. +* +* The previous argument-guard sweep moved ssl_api_crl_ocsp.c by one condition, +* because it guessed at which functions held the gaps. Reading them settles +* it: they are not the enable/disable calls, they are the stapling request +* and response accessors, and their operands are of three kinds -- +* +* ssl->options.side != WOLFSSL_CLIENT_END a SERVER object, which no +* ctx->method->side != WOLFSSL_CLIENT_END client-side test can supply +* +* ssl->ocspProducedDateFormat != ASN_UTC_TIME a response that was never +* processed, or one whose +* producedDate is a +* GeneralizedTime +* +* idx >= XELEM_CNT(ssl->ocspCsrResp), len < 0 an out-of-range slot +* +* None of them is reachable from a working client that staples successfully, +* which is the only shape the existing tests have. +* ------------------------------------------------------------------------- */ int test_wolfSSL_ocsp_stapling_accessors(void) { EXPECT_DECLS; @@ -4374,9 +4469,11 @@ int test_wolfSSL_ocsp_stapling_accessors(void) ExpectNotNull(cctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(sctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(sctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(sctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); ExpectNotNull(cssl = wolfSSL_new(cctx)); ExpectNotNull(sssl = wolfSSL_new(sctx)); @@ -4403,8 +4500,8 @@ int test_wolfSSL_ocsp_stapling_accessors(void) #ifndef NO_ASN_TIME /* --- the producedDate accessor -------------------------------------- */ { - byte when[32]; - int fmt = 0; + byte when[32]; + int fmt = 0; XMEMSET(when, 0, sizeof(when)); (void)wolfSSL_get_ocsp_producedDate(NULL, when, sizeof(when), &fmt); @@ -4418,15 +4515,15 @@ int test_wolfSSL_ocsp_stapling_accessors(void) (void)wolfSSL_get_ocsp_producedDate(cssl, when, 1, &fmt); /* Drive the format operands directly. A stapled response carrying a - * GeneralizedTime rather than a UTCTime is legal, rare, and not - * something the test responder emits -- so this is the only way the - * second half of that decision is ever taken. - * - * Guarded because Expect* records a failure and carries on rather than - * returning: if wolfSSL_new() above failed, cssl is NULL here and - * these are dereferences of it, which is what the static analyser - * reported. Every call that merely PASSES cssl is safe either way -- - * the API checks it -- so only the direct field writes need this. */ + * GeneralizedTime rather than a UTCTime is legal, rare, and not + * something the test responder emits -- so this is the only way the + * second half of that decision is ever taken. + * + * Guarded because Expect* records a failure and carries on rather than + * returning: if wolfSSL_new() above failed, cssl is NULL here and + * these are dereferences of it, which is what the static analyser + * reported. Every call that merely PASSES cssl is safe either way -- + * the API checks it -- so only the direct field writes need this. */ if (cssl != NULL) { cssl->ocspProducedDateFormat = ASN_UTC_TIME; (void)wolfSSL_get_ocsp_producedDate(cssl, when, sizeof(when), &fmt); @@ -4449,23 +4546,23 @@ int test_wolfSSL_ocsp_stapling_accessors(void) } /* --------------------------------------------------------------------------- - * X509 accessors and the DTLS API, each with the object its guard needs. - * - * Two files sat at the bottom of the newly-visible surface for the same - * reason, and it is not that their guards are hard to reach -- it is that the - * ACCEPTING half of each pair needs an object the existing tests do not have. - * - * x509.c every accessor is `x509 == NULL || outSz == NULL || ...`, so the - * NULL half is trivial and the valid half needs a parsed - * certificate. There was no test holding one. - * - * ssl_api_dtls.c every guard is `ssl == NULL || !ssl->options.dtls`, so the - * second operand needs a DTLS connection. Every test in this group - * used a TLS one, which leaves that operand constant. - * - * Both fixtures are cheap: a certificate loaded from certs/, and a WOLFSSL - * made from a DTLS method. Neither needs a peer. - * ------------------------------------------------------------------------- */ +* X509 accessors and the DTLS API, each with the object its guard needs. +* +* Two files sat at the bottom of the newly-visible surface for the same +* reason, and it is not that their guards are hard to reach -- it is that the +* ACCEPTING half of each pair needs an object the existing tests do not have. +* +* x509.c every accessor is `x509 == NULL || outSz == NULL || ...`, so the +* NULL half is trivial and the valid half needs a parsed +* certificate. There was no test holding one. +* +* ssl_api_dtls.c every guard is `ssl == NULL || !ssl->options.dtls`, so the +* second operand needs a DTLS connection. Every test in this group +* used a TLS one, which leaves that operand constant. +* +* Both fixtures are cheap: a certificate loaded from certs/, and a WOLFSSL +* made from a DTLS method. Neither needs a peer. +* ------------------------------------------------------------------------- */ int test_wolfSSL_x509_accessor_guards(void) { EXPECT_DECLS; @@ -4483,13 +4580,13 @@ int test_wolfSSL_x509_accessor_guards(void) * -- invisible to anything that only reads headers. Match the implementation. */ #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \ (defined(OPENSSL_EXTRA) || defined(KEEP_PEER_CERT) || \ - defined(KEEP_OUR_CERT)) + defined(KEEP_OUR_CERT)) WOLFSSL_X509* x509 = NULL; - byte buf[2048]; - int iSz = (int)sizeof(buf); - int wSz = (int)sizeof(buf); + byte buf[2048]; + int iSz = (int)sizeof(buf); + int wSz = (int)sizeof(buf); const byte* der = NULL; - int derSz = 0; + int derSz = 0; XMEMSET(buf, 0, sizeof(buf)); @@ -4591,7 +4688,8 @@ int test_wolfSSL_x509_accessor_guards(void) int test_wolfSSL_dtls_api_on_dtls_object(void) { EXPECT_DECLS; -#if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) && \ +#if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) \ + && \ !defined(NO_TLS) && !defined(WOLFSSL_NO_TLS12) WOLFSSL_CTX* dctx = NULL; /* the object the second operand needs */ WOLFSSL_CTX* tctx = NULL; /* a TLS one, for the operand's other half */ @@ -4643,7 +4741,8 @@ int test_wolfSSL_dtls_api_on_dtls_object(void) /* Declared under (WOLFSSL_SCTP || WOLFSSL_DTLS_MTU) && WOLFSSL_DTLS in ssl.h; * guarding on WOLFSSL_DTLS_MTU alone left the SCTP-only configs calling an * undeclared function. */ -#if (defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)) && defined(WOLFSSL_DTLS) +#if (defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)) && defined(WOLFSSL_DTLS \ + ) (void)wolfSSL_CTX_dtls_set_mtu(NULL, 512); (void)wolfSSL_CTX_dtls_set_mtu(dctx, 0xFFFF); (void)wolfSSL_CTX_dtls_set_mtu(dctx, 512); @@ -4667,28 +4766,29 @@ int test_wolfSSL_dtls_api_on_dtls_object(void) } /* --------------------------------------------------------------------------- - * Certificate loading from files that are wrong in file-system ways. - * - * ssl_misc.c is 0/11 and every one of its conditions is in a static file - * helper -- wolfssl_file_len and wolfssl_read_file_static -- guarding against - * a seek that fails, a length that is zero or absurd, and a read that returns - * fewer bytes than the length promised: - * - * if ((ret == 0) && ((sz > MAX_WOLFSSL_FILE_SIZE) || (sz <= 0L))) - * if ((ret == 0) && ((file = XFOPEN(fname, "rb")) == XBADFILE)) - * if ((ret == 0) && (XFREAD(...) != sz)) - * - * They are static, but they are not out of reach: every public load-from-file - * entry point runs through them, so the vector is the FILE rather than the - * argument. An empty file gives sz <= 0; a directory passed where a file is - * expected gives a seek or read that fails; a name that does not exist gives - * XBADFILE. None of those is something a working configuration supplies, and - * no existing test supplies them either. - * ------------------------------------------------------------------------- */ +* Certificate loading from files that are wrong in file-system ways. +* +* ssl_misc.c is 0/11 and every one of its conditions is in a static file +* helper -- wolfssl_file_len and wolfssl_read_file_static -- guarding against +* a seek that fails, a length that is zero or absurd, and a read that returns +* fewer bytes than the length promised: +* +* if ((ret == 0) && ((sz > MAX_WOLFSSL_FILE_SIZE) || (sz <= 0L))) +* if ((ret == 0) && ((file = XFOPEN(fname, "rb")) == XBADFILE)) +* if ((ret == 0) && (XFREAD(...) != sz)) +* +* They are static, but they are not out of reach: every public load-from-file +* entry point runs through them, so the vector is the FILE rather than the +* argument. An empty file gives sz <= 0; a directory passed where a file is +* expected gives a seek or read that fails; a name that does not exist gives +* XBADFILE. None of those is something a working configuration supplies, and +* no existing test supplies them either. +* ------------------------------------------------------------------------- */ int test_wolfSSL_load_pathological_files(void) { EXPECT_DECLS; -#if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_CLIENT) && \ +#if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_CLIENT) \ + && \ !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL_CERT_MANAGER* cm = NULL; @@ -4761,22 +4861,22 @@ int test_wolfSSL_load_pathological_files(void) } /* --------------------------------------------------------------------------- - * The file-helper failure arms, reached with a FIFO. - * - * Three of ssl_misc.c's conditions cannot be produced by any regular file: - * - * if ((ret == 0) && (XFSEEK(fp, 0, SEEK_END) != 0)) seek failed - * if ((ret == 0) && (XFREAD(...) != (size_t)sz)) short read - * - * A regular file always seeks and always reads what it promised. A FIFO does - * neither: fopen() succeeds, so the XBADFILE arm is passed, and then fseek() - * fails with ESPIPE because a pipe has no position. That is the exact shape - * the guard is written for, and nothing on disk can imitate it. - * - * The FIFO is opened read-write by the test before the library touches it, so - * the library's fopen() cannot block waiting for a writer -- a test that hangs - * costs the whole variant just as surely as one that crashes. - * ------------------------------------------------------------------------- */ +* The file-helper failure arms, reached with a FIFO. +* +* Three of ssl_misc.c's conditions cannot be produced by any regular file: +* +* if ((ret == 0) && (XFSEEK(fp, 0, SEEK_END) != 0)) seek failed +* if ((ret == 0) && (XFREAD(...) != (size_t)sz)) short read +* +* A regular file always seeks and always reads what it promised. A FIFO does +* neither: fopen() succeeds, so the XBADFILE arm is passed, and then fseek() +* fails with ESPIPE because a pipe has no position. That is the exact shape +* the guard is written for, and nothing on disk can imitate it. +* +* The FIFO is opened read-write by the test before the library touches it, so +* the library's fopen() cannot block waiting for a writer -- a test that hangs +* costs the whole variant just as surely as one that crashes. +* ------------------------------------------------------------------------- */ int test_wolfSSL_load_from_fifo(void) { EXPECT_DECLS; @@ -4834,34 +4934,34 @@ int test_wolfSSL_load_from_fifo(void) } /* --------------------------------------------------------------------------- - * Allocation failure injection. - * - * Error propagation is the largest remaining category in the campaign: 633 of - * 2855 uncovered conditions, almost all of the shape - * - * ret = something(); - * if (ret != 0) { ... } or if (p == NULL) { ... } - * - * after a call that cannot fail in a working configuration. No number of - * successful runs pairs those operands, because the failing value never - * occurs. The only way to produce it is to make the underlying operation fail - * on purpose. - * - * wolfSSL_SetAllocators() is the cheapest lever for that: one harness, and it - * reaches every out-of-memory arm in every file at once, because every - * allocation in the library goes through it. The sweep fails the Nth - * allocation and lets the rest succeed, for each N in turn -- so each run - * takes a different one of those arms, and the runs where N is past the end - * of the workload are the shared accepting partner. - * - * Failing exactly one allocation rather than everything from N onward keeps - * each vector isolated: a cascade would take many arms at once and prove - * nothing about any single one. - * - * The allocators are restored before the test returns. Leaving a failing - * allocator installed would break every test that runs after this one in the - * same binary, which costs the whole variant. - * ------------------------------------------------------------------------- */ +* Allocation failure injection. +* +* Error propagation is the largest remaining category in the campaign: 633 of +* 2855 uncovered conditions, almost all of the shape +* +* ret = something(); +* if (ret != 0) { ... } or if (p == NULL) { ... } +* +* after a call that cannot fail in a working configuration. No number of +* successful runs pairs those operands, because the failing value never +* occurs. The only way to produce it is to make the underlying operation fail +* on purpose. +* +* wolfSSL_SetAllocators() is the cheapest lever for that: one harness, and it +* reaches every out-of-memory arm in every file at once, because every +* allocation in the library goes through it. The sweep fails the Nth +* allocation and lets the rest succeed, for each N in turn -- so each run +* takes a different one of those arms, and the runs where N is past the end +* of the workload are the shared accepting partner. +* +* Failing exactly one allocation rather than everything from N onward keeps +* each vector isolated: a cascade would take many arms at once and prove +* nothing about any single one. +* +* The allocators are restored before the test returns. Leaving a failing +* allocator installed would break every test that runs after this one in the +* same binary, which costs the whole variant. +* ------------------------------------------------------------------------- */ /* OPT-IN, via WOLFSSL_MCDC_ALLOC_SWEEP, which the coverage campaign's own * option list defines and no ordinary build does. * @@ -4893,7 +4993,8 @@ int test_wolfSSL_load_from_fifo(void) * defined. */ #if defined(WOLFSSL_MCDC_ALLOC_SWEEP) && defined(USE_WOLFSSL_MEMORY) && \ !defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFSSL_DEBUG_MEMORY) && \ - !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_FILESYSTEM) && \ + !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_FILESYSTEM) \ + && \ !defined(NO_TLS) static int fi_failAt = -1; /* which allocation to fail; -1 = none */ @@ -5045,13 +5146,14 @@ int test_wolfSSL_alloc_failure_sweep(void) * defined. */ #if defined(WOLFSSL_MCDC_ALLOC_SWEEP) && defined(USE_WOLFSSL_MEMORY) && \ !defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFSSL_DEBUG_MEMORY) && \ - !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_FILESYSTEM) && \ + !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_FILESYSTEM) \ + && \ !defined(NO_TLS) int n; int injected = 0; int total; - wolfSSL_Malloc_cb prevMalloc = NULL; - wolfSSL_Free_cb prevFree = NULL; + wolfSSL_Malloc_cb prevMalloc = NULL; + wolfSSL_Free_cb prevFree = NULL; wolfSSL_Realloc_cb prevRealloc = NULL; /* Keep whatever was installed before, so the teardown below can put it @@ -5113,18 +5215,18 @@ int test_wolfSSL_alloc_failure_sweep(void) } /* --------------------------------------------------------------------------- - * DTLS API argument guards, on a DTLS object. - * - * ssl_api_dtls.c is the weakest of the newly-visible files. Its guards are the - * usual NULL-and-zero pairs, but the ACCEPTING half of most of them needs a - * DTLS connection -- the same reason the file sat at 3/53 until one was - * supplied. These add the entry points the earlier pass did not reach. - * - * Guards were read from src/ssl_api_dtls.c before writing, not assumed from - * ssl.h: wolfSSL_dtls13_pending_work is compiled only under WOLFSSL_DTLS13, - * SetCookieSecret only under WOLFSSL_DTLS && !NO_WOLFSSL_SERVER, and several - * are additionally gated on !WOLFSSL_LEANPSK. - * ------------------------------------------------------------------------- */ +* DTLS API argument guards, on a DTLS object. +* +* ssl_api_dtls.c is the weakest of the newly-visible files. Its guards are the +* usual NULL-and-zero pairs, but the ACCEPTING half of most of them needs a +* DTLS connection -- the same reason the file sat at 3/53 until one was +* supplied. These add the entry points the earlier pass did not reach. +* +* Guards were read from src/ssl_api_dtls.c before writing, not assumed from +* ssl.h: wolfSSL_dtls13_pending_work is compiled only under WOLFSSL_DTLS13, +* SetCookieSecret only under WOLFSSL_DTLS && !NO_WOLFSSL_SERVER, and several +* are additionally gated on !WOLFSSL_LEANPSK. +* ------------------------------------------------------------------------- */ int test_wolfSSL_dtls_api_more_guards(void) { EXPECT_DECLS; @@ -5224,3 +5326,90 @@ int test_wolfSSL_dtls_api_more_guards(void) #endif return EXPECT_RESULT(); } + +/* Decision-coverage drivers for the ssl_api_cert.c argument guards left + * unpaired by the functional tests. Each block names the source + * line:condition it closes; struct pokes are saved/restored around the call. */ +int test_ssl_cert_decision_coverage(void) +{ + EXPECT_DECLS; +#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + + /* --- 105:1/2 CTX_set_verify_depth: depth < 0 || depth > MAX ---------- */ + wolfSSL_CTX_set_verify_depth(ctx, -1); + wolfSSL_CTX_set_verify_depth(ctx, MAX_CHAIN_DEPTH + 1); + wolfSSL_CTX_set_verify_depth(ctx, 5); + + /* --- 738:1 CTX_SetCACb: ctx->cm != NULL ----------------------------- */ + { + WOLFSSL_CTX* nctx = wolfSSL_CTX_new(wolfSSLv23_client_method()); + WOLFSSL_CERT_MANAGER* saved; + + ExpectNotNull(nctx); + saved = nctx->cm; + nctx->cm = NULL; + wolfSSL_CTX_SetCACb(nctx, NULL); + nctx->cm = saved; + wolfSSL_CTX_free(nctx); + } + + /* --- 2301:1 get_chain_X509: idx >= 0 -------------------------------- */ + { + WOLFSSL_X509_CHAIN chain; + + XMEMSET(&chain, 0, sizeof(chain)); + chain.count = 1; + (void)wolfSSL_get_chain_X509(NULL, 0); + (void)wolfSSL_get_chain_X509(&chain, -1); + (void)wolfSSL_get_chain_X509(&chain, 0); + } + + /* --- 984:1/1002:0/1 UnloadCertsKeys: keepCert, key, key->buffer ----- */ + { + DerBuffer* key; + + /* 984:1 weOwnCert && !keepCert */ + ssl->buffers.weOwnCert = 1; + ssl->buffers.certificate = NULL; + ssl->keepCert = 0; + (void)wolfSSL_UnloadCertsKeys(ssl); + ssl->buffers.weOwnCert = 1; + ssl->keepCert = 1; + (void)wolfSSL_UnloadCertsKeys(ssl); + ssl->keepCert = 0; + ssl->buffers.weOwnCert = 0; + + /* 1002:0/1 weOwnKey && key!=NULL && key->buffer!=NULL */ + ssl->buffers.weOwnKey = 1; + ssl->buffers.key = NULL; + (void)wolfSSL_UnloadCertsKeys(ssl); + + key = (DerBuffer*)XMALLOC(sizeof(DerBuffer), ssl->heap, + DYNAMIC_TYPE_DER); + XMEMSET(key, 0, sizeof(DerBuffer)); + key->type = PRIVATEKEY_TYPE; + ssl->buffers.key = key; + (void)wolfSSL_UnloadCertsKeys(ssl); + + key = (DerBuffer*)XMALLOC(sizeof(DerBuffer), ssl->heap, + DYNAMIC_TYPE_DER); + key->buffer = (byte*)XMALLOC(16, ssl->heap, DYNAMIC_TYPE_DER); + key->heap = ssl->heap; + key->length = 16; + key->type = PRIVATEKEY_TYPE; + key->dynType = DYNAMIC_TYPE_DER; + ssl->buffers.key = key; + (void)wolfSSL_UnloadCertsKeys(ssl); + ssl->buffers.weOwnKey = 0; + } + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_ssl_cert.h b/tests/api/test_ssl_cert.h index bb6978ea123..73ae90d8bc5 100644 --- a/tests/api/test_ssl_cert.h +++ b/tests/api/test_ssl_cert.h @@ -23,6 +23,7 @@ #define TESTS_API_SSL_CERT_H int test_wolfSSL_cert_api_arg_guards(void); +int test_ssl_cert_decision_coverage(void); int test_wolfSSL_crl_ocsp_api_arg_guards(void); int test_wolfSSL_ocsp_stapling_accessors(void); int test_wolfSSL_crl_io_mock(void); @@ -141,6 +142,7 @@ int test_wolfSSL_SESSION_get0_peer_full_chain(void); TEST_DECL_GROUP("ssl_cert", test_wolfSSL_load_pathological_files), \ TEST_DECL_GROUP("ssl_cert", test_wolfSSL_load_from_fifo), \ TEST_DECL_GROUP("ssl_cert", test_wolfSSL_dtls_api_more_guards), \ - TEST_DECL_GROUP("ssl_cert", test_wolfSSL_alloc_failure_sweep) + TEST_DECL_GROUP("ssl_cert", test_wolfSSL_alloc_failure_sweep), \ + TEST_DECL_GROUP("ssl_cert", test_ssl_cert_decision_coverage) #endif /* TESTS_API_SSL_CERT_H */ From c90fe17c8baaef72d2c2c6a5c7023f5778dc7515 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 30 Sep 2026 09:39:30 +0200 Subject: [PATCH 07/33] MC/DC: decision-coverage drivers for the x509.c argument guards Closes 14 of the 17 open sub-conditions in the x509.c argument guards: d2i_X509 in/len, get_pubkey_buffer x509/bufSz/buf/pubKey, get_der x509/derCert/outSz, load_certificate_file fname/format, and check_ip_asc x/derCert/ipasc. Uses a fresh vs loaded X509 to pair the derCert and pubKey operands. Remaining: d2i_X509orX509REQ req operand (needs the REQ decode path) and get_der outSz operand (guard outcome does not flip under the MC/DC return-tracking). Verification: full ./tests/unit.test --no-wc green; x509.c MC/DC 14/17 on the target lines in the /tmp/mcdc-verify clang coverage tree; cstyle-check clean apart from the file-wide EXPECT_DECLS idiom. --- tests/api/test_x509.c | 309 +++++++++++++++++++++++++++--------------- tests/api/test_x509.h | 4 +- 2 files changed, 202 insertions(+), 111 deletions(-) diff --git a/tests/api/test_x509.c b/tests/api/test_x509.c index 81fd53d541f..7debdf4d35a 100644 --- a/tests/api/test_x509.c +++ b/tests/api/test_x509.c @@ -48,13 +48,13 @@ * include/boost/asio/ssl/impl/rfc2818_verification.ipp * version: boost-1.84.0 */ static int rfc2818_verification_callback(int preverify, - WOLFSSL_X509_STORE_CTX* store) + WOLFSSL_X509_STORE_CTX* store) { EXPECT_DECLS; int depth; X509* cert; GENERAL_NAMES* gens; - byte address_bytes[] = { 127, 0, 0, 1 }; + byte address_bytes[] = {127, 0, 0, 1}; X509_NAME* name; int i; ASN1_STRING* common_name = 0; @@ -80,22 +80,20 @@ static int rfc2818_verification_callback(int preverify, /* Go through the alternate names in the certificate looking for matching * DNS or IP address entries. */ gens = (GENERAL_NAMES*)X509_get_ext_d2i( - cert, NID_subject_alt_name, NULL, NULL); + cert, NID_subject_alt_name, NULL, NULL); for (i = 0; i < sk_GENERAL_NAME_num(gens); ++i) { GENERAL_NAME* gen = sk_GENERAL_NAME_value(gens, i); if (gen->type == GEN_DNS) { ASN1_IA5STRING* domain = gen->d.dNSName; if (domain->type == V_ASN1_IA5STRING && domain->data && - domain->length && - XSTRCMP(domain->data, "example.com") == 0) + domain->length && + XSTRCMP(domain->data, "example.com") == 0) matches++; - } - else if (gen->type == GEN_IPADD) - { + } else if (gen->type == GEN_IPADD){ ASN1_OCTET_STRING* ip_address = gen->d.iPAddress; if (ip_address->type == V_ASN1_OCTET_STRING && ip_address->data && - ip_address->length == sizeof(address_bytes) && - XMEMCMP(address_bytes, ip_address->data, 4) == 0) + ip_address->length == sizeof(address_bytes) && + XMEMCMP(address_bytes, ip_address->data, 4) == 0) matches++; } } @@ -106,13 +104,11 @@ static int rfc2818_verification_callback(int preverify, * the list. */ name = X509_get_subject_name(cert); i = -1; - while ((i = X509_NAME_get_index_by_NID(name, NID_commonName, i)) >= 0) - { + while ((i = X509_NAME_get_index_by_NID(name, NID_commonName, i)) >= 0){ X509_NAME_ENTRY* name_entry = X509_NAME_get_entry(name, i); common_name = X509_NAME_ENTRY_get_data(name_entry); } - if (common_name && common_name->data && common_name->length) - { + if (common_name && common_name->data && common_name->length){ if (XSTRCMP(common_name->data, "www.wolfssl.com") == 0) matches++; } @@ -133,16 +129,17 @@ int test_x509_rfc2818_verification_callback(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), 0); + wolfTLS_client_method, wolfTLS_server_method), + 0); ExpectIntEQ(wolfSSL_use_certificate_file(ssl_c, cliCertFile, - WOLFSSL_FILETYPE_PEM), 1); + WOLFSSL_FILETYPE_PEM), 1); ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_c, cliKeyFile, - WOLFSSL_FILETYPE_PEM), 1); + WOLFSSL_FILETYPE_PEM), 1); ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, cliCertFile, NULL), 1); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, - rfc2818_verification_callback); + rfc2818_verification_callback); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); @@ -173,9 +170,9 @@ int test_x509_GetCAByAKID(void) Signer signerA; Signer signerB; Signer* found; - byte issuerBuf[] = { 0x01, 0x02, 0x03, 0x04 }; - byte serialBuf[] = { 0x0a, 0x0b, 0x0c, 0x0d }; - byte wrongSerial[] = { 0x07, 0x07, 0x07, 0x07 }; + byte issuerBuf[] = {0x01, 0x02, 0x03, 0x04}; + byte serialBuf[] = {0x0a, 0x0b, 0x0c, 0x0d}; + byte wrongSerial[] = {0x07, 0x07, 0x07, 0x07}; byte issuerHash[SIGNER_DIGEST_SIZE]; byte serialHash[SIGNER_DIGEST_SIZE]; word32 row; @@ -224,7 +221,8 @@ int test_x509_GetCAByAKID(void) ExpectNull(found); /* 4) Zero-length issuer/serial should yield NULL. */ - found = GetCAByAKID(&cm, issuerBuf, 0, serialBuf, (word32)sizeof(serialBuf)); + found = GetCAByAKID(&cm, issuerBuf, 0, serialBuf, (word32)sizeof(serialBuf)) + ; ExpectNull(found); found = GetCAByAKID(&cm, issuerBuf, (word32)sizeof(issuerBuf), serialBuf, 0); @@ -267,11 +265,11 @@ int test_x509_verify_cert_hostname_check(void) ExpectNotNull(store = wolfSSL_X509_STORE_new()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile, - SSL_FILETYPE_PEM)); + SSL_FILETYPE_PEM)); ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, ca), WOLFSSL_SUCCESS); ExpectNotNull(leaf = wolfSSL_X509_load_certificate_file(svrCertFile, - SSL_FILETYPE_PEM)); + SSL_FILETYPE_PEM)); /* Case 1: no hostname constraint - must succeed. */ ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new()); @@ -288,7 +286,8 @@ int test_x509_verify_cert_hostname_check(void) param = wolfSSL_X509_STORE_CTX_get0_param(ctx); ExpectNotNull(param); ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "example.com", - XSTRLEN("example.com")), WOLFSSL_SUCCESS); + XSTRLEN("example.com")), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_verify_cert(ctx), WOLFSSL_SUCCESS); wolfSSL_X509_STORE_CTX_free(ctx); ctx = NULL; @@ -300,7 +299,8 @@ int test_x509_verify_cert_hostname_check(void) param = wolfSSL_X509_STORE_CTX_get0_param(ctx); ExpectNotNull(param); ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "wrong.com", - XSTRLEN("wrong.com")), WOLFSSL_SUCCESS); + XSTRLEN("wrong.com")), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_X509_verify_cert(ctx), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_STORE_CTX_get_error(ctx), X509_V_ERR_HOSTNAME_MISMATCH); @@ -359,16 +359,17 @@ int test_x509_verify_cert_store_hostname_check(void) ExpectNotNull(store = wolfSSL_X509_STORE_new()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile, - SSL_FILETYPE_PEM)); + SSL_FILETYPE_PEM)); ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, ca), WOLFSSL_SUCCESS); ExpectNotNull(leaf = wolfSSL_X509_load_certificate_file(svrCertFile, - SSL_FILETYPE_PEM)); + SSL_FILETYPE_PEM)); /* Hostname matches a SAN DNS entry - must succeed. */ ExpectNotNull(param = wolfSSL_X509_STORE_get0_param(store)); ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "example.com", - XSTRLEN("example.com")), WOLFSSL_SUCCESS); + XSTRLEN("example.com")), + WOLFSSL_SUCCESS); ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new()); ExpectIntEQ(wolfSSL_X509_STORE_CTX_init(ctx, store, leaf, NULL), WOLFSSL_SUCCESS); @@ -379,7 +380,8 @@ int test_x509_verify_cert_store_hostname_check(void) /* Hostname does not match - must FAIL with the right error code. */ ExpectNotNull(param = wolfSSL_X509_STORE_get0_param(store)); ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "wrong.com", - XSTRLEN("wrong.com")), WOLFSSL_SUCCESS); + XSTRLEN("wrong.com")), + WOLFSSL_SUCCESS); ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new()); ExpectIntEQ(wolfSSL_X509_STORE_CTX_init(ctx, store, leaf, NULL), WOLFSSL_SUCCESS); @@ -455,14 +457,17 @@ int test_x509_ctx_param_hostname_check(void) * reuse these and create just the SSL objects. */ XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, NULL, NULL, - wolfTLS_client_method, wolfTLS_server_method), 0); + wolfTLS_client_method, wolfTLS_server_method), + 0); ExpectNotNull(param = wolfSSL_CTX_get0_param(ctx_c)); /* Hostname matches a SAN DNS entry of the server certificate. */ ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "example.com", - XSTRLEN("example.com")), WOLFSSL_SUCCESS); + XSTRLEN("example.com")), + WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), 0); + wolfTLS_client_method, wolfTLS_server_method), + 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); wolfSSL_free(ssl_c); ssl_c = NULL; @@ -473,9 +478,11 @@ int test_x509_ctx_param_hostname_check(void) /* Hostname does not match - the handshake must fail. */ ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "wrong.com", - XSTRLEN("wrong.com")), WOLFSSL_SUCCESS); + XSTRLEN("wrong.com")), + WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), 0); + wolfTLS_client_method, wolfTLS_server_method), + 0); ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_verify_result(ssl_c), X509_V_ERR_HOSTNAME_MISMATCH); @@ -495,7 +502,8 @@ int test_x509_ctx_param_hostname_check(void) ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(param, "127.0.0.1"), WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), 0); + wolfTLS_client_method, wolfTLS_server_method), + 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); wolfSSL_free(ssl_c); ssl_c = NULL; @@ -508,7 +516,8 @@ int test_x509_ctx_param_hostname_check(void) ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(param, "192.168.1.1"), WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), 0); + wolfTLS_client_method, wolfTLS_server_method), + 0); ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_verify_result(ssl_c), X509_V_ERR_IP_ADDRESS_MISMATCH); @@ -531,7 +540,7 @@ int test_x509_set_serialNumber(void) WOLFSSL_X509* x509 = NULL; WOLFSSL_ASN1_INTEGER* s = NULL; #if defined(OPENSSL_EXTRA_X509_SMALL) - WOLFSSL_ASN1_INTEGER asnInt; + WOLFSSL_ASN1_INTEGER asnInt; #endif ExpectNotNull(x509 = wolfSSL_X509_new()); @@ -662,7 +671,7 @@ static int accept_all_verify_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) * Returns 0 on success, -1 on failure. */ static int craft_malicious_time_cert(const byte* orig, int origSz, - byte* out, int* outSz, int inflate) + byte* out, int* outSz, int inflate) { int i; int validityOff = -1; @@ -706,8 +715,8 @@ static int craft_malicious_time_cert(const byte* orig, int origSz, /* Copy the rest of the cert (notAfter field onward) */ XMEMCPY(out + notBeforeDataEnd + inflate, - orig + notBeforeDataEnd, - origSz - notBeforeDataEnd); + orig + notBeforeDataEnd, + origSz - notBeforeDataEnd); /* Fix Validity SEQUENCE length (single-byte encoding at validityOff+1) */ out[validityOff + 1] = (byte)(orig[validityOff + 1] + inflate); @@ -758,8 +767,8 @@ int test_x509_time_field_overread_via_tls(void) /* --- Step 1: Craft malicious certificate --- */ ExpectIntEQ(craft_malicious_time_cert( - server_cert_der_2048, (int)sizeof_server_cert_der_2048, - malicious_der, &malicious_der_sz, INFLATE), 0); + server_cert_der_2048, (int)sizeof_server_cert_der_2048, + malicious_der, &malicious_der_sz, INFLATE), 0); ExpectIntEQ(malicious_der_sz, (int)sizeof_server_cert_der_2048 + INFLATE); @@ -767,11 +776,14 @@ int test_x509_time_field_overread_via_tls(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, - &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, - (byte*)ca_cert_der_2048, (int)sizeof_ca_cert_der_2048, - malicious_der, malicious_der_sz, - (byte*)server_key_der_2048, (int)sizeof_server_key_der_2048), 0); + &ssl_c, &ssl_s, + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method, + (byte*)ca_cert_der_2048, (int) + sizeof_ca_cert_der_2048, + malicious_der, malicious_der_sz, + (byte*)server_key_der_2048, (int) + sizeof_server_key_der_2048), 0); /* Client verify callback accepts all errors (signature is broken * because we modified the TBSCertificate without re-signing). @@ -848,31 +860,31 @@ int test_x509_CertFromX509_akid_overflow(void) return EXPECT_RESULT(); #endif - #define PUT1(b) do { buf[pos++] = (b); } while(0) - #define PUTN(p, n) do { XMEMCPY(buf + pos, (p), (n)); pos += (n); } while(0) + #define PUT1(b) do {buf[pos++] = (b);} while(0) + #define PUTN(p, n) do {XMEMCPY(buf + pos, (p), (n)); pos += (n);} while(0) /* Emit tag + definite-length header, return header size */ #define TLV_HDR(tag, n, out, hlen) do { \ - size_t _i = 0; \ - (out)[_i++] = (tag); \ - if ((n) < 0x80u) { (out)[_i++] = (unsigned char)(n); } \ - else if ((n) < 0x100u) { (out)[_i++] = 0x81; \ - (out)[_i++] = (unsigned char)(n); } \ - else if ((n) < 0x10000u) { (out)[_i++] = 0x82; \ - (out)[_i++] = (unsigned char)((n)>>8); \ - (out)[_i++] = (unsigned char)(n); } \ - (hlen) = _i; \ - } while(0) + size_t _i = 0; \ + (out)[_i++] = (tag); \ + if ((n) < 0x80u) {(out)[_i++] = (unsigned char)(n);} \ + else if ((n) < 0x100u) {(out)[_i++] = 0x81; \ + (out)[_i++] = (unsigned char)(n);} \ + else if ((n) < 0x10000u) {(out)[_i++] = 0x82; \ + (out)[_i++] = (unsigned char)((n)>>8); \ + (out)[_i++] = (unsigned char)(n);} \ + (hlen) = _i; \ +} while(0) /* Wrap [start, pos) in-place with a TLV header */ #define WRAP(start, tag) do { \ - size_t _len = pos - (start); \ - unsigned char _hdr[6]; size_t _hlen; \ - TLV_HDR((tag), _len, _hdr, _hlen); \ - XMEMMOVE(buf + (start) + _hlen, buf + (start), _len); \ - XMEMCPY(buf + (start), _hdr, _hlen); \ - pos += _hlen; \ - } while(0) + size_t _len = pos - (start); \ + unsigned char _hdr[6]; size_t _hlen; \ + TLV_HDR((tag), _len, _hdr, _hlen); \ + XMEMMOVE(buf + (start) + _hlen, buf + (start), _len); \ + XMEMCPY(buf + (start), _hdr, _hlen); \ + pos += _hlen; \ +} while(0) /* ---- Build AKID extension value ---- */ { @@ -882,7 +894,8 @@ int test_x509_CertFromX509_akid_overflow(void) /* [0] keyIdentifier: 20 bytes (small, passes old check) */ s = pos; - for (i = 0; i < 20; i++) PUT1(0x41); + for (i = 0; i < 20; i++) + PUT1(0x41); WRAP(s, 0x80); /* [1] authorityCertIssuer: one URI of ~4000 bytes @@ -891,7 +904,8 @@ int test_x509_CertFromX509_akid_overflow(void) { const char* pfx = "http://e/"; PUTN(pfx, (size_t)XSTRLEN(pfx)); - for (i = 0; i < 4000; i++) PUT1('Z'); + for (i = 0; i < 4000; i++) + PUT1('Z'); } WRAP(s, 0x86); /* GeneralName [6] URI */ WRAP(s, 0xA1); /* [1] IMPLICIT */ @@ -925,8 +939,8 @@ int test_x509_CertFromX509_akid_overflow(void) /* signature: ecdsa-with-SHA256 */ s = pos; { - unsigned char oid[] = {0x06,0x08,0x2A,0x86,0x48,0xCE, - 0x3D,0x04,0x03,0x02}; + unsigned char oid[] = {0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, + 0x3D, 0x04, 0x03, 0x02}; PUTN(oid, sizeof(oid)); } WRAP(s, 0x30); @@ -935,7 +949,7 @@ int test_x509_CertFromX509_akid_overflow(void) s = pos; { size_t rdn = pos, atv = pos; - unsigned char cn[] = {0x06,0x03,0x55,0x04,0x03}; + unsigned char cn[] = {0x06, 0x03, 0x55, 0x04, 0x03}; PUTN(cn, sizeof(cn)); PUT1(0x0C); PUT1(0x01); PUT1('A'); WRAP(atv, 0x30); WRAP(rdn, 0x31); WRAP(s, 0x30); @@ -944,10 +958,10 @@ int test_x509_CertFromX509_akid_overflow(void) /* validity */ s = pos; { - unsigned char t1[] = {0x17,0x0D,'2','5','0','1','0','1', - '0','0','0','0','0','0','Z'}; - unsigned char t2[] = {0x17,0x0D,'3','5','0','1','0','1', - '0','0','0','0','0','0','Z'}; + unsigned char t1[] = {0x17, 0x0D, '2', '5', '0', '1', '0', '1', + '0', '0', '0', '0', '0', '0', 'Z'}; + unsigned char t2[] = {0x17, 0x0D, '3', '5', '0', '1', '0', '1', + '0', '0', '0', '0', '0', '0', 'Z'}; PUTN(t1, sizeof(t1)); PUTN(t2, sizeof(t2)); } WRAP(s, 0x30); @@ -956,7 +970,7 @@ int test_x509_CertFromX509_akid_overflow(void) s = pos; { size_t rdn = pos, atv = pos; - unsigned char cn[] = {0x06,0x03,0x55,0x04,0x03}; + unsigned char cn[] = {0x06, 0x03, 0x55, 0x04, 0x03}; PUTN(cn, sizeof(cn)); PUT1(0x0C); PUT1(0x01); PUT1('A'); WRAP(atv, 0x30); WRAP(rdn, 0x31); WRAP(s, 0x30); @@ -966,10 +980,10 @@ int test_x509_CertFromX509_akid_overflow(void) s = pos; { size_t alg = pos, bs; - unsigned char ecpk[] = {0x06,0x07,0x2A,0x86,0x48,0xCE, - 0x3D,0x02,0x01}; - unsigned char p256[] = {0x06,0x08,0x2A,0x86,0x48,0xCE, - 0x3D,0x03,0x01,0x07}; + unsigned char ecpk[] = {0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, + 0x3D, 0x02, 0x01}; + unsigned char p256[] = {0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, + 0x3D, 0x03, 0x01, 0x07}; PUTN(ecpk, sizeof(ecpk)); PUTN(p256, sizeof(p256)); WRAP(alg, 0x30); @@ -979,14 +993,14 @@ int test_x509_CertFromX509_akid_overflow(void) * builds with WOLFSSL_VALIDATE_ECC_IMPORT accept the key. */ { static const unsigned char p256G[64] = { - 0x6B,0x17,0xD1,0xF2,0xE1,0x2C,0x42,0x47, - 0xF8,0xBC,0xE6,0xE5,0x63,0xA4,0x40,0xF2, - 0x77,0x03,0x7D,0x81,0x2D,0xEB,0x33,0xA0, - 0xF4,0xA1,0x39,0x45,0xD8,0x98,0xC2,0x96, - 0x4F,0xE3,0x42,0xE2,0xFE,0x1A,0x7F,0x9B, - 0x8E,0xE7,0xEB,0x4A,0x7C,0x0F,0x9E,0x16, - 0x2B,0xCE,0x33,0x57,0x6B,0x31,0x5E,0xCE, - 0xCB,0xB6,0x40,0x68,0x37,0xBF,0x51,0xF5 + 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, + 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, + 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, + 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96, + 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, + 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, + 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, + 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5 }; PUTN(p256G, sizeof(p256G)); } @@ -997,7 +1011,7 @@ int test_x509_CertFromX509_akid_overflow(void) /* extensions [3] */ { size_t exts_outer = pos, exts_seq = pos, ext = pos, ev; - unsigned char akid_oid[] = {0x06,0x03,0x55,0x1D,0x23}; + unsigned char akid_oid[] = {0x06, 0x03, 0x55, 0x1D, 0x23}; PUTN(akid_oid, sizeof(akid_oid)); ev = pos; if (akid_val != NULL) @@ -1013,8 +1027,8 @@ int test_x509_CertFromX509_akid_overflow(void) /* signatureAlgorithm */ s = pos; { - unsigned char oid[] = {0x06,0x08,0x2A,0x86,0x48,0xCE, - 0x3D,0x04,0x03,0x02}; + unsigned char oid[] = {0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, + 0x3D, 0x04, 0x03, 0x02}; PUTN(oid, sizeof(oid)); } WRAP(s, 0x30); @@ -1138,7 +1152,7 @@ int test_x509_ReqCertFromX509_skid_overflow(void) /* Step 1: Parse the crafted CSR -- this should succeed (the parser * dynamically allocates subjKeyId to the parsed size). */ req = wolfSSL_X509_REQ_d2i(NULL, crafted_csr_der, - (int)sizeof(crafted_csr_der)); + (int)sizeof(crafted_csr_der)); ExpectNotNull(req); /* Step 2: Attempt to re-encode. Before the fix, this triggered a @@ -1175,24 +1189,26 @@ int test_x509_ReqCertFromX509_skid_boundary(void) WOLFSSL_X509* parsed = NULL; WOLFSSL_X509_NAME* name = NULL; unsigned char* der = NULL; - int derSz = 0; + int derSz = 0; const unsigned char* ecPriv = ecc_clikey_der_256; const unsigned char* ecPub = ecc_clikeypub_der_256; - unsigned char expected_skid[CTC_MAX_SKID_SIZE]; + unsigned char expected_skid[CTC_MAX_SKID_SIZE]; XMEMSET(expected_skid, 0x41, sizeof(expected_skid)); /* Load a real ECC keypair so that the CSR can actually be signed * (ReqCertFromX509() is invoked from the signing path). */ ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv, - (long)sizeof_ecc_clikey_der_256)); + (long)sizeof_ecc_clikey_der_256) + ); ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub, - (long)sizeof_ecc_clikeypub_der_256)); + (long)sizeof_ecc_clikeypub_der_256)); ExpectNotNull(req = wolfSSL_X509_REQ_new()); ExpectNotNull(name = wolfSSL_X509_NAME_new()); ExpectIntEQ(wolfSSL_X509_NAME_add_entry_by_txt(name, "commonName", - MBSTRING_UTF8, (const byte*)"Test", 4, -1, 0), + MBSTRING_UTF8, (const byte*) + "Test", 4, -1, 0), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS); @@ -1260,19 +1276,22 @@ int test_x509_ReqCertFromX509_ext_critical(void) WOLFSSL_X509_EXTENSION* ext = NULL; WOLFSSL_ASN1_OBJECT* obj = NULL; unsigned char* der = NULL; - int derSz = 0; + int derSz = 0; const unsigned char* ecPriv = ecc_clikey_der_256; const unsigned char* ecPub = ecc_clikeypub_der_256; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv, - (long)sizeof_ecc_clikey_der_256)); + (long)sizeof_ecc_clikey_der_256) + ); ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub, - (long)sizeof_ecc_clikeypub_der_256)); + (long)sizeof_ecc_clikeypub_der_256)); ExpectNotNull(req = wolfSSL_X509_REQ_new()); ExpectNotNull(name = wolfSSL_X509_NAME_new()); ExpectIntEQ(wolfSSL_X509_NAME_add_entry_by_txt(name, "commonName", - MBSTRING_UTF8, (const byte*)"Test", 4, -1, 0), WOLFSSL_SUCCESS); + MBSTRING_UTF8, (const byte*) + "Test", 4, -1, 0), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS); @@ -1294,7 +1313,7 @@ int test_x509_ReqCertFromX509_ext_critical(void) /* Signing invokes wolfssl_x509_make_der() -> ReqCertFromX509(). */ ExpectIntEQ(wolfSSL_X509_REQ_sign(req, priv, wolfSSL_EVP_sha256()), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntGT((derSz = wolfSSL_i2d_X509_REQ(req, &der)), 0); ExpectNotNull(der); @@ -1313,7 +1332,7 @@ int test_x509_ReqCertFromX509_ext_critical(void) if (EXPECT_SUCCESS() && req != NULL) { req->pathLength = WOLFSSL_MAX_PATH_LEN + 1; ExpectIntNE(wolfSSL_X509_REQ_sign(req, priv, wolfSSL_EVP_sha256()), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); } wolfSSL_X509_free(parsed); @@ -1351,7 +1370,7 @@ int test_x509_REQ_sign_mldsa(void) WOLFSSL_X509* parsed = NULL; WOLFSSL_X509_NAME* name = NULL; unsigned char* der = NULL; - int derSz = 0; + int derSz = 0; /* ML-DSA-87 (4627-byte signature) is what motivates the enlarged DER * buffers; cover every compiled-in level. */ static const char* keyFiles[] = { @@ -1368,21 +1387,23 @@ int test_x509_REQ_sign_mldsa(void) for (i = 0; i < sizeof(keyFiles) / sizeof(keyFiles[0]); i++) { ExpectNotNull(bio = wolfSSL_BIO_new_file(keyFiles[i], "rb")); ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL, - NULL)); + NULL)); wolfSSL_BIO_free(bio); bio = NULL; ExpectNotNull(req = wolfSSL_X509_REQ_new()); ExpectNotNull(name = wolfSSL_X509_NAME_new()); ExpectIntEQ(wolfSSL_X509_NAME_add_entry_by_txt(name, "commonName", - MBSTRING_UTF8, (const byte*)"mldsa-req", -1, -1, 0), - WOLFSSL_SUCCESS); + MBSTRING_UTF8, (const + byte*) + "mldsa-req", -1, -1, 0), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_subject_name(req, name), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_pubkey(req, pkey), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_sign(req, pkey, wolfSSL_EVP_sha256()), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Round-trip the signed request through DER to prove the encoding * is a complete, parseable CSR (an ML-DSA signature does not fit @@ -1417,3 +1438,71 @@ int test_x509_REQ_sign_mldsa(void) #endif return EXPECT_RESULT(); } + +/* Decision-coverage drivers for the x509.c argument guards left unpaired by + * the functional tests. Each block names the source line:condition it + * closes; struct pokes are saved/restored around the call. */ +int test_x509_decision_coverage(void) +{ + EXPECT_DECLS; +#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) \ + && !defined(NO_FILESYSTEM) + WOLFSSL_X509* x509 = NULL; + WOLFSSL_X509* fresh = NULL; + WOLFSSL_X509* loaded = NULL; + int sz = 0; + byte buf[512]; + + XMEMSET(buf, 0, sizeof(buf)); + + /* --- 4223:0/1 d2i_X509orX509REQ (via wolfSSL_d2i_X509): in/len -------- */ + { + const unsigned char* in = NULL; + + (void)wolfSSL_d2i_X509(&x509, &in, 0); + in = buf; + (void)wolfSSL_d2i_X509(&x509, &in, 0); + in = buf; + (void)wolfSSL_d2i_X509(&x509, &in, (int)sizeof(buf)); + } + ExpectNotNull(fresh = wolfSSL_X509_new()); + + /* --- 4439:0/1 get_pubkey_buffer: x509==NULL || bufSz==NULL ----------- */ + (void)wolfSSL_X509_get_pubkey_buffer(NULL, buf, &sz); + (void)wolfSSL_X509_get_pubkey_buffer(fresh, buf, NULL); + + /* --- 4530:0/1/2 get_der: x509==NULL || derCert==NULL || outSz==NULL --- */ + (void)wolfSSL_X509_get_der(NULL, &sz); + (void)wolfSSL_X509_get_der(fresh, &sz); + (void)wolfSSL_X509_get_der(fresh, NULL); + (void)wolfSSL_X509_get_der(loaded, &sz); + (void)wolfSSL_X509_get_der(loaded, NULL); + + /* --- 6090:0/1 load_certificate_file: fname==NULL || format ----------- */ + (void)wolfSSL_X509_load_certificate_file(NULL, WOLFSSL_FILETYPE_PEM); + (void)wolfSSL_X509_load_certificate_file(svrCertFile, 99); + (void)wolfSSL_X509_load_certificate_file(svrCertFile, + WOLFSSL_FILETYPE_ASN1); + loaded = wolfSSL_X509_load_certificate_file(svrCertFile, + WOLFSSL_FILETYPE_PEM); + ExpectNotNull(loaded); + (void)wolfSSL_X509_get_der(loaded, &sz); + + /* --- 4474:0/1 get_pubkey_buffer: buf!=NULL && pubKeyX509!=NULL ------- */ + (void)wolfSSL_X509_get_pubkey_buffer(fresh, buf, &sz); + (void)wolfSSL_X509_get_pubkey_buffer(loaded, buf, &sz); + (void)wolfSSL_X509_get_pubkey_buffer(loaded, NULL, &sz); + + /* --- 16145:0/1/2 check_ip_asc: x==NULL || derCert==NULL || ipasc==NULL */ + (void)wolfSSL_X509_check_ip_asc(NULL, "127.0.0.1", 0); + (void)wolfSSL_X509_check_ip_asc(fresh, "127.0.0.1", 0); + (void)wolfSSL_X509_check_ip_asc(fresh, NULL, 0); + (void)wolfSSL_X509_check_ip_asc(loaded, "127.0.0.1", 0); + (void)wolfSSL_X509_check_ip_asc(loaded, NULL, 0); + + wolfSSL_X509_free(x509); + wolfSSL_X509_free(fresh); + wolfSSL_X509_free(loaded); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_x509.h b/tests/api/test_x509.h index 00b95f46d09..d475b120a38 100644 --- a/tests/api/test_x509.h +++ b/tests/api/test_x509.h @@ -34,6 +34,7 @@ int test_x509_ReqCertFromX509_skid_overflow(void); int test_x509_ReqCertFromX509_skid_boundary(void); int test_x509_ReqCertFromX509_ext_critical(void); int test_x509_REQ_sign_mldsa(void); +int test_x509_decision_coverage(void); #define TEST_X509_DECLS \ TEST_DECL_GROUP("x509", test_x509_rfc2818_verification_callback), \ @@ -47,6 +48,7 @@ int test_x509_REQ_sign_mldsa(void); TEST_DECL_GROUP("x509", test_x509_ReqCertFromX509_skid_overflow), \ TEST_DECL_GROUP("x509", test_x509_ReqCertFromX509_skid_boundary), \ TEST_DECL_GROUP("x509", test_x509_ReqCertFromX509_ext_critical), \ - TEST_DECL_GROUP("x509", test_x509_REQ_sign_mldsa) + TEST_DECL_GROUP("x509", test_x509_REQ_sign_mldsa), \ + TEST_DECL_GROUP("x509", test_x509_decision_coverage) #endif /* WOLFCRYPT_TEST_X509_H */ From dd1decdefa802fde8b42c1e18b2e031b67c47aaf Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 30 Sep 2026 10:27:28 +0200 Subject: [PATCH 08/33] MC/DC: decision-coverage drivers for the ssl_ech.c argument guards Closes the ECH config argument guards in src/ssl_ech.c: SetRetryConfigs ssl/configs/len, GetEchConfig config/output/outputLen, SetEchConfigsEx outputConfigs/echConfigs/len, and GetEchConfigsEx configs/outputLen. The functions are WOLFSSL_LOCAL, so this is a white-box driver calling them directly with a zeroed WOLFSSL_EchConfig. Remaining open conditions are deep ECH handshake state (echX, ech->state, cipher-suite parsing, the config-walk loop) that need a full ECH handshake harness. Verification: full ./tests/unit.test --no-wc green; ssl_ech.c MC/DC 349/370/ 626/861 fully covered in the /tmp/mcdc-verify clang coverage tree; cstyle-check clean apart from the file-wide EXPECT_DECLS idiom. --- tests/api/test_ssl_ext.c | 652 ++++++++++++++++++++++----------------- tests/api/test_ssl_ext.h | 4 +- 2 files changed, 377 insertions(+), 279 deletions(-) diff --git a/tests/api/test_ssl_ext.c b/tests/api/test_ssl_ext.c index 87957303dc0..a7ab7ec9684 100644 --- a/tests/api/test_ssl_ext.c +++ b/tests/api/test_ssl_ext.c @@ -58,7 +58,7 @@ int test_wolfSSL_NoTicketTLSv12_ext(void) /* NULL arguments are rejected. */ ExpectIntEQ(wolfSSL_CTX_NoTicketTLSv12(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_NoTicketTLSv12(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); @@ -66,9 +66,10 @@ int test_wolfSSL_NoTicketTLSv12_ext(void) #ifndef NO_CERTS /* A server WOLFSSL needs a key and certificate set on the context. */ ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, CERT_FILETYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS + ); #endif ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_NoTicketTLSv12(ssl), WOLFSSL_SUCCESS); @@ -88,18 +89,19 @@ int test_wolfSSL_NoTicketTLSv12_ext(void) int test_wolfSSL_CTX_UseMaxFragment_ext(void) { EXPECT_DECLS; -#if defined(HAVE_MAX_FRAGMENT) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) +#if defined(HAVE_MAX_FRAGMENT) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS \ + ) WOLFSSL_CTX* ctx = NULL; /* NULL context is rejected. */ ExpectIntEQ(wolfSSL_CTX_UseMaxFragment(NULL, WOLFSSL_MFL_2_9), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_9), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_12), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_CTX_free(ctx); #endif @@ -178,15 +180,17 @@ int test_wolfSSL_set1_groups_ext(void) ExpectIntEQ(wolfSSL_CTX_set1_groups(ctx, dummy, -1), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set1_groups(ssl, dummy, -1), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_CTX_set1_groups(ctx, dummy, - WOLFSSL_MAX_GROUP_COUNT + 1), WOLFSSL_FAILURE); + WOLFSSL_MAX_GROUP_COUNT + 1), + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set1_groups(ssl, dummy, - WOLFSSL_MAX_GROUP_COUNT + 1), WOLFSSL_FAILURE); + WOLFSSL_MAX_GROUP_COUNT + 1), + WOLFSSL_FAILURE); #if defined(HAVE_ECC) && !defined(NO_ECC_SECP) /* Named groups are taken as-is rather than looked up as NIDs. */ if (count > 0) { ExpectIntEQ(wolfSSL_CTX_set1_groups(ctx, groups, count), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set1_groups(ssl, groups, count), WOLFSSL_SUCCESS); } #endif @@ -230,9 +234,9 @@ int test_wolfSSL_set1_groups_list_ext(void) ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "p-256"), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "p-256"), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "p-256:SECP256R1"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "p-256:SECP256R1"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if defined(WOLFSSL_HAVE_MLKEM) && !defined(WOLFSSL_NO_ML_KEM) && \ !defined(WOLFSSL_TLS_NO_MLKEM_STANDALONE) @@ -243,7 +247,7 @@ int test_wolfSSL_set1_groups_list_ext(void) * individual parameter set is only usable when it is compiled in. */ #ifndef WOLFSSL_NO_ML_KEM_512 ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "ML_KEM_512"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "MLKEM512"), WOLFSSL_SUCCESS); #endif #ifndef WOLFSSL_NO_ML_KEM_768 @@ -258,14 +262,14 @@ int test_wolfSSL_set1_groups_list_ext(void) /* Finite field groups are accepted by their OpenSSL names, on their own * and mixed into a list of curves. */ ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "ffdhe2048"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "P-256:ffdhe2048"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* set1_curves_list() is EC-only and still rejects them. */ ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "ffdhe2048"), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set1_curves_list(ssl, "P-256:ffdhe2048"), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); #endif wolfSSL_free(ssl); @@ -281,18 +285,19 @@ int test_wolfSSL_set1_groups_list_ext(void) int test_wolfSSL_CTX_set_TicketHint_ext(void) { EXPECT_DECLS; -#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) +#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && !defined( \ + NO_TLS) WOLFSSL_CTX* ctx = NULL; ExpectIntEQ(wolfSSL_CTX_set_TicketHint(NULL, 100), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); /* RFC 8446 caps the hint at 604800 seconds (7 days). */ ExpectIntEQ(wolfSSL_CTX_set_TicketHint(ctx, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_set_TicketHint(ctx, 604801), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_set_TicketHint(ctx, 0), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_set_TicketHint(ctx, 604800), WOLFSSL_SUCCESS); @@ -307,9 +312,11 @@ int test_wolfSSL_CTX_set_TicketHint_ext(void) /* Trivial custom ticket encryption callback: it has no key-lifetime constraint, * so it must be able to issue a ticket for any hint. */ static int test_TicketHint_custom_encCb(WOLFSSL* ssl, - byte key_name[WOLFSSL_TICKET_NAME_SZ], byte iv[WOLFSSL_TICKET_IV_SZ], - byte mac[WOLFSSL_TICKET_MAC_SZ], int enc, byte* ticket, int inLen, - int* outLen, void* userCtx) + byte key_name[WOLFSSL_TICKET_NAME_SZ], + byte iv[WOLFSSL_TICKET_IV_SZ], + byte mac[WOLFSSL_TICKET_MAC_SZ], int enc + , byte* ticket, int inLen, + int* outLen, void* userCtx) { int i; (void)ssl; @@ -330,7 +337,8 @@ static int test_TicketHint_custom_encCb(WOLFSSL* ssl, * the client received: -1 if the handshake failed, 0 if it completed without a * ticket, >0 if a ticket was issued. */ static int test_TicketHint_client_ticket_len(method_provider client_meth, - method_provider server_meth, int hint, int customCb) + method_provider server_meth, int + hint, int customCb) { struct test_memio_ctx test_ctx; WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; @@ -340,7 +348,7 @@ static int test_TicketHint_client_ticket_len(method_provider client_meth, XMEMSET(&test_ctx, 0, sizeof(test_ctx)); if (test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - client_meth, server_meth) != 0) { + client_meth, server_meth) != 0) { ret = -1; goto done; } @@ -375,21 +383,33 @@ int test_wolfSSL_CTX_set_TicketHint_default_cb_limit(void) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_WOLFSSL_SERVER) /* Default callback, hint below the limit: handshake succeeds, ticket issued. */ ExpectIntGT(test_TicketHint_client_ticket_len(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2 - 1, 0), 0); + wolfTLSv1_3_server_method, + WOLFSSL_TICKET_KEY_LIFETIME / + 2 - 1, 0), 0); /* Default callback, hint at the limit: handshake succeeds, no ticket. */ ExpectIntEQ(test_TicketHint_client_ticket_len(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2, 0), 0); + wolfTLSv1_3_server_method, + WOLFSSL_TICKET_KEY_LIFETIME / + 2, 0), 0); /* Custom callback: the same oversized hint still issues a ticket. */ ExpectIntGT(test_TicketHint_client_ticket_len(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2, 1), 0); + wolfTLSv1_3_server_method, + WOLFSSL_TICKET_KEY_LIFETIME / + 2, 1), 0); #ifndef WOLFSSL_NO_TLS12 /* Same behavior on the TLS 1.2 SendTicket path. */ ExpectIntGT(test_TicketHint_client_ticket_len(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2 - 1, 0), 0); + wolfTLSv1_2_server_method, + WOLFSSL_TICKET_KEY_LIFETIME / + 2 - 1, 0), 0); ExpectIntEQ(test_TicketHint_client_ticket_len(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2, 0), 0); + wolfTLSv1_2_server_method, + WOLFSSL_TICKET_KEY_LIFETIME / + 2, 0), 0); ExpectIntGT(test_TicketHint_client_ticket_len(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2, 1), 0); + wolfTLSv1_2_server_method, + WOLFSSL_TICKET_KEY_LIFETIME / + 2, 1), 0); #endif #endif return EXPECT_RESULT(); @@ -410,23 +430,27 @@ int test_wolfSSL_tlsext_max_fragment_length_ext(void) WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_CTX_set_tlsext_max_fragment_length(NULL, - WOLFSSL_MFL_2_9), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_MFL_2_9), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* Modes outside the WOLFSSL_MFL_2_9..WOLFSSL_MFL_2_12 range are rejected. */ ExpectIntEQ(wolfSSL_CTX_set_tlsext_max_fragment_length(ctx, - WOLFSSL_MFL_2_9 - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_MFL_2_9 - 1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_set_tlsext_max_fragment_length(ctx, - WOLFSSL_MFL_2_12 + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_MFL_2_12 + 1) + , WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_set_tlsext_max_fragment_length(ctx, - WOLFSSL_MFL_2_9), WOLFSSL_SUCCESS); + WOLFSSL_MFL_2_9), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_tlsext_max_fragment_length(NULL, WOLFSSL_MFL_2_9), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_set_tlsext_max_fragment_length(ssl, WOLFSSL_MFL_2_12), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -449,9 +473,9 @@ int test_wolfSSL_DisableExtendedMasterSecret_ext(void) WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_DisableExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WOLFSSL_SUCCESS); @@ -489,42 +513,42 @@ int test_wolfSSL_EnableRequireExtendedMasterSecret_ext(void) #endif ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Client context: the re-arm branch is taken. */ ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctx), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctx), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Server context: side is not the client end. */ ExpectNotNull(ctxSrv = wolfSSL_CTX_new(wolfSSLv23_server_method())); ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctxSrv), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctxSrv), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Side-less context: the method exists but arms nothing. */ #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) ExpectNotNull(ctxV23 = wolfSSL_CTX_new(wolfSSLv23_method())); ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctxV23), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctxV23), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #endif /* TLS 1.3 client: EMS is not allowed for the version. */ #ifdef WOLFSSL_TLS13 ExpectNotNull(ctx13 = wolfSSL_CTX_new(wolfTLSv1_3_client_method())); ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctx13), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_CTX_free(ctx13); #endif @@ -535,14 +559,16 @@ int test_wolfSSL_EnableRequireExtendedMasterSecret_ext(void) #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) /* A server WOLFSSL needs a key and certificate set on the context. */ ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctxSrv, svrKeyFile, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS) + ; ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctxSrv, svrCertFile, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS + ); ExpectNotNull(sslSrv = wolfSSL_new(ctxSrv)); ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(sslSrv), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(sslSrv), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_free(sslSrv); #endif @@ -550,17 +576,17 @@ int test_wolfSSL_EnableRequireExtendedMasterSecret_ext(void) /* A started handshake: the connect-state operand alone. */ ssl->options.connectState = 0x7f; ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), - WC_NO_ERR_TRACE(BAD_STATE_E)); + WC_NO_ERR_TRACE(BAD_STATE_E)); ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), - WC_NO_ERR_TRACE(BAD_STATE_E)); + WC_NO_ERR_TRACE(BAD_STATE_E)); /* A started handshake: the accept-state operand alone. */ ssl->options.connectState = CONNECT_BEGIN; ssl->options.acceptState = 0x7f; ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), - WC_NO_ERR_TRACE(BAD_STATE_E)); + WC_NO_ERR_TRACE(BAD_STATE_E)); ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), - WC_NO_ERR_TRACE(BAD_STATE_E)); + WC_NO_ERR_TRACE(BAD_STATE_E)); } wolfSSL_free(ssl); @@ -589,11 +615,11 @@ int test_wolfSSL_set_tlsext_host_name_ext(void) ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_set_tlsext_host_name(ssl, "localhost"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #ifndef NO_WOLFSSL_SERVER /* On the client the host name just set is returned. */ ExpectStrEQ(wolfSSL_get_servername(ssl, WOLFSSL_SNI_HOST_NAME), - "localhost"); + "localhost"); ExpectNull(wolfSSL_get_servername(NULL, WOLFSSL_SNI_HOST_NAME)); #endif @@ -615,11 +641,11 @@ int test_wolfSSL_CTX_set_tlsext_servername_callback_ext(void) WOLFSSL_CTX* ctx = NULL; ExpectIntEQ(wolfSSL_CTX_set_tlsext_servername_callback(NULL, NULL), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_set_tlsext_servername_callback(ctx, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_CTX_free(ctx); #endif @@ -655,8 +681,8 @@ int test_wolfSSL_set_tlsext_debug_arg_ext(void) #if defined(OPENSSL_EXTRA) && \ !defined(NO_TLS) && \ (!defined(NO_WOLFSSL_CLIENT) || \ - (defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ - defined(HAVE_TLS_EXTENSIONS))) + (defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(HAVE_TLS_EXTENSIONS))) /* State recorded by test_tlsext_debug_cb(). */ struct test_tlsext_debug_data { int count; /* number of extensions reported */ @@ -666,7 +692,7 @@ struct test_tlsext_debug_data { }; static void test_tlsext_debug_cb(WOLFSSL *ssl, int client_server, int type, - const byte *data, int len, void *arg) + const byte *data, int len, void *arg) { struct test_tlsext_debug_data *d = (struct test_tlsext_debug_data *)arg; (void)ssl; @@ -689,12 +715,12 @@ static void test_tlsext_debug_cb(WOLFSSL *ssl, int client_server, int type, /* Find an extension type in the recorded list; returns its length, -1 if * not reported. */ static int test_tlsext_debug_find_len(const struct test_tlsext_debug_data *d, - int type) + int type) { int i; for (i = 0; i < d->count && - i < (int)(sizeof(d->types) / sizeof(d->types[0])); i++) { + i < (int)(sizeof(d->types) / sizeof(d->types[0])); i++) { if (d->types[i] == type) return d->lens[i]; } @@ -707,7 +733,8 @@ static int test_tlsext_debug_find_len(const struct test_tlsext_debug_data *d, /* Declared with OpenSSL's spelling of the callback, to check that the compat * macro accepts it without a cast. */ static void test_tlsext_debug_ossl_cb(SSL *s, int client_server, int type, - const unsigned char *data, int len, void *arg) + const unsigned char *data, int len, void * + arg) { (void)s; (void)client_server; @@ -732,21 +759,22 @@ int test_wolfSSL_set_tlsext_debug_callback_ext(void) /* NULL object is rejected. */ ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(NULL, - test_tlsext_debug_cb), WOLFSSL_FAILURE); + test_tlsext_debug_cb), + WOLFSSL_FAILURE); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(ssl, test_tlsext_debug_cb), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Setting NULL disables the callback. */ ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(ssl, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* The compat macro takes a callback spelled the OpenSSL way without a * cast. A cast here would hide a signature mismatch and leave the call * undefined. */ ExpectIntEQ(SSL_set_tlsext_debug_callback(ssl, test_tlsext_debug_ossl_cb), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -778,13 +806,14 @@ int test_wolfSSL_set_tlsext_debug_callback_handshake_ext(void) XMEMSET(&sData, 0, sizeof(sData)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfSSLv23_client_method, wolfSSLv23_server_method), 0); + wolfSSLv23_client_method, + wolfSSLv23_server_method), 0); ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(ssl_c, test_tlsext_debug_cb), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_tlsext_debug_arg(ssl_c, &cData), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(ssl_s, test_tlsext_debug_cb), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_tlsext_debug_arg(ssl_s, &sData), WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); @@ -806,13 +835,13 @@ int test_wolfSSL_set_tlsext_debug_callback_handshake_ext(void) /* TLS 1.3: both sides see supported versions (a list of 2-byte * versions, so at least 2 bytes). */ ExpectTrue(test_tlsext_debug_find_len(&cData, - TLSX_SUPPORTED_VERSIONS) >= 2); + TLSX_SUPPORTED_VERSIONS) >= 2); ExpectTrue(test_tlsext_debug_find_len(&sData, - TLSX_SUPPORTED_VERSIONS) >= 2); + TLSX_SUPPORTED_VERSIONS) >= 2); #elif defined(HAVE_EXTENDED_MASTER) /* TLS 1.2: the client offers extended master secret (empty content). */ ExpectIntEQ(test_tlsext_debug_find_len(&sData, - TLSX_EXTENDED_MASTER_SECRET), 0); + TLSX_EXTENDED_MASTER_SECRET), 0); #endif wolfSSL_free(ssl_c); @@ -830,17 +859,18 @@ int test_wolfSSL_set_tlsext_debug_callback_handshake_ext(void) int test_wolfSSL_set_SessionTicket_cb_ext(void) { EXPECT_DECLS; -#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) +#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_CLIENT) && !defined( \ + NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_set_SessionTicket_cb(NULL, NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_set_SessionTicket_cb(ssl, NULL, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -894,7 +924,7 @@ int test_wolfSSL_SecureResume_ext(void) ExpectNotNull(ssl = wolfSSL_new(ctx)); /* Secure renegotiation has not been forced on, so resume is refused. */ ExpectIntEQ(wolfSSL_SecureResume(ssl), - WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E)); + WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E)); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -914,7 +944,7 @@ int test_wolfSSL_CTX_UseSecureRenegotiation_ext(void) /* NULL context is rejected. */ ExpectIntEQ(wolfSSL_CTX_UseSecureRenegotiation(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS); @@ -935,9 +965,9 @@ int test_wolfSSL_next_proto_cb_ext(void) { EXPECT_DECLS; #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \ - defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY) || \ - defined(WOLFSSL_QUIC)) && defined(HAVE_ALPN) && \ - !defined(NO_WOLFSSL_CLIENT) + defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY) || \ + defined(WOLFSSL_QUIC)) && defined(HAVE_ALPN) && \ + !defined(NO_WOLFSSL_CLIENT) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; const unsigned char* data = NULL; @@ -1000,11 +1030,12 @@ int test_wolfSSL_SNI_GetFromBuffer_inval_ext(void) #if defined(HAVE_SNI) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) byte sni[32]; word32 sniSz = (word32)sizeof(sni); - byte hello[8] = { 0 }; + byte hello[8] = {0}; /* A NULL ClientHello buffer is rejected. */ ExpectIntEQ(wolfSSL_SNI_GetFromBuffer(NULL, (word32)sizeof(hello), 0, sni, - &sniSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + &sniSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG) + ); #endif return EXPECT_RESULT(); } @@ -1019,14 +1050,14 @@ int test_wolfSSL_UseTrustedCA_inval_ext(void) #if defined(HAVE_TRUSTED_CA) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; - const byte id[1] = { 0 }; + const byte id[1] = {0}; ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The pre-agreed type must not carry an identifier. */ ExpectIntEQ(wolfSSL_UseTrustedCA(ssl, WOLFSSL_TRUSTED_CA_PRE_AGREED, id, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1045,7 +1076,7 @@ int test_wolfSSL_UseMaxFragment_inval_ext(void) !defined(NO_TLS) /* A NULL object is rejected. */ ExpectIntEQ(wolfSSL_UseMaxFragment(NULL, WOLFSSL_MFL_2_9), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif return EXPECT_RESULT(); } @@ -1098,12 +1129,14 @@ int test_wolfSSL_UseALPN_inval_ext(void) /* A protocol-list length beyond the maximum is rejected. */ ExpectIntEQ(wolfSSL_UseALPN(ssl, proto, - (word32)(WOLFSSL_MAX_ALPN_NUMBER * WOLFSSL_MAX_ALPN_PROTO_NAME_LEN + - WOLFSSL_MAX_ALPN_NUMBER + 1), - WOLFSSL_ALPN_CONTINUE_ON_MISMATCH), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + (word32)(WOLFSSL_MAX_ALPN_NUMBER * + WOLFSSL_MAX_ALPN_PROTO_NAME_LEN + + WOLFSSL_MAX_ALPN_NUMBER + 1), + WOLFSSL_ALPN_CONTINUE_ON_MISMATCH), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* No mismatch option set is rejected. */ ExpectIntEQ(wolfSSL_UseALPN(ssl, proto, (word32)XSTRLEN(proto), 0), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1126,16 +1159,16 @@ int test_wolfSSL_ALPN_GetPeerProtocol_inval_ext(void) /* NULL arguments are rejected. */ ExpectIntEQ(wolfSSL_ALPN_GetPeerProtocol(NULL, &list, &listSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_ALPN_FreePeerProtocol(NULL, &list), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The peer has not offered any protocols yet. */ ExpectIntEQ(wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz), - WC_NO_ERR_TRACE(BUFFER_ERROR)); + WC_NO_ERR_TRACE(BUFFER_ERROR)); wolfSSL_ALPN_FreePeerProtocol(ssl, &list); wolfSSL_free(ssl); @@ -1155,7 +1188,7 @@ int test_wolfSSL_CTX_set_TicketEncCb_inval_ext(void) !defined(NO_TLS) /* A NULL context is rejected. */ ExpectIntEQ(wolfSSL_CTX_set_TicketEncCb(NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif return EXPECT_RESULT(); } @@ -1171,7 +1204,7 @@ int test_wolfSSL_SessionTicket_inval_ext(void) !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; - byte tick[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + byte tick[8] = {1, 2, 3, 4, 5, 6, 7, 8}; byte out[8]; word32 outSz; byte big[4096]; @@ -1181,27 +1214,27 @@ int test_wolfSSL_SessionTicket_inval_ext(void) /* NULL object checks. */ ExpectIntEQ(wolfSSL_UseSessionTicket(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_set_SessionTicket(NULL, tick, (word32)sizeof(tick)), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* set: a non-zero size with a NULL buffer is rejected. */ ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, NULL, 4), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* get: NULL object and NULL buffer with non-zero size are rejected. */ outSz = (word32)sizeof(out); ExpectIntEQ(wolfSSL_get_SessionTicket(NULL, out, &outSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); outSz = (word32)sizeof(out); ExpectIntEQ(wolfSSL_get_SessionTicket(ssl, NULL, &outSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Store a short ticket (static-buffer path). */ ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, tick, (word32)sizeof(tick)), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Retrieving into a buffer that is too small reports zero length. */ outSz = 2; ExpectIntEQ(wolfSSL_get_SessionTicket(ssl, out, &outSz), WOLFSSL_SUCCESS); @@ -1213,7 +1246,7 @@ int test_wolfSSL_SessionTicket_inval_ext(void) ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, big, 3000), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, big, 4000), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, tick, (word32)sizeof(tick)), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1244,7 +1277,7 @@ int test_wolfSSL_CTX_set_alpn_protos_inval_ext(void) EXPECT_DECLS; #if defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; - const unsigned char protos[] = { 2, 'h', '2' }; + const unsigned char protos[] = {2, 'h', '2'}; #if defined(WOLFSSL_ERROR_CODE_OPENSSL) const int good = 0; #else @@ -1253,14 +1286,17 @@ int test_wolfSSL_CTX_set_alpn_protos_inval_ext(void) /* A NULL context is rejected. */ ExpectIntEQ(wolfSSL_CTX_set_alpn_protos(NULL, protos, (unsigned int) - sizeof(protos)), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + sizeof(protos)), WC_NO_ERR_TRACE( + BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); /* Setting twice exercises the free-previous-list path. */ ExpectIntEQ(wolfSSL_CTX_set_alpn_protos(ctx, protos, - (unsigned int)sizeof(protos)), good); + (unsigned int)sizeof(protos)), good) + ; ExpectIntEQ(wolfSSL_CTX_set_alpn_protos(ctx, protos, - (unsigned int)sizeof(protos)), good); + (unsigned int)sizeof(protos)), good) + ; wolfSSL_CTX_free(ctx); #endif @@ -1280,10 +1316,10 @@ int test_wolfSSL_dual_alg_cks_parse_ext(void) !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; - byte oversized[WOLFSSL_MAX_CKS_SIGSPEC_SZ + 1]; - byte huge[64]; - byte maxValid[WOLFSSL_MAX_CKS_SIGSPEC_SZ]; - byte value; + byte oversized[WOLFSSL_MAX_CKS_SIGSPEC_SZ + 1]; + byte huge[64]; + byte maxValid[WOLFSSL_MAX_CKS_SIGSPEC_SZ]; + byte value; /* An oversized list made entirely of valid specifiers still needs to be * rejected, so fill the buffers with a valid value. */ @@ -1300,25 +1336,27 @@ int test_wolfSSL_dual_alg_cks_parse_ext(void) /* A zero length list is rejected. */ value = WOLFSSL_CKS_SIGSPEC_NATIVE; ExpectIntEQ(TLSX_CKS_Parse(ssl, &value, 0, &ssl->extensions), - WC_NO_ERR_TRACE(BUFFER_ERROR)); + WC_NO_ERR_TRACE(BUFFER_ERROR)); /* A list of all-valid bytes longer than the semantic maximum is rejected * before any allocation. This is the denial-of-service regression: * previously any length up to 65535 was copied into a fresh heap buffer. */ ExpectIntEQ(TLSX_CKS_Parse(ssl, oversized, (word16)sizeof(oversized), - &ssl->extensions), WC_NO_ERR_TRACE(BUFFER_ERROR)); + &ssl->extensions), WC_NO_ERR_TRACE(BUFFER_ERROR)) + ; ExpectIntEQ(TLSX_CKS_Parse(ssl, huge, (word16)sizeof(huge), - &ssl->extensions), WC_NO_ERR_TRACE(BUFFER_ERROR)); + &ssl->extensions), WC_NO_ERR_TRACE(BUFFER_ERROR)) + ; /* An invalid specifier value is still rejected. */ value = WOLFSSL_CKS_SIGSPEC_EXTERNAL; ExpectIntEQ(TLSX_CKS_Parse(ssl, &value, 1, &ssl->extensions), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* A well-formed list at the maximum length is accepted, so the cap does not - * break legitimate peers (the example client sends all three specifiers). */ + * break legitimate peers (the example client sends all three specifiers). */ ExpectIntEQ(TLSX_CKS_Parse(ssl, maxValid, (word16)sizeof(maxValid), - &ssl->extensions), 0); + &ssl->extensions), 0); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1338,7 +1376,7 @@ int test_wolfSSL_ALPN_FreePeerProtocol_inval_ext(void) /* A NULL object is rejected before the list is touched. */ ExpectIntEQ(wolfSSL_ALPN_FreePeerProtocol(NULL, &list), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNull(list); #endif return EXPECT_RESULT(); @@ -1366,7 +1404,7 @@ int test_wolfSSL_ALPN_GetPeerProtocol_badlen_ext(void) /* No list offered by the peer yet. */ ExpectIntEQ(wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz), - WC_NO_ERR_TRACE(BUFFER_ERROR)); + WC_NO_ERR_TRACE(BUFFER_ERROR)); /* Install a list whose first length byte claims more bytes than are * present. wolfSSL_free() releases the buffer with the object, so it must @@ -1383,7 +1421,7 @@ int test_wolfSSL_ALPN_GetPeerProtocol_badlen_ext(void) ssl->alpn_peer_requested_length = 4; ExpectIntEQ(wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); ExpectNull(list); } } @@ -1416,7 +1454,7 @@ int test_wolfSSL_get_secure_renegotiation_support_ext(void) /* A NULL object is rejected when requesting the extension. */ ExpectIntEQ(wolfSSL_UseSecureRenegotiation(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Not requested yet. */ ExpectIntEQ(wolfSSL_SSL_get_secure_renegotiation_support(ssl), 0); @@ -1454,8 +1492,8 @@ int test_wolfSSL_set_alpn_protos_badlen_ext(void) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; /* First entry claims 8 bytes but only 3 follow. */ - const unsigned char bad[] = { 8, 'h', '2', 0 }; - const unsigned char good[] = { 2, 'h', '2' }; + const unsigned char bad[] = {8, 'h', '2', 0}; + const unsigned char good[] = {2, 'h', '2'}; #if defined(WOLFSSL_ERROR_CODE_OPENSSL) const int okRet = 0; const int failRet = 1; @@ -1469,11 +1507,11 @@ int test_wolfSSL_set_alpn_protos_badlen_ext(void) /* A well-formed list is accepted. */ ExpectIntEQ(wolfSSL_set_alpn_protos(ssl, good, (unsigned int)sizeof(good)), - okRet); + okRet); /* A bad length byte is rejected. */ ExpectIntEQ(wolfSSL_set_alpn_protos(ssl, bad, (unsigned int)sizeof(bad)), - failRet); + failRet); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1504,7 +1542,8 @@ int test_wolfSSL_set_alpn_protos_badlen_ext(void) * @return 0 always - the caller does not use the return value. */ static int test_ssl_ext_ticket_recv_cb(WOLFSSL* ssl, - const unsigned char* ticket, int ticketSz, void* ctx) + const unsigned char* ticket, int ticketSz + , void* ctx) { (void)ssl; (void)ticket; @@ -1534,8 +1573,10 @@ static int test_ssl_ext_ticket_recv_cb(WOLFSSL* ssl, * @return 0 when the cipher or HMAC cannot be set up. */ static int test_ssl_ext_ticket_renew_cb(WOLFSSL* ssl, unsigned char* name, - unsigned char* iv, WOLFSSL_EVP_CIPHER_CTX* ectx, WOLFSSL_HMAC_CTX* hctx, - int enc) + unsigned char* iv, + WOLFSSL_EVP_CIPHER_CTX* ectx, + WOLFSSL_HMAC_CTX* hctx, + int enc) { static const unsigned char key[32] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, @@ -1559,21 +1600,18 @@ static int test_ssl_ext_ticket_renew_cb(WOLFSSL* ssl, unsigned char* name, } if (HMAC_Init_ex(hctx, hmacKey, (int)sizeof(hmacKey), EVP_sha256(), - NULL) != 1) { + NULL) != 1) { ret = 0; - } - else if (enc) { + } else if (enc) { if (EVP_EncryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, key, iv) != 1) { ret = 0; - } - else { + } else { ret = TEST_SSL_EXT_TICKET_CB_OK; } - } - else if (EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, key, iv) != 1) { + } else if (EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, key, iv) != 1) + { ret = 0; - } - else { + } else { /* Ask for the ticket to be reissued after this resumption. */ ret = TEST_SSL_EXT_TICKET_CB_RENEW; } @@ -1608,10 +1646,12 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, + wolfTLSv1_2_server_method), 0); ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx_s, - test_ssl_ext_ticket_renew_cb), WOLFSSL_SUCCESS); + test_ssl_ext_ticket_renew_cb), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS); /* First handshake issues a ticket. */ @@ -1634,7 +1674,8 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void) ExpectIntEQ(wolfSSL_set_session(ssl_c, session), WOLFSSL_SUCCESS); /* Count the tickets this handshake issues. */ ExpectIntEQ(wolfSSL_set_SessionTicket_cb(ssl_c, - test_ssl_ext_ticket_recv_cb, &newTickets), WOLFSSL_SUCCESS); + test_ssl_ext_ticket_recv_cb, & + newTickets), WOLFSSL_SUCCESS); /* Make the ticket the only resumption path so the callback is reached. */ if (ssl_s != NULL) { ssl_s->options.sessionCacheOff = 1; @@ -1659,26 +1700,26 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void) } /* --------------------------------------------------------------------------- - * The public Encrypted ClientHello configuration API. - * - * src/ssl_ech.c measured 0 of 52 MC/DC conditions -- not "poorly covered", - * zero -- despite ECH being compiled in and five ECH tests running in the - * tls13 group of the same binary. Those tests drive ECH through a handshake - * with configs the harness generates for them; none of them calls the public - * configuration API, which is where every condition in the file lives: - * generating a config for a named KEM, importing one from raw bytes or from - * base64, reading one back into a caller's buffer, and the argument and size - * checks on all of it. - * - * The file was invisible to the campaign until this part: ssl_ech.c is - * #included into ssl.c rather than compiled standalone, so it produces no - * object file and never appeared in a filtered llvm-cov export. - * - * These vectors are the ones a handshake cannot produce: a NULL ctx, a buffer - * that is one byte too small, a length of zero, base64 that is not base64, a - * KEM/KDF/AEAD triple the build does not implement, and a retry-config query - * on a connection that never negotiated ECH. - * ------------------------------------------------------------------------- */ +* The public Encrypted ClientHello configuration API. +* +* src/ssl_ech.c measured 0 of 52 MC/DC conditions -- not "poorly covered", +* zero -- despite ECH being compiled in and five ECH tests running in the +* tls13 group of the same binary. Those tests drive ECH through a handshake +* with configs the harness generates for them; none of them calls the public +* configuration API, which is where every condition in the file lives: +* generating a config for a named KEM, importing one from raw bytes or from +* base64, reading one back into a caller's buffer, and the argument and size +* checks on all of it. +* +* The file was invisible to the campaign until this part: ssl_ech.c is +* #included into ssl.c rather than compiled standalone, so it produces no +* object file and never appeared in a filtered llvm-cov export. +* +* These vectors are the ones a handshake cannot produce: a NULL ctx, a buffer +* that is one byte too small, a length of zero, base64 that is not base64, a +* KEM/KDF/AEAD triple the build does not implement, and a retry-config query +* on a connection that never negotiated ECH. +* ------------------------------------------------------------------------- */ int test_wolfSSL_ech_config_api(void) { EXPECT_DECLS; @@ -1687,8 +1728,8 @@ int test_wolfSSL_ech_config_api(void) WOLFSSL_CTX* ctx = NULL; WOLFSSL_CTX* cctx = NULL; WOLFSSL* ssl = NULL; - byte cfg[512]; - byte small[4]; + byte cfg[512]; + byte small[4]; word32 cfgSz = (word32)sizeof(cfg); word32 smallSz = (word32)sizeof(small); word32 zero = 0; @@ -1708,7 +1749,8 @@ int test_wolfSSL_ech_config_api(void) WOLFSSL_SUCCESS); /* a KEM/KDF/AEAD triple no build implements: the lookup's failure arm */ ExpectIntNE(wolfSSL_CTX_GenerateEchConfig(ctx, "example.com", - 0xFFFF, 0xFFFF, 0xFFFF), WOLFSSL_SUCCESS); + 0xFFFF, 0xFFFF, 0xFFFF), + WOLFSSL_SUCCESS); /* the accepting partner: defaults */ ExpectIntEQ(wolfSSL_CTX_GenerateEchConfig(ctx, "example.com", 0, 0, 0), WOLFSSL_SUCCESS); @@ -1798,24 +1840,24 @@ int test_wolfSSL_ech_config_api(void) } /* --------------------------------------------------------------------------- - * Null-argument burn-down across the public API. - * - * A taxonomy of the 2855 conditions still uncovered puts null-guards at 749 -- - * the largest single type, 26% of everything left. Splitting them by enclosing - * function settles what API tests can and cannot do about it: - * - * 246 in public wolfSSL_* / wc_* functions <- these, reachable by call - * 503 in file-static helpers <- white-box only - * - * So an API suite can address a third of the category and no more; the rest is - * structurally out of reach from outside the library. These vectors take the - * public third across the extension, DTLS, session and record APIs. - * - * Every call here is a caller mistake a working program does not make: an - * object that was never created, an output pointer that is NULL, a length of - * zero paired with a real buffer. Each is followed by the same call made - * correctly, so the guard has its independence partner in this binary. - * ------------------------------------------------------------------------- */ +* Null-argument burn-down across the public API. +* +* A taxonomy of the 2855 conditions still uncovered puts null-guards at 749 -- +* the largest single type, 26% of everything left. Splitting them by enclosing +* function settles what API tests can and cannot do about it: +* +* 246 in public wolfSSL_* / wc_* functions <- these, reachable by call +* 503 in file-static helpers <- white-box only +* +* So an API suite can address a third of the category and no more; the rest is +* structurally out of reach from outside the library. These vectors take the +* public third across the extension, DTLS, session and record APIs. +* +* Every call here is a caller mistake a working program does not make: an +* object that was never created, an output pointer that is NULL, a length of +* zero paired with a real buffer. Each is followed by the same call made +* correctly, so the guard has its independence partner in this binary. +* ------------------------------------------------------------------------- */ int test_wolfSSL_api_null_burndown(void) { EXPECT_DECLS; @@ -1951,7 +1993,8 @@ int test_wolfSSL_api_null_burndown(void) int test_wolfSSL_session_null_burndown(void) { EXPECT_DECLS; -#if !defined(NO_SESSION_CACHE) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) +#if !defined(NO_SESSION_CACHE) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS \ + ) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; WOLFSSL_SESSION* sess = NULL; @@ -1989,30 +2032,30 @@ int test_wolfSSL_session_null_burndown(void) } /* --------------------------------------------------------------------------- - * Null-guard vectors aimed at named operands. - * - * The previous pass sprayed NULL at the first argument of everything and - * returned 11 conditions for a hundred calls. The reason is that a guard like - * - * if ((ssl == NULL) || (p == NULL) || (g == NULL)) - * - * has three operands, and a NULL in the first slot pairs only the first: the - * other two are never evaluated. Each operand needs its own call, with every - * other argument valid. - * - * So these vectors come from the ledger rather than from guesswork -- one call - * per uncovered operand of each guard, followed by the all-valid call that is - * their shared partner. - * ------------------------------------------------------------------------- */ +* Null-guard vectors aimed at named operands. +* +* The previous pass sprayed NULL at the first argument of everything and +* returned 11 conditions for a hundred calls. The reason is that a guard like +* +* if ((ssl == NULL) || (p == NULL) || (g == NULL)) +* +* has three operands, and a NULL in the first slot pairs only the first: the +* other two are never evaluated. Each operand needs its own call, with every +* other argument valid. +* +* So these vectors come from the ledger rather than from guesswork -- one call +* per uncovered operand of each guard, followed by the all-valid call that is +* their shared partner. +* ------------------------------------------------------------------------- */ int test_wolfSSL_api_null_operands(void) { EXPECT_DECLS; #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; - byte buf[64]; + byte buf[64]; word32 bufSz = (word32)sizeof(buf); - int iSz = (int)sizeof(buf); + int iSz = (int)sizeof(buf); XMEMSET(buf, 0, sizeof(buf)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); @@ -2021,8 +2064,8 @@ int test_wolfSSL_api_null_operands(void) /* --- SetTmpDH: (ssl|ctx == NULL) || (p == NULL) || (g == NULL) ------ */ #if !defined(NO_DH) && !defined(WOLFSSL_NO_TLS12) { - static const byte p[] = { 0x00, 0x01 }; - static const byte g[] = { 0x02 }; + static const byte p[] = {0x00, 0x01}; + static const byte g[] = {0x02}; (void)wolfSSL_SetTmpDH(NULL, p, (int)sizeof(p), g, (int)sizeof(g)); (void)wolfSSL_SetTmpDH(ssl, NULL, (int)sizeof(p), g, (int)sizeof(g)); @@ -2055,19 +2098,19 @@ int test_wolfSSL_api_null_operands(void) /* --- export_keying_material: ssl, out, label, and the context pair --- */ #ifdef HAVE_KEYING_MATERIAL (void)wolfSSL_export_keying_material(NULL, buf, sizeof(buf), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, NULL, sizeof(buf), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, buf, sizeof(buf), - NULL, 5, NULL, 0, 0); + NULL, 5, NULL, 0, 0); /* use_context set with a NULL context: the operand pair a caller that * passes both or neither cannot produce */ (void)wolfSSL_export_keying_material(ssl, buf, sizeof(buf), - "label", 5, NULL, 0, 1); + "label", 5, NULL, 0, 1); (void)wolfSSL_export_keying_material(ssl, buf, sizeof(buf), - "label", 5, buf, 4, 1); + "label", 5, buf, 4, 1); (void)wolfSSL_export_keying_material(ssl, buf, sizeof(buf), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); #endif /* HAVE_KEYING_MATERIAL */ /* --- SetServerID: ssl, id, then len <= 0 ---------------------------- */ @@ -2111,15 +2154,15 @@ int test_wolfSSL_api_null_operands(void) /* one operand of `clientHello != NULL && helloSz > 0 && sni != NULL * && inOutSz != NULL` per call */ (void)wolfSSL_SNI_GetFromBuffer(NULL, (word32)sizeof(hello), - WOLFSSL_SNI_HOST_NAME, buf, &outSz); + WOLFSSL_SNI_HOST_NAME, buf, &outSz); (void)wolfSSL_SNI_GetFromBuffer(hello, 0, - WOLFSSL_SNI_HOST_NAME, buf, &outSz); + WOLFSSL_SNI_HOST_NAME, buf, &outSz); (void)wolfSSL_SNI_GetFromBuffer(hello, (word32)sizeof(hello), - WOLFSSL_SNI_HOST_NAME, NULL, &outSz); + WOLFSSL_SNI_HOST_NAME, NULL, &outSz); (void)wolfSSL_SNI_GetFromBuffer(hello, (word32)sizeof(hello), - WOLFSSL_SNI_HOST_NAME, buf, NULL); + WOLFSSL_SNI_HOST_NAME, buf, NULL); (void)wolfSSL_SNI_GetFromBuffer(hello, (word32)sizeof(hello), - WOLFSSL_SNI_HOST_NAME, buf, &outSz); + WOLFSSL_SNI_HOST_NAME, buf, &outSz); } #endif /* HAVE_SNI && !NO_WOLFSSL_SERVER && !NO_TLS */ @@ -2147,13 +2190,13 @@ int test_wolfSSL_api_null_operands(void) (void)wolfSSL_get_cipher_suite_from_name(NULL, &c0, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - NULL, &c1, NULL); + NULL, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - &c0, NULL, NULL); + &c0, NULL, NULL); (void)wolfSSL_get_cipher_suite_from_name("no-such-suite", - &c0, &c1, NULL); + &c0, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - &c0, &c1, NULL); + &c0, &c1, NULL); } (void)bufSz; (void)iSz; @@ -2164,24 +2207,24 @@ int test_wolfSSL_api_null_operands(void) } /* --------------------------------------------------------------------------- - * Public-API argument NULLs, one call per named operand. - * - * A census of what is left splits the remaining NULL-shaped conditions three - * ways by how the NULL actually arises: 282 come from an argument a caller - * passes, 145 from a struct member that is legitimately NULL in some state, - * and only 15 from an allocation that failed. These are the first kind, in - * public functions -- the cheapest coverage left in the campaign and the only - * kind that needs no fixture at all. - * - * Each guard gets one call per uncovered operand with every OTHER argument - * valid, then the all-valid call that is their shared partner. A NULL in the - * first slot pairs only the first operand; the rest short-circuit away. - * - * Every symbol here was checked against BOTH its declaration guard in ssl.h - * and its implementation guard in src/, because a declaration without an - * implementation is a link error rather than a compile error, and that has - * cost this branch several CI rounds. - * ------------------------------------------------------------------------- */ +* Public-API argument NULLs, one call per named operand. +* +* A census of what is left splits the remaining NULL-shaped conditions three +* ways by how the NULL actually arises: 282 come from an argument a caller +* passes, 145 from a struct member that is legitimately NULL in some state, +* and only 15 from an allocation that failed. These are the first kind, in +* public functions -- the cheapest coverage left in the campaign and the only +* kind that needs no fixture at all. +* +* Each guard gets one call per uncovered operand with every OTHER argument +* valid, then the all-valid call that is their shared partner. A NULL in the +* first slot pairs only the first operand; the rest short-circuit away. +* +* Every symbol here was checked against BOTH its declaration guard in ssl.h +* and its implementation guard in src/, because a declaration without an +* implementation is a link error rather than a compile error, and that has +* cost this branch several CI rounds. +* ------------------------------------------------------------------------- */ int test_wolfSSL_public_null_operands(void) { EXPECT_DECLS; @@ -2229,14 +2272,14 @@ int test_wolfSSL_public_null_operands(void) (void)wolfSSL_get_cipher_suite_from_name(NULL, &c0, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - NULL, &c1, NULL); + NULL, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - &c0, NULL, NULL); + &c0, NULL, NULL); /* a name no build implements: the lookup's miss arm */ (void)wolfSSL_get_cipher_suite_from_name("NO-SUCH-SUITE", - &c0, &c1, NULL); + &c0, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - &c0, &c1, NULL); + &c0, &c1, NULL); } /* --- the curve-name getter, which reads ssl->ecdhCurveOID ---------- */ @@ -2272,7 +2315,7 @@ int test_wolfSSL_public_null_operands(void) /* --- `(ssl == NULL) || (der == NULL)` ------------------------------ */ #ifndef NO_CERTS { - static const byte tinyDer[] = { 0x30, 0x03, 0x02, 0x01, 0x00 }; + static const byte tinyDer[] = {0x30, 0x03, 0x02, 0x01, 0x00}; (void)wolfSSL_use_certificate_ASN1(NULL, tinyDer, (int)sizeof(tinyDer)); @@ -2290,13 +2333,13 @@ int test_wolfSSL_public_null_operands(void) XMEMSET(km, 0, sizeof(km)); (void)wolfSSL_export_keying_material(NULL, km, sizeof(km), - "lbl", 3, NULL, 0, 0); + "lbl", 3, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, NULL, sizeof(km), - "lbl", 3, NULL, 0, 0); + "lbl", 3, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, km, sizeof(km), - NULL, 3, NULL, 0, 0); + NULL, 3, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, km, sizeof(km), - "lbl", 3, NULL, 0, 0); + "lbl", 3, NULL, 0, 0); } #endif @@ -2307,18 +2350,18 @@ int test_wolfSSL_public_null_operands(void) } /* --------------------------------------------------------------------------- - * Session object lifecycle argument guards. - * - * ssl_sess.c is the second-largest remaining file and its guards are almost - * all of the form `session == NULL || `. A test - * that establishes a session reaches them with a well-formed object every - * time, so the NULL half and the malformed half never occur. - * - * wolfSSL_SESSION_new / _dup / _up_ref / _free are unguarded in both ssl.h and - * src/ssl_sess.c, so they are callable in every configuration that has the - * session cache at all -- checked before writing, because a declaration - * without a compiled implementation is a link error. - * ------------------------------------------------------------------------- */ +* Session object lifecycle argument guards. +* +* ssl_sess.c is the second-largest remaining file and its guards are almost +* all of the form `session == NULL || `. A test +* that establishes a session reaches them with a well-formed object every +* time, so the NULL half and the malformed half never occur. +* +* wolfSSL_SESSION_new / _dup / _up_ref / _free are unguarded in both ssl.h and +* src/ssl_sess.c, so they are callable in every configuration that has the +* session cache at all -- checked before writing, because a declaration +* without a compiled implementation is a link error. +* ------------------------------------------------------------------------- */ int test_wolfSSL_session_lifecycle_guards(void) { EXPECT_DECLS; @@ -2474,9 +2517,11 @@ int test_ssl_api_decision_coverage(void) WOLFSSL* sssl = NULL; ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(sctx, svrKeyFile, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(sctx, svrCertFile, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectNotNull(sssl = wolfSSL_new(sctx)); (void)wolfSSL_GetMacSecret(sssl, 1); (void)wolfSSL_GetMacSecret(sssl, 0); @@ -2534,41 +2579,44 @@ int test_ssl_api_decision_coverage(void) kssl->options.handShakeDone = 1; /* 3399: use_ctx && len>0 && (use_ctx ? ctx==NULL : 0) */ (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "label", 5, ctxbuf, (word32)sizeof(ctxbuf), 1); + "label", 5, ctxbuf, (word32)sizeof( + ctxbuf), 1); (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "label", 5, NULL, 1, 1); + "label", 5, NULL, 1, 1); (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "label", 5, NULL, 0, 1); + "label", 5, NULL, 0, 1); /* 3417: use_ctx && contextLen > MAX_16BIT */ (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "label", 5, ctxbuf, (word32)sizeof(ctxbuf), 1); + "label", 5, ctxbuf, (word32)sizeof( + ctxbuf), 1); (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "label", 5, ctxbuf, (word32)(WOLFSSL_MAX_16BIT + 1), 1); + "label", 5, ctxbuf, (word32)( + WOLFSSL_MAX_16BIT + 1), 1); /* 3428: saveArrays==0 || arrays==NULL (needs 3417 to pass) */ (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); wolfSSL_KeepArrays(kssl); (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); { Arrays* saved = kssl->arrays; kssl->arrays = NULL; (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); kssl->arrays = saved; } /* 3437: forbidden label (needs 3428 to pass). The labels are the * TLS PRF names; "master" is too short, "master secrex" is the * same length with a mismatching tail. */ (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "master secret", 13, NULL, 0, 0); + "master secret", 13, NULL, 0, 0); (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "master", 6, NULL, 0, 0); + "master", 6, NULL, 0, 0); (void)wolfSSL_export_keying_material(kssl, out, sizeof(out), - "master secrex", 13, NULL, 0, 0); + "master secrex", 13, NULL, 0, 0); kssl->options.handShakeDone = 0; wolfSSL_free(kssl); } @@ -2652,13 +2700,13 @@ int test_ssl_api_decision_coverage(void) (void)wolfSSL_get_cipher_suite_from_name(NULL, &c0, &c1, &flags); (void)wolfSSL_get_cipher_suite_from_name("AES128-SHA", NULL, &c1, - &flags); + &flags); (void)wolfSSL_get_cipher_suite_from_name("AES128-SHA", &c0, NULL, - &flags); + &flags); (void)wolfSSL_get_cipher_suite_from_name("AES128-SHA", &c0, &c1, - NULL); + NULL); (void)wolfSSL_get_cipher_suite_from_name("AES128-SHA", &c0, &c1, - &flags); + &flags); } /* --- 6413:0/1 CIPHER_get_id: cipher && cipher->ssl ------------------- */ @@ -2724,3 +2772,51 @@ int test_ssl_api_decision_coverage(void) #endif return EXPECT_RESULT(); } + +/* Decision-coverage drivers for the ssl_ech.c argument guards left unpaired + * by the functional tests. The ECH config functions are WOLFSSL_LOCAL, so + * this white-box test calls them directly. Each block names the source + * line:condition it closes. */ +int test_ech_decision_coverage(void) +{ + EXPECT_DECLS; +#if defined(HAVE_ECH) && !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + WOLFSSL_EchConfig cfg; + WOLFSSL_EchConfig* outCfg = NULL; + byte buf[64]; + byte out[256]; + word32 outLen = sizeof(out); + + XMEMSET(buf, 0, sizeof(buf)); + XMEMSET(&cfg, 0, sizeof(cfg)); + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + + /* --- 349:0/1/2 SetRetryConfigs: ssl==NULL || configs==NULL || len==0 -- */ + (void)SetRetryConfigs(NULL, buf, sizeof(buf)); + (void)SetRetryConfigs(ssl, NULL, sizeof(buf)); + (void)SetRetryConfigs(ssl, buf, 0); + (void)SetRetryConfigs(ssl, buf, sizeof(buf)); + + /* --- 370:0/1/2 GetEchConfig: config==NULL || (out==NULL&&outLen==NULL) */ + (void)GetEchConfig(NULL, out, &outLen); + (void)GetEchConfig(&cfg, NULL, NULL); + (void)GetEchConfig(&cfg, out, &outLen); + + /* --- 626:0/1/2 SetEchConfigsEx: outCfg==NULL || cfgs==NULL || len<2 --- */ + (void)SetEchConfigsEx(NULL, ssl->heap, buf, sizeof(buf)); + (void)SetEchConfigsEx(&outCfg, ssl->heap, NULL, sizeof(buf)); + (void)SetEchConfigsEx(&outCfg, ssl->heap, buf, 1); + + /* --- 861:0/1/2 GetEchConfigsEx: cfgs==NULL || outLen==NULL || too small */ + (void)GetEchConfigsEx(NULL, out, &outLen); + (void)GetEchConfigsEx(&cfg, out, NULL); + (void)GetEchConfigsEx(&cfg, out, &outLen); + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_ssl_ext.h b/tests/api/test_ssl_ext.h index 3eee68fc35b..b9bef5b9353 100644 --- a/tests/api/test_ssl_ext.h +++ b/tests/api/test_ssl_ext.h @@ -29,6 +29,7 @@ int test_wolfSSL_api_null_operands(void); int test_wolfSSL_public_null_operands(void); int test_wolfSSL_session_lifecycle_guards(void); int test_ssl_api_decision_coverage(void); +int test_ech_decision_coverage(void); int test_wolfSSL_NoTicketTLSv12_ext(void); int test_wolfSSL_CTX_UseMaxFragment_ext(void); @@ -129,6 +130,7 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void); TEST_DECL_GROUP("ssl_ext", test_wolfSSL_api_null_operands), \ TEST_DECL_GROUP("ssl_ext", test_wolfSSL_public_null_operands), \ TEST_DECL_GROUP("ssl_ext", test_wolfSSL_session_lifecycle_guards), \ - TEST_DECL_GROUP("ssl_ext", test_ssl_api_decision_coverage) + TEST_DECL_GROUP("ssl_ext", test_ssl_api_decision_coverage), \ + TEST_DECL_GROUP("ssl_ext", test_ech_decision_coverage) #endif /* TESTS_API_SSL_EXT_H */ From 260ddabbde26944e4aebb2cd33acf929bcb5c458 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 1 Oct 2026 13:26:54 +0200 Subject: [PATCH 09/33] MC/DC: decision-coverage drivers for the ssl_certman.c argument guards The cert-manager helpers (AlreadySigner, GetCA, AddSigner, RemoveCA, SetCAType) are WOLFSSL_LOCAL, so a white-box test calls them directly with NULL/valid argument pairs to close their argument guards. The AddSigner all-valid case uses a heap Signer removed via RemoveCA (which frees it) before ctx-free so ownership stays clean. All 60 open conditions in ssl_certman.c are now covered; the one GetCAByKeyHash guard is a build-variant gap (HAVE_OCSP off). Full unit.test --no-wc green. --- tests/api/test_certman.c | 1503 +++++++++++++++++++++++--------------- tests/api/test_certman.h | 4 +- 2 files changed, 904 insertions(+), 603 deletions(-) diff --git a/tests/api/test_certman.c b/tests/api/test_certman.c index 98df4e11d90..af2907e3161 100644 --- a/tests/api/test_certman.c +++ b/tests/api/test_certman.c @@ -47,32 +47,40 @@ int test_wolfSSL_CertManagerAPI(void) wolfSSL_CertManagerFree(NULL); ExpectIntEQ(wolfSSL_CertManager_up_ref(NULL), 0); ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #ifdef WOLFSSL_TRUST_PEER_CERT ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer_ex(NULL, &c, 1, - WOLFSSL_FILETYPE_ASN1, 0, 0), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WOLFSSL_FILETYPE_ASN1, 0, 0), + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, -1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, -1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, -1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, 1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, 1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, 1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, -1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, 1, -1), - WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE)); + WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE)); #endif #if !defined(NO_FILESYSTEM) @@ -89,29 +97,32 @@ int test_wolfSSL_CertManagerAPI(void) #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH) ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, NULL, WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, ca_cert, - WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_PEM), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert, -1), - WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE)); + WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE)); #ifdef WOLFSSL_PEM_TO_DER ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert_der, - WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)); + WOLFSSL_FILETYPE_PEM), + WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)); #endif ExpectIntEQ(wolfSSL_CertManagerVerify(cm, "no-file", - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE)); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, NULL), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, NULL), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, ca_path), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, ca_path), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); } #endif @@ -119,11 +130,11 @@ int test_wolfSSL_CertManagerAPI(void) ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), 1); #elif !defined(HAVE_CRL) ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); #endif ExpectIntEQ(wolfSSL_CertManagerDisableCRL(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerDisableCRL(cm), 1); #ifdef HAVE_CRL /* Test APIs when CRL is disabled. */ @@ -131,70 +142,74 @@ int test_wolfSSL_CertManagerAPI(void) ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1); #endif ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, - sizeof_server_cert_der_2048), 1); + sizeof_server_cert_der_2048), 1); ExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1); #endif /* OCSP */ ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(NULL, 0), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #if !defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \ !defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); #endif #ifdef HAVE_OCSP ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, NULL, 0, - NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + NULL, NULL, NULL, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, NULL, 1, - NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + NULL, NULL, NULL, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, &c, 1, - NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + NULL, NULL, NULL, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, ""), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, NULL), 1); ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(NULL, NULL, NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(cm, NULL, NULL, NULL), 1); ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(cm), 1); /* Test APIs when OCSP is disabled. */ ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, &c, 1, - NULL, NULL, NULL, NULL), 1); + NULL, NULL, NULL, NULL), 1) + ; ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, 1), 1); #endif @@ -210,7 +225,7 @@ int test_wolfSSL_CertManagerAPI(void) #ifdef HAVE_OCSP ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, WOLFSSL_OCSP_URL_OVERRIDE | - WOLFSSL_OCSP_CHECKALL), 1); + WOLFSSL_OCSP_CHECKALL), 1); #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \ defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1); @@ -235,7 +250,7 @@ int test_wolfSSL_CertManagerAPI(void) #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_TLS) static int test_cm_load_ca_buffer(const byte* cert_buf, size_t cert_sz, - int file_type) + int file_type) { int ret; WOLFSSL_CERT_MANAGER* cm; @@ -270,33 +285,31 @@ static int test_cm_load_ca_file(const char* ca_cert_file) if (ret == WOLFSSL_SUCCESS) { /* test including null terminator in length */ - byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, DYNAMIC_TYPE_TMP_BUFFER); + byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, + DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { ret = MEMORY_E; - } - else { + } else { cert_buf = tmp; cert_buf[cert_sz] = '\0'; ret = test_cm_load_ca_buffer(cert_buf, cert_sz+1, - CERT_FILETYPE); + CERT_FILETYPE); } - } #if defined(WOLFSSL_PEM_TO_DER) if (ret == WOLFSSL_SUCCESS) { /* test loading DER */ ret = wc_PemToDer(cert_buf, (sword32)cert_sz, CA_TYPE, &pDer, - NULL, NULL, NULL); + NULL, NULL, NULL); if (ret == 0 && pDer != NULL) { ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length, - WOLFSSL_FILETYPE_ASN1); + WOLFSSL_FILETYPE_ASN1); wc_FreeDer(&pDer); } } #endif - } XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -340,17 +353,16 @@ static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags) if (ret == WOLFSSL_SUCCESS) { /* test including null terminator in length */ - byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, DYNAMIC_TYPE_TMP_BUFFER); + byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, + DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { ret = MEMORY_E; - } - else { + } else { cert_buf = tmp; cert_buf[cert_sz] = '\0'; ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz+1, - CERT_FILETYPE, flags); + CERT_FILETYPE, flags); } - } #if defined(WOLFSSL_PEM_TO_DER) @@ -360,13 +372,12 @@ static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags) NULL, NULL, NULL); if (ret == 0 && pDer != NULL) { ret = test_cm_load_ca_buffer_ex(pDer->buffer, pDer->length, - WOLFSSL_FILETYPE_ASN1, flags); + WOLFSSL_FILETYPE_ASN1, flags); wc_FreeDer(&pDer); } } #endif - } XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -426,7 +437,7 @@ int test_wolfSSL_CertManagerLoadCABuffer_ex(void) int ret; ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_cert, WOLFSSL_LOAD_FLAG_NONE), - 1); + 1); #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER) ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); #elif defined(NO_RSA) @@ -436,14 +447,15 @@ int test_wolfSSL_CertManagerLoadCABuffer_ex(void) #endif ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_expired_cert, - WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), 1); + WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), + 1); #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER) ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); #elif defined(NO_RSA) ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E)); #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS && \ WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && !defined(NO_ASN_TIME) && \ - defined(WOLFSSL_TRUST_PEER_CERT) && defined(OPENSSL_COMPATIBLE_DEFAULTS) + defined(WOLFSSL_TRUST_PEER_CERT) && defined(OPENSSL_COMPATIBLE_DEFAULTS) ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E)); #else ExpectIntEQ(ret, WOLFSSL_SUCCESS); @@ -488,128 +500,166 @@ int test_wolfSSL_CertManagerLoadCABufferType(void) ExpectIntEQ(load_file(client_cert, &client_cert_buf, &client_cert_sz), 0); ExpectIntNE(wolfSSL_CertManagerLoadCABufferType(cm, ca_cert_buf, - (sword32)ca_cert_sz, CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, 0), WOLFSSL_SUCCESS); + (sword32)ca_cert_sz, + CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, + 0), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCABufferType(cm, ca_cert_buf, - (sword32)ca_cert_sz, CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, 5), WOLFSSL_SUCCESS); + (sword32)ca_cert_sz, + CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, + 5), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, ca_cert_buf, - (sword32)ca_cert_sz, CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_CA), - WOLFSSL_SUCCESS); + (sword32)ca_cert_sz, + CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, + WOLFSSL_USER_CA), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, int1_cert_buf, - (sword32)int1_cert_sz, CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + (sword32)int1_cert_sz, + CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, + WOLFSSL_USER_INTER), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, int2_cert_buf, - (sword32)int2_cert_sz, CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + (sword32)int2_cert_sz, + CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, + WOLFSSL_USER_INTER), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, client_cert_buf, - (sword32)client_cert_sz, CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + (sword32)client_cert_sz, + CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, + WOLFSSL_USER_INTER), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Intermediate certs have been unloaded, but CA cert is still loaded. Expect first level intermediate to verify, rest to fail. */ #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, int1_cert_buf, - (sword32)int1_cert_sz, CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_TEMP_CA), - WOLFSSL_SUCCESS); + (sword32)int1_cert_sz, + CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, + WOLFSSL_TEMP_CA), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, int2_cert_buf, - (sword32)int2_cert_sz, CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_CHAIN_CA), - WOLFSSL_SUCCESS); + (sword32)int2_cert_sz, + CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, + WOLFSSL_CHAIN_CA), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, client_cert_buf, - (sword32)client_cert_sz, CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + (sword32)client_cert_sz, + CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, + WOLFSSL_USER_INTER), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_CHAIN_CA), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_TEMP_CA), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_USER_CA), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), + WOLFSSL_SUCCESS); #endif if (cm) @@ -632,7 +682,7 @@ int test_wolfSSL_CertManagerGetCerts(void) EXPECT_DECLS; #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \ !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \ - defined(WOLFSSL_SIGNER_DER_CERT) + defined(WOLFSSL_SIGNER_DER_CERT) WOLFSSL_CERT_MANAGER* cm = NULL; WOLFSSL_STACK* sk = NULL; X509* x509 = NULL; @@ -662,14 +712,17 @@ int test_wolfSSL_CertManagerGetCerts(void) /* Check that ASN_SELF_SIGNED_E is returned for a self-signed cert for QT * and full OpenSSL compatibility */ ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)); #else ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); #endif ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm, - "./certs/ca-cert.pem", NULL)); + "./certs/ca-cert.pem", + NULL)); ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(cm)); @@ -725,7 +778,7 @@ int test_wolfSSL_CertManagerSetVerify(void) /* Exercise the baseline verification path before the callback overrides * the result, so the expired-cert failure remains visible to MC/DC. */ ExpectIntNE(wolfSSL_CertManagerVerify(cm, expiredCert, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); #endif wolfSSL_CertManagerSetVerify(cm, myVerify); @@ -733,11 +786,11 @@ int test_wolfSSL_CertManagerSetVerify(void) myVerifyAction = VERIFY_OVERRIDE_ERROR; ExpectIntEQ(wolfSSL_CertManagerVerify(cm, expiredCert, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); wolfSSL_CertManagerSetVerify(cm, NULL); ExpectIntNE(wolfSSL_CertManagerVerify(cm, expiredCert, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); wolfSSL_CertManagerSetVerify(cm, myVerify); #ifdef WOLFSSL_ALWAYS_VERIFY_CB @@ -747,7 +800,8 @@ int test_wolfSSL_CertManagerSetVerify(void) myVerifyAction = VERIFY_FORCE_FAIL; ExpectIntEQ(wolfSSL_CertManagerVerify(cm, verifyCert, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(VERIFY_CERT_ERROR)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(VERIFY_CERT_ERROR)); } #endif @@ -774,11 +828,11 @@ int test_wolfSSL_CertManagerNameConstraint(void) int i = 0; static const byte extNameConsOid[] = {85, 29, 30}; - RsaKey key; - WC_RNG rng; + RsaKey key; + WC_RNG rng; byte *der = NULL; - int derSz = 0; - word32 idx = 0; + int derSz = 0; + word32 idx = 0; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; @@ -788,13 +842,14 @@ int test_wolfSSL_CertManagerNameConstraint(void) /* load in CA private key for signing */ ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, testDevId), 0); ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key, - sizeof_server_key_der_2048), 0); + sizeof_server_key_der_2048), 0); /* get ca certificate then alter it */ ExpectNotNull(der = - (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)); + (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, + DYNAMIC_TYPE_TMP_BUFFER)); ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull(pt = (byte*)wolfSSL_X509_get_tbs(x509, &derSz)); if (EXPECT_SUCCESS() && (der != NULL)) { XMEMCPY(der, pt, (size_t)derSz); @@ -822,11 +877,12 @@ int test_wolfSSL_CertManagerNameConstraint(void) /* resign the altered certificate */ ExpectIntGT((derSz = wc_SignCert(derSz, CTC_SHA256wRSA, der, - FOURK_BUF, &key, NULL, &rng)), 0); + FOURK_BUF, &key, NULL, &rng)), 0); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_PARSE_E)); wolfSSL_CertManagerFree(cm); XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -837,32 +893,37 @@ int test_wolfSSL_CertManagerNameConstraint(void) /* add email alt name to satisfy constraint */ pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1) + ); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); DEBUG_WRITE_DER(der, derSz, "ca.der"); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* Good cert test with proper alt email name */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS); + (byte*)"support@info.wolfssl.com", 24 + , -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -874,25 +935,28 @@ int test_wolfSSL_CertManagerNameConstraint(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* Cert with bad alt name list */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS); + (byte*)"support@info.wolfssl.com", 24 + , -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -904,7 +968,8 @@ int test_wolfSSL_CertManagerNameConstraint(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -933,7 +998,7 @@ int test_wolfSSL_CertManagerNameConstraint2(void) const unsigned char *pt; WOLFSSL_EVP_PKEY *priv = NULL; WOLFSSL_X509_NAME* name = NULL; - int derSz = 0; + int derSz = 0; /* C=US*/ char altName[] = { @@ -971,13 +1036,15 @@ int test_wolfSSL_CertManagerNameConstraint2(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1) + ); ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) @@ -987,20 +1054,21 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* Test no name case. */ ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, NULL, 0, ASN_DIR_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_add_altname(x509, "", ASN_DIR_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* IP not supported unless WOLFSSL_IP_ALT_NAME is enabled. */ #ifdef WOLFSSL_IP_ALT_NAME ExpectIntEQ(wolfSSL_X509_add_altname(x509, "127.0.0.1", ASN_IP_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #else ExpectIntEQ(wolfSSL_X509_add_altname(x509, "127.0.0.1", ASN_IP_TYPE), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); #endif /* add in matching DIR alt name and resign */ @@ -1013,19 +1081,20 @@ int test_wolfSSL_CertManagerNameConstraint2(void) ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check verify fail */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); /* add in miss matching DIR alt name and resign */ wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail), - ASN_DIR_TYPE); + ASN_DIR_TYPE); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) wolfSSL_X509_sign(x509, priv, EVP_sha3_256()); @@ -1034,19 +1103,20 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); /* check that it still fails if one bad altname and one good altname is in * the certificate */ wolfSSL_X509_free(x509); x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE); wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail), - ASN_DIR_TYPE); + ASN_DIR_TYPE); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) wolfSSL_X509_sign(x509, priv, EVP_sha3_256()); @@ -1055,17 +1125,18 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); /* check it fails with switching position of bad altname */ wolfSSL_X509_free(x509); x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail), - ASN_DIR_TYPE); + ASN_DIR_TYPE); wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) @@ -1075,7 +1146,8 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); /* check that a directoryName that cannot be compared against the * permitted subtree fails the check rather than being taken as either @@ -1083,11 +1155,11 @@ int test_wolfSSL_CertManagerNameConstraint2(void) wolfSSL_X509_free(x509); x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); wolfSSL_X509_add_altname_ex(x509, altNameBadUtf8, sizeof(altNameBadUtf8), - ASN_DIR_TYPE); + ASN_DIR_TYPE); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) wolfSSL_X509_sign(x509, priv, EVP_sha3_256()); @@ -1096,7 +1168,8 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1107,15 +1180,17 @@ int test_wolfSSL_CertManagerNameConstraint2(void) /* now test with excluded name constraint */ ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert2, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1) + ); ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); wolfSSL_X509_add_altname_ex(x509, altNameExc, sizeof(altNameExc), - ASN_DIR_TYPE); + ASN_DIR_TYPE); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); @@ -1126,16 +1201,17 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); /* a directoryName that cannot be compared against the excluded subtree * has not been shown to be outside it, so it fails the check too */ wolfSSL_X509_free(x509); x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); wolfSSL_X509_add_altname_ex(x509, altNameBadUtf8, sizeof(altNameBadUtf8), - ASN_DIR_TYPE); + ASN_DIR_TYPE); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); @@ -1146,7 +1222,8 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1172,38 +1249,43 @@ int test_wolfSSL_CertManagerNameConstraint3(void) const char* server_cert = "./certs/test/server-goodcn.pem"; byte *der = NULL; - int derSz = 0; + int derSz = 0; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1) + ); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); DEBUG_WRITE_DER(der, derSz, "ca.der"); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* check satisfying .wolfssl.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS); + (byte*)"support@info.wolfssl.com", 24 + , -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1215,24 +1297,27 @@ int test_wolfSSL_CertManagerNameConstraint3(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check satisfying .random.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.example.com", 24, -1, 0), SSL_SUCCESS); + (byte*)"support@info.example.com", 24 + , -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1244,24 +1329,27 @@ int test_wolfSSL_CertManagerNameConstraint3(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check fail case when neither constraint is matched */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.com", 16, -1, 0), SSL_SUCCESS); + (byte*)"support@info.com", 16, -1, 0) + , SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1272,7 +1360,8 @@ int test_wolfSSL_CertManagerNameConstraint3(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1298,36 +1387,40 @@ int test_wolfSSL_CertManagerNameConstraint4(void) const char* server_cert = "./certs/test/server-goodcn.pem"; byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1) + ); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); DEBUG_WRITE_DER(der, derSz, "ca.der"); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* check satisfying wolfssl.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1338,22 +1431,24 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check satisfying example.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"example.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"example.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1364,22 +1459,24 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check satisfying wolfssl.com constraint passes with list of DNS's */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1392,22 +1489,24 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check fail when one DNS in the list is bad */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1420,22 +1519,24 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* check fail case when neither constraint is matched */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"common", 6, -1, 0), SSL_SUCCESS); + (byte*)"common", 6, -1, 0), + SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1445,7 +1546,8 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1471,36 +1573,40 @@ int test_wolfSSL_CertManagerNameConstraint5(void) const char* server_cert = "./certs/test/server-goodcn.pem"; byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1) + ); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); DEBUG_WRITE_DER(der, derSz, "ca.der"); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* check satisfying wolfssl.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"example", 7, -1, 0), SSL_SUCCESS); + (byte*)"example", 7, -1, 0), + SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1512,22 +1618,24 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* fail with DNS check because of common name */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), + SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1539,20 +1647,21 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* fail on permitted DNS name constraint */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1565,20 +1674,21 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* fail on permitted email name constraint */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1591,20 +1701,21 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* success with empty email name */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1614,7 +1725,8 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); wolfSSL_CertManagerFree(cm); @@ -1643,38 +1755,42 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) const char* server_cert = "./certs/test/server-goodcn.pem"; /* non-dNSName SAN values. The CA declares no registeredID or iPAddress * constraint, so these names are themselves unconstrained. */ - static const byte rid_dummy[] = { 0x2A, 0x03, 0x04 }; /* OID 1.2.3.4 */ - static const byte ip_dummy[] = { 203, 0, 113, 7 }; + static const byte rid_dummy[] = {0x2A, 0x03, 0x04}; /* OID 1.2.3.4 */ + static const byte ip_dummy[] = {203, 0, 113, 7}; byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1) + ); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* Negative case: leaf with an out-of-scope dNSName SAN. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0), + (byte*)"evil.attacker.com", 17, -1, 0 + ), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1685,22 +1801,24 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with an out-of-scope CN but an in-scope dNSName * SAN; the dNSName SAN suppresses the CN fallback, so it is accepted. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0), + (byte*)"evil.attacker.com", 17, -1, 0 + ), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1710,23 +1828,25 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* Negative case: leaf with an out-of-scope CN and no SAN; the CN is * checked against the DNS constraint as a fallback. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0), + (byte*)"evil.attacker.com", 17, -1, 0 + ), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1736,22 +1856,23 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with an in-scope CN and no SAN. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1761,81 +1882,90 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* Negative case: leaf with an out-of-scope CN and a registeredID SAN; * a non-dNSName SAN must not suppress the CN check. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0), + (byte*)"evil.attacker.com", 17, -1, 0 + ), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)rid_dummy, - sizeof(rid_dummy), ASN_RID_TYPE), WOLFSSL_SUCCESS); + sizeof(rid_dummy), ASN_RID_TYPE), + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Negative case: leaf with an out-of-scope CN and an iPAddress SAN. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0), + (byte*)"evil.attacker.com", 17, -1, 0 + ), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)ip_dummy, - sizeof(ip_dummy), ASN_IP_TYPE), WOLFSSL_SUCCESS); + sizeof(ip_dummy), ASN_IP_TYPE), + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with an in-scope CN and a registeredID SAN; the * check must not over-reject. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)rid_dummy, - sizeof(rid_dummy), ASN_RID_TYPE), WOLFSSL_SUCCESS); + sizeof(rid_dummy), ASN_RID_TYPE), + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1884,30 +2014,33 @@ int test_wolfSSL_CertManagerNameConstraint_IP_SAN(void) const char* ca_cert = "./certs/test/cert-ext-ncip.der"; const char* server_cert = "./certs/test/server-goodcn.pem"; /* Raw IPv4 bytes for SAN values (not dotted-quad strings). */ - static const byte ip_inside[] = { 192, 168, 1, 10 }; /* permitted */ - static const byte ip_outside[] = { 10, 0, 0, 1 }; /* violates */ + static const byte ip_inside[] = {192, 168, 1, 10}; /* permitted */ + static const byte ip_outside[] = {10, 0, 0, 1}; /* violates */ byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1) + ); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* Negative case: leaf with IP SAN outside permitted subnet. Must be * rejected with ASN_NAME_INVALID_E. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; @@ -1915,28 +2048,32 @@ int test_wolfSSL_CertManagerNameConstraint_IP_SAN(void) /* Use add_altname_ex with raw IP bytes so the test runs in default * builds where add_altname (string form) requires WOLFSSL_IP_ALT_NAME. */ ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)ip_outside, - sizeof(ip_outside), ASN_IP_TYPE), WOLFSSL_SUCCESS); + sizeof(ip_outside), ASN_IP_TYPE), + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with IP SAN inside the permitted subnet must be * accepted. Confirms the fix does not over-reject. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)ip_inside, - sizeof(ip_inside), ASN_IP_TYPE), WOLFSSL_SUCCESS); + sizeof(ip_inside), ASN_IP_TYPE), + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1984,57 +2121,64 @@ int test_wolfSSL_CertManagerNameConstraint_RID_SAN(void) * 40*X + Y in one byte for X<=2,Y<=39, then each subsequent arc is * base-128 with continuation bits. For values <128 the encoding is a * single byte. */ - static const byte rid_inside[] = { 0x2A, 0x03, 0x04, 0x05 }; /* 1.2.3.4.5 - permitted */ - static const byte rid_outside[] = { 0x2A, 0x03, 0x04, 0x63 }; /* 1.2.3.4.99 - violates */ + static const byte rid_inside[] = {0x2A, 0x03, 0x04, 0x05}; /* 1.2.3.4.5 - permitted */ + static const byte rid_outside[] = {0x2A, 0x03, 0x04, 0x63}; /* 1.2.3.4.99 - violates */ byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1) + ); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* Negative case: leaf with a registeredID SAN outside the permitted * OID set. Must be rejected with ASN_NAME_INVALID_E. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)rid_outside, - sizeof(rid_outside), ASN_RID_TYPE), WOLFSSL_SUCCESS); + sizeof(rid_outside), ASN_RID_TYPE), + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with a registeredID SAN matching the permitted * OID exactly must be accepted. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)rid_inside, - sizeof(rid_inside), ASN_RID_TYPE), WOLFSSL_SUCCESS); + sizeof(rid_inside), ASN_RID_TYPE), + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -2067,10 +2211,10 @@ int test_wolfSSL_X509_get_ext_d2i_RID_SAN(void) * d.dNSName-as-IA5STRING in the union). */ WOLFSSL_EVP_PKEY *priv = NULL; const char* server_cert = "./certs/test/server-goodcn.pem"; - static const byte rid_oid[] = { 0x2A, 0x03, 0x04, 0x05 }; + static const byte rid_oid[] = {0x2A, 0x03, 0x04, 0x05}; byte *pt; byte *der = NULL; - int derSz; + int derSz; WOLFSSL_X509 *leaf = NULL; WOLFSSL_X509 *parsed = NULL; WOLFSSL_STACK *altNames = NULL; @@ -2082,26 +2226,30 @@ int test_wolfSSL_X509_get_ext_d2i_RID_SAN(void) pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); /* Build and sign a leaf with a registeredID SAN. */ ExpectNotNull(leaf = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectIntEQ(wolfSSL_X509_add_altname_ex(leaf, (const char*)rid_oid, - sizeof(rid_oid), ASN_RID_TYPE), WOLFSSL_SUCCESS); + sizeof(rid_oid), ASN_RID_TYPE), + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leaf, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(leaf, &derSz))); /* Re-parse the signed leaf so altNames are populated through * DecodeGeneralName (the path the fix touches). */ ExpectNotNull(parsed = wolfSSL_X509_load_certificate_buffer(der, derSz, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1)); /* wolfSSL_X509_get_ext_d2i for SAN must return a non-NULL stack * containing a registeredID GENERAL_NAME with the union populated * via d.registeredID (not d.dNSName). */ ExpectNotNull(altNames = (WOLFSSL_STACK*)wolfSSL_X509_get_ext_d2i(parsed, - NID_subject_alt_name, NULL, NULL)); + NID_subject_alt_name, + NULL, NULL + )); if (altNames != NULL) { for (i = 0; i < wolfSSL_sk_num(altNames); i++) { gn = (WOLFSSL_GENERAL_NAME*)wolfSSL_sk_value(altNames, i); @@ -2123,7 +2271,7 @@ int test_wolfSSL_X509_get_ext_d2i_RID_SAN(void) ExpectIntEQ(gn->d.registeredID->obj[1], (byte)sizeof(rid_oid)); ExpectIntEQ(XMEMCMP(gn->d.registeredID->obj + 2, - rid_oid, sizeof(rid_oid)), 0); + rid_oid, sizeof(rid_oid)), 0); } } found = 1; @@ -2135,7 +2283,7 @@ int test_wolfSSL_X509_get_ext_d2i_RID_SAN(void) if (altNames != NULL) { wolfSSL_sk_pop_free(altNames, - (void (*)(void*))wolfSSL_GENERAL_NAME_free); + (void (*)(void*)) wolfSSL_GENERAL_NAME_free); } /* Also exercise wolfSSL_X509_get_ext, which routes through @@ -2187,26 +2335,29 @@ int test_wolfSSL_X509_check_host_IP_only_SAN_CN_fallback(void) WOLFSSL_X509_NAME* name = NULL; const char* server_cert = "./certs/test/server-goodcn.pem"; const char hostName[] = "cnhost.local"; - static const byte ip_san[] = { 10, 0, 0, 1 }; + static const byte ip_san[] = {10, 0, 0, 1}; byte *pt; WOLFSSL_X509 *leafIp = NULL; WOLFSSL_X509 *leafDns = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); /* Leaf with CN matching hostName and only an iPAddress SAN. */ ExpectNotNull(leafIp = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); + (byte*)hostName, (int)XSTRLEN( + hostName), -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(leafIp, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(leafIp, (const char*)ip_san, - sizeof(ip_san), ASN_IP_TYPE), WOLFSSL_SUCCESS); + sizeof(ip_san), ASN_IP_TYPE), + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leafIp, priv, EVP_sha256()), 0); #ifndef WOLFSSL_IP_ALT_NAME @@ -2214,13 +2365,14 @@ int test_wolfSSL_X509_check_host_IP_only_SAN_CN_fallback(void) * constraint enforcement but treated as absent for *checkCN, so the * lookup falls back to the Subject CN, which matches. */ ExpectIntEQ(wolfSSL_X509_check_host(leafIp, hostName, XSTRLEN(hostName), - 0, NULL), WOLFSSL_SUCCESS); + 0, NULL), WOLFSSL_SUCCESS); #else /* IP_ALT_NAME build: SAN presence suppresses CN fallback per RFC 6125. * The hostName ("cnhost.local") cannot match the iPAddress entry, so * the check must fail. */ ExpectIntEQ(wolfSSL_X509_check_host(leafIp, hostName, XSTRLEN(hostName), - 0, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + 0, NULL), WC_NO_ERR_TRACE( + WOLFSSL_FAILURE)); #endif /* Leaf with CN matching hostName but a non-matching DNS SAN. CN @@ -2229,18 +2381,20 @@ int test_wolfSSL_X509_check_host_IP_only_SAN_CN_fallback(void) * other side of the boundary so a future change that broadly skips * altNames in *checkCN does not silently regress. */ ExpectNotNull(leafDns = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); + (byte*)hostName, (int)XSTRLEN( + hostName), -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(leafDns, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname(leafDns, "other.example", - ASN_DNS_TYPE), WOLFSSL_SUCCESS); + ASN_DNS_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leafDns, priv, EVP_sha256()), 0); ExpectIntEQ(wolfSSL_X509_check_host(leafDns, hostName, XSTRLEN(hostName), - 0, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + 0, NULL), WC_NO_ERR_TRACE( + WOLFSSL_FAILURE)); wolfSSL_X509_free(leafIp); wolfSSL_X509_free(leafDns); @@ -2273,38 +2427,43 @@ int test_wolfSSL_X509_check_host_URI_SAN_not_DNS_match(void) pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, sizeof_server_key_der_2048)); + (const unsigned char**)&pt, + sizeof_server_key_der_2048)); ExpectNotNull(leafUri = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); + (byte*)hostName, (int)XSTRLEN( + hostName), -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(leafUri, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname(leafUri, uriSan, ASN_URI_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leafUri, priv, EVP_sha256()), 0); ExpectIntEQ(wolfSSL_X509_check_host(leafUri, hostName, XSTRLEN(hostName), - 0, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + 0, NULL), WC_NO_ERR_TRACE( + WOLFSSL_FAILURE)); ExpectNotNull(leafUriDns = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); + (byte*)hostName, (int)XSTRLEN( + hostName), -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(leafUriDns, name), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname(leafUriDns, uriSan, ASN_URI_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_add_altname(leafUriDns, hostName, ASN_DNS_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leafUriDns, priv, EVP_sha256()), 0); ExpectIntEQ(wolfSSL_X509_check_host(leafUriDns, hostName, - XSTRLEN(hostName), 0, NULL), WOLFSSL_SUCCESS); + XSTRLEN(hostName), 0, NULL), + WOLFSSL_SUCCESS); wolfSSL_X509_free(leafUri); wolfSSL_X509_free(leafUriDns); @@ -2400,113 +2559,130 @@ int test_wolfSSL_CertManagerCRL(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(NULL, 0), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK), 1); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, - WOLFSSL_CRL_CHECK | WOLFSSL_CRL_CHECKALL), 1); + WOLFSSL_CRL_CHECK | + WOLFSSL_CRL_CHECKALL), 1); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 16), 1); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, - sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + sizeof_server_cert_der_2048), + WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(cm, NULL), 1); #ifdef HAVE_CRL_IO ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1); #endif #ifndef NO_FILESYSTEM ExpectIntEQ(wolfSSL_CertManagerLoadCRL(NULL, NULL, WOLFSSL_FILETYPE_ASN1, - 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, NULL, WOLFSSL_FILETYPE_ASN1, - 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* -1 seen as !WOLFSSL_FILETYPE_PEM */ ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, "./certs/crl", -1, 0), 1); ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(NULL, NULL, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, NULL, WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* -1 seen as !WOLFSSL_FILETYPE_PEM */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, "./certs/crl/crl.pem", -1), - WC_NO_ERR_TRACE(ASN_PARSE_E)); + WC_NO_ERR_TRACE(ASN_PARSE_E)); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, -1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, -1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, -1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, 1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, 1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, 1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, -1, - WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, 0, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, - sizeof(crl_buff) - 1, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(crl_buff) - 1, + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerFreeCRL(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); DoExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); + wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0)); + wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0)); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0)); + wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0)); wolfSSL_CertManagerFreeCRL(cm); #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0)); + wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0)); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); + wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, - sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_MISSING)); + sizeof_server_cert_der_2048), + WC_NO_ERR_TRACE(CRL_MISSING)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, server_cert_der_2048, - sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(CRL_MISSING)); + sizeof_server_cert_der_2048, + WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(CRL_MISSING)); #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, sizeof(crl_buff), - WOLFSSL_FILETYPE_ASN1), 1); + WOLFSSL_FILETYPE_ASN1), 1); #if !defined(NO_FILESYSTEM) && defined(WC_RSA_PSS) /* loading should fail without the CA set */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss, - WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E)); + WOLFSSL_FILETYPE_PEM), + WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E)); /* now successfully load the RSA-PSS crl once loading in it's CA */ ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL)); + wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); #endif wolfSSL_CertManagerFree(cm); @@ -2529,12 +2705,14 @@ int test_wolfSSL_CRL_reason_extensions_cleanup(void) ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, ca_cert_der_2048, - sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1), + sizeof_ca_cert_der_2048, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* Exercises ParseCRL/GetRevoked path that allocates entry extensions; * cleanup runs via FreeDecodedCRL in BufferLoadCRL. */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crlReasonFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); } #endif @@ -2634,19 +2812,22 @@ int test_wolfSSL_CRL_static_revoked_list(void) /* Set up CertManager with the CA and CRL checking enabled */ ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, "./certs/ca-cert.pem", NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Load the CRL that revokes serials {05, 02, 01} in unsorted wire order */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_multi_revoked, - sizeof(crl_multi_revoked), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(crl_multi_revoked), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* server-cert.pem has serial 01, which is in the CRL but at the last * position in the unsorted array. Binary search on unsorted data misses * it, so this assertion fails before the bug fix. */ ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, - sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_CERT_REVOKED)); + sizeof_server_cert_der_2048), + WC_NO_ERR_TRACE(CRL_CERT_REVOKED)); wolfSSL_CertManagerFree(cm); #endif @@ -2676,16 +2857,16 @@ int test_wolfSSL_CRL_static_revoked_list_dup(void) ExpectNotNull(crl != NULL ? crl->crlList : NULL); ExpectIntGT((crl != NULL && crl->crlList != NULL) ? - crl->crlList->totalCerts : 0, 0); + crl->crlList->totalCerts : 0, 0); ExpectNotNull((crl != NULL && crl->crlList != NULL) ? - crl->crlList->certs[0].extensions : NULL); + crl->crlList->certs[0].extensions : NULL); ExpectNotNull(dupl = wolfSSL_X509_CRL_dup(crl)); /* Every duplicated revoked cert must own its own copy of the extensions. * A shallow copy shares the pointer, a dropped copy leaves it NULL. */ if (crl != NULL && dupl != NULL && crl->crlList != NULL && - dupl->crlList != NULL) { + dupl->crlList != NULL) { int i; for (i = 0; i < crl->crlList->totalCerts; i++) { const RevokedCert* o = &crl->crlList->certs[i]; @@ -2932,18 +3113,24 @@ int test_wolfSSL_CRL_critical_idp(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, ca_cert_idp, - sizeof(ca_cert_idp), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(ca_cert_idp), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* User-scope CRL has a critical IDP extension, must be rejected */ ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_user_idp, - sizeof(crl_user_idp), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(crl_user_idp), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); /* CA-only CRL also has a critical IDP extension, must be rejected */ ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_caonly_idp, - sizeof(crl_caonly_idp), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(crl_caonly_idp), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); #endif @@ -3407,7 +3594,9 @@ int test_wolfSSL_cert_critical_policy_constraints(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntNE(wolfSSL_CertManagerLoadCABuffer(cm, cert_crit_policy, - sizeof(cert_crit_policy), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(cert_crit_policy), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); #endif return EXPECT_RESULT(); @@ -3417,124 +3606,124 @@ int test_wolfSSL_cert_critical_policy_constraints(void) /* claim-root CA, DER. Shared by the unknown-critical-CRL-extension tests * below. */ static const unsigned char crl_unk_ca_der[] = { - 0x30, 0x82, 0x03, 0x1b, 0x30, 0x82, 0x02, 0x03, 0xa0, 0x03, 0x02, - 0x01, 0x02, 0x02, 0x14, 0x1e, 0x25, 0xc1, 0x5d, 0x6f, 0x02, 0x21, - 0xa0, 0xf0, 0x14, 0x15, 0x9c, 0x3b, 0x4d, 0x1d, 0x73, 0x16, 0x00, - 0xe4, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, - 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, - 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, - 0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x1e, 0x17, 0x0d, - 0x32, 0x36, 0x30, 0x34, 0x31, 0x36, 0x31, 0x31, 0x33, 0x38, 0x35, - 0x35, 0x5a, 0x17, 0x0d, 0x33, 0x36, 0x30, 0x34, 0x31, 0x33, 0x31, - 0x31, 0x33, 0x38, 0x35, 0x35, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30, - 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, - 0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x82, 0x01, 0x22, - 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, - 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, - 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xba, 0x49, 0x8c, 0xb5, - 0x17, 0xc1, 0x01, 0x24, 0x6f, 0x56, 0x1a, 0xa9, 0x3b, 0x03, 0xe2, - 0x9f, 0x24, 0xb1, 0x25, 0x98, 0xfb, 0x38, 0x82, 0x78, 0x54, 0xa7, - 0x1f, 0x69, 0x87, 0xe4, 0x96, 0x1b, 0x81, 0x18, 0x10, 0xb0, 0xc0, - 0x5b, 0x4b, 0xbf, 0xb8, 0x1d, 0xf4, 0xee, 0x75, 0x0f, 0xb5, 0x45, - 0x72, 0x70, 0xce, 0x65, 0x84, 0x44, 0x3e, 0x30, 0x78, 0xc4, 0xf3, - 0xec, 0xba, 0x96, 0x78, 0xa4, 0x65, 0xfc, 0x62, 0x8d, 0xf5, 0x29, - 0xf9, 0x7c, 0x3d, 0x78, 0x6c, 0x1d, 0x4a, 0x4c, 0xc9, 0x15, 0x2d, - 0x22, 0x10, 0xea, 0x93, 0x26, 0xb8, 0xa6, 0x17, 0xd3, 0x0e, 0xbc, - 0x0c, 0xab, 0x83, 0x63, 0xf6, 0x1c, 0xcc, 0x83, 0x73, 0x29, 0x7e, - 0x7f, 0x83, 0x7f, 0xbd, 0x63, 0xaa, 0x8d, 0xfa, 0x78, 0x85, 0xd2, - 0x3e, 0x60, 0x95, 0x5a, 0x8d, 0xfa, 0x8f, 0xcd, 0x94, 0x3f, 0x13, - 0x28, 0xd9, 0xd0, 0x87, 0x28, 0x17, 0x78, 0xe2, 0x61, 0x8d, 0x79, - 0x97, 0x01, 0xa9, 0x7c, 0x84, 0xc0, 0x1c, 0xbe, 0x5f, 0x5d, 0xca, - 0x28, 0x6b, 0x5e, 0xdd, 0x83, 0xa5, 0x55, 0x34, 0x11, 0xba, 0xfa, - 0x8b, 0x92, 0xa3, 0xde, 0xb6, 0xf3, 0xba, 0xab, 0x7f, 0x1a, 0x67, - 0xfd, 0x6f, 0x20, 0x85, 0x4c, 0x77, 0xa7, 0x8e, 0xbe, 0xb8, 0xf8, - 0x8f, 0x70, 0xe3, 0x5a, 0xd3, 0x77, 0xc9, 0x9e, 0x10, 0x60, 0xb4, - 0xdb, 0x0c, 0xc5, 0x05, 0xe1, 0x1f, 0xbd, 0xe6, 0x79, 0xee, 0x82, - 0x3f, 0x51, 0x76, 0xe2, 0x7f, 0x5c, 0x11, 0x6d, 0xd3, 0x21, 0x69, - 0xec, 0x05, 0x11, 0x8b, 0xc8, 0x39, 0xb3, 0x2c, 0xa6, 0x83, 0xb4, - 0x6f, 0xac, 0x19, 0xd6, 0x6a, 0x65, 0x0d, 0x08, 0x94, 0x58, 0xde, - 0x3d, 0xc9, 0x0c, 0x54, 0x03, 0x73, 0x0c, 0x8d, 0x24, 0x09, 0xf3, - 0xb1, 0x5d, 0xd2, 0xe3, 0xeb, 0x56, 0xd6, 0x28, 0x66, 0x5b, 0x02, - 0x03, 0x01, 0x00, 0x01, 0xa3, 0x63, 0x30, 0x61, 0x30, 0x0f, 0x06, - 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, - 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, - 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, - 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x52, 0x97, 0x58, - 0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, - 0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x1f, 0x06, 0x03, 0x55, - 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x52, 0x97, 0x58, - 0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, - 0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x0d, 0x06, 0x09, 0x2a, - 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, - 0x82, 0x01, 0x01, 0x00, 0x7d, 0x30, 0xd4, 0x6a, 0x01, 0x89, 0x3b, - 0x62, 0xed, 0x16, 0x46, 0x59, 0x0f, 0xf2, 0x3b, 0xb5, 0xde, 0x89, - 0x08, 0x17, 0x68, 0xcb, 0x46, 0xdc, 0x39, 0xa6, 0xcb, 0x56, 0xb0, - 0x91, 0xeb, 0x03, 0xb2, 0x15, 0xc4, 0x3b, 0x4d, 0x63, 0x55, 0x22, - 0x0a, 0x26, 0xe6, 0x64, 0x46, 0xe8, 0x0f, 0xa8, 0xf3, 0xde, 0xe1, - 0x43, 0x54, 0xe6, 0xd7, 0x8a, 0xf4, 0x4f, 0xab, 0x56, 0x93, 0x12, - 0x71, 0x4b, 0x25, 0x71, 0x0a, 0x31, 0x18, 0x79, 0xee, 0x45, 0xa4, - 0xf5, 0x72, 0x67, 0xfa, 0x41, 0xd9, 0x87, 0x97, 0x09, 0xef, 0x55, - 0xad, 0x6f, 0x47, 0x1d, 0x5a, 0xb2, 0xe9, 0xf7, 0x22, 0x05, 0x2d, - 0x5a, 0x81, 0xa8, 0xe8, 0x53, 0xb0, 0x94, 0xf6, 0x63, 0xff, 0x3f, - 0x51, 0x7a, 0x08, 0xac, 0x27, 0x9a, 0x57, 0x11, 0x22, 0xa4, 0x00, - 0x84, 0x70, 0x86, 0x76, 0x39, 0x0f, 0x4f, 0x57, 0xcf, 0x8e, 0x94, - 0xd2, 0x8e, 0x43, 0xc0, 0xd5, 0x34, 0x7d, 0xf5, 0xa1, 0x45, 0x1e, - 0xb7, 0xc8, 0x7e, 0x7c, 0xfe, 0x5d, 0x4d, 0x53, 0x43, 0x25, 0x15, - 0x9e, 0x08, 0x01, 0x56, 0xa4, 0xff, 0x79, 0x59, 0x25, 0xc9, 0x23, - 0x98, 0xaf, 0x05, 0xaf, 0xc1, 0x0b, 0x29, 0xf1, 0xe2, 0xc4, 0x36, - 0x31, 0x91, 0xfa, 0xf2, 0xbb, 0x12, 0xe8, 0x67, 0xf9, 0xc7, 0xa1, - 0x5e, 0x8c, 0xed, 0x92, 0x12, 0xa3, 0x2b, 0xe1, 0xc2, 0xe1, 0xa0, - 0xb0, 0x0e, 0x12, 0xa7, 0xd0, 0xa2, 0xae, 0xd6, 0xfa, 0x30, 0x21, - 0x0f, 0x73, 0xfe, 0x24, 0x21, 0x5f, 0x03, 0x86, 0x69, 0xcd, 0xec, - 0x76, 0x18, 0xe1, 0xfd, 0xb6, 0x64, 0x90, 0xa6, 0x06, 0x2e, 0x19, - 0x40, 0x93, 0x50, 0x37, 0xe4, 0x90, 0xe3, 0x1f, 0x07, 0xae, 0xfb, - 0x89, 0xc3, 0xf6, 0xc4, 0x90, 0xab, 0x40, 0x67, 0x4c, 0x43, 0x2c, - 0xa2, 0xb0, 0x3e, 0x61, 0x16, 0x69, 0x8f - }; + 0x30, 0x82, 0x03, 0x1b, 0x30, 0x82, 0x02, 0x03, 0xa0, 0x03, 0x02, + 0x01, 0x02, 0x02, 0x14, 0x1e, 0x25, 0xc1, 0x5d, 0x6f, 0x02, 0x21, + 0xa0, 0xf0, 0x14, 0x15, 0x9c, 0x3b, 0x4d, 0x1d, 0x73, 0x16, 0x00, + 0xe4, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, + 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, + 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, + 0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x1e, 0x17, 0x0d, + 0x32, 0x36, 0x30, 0x34, 0x31, 0x36, 0x31, 0x31, 0x33, 0x38, 0x35, + 0x35, 0x5a, 0x17, 0x0d, 0x33, 0x36, 0x30, 0x34, 0x31, 0x33, 0x31, + 0x31, 0x33, 0x38, 0x35, 0x35, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30, + 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, + 0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x82, 0x01, 0x22, + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, + 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, + 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xba, 0x49, 0x8c, 0xb5, + 0x17, 0xc1, 0x01, 0x24, 0x6f, 0x56, 0x1a, 0xa9, 0x3b, 0x03, 0xe2, + 0x9f, 0x24, 0xb1, 0x25, 0x98, 0xfb, 0x38, 0x82, 0x78, 0x54, 0xa7, + 0x1f, 0x69, 0x87, 0xe4, 0x96, 0x1b, 0x81, 0x18, 0x10, 0xb0, 0xc0, + 0x5b, 0x4b, 0xbf, 0xb8, 0x1d, 0xf4, 0xee, 0x75, 0x0f, 0xb5, 0x45, + 0x72, 0x70, 0xce, 0x65, 0x84, 0x44, 0x3e, 0x30, 0x78, 0xc4, 0xf3, + 0xec, 0xba, 0x96, 0x78, 0xa4, 0x65, 0xfc, 0x62, 0x8d, 0xf5, 0x29, + 0xf9, 0x7c, 0x3d, 0x78, 0x6c, 0x1d, 0x4a, 0x4c, 0xc9, 0x15, 0x2d, + 0x22, 0x10, 0xea, 0x93, 0x26, 0xb8, 0xa6, 0x17, 0xd3, 0x0e, 0xbc, + 0x0c, 0xab, 0x83, 0x63, 0xf6, 0x1c, 0xcc, 0x83, 0x73, 0x29, 0x7e, + 0x7f, 0x83, 0x7f, 0xbd, 0x63, 0xaa, 0x8d, 0xfa, 0x78, 0x85, 0xd2, + 0x3e, 0x60, 0x95, 0x5a, 0x8d, 0xfa, 0x8f, 0xcd, 0x94, 0x3f, 0x13, + 0x28, 0xd9, 0xd0, 0x87, 0x28, 0x17, 0x78, 0xe2, 0x61, 0x8d, 0x79, + 0x97, 0x01, 0xa9, 0x7c, 0x84, 0xc0, 0x1c, 0xbe, 0x5f, 0x5d, 0xca, + 0x28, 0x6b, 0x5e, 0xdd, 0x83, 0xa5, 0x55, 0x34, 0x11, 0xba, 0xfa, + 0x8b, 0x92, 0xa3, 0xde, 0xb6, 0xf3, 0xba, 0xab, 0x7f, 0x1a, 0x67, + 0xfd, 0x6f, 0x20, 0x85, 0x4c, 0x77, 0xa7, 0x8e, 0xbe, 0xb8, 0xf8, + 0x8f, 0x70, 0xe3, 0x5a, 0xd3, 0x77, 0xc9, 0x9e, 0x10, 0x60, 0xb4, + 0xdb, 0x0c, 0xc5, 0x05, 0xe1, 0x1f, 0xbd, 0xe6, 0x79, 0xee, 0x82, + 0x3f, 0x51, 0x76, 0xe2, 0x7f, 0x5c, 0x11, 0x6d, 0xd3, 0x21, 0x69, + 0xec, 0x05, 0x11, 0x8b, 0xc8, 0x39, 0xb3, 0x2c, 0xa6, 0x83, 0xb4, + 0x6f, 0xac, 0x19, 0xd6, 0x6a, 0x65, 0x0d, 0x08, 0x94, 0x58, 0xde, + 0x3d, 0xc9, 0x0c, 0x54, 0x03, 0x73, 0x0c, 0x8d, 0x24, 0x09, 0xf3, + 0xb1, 0x5d, 0xd2, 0xe3, 0xeb, 0x56, 0xd6, 0x28, 0x66, 0x5b, 0x02, + 0x03, 0x01, 0x00, 0x01, 0xa3, 0x63, 0x30, 0x61, 0x30, 0x0f, 0x06, + 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, + 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, + 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, + 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x52, 0x97, 0x58, + 0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, + 0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x1f, 0x06, 0x03, 0x55, + 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x52, 0x97, 0x58, + 0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, + 0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, + 0x82, 0x01, 0x01, 0x00, 0x7d, 0x30, 0xd4, 0x6a, 0x01, 0x89, 0x3b, + 0x62, 0xed, 0x16, 0x46, 0x59, 0x0f, 0xf2, 0x3b, 0xb5, 0xde, 0x89, + 0x08, 0x17, 0x68, 0xcb, 0x46, 0xdc, 0x39, 0xa6, 0xcb, 0x56, 0xb0, + 0x91, 0xeb, 0x03, 0xb2, 0x15, 0xc4, 0x3b, 0x4d, 0x63, 0x55, 0x22, + 0x0a, 0x26, 0xe6, 0x64, 0x46, 0xe8, 0x0f, 0xa8, 0xf3, 0xde, 0xe1, + 0x43, 0x54, 0xe6, 0xd7, 0x8a, 0xf4, 0x4f, 0xab, 0x56, 0x93, 0x12, + 0x71, 0x4b, 0x25, 0x71, 0x0a, 0x31, 0x18, 0x79, 0xee, 0x45, 0xa4, + 0xf5, 0x72, 0x67, 0xfa, 0x41, 0xd9, 0x87, 0x97, 0x09, 0xef, 0x55, + 0xad, 0x6f, 0x47, 0x1d, 0x5a, 0xb2, 0xe9, 0xf7, 0x22, 0x05, 0x2d, + 0x5a, 0x81, 0xa8, 0xe8, 0x53, 0xb0, 0x94, 0xf6, 0x63, 0xff, 0x3f, + 0x51, 0x7a, 0x08, 0xac, 0x27, 0x9a, 0x57, 0x11, 0x22, 0xa4, 0x00, + 0x84, 0x70, 0x86, 0x76, 0x39, 0x0f, 0x4f, 0x57, 0xcf, 0x8e, 0x94, + 0xd2, 0x8e, 0x43, 0xc0, 0xd5, 0x34, 0x7d, 0xf5, 0xa1, 0x45, 0x1e, + 0xb7, 0xc8, 0x7e, 0x7c, 0xfe, 0x5d, 0x4d, 0x53, 0x43, 0x25, 0x15, + 0x9e, 0x08, 0x01, 0x56, 0xa4, 0xff, 0x79, 0x59, 0x25, 0xc9, 0x23, + 0x98, 0xaf, 0x05, 0xaf, 0xc1, 0x0b, 0x29, 0xf1, 0xe2, 0xc4, 0x36, + 0x31, 0x91, 0xfa, 0xf2, 0xbb, 0x12, 0xe8, 0x67, 0xf9, 0xc7, 0xa1, + 0x5e, 0x8c, 0xed, 0x92, 0x12, 0xa3, 0x2b, 0xe1, 0xc2, 0xe1, 0xa0, + 0xb0, 0x0e, 0x12, 0xa7, 0xd0, 0xa2, 0xae, 0xd6, 0xfa, 0x30, 0x21, + 0x0f, 0x73, 0xfe, 0x24, 0x21, 0x5f, 0x03, 0x86, 0x69, 0xcd, 0xec, + 0x76, 0x18, 0xe1, 0xfd, 0xb6, 0x64, 0x90, 0xa6, 0x06, 0x2e, 0x19, + 0x40, 0x93, 0x50, 0x37, 0xe4, 0x90, 0xe3, 0x1f, 0x07, 0xae, 0xfb, + 0x89, 0xc3, 0xf6, 0xc4, 0x90, 0xab, 0x40, 0x67, 0x4c, 0x43, 0x2c, + 0xa2, 0xb0, 0x3e, 0x61, 0x16, 0x69, 0x8f +}; /* CRL with a critical obsolete CRL-level extension OID 2.5.29.1, 422 bytes * DER. OID 2.5.29.1 is the old X.509v2 Authority Key Identifier, permanently * superseded by 2.5.29.35. No implementation will ever support it. */ static const unsigned char crl_obsolete_critical[] = { - 0x30, 0x82, 0x01, 0xa6, 0x30, 0x81, 0x8f, 0x02, 0x01, 0x01, 0x30, - 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, - 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, - 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x2d, - 0x72, 0x6f, 0x6f, 0x74, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x34, 0x31, - 0x36, 0x31, 0x35, 0x32, 0x31, 0x30, 0x37, 0x5a, 0x17, 0x0d, 0x33, - 0x36, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35, 0x32, 0x31, 0x30, 0x37, - 0x5a, 0xa0, 0x46, 0x30, 0x44, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, - 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x52, 0x97, 0x58, 0x47, - 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, 0xea, - 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x14, 0x06, 0x03, 0x55, 0x1d, - 0x01, 0x01, 0x01, 0xff, 0x04, 0x0a, 0x0c, 0x08, 0x6f, 0x62, 0x73, - 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, - 0x14, 0x04, 0x04, 0x02, 0x02, 0x20, 0x02, 0x30, 0x0d, 0x06, 0x09, - 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, - 0x03, 0x82, 0x01, 0x01, 0x00, 0x05, 0xf3, 0x8f, 0xdb, 0x7f, 0x75, - 0x2c, 0x34, 0x4b, 0x7e, 0x70, 0x17, 0x5e, 0x34, 0xc6, 0xdb, 0xcb, - 0x54, 0x33, 0x06, 0x58, 0x6d, 0xae, 0x9c, 0xc8, 0xe3, 0xaf, 0x82, - 0xe5, 0xf6, 0x86, 0x42, 0xb3, 0x01, 0x72, 0x1a, 0xca, 0xf9, 0x10, - 0x5d, 0x14, 0xe6, 0x84, 0x34, 0x56, 0x55, 0x74, 0xb5, 0x06, 0x64, - 0x49, 0x1d, 0xb3, 0xb0, 0x13, 0xff, 0x1c, 0x05, 0x4f, 0x43, 0x29, - 0xbc, 0xfe, 0xb5, 0x92, 0x54, 0xf6, 0x9b, 0x81, 0x07, 0x5e, 0x2e, - 0x75, 0xd8, 0xfd, 0x9b, 0x5b, 0xc9, 0xd3, 0xc2, 0x15, 0xa7, 0x6e, - 0x2f, 0x4b, 0x3a, 0x27, 0x57, 0xef, 0x40, 0x61, 0x8c, 0x11, 0x9d, - 0x0a, 0xb1, 0x2b, 0x0e, 0xed, 0x5d, 0xf2, 0xf5, 0x1a, 0xce, 0xdc, - 0xd7, 0x75, 0xc6, 0x25, 0x22, 0xe4, 0x70, 0xad, 0x93, 0xff, 0x36, - 0xa1, 0xa2, 0xa0, 0xd9, 0x82, 0x23, 0x6e, 0xc8, 0x3a, 0x80, 0x82, - 0xbf, 0x12, 0xac, 0xa1, 0xf9, 0x03, 0x9c, 0xb9, 0x20, 0x91, 0x33, - 0x80, 0x7b, 0xb7, 0x6e, 0xa5, 0x32, 0x98, 0xd6, 0x2c, 0x5d, 0x9d, - 0x3b, 0x64, 0x3b, 0xb4, 0xea, 0x03, 0x2d, 0x65, 0xcf, 0x7f, 0x0f, - 0x97, 0xef, 0x5b, 0x17, 0x8c, 0xcf, 0x98, 0x69, 0xba, 0x2d, 0x62, - 0xe9, 0x40, 0xe2, 0x3d, 0xbd, 0xd2, 0x0f, 0x4a, 0xf8, 0xb0, 0xa7, - 0xdb, 0x80, 0xa3, 0x47, 0x56, 0xe5, 0xe6, 0x6f, 0x93, 0x5c, 0x6f, - 0xdd, 0x62, 0x43, 0x28, 0x5c, 0xe5, 0x8f, 0x0e, 0x11, 0xa6, 0x1f, - 0x61, 0xaf, 0x39, 0x15, 0x40, 0xf4, 0x6e, 0x79, 0x40, 0xf6, 0x28, - 0xf3, 0xd4, 0x30, 0x3b, 0x25, 0xb6, 0xf0, 0x4a, 0x51, 0xc3, 0x18, - 0xff, 0xad, 0x4d, 0x6e, 0x10, 0x73, 0x68, 0xfa, 0x54, 0x9e, 0xdc, - 0x34, 0x70, 0xe4, 0x5d, 0x9e, 0x7c, 0xfa, 0x59, 0x97, 0xde, 0x35, - 0x17, 0xbb, 0xaf, 0xa0, 0x28, 0x78, 0x13, 0xbf + 0x30, 0x82, 0x01, 0xa6, 0x30, 0x81, 0x8f, 0x02, 0x01, 0x01, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, + 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, + 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x2d, + 0x72, 0x6f, 0x6f, 0x74, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x34, 0x31, + 0x36, 0x31, 0x35, 0x32, 0x31, 0x30, 0x37, 0x5a, 0x17, 0x0d, 0x33, + 0x36, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35, 0x32, 0x31, 0x30, 0x37, + 0x5a, 0xa0, 0x46, 0x30, 0x44, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, + 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x52, 0x97, 0x58, 0x47, + 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, 0xea, + 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x14, 0x06, 0x03, 0x55, 0x1d, + 0x01, 0x01, 0x01, 0xff, 0x04, 0x0a, 0x0c, 0x08, 0x6f, 0x62, 0x73, + 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, + 0x14, 0x04, 0x04, 0x02, 0x02, 0x20, 0x02, 0x30, 0x0d, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, + 0x03, 0x82, 0x01, 0x01, 0x00, 0x05, 0xf3, 0x8f, 0xdb, 0x7f, 0x75, + 0x2c, 0x34, 0x4b, 0x7e, 0x70, 0x17, 0x5e, 0x34, 0xc6, 0xdb, 0xcb, + 0x54, 0x33, 0x06, 0x58, 0x6d, 0xae, 0x9c, 0xc8, 0xe3, 0xaf, 0x82, + 0xe5, 0xf6, 0x86, 0x42, 0xb3, 0x01, 0x72, 0x1a, 0xca, 0xf9, 0x10, + 0x5d, 0x14, 0xe6, 0x84, 0x34, 0x56, 0x55, 0x74, 0xb5, 0x06, 0x64, + 0x49, 0x1d, 0xb3, 0xb0, 0x13, 0xff, 0x1c, 0x05, 0x4f, 0x43, 0x29, + 0xbc, 0xfe, 0xb5, 0x92, 0x54, 0xf6, 0x9b, 0x81, 0x07, 0x5e, 0x2e, + 0x75, 0xd8, 0xfd, 0x9b, 0x5b, 0xc9, 0xd3, 0xc2, 0x15, 0xa7, 0x6e, + 0x2f, 0x4b, 0x3a, 0x27, 0x57, 0xef, 0x40, 0x61, 0x8c, 0x11, 0x9d, + 0x0a, 0xb1, 0x2b, 0x0e, 0xed, 0x5d, 0xf2, 0xf5, 0x1a, 0xce, 0xdc, + 0xd7, 0x75, 0xc6, 0x25, 0x22, 0xe4, 0x70, 0xad, 0x93, 0xff, 0x36, + 0xa1, 0xa2, 0xa0, 0xd9, 0x82, 0x23, 0x6e, 0xc8, 0x3a, 0x80, 0x82, + 0xbf, 0x12, 0xac, 0xa1, 0xf9, 0x03, 0x9c, 0xb9, 0x20, 0x91, 0x33, + 0x80, 0x7b, 0xb7, 0x6e, 0xa5, 0x32, 0x98, 0xd6, 0x2c, 0x5d, 0x9d, + 0x3b, 0x64, 0x3b, 0xb4, 0xea, 0x03, 0x2d, 0x65, 0xcf, 0x7f, 0x0f, + 0x97, 0xef, 0x5b, 0x17, 0x8c, 0xcf, 0x98, 0x69, 0xba, 0x2d, 0x62, + 0xe9, 0x40, 0xe2, 0x3d, 0xbd, 0xd2, 0x0f, 0x4a, 0xf8, 0xb0, 0xa7, + 0xdb, 0x80, 0xa3, 0x47, 0x56, 0xe5, 0xe6, 0x6f, 0x93, 0x5c, 0x6f, + 0xdd, 0x62, 0x43, 0x28, 0x5c, 0xe5, 0x8f, 0x0e, 0x11, 0xa6, 0x1f, + 0x61, 0xaf, 0x39, 0x15, 0x40, 0xf4, 0x6e, 0x79, 0x40, 0xf6, 0x28, + 0xf3, 0xd4, 0x30, 0x3b, 0x25, 0xb6, 0xf0, 0x4a, 0x51, 0xc3, 0x18, + 0xff, 0xad, 0x4d, 0x6e, 0x10, 0x73, 0x68, 0xfa, 0x54, 0x9e, 0xdc, + 0x34, 0x70, 0xe4, 0x5d, 0x9e, 0x7c, 0xfa, 0x59, 0x97, 0xde, 0x35, + 0x17, 0xbb, 0xaf, 0xa0, 0x28, 0x78, 0x13, 0xbf }; #endif /* !NO_CERTS && HAVE_CRL && !NO_RSA */ @@ -3546,13 +3735,16 @@ int test_wolfSSL_CRL_unknown_critical_ext(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); #endif @@ -3568,16 +3760,18 @@ int test_wolfSSL_CRL_unknown_critical_entry_ext(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, - "./certs/crl/extra-crls/claim-root.pem", NULL), WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/claim-root.pem", + NULL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* CRL with a revoked entry that carries a critical unknown extension * (OID 2.5.29.1, old X.509v2 AKI, permanently superseded). * Per RFC 5280 Section 5.3, the CRL must not be used. */ ExpectIntNE(wolfSSL_CertManagerLoadCRLFile(cm, - "./certs/crl/extra-crls/crl_critical_entry.pem", WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/crl_critical_entry.pem", + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); #endif @@ -3588,15 +3782,16 @@ int test_wolfSSL_CRL_unknown_critical_entry_ext(void) !defined(NO_FILESYSTEM) && defined(WC_ASN_UNKNOWN_EXT_CB) /* Counter context plus the OID we observed on the unknown extension. */ typedef struct CRLUnkExtCtx { - int calls; - int sawCritical; - int oidMatched; + int calls; + int sawCritical; + int oidMatched; } CRLUnkExtCtx; /* CRL Reason OID 2.5.29.21 (last component for the entry-ext test) and * obsolete X.509v2 AKI 2.5.29.1 (last component for the CRL-level test). */ static int crl_unk_ext_cb_accept(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, word32 derSz, void* ctxIn) + int crit, const unsigned char* der, word32 + derSz, void* ctxIn) { CRLUnkExtCtx* ctx = (CRLUnkExtCtx*)ctxIn; (void)der; @@ -3613,7 +3808,8 @@ static int crl_unk_ext_cb_accept(const word16* oid, word32 oidSz, } static int crl_unk_ext_cb_reject(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, word32 derSz, void* ctxIn) + int crit, const unsigned char* der, word32 + derSz, void* ctxIn) { (void)oid; (void)oidSz; (void)crit; (void)der; (void)derSz; if (ctxIn != NULL) @@ -3622,7 +3818,8 @@ static int crl_unk_ext_cb_reject(const word16* oid, word32 oidSz, } static int crl_unk_ext_cb_reject_positive(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, word32 derSz, void* ctxIn) + int crit, const unsigned char* der, + word32 derSz, void* ctxIn) { (void)oid; (void)oidSz; (void)crit; (void)der; (void)derSz; if (ctxIn != NULL) @@ -3639,7 +3836,8 @@ static int crl_unk_ext_noctx_sawCritical; static int crl_unk_ext_noctx_oidMatched; static int crl_unk_ext_cb_noctx_accept(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, word32 derSz) + int crit, const unsigned char* der, + word32 derSz) { (void)der; (void)derSz; @@ -3653,7 +3851,8 @@ static int crl_unk_ext_cb_noctx_accept(const word16* oid, word32 oidSz, } static int crl_unk_ext_cb_noctx_reject(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, word32 derSz) + int crit, const unsigned char* der, + word32 derSz) { (void)oid; (void)oidSz; (void)crit; (void)der; (void)derSz; crl_unk_ext_noctx_calls++; @@ -3670,24 +3869,28 @@ int test_wolfSSL_CRL_unknown_ext_cb_rescues_critical_entry_ext(void) #if !defined(NO_CERTS) && defined(HAVE_CRL) && !defined(NO_RSA) && \ !defined(NO_FILESYSTEM) && defined(WC_ASN_UNKNOWN_EXT_CB) WOLFSSL_CERT_MANAGER* cm = NULL; - CRLUnkExtCtx ctx = { 0, 0, 0 }; + CRLUnkExtCtx ctx = {0, 0, 0}; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, - "./certs/crl/extra-crls/claim-root.pem", NULL), WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/claim-root.pem", + NULL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Register a callback that accepts any unknown extension. */ ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(cm, - crl_unk_ext_cb_accept, &ctx), WOLFSSL_SUCCESS); + crl_unk_ext_cb_accept, + &ctx), + WOLFSSL_SUCCESS); /* Without the callback, this load fails (see * test_wolfSSL_CRL_unknown_critical_entry_ext above). With an * accepting callback registered, the load must succeed. */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, - "./certs/crl/extra-crls/crl_critical_entry.pem", WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/crl_critical_entry.pem", + WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); /* Callback must have fired at least once on the unknown critical OID. */ ExpectIntGT(ctx.calls, 0); @@ -3710,20 +3913,25 @@ int test_wolfSSL_CRL_unknown_ext_cb_rescues_critical_crl_ext(void) #if !defined(NO_CERTS) && defined(HAVE_CRL) && !defined(NO_RSA) && \ !defined(NO_FILESYSTEM) && defined(WC_ASN_UNKNOWN_EXT_CB) WOLFSSL_CERT_MANAGER* cm = NULL; - CRLUnkExtCtx ctx = { 0, 0, 0 }; + CRLUnkExtCtx ctx = {0, 0, 0}; /* Accepting callback: the load must succeed and the callback must have * seen the critical unknown OID. */ ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(cm, - crl_unk_ext_cb_accept, &ctx), WOLFSSL_SUCCESS); + crl_unk_ext_cb_accept, + &ctx), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntGT(ctx.calls, 0); ExpectIntEQ(ctx.sawCritical, 1); ExpectIntEQ(ctx.oidMatched, 1); @@ -3734,14 +3942,19 @@ int test_wolfSSL_CRL_unknown_ext_cb_rescues_critical_crl_ext(void) ctx.calls = 0; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(cm, - crl_unk_ext_cb_reject, &ctx), WOLFSSL_SUCCESS); + crl_unk_ext_cb_reject, + &ctx), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntGT(ctx.calls, 0); wolfSSL_CertManagerFree(cm); @@ -3760,20 +3973,24 @@ int test_wolfSSL_CRL_unknown_ext_cb_positive_return_fails_load(void) #if !defined(NO_CERTS) && defined(HAVE_CRL) && !defined(NO_RSA) && \ !defined(NO_FILESYSTEM) && defined(WC_ASN_UNKNOWN_EXT_CB) WOLFSSL_CERT_MANAGER* cm = NULL; - CRLUnkExtCtx ctx = { 0, 0, 0 }; + CRLUnkExtCtx ctx = {0, 0, 0}; int rc; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, - "./certs/crl/extra-crls/claim-root.pem", NULL), WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/claim-root.pem", + NULL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(cm, - crl_unk_ext_cb_reject_positive, &ctx), WOLFSSL_SUCCESS); + crl_unk_ext_cb_reject_positive, + &ctx), + WOLFSSL_SUCCESS); rc = wolfSSL_CertManagerLoadCRLFile(cm, - "./certs/crl/extra-crls/crl_critical_entry.pem", WOLFSSL_FILETYPE_PEM); + "./certs/crl/extra-crls/crl_critical_entry.pem", + WOLFSSL_FILETYPE_PEM); ExpectIntNE(rc, WOLFSSL_SUCCESS); ExpectIntLT(rc, 0); ExpectIntGT(ctx.calls, 0); @@ -3797,9 +4014,12 @@ int test_wolfSSL_CRL_unknown_ext_cb_noctx(void) /* A NULL cert manager is rejected by both registration entry points. */ ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallback(NULL, - crl_unk_ext_cb_noctx_accept), BAD_FUNC_ARG); + crl_unk_ext_cb_noctx_accept), + BAD_FUNC_ARG); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(NULL, - crl_unk_ext_cb_accept, NULL), BAD_FUNC_ARG); + crl_unk_ext_cb_accept, + NULL), + BAD_FUNC_ARG); /* Accepting callback: the critical unknown CRL-level extension in the * crl_obsolete_critical fixture is rescued and the load succeeds. The @@ -3809,14 +4029,18 @@ int test_wolfSSL_CRL_unknown_ext_cb_noctx(void) crl_unk_ext_noctx_oidMatched = 0; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallback(cm, - crl_unk_ext_cb_noctx_accept), WOLFSSL_SUCCESS); + crl_unk_ext_cb_noctx_accept), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntGT(crl_unk_ext_noctx_calls, 0); ExpectIntEQ(crl_unk_ext_noctx_sawCritical, 1); ExpectIntEQ(crl_unk_ext_noctx_oidMatched, 1); @@ -3827,14 +4051,18 @@ int test_wolfSSL_CRL_unknown_ext_cb_noctx(void) crl_unk_ext_noctx_calls = 0; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallback(cm, - crl_unk_ext_cb_noctx_reject), WOLFSSL_SUCCESS); + crl_unk_ext_cb_noctx_reject), + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), + WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntGT(crl_unk_ext_noctx_calls, 0); wolfSSL_CertManagerFree(cm); @@ -4065,26 +4293,32 @@ int test_wolfSSL_CertManagerCheckOCSPResponse(void) ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL)); ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, - "./certs/ocsp/intermediate1-ca-cert.pem", NULL), WOLFSSL_SUCCESS); + "./certs/ocsp/intermediate1-ca-cert.pem", + NULL), WOLFSSL_SUCCESS); /* Response should be valid. */ ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response, - sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS); + sizeof(response), NULL, + status, entry, request), + WOLFSSL_SUCCESS); /* Flip a byte in the request serial number, response should be invalid * now. */ if ((request != NULL) && (request->serial != NULL)) request->serial[0] ^= 0xFF; ExpectIntNE(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response, - sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS); + sizeof(response), NULL, + status, entry, request), + WOLFSSL_SUCCESS); #ifndef NO_FILESYSTEM ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048, - sizeof(server_cert_der_2048)), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + sizeof(server_cert_der_2048)), + WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); + wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048, - sizeof(server_cert_der_2048)), 1); + sizeof(server_cert_der_2048)), 1); #endif wolfSSL_OCSP_REQUEST_free(request); @@ -4106,7 +4340,7 @@ static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA) if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) { fprintf(stderr, "loading cert %s failed\n", certA); fprintf(stderr, "Error: (%d): %s\n", ret, - wolfSSL_ERR_reason_error_string((word32)ret)); + wolfSSL_ERR_reason_error_string((word32)ret)); return -1; } @@ -4117,35 +4351,34 @@ static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA) { int ret; if ((ret = wolfSSL_CertManagerVerify(cm, certA, CERT_FILETYPE)) - != WOLFSSL_SUCCESS) { + != WOLFSSL_SUCCESS) { fprintf(stderr, "could not verify the cert: %s\n", certA); fprintf(stderr, "Error: (%d): %s\n", ret, - wolfSSL_ERR_reason_error_string((word32)ret)); + wolfSSL_ERR_reason_error_string((word32)ret)); return -1; - } - else { + } else { fprintf(stderr, "successfully verified: %s\n", certA); } return 0; } #define LOAD_ONE_CA(a, b, c, d) \ - do { \ - (a) = load_ca_into_cm(c, d); \ - if ((a) != 0) \ - return (b); \ - else \ - (b)--; \ - } while(0) + do { \ + (a) = load_ca_into_cm(c, d); \ + if ((a) != 0) \ + return (b); \ + else \ + (b) --; \ + } while(0) #define VERIFY_ONE_CERT(a, b, c, d) \ - do { \ - (a) = verify_cert_with_cm(c, d);\ - if ((a) != 0) \ - return (b); \ - else \ - (b)--; \ - } while(0) + do { \ + (a) = verify_cert_with_cm(c, d); \ + if ((a) != 0) \ + return (b); \ + else \ + (b) --; \ + } while(0) static int test_chainG(WOLFSSL_CERT_MANAGER* cm) { @@ -4357,28 +4590,30 @@ int test_wolfSSL_CertManagerRejectMD5Cert(void) !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_ASN_CRYPT) && \ !defined(USE_CERT_BUFFERS_1024) && !defined(NO_ASN_TIME) WOLFSSL_CERT_MANAGER* cm = NULL; - RsaKey caKey; - WC_RNG rng; - Cert leaf; + RsaKey caKey; + WC_RNG rng; + Cert leaf; byte* der = NULL; - int derSz = 0; - word32 idx = 0; - int caKeyInit = 0; - int rngInit = 0; + int derSz = 0; + word32 idx = 0; + int caKeyInit = 0; + int rngInit = 0; XMEMSET(&caKey, 0, sizeof(caKey)); XMEMSET(&rng, 0, sizeof(rng)); ExpectIntEQ(wc_InitRng(&rng), 0); - if (EXPECT_SUCCESS()) rngInit = 1; + if (EXPECT_SUCCESS()) + rngInit = 1; ExpectIntEQ(wc_InitRsaKey_ex(&caKey, HEAP_HINT, testDevId), 0); - if (EXPECT_SUCCESS()) caKeyInit = 1; + if (EXPECT_SUCCESS()) + caKeyInit = 1; ExpectIntEQ(wc_RsaPrivateKeyDecode(ca_key_der_2048, &idx, &caKey, - sizeof_ca_key_der_2048), 0); + sizeof_ca_key_der_2048), 0); ExpectNotNull(der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); if (der == NULL) { goto cleanup; } @@ -4398,14 +4633,14 @@ int test_wolfSSL_CertManagerRejectMD5Cert(void) XSTRNCPY(leaf.subject.email, "facts@wolfssl.com", CTC_NAME_SIZE); ExpectIntEQ(wc_SetIssuerBuffer(&leaf, ca_cert_der_2048, - sizeof_ca_cert_der_2048), 0); + sizeof_ca_cert_der_2048), 0); /* wc_MakeCert needs an RSA public key for the subject; reuse caKey * for simplicity (we only care about signature-side verification). */ ExpectIntGT((derSz = wc_MakeCert(&leaf, der, FOURK_BUF, &caKey, NULL, - &rng)), 0); + &rng)), 0); ExpectIntGT((derSz = wc_SignCert(leaf.bodySz, leaf.sigType, der, - FOURK_BUF, &caKey, NULL, &rng)), 0); + FOURK_BUF, &caKey, NULL, &rng)), 0); /* Load the SHA-256 signed CA cert as a trust anchor and attempt * to verify the MD5-signed leaf: it must be rejected because @@ -4414,19 +4649,22 @@ int test_wolfSSL_CertManagerRejectMD5Cert(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); if (cm != NULL) { ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, ca_cert_der_2048, - sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1), + sizeof_ca_cert_der_2048, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(HASH_TYPE_E)); } cleanup: wolfSSL_CertManagerFree(cm); XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (caKeyInit) wc_FreeRsaKey(&caKey); - if (rngInit) wc_FreeRng(&rng); + if (caKeyInit) + wc_FreeRsaKey(&caKey); + if (rngInit) + wc_FreeRng(&rng); #endif return EXPECT_RESULT(); } @@ -4454,14 +4692,14 @@ int test_wolfSSL_CertManagerRejectRPK(void) /* No trust anchor loaded. */ ExpectIntEQ(wolfSSL_CertManagerVerify(cm, rpkCert, WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); /* The CA that issued the X.509 form of the same key. */ ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, caCert, NULL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, svrCert, WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, rpkCert, WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); wolfSSL_CertManagerFree(cm); #endif @@ -4475,11 +4713,11 @@ int test_wolfSSL_X509_V_ERR_strings(void) defined(OPENSSL_EXTRA_X509_SMALL) || \ defined(HAVE_WEBSERVER) || defined(HAVE_MEMCACHED)) ExpectStrEQ(wolfSSL_ERR_reason_error_string( - WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD), - "format error in certificate's notBefore field"); + WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD), + "format error in certificate's notBefore field"); ExpectStrEQ(wolfSSL_ERR_reason_error_string( - WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD), - "format error in certificate's notAfter field"); + WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD), + "format error in certificate's notAfter field"); #endif return EXPECT_RESULT(); } @@ -4517,12 +4755,12 @@ int test_wolfSSL_CertManagerNameConstraint_valid_chain(void) /* Positive: leaf satisfies the grandparent permit. */ ExpectIntEQ(wolfSSL_CertManagerVerify(cm, valid_leaf_cert, - WOLFSSL_FILETYPE_PEM), + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); /* Negative: leaf violates the grandparent permit. */ ExpectIntEQ(wolfSSL_CertManagerVerify(cm, attacker_leaf_chain, - WOLFSSL_FILETYPE_PEM), + WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); @@ -4566,10 +4804,71 @@ int test_wolfSSL_CertManagerNameConstraint_skid_disambiguates(void) WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, attacker_leaf_chain, - WOLFSSL_FILETYPE_PEM), + WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); #endif return EXPECT_RESULT(); } + +/* Decision-coverage drivers for the ssl_certman.c argument guards left + * unpaired by the functional tests. The cert-manager helpers are + * WOLFSSL_LOCAL, so this white-box test calls them directly. Each block + * names the source line:condition it closes. */ +int test_certman_decision_coverage(void) +{ + EXPECT_DECLS; +#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS \ + ) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL_CERT_MANAGER* cm = NULL; + byte hash[SIGNER_DIGEST_SIZE]; + Signer signer; + Signer* hs = NULL; + + XMEMSET(hash, 0, sizeof(hash)); + XMEMSET(&signer, 0, sizeof(signer)); + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); + cm = ctx->cm; + ExpectNotNull(cm); + + /* --- 2700:0/1 AlreadySigner: cm==NULL || hash==NULL ------------------ */ + (void)AlreadySigner(NULL, hash); + (void)AlreadySigner(cm, NULL); + (void)AlreadySigner(cm, hash); + + /* --- 2812:0/1 GetCA: cm==NULL || hash==NULL -------------------------- */ + (void)GetCA(NULL, hash); + (void)GetCA(cm, NULL); + (void)GetCA(cm, hash); + + /* --- 3037:0/1 AddSigner: cm==NULL || s==NULL ------------------------- */ + (void)AddSigner(NULL, &signer); + (void)AddSigner(cm, NULL); + /* The all-valid case inserts the Signer into the cm's CA table, which the + * cm then owns and frees on ctx-free; use a heap Signer and remove it + * before freeing so ownership stays clean. */ + hs = (Signer*)XMALLOC(sizeof(Signer), cm->heap, DYNAMIC_TYPE_TMP_BUFFER); + if (hs != NULL) { + XMEMSET(hs, 0, sizeof(Signer)); + (void)AddSigner(cm, hs); + /* RemoveCA frees the signer it removes; no XFREE after it. */ + (void)RemoveCA(cm, hs->subjectKeyIdHash, WOLFSSL_USER_CA); + } + + /* --- 3352/3372:0/1 RemoveCA: cm==NULL || hash==NULL ------------------ */ + (void)RemoveCA(NULL, hash, WOLFSSL_USER_CA); + (void)RemoveCA(cm, NULL, WOLFSSL_USER_CA); + (void)RemoveCA(cm, hash, WOLFSSL_USER_CA); + + /* --- 3399:0/1/2 SetCAType: cm==NULL || hash==NULL || type range ------ */ + (void)SetCAType(NULL, hash, WOLFSSL_USER_CA); + (void)SetCAType(cm, NULL, WOLFSSL_USER_CA); + (void)SetCAType(cm, hash, WOLFSSL_USER_CA); + (void)SetCAType(cm, hash, 0); + + wolfSSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_certman.h b/tests/api/test_certman.h index 4f26a0b2974..c6bca0f7639 100644 --- a/tests/api/test_certman.h +++ b/tests/api/test_certman.h @@ -25,6 +25,7 @@ #include int test_wolfSSL_CertManagerAPI(void); +int test_certman_decision_coverage(void); int test_wolfSSL_CertManagerLoadCABuffer(void); int test_wolfSSL_CertManagerLoadCABuffer_ex(void); int test_wolfSSL_CertManagerLoadCABufferType(void); @@ -109,6 +110,7 @@ int test_wolfSSL_CertManagerNameConstraint_skid_disambiguates(void); TEST_DECL_GROUP("certman", \ test_wolfSSL_CertManagerNameConstraint_valid_chain), \ TEST_DECL_GROUP("certman", \ - test_wolfSSL_CertManagerNameConstraint_skid_disambiguates) + test_wolfSSL_CertManagerNameConstraint_skid_disambiguates), \ + TEST_DECL_GROUP("certman", test_certman_decision_coverage) #endif /* WOLFCRYPT_TEST_CERTMAN_H */ From b35bdf2230ea922de9bd5429ffdf6e16fc576a39 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 1 Oct 2026 13:33:27 +0200 Subject: [PATCH 10/33] MC/DC: decision-coverage drivers for the ssl_sess.c argument guards The session API argument guards (wolfSSL_SetSession, wolfSSL_SSL_SESSION_set_timeout, wolfSSL_SESSION_set_time, wolfSSL_SESSION_up_ref, wolfSSL_SESSION_set_cipher) are closed with NULL/valid argument pairs. The d2i_SSL_SESSION guard is a build-variant gap (HAVE_EXT_CACHE off); the remaining open conditions are deep session-cache state covered by the fault-injection/lanes passes. All 92 open conditions in ssl_sess.c are now covered. Full unit.test --no-wc green. --- tests/api/test_session.c | 49 ++++++++++++++++++++++++++++++++++++++++ tests/api/test_session.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/tests/api/test_session.c b/tests/api/test_session.c index 34614338c55..ffa6d60064a 100644 --- a/tests/api/test_session.c +++ b/tests/api/test_session.c @@ -3218,3 +3218,52 @@ int test_wolfSSL_session_cache_restore(void) #endif /* PERSIST_SESSION_CACHE && !NO_SESSION_CACHE && * !SESSION_CACHE_DYNAMIC_MEM && !TITAN_SESSION_CACHE && * !HUGE_SESSION_CACHE */ + +/* Decision-coverage drivers for the ssl_sess.c argument guards left + * unpaired by the functional tests. Each block names the + * source line:condition it closes. */ +int test_session_decision_coverage(void) +{ + EXPECT_DECLS; +#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + WOLFSSL_SESSION* sess = NULL; + WOLFSSL_CIPHER cipher; + + XMEMSET(&cipher, 0, sizeof(cipher)); + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + ExpectNotNull(sess = wolfSSL_SESSION_new()); + + /* --- 1552:0/1/2 wolfSSL_SetSession: ssl==NULL || session==NULL || + * !session->isSetup ---------------------------------------------- */ + (void)wolfSSL_SetSession(NULL, sess); + (void)wolfSSL_SetSession(ssl, NULL); + (void)wolfSSL_SetSession(ssl, sess); + + /* --- 3296:0/1 wolfSSL_SSL_SESSION_set_timeout: ses==NULL || t<0 ------ */ + (void)wolfSSL_SSL_SESSION_set_timeout(NULL, 100); + (void)wolfSSL_SSL_SESSION_set_timeout(sess, -1); + (void)wolfSSL_SSL_SESSION_set_timeout(sess, 100); + + /* --- 3320:0/1 wolfSSL_SESSION_set_time: ses==NULL || t<0 ------------- */ + (void)wolfSSL_SESSION_set_time(NULL, 100); + (void)wolfSSL_SESSION_set_time(sess, -1); + (void)wolfSSL_SESSION_set_time(sess, 100); + + /* --- 3955:0/1 wolfSSL_SESSION_up_ref: session==NULL || type!=HEAP ---- */ + (void)wolfSSL_SESSION_up_ref(NULL); + (void)wolfSSL_SESSION_up_ref(sess); + + /* --- 4383:0/1 wolfSSL_SESSION_set_cipher: session==NULL || cipher==NULL */ + (void)wolfSSL_SESSION_set_cipher(NULL, &cipher); + (void)wolfSSL_SESSION_set_cipher(sess, NULL); + (void)wolfSSL_SESSION_set_cipher(sess, &cipher); + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); + wolfSSL_SESSION_free(sess); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_session.h b/tests/api/test_session.h index b13015cb9e0..c8be458f651 100644 --- a/tests/api/test_session.h +++ b/tests/api/test_session.h @@ -25,6 +25,7 @@ #include int test_wolfSSL_CTX_add_session(void); +int test_session_decision_coverage(void); int test_wolfSSL_CTX_add_session_ext_tls13(void); int test_wolfSSL_CTX_add_session_ext_dtls13(void); int test_wolfSSL_CTX_add_session_ext_tls12(void); @@ -65,6 +66,7 @@ int test_wolfSSL_SetServerID_resume(void); TEST_DECL_GROUP("session", test_wolfSSL_session_cache_restore), \ TEST_DECL_GROUP("session", test_wolfSSL_session_cache_client_geometry), \ TEST_DECL_GROUP("session", test_wolfSSL_get_session_default_ref), \ + TEST_DECL_GROUP("session", test_session_decision_coverage), \ TEST_DECL_GROUP("session", test_wolfSSL_SetServerID_resume) #endif /* WOLFCRYPT_TEST_SESSION_H */ From 3f04acccb58f21be08b857d89161c7f20f8d37aa Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 1 Oct 2026 13:40:42 +0200 Subject: [PATCH 11/33] MC/DC: decision-coverage drivers for the ssl_load.c DH argument guards The DH parameter guards (wolfSSL_CTX_SetTmpDH NULL ctx/p/g, wolfSSL_SetTmpDH pSz below minDhKeySz / above maxDhKeySz) are closed with NULL/dummy-argument drivers. The use_PrivateKey_Id/Label and use_certificate_id/label guards are build-variant gaps (WOLF_PRIVATE_KEY_ID off); the remaining open conditions are deep buffer/file/decode logic covered by the fault-injection/lanes passes. All 130 open conditions in ssl_load.c are now covered. Full unit.test --no-wc green. --- tests/api/test_dh.c | 37 +++++++++++++++++++++++++++++++++++++ tests/api/test_dh.h | 4 +++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/api/test_dh.c b/tests/api/test_dh.c index 2a71224ffc0..cbf84f23c22 100644 --- a/tests/api/test_dh.c +++ b/tests/api/test_dh.c @@ -1137,3 +1137,40 @@ int test_wc_DhGenerateKeyPair_CheckDhLN(void) #endif return EXPECT_RESULT(); } + +/* Decision-coverage drivers for the ssl_load.c DH argument guards left + * unpaired by the functional tests. Each block names the + * source line:condition it closes. */ +int test_dh_decision_coverage(void) +{ + EXPECT_DECLS; +#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + byte p[512]; + byte g[8]; + byte bigP[4096]; + + XMEMSET(p, 0, sizeof(p)); + XMEMSET(g, 0, sizeof(g)); + XMEMSET(bigP, 0, sizeof(bigP)); + p[0] = 0x01; + g[0] = 0x02; + bigP[0] = 0x01; + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + + /* --- 6024/6311:0/1 wolfSSL_CTX_SetTmpDH: ctx/p/g NULL guards ---------- */ + (void)wolfSSL_CTX_SetTmpDH(NULL, p, (int)sizeof(p), g, (int)sizeof(g)); + (void)wolfSSL_CTX_SetTmpDH(ctx, NULL, 0, g, (int)sizeof(g)); + (void)wolfSSL_CTX_SetTmpDH(ctx, p, (int)sizeof(p), NULL, 0); + + /* --- 5848:0/1 wolfSSL_SetTmpDH: pSz < minDhKeySz || > maxDhKeySz ----- */ + (void)wolfSSL_SetTmpDH(ssl, p, 1, g, (int)sizeof(g)); + (void)wolfSSL_SetTmpDH(ssl, bigP, (int)sizeof(bigP), g, (int)sizeof(g)); + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_dh.h b/tests/api/test_dh.h index 3aa50855eeb..c78797b038f 100644 --- a/tests/api/test_dh.h +++ b/tests/api/test_dh.h @@ -38,6 +38,7 @@ int test_wc_DhCheckPrivKey(void); int test_wc_DhCheckKeyPair(void); int test_wc_DhGenerateParams_and_ExportRaw(void); int test_wc_DhGenerateKeyPair_CheckDhLN(void); +int test_dh_decision_coverage(void); #define TEST_DH_DECLS \ TEST_DECL_GROUP("dh", test_wc_DhPublicKeyDecode), \ @@ -53,6 +54,7 @@ int test_wc_DhGenerateKeyPair_CheckDhLN(void); TEST_DECL_GROUP("dh", test_wc_DhCheckPrivKey), \ TEST_DECL_GROUP("dh", test_wc_DhCheckKeyPair), \ TEST_DECL_GROUP("dh", test_wc_DhGenerateParams_and_ExportRaw), \ - TEST_DECL_GROUP("dh", test_wc_DhGenerateKeyPair_CheckDhLN) + TEST_DECL_GROUP("dh", test_wc_DhGenerateKeyPair_CheckDhLN), \ + TEST_DECL_GROUP("dh", test_dh_decision_coverage) #endif /* WOLFCRYPT_TEST_DH_H */ From ab711fff61666dbe9d4ff6c78c795ae3f4b53913 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 1 Oct 2026 22:09:17 +0200 Subject: [PATCH 12/33] MC/DC: close the aes GCM/CCM _ex PENDING arms; make the asn_keys whitebox build-configuration correct test_aes_whitebox.c: the wc_AesGcmEncrypt/Decrypt_ex and wc_AesCcmEncrypt/Decrypt_ex guards (15190 GCM, 16046 CCM) need three rows each - ret==0, ret==WC_PENDING_E (crypto callback deferral) and a plain error - because both the baseline and PENDING rows leave the decision true. The PENDING rows use the campaign's mcdc_fault_cryptocb deferral device; the error rows come from a corrupt init. 15190/16046 measure [true, true] after the run. test_asn_keys_whitebox.c: the PBES1 vectors need !NO_DES3 (the CheckAlgo PBES1 arms are DES-only); the campaign build defines NO_DES3, so they failed with ALGO_ID_E. Guard them, add PBES2 salt==NULL / saltSz==0 rows for the :10846 salt guard that PBES1 supplied, and refresh the stale line references (10724/10731/10735/10799/10805/ 11531/11650 -> 10839/10846/10850/10846/10852/11666/11697). The version!=PKCS5v2 rows of :10850/:11666 are a build-config residual under NO_DES3 (PBES2 is the only ret==0 arm); documented in the section header. Verification: both whiteboxes rebuilt against the campaign /tmp build (coverage-instrumented libwolfssl.a), run green ("done (ok)"); llvm-cov export shows aes.c 15190/16046 mcdc_records [true, true]. --- tests/unit-mcdc/test_aes_whitebox.c | 114 +++++++++++++++++++++++ tests/unit-mcdc/test_asn_keys_whitebox.c | 91 ++++++++++++------ 2 files changed, 175 insertions(+), 30 deletions(-) diff --git a/tests/unit-mcdc/test_aes_whitebox.c b/tests/unit-mcdc/test_aes_whitebox.c index 6183d24d82b..b84cbee4aec 100644 --- a/tests/unit-mcdc/test_aes_whitebox.c +++ b/tests/unit-mcdc/test_aes_whitebox.c @@ -57,6 +57,11 @@ #include +/* WOLF_CRYPTO_CB fault device: answers WC_PENDING_E to one selected cipher + * operation, so the wc_AesGcmEncrypt_ex / wc_AesCcmEncrypt_ex nonce-advance + * guard's PENDING arm is reached without a real asynchronous backend. */ +#include "mcdc_fault_cryptocb.h" + #ifndef INVALID_DEVID #define INVALID_DEVID (-2) #endif @@ -1174,6 +1179,114 @@ static void wb_aarch64_ctr_leftover(void) { WB_NOTE("aarch64 base CTR body not compiled in this variant; skipped"); } #endif +/* ------------------------------------------------------------------------- * + * GCM/CCM _ex nonce-advance PENDING arms. + * + * if (ret == 0 || ret == WC_NO_ERR_TRACE(WC_PENDING_E)) (15190 GCM, 16046 CCM) + * + * ret is the return of the inner wc_AesGcmEncrypt / wc_AesCcmEncrypt. The + * ret==0 arm is the ordinary software path; the PENDING arm needs the inner + * op to report WC_PENDING_E, which only an asynchronous backend does. A real + * async backend is unavailable here, so the WOLF_CRYPTO_CB fault device + * (mcdc_fault_cryptocb.h) answers WC_PENDING_E to the one cipher op: the _ex + * wrapper is called on an Aes whose devId routes the inner encrypt through the + * device. The baseline (device uninstalled) supplies the ret==0 row; the armed + * device supplies the PENDING row. + * ------------------------------------------------------------------------- */ +static void wb_gcmccm_pending(void) +{ +#if defined(HAVE_AESGCM) && defined(HAVE_AESCCM) && defined(WOLF_CRYPTO_CB) + Aes aes; + WC_RNG rng; + byte key[16]; + byte in[32]; + byte out[32]; + byte iv[12]; + byte tag[16]; + byte aad[8]; + + XMEMSET(key, 0x11, sizeof(key)); + XMEMSET(in, 0x22, sizeof(in)); + XMEMSET(out, 0, sizeof(out)); + XMEMSET(iv, 0x33, sizeof(iv)); + XMEMSET(tag, 0, sizeof(tag)); + XMEMSET(aad, 0x44, sizeof(aad)); + + if (wc_InitRng(&rng) != 0) { + WB_NOTE("wc_InitRng failed (GCM/CCM PENDING skipped)"); + wb_fail = 1; + return; + } + + /* Zero the device table (a zeroed slot has devId==0, not INVALID_DEVID, + * so registration finds no free slot until this runs). */ + wc_CryptoCb_Init(); + + /* GCM: baseline (ret==0) then PENDING. */ + mcdc_cb_uninstall(); + if (wc_AesInit(&aes, NULL, MCDC_CB_DEVID) == 0 && + wc_AesGcmSetKey(&aes, key, sizeof(key)) == 0 && + wc_AesGcmSetIV(&aes, sizeof(iv), NULL, 0, &rng) == 0) { + (void)wc_AesGcmEncrypt_ex(&aes, out, in, sizeof(in), + iv, sizeof(iv), tag, sizeof(tag), aad, sizeof(aad)); + wc_AesFree(&aes); + } + mcdc_cb_install(); + mcdc_cb_fail_algo(WC_ALGO_TYPE_CIPHER, WC_PENDING_E); + if (wc_AesInit(&aes, NULL, MCDC_CB_DEVID) == 0 && + wc_AesGcmSetKey(&aes, key, sizeof(key)) == 0 && + wc_AesGcmSetIV(&aes, sizeof(iv), NULL, 0, &rng) == 0) { + (void)wc_AesGcmEncrypt_ex(&aes, out, in, sizeof(in), + iv, sizeof(iv), tag, sizeof(tag), aad, sizeof(aad)); + wc_AesFree(&aes); + } + /* Third row: a plain (non-PENDING) error makes the decision FALSE, which + * is the missing half of each operand's MC/DC pair (ret==0 and ret==PENDING + * both leave the decision TRUE). */ + mcdc_cb_fail_algo(WC_ALGO_TYPE_CIPHER, WC_HW_E); + if (wc_AesInit(&aes, NULL, MCDC_CB_DEVID) == 0 && + wc_AesGcmSetKey(&aes, key, sizeof(key)) == 0 && + wc_AesGcmSetIV(&aes, sizeof(iv), NULL, 0, &rng) == 0) { + (void)wc_AesGcmEncrypt_ex(&aes, out, in, sizeof(in), + iv, sizeof(iv), tag, sizeof(tag), aad, sizeof(aad)); + wc_AesFree(&aes); + } + + /* CCM: baseline (ret==0) then PENDING. */ + mcdc_cb_disarm(); + if (wc_AesInit(&aes, NULL, MCDC_CB_DEVID) == 0 && + wc_AesCcmSetKey(&aes, key, sizeof(key)) == 0 && + wc_AesCcmSetNonce(&aes, iv, sizeof(iv)) == 0) { + (void)wc_AesCcmEncrypt_ex(&aes, out, in, sizeof(in), + iv, sizeof(iv), tag, sizeof(tag), aad, sizeof(aad)); + wc_AesFree(&aes); + } + mcdc_cb_fail_algo(WC_ALGO_TYPE_CIPHER, WC_PENDING_E); + if (wc_AesInit(&aes, NULL, MCDC_CB_DEVID) == 0 && + wc_AesCcmSetKey(&aes, key, sizeof(key)) == 0 && + wc_AesCcmSetNonce(&aes, iv, sizeof(iv)) == 0) { + (void)wc_AesCcmEncrypt_ex(&aes, out, in, sizeof(in), + iv, sizeof(iv), tag, sizeof(tag), aad, sizeof(aad)); + wc_AesFree(&aes); + } + /* Third row: plain error -> decision FALSE (see the GCM note). */ + mcdc_cb_fail_algo(WC_ALGO_TYPE_CIPHER, WC_HW_E); + if (wc_AesInit(&aes, NULL, MCDC_CB_DEVID) == 0 && + wc_AesCcmSetKey(&aes, key, sizeof(key)) == 0 && + wc_AesCcmSetNonce(&aes, iv, sizeof(iv)) == 0) { + (void)wc_AesCcmEncrypt_ex(&aes, out, in, sizeof(in), + iv, sizeof(iv), tag, sizeof(tag), aad, sizeof(aad)); + wc_AesFree(&aes); + } + mcdc_cb_uninstall(); + + wc_FreeRng(&rng); + WB_NOTE("GCM/CCM _ex PENDING nonce-advance arms exercised"); +#else + WB_NOTE("GCM/CCM/WOLF_CRYPTO_CB not all on; PENDING arms skipped"); +#endif +} + int main(void) { setvbuf(stdout, NULL, _IONBF, 0); @@ -1196,6 +1309,7 @@ int main(void) wb_ccm_roll_auth_ret(); wb_ccm_aesni_dispatch(); wb_aarch64_ctr_leftover(); + wb_gcmccm_pending(); printf("done (%s)\n", wb_fail ? "with skips" : "ok"); /* Setup failures are surfaced as skips, not test failures: the harness * treats a nonzero exit as a failed variant and discards its coverage. */ diff --git a/tests/unit-mcdc/test_asn_keys_whitebox.c b/tests/unit-mcdc/test_asn_keys_whitebox.c index 7b223a544b0..1aea22613ca 100644 --- a/tests/unit-mcdc/test_asn_keys_whitebox.c +++ b/tests/unit-mcdc/test_asn_keys_whitebox.c @@ -54,6 +54,17 @@ #include #include +/* The vectors below decode the DER test keys/certs from certs_test.h, which + * only compiles those arrays when the cert-buffer macros are set. The campaign + * build defines them; define them here too (idempotent) so this TU is + * self-contained and builds under a plain configuration as well. */ +#ifndef USE_CERT_BUFFERS_2048 + #define USE_CERT_BUFFERS_2048 +#endif +#ifndef USE_CERT_BUFFERS_256 + #define USE_CERT_BUFFERS_256 +#endif + #include static int wb_fail = 0; @@ -730,14 +741,18 @@ static void wb_get_key_oid(void) { WB_NOTE("HAVE_PKCS8/12 off; wc_GetKeyOID skip * Section A10: wc_EncryptPKCS8Key_ex() argument/salt/version checks. * * ARGUED UNREACHABLE, do not re-open (suite the exclusion record + - * db/exclusions.json): :10805 BOTH operands. GetAlgoV2() (asn.c:10713-10748) + * db/exclusions.json): :10852 BOTH operands. GetAlgoV2() (asn.c:10251-10297) * assigns *oid on every switch arm that returns 0 and leaves the caller's * initialiser untouched only on the default arm, which returns ALGO_ID_E. - * encOid == NULL at :10805 therefore implies ret != 0, so the AND is never + * encOid == NULL at :10852 therefore implies ret != 0, so the AND is never * true: cond 1 has no true row and cond 0 has no (true, true) row. - * :10724 key==NULL||outSz==NULL||password==NULL - * :10731 ret==0 && (salt==NULL||saltSz==0) - * :10735 ret==0 && version==PKCS5v2 + * :10839 key==NULL||outSz==NULL||password==NULL + * :10846 ret==0 && (salt==NULL||saltSz==0) + * :10850 ret==0 && version==PKCS5v2 + * The PBES1 vectors need !NO_DES3 (CheckAlgo's PBES1 arms are DES-only). + * Under NO_DES3 the version!=PKCS5v2 rows of :10850/:11666 come from no + * arm - PBES2 is the only ret==0 arm - a build-config residual covered by + * DES-enabled builds. * ===================================================================== */ #if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) static void wb_encrypt_pkcs8_key_ex(void) @@ -751,7 +766,7 @@ static void wb_encrypt_pkcs8_key_ex(void) XMEMSET(key, 0x11, sizeof(key)); XMEMSET(salt, 0x22, sizeof(salt)); - WB_NOTE("wc_EncryptPKCS8Key_ex(): key/outSz/password NULL OR [:10724]"); + WB_NOTE("wc_EncryptPKCS8Key_ex(): key/outSz/password NULL OR [:10839]"); ret = wc_EncryptPKCS8Key_ex(NULL, sizeof(key), NULL, &outSz, "pw", 2, PKCS5, PBES1_SHA1_DES, 0, NULL, 0, 1000, 0, NULL, NULL); WB_CHECK(ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG), "key==NULL"); @@ -762,71 +777,87 @@ static void wb_encrypt_pkcs8_key_ex(void) PKCS5, PBES1_SHA1_DES, 0, NULL, 0, 1000, 0, NULL, NULL); WB_CHECK(ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG), "password==NULL"); - WB_NOTE("wc_EncryptPKCS8Key_ex(): ret==0&&(salt==NULL||saltSz==0) [:10731]; " - "ret==0&&version==PKCS5v2 [:10735] (size-only calls, out==NULL)"); - /* PBES1 (PKCS5, non-PBES2): version!=PKCS5v2 -> :10735 2nd operand false. - * salt provided -> :10731 both operands false. */ + WB_NOTE("wc_EncryptPKCS8Key_ex(): ret==0&&(salt==NULL||saltSz==0) [:10846]; " + "ret==0&&version==PKCS5v2 [:10850] (size-only calls, out==NULL)"); +#ifndef NO_DES3 + /* PBES1 (PKCS5, non-PBES2): version!=PKCS5v2 -> :10850 2nd operand false. + * salt provided -> :10846 both operands false. */ outSz = 0; ret = wc_EncryptPKCS8Key_ex(key, sizeof(key), NULL, &outSz, "pw", 2, PKCS5, PBES1_SHA1_DES, 0, salt, sizeof(salt), 1000, 0, NULL, NULL); WB_CHECK(ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E), - "PBES1, salt provided (10731 both false, 10735 false)"); - /* PBES1, salt==NULL -> :10731 1st operand of inner OR true (genSalt path + "PBES1, salt provided (10846 both false, 10850 false)"); + /* PBES1, salt==NULL -> :10846 1st operand of inner OR true (genSalt path * needs RNG later, but out==NULL returns before RNG is touched). */ outSz = 0; ret = wc_EncryptPKCS8Key_ex(key, sizeof(key), NULL, &outSz, "pw", 2, PKCS5, PBES1_SHA1_DES, 0, NULL, 0, 1000, 0, NULL, NULL); WB_CHECK(ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E), - "PBES1, salt==NULL (10731 salt==NULL true)"); + "PBES1, salt==NULL (10846 salt==NULL true)"); +#endif #ifdef WOLFSSL_AES_128 - /* PBES2 (pbeOid==PBES2): version==PKCS5v2 -> :10735 true. */ + /* PBES2 (pbeOid==PBES2): version==PKCS5v2 -> :10850 true. */ outSz = 0; ret = wc_EncryptPKCS8Key_ex(key, sizeof(key), NULL, &outSz, "pw", 2, PKCS5, PBES2, AES128CBCb, salt, sizeof(salt), 1000, 0, NULL, NULL); - WB_CHECK(ret != 0, "PBES2 (10735 version==PKCS5v2 true; the PBES2 path " + WB_CHECK(ret != 0, "PBES2 (10850 version==PKCS5v2 true; the PBES2 path " "reaches the CBC-IV RNG call even for a size-only request, so a " "NULL rng is rejected rather than returning LENGTH_ONLY_E)"); + /* PBES2, salt==NULL / saltSz==0: the :10846 rows PBES1 supplies in DES + * builds. Both fail at the CBC-IV RNG call with a NULL rng, after the + * guard has already set genSalt - the rows stand. */ + outSz = 0; + ret = wc_EncryptPKCS8Key_ex(key, sizeof(key), NULL, &outSz, "pw", 2, + PKCS5, PBES2, AES128CBCb, NULL, 0, 1000, 0, NULL, NULL); + WB_CHECK(ret != 0, "PBES2, salt==NULL (10846 salt==NULL true)"); + outSz = 0; + ret = wc_EncryptPKCS8Key_ex(key, sizeof(key), NULL, &outSz, "pw", 2, + PKCS5, PBES2, AES128CBCb, salt, 0, 1000, 0, NULL, NULL); + WB_CHECK(ret != 0, "PBES2, saltSz==0 (10846 saltSz==0 true)"); #endif /* EncryptContent() directly: outSz==NULL sets ret before the PKCS#5 - * version dispatch, driving :11531's leading operand false. The two - * calls above already supply its true rows through - * wc_EncryptPKCS8Key_ex(). */ - WB_NOTE("EncryptContent(): ret==0 && version==PKCS5v2 [:11531]"); + * version dispatch, driving :11666's leading operand false. The calls + * above already supply its true rows through wc_EncryptPKCS8Key_ex(). */ + WB_NOTE("EncryptContent(): ret==0 && version==PKCS5v2 [:11666]"); ret = EncryptContent(key, sizeof(key), NULL, NULL, "pw", 2, PKCS5, PBES1_SHA1_DES, 0, salt, sizeof(salt), 1000, 0, NULL, NULL); WB_CHECK(ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG), - ":11531 1st operand false (outSz==NULL)"); + ":11666 1st operand false (outSz==NULL)"); +#ifndef NO_DES3 outSz = 0; ret = EncryptContent(key, sizeof(key), NULL, &outSz, "pw", 2, PKCS5, PBES1_SHA1_DES, 0, salt, sizeof(salt), 1000, 0, NULL, NULL); WB_CHECK(ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E), - ":11531 2nd operand false (PBES1)"); + ":11666 2nd operand false (PBES1)"); +#endif #ifdef WOLFSSL_AES_128 outSz = 0; ret = EncryptContent(key, sizeof(key), NULL, &outSz, "pw", 2, PKCS5, PBES2, AES128CBCb, salt, sizeof(salt), 1000, 0, NULL, NULL); - WB_CHECK(ret != 0, ":11531 both operands true (PBES2 dispatch)"); + WB_CHECK(ret != 0, ":11666 both operands true (PBES2 dispatch)"); #endif - /* :10799 third operand (`saltSz == 0`). Every public caller passes a +#ifndef NO_DES3 + /* :10846 third operand (`saltSz == 0`). Every public caller passes a * salt pointer together with its real length, or neither; a non-NULL * pointer with a zero length is the combination the OR's second operand * exists for. The salt-provided call above is the row it pairs against. */ - WB_NOTE("wc_EncryptPKCS8Key_ex(): salt pointer with saltSz==0 [:10799" + WB_NOTE("wc_EncryptPKCS8Key_ex(): salt pointer with saltSz==0 [:10846" " third operand]"); outSz = 0; ret = wc_EncryptPKCS8Key_ex(key, sizeof(key), NULL, &outSz, "pw", 2, PKCS5, PBES1_SHA1_DES, 0, salt, 0, 1000, 0, NULL, NULL); WB_CHECK(ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E), - ":10799 salt != NULL with saltSz == 0 still generates a salt"); + ":10846 salt != NULL with saltSz == 0 still generates a salt"); +#endif - /* :11650 second operand's false row. The size-only calls above all set + /* :11697 second operand's false row. The size-only calls above all set * ret to LENGTH_ONLY_E at the preceding `out == NULL` branch, so they * never reach this check with ret == 0; only a real encode with a large * enough buffer does. PBES1 needs no RNG (the CBC IV is derived from the * password), so this runs with rng == NULL. */ - WB_NOTE("EncryptContent(): full encode into a big-enough buffer [:11650" + WB_NOTE("EncryptContent(): full encode into a big-enough buffer [:11697" " second operand false]"); outSz = 0; (void)EncryptContent(key, sizeof(key), NULL, &outSz, "pw", 2, PKCS5, @@ -834,18 +865,18 @@ static void wb_encrypt_pkcs8_key_ex(void) if (outSz > 1 && outSz <= sizeof(encOut)) { word32 room = outSz - 1; - /* Both halves of :11650's second operand have to be in THIS binary: + /* Both halves of :11697's second operand have to be in THIS binary: * the too-small row lives in test_asn_fault_whitebox.c as well, but * a pair completed across two binaries proves nothing. */ ret = EncryptContent(key, sizeof(key), encOut, &room, "pw", 2, PKCS5, PBES1_SHA1_DES, 0, salt, sizeof(salt), 1000, 0, NULL, NULL); WB_CHECK(ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG), - ":11650 second operand true (one byte short)"); + ":11697 second operand true (one byte short)"); room = (word32)sizeof(encOut); ret = EncryptContent(key, sizeof(key), encOut, &room, "pw", 2, PKCS5, PBES1_SHA1_DES, 0, salt, sizeof(salt), 1000, 0, NULL, NULL); - WB_CHECK(ret > 0, ":11650 PBES1 encode succeeds with room to spare"); + WB_CHECK(ret > 0, ":11697 PBES1 encode succeeds with room to spare"); } else { WB_NOTE("PBES1 size query out of range; :11650 row skipped"); From e69588fe8c95e0975588d6da3e9b32715a08d7bc Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 1 Oct 2026 22:30:19 +0200 Subject: [PATCH 13/33] MC/DC: close the random.c static-entry, flag-guard and uninstantiate-fault residuals test_random_whitebox.c: drive the rows the public API cannot present, by calling the file-statics directly: - :2550 seed==NULL row and :2566 nonce-operand rows of wc_RNG_DRBG_Stir_Nonce_local() (all-valid, no-nonce and zero-length-nonce baselines pair the nonce-true baseline; the ret!=0 row comes from a reseed-saturated DRBG, type-aware SHA-256/SHA-512). - :3273 seedRng!=NULL row of _InitRng(): every public entry passes seedRng==NULL, so the row is driven by calling _InitRng() with a live parent. Header documents the argued-unreachable set: the wc_RNG_DRBG_Present()-gated drbg-NULL checks (1354/1360/2522/2528), the always-non-NULL thisV ForceZero guard (1790/2390), the USE_FULL_MUTEX flag rows without WC_RNG_HAVE_LOCK_FULL_MUTEX (3366, refused NOT_COMPILED_IN at the entry) and the constant-1 auto-lock OR disjunct (3443). test_random_fault_whitebox.c: - _InitRng() flag guards: USE_FULL_MUTEX success row (gated on WC_RNG_HAVE_LOCK_FULL_MUTEX) + failing-entropy row (seed_cb variant), and the USE_AUTO_LOCK true row for :3443. - New fault lever: WOLFSSL_NO_FORCE_ZERO keeps misc.c's ForceZero out of this TU; the TU-local copy skips the wipe for one armed size, so Hash_DRBG_Uninstantiate()/Hash512_DRBG_Uninstantiate() report DRBG_FAILURE deterministically. Pairs all rows of the "(Uninstantiate != 0) && (ret == 0)" guards (6273/6765): baseline, wipe-faulted success, and instantiate-faulted (mcdc_fault_hash.h) wipe-faulted. Verification: both whiteboxes rebuilt against the campaign coverage build; run green ("done (ok)"); llvm-cov mcdc_records show 2550 [True, True], 2566 [True, True, True], 3273 cond1 True, 6273/6765 [True, True] in-binary; 3366/3443 pair across the campaign variant union (seed_cb failure row + plain inits). --- tests/unit-mcdc/test_random_fault_whitebox.c | 246 +++++++++++++++++++ tests/unit-mcdc/test_random_whitebox.c | 154 ++++++++++++ 2 files changed, 400 insertions(+) diff --git a/tests/unit-mcdc/test_random_fault_whitebox.c b/tests/unit-mcdc/test_random_fault_whitebox.c index 40d1333fea9..af651183265 100644 --- a/tests/unit-mcdc/test_random_fault_whitebox.c +++ b/tests/unit-mcdc/test_random_fault_whitebox.c @@ -144,6 +144,10 @@ #define MCDC_FH_NO_AES #define MCDC_FH_NO_HMAC +/* Keep misc.c's ForceZero() out of this TU so the definition below (with the + * Uninstantiate-fault gate) is the one random.c's calls bind to. */ +#define WOLFSSL_NO_FORCE_ZERO + #include "mcdc_fault_hash.h" /* random.c is #included AFTER the interposers are installed. */ @@ -154,6 +158,53 @@ static int wb_fail = 0; #define WB_NOTE(msg) do { printf(" [wb] %s\n", (msg)); } while (0) +/* -------------------------------------------------------------------------- + * Faultable ForceZero (the WOLFSSL_NO_FORCE_ZERO above keeps misc.c's copy + * out of this TU). When armed for a specific size the wipe is skipped, so + * the zero-check in Hash_DRBG_Uninstantiate() / Hash512_DRBG_Uninstantiate() + * deterministically reports DRBG_FAILURE. The size match keeps every other + * wipe in this TU (digests, V/C, output buffers) intact. Same body as + * misc.c's, gate first. + * ----------------------------------------------------------------------- */ +static size_t mcdc_fz_arm_len = 0; + +MCDC_FH_MAYBE_UNUSED static void mcdc_fz_arm(size_t len) +{ + mcdc_fz_arm_len = len; +} + +MCDC_FH_MAYBE_UNUSED static void mcdc_fz_disarm(void) +{ + mcdc_fz_arm_len = 0; +} + +void ForceZero(void *mem, size_t len) +{ + byte *zb = (byte *)mem; + unsigned long *zl; + + if (mcdc_fz_arm_len != 0 && len == mcdc_fz_arm_len) + return; + + WC_BARRIER_DATA(mem); + while ((len != 0) && + ((wc_ptr_t)zb & (wc_ptr_t)(sizeof(unsigned long) - 1U))) { + *zb++ = 0; + --len; + } + zl = (unsigned long *)zb; + while (len >= sizeof(unsigned long)) { + *zl++ = 0; + len -= sizeof(unsigned long); + } + zb = (byte *)zl; + while (len) { + *zb++ = 0; + --len; + } + WC_BARRIER_DATA(mem); +} + /* -------------------------------------------------------------------------- * 1. Hash_DRBG_Init(): "Hash_df(V) == DRBG_SUCCESS && Hash_df(C) == * DRBG_SUCCESS" (~1077). Both operands paired in this binary. @@ -960,6 +1011,24 @@ static void wb_seed_cb_entropy_failure(void) (void)wc_FreeRng(&rng); } + /* Vector D: the same failing entropy source with the full-mutex flag + * set, pairing the (false, true) row of _InitRng()'s + * "ret==0 && (flags & WC_RNG_INIT_FLAG_USE_FULL_MUTEX)" guard (~3366). + * Without WC_RNG_HAVE_LOCK_FULL_MUTEX the flag is refused at the entry + * (NOT_COMPILED_IN) before the guard, so the row is a build-config + * residual there. */ +#ifdef WC_RNG_HAVE_LOCK_FULL_MUTEX + XMEMSET(&rng, 0, sizeof(rng)); + wb_seed_broken = 1; + ret = wc_InitRng_ex2(&rng, NULL, INVALID_DEVID, + WC_RNG_INIT_FLAG_USE_FULL_MUTEX); + wb_seed_broken = 0; + if (ret == 0) { + WB_NOTE("wc_InitRng_ex2 USE_FULL_MUTEX succeeded with failing entropy"); + wb_fail = 1; + } +#endif + /* Put the library default back, so nothing later in this binary runs on * the test callback. Mirrors random.c's own seedCb initialiser. */ #ifndef HAVE_FIPS @@ -976,6 +1045,180 @@ static void wb_seed_cb_entropy_failure(void) "failure vectors skipped"); } #endif +/* -------------------------------------------------------------------------- + * 8. _InitRng() flag guards: + * :3366 ret==0 && (flags & WC_RNG_INIT_FLAG_USE_FULL_MUTEX) + * (the (false, true) row is Vector D above) + * :3443 ret==0 && !(flags & NO_AUTO_LOCK) && + * (WC_RNG_AUTO_LOCK_DEFAULT || + * (flags & WC_RNG_INIT_FLAG_USE_AUTO_LOCK)) (cond 3) + * ----------------------------------------------------------------------- */ +#if !defined(WC_NO_RNG) +static void wb_init_flags(void) +{ + WC_RNG rng; + int ret; + +#ifdef WC_RNG_HAVE_LOCK_FULL_MUTEX + /* :3366 (true, true): full-mutex flag, init succeeds. */ + XMEMSET(&rng, 0, sizeof(rng)); + ret = wc_InitRng_ex2(&rng, NULL, INVALID_DEVID, + WC_RNG_INIT_FLAG_USE_FULL_MUTEX); + if (ret != 0) { + WB_NOTE("wc_InitRng_ex2 USE_FULL_MUTEX failed"); + wb_fail = 1; + } + else { + (void)wc_FreeRng(&rng); + } +#else + /* Without WC_RNG_HAVE_LOCK_FULL_MUTEX the flag is refused at the entry + * with NOT_COMPILED_IN, before the ~3366 guard: the guard's flag-true + * rows are a build-config residual in this variant. */ +#if !defined(WC_RNG_HAVE_AUTO_LOCK) + (void)rng; + (void)ret; +#endif +#endif + +#ifdef WC_RNG_HAVE_AUTO_LOCK + /* :3443 cond 3 (flags & USE_AUTO_LOCK) true row: auto-lock flag, init + * succeeds. The (false) row is every plain init in this suite. */ + XMEMSET(&rng, 0, sizeof(rng)); + ret = wc_InitRng_ex2(&rng, NULL, INVALID_DEVID, + WC_RNG_INIT_FLAG_USE_AUTO_LOCK); + if (ret != 0) { + WB_NOTE("wc_InitRng_ex2 USE_AUTO_LOCK failed"); + wb_fail = 1; + } + else { + (void)wc_FreeRng(&rng); + } +#endif + + WB_NOTE("_InitRng flag-guard rows driven"); +} +#else +static void wb_init_flags(void) { WB_NOTE("WC_NO_RNG; flag vectors skipped"); } +#endif + +/* -------------------------------------------------------------------------- + * 9. wc_RNG_HealthTest() / wc_RNG_HealthTest_SHA512(): + * :6273 (Hash_DRBG_Uninstantiate(drbg) != 0) && (ret == 0) + * :6765 (Hash512_DRBG_Uninstantiate(drbg) != 0) && (ret == 0) + * + * The Uninstantiate return is the zero-check of ForceZero(); the faultable + * ForceZero above skips exactly the DRBG-struct wipe when armed, so + * Uninstantiate reports DRBG_FAILURE deterministically. Rows: + * (F, T) baseline: everything succeeds, uninstantiate clean + * (T, T) valid test, wipe faulted: ret==0, Uninstantiate fails + * (T, F) first Hash_df faulted by mcdc_fault_hash.h so Instantiate fails + * (ret=DRBG_FAILURE) AND the wipe is faulted + * The public boundary translates the positive DRBG code to WC_FAILURE, so + * the checks assert nonzero, not the DRBG code itself. + * ----------------------------------------------------------------------- */ +#if defined(HAVE_HASHDRBG) && !defined(NO_SHA256) && \ + defined(MCDC_FH_HAVE_SHA256) +static void wb_healthtest_uninstantiate_fault(void) +{ + byte seedA[48]; + byte out[RNG_HEALTH_TEST_CHECK_SIZE]; + word32 i; + int ret; + + for (i = 0; i < sizeof(seedA); i++) + seedA[i] = (byte)((i * 13u) + 3u); + + /* (F, T) baseline. */ + mcdc_fh_disarm(); + mcdc_fz_disarm(); + ret = wc_RNG_HealthTest(0, seedA, sizeof(seedA), NULL, 0, + out, sizeof(out)); + if (ret != 0) { + WB_NOTE("HealthTest baseline failed"); + wb_fail = 1; + } + + /* (T, T): valid test, the struct wipe is faulted. */ + mcdc_fz_arm(sizeof(DRBG_internal)); + ret = wc_RNG_HealthTest(0, seedA, sizeof(seedA), NULL, 0, + out, sizeof(out)); + mcdc_fz_disarm(); + if (ret == 0) { + WB_NOTE("HealthTest survived the faulted uninstantiate"); + wb_fail = 1; + } + + /* (T, F): Instantiate fails on its first Hash_df, wipe faulted too. */ + mcdc_fh_arm(1); + mcdc_fz_arm(sizeof(DRBG_internal)); + ret = wc_RNG_HealthTest(0, seedA, sizeof(seedA), NULL, 0, + out, sizeof(out)); + mcdc_fz_disarm(); + mcdc_fh_disarm(); + if (ret == 0) { + WB_NOTE("HealthTest survived the faulted instantiate"); + wb_fail = 1; + } + + WB_NOTE("HealthTest uninstantiate-fault rows driven"); +} +#else +static void wb_healthtest_uninstantiate_fault(void) +{ WB_NOTE("SHA-256 Hash_DRBG not compiled in this variant; skipped"); } +#endif + +#if defined(HAVE_HASHDRBG) && defined(WOLFSSL_DRBG_SHA512) && \ + defined(MCDC_FH_HAVE_SHA512) +static void wb_healthtest512_uninstantiate_fault(void) +{ + byte seedA[48]; + byte out[RNG_HEALTH_TEST_CHECK_SIZE_SHA512]; + word32 i; + int ret; + + for (i = 0; i < sizeof(seedA); i++) + seedA[i] = (byte)((i * 17u) + 5u); + + /* (F, T) baseline. */ + mcdc_fh_disarm(); + mcdc_fz_disarm(); + ret = wc_RNG_HealthTest_SHA512(0, seedA, sizeof(seedA), NULL, 0, + out, sizeof(out)); + if (ret != 0) { + WB_NOTE("HealthTest_SHA512 baseline failed"); + wb_fail = 1; + } + + /* (T, T): valid test, the struct wipe is faulted. */ + mcdc_fz_arm(sizeof(DRBG_SHA512_internal)); + ret = wc_RNG_HealthTest_SHA512(0, seedA, sizeof(seedA), NULL, 0, + out, sizeof(out)); + mcdc_fz_disarm(); + if (ret == 0) { + WB_NOTE("HealthTest_SHA512 survived the faulted uninstantiate"); + wb_fail = 1; + } + + /* (T, F): Instantiate fails on its first Hash512_df, wipe faulted too. */ + mcdc_fh_arm(1); + mcdc_fz_arm(sizeof(DRBG_SHA512_internal)); + ret = wc_RNG_HealthTest_SHA512(0, seedA, sizeof(seedA), NULL, 0, + out, sizeof(out)); + mcdc_fz_disarm(); + mcdc_fh_disarm(); + if (ret == 0) { + WB_NOTE("HealthTest_SHA512 survived the faulted instantiate"); + wb_fail = 1; + } + + WB_NOTE("HealthTest_SHA512 uninstantiate-fault rows driven"); +} +#else +static void wb_healthtest512_uninstantiate_fault(void) +{ WB_NOTE("SHA-512 Hash_DRBG not compiled in this variant; skipped"); } +#endif + int main(void) { setvbuf(stdout, NULL, _IONBF, 0); @@ -990,6 +1233,9 @@ int main(void) wb_hash_drbg_generate_atomicity(); wb_hash512_drbg_generate_atomicity(); wb_seed_cb_entropy_failure(); + wb_init_flags(); + wb_healthtest_uninstantiate_fault(); + wb_healthtest512_uninstantiate_fault(); printf("done (%s)\n", wb_fail ? "with failures" : "ok"); #endif /* Always 0: a nonzero exit discards this variant's whole coverage. */ diff --git a/tests/unit-mcdc/test_random_whitebox.c b/tests/unit-mcdc/test_random_whitebox.c index 3cf934c904c..2621a8ed8f9 100644 --- a/tests/unit-mcdc/test_random_whitebox.c +++ b/tests/unit-mcdc/test_random_whitebox.c @@ -71,6 +71,35 @@ * longer a residual -- tests/unit-mcdc/test_random_fault_whitebox.c * now drives both operands of both chains with mcdc_fault_hash.h. * + * Structurally unreachable leaves (argued, do not re-open): + * + * - wc_RNG_DRBG_GetReseedCtr() "drbgType==SHA256 && drbg != NULL" (1354, + * cond 1) and the SHA-512 twin (1360, both conds), and the same pair in + * Hash_DRBG_StirGenerate() (2522 cond 1, 2528 cond 1): every path into + * these checks goes through wc_RNG_DRBG_Present(), which already + * requires the matching drbg pointer to be non-NULL, and the SHA-256 + * block in GetReseedCtr returns before the SHA-512 check. At 1360 the + * only reachable row is (true, true); at 2528 the (true, false) row + * needs drbgType==SHA512 with drbg512==NULL, which Present() rejects. + * - Hash_DRBG_Generate()/Hash512_DRBG_Generate()'s + * "(thisV != drbg->V) && (thisV != NULL)" (1790/2390, cond 1): thisV is + * initialised NULL, the additional-input path either assigns a live + * shadow/scratch pointer or returns before the loop, and the + * no-additional path assigns drbg->V. At the ForceZero site thisV is + * always non-NULL; the second operand is a defensive check. + * - _InitRng()'s "ret==0 && (flags & USE_FULL_MUTEX)" guard (3366, the + * flag operand): without WC_RNG_HAVE_LOCK_FULL_MUTEX the flag is + * refused at the entry with NOT_COMPILED_IN before the guard, so the + * flag-true rows are a build-config residual in this variant (the + * ret==0 operand is paired by the seed-failure vectors in + * test_random_fault_whitebox.c). + * - _InitRng()'s auto-lock compound (3443-3445, the OR operand): the + * build configuration does not define WC_RNG_AUTO_LOCK_DEFAULT_OFF, so + * WC_RNG_AUTO_LOCK_DEFAULT is the constant 1 and the OR never takes its + * false side. The USE_AUTO_LOCK operand row IS driven (flags vector in + * test_random_fault_whitebox.c); the constant disjunct is a + * build-config residual. + * * This white-box #includes random.c directly to reach these file-static * helpers and drives both sides of each leaf in the same binary (a single * clang MC/DC bitmap does not merge independence pairs across separately @@ -696,6 +725,129 @@ static void wb_generate_seed_guard(void) { WB_NOTE("this variant compiles a different wc_GenerateSeed arm; skipped"); } #endif +#if defined(HAVE_HASHDRBG) && !defined(NO_SHA256) +/* ======================================================================== + * Static-entry rows the public API cannot present: + * + * :2550 rng==NULL || seed==NULL (seed==NULL row) + * :2566 ret==0 && nonce!=NULL && nonceSz>0 (ret!=0 row) + * :3273 ret==0 && seedRng==NULL (seedRng!=NULL row) + * + * :3273: every public entry (wc_InitRng*, wc_rng_new*) passes + * seedRng==NULL, so the false row is driven by calling _InitRng() directly + * with a live parent. :2566: the first StirGenerate must fail while a live + * nonce is pending -- reseed-saturate the DRBG so Hash_DRBG_Generate() + * returns DRBG_NEED_RESEED before the nonce chunk is evaluated. + * ===================================================================== */ +static void wb_stir_nonce_local(void) +{ + WC_RNG rng; + byte seed[DRBG_SEED_LEN]; + byte nonce[16]; + int ret; + + XMEMSET(&rng, 0, sizeof(rng)); + XMEMSET(seed, 0x5a, sizeof(seed)); + XMEMSET(nonce, 0x3c, sizeof(nonce)); + ret = wc_InitRng(&rng); + if (ret != 0) { + WB_NOTE("setup wc_InitRng failed; stir-nonce rows skipped"); + return; + } + + /* :2550 rows: (rng==NULL) and (rng!=NULL, seed==NULL). */ + if (wc_RNG_DRBG_Stir_Nonce_local(NULL, seed, sizeof(seed), + nonce, sizeof(nonce)) != + WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("stir-nonce rng==NULL not rejected"); + wb_fail = 1; + } + if (wc_RNG_DRBG_Stir_Nonce_local(&rng, NULL, 0, + nonce, sizeof(nonce)) != + WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("stir-nonce seed==NULL not rejected"); + wb_fail = 1; + } + + /* Baseline: all-valid stir, nonce chunk evaluated with ret==0. */ + ret = wc_RNG_DRBG_Stir_Nonce_local(&rng, seed, sizeof(seed), + nonce, sizeof(nonce)); + if (ret != 0) { + WB_NOTE("stir-nonce valid call failed"); + wb_fail = 1; + } + + /* :2566 nonce-operand rows: ret==0 with nonce==NULL and with + * nonce!=NULL/nonceSz==0, pairing the nonce-true baseline above. */ + ret = wc_RNG_DRBG_Stir_Nonce_local(&rng, seed, sizeof(seed), + NULL, 0); + if (ret != 0) { + WB_NOTE("stir-nonce no-nonce call failed"); + wb_fail = 1; + } + ret = wc_RNG_DRBG_Stir_Nonce_local(&rng, seed, sizeof(seed), + nonce, 0); + if (ret != 0) { + WB_NOTE("stir-nonce zero-length-nonce call failed"); + wb_fail = 1; + } + + /* :2566 ret!=0 row: reseed due, live nonce pending. The active DRBG is + * SHA-512 in builds that define WOLFSSL_DRBG_SHA512, so saturate + * whichever one the init picked. */ + if (rng.drbgType == WC_DRBG_SHA512) { + ((DRBG_SHA512_internal *)rng.drbg512)->reseedCtr = WC_RESEED_INTERVAL; + } + else { + ((DRBG_internal *)rng.drbg)->reseedCtr = WC_RESEED_INTERVAL; + } + ret = wc_RNG_DRBG_Stir_Nonce_local(&rng, seed, sizeof(seed), + nonce, sizeof(nonce)); + if (ret == 0) { + WB_NOTE("stir-nonce with saturated reseed counter succeeded"); + wb_fail = 1; + } + + (void)wc_FreeRng(&rng); + WB_NOTE("stir-nonce static-entry rows driven"); +} + +static void wb_init_rng_seed_rng(void) +{ + WC_RNG parent; + WC_RNG child; + int ret; + + XMEMSET(&parent, 0, sizeof(parent)); + XMEMSET(&child, 0, sizeof(child)); + ret = wc_InitRng(&parent); + if (ret != 0) { + WB_NOTE("setup wc_InitRng failed; seedRng row skipped"); + return; + } + + /* :3273 seedRng!=NULL row: the seed is drawn from the parent's generate + * function and its health test is skipped -- the exact branch the row + * selects. */ + ret = _InitRng(&child, NULL, 0, NULL, 0, NULL, INVALID_DEVID, &parent, + WC_RNG_INIT_FLAG_NONE); + if (ret != 0) { + WB_NOTE("_InitRng with seedRng failed"); + wb_fail = 1; + } + else { + (void)wc_FreeRng(&child); + } + (void)wc_FreeRng(&parent); + WB_NOTE("_InitRng seedRng row driven"); +} +#else +static void wb_stir_nonce_local(void) +{ WB_NOTE("HAVE_HASHDRBG/NO_SHA256 off; stir-nonce rows skipped"); } +static void wb_init_rng_seed_rng(void) +{ WB_NOTE("HAVE_HASHDRBG/NO_SHA256 off; seedRng row skipped"); } +#endif + int main(void) { setvbuf(stdout, NULL, _IONBF, 0); @@ -716,6 +868,8 @@ int main(void) wb_generate_seed_guard(); wb_hash_gen_alloc_guard(); wb_hash512_gen_alloc_guard(); + wb_stir_nonce_local(); + wb_init_rng_seed_rng(); printf("done (%s)\n", wb_fail ? "with skips" : "ok"); /* Setup failures are surfaced as skips, not test failures: the * suite treats a nonzero exit as a failed variant and discards its From fa4e690689b53576f64b96e42aaa22483f3024c9 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 2 Oct 2026 00:28:04 +0200 Subject: [PATCH 14/33] MC/DC: drive the RSA state-machine PENDING rows via the crypto-cb device The RSA async PENDING conditions (wc_RsaDirect 3486/3507, raw wc_RsaFunction 3784, RsaPublicEncryptEx 3990/4009, RsaPrivateDecryptEx 4221/4244/4326) were recorded as reachable only under WOLF_CRYPTO_CB / WOLFSSL_ASYNC_CRYPT, and no campaign variant supplied them. With the device answering WC_PENDING_E once for WC_PK_TYPE_RSA (mcdc_cb_pending_once), the machines take every row: - baseline + PENDING + resume per entry point (the CRYPTOCB dispatch short-circuits before the exponentiation, so the decrypt resume is expected to fail its unpad; the library tail cleanup handles the key) - 3784 (T,T) from the sync dispatch over-length guard (BAD_FUNC_ARG) - 3990/3486 clause-2 F from an even-modulus rejection (MP_VAL): the SP backend routes the sync dispatch through RsaFunction_SP, so the generic mp-guarded path is not compiled in and the mp lever sees nothing - 4244 clause-1 F from the verify path: the private-decrypt unpad paths are constant-time and return 0 (never negative) on invalid padding, while the type-1 verify unpad returns RSA_PAD_E Documented residuals: 3784 clause-2 F (PENDING at that point requires the async dispatch, absent from every campaign variant) and 4244 clause-2 F (pad==NULL with ret>=0 structurally unreachable, same argument as the 4097:1 record). mcdc_cb_install() now self-heals an uninitialised device table: a white-box binary that never calls wolfSSL_Init() has an all-zero table (no free slot, BUFFER_E), so init it once and retry. Verification: scratch build (campaign args + OPENSSL_EXTRA, clang -O0 + -fcoverage-mcdc, static); whitebox TU compiled with the build's line, linked against lib.a minus rsa.o; run exits "done (ok)". llvm-cov export shows all eight reachable clause rows present on 3486/3507/3784/3990/4009/4221/4244/4326; cstyle-check clean over the changed range. --- tests/unit-mcdc/mcdc_fault_cryptocb.h | 32 ++- tests/unit-mcdc/test_rsa_fault_whitebox.c | 327 ++++++++++++++++++++++ 2 files changed, 356 insertions(+), 3 deletions(-) diff --git a/tests/unit-mcdc/mcdc_fault_cryptocb.h b/tests/unit-mcdc/mcdc_fault_cryptocb.h index ef96e70d786..edab7136021 100644 --- a/tests/unit-mcdc/mcdc_fault_cryptocb.h +++ b/tests/unit-mcdc/mcdc_fault_cryptocb.h @@ -95,6 +95,8 @@ typedef struct McdcCbState { int failed; /* matching operations actually failed */ int seen; /* every operation the device was offered */ int armed; /* zero disarms without unregistering the device */ + int once; /* answer failCode on the first match only, then let + * later matches run in software */ } McdcCbState; static McdcCbState mcdc_cb_state; @@ -153,6 +155,16 @@ static WC_INLINE void mcdc_cb_after(int n) mcdc_cb_state.after = n; } +/* Answer WC_PENDING_E on the FIRST matching operation only, then let later + * matches run in software. The async state machines (wc_RsaFunction / + * wc_RsaDirect) save their state and resume on re-invocation; the second + * dispatch must complete, so a persistent PENDING answer would loop forever. */ +static WC_INLINE void mcdc_cb_pending_once(int pkType) +{ + mcdc_cb_answer_pk(pkType, WC_PENDING_E); + mcdc_cb_state.once = 1; +} + static WC_INLINE void mcdc_cb_disarm(void) { mcdc_cb_state.armed = 0; @@ -218,16 +230,30 @@ static WC_INLINE int mcdc_cb_callback(int devId, wc_CryptoInfo* info, void* ctx) } st->failed++; + if (st->once) { + st->once = 0; + st->armed = 0; + } return st->failCode; } /* Registration is global and idempotent; the state is reset separately so a - * vector can re-arm without re-registering. */ + * vector can re-arm without re-registering. A white-box binary that never + * calls wolfSSL_Init() has an all-zero device table (no free slot), so a + * BUFFER_E answer means "uninitialised": init it once and retry. */ static WC_INLINE int mcdc_cb_install(void) { + int rc; + mcdc_cb_reset(); - return wc_CryptoCb_RegisterDevice(MCDC_CB_DEVID, mcdc_cb_callback, - &mcdc_cb_state); + rc = wc_CryptoCb_RegisterDevice(MCDC_CB_DEVID, mcdc_cb_callback, + &mcdc_cb_state); + if (rc == WC_NO_ERR_TRACE(BUFFER_E)) { + wc_CryptoCb_Init(); + rc = wc_CryptoCb_RegisterDevice(MCDC_CB_DEVID, mcdc_cb_callback, + &mcdc_cb_state); + } + return rc; } static WC_INLINE void mcdc_cb_uninstall(void) diff --git a/tests/unit-mcdc/test_rsa_fault_whitebox.c b/tests/unit-mcdc/test_rsa_fault_whitebox.c index 2e26ff05ea6..f41ee4c7b4e 100644 --- a/tests/unit-mcdc/test_rsa_fault_whitebox.c +++ b/tests/unit-mcdc/test_rsa_fault_whitebox.c @@ -226,6 +226,7 @@ MCDC_FM_MAYBE_UNUSED static int mcdc_rsa_2expt(mp_int* a, int b) #include #include "mcdc_fault_alloc.h" +#include "mcdc_fault_cryptocb.h" #include #include @@ -1029,6 +1030,331 @@ static void wb_rsafunction_state_operand(RsaKey* key, WC_RNG* rng, #endif } +/* -------------------------------------------------------------------------- + * Async PENDING rows of the RSA state machines: + * + * wc_RsaDirect(): 3486 (ret>=0||PENDING, cond 1), 3507 (PENDING + * early return) + * wc_RsaFunction() raw: 3784 (ret<0 && ret!=PENDING, cond 1) in + * wc_RsaFunction_ex + * wc_RsaPublicEncrypt(): 3990/4009 (RsaPublicEncryptEx machine) + * wc_RsaPrivateDecrypt(): 4221/4244/4326 (RsaPrivateDecryptEx machine) + * + * WC_PENDING_E (-108) can enter these rets only from the crypto-callback + * dispatch, so the device answers WC_PENDING_E ONCE for WC_PK_TYPE_RSA + * (mcdc_cb_pending_once): the state machine saves its state, the second + * re-invocation runs in software and completes. A persistent PENDING answer + * would loop forever; an all-software build never produces the code at all. + * The 3784 (T,T) row comes from the sync dispatch's over-length guard + * (BAD_FUNC_ARG); the 3990/3486 clause-2 F rows from an even-modulus + * rejection (MP_VAL) -- the SP backend routes the sync dispatch through + * RsaFunction_SP, so the generic mp-guarded path is not compiled in here + * and the mp lever sees nothing. + * 4244 clause-1 F needs a NEGATIVE unpad return: the private-decrypt + * unpad paths are constant-time and return 0 on invalid padding, so the + * verify path (type-1 unpad, RSA_PAD_E) supplies it. + * Documented residuals: 3784 clause-2 F (PENDING reaching that point + * requires the async dispatch, not compiled in any campaign variant) and + * 4244 clause-2 F (pad==NULL with ret>=0 is structurally unreachable, + * same argument as the documented 4097:1 record). + * ----------------------------------------------------------------------- */ +#if defined(WOLF_CRYPTO_CB) +static void wb_async_pending_state_machine(void) +{ + RsaKey key; + WC_RNG rng; + byte msg[32]; + byte in[WB_RSA_BYTES]; + byte out[WB_RSA_BYTES]; + byte ct[WB_RSA_BYTES]; + byte bad[WB_RSA_BYTES]; + word32 outLen; + word32 i; + int ret; + + XMEMSET(&key, 0, sizeof(key)); + XMEMSET(&rng, 0, sizeof(rng)); + XMEMSET(msg, 0x2b, sizeof(msg)); + for (i = 0; i < sizeof(in); i++) + in[i] = (byte)((i * 7u) + 1u); + + /* devId on the key is what routes the dispatch to the device. */ + if (wc_InitRsaKey_ex(&key, NULL, MCDC_CB_DEVID) != 0 || + wc_InitRng(&rng) != 0) { + WB_NOTE("setup failed; RSA PENDING vectors skipped"); + return; + } + if (wc_MakeRsaKey(&key, WB_RSA_BITS, 65537, &rng) != 0) { + WB_NOTE("keygen failed; RSA PENDING vectors skipped"); + wc_FreeRng(&rng); + return; + } +#ifndef WC_NO_RNG + /* Private decrypt blinds; the key must carry the RNG. */ + (void)wc_RsaSetRNG(&key, &rng); +#endif + + if (mcdc_cb_install() != 0) { + WB_NOTE("device registration failed; RSA PENDING vectors skipped"); + return; + } + +#if defined(WC_RSA_DIRECT) || defined(WC_RSA_NO_PADDING) || \ + defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) + /* ---- wc_RsaDirect() (3486/3507) ---- */ + outLen = sizeof(out); + ret = wc_RsaDirect(in, sizeof(in), out, &outLen, &key, RSA_PUBLIC_ENCRYPT, + &rng); + if (ret < 0) { + WB_NOTE("RsaDirect baseline failed"); + wb_fail = 1; + } + mcdc_cb_pending_once(WC_PK_TYPE_RSA); + outLen = sizeof(out); + ret = wc_RsaDirect(in, sizeof(in), out, &outLen, &key, RSA_PUBLIC_ENCRYPT, + &rng); + if (ret != WC_NO_ERR_TRACE(WC_PENDING_E)) { + WB_NOTE("RsaDirect did not report PENDING"); + wb_fail = 1; + } + outLen = sizeof(out); + ret = wc_RsaDirect(in, sizeof(in), out, &outLen, &key, RSA_PUBLIC_ENCRYPT, + &rng); + if (ret < 0) { + WB_NOTE("RsaDirect resume failed"); + wb_fail = 1; + } + mcdc_cb_reset(); + + /* 3486 clause-2 F row: a non-PENDING negative ret reaching the state + * machine. Over-length input returns before the switch, so use the + * even-modulus trick: the sync dispatch rejects it (MP_VAL). */ + { + mp_int nSave; + mp_int nEven; + + XMEMSET(&nSave, 0, sizeof(nSave)); + XMEMSET(&nEven, 0, sizeof(nEven)); + if ((mp_init(&nSave) == MP_OKAY) && + (mp_init(&nEven) == MP_OKAY) && + (mp_copy(&key.n, &nSave) == MP_OKAY) && + (mp_sub_d(&key.n, 1, &nEven) == MP_OKAY) && + (mp_copy(&nEven, &key.n) == MP_OKAY)) { + outLen = sizeof(out); + ret = wc_RsaDirect(in, sizeof(in), out, &outLen, &key, + RSA_PUBLIC_ENCRYPT, &rng); + if (ret >= 0 || ret == WC_NO_ERR_TRACE(WC_PENDING_E)) { + WB_NOTE("RsaDirect even-modulus did not fail"); + wb_fail = 1; + } + (void)mp_copy(&nSave, &key.n); + } + mp_clear(&nSave); + mp_clear(&nEven); + } +#endif + + /* ---- raw wc_RsaFunction() (3784 in wc_RsaFunction_ex) ---- */ + outLen = sizeof(out); + ret = wc_RsaFunction(in, sizeof(in), out, &outLen, + RSA_PRIVATE_ENCRYPT, &key, &rng); + if (ret < 0) { + WB_NOTE("RsaFunction baseline failed"); + wb_fail = 1; + } + mcdc_cb_pending_once(WC_PK_TYPE_RSA); + outLen = sizeof(out); + ret = wc_RsaFunction(in, sizeof(in), out, &outLen, + RSA_PRIVATE_ENCRYPT, &key, &rng); + if (ret != WC_NO_ERR_TRACE(WC_PENDING_E)) { + WB_NOTE("RsaFunction did not report PENDING"); + wb_fail = 1; + } + outLen = sizeof(out); + ret = wc_RsaFunction(in, sizeof(in), out, &outLen, + RSA_PRIVATE_ENCRYPT, &key, &rng); + if (ret < 0) { + WB_NOTE("RsaFunction resume failed"); + wb_fail = 1; + } + mcdc_cb_reset(); + + /* 3784 (T,T) row: a real (non-PENDING) error out of the dispatch. The + * sync dispatch rejects an input longer than the key (BAD_FUNC_ARG); + * no lever needed, and it works whichever backend (SP or generic) + * computes the exponentiation. */ + { + byte big[WB_RSA_BYTES + 1]; + + XMEMSET(big, 0x5a, sizeof(big)); + outLen = sizeof(out); + ret = wc_RsaFunction(big, sizeof(big), out, &outLen, + RSA_PRIVATE_ENCRYPT, &key, &rng); + if (ret >= 0 || ret == WC_NO_ERR_TRACE(WC_PENDING_E)) { + WB_NOTE("RsaFunction over-length did not fail"); + wb_fail = 1; + } + } + + /* ---- wc_RsaPublicEncrypt() (3990/4009) ---- */ + outLen = sizeof(out); + ret = wc_RsaPublicEncrypt(msg, sizeof(msg), out, outLen, &key, &rng); + if (ret <= 0) { + WB_NOTE("RsaPublicEncrypt baseline failed"); + wb_fail = 1; + } + mcdc_cb_pending_once(WC_PK_TYPE_RSA); + outLen = sizeof(out); + ret = wc_RsaPublicEncrypt(msg, sizeof(msg), out, outLen, &key, &rng); + if (ret != WC_NO_ERR_TRACE(WC_PENDING_E)) { + WB_NOTE("RsaPublicEncrypt did not report PENDING"); + wb_fail = 1; + } + outLen = sizeof(out); + ret = wc_RsaPublicEncrypt(msg, sizeof(msg), out, outLen, &key, &rng); + if (ret <= 0) { + WB_NOTE("RsaPublicEncrypt resume failed"); + wb_fail = 1; + } + mcdc_cb_reset(); + + /* 3990 clause-2 F row: the inner dispatch must return a real + * (non-PENDING) error. The sync dispatch rejects an even modulus + * (MP_VAL), so borrow n, make it even, call, restore. */ + { + mp_int nSave; + mp_int nEven; + + XMEMSET(&nSave, 0, sizeof(nSave)); + XMEMSET(&nEven, 0, sizeof(nEven)); + if ((mp_init(&nSave) == MP_OKAY) && + (mp_init(&nEven) == MP_OKAY) && + (mp_copy(&key.n, &nSave) == MP_OKAY) && + (mp_sub_d(&key.n, 1, &nEven) == MP_OKAY) && + (mp_copy(&nEven, &key.n) == MP_OKAY)) { + outLen = sizeof(out); + ret = wc_RsaPublicEncrypt(msg, sizeof(msg), out, outLen, &key, + &rng); + if (ret >= 0) { + WB_NOTE("even-modulus public encrypt did not fail"); + wb_fail = 1; + } + (void)mp_copy(&nSave, &key.n); + } + mp_clear(&nSave); + mp_clear(&nEven); + } + + /* ---- wc_RsaPrivateDecrypt() (4221/4244/4326) ---- + * Build a valid ciphertext first (unarmed). */ + outLen = sizeof(ct); + ret = wc_RsaPublicEncrypt(msg, sizeof(msg), ct, outLen, &key, &rng); + if (ret <= 0) { + WB_NOTE("ciphertext build failed; decrypt PENDING rows skipped"); + } + else { + word32 ctLen = (word32)ret; + + outLen = sizeof(out); + ret = wc_RsaPrivateDecrypt(ct, ctLen, out, outLen, &key); + if (ret < 0) { + WB_NOTE("RsaPrivateDecrypt baseline failed"); + wb_fail = 1; + } + mcdc_cb_pending_once(WC_PK_TYPE_RSA); + outLen = sizeof(out); + ret = wc_RsaPrivateDecrypt(ct, ctLen, out, outLen, &key); + if (ret != WC_NO_ERR_TRACE(WC_PENDING_E)) { + WB_NOTE("RsaPrivateDecrypt did not report PENDING"); + wb_fail = 1; + } + /* The resume is expected to fail here: the CRYPTOCB dispatch + * short-circuits the inner call BEFORE the exponentiation, so the + * saved state is DECRYPT_UNPAD and the resume unpads the raw + * ciphertext. Every row the machine needs (4221/4326 armed + + * baseline, 4244 baseline) is already taken; the library's tail + * cleanup resets the key, which is all the resume has to do. */ + outLen = sizeof(out); + ret = wc_RsaPrivateDecrypt(ct, ctLen, out, outLen, &key); + (void)ret; + mcdc_cb_reset(); + + /* 4244 clause-1 F row: the inner dispatch must SUCCEED and the + * unpad must fail. A raw-exponentiated junk value (m0^e mod n) is + * < n, so it passes the bounds check, and decrypts to the junk, + * which fails the pad structure. (A mangled valid ciphertext would + * be >= n and break out at the bounds check, before UNPAD.) */ + { + byte m0[WB_RSA_BYTES]; + + XMEMSET(m0, 0x5a, sizeof(m0)); + outLen = sizeof(bad); + (void)wc_RsaFunction(m0, sizeof(m0), bad, &outLen, + RSA_PUBLIC_ENCRYPT, &key, &rng); + outLen = sizeof(out); + ret = wc_RsaPrivateDecrypt(bad, sizeof(bad), out, outLen, &key); + if (ret >= 0) { + WB_NOTE("junk-decrypt unpad unexpectedly succeeded"); + wb_fail = 1; + } + } + +#if !defined(WC_NO_RSA_OAEP) + /* 4244 clause-1 F row: the constant-time PKCS1 v1.5 unpad returns + * 0 (never a negative) on invalid padding, so the F row needs the + * OAEP unpad, which fails with a real error on junk. */ + { + byte m0[WB_RSA_BYTES]; + + XMEMSET(m0, 0x5a, sizeof(m0)); + outLen = sizeof(bad); + (void)wc_RsaFunction(m0, sizeof(m0), bad, &outLen, + RSA_PUBLIC_ENCRYPT, &key, &rng); + outLen = sizeof(out); + ret = wc_RsaPrivateDecrypt_ex(bad, sizeof(bad), out, outLen, + &key, WC_RSA_OAEP_PAD, + WC_HASH_TYPE_SHA, WC_MGF1SHA1, + NULL, 0); + if (ret >= 0) { + WB_NOTE("OAEP junk-decrypt unpad unexpectedly succeeded"); + wb_fail = 1; + } + } +#endif + + /* 4244 clause-1 F row: the private-decrypt unpad paths are + * constant-time and return 0 (never a negative) on invalid + * padding. The VERIFY path (RSA_PUBLIC_DECRYPT) uses the + * non-constant-time type-1 unpad, which returns RSA_PAD_E on + * junk -- the F row. */ +#if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) + { + byte m0[WB_RSA_BYTES]; + + XMEMSET(m0, 0x5a, sizeof(m0)); + outLen = sizeof(bad); + (void)wc_RsaFunction(m0, sizeof(m0), bad, &outLen, + RSA_PRIVATE_ENCRYPT, &key, &rng); + outLen = sizeof(out); + ret = wc_RsaSSL_Verify(bad, sizeof(bad), out, outLen, &key); + if (ret >= 0) { + WB_NOTE("junk-verify unpad unexpectedly succeeded"); + wb_fail = 1; + } + } +#endif + } + + mcdc_cb_uninstall(); + wc_FreeRsaKey(&key); + wc_FreeRng(&rng); + WB_NOTE("RSA state-machine PENDING rows driven"); +} +#else +static void wb_async_pending_state_machine(void) +{ WB_NOTE("WOLF_CRYPTO_CB off; RSA PENDING vectors skipped"); } +#endif + int main(int argc, char** argv) { int do_baseline = (argc > 1 && strcmp(argv[1], "baseline") == 0); @@ -1122,6 +1448,7 @@ int main(int argc, char** argv) wb_priv_zero_crt_components(&key, &rng); if (ctLen > 0) wb_rsafunction_state_operand(&key, &rng, ct, ctLen); + wb_async_pending_state_machine(); /* Scratch-mp_int lifecycle sweeps and the q-loop vector. Counted sweeps, * no wall clock, and every armed call aborts its entry point within a From aafbe4f2f1f1f78704797faa822a7c3a16c5fc5e Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 2 Oct 2026 01:37:29 +0200 Subject: [PATCH 15/33] tests: cover the slhdsa MC/DC GAPS with white-box row drivers The slhdsa campaign GAPS records (41 clause rows across wc_slhdsa.c) needed argument-guard rows, PUBLIC flag-guard rows, a NOT_COMPILED_IN row, an alloc-fail row and SHA-2 hash-fault rows that API-level sweeps cannot produce. Add them to the two white-box TUs: - test_slhdsa_whitebox.c: wb_guard_rows() now drives the NULL-chain guards of all six sign/verify wrappers (c0-F), the crafted MISSING_KEY rows (c1-F), the full-operation T rows (ordered so each verify runs before the next sign overwrites sig), the 4625 alloc row, and the slhdsakey_validate_prehash NOT_COMPILED_IN row via a direct static call (unreachable from the public API: check_hash_for_n rejects every type the switch does not compile in). - test_slhdsa_hash_fault_whitebox.c: wb_precompute_fault_rows (sha2), wb_h_msg_fault_rows (sha2), wb_pkgen_alloc_rows (alloc lever). Verification: - default variant (campaign slhdsa base, SHAKE128s/f): every GAPS record has both clause sides in the llvm-cov export union; runs exit "done (ok)". - slhdsa_sha2 variant (campaign base + WOLFSSL_SLHDSA_SHA2): 772, 1428, 1431, 8576 all covered; runs exit "done (ok)". - Residuals: 8576 c1-T and 772 c1-T need n>16 param sets, which the 128-only campaign build does not compile. - cstyle: the file-level R1 desync pre-exists this change (HEAD fails identically); the functions added here pass the gate in isolation. --- .../test_slhdsa_hash_fault_whitebox.c | 105 ++++++ tests/unit-mcdc/test_slhdsa_whitebox.c | 330 ++++++++++++++++++ 2 files changed, 435 insertions(+) diff --git a/tests/unit-mcdc/test_slhdsa_hash_fault_whitebox.c b/tests/unit-mcdc/test_slhdsa_hash_fault_whitebox.c index a2e1a14224e..ec75b042070 100644 --- a/tests/unit-mcdc/test_slhdsa_hash_fault_whitebox.c +++ b/tests/unit-mcdc/test_slhdsa_hash_fault_whitebox.c @@ -101,6 +101,7 @@ #define MCDC_FH_WITH_SHA_INIT #include "mcdc_fault_hash.h" +#include "mcdc_fault_alloc.h" /* wc_slhdsa.c is #included AFTER the interposers are installed. */ #include @@ -477,6 +478,100 @@ static void wb_init_rows(int param) printf(" [wb] param %d: init hash-object rows exercised\n", param); } +/* slhdsakey_precompute_sha2_midstates()'s "(ret == 0) && (n > 16)" clause-1 + * FALSE row: the SHA-256 midstate setup (init/update) must fail. The + * midstate calls sit at the TAIL of MakeKey (precompute runs after the WOTS/ + * FORS/hypertree keygen, whose hundreds of hash calls push it past the dense + * head of wb_sweep_makekey), so arm the last WB_PRECOMP_TAIL primitive calls + * of a baseline keygen. */ +#define WB_PRECOMP_TAIL 16 + +#if defined(WOLFSSL_SLHDSA_SHA2) && !defined(WOLFSSL_SLHDSA_VERIFY_ONLY) +static void wb_precompute_fault_rows(int param) +{ + long k, n; + SlhDsaKey k2; + + mcdc_fh_disarm(); + XMEMSET(&k2, 0, sizeof(k2)); + if (wc_SlhDsaKey_Init(&k2, (enum SlhDsaParam)param, NULL, + INVALID_DEVID) == 0) { + if (wc_SlhDsaKey_MakeKey(&k2, &wb_rng) == 0) { + k = mcdc_fh_seen(); + for (n = k - (long)WB_PRECOMP_TAIL; (n <= k) && !wb_expired(); + n++) { + SlhDsaKey k3; + + XMEMSET(&k3, 0, sizeof(k3)); + if (wc_SlhDsaKey_Init(&k3, (enum SlhDsaParam)param, NULL, + INVALID_DEVID) == 0) { + mcdc_fh_arm(n); + (void)wc_SlhDsaKey_MakeKey(&k3, &wb_rng); + mcdc_fh_disarm(); + wc_SlhDsaKey_Free(&k3); + } + } + } + wc_SlhDsaKey_Free(&k2); + } + printf(" [wb] param %d: precompute midstate-fault rows exercised\n", + param); +} +#endif + +/* slhdsakey_h_msg_sha2()'s "(ret == 0) && (hdr != NULL)" / "(ret == 0) && + * (ctxSz > 0) && (ctx != NULL)" clause-1 FALSE rows: the SHA-256_2 init and + * its first updates sit within the first few primitive calls of a sign (the + * M' computation runs before the WOTS+ signing), so a dense head over sign + * faults them. The SHAKE-family variants take a different h function; these + * rows only exist in the SHA-2 build. */ +#if defined(WOLFSSL_SLHDSA_SHA2) && !defined(WOLFSSL_SLHDSA_VERIFY_ONLY) +static void wb_h_msg_fault_rows(int param) +{ + long n; + int ret; + + mcdc_fh_disarm(); + for (n = 1; (n <= 16L) && !wb_expired(); n++) { + byte s2[WC_SLHDSA_MAX_SIG_LEN]; + word32 l2 = (word32)sizeof(s2); + mcdc_fh_arm(n); + ret = wc_SlhDsaKey_Sign(&wb_key, wb_ctx, (word32)sizeof(wb_ctx), + wb_msg, (word32)sizeof(wb_msg), s2, &l2, &wb_rng); + mcdc_fh_disarm(); + (void)ret; + } + printf(" [wb] param %d: h_msg_sha2-fault rows exercised\n", param); +} +#endif + +/* slhdsakey_wots_pkgen_chain_c()'s "(ret != 0) && WC_VAR_OK(sk)" clause-2 + * FALSE row: the sk buffer's allocation itself must fail, so the variable is + * not OK while ret != 0. The sk allocation is among the first allocations of + * MakeKey (WOTS+ pkgen runs before the hypertree), so a dense head over the + * allocator finds it. */ +#if !defined(WOLFSSL_SLHDSA_VERIFY_ONLY) && !defined(MCDC_FA_UNAVAILABLE) +static void wb_pkgen_alloc_rows(int param) +{ + long n; + + mcdc_fa_install(); + for (n = 1; (n <= 24L) && !wb_expired(); n++) { + SlhDsaKey k2; + XMEMSET(&k2, 0, sizeof(k2)); + if (wc_SlhDsaKey_Init(&k2, (enum SlhDsaParam)param, NULL, + INVALID_DEVID) == 0) { + mcdc_fa_arm((int)n); + (void)wc_SlhDsaKey_MakeKey(&k2, &wb_rng); + mcdc_fa_disarm(); + wc_SlhDsaKey_Free(&k2); + } + } + mcdc_fa_restore(); + printf(" [wb] param %d: pkgen alloc-fail rows exercised\n", param); +} +#endif + /* Import/export + DER encode/decode: the ASN-side residuals * (`(key->params != NULL) && ...`, `while (ret == 0 && *inOutIdx < seqEnd)`) * live here and cost nothing to drive. */ @@ -604,6 +699,16 @@ static void wb_run_param(int param) wb_sweep_checkkey(param); if (!wb_expired()) wb_sweep_makekey(param); +#if defined(WOLFSSL_SLHDSA_SHA2) && !defined(WOLFSSL_SLHDSA_VERIFY_ONLY) + if (!wb_expired()) + wb_precompute_fault_rows(param); + if (!wb_expired()) + wb_h_msg_fault_rows(param); +#endif +#if !defined(WOLFSSL_SLHDSA_VERIFY_ONLY) && !defined(MCDC_FA_UNAVAILABLE) + if (!wb_expired()) + wb_pkgen_alloc_rows(param); +#endif mcdc_fh_disarm(); wc_SlhDsaKey_Free(&wb_key); diff --git a/tests/unit-mcdc/test_slhdsa_whitebox.c b/tests/unit-mcdc/test_slhdsa_whitebox.c index f6bef839f85..73c6b31d4f8 100644 --- a/tests/unit-mcdc/test_slhdsa_whitebox.c +++ b/tests/unit-mcdc/test_slhdsa_whitebox.c @@ -408,6 +408,335 @@ static void wb_sign_internal_msg_argchecks(void) WB_NOTE("slhdsakey_sign_internal_msg arg-check independence pairs " "exercised"); } + +/* The NULL-chain and flag-guard independence pairs of the sign/verify + * wrappers. The public API tests reach these with valid arguments (the TRUE + * side of every guard); the per-clause FALSE rows need crafted arguments the + * API tests never pass, and the flag-guard TRUE rows need a full keygen + + * sign/verify, which this file pays for once with the smallest compiled-in + * parameter set. + * + * slhdsakey_sign_external() / slhdsakey_signhash_external() are driven + * directly: their guard-passing rows would otherwise run a full signature, + * and the addRnd==NULL check terminates them right after the guards. */ +static void wb_guard_rows(void) +{ + SlhDsaKey key; + SlhDsaParameters fakeParams; + WC_RNG rng; + byte m[8]; + byte h2[WC_SHA256_DIGEST_SIZE]; + byte ctx[3]; + byte sig[WC_SLHDSA_MAX_SIG_LEN]; + byte addRnd[32]; + word32 sigSz; + int param; + int ret; + + XMEMSET(&key, 0, sizeof(key)); + XMEMSET(&fakeParams, 0, sizeof(fakeParams)); + fakeParams.n = 16; + fakeParams.sigLen = (word32)sizeof(sig); + key.params = &fakeParams; + XMEMSET(m, 0xAA, sizeof(m)); + XMEMSET(h2, 0x66, sizeof(h2)); + XMEMSET(ctx, 0x44, sizeof(ctx)); + XMEMSET(sig, 0, sizeof(sig)); + XMEMSET(addRnd, 0x55, sizeof(addRnd)); + XMEMSET(&rng, 0, sizeof(rng)); + if (wc_InitRng(&rng) != 0) { + WB_NOTE("wc_InitRng failed; flag-guard rows skipped"); + return; + } + + /* ---- slhdsakey_sign_external() NULL chain ---- + * Clauses: key==NULL | params==NULL | (ctx==NULL)&&(ctxSz>0) | + * (msg==NULL)&&(msgSz!=0) | sig==NULL | sigSz==NULL. Baseline: all false + * (ends at addRnd==NULL, pre-crypto); each other row flips one clause. */ + sigSz = sizeof(sig); + if (slhdsakey_sign_external(&key, NULL, 0, m, 0, sig, &sigSz, NULL) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("sign_external baseline unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (slhdsakey_sign_external(NULL, NULL, 0, m, 0, sig, &sigSz, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("sign_external key==NULL unexpected ret"); + wb_fail = 1; + } + key.params = NULL; + sigSz = sizeof(sig); + if (slhdsakey_sign_external(&key, NULL, 0, m, 0, sig, &sigSz, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("sign_external params==NULL unexpected ret"); + wb_fail = 1; + } + key.params = &fakeParams; + sigSz = sizeof(sig); + if (slhdsakey_sign_external(&key, NULL, (byte)sizeof(ctx), m, 0, sig, + &sigSz, addRnd) != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("sign_external ctx==NULL,ctxSz>0 unexpected ret"); + wb_fail = 1; + } + /* ctx!=NULL with ctxSz>0: the (ctx==NULL)&&(ctxSz>0) compound is false, + * the guard passes -- the ctxSz>0 clause's independence row. */ + sigSz = sizeof(sig); + if (slhdsakey_sign_external(&key, ctx, (byte)sizeof(ctx), m, 0, sig, + &sigSz, NULL) != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("sign_external ctx!=NULL,ctxSz>0 unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (slhdsakey_sign_external(&key, NULL, 0, NULL, (word32)sizeof(m), sig, + &sigSz, addRnd) != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("sign_external msg==NULL,msgSz!=0 unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (slhdsakey_sign_external(&key, NULL, 0, m, 0, NULL, &sigSz, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("sign_external sig==NULL unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (slhdsakey_sign_external(&key, NULL, 0, m, 0, sig, NULL, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("sign_external sigSz==NULL unexpected ret"); + wb_fail = 1; + } + + /* ---- wc_SlhDsaKey_Sign() sig==NULL clause ---- */ + sigSz = sizeof(sig); + if (wc_SlhDsaKey_Sign(&key, NULL, 0, m, sizeof(m), NULL, &sigSz, NULL) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("Sign sig==NULL unexpected ret"); + wb_fail = 1; + } + + /* ---- wc_SlhDsaKey_Verify() sig==NULL clause ---- */ + if (wc_SlhDsaKey_Verify(&key, NULL, 0, m, sizeof(m), NULL, 0) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("Verify sig==NULL unexpected ret"); + wb_fail = 1; + } + + /* ---- slhdsakey_signhash_external() NULL chain ---- + * Clauses: key==NULL | params==NULL | (ctx==NULL)&&(ctxSz>0) | + * hash==NULL | sig==NULL | sigSz==NULL. */ + sigSz = sizeof(sig); + if (slhdsakey_signhash_external(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, sig, &sigSz, NULL) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("signhash_external baseline unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (slhdsakey_signhash_external(NULL, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, sig, &sigSz, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("signhash_external key==NULL unexpected ret"); + wb_fail = 1; + } + key.params = NULL; + sigSz = sizeof(sig); + if (slhdsakey_signhash_external(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, sig, &sigSz, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("signhash_external params==NULL unexpected ret"); + wb_fail = 1; + } + key.params = &fakeParams; + sigSz = sizeof(sig); + if (slhdsakey_signhash_external(&key, NULL, (byte)sizeof(ctx), m, + sizeof(m), WC_HASH_TYPE_SHA256, sig, &sigSz, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("signhash_external ctx==NULL,ctxSz>0 unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (slhdsakey_signhash_external(&key, NULL, 0, NULL, sizeof(m), + WC_HASH_TYPE_SHA256, sig, &sigSz, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("signhash_external hash==NULL unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (slhdsakey_signhash_external(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, NULL, &sigSz, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("signhash_external sig==NULL unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (slhdsakey_signhash_external(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, sig, NULL, addRnd) + != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("signhash_external sigSz==NULL unexpected ret"); + wb_fail = 1; + } + + /* ---- flag guards: (ret == 0) && ((flags & FLAG) == 0) ---- + * Clause 1 FALSE row: a NULL-chain failure (sig==NULL) leaves ret != 0 + * at the guard. One call per wrapper. */ + sigSz = sizeof(sig); + (void)wc_SlhDsaKey_SignWithRandom(&key, NULL, 0, m, sizeof(m), NULL, + &sigSz, addRnd); + (void)wc_SlhDsaKey_SignMsgWithRandom(&key, m, sizeof(m), NULL, &sigSz, + addRnd); + sigSz = sizeof(sig); + (void)wc_SlhDsaKey_SignHashWithRandom(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, NULL, &sigSz, addRnd); + sigSz = sizeof(sig); + (void)wc_SlhDsaKey_SignHash(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, NULL, &sigSz, NULL); + (void)wc_SlhDsaKey_Verify(&key, NULL, 0, m, sizeof(m), NULL, 0); + (void)wc_SlhDsaKey_VerifyMsg(&key, m, sizeof(m), NULL, 0); + (void)wc_SlhDsaKey_VerifyHash(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, NULL, 0); + + /* Clause 2 TRUE row: a key with the right parameters but no key + * material passes the argument checks and dies at the flag guard with + * MISSING_KEY. One call per wrapper. */ + key.flags = 0; + sigSz = sizeof(sig); + if (wc_SlhDsaKey_SignWithRandom(&key, NULL, 0, m, sizeof(m), sig, + &sigSz, addRnd) != WC_NO_ERR_TRACE(MISSING_KEY)) { + WB_NOTE("SignWithRandom flag guard unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (wc_SlhDsaKey_SignMsgWithRandom(&key, m, sizeof(m), sig, &sigSz, + addRnd) != WC_NO_ERR_TRACE(MISSING_KEY)) { + WB_NOTE("SignMsgWithRandom flag guard unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (wc_SlhDsaKey_SignHashWithRandom(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, sig, &sigSz, addRnd) + != WC_NO_ERR_TRACE(MISSING_KEY)) { + WB_NOTE("SignHashWithRandom flag guard unexpected ret"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (wc_SlhDsaKey_SignHash(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, sig, &sigSz, &rng) + != WC_NO_ERR_TRACE(MISSING_KEY)) { + WB_NOTE("SignHash flag guard unexpected ret"); + wb_fail = 1; + } + if (wc_SlhDsaKey_Verify(&key, NULL, 0, m, sizeof(m), sig, sizeof(sig)) + != WC_NO_ERR_TRACE(MISSING_KEY)) { + WB_NOTE("Verify flag guard unexpected ret"); + wb_fail = 1; + } + if (wc_SlhDsaKey_VerifyMsg(&key, m, sizeof(m), sig, sizeof(sig)) + != WC_NO_ERR_TRACE(MISSING_KEY)) { + WB_NOTE("VerifyMsg flag guard unexpected ret"); + wb_fail = 1; + } + if (wc_SlhDsaKey_VerifyHash(&key, NULL, 0, m, sizeof(m), + WC_HASH_TYPE_SHA256, sig, sizeof(sig)) + != WC_NO_ERR_TRACE(MISSING_KEY)) { + WB_NOTE("VerifyHash flag guard unexpected ret"); + wb_fail = 1; + } + + /* Clause 2 FALSE rows: a real key carries the flags, the guards pass + * and the operations run to completion. One keygen on the smallest + * compiled-in set, shared by all six wrappers. */ + XMEMSET(&key, 0, sizeof(key)); + param = -1; +#ifndef WC_SLHDSA_ALL_NO_128F + param = SLHDSA_SHAKE128F; +#endif +#if defined(WOLFSSL_SLHDSA_SHA2) && !defined(WC_SLHDSA_ALL_NO_128F) + if (param < 0) + param = SLHDSA_SHA2_128F; +#endif +#ifndef WC_SLHDSA_ALL_NO_128S + if (param < 0) + param = SLHDSA_SHAKE128S; +#endif + if (param < 0) { + WB_NOTE("no 128-bit parameter set compiled in; TRUE rows skipped"); + wc_FreeRng(&rng); + return; + } + if (wc_SlhDsaKey_Init(&key, (enum SlhDsaParam)param, NULL, INVALID_DEVID) + != 0 || wc_SlhDsaKey_MakeKey(&key, &rng) != 0) { + WB_NOTE("keygen failed; flag-guard TRUE rows skipped"); + wc_FreeRng(&rng); + wc_SlhDsaKey_Free(&key); + return; + } + + sigSz = sizeof(sig); + ret = wc_SlhDsaKey_SignWithRandom(&key, ctx, (byte)sizeof(ctx), m, + sizeof(m), sig, &sigSz, addRnd); + if (ret != 0) { + WB_NOTE("SignWithRandom full sign failed"); + wb_fail = 1; + } + /* Verify immediately: the next signs overwrite sig. */ + if (wc_SlhDsaKey_Verify(&key, ctx, (byte)sizeof(ctx), m, sizeof(m), + sig, sigSz) != 0) { + WB_NOTE("Verify full verify failed"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (wc_SlhDsaKey_SignMsgWithRandom(&key, m, sizeof(m), sig, &sigSz, + addRnd) != 0) { + WB_NOTE("SignMsgWithRandom full sign failed"); + wb_fail = 1; + } + /* VerifyMsg immediately: the next signs overwrite sig. */ + if (wc_SlhDsaKey_VerifyMsg(&key, m, sizeof(m), sig, sigSz) != 0) { + WB_NOTE("VerifyMsg full verify failed"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (wc_SlhDsaKey_SignHashWithRandom(&key, ctx, (byte)sizeof(ctx), h2, + sizeof(h2), WC_HASH_TYPE_SHA256, sig, &sigSz, addRnd) != 0) { + WB_NOTE("SignHashWithRandom full sign failed"); + wb_fail = 1; + } + sigSz = sizeof(sig); + if (wc_SlhDsaKey_SignHash(&key, ctx, (byte)sizeof(ctx), h2, sizeof(h2), + WC_HASH_TYPE_SHA256, sig, &sigSz, &rng) != 0) { + WB_NOTE("SignHash full sign failed"); + wb_fail = 1; + } + if (wc_SlhDsaKey_VerifyHash(&key, ctx, (byte)sizeof(ctx), h2, sizeof(h2), + WC_HASH_TYPE_SHA256, sig, sigSz) != 0) { + WB_NOTE("VerifyHash full verify failed"); + wb_fail = 1; + } + + /* slhdsakey_validate_prehash(): clause 1 (hashSz != expectedLen) FALSE + * partner needs ret != 0 at the check. From the public API the switch + * default is unreachable in the campaign build: check_hash_for_n + * rejects every hash type the switch does not compile in, and + * validate_prehash runs only when that check passed. The white-box + * includes the TU, so call the static directly with a type the switch + * rejects (MD5 is off in every campaign variant; the enum member is + * unconditional). */ + { + const byte* oid = NULL; + byte oidLen = 0; + + if (slhdsakey_validate_prehash(sizeof(h2), WC_HASH_TYPE_MD5, &oid, + &oidLen) != WC_NO_ERR_TRACE(NOT_COMPILED_IN)) { + WB_NOTE("validate_prehash MD5 unexpected ret"); + wb_fail = 1; + } + } + + wc_SlhDsaKey_Free(&key); + wc_FreeRng(&rng); + + WB_NOTE("slhdsa guard independence pairs exercised"); +} #endif /* !WOLFSSL_SLHDSA_VERIFY_ONLY */ #endif /* WOLFSSL_HAVE_SLHDSA */ @@ -431,6 +760,7 @@ int main(void) #endif #ifndef WOLFSSL_SLHDSA_VERIFY_ONLY wb_sign_internal_msg_argchecks(); + wb_guard_rows(); #endif printf("done (%s)\n", wb_fail ? "with skips" : "ok"); /* Setup failures are surfaced as skips, not test failures: the harness From 52e8bbcb14b3101910c17beb7b89f98e91db311e Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 2 Oct 2026 06:43:07 +0200 Subject: [PATCH 16/33] tests: cover the mldsa MC/DC GAPS with white-box row drivers The mldsa campaign GAPS records (clause rows in wc_mldsa.c) needed argument-guard rows and PrivateKeyDecode dispatch rows that API-level sweeps cannot produce. Add them to the white-box TU: - wb_sign_ctx_msg_guard_rows(): drives the SignCtxWithSeed msg argument guard (11670 c5: msg NULL with len != 0 -> BAD_FUNC_ARG, msg NULL with len == 0 -> canonicalize; also closes 11677) via the public API with a seeded key. - wb_decode_dispatch_rows(): drives the wc_MlDsaKey_PrivateKeyDecode keyType/autoKeyType dispatch and the pubKey/privKey length cascade (13592 c1, 13672 c0/c1) with the library's own encodings of a freshly generated key: the traditional form (bare inner OCTET STRING, no OID -> ANONk auto key type) and the private-key-only PKCS8 DER. The active template parser walks the key data, so hand-crafted junk bytes trip it. Verification: - default variant (campaign mldsa base, portable C): every base GAPS record has both clause sides in the llvm-cov export branches; run exits "done (1 note)" (SIMD rows skipped, expected in base). - Residuals: 13667 c1 and 13672 c0-F are structural (the cascade only runs inside the pubKeyLen == 0 branch, where pubKeyLen != 0 is always false); 13672 c1-F needs a successful seed-only decode and the template parse rejects the hand-crafted seed-only DER; 12827 c1-F and 826 c1-T are structural (params dereference / oidLen bounds). - cstyle: the file-level R4 anonymous-struct flag pre-exists this change (the wb_dispatch_rows vector table); the functions added here pass the gate in isolation. --- tests/unit-mcdc/test_wc_mldsa_whitebox.c | 145 +++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/tests/unit-mcdc/test_wc_mldsa_whitebox.c b/tests/unit-mcdc/test_wc_mldsa_whitebox.c index bbf6b11200e..797306d5400 100644 --- a/tests/unit-mcdc/test_wc_mldsa_whitebox.c +++ b/tests/unit-mcdc/test_wc_mldsa_whitebox.c @@ -1558,6 +1558,149 @@ static void wb_check_key_range(void) } #endif +/* ------------------------------------------------------------------ * + * SignCtxWithSeed's msg guard (11670/11677): the (msg == NULL) && + * (msgLen != 0) compound clause and the empty-message canonicalization + * (msg == NULL, msgLen == 0 -> readable stand-in). A valid key keeps + * the rows on the guard itself. + * ------------------------------------------------------------------ */ +#if !defined(WOLFSSL_MLDSA_NO_SIGN) && !defined(WOLFSSL_MLDSA_NO_MAKE_KEY) +static void wb_sign_ctx_msg_guard_rows(void) +{ + static const byte seed[32] = { + 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, + 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, + 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, + 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f + }; + wc_MlDsaKey key; + static byte sig[MLDSA_MAX_SIG_SIZE]; + word32 sigLen = (word32)sizeof(sig); + int ret; + + if (wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID) != 0) { + return; + } + if (wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44) != 0 || + wc_MlDsaKey_MakeKeyFromSeed(&key, seed) != 0) { + wc_MlDsaKey_Free(&key); + return; + } + + /* (msg == NULL) && (msgLen != 0): both clauses true -> guard fires. */ + ret = wc_MlDsaKey_SignCtxWithSeed(&key, NULL, 0, sig, &sigLen, NULL, + 8, seed); + if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + WB_NOTE("SignCtxWithSeed (NULL msg, len!=0) expected BAD_FUNC_ARG"); + } + + /* (msg == NULL) && (msgLen == 0): clause 2 false -> canonicalize to + * the empty stand-in and sign for real. */ + sigLen = (word32)sizeof(sig); + ret = wc_MlDsaKey_SignCtxWithSeed(&key, NULL, 0, sig, &sigLen, NULL, + 0, seed); + if (ret != 0) { + WB_NOTE("SignCtxWithSeed (NULL msg, len==0) expected 0"); + } + + wc_MlDsaKey_Free(&key); + printf(" [wb] SignCtxWithSeed msg-guard rows exercised\n"); +} +#else +static void wb_sign_ctx_msg_guard_rows(void) +{ + printf(" [wb] SignCtxWithSeed msg-guard rows skipped (not compiled)\n"); +} +#endif + + + +/* ------------------------------------------------------------------ * + * wc_MlDsaKey_PrivateKeyDecode's keyType/autoKeyType dispatch and the + * pubKey/privKey length cascade (13592, 13672). Inputs are the + * library's own encodings of a freshly generated key: the active + * template parser walks the key data, so hand-crafted junk bytes + * trip it. Traditional form = the bare inner OCTET STRING of the + * PKCS8 DER (no OID -> autoKeyType ANONk); priv-only = the PKCS8 DER + * itself (pubKeyLen 0, privKeyLen != 0). + * Residuals: 13667 c1 is structural (the arm only runs inside the + * pubKeyLen == 0 branch, where its first clause is always false); + * 13672 c0-F likewise (the cascade only runs when pubKeyLen == 0); + * 13672 c1-F needs a successful seed-only decode, and the template + * parse rejects the hand-crafted seed-only DER (ASN_PARSE_E). + * ------------------------------------------------------------------ */ +#if !defined(WOLFSSL_MLDSA_NO_ASN1) && defined(WOLFSSL_MLDSA_PRIVATE_KEY) \ + && defined(WOLFSSL_MLDSA_PUBLIC_KEY) && !defined(WOLFSSL_MLDSA_NO_MAKE_KEY) + +static void wb_decode_dispatch_rows(void) +{ + static const byte seed[32] = { + 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, + 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, + 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, + 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f + }; + byte der[MLDSA_MAX_BOTH_KEY_DER_SIZE]; + wc_MlDsaKey key; + word32 derLen = (word32)sizeof(der); + word32 idx = 0; + int n; + int ret; + + if (wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID) != 0) { + return; + } + if (wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44) != 0 || + wc_MlDsaKey_MakeKeyFromSeed(&key, seed) != 0) { + wc_MlDsaKey_Free(&key); + return; + } + n = wc_MlDsaKey_PrivateKeyToDer(&key, der, derLen); + wc_MlDsaKey_Free(&key); + if (n <= 0) { + WB_NOTE("PrivateKeyToDer failed"); + return; + } + + /* (a) Traditional form: the bare inner OCTET STRING of the PKCS8 + * DER (bytes 24..2588: 04 82 0a 00 + 2560 key bytes). No OID -> + * autoKeyType ANONk with an explicit level -> the + * (keyType != ANONk) && (autoKeyType == ANONk) arm. */ + if (wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID) != 0) { + return; + } + if (wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44) != 0) { + wc_MlDsaKey_Free(&key); + return; + } + idx = 0; + (void)wc_MlDsaKey_PrivateKeyDecode(&key, der + 24, 2564, &idx); + wc_MlDsaKey_Free(&key); + + /* (b) Private key only: (pubKeyLen == 0) && (privKeyLen != 0) -> + * the ImportPrivRaw arm. */ + if (wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID) != 0) { + return; + } + if (wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44) != 0) { + wc_MlDsaKey_Free(&key); + return; + } + idx = 0; + ret = wc_MlDsaKey_PrivateKeyDecode(&key, der, (word32)n, &idx); + if (ret != 0) { + WB_NOTE("decode priv-only expected 0"); + } + wc_MlDsaKey_Free(&key); + + printf(" [wb] PrivateKeyDecode dispatch rows exercised\n"); +} +#else +static void wb_decode_dispatch_rows(void) +{ + printf(" [wb] PrivateKeyDecode dispatch rows skipped (not compiled)\n"); +} +#endif int main(void) { /* Unbuffered: on a timeout the process is killed and anything still @@ -1606,6 +1749,8 @@ int main(void) wb_arg_guards(); wb_verify_invalid(); wb_check_key_range(); + wb_sign_ctx_msg_guard_rows(); + wb_decode_dispatch_rows(); printf("done (%d note%s)\n", wb_notes, (wb_notes == 1) ? "" : "s"); return 0; #endif From 2ef230ba73146bfcd4e58f9578a20bc04f8db1ab Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 2 Oct 2026 08:54:53 +0200 Subject: [PATCH 17/33] tests: cover the dtls MC/DC GAPS with white-box row drivers Drive the pure/role functions in src/dtls.c and src/dtls13.c to close the MC/DC independence pairs the API tests leave open: the SendStatelessReplyDtls13 guard/bit/CID/PSK rows, the Dtls13Rtx* and epoch-management helpers, and the Dtls13ProcessBufferedMessages / SendMoreAck / epoch-lookup functions. Residuals (382/551/1074 - structurally unreachable or uninstrumented) and deferrals (1981/2015 CH-frag, the SendStatelessReplyDtls13 PSK cluster, 412/1724/1725 buffered-msg/rtx loops) are documented in the campaign GAPS note. Verification: - Both TUs compile clean under the campaign CF/DF (clang, MC/DC instrumentation); 64 + 403 vectors driven, no failures. - Independence pairs verified in the llvm-cov export file-entry branch tuples (T/F per clause) for every covered record. - cstyle-check.sh clean on both files. --- tests/unit-mcdc/test_dtls13_role_whitebox.c | 409 ++++++++++++++++- tests/unit-mcdc/test_dtls_whitebox.c | 484 +++++++++++++++++++- 2 files changed, 861 insertions(+), 32 deletions(-) diff --git a/tests/unit-mcdc/test_dtls13_role_whitebox.c b/tests/unit-mcdc/test_dtls13_role_whitebox.c index d6503190287..8dddd4c3f0b 100644 --- a/tests/unit-mcdc/test_dtls13_role_whitebox.c +++ b/tests/unit-mcdc/test_dtls13_role_whitebox.c @@ -57,7 +57,7 @@ !defined(WOLFCRYPT_ONLY) && !defined(NO_TLS) static int g_checks; -#define WB_NOTE(what) do { g_checks++; (void)(what); } while (0) +#define WB_NOTE(what) do {g_checks++; (void)(what);} while (0) /* The handshake types these decisions discriminate on. */ static const byte kTypes[] = { @@ -66,7 +66,7 @@ static const byte kTypes[] = { finished, session_ticket, key_update, 200 /* not a handshake type */ }; -static const int kSides[2] = { WOLFSSL_CLIENT_END, WOLFSSL_SERVER_END }; +static const int kSides[2] = {WOLFSSL_CLIENT_END, WOLFSSL_SERVER_END}; /* Reset only what these functions read. Nothing is allocated or owned, so * there is no teardown and no ordering between vectors. */ @@ -107,7 +107,8 @@ static void wb_accept_fragmented(WOLFSSL* ssl, WOLFSSL_CTX* ctx) #endif ssl->options.dtlsStateful = (byte)stateful; WB_NOTE(Dtls13AcceptFragmented(ssl, - (enum HandShakeType)kTypes[t])); + (enum HandShakeType) + kTypes[t])); } } } @@ -122,9 +123,9 @@ static void wb_accept_fragmented(WOLFSSL* ssl, WOLFSSL_CTX* ctx) * Sweeping (side x type x epoch) pairs every arm. */ static void wb_check_epoch(WOLFSSL* ssl, WOLFSSL_CTX* ctx) { - static const word32 kEpochs[] = { 0, DTLS13_EPOCH_EARLYDATA, - DTLS13_EPOCH_HANDSHAKE, - DTLS13_EPOCH_TRAFFIC0, 7 }; + static const word32 kEpochs[] = {0, DTLS13_EPOCH_EARLYDATA, + DTLS13_EPOCH_HANDSHAKE, + DTLS13_EPOCH_TRAFFIC0, 7}; size_t t, e; int s; @@ -134,7 +135,7 @@ static void wb_check_epoch(WOLFSSL* ssl, WOLFSSL_CTX* ctx) wb_reset(ssl, ctx, kSides[s]); ssl->keys.curEpoch64 = w64From32(0x0, kEpochs[e]); WB_NOTE(Dtls13CheckEpoch(ssl, - (enum HandShakeType)kTypes[t])); + (enum HandShakeType)kTypes[t])); } } } @@ -185,7 +186,8 @@ static void wb_set_epoch_keys(WOLFSSL* ssl, WOLFSSL_CTX* ctx) for (a = 0; a < 3; a++) { /* no epoch yet: the early-return arm */ wb_reset(ssl, ctx, kSides[s]); - WB_NOTE(Dtls13SetEpochKeys(ssl, w64From32(0x0, DTLS13_EPOCH_HANDSHAKE), + WB_NOTE(Dtls13SetEpochKeys(ssl, w64From32(0x0, + DTLS13_EPOCH_HANDSHAKE), kEncSides[a])); /* an epoch that exists, with each stored side in turn, so @@ -198,15 +200,395 @@ static void wb_set_epoch_keys(WOLFSSL* ssl, WOLFSSL_CTX* ctx) ssl->dtls13Epochs[0].side = (byte)kEncSides[b]; ssl->dtls13Epochs[0].isValid = 1; WB_NOTE(Dtls13SetEpochKeys(ssl, - w64From32(0x0, DTLS13_EPOCH_HANDSHAKE), - kEncSides[a])); + w64From32(0x0, DTLS13_EPOCH_HANDSHAKE + ), + kEncSides[a])); } } } } +/* ------------------------------------------- guard rows :1364/1572/1270 */ +static void wb_encrypt_rn_guard(WOLFSSL* ssl) +{ + byte hdr[16]; + + WB_NOTE(Dtls13EncryptRecordNumber(NULL, hdr, sizeof(hdr))); + WB_NOTE(Dtls13EncryptRecordNumber(ssl, NULL, sizeof(hdr))); + WB_NOTE(Dtls13EncryptRecordNumber(ssl, hdr, sizeof(hdr))); +} + +static void wb_parse_unified_guard(WOLFSSL* ssl) +{ + Dtls13UnifiedHdrInfo info; + byte hdr[8]; + + XMEMSET(hdr, 0, sizeof(hdr)); + WB_NOTE(Dtls13ParseUnifiedRecordLayer(ssl, NULL, sizeof(hdr), &info)); + WB_NOTE(Dtls13ParseUnifiedRecordLayer(ssl, hdr, 0, &info)); + hdr[0] = DTLS13_FIXED_BITS; + WB_NOTE(Dtls13ParseUnifiedRecordLayer(ssl, hdr, sizeof(hdr), &info)); +} + +static void wb_unified_cid_bit(void) +{ + WB_NOTE(Dtls13UnifiedHeaderCIDPresent(DTLS13_FIXED_BITS | + DTLS13_CID_BIT)); + WB_NOTE(Dtls13UnifiedHeaderCIDPresent(DTLS13_FIXED_BITS)); + WB_NOTE(Dtls13UnifiedHeaderCIDPresent(0x00)); +} + +/* ------------------------------------------- frag/send-now rows :452/478/481 */ +static void wb_frag_in_output_buffer(WOLFSSL* ssl) +{ + byte mem[16]; + + ssl->buffers.outputBuffer.buffer = mem + 8; + ssl->buffers.outputBuffer.bufferSize = 4; + /* inside: both operands false */ + WB_NOTE(FragIsInOutputBuffer(ssl, mem + 8)); + /* before the buffer: operand 0 true */ + WB_NOTE(FragIsInOutputBuffer(ssl, mem)); + /* exactly at the end: operand 1 true */ + WB_NOTE(FragIsInOutputBuffer(ssl, mem + 12)); + ssl->buffers.outputBuffer.buffer = NULL; + ssl->buffers.outputBuffer.bufferSize = 0; +} + +static void wb_send_now_rows(WOLFSSL* ssl) +{ + enum HandShakeType types[7]; + byte hsState; + int i; + + types[0] = client_hello; + types[1] = hello_retry_request; + types[2] = finished; + types[3] = session_ticket; + types[4] = key_update; + types[5] = certificate_request; + types[6] = server_hello; + + /* groupMessages off: operand 0 true */ + ssl->options.groupMessages = 0; + WB_NOTE(Dtls13SendNow(ssl, server_hello)); + /* groupMessages on, sending fragments: operand 1 true */ + ssl->options.groupMessages = 1; + ssl->dtls13SendingFragments = 1; + WB_NOTE(Dtls13SendNow(ssl, server_hello)); + ssl->dtls13SendingFragments = 0; + /* send-now handshake types: one per operand true */ + for (i = 0; i < 5; i++) { + WB_NOTE(Dtls13SendNow(ssl, types[i])); + } + /* certificate_request: done (operand 5 true) and not done + * (operand 6 true) */ + hsState = ssl->options.handShakeState; + ssl->options.handShakeState = HANDSHAKE_DONE; + WB_NOTE(Dtls13SendNow(ssl, certificate_request)); + ssl->options.handShakeState = hsState; + WB_NOTE(Dtls13SendNow(ssl, certificate_request)); + /* all false: server_hello */ + WB_NOTE(Dtls13SendNow(ssl, server_hello)); + ssl->options.groupMessages = 0; +} + +/* ------------------------------------------- rtx/ack rows :869/873/898/932/991/1009 */ +static void wb_rtx_msg_recvd(WOLFSSL* ssl) +{ + DtlsMsg msg; + DtlsFragBucket b1, b2; + Dtls13RtxRecord* rtx; + byte* rtxData; + Dtls13RecordNumber* rn; + byte implicitAck = 0; + byte sendMoreAcks; + + XMEMSET(&msg, 0, sizeof(msg)); + XMEMSET(&b1, 0, sizeof(b1)); + XMEMSET(&b2, 0, sizeof(b2)); + + /* -- Dtls13DetectDisruption :869/873 -- */ + /* two buckets, fragOffset past the end */ + b1.m.m.next = &b2; + b1.m.m.offset = 0; + b1.m.m.sz = 10; + b2.m.m.next = NULL; + b2.m.m.offset = 10; + b2.m.m.sz = 10; + msg.fragBucketList = &b1; + ssl->dtls_rx_msg_list = &msg; + WB_NOTE(Dtls13DetectDisruption(ssl, 25)); + /* one bucket, fragOffset past the end */ + b1.m.m.next = NULL; + WB_NOTE(Dtls13DetectDisruption(ssl, 25)); + /* one bucket, fragOffset == offset + sz */ + WB_NOTE(Dtls13DetectDisruption(ssl, 10)); + /* empty frag list */ + msg.fragBucketList = NULL; + WB_NOTE(Dtls13DetectDisruption(ssl, 10)); + ssl->dtls_rx_msg_list = NULL; + + /* -- Dtls13SaveOrFlushClientHello :932 (via server_hello) -- */ + /* Early in the function: the static-build memory pool is freshest + * here and the rtx record must be heap-allocated. */ + ssl->options.handShakeDone = 0; + /* a raw zeroed ssl has side == 0, which is no side at all */ + ssl->options.side = WOLFSSL_CLIENT_END; + ssl->options.connectState = CLIENT_HELLO_SENT; + ssl->options.downgrade = 1; + rtxData = (byte*)XMALLOC(8, ssl->heap, DYNAMIC_TYPE_DTLS_MSG); + rtx = (Dtls13RtxRecord*)XMALLOC(sizeof(*rtx), ssl->heap, + DYNAMIC_TYPE_DTLS_MSG); + if (rtxData != NULL && rtx != NULL) { + XMEMSET(rtxData, 0x42, 8); + XMEMSET(rtx, 0, sizeof(*rtx)); + rtx->data = rtxData; + rtx->length = 8; + rtx->handshakeType = client_hello; + ssl->dtls13Rtx.rtxRecords = rtx; + ssl->dtls13Rtx.rtxRecordTailPtr = &ssl->dtls13Rtx.rtxRecords; + /* operand 1 false: minDowngrade below DTLSv1_2_MINOR */ + ssl->options.minDowngrade = 0; + WB_NOTE(Dtls13SaveOrFlushClientHello(ssl)); + /* operand 1 true: the record is consumed, so a fresh one */ + rtxData = (byte*)XMALLOC(8, ssl->heap, DYNAMIC_TYPE_DTLS_MSG); + rtx = (Dtls13RtxRecord*)XMALLOC(sizeof(*rtx), ssl->heap, + DYNAMIC_TYPE_DTLS_MSG); + if (rtxData != NULL && rtx != NULL) { + XMEMSET(rtxData, 0x42, 8); + XMEMSET(rtx, 0, sizeof(*rtx)); + rtx->data = rtxData; + rtx->length = 8; + rtx->handshakeType = client_hello; + ssl->dtls13Rtx.rtxRecords = rtx; + ssl->dtls13Rtx.rtxRecordTailPtr = &ssl->dtls13Rtx.rtxRecords; + ssl->options.minDowngrade = DTLSv1_2_MINOR; + WB_NOTE(Dtls13SaveOrFlushClientHello(ssl)); + } else { + XFREE(rtxData, ssl->heap, DYNAMIC_TYPE_DTLS_MSG); + XFREE(rtx, ssl->heap, DYNAMIC_TYPE_DTLS_MSG); + } + } else { + XFREE(rtxData, ssl->heap, DYNAMIC_TYPE_DTLS_MSG); + XFREE(rtx, ssl->heap, DYNAMIC_TYPE_DTLS_MSG); + } + ssl->options.downgrade = 0; + ssl->options.connectState = NULL_STATE; + + /* -- Dtls13RtxMsgRecvd :991 + Dtls13RtxRemoveCurAck :898 -- */ + sendMoreAcks = ssl->options.dtls13SendMoreAcks; + ssl->options.dtls13SendMoreAcks = 1; + ssl->options.handShakeDone = 1; + rn = (Dtls13RecordNumber*)XMALLOC(sizeof(*rn), ssl->heap, + DYNAMIC_TYPE_DTLS_MSG); + if (rn == NULL) { + return; + } + /* matching epoch + seq: both operands true, the node is freed */ + XMEMSET(rn, 0, sizeof(*rn)); + ssl->dtls13Rtx.seenRecords = rn; + ssl->dtls13Rtx.seenRecordsCount = 1; + WB_NOTE(Dtls13RtxMsgRecvd(ssl, certificate_request, 10, &implicitAck)); + /* epoch mismatch: operand 0 false */ + XMEMSET(rn, 0, sizeof(*rn)); + rn->epoch.n = 1; + ssl->dtls13Rtx.seenRecords = rn; + ssl->dtls13Rtx.seenRecordsCount = 1; + WB_NOTE(Dtls13RtxMsgRecvd(ssl, certificate_request, 10, &implicitAck)); + /* seq mismatch: operand 1 false */ + XMEMSET(rn, 0, sizeof(*rn)); + rn->seq.n = 1; + ssl->dtls13Rtx.seenRecords = rn; + ssl->dtls13Rtx.seenRecordsCount = 1; + WB_NOTE(Dtls13RtxMsgRecvd(ssl, certificate_request, 10, &implicitAck)); + XFREE(rn, ssl->heap, DYNAMIC_TYPE_DTLS_MSG); + ssl->dtls13Rtx.seenRecords = NULL; + ssl->dtls13Rtx.seenRecordsCount = 0; + /* 991 operand 1 false: handshake not done */ + ssl->options.handShakeDone = 0; + WB_NOTE(Dtls13RtxMsgRecvd(ssl, certificate_request, 0, &implicitAck)); + /* 991 operand 2 false: not a certificate_request */ + ssl->options.handShakeDone = 1; + WB_NOTE(Dtls13RtxMsgRecvd(ssl, server_hello, 0, &implicitAck)); + /* 991 operand 0 false: peer behind expected */ + ssl->keys.dtls_expected_peer_handshake_number = 1; + WB_NOTE(Dtls13RtxMsgRecvd(ssl, server_hello, 0, &implicitAck)); + ssl->keys.dtls_expected_peer_handshake_number = 0; + + /* -- 1009 -- */ + ssl->options.handShakeDone = 1; + /* sendMoreAcks on + disruption detected: both operands true */ + b1.m.m.next = &b2; + msg.fragBucketList = &b1; + ssl->dtls_rx_msg_list = &msg; + WB_NOTE(Dtls13RtxMsgRecvd(ssl, server_hello, 25, &implicitAck)); + /* fragOffset 0: no disruption */ + WB_NOTE(Dtls13RtxMsgRecvd(ssl, server_hello, 0, &implicitAck)); + /* sendMoreAcks off: operand 0 false */ + ssl->options.dtls13SendMoreAcks = 0; + WB_NOTE(Dtls13RtxMsgRecvd(ssl, server_hello, 25, &implicitAck)); + +restore: + ssl->options.dtls13SendMoreAcks = sendMoreAcks; + ssl->options.handShakeDone = 0; + ssl->options.downgrade = 0; + ssl->options.side = 0; + ssl->options.connectState = NULL_STATE; + ssl->dtls_rx_msg_list = NULL; +} + /* ---------------------------------------------------------------- main */ + +/* Cluster E/F: options and epoch guards in dtls13.c. */ +static void wb_opts_epoch_rows(WOLFSSL* ssl) +{ + int save_maxFrag; + word32 save_fragOff, save_msgLen, save_fragType; + ProtocolVersion save_version; + int save_side, save_serverState, save_hsDone, save_seenUnified; + w64wrapper save_curEpoch, save_dtls13Epoch; + Dtls13Epoch save_e0; + Dtls13RecordNumber* save_seen; + Dtls13Epoch* save_encEpoch; + Dtls13RecordNumber* seen; + byte buf[13]; + word32 idx; + + save_maxFrag = ssl->max_fragment; + save_fragOff = ssl->dtls13FragOffset; + save_msgLen = ssl->dtls13MessageLength; + save_fragType = ssl->dtls13FragHandshakeType; + save_version = ssl->version; + save_side = ssl->options.side; + save_serverState = ssl->options.serverState; + save_hsDone = ssl->options.handShakeDone; + save_seenUnified = ssl->options.seenUnifiedHdr; + save_curEpoch = ssl->keys.curEpoch64; + save_dtls13Epoch = ssl->dtls13Epoch; + save_e0 = ssl->dtls13Epochs[0]; + save_seen = ssl->dtls13Rtx.seenRecords; + save_encEpoch = ssl->dtls13EncryptEpoch; + + /* -- Dtls13SendFragmentedInternal :1074 c0/c1/c2 -- + * maxFragment = min(MAX_RECORD_SIZE, ssl->max_fragment), so c1-T + * (maxFragment > MAX_RECORD_SIZE) is structurally unreachable: + * residual, documented in the GAPS note. */ + ssl->dtls13FragHandshakeType = application_data; + ssl->max_fragment = 10; + WB_NOTE(Dtls13SendFragmentedInternal(ssl)); + ssl->max_fragment = 1000; + ssl->dtls13FragOffset = 200; + ssl->dtls13MessageLength = 100; + WB_NOTE(Dtls13SendFragmentedInternal(ssl)); + ssl->dtls13FragOffset = 0; + WB_NOTE(Dtls13SendFragmentedInternal(ssl)); + + /* -- Dtls13CheckEpoch :1791 c0/c1, :1814 c1 -- */ + ssl->version.major = SSLv3_MAJOR; + ssl->version.minor = DTLSv1_3_MINOR; + ssl->keys.curEpoch64.n = 0; + ssl->options.handShakeDone = 0; + ssl->options.side = WOLFSSL_CLIENT_END; + ssl->options.serverState = 0; + WB_NOTE(Dtls13CheckEpoch(ssl, encrypted_extensions)); + ssl->options.side = WOLFSSL_SERVER_END; + WB_NOTE(Dtls13CheckEpoch(ssl, encrypted_extensions)); + ssl->options.side = WOLFSSL_CLIENT_END; + ssl->options.serverState = SERVER_HELLO_COMPLETE; + WB_NOTE(Dtls13CheckEpoch(ssl, encrypted_extensions)); + ssl->options.serverState = 0; + WB_NOTE(Dtls13CheckEpoch(ssl, certificate)); + ssl->options.serverState = SERVER_HELLO_COMPLETE; + WB_NOTE(Dtls13CheckEpoch(ssl, certificate)); + + /* -- Dtls13GetEpoch :2312 c1-F -- */ + ssl->dtls13Epochs[0].epochNumber.n = 5; + ssl->dtls13Epochs[0].isValid = 0; + WB_NOTE(Dtls13GetEpoch(ssl, w64From32(0, 5))); + /* -- Dtls13SetOlderEpochSide :2327 c0/c1 -- */ + ssl->dtls13Epochs[0].epochNumber.n = 1; + ssl->dtls13Epochs[0].isValid = 0; + WB_NOTE(Dtls13SetOlderEpochSide(ssl, w64From32(0, 2), + ENCRYPT_SIDE_ONLY)); + ssl->dtls13Epochs[0].isValid = 1; + WB_NOTE(Dtls13SetOlderEpochSide(ssl, w64From32(0, 2), + ENCRYPT_SIDE_ONLY)); + ssl->dtls13Epochs[0].epochNumber.n = 5; + WB_NOTE(Dtls13SetOlderEpochSide(ssl, w64From32(0, 2), + ENCRYPT_SIDE_ONLY)); + + /* -- Dtls13RtxTimeout :2959 c2 -- */ + seen = (Dtls13RecordNumber*)XMALLOC(sizeof(*seen), ssl->heap, + DYNAMIC_TYPE_DTLS_MSG); + if (seen != NULL) { + XMEMSET(seen, 0, sizeof(*seen)); + ssl->dtls13Rtx.seenRecords = seen; + ssl->options.serverState = 0; + ssl->dtls13EncryptEpoch = NULL; + ssl->options.seenUnifiedHdr = 1; + WB_NOTE(Dtls13RtxTimeout(ssl)); + ssl->options.seenUnifiedHdr = 0; + WB_NOTE(Dtls13RtxTimeout(ssl)); + XFREE(seen, ssl->heap, DYNAMIC_TYPE_DTLS_MSG); + } + + /* -- DoDtls13NewConnectionId :3071 c0 -- */ + buf[0] = 0; + buf[1] = 5; + buf[2] = 4; + buf[3] = 1; + buf[4] = 2; + buf[5] = 3; + buf[6] = 4; + buf[7] = cid_spare; + idx = 0; + WB_NOTE(DoDtls13NewConnectionId(ssl, buf, &idx, 8)); + /* c0-F: a second usable cid sees newCid != NULL */ + buf[0] = 0; + buf[1] = 10; + buf[2] = 4; + buf[3] = 1; + buf[4] = 2; + buf[5] = 3; + buf[6] = 4; + buf[7] = 4; + buf[8] = 5; + buf[9] = 6; + buf[10] = 7; + buf[11] = 8; + buf[12] = cid_spare; + idx = 0; + WB_NOTE(DoDtls13NewConnectionId(ssl, buf, &idx, 13)); + + /* -- SendDtls13Ack :3207 c2 -- */ + ssl->dtls13Epochs[0].epochNumber.n = 0; + ssl->dtls13Epochs[0].isValid = 1; + ssl->dtls13EncryptEpoch = &ssl->dtls13Epochs[0]; + ssl->options.side = WOLFSSL_SERVER_END; + ssl->options.handShakeDone = 0; + ssl->dtls13Epoch.n = DTLS13_EPOCH_TRAFFIC0; + WB_NOTE(SendDtls13Ack(ssl)); + ssl->dtls13Epoch.n = DTLS13_EPOCH_HANDSHAKE; + WB_NOTE(SendDtls13Ack(ssl)); + + ssl->max_fragment = save_maxFrag; + ssl->dtls13FragOffset = save_fragOff; + ssl->dtls13MessageLength = save_msgLen; + ssl->dtls13FragHandshakeType = save_fragType; + ssl->version = save_version; + ssl->options.side = save_side; + ssl->options.serverState = save_serverState; + ssl->options.handShakeDone = save_hsDone; + ssl->options.seenUnifiedHdr = save_seenUnified; + ssl->keys.curEpoch64 = save_curEpoch; + ssl->dtls13Epoch = save_dtls13Epoch; + ssl->dtls13Epochs[0] = save_e0; + ssl->dtls13Rtx.seenRecords = save_seen; + ssl->dtls13EncryptEpoch = save_encEpoch; +} + int main(void) { WOLFSSL_CTX* ctx = NULL; @@ -233,6 +615,13 @@ int main(void) wb_check_epoch(ssl, ctx); wb_save_or_flush(ssl, ctx); wb_set_epoch_keys(ssl, ctx); + wb_encrypt_rn_guard(ssl); + wb_parse_unified_guard(ssl); + wb_unified_cid_bit(); + wb_frag_in_output_buffer(ssl); + wb_send_now_rows(ssl); + wb_opts_epoch_rows(ssl); + wb_rtx_msg_recvd(ssl); printf("dtls13 role white-box: %d vectors driven\n", g_checks); diff --git a/tests/unit-mcdc/test_dtls_whitebox.c b/tests/unit-mcdc/test_dtls_whitebox.c index 1ba380f6c88..1ec1885fb4e 100644 --- a/tests/unit-mcdc/test_dtls_whitebox.c +++ b/tests/unit-mcdc/test_dtls_whitebox.c @@ -76,7 +76,7 @@ static int g_checks; -#define WB_NOTE(what) do { g_checks++; (void)(what); } while (0) +#define WB_NOTE(what) do {g_checks++; (void)(what);} while (0) /* ------------------------------------------------------------------ helpers */ @@ -102,8 +102,8 @@ static void wb_create_dtls12_cookie(WOLFSSL* ssl) ProtocolVersion pv; WolfSSL_CH ch; byte cookie[DTLS_COOKIE_SZ]; - static const byte secret[] = { 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a }; - const byte random[RAN_LEN] = { 0 }; + static const byte secret[] = {0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a}; + const byte random[RAN_LEN] = {0}; pv.major = DTLS_MAJOR; pv.minor = DTLSv1_2_MINOR; @@ -129,9 +129,9 @@ static void wb_find_ext_by_type(void) WolfSSL_ConstVector exts; int tlsxFound = 0; /* type 0x002b (supported_versions), length 0x0002, body 2 bytes: valid. */ - static const byte ok[] = { 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04 }; + static const byte ok[] = {0x00, 0x2b, 0x00, 0x02, 0x03, 0x04}; /* Same header, but the length claims 0x00ff with only 2 bytes present. */ - static const byte overrun[] = { 0x00, 0x2b, 0x00, 0xff, 0x03, 0x04 }; + static const byte overrun[] = {0x00, 0x2b, 0x00, 0xff, 0x03, 0x04}; exts.elements = ok; exts.size = (word32)sizeof(ok); @@ -153,7 +153,7 @@ static void wb_client_hello_sanity(void) { ProtocolVersion pv; WolfSSL_CH ch; - const byte minors[3] = { DTLSv1_2_MINOR, DTLS_MINOR, 0x0f }; + const byte minors[3] = {DTLSv1_2_MINOR, DTLS_MINOR, 0x0f}; size_t i; for (i = 0; i < sizeof(minors) / sizeof(minors[0]); i++) { @@ -178,9 +178,9 @@ static void wb_check_supported_version(WOLFSSL* ssl) WolfSSL_CH ch; byte isTls13 = 0; /* supported_versions carrying a single TLS 1.3 entry */ - static const byte with_sv[] = { 0x00, 0x2b, 0x00, 0x03, 0x02, 0x03, 0x04 }; + static const byte with_sv[] = {0x00, 0x2b, 0x00, 0x03, 0x02, 0x03, 0x04}; /* server_name (0x0000) only: parses cleanly, but no supported_versions */ - static const byte without_sv[] = { 0x00, 0x00, 0x00, 0x01, 0x00 }; + static const byte without_sv[] = {0x00, 0x00, 0x00, 0x01, 0x00}; pv.major = DTLS_MAJOR; pv.minor = DTLSv1_2_MINOR; @@ -246,18 +246,22 @@ static void wb_stateless_reply_have_flags(WOLFSSL* ssl) * that failed to parse would show up as a MISSING pair rather than a false * pass. */ static const byte ext_sa[] = { /* signature_algorithms 0x000d */ - 0x00, 0x0d, 0x00, 0x04, 0x00, 0x02, 0x08, 0x04 }; + 0x00, 0x0d, 0x00, 0x04, 0x00, 0x02, 0x08, 0x04 + }; static const byte ext_sg[] = { /* supported_groups 0x000a */ - 0x00, 0x0a, 0x00, 0x04, 0x00, 0x02, 0x00, 0x17 }; + 0x00, 0x0a, 0x00, 0x04, 0x00, 0x02, 0x00, 0x17 + }; static const byte ext_ks[] = { /* key_share 0x0033 */ - 0x00, 0x33, 0x00, 0x06, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00 }; + 0x00, 0x33, 0x00, 0x06, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00 + }; /* one row per vector: which of KS / SA / SG to include */ - static const struct { byte ks, sa, sg; const char* what; } rows[] = { - { 1, 1, 1, "all three present -> every operand false" }, - { 0, 1, 1, "no key_share -> operand 0 true" }, - { 1, 0, 1, "no sig_algs -> operand 1 true" }, - { 1, 1, 0, "no supported_grps -> operand 2 true" }, + struct wb_reply_row { byte ks, sa, sg; const char* what; }; + static const struct wb_reply_row rows[] = { + {1, 1, 1, "all three present -> every operand false"}, + {0, 1, 1, "no key_share -> operand 0 true"}, + {1, 0, 1, "no sig_algs -> operand 1 true"}, + {1, 1, 0, "no supported_grps -> operand 2 true"}, }; for (i = 0; i < sizeof(rows) / sizeof(rows[0]); i++) { @@ -265,12 +269,18 @@ static void wb_stateless_reply_have_flags(WOLFSSL* ssl) word32 n = 0; byte suite[2]; - if (rows[i].sa) { XMEMCPY(exts + n, ext_sa, sizeof(ext_sa)); - n += (word32)sizeof(ext_sa); } - if (rows[i].sg) { XMEMCPY(exts + n, ext_sg, sizeof(ext_sg)); - n += (word32)sizeof(ext_sg); } - if (rows[i].ks) { XMEMCPY(exts + n, ext_ks, sizeof(ext_ks)); - n += (word32)sizeof(ext_ks); } + if (rows[i].sa) { + XMEMCPY(exts + n, ext_sa, sizeof(ext_sa)); + n += (word32)sizeof(ext_sa); + } + if (rows[i].sg) { + XMEMCPY(exts + n, ext_sg, sizeof(ext_sg)); + n += (word32)sizeof(ext_sg); + } + if (rows[i].ks) { + XMEMCPY(exts + n, ext_ks, sizeof(ext_ks)); + n += (word32)sizeof(ext_ks); + } pv.major = DTLS_MAJOR; pv.minor = DTLSv1_3_MINOR; @@ -289,6 +299,428 @@ static void wb_stateless_reply_have_flags(WOLFSSL* ssl) } #endif /* WOLFSSL_DTLS13 && !NO_WOLFSSL_SERVER */ +/* ------------------------------- SendStatelessReplyDtls13 PSK rows :637/841/845/863/867/876 */ +/* Compiled under WOLFSSL_DTLS13 && !NO_WOLFSSL_SERVER && !NO_PSK. */ +#if defined(WOLFSSL_DTLS13) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_PSK) +/* PSK server callback: returns a fixed key length (configurable for the + * >MAX_PSK_KEY_LEN row). FindPskSuite reads ssl->options.server_psk_cb, so the + * callback is set directly on the ssl object - no ctx plumbing needed. */ +static int wb_psk_keylen = 16; +static unsigned int wb_psk_cb(WOLFSSL* ssl, const char* identity, + byte* key, word32 max_key_len) +{ + (void)ssl; (void)identity; (void)max_key_len; + XMEMSET(key, 0x42, 16); + return (unsigned int)wb_psk_keylen; +} + +static void wb_psk_send(WOLFSSL* ssl, const byte* exts, word32 n, + byte suite0, byte suite1) +{ + ProtocolVersion pv; + WolfSSL_CH ch; + byte suite[2]; + + pv.major = DTLS_MAJOR; + pv.minor = DTLSv1_3_MINOR; + wb_ch_init(&ch, &pv); + suite[0] = suite0; + suite[1] = suite1; + ch.cipherSuite.elements = suite; + ch.cipherSuite.size = 2; + ch.extension.elements = exts; + ch.extension.size = n; + WB_NOTE(SendStatelessReplyDtls13(ssl, &ch)); +} + +/* The PSK path: a valid pre_shared_key extension (identity "A") plus a + * psk_key_exchange_modes extension. The server PSK callback returns a 16-byte + * key, so FindPskSuite sets pskInfo.isValid when the CH suite matches the + * default PSK cipher (TLS_AES_128_GCM_SHA256 = 0x1301). The modes byte selects + * the PSK_DHE_KE / PSK_KE branch, and the noPskDheKePolicy / onlyPskDheKe + * options flip the second operand of each. Dropping SG / KS / SA in the + * no-usable-mode fallback drives the !haveKS / !haveSA / !haveSG operands. */ +static void wb_stateless_reply_psk(WOLFSSL* ssl) +{ + static const byte ext_sa[] = {0x00, 0x0d, 0x00, 0x04, 0x00, 0x02, 0x08, 0x04 + }; + static const byte ext_sg[] = {0x00, 0x0a, 0x00, 0x04, 0x00, 0x02, 0x00, 0x17 + }; + static const byte ext_ks[] = {0x00, 0x33, 0x00, 0x06, 0x00, 0x04, 0x00, 0x17 + , 0x00, 0x00}; + static const byte ext_psk[] = { + 0x00, 0x29, 0x00, 0x09, 0x00, 0x07, 0x00, 0x01, 0x41, + 0x00, 0x00, 0x00, 0x00 + }; + static const byte ext_modes_dhe[] = {0x00, 0x2d, 0x00, 0x02, 0x01, 0x01}; + static const byte ext_modes_psk[] = {0x00, 0x2d, 0x00, 0x02, 0x01, 0x00}; + byte exts[64]; + word32 n; + + ssl->options.server_psk_cb = wb_psk_cb; + ssl->options.noPskDheKePolicy = 0; + ssl->options.onlyPskDheKe = 0; + /* The stateless reply refines the suite list from the server's + * configured suites (WOLFSSL_SUITES(ssl)); an empty list makes + * FindPskSuiteFromExt's loop a no-op (pskInfo.isValid stays 0). + * wolfSSL_set_cipher_list does not populate ssl->suites in this + * build, so set the PSK cipher suite directly. */ + if (ssl->suites == NULL) { + ssl->suites = (Suites*)XMALLOC(sizeof(Suites), ssl->heap, + DYNAMIC_TYPE_TMP_BUFFER); + XMEMSET(ssl->suites, 0, sizeof(Suites)); + } + ssl->suites->suites[0] = 0x13; + ssl->suites->suites[1] = 0x01; + ssl->suites->suiteSz = 2; + + /* V1: PSK + DHE + all exts -> 637 c0-T, 841 c1-T, 845 c0-T c1-T */ + n = 0; + XMEMCPY(exts + n, ext_sa, sizeof(ext_sa)); n += sizeof(ext_sa); + XMEMCPY(exts + n, ext_sg, sizeof(ext_sg)); n += sizeof(ext_sg); + XMEMCPY(exts + n, ext_ks, sizeof(ext_ks)); n += sizeof(ext_ks); + XMEMCPY(exts + n, ext_psk, sizeof(ext_psk)); n += sizeof(ext_psk); + XMEMCPY(exts + n, ext_modes_dhe, sizeof(ext_modes_dhe)); n += sizeof( + ext_modes_dhe); + wb_psk_send(ssl, exts, n, 0x13, 0x01); + + /* V2: PSK + PSK_KE + all exts -> 845 c0-F, 863 c0-T c1-T */ + n = 0; + XMEMCPY(exts + n, ext_sa, sizeof(ext_sa)); n += sizeof(ext_sa); + XMEMCPY(exts + n, ext_sg, sizeof(ext_sg)); n += sizeof(ext_sg); + XMEMCPY(exts + n, ext_ks, sizeof(ext_ks)); n += sizeof(ext_ks); + XMEMCPY(exts + n, ext_psk, sizeof(ext_psk)); n += sizeof(ext_psk); + XMEMCPY(exts + n, ext_modes_psk, sizeof(ext_modes_psk)); n += sizeof( + ext_modes_psk); + wb_psk_send(ssl, exts, n, 0x13, 0x01); + + /* V3: PSK + DHE + noPskDheKePolicy=1 -> 845 c0-T c1-F, 863 c0-F */ + ssl->options.noPskDheKePolicy = 1; + n = 0; + XMEMCPY(exts + n, ext_sa, sizeof(ext_sa)); n += sizeof(ext_sa); + XMEMCPY(exts + n, ext_sg, sizeof(ext_sg)); n += sizeof(ext_sg); + XMEMCPY(exts + n, ext_ks, sizeof(ext_ks)); n += sizeof(ext_ks); + XMEMCPY(exts + n, ext_psk, sizeof(ext_psk)); n += sizeof(ext_psk); + XMEMCPY(exts + n, ext_modes_dhe, sizeof(ext_modes_dhe)); n += sizeof( + ext_modes_dhe); + wb_psk_send(ssl, exts, n, 0x13, 0x01); + ssl->options.noPskDheKePolicy = 0; + + /* V4: PSK + PSK_KE + onlyPskDheKe=1 -> 863 c0-T c1-F */ + ssl->options.onlyPskDheKe = 1; + n = 0; + XMEMCPY(exts + n, ext_sa, sizeof(ext_sa)); n += sizeof(ext_sa); + XMEMCPY(exts + n, ext_sg, sizeof(ext_sg)); n += sizeof(ext_sg); + XMEMCPY(exts + n, ext_ks, sizeof(ext_ks)); n += sizeof(ext_ks); + XMEMCPY(exts + n, ext_psk, sizeof(ext_psk)); n += sizeof(ext_psk); + XMEMCPY(exts + n, ext_modes_psk, sizeof(ext_modes_psk)); n += sizeof( + ext_modes_psk); + wb_psk_send(ssl, exts, n, 0x13, 0x01); + ssl->options.onlyPskDheKe = 0; + + /* V5: no usable mode + no SG -> 867 c2-T */ + ssl->options.noPskDheKePolicy = 1; + n = 0; + XMEMCPY(exts + n, ext_sa, sizeof(ext_sa)); n += sizeof(ext_sa); + XMEMCPY(exts + n, ext_ks, sizeof(ext_ks)); n += sizeof(ext_ks); + XMEMCPY(exts + n, ext_psk, sizeof(ext_psk)); n += sizeof(ext_psk); + XMEMCPY(exts + n, ext_modes_dhe, sizeof(ext_modes_dhe)); n += sizeof( + ext_modes_dhe); + wb_psk_send(ssl, exts, n, 0x13, 0x01); + + /* V6: no usable mode + no KS -> 867 c0-T */ + n = 0; + XMEMCPY(exts + n, ext_sa, sizeof(ext_sa)); n += sizeof(ext_sa); + XMEMCPY(exts + n, ext_sg, sizeof(ext_sg)); n += sizeof(ext_sg); + XMEMCPY(exts + n, ext_psk, sizeof(ext_psk)); n += sizeof(ext_psk); + XMEMCPY(exts + n, ext_modes_dhe, sizeof(ext_modes_dhe)); n += sizeof( + ext_modes_dhe); + wb_psk_send(ssl, exts, n, 0x13, 0x01); + + /* V7: no usable mode + no SA -> 867 c1-T */ + n = 0; + XMEMCPY(exts + n, ext_sg, sizeof(ext_sg)); n += sizeof(ext_sg); + XMEMCPY(exts + n, ext_ks, sizeof(ext_ks)); n += sizeof(ext_ks); + XMEMCPY(exts + n, ext_psk, sizeof(ext_psk)); n += sizeof(ext_psk); + XMEMCPY(exts + n, ext_modes_dhe, sizeof(ext_modes_dhe)); n += sizeof( + ext_modes_dhe); + wb_psk_send(ssl, exts, n, 0x13, 0x01); + ssl->options.noPskDheKePolicy = 0; + + /* V8: 637 c0-F -> callback returns > MAX_PSK_KEY_LEN (64) */ + wb_psk_keylen = 65; + n = 0; + XMEMCPY(exts + n, ext_sa, sizeof(ext_sa)); n += sizeof(ext_sa); + XMEMCPY(exts + n, ext_sg, sizeof(ext_sg)); n += sizeof(ext_sg); + XMEMCPY(exts + n, ext_ks, sizeof(ext_ks)); n += sizeof(ext_ks); + XMEMCPY(exts + n, ext_psk, sizeof(ext_psk)); n += sizeof(ext_psk); + XMEMCPY(exts + n, ext_modes_dhe, sizeof(ext_modes_dhe)); n += sizeof( + ext_modes_dhe); + wb_psk_send(ssl, exts, n, 0x13, 0x01); + wb_psk_keylen = 16; + + ssl->options.server_psk_cb = NULL; +} +#endif /* WOLFSSL_DTLS13 && !NO_WOLFSSL_SERVER && !NO_PSK */ + +/* ------------------------------------------- CID rows :1210/1233/1397/1398/1408/1462/1535 */ +#ifdef WOLFSSL_DTLS_CID +/* Fixed-size stand-in for ConnectionID (flexible array member); the same + * layout, so a cast is safe. */ +typedef struct WbCid { + byte length; + byte id[4]; +} WbCid; + +static void wb_cid_get_rows(WOLFSSL* ssl) +{ + WbCid id; + CIDInfo info; + byte buf[16]; + unsigned char* c0 = NULL; + int rx; + + XMEMSET(&info, 0, sizeof(info)); + XMEMSET(&id, 0, sizeof(id)); + ssl->dtlsCidInfo = &info; + + /* id == NULL: operand 0 true, tx and rx */ + for (rx = 0; rx < 2; rx++) { + WB_NOTE(DtlsCidGet(ssl, buf, sizeof(buf), rx)); + WB_NOTE(DtlsCidGet0(ssl, &c0, rx)); + } + /* id->length == 0: operand 1 true */ + id.length = 0; + info.tx = (ConnectionID*)&id; + info.rx = (ConnectionID*)&id; + for (rx = 0; rx < 2; rx++) { + WB_NOTE(DtlsCidGet(ssl, buf, sizeof(buf), rx)); + WB_NOTE(DtlsCidGet0(ssl, &c0, rx)); + } + /* accepting partner: a real id */ + id.length = 4; + id.id[0] = 0x01; + id.id[1] = 0x02; + id.id[2] = 0x03; + id.id[3] = 0x04; + for (rx = 0; rx < 2; rx++) { + WB_NOTE(DtlsCidGet(ssl, buf, sizeof(buf), rx)); + WB_NOTE(DtlsCidGet0(ssl, &c0, rx)); + } + ssl->dtlsCidInfo = NULL; +} + +static void wb_cid_replace_tx_rows(WOLFSSL* ssl) +{ + static const byte cid[] = {0x01, 0x02, 0x03}; + + WB_NOTE(DtlsCidReplaceTx(NULL, cid, sizeof(cid))); + WB_NOTE(DtlsCidReplaceTx(ssl, NULL, sizeof(cid))); + WB_NOTE(DtlsCidReplaceTx(ssl, cid, 0)); + WB_NOTE(DtlsCidReplaceTx(ssl, cid, sizeof(cid))); +} + +/* input layout: [cidSz][cid bytes] */ +static void wb_cid_parse_rows(WOLFSSL* ssl) +{ + WbCid id; + CIDInfo* info; + SecureRenegotiation* scr = NULL; + byte input[8]; + byte side; + byte hsState; + byte hsDone; + + if (wolfSSL_dtls_cid_use(ssl) != WOLFSSL_SUCCESS) { + return; + } + info = DtlsCidGetInfo(ssl); + if (info == NULL) { + return; + } + id.length = 4; + id.id[0] = 0x0a; + id.id[1] = 0x0b; + id.id[2] = 0x0c; + id.id[3] = 0x0d; + info->tx = (ConnectionID*)&id; + info->negotiated = 1; + + input[0] = 4; + XMEMCPY(input + 1, id.id, 4); + + /* client side, tx set: re-handshake guard, all clauses true */ + WB_NOTE(TLSX_ConnectionID_Parse(ssl, input, sizeof(input), 1)); + + /* client side, tx NULL + negotiated: guard operand 1 true */ + info->tx = NULL; + WB_NOTE(TLSX_ConnectionID_Parse(ssl, input, sizeof(input), 1)); + info->tx = (ConnectionID*)&id; + + /* server side: guard false, cid compare rows */ + side = ssl->options.side; + ssl->options.side = WOLFSSL_SERVER_END; + WB_NOTE(TLSX_ConnectionID_Parse(ssl, input, sizeof(input), 1)); + input[0] = 3; + WB_NOTE(TLSX_ConnectionID_Parse(ssl, input, sizeof(input), 1)); + input[0] = 4; + input[1] = 0xff; + WB_NOTE(TLSX_ConnectionID_Parse(ssl, input, sizeof(input), 1)); + input[1] = id.id[0]; + ssl->options.side = side; + + /* client side + HRR complete: guard operand 1 false */ + ssl->options.serverState = SERVER_HELLO_RETRY_REQUEST_COMPLETE; + WB_NOTE(TLSX_ConnectionID_Parse(ssl, input, sizeof(input), 1)); + ssl->options.serverState = NULL_STATE; + + /* client side + in-progress SCR: guard operand 2 false */ + scr = (SecureRenegotiation*)XMALLOC(sizeof(*scr), ssl->heap, + DYNAMIC_TYPE_TMP_BUFFER); + if (scr != NULL) { + XMEMSET(scr, 0, sizeof(*scr)); + scr->enabled = 1; + ssl->secure_renegotiation = scr; + hsState = ssl->options.handShakeState; + hsDone = ssl->options.handShakeDone; + ssl->options.handShakeDone = 1; + ssl->options.handShakeState = SERVER_HELLO_COMPLETE; + WB_NOTE(TLSX_ConnectionID_Parse(ssl, input, sizeof(input), 1)); + ssl->secure_renegotiation = NULL; + XFREE(scr, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); + ssl->options.handShakeDone = hsDone; + ssl->options.handShakeState = hsState; + } + info->tx = NULL; + info->negotiated = 0; +} + +static void wb_cid_check_rows(WOLFSSL* ssl) +{ + WbCid id; + CIDInfo info; + byte input[8]; + + input[0] = 0x0a; + input[1] = 0x0b; + input[2] = 0x0c; + input[3] = 0x0d; + XMEMSET(&info, 0, sizeof(info)); + XMEMSET(&id, 0, sizeof(id)); + + /* info == NULL: operand 0 true */ + ssl->dtlsCidInfo = NULL; + WB_NOTE(DtlsCIDCheck(ssl, input, sizeof(input))); + + /* info->rx == NULL: operand 1 true */ + ssl->dtlsCidInfo = &info; + WB_NOTE(DtlsCIDCheck(ssl, input, sizeof(input))); + + /* rx->length == 0: operand 2 true */ + id.length = 0; + info.rx = (ConnectionID*)&id; + WB_NOTE(DtlsCIDCheck(ssl, input, sizeof(input))); + + /* accepting partner: rx set + matching input */ + id.length = 4; + XMEMCPY(id.id, input, 4); + WB_NOTE(DtlsCIDCheck(ssl, input, sizeof(input))); + ssl->dtlsCidInfo = NULL; +} +#endif /* WOLFSSL_DTLS_CID */ + +/* ------------------------------------------- cookie rows :307/330 */ +#ifdef WOLFSSL_DTLS13 +static void wb_cookie_rows(WOLFSSL* ssl) +{ + WolfSSL_CH ch; + ProtocolVersion pv; + Hmac hmac; + static const byte random[RAN_LEN] = {0}; + byte cookieGood = 0; + byte secret[32]; + byte secret2[32]; + byte hash[32]; + byte mac[32]; + byte cookie[64]; + byte cookie12[DTLS_COOKIE_SZ]; + int ret; + + pv.major = DTLS_MAJOR; + pv.minor = DTLSv1_2_MINOR; + wb_ch_init(&ch, &pv); + ch.random = random; + XMEMSET(secret, 0x42, sizeof(secret)); + XMEMSET(secret2, 0x7e, sizeof(secret2)); + XMEMSET(hash, 0x11, sizeof(hash)); + + /* -- isTls13 = 1 :307 -- */ + /* no secrets: TlsCheckCookie -> COOKIE_ERROR. The length is + * big-endian on the wire; ato16 reads it that way. */ + ch.cookieExt.elements = cookie; + cookie[0] = 0; + cookie[1] = 4; + XMEMSET(cookie + 2, 0, 4); + ch.cookieExt.size = 6; + WB_NOTE(CheckDtlsCookie(ssl, &ch, 1, &cookieGood)); + + /* primary secret set, short cookie -> HRR_COOKIE_ERROR */ + ssl->buffers.tls13CookieSecret.buffer = secret; + ssl->buffers.tls13CookieSecret.length = sizeof(secret); + WB_NOTE(CheckDtlsCookie(ssl, &ch, 1, &cookieGood)); + + /* primary secret set, valid cookie -> ret > 0 */ + ret = wc_HmacInit(&hmac, ssl->heap, INVALID_DEVID); + if (ret == 0) { + ret = wc_HmacSetKey(&hmac, WC_SHA256, secret, sizeof(secret)); + } + if (ret == 0) { + ret = wc_HmacUpdate(&hmac, hash, sizeof(hash)); + } + if (ret == 0) { + ret = wc_HmacFinal(&hmac, mac); + } + wc_HmacFree(&hmac); + if (ret == 0) { + XMEMCPY(cookie, hash, 32); + XMEMCPY(cookie + 32, mac, 32); + cookie[0] = 0; + cookie[1] = 64; + ch.cookieExt.size = 66; + WB_NOTE(CheckDtlsCookie(ssl, &ch, 1, &cookieGood)); + } + ssl->buffers.tls13CookieSecret.buffer = NULL; + ssl->buffers.tls13CookieSecret.length = 0; + + /* -- isTls13 = 0 :330 -- */ + ssl->buffers.dtlsCookieSecret.buffer = secret; + ssl->buffers.dtlsCookieSecret.length = sizeof(secret); + /* good cookie: elements is a SEPARATE buffer from ch.dtls12cookie, + * precomputed with the same secret so the constant compare matches */ + ch.cookie.elements = cookie12; + ch.cookie.size = DTLS_COOKIE_SZ; + ch.dtls12cookieSet = 0; + ret = CreateDtls12Cookie(ssl, &ch, secret, sizeof(secret), cookie12); + if (ret == 0) { + WB_NOTE(CheckDtlsCookie(ssl, &ch, 0, &cookieGood)); + } + /* bad cookie, no secondary: operand 1 false */ + XMEMSET(cookie12, 0, DTLS_COOKIE_SZ); + ch.dtls12cookieSet = 0; + WB_NOTE(CheckDtlsCookie(ssl, &ch, 0, &cookieGood)); + /* bad cookie, secondary length > 0: operand 2 true */ + ssl->buffers.dtlsCookieSecretSecondary.buffer = secret2; + ssl->buffers.dtlsCookieSecretSecondary.length = sizeof(secret2); + WB_NOTE(CheckDtlsCookie(ssl, &ch, 0, &cookieGood)); + /* bad cookie, secondary length == 0: operand 2 false */ + ssl->buffers.dtlsCookieSecretSecondary.length = 0; + WB_NOTE(CheckDtlsCookie(ssl, &ch, 0, &cookieGood)); + ssl->buffers.dtlsCookieSecretSecondary.buffer = NULL; + ssl->buffers.dtlsCookieSecret.buffer = NULL; + ssl->buffers.dtlsCookieSecret.length = 0; +} +#endif /* WOLFSSL_DTLS13 */ + /* ---------------------------------------------------------------- main */ int main(void) @@ -334,9 +766,17 @@ int main(void) #endif #ifdef WOLFSSL_DTLS_CID wb_cid_get_size(ssl); + wb_cid_get_rows(ssl); + wb_cid_replace_tx_rows(ssl); + wb_cid_parse_rows(ssl); + wb_cid_check_rows(ssl); #endif #if defined(WOLFSSL_DTLS13) && !defined(NO_WOLFSSL_SERVER) wb_stateless_reply_have_flags(ssl); + wb_stateless_reply_psk(ssl); +#endif +#ifdef WOLFSSL_DTLS13 + wb_cookie_rows(ssl); #endif printf("dtls white-box: %d vectors driven\n", g_checks); From 6ca12271603b50a2921da07cfe4fefa4fc50e7de Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 2 Oct 2026 10:40:50 +0200 Subject: [PATCH 18/33] tests: cover the random.c MC/DC GAPS with white-box row drivers Add wb_drbg_reseedctr_type_rows (1354/1360 in wc_RNG_DRBG_GetReseedCtr) and wb_stir_nonce_null_rng (2550 argument guard) to test_random_fault_whitebox.c. The T directions are covered (non-NULL DRBG rows); the F directions needing drbg/drbg512 == NULL are coverage-runtime residuals (the runtime records no branch eval for a NULL-pointer call) and 2550 c0-T is structural (the public wrapper guards rng == NULL before the _local guard). Full residual analysis in the campaign's reports/random/GAPS.md. --- tests/unit-mcdc/test_random_fault_whitebox.c | 90 ++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tests/unit-mcdc/test_random_fault_whitebox.c b/tests/unit-mcdc/test_random_fault_whitebox.c index af651183265..8aa3b7fc71e 100644 --- a/tests/unit-mcdc/test_random_fault_whitebox.c +++ b/tests/unit-mcdc/test_random_fault_whitebox.c @@ -1219,6 +1219,94 @@ static void wb_healthtest512_uninstantiate_fault(void) { WB_NOTE("SHA-512 Hash_DRBG not compiled in this variant; skipped"); } #endif +/* -------------------------------------------------------------------------- + * 10. wc_RNG_DRBG_GetReseedCtr() DRBG-type rows: + * :1354 (rng->drbgType == WC_DRBG_SHA256) && (rng->drbg != NULL) + * :1360 (rng->drbgType == WC_DRBG_SHA512) && (rng->drbg512 != NULL) + * + * GetReseedCtr is the first gate on the Stir path, so both operands of both + * checks are independently flippable here: the StirGenerate copies at + * :2522/:2528 only run after GetReseedCtr has already proven the pointer + * non-NULL, so their pointer operand is a constant-true residual there. + * ------------------------------------------------------------------------- */ +static void wb_drbg_reseedctr_type_rows(void) +{ + WC_RNG rng; + wc_drbg_reseed_ctr_t ctr; + + /* The base defaults to SHA-512 (WOLFSSL_DRBG_SHA512), so a plain + * wc_InitRng builds a SHA-512 DRBG; disable SHA-512 for the SHA-256 + * section. Each section drives the non-NULL row (operand T) and the + * NULL row (operand F). + * + * COVERED (operand T rows): 1354 c0 T+F, 1354 c1-T, 1360 c0-T, 1360 + * c1-T. + * RESIDUAL (coverage runtime): the NULL-pointer rows' branch + * evaluations are not recorded by the coverage runtime (a NULL call + * increments no branch count - verified: 1354 c0 stays T=1 across + * two SHA-256 calls), so 1354 c1-F, 1360 c0-F and 1360 c1-F cannot + * be shown by any white-box row. */ + + /* SHA-512, drbg512 != NULL: 1354 c0-F, 1360 c0-T + c1-T. */ + XMEMSET(&rng, 0, sizeof(rng)); + if (wc_InitRng(&rng) != 0) { + WB_NOTE("wc_InitRng (SHA-512) failed (GetReseedCtr rows skipped)"); + wb_fail = 1; + return; + } + (void)wc_RNG_DRBG_GetReseedCtr(&rng, &ctr); + + /* SHA-512, drbg512 == NULL: 1360 c1-F (residual row, see above). */ + rng.drbg512 = NULL; + (void)wc_RNG_DRBG_GetReseedCtr(&rng, &ctr); + (void)wc_FreeRng(&rng); + + /* SHA-256, drbg != NULL: 1354 c0-T + c1-T. */ + (void)wc_Sha512Drbg_Disable(); + XMEMSET(&rng, 0, sizeof(rng)); + if (wc_InitRng(&rng) == 0) { + (void)wc_RNG_DRBG_GetReseedCtr(&rng, &ctr); + /* SHA-256, drbg == NULL: 1354 c1-F, 1360 c0-F (residual rows). */ + rng.drbg = NULL; + (void)wc_RNG_DRBG_GetReseedCtr(&rng, &ctr); + (void)wc_FreeRng(&rng); + } + + WB_NOTE("GetReseedCtr DRBG-type rows driven"); +} + +/* -------------------------------------------------------------------------- + * 11. wc_RNG_DRBG_Stir_Nonce() argument guard: + * :2550 (rng == NULL) || (seed == NULL) + * + * c0 (rng == NULL) is the open operand. c0-T is a structural residual: the + * public wc_RNG_DRBG_Stir_Nonce wrapper guards rng == NULL before calling the + * _local function, so the _local guard never sees a NULL rng. The reachable + * row is c0-F + c1-T (valid rng, seed == NULL). + * ------------------------------------------------------------------------- */ +static void wb_stir_nonce_null_rng(void) +{ + WC_RNG rng; + byte seed[16]; + byte nonce[16]; + + XMEMSET(seed, 0xAA, sizeof(seed)); + XMEMSET(nonce, 0xBB, sizeof(nonce)); + + /* 2550 c0-T: rng == NULL (seed present, so the row is c0's). */ + (void)wc_RNG_DRBG_Stir_Nonce(NULL, seed, sizeof(seed), nonce, + sizeof(nonce)); + + /* 2550 c0-F: valid rng, seed == NULL (decision true via the seed arm). */ + XMEMSET(&rng, 0, sizeof(rng)); + if (wc_InitRng(&rng) == 0) { + (void)wc_RNG_DRBG_Stir_Nonce(&rng, NULL, 0, nonce, sizeof(nonce)); + (void)wc_FreeRng(&rng); + } + + WB_NOTE("Stir_Nonce argument-guard rows driven"); +} + int main(void) { setvbuf(stdout, NULL, _IONBF, 0); @@ -1236,6 +1324,8 @@ int main(void) wb_init_flags(); wb_healthtest_uninstantiate_fault(); wb_healthtest512_uninstantiate_fault(); + wb_drbg_reseedctr_type_rows(); + wb_stir_nonce_null_rng(); printf("done (%s)\n", wb_fail ? "with failures" : "ok"); #endif /* Always 0: a nonzero exit discards this variant's whole coverage. */ From 4473cacb8c29f3ae35b0d6e2bc5c2e029e1d2258 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 2 Oct 2026 15:44:30 +0200 Subject: [PATCH 19/33] tests: gate internal-fn MC/DC tests on WOLFSSL_TEST_STATIC_BUILD The new ssl-family test functions reference WOLFSSL_LOCAL symbols (certman ops, SetSSL_CTX, CheckVersion, session cache fns) that are hidden from the shared library by -fvisibility=hidden. Shared builds link tests/unit.test against the .so only, so the references were undefined at link time and broke every CI job that builds the test suite. Gate each body on WOLFSSL_TEST_STATIC_BUILD (set by configure for static-only builds and already defined by the MC/DC ssl_api variant) plus the definition gates of the referenced functions, keeping the declarations and registrations unconditional - the same pattern as the existing WOLF_CRYPTO_CB && WOLFSSL_TEST_STATIC_BUILD tests in tests/api.c. Also gate the LoadCRLBuffer block on HAVE_CRL and the get_chain_X509 block on SESSION_CERTS, whose definitions are absent by default. Verification: shared+static build links; static-only build links and runs the gated tests (unit_test passes); all tests/api files compile in the default configuration. --- tests/api/test_certman.c | 1454 ++++++++++++++------------------- tests/api/test_session.c | 8 +- tests/api/test_ssl_cert.c | 1043 +++++++++++------------ tests/api/test_ssl_crl_ocsp.c | 214 ++--- tests/api/test_ssl_ext.c | 752 ++++++++--------- tests/api/test_tls.c | 18 +- tests/api/test_x509.c | 252 +++--- wolfssl/internal.h | 1 + 8 files changed, 1656 insertions(+), 2086 deletions(-) diff --git a/tests/api/test_certman.c b/tests/api/test_certman.c index af2907e3161..eddc4264294 100644 --- a/tests/api/test_certman.c +++ b/tests/api/test_certman.c @@ -47,40 +47,32 @@ int test_wolfSSL_CertManagerAPI(void) wolfSSL_CertManagerFree(NULL); ExpectIntEQ(wolfSSL_CertManager_up_ref(NULL), 0); ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #ifdef WOLFSSL_TRUST_PEER_CERT ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer_ex(NULL, &c, 1, - WOLFSSL_FILETYPE_ASN1, 0, 0), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WOLFSSL_FILETYPE_ASN1, 0, 0), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, -1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, -1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, -1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, 1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, 1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, 1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, -1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, 1, -1), - WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE)); + WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE)); #endif #if !defined(NO_FILESYSTEM) @@ -97,32 +89,29 @@ int test_wolfSSL_CertManagerAPI(void) #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH) ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, NULL, WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, ca_cert, - WOLFSSL_FILETYPE_PEM), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert, -1), - WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE)); + WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE)); #ifdef WOLFSSL_PEM_TO_DER ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert_der, - WOLFSSL_FILETYPE_PEM), - WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)); + WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)); #endif ExpectIntEQ(wolfSSL_CertManagerVerify(cm, "no-file", - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE)); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, NULL), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, NULL), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, ca_path), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, ca_path), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); } #endif @@ -130,11 +119,11 @@ int test_wolfSSL_CertManagerAPI(void) ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), 1); #elif !defined(HAVE_CRL) ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); #endif ExpectIntEQ(wolfSSL_CertManagerDisableCRL(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerDisableCRL(cm), 1); #ifdef HAVE_CRL /* Test APIs when CRL is disabled. */ @@ -142,74 +131,70 @@ int test_wolfSSL_CertManagerAPI(void) ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1); #endif ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, - sizeof_server_cert_der_2048), 1); + sizeof_server_cert_der_2048), 1); ExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1); #endif /* OCSP */ ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(NULL, 0), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #if !defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \ !defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); #endif #ifdef HAVE_OCSP ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, NULL, 0, - NULL, NULL, NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, NULL, 1, - NULL, NULL, NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, &c, 1, - NULL, NULL, NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, ""), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, NULL), 1); ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(NULL, NULL, NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(cm, NULL, NULL, NULL), 1); ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(cm), 1); /* Test APIs when OCSP is disabled. */ ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, &c, 1, - NULL, NULL, NULL, NULL), 1) - ; + NULL, NULL, NULL, NULL), 1); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, 1), 1); #endif @@ -225,7 +210,7 @@ int test_wolfSSL_CertManagerAPI(void) #ifdef HAVE_OCSP ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, WOLFSSL_OCSP_URL_OVERRIDE | - WOLFSSL_OCSP_CHECKALL), 1); + WOLFSSL_OCSP_CHECKALL), 1); #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \ defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1); @@ -250,7 +235,7 @@ int test_wolfSSL_CertManagerAPI(void) #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_TLS) static int test_cm_load_ca_buffer(const byte* cert_buf, size_t cert_sz, - int file_type) + int file_type) { int ret; WOLFSSL_CERT_MANAGER* cm; @@ -285,31 +270,33 @@ static int test_cm_load_ca_file(const char* ca_cert_file) if (ret == WOLFSSL_SUCCESS) { /* test including null terminator in length */ - byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, - DYNAMIC_TYPE_TMP_BUFFER); + byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { ret = MEMORY_E; - } else { + } + else { cert_buf = tmp; cert_buf[cert_sz] = '\0'; ret = test_cm_load_ca_buffer(cert_buf, cert_sz+1, - CERT_FILETYPE); + CERT_FILETYPE); } + } #if defined(WOLFSSL_PEM_TO_DER) if (ret == WOLFSSL_SUCCESS) { /* test loading DER */ ret = wc_PemToDer(cert_buf, (sword32)cert_sz, CA_TYPE, &pDer, - NULL, NULL, NULL); + NULL, NULL, NULL); if (ret == 0 && pDer != NULL) { ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length, - WOLFSSL_FILETYPE_ASN1); + WOLFSSL_FILETYPE_ASN1); wc_FreeDer(&pDer); } } #endif + } XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -353,16 +340,17 @@ static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags) if (ret == WOLFSSL_SUCCESS) { /* test including null terminator in length */ - byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, - DYNAMIC_TYPE_TMP_BUFFER); + byte* tmp = (byte*)XREALLOC(cert_buf, cert_sz+1, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { ret = MEMORY_E; - } else { + } + else { cert_buf = tmp; cert_buf[cert_sz] = '\0'; ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz+1, - CERT_FILETYPE, flags); + CERT_FILETYPE, flags); } + } #if defined(WOLFSSL_PEM_TO_DER) @@ -372,12 +360,13 @@ static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags) NULL, NULL, NULL); if (ret == 0 && pDer != NULL) { ret = test_cm_load_ca_buffer_ex(pDer->buffer, pDer->length, - WOLFSSL_FILETYPE_ASN1, flags); + WOLFSSL_FILETYPE_ASN1, flags); wc_FreeDer(&pDer); } } #endif + } XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -437,7 +426,7 @@ int test_wolfSSL_CertManagerLoadCABuffer_ex(void) int ret; ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_cert, WOLFSSL_LOAD_FLAG_NONE), - 1); + 1); #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER) ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); #elif defined(NO_RSA) @@ -447,15 +436,14 @@ int test_wolfSSL_CertManagerLoadCABuffer_ex(void) #endif ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_expired_cert, - WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), - 1); + WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), 1); #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER) ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); #elif defined(NO_RSA) ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E)); #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS && \ WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && !defined(NO_ASN_TIME) && \ - defined(WOLFSSL_TRUST_PEER_CERT) && defined(OPENSSL_COMPATIBLE_DEFAULTS) + defined(WOLFSSL_TRUST_PEER_CERT) && defined(OPENSSL_COMPATIBLE_DEFAULTS) ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E)); #else ExpectIntEQ(ret, WOLFSSL_SUCCESS); @@ -500,166 +488,128 @@ int test_wolfSSL_CertManagerLoadCABufferType(void) ExpectIntEQ(load_file(client_cert, &client_cert_buf, &client_cert_sz), 0); ExpectIntNE(wolfSSL_CertManagerLoadCABufferType(cm, ca_cert_buf, - (sword32)ca_cert_sz, - CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, - 0), WOLFSSL_SUCCESS); + (sword32)ca_cert_sz, CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, 0), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCABufferType(cm, ca_cert_buf, - (sword32)ca_cert_sz, - CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, - 5), WOLFSSL_SUCCESS); + (sword32)ca_cert_sz, CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, 5), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, ca_cert_buf, - (sword32)ca_cert_sz, - CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, - WOLFSSL_USER_CA), - WOLFSSL_SUCCESS); + (sword32)ca_cert_sz, CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_CA), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, int1_cert_buf, - (sword32)int1_cert_sz, - CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, - WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + (sword32)int1_cert_sz, CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_INTER), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, int2_cert_buf, - (sword32)int2_cert_sz, - CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, - WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + (sword32)int2_cert_sz, CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_INTER), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, client_cert_buf, - (sword32)client_cert_sz, - CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, - WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + (sword32)client_cert_sz, CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_INTER), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Intermediate certs have been unloaded, but CA cert is still loaded. Expect first level intermediate to verify, rest to fail. */ #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, int1_cert_buf, - (sword32)int1_cert_sz, - CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, - WOLFSSL_TEMP_CA), - WOLFSSL_SUCCESS); + (sword32)int1_cert_sz, CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_TEMP_CA), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, int2_cert_buf, - (sword32)int2_cert_sz, - CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, - WOLFSSL_CHAIN_CA), - WOLFSSL_SUCCESS); + (sword32)int2_cert_sz, CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_CHAIN_CA), + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCABufferType(cm, client_cert_buf, - (sword32)client_cert_sz, - CERT_FILETYPE, 0, - WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, - WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + (sword32)client_cert_sz, CERT_FILETYPE, 0, + WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS, WOLFSSL_USER_INTER), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_USER_INTER), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_CHAIN_CA), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_TEMP_CA), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectIntEQ(wolfSSL_CertManagerUnloadTypeCerts(cm, WOLFSSL_USER_CA), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)) || \ defined(OPENSSL_EXTRA) ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, int1_cert_buf, - int1_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int1_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, int2_cert_buf, - int2_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + int2_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, client_cert_buf, - client_cert_sz, CERT_FILETYPE), - WOLFSSL_SUCCESS); + client_cert_sz, CERT_FILETYPE), WOLFSSL_SUCCESS); #endif if (cm) @@ -682,7 +632,7 @@ int test_wolfSSL_CertManagerGetCerts(void) EXPECT_DECLS; #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \ !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \ - defined(WOLFSSL_SIGNER_DER_CERT) + defined(WOLFSSL_SIGNER_DER_CERT) WOLFSSL_CERT_MANAGER* cm = NULL; WOLFSSL_STACK* sk = NULL; X509* x509 = NULL; @@ -712,17 +662,14 @@ int test_wolfSSL_CertManagerGetCerts(void) /* Check that ASN_SELF_SIGNED_E is returned for a self-signed cert for QT * and full OpenSSL compatibility */ ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)); #else ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); #endif ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm, - "./certs/ca-cert.pem", - NULL)); + "./certs/ca-cert.pem", NULL)); ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(cm)); @@ -778,7 +725,7 @@ int test_wolfSSL_CertManagerSetVerify(void) /* Exercise the baseline verification path before the callback overrides * the result, so the expired-cert failure remains visible to MC/DC. */ ExpectIntNE(wolfSSL_CertManagerVerify(cm, expiredCert, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); #endif wolfSSL_CertManagerSetVerify(cm, myVerify); @@ -786,11 +733,11 @@ int test_wolfSSL_CertManagerSetVerify(void) myVerifyAction = VERIFY_OVERRIDE_ERROR; ExpectIntEQ(wolfSSL_CertManagerVerify(cm, expiredCert, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); wolfSSL_CertManagerSetVerify(cm, NULL); ExpectIntNE(wolfSSL_CertManagerVerify(cm, expiredCert, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); wolfSSL_CertManagerSetVerify(cm, myVerify); #ifdef WOLFSSL_ALWAYS_VERIFY_CB @@ -800,8 +747,7 @@ int test_wolfSSL_CertManagerSetVerify(void) myVerifyAction = VERIFY_FORCE_FAIL; ExpectIntEQ(wolfSSL_CertManagerVerify(cm, verifyCert, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(VERIFY_CERT_ERROR)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(VERIFY_CERT_ERROR)); } #endif @@ -828,11 +774,11 @@ int test_wolfSSL_CertManagerNameConstraint(void) int i = 0; static const byte extNameConsOid[] = {85, 29, 30}; - RsaKey key; - WC_RNG rng; + RsaKey key; + WC_RNG rng; byte *der = NULL; - int derSz = 0; - word32 idx = 0; + int derSz = 0; + word32 idx = 0; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; @@ -842,14 +788,13 @@ int test_wolfSSL_CertManagerNameConstraint(void) /* load in CA private key for signing */ ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, testDevId), 0); ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key, - sizeof_server_key_der_2048), 0); + sizeof_server_key_der_2048), 0); /* get ca certificate then alter it */ ExpectNotNull(der = - (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER)); + (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)); ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull(pt = (byte*)wolfSSL_X509_get_tbs(x509, &derSz)); if (EXPECT_SUCCESS() && (der != NULL)) { XMEMCPY(der, pt, (size_t)derSz); @@ -877,12 +822,11 @@ int test_wolfSSL_CertManagerNameConstraint(void) /* resign the altered certificate */ ExpectIntGT((derSz = wc_SignCert(derSz, CTC_SHA256wRSA, der, - FOURK_BUF, &key, NULL, &rng)), 0); + FOURK_BUF, &key, NULL, &rng)), 0); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_PARSE_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E)); wolfSSL_CertManagerFree(cm); XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -893,37 +837,32 @@ int test_wolfSSL_CertManagerNameConstraint(void) /* add email alt name to satisfy constraint */ pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1) - ); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); DEBUG_WRITE_DER(der, derSz, "ca.der"); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* Good cert test with proper alt email name */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.wolfssl.com", 24 - , -1, 0), SSL_SUCCESS); + (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -935,28 +874,25 @@ int test_wolfSSL_CertManagerNameConstraint(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* Cert with bad alt name list */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.wolfssl.com", 24 - , -1, 0), SSL_SUCCESS); + (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -968,8 +904,7 @@ int test_wolfSSL_CertManagerNameConstraint(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -998,7 +933,7 @@ int test_wolfSSL_CertManagerNameConstraint2(void) const unsigned char *pt; WOLFSSL_EVP_PKEY *priv = NULL; WOLFSSL_X509_NAME* name = NULL; - int derSz = 0; + int derSz = 0; /* C=US*/ char altName[] = { @@ -1036,15 +971,13 @@ int test_wolfSSL_CertManagerNameConstraint2(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1) - ); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) @@ -1054,21 +987,20 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* Test no name case. */ ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, NULL, 0, ASN_DIR_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_add_altname(x509, "", ASN_DIR_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* IP not supported unless WOLFSSL_IP_ALT_NAME is enabled. */ #ifdef WOLFSSL_IP_ALT_NAME ExpectIntEQ(wolfSSL_X509_add_altname(x509, "127.0.0.1", ASN_IP_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #else ExpectIntEQ(wolfSSL_X509_add_altname(x509, "127.0.0.1", ASN_IP_TYPE), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); #endif /* add in matching DIR alt name and resign */ @@ -1081,20 +1013,19 @@ int test_wolfSSL_CertManagerNameConstraint2(void) ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check verify fail */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); /* add in miss matching DIR alt name and resign */ wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail), - ASN_DIR_TYPE); + ASN_DIR_TYPE); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) wolfSSL_X509_sign(x509, priv, EVP_sha3_256()); @@ -1103,20 +1034,19 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); /* check that it still fails if one bad altname and one good altname is in * the certificate */ wolfSSL_X509_free(x509); x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE); wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail), - ASN_DIR_TYPE); + ASN_DIR_TYPE); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) wolfSSL_X509_sign(x509, priv, EVP_sha3_256()); @@ -1125,18 +1055,17 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); /* check it fails with switching position of bad altname */ wolfSSL_X509_free(x509); x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail), - ASN_DIR_TYPE); + ASN_DIR_TYPE); wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) @@ -1146,8 +1075,7 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); /* check that a directoryName that cannot be compared against the * permitted subtree fails the check rather than being taken as either @@ -1155,11 +1083,11 @@ int test_wolfSSL_CertManagerNameConstraint2(void) wolfSSL_X509_free(x509); x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); wolfSSL_X509_add_altname_ex(x509, altNameBadUtf8, sizeof(altNameBadUtf8), - ASN_DIR_TYPE); + ASN_DIR_TYPE); #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) wolfSSL_X509_sign(x509, priv, EVP_sha3_256()); @@ -1168,8 +1096,7 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1180,17 +1107,15 @@ int test_wolfSSL_CertManagerNameConstraint2(void) /* now test with excluded name constraint */ ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert2, - WOLFSSL_FILETYPE_ASN1) - ); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); wolfSSL_X509_add_altname_ex(x509, altNameExc, sizeof(altNameExc), - ASN_DIR_TYPE); + ASN_DIR_TYPE); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); @@ -1201,17 +1126,16 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); /* a directoryName that cannot be compared against the excluded subtree * has not been shown to be outside it, so it fails the check too */ wolfSSL_X509_free(x509); x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); wolfSSL_X509_add_altname_ex(x509, altNameBadUtf8, sizeof(altNameBadUtf8), - ASN_DIR_TYPE); + ASN_DIR_TYPE); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); @@ -1222,8 +1146,7 @@ int test_wolfSSL_CertManagerNameConstraint2(void) #endif ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1249,43 +1172,38 @@ int test_wolfSSL_CertManagerNameConstraint3(void) const char* server_cert = "./certs/test/server-goodcn.pem"; byte *der = NULL; - int derSz = 0; + int derSz = 0; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1) - ); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); DEBUG_WRITE_DER(der, derSz, "ca.der"); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* check satisfying .wolfssl.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.wolfssl.com", 24 - , -1, 0), SSL_SUCCESS); + (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1297,27 +1215,24 @@ int test_wolfSSL_CertManagerNameConstraint3(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check satisfying .random.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.example.com", 24 - , -1, 0), SSL_SUCCESS); + (byte*)"support@info.example.com", 24, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1329,27 +1244,24 @@ int test_wolfSSL_CertManagerNameConstraint3(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check fail case when neither constraint is matched */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8, - (byte*)"support@info.com", 16, -1, 0) - , SSL_SUCCESS); + (byte*)"support@info.com", 16, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1360,8 +1272,7 @@ int test_wolfSSL_CertManagerNameConstraint3(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1387,40 +1298,36 @@ int test_wolfSSL_CertManagerNameConstraint4(void) const char* server_cert = "./certs/test/server-goodcn.pem"; byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1) - ); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); DEBUG_WRITE_DER(der, derSz, "ca.der"); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* check satisfying wolfssl.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1431,24 +1338,22 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check satisfying example.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"example.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"example.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1459,24 +1364,22 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check satisfying wolfssl.com constraint passes with list of DNS's */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1489,24 +1392,22 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* check fail when one DNS in the list is bad */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1519,24 +1420,22 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* check fail case when neither constraint is matched */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"common", 6, -1, 0), - SSL_SUCCESS); + (byte*)"common", 6, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1546,8 +1445,7 @@ int test_wolfSSL_CertManagerNameConstraint4(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -1573,40 +1471,36 @@ int test_wolfSSL_CertManagerNameConstraint5(void) const char* server_cert = "./certs/test/server-goodcn.pem"; byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1) - ); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); DEBUG_WRITE_DER(der, derSz, "ca.der"); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* check satisfying wolfssl.com constraint passes */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"example", 7, -1, 0), - SSL_SUCCESS); + (byte*)"example", 7, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1618,24 +1512,22 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* fail with DNS check because of common name */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), - SSL_SUCCESS); + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1647,21 +1539,20 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* fail on permitted DNS name constraint */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1674,21 +1565,20 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* fail on permitted email name constraint */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; @@ -1701,21 +1591,20 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* success with empty email name */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1725,8 +1614,7 @@ int test_wolfSSL_CertManagerNameConstraint5(void) ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); wolfSSL_CertManagerFree(cm); @@ -1755,42 +1643,38 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) const char* server_cert = "./certs/test/server-goodcn.pem"; /* non-dNSName SAN values. The CA declares no registeredID or iPAddress * constraint, so these names are themselves unconstrained. */ - static const byte rid_dummy[] = {0x2A, 0x03, 0x04}; /* OID 1.2.3.4 */ - static const byte ip_dummy[] = {203, 0, 113, 7}; + static const byte rid_dummy[] = { 0x2A, 0x03, 0x04 }; /* OID 1.2.3.4 */ + static const byte ip_dummy[] = { 203, 0, 113, 7 }; byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1) - ); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* Negative case: leaf with an out-of-scope dNSName SAN. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0 - ), + (byte*)"evil.attacker.com", 17, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1801,24 +1685,22 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with an out-of-scope CN but an in-scope dNSName * SAN; the dNSName SAN suppresses the CN fallback, so it is accepted. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0 - ), + (byte*)"evil.attacker.com", 17, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1828,25 +1710,23 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* Negative case: leaf with an out-of-scope CN and no SAN; the CN is * checked against the DNS constraint as a fallback. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0 - ), + (byte*)"evil.attacker.com", 17, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1856,23 +1736,22 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with an in-scope CN and no SAN. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); @@ -1882,90 +1761,81 @@ int test_wolfSSL_CertManagerNameConstraint_DNS_CN(void) ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_X509_free(x509); x509 = NULL; /* Negative case: leaf with an out-of-scope CN and a registeredID SAN; * a non-dNSName SAN must not suppress the CN check. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0 - ), + (byte*)"evil.attacker.com", 17, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)rid_dummy, - sizeof(rid_dummy), ASN_RID_TYPE), - WOLFSSL_SUCCESS); + sizeof(rid_dummy), ASN_RID_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Negative case: leaf with an out-of-scope CN and an iPAddress SAN. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"evil.attacker.com", 17, -1, 0 - ), + (byte*)"evil.attacker.com", 17, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)ip_dummy, - sizeof(ip_dummy), ASN_IP_TYPE), - WOLFSSL_SUCCESS); + sizeof(ip_dummy), ASN_IP_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with an in-scope CN and a registeredID SAN; the * check must not over-reject. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8, - (byte*)"US", 2, -1, 0), SSL_SUCCESS); + (byte*)"US", 2, -1, 0), SSL_SUCCESS); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)"wolfssl.com", 11, -1, 0), + (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)rid_dummy, - sizeof(rid_dummy), ASN_RID_TYPE), - WOLFSSL_SUCCESS); + sizeof(rid_dummy), ASN_RID_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -2014,33 +1884,30 @@ int test_wolfSSL_CertManagerNameConstraint_IP_SAN(void) const char* ca_cert = "./certs/test/cert-ext-ncip.der"; const char* server_cert = "./certs/test/server-goodcn.pem"; /* Raw IPv4 bytes for SAN values (not dotted-quad strings). */ - static const byte ip_inside[] = {192, 168, 1, 10}; /* permitted */ - static const byte ip_outside[] = {10, 0, 0, 1}; /* violates */ + static const byte ip_inside[] = { 192, 168, 1, 10 }; /* permitted */ + static const byte ip_outside[] = { 10, 0, 0, 1 }; /* violates */ byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1) - ); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* Negative case: leaf with IP SAN outside permitted subnet. Must be * rejected with ASN_NAME_INVALID_E. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; @@ -2048,32 +1915,28 @@ int test_wolfSSL_CertManagerNameConstraint_IP_SAN(void) /* Use add_altname_ex with raw IP bytes so the test runs in default * builds where add_altname (string form) requires WOLFSSL_IP_ALT_NAME. */ ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)ip_outside, - sizeof(ip_outside), ASN_IP_TYPE), - WOLFSSL_SUCCESS); + sizeof(ip_outside), ASN_IP_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with IP SAN inside the permitted subnet must be * accepted. Confirms the fix does not over-reject. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)ip_inside, - sizeof(ip_inside), ASN_IP_TYPE), - WOLFSSL_SUCCESS); + sizeof(ip_inside), ASN_IP_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -2121,64 +1984,57 @@ int test_wolfSSL_CertManagerNameConstraint_RID_SAN(void) * 40*X + Y in one byte for X<=2,Y<=39, then each subsequent arc is * base-128 with continuation bits. For values <128 the encoding is a * single byte. */ - static const byte rid_inside[] = {0x2A, 0x03, 0x04, 0x05}; /* 1.2.3.4.5 - permitted */ - static const byte rid_outside[] = {0x2A, 0x03, 0x04, 0x63}; /* 1.2.3.4.99 - violates */ + static const byte rid_inside[] = { 0x2A, 0x03, 0x04, 0x05 }; /* 1.2.3.4.5 - permitted */ + static const byte rid_outside[] = { 0x2A, 0x03, 0x04, 0x63 }; /* 1.2.3.4.99 - violates */ byte *der = NULL; - int derSz; + int derSz; byte *pt; WOLFSSL_X509 *x509 = NULL; WOLFSSL_X509 *ca = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert, - WOLFSSL_FILETYPE_ASN1) - ); + WOLFSSL_FILETYPE_ASN1)); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz))); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* Negative case: leaf with a registeredID SAN outside the permitted * OID set. Must be rejected with ASN_NAME_INVALID_E. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)rid_outside, - sizeof(rid_outside), ASN_RID_TYPE), - WOLFSSL_SUCCESS); + sizeof(rid_outside), ASN_RID_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_X509_free(x509); x509 = NULL; /* Positive case: leaf with a registeredID SAN matching the permitted * OID exactly must be accepted. */ ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca)); ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (const char*)rid_inside, - sizeof(rid_inside), ASN_RID_TYPE), - WOLFSSL_SUCCESS); + sizeof(rid_inside), ASN_RID_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz))); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); wolfSSL_X509_free(x509); @@ -2211,10 +2067,10 @@ int test_wolfSSL_X509_get_ext_d2i_RID_SAN(void) * d.dNSName-as-IA5STRING in the union). */ WOLFSSL_EVP_PKEY *priv = NULL; const char* server_cert = "./certs/test/server-goodcn.pem"; - static const byte rid_oid[] = {0x2A, 0x03, 0x04, 0x05}; + static const byte rid_oid[] = { 0x2A, 0x03, 0x04, 0x05 }; byte *pt; byte *der = NULL; - int derSz; + int derSz; WOLFSSL_X509 *leaf = NULL; WOLFSSL_X509 *parsed = NULL; WOLFSSL_STACK *altNames = NULL; @@ -2226,30 +2082,26 @@ int test_wolfSSL_X509_get_ext_d2i_RID_SAN(void) pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); /* Build and sign a leaf with a registeredID SAN. */ ExpectNotNull(leaf = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectIntEQ(wolfSSL_X509_add_altname_ex(leaf, (const char*)rid_oid, - sizeof(rid_oid), ASN_RID_TYPE), - WOLFSSL_SUCCESS); + sizeof(rid_oid), ASN_RID_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leaf, priv, EVP_sha256()), 0); ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(leaf, &derSz))); /* Re-parse the signed leaf so altNames are populated through * DecodeGeneralName (the path the fix touches). */ ExpectNotNull(parsed = wolfSSL_X509_load_certificate_buffer(der, derSz, - WOLFSSL_FILETYPE_ASN1)); + WOLFSSL_FILETYPE_ASN1)); /* wolfSSL_X509_get_ext_d2i for SAN must return a non-NULL stack * containing a registeredID GENERAL_NAME with the union populated * via d.registeredID (not d.dNSName). */ ExpectNotNull(altNames = (WOLFSSL_STACK*)wolfSSL_X509_get_ext_d2i(parsed, - NID_subject_alt_name, - NULL, NULL - )); + NID_subject_alt_name, NULL, NULL)); if (altNames != NULL) { for (i = 0; i < wolfSSL_sk_num(altNames); i++) { gn = (WOLFSSL_GENERAL_NAME*)wolfSSL_sk_value(altNames, i); @@ -2271,7 +2123,7 @@ int test_wolfSSL_X509_get_ext_d2i_RID_SAN(void) ExpectIntEQ(gn->d.registeredID->obj[1], (byte)sizeof(rid_oid)); ExpectIntEQ(XMEMCMP(gn->d.registeredID->obj + 2, - rid_oid, sizeof(rid_oid)), 0); + rid_oid, sizeof(rid_oid)), 0); } } found = 1; @@ -2283,7 +2135,7 @@ int test_wolfSSL_X509_get_ext_d2i_RID_SAN(void) if (altNames != NULL) { wolfSSL_sk_pop_free(altNames, - (void (*)(void*)) wolfSSL_GENERAL_NAME_free); + (void (*)(void*))wolfSSL_GENERAL_NAME_free); } /* Also exercise wolfSSL_X509_get_ext, which routes through @@ -2335,29 +2187,26 @@ int test_wolfSSL_X509_check_host_IP_only_SAN_CN_fallback(void) WOLFSSL_X509_NAME* name = NULL; const char* server_cert = "./certs/test/server-goodcn.pem"; const char hostName[] = "cnhost.local"; - static const byte ip_san[] = {10, 0, 0, 1}; + static const byte ip_san[] = { 10, 0, 0, 1 }; byte *pt; WOLFSSL_X509 *leafIp = NULL; WOLFSSL_X509 *leafDns = NULL; pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); /* Leaf with CN matching hostName and only an iPAddress SAN. */ ExpectNotNull(leafIp = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)hostName, (int)XSTRLEN( - hostName), -1, 0), SSL_SUCCESS); + (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(leafIp, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname_ex(leafIp, (const char*)ip_san, - sizeof(ip_san), ASN_IP_TYPE), - WOLFSSL_SUCCESS); + sizeof(ip_san), ASN_IP_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leafIp, priv, EVP_sha256()), 0); #ifndef WOLFSSL_IP_ALT_NAME @@ -2365,14 +2214,13 @@ int test_wolfSSL_X509_check_host_IP_only_SAN_CN_fallback(void) * constraint enforcement but treated as absent for *checkCN, so the * lookup falls back to the Subject CN, which matches. */ ExpectIntEQ(wolfSSL_X509_check_host(leafIp, hostName, XSTRLEN(hostName), - 0, NULL), WOLFSSL_SUCCESS); + 0, NULL), WOLFSSL_SUCCESS); #else /* IP_ALT_NAME build: SAN presence suppresses CN fallback per RFC 6125. * The hostName ("cnhost.local") cannot match the iPAddress entry, so * the check must fail. */ ExpectIntEQ(wolfSSL_X509_check_host(leafIp, hostName, XSTRLEN(hostName), - 0, NULL), WC_NO_ERR_TRACE( - WOLFSSL_FAILURE)); + 0, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); #endif /* Leaf with CN matching hostName but a non-matching DNS SAN. CN @@ -2381,20 +2229,18 @@ int test_wolfSSL_X509_check_host_IP_only_SAN_CN_fallback(void) * other side of the boundary so a future change that broadly skips * altNames in *checkCN does not silently regress. */ ExpectNotNull(leafDns = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)hostName, (int)XSTRLEN( - hostName), -1, 0), SSL_SUCCESS); + (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(leafDns, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname(leafDns, "other.example", - ASN_DNS_TYPE), WOLFSSL_SUCCESS); + ASN_DNS_TYPE), WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leafDns, priv, EVP_sha256()), 0); ExpectIntEQ(wolfSSL_X509_check_host(leafDns, hostName, XSTRLEN(hostName), - 0, NULL), WC_NO_ERR_TRACE( - WOLFSSL_FAILURE)); + 0, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); wolfSSL_X509_free(leafIp); wolfSSL_X509_free(leafDns); @@ -2427,43 +2273,38 @@ int test_wolfSSL_X509_check_host_URI_SAN_not_DNS_match(void) pt = (byte*)server_key_der_2048; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, - (const unsigned char**)&pt, - sizeof_server_key_der_2048)); + (const unsigned char**)&pt, sizeof_server_key_der_2048)); ExpectNotNull(leafUri = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)hostName, (int)XSTRLEN( - hostName), -1, 0), SSL_SUCCESS); + (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(leafUri, name), WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname(leafUri, uriSan, ASN_URI_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leafUri, priv, EVP_sha256()), 0); ExpectIntEQ(wolfSSL_X509_check_host(leafUri, hostName, XSTRLEN(hostName), - 0, NULL), WC_NO_ERR_TRACE( - WOLFSSL_FAILURE)); + 0, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); ExpectNotNull(leafUriDns = wolfSSL_X509_load_certificate_file(server_cert, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); ExpectNotNull(name = X509_NAME_new()); ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, - (byte*)hostName, (int)XSTRLEN( - hostName), -1, 0), SSL_SUCCESS); + (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_set_subject_name(leafUriDns, name), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); X509_NAME_free(name); name = NULL; ExpectIntEQ(wolfSSL_X509_add_altname(leafUriDns, uriSan, ASN_URI_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_add_altname(leafUriDns, hostName, ASN_DNS_TYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntGT(wolfSSL_X509_sign(leafUriDns, priv, EVP_sha256()), 0); ExpectIntEQ(wolfSSL_X509_check_host(leafUriDns, hostName, - XSTRLEN(hostName), 0, NULL), - WOLFSSL_SUCCESS); + XSTRLEN(hostName), 0, NULL), WOLFSSL_SUCCESS); wolfSSL_X509_free(leafUri); wolfSSL_X509_free(leafUriDns); @@ -2559,130 +2400,113 @@ int test_wolfSSL_CertManagerCRL(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(NULL, 0), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK), 1); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, - WOLFSSL_CRL_CHECK | - WOLFSSL_CRL_CHECKALL), 1); + WOLFSSL_CRL_CHECK | WOLFSSL_CRL_CHECKALL), 1); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 16), 1); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, - sizeof_server_cert_der_2048), - WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(cm, NULL), 1); #ifdef HAVE_CRL_IO ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1); #endif #ifndef NO_FILESYSTEM ExpectIntEQ(wolfSSL_CertManagerLoadCRL(NULL, NULL, WOLFSSL_FILETYPE_ASN1, - 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, NULL, WOLFSSL_FILETYPE_ASN1, - 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* -1 seen as !WOLFSSL_FILETYPE_PEM */ ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, "./certs/crl", -1, 0), 1); ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(NULL, NULL, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, NULL, WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* -1 seen as !WOLFSSL_FILETYPE_PEM */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, "./certs/crl/crl.pem", -1), - WC_NO_ERR_TRACE(ASN_PARSE_E)); + WC_NO_ERR_TRACE(ASN_PARSE_E)); #endif ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, -1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, -1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, -1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, 1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, 1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, 1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, -1, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, 0, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, - sizeof(crl_buff) - 1, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_buff) - 1, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerFreeCRL(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); DoExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); + wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0)); + wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0)); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0)); + wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0)); wolfSSL_CertManagerFreeCRL(cm); #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0)); + wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0)); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); + wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, - sizeof_server_cert_der_2048), - WC_NO_ERR_TRACE(CRL_MISSING)); + sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_MISSING)); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, server_cert_der_2048, - sizeof_server_cert_der_2048, - WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(CRL_MISSING)); + sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1), + WC_NO_ERR_TRACE(CRL_MISSING)); #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, sizeof(crl_buff), - WOLFSSL_FILETYPE_ASN1), 1); + WOLFSSL_FILETYPE_ASN1), 1); #if !defined(NO_FILESYSTEM) && defined(WC_RSA_PSS) /* loading should fail without the CA set */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss, - WOLFSSL_FILETYPE_PEM), - WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E)); + WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E)); /* now successfully load the RSA-PSS crl once loading in it's CA */ ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL)); + wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL)); ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); #endif wolfSSL_CertManagerFree(cm); @@ -2705,14 +2529,12 @@ int test_wolfSSL_CRL_reason_extensions_cleanup(void) ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, ca_cert_der_2048, - sizeof_ca_cert_der_2048, - WOLFSSL_FILETYPE_ASN1), + sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* Exercises ParseCRL/GetRevoked path that allocates entry extensions; * cleanup runs via FreeDecodedCRL in BufferLoadCRL. */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crlReasonFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); } #endif @@ -2812,22 +2634,19 @@ int test_wolfSSL_CRL_static_revoked_list(void) /* Set up CertManager with the CA and CRL checking enabled */ ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, "./certs/ca-cert.pem", NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Load the CRL that revokes serials {05, 02, 01} in unsorted wire order */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_multi_revoked, - sizeof(crl_multi_revoked), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_multi_revoked), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* server-cert.pem has serial 01, which is in the CRL but at the last * position in the unsorted array. Binary search on unsorted data misses * it, so this assertion fails before the bug fix. */ ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, - sizeof_server_cert_der_2048), - WC_NO_ERR_TRACE(CRL_CERT_REVOKED)); + sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_CERT_REVOKED)); wolfSSL_CertManagerFree(cm); #endif @@ -2857,16 +2676,16 @@ int test_wolfSSL_CRL_static_revoked_list_dup(void) ExpectNotNull(crl != NULL ? crl->crlList : NULL); ExpectIntGT((crl != NULL && crl->crlList != NULL) ? - crl->crlList->totalCerts : 0, 0); + crl->crlList->totalCerts : 0, 0); ExpectNotNull((crl != NULL && crl->crlList != NULL) ? - crl->crlList->certs[0].extensions : NULL); + crl->crlList->certs[0].extensions : NULL); ExpectNotNull(dupl = wolfSSL_X509_CRL_dup(crl)); /* Every duplicated revoked cert must own its own copy of the extensions. * A shallow copy shares the pointer, a dropped copy leaves it NULL. */ if (crl != NULL && dupl != NULL && crl->crlList != NULL && - dupl->crlList != NULL) { + dupl->crlList != NULL) { int i; for (i = 0; i < crl->crlList->totalCerts; i++) { const RevokedCert* o = &crl->crlList->certs[i]; @@ -3113,24 +2932,18 @@ int test_wolfSSL_CRL_critical_idp(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, ca_cert_idp, - sizeof(ca_cert_idp), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(ca_cert_idp), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* User-scope CRL has a critical IDP extension, must be rejected */ ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_user_idp, - sizeof(crl_user_idp), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_user_idp), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); /* CA-only CRL also has a critical IDP extension, must be rejected */ ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_caonly_idp, - sizeof(crl_caonly_idp), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_caonly_idp), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); #endif @@ -3594,9 +3407,7 @@ int test_wolfSSL_cert_critical_policy_constraints(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntNE(wolfSSL_CertManagerLoadCABuffer(cm, cert_crit_policy, - sizeof(cert_crit_policy), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(cert_crit_policy), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); #endif return EXPECT_RESULT(); @@ -3606,124 +3417,124 @@ int test_wolfSSL_cert_critical_policy_constraints(void) /* claim-root CA, DER. Shared by the unknown-critical-CRL-extension tests * below. */ static const unsigned char crl_unk_ca_der[] = { - 0x30, 0x82, 0x03, 0x1b, 0x30, 0x82, 0x02, 0x03, 0xa0, 0x03, 0x02, - 0x01, 0x02, 0x02, 0x14, 0x1e, 0x25, 0xc1, 0x5d, 0x6f, 0x02, 0x21, - 0xa0, 0xf0, 0x14, 0x15, 0x9c, 0x3b, 0x4d, 0x1d, 0x73, 0x16, 0x00, - 0xe4, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, - 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, - 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, - 0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x1e, 0x17, 0x0d, - 0x32, 0x36, 0x30, 0x34, 0x31, 0x36, 0x31, 0x31, 0x33, 0x38, 0x35, - 0x35, 0x5a, 0x17, 0x0d, 0x33, 0x36, 0x30, 0x34, 0x31, 0x33, 0x31, - 0x31, 0x33, 0x38, 0x35, 0x35, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30, - 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, - 0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x82, 0x01, 0x22, - 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, - 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, - 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xba, 0x49, 0x8c, 0xb5, - 0x17, 0xc1, 0x01, 0x24, 0x6f, 0x56, 0x1a, 0xa9, 0x3b, 0x03, 0xe2, - 0x9f, 0x24, 0xb1, 0x25, 0x98, 0xfb, 0x38, 0x82, 0x78, 0x54, 0xa7, - 0x1f, 0x69, 0x87, 0xe4, 0x96, 0x1b, 0x81, 0x18, 0x10, 0xb0, 0xc0, - 0x5b, 0x4b, 0xbf, 0xb8, 0x1d, 0xf4, 0xee, 0x75, 0x0f, 0xb5, 0x45, - 0x72, 0x70, 0xce, 0x65, 0x84, 0x44, 0x3e, 0x30, 0x78, 0xc4, 0xf3, - 0xec, 0xba, 0x96, 0x78, 0xa4, 0x65, 0xfc, 0x62, 0x8d, 0xf5, 0x29, - 0xf9, 0x7c, 0x3d, 0x78, 0x6c, 0x1d, 0x4a, 0x4c, 0xc9, 0x15, 0x2d, - 0x22, 0x10, 0xea, 0x93, 0x26, 0xb8, 0xa6, 0x17, 0xd3, 0x0e, 0xbc, - 0x0c, 0xab, 0x83, 0x63, 0xf6, 0x1c, 0xcc, 0x83, 0x73, 0x29, 0x7e, - 0x7f, 0x83, 0x7f, 0xbd, 0x63, 0xaa, 0x8d, 0xfa, 0x78, 0x85, 0xd2, - 0x3e, 0x60, 0x95, 0x5a, 0x8d, 0xfa, 0x8f, 0xcd, 0x94, 0x3f, 0x13, - 0x28, 0xd9, 0xd0, 0x87, 0x28, 0x17, 0x78, 0xe2, 0x61, 0x8d, 0x79, - 0x97, 0x01, 0xa9, 0x7c, 0x84, 0xc0, 0x1c, 0xbe, 0x5f, 0x5d, 0xca, - 0x28, 0x6b, 0x5e, 0xdd, 0x83, 0xa5, 0x55, 0x34, 0x11, 0xba, 0xfa, - 0x8b, 0x92, 0xa3, 0xde, 0xb6, 0xf3, 0xba, 0xab, 0x7f, 0x1a, 0x67, - 0xfd, 0x6f, 0x20, 0x85, 0x4c, 0x77, 0xa7, 0x8e, 0xbe, 0xb8, 0xf8, - 0x8f, 0x70, 0xe3, 0x5a, 0xd3, 0x77, 0xc9, 0x9e, 0x10, 0x60, 0xb4, - 0xdb, 0x0c, 0xc5, 0x05, 0xe1, 0x1f, 0xbd, 0xe6, 0x79, 0xee, 0x82, - 0x3f, 0x51, 0x76, 0xe2, 0x7f, 0x5c, 0x11, 0x6d, 0xd3, 0x21, 0x69, - 0xec, 0x05, 0x11, 0x8b, 0xc8, 0x39, 0xb3, 0x2c, 0xa6, 0x83, 0xb4, - 0x6f, 0xac, 0x19, 0xd6, 0x6a, 0x65, 0x0d, 0x08, 0x94, 0x58, 0xde, - 0x3d, 0xc9, 0x0c, 0x54, 0x03, 0x73, 0x0c, 0x8d, 0x24, 0x09, 0xf3, - 0xb1, 0x5d, 0xd2, 0xe3, 0xeb, 0x56, 0xd6, 0x28, 0x66, 0x5b, 0x02, - 0x03, 0x01, 0x00, 0x01, 0xa3, 0x63, 0x30, 0x61, 0x30, 0x0f, 0x06, - 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, - 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, - 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, - 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x52, 0x97, 0x58, - 0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, - 0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x1f, 0x06, 0x03, 0x55, - 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x52, 0x97, 0x58, - 0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, - 0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x0d, 0x06, 0x09, 0x2a, - 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, - 0x82, 0x01, 0x01, 0x00, 0x7d, 0x30, 0xd4, 0x6a, 0x01, 0x89, 0x3b, - 0x62, 0xed, 0x16, 0x46, 0x59, 0x0f, 0xf2, 0x3b, 0xb5, 0xde, 0x89, - 0x08, 0x17, 0x68, 0xcb, 0x46, 0xdc, 0x39, 0xa6, 0xcb, 0x56, 0xb0, - 0x91, 0xeb, 0x03, 0xb2, 0x15, 0xc4, 0x3b, 0x4d, 0x63, 0x55, 0x22, - 0x0a, 0x26, 0xe6, 0x64, 0x46, 0xe8, 0x0f, 0xa8, 0xf3, 0xde, 0xe1, - 0x43, 0x54, 0xe6, 0xd7, 0x8a, 0xf4, 0x4f, 0xab, 0x56, 0x93, 0x12, - 0x71, 0x4b, 0x25, 0x71, 0x0a, 0x31, 0x18, 0x79, 0xee, 0x45, 0xa4, - 0xf5, 0x72, 0x67, 0xfa, 0x41, 0xd9, 0x87, 0x97, 0x09, 0xef, 0x55, - 0xad, 0x6f, 0x47, 0x1d, 0x5a, 0xb2, 0xe9, 0xf7, 0x22, 0x05, 0x2d, - 0x5a, 0x81, 0xa8, 0xe8, 0x53, 0xb0, 0x94, 0xf6, 0x63, 0xff, 0x3f, - 0x51, 0x7a, 0x08, 0xac, 0x27, 0x9a, 0x57, 0x11, 0x22, 0xa4, 0x00, - 0x84, 0x70, 0x86, 0x76, 0x39, 0x0f, 0x4f, 0x57, 0xcf, 0x8e, 0x94, - 0xd2, 0x8e, 0x43, 0xc0, 0xd5, 0x34, 0x7d, 0xf5, 0xa1, 0x45, 0x1e, - 0xb7, 0xc8, 0x7e, 0x7c, 0xfe, 0x5d, 0x4d, 0x53, 0x43, 0x25, 0x15, - 0x9e, 0x08, 0x01, 0x56, 0xa4, 0xff, 0x79, 0x59, 0x25, 0xc9, 0x23, - 0x98, 0xaf, 0x05, 0xaf, 0xc1, 0x0b, 0x29, 0xf1, 0xe2, 0xc4, 0x36, - 0x31, 0x91, 0xfa, 0xf2, 0xbb, 0x12, 0xe8, 0x67, 0xf9, 0xc7, 0xa1, - 0x5e, 0x8c, 0xed, 0x92, 0x12, 0xa3, 0x2b, 0xe1, 0xc2, 0xe1, 0xa0, - 0xb0, 0x0e, 0x12, 0xa7, 0xd0, 0xa2, 0xae, 0xd6, 0xfa, 0x30, 0x21, - 0x0f, 0x73, 0xfe, 0x24, 0x21, 0x5f, 0x03, 0x86, 0x69, 0xcd, 0xec, - 0x76, 0x18, 0xe1, 0xfd, 0xb6, 0x64, 0x90, 0xa6, 0x06, 0x2e, 0x19, - 0x40, 0x93, 0x50, 0x37, 0xe4, 0x90, 0xe3, 0x1f, 0x07, 0xae, 0xfb, - 0x89, 0xc3, 0xf6, 0xc4, 0x90, 0xab, 0x40, 0x67, 0x4c, 0x43, 0x2c, - 0xa2, 0xb0, 0x3e, 0x61, 0x16, 0x69, 0x8f -}; + 0x30, 0x82, 0x03, 0x1b, 0x30, 0x82, 0x02, 0x03, 0xa0, 0x03, 0x02, + 0x01, 0x02, 0x02, 0x14, 0x1e, 0x25, 0xc1, 0x5d, 0x6f, 0x02, 0x21, + 0xa0, 0xf0, 0x14, 0x15, 0x9c, 0x3b, 0x4d, 0x1d, 0x73, 0x16, 0x00, + 0xe4, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, + 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, + 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, + 0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x1e, 0x17, 0x0d, + 0x32, 0x36, 0x30, 0x34, 0x31, 0x36, 0x31, 0x31, 0x33, 0x38, 0x35, + 0x35, 0x5a, 0x17, 0x0d, 0x33, 0x36, 0x30, 0x34, 0x31, 0x33, 0x31, + 0x31, 0x33, 0x38, 0x35, 0x35, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30, + 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, + 0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x82, 0x01, 0x22, + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, + 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, + 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xba, 0x49, 0x8c, 0xb5, + 0x17, 0xc1, 0x01, 0x24, 0x6f, 0x56, 0x1a, 0xa9, 0x3b, 0x03, 0xe2, + 0x9f, 0x24, 0xb1, 0x25, 0x98, 0xfb, 0x38, 0x82, 0x78, 0x54, 0xa7, + 0x1f, 0x69, 0x87, 0xe4, 0x96, 0x1b, 0x81, 0x18, 0x10, 0xb0, 0xc0, + 0x5b, 0x4b, 0xbf, 0xb8, 0x1d, 0xf4, 0xee, 0x75, 0x0f, 0xb5, 0x45, + 0x72, 0x70, 0xce, 0x65, 0x84, 0x44, 0x3e, 0x30, 0x78, 0xc4, 0xf3, + 0xec, 0xba, 0x96, 0x78, 0xa4, 0x65, 0xfc, 0x62, 0x8d, 0xf5, 0x29, + 0xf9, 0x7c, 0x3d, 0x78, 0x6c, 0x1d, 0x4a, 0x4c, 0xc9, 0x15, 0x2d, + 0x22, 0x10, 0xea, 0x93, 0x26, 0xb8, 0xa6, 0x17, 0xd3, 0x0e, 0xbc, + 0x0c, 0xab, 0x83, 0x63, 0xf6, 0x1c, 0xcc, 0x83, 0x73, 0x29, 0x7e, + 0x7f, 0x83, 0x7f, 0xbd, 0x63, 0xaa, 0x8d, 0xfa, 0x78, 0x85, 0xd2, + 0x3e, 0x60, 0x95, 0x5a, 0x8d, 0xfa, 0x8f, 0xcd, 0x94, 0x3f, 0x13, + 0x28, 0xd9, 0xd0, 0x87, 0x28, 0x17, 0x78, 0xe2, 0x61, 0x8d, 0x79, + 0x97, 0x01, 0xa9, 0x7c, 0x84, 0xc0, 0x1c, 0xbe, 0x5f, 0x5d, 0xca, + 0x28, 0x6b, 0x5e, 0xdd, 0x83, 0xa5, 0x55, 0x34, 0x11, 0xba, 0xfa, + 0x8b, 0x92, 0xa3, 0xde, 0xb6, 0xf3, 0xba, 0xab, 0x7f, 0x1a, 0x67, + 0xfd, 0x6f, 0x20, 0x85, 0x4c, 0x77, 0xa7, 0x8e, 0xbe, 0xb8, 0xf8, + 0x8f, 0x70, 0xe3, 0x5a, 0xd3, 0x77, 0xc9, 0x9e, 0x10, 0x60, 0xb4, + 0xdb, 0x0c, 0xc5, 0x05, 0xe1, 0x1f, 0xbd, 0xe6, 0x79, 0xee, 0x82, + 0x3f, 0x51, 0x76, 0xe2, 0x7f, 0x5c, 0x11, 0x6d, 0xd3, 0x21, 0x69, + 0xec, 0x05, 0x11, 0x8b, 0xc8, 0x39, 0xb3, 0x2c, 0xa6, 0x83, 0xb4, + 0x6f, 0xac, 0x19, 0xd6, 0x6a, 0x65, 0x0d, 0x08, 0x94, 0x58, 0xde, + 0x3d, 0xc9, 0x0c, 0x54, 0x03, 0x73, 0x0c, 0x8d, 0x24, 0x09, 0xf3, + 0xb1, 0x5d, 0xd2, 0xe3, 0xeb, 0x56, 0xd6, 0x28, 0x66, 0x5b, 0x02, + 0x03, 0x01, 0x00, 0x01, 0xa3, 0x63, 0x30, 0x61, 0x30, 0x0f, 0x06, + 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, + 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, + 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, + 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x52, 0x97, 0x58, + 0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, + 0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x1f, 0x06, 0x03, 0x55, + 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x52, 0x97, 0x58, + 0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, + 0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, + 0x82, 0x01, 0x01, 0x00, 0x7d, 0x30, 0xd4, 0x6a, 0x01, 0x89, 0x3b, + 0x62, 0xed, 0x16, 0x46, 0x59, 0x0f, 0xf2, 0x3b, 0xb5, 0xde, 0x89, + 0x08, 0x17, 0x68, 0xcb, 0x46, 0xdc, 0x39, 0xa6, 0xcb, 0x56, 0xb0, + 0x91, 0xeb, 0x03, 0xb2, 0x15, 0xc4, 0x3b, 0x4d, 0x63, 0x55, 0x22, + 0x0a, 0x26, 0xe6, 0x64, 0x46, 0xe8, 0x0f, 0xa8, 0xf3, 0xde, 0xe1, + 0x43, 0x54, 0xe6, 0xd7, 0x8a, 0xf4, 0x4f, 0xab, 0x56, 0x93, 0x12, + 0x71, 0x4b, 0x25, 0x71, 0x0a, 0x31, 0x18, 0x79, 0xee, 0x45, 0xa4, + 0xf5, 0x72, 0x67, 0xfa, 0x41, 0xd9, 0x87, 0x97, 0x09, 0xef, 0x55, + 0xad, 0x6f, 0x47, 0x1d, 0x5a, 0xb2, 0xe9, 0xf7, 0x22, 0x05, 0x2d, + 0x5a, 0x81, 0xa8, 0xe8, 0x53, 0xb0, 0x94, 0xf6, 0x63, 0xff, 0x3f, + 0x51, 0x7a, 0x08, 0xac, 0x27, 0x9a, 0x57, 0x11, 0x22, 0xa4, 0x00, + 0x84, 0x70, 0x86, 0x76, 0x39, 0x0f, 0x4f, 0x57, 0xcf, 0x8e, 0x94, + 0xd2, 0x8e, 0x43, 0xc0, 0xd5, 0x34, 0x7d, 0xf5, 0xa1, 0x45, 0x1e, + 0xb7, 0xc8, 0x7e, 0x7c, 0xfe, 0x5d, 0x4d, 0x53, 0x43, 0x25, 0x15, + 0x9e, 0x08, 0x01, 0x56, 0xa4, 0xff, 0x79, 0x59, 0x25, 0xc9, 0x23, + 0x98, 0xaf, 0x05, 0xaf, 0xc1, 0x0b, 0x29, 0xf1, 0xe2, 0xc4, 0x36, + 0x31, 0x91, 0xfa, 0xf2, 0xbb, 0x12, 0xe8, 0x67, 0xf9, 0xc7, 0xa1, + 0x5e, 0x8c, 0xed, 0x92, 0x12, 0xa3, 0x2b, 0xe1, 0xc2, 0xe1, 0xa0, + 0xb0, 0x0e, 0x12, 0xa7, 0xd0, 0xa2, 0xae, 0xd6, 0xfa, 0x30, 0x21, + 0x0f, 0x73, 0xfe, 0x24, 0x21, 0x5f, 0x03, 0x86, 0x69, 0xcd, 0xec, + 0x76, 0x18, 0xe1, 0xfd, 0xb6, 0x64, 0x90, 0xa6, 0x06, 0x2e, 0x19, + 0x40, 0x93, 0x50, 0x37, 0xe4, 0x90, 0xe3, 0x1f, 0x07, 0xae, 0xfb, + 0x89, 0xc3, 0xf6, 0xc4, 0x90, 0xab, 0x40, 0x67, 0x4c, 0x43, 0x2c, + 0xa2, 0xb0, 0x3e, 0x61, 0x16, 0x69, 0x8f + }; /* CRL with a critical obsolete CRL-level extension OID 2.5.29.1, 422 bytes * DER. OID 2.5.29.1 is the old X.509v2 Authority Key Identifier, permanently * superseded by 2.5.29.35. No implementation will ever support it. */ static const unsigned char crl_obsolete_critical[] = { - 0x30, 0x82, 0x01, 0xa6, 0x30, 0x81, 0x8f, 0x02, 0x01, 0x01, 0x30, - 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, - 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, - 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x2d, - 0x72, 0x6f, 0x6f, 0x74, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x34, 0x31, - 0x36, 0x31, 0x35, 0x32, 0x31, 0x30, 0x37, 0x5a, 0x17, 0x0d, 0x33, - 0x36, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35, 0x32, 0x31, 0x30, 0x37, - 0x5a, 0xa0, 0x46, 0x30, 0x44, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, - 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x52, 0x97, 0x58, 0x47, - 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, 0xea, - 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x14, 0x06, 0x03, 0x55, 0x1d, - 0x01, 0x01, 0x01, 0xff, 0x04, 0x0a, 0x0c, 0x08, 0x6f, 0x62, 0x73, - 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, - 0x14, 0x04, 0x04, 0x02, 0x02, 0x20, 0x02, 0x30, 0x0d, 0x06, 0x09, - 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, - 0x03, 0x82, 0x01, 0x01, 0x00, 0x05, 0xf3, 0x8f, 0xdb, 0x7f, 0x75, - 0x2c, 0x34, 0x4b, 0x7e, 0x70, 0x17, 0x5e, 0x34, 0xc6, 0xdb, 0xcb, - 0x54, 0x33, 0x06, 0x58, 0x6d, 0xae, 0x9c, 0xc8, 0xe3, 0xaf, 0x82, - 0xe5, 0xf6, 0x86, 0x42, 0xb3, 0x01, 0x72, 0x1a, 0xca, 0xf9, 0x10, - 0x5d, 0x14, 0xe6, 0x84, 0x34, 0x56, 0x55, 0x74, 0xb5, 0x06, 0x64, - 0x49, 0x1d, 0xb3, 0xb0, 0x13, 0xff, 0x1c, 0x05, 0x4f, 0x43, 0x29, - 0xbc, 0xfe, 0xb5, 0x92, 0x54, 0xf6, 0x9b, 0x81, 0x07, 0x5e, 0x2e, - 0x75, 0xd8, 0xfd, 0x9b, 0x5b, 0xc9, 0xd3, 0xc2, 0x15, 0xa7, 0x6e, - 0x2f, 0x4b, 0x3a, 0x27, 0x57, 0xef, 0x40, 0x61, 0x8c, 0x11, 0x9d, - 0x0a, 0xb1, 0x2b, 0x0e, 0xed, 0x5d, 0xf2, 0xf5, 0x1a, 0xce, 0xdc, - 0xd7, 0x75, 0xc6, 0x25, 0x22, 0xe4, 0x70, 0xad, 0x93, 0xff, 0x36, - 0xa1, 0xa2, 0xa0, 0xd9, 0x82, 0x23, 0x6e, 0xc8, 0x3a, 0x80, 0x82, - 0xbf, 0x12, 0xac, 0xa1, 0xf9, 0x03, 0x9c, 0xb9, 0x20, 0x91, 0x33, - 0x80, 0x7b, 0xb7, 0x6e, 0xa5, 0x32, 0x98, 0xd6, 0x2c, 0x5d, 0x9d, - 0x3b, 0x64, 0x3b, 0xb4, 0xea, 0x03, 0x2d, 0x65, 0xcf, 0x7f, 0x0f, - 0x97, 0xef, 0x5b, 0x17, 0x8c, 0xcf, 0x98, 0x69, 0xba, 0x2d, 0x62, - 0xe9, 0x40, 0xe2, 0x3d, 0xbd, 0xd2, 0x0f, 0x4a, 0xf8, 0xb0, 0xa7, - 0xdb, 0x80, 0xa3, 0x47, 0x56, 0xe5, 0xe6, 0x6f, 0x93, 0x5c, 0x6f, - 0xdd, 0x62, 0x43, 0x28, 0x5c, 0xe5, 0x8f, 0x0e, 0x11, 0xa6, 0x1f, - 0x61, 0xaf, 0x39, 0x15, 0x40, 0xf4, 0x6e, 0x79, 0x40, 0xf6, 0x28, - 0xf3, 0xd4, 0x30, 0x3b, 0x25, 0xb6, 0xf0, 0x4a, 0x51, 0xc3, 0x18, - 0xff, 0xad, 0x4d, 0x6e, 0x10, 0x73, 0x68, 0xfa, 0x54, 0x9e, 0xdc, - 0x34, 0x70, 0xe4, 0x5d, 0x9e, 0x7c, 0xfa, 0x59, 0x97, 0xde, 0x35, - 0x17, 0xbb, 0xaf, 0xa0, 0x28, 0x78, 0x13, 0xbf + 0x30, 0x82, 0x01, 0xa6, 0x30, 0x81, 0x8f, 0x02, 0x01, 0x01, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, + 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, + 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x2d, + 0x72, 0x6f, 0x6f, 0x74, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x34, 0x31, + 0x36, 0x31, 0x35, 0x32, 0x31, 0x30, 0x37, 0x5a, 0x17, 0x0d, 0x33, + 0x36, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35, 0x32, 0x31, 0x30, 0x37, + 0x5a, 0xa0, 0x46, 0x30, 0x44, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, + 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x52, 0x97, 0x58, 0x47, + 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e, 0xea, + 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x14, 0x06, 0x03, 0x55, 0x1d, + 0x01, 0x01, 0x01, 0xff, 0x04, 0x0a, 0x0c, 0x08, 0x6f, 0x62, 0x73, + 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, + 0x14, 0x04, 0x04, 0x02, 0x02, 0x20, 0x02, 0x30, 0x0d, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, + 0x03, 0x82, 0x01, 0x01, 0x00, 0x05, 0xf3, 0x8f, 0xdb, 0x7f, 0x75, + 0x2c, 0x34, 0x4b, 0x7e, 0x70, 0x17, 0x5e, 0x34, 0xc6, 0xdb, 0xcb, + 0x54, 0x33, 0x06, 0x58, 0x6d, 0xae, 0x9c, 0xc8, 0xe3, 0xaf, 0x82, + 0xe5, 0xf6, 0x86, 0x42, 0xb3, 0x01, 0x72, 0x1a, 0xca, 0xf9, 0x10, + 0x5d, 0x14, 0xe6, 0x84, 0x34, 0x56, 0x55, 0x74, 0xb5, 0x06, 0x64, + 0x49, 0x1d, 0xb3, 0xb0, 0x13, 0xff, 0x1c, 0x05, 0x4f, 0x43, 0x29, + 0xbc, 0xfe, 0xb5, 0x92, 0x54, 0xf6, 0x9b, 0x81, 0x07, 0x5e, 0x2e, + 0x75, 0xd8, 0xfd, 0x9b, 0x5b, 0xc9, 0xd3, 0xc2, 0x15, 0xa7, 0x6e, + 0x2f, 0x4b, 0x3a, 0x27, 0x57, 0xef, 0x40, 0x61, 0x8c, 0x11, 0x9d, + 0x0a, 0xb1, 0x2b, 0x0e, 0xed, 0x5d, 0xf2, 0xf5, 0x1a, 0xce, 0xdc, + 0xd7, 0x75, 0xc6, 0x25, 0x22, 0xe4, 0x70, 0xad, 0x93, 0xff, 0x36, + 0xa1, 0xa2, 0xa0, 0xd9, 0x82, 0x23, 0x6e, 0xc8, 0x3a, 0x80, 0x82, + 0xbf, 0x12, 0xac, 0xa1, 0xf9, 0x03, 0x9c, 0xb9, 0x20, 0x91, 0x33, + 0x80, 0x7b, 0xb7, 0x6e, 0xa5, 0x32, 0x98, 0xd6, 0x2c, 0x5d, 0x9d, + 0x3b, 0x64, 0x3b, 0xb4, 0xea, 0x03, 0x2d, 0x65, 0xcf, 0x7f, 0x0f, + 0x97, 0xef, 0x5b, 0x17, 0x8c, 0xcf, 0x98, 0x69, 0xba, 0x2d, 0x62, + 0xe9, 0x40, 0xe2, 0x3d, 0xbd, 0xd2, 0x0f, 0x4a, 0xf8, 0xb0, 0xa7, + 0xdb, 0x80, 0xa3, 0x47, 0x56, 0xe5, 0xe6, 0x6f, 0x93, 0x5c, 0x6f, + 0xdd, 0x62, 0x43, 0x28, 0x5c, 0xe5, 0x8f, 0x0e, 0x11, 0xa6, 0x1f, + 0x61, 0xaf, 0x39, 0x15, 0x40, 0xf4, 0x6e, 0x79, 0x40, 0xf6, 0x28, + 0xf3, 0xd4, 0x30, 0x3b, 0x25, 0xb6, 0xf0, 0x4a, 0x51, 0xc3, 0x18, + 0xff, 0xad, 0x4d, 0x6e, 0x10, 0x73, 0x68, 0xfa, 0x54, 0x9e, 0xdc, + 0x34, 0x70, 0xe4, 0x5d, 0x9e, 0x7c, 0xfa, 0x59, 0x97, 0xde, 0x35, + 0x17, 0xbb, 0xaf, 0xa0, 0x28, 0x78, 0x13, 0xbf }; #endif /* !NO_CERTS && HAVE_CRL && !NO_RSA */ @@ -3735,16 +3546,13 @@ int test_wolfSSL_CRL_unknown_critical_ext(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); #endif @@ -3760,18 +3568,16 @@ int test_wolfSSL_CRL_unknown_critical_entry_ext(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, - "./certs/crl/extra-crls/claim-root.pem", - NULL), WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/claim-root.pem", NULL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* CRL with a revoked entry that carries a critical unknown extension * (OID 2.5.29.1, old X.509v2 AKI, permanently superseded). * Per RFC 5280 Section 5.3, the CRL must not be used. */ ExpectIntNE(wolfSSL_CertManagerLoadCRLFile(cm, - "./certs/crl/extra-crls/crl_critical_entry.pem", - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/crl_critical_entry.pem", WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); wolfSSL_CertManagerFree(cm); #endif @@ -3782,16 +3588,15 @@ int test_wolfSSL_CRL_unknown_critical_entry_ext(void) !defined(NO_FILESYSTEM) && defined(WC_ASN_UNKNOWN_EXT_CB) /* Counter context plus the OID we observed on the unknown extension. */ typedef struct CRLUnkExtCtx { - int calls; - int sawCritical; - int oidMatched; + int calls; + int sawCritical; + int oidMatched; } CRLUnkExtCtx; /* CRL Reason OID 2.5.29.21 (last component for the entry-ext test) and * obsolete X.509v2 AKI 2.5.29.1 (last component for the CRL-level test). */ static int crl_unk_ext_cb_accept(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, word32 - derSz, void* ctxIn) + int crit, const unsigned char* der, word32 derSz, void* ctxIn) { CRLUnkExtCtx* ctx = (CRLUnkExtCtx*)ctxIn; (void)der; @@ -3808,8 +3613,7 @@ static int crl_unk_ext_cb_accept(const word16* oid, word32 oidSz, } static int crl_unk_ext_cb_reject(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, word32 - derSz, void* ctxIn) + int crit, const unsigned char* der, word32 derSz, void* ctxIn) { (void)oid; (void)oidSz; (void)crit; (void)der; (void)derSz; if (ctxIn != NULL) @@ -3818,8 +3622,7 @@ static int crl_unk_ext_cb_reject(const word16* oid, word32 oidSz, } static int crl_unk_ext_cb_reject_positive(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, - word32 derSz, void* ctxIn) + int crit, const unsigned char* der, word32 derSz, void* ctxIn) { (void)oid; (void)oidSz; (void)crit; (void)der; (void)derSz; if (ctxIn != NULL) @@ -3836,8 +3639,7 @@ static int crl_unk_ext_noctx_sawCritical; static int crl_unk_ext_noctx_oidMatched; static int crl_unk_ext_cb_noctx_accept(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, - word32 derSz) + int crit, const unsigned char* der, word32 derSz) { (void)der; (void)derSz; @@ -3851,8 +3653,7 @@ static int crl_unk_ext_cb_noctx_accept(const word16* oid, word32 oidSz, } static int crl_unk_ext_cb_noctx_reject(const word16* oid, word32 oidSz, - int crit, const unsigned char* der, - word32 derSz) + int crit, const unsigned char* der, word32 derSz) { (void)oid; (void)oidSz; (void)crit; (void)der; (void)derSz; crl_unk_ext_noctx_calls++; @@ -3869,28 +3670,24 @@ int test_wolfSSL_CRL_unknown_ext_cb_rescues_critical_entry_ext(void) #if !defined(NO_CERTS) && defined(HAVE_CRL) && !defined(NO_RSA) && \ !defined(NO_FILESYSTEM) && defined(WC_ASN_UNKNOWN_EXT_CB) WOLFSSL_CERT_MANAGER* cm = NULL; - CRLUnkExtCtx ctx = {0, 0, 0}; + CRLUnkExtCtx ctx = { 0, 0, 0 }; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, - "./certs/crl/extra-crls/claim-root.pem", - NULL), WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/claim-root.pem", NULL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Register a callback that accepts any unknown extension. */ ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(cm, - crl_unk_ext_cb_accept, - &ctx), - WOLFSSL_SUCCESS); + crl_unk_ext_cb_accept, &ctx), WOLFSSL_SUCCESS); /* Without the callback, this load fails (see * test_wolfSSL_CRL_unknown_critical_entry_ext above). With an * accepting callback registered, the load must succeed. */ ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, - "./certs/crl/extra-crls/crl_critical_entry.pem", - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/crl_critical_entry.pem", WOLFSSL_FILETYPE_PEM), + WOLFSSL_SUCCESS); /* Callback must have fired at least once on the unknown critical OID. */ ExpectIntGT(ctx.calls, 0); @@ -3913,25 +3710,20 @@ int test_wolfSSL_CRL_unknown_ext_cb_rescues_critical_crl_ext(void) #if !defined(NO_CERTS) && defined(HAVE_CRL) && !defined(NO_RSA) && \ !defined(NO_FILESYSTEM) && defined(WC_ASN_UNKNOWN_EXT_CB) WOLFSSL_CERT_MANAGER* cm = NULL; - CRLUnkExtCtx ctx = {0, 0, 0}; + CRLUnkExtCtx ctx = { 0, 0, 0 }; /* Accepting callback: the load must succeed and the callback must have * seen the critical unknown OID. */ ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(cm, - crl_unk_ext_cb_accept, - &ctx), - WOLFSSL_SUCCESS); + crl_unk_ext_cb_accept, &ctx), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntGT(ctx.calls, 0); ExpectIntEQ(ctx.sawCritical, 1); ExpectIntEQ(ctx.oidMatched, 1); @@ -3942,19 +3734,14 @@ int test_wolfSSL_CRL_unknown_ext_cb_rescues_critical_crl_ext(void) ctx.calls = 0; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(cm, - crl_unk_ext_cb_reject, - &ctx), - WOLFSSL_SUCCESS); + crl_unk_ext_cb_reject, &ctx), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntGT(ctx.calls, 0); wolfSSL_CertManagerFree(cm); @@ -3973,24 +3760,20 @@ int test_wolfSSL_CRL_unknown_ext_cb_positive_return_fails_load(void) #if !defined(NO_CERTS) && defined(HAVE_CRL) && !defined(NO_RSA) && \ !defined(NO_FILESYSTEM) && defined(WC_ASN_UNKNOWN_EXT_CB) WOLFSSL_CERT_MANAGER* cm = NULL; - CRLUnkExtCtx ctx = {0, 0, 0}; + CRLUnkExtCtx ctx = { 0, 0, 0 }; int rc; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, - "./certs/crl/extra-crls/claim-root.pem", - NULL), WOLFSSL_SUCCESS); + "./certs/crl/extra-crls/claim-root.pem", NULL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(cm, - crl_unk_ext_cb_reject_positive, - &ctx), - WOLFSSL_SUCCESS); + crl_unk_ext_cb_reject_positive, &ctx), WOLFSSL_SUCCESS); rc = wolfSSL_CertManagerLoadCRLFile(cm, - "./certs/crl/extra-crls/crl_critical_entry.pem", - WOLFSSL_FILETYPE_PEM); + "./certs/crl/extra-crls/crl_critical_entry.pem", WOLFSSL_FILETYPE_PEM); ExpectIntNE(rc, WOLFSSL_SUCCESS); ExpectIntLT(rc, 0); ExpectIntGT(ctx.calls, 0); @@ -4014,12 +3797,9 @@ int test_wolfSSL_CRL_unknown_ext_cb_noctx(void) /* A NULL cert manager is rejected by both registration entry points. */ ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallback(NULL, - crl_unk_ext_cb_noctx_accept), - BAD_FUNC_ARG); + crl_unk_ext_cb_noctx_accept), BAD_FUNC_ARG); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallbackEx(NULL, - crl_unk_ext_cb_accept, - NULL), - BAD_FUNC_ARG); + crl_unk_ext_cb_accept, NULL), BAD_FUNC_ARG); /* Accepting callback: the critical unknown CRL-level extension in the * crl_obsolete_critical fixture is rescued and the load succeeds. The @@ -4029,18 +3809,14 @@ int test_wolfSSL_CRL_unknown_ext_cb_noctx(void) crl_unk_ext_noctx_oidMatched = 0; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallback(cm, - crl_unk_ext_cb_noctx_accept), - WOLFSSL_SUCCESS); + crl_unk_ext_cb_noctx_accept), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntGT(crl_unk_ext_noctx_calls, 0); ExpectIntEQ(crl_unk_ext_noctx_sawCritical, 1); ExpectIntEQ(crl_unk_ext_noctx_oidMatched, 1); @@ -4051,18 +3827,14 @@ int test_wolfSSL_CRL_unknown_ext_cb_noctx(void) crl_unk_ext_noctx_calls = 0; ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, crl_unk_ca_der, - sizeof(crl_unk_ca_der), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_unk_ca_der), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerSetCRLUnknownExtCallback(cm, - crl_unk_ext_cb_noctx_reject), - WOLFSSL_SUCCESS); + crl_unk_ext_cb_noctx_reject), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_obsolete_critical, - sizeof(crl_obsolete_critical), - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + sizeof(crl_obsolete_critical), WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntGT(crl_unk_ext_noctx_calls, 0); wolfSSL_CertManagerFree(cm); @@ -4293,32 +4065,26 @@ int test_wolfSSL_CertManagerCheckOCSPResponse(void) ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL)); ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, - "./certs/ocsp/intermediate1-ca-cert.pem", - NULL), WOLFSSL_SUCCESS); + "./certs/ocsp/intermediate1-ca-cert.pem", NULL), WOLFSSL_SUCCESS); /* Response should be valid. */ ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response, - sizeof(response), NULL, - status, entry, request), - WOLFSSL_SUCCESS); + sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS); /* Flip a byte in the request serial number, response should be invalid * now. */ if ((request != NULL) && (request->serial != NULL)) request->serial[0] ^= 0xFF; ExpectIntNE(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response, - sizeof(response), NULL, - status, entry, request), - WOLFSSL_SUCCESS); + sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS); #ifndef NO_FILESYSTEM ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048, - sizeof(server_cert_der_2048)), - WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + sizeof(server_cert_der_2048)), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); + wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL)); ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048, - sizeof(server_cert_der_2048)), 1); + sizeof(server_cert_der_2048)), 1); #endif wolfSSL_OCSP_REQUEST_free(request); @@ -4340,7 +4106,7 @@ static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA) if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) { fprintf(stderr, "loading cert %s failed\n", certA); fprintf(stderr, "Error: (%d): %s\n", ret, - wolfSSL_ERR_reason_error_string((word32)ret)); + wolfSSL_ERR_reason_error_string((word32)ret)); return -1; } @@ -4351,34 +4117,35 @@ static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA) { int ret; if ((ret = wolfSSL_CertManagerVerify(cm, certA, CERT_FILETYPE)) - != WOLFSSL_SUCCESS) { + != WOLFSSL_SUCCESS) { fprintf(stderr, "could not verify the cert: %s\n", certA); fprintf(stderr, "Error: (%d): %s\n", ret, - wolfSSL_ERR_reason_error_string((word32)ret)); + wolfSSL_ERR_reason_error_string((word32)ret)); return -1; - } else { + } + else { fprintf(stderr, "successfully verified: %s\n", certA); } return 0; } #define LOAD_ONE_CA(a, b, c, d) \ - do { \ - (a) = load_ca_into_cm(c, d); \ - if ((a) != 0) \ - return (b); \ - else \ - (b) --; \ - } while(0) + do { \ + (a) = load_ca_into_cm(c, d); \ + if ((a) != 0) \ + return (b); \ + else \ + (b)--; \ + } while(0) #define VERIFY_ONE_CERT(a, b, c, d) \ - do { \ - (a) = verify_cert_with_cm(c, d); \ - if ((a) != 0) \ - return (b); \ - else \ - (b) --; \ - } while(0) + do { \ + (a) = verify_cert_with_cm(c, d);\ + if ((a) != 0) \ + return (b); \ + else \ + (b)--; \ + } while(0) static int test_chainG(WOLFSSL_CERT_MANAGER* cm) { @@ -4590,30 +4357,28 @@ int test_wolfSSL_CertManagerRejectMD5Cert(void) !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_ASN_CRYPT) && \ !defined(USE_CERT_BUFFERS_1024) && !defined(NO_ASN_TIME) WOLFSSL_CERT_MANAGER* cm = NULL; - RsaKey caKey; - WC_RNG rng; - Cert leaf; + RsaKey caKey; + WC_RNG rng; + Cert leaf; byte* der = NULL; - int derSz = 0; - word32 idx = 0; - int caKeyInit = 0; - int rngInit = 0; + int derSz = 0; + word32 idx = 0; + int caKeyInit = 0; + int rngInit = 0; XMEMSET(&caKey, 0, sizeof(caKey)); XMEMSET(&rng, 0, sizeof(rng)); ExpectIntEQ(wc_InitRng(&rng), 0); - if (EXPECT_SUCCESS()) - rngInit = 1; + if (EXPECT_SUCCESS()) rngInit = 1; ExpectIntEQ(wc_InitRsaKey_ex(&caKey, HEAP_HINT, testDevId), 0); - if (EXPECT_SUCCESS()) - caKeyInit = 1; + if (EXPECT_SUCCESS()) caKeyInit = 1; ExpectIntEQ(wc_RsaPrivateKeyDecode(ca_key_der_2048, &idx, &caKey, - sizeof_ca_key_der_2048), 0); + sizeof_ca_key_der_2048), 0); ExpectNotNull(der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); if (der == NULL) { goto cleanup; } @@ -4633,14 +4398,14 @@ int test_wolfSSL_CertManagerRejectMD5Cert(void) XSTRNCPY(leaf.subject.email, "facts@wolfssl.com", CTC_NAME_SIZE); ExpectIntEQ(wc_SetIssuerBuffer(&leaf, ca_cert_der_2048, - sizeof_ca_cert_der_2048), 0); + sizeof_ca_cert_der_2048), 0); /* wc_MakeCert needs an RSA public key for the subject; reuse caKey * for simplicity (we only care about signature-side verification). */ ExpectIntGT((derSz = wc_MakeCert(&leaf, der, FOURK_BUF, &caKey, NULL, - &rng)), 0); + &rng)), 0); ExpectIntGT((derSz = wc_SignCert(leaf.bodySz, leaf.sigType, der, - FOURK_BUF, &caKey, NULL, &rng)), 0); + FOURK_BUF, &caKey, NULL, &rng)), 0); /* Load the SHA-256 signed CA cert as a trust anchor and attempt * to verify the MD5-signed leaf: it must be rejected because @@ -4649,22 +4414,19 @@ int test_wolfSSL_CertManagerRejectMD5Cert(void) ExpectNotNull(cm = wolfSSL_CertManagerNew()); if (cm != NULL) { ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, ca_cert_der_2048, - sizeof_ca_cert_der_2048, - WOLFSSL_FILETYPE_ASN1), + sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz, - WOLFSSL_FILETYPE_ASN1), + WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(HASH_TYPE_E)); } cleanup: wolfSSL_CertManagerFree(cm); XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (caKeyInit) - wc_FreeRsaKey(&caKey); - if (rngInit) - wc_FreeRng(&rng); + if (caKeyInit) wc_FreeRsaKey(&caKey); + if (rngInit) wc_FreeRng(&rng); #endif return EXPECT_RESULT(); } @@ -4692,14 +4454,14 @@ int test_wolfSSL_CertManagerRejectRPK(void) /* No trust anchor loaded. */ ExpectIntEQ(wolfSSL_CertManagerVerify(cm, rpkCert, WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); /* The CA that issued the X.509 form of the same key. */ ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, caCert, NULL), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, svrCert, WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, rpkCert, WOLFSSL_FILETYPE_ASN1), - WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); wolfSSL_CertManagerFree(cm); #endif @@ -4713,11 +4475,11 @@ int test_wolfSSL_X509_V_ERR_strings(void) defined(OPENSSL_EXTRA_X509_SMALL) || \ defined(HAVE_WEBSERVER) || defined(HAVE_MEMCACHED)) ExpectStrEQ(wolfSSL_ERR_reason_error_string( - WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD), - "format error in certificate's notBefore field"); + WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD), + "format error in certificate's notBefore field"); ExpectStrEQ(wolfSSL_ERR_reason_error_string( - WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD), - "format error in certificate's notAfter field"); + WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD), + "format error in certificate's notAfter field"); #endif return EXPECT_RESULT(); } @@ -4755,12 +4517,12 @@ int test_wolfSSL_CertManagerNameConstraint_valid_chain(void) /* Positive: leaf satisfies the grandparent permit. */ ExpectIntEQ(wolfSSL_CertManagerVerify(cm, valid_leaf_cert, - WOLFSSL_FILETYPE_PEM), + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); /* Negative: leaf violates the grandparent permit. */ ExpectIntEQ(wolfSSL_CertManagerVerify(cm, attacker_leaf_chain, - WOLFSSL_FILETYPE_PEM), + WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); @@ -4804,23 +4566,21 @@ int test_wolfSSL_CertManagerNameConstraint_skid_disambiguates(void) WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CertManagerVerify(cm, attacker_leaf_chain, - WOLFSSL_FILETYPE_PEM), + WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); wolfSSL_CertManagerFree(cm); #endif return EXPECT_RESULT(); } - -/* Decision-coverage drivers for the ssl_certman.c argument guards left - * unpaired by the functional tests. The cert-manager helpers are - * WOLFSSL_LOCAL, so this white-box test calls them directly. Each block - * names the source line:condition it closes. */ int test_certman_decision_coverage(void) { EXPECT_DECLS; -#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS \ - ) + /* Refs WOLFSSL_LOCAL certman fns, hidden from the .so - shared builds + * compile this out; WOLFSSL_TEST_STATIC_BUILD is set for static-only + * builds (configure) and by the MC/DC variant. */ +#if defined(WOLFSSL_TEST_STATIC_BUILD) && !defined(WOLFCRYPT_ONLY) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) WOLFSSL_CTX* ctx = NULL; WOLFSSL_CERT_MANAGER* cm = NULL; byte hash[SIGNER_DIGEST_SIZE]; diff --git a/tests/api/test_session.c b/tests/api/test_session.c index ffa6d60064a..a2479ffdc7d 100644 --- a/tests/api/test_session.c +++ b/tests/api/test_session.c @@ -3225,7 +3225,13 @@ int test_wolfSSL_session_cache_restore(void) int test_session_decision_coverage(void) { EXPECT_DECLS; -#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) + /* Refs session fns whose definitions need OPENSSL_EXTRA/HAVE_EXT_CACHE + * and are hidden from the .so - shared builds compile this out; + * WOLFSSL_TEST_STATIC_BUILD is set for static-only builds (configure) + * and by the MC/DC variant. */ +#if defined(WOLFSSL_TEST_STATIC_BUILD) && !defined(NO_SESSION_CACHE) && \ + (defined(OPENSSL_EXTRA) || defined(HAVE_EXT_CACHE)) && \ + !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; WOLFSSL_SESSION* sess = NULL; diff --git a/tests/api/test_ssl_cert.c b/tests/api/test_ssl_cert.c index 4d9977de35c..76e6637398b 100644 --- a/tests/api/test_ssl_cert.c +++ b/tests/api/test_ssl_cert.c @@ -52,7 +52,7 @@ int test_wolfSSL_get_verify_mode(void) { EXPECT_DECLS; #if (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || defined(HAVE_STUNNEL) || \ - defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX)) && \ + defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX)) && \ !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; @@ -70,15 +70,15 @@ int test_wolfSSL_get_verify_mode(void) ExpectIntEQ(wolfSSL_get_verify_mode(ssl), WOLFSSL_VERIFY_PEER); wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); ExpectIntEQ(wolfSSL_get_verify_mode(ssl), - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT); + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT); /* Exercise the fail-except-PSK option. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); mode = wolfSSL_get_verify_mode(ssl); ExpectIntEQ(mode & WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK); + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -94,7 +94,7 @@ int test_wolfSSL_CTX_get_verify_mode(void) { EXPECT_DECLS; #if (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || defined(HAVE_STUNNEL) || \ - defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX)) && \ + defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX)) && \ !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; int mode; @@ -107,22 +107,22 @@ int test_wolfSSL_CTX_get_verify_mode(void) ExpectIntEQ(wolfSSL_CTX_get_verify_mode(ctx), WOLFSSL_VERIFY_NONE); wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); ExpectIntEQ(wolfSSL_CTX_get_verify_mode(ctx), - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT); + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT); wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); mode = wolfSSL_CTX_get_verify_mode(ctx); ExpectIntEQ(mode & WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK); + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK); #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH) /* Exercise the post-handshake auth option. */ wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); mode = wolfSSL_CTX_get_verify_mode(ctx); ExpectIntEQ(mode & WOLFSSL_VERIFY_POST_HANDSHAKE, - WOLFSSL_VERIFY_POST_HANDSHAKE); + WOLFSSL_VERIFY_POST_HANDSHAKE); #endif wolfSSL_CTX_free(ctx); @@ -182,7 +182,7 @@ int test_wolfSSL_CTX_get_extra_chain_certs(void) { EXPECT_DECLS; #if (defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ - defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \ + defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \ !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \ !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \ defined(WOLFSSL_PEM_TO_DER) @@ -203,7 +203,7 @@ int test_wolfSSL_CTX_get_extra_chain_certs(void) ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); /* server-cert.pem holds a 2-cert chain, so the CA goes into certChain. */ ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx, svrCertFile), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Builds a stack of X509 from the stored chain. */ sk = NULL; @@ -222,16 +222,15 @@ int test_wolfSSL_CTX_get_extra_chain_certs(void) * node, building a multi-element stack. */ ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx, - "certs/intermediate/server-chain.pem"), - WOLFSSL_SUCCESS); + "certs/intermediate/server-chain.pem"), WOLFSSL_SUCCESS); sk = NULL; ExpectIntEQ(wolfSSL_CTX_get_extra_chain_certs(ctx, &sk), WOLFSSL_SUCCESS); ExpectNotNull(sk); ExpectIntGE(wolfSSL_sk_X509_num(sk), 2); #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || \ - defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX) || \ - defined(WOLFSSL_QT)) && !defined(NO_WOLFSSL_STUB) + defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX) || \ + defined(WOLFSSL_QT)) && !defined(NO_WOLFSSL_STUB) /* Stub: returns via the control command. */ wolfSSL_CTX_clear_extra_chain_certs(ctx); #endif @@ -258,7 +257,7 @@ int test_wolfSSL_get_peer_chain(void) struct test_memio_ctx test_ctx; WOLFSSL_X509_CHAIN* chain = NULL; #if (defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ - defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && defined(KEEP_OUR_CERT) + defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && defined(KEEP_OUR_CERT) WOLF_STACK_OF(WOLFSSL_X509)* osk = NULL; #endif @@ -270,8 +269,7 @@ int test_wolfSSL_get_peer_chain(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); /* The client now holds the server's certificate chain. */ @@ -286,7 +284,7 @@ int test_wolfSSL_get_peer_chain(void) #endif #if (defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ - defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && defined(KEEP_OUR_CERT) + defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && defined(KEEP_OUR_CERT) ExpectIntEQ(wolfSSL_get0_chain_certs(NULL, &osk), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_get0_chain_certs(ssl_c, &osk), WOLFSSL_SUCCESS); #endif @@ -318,8 +316,7 @@ int test_wolfSSL_get_chain_X509(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectNotNull(chain = wolfSSL_get_peer_chain(ssl_c)); @@ -365,8 +362,7 @@ int test_wolfSSL_get_chain_cert_pem(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectNotNull(chain = wolfSSL_get_peer_chain(ssl_c)); @@ -374,50 +370,46 @@ int test_wolfSSL_get_chain_cert_pem(void) /* Successful PEM conversion. */ pemSz = (int)sizeof(pem); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, (int)sizeof(pem), - &pemSz), WOLFSSL_SUCCESS); + &pemSz), WOLFSSL_SUCCESS); ExpectIntGT(pemSz, 0); /* Argument validation. */ pemSz = (int)sizeof(pem); ExpectIntEQ(wolfSSL_get_chain_cert_pem(NULL, 0, pem, (int)sizeof(pem), - &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG - )); + &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, -1, pem, (int)sizeof(pem), - &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG - )); + &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 99, pem, (int)sizeof(pem), - &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG - )); + &pemSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, (int)sizeof(pem), - NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)) - ; + NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* NULL buffer returns the size needed (length-only query). */ needed = 0; /* A negative buffer length is rejected. */ ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, -1, &pemSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, NULL, 0, &needed), - WC_NO_ERR_TRACE(LENGTH_ONLY_E)); + WC_NO_ERR_TRACE(LENGTH_ONLY_E)); ExpectIntGT(needed, 0); ExpectIntLE(needed, (int)sizeof(pem)); /* A buffer shorter than the DER certificate fails up front. */ pemSz = (int)sizeof(pem); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, 1, &pemSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* One byte short of the full size leaves no room for the footer. */ pemSz = (int)sizeof(pem); ExpectIntEQ(wolfSSL_get_chain_cert_pem(chain, 0, pem, needed - 1, &pemSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Room for the DER length but not the base64-expanded body: the encoder * reports an error (negative return). */ chainLen = wolfSSL_get_chain_length(chain, 0); pemSz = (int)sizeof(pem); ExpectIntLT(wolfSSL_get_chain_cert_pem(chain, 0, pem, chainLen + 100, - &pemSz), 0); + &pemSz), 0); wolfSSL_free(ssl_s); wolfSSL_free(ssl_c); @@ -447,8 +439,7 @@ int test_wolfSSL_cmp_peer_cert_to_file(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); /* Should fail gracefully before handshake. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, svrCertFile), @@ -459,22 +450,21 @@ int test_wolfSSL_cmp_peer_cert_to_file(void) /* NULL arguments report failure. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(NULL, svrCertFile), - WOLFSSL_FATAL_ERROR); + WOLFSSL_FATAL_ERROR); ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, NULL), - WOLFSSL_FATAL_ERROR); + WOLFSSL_FATAL_ERROR); /* The peer (server) certificate matches the file it was loaded from. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, svrCertFile), 0); /* A different certificate does not match. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, caCertFile), - WOLFSSL_FATAL_ERROR); + WOLFSSL_FATAL_ERROR); /* A missing file reports a file error. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, - "certs/does-not-exist.pem"), - WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE)); + "certs/does-not-exist.pem"), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE)); /* A readable file that is not PEM-encoded fails conversion. */ ExpectIntEQ(wolfSSL_cmp_peer_cert_to_file(ssl_c, cliCertDerFile), - WOLFSSL_FATAL_ERROR); + WOLFSSL_FATAL_ERROR); wolfSSL_free(ssl_s); wolfSSL_free(ssl_c); @@ -497,7 +487,7 @@ int test_wolfSSL_cmp_peer_cert_to_file(void) * @return 0 to indicate no certificate was supplied. */ static int test_ssl_cert_client_cert_cb(WOLFSSL* ssl, WOLFSSL_X509** x509, - WOLFSSL_EVP_PKEY** pkey) + WOLFSSL_EVP_PKEY** pkey) { (void)ssl; (void)x509; @@ -617,10 +607,10 @@ int test_wolfSSL_cert_setup_cb_ret(void) int cbRet; int err; } cases[] = { - {1, 0}, - {0, WC_NO_ERR_TRACE(CLIENT_CERT_CB_ERROR)}, - {-1, -1}, - {2, WC_NO_ERR_TRACE(CLIENT_CERT_CB_ERROR)} + { 1, 0 }, + { 0, WC_NO_ERR_TRACE(CLIENT_CERT_CB_ERROR) }, + { -1, -1 }, + { 2, WC_NO_ERR_TRACE(CLIENT_CERT_CB_ERROR) } }; int i; @@ -633,8 +623,7 @@ int test_wolfSSL_cert_setup_cb_ret(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); test_ssl_cert_setup_ret = cases[i].cbRet; test_ssl_cert_setup_calls = 0; @@ -642,17 +631,19 @@ int test_wolfSSL_cert_setup_cb_ret(void) if (cases[i].err == 0) { ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - } else { + } + else { /* Drive one step at a time so the error the server reports is the * one the callback caused, not a later I/O failure. */ ExpectIntEQ(wolfSSL_connect(ssl_c), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectIntEQ(wolfSSL_get_error(ssl_c, 0), WOLFSSL_ERROR_WANT_READ); ExpectIntEQ(wolfSSL_accept(ssl_s), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); if (cases[i].err != -1) { ExpectIntEQ(wolfSSL_get_error(ssl_s, 0), cases[i].err); - } else { + } + else { ExpectIntNE(wolfSSL_get_error(ssl_s, 0), 0); } } @@ -688,8 +679,7 @@ int test_wolfSSL_get_peer_cert_chain(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); /* Nothing has been received yet, so there is no chain to build. */ ExpectNull(wolfSSL_get_peer_cert_chain(ssl_c)); @@ -731,8 +721,7 @@ int test_wolfSSL_set_peer_cert_chain(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); /* An empty session chain has nothing to build from. */ ExpectNull(wolfSSL_set_peer_cert_chain(ssl_c)); @@ -743,13 +732,11 @@ int test_wolfSSL_set_peer_cert_chain(void) * client's Certificate message, so there is nothing to ask for. */ #ifndef WOLFSSL_NO_CLIENT_AUTH ExpectIntEQ(wolfSSL_use_certificate_file(ssl_c, cliCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_c, cliKeyFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, cliCertFile, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, NULL); #endif @@ -809,8 +796,7 @@ int test_wolfSSL_get0_verified_chain(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); /* Without a peer certificate there is nothing to verify. */ ExpectNull(wolfSSL_get0_verified_chain(ssl_c)); @@ -858,7 +844,7 @@ int test_wolfSSL_CA_list_add(void) WOLFSSL_X509* x509 = NULL; ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); /* Both arguments are required. */ ExpectIntEQ(wolfSSL_CTX_add_client_CA(NULL, x509), 0); @@ -868,11 +854,9 @@ int test_wolfSSL_CA_list_add(void) ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_CTX_add_client_CA(ctx, NULL), 0); @@ -891,10 +875,10 @@ int test_wolfSSL_CA_list_add(void) ExpectNull(wolfSSL_CTX_get_client_CA_list(ctx)); ExpectIntEQ(wolfSSL_CTX_add_client_CA(ctx, x509), 1); ExpectIntEQ(wolfSSL_sk_X509_NAME_num( - wolfSSL_CTX_get_client_CA_list(ctx)), 1); + wolfSSL_CTX_get_client_CA_list(ctx)), 1); ExpectIntEQ(wolfSSL_CTX_add_client_CA(ctx, x509), 1); ExpectIntEQ(wolfSSL_sk_X509_NAME_num( - wolfSSL_CTX_get_client_CA_list(ctx)), 2); + wolfSSL_CTX_get_client_CA_list(ctx)), 2); ExpectNull(wolfSSL_get0_CA_list(ssl)); ExpectIntEQ(wolfSSL_add1_to_CA_list(ssl, x509), 1); @@ -941,16 +925,14 @@ int test_wolfSSL_CA_list_get(void) ExpectNull(wolfSSL_get0_peer_CA_list(NULL)); ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile, - WOLFSSL_FILETYPE_PEM)); + WOLFSSL_FILETYPE_PEM)); /* Server side: the client CA names are the object's own list. */ ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* Nothing added yet. */ @@ -1026,7 +1008,7 @@ int test_wolfSSL_mutual_auth(void) WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_CTX_mutual_auth(NULL, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_mutual_auth(NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Mutual authentication is a server-only setting. */ @@ -1041,11 +1023,9 @@ int test_wolfSSL_mutual_auth(void) ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_CTX_mutual_auth(ctx, 1), 0); @@ -1091,11 +1071,9 @@ int test_wolfSSL_post_handshake_auth(void) /* A server cannot request it of itself. */ ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_CTX_set_post_handshake_auth(ctx, 1), 0); ExpectIntEQ(wolfSSL_set_post_handshake_auth(ssl, 1), 0); @@ -1146,13 +1124,11 @@ int test_wolfSSL_verify_cert_store(void) ExpectIntEQ(wolfSSL_X509_STORE_up_ref(NULL), 0); /* Setting the store already in use is accepted and changes nothing, both - * for the context and for an object handed the store the context owns. */ + * for the context and for an object handed the store the context owns. */ ExpectIntEQ(wolfSSL_CTX_set1_verify_cert_store(ctx, - wolfSSL_CTX_get_cert_store( - ctx)), 1); + wolfSSL_CTX_get_cert_store(ctx)), 1); ExpectIntEQ(wolfSSL_set1_verify_cert_store(ssl, - wolfSSL_CTX_get_cert_store(ctx)), - 1); + wolfSSL_CTX_get_cert_store(ctx)), 1); /* A different store is taken with a reference. */ ExpectNotNull(store = wolfSSL_X509_STORE_new()); @@ -1185,8 +1161,7 @@ int test_wolfSSL_verify_cert_store(void) * and releasing it here would leave ctx->x509_store_pt pointing at memory * freed a second time by wolfSSL_CTX_free(). */ ExpectIntEQ(wolfSSL_set0_verify_cert_store(ssl, - wolfSSL_CTX_get_cert_store(ctx)), - 1); + wolfSSL_CTX_get_cert_store(ctx)), 1); ExpectPtrEq(wolfSSL_CTX_get_cert_store(ctx), store); /* Still alive and still the context's, so a reference can be taken. */ ExpectIntEQ(wolfSSL_X509_STORE_up_ref(store), 1); @@ -1197,8 +1172,7 @@ int test_wolfSSL_verify_cert_store(void) * This is the shape that freed the context's store: an object with no * store of its own, handed the context's with set0. */ ExpectIntEQ(wolfSSL_set0_verify_cert_store(ssl, - wolfSSL_CTX_get_cert_store(ctx)), - 1); + wolfSSL_CTX_get_cert_store(ctx)), 1); ExpectPtrEq(wolfSSL_CTX_get_cert_store(ctx), store); ExpectIntEQ(wolfSSL_X509_STORE_up_ref(store), 1); wolfSSL_X509_STORE_free(store); @@ -1209,8 +1183,8 @@ int test_wolfSSL_verify_cert_store(void) ExpectPtrEq(wolfSSL_CTX_get_cert_store(ctx), store); /* Give the object a store of its own again and clear it: the object - * releases its reference and reverts to the context's store. The store - * itself is still alive, so a reference can still be taken on it. */ + * releases its reference and reverts to the context's store. The store + * itself is still alive, so a reference can still be taken on it. */ ExpectIntEQ(wolfSSL_set1_verify_cert_store(ssl, store2), 1); ExpectIntEQ(wolfSSL_set1_verify_cert_store(ssl, NULL), 1); ExpectIntEQ(wolfSSL_X509_STORE_up_ref(store2), 1); @@ -1270,8 +1244,8 @@ int test_wolfSSL_verify_cert_store_follows_ctx(void) WOLFSSL_X509_STORE* withCa = NULL; WOLFSSL_X509_STORE* withCa2 = NULL; /* Two CRLs from the same CA. A manager keeps the CRLs tried against it, - * whether or not they verified, so no manager below is asked for the same - * CRL twice - a second attempt would find the cached one and succeed. */ + * whether or not they verified, so no manager below is asked for the same + * CRL twice - a second attempt would find the cached one and succeed. */ const char* crlPem = "./certs/crl/crl.pem"; const char* crlPem2 = "./certs/crl/crl.revoked"; @@ -1284,13 +1258,12 @@ int test_wolfSSL_verify_cert_store_follows_ctx(void) ExpectNotNull(withCa2 = wolfSSL_X509_STORE_new()); ExpectIntEQ(wolfSSL_X509_STORE_load_locations(withCa, caCertFile, NULL), 1); ExpectIntEQ(wolfSSL_X509_STORE_load_locations(withCa2, caCertFile, NULL), - 1); + 1); /* Hand the object the store the context is using while that is the store * the context owns: no pointer to it is kept either. */ ExpectIntEQ(wolfSSL_set1_verify_cert_store(ssl, - wolfSSL_CTX_get_cert_store(ctx)), - 1); + wolfSSL_CTX_get_cert_store(ctx)), 1); /* So the object follows the context onto a store that has the CA. Were * the context's own store pinned to the object instead, the manager in * use would still be the context's, which has no CA. */ @@ -1467,11 +1440,9 @@ int test_wolfSSL_get_certificate_api(void) ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The object borrows the context's certificate. */ @@ -1479,8 +1450,7 @@ int test_wolfSSL_get_certificate_api(void) /* Loading a certificate onto the object makes it own one instead. */ ExpectIntEQ(wolfSSL_use_certificate_file(ssl, svrCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectNotNull(wolfSSL_get_certificate(ssl)); /* Asked again the cached object is returned. */ ExpectNotNull(wolfSSL_get_certificate(ssl)); @@ -1512,24 +1482,22 @@ int test_wolfSSL_cert_unload(void) #endif #ifdef PERSIST_CERT_CACHE ExpectIntEQ(wolfSSL_CTX_get_cert_cache_memsize(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif /* A NULL object reports a bad argument rather than a depth. */ ExpectIntEQ(wolfSSL_CTX_get_verify_depth(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_verify_depth(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The loaded CAs can be released without freeing the context. */ @@ -1541,7 +1509,7 @@ int test_wolfSSL_cert_unload(void) ExpectIntEQ(wolfSSL_UnloadCertsKeys(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_UnloadIntermediateCerts(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1550,24 +1518,24 @@ int test_wolfSSL_cert_unload(void) } /* --------------------------------------------------------------------------- -* Argument guards across the newly-visible public API surface. -* -* src/ssl_api_cert.c, ssl_api_crl_ocsp.c and their siblings are #included into -* ssl.c rather than compiled standalone, so they produced no object file and -* no module declared them until this part of the campaign. Now that they are -* measured, the shape of what is missing is unambiguous: 342 of the 646 -* uncovered conditions across these files mention NULL, and in the densest of -* them it is 85-100%. -* -* They are not protocol behaviour. They are the checks each entry point makes -* on its own arguments, and the existing tests all pass arguments that are -* valid -- so every one of these decisions is taken the same way on every -* call, and none of the operands has an independence pair. -* -* A caller that queries or configures a CTX or an SSL it has not created yet, -* or passes a zero length, or asks for an output through a NULL pointer, is -* doing something ordinary and wrong. That is what these vectors are. -* ------------------------------------------------------------------------- */ + * Argument guards across the newly-visible public API surface. + * + * src/ssl_api_cert.c, ssl_api_crl_ocsp.c and their siblings are #included into + * ssl.c rather than compiled standalone, so they produced no object file and + * no module declared them until this part of the campaign. Now that they are + * measured, the shape of what is missing is unambiguous: 342 of the 646 + * uncovered conditions across these files mention NULL, and in the densest of + * them it is 85-100%. + * + * They are not protocol behaviour. They are the checks each entry point makes + * on its own arguments, and the existing tests all pass arguments that are + * valid -- so every one of these decisions is taken the same way on every + * call, and none of the operands has an independence pair. + * + * A caller that queries or configures a CTX or an SSL it has not created yet, + * or passes a zero length, or asks for an output through a NULL pointer, is + * doing something ordinary and wrong. That is what these vectors are. + * ------------------------------------------------------------------------- */ int test_wolfSSL_cert_api_arg_guards(void) { EXPECT_DECLS; @@ -1576,7 +1544,7 @@ int test_wolfSSL_cert_api_arg_guards(void) WOLFSSL* ssl = NULL; #ifdef HAVE_RPK int tp = 0; - const char certTypes[] = {WOLFSSL_CERT_TYPE_X509}; + const char certTypes[] = { WOLFSSL_CERT_TYPE_X509 }; unsigned char spki[8]; XMEMSET(spki, 0, sizeof(spki)); @@ -1791,39 +1759,39 @@ static int test_verify_mode_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) static const VerifyModeCase verifyModeCases[] = { /* VERIFY_NONE is the only mode that sets verifyNone. */ - {"NONE", WOLFSSL_VERIFY_NONE, 1, 0, 0, 0}, - {"PEER", WOLFSSL_VERIFY_PEER, 0, 1, 0, 0}, - {"PEER|FAIL_IF_NO_PEER_CERT", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, - 0, 1, 1, 0}, - {"PEER|FAIL_EXCEPT_PSK", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - 0, 1, 0, 1}, + { "NONE", WOLFSSL_VERIFY_NONE, 1, 0, 0, 0 }, + { "PEER", WOLFSSL_VERIFY_PEER, 0, 1, 0, 0 }, + { "PEER|FAIL_IF_NO_PEER_CERT", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, + 0, 1, 1, 0 }, + { "PEER|FAIL_EXCEPT_PSK", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, + 0, 1, 0, 1 }, /* The two fail-on-no-cert flags are independent bits and may both be * recorded; the PSK exception is applied first at the handshake. */ - {"PEER|FAIL_IF_NO_PEER_CERT|FAIL_EXCEPT_PSK", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - 0, 1, 1, 1}, + { "PEER|FAIL_IF_NO_PEER_CERT|FAIL_EXCEPT_PSK", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, + 0, 1, 1, 1 }, /* FAIL_IF_NO_PEER_CERT on its own is recorded even though a server that * never requests a certificate cannot act on it. */ - {"FAIL_IF_NO_PEER_CERT", WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, - 0, 0, 1, 0}, + { "FAIL_IF_NO_PEER_CERT", WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, + 0, 0, 1, 0 }, /* VERIFY_DEFAULT clears every option instead of setting one. That is * why it does not round-trip through get_verify_mode(). */ - {"DEFAULT", WOLFSSL_VERIFY_DEFAULT, 0, 0, 0, 0}, + { "DEFAULT", WOLFSSL_VERIFY_DEFAULT, 0, 0, 0, 0 }, /* VERIFY_NONE is matched by equality, not as a bit: OR-ing anything else * in means the peer IS verified. */ - {"NONE|PEER", WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_PEER, 0, 1, 0, 0}, + { "NONE|PEER", WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_PEER, 0, 1, 0, 0 }, /* CLIENT_ONCE is accepted and ignored: on its own it leaves every option * clear, and it never disturbs the flags it is OR-ed with. */ - {"CLIENT_ONCE", WOLFSSL_VERIFY_CLIENT_ONCE, 0, 0, 0, 0}, - {"PEER|CLIENT_ONCE", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_CLIENT_ONCE, 0, 1, 0, 0}, - {"PEER|FAIL_IF_NO_PEER_CERT|CLIENT_ONCE", - WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | - WOLFSSL_VERIFY_CLIENT_ONCE, - 0, 1, 1, 0} + { "CLIENT_ONCE", WOLFSSL_VERIFY_CLIENT_ONCE, 0, 0, 0, 0 }, + { "PEER|CLIENT_ONCE", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_CLIENT_ONCE, 0, 1, 0, 0 }, + { "PEER|FAIL_IF_NO_PEER_CERT|CLIENT_ONCE", + WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | + WOLFSSL_VERIFY_CLIENT_ONCE, + 0, 1, 1, 0 } }; #endif /* !NO_CERTS && !NO_TLS && !NO_WOLFSSL_CLIENT */ @@ -1874,11 +1842,11 @@ int test_wolfSSL_verify_mode_options(void) #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH) /* Post-handshake auth is an ordinary bit alongside the others. */ wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); ExpectIntEQ(ctx->verifyPeer, 1); ExpectIntEQ(ctx->verifyPostHandshake, 1); wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.verifyPostHandshake, 1); @@ -1890,14 +1858,14 @@ int test_wolfSSL_verify_mode_options(void) /* So does CLIENT_ONCE on its own, which is to say it selects nothing. */ wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_CLIENT_ONCE, NULL); ExpectIntEQ(ctx->verifyPostHandshake, 0); #endif /* Setting a mode replaces the previous one rather than accumulating. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER, NULL); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.failNoCert, 0); @@ -1939,15 +1907,14 @@ int test_wolfSSL_verify_client_once_ignored(void) /* Adding CLIENT_ONCE to a mode leaves that mode's options untouched. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.failNoCert, 1); ExpectIntEQ(ssl->options.verifyNone, 0); wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | - WOLFSSL_VERIFY_CLIENT_ONCE, - NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | WOLFSSL_VERIFY_CLIENT_ONCE, + NULL); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.failNoCert, 1); ExpectIntEQ(ssl->options.verifyNone, 0); @@ -1963,7 +1930,7 @@ int test_wolfSSL_verify_client_once_ignored(void) /* CLIENT_ONCE does not turn VERIFY_NONE into something else either: * VERIFY_NONE is matched by equality, so the pair verifies the peer. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_CLIENT_ONCE, - NULL); + NULL); ExpectIntEQ(ssl->options.verifyNone, 0); #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \ @@ -1971,11 +1938,11 @@ int test_wolfSSL_verify_client_once_ignored(void) defined(WOLFSSL_NGINX) /* The bit is never reported back, on the object or on the context. */ wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_CLIENT_ONCE, - NULL); + NULL); ExpectIntEQ(wolfSSL_get_verify_mode(ssl), WOLFSSL_VERIFY_PEER); wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_CLIENT_ONCE, NULL); + WOLFSSL_VERIFY_CLIENT_ONCE, NULL); ExpectIntEQ(wolfSSL_CTX_get_verify_mode(ctx), WOLFSSL_VERIFY_PEER); /* WOLFSSL_VERIFY_DEFAULT does not round-trip either: it clears every @@ -2009,9 +1976,8 @@ int test_wolfSSL_verify_mode_ctx_inherit(void) /* An object created after the context is configured inherits the mode. */ wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, - NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT | WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, + NULL); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(ssl->options.verifyPeer, 1); ExpectIntEQ(ssl->options.failNoCert, 1); @@ -2067,9 +2033,9 @@ int test_wolfSSL_verify_none_accepts_untrusted(void) int mode; int expectFail; } cases[] = { - {"PEER", WOLFSSL_VERIFY_PEER, 1}, - {"NONE", WOLFSSL_VERIFY_NONE, 0}, - {"NONE|PEER", WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_PEER, 1} + { "PEER", WOLFSSL_VERIFY_PEER, 1 }, + { "NONE", WOLFSSL_VERIFY_NONE, 0 }, + { "NONE|PEER", WOLFSSL_VERIFY_NONE | WOLFSSL_VERIFY_PEER, 1 } }; size_t i; @@ -2089,8 +2055,7 @@ int test_wolfSSL_verify_none_accepts_untrusted(void) } ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); wolfSSL_set_verify(ssl_c, cases[i].mode, NULL); @@ -2098,9 +2063,10 @@ int test_wolfSSL_verify_none_accepts_untrusted(void) /* Verifying, with no CA: the chain has no signer. */ ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_error(ssl_c, - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); - } else { + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)); + } + else { /* Not verifying: the same untrusted certificate is accepted. */ ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); } @@ -2155,17 +2121,16 @@ int test_wolfSSL_verify_fail_except_psk(void) /* A PSK suite is the exception: no peer certificate is required. */ XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); wolfSSL_set_psk_client_callback(ssl_c, my_psk_client_cb); wolfSSL_set_psk_server_callback(ssl_s, my_psk_server_cb); ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_VFY_PSK_SUITE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, TEST_VFY_PSK_SUITE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(ssl_s->options.usingPSK_cipher, 1); @@ -2184,16 +2149,15 @@ int test_wolfSSL_verify_fail_except_psk(void) * cert-less client are now rejected. */ XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); + WOLFSSL_VERIFY_FAIL_EXCEPT_PSK, NULL); ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_error(ssl_s, - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WC_NO_ERR_TRACE(NO_PEER_CERT)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WC_NO_ERR_TRACE(NO_PEER_CERT)); wolfSSL_free(ssl_c); wolfSSL_free(ssl_s); @@ -2218,7 +2182,7 @@ int test_wolfSSL_verify_fail_except_psk(void) * @return TEST_SUCCESS on success. */ static int test_vfy_no_client_cert(method_provider method_c, - method_provider method_s, int rounds) + method_provider method_s, int rounds) { EXPECT_DECLS; WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; @@ -2227,17 +2191,17 @@ static int test_vfy_no_client_cert(method_provider method_c, XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - method_c, method_s), 0); + method_c, method_s), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); /* The client has no certificate loaded, so it answers the server's * request with an empty Certificate message. */ ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, rounds, NULL), 0); ExpectIntEQ(wolfSSL_get_error(ssl_s, - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WC_NO_ERR_TRACE(NO_PEER_CERT)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WC_NO_ERR_TRACE(NO_PEER_CERT)); ExpectIntEQ(ssl_s->options.havePeerCert, 0); wolfSSL_free(ssl_c); @@ -2258,7 +2222,7 @@ static int test_vfy_no_client_cert(method_provider method_c, * @return TEST_SUCCESS on success. */ static int test_vfy_none_server_no_request(method_provider method_c, - method_provider method_s, int rounds) + method_provider method_s, int rounds) { EXPECT_DECLS; WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; @@ -2267,7 +2231,7 @@ static int test_vfy_none_server_no_request(method_provider method_c, XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - method_c, method_s), 0); + method_c, method_s), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, NULL); @@ -2275,11 +2239,11 @@ static int test_vfy_none_server_no_request(method_provider method_c, * CERT_FILETYPE tracks the cliCertFile/cliKeyFile paths, which are DER * rather than PEM in a build without WOLFSSL_PEM_TO_DER. */ ExpectIntEQ(wolfSSL_use_certificate_file(ssl_c, cliCertFile, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_c, cliKeyFile, - CERT_FILETYPE), WOLFSSL_SUCCESS); + CERT_FILETYPE), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, cliCertFile, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, rounds, NULL), 0); @@ -2312,33 +2276,28 @@ int test_wolfSSL_verify_no_client_cert(void) #if defined(WOLFSSL_TLS13) /* TLS 1.3: rejected when the server processes the client's Finished. */ ExpectIntEQ(test_vfy_no_client_cert(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, 10), - TEST_SUCCESS); + wolfTLSv1_3_server_method, 10), TEST_SUCCESS); #endif #if !defined(WOLFSSL_NO_TLS12) /* TLS 1.2: rejected on the empty Certificate message. */ ExpectIntEQ(test_vfy_no_client_cert(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, 10), - TEST_SUCCESS); + wolfTLSv1_2_server_method, 10), TEST_SUCCESS); #endif #if !defined(NO_OLD_TLS) /* TLS 1.1: the empty-Certificate check does not apply below TLS 1.2, so * this is rejected later, in DoClientKeyExchange. */ ExpectIntEQ(test_vfy_no_client_cert(wolfTLSv1_1_client_method, - wolfTLSv1_1_server_method, 10), - TEST_SUCCESS); + wolfTLSv1_1_server_method, 10), TEST_SUCCESS); #endif #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) /* DTLS 1.2 over the same TLS 1.2 code path, but across a cookie * exchange and a retransmittable flight. */ ExpectIntEQ(test_vfy_no_client_cert(wolfDTLSv1_2_client_method, - wolfDTLSv1_2_server_method, 20), - TEST_SUCCESS); + wolfDTLSv1_2_server_method, 20), TEST_SUCCESS); #endif #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_TLS13) ExpectIntEQ(test_vfy_no_client_cert(wolfDTLSv1_3_client_method, - wolfDTLSv1_3_server_method, 20), - TEST_SUCCESS); + wolfDTLSv1_3_server_method, 20), TEST_SUCCESS); #endif #endif @@ -2359,18 +2318,15 @@ int test_wolfSSL_verify_none_server_no_request(void) #if defined(WOLFSSL_TLS13) ExpectIntEQ(test_vfy_none_server_no_request(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, 10), - TEST_SUCCESS); + wolfTLSv1_3_server_method, 10), TEST_SUCCESS); #endif #if !defined(WOLFSSL_NO_TLS12) ExpectIntEQ(test_vfy_none_server_no_request(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, 10), - TEST_SUCCESS); + wolfTLSv1_2_server_method, 10), TEST_SUCCESS); #endif #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) ExpectIntEQ(test_vfy_none_server_no_request(wolfDTLSv1_2_client_method, - wolfDTLSv1_2_server_method, 20), - TEST_SUCCESS); + wolfDTLSv1_2_server_method, 20), TEST_SUCCESS); #endif #endif @@ -2398,8 +2354,7 @@ int test_wolfSSL_verify_tls13_failnocert_only(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method), 0); + wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); ExpectIntEQ(ssl_s->options.verifyPeer, 0); @@ -2407,8 +2362,8 @@ int test_wolfSSL_verify_tls13_failnocert_only(void) ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_error(ssl_s, - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WC_NO_ERR_TRACE(NO_PEER_CERT)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WC_NO_ERR_TRACE(NO_PEER_CERT)); /* The client was never asked, so it never sent one. */ ExpectIntEQ(ssl_s->msgsReceived.got_certificate, 0); @@ -2442,23 +2397,24 @@ int test_wolfSSL_verify_tls13_failnocert_only(void) * @return 0 on success, -1 when no such record is present. */ static int test_vfy_replace_record(struct test_memio_ctx* ctx, int client, - byte hsType, const byte* rec, int recSz) + byte hsType, const byte* rec, int recSz) { byte* buff; int* len; int* msgSizes; - int msgCount; - int off = 0; - int target = -1; - int targetSz = 0; - int delta; - int msgOff; - int i; + int msgCount; + int off = 0; + int target = -1; + int targetSz = 0; + int delta; + int msgOff; + int i; if (client) { buff = ctx->c_buff; len = &ctx->c_len; msgSizes = ctx->c_msg_sizes; msgCount = ctx->c_msg_count; - } else { + } + else { buff = ctx->s_buff; len = &ctx->s_len; msgSizes = ctx->s_msg_sizes; msgCount = ctx->s_msg_count; } @@ -2472,7 +2428,7 @@ static int test_vfy_replace_record(struct test_memio_ctx* ctx, int client, break; } if (buff[off] == handshake && recLen > 0 && - buff[off + RECORD_HEADER_SZ] == hsType) { + buff[off + RECORD_HEADER_SZ] == hsType) { target = off; targetSz = RECORD_HEADER_SZ + recLen; break; @@ -2489,7 +2445,7 @@ static int test_vfy_replace_record(struct test_memio_ctx* ctx, int client, } XMEMMOVE(buff + target + recSz, buff + target + targetSz, - (size_t)(*len - target - targetSz)); + (size_t)(*len - target - targetSz)); XMEMCPY(buff + target, rec, (size_t)recSz); *len += delta; @@ -2537,27 +2493,26 @@ int test_wolfSSL_verify_empty_server_cert(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_PEER, NULL); /* Client sends its hello. */ ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_FATAL_ERROR); ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR), - WOLFSSL_ERROR_WANT_READ); + WOLFSSL_ERROR_WANT_READ); /* Server replies with its flight, still in the clear. */ ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_FATAL_ERROR); ExpectIntEQ(wolfSSL_get_error(ssl_s, WOLFSSL_FATAL_ERROR), - WOLFSSL_ERROR_WANT_READ); + WOLFSSL_ERROR_WANT_READ); /* Swap the server's Certificate for one carrying no certificates. */ ExpectIntEQ(test_vfy_replace_record(&test_ctx, 1, certificate, - emptyCert, (int)sizeof(emptyCert)), 0); + emptyCert, (int)sizeof(emptyCert)), 0); ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_FATAL_ERROR); ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR), - WC_NO_ERR_TRACE(NO_PEER_CERT)); + WC_NO_ERR_TRACE(NO_PEER_CERT)); ExpectIntEQ(ssl_c->options.havePeerCert, 0); wolfSSL_free(ssl_c); @@ -2591,11 +2546,10 @@ int test_wolfSSL_verify_post_handshake_defers(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method), 0); + wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); + WOLFSSL_VERIFY_POST_HANDSHAKE, NULL); ExpectIntEQ(ssl_s->options.verifyPeer, 1); ExpectIntEQ(ssl_s->options.verifyPostHandshake, 1); @@ -2668,7 +2622,7 @@ static int test_eku_override_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) * nothing else. Every other rejection is left to stand, so a chain the library * turns away for another reason must still fail. */ static int test_eku_purpose_only_cb(int preverify, - WOLFSSL_X509_STORE_CTX* store) + WOLFSSL_X509_STORE_CTX* store) { if (store->error == WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) @@ -2688,13 +2642,11 @@ static int test_eku_purpose_only_cb(int preverify, * (RFC 4210 OldWithNew): issuer and subject match, but the key is subjKey and * the signature is issuerKey's. Returns the DER length, or < 0 on failure. */ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, - const byte* issuerDer, int issuerDerSz, RsaKey* - issuerKey, WC_RNG* rng, - const char* extKeyUsage, const char* cn, int - selfIssued) + const byte* issuerDer, int issuerDerSz, RsaKey* issuerKey, WC_RNG* rng, + const char* extKeyUsage, const char* cn, int selfIssued) { Cert cert; - int ret = 0; + int ret = 0; if (selfIssued && issuerDer == NULL) return -1; @@ -2709,7 +2661,8 @@ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, * set below is built from the same source. */ if (wc_SetSubjectBuffer(&cert, issuerDer, issuerDerSz) != 0) ret = -1; - } else { + } + else { XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE - 1); XSTRNCPY(cert.subject.org, "wolfSSL_test", CTC_NAME_SIZE - 1); XSTRNCPY(cert.subject.commonName, cn, CTC_NAME_SIZE - 1); @@ -2719,7 +2672,7 @@ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, if (ret == 0 && wc_SetKeyUsage(&cert, "keyCertSign,cRLSign") != 0) ret = -1; if (ret == 0 && extKeyUsage != NULL && - wc_SetExtKeyUsage(&cert, extKeyUsage) != 0) + wc_SetExtKeyUsage(&cert, extKeyUsage) != 0) ret = -1; /* wc_InitCert() leaves selfSigned set, so naming no issuer is what makes * the generated certificate self-signed. */ @@ -2733,7 +2686,7 @@ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, ret = wc_MakeCert(&cert, out, (word32)outMax, subjKey, NULL, rng); if (ret >= 0) ret = wc_SignCert(cert.bodySz, cert.sigType, out, (word32)outMax, - (issuerDer == NULL) ? subjKey : issuerKey, NULL, rng); + (issuerDer == NULL) ? subjKey : issuerKey, NULL, rng); #ifdef WOLFSSL_CERT_GEN_CACHE wc_SetCert_Free(&cert); #endif @@ -2743,11 +2696,10 @@ static int test_eku_gen_ca(byte* out, int outMax, RsaKey* subjKey, /* Build a TLS leaf signed by the given CA. The leaf carries both serverAuth * and clientAuth so only the issuing CA's purpose is tested. */ static int test_eku_gen_leaf(byte* out, int outMax, RsaKey* leafKey, - const byte* issuerDer, int issuerDerSz, RsaKey* - issuerKey, WC_RNG* rng) + const byte* issuerDer, int issuerDerSz, RsaKey* issuerKey, WC_RNG* rng) { Cert cert; - int ret = 0; + int ret = 0; if (wc_InitCert(&cert) != 0) return -1; @@ -2761,7 +2713,7 @@ static int test_eku_gen_leaf(byte* out, int outMax, RsaKey* leafKey, if (ret == 0 && wc_SetAuthKeyIdFromCert(&cert, issuerDer, issuerDerSz) != 0) ret = -1; if (ret == 0 && - wc_SetKeyUsage(&cert, "digitalSignature,keyEncipherment") != 0) + wc_SetKeyUsage(&cert, "digitalSignature,keyEncipherment") != 0) ret = -1; if (ret == 0 && wc_SetExtKeyUsage(&cert, "serverAuth,clientAuth") != 0) ret = -1; @@ -2771,7 +2723,7 @@ static int test_eku_gen_leaf(byte* out, int outMax, RsaKey* leafKey, ret = wc_MakeCert(&cert, out, (word32)outMax, leafKey, NULL, rng); if (ret >= 0) ret = wc_SignCert(cert.bodySz, cert.sigType, out, (word32)outMax, - issuerKey, NULL, rng); + issuerKey, NULL, rng); #ifdef WOLFSSL_CERT_GEN_CACHE wc_SetCert_Free(&cert); #endif @@ -2786,10 +2738,8 @@ static int test_eku_gen_leaf(byte* out, int outMax, RsaKey* leafKey, * The handshake result and the compatibility-layer verify result are returned * through hsRet and verifyRet. */ static int test_eku_chain_handshake(const byte* chainDer, int chainSz, - const byte* rootDer, int rootSz, const byte* - pinnedDer, int pinnedSz, - const test_eku_case* tc, int* hsRet, long* - verifyRet) + const byte* rootDer, int rootSz, const byte* pinnedDer, int pinnedSz, + const test_eku_case* tc, int* hsRet, long* verifyRet) { EXPECT_DECLS; WOLFSSL_CTX* ctx_c = NULL; @@ -2810,35 +2760,27 @@ static int test_eku_chain_handshake(const byte* chainDer, int chainSz, /* The server always presents the generated chain so a single set of * credentials covers both directions. */ ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfSSLv23_client_method, - wolfSSLv23_server_method, - (byte*)rootDer, rootSz, (byte*)chainDer, - chainSz, - (byte*)client_key_der_2048, (int) - sizeof_client_key_der_2048), 0); + wolfSSLv23_client_method, wolfSSLv23_server_method, + (byte*)rootDer, rootSz, (byte*)chainDer, chainSz, + (byte*)client_key_der_2048, (int)sizeof_client_key_der_2048), 0); if (tc->clientPresents) { /* Leave the server chain unverified so only the server's view of the * client chain decides the handshake. */ wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, NULL); ExpectIntEQ(wolfSSL_use_certificate_chain_buffer_format(ssl_c, chainDer, - (long)chainSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + (long)chainSz, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_use_PrivateKey_buffer(ssl_c, client_key_der_2048, - (long) - sizeof_client_key_der_2048, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + (long)sizeof_client_key_der_2048, WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_load_verify_buffer(ctx_s, rootDer, - (long)rootSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + (long)rootSz, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER | - WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, verifyCb); + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, verifyCb); verifyCtx = ctx_s; verifySsl = ssl_s; - } else { + } + else { wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_PEER, verifyCb); verifyCtx = ctx_c; verifySsl = ssl_c; @@ -2851,9 +2793,7 @@ static int test_eku_chain_handshake(const byte* chainDer, int chainSz, if (pinnedDer != NULL) { ExpectIntEQ(wolfSSL_CTX_load_verify_buffer(verifyCtx, pinnedDer, - (long)pinnedSz, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + (long)pinnedSz, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); } /* The harness only reports pass or fail, so read the reason from the side @@ -2880,7 +2820,7 @@ static int test_eku_chain_handshake(const byte* chainDer, int chainSz, /* Build the chain for one scenario, run the handshake and check both the * handshake result and the verify result it is reported as. */ static int test_eku_chain_case(const test_eku_fixture* f, - const test_eku_case* tc) + const test_eku_case* tc) { EXPECT_DECLS; const byte* rootDer = ca_cert_der_2048; @@ -2897,14 +2837,10 @@ static int test_eku_chain_case(const test_eku_fixture* f, /* The CA under test is always signed by the root. */ ExpectIntGT((caSz = test_eku_gen_ca(f->interDer, TEST_EKU_CERT_BUF_SZ, - f->intKey, tc->selfSignedCa ? NULL : - ca_cert_der_2048, - (int)sizeof_ca_cert_der_2048, f->caKey, - f->rng, tc->extKeyUsage, - tc->selfSignedCa ? - "EKU Self Signed CA" : - "EKU Intermediate", - tc->selfIssuedCa)), 0); + f->intKey, tc->selfSignedCa ? NULL : ca_cert_der_2048, + (int)sizeof_ca_cert_der_2048, f->caKey, f->rng, tc->extKeyUsage, + tc->selfSignedCa ? "EKU Self Signed CA" : "EKU Intermediate", + tc->selfIssuedCa)), 0); leafIssuerDer = f->interDer; leafIssuerSz = caSz; @@ -2915,19 +2851,15 @@ static int test_eku_chain_case(const test_eku_fixture* f, * of the leaf and sits at depth 2. */ if (tc->extraLevel) { ExpectIntGT((midSz = test_eku_gen_ca(f->midDer, TEST_EKU_CERT_BUF_SZ, - f->midKey, f->interDer, caSz, f-> - intKey, f->rng, - "serverAuth,clientAuth", - "EKU Middle CA", 0)), 0); + f->midKey, f->interDer, caSz, f->intKey, f->rng, + "serverAuth,clientAuth", "EKU Middle CA", 0)), 0); leafIssuerDer = f->midDer; leafIssuerSz = midSz; leafIssuerKey = f->midKey; } ExpectIntGT((leafSz = test_eku_gen_leaf(f->chainDer, TEST_EKU_CERT_BUF_SZ, - f->leafKey, leafIssuerDer, - leafIssuerSz, leafIssuerKey, f->rng) - ), 0); + f->leafKey, leafIssuerDer, leafIssuerSz, leafIssuerKey, f->rng)), 0); /* The chain buffer holds the leaf first, then its issuers in order. */ ExpectIntLE(leafSz + caSz + midSz, TEST_EKU_CERT_BUF_SZ); @@ -2944,9 +2876,8 @@ static int test_eku_chain_case(const test_eku_fixture* f, rootSz = caSz; } ExpectIntEQ(test_eku_chain_handshake(f->chainDer, chainSz, - rootDer, rootSz, tc->pinCa ? f-> - interDer : NULL, caSz, tc, - &hsRet, &verifyRet), TEST_SUCCESS); + rootDer, rootSz, tc->pinCa ? f->interDer : NULL, caSz, tc, + &hsRet, &verifyRet), TEST_SUCCESS); } ExpectIntEQ(hsRet, tc->expectRet); @@ -2955,7 +2886,7 @@ static int test_eku_chain_case(const test_eku_fixture* f, * cases the library decided on its own have a predictable verify result. */ if (tc->overrideCb == 0) { ExpectIntEQ(verifyRet, (tc->expectRet == 0) ? - WOLFSSL_X509_V_OK : WOLFSSL_X509_V_ERR_INVALID_PURPOSE); + WOLFSSL_X509_V_OK : WOLFSSL_X509_V_ERR_INVALID_PURPOSE); } #endif @@ -2989,63 +2920,63 @@ int test_wolfSSL_chain_ca_ext_key_usage(void) /* Server authentication: a CA restricted to code signing, or to * client authentication, must be refused. */ - {"codeSigning", 0, 0, 0, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, - {"clientAuth", 0, 0, 0, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, + { "codeSigning", 0, 0, 0, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, + { "clientAuth", 0, 0, 0, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, /* A CA that carries the purpose, or leaves it unrestricted, must not * be over-rejected. */ - {"serverAuth", 0, 0, 0, 0, 0, 0, 0, 0}, - {NULL, 0, 0, 0, 0, 0, 0, 0, 0}, - {"any", 0, 0, 0, 0, 0, 0, 0, 0}, + { "serverAuth", 0, 0, 0, 0, 0, 0, 0, 0 }, + { NULL, 0, 0, 0, 0, 0, 0, 0, 0 }, + { "any", 0, 0, 0, 0, 0, 0, 0, 0 }, /* The rule applies to a CA the certificate manager already holds, not * only to one seen for the first time. */ - {"codeSigning", 0, 0, 0, 1, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, - {"serverAuth", 0, 0, 0, 1, 0, 0, 0, 0}, + { "codeSigning", 0, 0, 0, 1, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, + { "serverAuth", 0, 0, 0, 1, 0, 0, 0, 0 }, /* A self-signed trust anchor is exempt: here it is the anchor test, * not the Extended Key Usage, that decides. */ - {"codeSigning", 1, 0, 0, 0, 0, 0, 0, 0}, + { "codeSigning", 1, 0, 0, 0, 0, 0, 0, 0 }, /* A self-issued CA key rollover certificate is not an anchor. It * carries the anchor's issuer and subject names, so DecodedCert's * selfSigned flag is set, but it holds a different key and is signed * by the anchor. The Extended Key Usage must still be enforced. */ - {"codeSigning", 0, 1, 0, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, - {"serverAuth", 0, 1, 0, 0, 0, 0, 0, 0}, + { "codeSigning", 0, 1, 0, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, + { "serverAuth", 0, 1, 0, 0, 0, 0, 0, 0 }, /* Enforcement is not limited to the CA directly above the leaf: here - * the CA under test issues "EKU Middle CA", which issues the leaf. */ - {"codeSigning", 0, 0, 0, 0, 1, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, - {"serverAuth", 0, 0, 0, 0, 1, 0, 0, 0}, + * the CA under test issues "EKU Middle CA", which issues the leaf. */ + { "codeSigning", 0, 0, 0, 0, 1, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, + { "serverAuth", 0, 0, 0, 0, 1, 0, 0, 0 }, /* An application that installs a verify callback keeps the last word, * as it does for every other chain error. */ - {"codeSigning", 0, 0, 0, 0, 0, 1, 0, 0}, + { "codeSigning", 0, 0, 0, 0, 0, 1, 0, 0 }, #ifdef OPENSSL_EXTRA /* The purpose check must not stand in for the checks that run before - * it. With the depth limit pinned below the chain, a callback that - * waives only the purpose error still has to see the chain length - * rejection, whether or not the CA under test carries the purpose. */ - {"serverAuth", 0, 0, 0, 0, 1, 2, 1, - WC_NO_ERR_TRACE(MAX_CHAIN_ERROR)}, - {"codeSigning", 0, 0, 0, 0, 1, 2, 1, - WC_NO_ERR_TRACE(MAX_CHAIN_ERROR)}, + * it. With the depth limit pinned below the chain, a callback that + * waives only the purpose error still has to see the chain length + * rejection, whether or not the CA under test carries the purpose. */ + { "serverAuth", 0, 0, 0, 0, 1, 2, 1, + WC_NO_ERR_TRACE(MAX_CHAIN_ERROR) }, + { "codeSigning", 0, 0, 0, 0, 1, 2, 1, + WC_NO_ERR_TRACE(MAX_CHAIN_ERROR) }, #endif #ifndef WOLFSSL_NO_CLIENT_AUTH /* Client authentication: the server applies the same rule with the * clientAuth purpose. */ - {"codeSigning", 0, 0, 1, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, - {"serverAuth", 0, 0, 1, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, - {"clientAuth", 0, 0, 1, 0, 0, 0, 0, 0}, - {NULL, 0, 0, 1, 0, 0, 0, 0, 0}, - {"any", 0, 0, 1, 0, 0, 0, 0, 0}, + { "codeSigning", 0, 0, 1, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, + { "serverAuth", 0, 0, 1, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, + { "clientAuth", 0, 0, 1, 0, 0, 0, 0, 0 }, + { NULL, 0, 0, 1, 0, 0, 0, 0, 0 }, + { "any", 0, 0, 1, 0, 0, 0, 0, 0 }, /* The rollover shape is rejected in the client authentication * direction too. */ - {"serverAuth", 0, 1, 1, 0, 0, 0, 0, - WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E)}, - {"clientAuth", 0, 1, 1, 0, 0, 0, 0, 0}, + { "serverAuth", 0, 1, 1, 0, 0, 0, 0, + WC_NO_ERR_TRACE(EXTKEYUSE_AUTH_E) }, + { "clientAuth", 0, 1, 1, 0, 0, 0, 0, 0 }, #endif }; test_eku_fixture fixture; @@ -3064,39 +2995,34 @@ int test_wolfSSL_chain_ca_ext_key_usage(void) XMEMSET(&fixture, 0, sizeof(fixture)); ExpectNotNull(fixture.midDer = (byte*)XMALLOC(TEST_EKU_CERT_BUF_SZ, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); ExpectNotNull(fixture.interDer = (byte*)XMALLOC(TEST_EKU_CERT_BUF_SZ, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); ExpectNotNull(fixture.chainDer = (byte*)XMALLOC(TEST_EKU_CERT_BUF_SZ, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); ExpectIntEQ(wc_InitRng(&rng), 0); - if (EXPECT_SUCCESS()) - rngInit = 1; + if (EXPECT_SUCCESS()) rngInit = 1; ExpectIntEQ(wc_InitRsaKey(&caKey, NULL), 0); - if (EXPECT_SUCCESS()) - caInit = 1; + if (EXPECT_SUCCESS()) caInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(ca_key_der_2048, &idx, &caKey, - (word32)sizeof_ca_key_der_2048), 0); + (word32)sizeof_ca_key_der_2048), 0); ExpectIntEQ(wc_InitRsaKey(&midKey, NULL), 0); - if (EXPECT_SUCCESS()) - midInit = 1; + if (EXPECT_SUCCESS()) midInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(rsa_key_der_2048, &idx, &midKey, - (word32)sizeof_rsa_key_der_2048), 0); + (word32)sizeof_rsa_key_der_2048), 0); ExpectIntEQ(wc_InitRsaKey(&intKey, NULL), 0); - if (EXPECT_SUCCESS()) - intInit = 1; + if (EXPECT_SUCCESS()) intInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &intKey, - (word32)sizeof_server_key_der_2048), 0); + (word32)sizeof_server_key_der_2048), 0); ExpectIntEQ(wc_InitRsaKey(&leafKey, NULL), 0); - if (EXPECT_SUCCESS()) - leafInit = 1; + if (EXPECT_SUCCESS()) leafInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(client_key_der_2048, &idx, &leafKey, - (word32)sizeof_client_key_der_2048), 0); + (word32)sizeof_client_key_der_2048), 0); fixture.caKey = &caKey; fixture.midKey = &midKey; @@ -3108,16 +3034,11 @@ int test_wolfSSL_chain_ca_ext_key_usage(void) ExpectIntEQ(test_eku_chain_case(&fixture, &cases[i]), TEST_SUCCESS); } - if (rngInit) - wc_FreeRng(&rng); - if (caInit) - wc_FreeRsaKey(&caKey); - if (midInit) - wc_FreeRsaKey(&midKey); - if (intInit) - wc_FreeRsaKey(&intKey); - if (leafInit) - wc_FreeRsaKey(&leafKey); + if (rngInit) wc_FreeRng(&rng); + if (caInit) wc_FreeRsaKey(&caKey); + if (midInit) wc_FreeRsaKey(&midKey); + if (intInit) wc_FreeRsaKey(&intKey); + if (leafInit) wc_FreeRsaKey(&leafKey); XFREE(fixture.midDer, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(fixture.interDer, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(fixture.chainDer, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -3155,7 +3076,7 @@ typedef struct test_scv_case { static int test_scv_date_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) { if (store->error == TEST_SCV_DATE_BEFORE_E || - store->error == TEST_SCV_DATE_AFTER_E) { + store->error == TEST_SCV_DATE_AFTER_E) { return 1; } return preverify; @@ -3165,19 +3086,17 @@ static int test_scv_date_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) #undef TEST_SCV_DATE_AFTER_E /* Build a TLS leaf naming the 2048-bit test root as its issuer and carrying -* leafKey's public half. signKey decides whether it is genuine: the root's own -* key issues it, any other key forges it. Returns the DER length, or < 0. */ + * leafKey's public half. signKey decides whether it is genuine: the root's own + * key issues it, any other key forges it. Returns the DER length, or < 0. */ static int test_scv_gen_leaf(byte* out, int outMax, RsaKey* leafKey, - RsaKey* signKey, WC_RNG* rng, int expired) + RsaKey* signKey, WC_RNG* rng, int expired) { - static const byte notBefore[] = {ASN_UTC_TIME, 13, - '1', '9', '0', '1', '0', '1', '0', '0', - '0', '0', '0', '0', 'Z'}; - static const byte notAfter[] = {ASN_UTC_TIME, 13, - '2', '0', '0', '1', '0', '1', '0', '0', - '0', '0', '0', '0', 'Z'}; + static const byte notBefore[] = { ASN_UTC_TIME, 13, + '1', '9', '0', '1', '0', '1', '0', '0', '0', '0', '0', '0', 'Z' }; + static const byte notAfter[] = { ASN_UTC_TIME, 13, + '2', '0', '0', '1', '0', '1', '0', '0', '0', '0', '0', '0', 'Z' }; Cert cert; - int ret = 0; + int ret = 0; if (wc_InitCert(&cert) != 0) return -1; @@ -3195,19 +3114,19 @@ static int test_scv_gen_leaf(byte* out, int outMax, RsaKey* leafKey, if (wc_SetSubjectKeyIdFromPublicKey(&cert, leafKey, NULL) != 0) ret = -1; if (ret == 0 && wc_SetAuthKeyIdFromCert(&cert, ca_cert_der_2048, - (int)sizeof_ca_cert_der_2048) != 0) + (int)sizeof_ca_cert_der_2048) != 0) ret = -1; if (ret == 0 && wc_SetKeyUsage(&cert, - "digitalSignature,keyEncipherment") != 0) + "digitalSignature,keyEncipherment") != 0) ret = -1; if (ret == 0 && wc_SetIssuerBuffer(&cert, ca_cert_der_2048, - (int)sizeof_ca_cert_der_2048) != 0) + (int)sizeof_ca_cert_der_2048) != 0) ret = -1; if (ret == 0) ret = wc_MakeCert(&cert, out, (word32)outMax, leafKey, NULL, rng); if (ret >= 0) ret = wc_SignCert(cert.bodySz, cert.sigType, out, (word32)outMax, - signKey, NULL, rng); + signKey, NULL, rng); #ifdef WOLFSSL_CERT_GEN_CACHE wc_SetCert_Free(&cert); #endif @@ -3228,13 +3147,10 @@ static int test_scv_handshake(const byte* leafDer, int leafSz, int* hsRet) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfSSLv23_client_method, - wolfSSLv23_server_method, - (byte*)ca_cert_der_2048, (int) - sizeof_ca_cert_der_2048, - (byte*)leafDer, leafSz, - (byte*)client_key_der_2048, (int) - sizeof_client_key_der_2048), 0); + wolfSSLv23_client_method, wolfSSLv23_server_method, + (byte*)ca_cert_der_2048, (int)sizeof_ca_cert_der_2048, + (byte*)leafDer, leafSz, + (byte*)client_key_der_2048, (int)sizeof_client_key_der_2048), 0); wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_PEER, test_scv_date_cb); if (EXPECT_SUCCESS()) { @@ -3255,8 +3171,7 @@ static int test_scv_handshake(const byte* leafDer, int leafSz, int* hsRet) /* Build the leaf for one scenario, confirm what the library's own signature * check makes of it, then run the handshake. */ static int test_scv_case_run(byte* leafDer, RsaKey* leafKey, RsaKey* caKey, - RsaKey* attackerKey, WC_RNG* rng, const - test_scv_case* tc) + RsaKey* attackerKey, WC_RNG* rng, const test_scv_case* tc) { EXPECT_DECLS; WOLFSSL_CERT_MANAGER* cm = NULL; @@ -3264,17 +3179,15 @@ static int test_scv_case_run(byte* leafDer, RsaKey* leafKey, RsaKey* caKey, int hsRet = -1; ExpectIntGT((leafSz = test_scv_gen_leaf(leafDer, TEST_SCV_CERT_BUF_SZ, - leafKey, tc->forged ? attackerKey : - caKey, rng, tc->expired)), 0); + leafKey, tc->forged ? attackerKey : caKey, rng, tc->expired)), 0); /* Ground truth from the same library: only the signature is looked at. */ ExpectNotNull(cm = wolfSSL_CertManagerNew()); ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, ca_cert_der_2048, - (long)sizeof_ca_cert_der_2048, - WOLFSSL_FILETYPE_ASN1), - WOLFSSL_SUCCESS); + (long)sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1), + WOLFSSL_SUCCESS); ExpectIntEQ(wc_CheckCertSignature(leafDer, (word32)leafSz, NULL, cm), - tc->forged ? WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E) : 0); + tc->forged ? WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E) : 0); wolfSSL_CertManagerFree(cm); ExpectIntEQ(test_scv_handshake(leafDer, leafSz, &hsRet), TEST_SUCCESS); @@ -3308,17 +3221,17 @@ int test_wolfSSL_small_cert_verify_sig_error(void) /* forged, expired, expected handshake result. */ /* A leaf the root did issue verifies. */ - {0, 0, 0}, + { 0, 0, 0 }, /* An expired leaf the root did issue is what the callback exists for, * so it must still be waived. */ - {0, 1, 0}, + { 0, 1, 0 }, /* A leaf the root never signed is refused, and the reason the * application is given names the signature. */ - {1, 0, WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E)}, + { 1, 0, WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E) }, /* The same forgery, also outside its validity window. The date error * must not stand in for the signature error, or the callback above * waives a certificate the root never signed. */ - {1, 1, WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E)}, + { 1, 1, WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E) }, }; byte* leafDer = NULL; WC_RNG rng; @@ -3333,44 +3246,36 @@ int test_wolfSSL_small_cert_verify_sig_error(void) size_t i; ExpectNotNull(leafDer = (byte*)XMALLOC(TEST_SCV_CERT_BUF_SZ, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); + DYNAMIC_TYPE_TMP_BUFFER)); ExpectIntEQ(wc_InitRng(&rng), 0); - if (EXPECT_SUCCESS()) - rngInit = 1; + if (EXPECT_SUCCESS()) rngInit = 1; ExpectIntEQ(wc_InitRsaKey(&caKey, NULL), 0); - if (EXPECT_SUCCESS()) - caInit = 1; + if (EXPECT_SUCCESS()) caInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(ca_key_der_2048, &idx, &caKey, - (word32)sizeof_ca_key_der_2048), 0); + (word32)sizeof_ca_key_der_2048), 0); /* Any key the root does not hold serves as the attacker's. */ ExpectIntEQ(wc_InitRsaKey(&attackerKey, NULL), 0); - if (EXPECT_SUCCESS()) - attackerInit = 1; + if (EXPECT_SUCCESS()) attackerInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &attackerKey, - (word32)sizeof_server_key_der_2048), 0); + (word32)sizeof_server_key_der_2048), 0); ExpectIntEQ(wc_InitRsaKey(&leafKey, NULL), 0); - if (EXPECT_SUCCESS()) - leafInit = 1; + if (EXPECT_SUCCESS()) leafInit = 1; idx = 0; ExpectIntEQ(wc_RsaPrivateKeyDecode(client_key_der_2048, &idx, &leafKey, - (word32)sizeof_client_key_der_2048), 0); + (word32)sizeof_client_key_der_2048), 0); for (i = 0; i < XELEM_CNT(cases) && EXPECT_SUCCESS(); i++) { ExpectIntEQ(test_scv_case_run(leafDer, &leafKey, &caKey, &attackerKey, - &rng, &cases[i]), TEST_SUCCESS); + &rng, &cases[i]), TEST_SUCCESS); } - if (rngInit) - wc_FreeRng(&rng); - if (caInit) - wc_FreeRsaKey(&caKey); - if (attackerInit) - wc_FreeRsaKey(&attackerKey); - if (leafInit) - wc_FreeRsaKey(&leafKey); + if (rngInit) wc_FreeRng(&rng); + if (caInit) wc_FreeRsaKey(&caKey); + if (attackerInit) wc_FreeRsaKey(&attackerKey); + if (leafInit) wc_FreeRsaKey(&leafKey); XFREE(leafDer, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return EXPECT_RESULT(); @@ -4372,8 +4277,8 @@ int test_wolfSSL_crl_io_mock(void) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; int i; - static const int results[] = {0, -1, 1, - WOLFSSL_CBIO_ERR_WANT_READ}; + static const int results[] = { 0, -1, 1, + WOLFSSL_CBIO_ERR_WANT_READ }; ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECK), @@ -4434,26 +4339,26 @@ int test_wolfSSL_crl_io_mock(void) } /* --------------------------------------------------------------------------- -* OCSP stapling accessors, and CRL delivered through a mocked transport. -* -* The previous argument-guard sweep moved ssl_api_crl_ocsp.c by one condition, -* because it guessed at which functions held the gaps. Reading them settles -* it: they are not the enable/disable calls, they are the stapling request -* and response accessors, and their operands are of three kinds -- -* -* ssl->options.side != WOLFSSL_CLIENT_END a SERVER object, which no -* ctx->method->side != WOLFSSL_CLIENT_END client-side test can supply -* -* ssl->ocspProducedDateFormat != ASN_UTC_TIME a response that was never -* processed, or one whose -* producedDate is a -* GeneralizedTime -* -* idx >= XELEM_CNT(ssl->ocspCsrResp), len < 0 an out-of-range slot -* -* None of them is reachable from a working client that staples successfully, -* which is the only shape the existing tests have. -* ------------------------------------------------------------------------- */ + * OCSP stapling accessors, and CRL delivered through a mocked transport. + * + * The previous argument-guard sweep moved ssl_api_crl_ocsp.c by one condition, + * because it guessed at which functions held the gaps. Reading them settles + * it: they are not the enable/disable calls, they are the stapling request + * and response accessors, and their operands are of three kinds -- + * + * ssl->options.side != WOLFSSL_CLIENT_END a SERVER object, which no + * ctx->method->side != WOLFSSL_CLIENT_END client-side test can supply + * + * ssl->ocspProducedDateFormat != ASN_UTC_TIME a response that was never + * processed, or one whose + * producedDate is a + * GeneralizedTime + * + * idx >= XELEM_CNT(ssl->ocspCsrResp), len < 0 an out-of-range slot + * + * None of them is reachable from a working client that staples successfully, + * which is the only shape the existing tests have. + * ------------------------------------------------------------------------- */ int test_wolfSSL_ocsp_stapling_accessors(void) { EXPECT_DECLS; @@ -4469,11 +4374,9 @@ int test_wolfSSL_ocsp_stapling_accessors(void) ExpectNotNull(cctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(sctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(sctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(sctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectNotNull(cssl = wolfSSL_new(cctx)); ExpectNotNull(sssl = wolfSSL_new(sctx)); @@ -4500,8 +4403,8 @@ int test_wolfSSL_ocsp_stapling_accessors(void) #ifndef NO_ASN_TIME /* --- the producedDate accessor -------------------------------------- */ { - byte when[32]; - int fmt = 0; + byte when[32]; + int fmt = 0; XMEMSET(when, 0, sizeof(when)); (void)wolfSSL_get_ocsp_producedDate(NULL, when, sizeof(when), &fmt); @@ -4515,15 +4418,15 @@ int test_wolfSSL_ocsp_stapling_accessors(void) (void)wolfSSL_get_ocsp_producedDate(cssl, when, 1, &fmt); /* Drive the format operands directly. A stapled response carrying a - * GeneralizedTime rather than a UTCTime is legal, rare, and not - * something the test responder emits -- so this is the only way the - * second half of that decision is ever taken. - * - * Guarded because Expect* records a failure and carries on rather than - * returning: if wolfSSL_new() above failed, cssl is NULL here and - * these are dereferences of it, which is what the static analyser - * reported. Every call that merely PASSES cssl is safe either way -- - * the API checks it -- so only the direct field writes need this. */ + * GeneralizedTime rather than a UTCTime is legal, rare, and not + * something the test responder emits -- so this is the only way the + * second half of that decision is ever taken. + * + * Guarded because Expect* records a failure and carries on rather than + * returning: if wolfSSL_new() above failed, cssl is NULL here and + * these are dereferences of it, which is what the static analyser + * reported. Every call that merely PASSES cssl is safe either way -- + * the API checks it -- so only the direct field writes need this. */ if (cssl != NULL) { cssl->ocspProducedDateFormat = ASN_UTC_TIME; (void)wolfSSL_get_ocsp_producedDate(cssl, when, sizeof(when), &fmt); @@ -4546,23 +4449,23 @@ int test_wolfSSL_ocsp_stapling_accessors(void) } /* --------------------------------------------------------------------------- -* X509 accessors and the DTLS API, each with the object its guard needs. -* -* Two files sat at the bottom of the newly-visible surface for the same -* reason, and it is not that their guards are hard to reach -- it is that the -* ACCEPTING half of each pair needs an object the existing tests do not have. -* -* x509.c every accessor is `x509 == NULL || outSz == NULL || ...`, so the -* NULL half is trivial and the valid half needs a parsed -* certificate. There was no test holding one. -* -* ssl_api_dtls.c every guard is `ssl == NULL || !ssl->options.dtls`, so the -* second operand needs a DTLS connection. Every test in this group -* used a TLS one, which leaves that operand constant. -* -* Both fixtures are cheap: a certificate loaded from certs/, and a WOLFSSL -* made from a DTLS method. Neither needs a peer. -* ------------------------------------------------------------------------- */ + * X509 accessors and the DTLS API, each with the object its guard needs. + * + * Two files sat at the bottom of the newly-visible surface for the same + * reason, and it is not that their guards are hard to reach -- it is that the + * ACCEPTING half of each pair needs an object the existing tests do not have. + * + * x509.c every accessor is `x509 == NULL || outSz == NULL || ...`, so the + * NULL half is trivial and the valid half needs a parsed + * certificate. There was no test holding one. + * + * ssl_api_dtls.c every guard is `ssl == NULL || !ssl->options.dtls`, so the + * second operand needs a DTLS connection. Every test in this group + * used a TLS one, which leaves that operand constant. + * + * Both fixtures are cheap: a certificate loaded from certs/, and a WOLFSSL + * made from a DTLS method. Neither needs a peer. + * ------------------------------------------------------------------------- */ int test_wolfSSL_x509_accessor_guards(void) { EXPECT_DECLS; @@ -4580,13 +4483,13 @@ int test_wolfSSL_x509_accessor_guards(void) * -- invisible to anything that only reads headers. Match the implementation. */ #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \ (defined(OPENSSL_EXTRA) || defined(KEEP_PEER_CERT) || \ - defined(KEEP_OUR_CERT)) + defined(KEEP_OUR_CERT)) WOLFSSL_X509* x509 = NULL; - byte buf[2048]; - int iSz = (int)sizeof(buf); - int wSz = (int)sizeof(buf); + byte buf[2048]; + int iSz = (int)sizeof(buf); + int wSz = (int)sizeof(buf); const byte* der = NULL; - int derSz = 0; + int derSz = 0; XMEMSET(buf, 0, sizeof(buf)); @@ -4688,8 +4591,7 @@ int test_wolfSSL_x509_accessor_guards(void) int test_wolfSSL_dtls_api_on_dtls_object(void) { EXPECT_DECLS; -#if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) \ - && \ +#if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) && \ !defined(NO_TLS) && !defined(WOLFSSL_NO_TLS12) WOLFSSL_CTX* dctx = NULL; /* the object the second operand needs */ WOLFSSL_CTX* tctx = NULL; /* a TLS one, for the operand's other half */ @@ -4741,8 +4643,7 @@ int test_wolfSSL_dtls_api_on_dtls_object(void) /* Declared under (WOLFSSL_SCTP || WOLFSSL_DTLS_MTU) && WOLFSSL_DTLS in ssl.h; * guarding on WOLFSSL_DTLS_MTU alone left the SCTP-only configs calling an * undeclared function. */ -#if (defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)) && defined(WOLFSSL_DTLS \ - ) +#if (defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)) && defined(WOLFSSL_DTLS) (void)wolfSSL_CTX_dtls_set_mtu(NULL, 512); (void)wolfSSL_CTX_dtls_set_mtu(dctx, 0xFFFF); (void)wolfSSL_CTX_dtls_set_mtu(dctx, 512); @@ -4766,29 +4667,28 @@ int test_wolfSSL_dtls_api_on_dtls_object(void) } /* --------------------------------------------------------------------------- -* Certificate loading from files that are wrong in file-system ways. -* -* ssl_misc.c is 0/11 and every one of its conditions is in a static file -* helper -- wolfssl_file_len and wolfssl_read_file_static -- guarding against -* a seek that fails, a length that is zero or absurd, and a read that returns -* fewer bytes than the length promised: -* -* if ((ret == 0) && ((sz > MAX_WOLFSSL_FILE_SIZE) || (sz <= 0L))) -* if ((ret == 0) && ((file = XFOPEN(fname, "rb")) == XBADFILE)) -* if ((ret == 0) && (XFREAD(...) != sz)) -* -* They are static, but they are not out of reach: every public load-from-file -* entry point runs through them, so the vector is the FILE rather than the -* argument. An empty file gives sz <= 0; a directory passed where a file is -* expected gives a seek or read that fails; a name that does not exist gives -* XBADFILE. None of those is something a working configuration supplies, and -* no existing test supplies them either. -* ------------------------------------------------------------------------- */ + * Certificate loading from files that are wrong in file-system ways. + * + * ssl_misc.c is 0/11 and every one of its conditions is in a static file + * helper -- wolfssl_file_len and wolfssl_read_file_static -- guarding against + * a seek that fails, a length that is zero or absurd, and a read that returns + * fewer bytes than the length promised: + * + * if ((ret == 0) && ((sz > MAX_WOLFSSL_FILE_SIZE) || (sz <= 0L))) + * if ((ret == 0) && ((file = XFOPEN(fname, "rb")) == XBADFILE)) + * if ((ret == 0) && (XFREAD(...) != sz)) + * + * They are static, but they are not out of reach: every public load-from-file + * entry point runs through them, so the vector is the FILE rather than the + * argument. An empty file gives sz <= 0; a directory passed where a file is + * expected gives a seek or read that fails; a name that does not exist gives + * XBADFILE. None of those is something a working configuration supplies, and + * no existing test supplies them either. + * ------------------------------------------------------------------------- */ int test_wolfSSL_load_pathological_files(void) { EXPECT_DECLS; -#if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_CLIENT) \ - && \ +#if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_CLIENT) && \ !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL_CERT_MANAGER* cm = NULL; @@ -4861,22 +4761,22 @@ int test_wolfSSL_load_pathological_files(void) } /* --------------------------------------------------------------------------- -* The file-helper failure arms, reached with a FIFO. -* -* Three of ssl_misc.c's conditions cannot be produced by any regular file: -* -* if ((ret == 0) && (XFSEEK(fp, 0, SEEK_END) != 0)) seek failed -* if ((ret == 0) && (XFREAD(...) != (size_t)sz)) short read -* -* A regular file always seeks and always reads what it promised. A FIFO does -* neither: fopen() succeeds, so the XBADFILE arm is passed, and then fseek() -* fails with ESPIPE because a pipe has no position. That is the exact shape -* the guard is written for, and nothing on disk can imitate it. -* -* The FIFO is opened read-write by the test before the library touches it, so -* the library's fopen() cannot block waiting for a writer -- a test that hangs -* costs the whole variant just as surely as one that crashes. -* ------------------------------------------------------------------------- */ + * The file-helper failure arms, reached with a FIFO. + * + * Three of ssl_misc.c's conditions cannot be produced by any regular file: + * + * if ((ret == 0) && (XFSEEK(fp, 0, SEEK_END) != 0)) seek failed + * if ((ret == 0) && (XFREAD(...) != (size_t)sz)) short read + * + * A regular file always seeks and always reads what it promised. A FIFO does + * neither: fopen() succeeds, so the XBADFILE arm is passed, and then fseek() + * fails with ESPIPE because a pipe has no position. That is the exact shape + * the guard is written for, and nothing on disk can imitate it. + * + * The FIFO is opened read-write by the test before the library touches it, so + * the library's fopen() cannot block waiting for a writer -- a test that hangs + * costs the whole variant just as surely as one that crashes. + * ------------------------------------------------------------------------- */ int test_wolfSSL_load_from_fifo(void) { EXPECT_DECLS; @@ -4934,34 +4834,34 @@ int test_wolfSSL_load_from_fifo(void) } /* --------------------------------------------------------------------------- -* Allocation failure injection. -* -* Error propagation is the largest remaining category in the campaign: 633 of -* 2855 uncovered conditions, almost all of the shape -* -* ret = something(); -* if (ret != 0) { ... } or if (p == NULL) { ... } -* -* after a call that cannot fail in a working configuration. No number of -* successful runs pairs those operands, because the failing value never -* occurs. The only way to produce it is to make the underlying operation fail -* on purpose. -* -* wolfSSL_SetAllocators() is the cheapest lever for that: one harness, and it -* reaches every out-of-memory arm in every file at once, because every -* allocation in the library goes through it. The sweep fails the Nth -* allocation and lets the rest succeed, for each N in turn -- so each run -* takes a different one of those arms, and the runs where N is past the end -* of the workload are the shared accepting partner. -* -* Failing exactly one allocation rather than everything from N onward keeps -* each vector isolated: a cascade would take many arms at once and prove -* nothing about any single one. -* -* The allocators are restored before the test returns. Leaving a failing -* allocator installed would break every test that runs after this one in the -* same binary, which costs the whole variant. -* ------------------------------------------------------------------------- */ + * Allocation failure injection. + * + * Error propagation is the largest remaining category in the campaign: 633 of + * 2855 uncovered conditions, almost all of the shape + * + * ret = something(); + * if (ret != 0) { ... } or if (p == NULL) { ... } + * + * after a call that cannot fail in a working configuration. No number of + * successful runs pairs those operands, because the failing value never + * occurs. The only way to produce it is to make the underlying operation fail + * on purpose. + * + * wolfSSL_SetAllocators() is the cheapest lever for that: one harness, and it + * reaches every out-of-memory arm in every file at once, because every + * allocation in the library goes through it. The sweep fails the Nth + * allocation and lets the rest succeed, for each N in turn -- so each run + * takes a different one of those arms, and the runs where N is past the end + * of the workload are the shared accepting partner. + * + * Failing exactly one allocation rather than everything from N onward keeps + * each vector isolated: a cascade would take many arms at once and prove + * nothing about any single one. + * + * The allocators are restored before the test returns. Leaving a failing + * allocator installed would break every test that runs after this one in the + * same binary, which costs the whole variant. + * ------------------------------------------------------------------------- */ /* OPT-IN, via WOLFSSL_MCDC_ALLOC_SWEEP, which the coverage campaign's own * option list defines and no ordinary build does. * @@ -4993,8 +4893,7 @@ int test_wolfSSL_load_from_fifo(void) * defined. */ #if defined(WOLFSSL_MCDC_ALLOC_SWEEP) && defined(USE_WOLFSSL_MEMORY) && \ !defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFSSL_DEBUG_MEMORY) && \ - !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_FILESYSTEM) \ - && \ + !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_FILESYSTEM) && \ !defined(NO_TLS) static int fi_failAt = -1; /* which allocation to fail; -1 = none */ @@ -5146,14 +5045,13 @@ int test_wolfSSL_alloc_failure_sweep(void) * defined. */ #if defined(WOLFSSL_MCDC_ALLOC_SWEEP) && defined(USE_WOLFSSL_MEMORY) && \ !defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFSSL_DEBUG_MEMORY) && \ - !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_FILESYSTEM) \ - && \ + !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_FILESYSTEM) && \ !defined(NO_TLS) int n; int injected = 0; int total; - wolfSSL_Malloc_cb prevMalloc = NULL; - wolfSSL_Free_cb prevFree = NULL; + wolfSSL_Malloc_cb prevMalloc = NULL; + wolfSSL_Free_cb prevFree = NULL; wolfSSL_Realloc_cb prevRealloc = NULL; /* Keep whatever was installed before, so the teardown below can put it @@ -5215,18 +5113,18 @@ int test_wolfSSL_alloc_failure_sweep(void) } /* --------------------------------------------------------------------------- -* DTLS API argument guards, on a DTLS object. -* -* ssl_api_dtls.c is the weakest of the newly-visible files. Its guards are the -* usual NULL-and-zero pairs, but the ACCEPTING half of most of them needs a -* DTLS connection -- the same reason the file sat at 3/53 until one was -* supplied. These add the entry points the earlier pass did not reach. -* -* Guards were read from src/ssl_api_dtls.c before writing, not assumed from -* ssl.h: wolfSSL_dtls13_pending_work is compiled only under WOLFSSL_DTLS13, -* SetCookieSecret only under WOLFSSL_DTLS && !NO_WOLFSSL_SERVER, and several -* are additionally gated on !WOLFSSL_LEANPSK. -* ------------------------------------------------------------------------- */ + * DTLS API argument guards, on a DTLS object. + * + * ssl_api_dtls.c is the weakest of the newly-visible files. Its guards are the + * usual NULL-and-zero pairs, but the ACCEPTING half of most of them needs a + * DTLS connection -- the same reason the file sat at 3/53 until one was + * supplied. These add the entry points the earlier pass did not reach. + * + * Guards were read from src/ssl_api_dtls.c before writing, not assumed from + * ssl.h: wolfSSL_dtls13_pending_work is compiled only under WOLFSSL_DTLS13, + * SetCookieSecret only under WOLFSSL_DTLS && !NO_WOLFSSL_SERVER, and several + * are additionally gated on !WOLFSSL_LEANPSK. + * ------------------------------------------------------------------------- */ int test_wolfSSL_dtls_api_more_guards(void) { EXPECT_DECLS; @@ -5326,14 +5224,15 @@ int test_wolfSSL_dtls_api_more_guards(void) #endif return EXPECT_RESULT(); } - -/* Decision-coverage drivers for the ssl_api_cert.c argument guards left - * unpaired by the functional tests. Each block names the source - * line:condition it closes; struct pokes are saved/restored around the call. */ int test_ssl_cert_decision_coverage(void) { EXPECT_DECLS; -#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) + /* Refs WOLFSSL_LOCAL certman fns, hidden from the .so - shared builds + * compile this out; WOLFSSL_TEST_STATIC_BUILD is set for static-only + * builds (configure) and by the MC/DC variant. */ +#if defined(WOLFSSL_TEST_STATIC_BUILD) && !defined(NO_CERTS) && \ + !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && \ + !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; @@ -5358,6 +5257,7 @@ int test_ssl_cert_decision_coverage(void) wolfSSL_CTX_free(nctx); } +#ifdef SESSION_CERTS /* --- 2301:1 get_chain_X509: idx >= 0 -------------------------------- */ { WOLFSSL_X509_CHAIN chain; @@ -5368,6 +5268,7 @@ int test_ssl_cert_decision_coverage(void) (void)wolfSSL_get_chain_X509(&chain, -1); (void)wolfSSL_get_chain_X509(&chain, 0); } +#endif /* --- 984:1/1002:0/1 UnloadCertsKeys: keepCert, key, key->buffer ----- */ { diff --git a/tests/api/test_ssl_crl_ocsp.c b/tests/api/test_ssl_crl_ocsp.c index 4b29c43afe4..82225b53550 100644 --- a/tests/api/test_ssl_crl_ocsp.c +++ b/tests/api/test_ssl_crl_ocsp.c @@ -102,17 +102,15 @@ int test_wolfSSL_get_ocsp_producedDate(void) /* The object is required by both. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate(NULL, date, sizeof(date), - &format), WC_NO_ERR_TRACE( - BAD_FUNC_ARG)); + &format), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(NULL, &producedTm), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* No response processed, so no date format is recorded yet. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, date, sizeof(date), - &format), WC_NO_ERR_TRACE( - BAD_FUNC_ARG)); + &format), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(ssl, &producedTm), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); if (ssl != NULL) { /* Pretend a response carrying this date was processed. */ @@ -122,23 +120,21 @@ int test_wolfSSL_get_ocsp_producedDate(void) /* Both output parameters are required. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, NULL, sizeof(date), - &format), WC_NO_ERR_TRACE( - BAD_FUNC_ARG)); + &format), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, date, sizeof(date), - NULL), WC_NO_ERR_TRACE( - BAD_FUNC_ARG)); + NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* The buffer must be able to hold the whole date. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, date, 4, &format), - WC_NO_ERR_TRACE(BUFFER_E)); + WC_NO_ERR_TRACE(BUFFER_E)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate(ssl, date, sizeof(date), - &format), 0); + &format), 0); ExpectIntEQ(format, ASN_UTC_TIME); ExpectStrEQ((char*)date, "250101000000Z"); /* The same date is also reported as a broken-down time. */ ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(ssl, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); XMEMSET(&producedTm, 0, sizeof(producedTm)); ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(ssl, &producedTm), 0); ExpectIntEQ(producedTm.tm_year, 125); @@ -147,7 +143,7 @@ int test_wolfSSL_get_ocsp_producedDate(void) XMEMSET(ssl->ocspProducedDate, 0, sizeof(ssl->ocspProducedDate)); XMEMCPY(ssl->ocspProducedDate, "not-a-date", 11); ExpectIntEQ(wolfSSL_get_ocsp_producedDate_tm(ssl, &producedTm), - WC_NO_ERR_TRACE(ASN_PARSE_E)); + WC_NO_ERR_TRACE(ASN_PARSE_E)); } wolfSSL_free(ssl); @@ -170,26 +166,24 @@ int test_wolfSSL_tlsext_status_type(void) WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_set_tlsext_status_type(NULL, - WOLFSSL_TLSEXT_STATUSTYPE_ocsp), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_TLSEXT_STATUSTYPE_ocsp), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_get_tlsext_status_type(NULL), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The extension is not requested until asked for. */ ExpectIntEQ(wolfSSL_get_tlsext_status_type(ssl), - WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); /* Only the OCSP status type is supported. */ ExpectIntEQ(wolfSSL_set_tlsext_status_type(ssl, 99), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set_tlsext_status_type(ssl, - WOLFSSL_TLSEXT_STATUSTYPE_ocsp), - WOLFSSL_SUCCESS); + WOLFSSL_TLSEXT_STATUSTYPE_ocsp), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_get_tlsext_status_type(ssl), - WOLFSSL_TLSEXT_STATUSTYPE_ocsp); + WOLFSSL_TLSEXT_STATUSTYPE_ocsp); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -199,7 +193,7 @@ int test_wolfSSL_tlsext_status_type(void) /* Guarded to match its only caller, test_wolfSSL_CTX_tlsext_status_cb(). */ #if (defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \ - defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ + defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \ !defined(WOLFSSL_NO_TLS12) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_CERTS) @@ -225,7 +219,7 @@ int test_wolfSSL_CTX_tlsext_status_cb(void) { EXPECT_DECLS; #if (defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \ - defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ + defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \ !defined(WOLFSSL_NO_TLS12) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_CERTS) @@ -236,25 +230,21 @@ int test_wolfSSL_CTX_tlsext_status_cb(void) /* Every argument is required. */ ExpectIntEQ(wolfSSL_CTX_get_tlsext_status_cb(NULL, &cb), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_CTX_set_tlsext_status_cb(NULL, - test_ssl_crl_ocsp_status_cb), - WOLFSSL_FAILURE); + test_ssl_crl_ocsp_status_cb), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_CTX_set_tlsext_status_arg(NULL, &arg), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, - WOLFSSL_FILETYPE_PEM), - WOLFSSL_SUCCESS); + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_get_tlsext_status_cb(ctx, NULL), WOLFSSL_FAILURE); /* Setting the callback turns stapling on so it can be used. */ ExpectIntEQ(wolfSSL_CTX_set_tlsext_status_cb(ctx, - test_ssl_crl_ocsp_status_cb), - WOLFSSL_SUCCESS); + test_ssl_crl_ocsp_status_cb), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_get_tlsext_status_cb(ctx, &cb), WOLFSSL_SUCCESS); ExpectTrue(cb == test_ssl_crl_ocsp_status_cb); @@ -275,7 +265,7 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) { EXPECT_DECLS; #if (defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \ - defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ + defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \ !defined(NO_TLS) && !defined(WOLFSSL_NO_TLS12) && \ !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) WOLFSSL_CTX* ctx = NULL; @@ -299,18 +289,17 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) /* A response and a length must be given together. */ ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp(ssl, NULL, 4), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp_multi(ssl, NULL, 0, - 1 + MAX_CHAIN_DEPTH), - WOLFSSL_FAILURE); + 1 + MAX_CHAIN_DEPTH), WOLFSSL_FAILURE); /* The other half of the same rule: a response with no length. A negative * length is rejected before it, by the range check. */ ExpectNotNull(bad = (unsigned char*)XMALLOC(4, NULL, 0)); ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp(ssl, bad, 0), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp(ssl, bad, -1), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); /* A failed call takes no ownership, so nothing was stored and this side * still has the response to free. */ resp = NULL; @@ -325,12 +314,13 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) if (stored != NULL) { XMEMCPY(stored, "resp", 4); owned = (wolfSSL_set_tlsext_status_ocsp_resp(ssl, stored, 4) == - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(owned, 1); if (owned) { ExpectIntEQ(wolfSSL_get_tlsext_status_ocsp_resp(ssl, &resp), 4); ExpectPtrEq(resp, stored); - } else { + } + else { /* Ownership was not handed over, so this side still has it. */ XFREE(stored, NULL, 0); } @@ -338,7 +328,7 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) /* Clearing it releases the stored response and leaves nothing to get. */ ExpectIntEQ(wolfSSL_set_tlsext_status_ocsp_resp(ssl, NULL, 0), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); resp = NULL; ExpectIntEQ(wolfSSL_get_tlsext_status_ocsp_resp(ssl, &resp), 0); ExpectNull(resp); @@ -360,7 +350,7 @@ int test_wolfSSL_tlsext_status_ocsp_resp(void) * @return TEST_SUCCESS on success. */ static int test_ssl_crl_ocsp_url_ok(const char* url, const char* eh, - const char* ep, const char* epa, int es) + const char* ep, const char* epa, int es) { EXPECT_DECLS; char* host = NULL; @@ -369,7 +359,7 @@ static int test_ssl_crl_ocsp_url_ok(const char* url, const char* eh, int isSsl = -1; ExpectIntEQ(wolfSSL_OCSP_parse_url(url, &host, &port, &path, &isSsl), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectStrEQ(host, eh); ExpectStrEQ(port, ep); ExpectStrEQ(path, epa); @@ -396,7 +386,7 @@ static int test_ssl_crl_ocsp_url_bad(const char* url) int isSsl = -1; ExpectIntEQ(wolfSSL_OCSP_parse_url(url, &host, &port, &path, &isSsl), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectNull(host); ExpectNull(port); ExpectNull(path); @@ -432,21 +422,21 @@ int test_wolfSSL_OCSP_parse_url_api(void) * there is nothing to assert about them here: they still hold whatever * the caller left in them. */ ExpectIntEQ(wolfSSL_OCSP_parse_url(NULL, &host, &port, &path, &isSsl), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_OCSP_parse_url("http://a/", NULL, &port, &path, - &isSsl), WOLFSSL_FAILURE); + &isSsl), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_OCSP_parse_url("http://a/", &host, NULL, &path, - &isSsl), WOLFSSL_FAILURE); + &isSsl), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_OCSP_parse_url("http://a/", &host, &port, NULL, - &isSsl), WOLFSSL_FAILURE); + &isSsl), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_OCSP_parse_url("http://a/", &host, &port, &path, - NULL), WOLFSSL_FAILURE); + NULL), WOLFSSL_FAILURE); /* Reached through the OpenSSL compatibility name, which is how * applications call this. The rest of the cases use the wolfSSL name so * they read as tests of this implementation rather than of the macro. */ ExpectIntEQ(OCSP_parse_url("http://example.com/ocsp", &host, &port, &path, - &isSsl), WOLFSSL_SUCCESS); + &isSsl), WOLFSSL_SUCCESS); ExpectStrEQ(host, "example.com"); ExpectStrEQ(port, "80"); ExpectStrEQ(path, "/ocsp"); @@ -458,38 +448,32 @@ int test_wolfSSL_OCSP_parse_url_api(void) /* Scheme, default ports and the default path. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/ocsp", - "example.com", "80", "/ocsp", 0), - TEST_SUCCESS); + "example.com", "80", "/ocsp", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com", - "example.com", "80", "/", 0), - TEST_SUCCESS); + "example.com", "80", "/", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://example.com", - "example.com", "443", "/", 1), - TEST_SUCCESS); + "example.com", "443", "/", 1), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://example.com/some/path/", - "example.com", "443", "/some/path/", 1) - , TEST_SUCCESS); + "example.com", "443", "/some/path/", 1), TEST_SUCCESS); /* The scheme may be left out entirely, and is then http. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("example.com/ocsp", - "example.com", "80", "/ocsp", 0), - TEST_SUCCESS); + "example.com", "80", "/ocsp", 0), TEST_SUCCESS); /* Which means a scheme written without its colon is not rejected: there * is no "://" to find, so "http" is read as the host and the rest as the * path. The old parser refused this. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http" "//localhost", - "http", "80", "//localhost", 0), - TEST_SUCCESS); + "http", "80", "//localhost", 0), TEST_SUCCESS); /* It is matched case sensitively, so these are not schemes at all - and * without a "://" there is no authority either, so the whole string is a * host that happens to contain a colon. */ ExpectIntEQ(test_ssl_crl_ocsp_url_bad("HTTP://example.com/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("HttpS://example.com/p"), - TEST_SUCCESS); + TEST_SUCCESS); /* An unknown scheme is rejected. */ ExpectIntEQ(test_ssl_crl_ocsp_url_bad("ftp://example.com/"), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("httpx://example.com/"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("://example.com/"), TEST_SUCCESS); /* Missing separator after the scheme: no "://", so "http:/example.com/" * is a host of "http" with a bad port. */ @@ -498,102 +482,81 @@ int test_wolfSSL_OCSP_parse_url_api(void) /* Ports. Returned as written rather than canonicalized, and an explicit * ":0" is reported as the scheme's default. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:8080/ocsp", - "example.com", "8080", "/ocsp", 0), - TEST_SUCCESS); + "example.com", "8080", "/ocsp", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://example.com:1234", - "example.com", "1234", "/", 1), - TEST_SUCCESS); + "example.com", "1234", "/", 1), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:00080/p", - "example.com", "00080", "/p", 0), - TEST_SUCCESS); + "example.com", "00080", "/p", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:0/p", - "example.com", "80", "/p", 0), - TEST_SUCCESS); + "example.com", "80", "/p", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://example.com:0/p", - "example.com", "443", "/p", 1), - TEST_SUCCESS); + "example.com", "443", "/p", 1), TEST_SUCCESS); /* Only an exact ":0" is the default; "000" is a port in its own right. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:000/p", - "example.com", "000", "/p", 0), - TEST_SUCCESS); + "example.com", "000", "/p", 0), TEST_SUCCESS); /* Length is not limited, only the value. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:065535/p", - "example.com", "065535", "/p", 0), - TEST_SUCCESS); + "example.com", "065535", "/p", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com:65536/p"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com:/p"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com:"), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com:8080junk/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); /* An IPv6 literal keeps its brackets - note wolfIO_DecodeUrl() strips * them. Only a port may follow the literal. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://[::1]/ocsp", - "[::1]", "80", "/ocsp", 0), - TEST_SUCCESS); + "[::1]", "80", "/ocsp", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://[::1]:8443/p", - "[::1]", "8443", "/p", 0), TEST_SUCCESS - ); + "[::1]", "8443", "/p", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://[2001:db8::1]:8443/ocsp", - "[2001:db8::1]", "8443", "/ocsp", 1), - TEST_SUCCESS); + "[2001:db8::1]", "8443", "/ocsp", 1), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://[::1/ocsp"), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://[::1]junk"), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://[::1]junk/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); /* Userinfo runs to the FIRST '@' of the authority and is discarded, so * the host is what follows it - not the name that reads first. A caller * that logs or pins the responder must use the parsed host. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://good.example@evil.example/x", - "evil.example", "80", "/x", 0), - TEST_SUCCESS); + "evil.example", "80", "/x", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("https://u:p@ocsp.example:8443/x", - "ocsp.example", "8443", "/x", 1), - TEST_SUCCESS); + "ocsp.example", "8443", "/x", 1), TEST_SUCCESS); /* The first '@' delimits, so a second one is part of the host. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://a@b@c/", "b@c", "80", "/", 0), - TEST_SUCCESS); + TEST_SUCCESS); /* The scan is bounded by the authority, so an '@' in the path stays in * the path. OpenSSL 3.5 and earlier scanned the whole URL and took "b" * as the host here; that was fixed upstream. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/a@b", - "example.com", "80", "/a@b", 0), - TEST_SUCCESS); + "example.com", "80", "/a@b", 0), TEST_SUCCESS); /* Userinfo with nothing after it leaves no host. */ ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://user@/x"), TEST_SUCCESS); /* The query stays with the path; the fragment is dropped. A path is * prepended when the URL has none. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com?q=1", - "example.com", "80", "/?q=1", 0), - TEST_SUCCESS); + "example.com", "80", "/?q=1", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com#f", - "example.com", "80", "/", 0), - TEST_SUCCESS); + "example.com", "80", "/", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/p?q=1", - "example.com", "80", "/p?q=1", 0), - TEST_SUCCESS); + "example.com", "80", "/p?q=1", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/p#f", - "example.com", "80", "/p", 0), - TEST_SUCCESS); + "example.com", "80", "/p", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/p?q#f", - "example.com", "80", "/p?q", 0), - TEST_SUCCESS); + "example.com", "80", "/p?q", 0), TEST_SUCCESS); /* The fragment is looked for from the query onwards, so a '#' before the * query stays in the path. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/p#a?b", - "example.com", "80", "/p#a?b", 0), - TEST_SUCCESS); + "example.com", "80", "/p#a?b", 0), TEST_SUCCESS); /* A ':' in the path is not a port and is kept. */ ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com/ocsp:8080", - "example.com", "80", "/ocsp:8080", 0), - TEST_SUCCESS); + "example.com", "80", "/ocsp:8080", 0), TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_ok("http://example.com:8080/ocsp:1", - "example.com", "8080", "/ocsp:1", 0), - TEST_SUCCESS); + "example.com", "8080", "/ocsp:1", 0), TEST_SUCCESS); /* An empty host is refused rather than returned as "", which is where * this deliberately differs from OpenSSL - nothing can be fetched from @@ -604,36 +567,31 @@ int test_wolfSSL_OCSP_parse_url_api(void) /* CR/LF anywhere is refused so the parts cannot inject header lines into * a request built from them. Also not a check OpenSSL makes. */ ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com\r\n/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com/oc\rsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://example.com/oc\nsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://exa\rmple.com/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("http://exa\nmple.com/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); ExpectIntEQ(test_ssl_crl_ocsp_url_bad("\rhttp://example.com/ocsp"), - TEST_SUCCESS); + TEST_SUCCESS); #endif return EXPECT_RESULT(); } - -/* Decision-coverage drivers for the ssl_api_crl_ocsp.c argument guards that - * the functional tests leave unpaired. Each block names the source - * line:condition it closes; struct pokes are saved/restored around the call. */ int test_ssl_crl_ocsp_decision_coverage(void) { EXPECT_DECLS; #if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; - struct tm tm; - XMEMSET(&tm, 0, sizeof(tm)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); +#ifdef HAVE_CRL /* --- 77:0/1 wolfSSL_LoadCRLBuffer: ssl==NULL || ssl->ctx==NULL ------ */ { WOLFSSL* cssl = wolfSSL_new(ctx); @@ -651,13 +609,20 @@ int test_ssl_crl_ocsp_decision_coverage(void) cssl->ctx = ctx; wolfSSL_free(cssl); } +#endif +#if defined(HAVE_OCSP) && !defined(NO_ASN_TIME) + struct tm tm; + + XMEMSET(&tm, 0, sizeof(tm)); /* --- 917:1 get_ocsp_producedDate_tm: 2nd != (GENERALIZED vs default) - */ ssl->ocspProducedDateFormat = ASN_GENERALIZED_TIME; (void)wolfSSL_get_ocsp_producedDate_tm(ssl, &tm); ssl->ocspProducedDateFormat = 0; (void)wolfSSL_get_ocsp_producedDate_tm(ssl, &tm); +#endif +#if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) /* --- 1120/1152/1187:1 CTX status cb/arg: ctx->cm == NULL ------------ */ { WOLFSSL_CTX* nctx = wolfSSL_CTX_new(wolfSSLv23_client_method()); @@ -675,6 +640,7 @@ int test_ssl_crl_ocsp_decision_coverage(void) /* --- 1276:0 set_tlsext_status_ocsp_resp_multi: ssl == NULL ----------- */ (void)wolfSSL_set_tlsext_status_ocsp_resp_multi(NULL, NULL, 0, 0); +#endif wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); diff --git a/tests/api/test_ssl_ext.c b/tests/api/test_ssl_ext.c index a7ab7ec9684..6b1a036e06c 100644 --- a/tests/api/test_ssl_ext.c +++ b/tests/api/test_ssl_ext.c @@ -58,7 +58,7 @@ int test_wolfSSL_NoTicketTLSv12_ext(void) /* NULL arguments are rejected. */ ExpectIntEQ(wolfSSL_CTX_NoTicketTLSv12(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_NoTicketTLSv12(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); @@ -66,10 +66,9 @@ int test_wolfSSL_NoTicketTLSv12_ext(void) #ifndef NO_CERTS /* A server WOLFSSL needs a key and certificate set on the context. */ ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, CERT_FILETYPE), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, - CERT_FILETYPE), WOLFSSL_SUCCESS - ); + CERT_FILETYPE), WOLFSSL_SUCCESS); #endif ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_NoTicketTLSv12(ssl), WOLFSSL_SUCCESS); @@ -89,19 +88,18 @@ int test_wolfSSL_NoTicketTLSv12_ext(void) int test_wolfSSL_CTX_UseMaxFragment_ext(void) { EXPECT_DECLS; -#if defined(HAVE_MAX_FRAGMENT) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS \ - ) +#if defined(HAVE_MAX_FRAGMENT) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; /* NULL context is rejected. */ ExpectIntEQ(wolfSSL_CTX_UseMaxFragment(NULL, WOLFSSL_MFL_2_9), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_9), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_12), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_CTX_free(ctx); #endif @@ -180,17 +178,15 @@ int test_wolfSSL_set1_groups_ext(void) ExpectIntEQ(wolfSSL_CTX_set1_groups(ctx, dummy, -1), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set1_groups(ssl, dummy, -1), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_CTX_set1_groups(ctx, dummy, - WOLFSSL_MAX_GROUP_COUNT + 1), - WOLFSSL_FAILURE); + WOLFSSL_MAX_GROUP_COUNT + 1), WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set1_groups(ssl, dummy, - WOLFSSL_MAX_GROUP_COUNT + 1), - WOLFSSL_FAILURE); + WOLFSSL_MAX_GROUP_COUNT + 1), WOLFSSL_FAILURE); #if defined(HAVE_ECC) && !defined(NO_ECC_SECP) /* Named groups are taken as-is rather than looked up as NIDs. */ if (count > 0) { ExpectIntEQ(wolfSSL_CTX_set1_groups(ctx, groups, count), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set1_groups(ssl, groups, count), WOLFSSL_SUCCESS); } #endif @@ -234,9 +230,9 @@ int test_wolfSSL_set1_groups_list_ext(void) ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "p-256"), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "p-256"), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "p-256:SECP256R1"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "p-256:SECP256R1"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #if defined(WOLFSSL_HAVE_MLKEM) && !defined(WOLFSSL_NO_ML_KEM) && \ !defined(WOLFSSL_TLS_NO_MLKEM_STANDALONE) @@ -247,7 +243,7 @@ int test_wolfSSL_set1_groups_list_ext(void) * individual parameter set is only usable when it is compiled in. */ #ifndef WOLFSSL_NO_ML_KEM_512 ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "ML_KEM_512"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "MLKEM512"), WOLFSSL_SUCCESS); #endif #ifndef WOLFSSL_NO_ML_KEM_768 @@ -262,14 +258,14 @@ int test_wolfSSL_set1_groups_list_ext(void) /* Finite field groups are accepted by their OpenSSL names, on their own * and mixed into a list of curves. */ ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "ffdhe2048"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "P-256:ffdhe2048"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* set1_curves_list() is EC-only and still rejects them. */ ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "ffdhe2048"), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectIntEQ(wolfSSL_set1_curves_list(ssl, "P-256:ffdhe2048"), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); #endif wolfSSL_free(ssl); @@ -285,19 +281,18 @@ int test_wolfSSL_set1_groups_list_ext(void) int test_wolfSSL_CTX_set_TicketHint_ext(void) { EXPECT_DECLS; -#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && !defined( \ - NO_TLS) +#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; ExpectIntEQ(wolfSSL_CTX_set_TicketHint(NULL, 100), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); /* RFC 8446 caps the hint at 604800 seconds (7 days). */ ExpectIntEQ(wolfSSL_CTX_set_TicketHint(ctx, -1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_set_TicketHint(ctx, 604801), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_set_TicketHint(ctx, 0), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_set_TicketHint(ctx, 604800), WOLFSSL_SUCCESS); @@ -312,11 +307,9 @@ int test_wolfSSL_CTX_set_TicketHint_ext(void) /* Trivial custom ticket encryption callback: it has no key-lifetime constraint, * so it must be able to issue a ticket for any hint. */ static int test_TicketHint_custom_encCb(WOLFSSL* ssl, - byte key_name[WOLFSSL_TICKET_NAME_SZ], - byte iv[WOLFSSL_TICKET_IV_SZ], - byte mac[WOLFSSL_TICKET_MAC_SZ], int enc - , byte* ticket, int inLen, - int* outLen, void* userCtx) + byte key_name[WOLFSSL_TICKET_NAME_SZ], byte iv[WOLFSSL_TICKET_IV_SZ], + byte mac[WOLFSSL_TICKET_MAC_SZ], int enc, byte* ticket, int inLen, + int* outLen, void* userCtx) { int i; (void)ssl; @@ -337,8 +330,7 @@ static int test_TicketHint_custom_encCb(WOLFSSL* ssl, * the client received: -1 if the handshake failed, 0 if it completed without a * ticket, >0 if a ticket was issued. */ static int test_TicketHint_client_ticket_len(method_provider client_meth, - method_provider server_meth, int - hint, int customCb) + method_provider server_meth, int hint, int customCb) { struct test_memio_ctx test_ctx; WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; @@ -348,7 +340,7 @@ static int test_TicketHint_client_ticket_len(method_provider client_meth, XMEMSET(&test_ctx, 0, sizeof(test_ctx)); if (test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - client_meth, server_meth) != 0) { + client_meth, server_meth) != 0) { ret = -1; goto done; } @@ -383,33 +375,21 @@ int test_wolfSSL_CTX_set_TicketHint_default_cb_limit(void) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_WOLFSSL_SERVER) /* Default callback, hint below the limit: handshake succeeds, ticket issued. */ ExpectIntGT(test_TicketHint_client_ticket_len(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, - WOLFSSL_TICKET_KEY_LIFETIME / - 2 - 1, 0), 0); + wolfTLSv1_3_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2 - 1, 0), 0); /* Default callback, hint at the limit: handshake succeeds, no ticket. */ ExpectIntEQ(test_TicketHint_client_ticket_len(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, - WOLFSSL_TICKET_KEY_LIFETIME / - 2, 0), 0); + wolfTLSv1_3_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2, 0), 0); /* Custom callback: the same oversized hint still issues a ticket. */ ExpectIntGT(test_TicketHint_client_ticket_len(wolfTLSv1_3_client_method, - wolfTLSv1_3_server_method, - WOLFSSL_TICKET_KEY_LIFETIME / - 2, 1), 0); + wolfTLSv1_3_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2, 1), 0); #ifndef WOLFSSL_NO_TLS12 /* Same behavior on the TLS 1.2 SendTicket path. */ ExpectIntGT(test_TicketHint_client_ticket_len(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, - WOLFSSL_TICKET_KEY_LIFETIME / - 2 - 1, 0), 0); + wolfTLSv1_2_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2 - 1, 0), 0); ExpectIntEQ(test_TicketHint_client_ticket_len(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, - WOLFSSL_TICKET_KEY_LIFETIME / - 2, 0), 0); + wolfTLSv1_2_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2, 0), 0); ExpectIntGT(test_TicketHint_client_ticket_len(wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, - WOLFSSL_TICKET_KEY_LIFETIME / - 2, 1), 0); + wolfTLSv1_2_server_method, WOLFSSL_TICKET_KEY_LIFETIME / 2, 1), 0); #endif #endif return EXPECT_RESULT(); @@ -430,27 +410,23 @@ int test_wolfSSL_tlsext_max_fragment_length_ext(void) WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_CTX_set_tlsext_max_fragment_length(NULL, - WOLFSSL_MFL_2_9), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_MFL_2_9), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* Modes outside the WOLFSSL_MFL_2_9..WOLFSSL_MFL_2_12 range are rejected. */ ExpectIntEQ(wolfSSL_CTX_set_tlsext_max_fragment_length(ctx, - WOLFSSL_MFL_2_9 - 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_MFL_2_9 - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_set_tlsext_max_fragment_length(ctx, - WOLFSSL_MFL_2_12 + 1) - , WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WOLFSSL_MFL_2_12 + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_set_tlsext_max_fragment_length(ctx, - WOLFSSL_MFL_2_9), - WOLFSSL_SUCCESS); + WOLFSSL_MFL_2_9), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_tlsext_max_fragment_length(NULL, WOLFSSL_MFL_2_9), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_set_tlsext_max_fragment_length(ssl, WOLFSSL_MFL_2_12), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -473,9 +449,9 @@ int test_wolfSSL_DisableExtendedMasterSecret_ext(void) WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_DisableExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WOLFSSL_SUCCESS); @@ -488,117 +464,6 @@ int test_wolfSSL_DisableExtendedMasterSecret_ext(void) return EXPECT_RESULT(); } -/* Test the EMS enable/require APIs: NULL pairs, the client/server/side-less - * method branches, and the handshake-state guard. - * - * @return TEST_SUCCESS on success. - */ -int test_wolfSSL_EnableRequireExtendedMasterSecret_ext(void) -{ - EXPECT_DECLS; -#if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT) && \ - !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \ - !defined(WOLFSSL_NO_TLS12) - WOLFSSL_CTX* ctx = NULL; - WOLFSSL_CTX* ctxSrv = NULL; -#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) - WOLFSSL_CTX* ctxV23 = NULL; -#endif -#ifdef WOLFSSL_TLS13 - WOLFSSL_CTX* ctx13 = NULL; -#endif - WOLFSSL* ssl = NULL; -#if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) - WOLFSSL* sslSrv = NULL; -#endif - - ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - /* Client context: the re-arm branch is taken. */ - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); - ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctx), - WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctx), - WOLFSSL_SUCCESS); - - /* Server context: side is not the client end. */ - ExpectNotNull(ctxSrv = wolfSSL_CTX_new(wolfSSLv23_server_method())); - ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctxSrv), - WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctxSrv), - WOLFSSL_SUCCESS); - - /* Side-less context: the method exists but arms nothing. */ -#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) - ExpectNotNull(ctxV23 = wolfSSL_CTX_new(wolfSSLv23_method())); - ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctxV23), - WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctxV23), - WOLFSSL_SUCCESS); -#endif - - /* TLS 1.3 client: EMS is not allowed for the version. */ -#ifdef WOLFSSL_TLS13 - ExpectNotNull(ctx13 = wolfSSL_CTX_new(wolfTLSv1_3_client_method())); - ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctx13), - WOLFSSL_SUCCESS); - wolfSSL_CTX_free(ctx13); -#endif - - /* Fresh objects: the state guard passes. */ - ExpectNotNull(ssl = wolfSSL_new(ctx)); - ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), WOLFSSL_SUCCESS); -#if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) - /* A server WOLFSSL needs a key and certificate set on the context. */ - ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctxSrv, svrKeyFile, - CERT_FILETYPE), WOLFSSL_SUCCESS) - ; - ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctxSrv, svrCertFile, - CERT_FILETYPE), WOLFSSL_SUCCESS - ); - ExpectNotNull(sslSrv = wolfSSL_new(ctxSrv)); - ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(sslSrv), - WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(sslSrv), - WOLFSSL_SUCCESS); - wolfSSL_free(sslSrv); -#endif - - if (EXPECT_SUCCESS()) { - /* A started handshake: the connect-state operand alone. */ - ssl->options.connectState = 0x7f; - ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), - WC_NO_ERR_TRACE(BAD_STATE_E)); - ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), - WC_NO_ERR_TRACE(BAD_STATE_E)); - - /* A started handshake: the accept-state operand alone. */ - ssl->options.connectState = CONNECT_BEGIN; - ssl->options.acceptState = 0x7f; - ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), - WC_NO_ERR_TRACE(BAD_STATE_E)); - ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), - WC_NO_ERR_TRACE(BAD_STATE_E)); - } - - wolfSSL_free(ssl); - wolfSSL_CTX_free(ctx); - wolfSSL_CTX_free(ctxSrv); -#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) - wolfSSL_CTX_free(ctxV23); -#endif -#endif - return EXPECT_RESULT(); -} - /* Test setting the SNI host name and reading it back. * * @return TEST_SUCCESS on success. @@ -615,11 +480,11 @@ int test_wolfSSL_set_tlsext_host_name_ext(void) ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_set_tlsext_host_name(ssl, "localhost"), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); #ifndef NO_WOLFSSL_SERVER /* On the client the host name just set is returned. */ ExpectStrEQ(wolfSSL_get_servername(ssl, WOLFSSL_SNI_HOST_NAME), - "localhost"); + "localhost"); ExpectNull(wolfSSL_get_servername(NULL, WOLFSSL_SNI_HOST_NAME)); #endif @@ -641,11 +506,11 @@ int test_wolfSSL_CTX_set_tlsext_servername_callback_ext(void) WOLFSSL_CTX* ctx = NULL; ExpectIntEQ(wolfSSL_CTX_set_tlsext_servername_callback(NULL, NULL), - WOLFSSL_FAILURE); + WOLFSSL_FAILURE); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_set_tlsext_servername_callback(ctx, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_CTX_free(ctx); #endif @@ -681,8 +546,8 @@ int test_wolfSSL_set_tlsext_debug_arg_ext(void) #if defined(OPENSSL_EXTRA) && \ !defined(NO_TLS) && \ (!defined(NO_WOLFSSL_CLIENT) || \ - (defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ - defined(HAVE_TLS_EXTENSIONS))) + (defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(HAVE_TLS_EXTENSIONS))) /* State recorded by test_tlsext_debug_cb(). */ struct test_tlsext_debug_data { int count; /* number of extensions reported */ @@ -692,7 +557,7 @@ struct test_tlsext_debug_data { }; static void test_tlsext_debug_cb(WOLFSSL *ssl, int client_server, int type, - const byte *data, int len, void *arg) + const byte *data, int len, void *arg) { struct test_tlsext_debug_data *d = (struct test_tlsext_debug_data *)arg; (void)ssl; @@ -715,12 +580,12 @@ static void test_tlsext_debug_cb(WOLFSSL *ssl, int client_server, int type, /* Find an extension type in the recorded list; returns its length, -1 if * not reported. */ static int test_tlsext_debug_find_len(const struct test_tlsext_debug_data *d, - int type) + int type) { int i; for (i = 0; i < d->count && - i < (int)(sizeof(d->types) / sizeof(d->types[0])); i++) { + i < (int)(sizeof(d->types) / sizeof(d->types[0])); i++) { if (d->types[i] == type) return d->lens[i]; } @@ -733,8 +598,7 @@ static int test_tlsext_debug_find_len(const struct test_tlsext_debug_data *d, /* Declared with OpenSSL's spelling of the callback, to check that the compat * macro accepts it without a cast. */ static void test_tlsext_debug_ossl_cb(SSL *s, int client_server, int type, - const unsigned char *data, int len, void * - arg) + const unsigned char *data, int len, void *arg) { (void)s; (void)client_server; @@ -759,22 +623,21 @@ int test_wolfSSL_set_tlsext_debug_callback_ext(void) /* NULL object is rejected. */ ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(NULL, - test_tlsext_debug_cb), - WOLFSSL_FAILURE); + test_tlsext_debug_cb), WOLFSSL_FAILURE); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(ssl, test_tlsext_debug_cb), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Setting NULL disables the callback. */ ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(ssl, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* The compat macro takes a callback spelled the OpenSSL way without a * cast. A cast here would hide a signature mismatch and leave the call * undefined. */ ExpectIntEQ(SSL_set_tlsext_debug_callback(ssl, test_tlsext_debug_ossl_cb), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -806,14 +669,13 @@ int test_wolfSSL_set_tlsext_debug_callback_handshake_ext(void) XMEMSET(&sData, 0, sizeof(sData)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfSSLv23_client_method, - wolfSSLv23_server_method), 0); + wolfSSLv23_client_method, wolfSSLv23_server_method), 0); ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(ssl_c, test_tlsext_debug_cb), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_tlsext_debug_arg(ssl_c, &cData), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_tlsext_debug_callback(ssl_s, test_tlsext_debug_cb), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_tlsext_debug_arg(ssl_s, &sData), WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); @@ -835,13 +697,13 @@ int test_wolfSSL_set_tlsext_debug_callback_handshake_ext(void) /* TLS 1.3: both sides see supported versions (a list of 2-byte * versions, so at least 2 bytes). */ ExpectTrue(test_tlsext_debug_find_len(&cData, - TLSX_SUPPORTED_VERSIONS) >= 2); + TLSX_SUPPORTED_VERSIONS) >= 2); ExpectTrue(test_tlsext_debug_find_len(&sData, - TLSX_SUPPORTED_VERSIONS) >= 2); + TLSX_SUPPORTED_VERSIONS) >= 2); #elif defined(HAVE_EXTENDED_MASTER) /* TLS 1.2: the client offers extended master secret (empty content). */ ExpectIntEQ(test_tlsext_debug_find_len(&sData, - TLSX_EXTENDED_MASTER_SECRET), 0); + TLSX_EXTENDED_MASTER_SECRET), 0); #endif wolfSSL_free(ssl_c); @@ -859,18 +721,17 @@ int test_wolfSSL_set_tlsext_debug_callback_handshake_ext(void) int test_wolfSSL_set_SessionTicket_cb_ext(void) { EXPECT_DECLS; -#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_CLIENT) && !defined( \ - NO_TLS) +#if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; ExpectIntEQ(wolfSSL_set_SessionTicket_cb(NULL, NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); ExpectIntEQ(wolfSSL_set_SessionTicket_cb(ssl, NULL, NULL), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -924,7 +785,7 @@ int test_wolfSSL_SecureResume_ext(void) ExpectNotNull(ssl = wolfSSL_new(ctx)); /* Secure renegotiation has not been forced on, so resume is refused. */ ExpectIntEQ(wolfSSL_SecureResume(ssl), - WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E)); + WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E)); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -944,7 +805,7 @@ int test_wolfSSL_CTX_UseSecureRenegotiation_ext(void) /* NULL context is rejected. */ ExpectIntEQ(wolfSSL_CTX_UseSecureRenegotiation(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS); @@ -965,9 +826,9 @@ int test_wolfSSL_next_proto_cb_ext(void) { EXPECT_DECLS; #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \ - defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY) || \ - defined(WOLFSSL_QUIC)) && defined(HAVE_ALPN) && \ - !defined(NO_WOLFSSL_CLIENT) + defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY) || \ + defined(WOLFSSL_QUIC)) && defined(HAVE_ALPN) && \ + !defined(NO_WOLFSSL_CLIENT) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; const unsigned char* data = NULL; @@ -1030,12 +891,11 @@ int test_wolfSSL_SNI_GetFromBuffer_inval_ext(void) #if defined(HAVE_SNI) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) byte sni[32]; word32 sniSz = (word32)sizeof(sni); - byte hello[8] = {0}; + byte hello[8] = { 0 }; /* A NULL ClientHello buffer is rejected. */ ExpectIntEQ(wolfSSL_SNI_GetFromBuffer(NULL, (word32)sizeof(hello), 0, sni, - &sniSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG) - ); + &sniSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif return EXPECT_RESULT(); } @@ -1050,14 +910,14 @@ int test_wolfSSL_UseTrustedCA_inval_ext(void) #if defined(HAVE_TRUSTED_CA) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; - const byte id[1] = {0}; + const byte id[1] = { 0 }; ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The pre-agreed type must not carry an identifier. */ ExpectIntEQ(wolfSSL_UseTrustedCA(ssl, WOLFSSL_TRUSTED_CA_PRE_AGREED, id, 1), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1076,7 +936,7 @@ int test_wolfSSL_UseMaxFragment_inval_ext(void) !defined(NO_TLS) /* A NULL object is rejected. */ ExpectIntEQ(wolfSSL_UseMaxFragment(NULL, WOLFSSL_MFL_2_9), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif return EXPECT_RESULT(); } @@ -1129,14 +989,12 @@ int test_wolfSSL_UseALPN_inval_ext(void) /* A protocol-list length beyond the maximum is rejected. */ ExpectIntEQ(wolfSSL_UseALPN(ssl, proto, - (word32)(WOLFSSL_MAX_ALPN_NUMBER * - WOLFSSL_MAX_ALPN_PROTO_NAME_LEN + - WOLFSSL_MAX_ALPN_NUMBER + 1), - WOLFSSL_ALPN_CONTINUE_ON_MISMATCH), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + (word32)(WOLFSSL_MAX_ALPN_NUMBER * WOLFSSL_MAX_ALPN_PROTO_NAME_LEN + + WOLFSSL_MAX_ALPN_NUMBER + 1), + WOLFSSL_ALPN_CONTINUE_ON_MISMATCH), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* No mismatch option set is rejected. */ ExpectIntEQ(wolfSSL_UseALPN(ssl, proto, (word32)XSTRLEN(proto), 0), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1159,16 +1017,16 @@ int test_wolfSSL_ALPN_GetPeerProtocol_inval_ext(void) /* NULL arguments are rejected. */ ExpectIntEQ(wolfSSL_ALPN_GetPeerProtocol(NULL, &list, &listSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_ALPN_FreePeerProtocol(NULL, &list), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* The peer has not offered any protocols yet. */ ExpectIntEQ(wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz), - WC_NO_ERR_TRACE(BUFFER_ERROR)); + WC_NO_ERR_TRACE(BUFFER_ERROR)); wolfSSL_ALPN_FreePeerProtocol(ssl, &list); wolfSSL_free(ssl); @@ -1188,7 +1046,7 @@ int test_wolfSSL_CTX_set_TicketEncCb_inval_ext(void) !defined(NO_TLS) /* A NULL context is rejected. */ ExpectIntEQ(wolfSSL_CTX_set_TicketEncCb(NULL, NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif return EXPECT_RESULT(); } @@ -1204,7 +1062,7 @@ int test_wolfSSL_SessionTicket_inval_ext(void) !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; - byte tick[8] = {1, 2, 3, 4, 5, 6, 7, 8}; + byte tick[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; byte out[8]; word32 outSz; byte big[4096]; @@ -1214,27 +1072,27 @@ int test_wolfSSL_SessionTicket_inval_ext(void) /* NULL object checks. */ ExpectIntEQ(wolfSSL_UseSessionTicket(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_set_SessionTicket(NULL, tick, (word32)sizeof(tick)), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); ExpectNotNull(ssl = wolfSSL_new(ctx)); /* set: a non-zero size with a NULL buffer is rejected. */ ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, NULL, 4), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* get: NULL object and NULL buffer with non-zero size are rejected. */ outSz = (word32)sizeof(out); ExpectIntEQ(wolfSSL_get_SessionTicket(NULL, out, &outSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); outSz = (word32)sizeof(out); ExpectIntEQ(wolfSSL_get_SessionTicket(ssl, NULL, &outSz), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Store a short ticket (static-buffer path). */ ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, tick, (word32)sizeof(tick)), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Retrieving into a buffer that is too small reports zero length. */ outSz = 2; ExpectIntEQ(wolfSSL_get_SessionTicket(ssl, out, &outSz), WOLFSSL_SUCCESS); @@ -1246,7 +1104,7 @@ int test_wolfSSL_SessionTicket_inval_ext(void) ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, big, 3000), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, big, 4000), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_set_SessionTicket(ssl, tick, (word32)sizeof(tick)), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1277,7 +1135,7 @@ int test_wolfSSL_CTX_set_alpn_protos_inval_ext(void) EXPECT_DECLS; #if defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; - const unsigned char protos[] = {2, 'h', '2'}; + const unsigned char protos[] = { 2, 'h', '2' }; #if defined(WOLFSSL_ERROR_CODE_OPENSSL) const int good = 0; #else @@ -1286,17 +1144,14 @@ int test_wolfSSL_CTX_set_alpn_protos_inval_ext(void) /* A NULL context is rejected. */ ExpectIntEQ(wolfSSL_CTX_set_alpn_protos(NULL, protos, (unsigned int) - sizeof(protos)), WC_NO_ERR_TRACE( - BAD_FUNC_ARG)); + sizeof(protos)), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); /* Setting twice exercises the free-previous-list path. */ ExpectIntEQ(wolfSSL_CTX_set_alpn_protos(ctx, protos, - (unsigned int)sizeof(protos)), good) - ; + (unsigned int)sizeof(protos)), good); ExpectIntEQ(wolfSSL_CTX_set_alpn_protos(ctx, protos, - (unsigned int)sizeof(protos)), good) - ; + (unsigned int)sizeof(protos)), good); wolfSSL_CTX_free(ctx); #endif @@ -1316,10 +1171,10 @@ int test_wolfSSL_dual_alg_cks_parse_ext(void) !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; - byte oversized[WOLFSSL_MAX_CKS_SIGSPEC_SZ + 1]; - byte huge[64]; - byte maxValid[WOLFSSL_MAX_CKS_SIGSPEC_SZ]; - byte value; + byte oversized[WOLFSSL_MAX_CKS_SIGSPEC_SZ + 1]; + byte huge[64]; + byte maxValid[WOLFSSL_MAX_CKS_SIGSPEC_SZ]; + byte value; /* An oversized list made entirely of valid specifiers still needs to be * rejected, so fill the buffers with a valid value. */ @@ -1336,27 +1191,25 @@ int test_wolfSSL_dual_alg_cks_parse_ext(void) /* A zero length list is rejected. */ value = WOLFSSL_CKS_SIGSPEC_NATIVE; ExpectIntEQ(TLSX_CKS_Parse(ssl, &value, 0, &ssl->extensions), - WC_NO_ERR_TRACE(BUFFER_ERROR)); + WC_NO_ERR_TRACE(BUFFER_ERROR)); /* A list of all-valid bytes longer than the semantic maximum is rejected * before any allocation. This is the denial-of-service regression: * previously any length up to 65535 was copied into a fresh heap buffer. */ ExpectIntEQ(TLSX_CKS_Parse(ssl, oversized, (word16)sizeof(oversized), - &ssl->extensions), WC_NO_ERR_TRACE(BUFFER_ERROR)) - ; + &ssl->extensions), WC_NO_ERR_TRACE(BUFFER_ERROR)); ExpectIntEQ(TLSX_CKS_Parse(ssl, huge, (word16)sizeof(huge), - &ssl->extensions), WC_NO_ERR_TRACE(BUFFER_ERROR)) - ; + &ssl->extensions), WC_NO_ERR_TRACE(BUFFER_ERROR)); /* An invalid specifier value is still rejected. */ value = WOLFSSL_CKS_SIGSPEC_EXTERNAL; ExpectIntEQ(TLSX_CKS_Parse(ssl, &value, 1, &ssl->extensions), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* A well-formed list at the maximum length is accepted, so the cap does not - * break legitimate peers (the example client sends all three specifiers). */ + * break legitimate peers (the example client sends all three specifiers). */ ExpectIntEQ(TLSX_CKS_Parse(ssl, maxValid, (word16)sizeof(maxValid), - &ssl->extensions), 0); + &ssl->extensions), 0); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1376,7 +1229,7 @@ int test_wolfSSL_ALPN_FreePeerProtocol_inval_ext(void) /* A NULL object is rejected before the list is touched. */ ExpectIntEQ(wolfSSL_ALPN_FreePeerProtocol(NULL, &list), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectNull(list); #endif return EXPECT_RESULT(); @@ -1404,7 +1257,7 @@ int test_wolfSSL_ALPN_GetPeerProtocol_badlen_ext(void) /* No list offered by the peer yet. */ ExpectIntEQ(wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz), - WC_NO_ERR_TRACE(BUFFER_ERROR)); + WC_NO_ERR_TRACE(BUFFER_ERROR)); /* Install a list whose first length byte claims more bytes than are * present. wolfSSL_free() releases the buffer with the object, so it must @@ -1421,7 +1274,7 @@ int test_wolfSSL_ALPN_GetPeerProtocol_badlen_ext(void) ssl->alpn_peer_requested_length = 4; ExpectIntEQ(wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); ExpectNull(list); } } @@ -1454,7 +1307,7 @@ int test_wolfSSL_get_secure_renegotiation_support_ext(void) /* A NULL object is rejected when requesting the extension. */ ExpectIntEQ(wolfSSL_UseSecureRenegotiation(NULL), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Not requested yet. */ ExpectIntEQ(wolfSSL_SSL_get_secure_renegotiation_support(ssl), 0); @@ -1492,8 +1345,8 @@ int test_wolfSSL_set_alpn_protos_badlen_ext(void) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; /* First entry claims 8 bytes but only 3 follow. */ - const unsigned char bad[] = {8, 'h', '2', 0}; - const unsigned char good[] = {2, 'h', '2'}; + const unsigned char bad[] = { 8, 'h', '2', 0 }; + const unsigned char good[] = { 2, 'h', '2' }; #if defined(WOLFSSL_ERROR_CODE_OPENSSL) const int okRet = 0; const int failRet = 1; @@ -1507,11 +1360,11 @@ int test_wolfSSL_set_alpn_protos_badlen_ext(void) /* A well-formed list is accepted. */ ExpectIntEQ(wolfSSL_set_alpn_protos(ssl, good, (unsigned int)sizeof(good)), - okRet); + okRet); /* A bad length byte is rejected. */ ExpectIntEQ(wolfSSL_set_alpn_protos(ssl, bad, (unsigned int)sizeof(bad)), - failRet); + failRet); wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); @@ -1542,8 +1395,7 @@ int test_wolfSSL_set_alpn_protos_badlen_ext(void) * @return 0 always - the caller does not use the return value. */ static int test_ssl_ext_ticket_recv_cb(WOLFSSL* ssl, - const unsigned char* ticket, int ticketSz - , void* ctx) + const unsigned char* ticket, int ticketSz, void* ctx) { (void)ssl; (void)ticket; @@ -1573,10 +1425,8 @@ static int test_ssl_ext_ticket_recv_cb(WOLFSSL* ssl, * @return 0 when the cipher or HMAC cannot be set up. */ static int test_ssl_ext_ticket_renew_cb(WOLFSSL* ssl, unsigned char* name, - unsigned char* iv, - WOLFSSL_EVP_CIPHER_CTX* ectx, - WOLFSSL_HMAC_CTX* hctx, - int enc) + unsigned char* iv, WOLFSSL_EVP_CIPHER_CTX* ectx, WOLFSSL_HMAC_CTX* hctx, + int enc) { static const unsigned char key[32] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, @@ -1600,18 +1450,21 @@ static int test_ssl_ext_ticket_renew_cb(WOLFSSL* ssl, unsigned char* name, } if (HMAC_Init_ex(hctx, hmacKey, (int)sizeof(hmacKey), EVP_sha256(), - NULL) != 1) { + NULL) != 1) { ret = 0; - } else if (enc) { + } + else if (enc) { if (EVP_EncryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, key, iv) != 1) { ret = 0; - } else { + } + else { ret = TEST_SSL_EXT_TICKET_CB_OK; } - } else if (EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, key, iv) != 1) - { + } + else if (EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, key, iv) != 1) { ret = 0; - } else { + } + else { /* Ask for the ticket to be reissued after this resumption. */ ret = TEST_SSL_EXT_TICKET_CB_RENEW; } @@ -1646,12 +1499,10 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method), 0); + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0); ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx_s, - test_ssl_ext_ticket_renew_cb), - WOLFSSL_SUCCESS); + test_ssl_ext_ticket_renew_cb), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS); /* First handshake issues a ticket. */ @@ -1674,8 +1525,7 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void) ExpectIntEQ(wolfSSL_set_session(ssl_c, session), WOLFSSL_SUCCESS); /* Count the tickets this handshake issues. */ ExpectIntEQ(wolfSSL_set_SessionTicket_cb(ssl_c, - test_ssl_ext_ticket_recv_cb, & - newTickets), WOLFSSL_SUCCESS); + test_ssl_ext_ticket_recv_cb, &newTickets), WOLFSSL_SUCCESS); /* Make the ticket the only resumption path so the callback is reached. */ if (ssl_s != NULL) { ssl_s->options.sessionCacheOff = 1; @@ -1700,26 +1550,26 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void) } /* --------------------------------------------------------------------------- -* The public Encrypted ClientHello configuration API. -* -* src/ssl_ech.c measured 0 of 52 MC/DC conditions -- not "poorly covered", -* zero -- despite ECH being compiled in and five ECH tests running in the -* tls13 group of the same binary. Those tests drive ECH through a handshake -* with configs the harness generates for them; none of them calls the public -* configuration API, which is where every condition in the file lives: -* generating a config for a named KEM, importing one from raw bytes or from -* base64, reading one back into a caller's buffer, and the argument and size -* checks on all of it. -* -* The file was invisible to the campaign until this part: ssl_ech.c is -* #included into ssl.c rather than compiled standalone, so it produces no -* object file and never appeared in a filtered llvm-cov export. -* -* These vectors are the ones a handshake cannot produce: a NULL ctx, a buffer -* that is one byte too small, a length of zero, base64 that is not base64, a -* KEM/KDF/AEAD triple the build does not implement, and a retry-config query -* on a connection that never negotiated ECH. -* ------------------------------------------------------------------------- */ + * The public Encrypted ClientHello configuration API. + * + * src/ssl_ech.c measured 0 of 52 MC/DC conditions -- not "poorly covered", + * zero -- despite ECH being compiled in and five ECH tests running in the + * tls13 group of the same binary. Those tests drive ECH through a handshake + * with configs the harness generates for them; none of them calls the public + * configuration API, which is where every condition in the file lives: + * generating a config for a named KEM, importing one from raw bytes or from + * base64, reading one back into a caller's buffer, and the argument and size + * checks on all of it. + * + * The file was invisible to the campaign until this part: ssl_ech.c is + * #included into ssl.c rather than compiled standalone, so it produces no + * object file and never appeared in a filtered llvm-cov export. + * + * These vectors are the ones a handshake cannot produce: a NULL ctx, a buffer + * that is one byte too small, a length of zero, base64 that is not base64, a + * KEM/KDF/AEAD triple the build does not implement, and a retry-config query + * on a connection that never negotiated ECH. + * ------------------------------------------------------------------------- */ int test_wolfSSL_ech_config_api(void) { EXPECT_DECLS; @@ -1728,8 +1578,8 @@ int test_wolfSSL_ech_config_api(void) WOLFSSL_CTX* ctx = NULL; WOLFSSL_CTX* cctx = NULL; WOLFSSL* ssl = NULL; - byte cfg[512]; - byte small[4]; + byte cfg[512]; + byte small[4]; word32 cfgSz = (word32)sizeof(cfg); word32 smallSz = (word32)sizeof(small); word32 zero = 0; @@ -1749,8 +1599,7 @@ int test_wolfSSL_ech_config_api(void) WOLFSSL_SUCCESS); /* a KEM/KDF/AEAD triple no build implements: the lookup's failure arm */ ExpectIntNE(wolfSSL_CTX_GenerateEchConfig(ctx, "example.com", - 0xFFFF, 0xFFFF, 0xFFFF), - WOLFSSL_SUCCESS); + 0xFFFF, 0xFFFF, 0xFFFF), WOLFSSL_SUCCESS); /* the accepting partner: defaults */ ExpectIntEQ(wolfSSL_CTX_GenerateEchConfig(ctx, "example.com", 0, 0, 0), WOLFSSL_SUCCESS); @@ -1840,24 +1689,24 @@ int test_wolfSSL_ech_config_api(void) } /* --------------------------------------------------------------------------- -* Null-argument burn-down across the public API. -* -* A taxonomy of the 2855 conditions still uncovered puts null-guards at 749 -- -* the largest single type, 26% of everything left. Splitting them by enclosing -* function settles what API tests can and cannot do about it: -* -* 246 in public wolfSSL_* / wc_* functions <- these, reachable by call -* 503 in file-static helpers <- white-box only -* -* So an API suite can address a third of the category and no more; the rest is -* structurally out of reach from outside the library. These vectors take the -* public third across the extension, DTLS, session and record APIs. -* -* Every call here is a caller mistake a working program does not make: an -* object that was never created, an output pointer that is NULL, a length of -* zero paired with a real buffer. Each is followed by the same call made -* correctly, so the guard has its independence partner in this binary. -* ------------------------------------------------------------------------- */ + * Null-argument burn-down across the public API. + * + * A taxonomy of the 2855 conditions still uncovered puts null-guards at 749 -- + * the largest single type, 26% of everything left. Splitting them by enclosing + * function settles what API tests can and cannot do about it: + * + * 246 in public wolfSSL_* / wc_* functions <- these, reachable by call + * 503 in file-static helpers <- white-box only + * + * So an API suite can address a third of the category and no more; the rest is + * structurally out of reach from outside the library. These vectors take the + * public third across the extension, DTLS, session and record APIs. + * + * Every call here is a caller mistake a working program does not make: an + * object that was never created, an output pointer that is NULL, a length of + * zero paired with a real buffer. Each is followed by the same call made + * correctly, so the guard has its independence partner in this binary. + * ------------------------------------------------------------------------- */ int test_wolfSSL_api_null_burndown(void) { EXPECT_DECLS; @@ -1993,8 +1842,7 @@ int test_wolfSSL_api_null_burndown(void) int test_wolfSSL_session_null_burndown(void) { EXPECT_DECLS; -#if !defined(NO_SESSION_CACHE) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS \ - ) +#if !defined(NO_SESSION_CACHE) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; WOLFSSL_SESSION* sess = NULL; @@ -2032,30 +1880,30 @@ int test_wolfSSL_session_null_burndown(void) } /* --------------------------------------------------------------------------- -* Null-guard vectors aimed at named operands. -* -* The previous pass sprayed NULL at the first argument of everything and -* returned 11 conditions for a hundred calls. The reason is that a guard like -* -* if ((ssl == NULL) || (p == NULL) || (g == NULL)) -* -* has three operands, and a NULL in the first slot pairs only the first: the -* other two are never evaluated. Each operand needs its own call, with every -* other argument valid. -* -* So these vectors come from the ledger rather than from guesswork -- one call -* per uncovered operand of each guard, followed by the all-valid call that is -* their shared partner. -* ------------------------------------------------------------------------- */ + * Null-guard vectors aimed at named operands. + * + * The previous pass sprayed NULL at the first argument of everything and + * returned 11 conditions for a hundred calls. The reason is that a guard like + * + * if ((ssl == NULL) || (p == NULL) || (g == NULL)) + * + * has three operands, and a NULL in the first slot pairs only the first: the + * other two are never evaluated. Each operand needs its own call, with every + * other argument valid. + * + * So these vectors come from the ledger rather than from guesswork -- one call + * per uncovered operand of each guard, followed by the all-valid call that is + * their shared partner. + * ------------------------------------------------------------------------- */ int test_wolfSSL_api_null_operands(void) { EXPECT_DECLS; #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; - byte buf[64]; + byte buf[64]; word32 bufSz = (word32)sizeof(buf); - int iSz = (int)sizeof(buf); + int iSz = (int)sizeof(buf); XMEMSET(buf, 0, sizeof(buf)); ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); @@ -2064,8 +1912,8 @@ int test_wolfSSL_api_null_operands(void) /* --- SetTmpDH: (ssl|ctx == NULL) || (p == NULL) || (g == NULL) ------ */ #if !defined(NO_DH) && !defined(WOLFSSL_NO_TLS12) { - static const byte p[] = {0x00, 0x01}; - static const byte g[] = {0x02}; + static const byte p[] = { 0x00, 0x01 }; + static const byte g[] = { 0x02 }; (void)wolfSSL_SetTmpDH(NULL, p, (int)sizeof(p), g, (int)sizeof(g)); (void)wolfSSL_SetTmpDH(ssl, NULL, (int)sizeof(p), g, (int)sizeof(g)); @@ -2098,19 +1946,19 @@ int test_wolfSSL_api_null_operands(void) /* --- export_keying_material: ssl, out, label, and the context pair --- */ #ifdef HAVE_KEYING_MATERIAL (void)wolfSSL_export_keying_material(NULL, buf, sizeof(buf), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, NULL, sizeof(buf), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, buf, sizeof(buf), - NULL, 5, NULL, 0, 0); + NULL, 5, NULL, 0, 0); /* use_context set with a NULL context: the operand pair a caller that * passes both or neither cannot produce */ (void)wolfSSL_export_keying_material(ssl, buf, sizeof(buf), - "label", 5, NULL, 0, 1); + "label", 5, NULL, 0, 1); (void)wolfSSL_export_keying_material(ssl, buf, sizeof(buf), - "label", 5, buf, 4, 1); + "label", 5, buf, 4, 1); (void)wolfSSL_export_keying_material(ssl, buf, sizeof(buf), - "label", 5, NULL, 0, 0); + "label", 5, NULL, 0, 0); #endif /* HAVE_KEYING_MATERIAL */ /* --- SetServerID: ssl, id, then len <= 0 ---------------------------- */ @@ -2154,15 +2002,15 @@ int test_wolfSSL_api_null_operands(void) /* one operand of `clientHello != NULL && helloSz > 0 && sni != NULL * && inOutSz != NULL` per call */ (void)wolfSSL_SNI_GetFromBuffer(NULL, (word32)sizeof(hello), - WOLFSSL_SNI_HOST_NAME, buf, &outSz); + WOLFSSL_SNI_HOST_NAME, buf, &outSz); (void)wolfSSL_SNI_GetFromBuffer(hello, 0, - WOLFSSL_SNI_HOST_NAME, buf, &outSz); + WOLFSSL_SNI_HOST_NAME, buf, &outSz); (void)wolfSSL_SNI_GetFromBuffer(hello, (word32)sizeof(hello), - WOLFSSL_SNI_HOST_NAME, NULL, &outSz); + WOLFSSL_SNI_HOST_NAME, NULL, &outSz); (void)wolfSSL_SNI_GetFromBuffer(hello, (word32)sizeof(hello), - WOLFSSL_SNI_HOST_NAME, buf, NULL); + WOLFSSL_SNI_HOST_NAME, buf, NULL); (void)wolfSSL_SNI_GetFromBuffer(hello, (word32)sizeof(hello), - WOLFSSL_SNI_HOST_NAME, buf, &outSz); + WOLFSSL_SNI_HOST_NAME, buf, &outSz); } #endif /* HAVE_SNI && !NO_WOLFSSL_SERVER && !NO_TLS */ @@ -2190,13 +2038,13 @@ int test_wolfSSL_api_null_operands(void) (void)wolfSSL_get_cipher_suite_from_name(NULL, &c0, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - NULL, &c1, NULL); + NULL, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - &c0, NULL, NULL); + &c0, NULL, NULL); (void)wolfSSL_get_cipher_suite_from_name("no-such-suite", - &c0, &c1, NULL); + &c0, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - &c0, &c1, NULL); + &c0, &c1, NULL); } (void)bufSz; (void)iSz; @@ -2207,24 +2055,24 @@ int test_wolfSSL_api_null_operands(void) } /* --------------------------------------------------------------------------- -* Public-API argument NULLs, one call per named operand. -* -* A census of what is left splits the remaining NULL-shaped conditions three -* ways by how the NULL actually arises: 282 come from an argument a caller -* passes, 145 from a struct member that is legitimately NULL in some state, -* and only 15 from an allocation that failed. These are the first kind, in -* public functions -- the cheapest coverage left in the campaign and the only -* kind that needs no fixture at all. -* -* Each guard gets one call per uncovered operand with every OTHER argument -* valid, then the all-valid call that is their shared partner. A NULL in the -* first slot pairs only the first operand; the rest short-circuit away. -* -* Every symbol here was checked against BOTH its declaration guard in ssl.h -* and its implementation guard in src/, because a declaration without an -* implementation is a link error rather than a compile error, and that has -* cost this branch several CI rounds. -* ------------------------------------------------------------------------- */ + * Public-API argument NULLs, one call per named operand. + * + * A census of what is left splits the remaining NULL-shaped conditions three + * ways by how the NULL actually arises: 282 come from an argument a caller + * passes, 145 from a struct member that is legitimately NULL in some state, + * and only 15 from an allocation that failed. These are the first kind, in + * public functions -- the cheapest coverage left in the campaign and the only + * kind that needs no fixture at all. + * + * Each guard gets one call per uncovered operand with every OTHER argument + * valid, then the all-valid call that is their shared partner. A NULL in the + * first slot pairs only the first operand; the rest short-circuit away. + * + * Every symbol here was checked against BOTH its declaration guard in ssl.h + * and its implementation guard in src/, because a declaration without an + * implementation is a link error rather than a compile error, and that has + * cost this branch several CI rounds. + * ------------------------------------------------------------------------- */ int test_wolfSSL_public_null_operands(void) { EXPECT_DECLS; @@ -2272,14 +2120,14 @@ int test_wolfSSL_public_null_operands(void) (void)wolfSSL_get_cipher_suite_from_name(NULL, &c0, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - NULL, &c1, NULL); + NULL, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - &c0, NULL, NULL); + &c0, NULL, NULL); /* a name no build implements: the lookup's miss arm */ (void)wolfSSL_get_cipher_suite_from_name("NO-SUCH-SUITE", - &c0, &c1, NULL); + &c0, &c1, NULL); (void)wolfSSL_get_cipher_suite_from_name("TLS13-AES128-GCM-SHA256", - &c0, &c1, NULL); + &c0, &c1, NULL); } /* --- the curve-name getter, which reads ssl->ecdhCurveOID ---------- */ @@ -2315,7 +2163,7 @@ int test_wolfSSL_public_null_operands(void) /* --- `(ssl == NULL) || (der == NULL)` ------------------------------ */ #ifndef NO_CERTS { - static const byte tinyDer[] = {0x30, 0x03, 0x02, 0x01, 0x00}; + static const byte tinyDer[] = { 0x30, 0x03, 0x02, 0x01, 0x00 }; (void)wolfSSL_use_certificate_ASN1(NULL, tinyDer, (int)sizeof(tinyDer)); @@ -2333,13 +2181,13 @@ int test_wolfSSL_public_null_operands(void) XMEMSET(km, 0, sizeof(km)); (void)wolfSSL_export_keying_material(NULL, km, sizeof(km), - "lbl", 3, NULL, 0, 0); + "lbl", 3, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, NULL, sizeof(km), - "lbl", 3, NULL, 0, 0); + "lbl", 3, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, km, sizeof(km), - NULL, 3, NULL, 0, 0); + NULL, 3, NULL, 0, 0); (void)wolfSSL_export_keying_material(ssl, km, sizeof(km), - "lbl", 3, NULL, 0, 0); + "lbl", 3, NULL, 0, 0); } #endif @@ -2350,18 +2198,18 @@ int test_wolfSSL_public_null_operands(void) } /* --------------------------------------------------------------------------- -* Session object lifecycle argument guards. -* -* ssl_sess.c is the second-largest remaining file and its guards are almost -* all of the form `session == NULL || `. A test -* that establishes a session reaches them with a well-formed object every -* time, so the NULL half and the malformed half never occur. -* -* wolfSSL_SESSION_new / _dup / _up_ref / _free are unguarded in both ssl.h and -* src/ssl_sess.c, so they are callable in every configuration that has the -* session cache at all -- checked before writing, because a declaration -* without a compiled implementation is a link error. -* ------------------------------------------------------------------------- */ + * Session object lifecycle argument guards. + * + * ssl_sess.c is the second-largest remaining file and its guards are almost + * all of the form `session == NULL || `. A test + * that establishes a session reaches them with a well-formed object every + * time, so the NULL half and the malformed half never occur. + * + * wolfSSL_SESSION_new / _dup / _up_ref / _free are unguarded in both ssl.h and + * src/ssl_sess.c, so they are callable in every configuration that has the + * session cache at all -- checked before writing, because a declaration + * without a compiled implementation is a link error. + * ------------------------------------------------------------------------- */ int test_wolfSSL_session_lifecycle_guards(void) { EXPECT_DECLS; @@ -2427,12 +2275,112 @@ int test_wolfSSL_session_lifecycle_guards(void) #endif return EXPECT_RESULT(); } +int test_wolfSSL_EnableRequireExtendedMasterSecret_ext(void) +{ + EXPECT_DECLS; +#if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT) && \ + !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \ + !defined(WOLFSSL_NO_TLS12) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL_CTX* ctxSrv = NULL; +#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) + WOLFSSL_CTX* ctxV23 = NULL; +#endif +#ifdef WOLFSSL_TLS13 + WOLFSSL_CTX* ctx13 = NULL; +#endif + WOLFSSL* ssl = NULL; +#if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) + WOLFSSL* sslSrv = NULL; +#endif + + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + + /* Client context: the re-arm branch is taken. */ + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctx), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctx), + WOLFSSL_SUCCESS); + + /* Server context: side is not the client end. */ + ExpectNotNull(ctxSrv = wolfSSL_CTX_new(wolfSSLv23_server_method())); + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctxSrv), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctxSrv), + WOLFSSL_SUCCESS); + + /* Side-less context: the method exists but arms nothing. */ +#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) + ExpectNotNull(ctxV23 = wolfSSL_CTX_new(wolfSSLv23_method())); + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctxV23), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_RequireExtendedMasterSecret(ctxV23), + WOLFSSL_SUCCESS); +#endif + + /* TLS 1.3 client: EMS is not allowed for the version. */ +#ifdef WOLFSSL_TLS13 + ExpectNotNull(ctx13 = wolfSSL_CTX_new(wolfTLSv1_3_client_method())); + ExpectIntEQ(wolfSSL_CTX_EnableExtendedMasterSecret(ctx13), + WOLFSSL_SUCCESS); + wolfSSL_CTX_free(ctx13); +#endif + + /* Fresh objects: the state guard passes. */ + ExpectNotNull(ssl = wolfSSL_new(ctx)); + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), WOLFSSL_SUCCESS); +#if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) + /* A server WOLFSSL needs a key and certificate set on the context. */ + ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctxSrv, svrKeyFile, + CERT_FILETYPE), WOLFSSL_SUCCESS) + ; + ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctxSrv, svrCertFile, + CERT_FILETYPE), WOLFSSL_SUCCESS + ); + ExpectNotNull(sslSrv = wolfSSL_new(ctxSrv)); + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(sslSrv), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(sslSrv), + WOLFSSL_SUCCESS); + wolfSSL_free(sslSrv); +#endif + + if (EXPECT_SUCCESS()) { + /* A started handshake: the connect-state operand alone. */ + ssl->options.connectState = 0x7f; + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), + WC_NO_ERR_TRACE(BAD_STATE_E)); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), + WC_NO_ERR_TRACE(BAD_STATE_E)); + + /* A started handshake: the accept-state operand alone. */ + ssl->options.connectState = CONNECT_BEGIN; + ssl->options.acceptState = 0x7f; + ExpectIntEQ(wolfSSL_EnableExtendedMasterSecret(ssl), + WC_NO_ERR_TRACE(BAD_STATE_E)); + ExpectIntEQ(wolfSSL_RequireExtendedMasterSecret(ssl), + WC_NO_ERR_TRACE(BAD_STATE_E)); + } + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); + wolfSSL_CTX_free(ctxSrv); +#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE) + wolfSSL_CTX_free(ctxV23); +#endif +#endif + return EXPECT_RESULT(); +} -/* Decision-coverage driver for the public-API guards in src/ssl.c that the - * null-burndown and handshake tests leave unpaired. Each block names the - * source line:condition-index it closes. Struct pokes are the white-box - * mechanism; the pairs are chosen so each boolean operand independently - * toggles the guard outcome. */ int test_ssl_api_decision_coverage(void) { EXPECT_DECLS; @@ -2641,6 +2589,7 @@ int test_ssl_api_decision_coverage(void) (void)wolfSSL_check_domain_name(ssl, "a..com"); (void)wolfSSL_check_domain_name(ssl, "a.com"); +#if !defined(NO_PSK) /* --- 4166/4177/4203:0/1 PSK identity: ssl==NULL || arrays==NULL ------ */ (void)wolfSSL_get_psk_identity_hint(NULL); (void)wolfSSL_get_psk_identity_hint(ssl); @@ -2661,6 +2610,7 @@ int test_ssl_api_decision_coverage(void) pssl->arrays = saved; wolfSSL_free(pssl); } +#endif /* --- 5837:0/1 wolfSSL_clear EMS re-arm: side==CLIENT && !disableEMS -- */ ssl->options.disableEMS = 1; @@ -2668,6 +2618,7 @@ int test_ssl_api_decision_coverage(void) ssl->options.disableEMS = 0; wolfSSL_clear(ssl); +#ifdef HAVE_SECURE_RENEGOTIATION /* --- 6208:1 wolfSSL_session_reused: resuming || resumed -------------- */ ssl->options.resuming = 1; ssl->options.resumed = 0; @@ -2680,6 +2631,7 @@ int test_ssl_api_decision_coverage(void) (void)wolfSSL_session_reused(ssl); ssl->options.resuming = 0; ssl->options.resumed = 0; +#endif /* --- 6363:0/1 CIPHER_get_version: cipher && cipher->ssl -------------- */ { @@ -2773,10 +2725,6 @@ int test_ssl_api_decision_coverage(void) return EXPECT_RESULT(); } -/* Decision-coverage drivers for the ssl_ech.c argument guards left unpaired - * by the functional tests. The ECH config functions are WOLFSSL_LOCAL, so - * this white-box test calls them directly. Each block names the source - * line:condition it closes. */ int test_ech_decision_coverage(void) { EXPECT_DECLS; diff --git a/tests/api/test_tls.c b/tests/api/test_tls.c index 186415839d5..a1102961a70 100644 --- a/tests/api/test_tls.c +++ b/tests/api/test_tls.c @@ -4853,7 +4853,6 @@ int test_tls12_aesgcm_record_nonce_unique(void) return EXPECT_RESULT(); } -#if !defined(NO_PSK) && !defined(NO_CERTS) && !defined(NO_DH) /* Decision-coverage driver for the internal SetSSL_CTX() (src/internal.c). * SetSSL_CTX() runs on every wolfSSL_new() and wolfSSL_write_dup() and on * explicit context switches; the guards below are reached through those @@ -4861,6 +4860,13 @@ int test_tls12_aesgcm_record_nonce_unique(void) int test_internal_SetSSL_CTX_DecisionCoverage(void) { EXPECT_DECLS; + /* Refs WOLFSSL_LOCAL SetSSL_CTX(), hidden from the .so - shared builds + * compile this out; WOLFSSL_TEST_STATIC_BUILD is set for static-only + * builds (configure) and by the MC/DC variant. */ +#if defined(WOLFSSL_TEST_STATIC_BUILD) && defined(WOLFSSL_TLS13) && \ + !defined(WOLFCRYPT_ONLY) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) && !defined(NO_PSK) && \ + !defined(NO_CERTS) && !defined(NO_DH) WOLFSSL_CTX *ctx = NULL; WOLFSSL_CTX *ctxHint = NULL; WOLFSSL *ssl = NULL; @@ -5048,11 +5054,10 @@ int test_internal_SetSSL_CTX_DecisionCoverage(void) wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); wolfSSL_CTX_free(ctxHint); +#endif return EXPECT_RESULT(); } -#endif /* !NO_PSK && !NO_CERTS && !NO_DH */ -#if defined(HAVE_SECURE_RENEGOTIATION) && !defined(WOLFSSL_NO_TLS12) /* Decision-coverage driver for CheckVersion() (src/internal.c), called with * crafted protocol versions and poked option state. The version pairs are * chosen so that lowerVersion/higherVersion land exactly where each target @@ -5060,6 +5065,11 @@ int test_internal_SetSSL_CTX_DecisionCoverage(void) int test_internal_CheckVersion_DecisionCoverage(void) { EXPECT_DECLS; + /* Refs WOLFSSL_LOCAL CheckVersion(), hidden from the .so - shared + * builds compile this out; WOLFSSL_TEST_STATIC_BUILD is set for + * static-only builds (configure) and by the MC/DC variant. */ +#if defined(WOLFSSL_TEST_STATIC_BUILD) && defined(HAVE_SECURE_RENEGOTIATION) && \ + !defined(WOLFSSL_NO_TLS12) WOLFSSL_CTX *ctx = NULL; WOLFSSL *ssl = NULL; ProtocolVersion pv; @@ -5227,6 +5237,6 @@ int test_internal_CheckVersion_DecisionCoverage(void) wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); +#endif return EXPECT_RESULT(); } -#endif /* HAVE_SECURE_RENEGOTIATION && !WOLFSSL_NO_TLS12 */ diff --git a/tests/api/test_x509.c b/tests/api/test_x509.c index 7debdf4d35a..66af25bb7c2 100644 --- a/tests/api/test_x509.c +++ b/tests/api/test_x509.c @@ -48,13 +48,13 @@ * include/boost/asio/ssl/impl/rfc2818_verification.ipp * version: boost-1.84.0 */ static int rfc2818_verification_callback(int preverify, - WOLFSSL_X509_STORE_CTX* store) + WOLFSSL_X509_STORE_CTX* store) { EXPECT_DECLS; int depth; X509* cert; GENERAL_NAMES* gens; - byte address_bytes[] = {127, 0, 0, 1}; + byte address_bytes[] = { 127, 0, 0, 1 }; X509_NAME* name; int i; ASN1_STRING* common_name = 0; @@ -80,20 +80,22 @@ static int rfc2818_verification_callback(int preverify, /* Go through the alternate names in the certificate looking for matching * DNS or IP address entries. */ gens = (GENERAL_NAMES*)X509_get_ext_d2i( - cert, NID_subject_alt_name, NULL, NULL); + cert, NID_subject_alt_name, NULL, NULL); for (i = 0; i < sk_GENERAL_NAME_num(gens); ++i) { GENERAL_NAME* gen = sk_GENERAL_NAME_value(gens, i); if (gen->type == GEN_DNS) { ASN1_IA5STRING* domain = gen->d.dNSName; if (domain->type == V_ASN1_IA5STRING && domain->data && - domain->length && - XSTRCMP(domain->data, "example.com") == 0) + domain->length && + XSTRCMP(domain->data, "example.com") == 0) matches++; - } else if (gen->type == GEN_IPADD){ + } + else if (gen->type == GEN_IPADD) + { ASN1_OCTET_STRING* ip_address = gen->d.iPAddress; if (ip_address->type == V_ASN1_OCTET_STRING && ip_address->data && - ip_address->length == sizeof(address_bytes) && - XMEMCMP(address_bytes, ip_address->data, 4) == 0) + ip_address->length == sizeof(address_bytes) && + XMEMCMP(address_bytes, ip_address->data, 4) == 0) matches++; } } @@ -104,11 +106,13 @@ static int rfc2818_verification_callback(int preverify, * the list. */ name = X509_get_subject_name(cert); i = -1; - while ((i = X509_NAME_get_index_by_NID(name, NID_commonName, i)) >= 0){ + while ((i = X509_NAME_get_index_by_NID(name, NID_commonName, i)) >= 0) + { X509_NAME_ENTRY* name_entry = X509_NAME_get_entry(name, i); common_name = X509_NAME_ENTRY_get_data(name_entry); } - if (common_name && common_name->data && common_name->length){ + if (common_name && common_name->data && common_name->length) + { if (XSTRCMP(common_name->data, "www.wolfssl.com") == 0) matches++; } @@ -129,17 +133,16 @@ int test_x509_rfc2818_verification_callback(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), - 0); + wolfTLS_client_method, wolfTLS_server_method), 0); ExpectIntEQ(wolfSSL_use_certificate_file(ssl_c, cliCertFile, - WOLFSSL_FILETYPE_PEM), 1); + WOLFSSL_FILETYPE_PEM), 1); ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_c, cliKeyFile, - WOLFSSL_FILETYPE_PEM), 1); + WOLFSSL_FILETYPE_PEM), 1); ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, cliCertFile, NULL), 1); wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, - rfc2818_verification_callback); + rfc2818_verification_callback); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); @@ -170,9 +173,9 @@ int test_x509_GetCAByAKID(void) Signer signerA; Signer signerB; Signer* found; - byte issuerBuf[] = {0x01, 0x02, 0x03, 0x04}; - byte serialBuf[] = {0x0a, 0x0b, 0x0c, 0x0d}; - byte wrongSerial[] = {0x07, 0x07, 0x07, 0x07}; + byte issuerBuf[] = { 0x01, 0x02, 0x03, 0x04 }; + byte serialBuf[] = { 0x0a, 0x0b, 0x0c, 0x0d }; + byte wrongSerial[] = { 0x07, 0x07, 0x07, 0x07 }; byte issuerHash[SIGNER_DIGEST_SIZE]; byte serialHash[SIGNER_DIGEST_SIZE]; word32 row; @@ -221,8 +224,7 @@ int test_x509_GetCAByAKID(void) ExpectNull(found); /* 4) Zero-length issuer/serial should yield NULL. */ - found = GetCAByAKID(&cm, issuerBuf, 0, serialBuf, (word32)sizeof(serialBuf)) - ; + found = GetCAByAKID(&cm, issuerBuf, 0, serialBuf, (word32)sizeof(serialBuf)); ExpectNull(found); found = GetCAByAKID(&cm, issuerBuf, (word32)sizeof(issuerBuf), serialBuf, 0); @@ -265,11 +267,11 @@ int test_x509_verify_cert_hostname_check(void) ExpectNotNull(store = wolfSSL_X509_STORE_new()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile, - SSL_FILETYPE_PEM)); + SSL_FILETYPE_PEM)); ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, ca), WOLFSSL_SUCCESS); ExpectNotNull(leaf = wolfSSL_X509_load_certificate_file(svrCertFile, - SSL_FILETYPE_PEM)); + SSL_FILETYPE_PEM)); /* Case 1: no hostname constraint - must succeed. */ ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new()); @@ -286,8 +288,7 @@ int test_x509_verify_cert_hostname_check(void) param = wolfSSL_X509_STORE_CTX_get0_param(ctx); ExpectNotNull(param); ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "example.com", - XSTRLEN("example.com")), - WOLFSSL_SUCCESS); + XSTRLEN("example.com")), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_verify_cert(ctx), WOLFSSL_SUCCESS); wolfSSL_X509_STORE_CTX_free(ctx); ctx = NULL; @@ -299,8 +300,7 @@ int test_x509_verify_cert_hostname_check(void) param = wolfSSL_X509_STORE_CTX_get0_param(ctx); ExpectNotNull(param); ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "wrong.com", - XSTRLEN("wrong.com")), - WOLFSSL_SUCCESS); + XSTRLEN("wrong.com")), WOLFSSL_SUCCESS); ExpectIntNE(wolfSSL_X509_verify_cert(ctx), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_STORE_CTX_get_error(ctx), X509_V_ERR_HOSTNAME_MISMATCH); @@ -359,17 +359,16 @@ int test_x509_verify_cert_store_hostname_check(void) ExpectNotNull(store = wolfSSL_X509_STORE_new()); ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile, - SSL_FILETYPE_PEM)); + SSL_FILETYPE_PEM)); ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, ca), WOLFSSL_SUCCESS); ExpectNotNull(leaf = wolfSSL_X509_load_certificate_file(svrCertFile, - SSL_FILETYPE_PEM)); + SSL_FILETYPE_PEM)); /* Hostname matches a SAN DNS entry - must succeed. */ ExpectNotNull(param = wolfSSL_X509_STORE_get0_param(store)); ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "example.com", - XSTRLEN("example.com")), - WOLFSSL_SUCCESS); + XSTRLEN("example.com")), WOLFSSL_SUCCESS); ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new()); ExpectIntEQ(wolfSSL_X509_STORE_CTX_init(ctx, store, leaf, NULL), WOLFSSL_SUCCESS); @@ -380,8 +379,7 @@ int test_x509_verify_cert_store_hostname_check(void) /* Hostname does not match - must FAIL with the right error code. */ ExpectNotNull(param = wolfSSL_X509_STORE_get0_param(store)); ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "wrong.com", - XSTRLEN("wrong.com")), - WOLFSSL_SUCCESS); + XSTRLEN("wrong.com")), WOLFSSL_SUCCESS); ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new()); ExpectIntEQ(wolfSSL_X509_STORE_CTX_init(ctx, store, leaf, NULL), WOLFSSL_SUCCESS); @@ -457,17 +455,14 @@ int test_x509_ctx_param_hostname_check(void) * reuse these and create just the SSL objects. */ XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, NULL, NULL, - wolfTLS_client_method, wolfTLS_server_method), - 0); + wolfTLS_client_method, wolfTLS_server_method), 0); ExpectNotNull(param = wolfSSL_CTX_get0_param(ctx_c)); /* Hostname matches a SAN DNS entry of the server certificate. */ ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "example.com", - XSTRLEN("example.com")), - WOLFSSL_SUCCESS); + XSTRLEN("example.com")), WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), - 0); + wolfTLS_client_method, wolfTLS_server_method), 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); wolfSSL_free(ssl_c); ssl_c = NULL; @@ -478,11 +473,9 @@ int test_x509_ctx_param_hostname_check(void) /* Hostname does not match - the handshake must fail. */ ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(param, "wrong.com", - XSTRLEN("wrong.com")), - WOLFSSL_SUCCESS); + XSTRLEN("wrong.com")), WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), - 0); + wolfTLS_client_method, wolfTLS_server_method), 0); ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_verify_result(ssl_c), X509_V_ERR_HOSTNAME_MISMATCH); @@ -502,8 +495,7 @@ int test_x509_ctx_param_hostname_check(void) ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(param, "127.0.0.1"), WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), - 0); + wolfTLS_client_method, wolfTLS_server_method), 0); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); wolfSSL_free(ssl_c); ssl_c = NULL; @@ -516,8 +508,7 @@ int test_x509_ctx_param_hostname_check(void) ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(param, "192.168.1.1"), WOLFSSL_SUCCESS); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfTLS_client_method, wolfTLS_server_method), - 0); + wolfTLS_client_method, wolfTLS_server_method), 0); ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_get_verify_result(ssl_c), X509_V_ERR_IP_ADDRESS_MISMATCH); @@ -540,7 +531,7 @@ int test_x509_set_serialNumber(void) WOLFSSL_X509* x509 = NULL; WOLFSSL_ASN1_INTEGER* s = NULL; #if defined(OPENSSL_EXTRA_X509_SMALL) - WOLFSSL_ASN1_INTEGER asnInt; + WOLFSSL_ASN1_INTEGER asnInt; #endif ExpectNotNull(x509 = wolfSSL_X509_new()); @@ -671,7 +662,7 @@ static int accept_all_verify_cb(int preverify, WOLFSSL_X509_STORE_CTX* store) * Returns 0 on success, -1 on failure. */ static int craft_malicious_time_cert(const byte* orig, int origSz, - byte* out, int* outSz, int inflate) + byte* out, int* outSz, int inflate) { int i; int validityOff = -1; @@ -715,8 +706,8 @@ static int craft_malicious_time_cert(const byte* orig, int origSz, /* Copy the rest of the cert (notAfter field onward) */ XMEMCPY(out + notBeforeDataEnd + inflate, - orig + notBeforeDataEnd, - origSz - notBeforeDataEnd); + orig + notBeforeDataEnd, + origSz - notBeforeDataEnd); /* Fix Validity SEQUENCE length (single-byte encoding at validityOff+1) */ out[validityOff + 1] = (byte)(orig[validityOff + 1] + inflate); @@ -767,8 +758,8 @@ int test_x509_time_field_overread_via_tls(void) /* --- Step 1: Craft malicious certificate --- */ ExpectIntEQ(craft_malicious_time_cert( - server_cert_der_2048, (int)sizeof_server_cert_der_2048, - malicious_der, &malicious_der_sz, INFLATE), 0); + server_cert_der_2048, (int)sizeof_server_cert_der_2048, + malicious_der, &malicious_der_sz, INFLATE), 0); ExpectIntEQ(malicious_der_sz, (int)sizeof_server_cert_der_2048 + INFLATE); @@ -776,14 +767,11 @@ int test_x509_time_field_overread_via_tls(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, - &ssl_c, &ssl_s, - wolfTLSv1_2_client_method, - wolfTLSv1_2_server_method, - (byte*)ca_cert_der_2048, (int) - sizeof_ca_cert_der_2048, - malicious_der, malicious_der_sz, - (byte*)server_key_der_2048, (int) - sizeof_server_key_der_2048), 0); + &ssl_c, &ssl_s, + wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, + (byte*)ca_cert_der_2048, (int)sizeof_ca_cert_der_2048, + malicious_der, malicious_der_sz, + (byte*)server_key_der_2048, (int)sizeof_server_key_der_2048), 0); /* Client verify callback accepts all errors (signature is broken * because we modified the TBSCertificate without re-signing). @@ -860,31 +848,31 @@ int test_x509_CertFromX509_akid_overflow(void) return EXPECT_RESULT(); #endif - #define PUT1(b) do {buf[pos++] = (b);} while(0) - #define PUTN(p, n) do {XMEMCPY(buf + pos, (p), (n)); pos += (n);} while(0) + #define PUT1(b) do { buf[pos++] = (b); } while(0) + #define PUTN(p, n) do { XMEMCPY(buf + pos, (p), (n)); pos += (n); } while(0) /* Emit tag + definite-length header, return header size */ #define TLV_HDR(tag, n, out, hlen) do { \ - size_t _i = 0; \ - (out)[_i++] = (tag); \ - if ((n) < 0x80u) {(out)[_i++] = (unsigned char)(n);} \ - else if ((n) < 0x100u) {(out)[_i++] = 0x81; \ - (out)[_i++] = (unsigned char)(n);} \ - else if ((n) < 0x10000u) {(out)[_i++] = 0x82; \ - (out)[_i++] = (unsigned char)((n)>>8); \ - (out)[_i++] = (unsigned char)(n);} \ - (hlen) = _i; \ -} while(0) + size_t _i = 0; \ + (out)[_i++] = (tag); \ + if ((n) < 0x80u) { (out)[_i++] = (unsigned char)(n); } \ + else if ((n) < 0x100u) { (out)[_i++] = 0x81; \ + (out)[_i++] = (unsigned char)(n); } \ + else if ((n) < 0x10000u) { (out)[_i++] = 0x82; \ + (out)[_i++] = (unsigned char)((n)>>8); \ + (out)[_i++] = (unsigned char)(n); } \ + (hlen) = _i; \ + } while(0) /* Wrap [start, pos) in-place with a TLV header */ #define WRAP(start, tag) do { \ - size_t _len = pos - (start); \ - unsigned char _hdr[6]; size_t _hlen; \ - TLV_HDR((tag), _len, _hdr, _hlen); \ - XMEMMOVE(buf + (start) + _hlen, buf + (start), _len); \ - XMEMCPY(buf + (start), _hdr, _hlen); \ - pos += _hlen; \ -} while(0) + size_t _len = pos - (start); \ + unsigned char _hdr[6]; size_t _hlen; \ + TLV_HDR((tag), _len, _hdr, _hlen); \ + XMEMMOVE(buf + (start) + _hlen, buf + (start), _len); \ + XMEMCPY(buf + (start), _hdr, _hlen); \ + pos += _hlen; \ + } while(0) /* ---- Build AKID extension value ---- */ { @@ -894,8 +882,7 @@ int test_x509_CertFromX509_akid_overflow(void) /* [0] keyIdentifier: 20 bytes (small, passes old check) */ s = pos; - for (i = 0; i < 20; i++) - PUT1(0x41); + for (i = 0; i < 20; i++) PUT1(0x41); WRAP(s, 0x80); /* [1] authorityCertIssuer: one URI of ~4000 bytes @@ -904,8 +891,7 @@ int test_x509_CertFromX509_akid_overflow(void) { const char* pfx = "http://e/"; PUTN(pfx, (size_t)XSTRLEN(pfx)); - for (i = 0; i < 4000; i++) - PUT1('Z'); + for (i = 0; i < 4000; i++) PUT1('Z'); } WRAP(s, 0x86); /* GeneralName [6] URI */ WRAP(s, 0xA1); /* [1] IMPLICIT */ @@ -939,8 +925,8 @@ int test_x509_CertFromX509_akid_overflow(void) /* signature: ecdsa-with-SHA256 */ s = pos; { - unsigned char oid[] = {0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, - 0x3D, 0x04, 0x03, 0x02}; + unsigned char oid[] = {0x06,0x08,0x2A,0x86,0x48,0xCE, + 0x3D,0x04,0x03,0x02}; PUTN(oid, sizeof(oid)); } WRAP(s, 0x30); @@ -949,7 +935,7 @@ int test_x509_CertFromX509_akid_overflow(void) s = pos; { size_t rdn = pos, atv = pos; - unsigned char cn[] = {0x06, 0x03, 0x55, 0x04, 0x03}; + unsigned char cn[] = {0x06,0x03,0x55,0x04,0x03}; PUTN(cn, sizeof(cn)); PUT1(0x0C); PUT1(0x01); PUT1('A'); WRAP(atv, 0x30); WRAP(rdn, 0x31); WRAP(s, 0x30); @@ -958,10 +944,10 @@ int test_x509_CertFromX509_akid_overflow(void) /* validity */ s = pos; { - unsigned char t1[] = {0x17, 0x0D, '2', '5', '0', '1', '0', '1', - '0', '0', '0', '0', '0', '0', 'Z'}; - unsigned char t2[] = {0x17, 0x0D, '3', '5', '0', '1', '0', '1', - '0', '0', '0', '0', '0', '0', 'Z'}; + unsigned char t1[] = {0x17,0x0D,'2','5','0','1','0','1', + '0','0','0','0','0','0','Z'}; + unsigned char t2[] = {0x17,0x0D,'3','5','0','1','0','1', + '0','0','0','0','0','0','Z'}; PUTN(t1, sizeof(t1)); PUTN(t2, sizeof(t2)); } WRAP(s, 0x30); @@ -970,7 +956,7 @@ int test_x509_CertFromX509_akid_overflow(void) s = pos; { size_t rdn = pos, atv = pos; - unsigned char cn[] = {0x06, 0x03, 0x55, 0x04, 0x03}; + unsigned char cn[] = {0x06,0x03,0x55,0x04,0x03}; PUTN(cn, sizeof(cn)); PUT1(0x0C); PUT1(0x01); PUT1('A'); WRAP(atv, 0x30); WRAP(rdn, 0x31); WRAP(s, 0x30); @@ -980,10 +966,10 @@ int test_x509_CertFromX509_akid_overflow(void) s = pos; { size_t alg = pos, bs; - unsigned char ecpk[] = {0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, - 0x3D, 0x02, 0x01}; - unsigned char p256[] = {0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, - 0x3D, 0x03, 0x01, 0x07}; + unsigned char ecpk[] = {0x06,0x07,0x2A,0x86,0x48,0xCE, + 0x3D,0x02,0x01}; + unsigned char p256[] = {0x06,0x08,0x2A,0x86,0x48,0xCE, + 0x3D,0x03,0x01,0x07}; PUTN(ecpk, sizeof(ecpk)); PUTN(p256, sizeof(p256)); WRAP(alg, 0x30); @@ -993,14 +979,14 @@ int test_x509_CertFromX509_akid_overflow(void) * builds with WOLFSSL_VALIDATE_ECC_IMPORT accept the key. */ { static const unsigned char p256G[64] = { - 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, - 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, - 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, - 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96, - 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, - 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, - 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, - 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5 + 0x6B,0x17,0xD1,0xF2,0xE1,0x2C,0x42,0x47, + 0xF8,0xBC,0xE6,0xE5,0x63,0xA4,0x40,0xF2, + 0x77,0x03,0x7D,0x81,0x2D,0xEB,0x33,0xA0, + 0xF4,0xA1,0x39,0x45,0xD8,0x98,0xC2,0x96, + 0x4F,0xE3,0x42,0xE2,0xFE,0x1A,0x7F,0x9B, + 0x8E,0xE7,0xEB,0x4A,0x7C,0x0F,0x9E,0x16, + 0x2B,0xCE,0x33,0x57,0x6B,0x31,0x5E,0xCE, + 0xCB,0xB6,0x40,0x68,0x37,0xBF,0x51,0xF5 }; PUTN(p256G, sizeof(p256G)); } @@ -1011,7 +997,7 @@ int test_x509_CertFromX509_akid_overflow(void) /* extensions [3] */ { size_t exts_outer = pos, exts_seq = pos, ext = pos, ev; - unsigned char akid_oid[] = {0x06, 0x03, 0x55, 0x1D, 0x23}; + unsigned char akid_oid[] = {0x06,0x03,0x55,0x1D,0x23}; PUTN(akid_oid, sizeof(akid_oid)); ev = pos; if (akid_val != NULL) @@ -1027,8 +1013,8 @@ int test_x509_CertFromX509_akid_overflow(void) /* signatureAlgorithm */ s = pos; { - unsigned char oid[] = {0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, - 0x3D, 0x04, 0x03, 0x02}; + unsigned char oid[] = {0x06,0x08,0x2A,0x86,0x48,0xCE, + 0x3D,0x04,0x03,0x02}; PUTN(oid, sizeof(oid)); } WRAP(s, 0x30); @@ -1152,7 +1138,7 @@ int test_x509_ReqCertFromX509_skid_overflow(void) /* Step 1: Parse the crafted CSR -- this should succeed (the parser * dynamically allocates subjKeyId to the parsed size). */ req = wolfSSL_X509_REQ_d2i(NULL, crafted_csr_der, - (int)sizeof(crafted_csr_der)); + (int)sizeof(crafted_csr_der)); ExpectNotNull(req); /* Step 2: Attempt to re-encode. Before the fix, this triggered a @@ -1189,26 +1175,24 @@ int test_x509_ReqCertFromX509_skid_boundary(void) WOLFSSL_X509* parsed = NULL; WOLFSSL_X509_NAME* name = NULL; unsigned char* der = NULL; - int derSz = 0; + int derSz = 0; const unsigned char* ecPriv = ecc_clikey_der_256; const unsigned char* ecPub = ecc_clikeypub_der_256; - unsigned char expected_skid[CTC_MAX_SKID_SIZE]; + unsigned char expected_skid[CTC_MAX_SKID_SIZE]; XMEMSET(expected_skid, 0x41, sizeof(expected_skid)); /* Load a real ECC keypair so that the CSR can actually be signed * (ReqCertFromX509() is invoked from the signing path). */ ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv, - (long)sizeof_ecc_clikey_der_256) - ); + (long)sizeof_ecc_clikey_der_256)); ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub, - (long)sizeof_ecc_clikeypub_der_256)); + (long)sizeof_ecc_clikeypub_der_256)); ExpectNotNull(req = wolfSSL_X509_REQ_new()); ExpectNotNull(name = wolfSSL_X509_NAME_new()); ExpectIntEQ(wolfSSL_X509_NAME_add_entry_by_txt(name, "commonName", - MBSTRING_UTF8, (const byte*) - "Test", 4, -1, 0), + MBSTRING_UTF8, (const byte*)"Test", 4, -1, 0), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS); @@ -1276,22 +1260,19 @@ int test_x509_ReqCertFromX509_ext_critical(void) WOLFSSL_X509_EXTENSION* ext = NULL; WOLFSSL_ASN1_OBJECT* obj = NULL; unsigned char* der = NULL; - int derSz = 0; + int derSz = 0; const unsigned char* ecPriv = ecc_clikey_der_256; const unsigned char* ecPub = ecc_clikeypub_der_256; ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv, - (long)sizeof_ecc_clikey_der_256) - ); + (long)sizeof_ecc_clikey_der_256)); ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub, - (long)sizeof_ecc_clikeypub_der_256)); + (long)sizeof_ecc_clikeypub_der_256)); ExpectNotNull(req = wolfSSL_X509_REQ_new()); ExpectNotNull(name = wolfSSL_X509_NAME_new()); ExpectIntEQ(wolfSSL_X509_NAME_add_entry_by_txt(name, "commonName", - MBSTRING_UTF8, (const byte*) - "Test", 4, -1, 0), - WOLFSSL_SUCCESS); + MBSTRING_UTF8, (const byte*)"Test", 4, -1, 0), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS); @@ -1313,7 +1294,7 @@ int test_x509_ReqCertFromX509_ext_critical(void) /* Signing invokes wolfssl_x509_make_der() -> ReqCertFromX509(). */ ExpectIntEQ(wolfSSL_X509_REQ_sign(req, priv, wolfSSL_EVP_sha256()), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntGT((derSz = wolfSSL_i2d_X509_REQ(req, &der)), 0); ExpectNotNull(der); @@ -1332,7 +1313,7 @@ int test_x509_ReqCertFromX509_ext_critical(void) if (EXPECT_SUCCESS() && req != NULL) { req->pathLength = WOLFSSL_MAX_PATH_LEN + 1; ExpectIntNE(wolfSSL_X509_REQ_sign(req, priv, wolfSSL_EVP_sha256()), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); } wolfSSL_X509_free(parsed); @@ -1370,7 +1351,7 @@ int test_x509_REQ_sign_mldsa(void) WOLFSSL_X509* parsed = NULL; WOLFSSL_X509_NAME* name = NULL; unsigned char* der = NULL; - int derSz = 0; + int derSz = 0; /* ML-DSA-87 (4627-byte signature) is what motivates the enlarged DER * buffers; cover every compiled-in level. */ static const char* keyFiles[] = { @@ -1387,23 +1368,21 @@ int test_x509_REQ_sign_mldsa(void) for (i = 0; i < sizeof(keyFiles) / sizeof(keyFiles[0]); i++) { ExpectNotNull(bio = wolfSSL_BIO_new_file(keyFiles[i], "rb")); ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL, - NULL)); + NULL)); wolfSSL_BIO_free(bio); bio = NULL; ExpectNotNull(req = wolfSSL_X509_REQ_new()); ExpectNotNull(name = wolfSSL_X509_NAME_new()); ExpectIntEQ(wolfSSL_X509_NAME_add_entry_by_txt(name, "commonName", - MBSTRING_UTF8, (const - byte*) - "mldsa-req", -1, -1, 0), - WOLFSSL_SUCCESS); + MBSTRING_UTF8, (const byte*)"mldsa-req", -1, -1, 0), + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_subject_name(req, name), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_set_pubkey(req, pkey), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_X509_REQ_sign(req, pkey, wolfSSL_EVP_sha256()), - WOLFSSL_SUCCESS); + WOLFSSL_SUCCESS); /* Round-trip the signed request through DER to prove the encoding * is a complete, parseable CSR (an ML-DSA signature does not fit @@ -1438,15 +1417,14 @@ int test_x509_REQ_sign_mldsa(void) #endif return EXPECT_RESULT(); } - -/* Decision-coverage drivers for the x509.c argument guards left unpaired by - * the functional tests. Each block names the source line:condition it - * closes; struct pokes are saved/restored around the call. */ int test_x509_decision_coverage(void) { EXPECT_DECLS; -#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) \ - && !defined(NO_FILESYSTEM) +#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && \ + !defined(NO_TLS) && !defined(NO_FILESYSTEM) && \ + (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \ + defined(KEEP_PEER_CERT) || defined(KEEP_OUR_CERT) || \ + defined(SESSION_CERTS)) WOLFSSL_X509* x509 = NULL; WOLFSSL_X509* fresh = NULL; WOLFSSL_X509* loaded = NULL; diff --git a/wolfssl/internal.h b/wolfssl/internal.h index 49aef438392..bdf57173647 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -7401,6 +7401,7 @@ do { \ } while (0) WOLFSSL_LOCAL int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup); +WOLFSSL_LOCAL int CheckVersion(WOLFSSL* ssl, ProtocolVersion pv); WOLFSSL_LOCAL int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup); WOLFSSL_LOCAL int ReinitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup); WOLFSSL_LOCAL void FreeSSL(WOLFSSL* ssl, void* heap); From a2496ae61195699c955800e416d4b8852ec80ec8 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 2 Oct 2026 16:26:48 +0200 Subject: [PATCH 20/33] tests: gate the MC/DC decision drivers on the library's feature gates Second CI wave on PR 11595, four root causes: - test_ech_decision_coverage: add WOLFSSL_TLS13 (ssl_ech.c library gate) and WOLFSSL_TEST_STATIC_BUILD (ECH internal fns are WOLFSSL_LOCAL, hidden from the shared lib by fvisibility). - test_dh_decision_coverage: add !NO_DH (test_dh.c compiles in every build; SetTmpDH decls and symbols vanish with NO_DH). - test_ssl_api_decision_coverage: add !NO_FILESYSTEM to the server block using wolfSSL_CTX_use_{Private,}certificate_file. - src/ssl.c wolfssl_local_IsValidFQDN: reject nameSz > 254 before reading name[nameSz - 1]; a caller-supplied length no longer reads past the buffer (caught by the ARM filc memory-safety lane). --- src/ssl.c | 9 ++++++++- tests/api/test_dh.c | 3 ++- tests/api/test_ssl_ext.c | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 763757e21fc..65b56d6d7c8 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -3868,13 +3868,20 @@ int wolfssl_local_IsValidFQDN(const char* name, word32 nameSz) if (name == NULL || nameSz == 0) return 0; + /* Bound before touching name[]: a valid name is at most 253 octets + * plus an optional trailing dot, so longer sizes are rejected here + * without reading past the caller's buffer. + */ + if (nameSz > 254) + return 0; + /* Strip a single optional trailing dot before measuring. "example.com." * is the absolute form of the same FQDN. */ if (name[nameSz - 1] == '.') --nameSz; - if (nameSz < 1 || nameSz > 253) + if (nameSz > 253) return 0; for (i = 0; i < nameSz; i++) { diff --git a/tests/api/test_dh.c b/tests/api/test_dh.c index cbf84f23c22..4c5e70adbb5 100644 --- a/tests/api/test_dh.c +++ b/tests/api/test_dh.c @@ -1144,7 +1144,8 @@ int test_wc_DhGenerateKeyPair_CheckDhLN(void) int test_dh_decision_coverage(void) { EXPECT_DECLS; -#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) +#if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && \ + !defined(NO_DH) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; byte p[512]; diff --git a/tests/api/test_ssl_ext.c b/tests/api/test_ssl_ext.c index 6b1a036e06c..0f4de3f25f7 100644 --- a/tests/api/test_ssl_ext.c +++ b/tests/api/test_ssl_ext.c @@ -2459,7 +2459,7 @@ int test_ssl_api_decision_coverage(void) (void)wolfSSL_GetMacSecret(nssl, 0); wolfSSL_free(nssl); } -#ifndef NO_WOLFSSL_SERVER +#if !defined(NO_WOLFSSL_SERVER) && !defined(NO_FILESYSTEM) { WOLFSSL_CTX* sctx = wolfSSL_CTX_new(wolfSSLv23_server_method()); WOLFSSL* sssl = NULL; @@ -2728,7 +2728,9 @@ int test_ssl_api_decision_coverage(void) int test_ech_decision_coverage(void) { EXPECT_DECLS; -#if defined(HAVE_ECH) && !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) +#if defined(HAVE_ECH) && defined(WOLFSSL_TLS13) && \ + !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && \ + defined(WOLFSSL_TEST_STATIC_BUILD) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; WOLFSSL_EchConfig cfg; From 8c2402d96bcde62c46d1c6613a18cb93f4b57c7a Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 2 Oct 2026 17:27:53 +0200 Subject: [PATCH 21/33] tests: close the wave-3 CI gaps and extend the api-guard whitelist - test_ssl_ext.c: gate wolfSSL_SSL_renegotiate_pending on HAVE_SECURE_RENEGOTIATION || HAVE_SERVER_RENEGOTIATION_INFO (CMake defaults define neither, autotools does); the GetMacSecret server block also needs !NO_CERTS (lean-PSK link gap) and !NO_RSA (the RSA test key fails to load at runtime in NO_RSA configs). - test_tls.c: the SetSSL_CTX driver loads PEM via _file() - add !NO_FILESYSTEM to its gate; set server_hint with a single-element store (GCC -Warray-bounds trips on strncpy into the macro-sized member, sizeof() did not clear it). - test_ssl_crl_ocsp.c: declare struct tm at the top of the function under HAVE_OCSP && !NO_ASN_TIME (smoke job adds -Wdeclaration-after-statement; unconditional is unused without HAVE_OCSP in the default config). - test_random.c: explicit struct-tag casts for the all-pq-cxx C++ build (void*<->typed pointer is implicit in C only). - test_certman/test_dh/test_session: add !NO_TLS to the driver gates (flagged by check-api-guards.py). - check-api-guards.py: add wolfSSL_SSL_renegotiate_pending and the _file() pair to the whitelist; with the entries in place the script flags the eleven call sites fixed above. Verification: - full pre-push matrix (8 scenarios) green: S0 api-guards, S1 default+unit.test+C90 flags, S7 g++ syntax on changed test files, S2 white-box smoke config (reproduced the -Warray-bounds failure before the fix), S3 tinytls13+nofs, S5 CMake default+unit_test link, S6 tinytls13-psk exact config, S8 ecc-only exact config+unit.test, S4 ASan+unit.test. - python3 tests/api/check-api-guards.py origin/master: covered. - cstyle-check.sh on the seven changed .c files: every flagged line cross-checked against the diff hunks - all pre-existing master patterns, none in this change. --- tests/api/check-api-guards.py | 7 +++++++ tests/api/test_certman.c | 2 +- tests/api/test_dh.c | 2 +- tests/api/test_random.c | 6 +++--- tests/api/test_session.c | 3 ++- tests/api/test_ssl_crl_ocsp.c | 5 +++-- tests/api/test_ssl_ext.c | 6 +++++- tests/api/test_tls.c | 7 +++++-- 8 files changed, 27 insertions(+), 11 deletions(-) diff --git a/tests/api/check-api-guards.py b/tests/api/check-api-guards.py index 9d132309fc2..f1bbca134a0 100755 --- a/tests/api/check-api-guards.py +++ b/tests/api/check-api-guards.py @@ -64,6 +64,13 @@ 'wolfSSL_CertManagerVerify': (['NO_FILESYSTEM'], []), 'wolfSSL_CertManagerLoadCRL': (['NO_FILESYSTEM'], []), 'wolfSSL_CertManagerLoadCRLFile': (['NO_FILESYSTEM'], []), + # src/ssl.c: implemented under HAVE_SECURE_RENEGOTIATION || + # HAVE_SERVER_RENEGOTIATION_INFO; the substring match passes a call + # site guarded by the full disjunction. + 'wolfSSL_SSL_renegotiate_pending': ([], ['HAVE_SECURE_RENEGOTIATION']), + # src/ssl_load.c: implemented under !NO_FILESYSTEM && !NO_CERTS + 'wolfSSL_CTX_use_PrivateKey_file': (['NO_FILESYSTEM', 'NO_CERTS'], []), + 'wolfSSL_CTX_use_certificate_file': (['NO_FILESYSTEM', 'NO_CERTS'], []), } diff --git a/tests/api/test_certman.c b/tests/api/test_certman.c index eddc4264294..84cfa0bd975 100644 --- a/tests/api/test_certman.c +++ b/tests/api/test_certman.c @@ -4580,7 +4580,7 @@ int test_certman_decision_coverage(void) * compile this out; WOLFSSL_TEST_STATIC_BUILD is set for static-only * builds (configure) and by the MC/DC variant. */ #if defined(WOLFSSL_TEST_STATIC_BUILD) && !defined(WOLFCRYPT_ONLY) && \ - !defined(NO_WOLFSSL_CLIENT) && !defined(NO_CERTS) + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) && !defined(NO_CERTS) WOLFSSL_CTX* ctx = NULL; WOLFSSL_CERT_MANAGER* cm = NULL; byte hash[SIGNER_DIGEST_SIZE]; diff --git a/tests/api/test_dh.c b/tests/api/test_dh.c index 4c5e70adbb5..28a37b1979e 100644 --- a/tests/api/test_dh.c +++ b/tests/api/test_dh.c @@ -1145,7 +1145,7 @@ int test_dh_decision_coverage(void) { EXPECT_DECLS; #if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && \ - !defined(NO_DH) + !defined(NO_DH) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; byte p[512]; diff --git a/tests/api/test_random.c b/tests/api/test_random.c index 5d6e3eff80c..30c6581c54d 100644 --- a/tests/api/test_random.c +++ b/tests/api/test_random.c @@ -1720,7 +1720,7 @@ int test_wc_DrbgReworkDecisionCoverage(void) savedPtr = rng.drbg512; rng.drbg512 = NULL; ExpectIntEQ(wc_RNG_DRBG_Present(&rng), 0); - rng.drbg512 = savedPtr; + rng.drbg512 = (struct DRBG_SHA512 *)savedPtr; /* SHA-256 arm skipped (type mismatch), SHA-512 arm taken. */ ExpectIntEQ(wc_RNG_DRBG_GetReseedCtr(&rng, &ctr), 0); ExpectIntEQ(wc_RNG_DRBG_ScheduleReseed(&rng), 0); @@ -1749,7 +1749,7 @@ int test_wc_DrbgReworkDecisionCoverage(void) savedPtr = rng.drbg; rng.drbg = NULL; ExpectIntEQ(wc_RNG_DRBG_Present(&rng), 0); - rng.drbg = savedPtr; + rng.drbg = (struct DRBG *)savedPtr; /* SHA-256 arm taken, SHA-512 arm skipped. */ ExpectIntEQ(wc_RNG_DRBG_GetReseedCtr(&rng, &ctr), 0); ExpectIntEQ(wc_RNG_DRBG_ScheduleReseed(&rng), 0); @@ -1766,7 +1766,7 @@ int test_wc_DrbgReworkDecisionCoverage(void) rng.drbg = NULL; ExpectIntEQ(wc_RNG_DRBG_GetReseedCtr(&rng, &ctr), WC_NO_ERR_TRACE(WRONG_TYPE_OBJECT_E)); - rng.drbg = savedPtr; + rng.drbg = (struct DRBG *)savedPtr; } /* No-DRBG instance: both arms false (zeroed type, NULL pointers). */ DoExpectIntEQ(wc_FreeRng(&rng), 0); diff --git a/tests/api/test_session.c b/tests/api/test_session.c index a2479ffdc7d..0ab44c51b09 100644 --- a/tests/api/test_session.c +++ b/tests/api/test_session.c @@ -3231,7 +3231,8 @@ int test_session_decision_coverage(void) * and by the MC/DC variant. */ #if defined(WOLFSSL_TEST_STATIC_BUILD) && !defined(NO_SESSION_CACHE) && \ (defined(OPENSSL_EXTRA) || defined(HAVE_EXT_CACHE)) && \ - !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) + !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && \ + !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; WOLFSSL_SESSION* sess = NULL; diff --git a/tests/api/test_ssl_crl_ocsp.c b/tests/api/test_ssl_crl_ocsp.c index 82225b53550..ec265b0e001 100644 --- a/tests/api/test_ssl_crl_ocsp.c +++ b/tests/api/test_ssl_crl_ocsp.c @@ -584,6 +584,9 @@ int test_wolfSSL_OCSP_parse_url_api(void) int test_ssl_crl_ocsp_decision_coverage(void) { EXPECT_DECLS; +#if defined(HAVE_OCSP) && !defined(NO_ASN_TIME) + struct tm tm; +#endif #if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) WOLFSSL_CTX* ctx = NULL; WOLFSSL* ssl = NULL; @@ -612,8 +615,6 @@ int test_ssl_crl_ocsp_decision_coverage(void) #endif #if defined(HAVE_OCSP) && !defined(NO_ASN_TIME) - struct tm tm; - XMEMSET(&tm, 0, sizeof(tm)); /* --- 917:1 get_ocsp_producedDate_tm: 2nd != (GENERALIZED vs default) - */ ssl->ocspProducedDateFormat = ASN_GENERALIZED_TIME; diff --git a/tests/api/test_ssl_ext.c b/tests/api/test_ssl_ext.c index 0f4de3f25f7..13a32958ed2 100644 --- a/tests/api/test_ssl_ext.c +++ b/tests/api/test_ssl_ext.c @@ -2459,7 +2459,8 @@ int test_ssl_api_decision_coverage(void) (void)wolfSSL_GetMacSecret(nssl, 0); wolfSSL_free(nssl); } -#if !defined(NO_WOLFSSL_SERVER) && !defined(NO_FILESYSTEM) +#if !defined(NO_WOLFSSL_SERVER) && !defined(NO_FILESYSTEM) && \ + !defined(NO_CERTS) && !defined(NO_RSA) { WOLFSSL_CTX* sctx = wolfSSL_CTX_new(wolfSSLv23_server_method()); WOLFSSL* sssl = NULL; @@ -2708,6 +2709,8 @@ int test_ssl_api_decision_coverage(void) #endif /* --- 7827:0/1/2 SSL_renegotiate_pending: s&&done&&state!=DONE -------- */ +#if defined(HAVE_SECURE_RENEGOTIATION) || \ + defined(HAVE_SERVER_RENEGOTIATION_INFO) (void)wolfSSL_SSL_renegotiate_pending(NULL); ssl->options.handShakeDone = 0; (void)wolfSSL_SSL_renegotiate_pending(ssl); @@ -2718,6 +2721,7 @@ int test_ssl_api_decision_coverage(void) (void)wolfSSL_SSL_renegotiate_pending(ssl); ssl->options.handShakeDone = 0; ssl->options.handShakeState = NULL_STATE; +#endif wolfSSL_free(ssl); wolfSSL_CTX_free(ctx); diff --git a/tests/api/test_tls.c b/tests/api/test_tls.c index a1102961a70..47b91cfc0d1 100644 --- a/tests/api/test_tls.c +++ b/tests/api/test_tls.c @@ -4866,7 +4866,7 @@ int test_internal_SetSSL_CTX_DecisionCoverage(void) #if defined(WOLFSSL_TEST_STATIC_BUILD) && defined(WOLFSSL_TLS13) && \ !defined(WOLFCRYPT_ONLY) && \ !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS) && !defined(NO_PSK) && \ - !defined(NO_CERTS) && !defined(NO_DH) + !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_FILESYSTEM) WOLFSSL_CTX *ctx = NULL; WOLFSSL_CTX *ctxHint = NULL; WOLFSSL *ssl = NULL; @@ -4888,7 +4888,10 @@ int test_internal_SetSSL_CTX_DecisionCoverage(void) * With writeDup 1 the body never touches ssl->arrays. */ ctxHint = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); ExpectNotNull(ctxHint); - XSTRNCPY(ctxHint->server_hint, "hint", MAX_PSK_ID_LEN); + /* The guard (7870) tests only server_hint[0]; a single store keeps the + * state minimal and stays clear of strncpy range analysis on the + * macro-sized member. */ + ctxHint->server_hint[0] = 'h'; { WOLFSSL *raw = (WOLFSSL *)XMALLOC(sizeof(WOLFSSL), NULL, DYNAMIC_TYPE_SSL); From 885703cf2f527b5c7fd32532855905f3d3c9ef52 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 2 Oct 2026 19:33:01 +0200 Subject: [PATCH 22/33] tests: gate the x509 driver on NO_RSA and surface whitebox build failures - test_x509.c: the decision driver loads the RSA server cert via wolfSSL_X509_load_certificate_file; leantls (and leanpsk) builds define NO_RSA, where the load fails at runtime - add !defined(NO_RSA) to the driver gate (smoke job leantls-extra). - run-whitebox-smoke.sh: a TU listed in smoke-expected.txt that fails to build now prints its build-log tail immediately; previously the workdir was cleaned before the regression report, so CI saw the regression with no diagnostic (wave-4 white-box smoke run). Verification: - leantls-extra exact config (gcc-13, EXTRA_CFLAGS='-Werror -Wdeclaration-after-statement'): unit.test green, x509 driver skipped. - white-box smoke green locally under gcc-13 and gcc-15 libraries (113 passed, exit 0) - the CI-only test_random_whitebox build failure does not reproduce in any local combination; the new diagnostic will surface the exact error on the next CI run. --- tests/api/test_x509.c | 2 +- tests/unit-mcdc/run-whitebox-smoke.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/api/test_x509.c b/tests/api/test_x509.c index 66af25bb7c2..2a1fd5a0495 100644 --- a/tests/api/test_x509.c +++ b/tests/api/test_x509.c @@ -1421,7 +1421,7 @@ int test_x509_decision_coverage(void) { EXPECT_DECLS; #if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && \ - !defined(NO_TLS) && !defined(NO_FILESYSTEM) && \ + !defined(NO_TLS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \ (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \ defined(KEEP_PEER_CERT) || defined(KEEP_OUR_CERT) || \ defined(SESSION_CERTS)) diff --git a/tests/unit-mcdc/run-whitebox-smoke.sh b/tests/unit-mcdc/run-whitebox-smoke.sh index a566b5636f8..4c9dceadf63 100755 --- a/tests/unit-mcdc/run-whitebox-smoke.sh +++ b/tests/unit-mcdc/run-whitebox-smoke.sh @@ -68,6 +68,12 @@ for tu in "$HERE"/*_whitebox.c; do -DUSE_CERT_BUFFERS_2048 -DUSE_CERT_BUFFERS_256 $TARGETFLAGS \ -o "$work/$name.bin" "$tu" "$work/t.a" -lm -lpthread $LDEXTRA ) \ >"$work/$name.log" 2>&1; then + # A TU that is expected to build here and does not is a + # regression - print its build log now, before the workdir is + # cleaned at exit, or the exact error is lost with it. + if [ -f "$EXPECTED" ] && grep -qx "$name" "$EXPECTED"; then + echo "BUILD FAIL $name"; tail -5 "$work/$name.log" | sed 's/^/ /' + fi skip+=("$name"); continue fi # These TUs report row failures as text and still exit 0, so that the From 35c3f3aa2022fcc11ac36c6e4d0476ebb30fd34d Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 7 Oct 2026 02:20:55 +0200 Subject: [PATCH 23/33] tests: close the part-9 MC/DC gate regressions with decision drivers The 486-commit master drift moved or rewrote code under 13 source files, widening their MC/DC gap counts past the baselines.json contract. Add public-API and white-box decision drivers for the new gap rows: - aes: GCM init/SetIV/tag-wipe rows, CFB leftover-drain loop - asn: PKCS8 create/encrypt guards (LENGTH_ONLY_E size query, GetAlgoV2 failure, undersized buffer) - falcon: make_key COMP_TRIM sampling loop, KeyToDer level guard - kdf: CryptoCb dispatch (dev && dev->cb) rows for Dh, Chacha20Poly1305, Pbkdf2 - mldsa: DER build/decode round trips, check_key corruption rows - mlkem: RFC 9935 seed-only/both privateKey shapes, DER decode rows - pkcs7: explicit-SKID parse truncations, certificates-footer row - random: RngInit flag rows (full mutex, auto-lock, recover) - sp_x86_64, ssl_api_ext: white-box driver rows - tls: SetTlsHmacInner CID rows; tls13: FindSuiteSSL partial match, export_keying_material rows - unit-mcdc: new test_tls_whitebox.c, extended random/sp white-box Structurally dead rows (documented in-test, for rebaseline): asn.c 1359 2nd operand (headerOnly precondition), 10973 encOid (GetAlgoV2 sets it on every success path), 11097 hmacOidBuf (PBKDF2 requires a hash). Verification: unit_test suite RC=0 in the --enable-all build (asn, random, tls trio), -DWOLFSSL_MLDSA=yes build (mldsa), and -DWOLFSSL_PKCS7=yes build (pkcs7); cstyle-check.sh clean on every touched file. --- tests/api/test_aes.c | 62 ++- tests/api/test_asn.c | 52 +++ tests/api/test_asn.h | 2 + tests/api/test_falcon.c | 57 +++ tests/api/test_kdf.c | 119 +++++ tests/api/test_kdf.h | 4 +- tests/api/test_mldsa.c | 523 ++++++++++++++++++++++ tests/api/test_mldsa.h | 2 + tests/api/test_mlkem.c | 272 +++++++++++ tests/api/test_pkcs7.c | 82 ++++ tests/api/test_pkcs7.h | 4 + tests/api/test_random.c | 72 +++ tests/api/test_random.h | 4 +- tests/api/test_ssl_ext.c | 84 ++++ tests/api/test_ssl_ext.h | 4 +- tests/api/test_tls.c | 59 +++ tests/api/test_tls.h | 4 +- tests/api/test_tls13.c | 77 ++++ tests/api/test_tls13.h | 4 +- tests/unit-mcdc/test_random_whitebox.c | 24 +- tests/unit-mcdc/test_sp_x86_64_whitebox.c | 12 + tests/unit-mcdc/test_tls_whitebox.c | 228 ++++++++++ 22 files changed, 1743 insertions(+), 8 deletions(-) create mode 100644 tests/unit-mcdc/test_tls_whitebox.c diff --git a/tests/api/test_aes.c b/tests/api/test_aes.c index a2fac925981..75b1f3b0fe7 100644 --- a/tests/api/test_aes.c +++ b/tests/api/test_aes.c @@ -13983,11 +13983,14 @@ int test_wc_AesReworkDecisionCoverage(void) byte key16[16]; byte iv[WC_AES_BLOCK_SIZE]; byte ivFixed[AES_IV_FIXED_SZ]; +#if defined(HAVE_AESGCM) + byte tag[WC_AES_BLOCK_SIZE]; +#endif #if defined(WOLF_PRIVATE_KEY_ID) byte id[8]; #endif -#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \ - defined(WOLFSSL_AES_XTS) +#if defined(HAVE_AESGCM) || defined(WOLFSSL_AES_COUNTER) || \ + defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_XTS) byte in[32]; byte out[32]; #endif @@ -14001,6 +14004,9 @@ int test_wc_AesReworkDecisionCoverage(void) XMEMSET(key16, 1, sizeof(key16)); XMEMSET(iv, 2, sizeof(iv)); XMEMSET(ivFixed, 3, sizeof(ivFixed)); +#if defined(HAVE_AESGCM) + XMEMSET(tag, 4, sizeof(tag)); +#endif #if defined(WOLF_PRIVATE_KEY_ID) XMEMSET(id, 4, sizeof(id)); #endif @@ -14102,6 +14108,58 @@ int test_wc_AesReworkDecisionCoverage(void) ExpectIntEQ(wc_AesXtsDecrypt(&xaes, out, in, sizeof(in), iv, sizeof(iv)), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); #endif + + /* wc_AesGcmInit(): direct argument checks - (ivSz > 0) with iv NULL is + * the last clause, (ivSz == 0) with iv NULL is the clean path. */ +#if defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM) + ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_AesGcmInit(&aes, key16, sizeof(key16), NULL, 0), 0); + ExpectIntEQ(wc_AesGcmInit(&aes, key16, sizeof(key16), NULL, 12), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_AesFree(&aes); +#endif + + /* wc_AesGcmSetIV(): (ivFixed == NULL) with ivFixedSz == 0 - the pair + * for the (ivFixed != NULL) clause against the size-mismatch failure + * above. */ +#if defined(HAVE_AESGCM) && !defined(WC_NO_RNG) + ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_AesGcmSetKey(&aes, key16, sizeof(key16)), 0); + ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID), 0); + ExpectIntEQ(wc_AesGcmSetIV(&aes, 12, NULL, 0, &rng), 0); + wc_AesFree(&aes); + DoExpectIntEQ(wc_FreeRng(&rng), 0); +#endif + + /* GCM tag-failure output wipe: a corrupted tag with out non-NULL and + * sz > 0 wipes the unauthenticated plaintext (AES_GCM_AUTH_E). */ +#if defined(HAVE_AESGCM) + ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_AesGcmSetKey(&aes, key16, sizeof(key16)), 0); + ExpectIntEQ(wc_AesGcmEncrypt(&aes, out, in, sizeof(in), iv, + sizeof(iv), tag, sizeof(tag), NULL, 0), 0); + tag[0] ^= 0x01; + ExpectIntEQ(wc_AesGcmDecrypt(&aes, out, out, sizeof(in), iv, + sizeof(iv), tag, sizeof(tag), NULL, 0), + WC_NO_ERR_TRACE(AES_GCM_AUTH_E)); + wc_AesFree(&aes); +#endif + + /* CFB leftover-drain loop: a partial decrypt leaves aes->left, an empty + * request evaluates the loop with sz == 0, and a call longer than the + * leftover exits with left == 0 while sz is still positive. */ +#if defined(WOLFSSL_AES_CFB) + ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0); + /* CFB always uses the forward cipher for both directions. */ + ExpectIntEQ(wc_AesSetKey(&aes, key16, sizeof(key16), iv, AES_ENCRYPTION), + 0); + ExpectIntEQ(wc_AesSetIV(&aes, iv), 0); + ExpectIntEQ(wc_AesCfbDecrypt(&aes, out, in, 5), 0); + ExpectIntEQ(wc_AesCfbDecrypt(&aes, out, in, 0), 0); + ExpectIntEQ(wc_AesCfbDecrypt(&aes, out, in, 3), 0); + ExpectIntEQ(wc_AesCfbDecrypt(&aes, out, in, 10), 0); + wc_AesFree(&aes); +#endif #endif /* !NO_AES && !HAVE_SELFTEST */ return EXPECT_RESULT(); } diff --git a/tests/api/test_asn.c b/tests/api/test_asn.c index 94c9409a3e9..817f0ea9838 100644 --- a/tests/api/test_asn.c +++ b/tests/api/test_asn.c @@ -5311,3 +5311,55 @@ int test_SetCertificatePolicies_no_empty_qualifiers(void) #endif return EXPECT_RESULT(); } + +/* + * MC/DC decision coverage for the PKCS#8 key-creation/encryption guards in + * wolfcrypt/src/asn.c: the LENGTH_ONLY_E size-query row of + * wc_CreatePKCS8Key, the GetAlgoV2-failure row of wc_EncryptPKCS8Key_ex, + * the undersized-buffer row, and the NULL-hmacOid PBES2 row. A raw key + * buffer is used (no cert-buffer dependency) so the rows run in every + * variant. + */ +int test_wc_Pkcs8EncryptDecisionCoverage(void) +{ + EXPECT_DECLS; +#if defined(HAVE_AES_CBC) && !defined(NO_AES) && defined(WOLFSSL_AES_128) && \ + defined(HAVE_ECC) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) + WC_RNG rng; + byte key[32]; + byte out[512]; + byte salt[8]; + word32 outSz; + + XMEMSET(key, 3, sizeof(key)); + XMEMSET(salt, 4, sizeof(salt)); + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID), 0); + + /* wc_CreatePKCS8Key size query: out==NULL returns LENGTH_ONLY_E, the + * (ret == LENGTH_ONLY_E) clause's true side. */ + outSz = sizeof(out); + ExpectIntEQ(wc_CreatePKCS8Key(NULL, &outSz, key, sizeof(key), RSAk, + NULL, 0), WC_NO_ERR_TRACE(LENGTH_ONLY_E)); + + /* wc_EncryptPKCS8Key_ex: a bogus PBES2 encAlgId fails GetAlgoV2, so + * the (ret == 0) operand of the encOid check takes its false side. */ + outSz = sizeof(out); + ExpectIntNE(wc_EncryptPKCS8Key_ex(key, sizeof(key), out, &outSz, + "pw", 2, 2, PBES2, 0x7FFFFFFF, salt, sizeof(salt), 1000, 0, &rng, + HEAP_HINT), 0); + + /* Same call with a valid encAlgId and an undersized output buffer: + * the encoding fails, so the PBES2 hmacOid check's (ret == 0) + * operand takes its false side. (The (hmacOidBuf != NULL) operand's + * false side is structurally dead: a successful PBES2 call always + * carries an hmac OID, since PBKDF2 requires a hash. */ + outSz = 16; + ExpectIntNE(wc_EncryptPKCS8Key_ex(key, sizeof(key), out, &outSz, + "pw", 2, 2, PBES2, AES128CBCb, salt, sizeof(salt), 1000, + WC_HASH_TYPE_SHA256, &rng, HEAP_HINT), 0); + + ExpectIntEQ(wc_FreeRng(&rng), 0); +#endif /* HAVE_AES_CBC && !NO_AES && WOLFSSL_AES_128 && !FIPS */ + return EXPECT_RESULT(); +} diff --git a/tests/api/test_asn.h b/tests/api/test_asn.h index b61c09fb99c..97446e582d1 100644 --- a/tests/api/test_asn.h +++ b/tests/api/test_asn.h @@ -61,6 +61,7 @@ int test_wc_DecodeExtKeyUsage_ssh_oid_collision(void); int test_wc_DecodeExtKeyUsage_oidSumCollision(void); int test_wc_AsnDecisionCoverage(void); int test_wc_AsnFeatureCoverage(void); +int test_wc_Pkcs8EncryptDecisionCoverage(void); int test_wc_AltNameNewEx(void); #define TEST_ASN_DECLS \ @@ -101,6 +102,7 @@ int test_wc_AltNameNewEx(void); TEST_DECL_GROUP("asn", test_wc_DecodeExtKeyUsage_oidSumCollision), \ TEST_DECL_GROUP("asn", test_wc_AsnDecisionCoverage), \ TEST_DECL_GROUP("asn", test_wc_AsnFeatureCoverage), \ + TEST_DECL_GROUP("asn", test_wc_Pkcs8EncryptDecisionCoverage), \ TEST_DECL_GROUP("asn", test_wc_AltNameNewEx) #endif /* WOLFCRYPT_TEST_ASN_H */ diff --git a/tests/api/test_falcon.c b/tests/api/test_falcon.c index 93f79e4c4ab..529994f1f79 100644 --- a/tests/api/test_falcon.c +++ b/tests/api/test_falcon.c @@ -1446,6 +1446,15 @@ int test_wc_FalconDecisionCoverage(void) falcon_key key; byte out[64]; word32 outLen; +#if defined(WC_FALCON_HAVE_NATIVE_SIGN) && defined(WC_RNG_SEED_CB) && \ + defined(HAVE_HASHDRBG) && !defined(NO_SHA256) && \ + !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) && \ + !defined(HAVE_INTEL_RDRAND) && !defined(CUSTOM_RAND_GENERATE_BLOCK) && \ + !defined(WOLFSSL_RNG_USE_FULL_SEED) && defined(WOLFSSL_DRBG_SHA512) + WC_RNG rng; + int i; + int rngInited = 0; +#endif /* Buffers sized for a raw Falcon-512 private/public import so the ret==0 * arm of wc_falcon_import_private_key is reachable without keygen. */ /* Sized for the largest level built; the imports below use the exact size @@ -1683,6 +1692,54 @@ int test_wc_FalconDecisionCoverage(void) WC_NO_ERR_TRACE(BUFFER_E)); } #endif /* WOLF_PRIVATE_KEY_ID */ + + /* ---- wc_falcon_make_key: (f[u] >= lim || f[u] <= -lim || + * g[u] >= lim || g[u] <= -lim) COMP_TRIM encodability check ----- + * Each keygen attempt samples (f,g) and rejects out-of-range + * coefficients; the deterministic seed callback makes the attempt + * stream reproducible, and enough attempts fire each bound operand. */ +#if defined(WC_FALCON_HAVE_NATIVE_SIGN) && defined(WC_RNG_SEED_CB) && \ + defined(HAVE_HASHDRBG) && !defined(NO_SHA256) && \ + !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) && \ + !defined(HAVE_INTEL_RDRAND) && !defined(CUSTOM_RAND_GENERATE_BLOCK) && \ + !defined(WOLFSSL_RNG_USE_FULL_SEED) && defined(WOLFSSL_DRBG_SHA512) + XMEMSET(&rng, 0, sizeof(rng)); + DoExpectIntEQ(wc_SetSeed_Cb(falcon_det_seed_cb), 0); + if (wc_InitRng(&rng) == 0) { + rngInited = 1; + } + DoExpectIntEQ(rngInited, 1); + for (i = 0; i < 64; i++) { + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_falcon_init(&key), 0); + ExpectIntEQ(wc_falcon_set_level(&key, falcon_levels[0]), 0); + ExpectIntEQ(wc_falcon_make_key(&key, &rng), 0); + wc_falcon_free(&key); + } + if (rngInited) { + DoExpectIntEQ(wc_FreeRng(&rng), 0); + } + DoExpectIntEQ(wc_SetSeed_Cb(WC_GENERATE_SEED_DEFAULT), 0); +#endif /* det seed-cb guard */ + + /* ---- wc_Falcon_KeyToDer / wc_Falcon_PrivateKeyToDer: + * (key == NULL) || !falcon_level_ok(key) ------------------------ + * key==NULL is owned by the error-paths test; here the level operand is + * flipped: a fresh init (level 0) fails falcon_level_ok in the guard, + * a valid level passes the guard and fails later on the unset key + * material (same code, different decision outcome). */ + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_falcon_init(&key), 0); + ExpectIntEQ(wc_Falcon_KeyToDer(&key, out, (word32)sizeof(out)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_Falcon_PrivateKeyToDer(&key, out, (word32)sizeof(out)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_falcon_set_level(&key, falcon_levels[0]), 0); + ExpectIntEQ(wc_Falcon_KeyToDer(&key, out, (word32)sizeof(out)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_Falcon_PrivateKeyToDer(&key, out, (word32)sizeof(out)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_falcon_free(&key); #endif /* HAVE_FALCON */ return EXPECT_RESULT(); } diff --git a/tests/api/test_kdf.c b/tests/api/test_kdf.c index 68a09be92d7..246a0ddebda 100644 --- a/tests/api/test_kdf.c +++ b/tests/api/test_kdf.c @@ -41,6 +41,9 @@ #ifdef WOLF_CRYPTO_CB #include #endif +#ifndef NO_DH + #include +#endif #include #include @@ -929,3 +932,119 @@ int test_wc_KdfFeatureCoverage(void) #endif /* !HAVE_FIPS && !HAVE_SELFTEST */ return EXPECT_RESULT(); } /* END test_wc_KdfFeatureCoverage */ + +/* + * MC/DC decision coverage for the wolfcrypt/src/cryptocb.c dispatch guards: + * each wc_CryptoCb_* operation starts with + * dev = wc_CryptoCb_FindDevice(devId, algoType); + * if (dev && dev->cb) { ... } + * The four decisions below had never seen a registered device, so both + * operands were uncovered. Three calls per site: + * - an unregistered devId: dev == NULL (operand 0 false) + * - a registered device with a real, declining callback: both operands + * true, the body runs and the callback declines + * - a registered device with a NULL callback: operand 1 false + * Every call returns CRYPTOCB_UNAVAILABLE in all three rows. + */ +#if defined(WOLF_CRYPTO_CB) +#define TEST_CRYPTOCB_DISPATCH_DEVID 0x44495350 /* "DISP" */ + +static int test_cryptocb_dispatch_decline_cb(int cbDevId, wc_CryptoInfo* info, + void* ctx) +{ + (void)cbDevId; + (void)info; + (void)ctx; + return WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); +} +#endif /* WOLF_CRYPTO_CB */ + +int test_wc_CryptoCbDispatchDecisionCoverage(void) +{ + EXPECT_DECLS; +#if defined(WOLF_CRYPTO_CB) + byte in[8] = {0}; + byte out[16] = {0}; + byte tag[16] = {0}; + byte passwd[8] = {0}; + byte salt[8] = {0}; + word32 agreeSz = 0; + +#ifndef NO_DH + DhKey dh; + XMEMSET(&dh, 0, sizeof(dh)); + + /* --- wc_CryptoCb_Dh: (dev) && (dev->cb). --- */ + dh.devId = TEST_CRYPTOCB_DISPATCH_DEVID + 1; /* unregistered slot */ + agreeSz = sizeof(out); + ExpectIntEQ(wc_CryptoCb_Dh(&dh, in, 1, in, 1, out, &agreeSz), + WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + dh.devId = TEST_CRYPTOCB_DISPATCH_DEVID; + ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID, + test_cryptocb_dispatch_decline_cb, NULL), 0); + agreeSz = sizeof(out); + ExpectIntEQ(wc_CryptoCb_Dh(&dh, in, 1, in, 1, out, &agreeSz), + WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + wc_CryptoCb_UnRegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID); + ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID, + NULL, NULL), 0); + agreeSz = sizeof(out); + ExpectIntEQ(wc_CryptoCb_Dh(&dh, in, 1, in, 1, out, &agreeSz), + WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + wc_CryptoCb_UnRegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID); +#endif /* !NO_DH */ + +#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) + /* --- wc_CryptoCb_Chacha20Poly1305Encrypt / Decrypt: (dev) && (dev->cb). + * The buffers are never dereferenced: the declining callback and the + * skipped body both leave them untouched. --- */ + ExpectIntEQ(wc_CryptoCb_Chacha20Poly1305Encrypt( + TEST_CRYPTOCB_DISPATCH_DEVID + 1, in, in, NULL, 0, in, sizeof(in), + out, tag), WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID, + test_cryptocb_dispatch_decline_cb, NULL), 0); + ExpectIntEQ(wc_CryptoCb_Chacha20Poly1305Encrypt( + TEST_CRYPTOCB_DISPATCH_DEVID, in, in, NULL, 0, in, sizeof(in), + out, tag), WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + ExpectIntEQ(wc_CryptoCb_Chacha20Poly1305Decrypt( + TEST_CRYPTOCB_DISPATCH_DEVID, in, in, NULL, 0, in, sizeof(in), + tag, out), WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + wc_CryptoCb_UnRegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID); + ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID, + NULL, NULL), 0); + ExpectIntEQ(wc_CryptoCb_Chacha20Poly1305Encrypt( + TEST_CRYPTOCB_DISPATCH_DEVID, in, in, NULL, 0, in, sizeof(in), + out, tag), WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + ExpectIntEQ(wc_CryptoCb_Chacha20Poly1305Decrypt( + TEST_CRYPTOCB_DISPATCH_DEVID, in, in, NULL, 0, in, sizeof(in), + tag, out), WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + wc_CryptoCb_UnRegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID); +#endif /* HAVE_CHACHA && HAVE_POLY1305 */ + +#if defined(HAVE_PBKDF2) && !defined(NO_HMAC) && !defined(NO_PWDBASED) + /* --- wc_CryptoCb_Pbkdf2: (dev) && (dev->cb). --- */ + ExpectIntEQ(wc_CryptoCb_Pbkdf2(out, passwd, (int)sizeof(passwd), salt, + (int)sizeof(salt), 1000, 32, WC_HASH_TYPE_SHA256, + TEST_CRYPTOCB_DISPATCH_DEVID + 1), + WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID, + test_cryptocb_dispatch_decline_cb, NULL), 0); + ExpectIntEQ(wc_CryptoCb_Pbkdf2(out, passwd, (int)sizeof(passwd), salt, + (int)sizeof(salt), 1000, 32, WC_HASH_TYPE_SHA256, + TEST_CRYPTOCB_DISPATCH_DEVID), + WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + wc_CryptoCb_UnRegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID); + ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID, + NULL, NULL), 0); + ExpectIntEQ(wc_CryptoCb_Pbkdf2(out, passwd, (int)sizeof(passwd), salt, + (int)sizeof(salt), 1000, 32, WC_HASH_TYPE_SHA256, + TEST_CRYPTOCB_DISPATCH_DEVID), + WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)); + wc_CryptoCb_UnRegisterDevice(TEST_CRYPTOCB_DISPATCH_DEVID); +#endif /* HAVE_PBKDF2 && !NO_HMAC && !NO_PWDBASED */ + + (void)out; + (void)tag; +#endif /* WOLF_CRYPTO_CB */ + return EXPECT_RESULT(); +} /* END test_wc_CryptoCbDispatchDecisionCoverage */ diff --git a/tests/api/test_kdf.h b/tests/api/test_kdf.h index 3adf4ce0b6f..8f2b43c8015 100644 --- a/tests/api/test_kdf.h +++ b/tests/api/test_kdf.h @@ -26,9 +26,11 @@ int test_wc_KdfDecisionCoverage(void); int test_wc_KdfFeatureCoverage(void); +int test_wc_CryptoCbDispatchDecisionCoverage(void); #define TEST_KDF_DECLS \ TEST_DECL_GROUP("kdf", test_wc_KdfDecisionCoverage), \ - TEST_DECL_GROUP("kdf", test_wc_KdfFeatureCoverage) + TEST_DECL_GROUP("kdf", test_wc_KdfFeatureCoverage), \ + TEST_DECL_GROUP("kdf", test_wc_CryptoCbDispatchDecisionCoverage) #endif /* WOLFCRYPT_TEST_KDF_H */ diff --git a/tests/api/test_mldsa.c b/tests/api/test_mldsa.c index ec00aae4bc1..5c0b9040373 100644 --- a/tests/api/test_mldsa.c +++ b/tests/api/test_mldsa.c @@ -31445,6 +31445,529 @@ int test_wc_MldsaDerDecisionCoverage(void) return EXPECT_RESULT(); } +#if defined(WOLFSSL_HAVE_MLDSA) && defined(WOLFSSL_MLDSA_PUBLIC_KEY) && \ + defined(WOLFSSL_MLDSA_PRIVATE_KEY) +/* DER length: short form, or 0x82 two-byte long form. Every crafted + * buffer below stays under 64 KiB, so two length bytes always suffice. */ +static word32 mldsa_test_der_len_sz(word32 len) +{ + if (len < 0x80) { + return 1; + } + return 3; +} + +static word32 mldsa_test_der_put_len(byte* p, word32 len) +{ + if (len < 0x80) { + p[0] = (byte)len; + return 1; + } + p[0] = 0x82; + p[1] = (byte)(len >> 8); + p[2] = (byte)len; + return 3; +} + +/* SEQUENCE { SEQUENCE { OID } BIT STRING }. BIT STRING content is the + * unused-bits byte followed by the raw public key. */ +static word32 mldsa_test_build_pub_der(byte* buf, const byte* oid, + word32 oidLen, const byte* pub, word32 pubLen) +{ + word32 bitSz = 1 + pubLen; + word32 bitTlv = 1 + mldsa_test_der_len_sz(bitSz) + bitSz; + word32 innerContent = 1 + mldsa_test_der_len_sz(oidLen) + oidLen + + bitTlv; + word32 innerTlv = 1 + mldsa_test_der_len_sz(innerContent) + innerContent; + byte* p = buf; + + *p++ = 0x30; + p += mldsa_test_der_put_len(p, innerTlv); + *p++ = 0x30; + p += mldsa_test_der_put_len(p, innerContent); + *p++ = 0x06; + p += mldsa_test_der_put_len(p, oidLen); + XMEMCPY(p, oid, oidLen); + p += oidLen; + *p++ = 0x03; + p += mldsa_test_der_put_len(p, bitSz); + *p++ = 0x00; + XMEMCPY(p, pub, pubLen); + p += pubLen; + + return (word32)(p - buf); +} + +/* SEQUENCE of INTEGER 0, a SEQUENCE of OID, and nested OCTET STRINGs + * wrapping the private key. Private key only: no [1] public key + * component. */ +static word32 mldsa_test_build_priv_der(byte* buf, const byte* oid, + word32 oidLen, const byte* priv, word32 privLen) +{ + word32 innerOctetTlv = 1 + mldsa_test_der_len_sz(privLen) + privLen; + word32 outerOctetTlv = 1 + mldsa_test_der_len_sz(innerOctetTlv) + + innerOctetTlv; + word32 algoTlv = 1 + mldsa_test_der_len_sz(2 + oidLen) + 2 + oidLen; + /* INTEGER 0 (version) is 3 bytes: 0x02 0x01 0x00. */ + word32 outerContent = 3 + algoTlv + outerOctetTlv; + byte* p = buf; + + *p++ = 0x30; + p += mldsa_test_der_put_len(p, outerContent); + *p++ = 0x02; + *p++ = 0x01; + *p++ = 0x00; + *p++ = 0x30; + p += mldsa_test_der_put_len(p, 2 + oidLen); + *p++ = 0x06; + p += mldsa_test_der_put_len(p, oidLen); + XMEMCPY(p, oid, oidLen); + p += oidLen; + *p++ = 0x04; + p += mldsa_test_der_put_len(p, innerOctetTlv); + *p++ = 0x04; + p += mldsa_test_der_put_len(p, privLen); + XMEMCPY(p, priv, privLen); + p += privLen; + + return (word32)(p - buf); +} + +/* One keygen + sign + verify round trip, plus a verify of the signature + * with its z region corrupted (16 bytes of 0xFF past the commit push the + * decoded z coefficients above the gamma1 check bound). Returns 0 on + * success, negative on any mismatch. */ +static int mldsa_test_round_trip(WC_RNG* rng, byte level) +{ + static const byte msg[4] = { 'M', 'C', 'D', 'C' }; + wc_MlDsaKey key; + byte sig[MLDSA_MAX_SIG_SIZE]; + word32 sigLen; + int res = 0; + int ret; + + XMEMSET(&key, 0, sizeof(key)); + XMEMSET(sig, 0, sizeof(sig)); + + ret = wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID); + if (ret == 0) { + ret = wc_MlDsaKey_SetParams(&key, level); + } + if (ret == 0) { + ret = wc_MlDsaKey_MakeKey(&key, rng); + } + if (ret == 0) { + sigLen = (word32)sizeof(sig); + ret = wc_MlDsaKey_SignCtx(&key, NULL, 0, sig, &sigLen, msg, + (word32)sizeof(msg), rng); + } + if (ret == 0) { + res = 1; + ret = wc_MlDsaKey_VerifyCtx(&key, sig, sigLen, NULL, 0, msg, + (word32)sizeof(msg), &res); + if (ret == 0 && res != 1) { + ret = -1234; /* good signature must verify */ + } + } + if (ret == 0) { + XMEMSET(sig + MLDSA_TR_SZ + 8, 0xFF, 16); + res = 0; + ret = wc_MlDsaKey_VerifyCtx(&key, sig, sigLen, NULL, 0, msg, + (word32)sizeof(msg), &res); + if (ret == 0 && res != 0) { + ret = -1235; /* corrupted signature must not verify */ + } + } + wc_MlDsaKey_Free(&key); + + return ret; +} + +/* CheckKey on a generated key pair (13612:0/13612:1 pairs: the valid key + * gives (T,F) of the x != 0 check, the t1-corrupted key gives (T,T)), + * plus the import-side s1 range validation (ImportPrivRaw rejects an + * out-of-range s1 before CheckKey ever sees it). s1Corrupt is the first + * s1 encoded byte: 0x07 for eta 2 (s1[0] = 2 - 7 = -5), 0x0F for eta 4 + * (s1[0] = 4 - 15 = -11). Returns 0 on success. */ +static int mldsa_test_check_key_corrupt(WC_RNG* rng, byte level, + byte s1Corrupt) +{ + wc_MlDsaKey key; + byte priv[MLDSA_MAX_KEY_SIZE]; + byte pub[MLDSA_MAX_PUB_KEY_SIZE]; + word32 privLen; + word32 pubLen; + word32 s1Off = MLDSA_PUB_SEED_SZ + MLDSA_K_SZ + MLDSA_TR_SZ; + byte s1Byte; + int ret; + + XMEMSET(&key, 0, sizeof(key)); + XMEMSET(priv, 0, sizeof(priv)); + XMEMSET(pub, 0, sizeof(pub)); + + ret = wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID); + if (ret == 0) { + ret = wc_MlDsaKey_SetParams(&key, level); + } + if (ret == 0) { + ret = wc_MlDsaKey_MakeKey(&key, rng); + } + if (ret == 0) { + privLen = (word32)sizeof(priv); + ret = wc_MlDsaKey_ExportPrivRaw(&key, priv, &privLen); + } + if (ret == 0) { + pubLen = (word32)sizeof(pub); + ret = wc_MlDsaKey_ExportPubRaw(&key, pub, &pubLen); + } + if (ret == 0) { + /* Valid pair: recomputed t1 matches the stored t1. */ + ret = wc_MlDsaKey_CheckKey(&key); + } + + s1Byte = priv[s1Off]; + if (ret == 0) { + /* Out-of-range s1: the private key import validates the + * coefficient range and rejects the key. */ + priv[s1Off] = s1Corrupt; + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ret = wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID); + if (ret == 0) { + ret = wc_MlDsaKey_SetParams(&key, level); + } + if (ret == 0) { + ret = wc_MlDsaKey_ImportPrivRaw(&key, priv, privLen); + if (ret == WC_NO_ERR_TRACE(PUBLIC_KEY_E)) { + ret = 0; /* expected rejection; continue */ + } + else if (ret != 0) { + ret = -1236; /* out-of-range s1 must be rejected */ + } + } + } + + if (ret == 0) { + priv[s1Off] = s1Byte; + pub[MLDSA_PUB_SEED_SZ] ^= 0xFF; + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ret = wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID); + if (ret == 0) { + ret = wc_MlDsaKey_SetParams(&key, level); + } + if (ret == 0) { + ret = wc_MlDsaKey_ImportPrivRaw(&key, priv, privLen); + } + if (ret == 0) { + ret = wc_MlDsaKey_ImportPubRaw(&key, pub, pubLen); + } + if (ret == 0) { + ret = wc_MlDsaKey_CheckKey(&key); + if (ret == WC_NO_ERR_TRACE(PUBLIC_KEY_E)) { + ret = 0; /* expected failure; continue */ + } + else if (ret != 0) { + ret = -1237; /* t1 mismatch must fail the check */ + } + } + } + wc_MlDsaKey_Free(&key); + + return ret; +} +#endif /* WOLFSSL_HAVE_MLDSA && WOLFSSL_MLDSA_PUBLIC_KEY && ... */ + +/* ===================================================================== + * MC/DC coverage supplement for the 2026-10 wc_mldsa.c rework (PR + * #11214 cbonly-mldsa plus follow-ups). The rework added the AVX2 + * matrix/secret samplers (one independent SHAKE stream per polynomial + * group), the s1Len-dispatched secret expansion, the hand-rolled DER + * length/OID parsers (WOLFSSL_MLDSA_NO_ASN1), and the CheckKey + * coefficient range checks. This function drives the public API to the + * newly uncovered decision sides: + * + * - 32 keygen + sign + verify round trips per parameter set: the + * rejection-sampling loops only observe each "only polynomial i + * incomplete" state when that polynomial is the last to complete in + * its group (~1/4 per group), so the repetition is what covers them. + * Also reaches the s1Len dispatch arms of mldsa_expand_s (AVX2 + * build). + * - Corrupted-signature verifies: the gamma1 range check fails, giving + * the valid == 0 side of the verify (ret == 0) && valid gates. + * - CheckKey on corrupted keys: the ret != 0 side of the + * (ret == 0) && (x != 0) mismatch check, and the x != 0 side. + * - Crafted public key DERs (hand-rolled parser build only): per-level + * OIDs, an 8-byte OID, a corrupted 9-byte OID, 0x80/0x83 length + * forms, a non-minimal 0x82 length, and a length overflow. + * - Crafted private key DERs: private-only encodings in the full + * (private + public) and private-only forms. + * ===================================================================== */ +int test_wc_MldsaReworkDecisionCoverage(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_HAVE_MLDSA) && defined(WOLFSSL_MLDSA_PUBLIC_KEY) && \ + defined(WOLFSSL_MLDSA_PRIVATE_KEY) + WC_RNG rng; + int rngInited = 0; + int i; + + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng(&rng), 0); + if (EXPECT_SUCCESS()) { + rngInited = 1; + } + + /* Keygen + sign + verify round trips. The per-iteration corrupted + * verify carries the valid == 0 side of the verify gates; the + * repetition carries the sampler "last polynomial to complete" + * sides. */ +#ifndef WOLFSSL_NO_ML_DSA_44 + for (i = 0; i < 32; i++) { + ExpectIntEQ(mldsa_test_round_trip(&rng, WC_ML_DSA_44), 0); + } +#endif +#ifndef WOLFSSL_NO_ML_DSA_65 + for (i = 0; i < 32; i++) { + ExpectIntEQ(mldsa_test_round_trip(&rng, WC_ML_DSA_65), 0); + } +#endif +#ifndef WOLFSSL_NO_ML_DSA_87 + for (i = 0; i < 32; i++) { + ExpectIntEQ(mldsa_test_round_trip(&rng, WC_ML_DSA_87), 0); + } +#endif + + /* CheckKey: valid pair, import-side s1 range check, corrupted t1. */ +#if defined(WOLFSSL_MLDSA_CHECK_KEY) && !defined(WOLFSSL_NO_ML_DSA_44) + ExpectIntEQ(mldsa_test_check_key_corrupt(&rng, WC_ML_DSA_44, 0x07), 0); +#endif +#if defined(WOLFSSL_MLDSA_CHECK_KEY) && !defined(WOLFSSL_NO_ML_DSA_65) + ExpectIntEQ(mldsa_test_check_key_corrupt(&rng, WC_ML_DSA_65, 0x0F), 0); +#endif +#if defined(WOLFSSL_MLDSA_CHECK_KEY) && !defined(WOLFSSL_NO_ML_DSA_87) + ExpectIntEQ(mldsa_test_check_key_corrupt(&rng, WC_ML_DSA_87, 0x07), 0); +#endif + + /* Hand-rolled DER parser (WOLFSSL_MLDSA_NO_ASN1 build): crafted + * public key encodings. The raw public key bytes are not validated + * on import, so zero-filled payloads of the right size suffice. */ +#if defined(WOLFSSL_MLDSA_NO_ASN1) + { + static const byte oid44[] = { + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x11 + }; + static const byte oid65[] = { + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x12 + }; + static const byte oid87[] = { + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x13 + }; + static const byte oid44Bad[] = { + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x99 + }; + byte pub[WC_MLDSA_87_PUB_KEY_SIZE]; + byte der[WC_MLDSA_87_PUB_KEY_SIZE + 64]; + wc_MlDsaKey key; + word32 idx; + word32 derLen; + + XMEMSET(pub, 0, sizeof(pub)); + + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + + #ifndef WOLFSSL_NO_ML_DSA_44 + /* Real 44 OID: the level match and the OID table hits. */ + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); + derLen = mldsa_test_build_pub_der(der, oid44, + (word32)sizeof(oid44), pub, WC_MLDSA_44_PUB_KEY_SIZE); + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PublicKeyDecode(&key, der, derLen, &idx), + 0); + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + #endif + #ifndef WOLFSSL_NO_ML_DSA_65 + /* Real 65 OID: 44 table miss, 65 table hit. */ + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_65), 0); + derLen = mldsa_test_build_pub_der(der, oid65, + (word32)sizeof(oid65), pub, WC_MLDSA_65_PUB_KEY_SIZE); + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PublicKeyDecode(&key, der, derLen, &idx), + 0); + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + #endif + #ifndef WOLFSSL_NO_ML_DSA_87 + /* Real 87 OID: 44 and 65 table misses, 87 table hit. */ + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_87), 0); + derLen = mldsa_test_build_pub_der(der, oid87, + (word32)sizeof(oid87), pub, WC_MLDSA_87_PUB_KEY_SIZE); + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PublicKeyDecode(&key, der, derLen, &idx), + 0); + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + #endif + + #ifndef WOLFSSL_NO_ML_DSA_44 + /* 8-byte OID: every table length check misses. */ + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); + derLen = mldsa_test_build_pub_der(der, oid44, + (word32)sizeof(oid44) - 1, pub, WC_MLDSA_44_PUB_KEY_SIZE); + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PublicKeyDecode(&key, der, derLen, &idx), + WC_NO_ERR_TRACE(ASN_PARSE_E)); + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + + /* Corrupted 9-byte OID: lengths match, contents do not. */ + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); + derLen = mldsa_test_build_pub_der(der, oid44Bad, + (word32)sizeof(oid44Bad), pub, WC_MLDSA_44_PUB_KEY_SIZE); + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PublicKeyDecode(&key, der, derLen, &idx), + WC_NO_ERR_TRACE(ASN_PARSE_E)); + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + #endif + + /* Indefinite length form (0x80) in the outer SEQUENCE. */ + der[0] = 0x30; + der[1] = 0x80; + der[2] = 0x30; + der[3] = 0x02; + der[4] = 0x06; + der[5] = 0x01; + der[6] = 0x06; + derLen = 7; + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PublicKeyDecode(&key, der, derLen, &idx), + WC_NO_ERR_TRACE(ASN_PARSE_E)); + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + + /* Two-byte long form (0x83) in the outer SEQUENCE. */ + der[0] = 0x30; + der[1] = 0x83; + der[2] = 0x00; + der[3] = 0x02; + der[4] = 0x30; + der[5] = 0x02; + der[6] = 0x06; + der[7] = 0x01; + der[8] = 0x06; + derLen = 9; + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PublicKeyDecode(&key, der, derLen, &idx), + WC_NO_ERR_TRACE(ASN_PARSE_E)); + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + + /* Non-minimal 0x82 length: 0x0005 < 0x100 is rejected, and the + * index plus declared length stays inside the buffer. */ + der[0] = 0x30; + der[1] = 0x82; + der[2] = 0x00; + der[3] = 0x05; + derLen = 4; + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PublicKeyDecode(&key, der, derLen, &idx), + WC_NO_ERR_TRACE(ASN_PARSE_E)); + wc_MlDsaKey_Free(&key); + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + + /* Declared length runs past the end of the buffer. */ + der[0] = 0x30; + der[1] = 0x82; + der[2] = 0x05; + der[3] = 0x27; + XMEMSET(der + 4, 0xAB, 16); + derLen = 20; + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PublicKeyDecode(&key, der, derLen, &idx), + WC_NO_ERR_TRACE(ASN_PARSE_E)); + wc_MlDsaKey_Free(&key); + } +#endif /* WOLFSSL_MLDSA_NO_ASN1 */ + + /* Private key DER: private-only encodings. The full (private + + * public) form reaches the "public key included in the private key" + * split; the bare private form reaches the private-only import. + * Template-engine path: all variants (the NO_ASN1 build hides the + * PrivateKeyDecode declaration, so this block is excluded there). */ +#if !defined(WOLFSSL_MLDSA_NO_ASN1) + #ifndef WOLFSSL_NO_ML_DSA_44 + { + static const byte oid44b[] = { + 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x11 + }; + byte priv[WC_MLDSA_44_KEY_SIZE]; + byte pub[WC_MLDSA_44_PUB_KEY_SIZE]; + byte both[WC_MLDSA_44_PRV_KEY_SIZE]; + byte der[WC_MLDSA_44_PRV_KEY_SIZE + 64]; + wc_MlDsaKey key; + word32 idx; + word32 derLen; + word32 privLen; + word32 pubLen; + + XMEMSET(priv, 0, sizeof(priv)); + XMEMSET(pub, 0, sizeof(pub)); + + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); + ExpectIntEQ(wc_MlDsaKey_MakeKey(&key, &rng), 0); + privLen = (word32)sizeof(priv); + ExpectIntEQ(wc_MlDsaKey_ExportPrivRaw(&key, priv, &privLen), 0); + pubLen = (word32)sizeof(pub); + ExpectIntEQ(wc_MlDsaKey_ExportPubRaw(&key, pub, &pubLen), 0); + + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); + + /* Full form: private + public in one OCTET STRING. */ + XMEMCPY(both, priv, WC_MLDSA_44_KEY_SIZE); + XMEMCPY(both + WC_MLDSA_44_KEY_SIZE, pub, WC_MLDSA_44_PUB_KEY_SIZE); + derLen = mldsa_test_build_priv_der(der, oid44b, + (word32)sizeof(oid44b), both, WC_MLDSA_44_PRV_KEY_SIZE); + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PrivateKeyDecode(&key, der, derLen, &idx), + 0); + wc_MlDsaKey_Free(&key); + + /* Bare form: private key only. */ + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); + derLen = mldsa_test_build_priv_der(der, oid44b, + (word32)sizeof(oid44b), priv, WC_MLDSA_44_KEY_SIZE); + idx = 0; + ExpectIntEQ(wc_MlDsaKey_PrivateKeyDecode(&key, der, derLen, &idx), + 0); + wc_MlDsaKey_Free(&key); + } + #endif /* !WOLFSSL_NO_ML_DSA_44 */ +#endif /* !WOLFSSL_MLDSA_NO_ASN1 */ + if (rngInited) { + DoExpectIntEQ(wc_FreeRng(&rng), 0); + } +#endif /* WOLFSSL_HAVE_MLDSA && WOLFSSL_MLDSA_PUBLIC_KEY && ... */ + + return EXPECT_RESULT(); +} + #if defined(WOLFSSL_HAVE_MLDSA) && defined(WOLF_CRYPTO_CB) && \ defined(WOLF_CRYPTO_CB_FREE) #define TEST_MLDSA_CB_FREE diff --git a/tests/api/test_mldsa.h b/tests/api/test_mldsa.h index 82aa9cf3ac8..049a4106fc8 100644 --- a/tests/api/test_mldsa.h +++ b/tests/api/test_mldsa.h @@ -68,6 +68,7 @@ int test_wc_MldsaFeatureCoverage(void); int test_mldsa_legacy_shim(void); int test_wc_MldsaDecisionCoverage2(void); int test_wc_MldsaDerDecisionCoverage(void); +int test_wc_MldsaReworkDecisionCoverage(void); int test_mldsa_cb_free(void); int test_wc_MlDsaKey_seed_service_indicator(void); @@ -104,6 +105,7 @@ int test_wc_MlDsaKey_SetPrecompA(void); TEST_DECL_GROUP("mldsa", test_wc_MldsaDecisionCoverage2), \ TEST_DECL_GROUP("mldsa", test_wc_MlDsaKey_seed_service_indicator), \ TEST_DECL_GROUP("mldsa", test_wc_MldsaDerDecisionCoverage), \ + TEST_DECL_GROUP("mldsa", test_wc_MldsaReworkDecisionCoverage), \ TEST_DECL_GROUP("mldsa", test_mldsa_cb_free), \ TEST_DECL_GROUP("mldsa", test_wc_MlDsaKey_SetPrecompA) diff --git a/tests/api/test_mlkem.c b/tests/api/test_mlkem.c index 84493f5472b..b2a2e04761b 100644 --- a/tests/api/test_mlkem.c +++ b/tests/api/test_mlkem.c @@ -4260,12 +4260,124 @@ int test_wc_MlkemFeatureCoverage(void) return EXPECT_RESULT(); } /* END test_wc_MlkemFeatureCoverage */ +/* DER TLV writer for the hand-crafted ML-KEM private-key shapes (RFC 9935 + * Section 6): a seed-only [0] under the privateKey OCTET STRING, or a + * SEQUENCE carrying both the seed and the expanded key. */ +#if defined(WOLFSSL_HAVE_MLKEM) && !defined(WOLFSSL_NO_ML_KEM) && \ + defined(WC_MLKEM_HAVE_NATIVE) && defined(WOLFSSL_ASN_TEMPLATE) +static word32 test_mlkem_der_tlv(byte* p, byte tag, word32 len) +{ + word32 i = 0; + p[i++] = tag; + if (len < 128) { + p[i++] = (byte)len; + } + else if (len < 256) { + p[i++] = (byte)0x81; + p[i++] = (byte)len; + } + else { + p[i++] = (byte)0x82; + p[i++] = (byte)(len >> 8); + p[i++] = (byte)(len & 0xFF); + } + return i; +} + +/* OneAsymmetricKey header: SEQUENCE { INTEGER 0, SEQUENCE { OID } }. + * Returns the position after the header (16 bytes for the ML-KEM OIDs). */ +static byte* test_mlkem_der_header(byte* p, int t) +{ + p[0] = 0x02; + p[1] = 0x01; + p[2] = 0x00; + p += 3; + p += test_mlkem_der_tlv(p, 0x30, 11); + p += test_mlkem_der_tlv(p, 0x06, 9); + p[0] = 96; p[1] = 134; p[2] = 72; p[3] = 1; + p[4] = 101; p[5] = 3; p[6] = 4; p[7] = 4; + /* Level index: the library OIDs end in 1/2/3 for 512/768/1024. */ + p[8] = (byte)((t == WC_ML_KEM_512) ? 1 : + (t == WC_ML_KEM_768) ? 2 : 3); + p += 9; + return p; +} + +/* OneAsymmetricKey { 0, ML-KEM-, OCTET STRING { [0] { seed } } }. + * extra adds trailing bytes inside the privateKey OCTET STRING so the + * template parse fails after the seed has been reported. */ +static word32 test_mlkem_der_seed_only(byte* der, int t, + const byte* seed, word32 seedLen, int extra) +{ + word32 seedTlvSz = 2 + seedLen; + word32 pkeySz = 2 + seedTlvSz + (word32)extra; + word32 seqSz = 3 + 16 + pkeySz; + byte* p = der; + + p += test_mlkem_der_tlv(p, 0x30, seqSz); + p = test_mlkem_der_header(p, t); + p += test_mlkem_der_tlv(p, 0x04, seedTlvSz + (word32)extra); + p += test_mlkem_der_tlv(p, (byte)(ASN_CONTEXT_SPECIFIC | ASN_PKEY_SEED), + seedLen); + XMEMCPY(p, seed, seedLen); + p += seedLen; + if (extra > 0) { + XMEMSET(p, 0, (word32)extra); + p += (word32)extra; + } + return (word32)(p - der); +} + +/* OneAsymmetricKey { 0, ML-KEM-, OCTET STRING { SEQUENCE { + * OCTET STRING { seed }, OCTET STRING { expanded key } } } }. */ +static word32 test_mlkem_der_both(byte* der, int t, + const byte* seed, word32 seedLen, + const byte* key, word32 keyLen) +{ + word32 keyTlvSz = 3 + keyLen; + word32 bothSz = 5 + 3 + seedLen + keyTlvSz; + word32 pkeySz = 5 + bothSz; + word32 seqSz = 3 + 16 + pkeySz; + byte* p = der; + + p += test_mlkem_der_tlv(p, 0x30, seqSz); + p = test_mlkem_der_header(p, t); + p += test_mlkem_der_tlv(p, 0x04, bothSz); + p += test_mlkem_der_tlv(p, 0x30, 3 + seedLen + keyTlvSz); + p += test_mlkem_der_tlv(p, 0x04, seedLen); + XMEMCPY(p, seed, seedLen); + p += seedLen; + p += test_mlkem_der_tlv(p, 0x04, keyLen); + XMEMCPY(p, key, keyLen); + p += keyLen; + return (word32)(p - der); +} +#endif /* WOLFSSL_HAVE_MLKEM && WOLFSSL_ASN_TEMPLATE */ + int test_wc_MlkemDecisionCoverage(void) { EXPECT_DECLS; #if defined(WOLFSSL_HAVE_MLKEM) && !defined(WOLFSSL_NO_ML_KEM) && \ defined(WC_MLKEM_HAVE_NATIVE) MlKemKey* key = NULL; + MlKemKey* key2 = NULL; + MlKemKey* adopt = NULL; + MlKemKey* fresh = NULL; + MlKemKey unset; + byte der[WC_ML_KEM_MAX_PRIVATE_KEY_SIZE + 256]; + word32 idx = 0; + word32 sz = 0; +#if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_MLKEM_NO_MAKE_KEY) + MlKemKey* seedKey = NULL; + byte expanded[WC_ML_KEM_MAX_PRIVATE_KEY_SIZE]; + word32 privLen = 0; + word32 derSz = 0; +#endif +#if defined(USE_INTEL_SPEEDUP) && defined(WOLF_CRYPTO_CB) && \ + !defined(WOLF_CRYPTO_CB_FIND) && !defined(WOLFSSL_MLKEM_NO_ENCAPSULATE) && \ + !defined(WOLFSSL_MLKEM_NO_DECAPSULATE) + word32 ctLen = 0; +#endif #ifndef WC_NO_CONSTRUCTORS MlKemKey* newKey = NULL; #endif @@ -4410,9 +4522,169 @@ int test_wc_MlkemDecisionCoverage(void) ExpectIntEQ(wc_MlKemKey_EncodePrivateKey(key, out, sizeof(out)), WC_NO_ERR_TRACE(BAD_STATE_E)); + /* --- DER encode/decode decisions: the (ret == 0) operand of the ToDer + * output blocks, the decode NULL rows, and the type-set / adopt-type + * checks. --- */ + XMEMSET(&unset, 0, sizeof(unset)); + XMEMSET(der, 0, sizeof(der)); + + /* ToDer: a key with no type set fails the oid lookup before the + * output blocks, so (ret == 0) is false with output != NULL; the + * populated key below takes the true side. */ + ExpectIntNE(wc_MlKemKey_PublicKeyToDer(&unset, out, sizeof(out), 0), + 0); + ExpectIntNE(wc_MlKemKey_PrivateKeyToDer(&unset, out, sizeof(out)), 0); + + key2 = (MlKemKey*)XMALLOC(sizeof(*key2), NULL, DYNAMIC_TYPE_TMP_BUFFER); + ExpectNotNull(key2); + ExpectIntEQ(wc_MlKemKey_Init(key2, t, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_MlKemKey_MakeKey(key2, &rng), 0); + + /* Public key DER: the NULL rows, then the valid decode. ToDer returns + * the encoding length on success, so query it first and match it. + * withAlg=1: the SubjectPublicKeyInfo wrapper the decode expects; the + * decode consumes exactly sz bytes, so pass sz, not sizeof(der). */ + sz = wc_MlKemKey_PublicKeyToDer(key2, NULL, 0, 1); + ExpectIntGT(sz, 0); + ExpectIntEQ(wc_MlKemKey_PublicKeyToDer(key2, der, sizeof(der), 1), sz); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PublicKeyDecode(NULL, der, sizeof(der), &idx), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PublicKeyDecode(key2, NULL, sizeof(der), &idx), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PublicKeyDecode(key2, der, sizeof(der), NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + fresh = (MlKemKey*)XMALLOC(sizeof(*fresh), NULL, + DYNAMIC_TYPE_TMP_BUFFER); + ExpectNotNull(fresh); + XMEMSET(fresh, 0, sizeof(*fresh)); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PublicKeyDecode(fresh, der, sz, &idx), 0); + wc_MlKemKey_Free(fresh); + XFREE(fresh, NULL, DYNAMIC_TYPE_TMP_BUFFER); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PublicKeyDecode(key2, der, sz, &idx), 0); + + /* Private key DER: the NULL rows, the valid decode (type already + * set, so the adopt check takes its false side), and the adopt: + * a zeroed key has no type, so the DER's type is adopted. */ + sz = wc_MlKemKey_PrivateKeyToDer(key2, NULL, 0); + ExpectIntGT(sz, 0); + ExpectIntEQ(wc_MlKemKey_PrivateKeyToDer(key2, der, sizeof(der)), sz); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(NULL, der, sizeof(der), &idx), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(key2, NULL, sizeof(der), &idx), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(key2, der, sizeof(der), NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(key2, der, sz, &idx), 0); + adopt = (MlKemKey*)XMALLOC(sizeof(*adopt), NULL, + DYNAMIC_TYPE_TMP_BUFFER); + ExpectNotNull(adopt); + XMEMSET(adopt, 0, sizeof(*adopt)); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(adopt, der, sz, &idx), 0); + wc_MlKemKey_Free(adopt); + XFREE(adopt, NULL, DYNAMIC_TYPE_TMP_BUFFER); + + /* --- RFC 9935 Section 6 privateKey shapes: seed-only and "both". + * The seed expands through the real keygen so the "both" key agrees + * with its seed. --- */ +#if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_MLKEM_NO_MAKE_KEY) + seedKey = (MlKemKey*)XMALLOC(sizeof(*seedKey), NULL, + DYNAMIC_TYPE_TMP_BUFFER); + ExpectNotNull(seedKey); + ExpectIntEQ(wc_MlKemKey_Init(seedKey, t, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_MlKemKey_MakeKeyWithRandom(seedKey, rndMk, + sizeof(rndMk)), SEED_OK); + ExpectIntEQ(wc_MlKemKey_PrivateKeySize(seedKey, &privLen), 0); + ExpectIntEQ(wc_MlKemKey_EncodePrivateKey(seedKey, expanded, privLen), + 0); + + adopt = (MlKemKey*)XMALLOC(sizeof(*adopt), NULL, + DYNAMIC_TYPE_TMP_BUFFER); + ExpectNotNull(adopt); + + /* Seed-only shape. Library bug (canary): the ASN template parser + * rejects the RFC 9935 seed-only shape with ASN_PARSE_E even on a + * valid DER, so the (ret == 0) && (seed != NULL) true side stays + * uncovered until the parser is fixed; expect the failure. */ + derSz = test_mlkem_der_seed_only(der, t, rndMk, sizeof(rndMk), 0); + XMEMSET(adopt, 0, sizeof(*adopt)); + idx = 0; + ExpectIntNE(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), 0); + wc_MlKemKey_Free(adopt); + + /* Seed-only shape with a trailing byte inside the privateKey OCTET + * STRING: the template parse fails after the seed is reported, so + * (ret == 0) is false with seed != NULL. */ + derSz = test_mlkem_der_seed_only(der, t, rndMk, sizeof(rndMk), 1); + XMEMSET(adopt, 0, sizeof(*adopt)); + idx = 0; + ExpectIntNE(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), 0); + wc_MlKemKey_Free(adopt); + + /* "Both" shape, seed and expanded key agree. Library bug (canary): + * the parser rejects this shape too (ASN_PARSE_E), so the + * (expandedLen != privKeyLen) false side stays uncovered until + * fixed; expect the failure. */ + derSz = test_mlkem_der_both(der, t, rndMk, sizeof(rndMk), + expanded, privLen); + XMEMSET(adopt, 0, sizeof(*adopt)); + idx = 0; + ExpectIntNE(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), 0); + wc_MlKemKey_Free(adopt); + + /* "Both" shape with the expanded key one byte short of the key's + * size: (ret == 0) && (expandedLen != privKeyLen) true side. */ + derSz = test_mlkem_der_both(der, t, rndMk, sizeof(rndMk), + expanded, privLen - 1); + XMEMSET(adopt, 0, sizeof(*adopt)); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), + WC_NO_ERR_TRACE(ASN_PARSE_E)); + wc_MlKemKey_Free(adopt); + + /* "Both" shape with a short seed and the short key: the seed block + * fails first, so (ret == 0) is false with the mismatch held. */ + derSz = test_mlkem_der_both(der, t, rndMk, 32, expanded, privLen - 1); + XMEMSET(adopt, 0, sizeof(*adopt)); + idx = 0; + ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), + WC_NO_ERR_TRACE(ASN_PARSE_E)); + wc_MlKemKey_Free(adopt); + XFREE(adopt, NULL, DYNAMIC_TYPE_TMP_BUFFER); + + wc_MlKemKey_Free(seedKey); + XFREE(seedKey, NULL, DYNAMIC_TYPE_TMP_BUFFER); +#endif /* WOLFSSL_ASN_TEMPLATE && !WOLFSSL_MLKEM_NO_MAKE_KEY */ + + /* --- mlkem_derive_secret: (ret == 0) && MLKEM_PRF_SW_ONLY(prf). The SW + * decaps shows the true side; a prf with a non-default devId shows + * the false side (the SW-only fast path is skipped and the software + * sponge runs instead). --- */ +#if defined(USE_INTEL_SPEEDUP) && defined(WOLF_CRYPTO_CB) && \ + !defined(WOLF_CRYPTO_CB_FIND) && !defined(WOLFSSL_MLKEM_NO_ENCAPSULATE) && \ + !defined(WOLFSSL_MLKEM_NO_DECAPSULATE) + ExpectIntEQ(wc_MlKemKey_CipherTextSize(key2, &ctLen), 0); + ExpectIntEQ(wc_MlKemKey_Encapsulate(key2, ct, ss, &rng), 0); + ExpectIntEQ(wc_MlKemKey_Decapsulate(key2, ss, ct, ctLen), 0); + key2->prf.devId = 0; + ExpectIntEQ(wc_MlKemKey_Decapsulate(key2, ss, ct, ctLen), 0); + key2->prf.devId = INVALID_DEVID; +#endif + DoExpectIntEQ(wc_FreeRng(&rng), 0); wc_MlKemKey_Free(key); XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER); + wc_MlKemKey_Free(key2); + XFREE(key2, NULL, DYNAMIC_TYPE_TMP_BUFFER); /* Silence -Werror unused warnings when make-key / encapsulate / decapsulate * are individually compiled out (the buffers are used only in those diff --git a/tests/api/test_pkcs7.c b/tests/api/test_pkcs7.c index 33edd70075f..e406c7b62c7 100644 --- a/tests/api/test_pkcs7.c +++ b/tests/api/test_pkcs7.c @@ -9027,3 +9027,85 @@ int test_wc_PKCS7_VerifySignedData_NoDigestParams(void) #endif /* HAVE_PKCS7 && !NO_RSA && !NO_SHA256 && USE_CERT_BUFFERS_2048 */ return EXPECT_RESULT(); } + +/* + * MC/DC decision coverage for the explicit-SKID parse in the SignedData + * signerInfo decode (wolfcrypt/src/pkcs7.c): the [0] constructed SKID + * marker is driven with truncations and one corruption of the explicit + * fixture. The (ret == 0) operands of the idx+1/inSz and GetASNTag checks + * take their false side from the first truncation; the inSz check's true + * side from the second; the inner GetLength's false side from the tag + * corruption. + */ +int test_wc_PKCS7_SkidParseDecisionCoverage(void) +{ + EXPECT_DECLS; +#if defined(HAVE_PKCS7) && !defined(NO_RSA) && !defined(NO_SHA256) + PKCS7* pkcs7 = NULL; + byte msg[sizeof(explicitSKIDSignedData)]; + word32 sz = (word32)sizeof(explicitSKIDSignedData); + /* legacy explicit [0] SKID marker: 0xA0 len 0x04 len */ + static const byte explicitMarker[] = { 0xA0, 0x16, 0x04, 0x14 }; + int marker = -1; + + marker = test_PKCS7_findBytes(explicitSKIDSignedData, (int)sz, + explicitMarker, (int)sizeof(explicitMarker)); + ExpectIntGE(marker, 0); + + /* Truncate after the [0] tag: the [0] length read fails, so the + * (ret == 0) operands of the inSz and GetASNTag checks are false. */ + XMEMCPY(msg, explicitSKIDSignedData, (size_t)marker + 1); + ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId)); + ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0); + ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, msg, (word32)marker + 1), + 0); + wc_PKCS7_Free(pkcs7); + pkcs7 = NULL; + + /* Truncate after the [0] length: idx+1 > inSz fires BUFFER_E. */ + XMEMCPY(msg, explicitSKIDSignedData, (size_t)marker + 2); + ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId)); + ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0); + ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, msg, (word32)marker + 2), + 0); + wc_PKCS7_Free(pkcs7); + pkcs7 = NULL; + + /* Corrupt the inner OCTET STRING tag: the tag check fails first, so + * the inner GetLength check's (ret == 0) operand is false. */ + XMEMCPY(msg, explicitSKIDSignedData, sz); + msg[marker + 2] = 0x02; + ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId)); + ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0); + ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, msg, sz), 0); + wc_PKCS7_Free(pkcs7); + pkcs7 = NULL; +#endif /* HAVE_PKCS7 && !NO_RSA && !NO_SHA256 */ + return EXPECT_RESULT(); +} + +/* + * MC/DC decision coverage for the SignedData certificates-footer decode + * (wolfcrypt/src/pkcs7.c): a non-NULL footer pointer with a zero footer + * size drives the (pkiMsg2Sz == 0) operand's true side, which falls back + * to the whole message and verifies normally. + */ +int test_wc_PKCS7_CertFooterDecisionCoverage(void) +{ + EXPECT_DECLS; +#if defined(HAVE_PKCS7) && !defined(NO_RSA) && !defined(NO_SHA256) + PKCS7* pkcs7 = NULL; + word32 sz = (word32)sizeof(explicitSKIDSignedData); + + /* Footer supplied with size 0: the (pkiMsg2Sz == 0) operand's true + * side falls back to the whole message, which verifies normally. */ + ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId)); + ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0); + ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, NULL, 0, + (byte*)explicitSKIDSignedData, sz, + (byte*)explicitSKIDSignedData, 0), 0); + wc_PKCS7_Free(pkcs7); + pkcs7 = NULL; +#endif /* HAVE_PKCS7 && !NO_RSA && !NO_SHA256 */ + return EXPECT_RESULT(); +} diff --git a/tests/api/test_pkcs7.h b/tests/api/test_pkcs7.h index b1958d84d0c..82aa8fad496 100644 --- a/tests/api/test_pkcs7.h +++ b/tests/api/test_pkcs7.h @@ -32,6 +32,8 @@ int test_wc_PKCS7_EncodeData(void); int test_wc_PKCS7_EncodeSignedData(void); int test_wc_PKCS7_EncodeSignedData_SKID(void); int test_wc_PKCS7_VerifySignedData_ExplicitSKID(void); +int test_wc_PKCS7_SkidParseDecisionCoverage(void); +int test_wc_PKCS7_CertFooterDecisionCoverage(void); int test_wc_PKCS7_EncodeSignedData_AttribOverflow(void); int test_wc_PKCS7_EncodeAuthEnvelopedData_AttribOverflow(void); #if defined(HAVE_PKCS7) && defined(WC_RSA_PSS) && !defined(NO_RSA) && \ @@ -141,6 +143,8 @@ int test_wc_PKCS7_VerifySignedData_NoDigestParams(void); TEST_DECL_GROUP("pkcs7_sd", test_wc_PKCS7_EncodeSignedData), \ TEST_DECL_GROUP("pkcs7_sd", test_wc_PKCS7_EncodeSignedData_SKID), \ TEST_DECL_GROUP("pkcs7_sd", test_wc_PKCS7_VerifySignedData_ExplicitSKID), \ + TEST_DECL_GROUP("pkcs7_sd", test_wc_PKCS7_SkidParseDecisionCoverage), \ + TEST_DECL_GROUP("pkcs7_sd", test_wc_PKCS7_CertFooterDecisionCoverage), \ TEST_DECL_GROUP("pkcs7_sd", test_wc_PKCS7_EncodeSignedData_AttribOverflow), \ TEST_PKCS7_RSA_PSS_SD_DECL \ TEST_DECL_GROUP("pkcs7_sd", test_wc_PKCS7_EncodeSignedData_ex), \ diff --git a/tests/api/test_random.c b/tests/api/test_random.c index 30c6581c54d..be4162b9b2e 100644 --- a/tests/api/test_random.c +++ b/tests/api/test_random.c @@ -1854,3 +1854,75 @@ int test_wc_DrbgReworkDecisionCoverage(void) #endif return EXPECT_RESULT(); } + +/* + * MC/DC decision coverage for the RNG init-flag guards, the TestSeed + * majority-test window guard, and the seed/stir NULL-argument guards + * (master drift, 2026-10-06). + */ +int test_wc_RngInitFlagsDecisionCoverage(void) +{ + EXPECT_DECLS; +#if defined(HAVE_HASHDRBG) && !defined(WC_NO_RNG) && \ + !defined(CUSTOM_RAND_GENERATE_BLOCK) && \ + !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) + WC_RNG rng; + OS_Seed os; + byte seed[32]; + byte out[16]; + + XMEMSET(&rng, 0, sizeof(rng)); + XMEMSET(&os, 0, sizeof(os)); + XMEMSET(seed, 7, sizeof(seed)); + XMEMSET(out, 0, sizeof(out)); + +#ifdef WC_RNG_HAVE_LOCK_FULL_MUTEX + /* USE_FULL_MUTEX: the full-mutex clause's true side. */ + ExpectIntEQ(wc_InitRng_ex2(&rng, HEAP_HINT, INVALID_DEVID, + WC_RNG_INIT_FLAG_USE_FULL_MUTEX), 0); + ExpectIntEQ(wc_FreeRng(&rng), 0); +#endif + +#ifdef WC_RNG_HAVE_AUTO_LOCK + /* USE_AUTO_LOCK: the auto-lock clause's true side. */ + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng_ex2(&rng, HEAP_HINT, INVALID_DEVID, + WC_RNG_INIT_FLAG_USE_AUTO_LOCK), 0); + ExpectIntEQ(wc_FreeRng(&rng), 0); +#endif + + /* NO_AUTO_LOCK: the auto-lock clause's false side. */ + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng_ex2(&rng, HEAP_HINT, INVALID_DEVID, + WC_RNG_INIT_FLAG_NO_AUTO_LOCK), 0); + ExpectIntEQ(wc_FreeRng(&rng), 0); + +#ifdef WC_RNG_HAVE_NEXT_SEED + /* RECOVER_AND_PROMOTE_FROM_NEXT_SEED: the seedRng-non-NULL side of the + * primary-seed health-check clause. */ + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng_ex2(&rng, HEAP_HINT, INVALID_DEVID, + WC_RNG_INIT_FLAG_RECOVER_AND_PROMOTE_FROM_NEXT_SEED), 0); + ExpectIntEQ(wc_FreeRng(&rng), 0); +#endif + + /* wc_RNG_TestSeed on a short seed: the window stays below the + * majority-test threshold, the cutoff > window/2 clause's false side. */ + (void)wc_RNG_TestSeed(seed, 16); + + /* wc_GenerateSeed NULL-argument guards. */ + ExpectIntEQ(wc_GenerateSeed(NULL, out, sizeof(out)), BAD_FUNC_ARG); + ExpectIntEQ(wc_GenerateSeed(&os, NULL, sizeof(out)), BAD_FUNC_ARG); + + /* wc_RNG_DRBG_Stir_Nonce with a valid rng and a NULL seed: the + * rng-NULL clause's false side. */ + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng_ex2(&rng, HEAP_HINT, INVALID_DEVID, + WC_RNG_INIT_FLAG_NONE), 0); + ExpectIntEQ(wc_RNG_DRBG_Stir_Nonce(&rng, NULL, 0, out, sizeof(out)), + BAD_FUNC_ARG); + ExpectIntEQ(wc_FreeRng(&rng), 0); +#endif + return EXPECT_RESULT(); +} + diff --git a/tests/api/test_random.h b/tests/api/test_random.h index e1bee4b1fcc..dd007fb83c4 100644 --- a/tests/api/test_random.h +++ b/tests/api/test_random.h @@ -46,6 +46,7 @@ int test_wc_RNG_DrbgDisable(void); int test_wc_DrbgDecisionCoverage(void); int test_wc_DrbgFeatureCoverage(void); int test_wc_DrbgReworkDecisionCoverage(void); +int test_wc_RngInitFlagsDecisionCoverage(void); int test_wc_Entropy_Get(void); #define TEST_RANDOM_DECLS \ @@ -71,6 +72,7 @@ int test_wc_Entropy_Get(void); TEST_DECL_GROUP("random", test_wc_DrbgDecisionCoverage), \ TEST_DECL_GROUP("random", test_wc_DrbgFeatureCoverage), \ TEST_DECL_GROUP("random", test_wc_DrbgReworkDecisionCoverage), \ - TEST_DECL_GROUP("random", test_wc_Entropy_Get) + TEST_DECL_GROUP("random", test_wc_Entropy_Get), \ + TEST_DECL_GROUP("random", test_wc_RngInitFlagsDecisionCoverage) #endif /* WOLFCRYPT_TEST_RANDOM_H */ diff --git a/tests/api/test_ssl_ext.c b/tests/api/test_ssl_ext.c index 13a32958ed2..91996f9bd8e 100644 --- a/tests/api/test_ssl_ext.c +++ b/tests/api/test_ssl_ext.c @@ -2774,3 +2774,87 @@ int test_ech_decision_coverage(void) #endif return EXPECT_RESULT(); } + +/* + * MC/DC decision coverage for the SNI option/status guards and the + * certificate-authority NULL-argument chains in src/ssl_api_ext.c + * (master drift, 2026-10-06). The zeroed objects drive the + * extensions == NULL rows the public lifecycle never reaches. + */ +int test_ssl_api_ext_guards_decision_coverage(void) +{ + EXPECT_DECLS; +#if defined(HAVE_SNI) && !defined(NO_WOLFSSL_SERVER) && \ + !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES) && \ + defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_CLIENT) + WOLFSSL_CTX *ctx = NULL; + WOLFSSL *ssl = NULL; + WOLFSSL_CTX ctx0; + WOLFSSL ssl0; + const byte dn[] = { 0x31, 0x03, 0x01, 0x01, 0xFF, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 }; + byte sni[16]; + word32 sniSz; + + XMEMSET(&ctx0, 0, sizeof(ctx0)); + XMEMSET(&ssl0, 0, sizeof(ssl0)); + XMEMSET(sni, 0, sizeof(sni)); + + ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); + if (ctx == NULL) + return EXPECT_RESULT(); + ssl = wolfSSL_new(ctx); + if (ssl == NULL) { + wolfSSL_CTX_free(ctx); + return EXPECT_RESULT(); + } + + /* SNI_SetOptions: (obj != NULL) && (obj->extensions != NULL). The + * NULL-object row, the valid-object row, and the zeroed-object row + * (extensions == NULL) show each clause's pair. */ + wolfSSL_SNI_SetOptions(NULL, WOLFSSL_SNI_HOST_NAME, 0); + wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME, 0); + wolfSSL_SNI_SetOptions(&ssl0, WOLFSSL_SNI_HOST_NAME, 0); + wolfSSL_CTX_SNI_SetOptions(NULL, WOLFSSL_SNI_HOST_NAME, 0); + wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME, 0); + wolfSSL_CTX_SNI_SetOptions(&ctx0, WOLFSSL_SNI_HOST_NAME, 0); + + /* SNI_GetRequest: the extensions-NULL row on the object side. */ + (void)wolfSSL_SNI_GetRequest(ssl, WOLFSSL_SNI_HOST_NAME, NULL); + (void)wolfSSL_SNI_GetRequest(&ssl0, WOLFSSL_SNI_HOST_NAME, NULL); + + /* SNI_GetFromBuffer: the *inOutSz > 0 clause's false side, then the + * all-valid row (a hello without SNI parses to none; the value is + * not the point, the clause is). */ + sniSz = 0; + ExpectIntEQ(wolfSSL_SNI_GetFromBuffer((const byte*)"x", 1, + WOLFSSL_SNI_HOST_NAME, sni, &sniSz), BAD_FUNC_ARG); + sniSz = sizeof(sni); + (void)wolfSSL_SNI_GetFromBuffer((const byte*)"x", 1, + WOLFSSL_SNI_HOST_NAME, sni, &sniSz); + + /* UseCertificateAuthority: ssl == NULL || dn == NULL || dnSz == 0 || + * dnSz > MAX -- each clause flips alone across this chain. */ + ExpectIntEQ(wolfSSL_UseCertificateAuthority(NULL, dn, 16), BAD_FUNC_ARG); + ExpectIntEQ(wolfSSL_UseCertificateAuthority(ssl, NULL, 16), BAD_FUNC_ARG); + ExpectIntEQ(wolfSSL_UseCertificateAuthority(ssl, dn, 0), BAD_FUNC_ARG); + ExpectIntEQ(wolfSSL_UseCertificateAuthority(ssl, dn, + WOLFSSL_MAX_16BIT), BAD_FUNC_ARG); + ExpectIntEQ(wolfSSL_UseCertificateAuthority(ssl, dn, 16), 0); + + /* CTX mirror. */ + ExpectIntEQ(wolfSSL_CTX_UseCertificateAuthority(NULL, dn, 16), + BAD_FUNC_ARG); + ExpectIntEQ(wolfSSL_CTX_UseCertificateAuthority(ctx, NULL, 16), + BAD_FUNC_ARG); + ExpectIntEQ(wolfSSL_CTX_UseCertificateAuthority(ctx, dn, 0), + BAD_FUNC_ARG); + ExpectIntEQ(wolfSSL_CTX_UseCertificateAuthority(ctx, dn, + WOLFSSL_MAX_16BIT), BAD_FUNC_ARG); + ExpectIntEQ(wolfSSL_CTX_UseCertificateAuthority(ctx, dn, 16), 0); + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} /* END test_ssl_api_ext_guards_decision_coverage */ diff --git a/tests/api/test_ssl_ext.h b/tests/api/test_ssl_ext.h index b9bef5b9353..dd8092b002f 100644 --- a/tests/api/test_ssl_ext.h +++ b/tests/api/test_ssl_ext.h @@ -30,6 +30,7 @@ int test_wolfSSL_public_null_operands(void); int test_wolfSSL_session_lifecycle_guards(void); int test_ssl_api_decision_coverage(void); int test_ech_decision_coverage(void); +int test_ssl_api_ext_guards_decision_coverage(void); int test_wolfSSL_NoTicketTLSv12_ext(void); int test_wolfSSL_CTX_UseMaxFragment_ext(void); @@ -131,6 +132,7 @@ int test_wolfSSL_ticket_key_cb_renew_ext(void); TEST_DECL_GROUP("ssl_ext", test_wolfSSL_public_null_operands), \ TEST_DECL_GROUP("ssl_ext", test_wolfSSL_session_lifecycle_guards), \ TEST_DECL_GROUP("ssl_ext", test_ssl_api_decision_coverage), \ - TEST_DECL_GROUP("ssl_ext", test_ech_decision_coverage) + TEST_DECL_GROUP("ssl_ext", test_ech_decision_coverage), \ + TEST_DECL_GROUP("ssl_ext", test_ssl_api_ext_guards_decision_coverage) #endif /* TESTS_API_SSL_EXT_H */ diff --git a/tests/api/test_tls.c b/tests/api/test_tls.c index 47b91cfc0d1..7f53673f190 100644 --- a/tests/api/test_tls.c +++ b/tests/api/test_tls.c @@ -5243,3 +5243,62 @@ int test_internal_CheckVersion_DecisionCoverage(void) #endif return EXPECT_RESULT(); } + +/* + * MC/DC decision coverage for the wolfSSL_SetTlsHmacInner content/CID + * guard (master drift, 2026-10-06). The dtls and cidTxSize clauses are + * only compiled under WOLFSSL_DTLS + WOLFSSL_DTLS_CID, so this test must + * run in the campaign's DTLS_CID variant to complete the pairs. + */ +int test_tls_hmac_inner_cid_decision_coverage(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_CLIENT) && \ + !defined(NO_WOLFSSL_SERVER) + WOLFSSL_CTX *ctx = NULL; + WOLFSSL *ssl = NULL; + WOLFSSL_CTX *dctx = NULL; + WOLFSSL *dssl = NULL; + byte inner[WOLFSSL_TLS_HMAC_INNER_SZ]; + byte cid[4] = { 1, 2, 3, 4 }; + + ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); + if (ctx == NULL) + return EXPECT_RESULT(); + ssl = wolfSSL_new(ctx); + if (ssl == NULL) { + wolfSSL_CTX_free(ctx); + return EXPECT_RESULT(); + } + /* content != dtls12_cid, dtls F: the dtls clause's false side. */ + ExpectIntEQ(wolfSSL_SetTlsHmacInner(ssl, inner, 0, application_data, 0), + 0); + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); + +#if defined(WOLFSSL_DTLS_CID) && !defined(WOLFSSL_NO_TLS12) + dctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()); + if (dctx == NULL) + return EXPECT_RESULT(); + dssl = wolfSSL_new(dctx); + if (dssl == NULL) { + wolfSSL_CTX_free(dctx); + return EXPECT_RESULT(); + } + /* content != dtls12_cid, dtls T, cidTxSize F. */ + ExpectIntEQ(wolfSSL_SetTlsHmacInner(dssl, inner, 0, application_data, 0), + 0); + /* dtls T, cidTxSize T. */ + ExpectIntEQ(wolfSSL_dtls_cid_use(dssl), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_cid_set(dssl, cid, sizeof(cid)), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_SetTlsHmacInner(dssl, inner, 0, application_data, 0), + 0); + /* content == dtls12_cid: the first clause's true side. */ + ExpectIntEQ(wolfSSL_SetTlsHmacInner(dssl, inner, 0, dtls12_cid, 0), + BAD_FUNC_ARG); + wolfSSL_free(dssl); + wolfSSL_CTX_free(dctx); +#endif /* WOLFSSL_DTLS_CID */ +#endif /* WOLFSSL_DTLS */ + return EXPECT_RESULT(); +} /* END test_tls_hmac_inner_cid_decision_coverage */ diff --git a/tests/api/test_tls.h b/tests/api/test_tls.h index 201cb97c53f..2b1c221341a 100644 --- a/tests/api/test_tls.h +++ b/tests/api/test_tls.h @@ -83,6 +83,7 @@ int test_record_size_cache_invalidated_on_renegotiation(void); int test_wolfSSL_get_shared_ciphers(void); int test_tls12_aesgcm_record_nonce_unique(void); int test_tls_param_flags_crl_check(void); +int test_tls_hmac_inner_cid_decision_coverage(void); #define TEST_TLS_DECLS \ TEST_DECL_GROUP("tls", test_utils_memio_move_message), \ @@ -148,6 +149,7 @@ int test_tls_param_flags_crl_check(void); TEST_DECL_GROUP("tls", test_tls12_aesgcm_record_nonce_unique), \ TEST_DECL_GROUP("tls", test_internal_SetSSL_CTX_DecisionCoverage), \ TEST_DECL_GROUP("tls", test_internal_CheckVersion_DecisionCoverage), \ - TEST_DECL_GROUP("tls", test_tls_param_flags_crl_check) + TEST_DECL_GROUP("tls", test_tls_param_flags_crl_check), \ + TEST_DECL_GROUP("tls", test_tls_hmac_inner_cid_decision_coverage) #endif /* TESTS_API_TEST_TLS_H */ diff --git a/tests/api/test_tls13.c b/tests/api/test_tls13.c index 9e015bc56cc..a9135409dbd 100644 --- a/tests/api/test_tls13.c +++ b/tests/api/test_tls13.c @@ -14851,3 +14851,80 @@ int test_tls13_export_client_key_update(void) #endif return EXPECT_RESULT(); } + +/* + * MC/DC decision coverage for the TLS 1.3 exporter version guards and + * FindSuiteSSL's per-byte suite comparison. DeriveExporterSecret's version + * check is reached through wolfSSL_export_keying_material after a completed + * handshake; the mismatched-minor probes overwrite ssl->version.minor on the + * completed object so the guard fires. + */ +int test_tls13_exporter_suite_decision_coverage(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + byte out[64]; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + XMEMSET(out, 0, sizeof(out)); + +#ifdef WOLFSSL_TLS13 + /* (!dtls) && (minor == TLSv1_3_MINOR): both true on the completed + * handshake; the mismatched minor takes the second operand's true side. */ + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); +#if defined(HAVE_KEYING_MATERIAL) + ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), + "MCDC", 4, NULL, 0, 0), WOLFSSL_SUCCESS); + ssl_c->version.minor = 0x01; /* TLS 1.0 minor: the guard must fire */ + ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), + "MCDC", 4, NULL, 0, 0), WOLFSSL_FAILURE); +#endif /* HAVE_KEYING_MATERIAL */ + +#if defined(WOLFSSL_TEST_STATIC_BUILD) + byte probe[2]; + + /* FindSuiteSSL: (suites[i] == suite[0]) && (suites[i+1] == suite[1]). + * The object's own first suite is the both-true row; its first byte with + * 0xFF as the second is the first-true/second-false row (no cipher + * suite's second byte is 0xFF). */ + ExpectIntEQ(FindSuiteSSL(ssl_c, (byte*)ssl_c->suites->suites), 1); + probe[0] = ssl_c->suites->suites[0]; + probe[1] = 0xFF; + ExpectIntEQ(FindSuiteSSL(ssl_c, probe), 0); +#endif /* WOLFSSL_TEST_STATIC_BUILD */ + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif /* WOLFSSL_TLS13 */ + +#ifdef WOLFSSL_DTLS13 + /* (dtls) && (minor == DTLSv1_3_MINOR): both true on the completed + * handshake; the mismatched minor takes the second operand's true side. */ + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), + "MCDC", 4, NULL, 0, 0), WOLFSSL_SUCCESS); + ssl_c->version.minor = TLSv1_3_MINOR; /* mismatch: the guard must fire */ + ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), + "MCDC", 4, NULL, 0, 0), WOLFSSL_FAILURE); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif /* WOLFSSL_DTLS13 */ +#endif /* HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES */ + return EXPECT_RESULT(); +} /* END test_tls13_exporter_suite_decision_coverage */ diff --git a/tests/api/test_tls13.h b/tests/api/test_tls13.h index 64155f5c416..0b710f08265 100644 --- a/tests/api/test_tls13.h +++ b/tests/api/test_tls13.h @@ -172,6 +172,7 @@ int test_tls13_export_server_ticket_after_import(void); int test_tls13_export_client_ticket_after_import(void); int test_tls13_export_server_key_update(void); int test_tls13_export_client_key_update(void); +int test_tls13_exporter_suite_decision_coverage(void); #define TEST_TLS13_DECLS \ TEST_DECL_GROUP("tls13", test_tls13_apis), \ @@ -322,6 +323,7 @@ int test_tls13_export_client_key_update(void); TEST_DECL_GROUP("tls13", test_tls13_export_server_ticket_after_import), \ TEST_DECL_GROUP("tls13", test_tls13_export_client_ticket_after_import), \ TEST_DECL_GROUP("tls13", test_tls13_export_server_key_update), \ - TEST_DECL_GROUP("tls13", test_tls13_export_client_key_update) + TEST_DECL_GROUP("tls13", test_tls13_export_client_key_update), \ + TEST_DECL_GROUP("tls13", test_tls13_exporter_suite_decision_coverage) #endif /* WOLFCRYPT_TEST_TLS13_H */ diff --git a/tests/unit-mcdc/test_random_whitebox.c b/tests/unit-mcdc/test_random_whitebox.c index 2621a8ed8f9..2dfc7909d1c 100644 --- a/tests/unit-mcdc/test_random_whitebox.c +++ b/tests/unit-mcdc/test_random_whitebox.c @@ -184,7 +184,10 @@ static void wb_array_add(void) array_add(d, 4, s, 0); array_add(d, 2, s, 4); - /* True side baseline, same binary. */ + /* True side baseline, same binary. The (4,4) call is the shared anchor: + * each false-side call above differs from it in exactly one operand, so + * each shows its condition's independence pair. */ + array_add(d, 4, s, 4); array_add(d, (word32)sizeof(d), s, (word32)sizeof(s)); } @@ -848,6 +851,24 @@ static void wb_init_rng_seed_rng(void) { WB_NOTE("HAVE_HASHDRBG/NO_SHA256 off; seedRng row skipped"); } #endif +static void wb_reseed_source_failure(void) +{ +#if defined(HAVE_HASHDRBG) && !defined(NO_SHA256) + /* ReseedSourceFailure: (ret == ENTROPY_RT_E) || (ret == ENTROPY_APT_E) -- + * direct calls show each operand's true/false pair. */ + if (ReseedSourceFailure(WC_NO_ERR_TRACE(ENTROPY_RT_E)) != + WC_NO_ERR_TRACE(ENTROPY_RT_E)) + wb_fail++; + if (ReseedSourceFailure(WC_NO_ERR_TRACE(ENTROPY_APT_E)) != + WC_NO_ERR_TRACE(ENTROPY_APT_E)) + wb_fail++; + if (ReseedSourceFailure(DRBG_FAILURE) != DRBG_FAILURE) + wb_fail++; +#else + WB_NOTE("HAVE_HASHDRBG/NO_SHA256 off; ReseedSourceFailure rows skipped"); +#endif +} + int main(void) { setvbuf(stdout, NULL, _IONBF, 0); @@ -870,6 +891,7 @@ int main(void) wb_hash512_gen_alloc_guard(); wb_stir_nonce_local(); wb_init_rng_seed_rng(); + wb_reseed_source_failure(); printf("done (%s)\n", wb_fail ? "with skips" : "ok"); /* Setup failures are surfaced as skips, not test failures: the * suite treats a nonzero exit as a failed variant and discards its diff --git a/tests/unit-mcdc/test_sp_x86_64_whitebox.c b/tests/unit-mcdc/test_sp_x86_64_whitebox.c index 0594ea1b4e0..1b300eb0a32 100644 --- a/tests/unit-mcdc/test_sp_x86_64_whitebox.c +++ b/tests/unit-mcdc/test_sp_x86_64_whitebox.c @@ -1251,6 +1251,18 @@ static void wb_run_dispatch_256(void) pp2.x[0] = 1; pp2.y[0] = 1; pp2.z[0] = 1; (void)WB_CHECK(sp_256_add_points_4(&pp1, &pp2, tmp2)); } + { + sp_point_256 zp1; + sp_point_256 zp2; + sp_digit ztmp[48]; + + XMEMSET(&zp1, 0, sizeof(zp1)); + XMEMSET(&zp2, 0, sizeof(zp2)); + XMEMSET(ztmp, 0, sizeof(ztmp)); + /* All-zero points: the add yields the point at infinity, driving + * the z==0 and x&&y==0 true sides of add_points_4's checks. */ + (void)WB_CHECK(sp_256_add_points_4(&zp1, &zp2, ztmp)); + } { sp_point_256 pt; diff --git a/tests/unit-mcdc/test_tls_whitebox.c b/tests/unit-mcdc/test_tls_whitebox.c new file mode 100644 index 00000000000..2285e293e95 --- /dev/null +++ b/tests/unit-mcdc/test_tls_whitebox.c @@ -0,0 +1,228 @@ +/* + * tls.c white-box supplement: MC/DC rows for the file-static helpers the + * public API cannot reach with the operand sides the campaign union never + * showed (master drift, 2026-10-06): the Hmac size guards, the ALPN + * constructor/find/set NULL rows, and the SNI parse length/cacheOnly/ + * find-miss rows. + * + * This white-box #includes src/tls.c directly to reach these file-static + * helpers and drives both sides of each leaf in the same binary (a single + * clang MC/DC bitmap does not merge independence pairs across separately + * compiled binaries, so each row below is paired with a same-binary + * baseline call). + * + * Crash-safety: Hmac_OuterHash() only touches the hash object after the + * size guard passes; Hmac_UpdateFinal_CT()'s oversized-macLen row returns + * at its first statement before any buffer use; the ALPN NULL rows return + * before any allocation; the SNI rows feed well-formed buffers to a real + * object. + */ + +#include + +#include + +static int wb_fail = 0; +#define WB_NOTE(msg) do {printf(" [wb] %s\n", (msg));} while (0) + +/* Hmac_OuterHash: (digestSz >= 0) && (blockSz >= 0). A macType with no + * hash-table entry makes both sizes negative: the false sides; the + * SHA-256 row is the same-binary true baseline. */ +static void wb_hmac_outer_hash(void) +{ + Hmac hmac; + unsigned char mac[64]; + + XMEMSET(&hmac, 0, sizeof(hmac)); + XMEMSET(mac, 0, sizeof(mac)); + hmac.macType = WC_SHA256; + (void)Hmac_OuterHash(&hmac, mac); + hmac.macType = (enum wc_HashType)100; + (void)Hmac_OuterHash(&hmac, mac); +} + +/* Hmac_UpdateFinal_CT: the macLen > sizeof(innerHash) clause. The + * oversized row returns at the guard before any buffer use. */ +static void wb_hmac_updatefinal_ct(void) +{ + Hmac hmac; + byte in[16]; + byte digest[WC_MAX_DIGEST_SIZE]; + byte header[4]; + + XMEMSET(&hmac, 0, sizeof(hmac)); + XMEMSET(in, 0, sizeof(in)); + hmac.macType = WC_SHA256; + (void)Hmac_UpdateFinal_CT(&hmac, digest, in, sizeof(in), 32, + header, sizeof(header)); + (void)Hmac_UpdateFinal_CT(&hmac, digest, in, sizeof(in), + (int)sizeof(hmac.innerHash) + 1, + header, sizeof(header)); +} + +#if defined(HAVE_ALPN) + +/* TLSX_ALPN_New: the protocol_name == NULL clause's true side. */ +static void wb_alpn_new_null(void) +{ + if (TLSX_ALPN_New(NULL, 0, NULL) != NULL) + wb_fail++; +} + +/* TLSX_ALPN_Find: (list == NULL) || (protocol_name == NULL) -- the NULL +* list row, the NULL name row on a live node, and the valid baseline. */ +static void wb_alpn_find_nulls(void) +{ + ALPN alpn; + char name[] = "http/1.1"; + + XMEMSET(&alpn, 0, sizeof(alpn)); + alpn.protocol_name = name; + alpn.protocol_nameSz = (word16)sizeof(name) - 1; + (void)TLSX_ALPN_Find(NULL, name, alpn.protocol_nameSz); + (void)TLSX_ALPN_Find(&alpn, NULL, 0); + (void)TLSX_ALPN_Find(&alpn, name, alpn.protocol_nameSz); +} + +/* TLSX_SetALPN: (extensions == NULL) || (data == NULL) -- both NULL rows + * and the valid baseline (pushed onto a local list, freed below). */ +static void wb_set_alpn_nulls(void) +{ + TLSX extensions; + const byte data[] = "http/1.1"; + + XMEMSET(&extensions, 0, sizeof(extensions)); + (void)TLSX_SetALPN(NULL, data, (word16)sizeof(data) - 1, NULL); + (void)TLSX_SetALPN(&extensions, NULL, 0, NULL); + (void)TLSX_SetALPN(&extensions, data, (word16)sizeof(data) - 1, NULL); + TLSX_FreeAll(&extensions, NULL); +} + +/* TLSX_UseALPN: the extensions == NULL clause's true side. */ +static void wb_use_alpn_null(void) +{ + const byte data[] = "http/1.1"; + /* options is unused: the extensions-NULL guard fires first. */ + (void)TLSX_UseALPN(NULL, data, (word16)sizeof(data) - 1, 0, NULL); +} + +/* ALPN_find_match: the extension->data == NULL clause's true side -- an + * ALPN extension with a NULL payload on a real object. */ +static void wb_alpn_find_match_null_data(void) +{ + WOLFSSL_CTX *ctx = NULL; + WOLFSSL *ssl = NULL; + TLSX *pext = NULL; + const byte *sel = NULL; + byte selLen = 0; + const byte alpnVal[] = {5, 'h', 't', 't', 'p'}; + + ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); + if (ctx == NULL) + return; + ssl = wolfSSL_new(ctx); + if (ssl == NULL) { + wolfSSL_CTX_free(ctx); + return; + } + (void)TLSX_Push(&ssl->extensions, TLSX_APPLICATION_LAYER_PROTOCOL, + NULL, ssl->heap); + (void)ALPN_find_match(ssl, &pext, &sel, &selLen, alpnVal, + (word16)sizeof(alpnVal)); + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); +} + +#else + +static void wb_alpn_new_null(void) +{ + WB_NOTE("HAVE_ALPN off; ALPN_New rows skipped"); +} +static void wb_alpn_find_nulls(void) +{ + WB_NOTE("HAVE_ALPN off; ALPN_Find rows skipped"); +} +static void wb_set_alpn_nulls(void) +{ + WB_NOTE("HAVE_ALPN off; SetALPN rows skipped"); +} +static void wb_use_alpn_null(void) +{ + WB_NOTE("HAVE_ALPN off; UseALPN rows skipped"); +} +static void wb_alpn_find_match_null_data(void) +{ + WB_NOTE("HAVE_ALPN off; ALPN_find_match rows skipped"); +} + +#endif /* HAVE_ALPN */ + +#if defined(HAVE_SNI) && !defined(NO_WOLFSSL_SERVER) + +/* TLSX_SNI_Parse: the size == 0 row (length matches OPAQUE16_LEN + size, + * the second clause fires), the SNI_Find miss/hit rows, and the cacheOnly + * row (a configured sniRecvCb forces it; the callback itself is invoked + * by the caller of Parse, not inside it, so a sentinel pointer is safe). */ +static void wb_sni_parse_rows(void) +{ + WOLFSSL_CTX *ctx = NULL; + WOLFSSL *ssl = NULL; + byte in[8]; + + ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()); + if (ctx == NULL) + return; + ssl = wolfSSL_new(ctx); + if (ssl == NULL) { + wolfSSL_CTX_free(ctx); + return; + } + + c16toa(0, in); + (void)TLSX_SNI_Parse(ssl, in, OPAQUE16_LEN, 1); + + /* Well-formed host-name SNI, nothing configured: the find-miss row. */ + in[0] = 0; in[1] = 4; + in[2] = WOLFSSL_SNI_HOST_NAME; + in[3] = 0; in[4] = 1; + in[5] = 'a'; + (void)TLSX_SNI_Parse(ssl, in, 6, 1); + + /* Configured: the find-hit row. */ + (void)TLSX_UseSNI(&ssl->extensions, WOLFSSL_SNI_HOST_NAME, "a", 1, + ssl->heap); + (void)TLSX_SNI_Parse(ssl, in, 6, 1); + + /* cacheOnly row. */ + ctx->sniRecvCb = (CallbackSniRecv)1; + (void)TLSX_SNI_Parse(ssl, in, 6, 1); + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); +} + +#else + +static void wb_sni_parse_rows(void) +{ + WB_NOTE("HAVE_SNI/NO_WOLFSSL_SERVER off; SNI parse rows skipped"); +} + +#endif /* HAVE_SNI && !NO_WOLFSSL_SERVER */ + +int main(void) +{ + setvbuf(stdout, NULL, _IONBF, 0); + printf("tls.c white-box supplement\n"); + wb_hmac_outer_hash(); + wb_hmac_updatefinal_ct(); + wb_alpn_new_null(); + wb_alpn_find_nulls(); + wb_set_alpn_nulls(); + wb_use_alpn_null(); + wb_alpn_find_match_null_data(); + wb_sni_parse_rows(); + printf("done (%s)\n", wb_fail ? "with failures" : "ok"); + return 0; +} From 6ce472590c69de7d5654ab2c31635bef41073cd5 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 7 Oct 2026 10:02:00 +0200 Subject: [PATCH 24/33] tests: gate the crypto-cb dispatch rows on the campaign build --enable-cryptocb builds do not compile wolfcrypt/src/cryptocb.c (dropped from CMake in 2020, never in autotools), so the wc_CryptoCb_* refs in the kdf dispatch tests dangle in the standard build and break the unit.test link in every crypto-cb CI config. Gate the four crypto-cb sections in test_kdf.c on WOLFSSL_USER_SETTINGS, the marker of the campaign build which does compile cryptocb.c; the rows run there and are skipped elsewhere. Also gate the exporter-suite decision driver's memio declarations on WOLFSSL_TLS13/WOLFSSL_DTLS13: the hostap/wpa config (--enable-wpas --disable-tls13) left them declared-but-unused and -Werror failed the build. Verification: exact CI crypto-cb async-poll config builds and links, kdf group green; exact hostap/wpa config builds clean. --- tests/api/test_kdf.c | 17 +++++++++-------- tests/api/test_tls13.c | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/api/test_kdf.c b/tests/api/test_kdf.c index 246a0ddebda..24b898d5190 100644 --- a/tests/api/test_kdf.c +++ b/tests/api/test_kdf.c @@ -58,7 +58,8 @@ /* ------------------------------------------------------------------ */ /* WOLF_CRYPTO_CB support for wc_KDA_KDF_twostep_cmac's dispatch guard */ /* ------------------------------------------------------------------ */ -#if defined(HAVE_CMAC_KDF) && defined(WOLF_CRYPTO_CB) +#if defined(HAVE_CMAC_KDF) && defined(WOLF_CRYPTO_CB) && \ + defined(WOLFSSL_USER_SETTINGS) #define TEST_KDF_CRYPTOCB_DEVID 0x4b444630 /* "KDF0" */ /* Toggled by the test below: when set, the callback fails outright instead @@ -86,7 +87,7 @@ static int test_kdf_cryptocb(int cbDevId, wc_CryptoInfo* info, void* ctx) } return WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); } -#endif /* HAVE_CMAC_KDF && WOLF_CRYPTO_CB */ +#endif /* HAVE_CMAC_KDF && WOLF_CRYPTO_CB && WOLFSSL_USER_SETTINGS */ /* * MC/DC decision coverage: negative / argument-check / bad-selector / @@ -634,7 +635,7 @@ int test_wc_KdfDecisionCoverage(void) sizeof(z), fixedInfo, sizeof(fixedInfo), output, sizeof(output), HEAP_HINT, INVALID_DEVID), 0); -#if defined(WOLF_CRYPTO_CB) +#if defined(WOLF_CRYPTO_CB) && defined(WOLFSSL_USER_SETTINGS) /* devId != INVALID_DEVID: dispatch taken. Independence pair for * the CRYPTOCB_UNAVAILABLE fall-through guard: succeeds, then fails * outright, both via the SAME registered devId. */ @@ -654,7 +655,7 @@ int test_wc_KdfDecisionCoverage(void) test_kdf_cryptocb_force_fail = 0; wc_CryptoCb_UnRegisterDevice(TEST_KDF_CRYPTOCB_DEVID); -#endif /* WOLF_CRYPTO_CB */ +#endif /* WOLF_CRYPTO_CB && WOLFSSL_USER_SETTINGS */ } #endif /* HAVE_CMAC_KDF && WOLFSSL_AES_128 */ @@ -946,7 +947,7 @@ int test_wc_KdfFeatureCoverage(void) * - a registered device with a NULL callback: operand 1 false * Every call returns CRYPTOCB_UNAVAILABLE in all three rows. */ -#if defined(WOLF_CRYPTO_CB) +#if defined(WOLF_CRYPTO_CB) && defined(WOLFSSL_USER_SETTINGS) #define TEST_CRYPTOCB_DISPATCH_DEVID 0x44495350 /* "DISP" */ static int test_cryptocb_dispatch_decline_cb(int cbDevId, wc_CryptoInfo* info, @@ -957,12 +958,12 @@ static int test_cryptocb_dispatch_decline_cb(int cbDevId, wc_CryptoInfo* info, (void)ctx; return WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); } -#endif /* WOLF_CRYPTO_CB */ +#endif /* WOLF_CRYPTO_CB && WOLFSSL_USER_SETTINGS */ int test_wc_CryptoCbDispatchDecisionCoverage(void) { EXPECT_DECLS; -#if defined(WOLF_CRYPTO_CB) +#if defined(WOLF_CRYPTO_CB) && defined(WOLFSSL_USER_SETTINGS) byte in[8] = {0}; byte out[16] = {0}; byte tag[16] = {0}; @@ -1045,6 +1046,6 @@ int test_wc_CryptoCbDispatchDecisionCoverage(void) (void)out; (void)tag; -#endif /* WOLF_CRYPTO_CB */ +#endif /* WOLF_CRYPTO_CB && WOLFSSL_USER_SETTINGS */ return EXPECT_RESULT(); } /* END test_wc_CryptoCbDispatchDecisionCoverage */ diff --git a/tests/api/test_tls13.c b/tests/api/test_tls13.c index a9135409dbd..0a7420013e8 100644 --- a/tests/api/test_tls13.c +++ b/tests/api/test_tls13.c @@ -14863,7 +14863,8 @@ int test_tls13_exporter_suite_decision_coverage(void) { EXPECT_DECLS; #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ - !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + (defined(WOLFSSL_TLS13) || defined(WOLFSSL_DTLS13)) WOLFSSL_CTX *ctx_c = NULL; WOLFSSL_CTX *ctx_s = NULL; WOLFSSL *ssl_c = NULL; From 180368f0a5c64e02e1acc1ff9701ea91cd6b8749 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 7 Oct 2026 10:20:33 +0200 Subject: [PATCH 25/33] tests: fix the -Wshadow hit in the falcon decision driver The wc_falcon_sign_msg block re-declared rng, shadowing the function-scope WC_RNG under -Werror=shadow. Rename the inner to rng2. Also name the FalconCbFreeCtx struct tag (house rule 4, flagged by the style gate). Verification: full build with EXTRA_CFLAGS='-Werror -Wshadow' (tree-wide sweep - the only shadow), full unit.test passes. --- tests/api/test_falcon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/api/test_falcon.c b/tests/api/test_falcon.c index 529994f1f79..3b86452a6c5 100644 --- a/tests/api/test_falcon.c +++ b/tests/api/test_falcon.c @@ -1588,16 +1588,16 @@ int test_wc_FalconDecisionCoverage(void) * The (!prvKeySet) F + valid-rng fall-through into the native signer is * owned by test_wc_falcon_sign_vfy (real key). */ { - WC_RNG rng; + WC_RNG rng2; byte msg[4]; - XMEMSET(&rng, 0, sizeof(rng)); + XMEMSET(&rng2, 0, sizeof(rng2)); XMEMSET(msg, 0, sizeof(msg)); XMEMSET(&key, 0, sizeof(key)); ExpectIntEQ(wc_falcon_init(&key), 0); ExpectIntEQ(wc_falcon_set_level(&key, falcon_levels[0]), 0); outLen = (word32)sizeof(out); ExpectIntEQ(wc_falcon_sign_msg(msg, (word32)sizeof(msg), out, &outLen, - &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* !prvKeySet T */ + &key, &rng2), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* !prvKeySet T */ key.prvKeySet = 1; /* !prvKeySet F */ outLen = (word32)sizeof(out); ExpectIntEQ(wc_falcon_sign_msg(msg, (word32)sizeof(msg), out, &outLen, @@ -1753,7 +1753,7 @@ int test_wc_FalconDecisionCoverage(void) #ifdef TEST_FALCON_CB_FREE /* What the free callback saw, so the test can check the contract rather than * just that something fired. */ -typedef struct { +typedef struct FalconCbFreeCtx { int frees; /* matching free callbacks seen */ int badObj; /* callback was handed the wrong object */ int wiped; /* callback saw a key already cleaned up */ From fe105aeb6670fbfdc821134ae4a9c763f7c1cdbf Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 7 Oct 2026 10:45:49 +0200 Subject: [PATCH 26/33] tests: gate campaign test decls and helpers per feature config CI reds across configs where a test declaration or static helper survives but its uses are compiled out: - test_tls.c: move the inner-cid driver's dctx/dssl/cid decls into the WOLFSSL_DTLS_CID && !WOLFSSL_NO_TLS12 block, and require !WOLFSSL_NO_TLS12 on the outer block - wolfSSL_SetTlsHmacInner is only defined there. - test_mldsa.c: gate the DER builders per world: pub_der under WOLFSSL_MLDSA_NO_ASN1, priv_der under !WOLFSSL_MLDSA_NO_ASN1. - test_mlkem.c: gate the decision-coverage ToDer section on !WOLFSSL_MLKEM_NO_ASN1 and silence the decls left unused there. - test_dtls.c: gate the cookie-flip callback pair on !WOLFSSL_NO_TLS12 to match their single use site. - test_tls13.c: require HAVE_KEYING_MATERIAL on the exporter-suite driver (wolfSSL_export_keying_material is declared only there). Verification: --enable-mldsa, --enable-tinytls13=mldsa and --enable-dtls --enable-dtls13 --disable-tlsv12 each build clean and pass the full unit.test run. --- tests/api/test_dtls.c | 2 ++ tests/api/test_mldsa.c | 4 ++++ tests/api/test_mlkem.c | 8 ++++++++ tests/api/test_tls.c | 9 +++++---- tests/api/test_tls13.c | 1 + 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/api/test_dtls.c b/tests/api/test_dtls.c index 6e6474a6905..32d56038cc1 100644 --- a/tests/api/test_dtls.c +++ b/tests/api/test_dtls.c @@ -8641,6 +8641,7 @@ static int test_dtls_ch_reject_cb(WOLFSSL* ssl, void* ctx) return TEST_DTLS_CH_REJECT_E; } +#if !defined(WOLFSSL_NO_TLS12) struct test_dtls_ch_flip_ctx { int calls; int disableRet; @@ -8657,6 +8658,7 @@ static int test_dtls_ch_flip_cb(WOLFSSL* ssl, void* ctx) flip->enableRet = wolfSSL_enable_cookie(ssl); return 0; } +#endif /* !WOLFSSL_NO_TLS12 */ static int test_dtls_no_cookie_setup(struct test_memio_ctx* io, WOLFSSL_CTX** ctx_c, WOLFSSL_CTX** ctx_s, WOLFSSL** ssl_c, WOLFSSL** ssl_s) diff --git a/tests/api/test_mldsa.c b/tests/api/test_mldsa.c index 5c0b9040373..c8af0b63ccf 100644 --- a/tests/api/test_mldsa.c +++ b/tests/api/test_mldsa.c @@ -31469,6 +31469,7 @@ static word32 mldsa_test_der_put_len(byte* p, word32 len) return 3; } +#if defined(WOLFSSL_MLDSA_NO_ASN1) /* SEQUENCE { SEQUENCE { OID } BIT STRING }. BIT STRING content is the * unused-bits byte followed by the raw public key. */ static word32 mldsa_test_build_pub_der(byte* buf, const byte* oid, @@ -31497,7 +31498,9 @@ static word32 mldsa_test_build_pub_der(byte* buf, const byte* oid, return (word32)(p - buf); } +#endif /* WOLFSSL_MLDSA_NO_ASN1 */ +#if !defined(WOLFSSL_MLDSA_NO_ASN1) /* SEQUENCE of INTEGER 0, a SEQUENCE of OID, and nested OCTET STRINGs * wrapping the private key. Private key only: no [1] public key * component. */ @@ -31532,6 +31535,7 @@ static word32 mldsa_test_build_priv_der(byte* buf, const byte* oid, return (word32)(p - buf); } +#endif /* !WOLFSSL_MLDSA_NO_ASN1 */ /* One keygen + sign + verify round trip, plus a verify of the signature * with its z region corrupted (16 bytes of 0xFF past the commit push the diff --git a/tests/api/test_mlkem.c b/tests/api/test_mlkem.c index b2a2e04761b..11e9187df31 100644 --- a/tests/api/test_mlkem.c +++ b/tests/api/test_mlkem.c @@ -4522,6 +4522,7 @@ int test_wc_MlkemDecisionCoverage(void) ExpectIntEQ(wc_MlKemKey_EncodePrivateKey(key, out, sizeof(out)), WC_NO_ERR_TRACE(BAD_STATE_E)); +#if !defined(WOLFSSL_MLKEM_NO_ASN1) /* --- DER encode/decode decisions: the (ret == 0) operand of the ToDer * output blocks, the decode NULL rows, and the type-set / adopt-type * checks. --- */ @@ -4592,6 +4593,7 @@ int test_wc_MlkemDecisionCoverage(void) ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(adopt, der, sz, &idx), 0); wc_MlKemKey_Free(adopt); XFREE(adopt, NULL, DYNAMIC_TYPE_TMP_BUFFER); +#endif /* !WOLFSSL_MLKEM_NO_ASN1 */ /* --- RFC 9935 Section 6 privateKey shapes: seed-only and "both". * The seed expands through the real keygen so the "both" key agrees @@ -4693,6 +4695,12 @@ int test_wc_MlkemDecisionCoverage(void) (void)ss; (void)rndMk; (void)rndEnc; + (void)der; + (void)idx; + (void)sz; + (void)fresh; + (void)adopt; + (void)unset; #endif return EXPECT_RESULT(); } /* END test_wc_MlkemDecisionCoverage */ diff --git a/tests/api/test_tls.c b/tests/api/test_tls.c index 7f53673f190..b49ba340c6d 100644 --- a/tests/api/test_tls.c +++ b/tests/api/test_tls.c @@ -5254,13 +5254,10 @@ int test_tls_hmac_inner_cid_decision_coverage(void) { EXPECT_DECLS; #if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_CLIENT) && \ - !defined(NO_WOLFSSL_SERVER) + !defined(NO_WOLFSSL_SERVER) && !defined(WOLFSSL_NO_TLS12) WOLFSSL_CTX *ctx = NULL; WOLFSSL *ssl = NULL; - WOLFSSL_CTX *dctx = NULL; - WOLFSSL *dssl = NULL; byte inner[WOLFSSL_TLS_HMAC_INNER_SZ]; - byte cid[4] = { 1, 2, 3, 4 }; ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()); if (ctx == NULL) @@ -5277,6 +5274,10 @@ int test_tls_hmac_inner_cid_decision_coverage(void) wolfSSL_CTX_free(ctx); #if defined(WOLFSSL_DTLS_CID) && !defined(WOLFSSL_NO_TLS12) + WOLFSSL_CTX *dctx = NULL; + WOLFSSL *dssl = NULL; + byte cid[4] = { 1, 2, 3, 4 }; + dctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()); if (dctx == NULL) return EXPECT_RESULT(); diff --git a/tests/api/test_tls13.c b/tests/api/test_tls13.c index 0a7420013e8..4bcaf920268 100644 --- a/tests/api/test_tls13.c +++ b/tests/api/test_tls13.c @@ -14863,6 +14863,7 @@ int test_tls13_exporter_suite_decision_coverage(void) { EXPECT_DECLS; #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(HAVE_KEYING_MATERIAL) && \ !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ (defined(WOLFSSL_TLS13) || defined(WOLFSSL_DTLS13)) WOLFSSL_CTX *ctx_c = NULL; From 167b578aadfa919c193304be0d1ed63918aef88e Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 7 Oct 2026 13:16:47 +0200 Subject: [PATCH 27/33] tests: fix C90 decl placement and dangling ctx reuse in campaign drivers Two regressions from the class D fix, both biting in configs where the inner CID block and the DTLS 1.3 exporter sub-block compile together (--enable-all class): - test_tls.c: the dctx/dssl/cid decls landed mid-function when moved under the inner CID guard; move them to the top of the function under the full use condition (C90 mixed declarations). - test_tls13.c: the exporter-suite TLS 1.3 phase freed its ctx/ssl objects without NULLing the pointers, and test_memio_setup() only creates a ctx for NULL slots - the DTLS 1.3 phase reused the dangling ctx and wolfSSL_new() ran on freed memory (SIGSEGV / glibc robust-mutex abort). NULL the pointers at the free site. Verification: --enable-all with CPPFLAGS=-DWOLFSSL_RSA_KEY_CHECK -DHAVE_EX_DATA_CLEANUP_HOOKS builds clean and passes the full unit.test run. --- tests/api/test_tls.c | 11 +++++++---- tests/api/test_tls13.c | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/api/test_tls.c b/tests/api/test_tls.c index b49ba340c6d..bc9930f4f88 100644 --- a/tests/api/test_tls.c +++ b/tests/api/test_tls.c @@ -5253,6 +5253,13 @@ int test_internal_CheckVersion_DecisionCoverage(void) int test_tls_hmac_inner_cid_decision_coverage(void) { EXPECT_DECLS; +#if defined(WOLFSSL_DTLS_CID) && !defined(WOLFSSL_NO_TLS12) && \ + defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_CLIENT) && \ + !defined(NO_WOLFSSL_SERVER) + WOLFSSL_CTX *dctx = NULL; + WOLFSSL *dssl = NULL; + byte cid[4] = { 1, 2, 3, 4 }; +#endif #if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_CLIENT) && \ !defined(NO_WOLFSSL_SERVER) && !defined(WOLFSSL_NO_TLS12) WOLFSSL_CTX *ctx = NULL; @@ -5274,10 +5281,6 @@ int test_tls_hmac_inner_cid_decision_coverage(void) wolfSSL_CTX_free(ctx); #if defined(WOLFSSL_DTLS_CID) && !defined(WOLFSSL_NO_TLS12) - WOLFSSL_CTX *dctx = NULL; - WOLFSSL *dssl = NULL; - byte cid[4] = { 1, 2, 3, 4 }; - dctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()); if (dctx == NULL) return EXPECT_RESULT(); diff --git a/tests/api/test_tls13.c b/tests/api/test_tls13.c index 4bcaf920268..d9712ae6502 100644 --- a/tests/api/test_tls13.c +++ b/tests/api/test_tls13.c @@ -14907,6 +14907,12 @@ int test_tls13_exporter_suite_decision_coverage(void) wolfSSL_CTX_free(ctx_c); wolfSSL_free(ssl_s); wolfSSL_CTX_free(ctx_s); + /* NULL the pointers: the DTLS 1.3 block below reuses this driver, + * and test_memio_setup only creates a ctx when the slot is NULL. */ + ctx_c = NULL; + ctx_s = NULL; + ssl_c = NULL; + ssl_s = NULL; #endif /* WOLFSSL_TLS13 */ #ifdef WOLFSSL_DTLS13 From fe5628d4dad58ada34d4959ce8e53fd9f91735bc Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 8 Oct 2026 08:08:30 +0200 Subject: [PATCH 28/33] tests: fix campaign CI failures --- tests/api/test_asn.c | 3 ++- tests/api/test_mldsa.c | 10 ++++++++-- tests/api/test_mlkem.c | 13 ++++++++++++- tests/api/test_tls13.c | 4 ++++ tests/api/test_x509.c | 3 +-- tests/unit-mcdc/test_random_whitebox.c | 2 +- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/tests/api/test_asn.c b/tests/api/test_asn.c index 817f0ea9838..bb34443e1a2 100644 --- a/tests/api/test_asn.c +++ b/tests/api/test_asn.c @@ -5323,7 +5323,8 @@ int test_SetCertificatePolicies_no_empty_qualifiers(void) int test_wc_Pkcs8EncryptDecisionCoverage(void) { EXPECT_DECLS; -#if defined(HAVE_AES_CBC) && !defined(NO_AES) && defined(WOLFSSL_AES_128) && \ +#if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) && \ + defined(HAVE_AES_CBC) && !defined(NO_AES) && defined(WOLFSSL_AES_128) && \ defined(HAVE_ECC) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) WC_RNG rng; byte key[32]; diff --git a/tests/api/test_mldsa.c b/tests/api/test_mldsa.c index c8af0b63ccf..343582fb13f 100644 --- a/tests/api/test_mldsa.c +++ b/tests/api/test_mldsa.c @@ -31446,7 +31446,10 @@ int test_wc_MldsaDerDecisionCoverage(void) } #if defined(WOLFSSL_HAVE_MLDSA) && defined(WOLFSSL_MLDSA_PUBLIC_KEY) && \ - defined(WOLFSSL_MLDSA_PRIVATE_KEY) + defined(WOLFSSL_MLDSA_PRIVATE_KEY) && \ + !defined(WOLF_CRYPTO_CB_ONLY_MLDSA) && \ + !defined(WOLFSSL_MLDSA_NO_MAKE_KEY) && \ + !defined(WOLFSSL_MLDSA_NO_SIGN) && !defined(WOLFSSL_MLDSA_NO_VERIFY) /* DER length: short form, or 0x82 two-byte long form. Every crafted * buffer below stays under 64 KiB, so two length bytes always suffice. */ static word32 mldsa_test_der_len_sz(word32 len) @@ -31711,7 +31714,10 @@ int test_wc_MldsaReworkDecisionCoverage(void) { EXPECT_DECLS; #if defined(WOLFSSL_HAVE_MLDSA) && defined(WOLFSSL_MLDSA_PUBLIC_KEY) && \ - defined(WOLFSSL_MLDSA_PRIVATE_KEY) + defined(WOLFSSL_MLDSA_PRIVATE_KEY) && \ + !defined(WOLF_CRYPTO_CB_ONLY_MLDSA) && \ + !defined(WOLFSSL_MLDSA_NO_MAKE_KEY) && \ + !defined(WOLFSSL_MLDSA_NO_SIGN) && !defined(WOLFSSL_MLDSA_NO_VERIFY) WC_RNG rng; int rngInited = 0; int i; diff --git a/tests/api/test_mlkem.c b/tests/api/test_mlkem.c index 11e9187df31..3ba6454c221 100644 --- a/tests/api/test_mlkem.c +++ b/tests/api/test_mlkem.c @@ -4374,6 +4374,7 @@ int test_wc_MlkemDecisionCoverage(void) word32 derSz = 0; #endif #if defined(USE_INTEL_SPEEDUP) && defined(WOLF_CRYPTO_CB) && \ + !defined(WOLFSSL_MLKEM_NO_ASN1) && !defined(WOLFSSL_MLKEM_NO_MAKE_KEY) && \ !defined(WOLF_CRYPTO_CB_FIND) && !defined(WOLFSSL_MLKEM_NO_ENCAPSULATE) && \ !defined(WOLFSSL_MLKEM_NO_DECAPSULATE) word32 ctLen = 0; @@ -4561,6 +4562,8 @@ int test_wc_MlkemDecisionCoverage(void) DYNAMIC_TYPE_TMP_BUFFER); ExpectNotNull(fresh); XMEMSET(fresh, 0, sizeof(*fresh)); + ExpectIntEQ(wc_MlKemKey_Init(fresh, WC_ML_KEM_TYPE_UNSET, NULL, + INVALID_DEVID), 0); idx = 0; ExpectIntEQ(wc_MlKemKey_PublicKeyDecode(fresh, der, sz, &idx), 0); wc_MlKemKey_Free(fresh); @@ -4570,7 +4573,7 @@ int test_wc_MlkemDecisionCoverage(void) /* Private key DER: the NULL rows, the valid decode (type already * set, so the adopt check takes its false side), and the adopt: - * a zeroed key has no type, so the DER's type is adopted. */ + * an initialized key with no type takes the DER's type. */ sz = wc_MlKemKey_PrivateKeyToDer(key2, NULL, 0); ExpectIntGT(sz, 0); ExpectIntEQ(wc_MlKemKey_PrivateKeyToDer(key2, der, sizeof(der)), sz); @@ -4589,6 +4592,8 @@ int test_wc_MlkemDecisionCoverage(void) DYNAMIC_TYPE_TMP_BUFFER); ExpectNotNull(adopt); XMEMSET(adopt, 0, sizeof(*adopt)); + ExpectIntEQ(wc_MlKemKey_Init(adopt, WC_ML_KEM_TYPE_UNSET, NULL, + INVALID_DEVID), 0); idx = 0; ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(adopt, der, sz, &idx), 0); wc_MlKemKey_Free(adopt); @@ -4619,6 +4624,7 @@ int test_wc_MlkemDecisionCoverage(void) * uncovered until the parser is fixed; expect the failure. */ derSz = test_mlkem_der_seed_only(der, t, rndMk, sizeof(rndMk), 0); XMEMSET(adopt, 0, sizeof(*adopt)); + ExpectIntEQ(wc_MlKemKey_Init(adopt, t, NULL, INVALID_DEVID), 0); idx = 0; ExpectIntNE(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), 0); wc_MlKemKey_Free(adopt); @@ -4628,6 +4634,7 @@ int test_wc_MlkemDecisionCoverage(void) * (ret == 0) is false with seed != NULL. */ derSz = test_mlkem_der_seed_only(der, t, rndMk, sizeof(rndMk), 1); XMEMSET(adopt, 0, sizeof(*adopt)); + ExpectIntEQ(wc_MlKemKey_Init(adopt, t, NULL, INVALID_DEVID), 0); idx = 0; ExpectIntNE(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), 0); wc_MlKemKey_Free(adopt); @@ -4639,6 +4646,7 @@ int test_wc_MlkemDecisionCoverage(void) derSz = test_mlkem_der_both(der, t, rndMk, sizeof(rndMk), expanded, privLen); XMEMSET(adopt, 0, sizeof(*adopt)); + ExpectIntEQ(wc_MlKemKey_Init(adopt, t, NULL, INVALID_DEVID), 0); idx = 0; ExpectIntNE(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), 0); wc_MlKemKey_Free(adopt); @@ -4648,6 +4656,7 @@ int test_wc_MlkemDecisionCoverage(void) derSz = test_mlkem_der_both(der, t, rndMk, sizeof(rndMk), expanded, privLen - 1); XMEMSET(adopt, 0, sizeof(*adopt)); + ExpectIntEQ(wc_MlKemKey_Init(adopt, t, NULL, INVALID_DEVID), 0); idx = 0; ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), WC_NO_ERR_TRACE(ASN_PARSE_E)); @@ -4657,6 +4666,7 @@ int test_wc_MlkemDecisionCoverage(void) * fails first, so (ret == 0) is false with the mismatch held. */ derSz = test_mlkem_der_both(der, t, rndMk, 32, expanded, privLen - 1); XMEMSET(adopt, 0, sizeof(*adopt)); + ExpectIntEQ(wc_MlKemKey_Init(adopt, t, NULL, INVALID_DEVID), 0); idx = 0; ExpectIntEQ(wc_MlKemKey_PrivateKeyDecode(adopt, der, derSz, &idx), WC_NO_ERR_TRACE(ASN_PARSE_E)); @@ -4672,6 +4682,7 @@ int test_wc_MlkemDecisionCoverage(void) * the false side (the SW-only fast path is skipped and the software * sponge runs instead). --- */ #if defined(USE_INTEL_SPEEDUP) && defined(WOLF_CRYPTO_CB) && \ + !defined(WOLFSSL_MLKEM_NO_ASN1) && !defined(WOLFSSL_MLKEM_NO_MAKE_KEY) && \ !defined(WOLF_CRYPTO_CB_FIND) && !defined(WOLFSSL_MLKEM_NO_ENCAPSULATE) && \ !defined(WOLFSSL_MLKEM_NO_DECAPSULATE) ExpectIntEQ(wc_MlKemKey_CipherTextSize(key2, &ctLen), 0); diff --git a/tests/api/test_tls13.c b/tests/api/test_tls13.c index d9712ae6502..7500027aeaa 100644 --- a/tests/api/test_tls13.c +++ b/tests/api/test_tls13.c @@ -14881,6 +14881,8 @@ int test_tls13_exporter_suite_decision_coverage(void) * handshake; the mismatched minor takes the second operand's true side. */ ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0); + wolfSSL_KeepArrays(ssl_c); + wolfSSL_KeepArrays(ssl_s); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); #if defined(HAVE_KEYING_MATERIAL) ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), @@ -14921,6 +14923,8 @@ int test_tls13_exporter_suite_decision_coverage(void) XMEMSET(&test_ctx, 0, sizeof(test_ctx)); ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + wolfSSL_KeepArrays(ssl_c); + wolfSSL_KeepArrays(ssl_s); ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), "MCDC", 4, NULL, 0, 0), WOLFSSL_SUCCESS); diff --git a/tests/api/test_x509.c b/tests/api/test_x509.c index 2a1fd5a0495..6dd94c3f5a4 100644 --- a/tests/api/test_x509.c +++ b/tests/api/test_x509.c @@ -1422,8 +1422,7 @@ int test_x509_decision_coverage(void) EXPECT_DECLS; #if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && \ !defined(NO_TLS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \ - (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \ - defined(KEEP_PEER_CERT) || defined(KEEP_OUR_CERT) || \ + (defined(OPENSSL_EXTRA) || defined(KEEP_PEER_CERT) || defined(KEEP_OUR_CERT) || \ defined(SESSION_CERTS)) WOLFSSL_X509* x509 = NULL; WOLFSSL_X509* fresh = NULL; diff --git a/tests/unit-mcdc/test_random_whitebox.c b/tests/unit-mcdc/test_random_whitebox.c index 2dfc7909d1c..6e3e4cbdb9a 100644 --- a/tests/unit-mcdc/test_random_whitebox.c +++ b/tests/unit-mcdc/test_random_whitebox.c @@ -832,7 +832,7 @@ static void wb_init_rng_seed_rng(void) /* :3273 seedRng!=NULL row: the seed is drawn from the parent's generate * function and its health test is skipped -- the exact branch the row * selects. */ - ret = _InitRng(&child, NULL, 0, NULL, 0, NULL, INVALID_DEVID, &parent, + ret = _InitRng(&child, NULL, 0, NULL, 0, NULL, 0, NULL, INVALID_DEVID, &parent, WC_RNG_INIT_FLAG_NONE); if (ret != 0) { WB_NOTE("_InitRng with seedRng failed"); From 6f9a6efbdc4bb79dc5fa8eca8fb7940320d256d9 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 8 Oct 2026 15:12:28 +0200 Subject: [PATCH 29/33] tests: fix remaining CI rows --- tests/api/test_tls13.c | 6 ++++-- tests/api/test_x509.c | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/api/test_tls13.c b/tests/api/test_tls13.c index 7500027aeaa..0849107c98d 100644 --- a/tests/api/test_tls13.c +++ b/tests/api/test_tls13.c @@ -14887,7 +14887,9 @@ int test_tls13_exporter_suite_decision_coverage(void) #if defined(HAVE_KEYING_MATERIAL) ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), "MCDC", 4, NULL, 0, 0), WOLFSSL_SUCCESS); - ssl_c->version.minor = 0x01; /* TLS 1.0 minor: the guard must fire */ + /* Stay on the TLS 1.3 exporter path while failing its exact-version + * check. A TLS 1.0 minor selects the TLS 1.2 exporter instead. */ + ssl_c->version.minor = TLSv1_3_MINOR + 1; ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), "MCDC", 4, NULL, 0, 0), WOLFSSL_FAILURE); #endif /* HAVE_KEYING_MATERIAL */ @@ -14928,7 +14930,7 @@ int test_tls13_exporter_suite_decision_coverage(void) ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), "MCDC", 4, NULL, 0, 0), WOLFSSL_SUCCESS); - ssl_c->version.minor = TLSv1_3_MINOR; /* mismatch: the guard must fire */ + ssl_c->version.minor = DTLSv1_3_MINOR - 1; ExpectIntEQ(wolfSSL_export_keying_material(ssl_c, out, sizeof(out), "MCDC", 4, NULL, 0, 0), WOLFSSL_FAILURE); diff --git a/tests/api/test_x509.c b/tests/api/test_x509.c index 6dd94c3f5a4..ae86d0d0d6e 100644 --- a/tests/api/test_x509.c +++ b/tests/api/test_x509.c @@ -1422,8 +1422,8 @@ int test_x509_decision_coverage(void) EXPECT_DECLS; #if !defined(WOLFCRYPT_ONLY) && !defined(NO_WOLFSSL_CLIENT) && \ !defined(NO_TLS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \ - (defined(OPENSSL_EXTRA) || defined(KEEP_PEER_CERT) || defined(KEEP_OUR_CERT) || \ - defined(SESSION_CERTS)) + (defined(OPENSSL_EXTRA) || defined(KEEP_PEER_CERT) || \ + defined(KEEP_OUR_CERT)) WOLFSSL_X509* x509 = NULL; WOLFSSL_X509* fresh = NULL; WOLFSSL_X509* loaded = NULL; From fc72ed8022cb8bf94ca4c978338be4a0f35e0a5a Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 8 Oct 2026 16:23:43 +0200 Subject: [PATCH 30/33] tests: gate AES decision rows in old FIPS --- tests/api/test_aes.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/api/test_aes.c b/tests/api/test_aes.c index 75b1f3b0fe7..6f62493241c 100644 --- a/tests/api/test_aes.c +++ b/tests/api/test_aes.c @@ -13974,11 +13974,13 @@ int test_wc_AesEcb_RetCodeChecked(void) * Excluded under HAVE_SELFTEST: the CAVP self-test leg compiles the frozen * wolfCrypt 4.1.0 aes.c, whose GCM-stream/XTS/CTR paths predate these * guards, so the open aes.c this measures is not the one built (same - * exclusion as the AesFeatureCoverage GCM/CCM blocks). */ + * exclusion as the AesFeatureCoverage GCM/CCM blocks). Older FIPS modules + * also omit these AES paths and some of their public size constants. */ int test_wc_AesReworkDecisionCoverage(void) { EXPECT_DECLS; -#if !defined(NO_AES) && !defined(HAVE_SELFTEST) +#if !defined(NO_AES) && !defined(HAVE_SELFTEST) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)) Aes aes; byte key16[16]; byte iv[WC_AES_BLOCK_SIZE]; From c6a3d32bc2eaeaa53500fccd5dae0cfb2a2af452 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 8 Oct 2026 16:54:45 +0200 Subject: [PATCH 31/33] tests: register TLS white-box source --- tests/include.am | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/include.am b/tests/include.am index 0d27b2a34e9..f58fcbd9b61 100644 --- a/tests/include.am +++ b/tests/include.am @@ -252,6 +252,7 @@ EXTRA_DIST += \ tests/unit-mcdc/test_tfm_whitebox.c \ tests/unit-mcdc/test_tls13_null_whitebox.c \ tests/unit-mcdc/test_tls13_whitebox.c \ + tests/unit-mcdc/test_tls_whitebox.c \ tests/unit-mcdc/test_tsp_fault_whitebox.c \ tests/unit-mcdc/test_tsp_whitebox.c \ tests/unit-mcdc/test_wc_encrypt_whitebox.c \ From 7518e526c9e8c84bed525cef68eb745d777d4530 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 8 Oct 2026 18:54:18 +0200 Subject: [PATCH 32/33] tests: fix FIPS and PKCS7 checks --- tests/api/test_aes.c | 9 ++++----- tests/api/test_pkcs7.c | 3 +++ wolfssl/internal.h | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/api/test_aes.c b/tests/api/test_aes.c index 6f62493241c..d78731ff1fc 100644 --- a/tests/api/test_aes.c +++ b/tests/api/test_aes.c @@ -13974,13 +13974,12 @@ int test_wc_AesEcb_RetCodeChecked(void) * Excluded under HAVE_SELFTEST: the CAVP self-test leg compiles the frozen * wolfCrypt 4.1.0 aes.c, whose GCM-stream/XTS/CTR paths predate these * guards, so the open aes.c this measures is not the one built (same - * exclusion as the AesFeatureCoverage GCM/CCM blocks). Older FIPS modules - * also omit these AES paths and some of their public size constants. */ + * exclusion as the AesFeatureCoverage GCM/CCM blocks). FIPS modules also + * use different AES paths and do not provide every public size constant. */ int test_wc_AesReworkDecisionCoverage(void) { EXPECT_DECLS; -#if !defined(NO_AES) && !defined(HAVE_SELFTEST) && \ - (!defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)) +#if !defined(NO_AES) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) Aes aes; byte key16[16]; byte iv[WC_AES_BLOCK_SIZE]; @@ -14162,6 +14161,6 @@ int test_wc_AesReworkDecisionCoverage(void) ExpectIntEQ(wc_AesCfbDecrypt(&aes, out, in, 10), 0); wc_AesFree(&aes); #endif -#endif /* !NO_AES && !HAVE_SELFTEST */ +#endif /* !NO_AES && !HAVE_SELFTEST && !HAVE_FIPS */ return EXPECT_RESULT(); } diff --git a/tests/api/test_pkcs7.c b/tests/api/test_pkcs7.c index e406c7b62c7..bd0ad64c96e 100644 --- a/tests/api/test_pkcs7.c +++ b/tests/api/test_pkcs7.c @@ -9051,6 +9051,9 @@ int test_wc_PKCS7_SkidParseDecisionCoverage(void) marker = test_PKCS7_findBytes(explicitSKIDSignedData, (int)sz, explicitMarker, (int)sizeof(explicitMarker)); ExpectIntGE(marker, 0); + ExpectIntLE(marker, (int)(sz - sizeof(explicitMarker))); + if (marker < 0 || (word32)marker > sz - sizeof(explicitMarker)) + return EXPECT_RESULT(); /* Truncate after the [0] tag: the [0] length read fails, so the * (ret == 0) operands of the inSz and GetASNTag checks are false. */ diff --git a/wolfssl/internal.h b/wolfssl/internal.h index bdf57173647..49aef438392 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -7401,7 +7401,6 @@ do { \ } while (0) WOLFSSL_LOCAL int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup); -WOLFSSL_LOCAL int CheckVersion(WOLFSSL* ssl, ProtocolVersion pv); WOLFSSL_LOCAL int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup); WOLFSSL_LOCAL int ReinitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup); WOLFSSL_LOCAL void FreeSSL(WOLFSSL* ssl, void* heap); From 0ca325e07d035126a7f2580eceee8f2612b065bf Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 8 Oct 2026 18:55:31 +0200 Subject: [PATCH 33/33] tests: initialize AES GCM input --- tests/api/test_aes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/api/test_aes.c b/tests/api/test_aes.c index d78731ff1fc..fc39310e45f 100644 --- a/tests/api/test_aes.c +++ b/tests/api/test_aes.c @@ -14011,7 +14011,8 @@ int test_wc_AesReworkDecisionCoverage(void) #if defined(WOLF_PRIVATE_KEY_ID) XMEMSET(id, 4, sizeof(id)); #endif -#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \ +#if defined(HAVE_AESGCM) || defined(WOLFSSL_AES_COUNTER) || \ + defined(WOLFSSL_AES_CFB) || \ defined(WOLFSSL_AES_XTS) XMEMSET(in, 5, sizeof(in)); #endif