Skip to content

Commit 48116ab

Browse files
committed
More review comments
1 parent d900037 commit 48116ab

4 files changed

Lines changed: 131 additions & 116 deletions

File tree

src/internal.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18566,8 +18566,12 @@ int DoHandShakeMsgType(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1856618566
((defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)) || \
1856718567
(defined(HAVE_ED25519) && !defined(NO_ED25519_CLIENT_AUTH)) || \
1856818568
(defined(HAVE_ED448) && !defined(NO_ED448_CLIENT_AUTH)))
18569-
if (ssl->options.resuming || !ssl->options.verifyPeer || \
18570-
!IsAtLeastTLSv1_2(ssl) || IsAtLeastTLSv1_3(ssl->version)) {
18569+
if ((ssl->options.resuming || !ssl->options.verifyPeer ||
18570+
!IsAtLeastTLSv1_2(ssl) || IsAtLeastTLSv1_3(ssl->version))
18571+
#ifdef WOLFSSL_DTLS
18572+
&& !ssl->options.dtls
18573+
#endif
18574+
) {
1857118575
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_NONBLOCK_OCSP)
1857218576
if (ret != WC_NO_ERR_TRACE(WC_PENDING_E) &&
1857318577
ret != WC_NO_ERR_TRACE(OCSP_WANT_READ))

src/tls.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7268,7 +7268,7 @@ static int TLSX_Cookie_RestoreHrrGroup(WOLFSSL* ssl)
72687268
#elif defined(WOLFSSL_SM3)
72697269
byte macSz = WC_SM3_DIGEST_SIZE;
72707270
#else
7271-
#error "No digest to available to use with HMAC for cookies."
7271+
#error "No digest available to use with HMAC for cookies."
72727272
#endif /* NO_SHA */
72737273

72747274
extension = TLSX_Find(ssl->extensions, TLSX_COOKIE);
@@ -10275,18 +10275,6 @@ int TLSX_KeyShare_Parse_ClientHello(const WOLFSSL* ssl,
1027510275
}
1027610276

1027710277
if (ssl->hrr_keyshare_group != 0) {
10278-
#ifdef WOLFSSL_DTLS
10279-
/* In case of stateless DTLSv1.3, the ssl->hrr_keyshare_group variable
10280-
* may have already been set without further proceeding the handshake,
10281-
* so we never received the second ClientHello with the selected group.
10282-
* Hence, when we receive another ClientHello message, we do not
10283-
* consider that as an error here.
10284-
*/
10285-
if (ssl->options.dtls && IsAtLeastTLSv1_3(ssl->version) &&
10286-
!ssl->options.dtlsStateful) {
10287-
return 0;
10288-
}
10289-
#endif
1029010278
/*
1029110279
* https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.8
1029210280
* when sending the new ClientHello, the client MUST

src/tls13.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7509,7 +7509,18 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType)
75097509
if (ret != 0)
75107510
return ret;
75117511

7512-
if (extMsgType == hello_retry_request) {
7512+
/* When we send a HRR, we store the selected key share group to later check
7513+
* that the client uses the same group in the second ClientHello.
7514+
*
7515+
* In case of stateless DTLS, we do not store the group, however, as it is
7516+
* already stored in the cookie that is sent to the client. We later recover
7517+
* the group from the cookie to prevent storing a state in a stateless
7518+
* server. */
7519+
if (extMsgType == hello_retry_request
7520+
#if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
7521+
&& (!ssl->options.dtls || ssl->options.dtlsStateful)
7522+
#endif
7523+
) {
75137524
TLSX* ksExt = TLSX_Find(ssl->extensions, TLSX_KEY_SHARE);
75147525
if (ksExt != NULL) {
75157526
KeyShareEntry* kse = (KeyShareEntry*)ksExt->data;

tests/api.c

Lines changed: 112 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -24317,11 +24317,122 @@ static int test_wolfSSL_dtls_stateless(void)
2431724317

2431824318
return TEST_SUCCESS;
2431924319
}
24320+
24321+
/* DTLS stateless API handling multiple CHs with different HRR groups */
24322+
static int test_wolfSSL_dtls_stateless_hrr_group(void)
24323+
{
24324+
EXPECT_DECLS;
24325+
#if defined(WOLFSSL_SEND_HRR_COOKIE)
24326+
size_t i;
24327+
word32 initHash;
24328+
struct {
24329+
method_provider client_meth;
24330+
method_provider server_meth;
24331+
} params[] = {
24332+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13)
24333+
{ wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method },
24334+
#endif
24335+
#if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_DTLS)
24336+
{ wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method },
24337+
#endif
24338+
};
24339+
for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) {
24340+
WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL;
24341+
WOLFSSL *ssl_s = NULL, *ssl_c = NULL, *ssl_c2 = NULL;
24342+
struct test_memio_ctx test_ctx;
24343+
int groups_1[] = {
24344+
WOLFSSL_ECC_SECP256R1,
24345+
WOLFSSL_ECC_SECP384R1,
24346+
WOLFSSL_ECC_SECP521R1
24347+
};
24348+
int groups_2[] = {
24349+
WOLFSSL_ECC_SECP384R1,
24350+
WOLFSSL_ECC_SECP521R1
24351+
};
24352+
char hrrBuf[1000];
24353+
int hrrSz = sizeof(hrrBuf);
24354+
24355+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
24356+
24357+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
24358+
params[i].client_meth, params[i].server_meth), 0);
24359+
24360+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c2, NULL,
24361+
params[i].client_meth, params[i].server_meth), 0);
24362+
24363+
24364+
wolfSSL_SetLoggingPrefix("server");
24365+
wolfSSL_dtls_set_using_nonblock(ssl_s, 1);
24366+
24367+
initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl_s);
24368+
24369+
/* Set groups and disable key shares. This ensures that only the given
24370+
* groups are in the SupportedGroups extension and that an empty key
24371+
* share extension is sent in the initial ClientHello of each session.
24372+
* This triggers the server to send a HelloRetryRequest with the first
24373+
* group in the SupportedGroups extension selected. */
24374+
wolfSSL_SetLoggingPrefix("client1");
24375+
ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups_1, 3), WOLFSSL_SUCCESS);
24376+
ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c), WOLFSSL_SUCCESS);
24377+
24378+
wolfSSL_SetLoggingPrefix("client2");
24379+
ExpectIntEQ(wolfSSL_set_groups(ssl_c2, groups_2, 2), WOLFSSL_SUCCESS);
24380+
ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c2), WOLFSSL_SUCCESS);
24381+
24382+
/* Start handshake, send first ClientHello */
24383+
wolfSSL_SetLoggingPrefix("client1");
24384+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
24385+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
24386+
24387+
/* Read first ClientHello, send HRR with WOLFSSL_ECC_SECP256R1 */
24388+
wolfSSL_SetLoggingPrefix("server");
24389+
ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), 0);
24390+
ExpectIntEQ(test_memio_copy_message(&test_ctx, 1, hrrBuf, &hrrSz, 0), 0);
24391+
ExpectIntGT(hrrSz, 0);
24392+
ExpectIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl_s));
24393+
test_memio_clear_buffer(&test_ctx, 1);
24394+
24395+
/* Send second ClientHello */
24396+
wolfSSL_SetLoggingPrefix("client2");
24397+
ExpectIntEQ(wolfSSL_connect(ssl_c2), -1);
24398+
ExpectIntEQ(wolfSSL_get_error(ssl_c2, -1), WOLFSSL_ERROR_WANT_READ);
24399+
24400+
/* Read second ClientHello, send HRR now with WOLFSSL_ECC_SECP384R1 */
24401+
wolfSSL_SetLoggingPrefix("server");
24402+
ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), 0);
24403+
ExpectIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl_s));
24404+
test_memio_clear_buffer(&test_ctx, 1);
24405+
24406+
/* Complete first handshake with WOLFSSL_ECC_SECP256R1 */
24407+
wolfSSL_SetLoggingPrefix("client1");
24408+
ExpectIntEQ(test_memio_inject_message(&test_ctx, 1, hrrBuf, hrrSz), 0);
24409+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
24410+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
24411+
24412+
wolfSSL_SetLoggingPrefix("server");
24413+
ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_SUCCESS);
24414+
24415+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
24416+
24417+
wolfSSL_free(ssl_s);
24418+
wolfSSL_free(ssl_c);
24419+
wolfSSL_free(ssl_c2);
24420+
wolfSSL_CTX_free(ctx_s);
24421+
wolfSSL_CTX_free(ctx_c);
24422+
}
24423+
#endif /* WOLFSSL_SEND_HRR_COOKIE */
24424+
return EXPECT_RESULT();
24425+
}
2432024426
#else
2432124427
static int test_wolfSSL_dtls_stateless(void)
2432224428
{
2432324429
return TEST_SKIPPED;
2432424430
}
24431+
24432+
static int test_wolfSSL_dtls_stateless_hrr_group(void)
24433+
{
24434+
return TEST_SKIPPED;
24435+
}
2432524436
#endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE &&
2432624437
* HAVE_IO_TESTS_DEPENDENCIES && !SINGLE_THREADED */
2432724438

@@ -27783,105 +27894,6 @@ static int test_wolfSSL_dtls_stateless_downgrade(void)
2778327894
}
2778427895
#endif /* !defined(NO_OLD_TLS) */
2778527896

27786-
/* DTLS stateless API handling multiple CHs with different HRR groups */
27787-
static int test_wolfSSL_dtls_stateless_hrr_group(void)
27788-
{
27789-
EXPECT_DECLS;
27790-
size_t i;
27791-
struct {
27792-
method_provider client_meth;
27793-
method_provider server_meth;
27794-
} params[] = {
27795-
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13)
27796-
{ wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method },
27797-
#endif
27798-
#if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_DTLS)
27799-
{ wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method },
27800-
#endif
27801-
};
27802-
for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) {
27803-
WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL;
27804-
WOLFSSL *ssl_s = NULL, *ssl_c = NULL, *ssl_c2 = NULL;
27805-
struct test_memio_ctx test_ctx;
27806-
int groups_1[] = {
27807-
WOLFSSL_ECC_SECP256R1,
27808-
WOLFSSL_ECC_SECP384R1,
27809-
WOLFSSL_ECC_SECP521R1
27810-
};
27811-
int groups_2[] = {
27812-
WOLFSSL_ECC_SECP384R1,
27813-
WOLFSSL_ECC_SECP521R1
27814-
};
27815-
char hrrBuf[1000];
27816-
int hrrSz = sizeof(hrrBuf);
27817-
27818-
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
27819-
27820-
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
27821-
params[i].client_meth, params[i].server_meth), 0);
27822-
27823-
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c2, NULL,
27824-
params[i].client_meth, params[i].server_meth), 0);
27825-
27826-
27827-
wolfSSL_SetLoggingPrefix("server");
27828-
wolfSSL_dtls_set_using_nonblock(ssl_s, 1);
27829-
27830-
/* Set groups and disable key shares. This ensures that only the given
27831-
* groups are in the SupportedGroups extension and that an empty key
27832-
* share extension is sent in the initial ClientHello of each session.
27833-
* This triggers the server to send a HelloRetryRequest with the first
27834-
* group in the SupportedGroups extension selected. */
27835-
wolfSSL_SetLoggingPrefix("client1");
27836-
ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups_1, 3), WOLFSSL_SUCCESS);
27837-
ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c), WOLFSSL_SUCCESS);
27838-
27839-
wolfSSL_SetLoggingPrefix("client2");
27840-
ExpectIntEQ(wolfSSL_set_groups(ssl_c2, groups_2, 2), WOLFSSL_SUCCESS);
27841-
ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c2), WOLFSSL_SUCCESS);
27842-
27843-
/* Start handshake, send first ClientHello */
27844-
wolfSSL_SetLoggingPrefix("client1");
27845-
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
27846-
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
27847-
27848-
/* Read first ClientHello, send HRR with WOLFSSL_ECC_SECP256R1 */
27849-
wolfSSL_SetLoggingPrefix("server");
27850-
ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), 0);
27851-
ExpectIntEQ(test_memio_copy_message(&test_ctx, 1, hrrBuf, &hrrSz, 0), 0);
27852-
ExpectIntGT(hrrSz, 0);
27853-
test_memio_clear_buffer(&test_ctx, 1);
27854-
27855-
/* Send second ClientHello */
27856-
wolfSSL_SetLoggingPrefix("client2");
27857-
ExpectIntEQ(wolfSSL_connect(ssl_c2), -1);
27858-
ExpectIntEQ(wolfSSL_get_error(ssl_c2, -1), WOLFSSL_ERROR_WANT_READ);
27859-
27860-
/* Read second ClientHello, send HRR now with WOLFSSL_ECC_SECP384R1 */
27861-
wolfSSL_SetLoggingPrefix("server");
27862-
ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), 0);
27863-
test_memio_clear_buffer(&test_ctx, 1);
27864-
27865-
/* Complete first handshake with WOLFSSL_ECC_SECP256R1 */
27866-
wolfSSL_SetLoggingPrefix("client1");
27867-
ExpectIntEQ(test_memio_inject_message(&test_ctx, 1, hrrBuf, hrrSz), 0);
27868-
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
27869-
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
27870-
27871-
wolfSSL_SetLoggingPrefix("server");
27872-
ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_SUCCESS);
27873-
27874-
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
27875-
27876-
wolfSSL_free(ssl_s);
27877-
wolfSSL_free(ssl_c);
27878-
wolfSSL_free(ssl_c2);
27879-
wolfSSL_CTX_free(ctx_s);
27880-
wolfSSL_CTX_free(ctx_c);
27881-
}
27882-
return EXPECT_RESULT();
27883-
}
27884-
2788527897
#endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
2788627898
!defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)*/
2788727899

@@ -33285,6 +33297,7 @@ TEST_CASE testCases[] = {
3328533297
TEST_DECL(test_wolfSSL_dtls_bad_record),
3328633298
/* Uses Assert in handshake callback. */
3328733299
TEST_DECL(test_wolfSSL_dtls_stateless),
33300+
TEST_DECL(test_wolfSSL_dtls_stateless_hrr_group),
3328833301
TEST_DECL(test_generate_cookie),
3328933302

3329033303
#ifndef NO_BIO
@@ -33322,7 +33335,6 @@ TEST_CASE testCases[] = {
3332233335
#if !defined(NO_OLD_TLS)
3332333336
TEST_DECL(test_wolfSSL_dtls_stateless_downgrade),
3332433337
#endif /* !defined(NO_OLD_TLS) */
33325-
TEST_DECL(test_wolfSSL_dtls_stateless_hrr_group),
3332633338
#endif /* ! NO_RSA */
3332733339
#endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
3332833340
* !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) */

0 commit comments

Comments
 (0)