Skip to content

Commit df50430

Browse files
authored
Merge pull request #9863 from JacobBarthelmeh/f361
Fix for setting curve using all caps with wolfSSL_set1_curves_list
2 parents 65092ab + 6e56635 commit df50430

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
@@ -16957,7 +16957,7 @@ int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names,
1695716957
goto leave;
1695816958
}
1695916959

16960-
eccSet = wc_ecc_get_curve_params(ret);
16960+
eccSet = wc_ecc_get_curve_params(nret);
1696116961
if (eccSet == NULL) {
1696216962
WOLFSSL_MSG("NULL set returned");
1696316963
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)
@@ -723,3 +724,47 @@ int test_tls12_no_null_compression(void)
723724
return EXPECT_RESULT();
724725
}
725726

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+

tests/api/test_tls.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ int test_tls13_curve_intersection(void);
3030
int test_tls_certreq_order(void);
3131
int test_tls12_bad_cv_sig_alg(void);
3232
int test_tls12_no_null_compression(void);
33+
int test_tls_set_curves_list_ecc_fallback(void);
3334

3435
#define TEST_TLS_DECLS \
3536
TEST_DECL_GROUP("tls", test_utils_memio_move_message), \
@@ -39,6 +40,7 @@ int test_tls12_no_null_compression(void);
3940
TEST_DECL_GROUP("tls", test_tls13_curve_intersection), \
4041
TEST_DECL_GROUP("tls", test_tls_certreq_order), \
4142
TEST_DECL_GROUP("tls", test_tls12_bad_cv_sig_alg), \
42-
TEST_DECL_GROUP("tls", test_tls12_no_null_compression)
43+
TEST_DECL_GROUP("tls", test_tls12_no_null_compression), \
44+
TEST_DECL_GROUP("tls", test_tls_set_curves_list_ecc_fallback)
4345

4446
#endif /* TESTS_API_TEST_TLS_H */

0 commit comments

Comments
 (0)