Skip to content

Commit ba8ffc7

Browse files
authored
Merge pull request #5513 from rizlik/hrr_default
DTLSv1.3: Do HRR Cookie exchange by default
2 parents 0222833 + 08b89fb commit ba8ffc7

8 files changed

Lines changed: 135 additions & 47 deletions

File tree

CMakeLists.txt

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,36 @@ if("${FIPS_VERSION}" STREQUAL "v1")
275275
override_cache(WOLFSSL_TLS13 "no")
276276
endif()
277277

278+
# Post-handshake authentication
279+
add_option("WOLFSSL_POSTAUTH"
280+
"Enable wolfSSL Post-handshake Authentication (default: disabled)"
281+
"no" "yes;no")
282+
283+
if(WOLFSSL_POSTAUTH)
284+
if(NOT WOLFSSL_TLS13)
285+
message(WARNING "TLS 1.3 is disabled - disabling Post-handshake Authentication")
286+
override_cache(WOLFSSL_POSTAUTH "no")
287+
else()
288+
list(APPEND WOLFSSL_DEFINITIONS
289+
"-DWOLFSSL_POST_HANDSHAKE_AUTH")
290+
endif()
291+
endif()
292+
293+
# Hello Retry Request Cookie
294+
add_option("WOLFSSL_HRR_COOKIE"
295+
"Enable the server to send Cookie Extension in HRR with state (default: disabled)"
296+
"undefined" "yes;no;undefined")
297+
298+
if("${WOLFSSL_HRR_COOKIE}" STREQUAL "yes")
299+
if(NOT WOLFSSL_TLS13)
300+
message(WARNING "TLS 1.3 is disabled - disabling HRR Cookie")
301+
override_cache(WOLFSSL_HRR_COOKIE "no")
302+
else()
303+
list(APPEND WOLFSSL_DEFINITIONS
304+
"-DWOLFSSL_SEND_HRR_COOKIE")
305+
endif()
306+
endif()
307+
278308
# DTLS v1.3
279309
add_option("WOLFSSL_DTLS13"
280310
"Enable wolfSSL DTLS v1.3 (default: disabled)"
@@ -289,7 +319,11 @@ if(WOLFSSL_DTLS13)
289319
endif()
290320
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DTLS13")
291321
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_W64_WRAPPER")
292-
322+
if ("${WOLFSSL_HRR_COOKIE}" STREQUAL "undefined")
323+
message(WARNING "DTLS1.3 is enabled - enabling HRR Cookie")
324+
override_cache(WOLFSSL_HRR_COOKIE "yes")
325+
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SEND_HRR_COOKIE")
326+
endif()
293327
if (WOLFSSL_AES)
294328
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_DIRECT")
295329
endif()
@@ -307,36 +341,6 @@ if(WOLFSSL_DTLS_CID)
307341
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DTLS_CID")
308342
endif()
309343

310-
# Post-handshake authentication
311-
add_option("WOLFSSL_POSTAUTH"
312-
"Enable wolfSSL Post-handshake Authentication (default: disabled)"
313-
"no" "yes;no")
314-
315-
if(WOLFSSL_POSTAUTH)
316-
if(NOT WOLFSSL_TLS13)
317-
message(WARNING "TLS 1.3 is disabled - disabling Post-handshake Authentication")
318-
override_cache(WOLFSSL_POSTAUTH "no")
319-
else()
320-
list(APPEND WOLFSSL_DEFINITIONS
321-
"-DWOLFSSL_POST_HANDSHAKE_AUTH")
322-
endif()
323-
endif()
324-
325-
# Hello Retry Request Cookie
326-
add_option("WOLFSSL_HRR_COOKIE"
327-
"Enable the server to send Cookie Extension in HRR with state (default: disabled)"
328-
"no" "yes;no")
329-
330-
if(WOLFSSL_HRR_COOKIE)
331-
if(NOT WOLFSSL_TLS13)
332-
message(WARNING "TLS 1.3 is disabled - disabling HRR Cookie")
333-
override_cache(WOLFSSL_HRR_COOKIE "no")
334-
else()
335-
list(APPEND WOLFSSL_DEFINITIONS
336-
"-DWOLFSSL_SEND_HRR_COOKIE")
337-
endif()
338-
endif()
339-
340344
# RNG
341345
add_option("WOLFSSL_RNG"
342346
"Enable compiling and using RNG (default: enabled)"

configure.ac

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ fi
10781078
AC_ARG_ENABLE([hrrcookie],
10791079
[AS_HELP_STRING([--enable-hrrcookie],[Enable the server to send Cookie Extension in HRR with state (default: disabled)])],
10801080
[ ENABLED_SEND_HRR_COOKIE=$enableval ],
1081-
[ ENABLED_SEND_HRR_COOKIE=no ]
1081+
[ ENABLED_SEND_HRR_COOKIE=undefined ]
10821082
)
10831083
if test "$ENABLED_SEND_HRR_COOKIE" = "yes"
10841084
then
@@ -3753,6 +3753,12 @@ then
37533753
then
37543754
AC_MSG_ERROR([You need to enable both DTLS and TLSv1.3 to use DTLSv1.3])
37553755
fi
3756+
if test "x$ENABLED_SEND_HRR_COOKIE" == "xundefined"
3757+
then
3758+
AC_MSG_NOTICE([DTLSv1.3 is enabled, enabling HRR cookie])
3759+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SEND_HRR_COOKIE"
3760+
ENABLED_SEND_HRR_COOKIE="yes"
3761+
fi
37563762
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_DTLS13 -DWOLFSSL_W64_WRAPPER"
37573763
if test "x$ENABLED_AES" = "xyes"
37583764
then

doc/dox_comments/header_files/ssl.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13052,10 +13052,13 @@ int wolfSSL_connect(WOLFSSL* ssl);
1305213052
\ingroup Setup
1305313053
1305413054
\brief This function is called on the server side to indicate that a
13055-
HelloRetryRequest message must contain a Cookie.
13056-
The Cookie holds a hash of the current transcript so that another server
13057-
process can handle the ClientHello in reply.
13058-
The secret is used when generting the integrity check on the Cookie data.
13055+
HelloRetryRequest message must contain a Cookie and, in case of using
13056+
protocol DTLS v1.3, that the handshake will always include a cookie
13057+
exchange. Please note that when using protocol DTLS v1.3, the cookie
13058+
exchange is enabled by default. The Cookie holds a hash of the current
13059+
transcript so that another server process can handle the ClientHello in
13060+
reply. The secret is used when generting the integrity check on the Cookie
13061+
data.
1305913062
1306013063
\param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
1306113064
\param [in] secret a pointer to a buffer holding the secret.
@@ -13082,10 +13085,31 @@ int wolfSSL_connect(WOLFSSL* ssl);
1308213085
\endcode
1308313086
1308413087
\sa wolfSSL_new
13088+
\sa wolfSSL_disable_hrr_cookie
1308513089
*/
1308613090
int wolfSSL_send_hrr_cookie(WOLFSSL* ssl,
1308713091
const unsigned char* secret, unsigned int secretSz);
1308813092

13093+
/*!
13094+
13095+
\ingroup Setup
13096+
13097+
\brief This function is called on the server side to indicate that a
13098+
HelloRetryRequest message must NOT contain a Cookie and that, if using
13099+
protocol DTLS v1.3, a cookie exchange will not be included in the
13100+
handshake. Please note that not doing a cookie exchange when using protocol
13101+
DTLS v1.3 can make the server susceptible to DoS/Amplification attacks.
13102+
13103+
\param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
13104+
13105+
\return WOLFSSL_SUCCESS if successful
13106+
\return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3
13107+
\return SIDE_ERROR if invoked on client
13108+
13109+
\sa wolfSSL_send_hrr_cookie
13110+
*/
13111+
int wolfSSL_disable_hrr_cookie(WOLFSSL* ssl);
13112+
1308913113
/*!
1309013114
\ingroup Setup
1309113115

examples/server/server.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,8 @@ static const char* server_usage_msg[][65] = {
936936
"-Q Request certificate from client post-handshake\n", /* 49 */
937937
#endif
938938
#ifdef WOLFSSL_SEND_HRR_COOKIE
939-
"-J Server sends Cookie Extension containing state\n", /* 50 */
939+
"-J [n] Server sends Cookie Extension containing state (n to "
940+
"disable)\n", /* 50 */
940941
#endif
941942
#endif /* WOLFSSL_TLS13 */
942943
#ifdef WOLFSSL_EARLY_DATA
@@ -1702,7 +1703,7 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
17021703
/* Not Used: h, z, W, X */
17031704
while ((ch = mygetopt_long(argc, argv, "?:"
17041705
"abc:defgijk:l:mop:q:rstu;v:wxy"
1705-
"A:B:C:D:E:FGH:IJKL:MNO:PQR:S:T;UVYZ:"
1706+
"A:B:C:D:E:FGH:IJ;KL:MNO:PQR:S:T;UVYZ:"
17061707
"01:23:4:567:89"
17071708
"@#", long_options, 0)) != -1) {
17081709
switch (ch) {
@@ -2085,6 +2086,8 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
20852086
case 'J' :
20862087
#ifdef WOLFSSL_SEND_HRR_COOKIE
20872088
hrrCookie = 1;
2089+
if (XSTRCMP(myoptarg, "n") == 0)
2090+
hrrCookie = -1;
20882091
#endif
20892092
break;
20902093

@@ -2959,10 +2962,13 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
29592962
#endif /* !NO_CERTS */
29602963

29612964
#ifdef WOLFSSL_SEND_HRR_COOKIE
2962-
if (hrrCookie && wolfSSL_send_hrr_cookie(ssl, NULL, 0)
2965+
if (hrrCookie == 1 && wolfSSL_send_hrr_cookie(ssl, NULL, 0)
29632966
!= WOLFSSL_SUCCESS) {
29642967
err_sys("unable to set use of cookie with HRR msg");
29652968
}
2969+
else if (hrrCookie == -1) {
2970+
wolfSSL_disable_hrr_cookie(ssl);
2971+
}
29662972
#endif
29672973

29682974
#if defined(WOLFSSL_STATIC_MEMORY) && defined(DEBUG_WOLFSSL)

src/internal.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6934,11 +6934,22 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
69346934

69356935
#if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_SERVER)
69366936
if (ssl->options.dtls && ssl->options.side == WOLFSSL_SERVER_END) {
6937-
ret = wolfSSL_DTLS_SetCookieSecret(ssl, NULL, 0);
6938-
if (ret != 0) {
6939-
WOLFSSL_MSG("DTLS Cookie Secret error");
6940-
return ret;
6937+
if (!IsAtLeastTLSv1_3(ssl->version)) {
6938+
ret = wolfSSL_DTLS_SetCookieSecret(ssl, NULL, 0);
6939+
if (ret != 0) {
6940+
WOLFSSL_MSG("DTLS Cookie Secret error");
6941+
return ret;
6942+
}
6943+
}
6944+
#if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
6945+
else {
6946+
ret = wolfSSL_send_hrr_cookie(ssl, NULL, 0);
6947+
if (ret != WOLFSSL_SUCCESS) {
6948+
WOLFSSL_MSG("DTLS1.3 Cookie secret error");
6949+
return ret;
6950+
}
69416951
}
6952+
#endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE */
69426953
}
69436954
#endif /* WOLFSSL_DTLS && !NO_WOLFSSL_SERVER */
69446955

src/tls13.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10628,7 +10628,33 @@ int wolfSSL_send_hrr_cookie(WOLFSSL* ssl, const unsigned char* secret,
1062810628

1062910629
return ret;
1063010630
}
10631-
#endif
10631+
10632+
int wolfSSL_disable_hrr_cookie(WOLFSSL* ssl)
10633+
{
10634+
if (ssl == NULL || !IsAtLeastTLSv1_3(ssl->version))
10635+
return BAD_FUNC_ARG;
10636+
10637+
#ifdef NO_WOLFSSL_SERVER
10638+
return SIDE_ERROR
10639+
#else
10640+
if (ssl->options.side == WOLFSSL_CLIENT_END)
10641+
return SIDE_ERROR;
10642+
10643+
if (ssl->buffers.tls13CookieSecret.buffer != NULL) {
10644+
ForceZero(ssl->buffers.tls13CookieSecret.buffer,
10645+
ssl->buffers.tls13CookieSecret.length);
10646+
XFREE(ssl->buffers.tls13CookieSecret.buffer, ssl->heap,
10647+
DYNAMIC_TYPE_COOKIE_PWD);
10648+
ssl->buffers.tls13CookieSecret.buffer = NULL;
10649+
ssl->buffers.tls13CookieSecret.length = 0;
10650+
}
10651+
10652+
ssl->options.sendCookie = 0;
10653+
return WOLFSSL_SUCCESS;
10654+
#endif /* NO_WOLFSSL_SERVER */
10655+
}
10656+
10657+
#endif /* defined(WOLFSSL_SEND_HRR_COOKIE) */
1063210658

1063310659
#ifdef HAVE_SUPPORTED_CURVES
1063410660
/* Create a key share entry from group.

tests/test-dtls13.conf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,16 @@
129129
-l TLS13-AES128-GCM-SHA256
130130
-J
131131

132-
# server DTLSv1.3
132+
# server DTLSv1.3 HelloRetryRequest with cookie
133133
-v 4
134134
-u
135135
-l TLS13-AES128-GCM-SHA256
136136
-J
137137

138-
# client DTLSv1.3 HelloRetryRequest with cookie
138+
# client DTLSv1.3
139139
-v 4
140140
-u
141141
-l TLS13-AES128-GCM-SHA256
142-
-J
143142

144143
# server DTLSv1.3
145144
-v 4
@@ -260,3 +259,14 @@
260259
-u
261260
-l TLS13-AES128-GCM-SHA256
262261
-f
262+
263+
# server DTLSv1.3 no HelloRetryRequest cookie
264+
-u
265+
-v 4
266+
-l TLS_AES_128_GCM_SHA256
267+
-J n
268+
269+
# client DTLSv1.3 defaults
270+
-u
271+
-v 4
272+
-l TLS_AES_128_GCM_SHA256

wolfssl/ssl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ WOLFSSL_API int wolfSSL_mutual_auth(WOLFSSL* ssl, int req);
11441144
#ifdef WOLFSSL_TLS13
11451145
WOLFSSL_API int wolfSSL_send_hrr_cookie(WOLFSSL* ssl,
11461146
const unsigned char* secret, unsigned int secretSz);
1147+
WOLFSSL_API int wolfSSL_disable_hrr_cookie(WOLFSSL * ssl);
11471148
WOLFSSL_API int wolfSSL_CTX_no_ticket_TLSv13(WOLFSSL_CTX* ctx);
11481149
WOLFSSL_API int wolfSSL_no_ticket_TLSv13(WOLFSSL* ssl);
11491150
WOLFSSL_API int wolfSSL_CTX_no_dhe_psk(WOLFSSL_CTX* ctx);

0 commit comments

Comments
 (0)