blob: b35a9e4a847016aa6fd501b349052e1ee8336a5f [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 *)
67 echo "Unkown argument: '$1'"
68 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
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100154 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard84fd6872014-03-13 18:35:10 +0100155 "$P_CLI" request_page=SERVERQUIT tickets=0 auth_mode=none \
156 crt_file=data_files/cli2.crt key_file=data_files/cli2.key \
157 >/dev/null
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100158 else
159 kill $SRV_PID
160 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100161 wait $SRV_PID
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100162
163 # check if the client and server went at least to the handshake stage
164 # (usefull to avoid tests with only negative assertions and non-zero
165 # expected client exit to incorrectly succeed in case of catastrophic
166 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100167 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100168 if grep "Performing the SSL/TLS handshake" srv_out >/dev/null; then :;
169 else
170 fail "server failed to start"
171 return
172 fi
173 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100174 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100175 if grep "Performing the SSL/TLS handshake" cli_out >/dev/null; then :;
176 else
177 fail "client failed to start"
178 return
179 fi
180 fi
181
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100182 # check server exit code
183 if [ $? != 0 ]; then
184 fail "server fail"
185 return
186 fi
187
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100188 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100189 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
190 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100191 then
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100192 fail "bad client exit code"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100193 return
194 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100195
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100196 # check other assertions
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100197 while [ $# -gt 0 ]
198 do
199 case $1 in
200 "-s")
201 if grep "$2" srv_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100202 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100203 return
204 fi
205 ;;
206
207 "-c")
208 if grep "$2" cli_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100209 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100210 return
211 fi
212 ;;
213
214 "-S")
215 if grep "$2" srv_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100216 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100217 return
218 fi
219 ;;
220
221 "-C")
222 if grep "$2" cli_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100223 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100224 return
225 fi
226 ;;
227
228 *)
229 echo "Unkown test: $1" >&2
230 exit 1
231 esac
232 shift 2
233 done
234
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100235 # check valgrind's results
236 if [ "$MEMCHECK" -gt 0 ]; then
237 if is_polar "$SRV_CMD" && has_mem_err srv_out; then
238 fail "Server has memory errors"
239 return
240 fi
241 if is_polar "$CLI_CMD" && has_mem_err cli_out; then
242 fail "Client has memory errors"
243 return
244 fi
245 fi
246
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100247 # if we're here, everything is ok
248 echo "PASS"
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100249 rm -f srv_out cli_out
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100250}
251
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100252cleanup() {
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100253 rm -f cli_out srv_out sess
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100254 kill $SRV_PID
255 exit 1
256}
257
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100258#
259# MAIN
260#
261
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100262get_options "$@"
263
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100264# sanity checks, avoid an avalanche of errors
265if [ ! -x "$P_SRV" ]; then
266 echo "Command '$P_SRV' is not an executable file"
267 exit 1
268fi
269if [ ! -x "$P_CLI" ]; then
270 echo "Command '$P_CLI' is not an executable file"
271 exit 1
272fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100273if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
274 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100275 exit 1
276fi
277
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100278killall -q openssl ssl_server ssl_server2
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100279trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100280
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100281# Test for SSLv2 ClientHello
282
283run_test "SSLv2 ClientHello #0 (reference)" \
284 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100285 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100286 0 \
287 -S "parse client hello v2" \
288 -S "ssl_handshake returned"
289
290# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
291run_test "SSLv2 ClientHello #1 (actual test)" \
292 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100293 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100294 0 \
295 -s "parse client hello v2" \
296 -S "ssl_handshake returned"
297
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100298# Tests for Truncated HMAC extension
299
300run_test "Truncated HMAC #0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100301 "$P_SRV debug_level=5" \
302 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100303 0 \
304 -s "dumping 'computed mac' (20 bytes)"
305
306run_test "Truncated HMAC #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100307 "$P_SRV debug_level=5" \
308 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100309 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100310 -s "dumping 'computed mac' (10 bytes)"
311
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100312# Tests for Session Tickets
313
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100314run_test "Session resume using tickets #1 (basic)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100315 "$P_SRV debug_level=4 tickets=1" \
316 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100317 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100318 -c "client hello, adding session ticket extension" \
319 -s "found session ticket extension" \
320 -s "server hello, adding session ticket extension" \
321 -c "found session_ticket extension" \
322 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100323 -S "session successfully restored from cache" \
324 -s "session successfully restored from ticket" \
325 -s "a session has been resumed" \
326 -c "a session has been resumed"
327
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100328run_test "Session resume using tickets #2 (cache disabled)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100329 "$P_SRV debug_level=4 tickets=1 cache_max=0" \
330 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100331 0 \
332 -c "client hello, adding session ticket extension" \
333 -s "found session ticket extension" \
334 -s "server hello, adding session ticket extension" \
335 -c "found session_ticket extension" \
336 -c "parse new session ticket" \
337 -S "session successfully restored from cache" \
338 -s "session successfully restored from ticket" \
339 -s "a session has been resumed" \
340 -c "a session has been resumed"
341
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100342run_test "Session resume using tickets #3 (timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100343 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=1" \
344 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100345 0 \
346 -c "client hello, adding session ticket extension" \
347 -s "found session ticket extension" \
348 -s "server hello, adding session ticket extension" \
349 -c "found session_ticket extension" \
350 -c "parse new session ticket" \
351 -S "session successfully restored from cache" \
352 -S "session successfully restored from ticket" \
353 -S "a session has been resumed" \
354 -C "a session has been resumed"
355
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100356run_test "Session resume using tickets #4 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100357 "$O_SRV" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100358 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
359 0 \
360 -c "client hello, adding session ticket extension" \
361 -c "found session_ticket extension" \
362 -c "parse new session ticket" \
363 -c "a session has been resumed"
364
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100365run_test "Session resume using tickets #5 (openssl client)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100366 "$P_SRV debug_level=4 tickets=1" \
367 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
368 0 \
369 -s "found session ticket extension" \
370 -s "server hello, adding session ticket extension" \
371 -S "session successfully restored from cache" \
372 -s "session successfully restored from ticket" \
373 -s "a session has been resumed"
374
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100375# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100376
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100377run_test "Session resume using cache #1 (tickets enabled on client)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100378 "$P_SRV debug_level=4 tickets=0" \
379 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100380 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100381 -c "client hello, adding session ticket extension" \
382 -s "found session ticket extension" \
383 -S "server hello, adding session ticket extension" \
384 -C "found session_ticket extension" \
385 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100386 -s "session successfully restored from cache" \
387 -S "session successfully restored from ticket" \
388 -s "a session has been resumed" \
389 -c "a session has been resumed"
390
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100391run_test "Session resume using cache #2 (tickets enabled on server)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100392 "$P_SRV debug_level=4 tickets=1" \
393 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100394 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100395 -C "client hello, adding session ticket extension" \
396 -S "found session ticket extension" \
397 -S "server hello, adding session ticket extension" \
398 -C "found session_ticket extension" \
399 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100400 -s "session successfully restored from cache" \
401 -S "session successfully restored from ticket" \
402 -s "a session has been resumed" \
403 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100404
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100405run_test "Session resume using cache #3 (cache_max=0)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100406 "$P_SRV debug_level=4 tickets=0 cache_max=0" \
407 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100408 0 \
409 -S "session successfully restored from cache" \
410 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100411 -S "a session has been resumed" \
412 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100413
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100414run_test "Session resume using cache #4 (cache_max=1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100415 "$P_SRV debug_level=4 tickets=0 cache_max=1" \
416 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100417 0 \
418 -s "session successfully restored from cache" \
419 -S "session successfully restored from ticket" \
420 -s "a session has been resumed" \
421 -c "a session has been resumed"
422
423run_test "Session resume using cache #5 (timemout > delay)" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100424 "$P_SRV debug_level=4 tickets=0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100425 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100426 0 \
427 -s "session successfully restored from cache" \
428 -S "session successfully restored from ticket" \
429 -s "a session has been resumed" \
430 -c "a session has been resumed"
431
432run_test "Session resume using cache #6 (timeout < delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100433 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
434 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100435 0 \
436 -S "session successfully restored from cache" \
437 -S "session successfully restored from ticket" \
438 -S "a session has been resumed" \
439 -C "a session has been resumed"
440
441run_test "Session resume using cache #7 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100442 "$P_SRV debug_level=4 tickets=0 cache_timeout=0" \
443 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100444 0 \
445 -s "session successfully restored from cache" \
446 -S "session successfully restored from ticket" \
447 -s "a session has been resumed" \
448 -c "a session has been resumed"
449
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100450run_test "Session resume using cache #8 (openssl client)" \
451 "$P_SRV debug_level=4 tickets=0" \
452 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
453 0 \
454 -s "found session ticket extension" \
455 -S "server hello, adding session ticket extension" \
456 -s "session successfully restored from cache" \
457 -S "session successfully restored from ticket" \
458 -s "a session has been resumed"
459
460run_test "Session resume using cache #9 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100461 "$O_SRV" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100462 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
463 0 \
464 -C "found session_ticket extension" \
465 -C "parse new session ticket" \
466 -c "a session has been resumed"
467
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100468# Tests for Max Fragment Length extension
469
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100470run_test "Max fragment length #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100471 "$P_SRV debug_level=4" \
472 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100473 0 \
474 -C "client hello, adding max_fragment_length extension" \
475 -S "found max fragment length extension" \
476 -S "server hello, max_fragment_length extension" \
477 -C "found max_fragment_length extension"
478
479run_test "Max fragment length #2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100480 "$P_SRV debug_level=4" \
481 "$P_CLI debug_level=4 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100482 0 \
483 -c "client hello, adding max_fragment_length extension" \
484 -s "found max fragment length extension" \
485 -s "server hello, max_fragment_length extension" \
486 -c "found max_fragment_length extension"
487
488run_test "Max fragment length #3" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100489 "$P_SRV debug_level=4 max_frag_len=4096" \
490 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100491 0 \
492 -C "client hello, adding max_fragment_length extension" \
493 -S "found max fragment length extension" \
494 -S "server hello, max_fragment_length extension" \
495 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100496
497# Tests for renegotiation
498
499run_test "Renegotiation #0 (none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100500 "$P_SRV debug_level=4" \
501 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100502 0 \
503 -C "client hello, adding renegotiation extension" \
504 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
505 -S "found renegotiation extension" \
506 -s "server hello, secure renegotiation extension" \
507 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100508 -C "=> renegotiate" \
509 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100510 -S "write hello request"
511
512run_test "Renegotiation #1 (enabled, client-initiated)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200513 "$P_SRV debug_level=4 renegotiation=1" \
514 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100515 0 \
516 -c "client hello, adding renegotiation extension" \
517 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
518 -s "found renegotiation extension" \
519 -s "server hello, secure renegotiation extension" \
520 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100521 -c "=> renegotiate" \
522 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100523 -S "write hello request"
524
525run_test "Renegotiation #2 (enabled, server-initiated)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200526 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
527 "$P_CLI debug_level=4 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100528 0 \
529 -c "client hello, adding renegotiation extension" \
530 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
531 -s "found renegotiation extension" \
532 -s "server hello, secure renegotiation extension" \
533 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100534 -c "=> renegotiate" \
535 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100536 -s "write hello request"
537
538run_test "Renegotiation #3 (enabled, double)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200539 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
540 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100541 0 \
542 -c "client hello, adding renegotiation extension" \
543 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
544 -s "found renegotiation extension" \
545 -s "server hello, secure renegotiation extension" \
546 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100547 -c "=> renegotiate" \
548 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100549 -s "write hello request"
550
551run_test "Renegotiation #4 (client-initiated, server-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100552 "$P_SRV debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200553 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100554 1 \
555 -c "client hello, adding renegotiation extension" \
556 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
557 -S "found renegotiation extension" \
558 -s "server hello, secure renegotiation extension" \
559 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100560 -c "=> renegotiate" \
561 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100562 -S "write hello request"
563
564run_test "Renegotiation #5 (server-initiated, client-rejected)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200565 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100566 "$P_CLI debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100567 0 \
568 -C "client hello, adding renegotiation extension" \
569 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
570 -S "found renegotiation extension" \
571 -s "server hello, secure renegotiation extension" \
572 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100573 -C "=> renegotiate" \
574 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100575 -s "write hello request" \
576 -s "SSL - An unexpected message was received from our peer" \
577 -s "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100578
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100579# Tests for auth_mode
580
581run_test "Authentication #1 (server badcert, client required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100582 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100583 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100584 "$P_CLI debug_level=2 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100585 1 \
586 -c "x509_verify_cert() returned" \
587 -c "! self-signed or not signed by a trusted CA" \
588 -c "! ssl_handshake returned" \
589 -c "X509 - Certificate verification failed"
590
591run_test "Authentication #2 (server badcert, client optional)" \
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=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100595 0 \
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 #3 (server badcert, client none)" \
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=none" \
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 #4 (client badcert, server required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100612 "$P_SRV debug_level=4 auth_mode=required" \
613 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100614 key_file=data_files/server5.key" \
615 1 \
616 -S "skip write certificate request" \
617 -C "skip parse certificate request" \
618 -c "got a certificate request" \
619 -C "skip write certificate" \
620 -C "skip write certificate verify" \
621 -S "skip parse certificate verify" \
622 -s "x509_verify_cert() returned" \
623 -S "! self-signed or not signed by a trusted CA" \
624 -s "! ssl_handshake returned" \
625 -c "! ssl_handshake returned" \
626 -s "X509 - Certificate verification failed"
627
628run_test "Authentication #5 (client badcert, server optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100629 "$P_SRV debug_level=4 auth_mode=optional" \
630 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100631 key_file=data_files/server5.key" \
632 0 \
633 -S "skip write certificate request" \
634 -C "skip parse certificate request" \
635 -c "got a certificate request" \
636 -C "skip write certificate" \
637 -C "skip write certificate verify" \
638 -S "skip parse certificate verify" \
639 -s "x509_verify_cert() returned" \
640 -s "! self-signed or not signed by a trusted CA" \
641 -S "! ssl_handshake returned" \
642 -C "! ssl_handshake returned" \
643 -S "X509 - Certificate verification failed"
644
645run_test "Authentication #6 (client badcert, server none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100646 "$P_SRV debug_level=4 auth_mode=none" \
647 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100648 key_file=data_files/server5.key" \
649 0 \
650 -s "skip write certificate request" \
651 -C "skip parse certificate request" \
652 -c "got no certificate request" \
653 -c "skip write certificate" \
654 -c "skip write certificate verify" \
655 -s "skip parse certificate verify" \
656 -S "x509_verify_cert() returned" \
657 -S "! self-signed or not signed by a trusted CA" \
658 -S "! ssl_handshake returned" \
659 -C "! ssl_handshake returned" \
660 -S "X509 - Certificate verification failed"
661
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +0100662run_test "Authentication #7 (client no cert, server optional)" \
663 "$P_SRV debug_level=4 auth_mode=optional" \
664 "$P_CLI debug_level=4 crt_file=none key_file=none" \
665 0 \
666 -S "skip write certificate request" \
667 -C "skip parse certificate request" \
668 -c "got a certificate request" \
669 -C "skip write certificate$" \
670 -C "got no certificate to send" \
671 -S "SSLv3 client has no certificate" \
672 -c "skip write certificate verify" \
673 -s "skip parse certificate verify" \
674 -s "! no client certificate sent" \
675 -S "! ssl_handshake returned" \
676 -C "! ssl_handshake returned" \
677 -S "X509 - Certificate verification failed"
678
679run_test "Authentication #8 (openssl client no cert, server optional)" \
680 "$P_SRV debug_level=4 auth_mode=optional" \
681 "$O_CLI" \
682 0 \
683 -S "skip write certificate request" \
684 -s "skip parse certificate verify" \
685 -s "! no client certificate sent" \
686 -S "! ssl_handshake returned" \
687 -S "X509 - Certificate verification failed"
688
689run_test "Authentication #9 (client no cert, openssl server optional)" \
690 "$O_SRV -verify 10" \
691 "$P_CLI debug_level=4 crt_file=none key_file=none" \
692 0 \
693 -C "skip parse certificate request" \
694 -c "got a certificate request" \
695 -C "skip write certificate$" \
696 -c "skip write certificate verify" \
697 -C "! ssl_handshake returned"
698
699run_test "Authentication #10 (client no cert, ssl3)" \
700 "$P_SRV debug_level=4 auth_mode=optional force_version=ssl3" \
701 "$P_CLI debug_level=4 crt_file=none key_file=none" \
702 0 \
703 -S "skip write certificate request" \
704 -C "skip parse certificate request" \
705 -c "got a certificate request" \
706 -C "skip write certificate$" \
707 -c "skip write certificate verify" \
708 -c "got no certificate to send" \
709 -s "SSLv3 client has no certificate" \
710 -s "skip parse certificate verify" \
711 -s "! no client certificate sent" \
712 -S "! ssl_handshake returned" \
713 -C "! ssl_handshake returned" \
714 -S "X509 - Certificate verification failed"
715
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100716# tests for SNI
717
718run_test "SNI #0 (no SNI callback)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100719 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100720 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100721 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100722 server_name=localhost" \
723 0 \
724 -S "parse ServerName extension" \
725 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
726 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
727
728run_test "SNI #1 (matching cert 1)" \
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é-Gonnard76b8ab72014-03-26 09:31:35 +0100731 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 +0100732 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100733 server_name=localhost" \
734 0 \
735 -s "parse ServerName extension" \
736 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
737 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
738
739run_test "SNI #2 (matching cert 2)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100740 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100741 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100742 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 +0100743 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100744 server_name=polarssl.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100745 0 \
746 -s "parse ServerName extension" \
747 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100748 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100749
750run_test "SNI #3 (no matching cert)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100751 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100752 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100753 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 +0100754 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100755 server_name=nonesuch.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100756 1 \
757 -s "parse ServerName extension" \
758 -s "ssl_sni_wrapper() returned" \
759 -s "ssl_handshake returned" \
760 -c "ssl_handshake returned" \
761 -c "SSL - A fatal alert message was received from our peer"
762
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +0100763# Tests for non-blocking I/O: exercise a variety of handshake flows
764
765run_test "Non-blocking I/O #1 (basic handshake)" \
766 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
767 "$P_CLI nbio=2 tickets=0" \
768 0 \
769 -S "ssl_handshake returned" \
770 -C "ssl_handshake returned" \
771 -c "Read from server: .* bytes read"
772
773run_test "Non-blocking I/O #2 (client auth)" \
774 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
775 "$P_CLI nbio=2 tickets=0" \
776 0 \
777 -S "ssl_handshake returned" \
778 -C "ssl_handshake returned" \
779 -c "Read from server: .* bytes read"
780
781run_test "Non-blocking I/O #3 (ticket)" \
782 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
783 "$P_CLI nbio=2 tickets=1" \
784 0 \
785 -S "ssl_handshake returned" \
786 -C "ssl_handshake returned" \
787 -c "Read from server: .* bytes read"
788
789run_test "Non-blocking I/O #4 (ticket + client auth)" \
790 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
791 "$P_CLI nbio=2 tickets=1" \
792 0 \
793 -S "ssl_handshake returned" \
794 -C "ssl_handshake returned" \
795 -c "Read from server: .* bytes read"
796
797run_test "Non-blocking I/O #5 (ticket + client auth + resume)" \
798 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
799 "$P_CLI nbio=2 tickets=1 reconnect=1" \
800 0 \
801 -S "ssl_handshake returned" \
802 -C "ssl_handshake returned" \
803 -c "Read from server: .* bytes read"
804
805run_test "Non-blocking I/O #6 (ticket + resume)" \
806 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
807 "$P_CLI nbio=2 tickets=1 reconnect=1" \
808 0 \
809 -S "ssl_handshake returned" \
810 -C "ssl_handshake returned" \
811 -c "Read from server: .* bytes read"
812
813run_test "Non-blocking I/O #7 (session-id resume)" \
814 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
815 "$P_CLI nbio=2 tickets=0 reconnect=1" \
816 0 \
817 -S "ssl_handshake returned" \
818 -C "ssl_handshake returned" \
819 -c "Read from server: .* bytes read"
820
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200821# Tests for version negotiation
822
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100823run_test "Version check #1 (all -> 1.2)" \
824 "$P_SRV" \
825 "$P_CLI" \
826 0 \
827 -S "ssl_handshake returned" \
828 -C "ssl_handshake returned" \
829 -s "Protocol is TLSv1.2" \
830 -c "Protocol is TLSv1.2"
831
832run_test "Version check #2 (cli max 1.1 -> 1.1)" \
833 "$P_SRV" \
834 "$P_CLI max_version=tls1_1" \
835 0 \
836 -S "ssl_handshake returned" \
837 -C "ssl_handshake returned" \
838 -s "Protocol is TLSv1.1" \
839 -c "Protocol is TLSv1.1"
840
841run_test "Version check #3 (srv max 1.1 -> 1.1)" \
842 "$P_SRV max_version=tls1_1" \
843 "$P_CLI" \
844 0 \
845 -S "ssl_handshake returned" \
846 -C "ssl_handshake returned" \
847 -s "Protocol is TLSv1.1" \
848 -c "Protocol is TLSv1.1"
849
850run_test "Version check #4 (cli+srv max 1.1 -> 1.1)" \
851 "$P_SRV max_version=tls1_1" \
852 "$P_CLI max_version=tls1_1" \
853 0 \
854 -S "ssl_handshake returned" \
855 -C "ssl_handshake returned" \
856 -s "Protocol is TLSv1.1" \
857 -c "Protocol is TLSv1.1"
858
859run_test "Version check #5 (cli max 1.1, srv min 1.1 -> 1.1)" \
860 "$P_SRV min_version=tls1_1" \
861 "$P_CLI max_version=tls1_1" \
862 0 \
863 -S "ssl_handshake returned" \
864 -C "ssl_handshake returned" \
865 -s "Protocol is TLSv1.1" \
866 -c "Protocol is TLSv1.1"
867
868run_test "Version check #6 (cli min 1.1, srv max 1.1 -> 1.1)" \
869 "$P_SRV max_version=tls1_1" \
870 "$P_CLI min_version=tls1_1" \
871 0 \
872 -S "ssl_handshake returned" \
873 -C "ssl_handshake returned" \
874 -s "Protocol is TLSv1.1" \
875 -c "Protocol is TLSv1.1"
876
877run_test "Version check #7 (cli min 1.2, srv max 1.1 -> fail)" \
878 "$P_SRV max_version=tls1_1" \
879 "$P_CLI min_version=tls1_2" \
880 1 \
881 -s "ssl_handshake returned" \
882 -c "ssl_handshake returned" \
883 -c "SSL - Handshake protocol not within min/max boundaries"
884
885run_test "Version check #8 (srv min 1.2, cli max 1.1 -> fail)" \
886 "$P_SRV min_version=tls1_2" \
887 "$P_CLI max_version=tls1_1" \
888 1 \
889 -s "ssl_handshake returned" \
890 -c "ssl_handshake returned" \
891 -s "SSL - Handshake protocol not within min/max boundaries"
892
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200893# Tests for ALPN extension
894
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +0200895if grep '^#define POLARSSL_SSL_ALPN' $CONFIG_H >/dev/null; then
896
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200897run_test "ALPN #0 (none)" \
898 "$P_SRV debug_level=4" \
899 "$P_CLI debug_level=4" \
900 0 \
901 -C "client hello, adding alpn extension" \
902 -S "found alpn extension" \
903 -C "got an alert message, type: \\[2:120]" \
904 -S "server hello, adding alpn extension" \
905 -C "found alpn extension " \
906 -C "Application Layer Protocol is" \
907 -S "Application Layer Protocol is"
908
909run_test "ALPN #1 (client only)" \
910 "$P_SRV debug_level=4" \
911 "$P_CLI debug_level=4 alpn=abc,1234" \
912 0 \
913 -c "client hello, adding alpn extension" \
914 -s "found alpn extension" \
915 -C "got an alert message, type: \\[2:120]" \
916 -S "server hello, adding alpn extension" \
917 -C "found alpn extension " \
918 -c "Application Layer Protocol is (none)" \
919 -S "Application Layer Protocol is"
920
921run_test "ALPN #2 (server only)" \
922 "$P_SRV debug_level=4 alpn=abc,1234" \
923 "$P_CLI debug_level=4" \
924 0 \
925 -C "client hello, adding alpn extension" \
926 -S "found alpn extension" \
927 -C "got an alert message, type: \\[2:120]" \
928 -S "server hello, adding alpn extension" \
929 -C "found alpn extension " \
930 -C "Application Layer Protocol is" \
931 -s "Application Layer Protocol is (none)"
932
933run_test "ALPN #3 (both, common cli1-srv1)" \
934 "$P_SRV debug_level=4 alpn=abc,1234" \
935 "$P_CLI debug_level=4 alpn=abc,1234" \
936 0 \
937 -c "client hello, adding alpn extension" \
938 -s "found alpn extension" \
939 -C "got an alert message, type: \\[2:120]" \
940 -s "server hello, adding alpn extension" \
941 -c "found alpn extension" \
942 -c "Application Layer Protocol is abc" \
943 -s "Application Layer Protocol is abc"
944
945run_test "ALPN #4 (both, common cli2-srv1)" \
946 "$P_SRV debug_level=4 alpn=abc,1234" \
947 "$P_CLI debug_level=4 alpn=1234,abc" \
948 0 \
949 -c "client hello, adding alpn extension" \
950 -s "found alpn extension" \
951 -C "got an alert message, type: \\[2:120]" \
952 -s "server hello, adding alpn extension" \
953 -c "found alpn extension" \
954 -c "Application Layer Protocol is abc" \
955 -s "Application Layer Protocol is abc"
956
957run_test "ALPN #5 (both, common cli1-srv2)" \
958 "$P_SRV debug_level=4 alpn=abc,1234" \
959 "$P_CLI debug_level=4 alpn=1234,abcde" \
960 0 \
961 -c "client hello, adding alpn extension" \
962 -s "found alpn extension" \
963 -C "got an alert message, type: \\[2:120]" \
964 -s "server hello, adding alpn extension" \
965 -c "found alpn extension" \
966 -c "Application Layer Protocol is 1234" \
967 -s "Application Layer Protocol is 1234"
968
969run_test "ALPN #6 (both, no common)" \
970 "$P_SRV debug_level=4 alpn=abc,123" \
971 "$P_CLI debug_level=4 alpn=1234,abcde" \
972 1 \
973 -c "client hello, adding alpn extension" \
974 -s "found alpn extension" \
975 -c "got an alert message, type: \\[2:120]" \
976 -S "server hello, adding alpn extension" \
977 -C "found alpn extension" \
978 -C "Application Layer Protocol is 1234" \
979 -S "Application Layer Protocol is 1234"
980
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +0200981fi
982
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100983# Final report
984
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100985echo "------------------------------------------------------------------------"
986
987if [ $FAILS = 0 ]; then
988 echo -n "PASSED"
989else
990 echo -n "FAILED"
991fi
992PASSES=`echo $TESTS - $FAILS | bc`
Manuel Pégourié-Gonnard4145b892014-02-24 13:20:14 +0100993echo " ($PASSES / $TESTS tests)"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100994
995exit $FAILS