Skip to content

Commit 1d1ec94

Browse files
Fix for setting curve using all caps with wolfSSL_set1_curves_list
1 parent 350706d commit 1d1ec94

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
@@ -16944,7 +16944,7 @@ int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names,
1694416944
goto leave;
1694516945
}
1694616946

16947-
eccSet = wc_ecc_get_curve_params(ret);
16947+
eccSet = wc_ecc_get_curve_params(nret);
1694816948
if (eccSet == NULL) {
1694916949
WOLFSSL_MSG("NULL set returned");
1695016950
goto leave;

tests/api/test_tls13.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,3 +3186,47 @@ int test_tls13_cert_req_sigalgs(void)
31863186
return EXPECT_RESULT();
31873187
}
31883188

3189+
/* Test that set_curves_list correctly resolves ECC curve names that fall
3190+
* through the kNistCurves table and reach the wc_ecc_get_curve_idx_from_name
3191+
* fallback path. The kNistCurves lookup uses a case-sensitive XSTRNCMP, so
3192+
* uppercase names like "SECP384R1" do not match the lowercase "secp384r1"
3193+
* entry; they fall through to the wolfCrypt ECC look-up which uses
3194+
* XSTRCASECMP. */
3195+
int test_set_curves_list_ecc_fallback(void)
3196+
{
3197+
EXPECT_DECLS;
3198+
#if defined(WOLFSSL_TLS13) && defined(HAVE_ECC) && \
3199+
(defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && \
3200+
!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
3201+
(defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
3202+
ECC_MIN_KEY_SZ <= 384
3203+
#ifndef NO_WOLFSSL_CLIENT
3204+
WOLFSSL_CTX* ctx = NULL;
3205+
WOLFSSL* ssl = NULL;
3206+
3207+
/* "SECP384R1" (uppercase) is NOT in kNistCurves (case-sensitive table),
3208+
* so set_curves_list must use the wc_ecc_get_curve_idx_from_name fallback.
3209+
*/
3210+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
3211+
3212+
/* CTX-level: set single curve via its wolfCrypt name (uppercase) */
3213+
ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "SECP384R1"),
3214+
WOLFSSL_SUCCESS);
3215+
3216+
/* Verify the correct curve was stored, not ecc_sets[0] */
3217+
ExpectIntEQ(ctx->numGroups, 1);
3218+
ExpectIntEQ(ctx->group[0], WOLFSSL_ECC_SECP384R1);
3219+
3220+
/* SSL-level: same check via wolfSSL_set1_curves_list */
3221+
ExpectNotNull(ssl = wolfSSL_new(ctx));
3222+
ExpectIntEQ(wolfSSL_set1_curves_list(ssl, "SECP384R1"), WOLFSSL_SUCCESS);
3223+
ExpectIntEQ(ssl->numGroups, 1);
3224+
ExpectIntEQ(ssl->group[0], WOLFSSL_ECC_SECP384R1);
3225+
3226+
wolfSSL_free(ssl);
3227+
wolfSSL_CTX_free(ctx);
3228+
#endif /* NO_WOLFSSL_CLIENT */
3229+
#endif
3230+
return EXPECT_RESULT();
3231+
}
3232+

tests/api/test_tls13.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int test_key_share_mismatch(void);
3939
int test_tls13_middlebox_compat_empty_session_id(void);
4040
int test_tls13_plaintext_alert(void);
4141
int test_tls13_cert_req_sigalgs(void);
42+
int test_set_curves_list_ecc_fallback(void);
4243

4344
#define TEST_TLS13_DECLS \
4445
TEST_DECL_GROUP("tls13", test_tls13_apis), \
@@ -55,6 +56,7 @@ int test_tls13_cert_req_sigalgs(void);
5556
TEST_DECL_GROUP("tls13", test_key_share_mismatch), \
5657
TEST_DECL_GROUP("tls13", test_tls13_middlebox_compat_empty_session_id), \
5758
TEST_DECL_GROUP("tls13", test_tls13_plaintext_alert), \
58-
TEST_DECL_GROUP("tls13", test_tls13_cert_req_sigalgs)
59+
TEST_DECL_GROUP("tls13", test_tls13_cert_req_sigalgs), \
60+
TEST_DECL_GROUP("tls13", test_set_curves_list_ecc_fallback)
5961

6062
#endif /* WOLFCRYPT_TEST_TLS13_H */

0 commit comments

Comments
 (0)