|
30 | 30 |
|
31 | 31 | #include <tests/utils.h> |
32 | 32 | #include <tests/api/test_tls.h> |
| 33 | +#include <wolfssl/internal.h> |
33 | 34 |
|
34 | 35 |
|
35 | 36 | int test_utils_memio_move_message(void) |
@@ -666,3 +667,47 @@ int test_tls12_bad_cv_sig_alg(void) |
666 | 667 | return EXPECT_RESULT(); |
667 | 668 | } |
668 | 669 |
|
| 670 | +/* Test that set_curves_list correctly resolves ECC curve names that fall |
| 671 | + * through the kNistCurves table and reach the wc_ecc_get_curve_idx_from_name |
| 672 | + * fallback path. The kNistCurves lookup uses a case-sensitive XSTRNCMP, so |
| 673 | + * uppercase names like "SECP384R1" do not match the lowercase "secp384r1" |
| 674 | + * entry; they fall through to the wolfCrypt ECC look-up which uses |
| 675 | + * XSTRCASECMP. */ |
| 676 | +int test_tls_set_curves_list_ecc_fallback(void) |
| 677 | +{ |
| 678 | + EXPECT_DECLS; |
| 679 | +#if defined(WOLFSSL_TLS13) && defined(HAVE_ECC) && \ |
| 680 | + (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && \ |
| 681 | + !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \ |
| 682 | + (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \ |
| 683 | + ECC_MIN_KEY_SZ <= 384 |
| 684 | +#ifndef NO_WOLFSSL_CLIENT |
| 685 | + WOLFSSL_CTX* ctx = NULL; |
| 686 | + WOLFSSL* ssl = NULL; |
| 687 | + |
| 688 | + /* "SECP384R1" (uppercase) is NOT in kNistCurves (case-sensitive table), |
| 689 | + * so set_curves_list must use the wc_ecc_get_curve_idx_from_name fallback. |
| 690 | + */ |
| 691 | + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method())); |
| 692 | + |
| 693 | + /* CTX-level: set single curve via its wolfCrypt name (uppercase) */ |
| 694 | + ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "SECP384R1"), |
| 695 | + WOLFSSL_SUCCESS); |
| 696 | + |
| 697 | + /* Verify the correct curve was stored, not ecc_sets[0] */ |
| 698 | + ExpectIntEQ(ctx->numGroups, 1); |
| 699 | + ExpectIntEQ(ctx->group[0], WOLFSSL_ECC_SECP384R1); |
| 700 | + |
| 701 | + /* SSL-level: same check via wolfSSL_set1_curves_list */ |
| 702 | + ExpectNotNull(ssl = wolfSSL_new(ctx)); |
| 703 | + ExpectIntEQ(wolfSSL_set1_curves_list(ssl, "SECP384R1"), WOLFSSL_SUCCESS); |
| 704 | + ExpectIntEQ(ssl->numGroups, 1); |
| 705 | + ExpectIntEQ(ssl->group[0], WOLFSSL_ECC_SECP384R1); |
| 706 | + |
| 707 | + wolfSSL_free(ssl); |
| 708 | + wolfSSL_CTX_free(ctx); |
| 709 | +#endif /* NO_WOLFSSL_CLIENT */ |
| 710 | +#endif |
| 711 | + return EXPECT_RESULT(); |
| 712 | +} |
| 713 | + |
0 commit comments