Skip to content

Commit 2d8ec89

Browse files
Fix for setting curve using all caps with wolfSSL_set1_curves_list
1 parent 90ca9c4 commit 2d8ec89

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

src/ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16949,7 +16949,7 @@ int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names,
1694916949
goto leave;
1695016950
}
1695116951

16952-
eccSet = wc_ecc_get_curve_params(ret);
16952+
eccSet = wc_ecc_get_curve_params(nret);
1695316953
if (eccSet == NULL) {
1695416954
WOLFSSL_MSG("NULL set returned");
1695516955
goto leave;

tests/api/test_tls.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <tests/utils.h>
3232
#include <tests/api/test_tls.h>
33+
#include <wolfssl/internal.h>
3334

3435

3536
int test_utils_memio_move_message(void)
@@ -666,3 +667,47 @@ int test_tls12_bad_cv_sig_alg(void)
666667
return EXPECT_RESULT();
667668
}
668669

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+

tests/api/test_tls.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int test_tls12_curve_intersection(void);
2929
int test_tls13_curve_intersection(void);
3030
int test_tls_certreq_order(void);
3131
int test_tls12_bad_cv_sig_alg(void);
32+
int test_tls_set_curves_list_ecc_fallback(void);
3233

3334
#define TEST_TLS_DECLS \
3435
TEST_DECL_GROUP("tls", test_utils_memio_move_message), \
@@ -37,6 +38,7 @@ int test_tls12_bad_cv_sig_alg(void);
3738
TEST_DECL_GROUP("tls", test_tls12_curve_intersection), \
3839
TEST_DECL_GROUP("tls", test_tls13_curve_intersection), \
3940
TEST_DECL_GROUP("tls", test_tls_certreq_order), \
40-
TEST_DECL_GROUP("tls", test_tls12_bad_cv_sig_alg)
41+
TEST_DECL_GROUP("tls", test_tls12_bad_cv_sig_alg), \
42+
TEST_DECL_GROUP("tls", test_tls_set_curves_list_ecc_fallback)
4143

4244
#endif /* TESTS_API_TEST_TLS_H */

0 commit comments

Comments
 (0)