Skip to content

Commit 6b47ebd

Browse files
committed
Expose *_set_groups for TLS < 1.3
- Add test to make sure we fail on curve mismatch
1 parent 020bcd0 commit 6b47ebd

7 files changed

Lines changed: 233 additions & 111 deletions

File tree

src/internal.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,22 @@ int IsTLS(const WOLFSSL* ssl)
517517
{
518518
if (ssl->version.major == SSLv3_MAJOR && ssl->version.minor >=TLSv1_MINOR)
519519
return 1;
520+
#ifdef WOLFSSL_DTLS
521+
if (ssl->version.major == DTLS_MAJOR)
522+
return 1;
523+
#endif
524+
525+
return 0;
526+
}
527+
528+
int IsTLS_ex(const ProtocolVersion pv)
529+
{
530+
if (pv.major == SSLv3_MAJOR && pv.minor >=TLSv1_MINOR)
531+
return 1;
532+
#ifdef WOLFSSL_DTLS
533+
if (pv.major == DTLS_MAJOR)
534+
return 1;
535+
#endif
520536

521537
return 0;
522538
}

src/ssl.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,7 @@ int wolfSSL_GetOutputSize(WOLFSSL* ssl, int inSz)
26922692
#ifdef HAVE_ECC
26932693
int wolfSSL_CTX_SetMinEccKey_Sz(WOLFSSL_CTX* ctx, short keySz)
26942694
{
2695+
WOLFSSL_ENTER("wolfSSL_CTX_SetMinEccKey_Sz");
26952696
if (ctx == NULL || keySz < 0 || keySz % 8 != 0) {
26962697
WOLFSSL_MSG("Key size must be divisible by 8 or ctx was null");
26972698
return BAD_FUNC_ARG;
@@ -2707,6 +2708,7 @@ int wolfSSL_CTX_SetMinEccKey_Sz(WOLFSSL_CTX* ctx, short keySz)
27072708

27082709
int wolfSSL_SetMinEccKey_Sz(WOLFSSL* ssl, short keySz)
27092710
{
2711+
WOLFSSL_ENTER("wolfSSL_SetMinEccKey_Sz");
27102712
if (ssl == NULL || keySz < 0 || keySz % 8 != 0) {
27112713
WOLFSSL_MSG("Key size must be divisible by 8 or ssl was null");
27122714
return BAD_FUNC_ARG;
@@ -3349,7 +3351,7 @@ int wolfSSL_CTX_UseSupportedCurve(WOLFSSL_CTX* ctx, word16 name)
33493351
#endif /* NO_TLS */
33503352
}
33513353

3352-
#if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13)
3354+
#if defined(OPENSSL_EXTRA)
33533355
int wolfSSL_CTX_set1_groups(WOLFSSL_CTX* ctx, int* groups,
33543356
int count)
33553357
{
@@ -3420,7 +3422,7 @@ int wolfSSL_set1_groups(WOLFSSL* ssl, int* groups, int count)
34203422
return wolfSSL_set_groups(ssl, _groups, count) == WOLFSSL_SUCCESS ?
34213423
WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
34223424
}
3423-
#endif /* OPENSSL_EXTRA && WOLFSSL_TLS13 */
3425+
#endif /* OPENSSL_EXTRA */
34243426
#endif /* HAVE_SUPPORTED_CURVES */
34253427

34263428
/* Application-Layer Protocol Negotiation */
@@ -7877,6 +7879,8 @@ WOLFSSL_API int wolfSSL_get_negotiated_server_cert_type(WOLFSSL* ssl, int* tp)
78777879
/* Set Temp CTX EC-DHE size in octets, can be 14 - 66 (112 - 521 bit) */
78787880
int wolfSSL_CTX_SetTmpEC_DHE_Sz(WOLFSSL_CTX* ctx, word16 sz)
78797881
{
7882+
WOLFSSL_ENTER("wolfSSL_CTX_SetTmpEC_DHE_Sz");
7883+
78807884
if (ctx == NULL)
78817885
return BAD_FUNC_ARG;
78827886

@@ -7911,6 +7915,8 @@ int wolfSSL_CTX_SetTmpEC_DHE_Sz(WOLFSSL_CTX* ctx, word16 sz)
79117915
/* Set Temp SSL EC-DHE size in octets, can be 14 - 66 (112 - 521 bit) */
79127916
int wolfSSL_SetTmpEC_DHE_Sz(WOLFSSL* ssl, word16 sz)
79137917
{
7918+
WOLFSSL_ENTER("wolfSSL_SetTmpEC_DHE_Sz");
7919+
79147920
if (ssl == NULL)
79157921
return BAD_FUNC_ARG;
79167922

@@ -15819,7 +15825,6 @@ long wolfSSL_set_options(WOLFSSL* ssl, long op)
1581915825
}
1582015826
ssl->suites->hashSigAlgoSz = out;
1582115827
}
15822-
1582315828
}
1582415829

1582515830
return ssl->options.mask;
@@ -21356,20 +21361,29 @@ void wolfSSL_get0_next_proto_negotiated(const WOLFSSL *s,
2135621361
#if defined(OPENSSL_EXTRA) || defined(HAVE_CURL)
2135721362
int wolfSSL_curve_is_disabled(const WOLFSSL* ssl, word16 curve_id)
2135821363
{
21359-
if (curve_id >= WOLFSSL_FFDHE_START) {
21360-
/* DH parameters are never disabled. */
21361-
return 0;
21362-
}
21363-
if (curve_id > WOLFSSL_ECC_MAX_AVAIL) {
21364-
WOLFSSL_MSG("Curve id out of supported range");
21365-
/* Disabled if not in valid range. */
21366-
return 1;
21367-
}
21368-
if (curve_id >= 32) {
21369-
/* 0 is for invalid and 1-14 aren't used otherwise. */
21370-
return (ssl->disabledCurves & (1U << (curve_id - 32))) != 0;
21364+
int ret = 0;
21365+
21366+
WOLFSSL_ENTER("wolfSSL_curve_is_disabled");
21367+
WOLFSSL_MSG_EX("wolfSSL_curve_is_disabled checking for %d", curve_id);
21368+
21369+
/* (curve_id >= WOLFSSL_FFDHE_START) - DH parameters are never disabled. */
21370+
if (curve_id < WOLFSSL_FFDHE_START) {
21371+
if (curve_id > WOLFSSL_ECC_MAX_AVAIL) {
21372+
WOLFSSL_MSG("Curve id out of supported range");
21373+
/* Disabled if not in valid range. */
21374+
ret = 1;
21375+
}
21376+
else if (curve_id >= 32) {
21377+
/* 0 is for invalid and 1-14 aren't used otherwise. */
21378+
ret = (ssl->disabledCurves & (1U << (curve_id - 32))) != 0;
21379+
}
21380+
else {
21381+
ret = (ssl->disabledCurves & (1U << curve_id)) != 0;
21382+
}
2137121383
}
21372-
return (ssl->disabledCurves & (1U << curve_id)) != 0;
21384+
21385+
WOLFSSL_LEAVE("wolfSSL_curve_is_disabled", ret);
21386+
return ret;
2137321387
}
2137421388

2137521389
#if (defined(HAVE_ECC) || \
@@ -21504,7 +21518,7 @@ static int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names)
2150421518
disabled &= ~(1U << curve);
2150521519
}
2150621520
#ifdef HAVE_SUPPORTED_CURVES
21507-
#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_OLD_SET_CURVES_LIST)
21521+
#if !defined(WOLFSSL_OLD_SET_CURVES_LIST)
2150821522
/* using the wolfSSL API to set the groups, this will populate
2150921523
* (ssl|ctx)->groups and reset any TLSX_SUPPORTED_GROUPS.
2151021524
* The order in (ssl|ctx)->groups will then be respected
@@ -21545,6 +21559,7 @@ static int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names)
2154521559

2154621560
int wolfSSL_CTX_set1_curves_list(WOLFSSL_CTX* ctx, const char* names)
2154721561
{
21562+
WOLFSSL_ENTER("wolfSSL_CTX_set1_curves_list");
2154821563
if (ctx == NULL || names == NULL) {
2154921564
WOLFSSL_MSG("ctx or names was NULL");
2155021565
return WOLFSSL_FAILURE;
@@ -21554,6 +21569,7 @@ int wolfSSL_CTX_set1_curves_list(WOLFSSL_CTX* ctx, const char* names)
2155421569

2155521570
int wolfSSL_set1_curves_list(WOLFSSL* ssl, const char* names)
2155621571
{
21572+
WOLFSSL_ENTER("wolfSSL_set1_curves_list");
2155721573
if (ssl == NULL || names == NULL) {
2155821574
WOLFSSL_MSG("ssl or names was NULL");
2155921575
return WOLFSSL_FAILURE;

src/tls.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,86 @@ ProtocolVersion MakeTLSv1_3(void)
300300
}
301301
#endif
302302

303+
#if defined(HAVE_SUPPORTED_CURVES)
304+
/* Sets the key exchange groups in rank order on a context.
305+
*
306+
* ctx SSL/TLS context object.
307+
* groups Array of groups.
308+
* count Number of groups in array.
309+
* returns BAD_FUNC_ARG when ctx or groups is NULL, not using TLS v1.3 or
310+
* count is greater than WOLFSSL_MAX_GROUP_COUNT and WOLFSSL_SUCCESS on success.
311+
*/
312+
int wolfSSL_CTX_set_groups(WOLFSSL_CTX* ctx, int* groups, int count)
313+
{
314+
int ret, i;
315+
316+
WOLFSSL_ENTER("wolfSSL_CTX_set_groups");
317+
if (ctx == NULL || groups == NULL || count > WOLFSSL_MAX_GROUP_COUNT)
318+
return BAD_FUNC_ARG;
319+
if (!IsTLS_ex(ctx->method->version))
320+
return BAD_FUNC_ARG;
321+
322+
ctx->numGroups = 0;
323+
#if !defined(NO_TLS)
324+
TLSX_Remove(&ctx->extensions, TLSX_SUPPORTED_GROUPS, ctx->heap);
325+
#endif /* !NO_TLS */
326+
for (i = 0; i < count; i++) {
327+
/* Call to wolfSSL_CTX_UseSupportedCurve also checks if input groups
328+
* are valid */
329+
if ((ret = wolfSSL_CTX_UseSupportedCurve(ctx, (word16)groups[i]))
330+
!= WOLFSSL_SUCCESS) {
331+
#if !defined(NO_TLS)
332+
TLSX_Remove(&ctx->extensions, TLSX_SUPPORTED_GROUPS, ctx->heap);
333+
#endif /* !NO_TLS */
334+
return ret;
335+
}
336+
ctx->group[i] = (word16)groups[i];
337+
}
338+
ctx->numGroups = (byte)count;
339+
340+
return WOLFSSL_SUCCESS;
341+
}
342+
343+
/* Sets the key exchange groups in rank order.
344+
*
345+
* ssl SSL/TLS object.
346+
* groups Array of groups.
347+
* count Number of groups in array.
348+
* returns BAD_FUNC_ARG when ssl or groups is NULL, not using TLS v1.3 or
349+
* count is greater than WOLFSSL_MAX_GROUP_COUNT and WOLFSSL_SUCCESS on success.
350+
*/
351+
int wolfSSL_set_groups(WOLFSSL* ssl, int* groups, int count)
352+
{
353+
int ret, i;
354+
355+
WOLFSSL_ENTER("wolfSSL_set_groups");
356+
if (ssl == NULL || groups == NULL || count > WOLFSSL_MAX_GROUP_COUNT)
357+
return BAD_FUNC_ARG;
358+
if (!IsTLS_ex(ssl->version))
359+
return BAD_FUNC_ARG;
360+
361+
ssl->numGroups = 0;
362+
#if !defined(NO_TLS)
363+
TLSX_Remove(&ssl->extensions, TLSX_SUPPORTED_GROUPS, ssl->heap);
364+
#endif /* !NO_TLS */
365+
for (i = 0; i < count; i++) {
366+
/* Call to wolfSSL_UseSupportedCurve also checks if input groups
367+
* are valid */
368+
if ((ret = wolfSSL_UseSupportedCurve(ssl, (word16)groups[i]))
369+
!= WOLFSSL_SUCCESS) {
370+
#if !defined(NO_TLS)
371+
TLSX_Remove(&ssl->extensions, TLSX_SUPPORTED_GROUPS, ssl->heap);
372+
#endif /* !NO_TLS */
373+
return ret;
374+
}
375+
ssl->group[i] = (word16)groups[i];
376+
}
377+
ssl->numGroups = (byte)count;
378+
379+
return WOLFSSL_SUCCESS;
380+
}
381+
#endif /* HAVE_SUPPORTED_CURVES */
382+
303383
#ifndef WOLFSSL_NO_TLS12
304384

305385
#ifdef HAVE_EXTENDED_MASTER
@@ -4675,6 +4755,7 @@ int TLSX_ValidateSupportedCurves(const WOLFSSL* ssl, byte first, byte second,
46754755
int ephmSuite = 0;
46764756
word16 octets = 0; /* according to 'ecc_set_type ecc_sets[];' */
46774757
int key = 0; /* validate key */
4758+
int foundCurve = 0; /* Found at least one supported curve */
46784759

46794760
(void)oid;
46804761

@@ -4836,6 +4917,8 @@ int TLSX_ValidateSupportedCurves(const WOLFSSL* ssl, byte first, byte second,
48364917
default: continue; /* unsupported curve */
48374918
}
48384919

4920+
foundCurve = 1;
4921+
48394922
#ifdef HAVE_ECC
48404923
/* Set default Oid */
48414924
if (defOid == 0 && ssl->eccTempKeySz <= octets && defSz > octets) {
@@ -4980,6 +5063,10 @@ int TLSX_ValidateSupportedCurves(const WOLFSSL* ssl, byte first, byte second,
49805063
}
49815064
}
49825065

5066+
/* Check we found at least one supported curve */
5067+
if (!foundCurve)
5068+
return 0;
5069+
49835070
*ecdhCurveOID = ssl->ecdhCurveOID;
49845071
/* Choose the default if it is at the required strength. */
49855072
#ifdef HAVE_ECC

src/tls13.c

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -13687,86 +13687,6 @@ int wolfSSL_preferred_group(WOLFSSL* ssl)
1368713687
}
1368813688
#endif
1368913689

13690-
#if defined(HAVE_SUPPORTED_CURVES)
13691-
/* Sets the key exchange groups in rank order on a context.
13692-
*
13693-
* ctx SSL/TLS context object.
13694-
* groups Array of groups.
13695-
* count Number of groups in array.
13696-
* returns BAD_FUNC_ARG when ctx or groups is NULL, not using TLS v1.3 or
13697-
* count is greater than WOLFSSL_MAX_GROUP_COUNT and WOLFSSL_SUCCESS on success.
13698-
*/
13699-
int wolfSSL_CTX_set_groups(WOLFSSL_CTX* ctx, int* groups, int count)
13700-
{
13701-
int ret, i;
13702-
13703-
WOLFSSL_ENTER("wolfSSL_CTX_set_groups");
13704-
if (ctx == NULL || groups == NULL || count > WOLFSSL_MAX_GROUP_COUNT)
13705-
return BAD_FUNC_ARG;
13706-
if (!IsAtLeastTLSv1_3(ctx->method->version))
13707-
return BAD_FUNC_ARG;
13708-
13709-
ctx->numGroups = 0;
13710-
#if !defined(NO_TLS)
13711-
TLSX_Remove(&ctx->extensions, TLSX_SUPPORTED_GROUPS, ctx->heap);
13712-
#endif /* !NO_TLS */
13713-
for (i = 0; i < count; i++) {
13714-
/* Call to wolfSSL_CTX_UseSupportedCurve also checks if input groups
13715-
* are valid */
13716-
if ((ret = wolfSSL_CTX_UseSupportedCurve(ctx, (word16)groups[i]))
13717-
!= WOLFSSL_SUCCESS) {
13718-
#if !defined(NO_TLS)
13719-
TLSX_Remove(&ctx->extensions, TLSX_SUPPORTED_GROUPS, ctx->heap);
13720-
#endif /* !NO_TLS */
13721-
return ret;
13722-
}
13723-
ctx->group[i] = (word16)groups[i];
13724-
}
13725-
ctx->numGroups = (byte)count;
13726-
13727-
return WOLFSSL_SUCCESS;
13728-
}
13729-
13730-
/* Sets the key exchange groups in rank order.
13731-
*
13732-
* ssl SSL/TLS object.
13733-
* groups Array of groups.
13734-
* count Number of groups in array.
13735-
* returns BAD_FUNC_ARG when ssl or groups is NULL, not using TLS v1.3 or
13736-
* count is greater than WOLFSSL_MAX_GROUP_COUNT and WOLFSSL_SUCCESS on success.
13737-
*/
13738-
int wolfSSL_set_groups(WOLFSSL* ssl, int* groups, int count)
13739-
{
13740-
int ret, i;
13741-
13742-
WOLFSSL_ENTER("wolfSSL_set_groups");
13743-
if (ssl == NULL || groups == NULL || count > WOLFSSL_MAX_GROUP_COUNT)
13744-
return BAD_FUNC_ARG;
13745-
if (!IsAtLeastTLSv1_3(ssl->version))
13746-
return BAD_FUNC_ARG;
13747-
13748-
ssl->numGroups = 0;
13749-
#if !defined(NO_TLS)
13750-
TLSX_Remove(&ssl->extensions, TLSX_SUPPORTED_GROUPS, ssl->heap);
13751-
#endif /* !NO_TLS */
13752-
for (i = 0; i < count; i++) {
13753-
/* Call to wolfSSL_UseSupportedCurve also checks if input groups
13754-
* are valid */
13755-
if ((ret = wolfSSL_UseSupportedCurve(ssl, (word16)groups[i]))
13756-
!= WOLFSSL_SUCCESS) {
13757-
#if !defined(NO_TLS)
13758-
TLSX_Remove(&ssl->extensions, TLSX_SUPPORTED_GROUPS, ssl->heap);
13759-
#endif /* !NO_TLS */
13760-
return ret;
13761-
}
13762-
ssl->group[i] = (word16)groups[i];
13763-
}
13764-
ssl->numGroups = (byte)count;
13765-
13766-
return WOLFSSL_SUCCESS;
13767-
}
13768-
#endif /* HAVE_SUPPORTED_CURVES */
13769-
1377013690
#ifndef NO_PSK
1377113691
/* Set the PSK callback, that is passed the cipher suite, for a client to use
1377213692
* against context object.

0 commit comments

Comments
 (0)