blob: 4df999eb64cad567682f3ca82c13f8811193b953 [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é-Gonnard3eec6042014-02-27 15:37:24 +010092 cp srv_out o-srv-${TESTS}.log
93 cp cli_out o-cli-${TESTS}.log
94 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é-Gonnardfccd3252014-02-25 17:14:15 +0100115# Usage: run_test name srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100116# Options: -s pattern pattern that must be present in server output
117# -c pattern pattern that must be present in client output
118# -S pattern pattern that must be absent in server output
119# -C pattern pattern that must be absent in client output
120run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100121 NAME="$1"
122 SRV_CMD="$2"
123 CLI_CMD="$3"
124 CLI_EXPECT="$4"
125 shift 4
126
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100127 if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
128 else
129 return
130 fi
131
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100132 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100133
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100134 # prepend valgrind to our commands if active
135 if [ "$MEMCHECK" -gt 0 ]; then
136 if is_polar "$SRV_CMD"; then
137 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
138 fi
139 if is_polar "$CLI_CMD"; then
140 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
141 fi
142 fi
143
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100144 # run the commands
Manuel Pégourié-Gonnardba0b8442014-03-13 17:57:45 +0100145 echo "$SRV_CMD" > srv_out
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100146 $SRV_CMD >> srv_out 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100147 SRV_PID=$!
148 sleep 1
Manuel Pégourié-Gonnardba0b8442014-03-13 17:57:45 +0100149 echo "$CLI_CMD" > cli_out
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100150 eval "$CLI_CMD" >> cli_out 2>&1
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100151 CLI_EXIT=$?
Manuel Pégourié-Gonnarde01af4c2014-03-25 14:16:44 +0100152 echo "EXIT: $CLI_EXIT" >> cli_out
153
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200154 # psk is useful when server only has bad certs
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100155 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200156 $P_CLI request_page=SERVERQUIT tickets=0 auth_mode=none psk=abc123 \
Manuel Pégourié-Gonnard84fd6872014-03-13 18:35:10 +0100157 crt_file=data_files/cli2.crt key_file=data_files/cli2.key \
158 >/dev/null
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100159 else
160 kill $SRV_PID
161 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100162 wait $SRV_PID
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100163
164 # check if the client and server went at least to the handshake stage
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200165 # (useful to avoid tests with only negative assertions and non-zero
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100166 # expected client exit to incorrectly succeed in case of catastrophic
167 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100168 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100169 if grep "Performing the SSL/TLS handshake" srv_out >/dev/null; then :;
170 else
171 fail "server failed to start"
172 return
173 fi
174 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100175 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100176 if grep "Performing the SSL/TLS handshake" cli_out >/dev/null; then :;
177 else
178 fail "client failed to start"
179 return
180 fi
181 fi
182
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100183 # check server exit code
184 if [ $? != 0 ]; then
185 fail "server fail"
186 return
187 fi
188
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100189 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100190 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
191 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100192 then
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100193 fail "bad client exit code"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100194 return
195 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100196
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100197 # check other assertions
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100198 while [ $# -gt 0 ]
199 do
200 case $1 in
201 "-s")
202 if grep "$2" srv_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100203 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100204 return
205 fi
206 ;;
207
208 "-c")
209 if grep "$2" cli_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100210 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100211 return
212 fi
213 ;;
214
215 "-S")
216 if grep "$2" srv_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100217 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100218 return
219 fi
220 ;;
221
222 "-C")
223 if grep "$2" cli_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100224 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100225 return
226 fi
227 ;;
228
229 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200230 echo "Unknown test: $1" >&2
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100231 exit 1
232 esac
233 shift 2
234 done
235
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100236 # check valgrind's results
237 if [ "$MEMCHECK" -gt 0 ]; then
238 if is_polar "$SRV_CMD" && has_mem_err srv_out; then
239 fail "Server has memory errors"
240 return
241 fi
242 if is_polar "$CLI_CMD" && has_mem_err cli_out; then
243 fail "Client has memory errors"
244 return
245 fi
246 fi
247
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100248 # if we're here, everything is ok
249 echo "PASS"
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100250 rm -f srv_out cli_out
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100251}
252
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100253cleanup() {
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100254 rm -f cli_out srv_out sess
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100255 kill $SRV_PID
256 exit 1
257}
258
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100259#
260# MAIN
261#
262
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100263get_options "$@"
264
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100265# sanity checks, avoid an avalanche of errors
266if [ ! -x "$P_SRV" ]; then
267 echo "Command '$P_SRV' is not an executable file"
268 exit 1
269fi
270if [ ! -x "$P_CLI" ]; then
271 echo "Command '$P_CLI' is not an executable file"
272 exit 1
273fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100274if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
275 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100276 exit 1
277fi
278
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200279# Pick a "unique" port in the range 10000-19999.
280PORT="0000$$"
281PORT="1$(echo $PORT | tail -c 4)"
282
283# fix commands to use this port
284P_SRV="$P_SRV server_port=$PORT"
285P_CLI="$P_CLI server_port=$PORT"
286O_SRV="$O_SRV -accept $PORT"
287O_CLI="$O_CLI -connect localhost:$PORT"
288
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100289trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100290
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100291# Test for SSLv2 ClientHello
292
293run_test "SSLv2 ClientHello #0 (reference)" \
294 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100295 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100296 0 \
297 -S "parse client hello v2" \
298 -S "ssl_handshake returned"
299
300# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
301run_test "SSLv2 ClientHello #1 (actual test)" \
302 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100303 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100304 0 \
305 -s "parse client hello v2" \
306 -S "ssl_handshake returned"
307
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100308# Tests for Truncated HMAC extension
309
310run_test "Truncated HMAC #0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100311 "$P_SRV debug_level=5" \
312 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100313 0 \
314 -s "dumping 'computed mac' (20 bytes)"
315
316run_test "Truncated HMAC #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100317 "$P_SRV debug_level=5" \
318 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100319 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100320 -s "dumping 'computed mac' (10 bytes)"
321
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100322# Tests for Session Tickets
323
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100324run_test "Session resume using tickets #1 (basic)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100325 "$P_SRV debug_level=4 tickets=1" \
326 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100327 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100328 -c "client hello, adding session ticket extension" \
329 -s "found session ticket extension" \
330 -s "server hello, adding session ticket extension" \
331 -c "found session_ticket extension" \
332 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100333 -S "session successfully restored from cache" \
334 -s "session successfully restored from ticket" \
335 -s "a session has been resumed" \
336 -c "a session has been resumed"
337
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100338run_test "Session resume using tickets #2 (cache disabled)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100339 "$P_SRV debug_level=4 tickets=1 cache_max=0" \
340 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100341 0 \
342 -c "client hello, adding session ticket extension" \
343 -s "found session ticket extension" \
344 -s "server hello, adding session ticket extension" \
345 -c "found session_ticket extension" \
346 -c "parse new session ticket" \
347 -S "session successfully restored from cache" \
348 -s "session successfully restored from ticket" \
349 -s "a session has been resumed" \
350 -c "a session has been resumed"
351
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100352run_test "Session resume using tickets #3 (timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100353 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=1" \
354 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100355 0 \
356 -c "client hello, adding session ticket extension" \
357 -s "found session ticket extension" \
358 -s "server hello, adding session ticket extension" \
359 -c "found session_ticket extension" \
360 -c "parse new session ticket" \
361 -S "session successfully restored from cache" \
362 -S "session successfully restored from ticket" \
363 -S "a session has been resumed" \
364 -C "a session has been resumed"
365
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100366run_test "Session resume using tickets #4 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100367 "$O_SRV" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100368 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
369 0 \
370 -c "client hello, adding session ticket extension" \
371 -c "found session_ticket extension" \
372 -c "parse new session ticket" \
373 -c "a session has been resumed"
374
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100375run_test "Session resume using tickets #5 (openssl client)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100376 "$P_SRV debug_level=4 tickets=1" \
377 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
378 0 \
379 -s "found session ticket extension" \
380 -s "server hello, adding session ticket extension" \
381 -S "session successfully restored from cache" \
382 -s "session successfully restored from ticket" \
383 -s "a session has been resumed"
384
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100385# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100386
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100387run_test "Session resume using cache #1 (tickets enabled on client)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100388 "$P_SRV debug_level=4 tickets=0" \
389 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100390 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100391 -c "client hello, adding session ticket extension" \
392 -s "found session ticket extension" \
393 -S "server hello, adding session ticket extension" \
394 -C "found session_ticket extension" \
395 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100396 -s "session successfully restored from cache" \
397 -S "session successfully restored from ticket" \
398 -s "a session has been resumed" \
399 -c "a session has been resumed"
400
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100401run_test "Session resume using cache #2 (tickets enabled on server)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100402 "$P_SRV debug_level=4 tickets=1" \
403 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100404 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100405 -C "client hello, adding session ticket extension" \
406 -S "found session ticket extension" \
407 -S "server hello, adding session ticket extension" \
408 -C "found session_ticket extension" \
409 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100410 -s "session successfully restored from cache" \
411 -S "session successfully restored from ticket" \
412 -s "a session has been resumed" \
413 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100414
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100415run_test "Session resume using cache #3 (cache_max=0)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100416 "$P_SRV debug_level=4 tickets=0 cache_max=0" \
417 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100418 0 \
419 -S "session successfully restored from cache" \
420 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100421 -S "a session has been resumed" \
422 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100423
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100424run_test "Session resume using cache #4 (cache_max=1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100425 "$P_SRV debug_level=4 tickets=0 cache_max=1" \
426 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100427 0 \
428 -s "session successfully restored from cache" \
429 -S "session successfully restored from ticket" \
430 -s "a session has been resumed" \
431 -c "a session has been resumed"
432
433run_test "Session resume using cache #5 (timemout > delay)" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100434 "$P_SRV debug_level=4 tickets=0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100435 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100436 0 \
437 -s "session successfully restored from cache" \
438 -S "session successfully restored from ticket" \
439 -s "a session has been resumed" \
440 -c "a session has been resumed"
441
442run_test "Session resume using cache #6 (timeout < delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100443 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
444 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100445 0 \
446 -S "session successfully restored from cache" \
447 -S "session successfully restored from ticket" \
448 -S "a session has been resumed" \
449 -C "a session has been resumed"
450
451run_test "Session resume using cache #7 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100452 "$P_SRV debug_level=4 tickets=0 cache_timeout=0" \
453 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100454 0 \
455 -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"
459
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100460run_test "Session resume using cache #8 (openssl client)" \
461 "$P_SRV debug_level=4 tickets=0" \
462 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
463 0 \
464 -s "found session ticket extension" \
465 -S "server hello, adding session ticket extension" \
466 -s "session successfully restored from cache" \
467 -S "session successfully restored from ticket" \
468 -s "a session has been resumed"
469
470run_test "Session resume using cache #9 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100471 "$O_SRV" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100472 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
473 0 \
474 -C "found session_ticket extension" \
475 -C "parse new session ticket" \
476 -c "a session has been resumed"
477
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100478# Tests for Max Fragment Length extension
479
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100480run_test "Max fragment length #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100481 "$P_SRV debug_level=4" \
482 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100483 0 \
484 -C "client hello, adding max_fragment_length extension" \
485 -S "found max fragment length extension" \
486 -S "server hello, max_fragment_length extension" \
487 -C "found max_fragment_length extension"
488
489run_test "Max fragment length #2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100490 "$P_SRV debug_level=4" \
491 "$P_CLI debug_level=4 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100492 0 \
493 -c "client hello, adding max_fragment_length extension" \
494 -s "found max fragment length extension" \
495 -s "server hello, max_fragment_length extension" \
496 -c "found max_fragment_length extension"
497
498run_test "Max fragment length #3" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100499 "$P_SRV debug_level=4 max_frag_len=4096" \
500 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100501 0 \
502 -C "client hello, adding max_fragment_length extension" \
503 -S "found max fragment length extension" \
504 -S "server hello, max_fragment_length extension" \
505 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100506
507# Tests for renegotiation
508
509run_test "Renegotiation #0 (none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100510 "$P_SRV debug_level=4" \
511 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100512 0 \
513 -C "client hello, adding renegotiation extension" \
514 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
515 -S "found renegotiation extension" \
516 -s "server hello, secure renegotiation extension" \
517 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100518 -C "=> renegotiate" \
519 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100520 -S "write hello request"
521
522run_test "Renegotiation #1 (enabled, client-initiated)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200523 "$P_SRV debug_level=4 renegotiation=1" \
524 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100525 0 \
526 -c "client hello, adding renegotiation extension" \
527 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
528 -s "found renegotiation extension" \
529 -s "server hello, secure renegotiation extension" \
530 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100531 -c "=> renegotiate" \
532 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100533 -S "write hello request"
534
535run_test "Renegotiation #2 (enabled, server-initiated)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200536 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
537 "$P_CLI debug_level=4 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100538 0 \
539 -c "client hello, adding renegotiation extension" \
540 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
541 -s "found renegotiation extension" \
542 -s "server hello, secure renegotiation extension" \
543 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100544 -c "=> renegotiate" \
545 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100546 -s "write hello request"
547
548run_test "Renegotiation #3 (enabled, double)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200549 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
550 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100551 0 \
552 -c "client hello, adding renegotiation extension" \
553 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
554 -s "found renegotiation extension" \
555 -s "server hello, secure renegotiation extension" \
556 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100557 -c "=> renegotiate" \
558 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100559 -s "write hello request"
560
561run_test "Renegotiation #4 (client-initiated, server-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100562 "$P_SRV debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200563 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100564 1 \
565 -c "client hello, adding renegotiation extension" \
566 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
567 -S "found renegotiation extension" \
568 -s "server hello, secure renegotiation extension" \
569 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100570 -c "=> renegotiate" \
571 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100572 -S "write hello request"
573
574run_test "Renegotiation #5 (server-initiated, client-rejected)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200575 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100576 "$P_CLI debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100577 0 \
578 -C "client hello, adding renegotiation extension" \
579 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
580 -S "found renegotiation extension" \
581 -s "server hello, secure renegotiation extension" \
582 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100583 -C "=> renegotiate" \
584 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100585 -s "write hello request" \
586 -s "SSL - An unexpected message was received from our peer" \
587 -s "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100588
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100589# Tests for auth_mode
590
591run_test "Authentication #1 (server badcert, client required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100592 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100593 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100594 "$P_CLI debug_level=2 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100595 1 \
596 -c "x509_verify_cert() returned" \
597 -c "! self-signed or not signed by a trusted CA" \
598 -c "! ssl_handshake returned" \
599 -c "X509 - Certificate verification failed"
600
601run_test "Authentication #2 (server badcert, client optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100602 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100603 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100604 "$P_CLI debug_level=2 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100605 0 \
606 -c "x509_verify_cert() returned" \
607 -c "! self-signed or not signed by a trusted CA" \
608 -C "! ssl_handshake returned" \
609 -C "X509 - Certificate verification failed"
610
611run_test "Authentication #3 (server badcert, client none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100612 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100613 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100614 "$P_CLI debug_level=2 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100615 0 \
616 -C "x509_verify_cert() returned" \
617 -C "! self-signed or not signed by a trusted CA" \
618 -C "! ssl_handshake returned" \
619 -C "X509 - Certificate verification failed"
620
621run_test "Authentication #4 (client badcert, server required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100622 "$P_SRV debug_level=4 auth_mode=required" \
623 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100624 key_file=data_files/server5.key" \
625 1 \
626 -S "skip write certificate request" \
627 -C "skip parse certificate request" \
628 -c "got a certificate request" \
629 -C "skip write certificate" \
630 -C "skip write certificate verify" \
631 -S "skip parse certificate verify" \
632 -s "x509_verify_cert() returned" \
633 -S "! self-signed or not signed by a trusted CA" \
634 -s "! ssl_handshake returned" \
635 -c "! ssl_handshake returned" \
636 -s "X509 - Certificate verification failed"
637
638run_test "Authentication #5 (client badcert, server optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100639 "$P_SRV debug_level=4 auth_mode=optional" \
640 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100641 key_file=data_files/server5.key" \
642 0 \
643 -S "skip write certificate request" \
644 -C "skip parse certificate request" \
645 -c "got a certificate request" \
646 -C "skip write certificate" \
647 -C "skip write certificate verify" \
648 -S "skip parse certificate verify" \
649 -s "x509_verify_cert() returned" \
650 -s "! self-signed or not signed by a trusted CA" \
651 -S "! ssl_handshake returned" \
652 -C "! ssl_handshake returned" \
653 -S "X509 - Certificate verification failed"
654
655run_test "Authentication #6 (client badcert, server none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100656 "$P_SRV debug_level=4 auth_mode=none" \
657 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100658 key_file=data_files/server5.key" \
659 0 \
660 -s "skip write certificate request" \
661 -C "skip parse certificate request" \
662 -c "got no certificate request" \
663 -c "skip write certificate" \
664 -c "skip write certificate verify" \
665 -s "skip parse certificate verify" \
666 -S "x509_verify_cert() returned" \
667 -S "! self-signed or not signed by a trusted CA" \
668 -S "! ssl_handshake returned" \
669 -C "! ssl_handshake returned" \
670 -S "X509 - Certificate verification failed"
671
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +0100672run_test "Authentication #7 (client no cert, server optional)" \
673 "$P_SRV debug_level=4 auth_mode=optional" \
674 "$P_CLI debug_level=4 crt_file=none key_file=none" \
675 0 \
676 -S "skip write certificate request" \
677 -C "skip parse certificate request" \
678 -c "got a certificate request" \
679 -C "skip write certificate$" \
680 -C "got no certificate to send" \
681 -S "SSLv3 client has no certificate" \
682 -c "skip write certificate verify" \
683 -s "skip parse certificate verify" \
684 -s "! no client certificate sent" \
685 -S "! ssl_handshake returned" \
686 -C "! ssl_handshake returned" \
687 -S "X509 - Certificate verification failed"
688
689run_test "Authentication #8 (openssl client no cert, server optional)" \
690 "$P_SRV debug_level=4 auth_mode=optional" \
691 "$O_CLI" \
692 0 \
693 -S "skip write certificate request" \
694 -s "skip parse certificate verify" \
695 -s "! no client certificate sent" \
696 -S "! ssl_handshake returned" \
697 -S "X509 - Certificate verification failed"
698
699run_test "Authentication #9 (client no cert, openssl server optional)" \
700 "$O_SRV -verify 10" \
701 "$P_CLI debug_level=4 crt_file=none key_file=none" \
702 0 \
703 -C "skip parse certificate request" \
704 -c "got a certificate request" \
705 -C "skip write certificate$" \
706 -c "skip write certificate verify" \
707 -C "! ssl_handshake returned"
708
709run_test "Authentication #10 (client no cert, ssl3)" \
710 "$P_SRV debug_level=4 auth_mode=optional force_version=ssl3" \
711 "$P_CLI debug_level=4 crt_file=none key_file=none" \
712 0 \
713 -S "skip write certificate request" \
714 -C "skip parse certificate request" \
715 -c "got a certificate request" \
716 -C "skip write certificate$" \
717 -c "skip write certificate verify" \
718 -c "got no certificate to send" \
719 -s "SSLv3 client has no certificate" \
720 -s "skip parse certificate verify" \
721 -s "! no client certificate sent" \
722 -S "! ssl_handshake returned" \
723 -C "! ssl_handshake returned" \
724 -S "X509 - Certificate verification failed"
725
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100726# tests for SNI
727
728run_test "SNI #0 (no SNI callback)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100729 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100730 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100731 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100732 server_name=localhost" \
733 0 \
734 -S "parse ServerName extension" \
735 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
736 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
737
738run_test "SNI #1 (matching cert 1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100739 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100740 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100741 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 +0100742 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100743 server_name=localhost" \
744 0 \
745 -s "parse ServerName extension" \
746 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
747 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
748
749run_test "SNI #2 (matching cert 2)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100750 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100751 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100752 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 +0100753 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100754 server_name=polarssl.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100755 0 \
756 -s "parse ServerName extension" \
757 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100758 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100759
760run_test "SNI #3 (no matching cert)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100761 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100762 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100763 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 +0100764 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100765 server_name=nonesuch.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100766 1 \
767 -s "parse ServerName extension" \
768 -s "ssl_sni_wrapper() returned" \
769 -s "ssl_handshake returned" \
770 -c "ssl_handshake returned" \
771 -c "SSL - A fatal alert message was received from our peer"
772
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +0100773# Tests for non-blocking I/O: exercise a variety of handshake flows
774
775run_test "Non-blocking I/O #1 (basic handshake)" \
776 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
777 "$P_CLI nbio=2 tickets=0" \
778 0 \
779 -S "ssl_handshake returned" \
780 -C "ssl_handshake returned" \
781 -c "Read from server: .* bytes read"
782
783run_test "Non-blocking I/O #2 (client auth)" \
784 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
785 "$P_CLI nbio=2 tickets=0" \
786 0 \
787 -S "ssl_handshake returned" \
788 -C "ssl_handshake returned" \
789 -c "Read from server: .* bytes read"
790
791run_test "Non-blocking I/O #3 (ticket)" \
792 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
793 "$P_CLI nbio=2 tickets=1" \
794 0 \
795 -S "ssl_handshake returned" \
796 -C "ssl_handshake returned" \
797 -c "Read from server: .* bytes read"
798
799run_test "Non-blocking I/O #4 (ticket + client auth)" \
800 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
801 "$P_CLI nbio=2 tickets=1" \
802 0 \
803 -S "ssl_handshake returned" \
804 -C "ssl_handshake returned" \
805 -c "Read from server: .* bytes read"
806
807run_test "Non-blocking I/O #5 (ticket + client auth + resume)" \
808 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
809 "$P_CLI nbio=2 tickets=1 reconnect=1" \
810 0 \
811 -S "ssl_handshake returned" \
812 -C "ssl_handshake returned" \
813 -c "Read from server: .* bytes read"
814
815run_test "Non-blocking I/O #6 (ticket + resume)" \
816 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
817 "$P_CLI nbio=2 tickets=1 reconnect=1" \
818 0 \
819 -S "ssl_handshake returned" \
820 -C "ssl_handshake returned" \
821 -c "Read from server: .* bytes read"
822
823run_test "Non-blocking I/O #7 (session-id resume)" \
824 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
825 "$P_CLI nbio=2 tickets=0 reconnect=1" \
826 0 \
827 -S "ssl_handshake returned" \
828 -C "ssl_handshake returned" \
829 -c "Read from server: .* bytes read"
830
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200831# Tests for version negotiation
832
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100833run_test "Version check #1 (all -> 1.2)" \
834 "$P_SRV" \
835 "$P_CLI" \
836 0 \
837 -S "ssl_handshake returned" \
838 -C "ssl_handshake returned" \
839 -s "Protocol is TLSv1.2" \
840 -c "Protocol is TLSv1.2"
841
842run_test "Version check #2 (cli max 1.1 -> 1.1)" \
843 "$P_SRV" \
844 "$P_CLI max_version=tls1_1" \
845 0 \
846 -S "ssl_handshake returned" \
847 -C "ssl_handshake returned" \
848 -s "Protocol is TLSv1.1" \
849 -c "Protocol is TLSv1.1"
850
851run_test "Version check #3 (srv max 1.1 -> 1.1)" \
852 "$P_SRV max_version=tls1_1" \
853 "$P_CLI" \
854 0 \
855 -S "ssl_handshake returned" \
856 -C "ssl_handshake returned" \
857 -s "Protocol is TLSv1.1" \
858 -c "Protocol is TLSv1.1"
859
860run_test "Version check #4 (cli+srv max 1.1 -> 1.1)" \
861 "$P_SRV max_version=tls1_1" \
862 "$P_CLI max_version=tls1_1" \
863 0 \
864 -S "ssl_handshake returned" \
865 -C "ssl_handshake returned" \
866 -s "Protocol is TLSv1.1" \
867 -c "Protocol is TLSv1.1"
868
869run_test "Version check #5 (cli max 1.1, srv min 1.1 -> 1.1)" \
870 "$P_SRV min_version=tls1_1" \
871 "$P_CLI max_version=tls1_1" \
872 0 \
873 -S "ssl_handshake returned" \
874 -C "ssl_handshake returned" \
875 -s "Protocol is TLSv1.1" \
876 -c "Protocol is TLSv1.1"
877
878run_test "Version check #6 (cli min 1.1, srv max 1.1 -> 1.1)" \
879 "$P_SRV max_version=tls1_1" \
880 "$P_CLI min_version=tls1_1" \
881 0 \
882 -S "ssl_handshake returned" \
883 -C "ssl_handshake returned" \
884 -s "Protocol is TLSv1.1" \
885 -c "Protocol is TLSv1.1"
886
887run_test "Version check #7 (cli min 1.2, srv max 1.1 -> fail)" \
888 "$P_SRV max_version=tls1_1" \
889 "$P_CLI min_version=tls1_2" \
890 1 \
891 -s "ssl_handshake returned" \
892 -c "ssl_handshake returned" \
893 -c "SSL - Handshake protocol not within min/max boundaries"
894
895run_test "Version check #8 (srv min 1.2, cli max 1.1 -> fail)" \
896 "$P_SRV min_version=tls1_2" \
897 "$P_CLI max_version=tls1_1" \
898 1 \
899 -s "ssl_handshake returned" \
900 -c "ssl_handshake returned" \
901 -s "SSL - Handshake protocol not within min/max boundaries"
902
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200903# Tests for ALPN extension
904
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +0200905if grep '^#define POLARSSL_SSL_ALPN' $CONFIG_H >/dev/null; then
906
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200907run_test "ALPN #0 (none)" \
908 "$P_SRV debug_level=4" \
909 "$P_CLI debug_level=4" \
910 0 \
911 -C "client hello, adding alpn extension" \
912 -S "found alpn extension" \
913 -C "got an alert message, type: \\[2:120]" \
914 -S "server hello, adding alpn extension" \
915 -C "found alpn extension " \
916 -C "Application Layer Protocol is" \
917 -S "Application Layer Protocol is"
918
919run_test "ALPN #1 (client only)" \
920 "$P_SRV debug_level=4" \
921 "$P_CLI debug_level=4 alpn=abc,1234" \
922 0 \
923 -c "client hello, adding alpn extension" \
924 -s "found alpn extension" \
925 -C "got an alert message, type: \\[2:120]" \
926 -S "server hello, adding alpn extension" \
927 -C "found alpn extension " \
928 -c "Application Layer Protocol is (none)" \
929 -S "Application Layer Protocol is"
930
931run_test "ALPN #2 (server only)" \
932 "$P_SRV debug_level=4 alpn=abc,1234" \
933 "$P_CLI debug_level=4" \
934 0 \
935 -C "client hello, adding alpn extension" \
936 -S "found alpn extension" \
937 -C "got an alert message, type: \\[2:120]" \
938 -S "server hello, adding alpn extension" \
939 -C "found alpn extension " \
940 -C "Application Layer Protocol is" \
941 -s "Application Layer Protocol is (none)"
942
943run_test "ALPN #3 (both, common cli1-srv1)" \
944 "$P_SRV debug_level=4 alpn=abc,1234" \
945 "$P_CLI debug_level=4 alpn=abc,1234" \
946 0 \
947 -c "client hello, adding alpn extension" \
948 -s "found alpn extension" \
949 -C "got an alert message, type: \\[2:120]" \
950 -s "server hello, adding alpn extension" \
951 -c "found alpn extension" \
952 -c "Application Layer Protocol is abc" \
953 -s "Application Layer Protocol is abc"
954
955run_test "ALPN #4 (both, common cli2-srv1)" \
956 "$P_SRV debug_level=4 alpn=abc,1234" \
957 "$P_CLI debug_level=4 alpn=1234,abc" \
958 0 \
959 -c "client hello, adding alpn extension" \
960 -s "found alpn extension" \
961 -C "got an alert message, type: \\[2:120]" \
962 -s "server hello, adding alpn extension" \
963 -c "found alpn extension" \
964 -c "Application Layer Protocol is abc" \
965 -s "Application Layer Protocol is abc"
966
967run_test "ALPN #5 (both, common cli1-srv2)" \
968 "$P_SRV debug_level=4 alpn=abc,1234" \
969 "$P_CLI debug_level=4 alpn=1234,abcde" \
970 0 \
971 -c "client hello, adding alpn extension" \
972 -s "found alpn extension" \
973 -C "got an alert message, type: \\[2:120]" \
974 -s "server hello, adding alpn extension" \
975 -c "found alpn extension" \
976 -c "Application Layer Protocol is 1234" \
977 -s "Application Layer Protocol is 1234"
978
979run_test "ALPN #6 (both, no common)" \
980 "$P_SRV debug_level=4 alpn=abc,123" \
981 "$P_CLI debug_level=4 alpn=1234,abcde" \
982 1 \
983 -c "client hello, adding alpn extension" \
984 -s "found alpn extension" \
985 -c "got an alert message, type: \\[2:120]" \
986 -S "server hello, adding alpn extension" \
987 -C "found alpn extension" \
988 -C "Application Layer Protocol is 1234" \
989 -S "Application Layer Protocol is 1234"
990
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +0200991fi
992
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +0200993# Tests for keyUsage in leaf certificates, part 1:
994# server-side certificate/suite selection
995
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +0200996run_test "keyUsage srv #1 (RSA, digitalSignature -> (EC)DHE-RSA)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +0200997 "$P_SRV key_file=data_files/server2.key \
998 crt_file=data_files/server2.ku-ds.crt" \
999 "$P_CLI" \
1000 0 \
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02001001 -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001002
1003
1004run_test "keyUsage srv #2 (RSA, keyEncipherment -> RSA)" \
1005 "$P_SRV key_file=data_files/server2.key \
1006 crt_file=data_files/server2.ku-ke.crt" \
1007 "$P_CLI" \
1008 0 \
1009 -c "Ciphersuite is TLS-RSA-WITH-"
1010
1011# add psk to leave an option for client to send SERVERQUIT
1012run_test "keyUsage srv #3 (RSA, keyAgreement -> fail)" \
1013 "$P_SRV psk=abc123 key_file=data_files/server2.key \
1014 crt_file=data_files/server2.ku-ka.crt" \
1015 "$P_CLI psk=badbad" \
1016 1 \
1017 -C "Ciphersuite is "
1018
1019run_test "keyUsage srv #4 (ECDSA, digitalSignature -> ECDHE-ECDSA)" \
1020 "$P_SRV key_file=data_files/server5.key \
1021 crt_file=data_files/server5.ku-ds.crt" \
1022 "$P_CLI" \
1023 0 \
1024 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
1025
1026
1027run_test "keyUsage srv #5 (ECDSA, keyAgreement -> ECDH-)" \
1028 "$P_SRV key_file=data_files/server5.key \
1029 crt_file=data_files/server5.ku-ka.crt" \
1030 "$P_CLI" \
1031 0 \
1032 -c "Ciphersuite is TLS-ECDH-"
1033
1034# add psk to leave an option for client to send SERVERQUIT
1035run_test "keyUsage srv #6 (ECDSA, keyEncipherment -> fail)" \
1036 "$P_SRV psk=abc123 key_file=data_files/server5.key \
1037 crt_file=data_files/server5.ku-ke.crt" \
1038 "$P_CLI psk=badbad" \
1039 1 \
1040 -C "Ciphersuite is "
1041
1042# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001043# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001044
1045run_test "keyUsage cli #1 (DigitalSignature+KeyEncipherment, RSA: OK)" \
1046 "$O_SRV -key data_files/server2.key \
1047 -cert data_files/server2.ku-ds_ke.crt" \
1048 "$P_CLI debug_level=2 \
1049 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1050 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001051 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001052 -C "Processing of the Certificate handshake message failed" \
1053 -c "Ciphersuite is TLS-"
1054
1055run_test "keyUsage cli #2 (DigitalSignature+KeyEncipherment, DHE-RSA: OK)" \
1056 "$O_SRV -key data_files/server2.key \
1057 -cert data_files/server2.ku-ds_ke.crt" \
1058 "$P_CLI debug_level=2 \
1059 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1060 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001061 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001062 -C "Processing of the Certificate handshake message failed" \
1063 -c "Ciphersuite is TLS-"
1064
1065run_test "keyUsage cli #3 (KeyEncipherment, RSA: OK)" \
1066 "$O_SRV -key data_files/server2.key \
1067 -cert data_files/server2.ku-ke.crt" \
1068 "$P_CLI debug_level=2 \
1069 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1070 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001071 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001072 -C "Processing of the Certificate handshake message failed" \
1073 -c "Ciphersuite is TLS-"
1074
1075run_test "keyUsage cli #4 (KeyEncipherment, DHE-RSA: fail)" \
1076 "$O_SRV -key data_files/server2.key \
1077 -cert data_files/server2.ku-ke.crt" \
1078 "$P_CLI debug_level=2 \
1079 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1080 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001081 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001082 -c "Processing of the Certificate handshake message failed" \
1083 -C "Ciphersuite is TLS-"
1084
1085run_test "keyUsage cli #5 (DigitalSignature, DHE-RSA: OK)" \
1086 "$O_SRV -key data_files/server2.key \
1087 -cert data_files/server2.ku-ds.crt" \
1088 "$P_CLI debug_level=2 \
1089 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1090 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001091 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001092 -C "Processing of the Certificate handshake message failed" \
1093 -c "Ciphersuite is TLS-"
1094
1095run_test "keyUsage cli #5 (DigitalSignature, RSA: fail)" \
1096 "$O_SRV -key data_files/server2.key \
1097 -cert data_files/server2.ku-ds.crt" \
1098 "$P_CLI debug_level=2 \
1099 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1100 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001101 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001102 -c "Processing of the Certificate handshake message failed" \
1103 -C "Ciphersuite is TLS-"
1104
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001105# Tests for keyUsage in leaf certificates, part 3:
1106# server-side checking of client cert
1107
1108run_test "keyUsage cli-auth #1 (RSA, DigitalSignature: OK)" \
1109 "$P_SRV debug_level=2 auth_mode=optional" \
1110 "$O_CLI -key data_files/server2.key \
1111 -cert data_files/server2.ku-ds.crt" \
1112 0 \
1113 -S "bad certificate (usage extensions)" \
1114 -S "Processing of the Certificate handshake message failed"
1115
1116run_test "keyUsage cli-auth #2 (RSA, KeyEncipherment: fail (soft))" \
1117 "$P_SRV debug_level=2 auth_mode=optional" \
1118 "$O_CLI -key data_files/server2.key \
1119 -cert data_files/server2.ku-ke.crt" \
1120 0 \
1121 -s "bad certificate (usage extensions)" \
1122 -S "Processing of the Certificate handshake message failed"
1123
1124run_test "keyUsage cli-auth #3 (RSA, KeyEncipherment: fail (hard))" \
1125 "$P_SRV debug_level=2 auth_mode=required" \
1126 "$O_CLI -key data_files/server2.key \
1127 -cert data_files/server2.ku-ke.crt" \
1128 1 \
1129 -s "bad certificate (usage extensions)" \
1130 -s "Processing of the Certificate handshake message failed"
1131
1132run_test "keyUsage cli-auth #4 (ECDSA, DigitalSignature: OK)" \
1133 "$P_SRV debug_level=2 auth_mode=optional" \
1134 "$O_CLI -key data_files/server5.key \
1135 -cert data_files/server5.ku-ds.crt" \
1136 0 \
1137 -S "bad certificate (usage extensions)" \
1138 -S "Processing of the Certificate handshake message failed"
1139
1140run_test "keyUsage cli-auth #5 (ECDSA, KeyAgreement: fail (soft))" \
1141 "$P_SRV debug_level=2 auth_mode=optional" \
1142 "$O_CLI -key data_files/server5.key \
1143 -cert data_files/server5.ku-ka.crt" \
1144 0 \
1145 -s "bad certificate (usage extensions)" \
1146 -S "Processing of the Certificate handshake message failed"
1147
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001148# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
1149
1150run_test "extKeyUsage srv #1 (serverAuth -> OK)" \
1151 "$P_SRV key_file=data_files/server5.key \
1152 crt_file=data_files/server5.eku-srv.crt" \
1153 "$P_CLI" \
1154 0
1155
1156run_test "extKeyUsage srv #2 (serverAuth,clientAuth -> OK)" \
1157 "$P_SRV key_file=data_files/server5.key \
1158 crt_file=data_files/server5.eku-srv.crt" \
1159 "$P_CLI" \
1160 0
1161
1162run_test "extKeyUsage srv #3 (codeSign,anyEKU -> OK)" \
1163 "$P_SRV key_file=data_files/server5.key \
1164 crt_file=data_files/server5.eku-cs_any.crt" \
1165 "$P_CLI" \
1166 0
1167
1168# add psk to leave an option for client to send SERVERQUIT
1169run_test "extKeyUsage srv #4 (codeSign -> fail)" \
1170 "$P_SRV psk=abc123 key_file=data_files/server5.key \
1171 crt_file=data_files/server5.eku-cli.crt" \
1172 "$P_CLI psk=badbad" \
1173 1
1174
1175# Tests for extendedKeyUsage, part 2: client-side checking of server cert
1176
1177run_test "extKeyUsage cli #1 (serverAuth -> OK)" \
1178 "$O_SRV -key data_files/server5.key \
1179 -cert data_files/server5.eku-srv.crt" \
1180 "$P_CLI debug_level=2" \
1181 0 \
1182 -C "bad certificate (usage extensions)" \
1183 -C "Processing of the Certificate handshake message failed" \
1184 -c "Ciphersuite is TLS-"
1185
1186run_test "extKeyUsage cli #2 (serverAuth,clientAuth -> OK)" \
1187 "$O_SRV -key data_files/server5.key \
1188 -cert data_files/server5.eku-srv_cli.crt" \
1189 "$P_CLI debug_level=2" \
1190 0 \
1191 -C "bad certificate (usage extensions)" \
1192 -C "Processing of the Certificate handshake message failed" \
1193 -c "Ciphersuite is TLS-"
1194
1195run_test "extKeyUsage cli #3 (codeSign,anyEKU -> OK)" \
1196 "$O_SRV -key data_files/server5.key \
1197 -cert data_files/server5.eku-cs_any.crt" \
1198 "$P_CLI debug_level=2" \
1199 0 \
1200 -C "bad certificate (usage extensions)" \
1201 -C "Processing of the Certificate handshake message failed" \
1202 -c "Ciphersuite is TLS-"
1203
1204run_test "extKeyUsage cli #4 (codeSign -> fail)" \
1205 "$O_SRV -key data_files/server5.key \
1206 -cert data_files/server5.eku-cs.crt" \
1207 "$P_CLI debug_level=2" \
1208 1 \
1209 -c "bad certificate (usage extensions)" \
1210 -c "Processing of the Certificate handshake message failed" \
1211 -C "Ciphersuite is TLS-"
1212
1213# Tests for extendedKeyUsage, part 3: server-side checking of client cert
1214
1215run_test "extKeyUsage cli-auth #1 (clientAuth -> OK)" \
1216 "$P_SRV debug_level=2 auth_mode=optional" \
1217 "$O_CLI -key data_files/server5.key \
1218 -cert data_files/server5.eku-cli.crt" \
1219 0 \
1220 -S "bad certificate (usage extensions)" \
1221 -S "Processing of the Certificate handshake message failed"
1222
1223run_test "extKeyUsage cli-auth #2 (serverAuth,clientAuth -> OK)" \
1224 "$P_SRV debug_level=2 auth_mode=optional" \
1225 "$O_CLI -key data_files/server5.key \
1226 -cert data_files/server5.eku-srv_cli.crt" \
1227 0 \
1228 -S "bad certificate (usage extensions)" \
1229 -S "Processing of the Certificate handshake message failed"
1230
1231run_test "extKeyUsage cli-auth #3 (codeSign,anyEKU -> OK)" \
1232 "$P_SRV debug_level=2 auth_mode=optional" \
1233 "$O_CLI -key data_files/server5.key \
1234 -cert data_files/server5.eku-cs_any.crt" \
1235 0 \
1236 -S "bad certificate (usage extensions)" \
1237 -S "Processing of the Certificate handshake message failed"
1238
1239run_test "extKeyUsage cli-auth #4 (codeSign -> fail (soft))" \
1240 "$P_SRV debug_level=2 auth_mode=optional" \
1241 "$O_CLI -key data_files/server5.key \
1242 -cert data_files/server5.eku-cs.crt" \
1243 0 \
1244 -s "bad certificate (usage extensions)" \
1245 -S "Processing of the Certificate handshake message failed"
1246
1247run_test "extKeyUsage cli-auth #4b (codeSign -> fail (hard))" \
1248 "$P_SRV debug_level=2 auth_mode=required" \
1249 "$O_CLI -key data_files/server5.key \
1250 -cert data_files/server5.eku-cs.crt" \
1251 1 \
1252 -s "bad certificate (usage extensions)" \
1253 -s "Processing of the Certificate handshake message failed"
1254
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001255# Final report
1256
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01001257echo "------------------------------------------------------------------------"
1258
1259if [ $FAILS = 0 ]; then
1260 echo -n "PASSED"
1261else
1262 echo -n "FAILED"
1263fi
1264PASSES=`echo $TESTS - $FAILS | bc`
Manuel Pégourié-Gonnard4145b892014-02-24 13:20:14 +01001265echo " ($PASSES / $TESTS tests)"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01001266
1267exit $FAILS