Skip to content

Commit 65286e4

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

3 files changed

Lines changed: 48 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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,47 @@ int test_tls12_bad_cv_sig_alg(void)
666666
return EXPECT_RESULT();
667667
}
668668

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

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)