blob: 7ddb8e50e204c419af7a04b429c3dc2b2b0c28a2 [file] [log] [blame]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +01001#!/bin/sh
2
3# Test various options that are not covered by compat.sh
4#
5# Here the goal is not to cover every ciphersuite/version, but
6# rather specific options (max fragment length, truncated hmac, etc)
7# or procedures (session resumption from cache or ticket, renego, etc).
8#
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02009# Assumes a build with default options.
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010010
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010011set -u
12
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +010013# default values, can be overriden by the environment
14: ${P_SRV:=../programs/ssl/ssl_server2}
15: ${P_CLI:=../programs/ssl/ssl_client2}
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +020016: ${P_PXY:=../programs/test/udp_proxy}
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010017: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020018: ${GNUTLS_CLI:=gnutls-cli}
19: ${GNUTLS_SERV:=gnutls-serv}
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010020
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +020021O_SRV="$OPENSSL_CMD s_server -cert data_files/server5.crt -key data_files/server5.key"
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010022O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_CMD s_client"
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020023G_SRV="$GNUTLS_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
24G_CLI="$GNUTLS_CLI"
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010025
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010026TESTS=0
27FAILS=0
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020028SKIPS=0
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010029
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +020030CONFIG_H='../include/polarssl/config.h'
31
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010032MEMCHECK=0
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010033FILTER='.*'
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020034EXCLUDE='^$'
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010035
36print_usage() {
37 echo "Usage: $0 [options]"
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010038 echo -e " -h|--help\tPrint this help."
39 echo -e " -m|--memcheck\tCheck memory leaks and errors."
40 echo -e " -f|--filter\tOnly matching tests are executed (default: '$FILTER')"
41 echo -e " -e|--exclude\tMatching tests are excluded (default: '$EXCLUDE')"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010042}
43
44get_options() {
45 while [ $# -gt 0 ]; do
46 case "$1" in
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010047 -f|--filter)
48 shift; FILTER=$1
49 ;;
50 -e|--exclude)
51 shift; EXCLUDE=$1
52 ;;
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010053 -m|--memcheck)
54 MEMCHECK=1
55 ;;
56 -h|--help)
57 print_usage
58 exit 0
59 ;;
60 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +020061 echo "Unknown argument: '$1'"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010062 print_usage
63 exit 1
64 ;;
65 esac
66 shift
67 done
68}
69
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020070# skip next test if OpenSSL can't send SSLv2 ClientHello
71requires_openssl_with_sslv2() {
72 if [ -z "${OPENSSL_HAS_SSL2:-}" ]; then
Manuel Pégourié-Gonnarda4afadf2014-08-30 22:09:36 +020073 if $OPENSSL_CMD ciphers -ssl2 >/dev/null 2>&1; then
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020074 OPENSSL_HAS_SSL2="YES"
75 else
76 OPENSSL_HAS_SSL2="NO"
77 fi
78 fi
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +020079
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020080 if [ "$OPENSSL_HAS_SSL2" = "NO" ]; then
81 SKIP_NEXT="YES"
82 fi
83}
84
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020085# skip next test if GnuTLS isn't available
86requires_gnutls() {
87 if [ -z "${GNUTLS_AVAILABLE:-}" ]; then
88 if ( which "$GNUTLS_CLI" && which "$GNUTLS_SERV" ) >/dev/null; then
89 GNUTLS_AVAILABLE="YES"
90 else
91 GNUTLS_AVAILABLE="NO"
92 fi
93 fi
94 if [ "$GNUTLS_AVAILABLE" = "NO" ]; then
95 SKIP_NEXT="YES"
96 fi
97}
98
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +020099# skip next test if IPv6 isn't available on this host
100requires_ipv6() {
101 if [ -z "${HAS_IPV6:-}" ]; then
102 $P_SRV server_addr='::1' > $SRV_OUT 2>&1 &
103 SRV_PID=$!
104 sleep 1
105 kill $SRV_PID >/dev/null 2>&1
106 if grep "NET - Binding of the socket failed" $SRV_OUT >/dev/null; then
107 HAS_IPV6="NO"
108 else
109 HAS_IPV6="YES"
110 fi
111 rm -r $SRV_OUT
112 fi
113
114 if [ "$HAS_IPV6" = "NO" ]; then
115 SKIP_NEXT="YES"
116 fi
117}
118
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200119# multiply the client timeout delay by the given factor for the next test
120needs_more_time() {
121 CLI_DELAY_FACTOR=$1
122}
123
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100124# print_name <name>
125print_name() {
126 echo -n "$1 "
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200127 LEN=$(( 72 - `echo "$1" | wc -c` ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100128 for i in `seq 1 $LEN`; do echo -n '.'; done
129 echo -n ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100130
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200131 TESTS=$(( $TESTS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100132}
133
134# fail <message>
135fail() {
136 echo "FAIL"
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +0100137 echo " ! $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100138
Manuel Pégourié-Gonnardc2b00922014-08-31 16:46:04 +0200139 mv $SRV_OUT o-srv-${TESTS}.log
140 mv $CLI_OUT o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200141 if [ -n "$PXY_CMD" ]; then
142 mv $PXY_OUT o-pxy-${TESTS}.log
143 fi
144 echo " ! outputs saved to o-XXX-${TESTS}.log"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100145
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200146 if [ "X${USER:-}" = Xbuildbot -o "X${LOGNAME:-}" = Xbuildbot ]; then
147 echo " ! server output:"
148 cat o-srv-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200149 echo " ! ========================================================"
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200150 echo " ! client output:"
151 cat o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200152 if [ -n "$PXY_CMD" ]; then
153 echo " ! ========================================================"
154 echo " ! proxy output:"
155 cat o-pxy-${TESTS}.log
156 fi
157 echo ""
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200158 fi
159
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200160 FAILS=$(( $FAILS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100161}
162
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100163# is_polar <cmd_line>
164is_polar() {
165 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
166}
167
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100168# has_mem_err <log_file_name>
169has_mem_err() {
170 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
171 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
172 then
173 return 1 # false: does not have errors
174 else
175 return 0 # true: has errors
176 fi
177}
178
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200179# wait for server to start: two versions depending on lsof availability
180wait_server_start() {
181 if which lsof >/dev/null; then
182 # make sure we don't loop forever
183 ( sleep "$DOG_DELAY"; echo "SERVERSTART TIMEOUT"; kill $MAIN_PID ) &
184 WATCHDOG_PID=$!
185
186 # make a tight loop, server usually takes less than 1 sec to start
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200187 if [ "$DTLS" -eq 1 ]; then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200188 until lsof -nbi UDP:"$SRV_PORT" | grep UDP >/dev/null; do :; done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200189 else
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200190 until lsof -nbi TCP:"$SRV_PORT" | grep LISTEN >/dev/null; do :; done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200191 fi
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200192
193 kill $WATCHDOG_PID
194 wait $WATCHDOG_PID
195 else
196 sleep "$START_DELAY"
197 fi
198}
199
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200200# wait for client to terminate and set CLI_EXIT
201# must be called right after starting the client
202wait_client_done() {
203 CLI_PID=$!
204
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200205 CLI_DELAY=$(( $DOG_DELAY * $CLI_DELAY_FACTOR ))
206 CLI_DELAY_FACTOR=1
207
208 ( sleep $CLI_DELAY; echo "TIMEOUT" >> $CLI_OUT; kill $CLI_PID ) &
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200209 WATCHDOG_PID=$!
210
211 wait $CLI_PID
212 CLI_EXIT=$?
213
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200214 kill $WATCHDOG_PID >/dev/null 2>&1
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200215 wait $WATCHDOG_PID
216
217 echo "EXIT: $CLI_EXIT" >> $CLI_OUT
218}
219
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200220# check if the given command uses dtls and sets global variable DTLS
221detect_dtls() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200222 if echo "$1" | grep 'dtls=1\|-dtls1\|-u' >/dev/null; then
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200223 DTLS=1
224 else
225 DTLS=0
226 fi
227}
228
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200229# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100230# Options: -s pattern pattern that must be present in server output
231# -c pattern pattern that must be present in client output
232# -S pattern pattern that must be absent in server output
233# -C pattern pattern that must be absent in client output
234run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100235 NAME="$1"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200236 shift 1
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100237
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100238 if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
239 else
240 return
241 fi
242
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100243 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100244
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200245 # should we skip?
246 if [ "X$SKIP_NEXT" = "XYES" ]; then
247 SKIP_NEXT="NO"
248 echo "SKIP"
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200249 SKIPS=$(( $SKIPS + 1 ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200250 return
251 fi
252
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200253 # does this test use a proxy?
254 if [ "X$1" = "X-p" ]; then
255 PXY_CMD="$2"
256 shift 2
257 else
258 PXY_CMD=""
259 fi
260
261 # get commands and client output
262 SRV_CMD="$1"
263 CLI_CMD="$2"
264 CLI_EXPECT="$3"
265 shift 3
266
267 # fix client port
268 if [ -n "$PXY_CMD" ]; then
269 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
270 else
271 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
272 fi
273
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200274 # update DTLS variable
275 detect_dtls "$SRV_CMD"
276
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100277 # prepend valgrind to our commands if active
278 if [ "$MEMCHECK" -gt 0 ]; then
279 if is_polar "$SRV_CMD"; then
280 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
281 fi
282 if is_polar "$CLI_CMD"; then
283 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
284 fi
285 fi
286
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100287 # run the commands
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200288 if [ -n "$PXY_CMD" ]; then
289 echo "$PXY_CMD" > $PXY_OUT
290 eval "$PXY_CMD" >> $PXY_OUT 2>&1 &
291 PXY_PID=$!
292 # assume proxy starts faster than server
293 fi
294
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200295 echo "$SRV_CMD" > $SRV_OUT
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200296 # "yes" is for servers without -www (openssl with DTLS)
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +0200297 yes blabla | $SRV_CMD >> $SRV_OUT 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100298 SRV_PID=$!
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200299 wait_server_start
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200300
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200301 echo "$CLI_CMD" > $CLI_OUT
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200302 eval "$CLI_CMD" >> $CLI_OUT 2>&1 &
303 wait_client_done
Manuel Pégourié-Gonnarde01af4c2014-03-25 14:16:44 +0100304
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200305 # terminate the server (and the proxy)
Manuel Pégourié-Gonnard74b11702014-08-14 15:47:33 +0200306 kill $SRV_PID
307 wait $SRV_PID
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200308 if [ -n "$PXY_CMD" ]; then
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200309 kill $PXY_PID >/dev/null 2>&1
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200310 wait $PXY_PID
311 fi
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100312
313 # check if the client and server went at least to the handshake stage
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200314 # (useful to avoid tests with only negative assertions and non-zero
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100315 # expected client exit to incorrectly succeed in case of catastrophic
316 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100317 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200318 if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100319 else
320 fail "server failed to start"
321 return
322 fi
323 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100324 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200325 if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100326 else
327 fail "client failed to start"
328 return
329 fi
330 fi
331
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100332 # check server exit code
333 if [ $? != 0 ]; then
334 fail "server fail"
335 return
336 fi
337
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100338 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100339 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
340 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100341 then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200342 fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100343 return
344 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100345
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100346 # check other assertions
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200347 # lines beginning with == are added by valgrind, ignore them
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100348 while [ $# -gt 0 ]
349 do
350 case $1 in
351 "-s")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200352 if grep -v '^==' $SRV_OUT | grep "$2" >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100353 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100354 return
355 fi
356 ;;
357
358 "-c")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200359 if grep -v '^==' $CLI_OUT | grep "$2" >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100360 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100361 return
362 fi
363 ;;
364
365 "-S")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200366 if grep -v '^==' $SRV_OUT | grep "$2" >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100367 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100368 return
369 fi
370 ;;
371
372 "-C")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200373 if grep -v '^==' $CLI_OUT | grep "$2" >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100374 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100375 return
376 fi
377 ;;
378
379 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200380 echo "Unknown test: $1" >&2
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100381 exit 1
382 esac
383 shift 2
384 done
385
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100386 # check valgrind's results
387 if [ "$MEMCHECK" -gt 0 ]; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200388 if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100389 fail "Server has memory errors"
390 return
391 fi
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200392 if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100393 fail "Client has memory errors"
394 return
395 fi
396 fi
397
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100398 # if we're here, everything is ok
399 echo "PASS"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200400 rm -f $SRV_OUT $CLI_OUT $PXY_OUT
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100401}
402
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100403cleanup() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200404 rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200405 kill $SRV_PID >/dev/null 2>&1
406 kill $WATCHDOG_PID >/dev/null 2>&1
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200407 if [ -n "$PXY_CMD" ]; then
408 kill $PXY_PID >/dev/null 2>&1
409 fi
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100410 exit 1
411}
412
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100413#
414# MAIN
415#
416
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100417get_options "$@"
418
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100419# sanity checks, avoid an avalanche of errors
420if [ ! -x "$P_SRV" ]; then
421 echo "Command '$P_SRV' is not an executable file"
422 exit 1
423fi
424if [ ! -x "$P_CLI" ]; then
425 echo "Command '$P_CLI' is not an executable file"
426 exit 1
427fi
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200428if [ ! -x "$P_PXY" ]; then
429 echo "Command '$P_PXY' is not an executable file"
430 exit 1
431fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100432if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
433 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100434 exit 1
435fi
436
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200437# used by watchdog
438MAIN_PID="$$"
439
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200440# be more patient with valgrind
441if [ "$MEMCHECK" -gt 0 ]; then
442 START_DELAY=3
443 DOG_DELAY=30
444else
445 START_DELAY=1
446 DOG_DELAY=10
447fi
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200448CLI_DELAY_FACTOR=1
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200449
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200450# Pick a "unique" server port in the range 10000-19999, and a proxy port
451PORT_BASE="0000$$"
452PORT_BASE="$( echo -n $PORT_BASE | tail -c 4 )"
453SRV_PORT="1$PORT_BASE"
454PXY_PORT="2$PORT_BASE"
455unset PORT_BASE
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200456
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200457# fix commands to use this port, force IPv4 while at it
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200458P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
459P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
460P_PXY="$P_PXY server_addr=127.0.0.1 server_port=$SRV_PORT listen_addr=127.0.0.1 listen_port=$PXY_PORT"
461O_SRV="$O_SRV -accept $SRV_PORT"
462O_CLI="$O_CLI -connect localhost:+SRV_PORT"
463G_SRV="$G_SRV -p $SRV_PORT"
464G_CLI="$G_CLI -p +SRV_PORT"
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200465
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200466# Also pick a unique name for intermediate files
467SRV_OUT="srv_out.$$"
468CLI_OUT="cli_out.$$"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200469PXY_OUT="pxy_out.$$"
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200470SESSION="session.$$"
471
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200472SKIP_NEXT="NO"
473
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100474trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100475
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200476# Basic test
477
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200478# Checks that:
479# - things work with all ciphersuites active (used with config-full in all.sh)
480# - the expected (highest security) parameters are selected
481# ("signature_algorithm ext: 6" means SHA-512 (highest common hash))
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200482run_test "Default" \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200483 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200484 "$P_CLI" \
485 0 \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200486 -s "Protocol is TLSv1.2" \
487 -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
488 -s "client hello v3, signature_algorithm ext: 6" \
489 -s "ECDHE curve: secp521r1" \
490 -S "error" \
491 -C "error"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200492
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100493# Test for SSLv2 ClientHello
494
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200495requires_openssl_with_sslv2
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200496run_test "SSLv2 ClientHello: reference" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100497 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100498 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100499 0 \
500 -S "parse client hello v2" \
501 -S "ssl_handshake returned"
502
503# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200504requires_openssl_with_sslv2
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200505run_test "SSLv2 ClientHello: actual test" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200506 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100507 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100508 0 \
509 -s "parse client hello v2" \
510 -S "ssl_handshake returned"
511
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100512# Tests for Truncated HMAC extension
513
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200514run_test "Truncated HMAC: reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200515 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100516 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100517 0 \
518 -s "dumping 'computed mac' (20 bytes)"
519
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200520run_test "Truncated HMAC: actual test" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200521 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100522 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100523 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100524 -s "dumping 'computed mac' (10 bytes)"
525
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100526# Tests for Session Tickets
527
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200528run_test "Session resume using tickets: basic" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200529 "$P_SRV debug_level=3 tickets=1" \
530 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100531 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100532 -c "client hello, adding session ticket extension" \
533 -s "found session ticket extension" \
534 -s "server hello, adding session ticket extension" \
535 -c "found session_ticket extension" \
536 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100537 -S "session successfully restored from cache" \
538 -s "session successfully restored from ticket" \
539 -s "a session has been resumed" \
540 -c "a session has been resumed"
541
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200542run_test "Session resume using tickets: cache disabled" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200543 "$P_SRV debug_level=3 tickets=1 cache_max=0" \
544 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100545 0 \
546 -c "client hello, adding session ticket extension" \
547 -s "found session ticket extension" \
548 -s "server hello, adding session ticket extension" \
549 -c "found session_ticket extension" \
550 -c "parse new session ticket" \
551 -S "session successfully restored from cache" \
552 -s "session successfully restored from ticket" \
553 -s "a session has been resumed" \
554 -c "a session has been resumed"
555
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200556run_test "Session resume using tickets: timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200557 "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
558 "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100559 0 \
560 -c "client hello, adding session ticket extension" \
561 -s "found session ticket extension" \
562 -s "server hello, adding session ticket extension" \
563 -c "found session_ticket extension" \
564 -c "parse new session ticket" \
565 -S "session successfully restored from cache" \
566 -S "session successfully restored from ticket" \
567 -S "a session has been resumed" \
568 -C "a session has been resumed"
569
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200570run_test "Session resume using tickets: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100571 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200572 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100573 0 \
574 -c "client hello, adding session ticket extension" \
575 -c "found session_ticket extension" \
576 -c "parse new session ticket" \
577 -c "a session has been resumed"
578
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200579run_test "Session resume using tickets: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200580 "$P_SRV debug_level=3 tickets=1" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200581 "( $O_CLI -sess_out $SESSION; \
582 $O_CLI -sess_in $SESSION; \
583 rm -f $SESSION )" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100584 0 \
585 -s "found session ticket extension" \
586 -s "server hello, adding session ticket extension" \
587 -S "session successfully restored from cache" \
588 -s "session successfully restored from ticket" \
589 -s "a session has been resumed"
590
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100591# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100592
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200593run_test "Session resume using cache: tickets enabled on client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200594 "$P_SRV debug_level=3 tickets=0" \
595 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100596 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100597 -c "client hello, adding session ticket extension" \
598 -s "found session ticket extension" \
599 -S "server hello, adding session ticket extension" \
600 -C "found session_ticket extension" \
601 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100602 -s "session successfully restored from cache" \
603 -S "session successfully restored from ticket" \
604 -s "a session has been resumed" \
605 -c "a session has been resumed"
606
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200607run_test "Session resume using cache: tickets enabled on server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200608 "$P_SRV debug_level=3 tickets=1" \
609 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100610 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100611 -C "client hello, adding session ticket extension" \
612 -S "found session ticket extension" \
613 -S "server hello, adding session ticket extension" \
614 -C "found session_ticket extension" \
615 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100616 -s "session successfully restored from cache" \
617 -S "session successfully restored from ticket" \
618 -s "a session has been resumed" \
619 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100620
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200621run_test "Session resume using cache: cache_max=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200622 "$P_SRV debug_level=3 tickets=0 cache_max=0" \
623 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100624 0 \
625 -S "session successfully restored from cache" \
626 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100627 -S "a session has been resumed" \
628 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100629
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200630run_test "Session resume using cache: cache_max=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200631 "$P_SRV debug_level=3 tickets=0 cache_max=1" \
632 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100633 0 \
634 -s "session successfully restored from cache" \
635 -S "session successfully restored from ticket" \
636 -s "a session has been resumed" \
637 -c "a session has been resumed"
638
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200639run_test "Session resume using cache: timemout > delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200640 "$P_SRV debug_level=3 tickets=0" \
641 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100642 0 \
643 -s "session successfully restored from cache" \
644 -S "session successfully restored from ticket" \
645 -s "a session has been resumed" \
646 -c "a session has been resumed"
647
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200648run_test "Session resume using cache: timeout < delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200649 "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
650 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100651 0 \
652 -S "session successfully restored from cache" \
653 -S "session successfully restored from ticket" \
654 -S "a session has been resumed" \
655 -C "a session has been resumed"
656
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200657run_test "Session resume using cache: no timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200658 "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
659 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100660 0 \
661 -s "session successfully restored from cache" \
662 -S "session successfully restored from ticket" \
663 -s "a session has been resumed" \
664 -c "a session has been resumed"
665
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200666run_test "Session resume using cache: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200667 "$P_SRV debug_level=3 tickets=0" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200668 "( $O_CLI -sess_out $SESSION; \
669 $O_CLI -sess_in $SESSION; \
670 rm -f $SESSION )" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100671 0 \
672 -s "found session ticket extension" \
673 -S "server hello, adding session ticket extension" \
674 -s "session successfully restored from cache" \
675 -S "session successfully restored from ticket" \
676 -s "a session has been resumed"
677
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200678run_test "Session resume using cache: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100679 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200680 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100681 0 \
682 -C "found session_ticket extension" \
683 -C "parse new session ticket" \
684 -c "a session has been resumed"
685
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100686# Tests for Max Fragment Length extension
687
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200688run_test "Max fragment length: not used, reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200689 "$P_SRV debug_level=3" \
690 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100691 0 \
692 -C "client hello, adding max_fragment_length extension" \
693 -S "found max fragment length extension" \
694 -S "server hello, max_fragment_length extension" \
695 -C "found max_fragment_length extension"
696
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200697run_test "Max fragment length: used by client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200698 "$P_SRV debug_level=3" \
699 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100700 0 \
701 -c "client hello, adding max_fragment_length extension" \
702 -s "found max fragment length extension" \
703 -s "server hello, max_fragment_length extension" \
704 -c "found max_fragment_length extension"
705
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200706run_test "Max fragment length: used by server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200707 "$P_SRV debug_level=3 max_frag_len=4096" \
708 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100709 0 \
710 -C "client hello, adding max_fragment_length extension" \
711 -S "found max fragment length extension" \
712 -S "server hello, max_fragment_length extension" \
713 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100714
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200715requires_gnutls
716run_test "Max fragment length: gnutls server" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200717 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200718 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200719 0 \
720 -c "client hello, adding max_fragment_length extension" \
721 -c "found max_fragment_length extension"
722
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100723# Tests for renegotiation
724
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200725run_test "Renegotiation: none, for reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200726 "$P_SRV debug_level=3 exchanges=2" \
727 "$P_CLI debug_level=3 exchanges=2" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100728 0 \
729 -C "client hello, adding renegotiation extension" \
730 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
731 -S "found renegotiation extension" \
732 -s "server hello, secure renegotiation extension" \
733 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100734 -C "=> renegotiate" \
735 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100736 -S "write hello request"
737
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200738run_test "Renegotiation: client-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200739 "$P_SRV debug_level=3 exchanges=2 renegotiation=1" \
740 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100741 0 \
742 -c "client hello, adding renegotiation extension" \
743 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
744 -s "found renegotiation extension" \
745 -s "server hello, secure renegotiation extension" \
746 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100747 -c "=> renegotiate" \
748 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100749 -S "write hello request"
750
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200751run_test "Renegotiation: server-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200752 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
753 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100754 0 \
755 -c "client hello, adding renegotiation extension" \
756 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
757 -s "found renegotiation extension" \
758 -s "server hello, secure renegotiation extension" \
759 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100760 -c "=> renegotiate" \
761 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100762 -s "write hello request"
763
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200764run_test "Renegotiation: double" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200765 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
766 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100767 0 \
768 -c "client hello, adding renegotiation extension" \
769 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
770 -s "found renegotiation extension" \
771 -s "server hello, secure renegotiation extension" \
772 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100773 -c "=> renegotiate" \
774 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100775 -s "write hello request"
776
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200777run_test "Renegotiation: client-initiated, server-rejected" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200778 "$P_SRV debug_level=3 exchanges=2 renegotiation=0" \
779 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100780 1 \
781 -c "client hello, adding renegotiation extension" \
782 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
783 -S "found renegotiation extension" \
784 -s "server hello, secure renegotiation extension" \
785 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100786 -c "=> renegotiate" \
787 -S "=> renegotiate" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200788 -S "write hello request" \
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +0200789 -c "SSL - Unexpected message at ServerHello in renegotiation" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200790 -c "failed"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100791
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200792run_test "Renegotiation: server-initiated, client-rejected, default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200793 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
794 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100795 0 \
796 -C "client hello, adding renegotiation extension" \
797 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
798 -S "found renegotiation extension" \
799 -s "server hello, secure renegotiation extension" \
800 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100801 -C "=> renegotiate" \
802 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100803 -s "write hello request" \
Manuel Pégourié-Gonnarda9964db2014-07-03 19:29:16 +0200804 -S "SSL - An unexpected message was received from our peer" \
805 -S "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100806
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200807run_test "Renegotiation: server-initiated, client-rejected, not enforced" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200808 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200809 renego_delay=-1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200810 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200811 0 \
812 -C "client hello, adding renegotiation extension" \
813 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
814 -S "found renegotiation extension" \
815 -s "server hello, secure renegotiation extension" \
816 -c "found renegotiation extension" \
817 -C "=> renegotiate" \
818 -S "=> renegotiate" \
819 -s "write hello request" \
820 -S "SSL - An unexpected message was received from our peer" \
821 -S "failed"
822
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200823# delay 2 for 1 alert record + 1 application data record
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200824run_test "Renegotiation: server-initiated, client-rejected, delay 2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200825 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200826 renego_delay=2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200827 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200828 0 \
829 -C "client hello, adding renegotiation extension" \
830 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
831 -S "found renegotiation extension" \
832 -s "server hello, secure renegotiation extension" \
833 -c "found renegotiation extension" \
834 -C "=> renegotiate" \
835 -S "=> renegotiate" \
836 -s "write hello request" \
837 -S "SSL - An unexpected message was received from our peer" \
838 -S "failed"
839
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200840run_test "Renegotiation: server-initiated, client-rejected, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200841 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200842 renego_delay=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200843 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200844 0 \
845 -C "client hello, adding renegotiation extension" \
846 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
847 -S "found renegotiation extension" \
848 -s "server hello, secure renegotiation extension" \
849 -c "found renegotiation extension" \
850 -C "=> renegotiate" \
851 -S "=> renegotiate" \
852 -s "write hello request" \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200853 -s "SSL - An unexpected message was received from our peer"
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200854
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200855run_test "Renegotiation: server-initiated, client-accepted, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200856 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200857 renego_delay=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200858 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200859 0 \
860 -c "client hello, adding renegotiation extension" \
861 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
862 -s "found renegotiation extension" \
863 -s "server hello, secure renegotiation extension" \
864 -c "found renegotiation extension" \
865 -c "=> renegotiate" \
866 -s "=> renegotiate" \
867 -s "write hello request" \
868 -S "SSL - An unexpected message was received from our peer" \
869 -S "failed"
870
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200871run_test "Renegotiation: nbio, client-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200872 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
873 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +0200874 0 \
875 -c "client hello, adding renegotiation extension" \
876 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
877 -s "found renegotiation extension" \
878 -s "server hello, secure renegotiation extension" \
879 -c "found renegotiation extension" \
880 -c "=> renegotiate" \
881 -s "=> renegotiate" \
882 -S "write hello request"
883
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200884run_test "Renegotiation: nbio, server-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200885 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
886 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +0200887 0 \
888 -c "client hello, adding renegotiation extension" \
889 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
890 -s "found renegotiation extension" \
891 -s "server hello, secure renegotiation extension" \
892 -c "found renegotiation extension" \
893 -c "=> renegotiate" \
894 -s "=> renegotiate" \
895 -s "write hello request"
896
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200897run_test "Renegotiation: openssl server, client-initiated" \
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +0200898 "$O_SRV -www" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200899 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200900 0 \
901 -c "client hello, adding renegotiation extension" \
902 -c "found renegotiation extension" \
903 -c "=> renegotiate" \
904 -C "ssl_handshake returned" \
905 -C "error" \
906 -c "HTTP/1.0 200 [Oo][Kk]"
907
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200908run_test "Renegotiation: gnutls server, client-initiated" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200909 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200910 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200911 0 \
912 -c "client hello, adding renegotiation extension" \
913 -c "found renegotiation extension" \
914 -c "=> renegotiate" \
915 -C "ssl_handshake returned" \
916 -C "error" \
917 -c "HTTP/1.0 200 [Oo][Kk]"
918
Manuel Pégourié-Gonnard30d16eb2014-08-19 17:43:50 +0200919run_test "Renegotiation: DTLS, client-initiated" \
920 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
921 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
922 0 \
923 -c "client hello, adding renegotiation extension" \
924 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
925 -s "found renegotiation extension" \
926 -s "server hello, secure renegotiation extension" \
927 -c "found renegotiation extension" \
928 -c "=> renegotiate" \
929 -s "=> renegotiate" \
930 -S "write hello request"
931
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +0200932run_test "Renegotiation: DTLS, server-initiated" \
933 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
934 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
935 0 \
936 -c "client hello, adding renegotiation extension" \
937 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
938 -s "found renegotiation extension" \
939 -s "server hello, secure renegotiation extension" \
940 -c "found renegotiation extension" \
941 -c "=> renegotiate" \
942 -s "=> renegotiate" \
943 -s "write hello request"
944
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +0200945run_test "Renegotiation: DTLS, gnutls server, client-initiated" \
946 "$G_SRV -u --mtu 4096" \
947 "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
948 0 \
949 -c "client hello, adding renegotiation extension" \
950 -c "found renegotiation extension" \
951 -c "=> renegotiate" \
952 -C "ssl_handshake returned" \
953 -C "error" \
954 -s "Extra-header:"
955
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100956# Tests for auth_mode
957
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200958run_test "Authentication: server badcert, client required" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100959 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100960 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200961 "$P_CLI debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100962 1 \
963 -c "x509_verify_cert() returned" \
964 -c "! self-signed or not signed by a trusted CA" \
965 -c "! ssl_handshake returned" \
966 -c "X509 - Certificate verification failed"
967
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200968run_test "Authentication: server badcert, client optional" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100969 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100970 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200971 "$P_CLI debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100972 0 \
973 -c "x509_verify_cert() returned" \
974 -c "! self-signed or not signed by a trusted CA" \
975 -C "! ssl_handshake returned" \
976 -C "X509 - Certificate verification failed"
977
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200978run_test "Authentication: server badcert, client none" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100979 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100980 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200981 "$P_CLI debug_level=1 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100982 0 \
983 -C "x509_verify_cert() returned" \
984 -C "! self-signed or not signed by a trusted CA" \
985 -C "! ssl_handshake returned" \
986 -C "X509 - Certificate verification failed"
987
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200988run_test "Authentication: client badcert, server required" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200989 "$P_SRV debug_level=3 auth_mode=required" \
990 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100991 key_file=data_files/server5.key" \
992 1 \
993 -S "skip write certificate request" \
994 -C "skip parse certificate request" \
995 -c "got a certificate request" \
996 -C "skip write certificate" \
997 -C "skip write certificate verify" \
998 -S "skip parse certificate verify" \
999 -s "x509_verify_cert() returned" \
1000 -S "! self-signed or not signed by a trusted CA" \
1001 -s "! ssl_handshake returned" \
1002 -c "! ssl_handshake returned" \
1003 -s "X509 - Certificate verification failed"
1004
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001005run_test "Authentication: client badcert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001006 "$P_SRV debug_level=3 auth_mode=optional" \
1007 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001008 key_file=data_files/server5.key" \
1009 0 \
1010 -S "skip write certificate request" \
1011 -C "skip parse certificate request" \
1012 -c "got a certificate request" \
1013 -C "skip write certificate" \
1014 -C "skip write certificate verify" \
1015 -S "skip parse certificate verify" \
1016 -s "x509_verify_cert() returned" \
1017 -s "! self-signed or not signed by a trusted CA" \
1018 -S "! ssl_handshake returned" \
1019 -C "! ssl_handshake returned" \
1020 -S "X509 - Certificate verification failed"
1021
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001022run_test "Authentication: client badcert, server none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001023 "$P_SRV debug_level=3 auth_mode=none" \
1024 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001025 key_file=data_files/server5.key" \
1026 0 \
1027 -s "skip write certificate request" \
1028 -C "skip parse certificate request" \
1029 -c "got no certificate request" \
1030 -c "skip write certificate" \
1031 -c "skip write certificate verify" \
1032 -s "skip parse certificate verify" \
1033 -S "x509_verify_cert() returned" \
1034 -S "! self-signed or not signed by a trusted CA" \
1035 -S "! ssl_handshake returned" \
1036 -C "! ssl_handshake returned" \
1037 -S "X509 - Certificate verification failed"
1038
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001039run_test "Authentication: client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001040 "$P_SRV debug_level=3 auth_mode=optional" \
1041 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001042 0 \
1043 -S "skip write certificate request" \
1044 -C "skip parse certificate request" \
1045 -c "got a certificate request" \
1046 -C "skip write certificate$" \
1047 -C "got no certificate to send" \
1048 -S "SSLv3 client has no certificate" \
1049 -c "skip write certificate verify" \
1050 -s "skip parse certificate verify" \
1051 -s "! no client certificate sent" \
1052 -S "! ssl_handshake returned" \
1053 -C "! ssl_handshake returned" \
1054 -S "X509 - Certificate verification failed"
1055
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001056run_test "Authentication: openssl client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001057 "$P_SRV debug_level=3 auth_mode=optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001058 "$O_CLI" \
1059 0 \
1060 -S "skip write certificate request" \
1061 -s "skip parse certificate verify" \
1062 -s "! no client certificate sent" \
1063 -S "! ssl_handshake returned" \
1064 -S "X509 - Certificate verification failed"
1065
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001066run_test "Authentication: client no cert, openssl server optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001067 "$O_SRV -verify 10" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001068 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001069 0 \
1070 -C "skip parse certificate request" \
1071 -c "got a certificate request" \
1072 -C "skip write certificate$" \
1073 -c "skip write certificate verify" \
1074 -C "! ssl_handshake returned"
1075
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001076run_test "Authentication: client no cert, ssl3" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001077 "$P_SRV debug_level=3 auth_mode=optional force_version=ssl3" \
1078 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001079 0 \
1080 -S "skip write certificate request" \
1081 -C "skip parse certificate request" \
1082 -c "got a certificate request" \
1083 -C "skip write certificate$" \
1084 -c "skip write certificate verify" \
1085 -c "got no certificate to send" \
1086 -s "SSLv3 client has no certificate" \
1087 -s "skip parse certificate verify" \
1088 -s "! no client certificate sent" \
1089 -S "! ssl_handshake returned" \
1090 -C "! ssl_handshake returned" \
1091 -S "X509 - Certificate verification failed"
1092
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001093# tests for SNI
1094
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001095run_test "SNI: no SNI callback" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001096 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001097 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001098 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001099 0 \
1100 -S "parse ServerName extension" \
1101 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
1102 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
1103
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001104run_test "SNI: matching cert 1" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001105 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001106 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001107 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001108 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001109 0 \
1110 -s "parse ServerName extension" \
1111 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
1112 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
1113
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001114run_test "SNI: matching cert 2" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001115 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001116 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001117 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001118 "$P_CLI server_name=polarssl.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001119 0 \
1120 -s "parse ServerName extension" \
1121 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001122 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001123
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001124run_test "SNI: no matching cert" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001125 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001126 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001127 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001128 "$P_CLI server_name=nonesuch.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001129 1 \
1130 -s "parse ServerName extension" \
1131 -s "ssl_sni_wrapper() returned" \
1132 -s "ssl_handshake returned" \
1133 -c "ssl_handshake returned" \
1134 -c "SSL - A fatal alert message was received from our peer"
1135
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001136# Tests for non-blocking I/O: exercise a variety of handshake flows
1137
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001138run_test "Non-blocking I/O: basic handshake" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001139 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
1140 "$P_CLI nbio=2 tickets=0" \
1141 0 \
1142 -S "ssl_handshake returned" \
1143 -C "ssl_handshake returned" \
1144 -c "Read from server: .* bytes read"
1145
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001146run_test "Non-blocking I/O: client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001147 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
1148 "$P_CLI nbio=2 tickets=0" \
1149 0 \
1150 -S "ssl_handshake returned" \
1151 -C "ssl_handshake returned" \
1152 -c "Read from server: .* bytes read"
1153
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001154run_test "Non-blocking I/O: ticket" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001155 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
1156 "$P_CLI nbio=2 tickets=1" \
1157 0 \
1158 -S "ssl_handshake returned" \
1159 -C "ssl_handshake returned" \
1160 -c "Read from server: .* bytes read"
1161
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001162run_test "Non-blocking I/O: ticket + client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001163 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
1164 "$P_CLI nbio=2 tickets=1" \
1165 0 \
1166 -S "ssl_handshake returned" \
1167 -C "ssl_handshake returned" \
1168 -c "Read from server: .* bytes read"
1169
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001170run_test "Non-blocking I/O: ticket + client auth + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001171 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
1172 "$P_CLI nbio=2 tickets=1 reconnect=1" \
1173 0 \
1174 -S "ssl_handshake returned" \
1175 -C "ssl_handshake returned" \
1176 -c "Read from server: .* bytes read"
1177
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001178run_test "Non-blocking I/O: ticket + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001179 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
1180 "$P_CLI nbio=2 tickets=1 reconnect=1" \
1181 0 \
1182 -S "ssl_handshake returned" \
1183 -C "ssl_handshake returned" \
1184 -c "Read from server: .* bytes read"
1185
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001186run_test "Non-blocking I/O: session-id resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001187 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
1188 "$P_CLI nbio=2 tickets=0 reconnect=1" \
1189 0 \
1190 -S "ssl_handshake returned" \
1191 -C "ssl_handshake returned" \
1192 -c "Read from server: .* bytes read"
1193
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001194# Tests for version negotiation
1195
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001196run_test "Version check: all -> 1.2" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001197 "$P_SRV" \
1198 "$P_CLI" \
1199 0 \
1200 -S "ssl_handshake returned" \
1201 -C "ssl_handshake returned" \
1202 -s "Protocol is TLSv1.2" \
1203 -c "Protocol is TLSv1.2"
1204
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001205run_test "Version check: cli max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001206 "$P_SRV" \
1207 "$P_CLI max_version=tls1_1" \
1208 0 \
1209 -S "ssl_handshake returned" \
1210 -C "ssl_handshake returned" \
1211 -s "Protocol is TLSv1.1" \
1212 -c "Protocol is TLSv1.1"
1213
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001214run_test "Version check: srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001215 "$P_SRV max_version=tls1_1" \
1216 "$P_CLI" \
1217 0 \
1218 -S "ssl_handshake returned" \
1219 -C "ssl_handshake returned" \
1220 -s "Protocol is TLSv1.1" \
1221 -c "Protocol is TLSv1.1"
1222
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001223run_test "Version check: cli+srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001224 "$P_SRV max_version=tls1_1" \
1225 "$P_CLI max_version=tls1_1" \
1226 0 \
1227 -S "ssl_handshake returned" \
1228 -C "ssl_handshake returned" \
1229 -s "Protocol is TLSv1.1" \
1230 -c "Protocol is TLSv1.1"
1231
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001232run_test "Version check: cli max 1.1, srv min 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001233 "$P_SRV min_version=tls1_1" \
1234 "$P_CLI max_version=tls1_1" \
1235 0 \
1236 -S "ssl_handshake returned" \
1237 -C "ssl_handshake returned" \
1238 -s "Protocol is TLSv1.1" \
1239 -c "Protocol is TLSv1.1"
1240
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001241run_test "Version check: cli min 1.1, srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001242 "$P_SRV max_version=tls1_1" \
1243 "$P_CLI min_version=tls1_1" \
1244 0 \
1245 -S "ssl_handshake returned" \
1246 -C "ssl_handshake returned" \
1247 -s "Protocol is TLSv1.1" \
1248 -c "Protocol is TLSv1.1"
1249
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001250run_test "Version check: cli min 1.2, srv max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001251 "$P_SRV max_version=tls1_1" \
1252 "$P_CLI min_version=tls1_2" \
1253 1 \
1254 -s "ssl_handshake returned" \
1255 -c "ssl_handshake returned" \
1256 -c "SSL - Handshake protocol not within min/max boundaries"
1257
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001258run_test "Version check: srv min 1.2, cli max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001259 "$P_SRV min_version=tls1_2" \
1260 "$P_CLI max_version=tls1_1" \
1261 1 \
1262 -s "ssl_handshake returned" \
1263 -c "ssl_handshake returned" \
1264 -s "SSL - Handshake protocol not within min/max boundaries"
1265
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001266# Tests for ALPN extension
1267
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02001268if grep '^#define POLARSSL_SSL_ALPN' $CONFIG_H >/dev/null; then
1269
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001270run_test "ALPN: none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001271 "$P_SRV debug_level=3" \
1272 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001273 0 \
1274 -C "client hello, adding alpn extension" \
1275 -S "found alpn extension" \
1276 -C "got an alert message, type: \\[2:120]" \
1277 -S "server hello, adding alpn extension" \
1278 -C "found alpn extension " \
1279 -C "Application Layer Protocol is" \
1280 -S "Application Layer Protocol is"
1281
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001282run_test "ALPN: client only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001283 "$P_SRV debug_level=3" \
1284 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001285 0 \
1286 -c "client hello, adding alpn extension" \
1287 -s "found alpn extension" \
1288 -C "got an alert message, type: \\[2:120]" \
1289 -S "server hello, adding alpn extension" \
1290 -C "found alpn extension " \
1291 -c "Application Layer Protocol is (none)" \
1292 -S "Application Layer Protocol is"
1293
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001294run_test "ALPN: server only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001295 "$P_SRV debug_level=3 alpn=abc,1234" \
1296 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001297 0 \
1298 -C "client hello, adding alpn extension" \
1299 -S "found alpn extension" \
1300 -C "got an alert message, type: \\[2:120]" \
1301 -S "server hello, adding alpn extension" \
1302 -C "found alpn extension " \
1303 -C "Application Layer Protocol is" \
1304 -s "Application Layer Protocol is (none)"
1305
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001306run_test "ALPN: both, common cli1-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001307 "$P_SRV debug_level=3 alpn=abc,1234" \
1308 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001309 0 \
1310 -c "client hello, adding alpn extension" \
1311 -s "found alpn extension" \
1312 -C "got an alert message, type: \\[2:120]" \
1313 -s "server hello, adding alpn extension" \
1314 -c "found alpn extension" \
1315 -c "Application Layer Protocol is abc" \
1316 -s "Application Layer Protocol is abc"
1317
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001318run_test "ALPN: both, common cli2-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001319 "$P_SRV debug_level=3 alpn=abc,1234" \
1320 "$P_CLI debug_level=3 alpn=1234,abc" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001321 0 \
1322 -c "client hello, adding alpn extension" \
1323 -s "found alpn extension" \
1324 -C "got an alert message, type: \\[2:120]" \
1325 -s "server hello, adding alpn extension" \
1326 -c "found alpn extension" \
1327 -c "Application Layer Protocol is abc" \
1328 -s "Application Layer Protocol is abc"
1329
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001330run_test "ALPN: both, common cli1-srv2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001331 "$P_SRV debug_level=3 alpn=abc,1234" \
1332 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001333 0 \
1334 -c "client hello, adding alpn extension" \
1335 -s "found alpn extension" \
1336 -C "got an alert message, type: \\[2:120]" \
1337 -s "server hello, adding alpn extension" \
1338 -c "found alpn extension" \
1339 -c "Application Layer Protocol is 1234" \
1340 -s "Application Layer Protocol is 1234"
1341
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001342run_test "ALPN: both, no common" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001343 "$P_SRV debug_level=3 alpn=abc,123" \
1344 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001345 1 \
1346 -c "client hello, adding alpn extension" \
1347 -s "found alpn extension" \
1348 -c "got an alert message, type: \\[2:120]" \
1349 -S "server hello, adding alpn extension" \
1350 -C "found alpn extension" \
1351 -C "Application Layer Protocol is 1234" \
1352 -S "Application Layer Protocol is 1234"
1353
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02001354fi
1355
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001356# Tests for keyUsage in leaf certificates, part 1:
1357# server-side certificate/suite selection
1358
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001359run_test "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001360 "$P_SRV key_file=data_files/server2.key \
1361 crt_file=data_files/server2.ku-ds.crt" \
1362 "$P_CLI" \
1363 0 \
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02001364 -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001365
1366
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001367run_test "keyUsage srv: RSA, keyEncipherment -> RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001368 "$P_SRV key_file=data_files/server2.key \
1369 crt_file=data_files/server2.ku-ke.crt" \
1370 "$P_CLI" \
1371 0 \
1372 -c "Ciphersuite is TLS-RSA-WITH-"
1373
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001374run_test "keyUsage srv: RSA, keyAgreement -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001375 "$P_SRV key_file=data_files/server2.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001376 crt_file=data_files/server2.ku-ka.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001377 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001378 1 \
1379 -C "Ciphersuite is "
1380
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001381run_test "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001382 "$P_SRV key_file=data_files/server5.key \
1383 crt_file=data_files/server5.ku-ds.crt" \
1384 "$P_CLI" \
1385 0 \
1386 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
1387
1388
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001389run_test "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001390 "$P_SRV key_file=data_files/server5.key \
1391 crt_file=data_files/server5.ku-ka.crt" \
1392 "$P_CLI" \
1393 0 \
1394 -c "Ciphersuite is TLS-ECDH-"
1395
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001396run_test "keyUsage srv: ECDSA, keyEncipherment -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001397 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001398 crt_file=data_files/server5.ku-ke.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001399 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001400 1 \
1401 -C "Ciphersuite is "
1402
1403# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001404# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001405
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001406run_test "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001407 "$O_SRV -key data_files/server2.key \
1408 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001409 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001410 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1411 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001412 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001413 -C "Processing of the Certificate handshake message failed" \
1414 -c "Ciphersuite is TLS-"
1415
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001416run_test "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001417 "$O_SRV -key data_files/server2.key \
1418 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001419 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001420 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1421 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001422 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001423 -C "Processing of the Certificate handshake message failed" \
1424 -c "Ciphersuite is TLS-"
1425
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001426run_test "keyUsage cli: KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001427 "$O_SRV -key data_files/server2.key \
1428 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001429 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001430 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1431 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001432 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001433 -C "Processing of the Certificate handshake message failed" \
1434 -c "Ciphersuite is TLS-"
1435
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001436run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001437 "$O_SRV -key data_files/server2.key \
1438 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001439 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001440 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1441 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001442 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001443 -c "Processing of the Certificate handshake message failed" \
1444 -C "Ciphersuite is TLS-"
1445
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001446run_test "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001447 "$O_SRV -key data_files/server2.key \
1448 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001449 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001450 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1451 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001452 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001453 -C "Processing of the Certificate handshake message failed" \
1454 -c "Ciphersuite is TLS-"
1455
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001456run_test "keyUsage cli: DigitalSignature, RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001457 "$O_SRV -key data_files/server2.key \
1458 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001459 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001460 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1461 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001462 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001463 -c "Processing of the Certificate handshake message failed" \
1464 -C "Ciphersuite is TLS-"
1465
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001466# Tests for keyUsage in leaf certificates, part 3:
1467# server-side checking of client cert
1468
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001469run_test "keyUsage cli-auth: RSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001470 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001471 "$O_CLI -key data_files/server2.key \
1472 -cert data_files/server2.ku-ds.crt" \
1473 0 \
1474 -S "bad certificate (usage extensions)" \
1475 -S "Processing of the Certificate handshake message failed"
1476
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001477run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001478 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001479 "$O_CLI -key data_files/server2.key \
1480 -cert data_files/server2.ku-ke.crt" \
1481 0 \
1482 -s "bad certificate (usage extensions)" \
1483 -S "Processing of the Certificate handshake message failed"
1484
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001485run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001486 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001487 "$O_CLI -key data_files/server2.key \
1488 -cert data_files/server2.ku-ke.crt" \
1489 1 \
1490 -s "bad certificate (usage extensions)" \
1491 -s "Processing of the Certificate handshake message failed"
1492
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001493run_test "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001494 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001495 "$O_CLI -key data_files/server5.key \
1496 -cert data_files/server5.ku-ds.crt" \
1497 0 \
1498 -S "bad certificate (usage extensions)" \
1499 -S "Processing of the Certificate handshake message failed"
1500
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001501run_test "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001502 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001503 "$O_CLI -key data_files/server5.key \
1504 -cert data_files/server5.ku-ka.crt" \
1505 0 \
1506 -s "bad certificate (usage extensions)" \
1507 -S "Processing of the Certificate handshake message failed"
1508
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001509# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
1510
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001511run_test "extKeyUsage srv: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001512 "$P_SRV key_file=data_files/server5.key \
1513 crt_file=data_files/server5.eku-srv.crt" \
1514 "$P_CLI" \
1515 0
1516
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001517run_test "extKeyUsage srv: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001518 "$P_SRV key_file=data_files/server5.key \
1519 crt_file=data_files/server5.eku-srv.crt" \
1520 "$P_CLI" \
1521 0
1522
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001523run_test "extKeyUsage srv: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001524 "$P_SRV key_file=data_files/server5.key \
1525 crt_file=data_files/server5.eku-cs_any.crt" \
1526 "$P_CLI" \
1527 0
1528
1529# add psk to leave an option for client to send SERVERQUIT
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001530run_test "extKeyUsage srv: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001531 "$P_SRV psk=abc123 key_file=data_files/server5.key \
1532 crt_file=data_files/server5.eku-cli.crt" \
1533 "$P_CLI psk=badbad" \
1534 1
1535
1536# Tests for extendedKeyUsage, part 2: client-side checking of server cert
1537
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001538run_test "extKeyUsage cli: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001539 "$O_SRV -key data_files/server5.key \
1540 -cert data_files/server5.eku-srv.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001541 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001542 0 \
1543 -C "bad certificate (usage extensions)" \
1544 -C "Processing of the Certificate handshake message failed" \
1545 -c "Ciphersuite is TLS-"
1546
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001547run_test "extKeyUsage cli: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001548 "$O_SRV -key data_files/server5.key \
1549 -cert data_files/server5.eku-srv_cli.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001550 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001551 0 \
1552 -C "bad certificate (usage extensions)" \
1553 -C "Processing of the Certificate handshake message failed" \
1554 -c "Ciphersuite is TLS-"
1555
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001556run_test "extKeyUsage cli: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001557 "$O_SRV -key data_files/server5.key \
1558 -cert data_files/server5.eku-cs_any.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001559 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001560 0 \
1561 -C "bad certificate (usage extensions)" \
1562 -C "Processing of the Certificate handshake message failed" \
1563 -c "Ciphersuite is TLS-"
1564
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001565run_test "extKeyUsage cli: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001566 "$O_SRV -key data_files/server5.key \
1567 -cert data_files/server5.eku-cs.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001568 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001569 1 \
1570 -c "bad certificate (usage extensions)" \
1571 -c "Processing of the Certificate handshake message failed" \
1572 -C "Ciphersuite is TLS-"
1573
1574# Tests for extendedKeyUsage, part 3: server-side checking of client cert
1575
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001576run_test "extKeyUsage cli-auth: clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001577 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001578 "$O_CLI -key data_files/server5.key \
1579 -cert data_files/server5.eku-cli.crt" \
1580 0 \
1581 -S "bad certificate (usage extensions)" \
1582 -S "Processing of the Certificate handshake message failed"
1583
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001584run_test "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001585 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001586 "$O_CLI -key data_files/server5.key \
1587 -cert data_files/server5.eku-srv_cli.crt" \
1588 0 \
1589 -S "bad certificate (usage extensions)" \
1590 -S "Processing of the Certificate handshake message failed"
1591
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001592run_test "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001593 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001594 "$O_CLI -key data_files/server5.key \
1595 -cert data_files/server5.eku-cs_any.crt" \
1596 0 \
1597 -S "bad certificate (usage extensions)" \
1598 -S "Processing of the Certificate handshake message failed"
1599
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001600run_test "extKeyUsage cli-auth: codeSign -> fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001601 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001602 "$O_CLI -key data_files/server5.key \
1603 -cert data_files/server5.eku-cs.crt" \
1604 0 \
1605 -s "bad certificate (usage extensions)" \
1606 -S "Processing of the Certificate handshake message failed"
1607
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001608run_test "extKeyUsage cli-auth: codeSign -> fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001609 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001610 "$O_CLI -key data_files/server5.key \
1611 -cert data_files/server5.eku-cs.crt" \
1612 1 \
1613 -s "bad certificate (usage extensions)" \
1614 -s "Processing of the Certificate handshake message failed"
1615
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001616# Tests for DHM parameters loading
1617
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001618run_test "DHM parameters: reference" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001619 "$P_SRV" \
1620 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1621 debug_level=3" \
1622 0 \
1623 -c "value of 'DHM: P ' (2048 bits)" \
1624 -c "value of 'DHM: G ' (2048 bits)"
1625
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001626run_test "DHM parameters: other parameters" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001627 "$P_SRV dhm_file=data_files/dhparams.pem" \
1628 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1629 debug_level=3" \
1630 0 \
1631 -c "value of 'DHM: P ' (1024 bits)" \
1632 -c "value of 'DHM: G ' (2 bits)"
1633
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001634# Tests for PSK callback
1635
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001636run_test "PSK callback: psk, no callback" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001637 "$P_SRV psk=abc123 psk_identity=foo" \
1638 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1639 psk_identity=foo psk=abc123" \
1640 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001641 -S "SSL - The server has no ciphersuites in common" \
1642 -S "SSL - Unknown identity received" \
1643 -S "SSL - Verification of the message MAC failed"
1644
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001645run_test "PSK callback: no psk, no callback" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001646 "$P_SRV" \
1647 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1648 psk_identity=foo psk=abc123" \
1649 1 \
1650 -s "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001651 -S "SSL - Unknown identity received" \
1652 -S "SSL - Verification of the message MAC failed"
1653
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001654run_test "PSK callback: callback overrides other settings" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001655 "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
1656 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1657 psk_identity=foo psk=abc123" \
1658 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001659 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001660 -s "SSL - Unknown identity received" \
1661 -S "SSL - Verification of the message MAC failed"
1662
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001663run_test "PSK callback: first id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001664 "$P_SRV psk_list=abc,dead,def,beef" \
1665 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1666 psk_identity=abc psk=dead" \
1667 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001668 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001669 -S "SSL - Unknown identity received" \
1670 -S "SSL - Verification of the message MAC failed"
1671
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001672run_test "PSK callback: second id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001673 "$P_SRV psk_list=abc,dead,def,beef" \
1674 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1675 psk_identity=def psk=beef" \
1676 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001677 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001678 -S "SSL - Unknown identity received" \
1679 -S "SSL - Verification of the message MAC failed"
1680
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001681run_test "PSK callback: no match" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001682 "$P_SRV psk_list=abc,dead,def,beef" \
1683 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1684 psk_identity=ghi psk=beef" \
1685 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001686 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001687 -s "SSL - Unknown identity received" \
1688 -S "SSL - Verification of the message MAC failed"
1689
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001690run_test "PSK callback: wrong key" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001691 "$P_SRV psk_list=abc,dead,def,beef" \
1692 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1693 psk_identity=abc psk=beef" \
1694 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001695 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001696 -S "SSL - Unknown identity received" \
1697 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001698
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001699# Tests for ciphersuites per version
1700
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001701run_test "Per-version suites: SSL3" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001702 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1703 "$P_CLI force_version=ssl3" \
1704 0 \
1705 -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA"
1706
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001707run_test "Per-version suites: TLS 1.0" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001708 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1709 "$P_CLI force_version=tls1" \
1710 0 \
1711 -c "Ciphersuite is TLS-RSA-WITH-RC4-128-SHA"
1712
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001713run_test "Per-version suites: TLS 1.1" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001714 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1715 "$P_CLI force_version=tls1_1" \
1716 0 \
1717 -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA"
1718
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001719run_test "Per-version suites: TLS 1.2" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001720 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1721 "$P_CLI force_version=tls1_2" \
1722 0 \
1723 -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
1724
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001725# Tests for ssl_get_bytes_avail()
1726
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001727run_test "ssl_get_bytes_avail: no extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001728 "$P_SRV" \
1729 "$P_CLI request_size=100" \
1730 0 \
1731 -s "Read from client: 100 bytes read$"
1732
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001733run_test "ssl_get_bytes_avail: extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001734 "$P_SRV" \
1735 "$P_CLI request_size=500" \
1736 0 \
1737 -s "Read from client: 500 bytes read (.*+.*)"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001738
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02001739# Tests for small packets
1740
1741run_test "Small packet SSLv3 BlockCipher" \
1742 "$P_SRV" \
1743 "$P_CLI request_size=1 force_version=ssl3 \
1744 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1745 0 \
1746 -s "Read from client: 1 bytes read"
1747
1748run_test "Small packet SSLv3 StreamCipher" \
1749 "$P_SRV" \
1750 "$P_CLI request_size=1 force_version=ssl3 \
1751 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1752 0 \
1753 -s "Read from client: 1 bytes read"
1754
1755run_test "Small packet TLS 1.0 BlockCipher" \
1756 "$P_SRV" \
1757 "$P_CLI request_size=1 force_version=tls1 \
1758 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1759 0 \
1760 -s "Read from client: 1 bytes read"
1761
1762run_test "Small packet TLS 1.0 BlockCipher truncated MAC" \
1763 "$P_SRV" \
1764 "$P_CLI request_size=1 force_version=tls1 \
1765 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1766 trunc_hmac=1" \
1767 0 \
1768 -s "Read from client: 1 bytes read"
1769
1770run_test "Small packet TLS 1.0 StreamCipher truncated MAC" \
1771 "$P_SRV" \
1772 "$P_CLI request_size=1 force_version=tls1 \
1773 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1774 trunc_hmac=1" \
1775 0 \
1776 -s "Read from client: 1 bytes read"
1777
1778run_test "Small packet TLS 1.1 BlockCipher" \
1779 "$P_SRV" \
1780 "$P_CLI request_size=1 force_version=tls1_1 \
1781 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1782 0 \
1783 -s "Read from client: 1 bytes read"
1784
1785run_test "Small packet TLS 1.1 StreamCipher" \
1786 "$P_SRV" \
1787 "$P_CLI request_size=1 force_version=tls1_1 \
1788 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1789 0 \
1790 -s "Read from client: 1 bytes read"
1791
1792run_test "Small packet TLS 1.1 BlockCipher truncated MAC" \
1793 "$P_SRV" \
1794 "$P_CLI request_size=1 force_version=tls1_1 \
1795 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1796 trunc_hmac=1" \
1797 0 \
1798 -s "Read from client: 1 bytes read"
1799
1800run_test "Small packet TLS 1.1 StreamCipher truncated MAC" \
1801 "$P_SRV" \
1802 "$P_CLI request_size=1 force_version=tls1_1 \
1803 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1804 trunc_hmac=1" \
1805 0 \
1806 -s "Read from client: 1 bytes read"
1807
1808run_test "Small packet TLS 1.2 BlockCipher" \
1809 "$P_SRV" \
1810 "$P_CLI request_size=1 force_version=tls1_2 \
1811 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1812 0 \
1813 -s "Read from client: 1 bytes read"
1814
1815run_test "Small packet TLS 1.2 BlockCipher larger MAC" \
1816 "$P_SRV" \
1817 "$P_CLI request_size=1 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1818 0 \
1819 -s "Read from client: 1 bytes read"
1820
1821run_test "Small packet TLS 1.2 BlockCipher truncated MAC" \
1822 "$P_SRV" \
1823 "$P_CLI request_size=1 force_version=tls1_2 \
1824 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1825 trunc_hmac=1" \
1826 0 \
1827 -s "Read from client: 1 bytes read"
1828
1829run_test "Small packet TLS 1.2 StreamCipher" \
1830 "$P_SRV" \
1831 "$P_CLI request_size=1 force_version=tls1_2 \
1832 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1833 0 \
1834 -s "Read from client: 1 bytes read"
1835
1836run_test "Small packet TLS 1.2 StreamCipher truncated MAC" \
1837 "$P_SRV" \
1838 "$P_CLI request_size=1 force_version=tls1_2 \
1839 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1840 trunc_hmac=1" \
1841 0 \
1842 -s "Read from client: 1 bytes read"
1843
1844run_test "Small packet TLS 1.2 AEAD" \
1845 "$P_SRV" \
1846 "$P_CLI request_size=1 force_version=tls1_2 \
1847 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1848 0 \
1849 -s "Read from client: 1 bytes read"
1850
1851run_test "Small packet TLS 1.2 AEAD shorter tag" \
1852 "$P_SRV" \
1853 "$P_CLI request_size=1 force_version=tls1_2 \
1854 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
1855 0 \
1856 -s "Read from client: 1 bytes read"
1857
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02001858# Test for large packets
1859
1860run_test "Large packet SSLv3 BlockCipher" \
1861 "$P_SRV" \
1862 "$P_CLI request_size=16384 force_version=ssl3 \
1863 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1864 0 \
1865 -s "Read from client: 16384 bytes read"
1866
1867run_test "Large packet SSLv3 StreamCipher" \
1868 "$P_SRV" \
1869 "$P_CLI request_size=16384 force_version=ssl3 \
1870 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1871 0 \
1872 -s "Read from client: 16384 bytes read"
1873
1874run_test "Large packet TLS 1.0 BlockCipher" \
1875 "$P_SRV" \
1876 "$P_CLI request_size=16384 force_version=tls1 \
1877 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1878 0 \
1879 -s "Read from client: 16384 bytes read"
1880
1881run_test "Large packet TLS 1.0 BlockCipher truncated MAC" \
1882 "$P_SRV" \
1883 "$P_CLI request_size=16384 force_version=tls1 \
1884 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1885 trunc_hmac=1" \
1886 0 \
1887 -s "Read from client: 16384 bytes read"
1888
1889run_test "Large packet TLS 1.0 StreamCipher truncated MAC" \
1890 "$P_SRV" \
1891 "$P_CLI request_size=16384 force_version=tls1 \
1892 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1893 trunc_hmac=1" \
1894 0 \
1895 -s "Read from client: 16384 bytes read"
1896
1897run_test "Large packet TLS 1.1 BlockCipher" \
1898 "$P_SRV" \
1899 "$P_CLI request_size=16384 force_version=tls1_1 \
1900 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1901 0 \
1902 -s "Read from client: 16384 bytes read"
1903
1904run_test "Large packet TLS 1.1 StreamCipher" \
1905 "$P_SRV" \
1906 "$P_CLI request_size=16384 force_version=tls1_1 \
1907 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1908 0 \
1909 -s "Read from client: 16384 bytes read"
1910
1911run_test "Large packet TLS 1.1 BlockCipher truncated MAC" \
1912 "$P_SRV" \
1913 "$P_CLI request_size=16384 force_version=tls1_1 \
1914 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1915 trunc_hmac=1" \
1916 0 \
1917 -s "Read from client: 16384 bytes read"
1918
1919run_test "Large packet TLS 1.1 StreamCipher truncated MAC" \
1920 "$P_SRV" \
1921 "$P_CLI request_size=16384 force_version=tls1_1 \
1922 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1923 trunc_hmac=1" \
1924 0 \
1925 -s "Read from client: 16384 bytes read"
1926
1927run_test "Large packet TLS 1.2 BlockCipher" \
1928 "$P_SRV" \
1929 "$P_CLI request_size=16384 force_version=tls1_2 \
1930 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1931 0 \
1932 -s "Read from client: 16384 bytes read"
1933
1934run_test "Large packet TLS 1.2 BlockCipher larger MAC" \
1935 "$P_SRV" \
1936 "$P_CLI request_size=16384 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1937 0 \
1938 -s "Read from client: 16384 bytes read"
1939
1940run_test "Large packet TLS 1.2 BlockCipher truncated MAC" \
1941 "$P_SRV" \
1942 "$P_CLI request_size=16384 force_version=tls1_2 \
1943 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1944 trunc_hmac=1" \
1945 0 \
1946 -s "Read from client: 16384 bytes read"
1947
1948run_test "Large packet TLS 1.2 StreamCipher" \
1949 "$P_SRV" \
1950 "$P_CLI request_size=16384 force_version=tls1_2 \
1951 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1952 0 \
1953 -s "Read from client: 16384 bytes read"
1954
1955run_test "Large packet TLS 1.2 StreamCipher truncated MAC" \
1956 "$P_SRV" \
1957 "$P_CLI request_size=16384 force_version=tls1_2 \
1958 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1959 trunc_hmac=1" \
1960 0 \
1961 -s "Read from client: 16384 bytes read"
1962
1963run_test "Large packet TLS 1.2 AEAD" \
1964 "$P_SRV" \
1965 "$P_CLI request_size=16384 force_version=tls1_2 \
1966 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1967 0 \
1968 -s "Read from client: 16384 bytes read"
1969
1970run_test "Large packet TLS 1.2 AEAD shorter tag" \
1971 "$P_SRV" \
1972 "$P_CLI request_size=16384 force_version=tls1_2 \
1973 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
1974 0 \
1975 -s "Read from client: 16384 bytes read"
1976
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001977# Tests for DTLS HelloVerifyRequest
1978
1979run_test "DTLS cookie: enabled" \
1980 "$P_SRV dtls=1 debug_level=2" \
1981 "$P_CLI dtls=1 debug_level=2" \
1982 0 \
1983 -s "cookie verification failed" \
1984 -s "cookie verification passed" \
1985 -S "cookie verification skipped" \
1986 -c "received hello verify request" \
1987 -S "SSL - The requested feature is not available"
1988
1989run_test "DTLS cookie: disabled" \
1990 "$P_SRV dtls=1 debug_level=2 cookies=0" \
1991 "$P_CLI dtls=1 debug_level=2" \
1992 0 \
1993 -S "cookie verification failed" \
1994 -S "cookie verification passed" \
1995 -s "cookie verification skipped" \
1996 -C "received hello verify request" \
1997 -S "SSL - The requested feature is not available"
1998
1999# wait for client having a timeout, or server sending an alert
2000#run_test "DTLS cookie: default (failing)" \
2001# "$P_SRV dtls=1 debug_level=2 cookies=-1" \
2002# "$P_CLI dtls=1 debug_level=2" \
2003# 0 \
2004# -S "cookie verification failed" \
2005# -S "cookie verification passed" \
2006# -S "cookie verification skipped" \
2007# -C "received hello verify request" \
2008# -s "SSL - The requested feature is not available"
2009
2010requires_ipv6
2011run_test "DTLS cookie: enabled, IPv6" \
2012 "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
2013 "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
2014 0 \
2015 -s "cookie verification failed" \
2016 -s "cookie verification passed" \
2017 -S "cookie verification skipped" \
2018 -c "received hello verify request" \
2019 -S "SSL - The requested feature is not available"
2020
Manuel Pégourié-Gonnard502bf302014-08-20 13:12:58 +02002021# Tests for receiving fragmented handshake messages with DTLS
2022
2023requires_gnutls
2024run_test "DTLS reassembly: no fragmentation (gnutls server)" \
2025 "$G_SRV -u --mtu 2048 -a" \
2026 "$P_CLI dtls=1 debug_level=2" \
2027 0 \
2028 -C "found fragmented DTLS handshake message" \
2029 -C "error"
2030
2031requires_gnutls
2032run_test "DTLS reassembly: some fragmentation (gnutls server)" \
2033 "$G_SRV -u --mtu 512" \
2034 "$P_CLI dtls=1 debug_level=2" \
2035 0 \
2036 -c "found fragmented DTLS handshake message" \
2037 -C "error"
2038
2039requires_gnutls
2040run_test "DTLS reassembly: more fragmentation (gnutls server)" \
2041 "$G_SRV -u --mtu 128" \
2042 "$P_CLI dtls=1 debug_level=2" \
2043 0 \
2044 -c "found fragmented DTLS handshake message" \
2045 -C "error"
2046
2047requires_gnutls
2048run_test "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
2049 "$G_SRV -u --mtu 128" \
2050 "$P_CLI dtls=1 nbio=2 debug_level=2" \
2051 0 \
2052 -c "found fragmented DTLS handshake message" \
2053 -C "error"
2054
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002055requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002056run_test "DTLS reassembly: fragmentation, renego (gnutls server)" \
2057 "$G_SRV -u --mtu 256" \
2058 "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
2059 0 \
2060 -c "found fragmented DTLS handshake message" \
2061 -c "client hello, adding renegotiation extension" \
2062 -c "found renegotiation extension" \
2063 -c "=> renegotiate" \
2064 -C "ssl_handshake returned" \
2065 -C "error" \
2066 -s "Extra-header:"
2067
2068requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002069run_test "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
2070 "$G_SRV -u --mtu 256" \
2071 "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
2072 0 \
2073 -c "found fragmented DTLS handshake message" \
2074 -c "client hello, adding renegotiation extension" \
2075 -c "found renegotiation extension" \
2076 -c "=> renegotiate" \
2077 -C "ssl_handshake returned" \
2078 -C "error" \
2079 -s "Extra-header:"
2080
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02002081run_test "DTLS reassembly: no fragmentation (openssl server)" \
2082 "$O_SRV -dtls1 -mtu 2048" \
2083 "$P_CLI dtls=1 debug_level=2" \
2084 0 \
2085 -C "found fragmented DTLS handshake message" \
2086 -C "error"
2087
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02002088run_test "DTLS reassembly: fragmentation (openssl server)" \
2089 "$O_SRV -dtls1 -mtu 256" \
2090 "$P_CLI dtls=1 debug_level=2" \
2091 0 \
2092 -c "found fragmented DTLS handshake message" \
2093 -C "error"
2094
2095run_test "DTLS reassembly: fragmentation (openssl server)" \
2096 "$O_SRV -dtls1 -mtu 256" \
2097 "$P_CLI dtls=1 debug_level=2" \
2098 0 \
2099 -c "found fragmented DTLS handshake message" \
2100 -C "error"
2101
2102run_test "DTLS reassembly: fragmentation, nbio (openssl server)" \
2103 "$O_SRV -dtls1 -mtu 256" \
2104 "$P_CLI dtls=1 nbio=2 debug_level=2" \
2105 0 \
2106 -c "found fragmented DTLS handshake message" \
2107 -C "error"
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02002108
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002109# Tests with UDP proxy emulating unreliable transport
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002110
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002111run_test "DTLS proxy: reference" \
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002112 -p "$P_PXY" \
2113 "$P_SRV dtls=1" \
2114 "$P_CLI dtls=1" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002115 0 \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002116 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002117 -c "HTTP/1.0 200 OK"
2118
2119run_test "DTLS proxy: some duplication" \
2120 -p "$P_PXY duplicate=3" \
2121 "$P_SRV dtls=1" \
2122 "$P_CLI dtls=1" \
2123 0 \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002124 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002125 -c "HTTP/1.0 200 OK"
2126
2127run_test "DTLS proxy: lots of duplication" \
2128 -p "$P_PXY duplicate=1" \
2129 "$P_SRV dtls=1" \
2130 "$P_CLI dtls=1" \
2131 0 \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002132 -s "Extra-header:" \
2133 -c "HTTP/1.0 200 OK"
2134
2135run_test "DTLS proxy: inject invalid AD record" \
2136 -p "$P_PXY bad_ad=1" \
2137 "$P_SRV dtls=1" \
2138 "$P_CLI dtls=1" \
2139 0 \
2140 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002141 -c "HTTP/1.0 200 OK"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002142
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +02002143run_test "DTLS proxy: drop a few packets" \
2144 -p "$P_PXY drop=10" \
2145 "$P_SRV dtls=1" \
2146 "$P_CLI dtls=1" \
2147 0 \
2148 -s "Extra-header:" \
2149 -c "HTTP/1.0 200 OK"
2150
2151needs_more_time 2
2152run_test "DTLS proxy: drop a bit more packets" \
2153 -p "$P_PXY drop=6" \
2154 "$P_SRV dtls=1" \
2155 "$P_CLI dtls=1" \
2156 0 \
2157 -s "Extra-header:" \
2158 -c "HTTP/1.0 200 OK"
2159
2160needs_more_time 3
2161run_test "DTLS proxy: drop more packets" \
2162 -p "$P_PXY drop=3" \
2163 "$P_SRV dtls=1" \
2164 "$P_CLI dtls=1" \
2165 0 \
2166 -s "Extra-header:" \
2167 -c "HTTP/1.0 200 OK"
2168
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002169# Final report
2170
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01002171echo "------------------------------------------------------------------------"
2172
2173if [ $FAILS = 0 ]; then
2174 echo -n "PASSED"
2175else
2176 echo -n "FAILED"
2177fi
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +02002178PASSES=$(( $TESTS - $FAILS ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +02002179echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01002180
2181exit $FAILS