|
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) |
@@ -723,3 +724,47 @@ int test_tls12_no_null_compression(void) |
723 | 724 | return EXPECT_RESULT(); |
724 | 725 | } |
725 | 726 |
|
| 727 | +/* Test that set_curves_list correctly resolves ECC curve names that fall |
| 728 | + * through the kNistCurves table and reach the wc_ecc_get_curve_idx_from_name |
| 729 | + * fallback path. The kNistCurves lookup uses a case-sensitive XSTRNCMP, so |
| 730 | + * uppercase names like "SECP384R1" do not match the lowercase "secp384r1" |
| 731 | + * entry; they fall through to the wolfCrypt ECC look-up which uses |
| 732 | + * XSTRCASECMP. */ |
| 733 | +int test_tls_set_curves_list_ecc_fallback(void) |
| 734 | +{ |
| 735 | + EXPECT_DECLS; |
| 736 | +#if defined(WOLFSSL_TLS13) && defined(HAVE_ECC) && \ |
| 737 | + (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && \ |
| 738 | + !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \ |
| 739 | + (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \ |
| 740 | + ECC_MIN_KEY_SZ <= 384 |
| 741 | +#ifndef NO_WOLFSSL_CLIENT |
| 742 | + WOLFSSL_CTX* ctx = NULL; |
| 743 | + WOLFSSL* ssl = NULL; |
| 744 | + |
| 745 | + /* "SECP384R1" (uppercase) is NOT in kNistCurves (case-sensitive table), |
| 746 | + * so set_curves_list must use the wc_ecc_get_curve_idx_from_name fallback. |
| 747 | + */ |
| 748 | + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method())); |
| 749 | + |
| 750 | + /* CTX-level: set single curve via its wolfCrypt name (uppercase) */ |
| 751 | + ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "SECP384R1"), |
| 752 | + WOLFSSL_SUCCESS); |
| 753 | + |
| 754 | + /* Verify the correct curve was stored, not ecc_sets[0] */ |
| 755 | + ExpectIntEQ(ctx->numGroups, 1); |
| 756 | + ExpectIntEQ(ctx->group[0], WOLFSSL_ECC_SECP384R1); |
| 757 | + |
| 758 | + /* SSL-level: same check via wolfSSL_set1_curves_list */ |
| 759 | + ExpectNotNull(ssl = wolfSSL_new(ctx)); |
| 760 | + ExpectIntEQ(wolfSSL_set1_curves_list(ssl, "SECP384R1"), WOLFSSL_SUCCESS); |
| 761 | + ExpectIntEQ(ssl->numGroups, 1); |
| 762 | + ExpectIntEQ(ssl->group[0], WOLFSSL_ECC_SECP384R1); |
| 763 | + |
| 764 | + wolfSSL_free(ssl); |
| 765 | + wolfSSL_CTX_free(ctx); |
| 766 | +#endif /* NO_WOLFSSL_CLIENT */ |
| 767 | +#endif |
| 768 | + return EXPECT_RESULT(); |
| 769 | +} |
| 770 | + |
0 commit comments