Skip to content

Commit 94b9972

Browse files
Merge pull request #10007 from minosgalanakis/task9887_extend_defragmentation_tests
Extend ssl-opt testing for TLS HS defragmentation
2 parents 54a6386 + 625c8fd commit 94b9972

File tree

2 files changed

+173
-2
lines changed

2 files changed

+173
-2
lines changed

programs/ssl/ssl_client2.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ int main(void)
7575
#define DFL_RECO_SERVER_NAME NULL
7676
#define DFL_RECO_DELAY 0
7777
#define DFL_RECO_MODE 1
78+
#define DFL_RENEGO_DELAY -2
7879
#define DFL_CID_ENABLED 0
7980
#define DFL_CID_VALUE ""
8081
#define DFL_CID_ENABLED_RENEGO -1
@@ -298,7 +299,8 @@ int main(void)
298299
#if defined(MBEDTLS_SSL_RENEGOTIATION)
299300
#define USAGE_RENEGO \
300301
" renegotiation=%%d default: 0 (disabled)\n" \
301-
" renegotiate=%%d default: 0 (disabled)\n"
302+
" renegotiate=%%d default: 0 (disabled)\n" \
303+
" renego_delay=%%d default: -2 (library default)\n"
302304
#else
303305
#define USAGE_RENEGO ""
304306
#endif
@@ -938,6 +940,7 @@ int main(int argc, char *argv[])
938940
opt.renegotiation = DFL_RENEGOTIATION;
939941
opt.allow_legacy = DFL_ALLOW_LEGACY;
940942
opt.renegotiate = DFL_RENEGOTIATE;
943+
opt.renego_delay = DFL_RENEGO_DELAY;
941944
opt.exchanges = DFL_EXCHANGES;
942945
opt.min_version = DFL_MIN_VERSION;
943946
opt.max_version = DFL_MAX_VERSION;
@@ -1172,6 +1175,8 @@ int main(int argc, char *argv[])
11721175
break;
11731176
default: goto usage;
11741177
}
1178+
} else if (strcmp(p, "renego_delay") == 0) {
1179+
opt.renego_delay = (atoi(q));
11751180
} else if (strcmp(p, "renegotiate") == 0) {
11761181
opt.renegotiate = atoi(q);
11771182
if (opt.renegotiate < 0 || opt.renegotiate > 1) {
@@ -1923,6 +1928,9 @@ int main(int argc, char *argv[])
19231928
}
19241929
#if defined(MBEDTLS_SSL_RENEGOTIATION)
19251930
mbedtls_ssl_conf_renegotiation(&conf, opt.renegotiation);
1931+
if (opt.renego_delay != DFL_RENEGO_DELAY) {
1932+
mbedtls_ssl_conf_renegotiation_enforced(&conf, opt.renego_delay);
1933+
}
19261934
#endif
19271935

19281936
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
@@ -2467,6 +2475,8 @@ int main(int argc, char *argv[])
24672475
}
24682476
mbedtls_printf(" ok\n");
24692477
}
2478+
2479+
24702480
#endif /* MBEDTLS_SSL_RENEGOTIATION */
24712481

24722482
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)

tests/ssl-opt.sh

Lines changed: 162 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ if [ -n "${OPENSSL_NEXT:-}" ]; then
103103
O_NEXT_SRV_NO_CERT="$OPENSSL_NEXT s_server -www "
104104
O_NEXT_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_NEXT s_client -CAfile $DATA_FILES_PATH/test-ca_cat12.crt"
105105
O_NEXT_CLI_NO_CERT="echo 'GET / HTTP/1.0' | $OPENSSL_NEXT s_client"
106+
O_NEXT_CLI_RENEGOTIATE="echo 'R' | $OPENSSL_NEXT s_client -cert $DATA_FILES_PATH/server5.crt -key $DATA_FILES_PATH/server5.key"
106107
else
107108
O_NEXT_SRV=false
108109
O_NEXT_SRV_NO_CERT=false
109110
O_NEXT_SRV_EARLY_DATA=false
110111
O_NEXT_CLI_NO_CERT=false
111112
O_NEXT_CLI=false
113+
O_NEXT_CLI_RENEGOTIATE=false
112114
fi
113115

114116
if [ -n "${GNUTLS_NEXT_SERV:-}" ]; then
@@ -13711,14 +13713,173 @@ run_test "TLS 1.2 ClientHello indicating support for deflate compression meth
1371113713

1371213714
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1371313715
requires_certificate_authentication
13714-
run_test "Handshake defragmentation on server: len=32, TLS 1.2 ClientHello" \
13716+
run_test "Handshake defragmentation on server: len=32, TLS 1.2 ClientHello (unsupported)" \
1371513717
"$P_SRV debug_level=4 force_version=tls12 auth_mode=required" \
1371613718
"$O_NEXT_CLI -tls1_2 -split_send_frag 32 -cert $DATA_FILES_PATH/server5.crt -key $DATA_FILES_PATH/server5.key" \
1371713719
1 \
1371813720
-s "The SSL configuration is tls12 only" \
1371913721
-s "bad client hello message" \
1372013722
-s "SSL - A message could not be parsed due to a syntactic error"
1372113723

13724+
# Test server-side buffer resizing with fragmented handshake on TLS1.2
13725+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13726+
requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
13727+
requires_config_enabled MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
13728+
requires_max_content_len 1025
13729+
run_test "Handshake defragmentation on server: len=256, buffer resizing with MFL=1024" \
13730+
"$P_SRV debug_level=4 auth_mode=required" \
13731+
"$O_NEXT_CLI -tls1_2 -split_send_frag 256 -maxfraglen 1024 -cert $DATA_FILES_PATH/server5.crt -key $DATA_FILES_PATH/server5.key" \
13732+
0 \
13733+
-s "Reallocating in_buf" \
13734+
-s "Reallocating out_buf" \
13735+
-s "reassembled record" \
13736+
-s "initial handshake fragment: 256, 0\\.\\.256 of [0-9]\\+" \
13737+
-s "Prepare: waiting for more handshake fragments 256/" \
13738+
-s "Consume: waiting for more handshake fragments 256/"
13739+
13740+
# Test client-initiated renegotiation with fragmented handshake on TLS1.2
13741+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13742+
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
13743+
run_test "Handshake defragmentation on server: len=512, client-initiated renegotiation" \
13744+
"$P_SRV debug_level=4 exchanges=2 renegotiation=1 auth_mode=required" \
13745+
"$O_NEXT_CLI_RENEGOTIATE -tls1_2 -split_send_frag 512 -connect 127.0.0.1:+$SRV_PORT" \
13746+
0 \
13747+
-s "received TLS_EMPTY_RENEGOTIATION_INFO" \
13748+
-s "found renegotiation extension" \
13749+
-s "server hello, secure renegotiation extension" \
13750+
-s "=> renegotiate" \
13751+
-S "write hello request" \
13752+
-s "reassembled record" \
13753+
-s "initial handshake fragment: 512, 0\\.\\.512 of [0-9]\\+" \
13754+
-s "Prepare: waiting for more handshake fragments 512/" \
13755+
-s "Consume: waiting for more handshake fragments 512/" \
13756+
13757+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13758+
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
13759+
run_test "Handshake defragmentation on server: len=256, client-initiated renegotiation" \
13760+
"$P_SRV debug_level=4 exchanges=2 renegotiation=1 auth_mode=required" \
13761+
"$O_NEXT_CLI_RENEGOTIATE -tls1_2 -split_send_frag 256 -connect 127.0.0.1:+$SRV_PORT" \
13762+
0 \
13763+
-s "received TLS_EMPTY_RENEGOTIATION_INFO" \
13764+
-s "found renegotiation extension" \
13765+
-s "server hello, secure renegotiation extension" \
13766+
-s "=> renegotiate" \
13767+
-S "write hello request" \
13768+
-s "reassembled record" \
13769+
-s "initial handshake fragment: 256, 0\\.\\.256 of [0-9]\\+" \
13770+
-s "Prepare: waiting for more handshake fragments 256/" \
13771+
-s "Consume: waiting for more handshake fragments 256/" \
13772+
13773+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13774+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
13775+
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
13776+
run_test "Handshake defragmentation on server: len=128, client-initiated renegotiation" \
13777+
"$P_SRV debug_level=4 exchanges=2 renegotiation=1 auth_mode=required" \
13778+
"$O_NEXT_CLI_RENEGOTIATE -tls1_2 -split_send_frag 128 -connect 127.0.0.1:+$SRV_PORT" \
13779+
0 \
13780+
-s "received TLS_EMPTY_RENEGOTIATION_INFO" \
13781+
-s "found renegotiation extension" \
13782+
-s "server hello, secure renegotiation extension" \
13783+
-s "=> renegotiate" \
13784+
-S "write hello request" \
13785+
-s "reassembled record" \
13786+
-s "initial handshake fragment: 128, 0\\.\\.128 of [0-9]\\+" \
13787+
-s "Prepare: waiting for more handshake fragments 128/" \
13788+
-s "Consume: waiting for more handshake fragments 128/" \
13789+
13790+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13791+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
13792+
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
13793+
run_test "Handshake defragmentation on server: len=4, client-initiated renegotiation" \
13794+
"$P_SRV debug_level=4 exchanges=2 renegotiation=1 auth_mode=required" \
13795+
"$O_NEXT_CLI_RENEGOTIATE -tls1_2 -split_send_frag 4 -connect 127.0.0.1:+$SRV_PORT" \
13796+
0 \
13797+
-s "received TLS_EMPTY_RENEGOTIATION_INFO" \
13798+
-s "found renegotiation extension" \
13799+
-s "server hello, secure renegotiation extension" \
13800+
-s "=> renegotiate" \
13801+
-S "write hello request" \
13802+
-s "reassembled record" \
13803+
-s "initial handshake fragment: 4, 0\\.\\.4 of [0-9]\\+" \
13804+
-s "Prepare: waiting for more handshake fragments 4/" \
13805+
-s "Consume: waiting for more handshake fragments 4/" \
13806+
13807+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13808+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
13809+
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
13810+
run_test "Handshake defragmentation on server: len=4, client-initiated server-rejected renegotiation" \
13811+
"$P_SRV debug_level=4 exchanges=2 renegotiation=0 auth_mode=required" \
13812+
"$O_NEXT_CLI_RENEGOTIATE -tls1_2 -split_send_frag 4 -connect 127.0.0.1:+$SRV_PORT" \
13813+
1 \
13814+
-s "received TLS_EMPTY_RENEGOTIATION_INFO" \
13815+
-s "refusing renegotiation, sending alert" \
13816+
-s "server hello, secure renegotiation extension" \
13817+
-s "initial handshake fragment: 4, 0\\.\\.4 of [0-9]\\+" \
13818+
-s "Prepare: waiting for more handshake fragments 4/" \
13819+
-s "Consume: waiting for more handshake fragments 4/" \
13820+
13821+
# Test server-initiated renegotiation with fragmented handshake on TLS1.2
13822+
13823+
# Note: The /reneg endpoint serves as a directive for OpenSSL's s_server
13824+
# to initiate a handshake renegotiation.
13825+
# Note: Adjusting the renegotiation delay beyond the library's default
13826+
# value of 16 is necessary. This parameter defines the maximum
13827+
# number of records received before renegotiation is completed.
13828+
# By fragmenting records and thereby increasing their quantity,
13829+
# the default threshold can be reached more quickly.
13830+
# Setting it to -1 disables that policy's enforment.
13831+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13832+
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
13833+
run_test "Handshake defragmentation on client: len=512, server-initiated renegotiation" \
13834+
"$O_NEXT_SRV -tls1_2 -split_send_frag 512 -cert $DATA_FILES_PATH/server5.crt -key $DATA_FILES_PATH/server5.key" \
13835+
"$P_CLI debug_level=3 renegotiation=1 request_page=/reneg" \
13836+
0 \
13837+
-c "initial handshake fragment: 512, 0\\.\\.512 of [0-9]\\+" \
13838+
-c "Prepare: waiting for more handshake fragments 512/" \
13839+
-c "Consume: waiting for more handshake fragments 512/" \
13840+
-c "client hello, adding renegotiation extension" \
13841+
-c "found renegotiation extension" \
13842+
-c "=> renegotiate"
13843+
13844+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13845+
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
13846+
run_test "Handshake defragmentation on client: len=256, server-initiated renegotiation" \
13847+
"$O_NEXT_SRV -tls1_2 -split_send_frag 256 -cert $DATA_FILES_PATH/server5.crt -key $DATA_FILES_PATH/server5.key" \
13848+
"$P_CLI debug_level=3 renegotiation=1 renego_delay=-1 request_page=/reneg" \
13849+
0 \
13850+
-c "initial handshake fragment: 256, 0\\.\\.256 of [0-9]\\+" \
13851+
-c "Prepare: waiting for more handshake fragments 256/" \
13852+
-c "Consume: waiting for more handshake fragments 256/" \
13853+
-c "client hello, adding renegotiation extension" \
13854+
-c "found renegotiation extension" \
13855+
-c "=> renegotiate"
13856+
13857+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13858+
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
13859+
run_test "Handshake defragmentation on client: len=128, server-initiated renegotiation" \
13860+
"$O_NEXT_SRV -tls1_2 -split_send_frag 128 -cert $DATA_FILES_PATH/server5.crt -key $DATA_FILES_PATH/server5.key" \
13861+
"$P_CLI debug_level=3 renegotiation=1 renego_delay=-1 request_page=/reneg" \
13862+
0 \
13863+
-c "initial handshake fragment: 128, 0\\.\\.128 of [0-9]\\+" \
13864+
-c "Prepare: waiting for more handshake fragments 128/" \
13865+
-c "Consume: waiting for more handshake fragments 128/" \
13866+
-c "client hello, adding renegotiation extension" \
13867+
-c "found renegotiation extension" \
13868+
-c "=> renegotiate"
13869+
13870+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13871+
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
13872+
run_test "Handshake defragmentation on client: len=4, server-initiated renegotiation" \
13873+
"$O_NEXT_SRV -tls1_2 -split_send_frag 4 -cert $DATA_FILES_PATH/server5.crt -key $DATA_FILES_PATH/server5.key" \
13874+
"$P_CLI debug_level=3 renegotiation=1 renego_delay=-1 request_page=/reneg" \
13875+
0 \
13876+
-c "initial handshake fragment: 4, 0\\.\\.4 of [0-9]\\+" \
13877+
-c "Prepare: waiting for more handshake fragments 4/" \
13878+
-c "Consume: waiting for more handshake fragments 4/" \
13879+
-c "client hello, adding renegotiation extension" \
13880+
-c "found renegotiation extension" \
13881+
-c "=> renegotiate"
13882+
1372213883
# Test heap memory usage after handshake
1372313884
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1372413885
requires_config_enabled MBEDTLS_MEMORY_DEBUG

0 commit comments

Comments
 (0)