blob: 102a5b50c8971fe83f1da0b94774fb2a0e40408e [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#
9# Assumes all options are compiled in.
10
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010011set -u
12
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +010013# test if it is defined from the environment before assining default
14# if yes, assume it means it's a build with all the options we need (SSLv2)
15if [ -n "${OPENSSL_CMD:-}" ]; then
16 OPENSSL_OK=1
17else
18 OPENSSL_OK=0
19fi
20
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +010021# default values, can be overriden by the environment
22: ${P_SRV:=../programs/ssl/ssl_server2}
23: ${P_CLI:=../programs/ssl/ssl_client2}
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010024: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010025
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010026O_SRV="$OPENSSL_CMD s_server -www -cert data_files/server5.crt -key data_files/server5.key"
27O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_CMD s_client"
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010028
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010029TESTS=0
30FAILS=0
31
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +020032CONFIG_H='../include/polarssl/config.h'
33
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010034MEMCHECK=0
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010035FILTER='.*'
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +010036if [ "$OPENSSL_OK" -gt 0 ]; then
37 EXCLUDE='^$'
38else
39 EXCLUDE='SSLv2'
40fi
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010041
42print_usage() {
43 echo "Usage: $0 [options]"
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010044 echo -e " -h|--help\tPrint this help."
45 echo -e " -m|--memcheck\tCheck memory leaks and errors."
46 echo -e " -f|--filter\tOnly matching tests are executed (default: '$FILTER')"
47 echo -e " -e|--exclude\tMatching tests are excluded (default: '$EXCLUDE')"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010048}
49
50get_options() {
51 while [ $# -gt 0 ]; do
52 case "$1" in
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010053 -f|--filter)
54 shift; FILTER=$1
55 ;;
56 -e|--exclude)
57 shift; EXCLUDE=$1
58 ;;
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010059 -m|--memcheck)
60 MEMCHECK=1
61 ;;
62 -h|--help)
63 print_usage
64 exit 0
65 ;;
66 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +020067 echo "Unknown argument: '$1'"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010068 print_usage
69 exit 1
70 ;;
71 esac
72 shift
73 done
74}
75
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010076# print_name <name>
77print_name() {
78 echo -n "$1 "
79 LEN=`echo "$1" | wc -c`
80 LEN=`echo 72 - $LEN | bc`
81 for i in `seq 1 $LEN`; do echo -n '.'; done
82 echo -n ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010083
84 TESTS=`echo $TESTS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010085}
86
87# fail <message>
88fail() {
89 echo "FAIL"
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +010090 echo " ! $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010091
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +020092 cp $SRV_OUT o-srv-${TESTS}.log
93 cp $CLI_OUT o-cli-${TESTS}.log
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +010094 echo " ! outputs saved to o-srv-${TESTS}.log and o-cli-${TESTS}.log"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010095
96 FAILS=`echo $FAILS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010097}
98
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +010099# is_polar <cmd_line>
100is_polar() {
101 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
102}
103
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100104# has_mem_err <log_file_name>
105has_mem_err() {
106 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
107 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
108 then
109 return 1 # false: does not have errors
110 else
111 return 0 # true: has errors
112 fi
113}
114
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200115# wait for server to start: two versions depending on lsof availability
116wait_server_start() {
117 if which lsof >/dev/null; then
118 # make sure we don't loop forever
119 ( sleep "$DOG_DELAY"; echo "SERVERSTART TIMEOUT"; kill $MAIN_PID ) &
120 WATCHDOG_PID=$!
121
122 # make a tight loop, server usually takes less than 1 sec to start
123 until lsof -nbi TCP:"$PORT" | grep LISTEN >/dev/null; do :; done
124
125 kill $WATCHDOG_PID
126 wait $WATCHDOG_PID
127 else
128 sleep "$START_DELAY"
129 fi
130}
131
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100132# Usage: run_test name srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100133# Options: -s pattern pattern that must be present in server output
134# -c pattern pattern that must be present in client output
135# -S pattern pattern that must be absent in server output
136# -C pattern pattern that must be absent in client output
137run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100138 NAME="$1"
139 SRV_CMD="$2"
140 CLI_CMD="$3"
141 CLI_EXPECT="$4"
142 shift 4
143
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100144 if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
145 else
146 return
147 fi
148
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100149 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100150
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100151 # prepend valgrind to our commands if active
152 if [ "$MEMCHECK" -gt 0 ]; then
153 if is_polar "$SRV_CMD"; then
154 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
155 fi
156 if is_polar "$CLI_CMD"; then
157 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
158 fi
159 fi
160
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100161 # run the commands
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200162 echo "$SRV_CMD" > $SRV_OUT
163 $SRV_CMD >> $SRV_OUT 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100164 SRV_PID=$!
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200165 wait_server_start
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200166 echo "$CLI_CMD" > $CLI_OUT
167 eval "$CLI_CMD" >> $CLI_OUT 2>&1
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100168 CLI_EXIT=$?
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200169 echo "EXIT: $CLI_EXIT" >> $CLI_OUT
Manuel Pégourié-Gonnarde01af4c2014-03-25 14:16:44 +0100170
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100171 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200172 # start watchdog in case SERVERQUIT fails
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200173 ( sleep "$DOG_DELAY"; echo "SERVERQUIT TIMEOUT"; kill $MAIN_PID ) &
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200174 WATCHDOG_PID=$!
175
176 # psk is useful when server only has bad certs
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200177 $P_CLI request_page=SERVERQUIT tickets=0 auth_mode=none psk=abc123 \
Manuel Pégourié-Gonnard84fd6872014-03-13 18:35:10 +0100178 crt_file=data_files/cli2.crt key_file=data_files/cli2.key \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +0200179 >/dev/null 2>&1
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200180
181 wait $SRV_PID
182 kill $WATCHDOG_PID
183 wait $WATCHDOG_PID
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100184 else
185 kill $SRV_PID
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200186 wait $SRV_PID
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100187 fi
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100188
189 # check if the client and server went at least to the handshake stage
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200190 # (useful to avoid tests with only negative assertions and non-zero
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100191 # expected client exit to incorrectly succeed in case of catastrophic
192 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100193 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200194 if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100195 else
196 fail "server failed to start"
197 return
198 fi
199 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100200 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200201 if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100202 else
203 fail "client failed to start"
204 return
205 fi
206 fi
207
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100208 # check server exit code
209 if [ $? != 0 ]; then
210 fail "server fail"
211 return
212 fi
213
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100214 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100215 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
216 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100217 then
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100218 fail "bad client exit code"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100219 return
220 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100221
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100222 # check other assertions
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100223 while [ $# -gt 0 ]
224 do
225 case $1 in
226 "-s")
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200227 if grep "$2" $SRV_OUT >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100228 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100229 return
230 fi
231 ;;
232
233 "-c")
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200234 if grep "$2" $CLI_OUT >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100235 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100236 return
237 fi
238 ;;
239
240 "-S")
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200241 if grep "$2" $SRV_OUT >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100242 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100243 return
244 fi
245 ;;
246
247 "-C")
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200248 if grep "$2" $CLI_OUT >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100249 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100250 return
251 fi
252 ;;
253
254 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200255 echo "Unknown test: $1" >&2
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100256 exit 1
257 esac
258 shift 2
259 done
260
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100261 # check valgrind's results
262 if [ "$MEMCHECK" -gt 0 ]; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200263 if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100264 fail "Server has memory errors"
265 return
266 fi
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200267 if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100268 fail "Client has memory errors"
269 return
270 fi
271 fi
272
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100273 # if we're here, everything is ok
274 echo "PASS"
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200275 rm -f $SRV_OUT $CLI_OUT
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100276}
277
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100278cleanup() {
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200279 rm -f $CLI_OUT $SRV_OUT $SESSION
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200280 kill $SRV_PID >/dev/null 2>&1
281 kill $WATCHDOG_PID >/dev/null 2>&1
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100282 exit 1
283}
284
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100285#
286# MAIN
287#
288
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100289get_options "$@"
290
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100291# sanity checks, avoid an avalanche of errors
292if [ ! -x "$P_SRV" ]; then
293 echo "Command '$P_SRV' is not an executable file"
294 exit 1
295fi
296if [ ! -x "$P_CLI" ]; then
297 echo "Command '$P_CLI' is not an executable file"
298 exit 1
299fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100300if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
301 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100302 exit 1
303fi
304
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200305# used by watchdog
306MAIN_PID="$$"
307
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200308# be more patient with valgrind
309if [ "$MEMCHECK" -gt 0 ]; then
310 START_DELAY=3
311 DOG_DELAY=30
312else
313 START_DELAY=1
314 DOG_DELAY=10
315fi
316
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200317# Pick a "unique" port in the range 10000-19999.
318PORT="0000$$"
Manuel Pégourié-Gonnardfab2a3c2014-06-16 16:54:36 +0200319PORT="1$(echo $PORT | tail -c 5)"
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200320
321# fix commands to use this port
322P_SRV="$P_SRV server_port=$PORT"
323P_CLI="$P_CLI server_port=$PORT"
324O_SRV="$O_SRV -accept $PORT"
325O_CLI="$O_CLI -connect localhost:$PORT"
326
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200327# Also pick a unique name for intermediate files
328SRV_OUT="srv_out.$$"
329CLI_OUT="cli_out.$$"
330SESSION="session.$$"
331
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100332trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100333
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100334# Test for SSLv2 ClientHello
335
336run_test "SSLv2 ClientHello #0 (reference)" \
337 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100338 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100339 0 \
340 -S "parse client hello v2" \
341 -S "ssl_handshake returned"
342
343# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
344run_test "SSLv2 ClientHello #1 (actual test)" \
345 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100346 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100347 0 \
348 -s "parse client hello v2" \
349 -S "ssl_handshake returned"
350
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100351# Tests for Truncated HMAC extension
352
353run_test "Truncated HMAC #0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100354 "$P_SRV debug_level=5" \
355 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100356 0 \
357 -s "dumping 'computed mac' (20 bytes)"
358
359run_test "Truncated HMAC #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100360 "$P_SRV debug_level=5" \
361 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100362 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100363 -s "dumping 'computed mac' (10 bytes)"
364
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100365# Tests for Session Tickets
366
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100367run_test "Session resume using tickets #1 (basic)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100368 "$P_SRV debug_level=4 tickets=1" \
369 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100370 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100371 -c "client hello, adding session ticket extension" \
372 -s "found session ticket extension" \
373 -s "server hello, adding session ticket extension" \
374 -c "found session_ticket extension" \
375 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100376 -S "session successfully restored from cache" \
377 -s "session successfully restored from ticket" \
378 -s "a session has been resumed" \
379 -c "a session has been resumed"
380
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100381run_test "Session resume using tickets #2 (cache disabled)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100382 "$P_SRV debug_level=4 tickets=1 cache_max=0" \
383 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100384 0 \
385 -c "client hello, adding session ticket extension" \
386 -s "found session ticket extension" \
387 -s "server hello, adding session ticket extension" \
388 -c "found session_ticket extension" \
389 -c "parse new session ticket" \
390 -S "session successfully restored from cache" \
391 -s "session successfully restored from ticket" \
392 -s "a session has been resumed" \
393 -c "a session has been resumed"
394
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100395run_test "Session resume using tickets #3 (timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100396 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=1" \
397 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100398 0 \
399 -c "client hello, adding session ticket extension" \
400 -s "found session ticket extension" \
401 -s "server hello, adding session ticket extension" \
402 -c "found session_ticket extension" \
403 -c "parse new session ticket" \
404 -S "session successfully restored from cache" \
405 -S "session successfully restored from ticket" \
406 -S "a session has been resumed" \
407 -C "a session has been resumed"
408
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100409run_test "Session resume using tickets #4 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100410 "$O_SRV" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100411 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
412 0 \
413 -c "client hello, adding session ticket extension" \
414 -c "found session_ticket extension" \
415 -c "parse new session ticket" \
416 -c "a session has been resumed"
417
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100418run_test "Session resume using tickets #5 (openssl client)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100419 "$P_SRV debug_level=4 tickets=1" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200420 "( $O_CLI -sess_out $SESSION; \
421 $O_CLI -sess_in $SESSION; \
422 rm -f $SESSION )" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100423 0 \
424 -s "found session ticket extension" \
425 -s "server hello, adding session ticket extension" \
426 -S "session successfully restored from cache" \
427 -s "session successfully restored from ticket" \
428 -s "a session has been resumed"
429
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100430# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100431
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100432run_test "Session resume using cache #1 (tickets enabled on client)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100433 "$P_SRV debug_level=4 tickets=0" \
434 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100435 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100436 -c "client hello, adding session ticket extension" \
437 -s "found session ticket extension" \
438 -S "server hello, adding session ticket extension" \
439 -C "found session_ticket extension" \
440 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100441 -s "session successfully restored from cache" \
442 -S "session successfully restored from ticket" \
443 -s "a session has been resumed" \
444 -c "a session has been resumed"
445
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100446run_test "Session resume using cache #2 (tickets enabled on server)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100447 "$P_SRV debug_level=4 tickets=1" \
448 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100449 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100450 -C "client hello, adding session ticket extension" \
451 -S "found session ticket extension" \
452 -S "server hello, adding session ticket extension" \
453 -C "found session_ticket extension" \
454 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100455 -s "session successfully restored from cache" \
456 -S "session successfully restored from ticket" \
457 -s "a session has been resumed" \
458 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100459
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100460run_test "Session resume using cache #3 (cache_max=0)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100461 "$P_SRV debug_level=4 tickets=0 cache_max=0" \
462 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100463 0 \
464 -S "session successfully restored from cache" \
465 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100466 -S "a session has been resumed" \
467 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100468
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100469run_test "Session resume using cache #4 (cache_max=1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100470 "$P_SRV debug_level=4 tickets=0 cache_max=1" \
471 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100472 0 \
473 -s "session successfully restored from cache" \
474 -S "session successfully restored from ticket" \
475 -s "a session has been resumed" \
476 -c "a session has been resumed"
477
478run_test "Session resume using cache #5 (timemout > delay)" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100479 "$P_SRV debug_level=4 tickets=0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100480 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100481 0 \
482 -s "session successfully restored from cache" \
483 -S "session successfully restored from ticket" \
484 -s "a session has been resumed" \
485 -c "a session has been resumed"
486
487run_test "Session resume using cache #6 (timeout < delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100488 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
489 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100490 0 \
491 -S "session successfully restored from cache" \
492 -S "session successfully restored from ticket" \
493 -S "a session has been resumed" \
494 -C "a session has been resumed"
495
496run_test "Session resume using cache #7 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100497 "$P_SRV debug_level=4 tickets=0 cache_timeout=0" \
498 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100499 0 \
500 -s "session successfully restored from cache" \
501 -S "session successfully restored from ticket" \
502 -s "a session has been resumed" \
503 -c "a session has been resumed"
504
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100505run_test "Session resume using cache #8 (openssl client)" \
506 "$P_SRV debug_level=4 tickets=0" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200507 "( $O_CLI -sess_out $SESSION; \
508 $O_CLI -sess_in $SESSION; \
509 rm -f $SESSION )" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100510 0 \
511 -s "found session ticket extension" \
512 -S "server hello, adding session ticket extension" \
513 -s "session successfully restored from cache" \
514 -S "session successfully restored from ticket" \
515 -s "a session has been resumed"
516
517run_test "Session resume using cache #9 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100518 "$O_SRV" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100519 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
520 0 \
521 -C "found session_ticket extension" \
522 -C "parse new session ticket" \
523 -c "a session has been resumed"
524
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100525# Tests for Max Fragment Length extension
526
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100527run_test "Max fragment length #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100528 "$P_SRV debug_level=4" \
529 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100530 0 \
531 -C "client hello, adding max_fragment_length extension" \
532 -S "found max fragment length extension" \
533 -S "server hello, max_fragment_length extension" \
534 -C "found max_fragment_length extension"
535
536run_test "Max fragment length #2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100537 "$P_SRV debug_level=4" \
538 "$P_CLI debug_level=4 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100539 0 \
540 -c "client hello, adding max_fragment_length extension" \
541 -s "found max fragment length extension" \
542 -s "server hello, max_fragment_length extension" \
543 -c "found max_fragment_length extension"
544
545run_test "Max fragment length #3" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100546 "$P_SRV debug_level=4 max_frag_len=4096" \
547 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100548 0 \
549 -C "client hello, adding max_fragment_length extension" \
550 -S "found max fragment length extension" \
551 -S "server hello, max_fragment_length extension" \
552 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100553
554# Tests for renegotiation
555
556run_test "Renegotiation #0 (none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100557 "$P_SRV debug_level=4" \
558 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100559 0 \
560 -C "client hello, adding renegotiation extension" \
561 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
562 -S "found renegotiation extension" \
563 -s "server hello, secure renegotiation extension" \
564 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100565 -C "=> renegotiate" \
566 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100567 -S "write hello request"
568
569run_test "Renegotiation #1 (enabled, client-initiated)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200570 "$P_SRV debug_level=4 renegotiation=1" \
571 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100572 0 \
573 -c "client hello, adding renegotiation extension" \
574 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
575 -s "found renegotiation extension" \
576 -s "server hello, secure renegotiation extension" \
577 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100578 -c "=> renegotiate" \
579 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100580 -S "write hello request"
581
582run_test "Renegotiation #2 (enabled, server-initiated)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200583 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
584 "$P_CLI debug_level=4 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100585 0 \
586 -c "client hello, adding renegotiation extension" \
587 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
588 -s "found renegotiation extension" \
589 -s "server hello, secure renegotiation extension" \
590 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100591 -c "=> renegotiate" \
592 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100593 -s "write hello request"
594
595run_test "Renegotiation #3 (enabled, double)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200596 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
597 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100598 0 \
599 -c "client hello, adding renegotiation extension" \
600 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
601 -s "found renegotiation extension" \
602 -s "server hello, secure renegotiation extension" \
603 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100604 -c "=> renegotiate" \
605 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100606 -s "write hello request"
607
608run_test "Renegotiation #4 (client-initiated, server-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100609 "$P_SRV debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200610 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100611 1 \
612 -c "client hello, adding renegotiation extension" \
613 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
614 -S "found renegotiation extension" \
615 -s "server hello, secure renegotiation extension" \
616 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100617 -c "=> renegotiate" \
618 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100619 -S "write hello request"
620
621run_test "Renegotiation #5 (server-initiated, client-rejected)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200622 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100623 "$P_CLI debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100624 0 \
625 -C "client hello, adding renegotiation extension" \
626 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
627 -S "found renegotiation extension" \
628 -s "server hello, secure renegotiation extension" \
629 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100630 -C "=> renegotiate" \
631 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100632 -s "write hello request" \
633 -s "SSL - An unexpected message was received from our peer" \
634 -s "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100635
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100636# Tests for auth_mode
637
638run_test "Authentication #1 (server badcert, client required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100639 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100640 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100641 "$P_CLI debug_level=2 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100642 1 \
643 -c "x509_verify_cert() returned" \
644 -c "! self-signed or not signed by a trusted CA" \
645 -c "! ssl_handshake returned" \
646 -c "X509 - Certificate verification failed"
647
648run_test "Authentication #2 (server badcert, client optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100649 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100650 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100651 "$P_CLI debug_level=2 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100652 0 \
653 -c "x509_verify_cert() returned" \
654 -c "! self-signed or not signed by a trusted CA" \
655 -C "! ssl_handshake returned" \
656 -C "X509 - Certificate verification failed"
657
658run_test "Authentication #3 (server badcert, client none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100659 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100660 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100661 "$P_CLI debug_level=2 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100662 0 \
663 -C "x509_verify_cert() returned" \
664 -C "! self-signed or not signed by a trusted CA" \
665 -C "! ssl_handshake returned" \
666 -C "X509 - Certificate verification failed"
667
668run_test "Authentication #4 (client badcert, server required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100669 "$P_SRV debug_level=4 auth_mode=required" \
670 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100671 key_file=data_files/server5.key" \
672 1 \
673 -S "skip write certificate request" \
674 -C "skip parse certificate request" \
675 -c "got a certificate request" \
676 -C "skip write certificate" \
677 -C "skip write certificate verify" \
678 -S "skip parse certificate verify" \
679 -s "x509_verify_cert() returned" \
680 -S "! self-signed or not signed by a trusted CA" \
681 -s "! ssl_handshake returned" \
682 -c "! ssl_handshake returned" \
683 -s "X509 - Certificate verification failed"
684
685run_test "Authentication #5 (client badcert, server optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100686 "$P_SRV debug_level=4 auth_mode=optional" \
687 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100688 key_file=data_files/server5.key" \
689 0 \
690 -S "skip write certificate request" \
691 -C "skip parse certificate request" \
692 -c "got a certificate request" \
693 -C "skip write certificate" \
694 -C "skip write certificate verify" \
695 -S "skip parse certificate verify" \
696 -s "x509_verify_cert() returned" \
697 -s "! self-signed or not signed by a trusted CA" \
698 -S "! ssl_handshake returned" \
699 -C "! ssl_handshake returned" \
700 -S "X509 - Certificate verification failed"
701
702run_test "Authentication #6 (client badcert, server none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100703 "$P_SRV debug_level=4 auth_mode=none" \
704 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100705 key_file=data_files/server5.key" \
706 0 \
707 -s "skip write certificate request" \
708 -C "skip parse certificate request" \
709 -c "got no certificate request" \
710 -c "skip write certificate" \
711 -c "skip write certificate verify" \
712 -s "skip parse certificate verify" \
713 -S "x509_verify_cert() returned" \
714 -S "! self-signed or not signed by a trusted CA" \
715 -S "! ssl_handshake returned" \
716 -C "! ssl_handshake returned" \
717 -S "X509 - Certificate verification failed"
718
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +0100719run_test "Authentication #7 (client no cert, server optional)" \
720 "$P_SRV debug_level=4 auth_mode=optional" \
721 "$P_CLI debug_level=4 crt_file=none key_file=none" \
722 0 \
723 -S "skip write certificate request" \
724 -C "skip parse certificate request" \
725 -c "got a certificate request" \
726 -C "skip write certificate$" \
727 -C "got no certificate to send" \
728 -S "SSLv3 client has no certificate" \
729 -c "skip write certificate verify" \
730 -s "skip parse certificate verify" \
731 -s "! no client certificate sent" \
732 -S "! ssl_handshake returned" \
733 -C "! ssl_handshake returned" \
734 -S "X509 - Certificate verification failed"
735
736run_test "Authentication #8 (openssl client no cert, server optional)" \
737 "$P_SRV debug_level=4 auth_mode=optional" \
738 "$O_CLI" \
739 0 \
740 -S "skip write certificate request" \
741 -s "skip parse certificate verify" \
742 -s "! no client certificate sent" \
743 -S "! ssl_handshake returned" \
744 -S "X509 - Certificate verification failed"
745
746run_test "Authentication #9 (client no cert, openssl server optional)" \
747 "$O_SRV -verify 10" \
748 "$P_CLI debug_level=4 crt_file=none key_file=none" \
749 0 \
750 -C "skip parse certificate request" \
751 -c "got a certificate request" \
752 -C "skip write certificate$" \
753 -c "skip write certificate verify" \
754 -C "! ssl_handshake returned"
755
756run_test "Authentication #10 (client no cert, ssl3)" \
757 "$P_SRV debug_level=4 auth_mode=optional force_version=ssl3" \
758 "$P_CLI debug_level=4 crt_file=none key_file=none" \
759 0 \
760 -S "skip write certificate request" \
761 -C "skip parse certificate request" \
762 -c "got a certificate request" \
763 -C "skip write certificate$" \
764 -c "skip write certificate verify" \
765 -c "got no certificate to send" \
766 -s "SSLv3 client has no certificate" \
767 -s "skip parse certificate verify" \
768 -s "! no client certificate sent" \
769 -S "! ssl_handshake returned" \
770 -C "! ssl_handshake returned" \
771 -S "X509 - Certificate verification failed"
772
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100773# tests for SNI
774
775run_test "SNI #0 (no SNI callback)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100776 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100777 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100778 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100779 server_name=localhost" \
780 0 \
781 -S "parse ServerName extension" \
782 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
783 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
784
785run_test "SNI #1 (matching cert 1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100786 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100787 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100788 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100789 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100790 server_name=localhost" \
791 0 \
792 -s "parse ServerName extension" \
793 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
794 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
795
796run_test "SNI #2 (matching cert 2)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100797 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100798 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100799 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100800 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100801 server_name=polarssl.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100802 0 \
803 -s "parse ServerName extension" \
804 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100805 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100806
807run_test "SNI #3 (no matching cert)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100808 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100809 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100810 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100811 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100812 server_name=nonesuch.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100813 1 \
814 -s "parse ServerName extension" \
815 -s "ssl_sni_wrapper() returned" \
816 -s "ssl_handshake returned" \
817 -c "ssl_handshake returned" \
818 -c "SSL - A fatal alert message was received from our peer"
819
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +0100820# Tests for non-blocking I/O: exercise a variety of handshake flows
821
822run_test "Non-blocking I/O #1 (basic handshake)" \
823 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
824 "$P_CLI nbio=2 tickets=0" \
825 0 \
826 -S "ssl_handshake returned" \
827 -C "ssl_handshake returned" \
828 -c "Read from server: .* bytes read"
829
830run_test "Non-blocking I/O #2 (client auth)" \
831 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
832 "$P_CLI nbio=2 tickets=0" \
833 0 \
834 -S "ssl_handshake returned" \
835 -C "ssl_handshake returned" \
836 -c "Read from server: .* bytes read"
837
838run_test "Non-blocking I/O #3 (ticket)" \
839 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
840 "$P_CLI nbio=2 tickets=1" \
841 0 \
842 -S "ssl_handshake returned" \
843 -C "ssl_handshake returned" \
844 -c "Read from server: .* bytes read"
845
846run_test "Non-blocking I/O #4 (ticket + client auth)" \
847 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
848 "$P_CLI nbio=2 tickets=1" \
849 0 \
850 -S "ssl_handshake returned" \
851 -C "ssl_handshake returned" \
852 -c "Read from server: .* bytes read"
853
854run_test "Non-blocking I/O #5 (ticket + client auth + resume)" \
855 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
856 "$P_CLI nbio=2 tickets=1 reconnect=1" \
857 0 \
858 -S "ssl_handshake returned" \
859 -C "ssl_handshake returned" \
860 -c "Read from server: .* bytes read"
861
862run_test "Non-blocking I/O #6 (ticket + resume)" \
863 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
864 "$P_CLI nbio=2 tickets=1 reconnect=1" \
865 0 \
866 -S "ssl_handshake returned" \
867 -C "ssl_handshake returned" \
868 -c "Read from server: .* bytes read"
869
870run_test "Non-blocking I/O #7 (session-id resume)" \
871 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
872 "$P_CLI nbio=2 tickets=0 reconnect=1" \
873 0 \
874 -S "ssl_handshake returned" \
875 -C "ssl_handshake returned" \
876 -c "Read from server: .* bytes read"
877
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200878# Tests for version negotiation
879
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100880run_test "Version check #1 (all -> 1.2)" \
881 "$P_SRV" \
882 "$P_CLI" \
883 0 \
884 -S "ssl_handshake returned" \
885 -C "ssl_handshake returned" \
886 -s "Protocol is TLSv1.2" \
887 -c "Protocol is TLSv1.2"
888
889run_test "Version check #2 (cli max 1.1 -> 1.1)" \
890 "$P_SRV" \
891 "$P_CLI max_version=tls1_1" \
892 0 \
893 -S "ssl_handshake returned" \
894 -C "ssl_handshake returned" \
895 -s "Protocol is TLSv1.1" \
896 -c "Protocol is TLSv1.1"
897
898run_test "Version check #3 (srv max 1.1 -> 1.1)" \
899 "$P_SRV max_version=tls1_1" \
900 "$P_CLI" \
901 0 \
902 -S "ssl_handshake returned" \
903 -C "ssl_handshake returned" \
904 -s "Protocol is TLSv1.1" \
905 -c "Protocol is TLSv1.1"
906
907run_test "Version check #4 (cli+srv max 1.1 -> 1.1)" \
908 "$P_SRV max_version=tls1_1" \
909 "$P_CLI max_version=tls1_1" \
910 0 \
911 -S "ssl_handshake returned" \
912 -C "ssl_handshake returned" \
913 -s "Protocol is TLSv1.1" \
914 -c "Protocol is TLSv1.1"
915
916run_test "Version check #5 (cli max 1.1, srv min 1.1 -> 1.1)" \
917 "$P_SRV min_version=tls1_1" \
918 "$P_CLI max_version=tls1_1" \
919 0 \
920 -S "ssl_handshake returned" \
921 -C "ssl_handshake returned" \
922 -s "Protocol is TLSv1.1" \
923 -c "Protocol is TLSv1.1"
924
925run_test "Version check #6 (cli min 1.1, srv max 1.1 -> 1.1)" \
926 "$P_SRV max_version=tls1_1" \
927 "$P_CLI min_version=tls1_1" \
928 0 \
929 -S "ssl_handshake returned" \
930 -C "ssl_handshake returned" \
931 -s "Protocol is TLSv1.1" \
932 -c "Protocol is TLSv1.1"
933
934run_test "Version check #7 (cli min 1.2, srv max 1.1 -> fail)" \
935 "$P_SRV max_version=tls1_1" \
936 "$P_CLI min_version=tls1_2" \
937 1 \
938 -s "ssl_handshake returned" \
939 -c "ssl_handshake returned" \
940 -c "SSL - Handshake protocol not within min/max boundaries"
941
942run_test "Version check #8 (srv min 1.2, cli max 1.1 -> fail)" \
943 "$P_SRV min_version=tls1_2" \
944 "$P_CLI max_version=tls1_1" \
945 1 \
946 -s "ssl_handshake returned" \
947 -c "ssl_handshake returned" \
948 -s "SSL - Handshake protocol not within min/max boundaries"
949
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200950# Tests for ALPN extension
951
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +0200952if grep '^#define POLARSSL_SSL_ALPN' $CONFIG_H >/dev/null; then
953
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200954run_test "ALPN #0 (none)" \
955 "$P_SRV debug_level=4" \
956 "$P_CLI debug_level=4" \
957 0 \
958 -C "client hello, adding alpn extension" \
959 -S "found alpn extension" \
960 -C "got an alert message, type: \\[2:120]" \
961 -S "server hello, adding alpn extension" \
962 -C "found alpn extension " \
963 -C "Application Layer Protocol is" \
964 -S "Application Layer Protocol is"
965
966run_test "ALPN #1 (client only)" \
967 "$P_SRV debug_level=4" \
968 "$P_CLI debug_level=4 alpn=abc,1234" \
969 0 \
970 -c "client hello, adding alpn extension" \
971 -s "found alpn extension" \
972 -C "got an alert message, type: \\[2:120]" \
973 -S "server hello, adding alpn extension" \
974 -C "found alpn extension " \
975 -c "Application Layer Protocol is (none)" \
976 -S "Application Layer Protocol is"
977
978run_test "ALPN #2 (server only)" \
979 "$P_SRV debug_level=4 alpn=abc,1234" \
980 "$P_CLI debug_level=4" \
981 0 \
982 -C "client hello, adding alpn extension" \
983 -S "found alpn extension" \
984 -C "got an alert message, type: \\[2:120]" \
985 -S "server hello, adding alpn extension" \
986 -C "found alpn extension " \
987 -C "Application Layer Protocol is" \
988 -s "Application Layer Protocol is (none)"
989
990run_test "ALPN #3 (both, common cli1-srv1)" \
991 "$P_SRV debug_level=4 alpn=abc,1234" \
992 "$P_CLI debug_level=4 alpn=abc,1234" \
993 0 \
994 -c "client hello, adding alpn extension" \
995 -s "found alpn extension" \
996 -C "got an alert message, type: \\[2:120]" \
997 -s "server hello, adding alpn extension" \
998 -c "found alpn extension" \
999 -c "Application Layer Protocol is abc" \
1000 -s "Application Layer Protocol is abc"
1001
1002run_test "ALPN #4 (both, common cli2-srv1)" \
1003 "$P_SRV debug_level=4 alpn=abc,1234" \
1004 "$P_CLI debug_level=4 alpn=1234,abc" \
1005 0 \
1006 -c "client hello, adding alpn extension" \
1007 -s "found alpn extension" \
1008 -C "got an alert message, type: \\[2:120]" \
1009 -s "server hello, adding alpn extension" \
1010 -c "found alpn extension" \
1011 -c "Application Layer Protocol is abc" \
1012 -s "Application Layer Protocol is abc"
1013
1014run_test "ALPN #5 (both, common cli1-srv2)" \
1015 "$P_SRV debug_level=4 alpn=abc,1234" \
1016 "$P_CLI debug_level=4 alpn=1234,abcde" \
1017 0 \
1018 -c "client hello, adding alpn extension" \
1019 -s "found alpn extension" \
1020 -C "got an alert message, type: \\[2:120]" \
1021 -s "server hello, adding alpn extension" \
1022 -c "found alpn extension" \
1023 -c "Application Layer Protocol is 1234" \
1024 -s "Application Layer Protocol is 1234"
1025
1026run_test "ALPN #6 (both, no common)" \
1027 "$P_SRV debug_level=4 alpn=abc,123" \
1028 "$P_CLI debug_level=4 alpn=1234,abcde" \
1029 1 \
1030 -c "client hello, adding alpn extension" \
1031 -s "found alpn extension" \
1032 -c "got an alert message, type: \\[2:120]" \
1033 -S "server hello, adding alpn extension" \
1034 -C "found alpn extension" \
1035 -C "Application Layer Protocol is 1234" \
1036 -S "Application Layer Protocol is 1234"
1037
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02001038fi
1039
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001040# Tests for keyUsage in leaf certificates, part 1:
1041# server-side certificate/suite selection
1042
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02001043run_test "keyUsage srv #1 (RSA, digitalSignature -> (EC)DHE-RSA)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001044 "$P_SRV key_file=data_files/server2.key \
1045 crt_file=data_files/server2.ku-ds.crt" \
1046 "$P_CLI" \
1047 0 \
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02001048 -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001049
1050
1051run_test "keyUsage srv #2 (RSA, keyEncipherment -> RSA)" \
1052 "$P_SRV key_file=data_files/server2.key \
1053 crt_file=data_files/server2.ku-ke.crt" \
1054 "$P_CLI" \
1055 0 \
1056 -c "Ciphersuite is TLS-RSA-WITH-"
1057
1058# add psk to leave an option for client to send SERVERQUIT
1059run_test "keyUsage srv #3 (RSA, keyAgreement -> fail)" \
1060 "$P_SRV psk=abc123 key_file=data_files/server2.key \
1061 crt_file=data_files/server2.ku-ka.crt" \
1062 "$P_CLI psk=badbad" \
1063 1 \
1064 -C "Ciphersuite is "
1065
1066run_test "keyUsage srv #4 (ECDSA, digitalSignature -> ECDHE-ECDSA)" \
1067 "$P_SRV key_file=data_files/server5.key \
1068 crt_file=data_files/server5.ku-ds.crt" \
1069 "$P_CLI" \
1070 0 \
1071 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
1072
1073
1074run_test "keyUsage srv #5 (ECDSA, keyAgreement -> ECDH-)" \
1075 "$P_SRV key_file=data_files/server5.key \
1076 crt_file=data_files/server5.ku-ka.crt" \
1077 "$P_CLI" \
1078 0 \
1079 -c "Ciphersuite is TLS-ECDH-"
1080
1081# add psk to leave an option for client to send SERVERQUIT
1082run_test "keyUsage srv #6 (ECDSA, keyEncipherment -> fail)" \
1083 "$P_SRV psk=abc123 key_file=data_files/server5.key \
1084 crt_file=data_files/server5.ku-ke.crt" \
1085 "$P_CLI psk=badbad" \
1086 1 \
1087 -C "Ciphersuite is "
1088
1089# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001090# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001091
1092run_test "keyUsage cli #1 (DigitalSignature+KeyEncipherment, RSA: OK)" \
1093 "$O_SRV -key data_files/server2.key \
1094 -cert data_files/server2.ku-ds_ke.crt" \
1095 "$P_CLI debug_level=2 \
1096 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1097 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001098 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001099 -C "Processing of the Certificate handshake message failed" \
1100 -c "Ciphersuite is TLS-"
1101
1102run_test "keyUsage cli #2 (DigitalSignature+KeyEncipherment, DHE-RSA: OK)" \
1103 "$O_SRV -key data_files/server2.key \
1104 -cert data_files/server2.ku-ds_ke.crt" \
1105 "$P_CLI debug_level=2 \
1106 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1107 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001108 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001109 -C "Processing of the Certificate handshake message failed" \
1110 -c "Ciphersuite is TLS-"
1111
1112run_test "keyUsage cli #3 (KeyEncipherment, RSA: OK)" \
1113 "$O_SRV -key data_files/server2.key \
1114 -cert data_files/server2.ku-ke.crt" \
1115 "$P_CLI debug_level=2 \
1116 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1117 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001118 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001119 -C "Processing of the Certificate handshake message failed" \
1120 -c "Ciphersuite is TLS-"
1121
1122run_test "keyUsage cli #4 (KeyEncipherment, DHE-RSA: fail)" \
1123 "$O_SRV -key data_files/server2.key \
1124 -cert data_files/server2.ku-ke.crt" \
1125 "$P_CLI debug_level=2 \
1126 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1127 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001128 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001129 -c "Processing of the Certificate handshake message failed" \
1130 -C "Ciphersuite is TLS-"
1131
1132run_test "keyUsage cli #5 (DigitalSignature, DHE-RSA: OK)" \
1133 "$O_SRV -key data_files/server2.key \
1134 -cert data_files/server2.ku-ds.crt" \
1135 "$P_CLI debug_level=2 \
1136 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1137 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001138 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001139 -C "Processing of the Certificate handshake message failed" \
1140 -c "Ciphersuite is TLS-"
1141
1142run_test "keyUsage cli #5 (DigitalSignature, RSA: fail)" \
1143 "$O_SRV -key data_files/server2.key \
1144 -cert data_files/server2.ku-ds.crt" \
1145 "$P_CLI debug_level=2 \
1146 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1147 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001148 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001149 -c "Processing of the Certificate handshake message failed" \
1150 -C "Ciphersuite is TLS-"
1151
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001152# Tests for keyUsage in leaf certificates, part 3:
1153# server-side checking of client cert
1154
1155run_test "keyUsage cli-auth #1 (RSA, DigitalSignature: OK)" \
1156 "$P_SRV debug_level=2 auth_mode=optional" \
1157 "$O_CLI -key data_files/server2.key \
1158 -cert data_files/server2.ku-ds.crt" \
1159 0 \
1160 -S "bad certificate (usage extensions)" \
1161 -S "Processing of the Certificate handshake message failed"
1162
1163run_test "keyUsage cli-auth #2 (RSA, KeyEncipherment: fail (soft))" \
1164 "$P_SRV debug_level=2 auth_mode=optional" \
1165 "$O_CLI -key data_files/server2.key \
1166 -cert data_files/server2.ku-ke.crt" \
1167 0 \
1168 -s "bad certificate (usage extensions)" \
1169 -S "Processing of the Certificate handshake message failed"
1170
1171run_test "keyUsage cli-auth #3 (RSA, KeyEncipherment: fail (hard))" \
1172 "$P_SRV debug_level=2 auth_mode=required" \
1173 "$O_CLI -key data_files/server2.key \
1174 -cert data_files/server2.ku-ke.crt" \
1175 1 \
1176 -s "bad certificate (usage extensions)" \
1177 -s "Processing of the Certificate handshake message failed"
1178
1179run_test "keyUsage cli-auth #4 (ECDSA, DigitalSignature: OK)" \
1180 "$P_SRV debug_level=2 auth_mode=optional" \
1181 "$O_CLI -key data_files/server5.key \
1182 -cert data_files/server5.ku-ds.crt" \
1183 0 \
1184 -S "bad certificate (usage extensions)" \
1185 -S "Processing of the Certificate handshake message failed"
1186
1187run_test "keyUsage cli-auth #5 (ECDSA, KeyAgreement: fail (soft))" \
1188 "$P_SRV debug_level=2 auth_mode=optional" \
1189 "$O_CLI -key data_files/server5.key \
1190 -cert data_files/server5.ku-ka.crt" \
1191 0 \
1192 -s "bad certificate (usage extensions)" \
1193 -S "Processing of the Certificate handshake message failed"
1194
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001195# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
1196
1197run_test "extKeyUsage srv #1 (serverAuth -> OK)" \
1198 "$P_SRV key_file=data_files/server5.key \
1199 crt_file=data_files/server5.eku-srv.crt" \
1200 "$P_CLI" \
1201 0
1202
1203run_test "extKeyUsage srv #2 (serverAuth,clientAuth -> OK)" \
1204 "$P_SRV key_file=data_files/server5.key \
1205 crt_file=data_files/server5.eku-srv.crt" \
1206 "$P_CLI" \
1207 0
1208
1209run_test "extKeyUsage srv #3 (codeSign,anyEKU -> OK)" \
1210 "$P_SRV key_file=data_files/server5.key \
1211 crt_file=data_files/server5.eku-cs_any.crt" \
1212 "$P_CLI" \
1213 0
1214
1215# add psk to leave an option for client to send SERVERQUIT
1216run_test "extKeyUsage srv #4 (codeSign -> fail)" \
1217 "$P_SRV psk=abc123 key_file=data_files/server5.key \
1218 crt_file=data_files/server5.eku-cli.crt" \
1219 "$P_CLI psk=badbad" \
1220 1
1221
1222# Tests for extendedKeyUsage, part 2: client-side checking of server cert
1223
1224run_test "extKeyUsage cli #1 (serverAuth -> OK)" \
1225 "$O_SRV -key data_files/server5.key \
1226 -cert data_files/server5.eku-srv.crt" \
1227 "$P_CLI debug_level=2" \
1228 0 \
1229 -C "bad certificate (usage extensions)" \
1230 -C "Processing of the Certificate handshake message failed" \
1231 -c "Ciphersuite is TLS-"
1232
1233run_test "extKeyUsage cli #2 (serverAuth,clientAuth -> OK)" \
1234 "$O_SRV -key data_files/server5.key \
1235 -cert data_files/server5.eku-srv_cli.crt" \
1236 "$P_CLI debug_level=2" \
1237 0 \
1238 -C "bad certificate (usage extensions)" \
1239 -C "Processing of the Certificate handshake message failed" \
1240 -c "Ciphersuite is TLS-"
1241
1242run_test "extKeyUsage cli #3 (codeSign,anyEKU -> OK)" \
1243 "$O_SRV -key data_files/server5.key \
1244 -cert data_files/server5.eku-cs_any.crt" \
1245 "$P_CLI debug_level=2" \
1246 0 \
1247 -C "bad certificate (usage extensions)" \
1248 -C "Processing of the Certificate handshake message failed" \
1249 -c "Ciphersuite is TLS-"
1250
1251run_test "extKeyUsage cli #4 (codeSign -> fail)" \
1252 "$O_SRV -key data_files/server5.key \
1253 -cert data_files/server5.eku-cs.crt" \
1254 "$P_CLI debug_level=2" \
1255 1 \
1256 -c "bad certificate (usage extensions)" \
1257 -c "Processing of the Certificate handshake message failed" \
1258 -C "Ciphersuite is TLS-"
1259
1260# Tests for extendedKeyUsage, part 3: server-side checking of client cert
1261
1262run_test "extKeyUsage cli-auth #1 (clientAuth -> OK)" \
1263 "$P_SRV debug_level=2 auth_mode=optional" \
1264 "$O_CLI -key data_files/server5.key \
1265 -cert data_files/server5.eku-cli.crt" \
1266 0 \
1267 -S "bad certificate (usage extensions)" \
1268 -S "Processing of the Certificate handshake message failed"
1269
1270run_test "extKeyUsage cli-auth #2 (serverAuth,clientAuth -> OK)" \
1271 "$P_SRV debug_level=2 auth_mode=optional" \
1272 "$O_CLI -key data_files/server5.key \
1273 -cert data_files/server5.eku-srv_cli.crt" \
1274 0 \
1275 -S "bad certificate (usage extensions)" \
1276 -S "Processing of the Certificate handshake message failed"
1277
1278run_test "extKeyUsage cli-auth #3 (codeSign,anyEKU -> OK)" \
1279 "$P_SRV debug_level=2 auth_mode=optional" \
1280 "$O_CLI -key data_files/server5.key \
1281 -cert data_files/server5.eku-cs_any.crt" \
1282 0 \
1283 -S "bad certificate (usage extensions)" \
1284 -S "Processing of the Certificate handshake message failed"
1285
1286run_test "extKeyUsage cli-auth #4 (codeSign -> fail (soft))" \
1287 "$P_SRV debug_level=2 auth_mode=optional" \
1288 "$O_CLI -key data_files/server5.key \
1289 -cert data_files/server5.eku-cs.crt" \
1290 0 \
1291 -s "bad certificate (usage extensions)" \
1292 -S "Processing of the Certificate handshake message failed"
1293
1294run_test "extKeyUsage cli-auth #4b (codeSign -> fail (hard))" \
1295 "$P_SRV debug_level=2 auth_mode=required" \
1296 "$O_CLI -key data_files/server5.key \
1297 -cert data_files/server5.eku-cs.crt" \
1298 1 \
1299 -s "bad certificate (usage extensions)" \
1300 -s "Processing of the Certificate handshake message failed"
1301
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001302# Tests for DHM parameters loading
1303
1304run_test "DHM parameters #0 (reference)" \
1305 "$P_SRV" \
1306 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1307 debug_level=3" \
1308 0 \
1309 -c "value of 'DHM: P ' (2048 bits)" \
1310 -c "value of 'DHM: G ' (2048 bits)"
1311
1312run_test "DHM parameters #1 (other parameters)" \
1313 "$P_SRV dhm_file=data_files/dhparams.pem" \
1314 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1315 debug_level=3" \
1316 0 \
1317 -c "value of 'DHM: P ' (1024 bits)" \
1318 -c "value of 'DHM: G ' (2 bits)"
1319
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001320# Tests for PSK callback
1321
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001322run_test "PSK callback #0a (psk, no callback)" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001323 "$P_SRV psk=abc123 psk_identity=foo" \
1324 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1325 psk_identity=foo psk=abc123" \
1326 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001327 -S "SSL - The server has no ciphersuites in common" \
1328 -S "SSL - Unknown identity received" \
1329 -S "SSL - Verification of the message MAC failed"
1330
1331run_test "PSK callback #0b (no psk, no callback)" \
1332 "$P_SRV" \
1333 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1334 psk_identity=foo psk=abc123" \
1335 1 \
1336 -s "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001337 -S "SSL - Unknown identity received" \
1338 -S "SSL - Verification of the message MAC failed"
1339
1340run_test "PSK callback #1 (callback overrides other settings)" \
1341 "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
1342 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1343 psk_identity=foo psk=abc123" \
1344 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001345 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001346 -s "SSL - Unknown identity received" \
1347 -S "SSL - Verification of the message MAC failed"
1348
1349run_test "PSK callback #2 (first id matches)" \
1350 "$P_SRV psk_list=abc,dead,def,beef" \
1351 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1352 psk_identity=abc psk=dead" \
1353 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001354 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001355 -S "SSL - Unknown identity received" \
1356 -S "SSL - Verification of the message MAC failed"
1357
1358run_test "PSK callback #3 (second id matches)" \
1359 "$P_SRV psk_list=abc,dead,def,beef" \
1360 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1361 psk_identity=def psk=beef" \
1362 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001363 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001364 -S "SSL - Unknown identity received" \
1365 -S "SSL - Verification of the message MAC failed"
1366
1367run_test "PSK callback #4 (no match)" \
1368 "$P_SRV psk_list=abc,dead,def,beef" \
1369 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1370 psk_identity=ghi psk=beef" \
1371 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001372 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001373 -s "SSL - Unknown identity received" \
1374 -S "SSL - Verification of the message MAC failed"
1375
1376run_test "PSK callback #5 (wrong key)" \
1377 "$P_SRV psk_list=abc,dead,def,beef" \
1378 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1379 psk_identity=abc psk=beef" \
1380 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001381 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001382 -S "SSL - Unknown identity received" \
1383 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001384
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001385# Tests for ciphersuites per version
1386
1387run_test "Per-version suites #1" \
1388 "$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" \
1389 "$P_CLI force_version=ssl3" \
1390 0 \
1391 -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA"
1392
1393run_test "Per-version suites #2" \
1394 "$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" \
1395 "$P_CLI force_version=tls1" \
1396 0 \
1397 -c "Ciphersuite is TLS-RSA-WITH-RC4-128-SHA"
1398
1399run_test "Per-version suites #3" \
1400 "$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" \
1401 "$P_CLI force_version=tls1_1" \
1402 0 \
1403 -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA"
1404
1405run_test "Per-version suites #4" \
1406 "$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" \
1407 "$P_CLI force_version=tls1_2" \
1408 0 \
1409 -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
1410
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001411# Tests for ssl_get_bytes_avail()
1412
1413run_test "ssl_get_bytes_avail #1 (no extra data)" \
1414 "$P_SRV" \
1415 "$P_CLI request_size=100" \
1416 0 \
1417 -s "Read from client: 100 bytes read$"
1418
1419run_test "ssl_get_bytes_avail #2 (extra data)" \
1420 "$P_SRV" \
1421 "$P_CLI request_size=500" \
1422 0 \
1423 -s "Read from client: 500 bytes read (.*+.*)"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001424
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02001425# Tests for small packets
1426
1427run_test "Small packet SSLv3 BlockCipher" \
1428 "$P_SRV" \
1429 "$P_CLI request_size=1 force_version=ssl3 \
1430 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1431 0 \
1432 -s "Read from client: 1 bytes read"
1433
1434run_test "Small packet SSLv3 StreamCipher" \
1435 "$P_SRV" \
1436 "$P_CLI request_size=1 force_version=ssl3 \
1437 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1438 0 \
1439 -s "Read from client: 1 bytes read"
1440
1441run_test "Small packet TLS 1.0 BlockCipher" \
1442 "$P_SRV" \
1443 "$P_CLI request_size=1 force_version=tls1 \
1444 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1445 0 \
1446 -s "Read from client: 1 bytes read"
1447
1448run_test "Small packet TLS 1.0 BlockCipher truncated MAC" \
1449 "$P_SRV" \
1450 "$P_CLI request_size=1 force_version=tls1 \
1451 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1452 trunc_hmac=1" \
1453 0 \
1454 -s "Read from client: 1 bytes read"
1455
1456run_test "Small packet TLS 1.0 StreamCipher truncated MAC" \
1457 "$P_SRV" \
1458 "$P_CLI request_size=1 force_version=tls1 \
1459 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1460 trunc_hmac=1" \
1461 0 \
1462 -s "Read from client: 1 bytes read"
1463
1464run_test "Small packet TLS 1.1 BlockCipher" \
1465 "$P_SRV" \
1466 "$P_CLI request_size=1 force_version=tls1_1 \
1467 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1468 0 \
1469 -s "Read from client: 1 bytes read"
1470
1471run_test "Small packet TLS 1.1 StreamCipher" \
1472 "$P_SRV" \
1473 "$P_CLI request_size=1 force_version=tls1_1 \
1474 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1475 0 \
1476 -s "Read from client: 1 bytes read"
1477
1478run_test "Small packet TLS 1.1 BlockCipher truncated MAC" \
1479 "$P_SRV" \
1480 "$P_CLI request_size=1 force_version=tls1_1 \
1481 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1482 trunc_hmac=1" \
1483 0 \
1484 -s "Read from client: 1 bytes read"
1485
1486run_test "Small packet TLS 1.1 StreamCipher truncated MAC" \
1487 "$P_SRV" \
1488 "$P_CLI request_size=1 force_version=tls1_1 \
1489 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1490 trunc_hmac=1" \
1491 0 \
1492 -s "Read from client: 1 bytes read"
1493
1494run_test "Small packet TLS 1.2 BlockCipher" \
1495 "$P_SRV" \
1496 "$P_CLI request_size=1 force_version=tls1_2 \
1497 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1498 0 \
1499 -s "Read from client: 1 bytes read"
1500
1501run_test "Small packet TLS 1.2 BlockCipher larger MAC" \
1502 "$P_SRV" \
1503 "$P_CLI request_size=1 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1504 0 \
1505 -s "Read from client: 1 bytes read"
1506
1507run_test "Small packet TLS 1.2 BlockCipher truncated MAC" \
1508 "$P_SRV" \
1509 "$P_CLI request_size=1 force_version=tls1_2 \
1510 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1511 trunc_hmac=1" \
1512 0 \
1513 -s "Read from client: 1 bytes read"
1514
1515run_test "Small packet TLS 1.2 StreamCipher" \
1516 "$P_SRV" \
1517 "$P_CLI request_size=1 force_version=tls1_2 \
1518 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1519 0 \
1520 -s "Read from client: 1 bytes read"
1521
1522run_test "Small packet TLS 1.2 StreamCipher truncated MAC" \
1523 "$P_SRV" \
1524 "$P_CLI request_size=1 force_version=tls1_2 \
1525 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1526 trunc_hmac=1" \
1527 0 \
1528 -s "Read from client: 1 bytes read"
1529
1530run_test "Small packet TLS 1.2 AEAD" \
1531 "$P_SRV" \
1532 "$P_CLI request_size=1 force_version=tls1_2 \
1533 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1534 0 \
1535 -s "Read from client: 1 bytes read"
1536
1537run_test "Small packet TLS 1.2 AEAD shorter tag" \
1538 "$P_SRV" \
1539 "$P_CLI request_size=1 force_version=tls1_2 \
1540 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
1541 0 \
1542 -s "Read from client: 1 bytes read"
1543
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02001544# Test for large packets
1545
1546run_test "Large packet SSLv3 BlockCipher" \
1547 "$P_SRV" \
1548 "$P_CLI request_size=16384 force_version=ssl3 \
1549 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1550 0 \
1551 -s "Read from client: 16384 bytes read"
1552
1553run_test "Large packet SSLv3 StreamCipher" \
1554 "$P_SRV" \
1555 "$P_CLI request_size=16384 force_version=ssl3 \
1556 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1557 0 \
1558 -s "Read from client: 16384 bytes read"
1559
1560run_test "Large packet TLS 1.0 BlockCipher" \
1561 "$P_SRV" \
1562 "$P_CLI request_size=16384 force_version=tls1 \
1563 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1564 0 \
1565 -s "Read from client: 16384 bytes read"
1566
1567run_test "Large packet TLS 1.0 BlockCipher truncated MAC" \
1568 "$P_SRV" \
1569 "$P_CLI request_size=16384 force_version=tls1 \
1570 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1571 trunc_hmac=1" \
1572 0 \
1573 -s "Read from client: 16384 bytes read"
1574
1575run_test "Large packet TLS 1.0 StreamCipher truncated MAC" \
1576 "$P_SRV" \
1577 "$P_CLI request_size=16384 force_version=tls1 \
1578 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1579 trunc_hmac=1" \
1580 0 \
1581 -s "Read from client: 16384 bytes read"
1582
1583run_test "Large packet TLS 1.1 BlockCipher" \
1584 "$P_SRV" \
1585 "$P_CLI request_size=16384 force_version=tls1_1 \
1586 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1587 0 \
1588 -s "Read from client: 16384 bytes read"
1589
1590run_test "Large packet TLS 1.1 StreamCipher" \
1591 "$P_SRV" \
1592 "$P_CLI request_size=16384 force_version=tls1_1 \
1593 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1594 0 \
1595 -s "Read from client: 16384 bytes read"
1596
1597run_test "Large packet TLS 1.1 BlockCipher truncated MAC" \
1598 "$P_SRV" \
1599 "$P_CLI request_size=16384 force_version=tls1_1 \
1600 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1601 trunc_hmac=1" \
1602 0 \
1603 -s "Read from client: 16384 bytes read"
1604
1605run_test "Large packet TLS 1.1 StreamCipher truncated MAC" \
1606 "$P_SRV" \
1607 "$P_CLI request_size=16384 force_version=tls1_1 \
1608 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1609 trunc_hmac=1" \
1610 0 \
1611 -s "Read from client: 16384 bytes read"
1612
1613run_test "Large packet TLS 1.2 BlockCipher" \
1614 "$P_SRV" \
1615 "$P_CLI request_size=16384 force_version=tls1_2 \
1616 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1617 0 \
1618 -s "Read from client: 16384 bytes read"
1619
1620run_test "Large packet TLS 1.2 BlockCipher larger MAC" \
1621 "$P_SRV" \
1622 "$P_CLI request_size=16384 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1623 0 \
1624 -s "Read from client: 16384 bytes read"
1625
1626run_test "Large packet TLS 1.2 BlockCipher truncated MAC" \
1627 "$P_SRV" \
1628 "$P_CLI request_size=16384 force_version=tls1_2 \
1629 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1630 trunc_hmac=1" \
1631 0 \
1632 -s "Read from client: 16384 bytes read"
1633
1634run_test "Large packet TLS 1.2 StreamCipher" \
1635 "$P_SRV" \
1636 "$P_CLI request_size=16384 force_version=tls1_2 \
1637 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1638 0 \
1639 -s "Read from client: 16384 bytes read"
1640
1641run_test "Large packet TLS 1.2 StreamCipher truncated MAC" \
1642 "$P_SRV" \
1643 "$P_CLI request_size=16384 force_version=tls1_2 \
1644 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1645 trunc_hmac=1" \
1646 0 \
1647 -s "Read from client: 16384 bytes read"
1648
1649run_test "Large packet TLS 1.2 AEAD" \
1650 "$P_SRV" \
1651 "$P_CLI request_size=16384 force_version=tls1_2 \
1652 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1653 0 \
1654 -s "Read from client: 16384 bytes read"
1655
1656run_test "Large packet TLS 1.2 AEAD shorter tag" \
1657 "$P_SRV" \
1658 "$P_CLI request_size=16384 force_version=tls1_2 \
1659 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
1660 0 \
1661 -s "Read from client: 16384 bytes read"
1662
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001663# Final report
1664
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01001665echo "------------------------------------------------------------------------"
1666
1667if [ $FAILS = 0 ]; then
1668 echo -n "PASSED"
1669else
1670 echo -n "FAILED"
1671fi
1672PASSES=`echo $TESTS - $FAILS | bc`
Manuel Pégourié-Gonnard4145b892014-02-24 13:20:14 +01001673echo " ($PASSES / $TESTS tests)"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01001674
1675exit $FAILS