blob: 916ce77eca187d9fbc13f5cd74afcd9042ff84ba [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é-Gonnardf7a26902014-02-27 12:25:54 +010013# default values, can be overriden by the environment
14: ${P_SRV:=../programs/ssl/ssl_server2}
15: ${P_CLI:=../programs/ssl/ssl_client2}
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010016: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010017
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010018O_SRV="$OPENSSL_CMD s_server -www -cert data_files/server5.crt -key data_files/server5.key"
19O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_CMD s_client"
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010020
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010021TESTS=0
22FAILS=0
23
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +020024CONFIG_H='../include/polarssl/config.h'
25
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010026MEMCHECK=0
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010027FILTER='.*'
28EXCLUDE='SSLv2' # disabled by default, needs OpenSSL compiled with SSLv2
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010029
30print_usage() {
31 echo "Usage: $0 [options]"
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010032 echo -e " -h|--help\tPrint this help."
33 echo -e " -m|--memcheck\tCheck memory leaks and errors."
34 echo -e " -f|--filter\tOnly matching tests are executed (default: '$FILTER')"
35 echo -e " -e|--exclude\tMatching tests are excluded (default: '$EXCLUDE')"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010036}
37
38get_options() {
39 while [ $# -gt 0 ]; do
40 case "$1" in
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010041 -f|--filter)
42 shift; FILTER=$1
43 ;;
44 -e|--exclude)
45 shift; EXCLUDE=$1
46 ;;
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010047 -m|--memcheck)
48 MEMCHECK=1
49 ;;
50 -h|--help)
51 print_usage
52 exit 0
53 ;;
54 *)
55 echo "Unkown argument: '$1'"
56 print_usage
57 exit 1
58 ;;
59 esac
60 shift
61 done
62}
63
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010064# print_name <name>
65print_name() {
66 echo -n "$1 "
67 LEN=`echo "$1" | wc -c`
68 LEN=`echo 72 - $LEN | bc`
69 for i in `seq 1 $LEN`; do echo -n '.'; done
70 echo -n ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010071
72 TESTS=`echo $TESTS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010073}
74
75# fail <message>
76fail() {
77 echo "FAIL"
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +010078 echo " ! $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010079
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +010080 cp srv_out o-srv-${TESTS}.log
81 cp cli_out o-cli-${TESTS}.log
82 echo " ! outputs saved to o-srv-${TESTS}.log and o-cli-${TESTS}.log"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010083
84 FAILS=`echo $FAILS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010085}
86
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +010087# is_polar <cmd_line>
88is_polar() {
89 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
90}
91
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010092# has_mem_err <log_file_name>
93has_mem_err() {
94 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
95 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
96 then
97 return 1 # false: does not have errors
98 else
99 return 0 # true: has errors
100 fi
101}
102
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100103# Usage: run_test name srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100104# Options: -s pattern pattern that must be present in server output
105# -c pattern pattern that must be present in client output
106# -S pattern pattern that must be absent in server output
107# -C pattern pattern that must be absent in client output
108run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100109 NAME="$1"
110 SRV_CMD="$2"
111 CLI_CMD="$3"
112 CLI_EXPECT="$4"
113 shift 4
114
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100115 if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
116 else
117 return
118 fi
119
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100120 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100121
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100122 # prepend valgrind to our commands if active
123 if [ "$MEMCHECK" -gt 0 ]; then
124 if is_polar "$SRV_CMD"; then
125 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
126 fi
127 if is_polar "$CLI_CMD"; then
128 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
129 fi
130 fi
131
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100132 # run the commands
Manuel Pégourié-Gonnardba0b8442014-03-13 17:57:45 +0100133 echo "$SRV_CMD" > srv_out
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100134 $SRV_CMD >> srv_out 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100135 SRV_PID=$!
136 sleep 1
Manuel Pégourié-Gonnardba0b8442014-03-13 17:57:45 +0100137 echo "$CLI_CMD" > cli_out
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100138 eval "$CLI_CMD" >> cli_out 2>&1
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100139 CLI_EXIT=$?
Manuel Pégourié-Gonnarde01af4c2014-03-25 14:16:44 +0100140 echo "EXIT: $CLI_EXIT" >> cli_out
141
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100142 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard84fd6872014-03-13 18:35:10 +0100143 "$P_CLI" request_page=SERVERQUIT tickets=0 auth_mode=none \
144 crt_file=data_files/cli2.crt key_file=data_files/cli2.key \
145 >/dev/null
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100146 else
147 kill $SRV_PID
148 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100149 wait $SRV_PID
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100150
151 # check if the client and server went at least to the handshake stage
152 # (usefull to avoid tests with only negative assertions and non-zero
153 # expected client exit to incorrectly succeed in case of catastrophic
154 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100155 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100156 if grep "Performing the SSL/TLS handshake" srv_out >/dev/null; then :;
157 else
158 fail "server failed to start"
159 return
160 fi
161 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100162 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100163 if grep "Performing the SSL/TLS handshake" cli_out >/dev/null; then :;
164 else
165 fail "client failed to start"
166 return
167 fi
168 fi
169
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100170 # check server exit code
171 if [ $? != 0 ]; then
172 fail "server fail"
173 return
174 fi
175
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100176 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100177 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
178 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100179 then
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100180 fail "bad client exit code"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100181 return
182 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100183
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100184 # check other assertions
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100185 while [ $# -gt 0 ]
186 do
187 case $1 in
188 "-s")
189 if grep "$2" srv_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100190 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100191 return
192 fi
193 ;;
194
195 "-c")
196 if grep "$2" cli_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100197 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100198 return
199 fi
200 ;;
201
202 "-S")
203 if grep "$2" srv_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100204 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100205 return
206 fi
207 ;;
208
209 "-C")
210 if grep "$2" cli_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100211 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100212 return
213 fi
214 ;;
215
216 *)
217 echo "Unkown test: $1" >&2
218 exit 1
219 esac
220 shift 2
221 done
222
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100223 # check valgrind's results
224 if [ "$MEMCHECK" -gt 0 ]; then
225 if is_polar "$SRV_CMD" && has_mem_err srv_out; then
226 fail "Server has memory errors"
227 return
228 fi
229 if is_polar "$CLI_CMD" && has_mem_err cli_out; then
230 fail "Client has memory errors"
231 return
232 fi
233 fi
234
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100235 # if we're here, everything is ok
236 echo "PASS"
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100237 rm -f srv_out cli_out
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100238}
239
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100240cleanup() {
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100241 rm -f cli_out srv_out sess
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100242 kill $SRV_PID
243 exit 1
244}
245
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100246#
247# MAIN
248#
249
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100250# sanity checks, avoid an avalanche of errors
251if [ ! -x "$P_SRV" ]; then
252 echo "Command '$P_SRV' is not an executable file"
253 exit 1
254fi
255if [ ! -x "$P_CLI" ]; then
256 echo "Command '$P_CLI' is not an executable file"
257 exit 1
258fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100259if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
260 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100261 exit 1
262fi
263
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100264get_options "$@"
265
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100266killall -q openssl ssl_server ssl_server2
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100267trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100268
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100269# Test for SSLv2 ClientHello
270
271run_test "SSLv2 ClientHello #0 (reference)" \
272 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100273 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100274 0 \
275 -S "parse client hello v2" \
276 -S "ssl_handshake returned"
277
278# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
279run_test "SSLv2 ClientHello #1 (actual test)" \
280 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100281 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100282 0 \
283 -s "parse client hello v2" \
284 -S "ssl_handshake returned"
285
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100286# Tests for Truncated HMAC extension
287
288run_test "Truncated HMAC #0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100289 "$P_SRV debug_level=5" \
290 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100291 0 \
292 -s "dumping 'computed mac' (20 bytes)"
293
294run_test "Truncated HMAC #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100295 "$P_SRV debug_level=5" \
296 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100297 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100298 -s "dumping 'computed mac' (10 bytes)"
299
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100300# Tests for Session Tickets
301
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100302run_test "Session resume using tickets #1 (basic)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100303 "$P_SRV debug_level=4 tickets=1" \
304 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100305 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100306 -c "client hello, adding session ticket extension" \
307 -s "found session ticket extension" \
308 -s "server hello, adding session ticket extension" \
309 -c "found session_ticket extension" \
310 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100311 -S "session successfully restored from cache" \
312 -s "session successfully restored from ticket" \
313 -s "a session has been resumed" \
314 -c "a session has been resumed"
315
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100316run_test "Session resume using tickets #2 (cache disabled)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100317 "$P_SRV debug_level=4 tickets=1 cache_max=0" \
318 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100319 0 \
320 -c "client hello, adding session ticket extension" \
321 -s "found session ticket extension" \
322 -s "server hello, adding session ticket extension" \
323 -c "found session_ticket extension" \
324 -c "parse new session ticket" \
325 -S "session successfully restored from cache" \
326 -s "session successfully restored from ticket" \
327 -s "a session has been resumed" \
328 -c "a session has been resumed"
329
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100330run_test "Session resume using tickets #3 (timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100331 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=1" \
332 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100333 0 \
334 -c "client hello, adding session ticket extension" \
335 -s "found session ticket extension" \
336 -s "server hello, adding session ticket extension" \
337 -c "found session_ticket extension" \
338 -c "parse new session ticket" \
339 -S "session successfully restored from cache" \
340 -S "session successfully restored from ticket" \
341 -S "a session has been resumed" \
342 -C "a session has been resumed"
343
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100344run_test "Session resume using tickets #4 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100345 "$O_SRV" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100346 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
347 0 \
348 -c "client hello, adding session ticket extension" \
349 -c "found session_ticket extension" \
350 -c "parse new session ticket" \
351 -c "a session has been resumed"
352
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100353run_test "Session resume using tickets #5 (openssl client)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100354 "$P_SRV debug_level=4 tickets=1" \
355 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
356 0 \
357 -s "found session ticket extension" \
358 -s "server hello, adding session ticket extension" \
359 -S "session successfully restored from cache" \
360 -s "session successfully restored from ticket" \
361 -s "a session has been resumed"
362
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100363# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100364
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100365run_test "Session resume using cache #1 (tickets enabled on client)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100366 "$P_SRV debug_level=4 tickets=0" \
367 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100368 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100369 -c "client hello, adding session ticket extension" \
370 -s "found session ticket extension" \
371 -S "server hello, adding session ticket extension" \
372 -C "found session_ticket extension" \
373 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100374 -s "session successfully restored from cache" \
375 -S "session successfully restored from ticket" \
376 -s "a session has been resumed" \
377 -c "a session has been resumed"
378
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100379run_test "Session resume using cache #2 (tickets enabled on server)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100380 "$P_SRV debug_level=4 tickets=1" \
381 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100382 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100383 -C "client hello, adding session ticket extension" \
384 -S "found session ticket extension" \
385 -S "server hello, adding session ticket extension" \
386 -C "found session_ticket extension" \
387 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100388 -s "session successfully restored from cache" \
389 -S "session successfully restored from ticket" \
390 -s "a session has been resumed" \
391 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100392
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100393run_test "Session resume using cache #3 (cache_max=0)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100394 "$P_SRV debug_level=4 tickets=0 cache_max=0" \
395 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100396 0 \
397 -S "session successfully restored from cache" \
398 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100399 -S "a session has been resumed" \
400 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100401
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100402run_test "Session resume using cache #4 (cache_max=1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100403 "$P_SRV debug_level=4 tickets=0 cache_max=1" \
404 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100405 0 \
406 -s "session successfully restored from cache" \
407 -S "session successfully restored from ticket" \
408 -s "a session has been resumed" \
409 -c "a session has been resumed"
410
411run_test "Session resume using cache #5 (timemout > delay)" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100412 "$P_SRV debug_level=4 tickets=0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100413 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100414 0 \
415 -s "session successfully restored from cache" \
416 -S "session successfully restored from ticket" \
417 -s "a session has been resumed" \
418 -c "a session has been resumed"
419
420run_test "Session resume using cache #6 (timeout < delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100421 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
422 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100423 0 \
424 -S "session successfully restored from cache" \
425 -S "session successfully restored from ticket" \
426 -S "a session has been resumed" \
427 -C "a session has been resumed"
428
429run_test "Session resume using cache #7 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100430 "$P_SRV debug_level=4 tickets=0 cache_timeout=0" \
431 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100432 0 \
433 -s "session successfully restored from cache" \
434 -S "session successfully restored from ticket" \
435 -s "a session has been resumed" \
436 -c "a session has been resumed"
437
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100438run_test "Session resume using cache #8 (openssl client)" \
439 "$P_SRV debug_level=4 tickets=0" \
440 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
441 0 \
442 -s "found session ticket extension" \
443 -S "server hello, adding session ticket extension" \
444 -s "session successfully restored from cache" \
445 -S "session successfully restored from ticket" \
446 -s "a session has been resumed"
447
448run_test "Session resume using cache #9 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100449 "$O_SRV" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100450 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
451 0 \
452 -C "found session_ticket extension" \
453 -C "parse new session ticket" \
454 -c "a session has been resumed"
455
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100456# Tests for Max Fragment Length extension
457
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100458run_test "Max fragment length #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100459 "$P_SRV debug_level=4" \
460 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100461 0 \
462 -C "client hello, adding max_fragment_length extension" \
463 -S "found max fragment length extension" \
464 -S "server hello, max_fragment_length extension" \
465 -C "found max_fragment_length extension"
466
467run_test "Max fragment length #2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100468 "$P_SRV debug_level=4" \
469 "$P_CLI debug_level=4 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100470 0 \
471 -c "client hello, adding max_fragment_length extension" \
472 -s "found max fragment length extension" \
473 -s "server hello, max_fragment_length extension" \
474 -c "found max_fragment_length extension"
475
476run_test "Max fragment length #3" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100477 "$P_SRV debug_level=4 max_frag_len=4096" \
478 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100479 0 \
480 -C "client hello, adding max_fragment_length extension" \
481 -S "found max fragment length extension" \
482 -S "server hello, max_fragment_length extension" \
483 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100484
485# Tests for renegotiation
486
487run_test "Renegotiation #0 (none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100488 "$P_SRV debug_level=4" \
489 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100490 0 \
491 -C "client hello, adding renegotiation extension" \
492 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
493 -S "found renegotiation extension" \
494 -s "server hello, secure renegotiation extension" \
495 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100496 -C "=> renegotiate" \
497 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100498 -S "write hello request"
499
500run_test "Renegotiation #1 (enabled, client-initiated)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200501 "$P_SRV debug_level=4 renegotiation=1" \
502 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100503 0 \
504 -c "client hello, adding renegotiation extension" \
505 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
506 -s "found renegotiation extension" \
507 -s "server hello, secure renegotiation extension" \
508 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100509 -c "=> renegotiate" \
510 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100511 -S "write hello request"
512
513run_test "Renegotiation #2 (enabled, server-initiated)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200514 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
515 "$P_CLI debug_level=4 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100516 0 \
517 -c "client hello, adding renegotiation extension" \
518 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
519 -s "found renegotiation extension" \
520 -s "server hello, secure renegotiation extension" \
521 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100522 -c "=> renegotiate" \
523 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100524 -s "write hello request"
525
526run_test "Renegotiation #3 (enabled, double)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200527 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
528 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100529 0 \
530 -c "client hello, adding renegotiation extension" \
531 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
532 -s "found renegotiation extension" \
533 -s "server hello, secure renegotiation extension" \
534 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100535 -c "=> renegotiate" \
536 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100537 -s "write hello request"
538
539run_test "Renegotiation #4 (client-initiated, server-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100540 "$P_SRV debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200541 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100542 1 \
543 -c "client hello, adding renegotiation extension" \
544 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
545 -S "found renegotiation extension" \
546 -s "server hello, secure renegotiation extension" \
547 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100548 -c "=> renegotiate" \
549 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100550 -S "write hello request"
551
552run_test "Renegotiation #5 (server-initiated, client-rejected)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200553 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100554 "$P_CLI debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100555 0 \
556 -C "client hello, adding renegotiation extension" \
557 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
558 -S "found renegotiation extension" \
559 -s "server hello, secure renegotiation extension" \
560 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100561 -C "=> renegotiate" \
562 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100563 -s "write hello request" \
564 -s "SSL - An unexpected message was received from our peer" \
565 -s "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100566
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100567# Tests for auth_mode
568
569run_test "Authentication #1 (server badcert, client required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100570 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100571 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100572 "$P_CLI debug_level=2 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100573 1 \
574 -c "x509_verify_cert() returned" \
575 -c "! self-signed or not signed by a trusted CA" \
576 -c "! ssl_handshake returned" \
577 -c "X509 - Certificate verification failed"
578
579run_test "Authentication #2 (server badcert, client optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100580 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100581 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100582 "$P_CLI debug_level=2 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100583 0 \
584 -c "x509_verify_cert() returned" \
585 -c "! self-signed or not signed by a trusted CA" \
586 -C "! ssl_handshake returned" \
587 -C "X509 - Certificate verification failed"
588
589run_test "Authentication #3 (server badcert, client none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100590 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100591 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100592 "$P_CLI debug_level=2 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100593 0 \
594 -C "x509_verify_cert() returned" \
595 -C "! self-signed or not signed by a trusted CA" \
596 -C "! ssl_handshake returned" \
597 -C "X509 - Certificate verification failed"
598
599run_test "Authentication #4 (client badcert, server required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100600 "$P_SRV debug_level=4 auth_mode=required" \
601 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100602 key_file=data_files/server5.key" \
603 1 \
604 -S "skip write certificate request" \
605 -C "skip parse certificate request" \
606 -c "got a certificate request" \
607 -C "skip write certificate" \
608 -C "skip write certificate verify" \
609 -S "skip parse certificate verify" \
610 -s "x509_verify_cert() returned" \
611 -S "! self-signed or not signed by a trusted CA" \
612 -s "! ssl_handshake returned" \
613 -c "! ssl_handshake returned" \
614 -s "X509 - Certificate verification failed"
615
616run_test "Authentication #5 (client badcert, server optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100617 "$P_SRV debug_level=4 auth_mode=optional" \
618 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100619 key_file=data_files/server5.key" \
620 0 \
621 -S "skip write certificate request" \
622 -C "skip parse certificate request" \
623 -c "got a certificate request" \
624 -C "skip write certificate" \
625 -C "skip write certificate verify" \
626 -S "skip parse certificate verify" \
627 -s "x509_verify_cert() returned" \
628 -s "! self-signed or not signed by a trusted CA" \
629 -S "! ssl_handshake returned" \
630 -C "! ssl_handshake returned" \
631 -S "X509 - Certificate verification failed"
632
633run_test "Authentication #6 (client badcert, server none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100634 "$P_SRV debug_level=4 auth_mode=none" \
635 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100636 key_file=data_files/server5.key" \
637 0 \
638 -s "skip write certificate request" \
639 -C "skip parse certificate request" \
640 -c "got no certificate request" \
641 -c "skip write certificate" \
642 -c "skip write certificate verify" \
643 -s "skip parse certificate verify" \
644 -S "x509_verify_cert() returned" \
645 -S "! self-signed or not signed by a trusted CA" \
646 -S "! ssl_handshake returned" \
647 -C "! ssl_handshake returned" \
648 -S "X509 - Certificate verification failed"
649
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +0100650run_test "Authentication #7 (client no cert, server optional)" \
651 "$P_SRV debug_level=4 auth_mode=optional" \
652 "$P_CLI debug_level=4 crt_file=none key_file=none" \
653 0 \
654 -S "skip write certificate request" \
655 -C "skip parse certificate request" \
656 -c "got a certificate request" \
657 -C "skip write certificate$" \
658 -C "got no certificate to send" \
659 -S "SSLv3 client has no certificate" \
660 -c "skip write certificate verify" \
661 -s "skip parse certificate verify" \
662 -s "! no client certificate sent" \
663 -S "! ssl_handshake returned" \
664 -C "! ssl_handshake returned" \
665 -S "X509 - Certificate verification failed"
666
667run_test "Authentication #8 (openssl client no cert, server optional)" \
668 "$P_SRV debug_level=4 auth_mode=optional" \
669 "$O_CLI" \
670 0 \
671 -S "skip write certificate request" \
672 -s "skip parse certificate verify" \
673 -s "! no client certificate sent" \
674 -S "! ssl_handshake returned" \
675 -S "X509 - Certificate verification failed"
676
677run_test "Authentication #9 (client no cert, openssl server optional)" \
678 "$O_SRV -verify 10" \
679 "$P_CLI debug_level=4 crt_file=none key_file=none" \
680 0 \
681 -C "skip parse certificate request" \
682 -c "got a certificate request" \
683 -C "skip write certificate$" \
684 -c "skip write certificate verify" \
685 -C "! ssl_handshake returned"
686
687run_test "Authentication #10 (client no cert, ssl3)" \
688 "$P_SRV debug_level=4 auth_mode=optional force_version=ssl3" \
689 "$P_CLI debug_level=4 crt_file=none key_file=none" \
690 0 \
691 -S "skip write certificate request" \
692 -C "skip parse certificate request" \
693 -c "got a certificate request" \
694 -C "skip write certificate$" \
695 -c "skip write certificate verify" \
696 -c "got no certificate to send" \
697 -s "SSLv3 client has no certificate" \
698 -s "skip parse certificate verify" \
699 -s "! no client certificate sent" \
700 -S "! ssl_handshake returned" \
701 -C "! ssl_handshake returned" \
702 -S "X509 - Certificate verification failed"
703
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100704# tests for SNI
705
706run_test "SNI #0 (no SNI callback)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100707 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100708 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100709 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100710 server_name=localhost" \
711 0 \
712 -S "parse ServerName extension" \
713 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
714 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
715
716run_test "SNI #1 (matching cert 1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100717 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100718 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100719 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 +0100720 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100721 server_name=localhost" \
722 0 \
723 -s "parse ServerName extension" \
724 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
725 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
726
727run_test "SNI #2 (matching cert 2)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100728 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100729 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100730 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 +0100731 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100732 server_name=polarssl.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100733 0 \
734 -s "parse ServerName extension" \
735 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100736 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100737
738run_test "SNI #3 (no matching cert)" \
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é-Gonnard76b8ab72014-03-26 09:31:35 +0100743 server_name=nonesuch.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100744 1 \
745 -s "parse ServerName extension" \
746 -s "ssl_sni_wrapper() returned" \
747 -s "ssl_handshake returned" \
748 -c "ssl_handshake returned" \
749 -c "SSL - A fatal alert message was received from our peer"
750
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +0100751# Tests for non-blocking I/O: exercise a variety of handshake flows
752
753run_test "Non-blocking I/O #1 (basic handshake)" \
754 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
755 "$P_CLI nbio=2 tickets=0" \
756 0 \
757 -S "ssl_handshake returned" \
758 -C "ssl_handshake returned" \
759 -c "Read from server: .* bytes read"
760
761run_test "Non-blocking I/O #2 (client auth)" \
762 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
763 "$P_CLI nbio=2 tickets=0" \
764 0 \
765 -S "ssl_handshake returned" \
766 -C "ssl_handshake returned" \
767 -c "Read from server: .* bytes read"
768
769run_test "Non-blocking I/O #3 (ticket)" \
770 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
771 "$P_CLI nbio=2 tickets=1" \
772 0 \
773 -S "ssl_handshake returned" \
774 -C "ssl_handshake returned" \
775 -c "Read from server: .* bytes read"
776
777run_test "Non-blocking I/O #4 (ticket + client auth)" \
778 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
779 "$P_CLI nbio=2 tickets=1" \
780 0 \
781 -S "ssl_handshake returned" \
782 -C "ssl_handshake returned" \
783 -c "Read from server: .* bytes read"
784
785run_test "Non-blocking I/O #5 (ticket + client auth + resume)" \
786 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
787 "$P_CLI nbio=2 tickets=1 reconnect=1" \
788 0 \
789 -S "ssl_handshake returned" \
790 -C "ssl_handshake returned" \
791 -c "Read from server: .* bytes read"
792
793run_test "Non-blocking I/O #6 (ticket + resume)" \
794 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
795 "$P_CLI nbio=2 tickets=1 reconnect=1" \
796 0 \
797 -S "ssl_handshake returned" \
798 -C "ssl_handshake returned" \
799 -c "Read from server: .* bytes read"
800
801run_test "Non-blocking I/O #7 (session-id resume)" \
802 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
803 "$P_CLI nbio=2 tickets=0 reconnect=1" \
804 0 \
805 -S "ssl_handshake returned" \
806 -C "ssl_handshake returned" \
807 -c "Read from server: .* bytes read"
808
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200809# Tests for version negotiation
810
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100811run_test "Version check #1 (all -> 1.2)" \
812 "$P_SRV" \
813 "$P_CLI" \
814 0 \
815 -S "ssl_handshake returned" \
816 -C "ssl_handshake returned" \
817 -s "Protocol is TLSv1.2" \
818 -c "Protocol is TLSv1.2"
819
820run_test "Version check #2 (cli max 1.1 -> 1.1)" \
821 "$P_SRV" \
822 "$P_CLI max_version=tls1_1" \
823 0 \
824 -S "ssl_handshake returned" \
825 -C "ssl_handshake returned" \
826 -s "Protocol is TLSv1.1" \
827 -c "Protocol is TLSv1.1"
828
829run_test "Version check #3 (srv max 1.1 -> 1.1)" \
830 "$P_SRV max_version=tls1_1" \
831 "$P_CLI" \
832 0 \
833 -S "ssl_handshake returned" \
834 -C "ssl_handshake returned" \
835 -s "Protocol is TLSv1.1" \
836 -c "Protocol is TLSv1.1"
837
838run_test "Version check #4 (cli+srv max 1.1 -> 1.1)" \
839 "$P_SRV max_version=tls1_1" \
840 "$P_CLI max_version=tls1_1" \
841 0 \
842 -S "ssl_handshake returned" \
843 -C "ssl_handshake returned" \
844 -s "Protocol is TLSv1.1" \
845 -c "Protocol is TLSv1.1"
846
847run_test "Version check #5 (cli max 1.1, srv min 1.1 -> 1.1)" \
848 "$P_SRV min_version=tls1_1" \
849 "$P_CLI max_version=tls1_1" \
850 0 \
851 -S "ssl_handshake returned" \
852 -C "ssl_handshake returned" \
853 -s "Protocol is TLSv1.1" \
854 -c "Protocol is TLSv1.1"
855
856run_test "Version check #6 (cli min 1.1, srv max 1.1 -> 1.1)" \
857 "$P_SRV max_version=tls1_1" \
858 "$P_CLI min_version=tls1_1" \
859 0 \
860 -S "ssl_handshake returned" \
861 -C "ssl_handshake returned" \
862 -s "Protocol is TLSv1.1" \
863 -c "Protocol is TLSv1.1"
864
865run_test "Version check #7 (cli min 1.2, srv max 1.1 -> fail)" \
866 "$P_SRV max_version=tls1_1" \
867 "$P_CLI min_version=tls1_2" \
868 1 \
869 -s "ssl_handshake returned" \
870 -c "ssl_handshake returned" \
871 -c "SSL - Handshake protocol not within min/max boundaries"
872
873run_test "Version check #8 (srv min 1.2, cli max 1.1 -> fail)" \
874 "$P_SRV min_version=tls1_2" \
875 "$P_CLI max_version=tls1_1" \
876 1 \
877 -s "ssl_handshake returned" \
878 -c "ssl_handshake returned" \
879 -s "SSL - Handshake protocol not within min/max boundaries"
880
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200881# Tests for ALPN extension
882
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +0200883if grep '^#define POLARSSL_SSL_ALPN' $CONFIG_H >/dev/null; then
884
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200885run_test "ALPN #0 (none)" \
886 "$P_SRV debug_level=4" \
887 "$P_CLI debug_level=4" \
888 0 \
889 -C "client hello, adding alpn extension" \
890 -S "found alpn extension" \
891 -C "got an alert message, type: \\[2:120]" \
892 -S "server hello, adding alpn extension" \
893 -C "found alpn extension " \
894 -C "Application Layer Protocol is" \
895 -S "Application Layer Protocol is"
896
897run_test "ALPN #1 (client only)" \
898 "$P_SRV debug_level=4" \
899 "$P_CLI debug_level=4 alpn=abc,1234" \
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 (none)" \
907 -S "Application Layer Protocol is"
908
909run_test "ALPN #2 (server only)" \
910 "$P_SRV debug_level=4 alpn=abc,1234" \
911 "$P_CLI debug_level=4" \
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" \
919 -s "Application Layer Protocol is (none)"
920
921run_test "ALPN #3 (both, common cli1-srv1)" \
922 "$P_SRV debug_level=4 alpn=abc,1234" \
923 "$P_CLI debug_level=4 alpn=abc,1234" \
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 abc" \
931 -s "Application Layer Protocol is abc"
932
933run_test "ALPN #4 (both, common cli2-srv1)" \
934 "$P_SRV debug_level=4 alpn=abc,1234" \
935 "$P_CLI debug_level=4 alpn=1234,abc" \
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 #5 (both, common cli1-srv2)" \
946 "$P_SRV debug_level=4 alpn=abc,1234" \
947 "$P_CLI debug_level=4 alpn=1234,abcde" \
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 1234" \
955 -s "Application Layer Protocol is 1234"
956
957run_test "ALPN #6 (both, no common)" \
958 "$P_SRV debug_level=4 alpn=abc,123" \
959 "$P_CLI debug_level=4 alpn=1234,abcde" \
960 1 \
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
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +0200969fi
970
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100971# Final report
972
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100973echo "------------------------------------------------------------------------"
974
975if [ $FAILS = 0 ]; then
976 echo -n "PASSED"
977else
978 echo -n "FAILED"
979fi
980PASSES=`echo $TESTS - $FAILS | bc`
Manuel Pégourié-Gonnard4145b892014-02-24 13:20:14 +0100981echo " ($PASSES / $TESTS tests)"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100982
983exit $FAILS