blob: 16748b07cfd513939440138d526cccb038e7fc19 [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é-Gonnard7f2a07d2014-04-09 09:50:57 +0200154 # psk is usefull 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é-Gonnard7f2a07d2014-04-09 09:50:57 +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
165 # (usefull to avoid tests with only negative assertions and non-zero
166 # 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 *)
230 echo "Unkown test: $1" >&2
231 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é-Gonnardeaadc502014-02-20 11:01:30 +0100279killall -q openssl ssl_server ssl_server2
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100280trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100281
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100282# Test for SSLv2 ClientHello
283
284run_test "SSLv2 ClientHello #0 (reference)" \
285 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100286 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100287 0 \
288 -S "parse client hello v2" \
289 -S "ssl_handshake returned"
290
291# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
292run_test "SSLv2 ClientHello #1 (actual test)" \
293 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100294 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100295 0 \
296 -s "parse client hello v2" \
297 -S "ssl_handshake returned"
298
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100299# Tests for Truncated HMAC extension
300
301run_test "Truncated HMAC #0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100302 "$P_SRV debug_level=5" \
303 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100304 0 \
305 -s "dumping 'computed mac' (20 bytes)"
306
307run_test "Truncated HMAC #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100308 "$P_SRV debug_level=5" \
309 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100310 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100311 -s "dumping 'computed mac' (10 bytes)"
312
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100313# Tests for Session Tickets
314
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100315run_test "Session resume using tickets #1 (basic)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100316 "$P_SRV debug_level=4 tickets=1" \
317 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100318 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100319 -c "client hello, adding session ticket extension" \
320 -s "found session ticket extension" \
321 -s "server hello, adding session ticket extension" \
322 -c "found session_ticket extension" \
323 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100324 -S "session successfully restored from cache" \
325 -s "session successfully restored from ticket" \
326 -s "a session has been resumed" \
327 -c "a session has been resumed"
328
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100329run_test "Session resume using tickets #2 (cache disabled)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100330 "$P_SRV debug_level=4 tickets=1 cache_max=0" \
331 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100332 0 \
333 -c "client hello, adding session ticket extension" \
334 -s "found session ticket extension" \
335 -s "server hello, adding session ticket extension" \
336 -c "found session_ticket extension" \
337 -c "parse new session ticket" \
338 -S "session successfully restored from cache" \
339 -s "session successfully restored from ticket" \
340 -s "a session has been resumed" \
341 -c "a session has been resumed"
342
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100343run_test "Session resume using tickets #3 (timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100344 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=1" \
345 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100346 0 \
347 -c "client hello, adding session ticket extension" \
348 -s "found session ticket extension" \
349 -s "server hello, adding session ticket extension" \
350 -c "found session_ticket extension" \
351 -c "parse new session ticket" \
352 -S "session successfully restored from cache" \
353 -S "session successfully restored from ticket" \
354 -S "a session has been resumed" \
355 -C "a session has been resumed"
356
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100357run_test "Session resume using tickets #4 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100358 "$O_SRV" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100359 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
360 0 \
361 -c "client hello, adding session ticket extension" \
362 -c "found session_ticket extension" \
363 -c "parse new session ticket" \
364 -c "a session has been resumed"
365
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100366run_test "Session resume using tickets #5 (openssl client)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100367 "$P_SRV debug_level=4 tickets=1" \
368 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
369 0 \
370 -s "found session ticket extension" \
371 -s "server hello, adding session ticket extension" \
372 -S "session successfully restored from cache" \
373 -s "session successfully restored from ticket" \
374 -s "a session has been resumed"
375
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100376# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100377
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100378run_test "Session resume using cache #1 (tickets enabled on client)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100379 "$P_SRV debug_level=4 tickets=0" \
380 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100381 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100382 -c "client hello, adding session ticket extension" \
383 -s "found session ticket extension" \
384 -S "server hello, adding session ticket extension" \
385 -C "found session_ticket extension" \
386 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100387 -s "session successfully restored from cache" \
388 -S "session successfully restored from ticket" \
389 -s "a session has been resumed" \
390 -c "a session has been resumed"
391
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100392run_test "Session resume using cache #2 (tickets enabled on server)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100393 "$P_SRV debug_level=4 tickets=1" \
394 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100395 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100396 -C "client hello, adding session ticket extension" \
397 -S "found session ticket extension" \
398 -S "server hello, adding session ticket extension" \
399 -C "found session_ticket extension" \
400 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100401 -s "session successfully restored from cache" \
402 -S "session successfully restored from ticket" \
403 -s "a session has been resumed" \
404 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100405
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100406run_test "Session resume using cache #3 (cache_max=0)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100407 "$P_SRV debug_level=4 tickets=0 cache_max=0" \
408 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100409 0 \
410 -S "session successfully restored from cache" \
411 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100412 -S "a session has been resumed" \
413 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100414
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100415run_test "Session resume using cache #4 (cache_max=1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100416 "$P_SRV debug_level=4 tickets=0 cache_max=1" \
417 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100418 0 \
419 -s "session successfully restored from cache" \
420 -S "session successfully restored from ticket" \
421 -s "a session has been resumed" \
422 -c "a session has been resumed"
423
424run_test "Session resume using cache #5 (timemout > delay)" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100425 "$P_SRV debug_level=4 tickets=0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100426 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=0" \
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 #6 (timeout < delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100434 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
435 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
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 #7 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100443 "$P_SRV debug_level=4 tickets=0 cache_timeout=0" \
444 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +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
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100451run_test "Session resume using cache #8 (openssl client)" \
452 "$P_SRV debug_level=4 tickets=0" \
453 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
454 0 \
455 -s "found session ticket extension" \
456 -S "server hello, adding session ticket extension" \
457 -s "session successfully restored from cache" \
458 -S "session successfully restored from ticket" \
459 -s "a session has been resumed"
460
461run_test "Session resume using cache #9 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100462 "$O_SRV" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100463 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
464 0 \
465 -C "found session_ticket extension" \
466 -C "parse new session ticket" \
467 -c "a session has been resumed"
468
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100469# Tests for Max Fragment Length extension
470
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100471run_test "Max fragment length #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100472 "$P_SRV debug_level=4" \
473 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100474 0 \
475 -C "client hello, adding max_fragment_length extension" \
476 -S "found max fragment length extension" \
477 -S "server hello, max_fragment_length extension" \
478 -C "found max_fragment_length extension"
479
480run_test "Max fragment length #2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100481 "$P_SRV debug_level=4" \
482 "$P_CLI debug_level=4 max_frag_len=4096" \
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 #3" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100490 "$P_SRV debug_level=4 max_frag_len=4096" \
491 "$P_CLI debug_level=4" \
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"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100497
498# Tests for renegotiation
499
500run_test "Renegotiation #0 (none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100501 "$P_SRV debug_level=4" \
502 "$P_CLI debug_level=4" \
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 #1 (enabled, client-initiated)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200514 "$P_SRV debug_level=4 renegotiation=1" \
515 "$P_CLI debug_level=4 renegotiation=1 renegotiate=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 #2 (enabled, server-initiated)" \
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" \
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 #3 (enabled, double)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200540 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
541 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100542 0 \
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 #4 (client-initiated, server-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100553 "$P_SRV debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200554 "$P_CLI debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100555 1 \
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
565run_test "Renegotiation #5 (server-initiated, client-rejected)" \
Manuel Pégourié-Gonnard00d538f2014-03-31 10:44:40 +0200566 "$P_SRV debug_level=4 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100567 "$P_CLI debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100568 0 \
569 -C "client hello, adding renegotiation extension" \
570 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
571 -S "found renegotiation extension" \
572 -s "server hello, secure renegotiation extension" \
573 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100574 -C "=> renegotiate" \
575 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100576 -s "write hello request" \
577 -s "SSL - An unexpected message was received from our peer" \
578 -s "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100579
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100580# Tests for auth_mode
581
582run_test "Authentication #1 (server badcert, client required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100583 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100584 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100585 "$P_CLI debug_level=2 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100586 1 \
587 -c "x509_verify_cert() returned" \
588 -c "! self-signed or not signed by a trusted CA" \
589 -c "! ssl_handshake returned" \
590 -c "X509 - Certificate verification failed"
591
592run_test "Authentication #2 (server badcert, client optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100593 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100594 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100595 "$P_CLI debug_level=2 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100596 0 \
597 -c "x509_verify_cert() returned" \
598 -c "! self-signed or not signed by a trusted CA" \
599 -C "! ssl_handshake returned" \
600 -C "X509 - Certificate verification failed"
601
602run_test "Authentication #3 (server badcert, client none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100603 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100604 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100605 "$P_CLI debug_level=2 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100606 0 \
607 -C "x509_verify_cert() returned" \
608 -C "! self-signed or not signed by a trusted CA" \
609 -C "! ssl_handshake returned" \
610 -C "X509 - Certificate verification failed"
611
612run_test "Authentication #4 (client badcert, server required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100613 "$P_SRV debug_level=4 auth_mode=required" \
614 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100615 key_file=data_files/server5.key" \
616 1 \
617 -S "skip write certificate request" \
618 -C "skip parse certificate request" \
619 -c "got a certificate request" \
620 -C "skip write certificate" \
621 -C "skip write certificate verify" \
622 -S "skip parse certificate verify" \
623 -s "x509_verify_cert() returned" \
624 -S "! self-signed or not signed by a trusted CA" \
625 -s "! ssl_handshake returned" \
626 -c "! ssl_handshake returned" \
627 -s "X509 - Certificate verification failed"
628
629run_test "Authentication #5 (client badcert, server optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100630 "$P_SRV debug_level=4 auth_mode=optional" \
631 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100632 key_file=data_files/server5.key" \
633 0 \
634 -S "skip write certificate request" \
635 -C "skip parse certificate request" \
636 -c "got a certificate request" \
637 -C "skip write certificate" \
638 -C "skip write certificate verify" \
639 -S "skip parse certificate verify" \
640 -s "x509_verify_cert() returned" \
641 -s "! self-signed or not signed by a trusted CA" \
642 -S "! ssl_handshake returned" \
643 -C "! ssl_handshake returned" \
644 -S "X509 - Certificate verification failed"
645
646run_test "Authentication #6 (client badcert, server none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100647 "$P_SRV debug_level=4 auth_mode=none" \
648 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100649 key_file=data_files/server5.key" \
650 0 \
651 -s "skip write certificate request" \
652 -C "skip parse certificate request" \
653 -c "got no certificate request" \
654 -c "skip write certificate" \
655 -c "skip write certificate verify" \
656 -s "skip parse certificate verify" \
657 -S "x509_verify_cert() returned" \
658 -S "! self-signed or not signed by a trusted CA" \
659 -S "! ssl_handshake returned" \
660 -C "! ssl_handshake returned" \
661 -S "X509 - Certificate verification failed"
662
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +0100663run_test "Authentication #7 (client no cert, server optional)" \
664 "$P_SRV debug_level=4 auth_mode=optional" \
665 "$P_CLI debug_level=4 crt_file=none key_file=none" \
666 0 \
667 -S "skip write certificate request" \
668 -C "skip parse certificate request" \
669 -c "got a certificate request" \
670 -C "skip write certificate$" \
671 -C "got no certificate to send" \
672 -S "SSLv3 client has no certificate" \
673 -c "skip write certificate verify" \
674 -s "skip parse certificate verify" \
675 -s "! no client certificate sent" \
676 -S "! ssl_handshake returned" \
677 -C "! ssl_handshake returned" \
678 -S "X509 - Certificate verification failed"
679
680run_test "Authentication #8 (openssl client no cert, server optional)" \
681 "$P_SRV debug_level=4 auth_mode=optional" \
682 "$O_CLI" \
683 0 \
684 -S "skip write certificate request" \
685 -s "skip parse certificate verify" \
686 -s "! no client certificate sent" \
687 -S "! ssl_handshake returned" \
688 -S "X509 - Certificate verification failed"
689
690run_test "Authentication #9 (client no cert, openssl server optional)" \
691 "$O_SRV -verify 10" \
692 "$P_CLI debug_level=4 crt_file=none key_file=none" \
693 0 \
694 -C "skip parse certificate request" \
695 -c "got a certificate request" \
696 -C "skip write certificate$" \
697 -c "skip write certificate verify" \
698 -C "! ssl_handshake returned"
699
700run_test "Authentication #10 (client no cert, ssl3)" \
701 "$P_SRV debug_level=4 auth_mode=optional force_version=ssl3" \
702 "$P_CLI debug_level=4 crt_file=none key_file=none" \
703 0 \
704 -S "skip write certificate request" \
705 -C "skip parse certificate request" \
706 -c "got a certificate request" \
707 -C "skip write certificate$" \
708 -c "skip write certificate verify" \
709 -c "got no certificate to send" \
710 -s "SSLv3 client has no certificate" \
711 -s "skip parse certificate verify" \
712 -s "! no client certificate sent" \
713 -S "! ssl_handshake returned" \
714 -C "! ssl_handshake returned" \
715 -S "X509 - Certificate verification failed"
716
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100717# tests for SNI
718
719run_test "SNI #0 (no SNI callback)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100720 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100721 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100722 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100723 server_name=localhost" \
724 0 \
725 -S "parse ServerName extension" \
726 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
727 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
728
729run_test "SNI #1 (matching cert 1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100730 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100731 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100732 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 +0100733 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100734 server_name=localhost" \
735 0 \
736 -s "parse ServerName extension" \
737 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
738 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
739
740run_test "SNI #2 (matching cert 2)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100741 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100742 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100743 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 +0100744 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100745 server_name=polarssl.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100746 0 \
747 -s "parse ServerName extension" \
748 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100749 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100750
751run_test "SNI #3 (no matching cert)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100752 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100753 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100754 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 +0100755 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +0100756 server_name=nonesuch.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100757 1 \
758 -s "parse ServerName extension" \
759 -s "ssl_sni_wrapper() returned" \
760 -s "ssl_handshake returned" \
761 -c "ssl_handshake returned" \
762 -c "SSL - A fatal alert message was received from our peer"
763
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +0100764# Tests for non-blocking I/O: exercise a variety of handshake flows
765
766run_test "Non-blocking I/O #1 (basic handshake)" \
767 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
768 "$P_CLI nbio=2 tickets=0" \
769 0 \
770 -S "ssl_handshake returned" \
771 -C "ssl_handshake returned" \
772 -c "Read from server: .* bytes read"
773
774run_test "Non-blocking I/O #2 (client auth)" \
775 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
776 "$P_CLI nbio=2 tickets=0" \
777 0 \
778 -S "ssl_handshake returned" \
779 -C "ssl_handshake returned" \
780 -c "Read from server: .* bytes read"
781
782run_test "Non-blocking I/O #3 (ticket)" \
783 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
784 "$P_CLI nbio=2 tickets=1" \
785 0 \
786 -S "ssl_handshake returned" \
787 -C "ssl_handshake returned" \
788 -c "Read from server: .* bytes read"
789
790run_test "Non-blocking I/O #4 (ticket + client auth)" \
791 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
792 "$P_CLI nbio=2 tickets=1" \
793 0 \
794 -S "ssl_handshake returned" \
795 -C "ssl_handshake returned" \
796 -c "Read from server: .* bytes read"
797
798run_test "Non-blocking I/O #5 (ticket + client auth + resume)" \
799 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
800 "$P_CLI nbio=2 tickets=1 reconnect=1" \
801 0 \
802 -S "ssl_handshake returned" \
803 -C "ssl_handshake returned" \
804 -c "Read from server: .* bytes read"
805
806run_test "Non-blocking I/O #6 (ticket + resume)" \
807 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
808 "$P_CLI nbio=2 tickets=1 reconnect=1" \
809 0 \
810 -S "ssl_handshake returned" \
811 -C "ssl_handshake returned" \
812 -c "Read from server: .* bytes read"
813
814run_test "Non-blocking I/O #7 (session-id resume)" \
815 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
816 "$P_CLI nbio=2 tickets=0 reconnect=1" \
817 0 \
818 -S "ssl_handshake returned" \
819 -C "ssl_handshake returned" \
820 -c "Read from server: .* bytes read"
821
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200822# Tests for version negotiation
823
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100824run_test "Version check #1 (all -> 1.2)" \
825 "$P_SRV" \
826 "$P_CLI" \
827 0 \
828 -S "ssl_handshake returned" \
829 -C "ssl_handshake returned" \
830 -s "Protocol is TLSv1.2" \
831 -c "Protocol is TLSv1.2"
832
833run_test "Version check #2 (cli max 1.1 -> 1.1)" \
834 "$P_SRV" \
835 "$P_CLI max_version=tls1_1" \
836 0 \
837 -S "ssl_handshake returned" \
838 -C "ssl_handshake returned" \
839 -s "Protocol is TLSv1.1" \
840 -c "Protocol is TLSv1.1"
841
842run_test "Version check #3 (srv max 1.1 -> 1.1)" \
843 "$P_SRV max_version=tls1_1" \
844 "$P_CLI" \
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 #4 (cli+srv max 1.1 -> 1.1)" \
852 "$P_SRV max_version=tls1_1" \
853 "$P_CLI max_version=tls1_1" \
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 #5 (cli max 1.1, srv min 1.1 -> 1.1)" \
861 "$P_SRV min_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 #6 (cli min 1.1, srv max 1.1 -> 1.1)" \
870 "$P_SRV max_version=tls1_1" \
871 "$P_CLI min_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 #7 (cli min 1.2, srv max 1.1 -> fail)" \
879 "$P_SRV max_version=tls1_1" \
880 "$P_CLI min_version=tls1_2" \
881 1 \
882 -s "ssl_handshake returned" \
883 -c "ssl_handshake returned" \
884 -c "SSL - Handshake protocol not within min/max boundaries"
885
886run_test "Version check #8 (srv min 1.2, cli max 1.1 -> fail)" \
887 "$P_SRV min_version=tls1_2" \
888 "$P_CLI max_version=tls1_1" \
889 1 \
890 -s "ssl_handshake returned" \
891 -c "ssl_handshake returned" \
892 -s "SSL - Handshake protocol not within min/max boundaries"
893
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200894# Tests for ALPN extension
895
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +0200896if grep '^#define POLARSSL_SSL_ALPN' $CONFIG_H >/dev/null; then
897
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +0200898run_test "ALPN #0 (none)" \
899 "$P_SRV debug_level=4" \
900 "$P_CLI debug_level=4" \
901 0 \
902 -C "client hello, adding alpn extension" \
903 -S "found alpn extension" \
904 -C "got an alert message, type: \\[2:120]" \
905 -S "server hello, adding alpn extension" \
906 -C "found alpn extension " \
907 -C "Application Layer Protocol is" \
908 -S "Application Layer Protocol is"
909
910run_test "ALPN #1 (client only)" \
911 "$P_SRV debug_level=4" \
912 "$P_CLI debug_level=4 alpn=abc,1234" \
913 0 \
914 -c "client hello, adding alpn extension" \
915 -s "found alpn extension" \
916 -C "got an alert message, type: \\[2:120]" \
917 -S "server hello, adding alpn extension" \
918 -C "found alpn extension " \
919 -c "Application Layer Protocol is (none)" \
920 -S "Application Layer Protocol is"
921
922run_test "ALPN #2 (server only)" \
923 "$P_SRV debug_level=4 alpn=abc,1234" \
924 "$P_CLI debug_level=4" \
925 0 \
926 -C "client hello, adding alpn extension" \
927 -S "found alpn extension" \
928 -C "got an alert message, type: \\[2:120]" \
929 -S "server hello, adding alpn extension" \
930 -C "found alpn extension " \
931 -C "Application Layer Protocol is" \
932 -s "Application Layer Protocol is (none)"
933
934run_test "ALPN #3 (both, common cli1-srv1)" \
935 "$P_SRV debug_level=4 alpn=abc,1234" \
936 "$P_CLI debug_level=4 alpn=abc,1234" \
937 0 \
938 -c "client hello, adding alpn extension" \
939 -s "found alpn extension" \
940 -C "got an alert message, type: \\[2:120]" \
941 -s "server hello, adding alpn extension" \
942 -c "found alpn extension" \
943 -c "Application Layer Protocol is abc" \
944 -s "Application Layer Protocol is abc"
945
946run_test "ALPN #4 (both, common cli2-srv1)" \
947 "$P_SRV debug_level=4 alpn=abc,1234" \
948 "$P_CLI debug_level=4 alpn=1234,abc" \
949 0 \
950 -c "client hello, adding alpn extension" \
951 -s "found alpn extension" \
952 -C "got an alert message, type: \\[2:120]" \
953 -s "server hello, adding alpn extension" \
954 -c "found alpn extension" \
955 -c "Application Layer Protocol is abc" \
956 -s "Application Layer Protocol is abc"
957
958run_test "ALPN #5 (both, common cli1-srv2)" \
959 "$P_SRV debug_level=4 alpn=abc,1234" \
960 "$P_CLI debug_level=4 alpn=1234,abcde" \
961 0 \
962 -c "client hello, adding alpn extension" \
963 -s "found alpn extension" \
964 -C "got an alert message, type: \\[2:120]" \
965 -s "server hello, adding alpn extension" \
966 -c "found alpn extension" \
967 -c "Application Layer Protocol is 1234" \
968 -s "Application Layer Protocol is 1234"
969
970run_test "ALPN #6 (both, no common)" \
971 "$P_SRV debug_level=4 alpn=abc,123" \
972 "$P_CLI debug_level=4 alpn=1234,abcde" \
973 1 \
974 -c "client hello, adding alpn extension" \
975 -s "found alpn extension" \
976 -c "got an alert message, type: \\[2:120]" \
977 -S "server hello, adding alpn extension" \
978 -C "found alpn extension" \
979 -C "Application Layer Protocol is 1234" \
980 -S "Application Layer Protocol is 1234"
981
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +0200982fi
983
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +0200984# Tests for keyUsage in leaf certificates, part 1:
985# server-side certificate/suite selection
986
987run_test "keyUsage srv #1 (RSA, digitalSignature -> ECDHE-RSA)" \
988 "$P_SRV key_file=data_files/server2.key \
989 crt_file=data_files/server2.ku-ds.crt" \
990 "$P_CLI" \
991 0 \
992 -c "Ciphersuite is TLS-ECDHE-RSA-WITH-"
993
994
995run_test "keyUsage srv #2 (RSA, keyEncipherment -> RSA)" \
996 "$P_SRV key_file=data_files/server2.key \
997 crt_file=data_files/server2.ku-ke.crt" \
998 "$P_CLI" \
999 0 \
1000 -c "Ciphersuite is TLS-RSA-WITH-"
1001
1002# add psk to leave an option for client to send SERVERQUIT
1003run_test "keyUsage srv #3 (RSA, keyAgreement -> fail)" \
1004 "$P_SRV psk=abc123 key_file=data_files/server2.key \
1005 crt_file=data_files/server2.ku-ka.crt" \
1006 "$P_CLI psk=badbad" \
1007 1 \
1008 -C "Ciphersuite is "
1009
1010run_test "keyUsage srv #4 (ECDSA, digitalSignature -> ECDHE-ECDSA)" \
1011 "$P_SRV key_file=data_files/server5.key \
1012 crt_file=data_files/server5.ku-ds.crt" \
1013 "$P_CLI" \
1014 0 \
1015 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
1016
1017
1018run_test "keyUsage srv #5 (ECDSA, keyAgreement -> ECDH-)" \
1019 "$P_SRV key_file=data_files/server5.key \
1020 crt_file=data_files/server5.ku-ka.crt" \
1021 "$P_CLI" \
1022 0 \
1023 -c "Ciphersuite is TLS-ECDH-"
1024
1025# add psk to leave an option for client to send SERVERQUIT
1026run_test "keyUsage srv #6 (ECDSA, keyEncipherment -> fail)" \
1027 "$P_SRV psk=abc123 key_file=data_files/server5.key \
1028 crt_file=data_files/server5.ku-ke.crt" \
1029 "$P_CLI psk=badbad" \
1030 1 \
1031 -C "Ciphersuite is "
1032
1033# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001034# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001035
1036run_test "keyUsage cli #1 (DigitalSignature+KeyEncipherment, RSA: OK)" \
1037 "$O_SRV -key data_files/server2.key \
1038 -cert data_files/server2.ku-ds_ke.crt" \
1039 "$P_CLI debug_level=2 \
1040 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1041 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001042 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001043 -C "Processing of the Certificate handshake message failed" \
1044 -c "Ciphersuite is TLS-"
1045
1046run_test "keyUsage cli #2 (DigitalSignature+KeyEncipherment, DHE-RSA: OK)" \
1047 "$O_SRV -key data_files/server2.key \
1048 -cert data_files/server2.ku-ds_ke.crt" \
1049 "$P_CLI debug_level=2 \
1050 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1051 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001052 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001053 -C "Processing of the Certificate handshake message failed" \
1054 -c "Ciphersuite is TLS-"
1055
1056run_test "keyUsage cli #3 (KeyEncipherment, RSA: OK)" \
1057 "$O_SRV -key data_files/server2.key \
1058 -cert data_files/server2.ku-ke.crt" \
1059 "$P_CLI debug_level=2 \
1060 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1061 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001062 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001063 -C "Processing of the Certificate handshake message failed" \
1064 -c "Ciphersuite is TLS-"
1065
1066run_test "keyUsage cli #4 (KeyEncipherment, DHE-RSA: fail)" \
1067 "$O_SRV -key data_files/server2.key \
1068 -cert data_files/server2.ku-ke.crt" \
1069 "$P_CLI debug_level=2 \
1070 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1071 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001072 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001073 -c "Processing of the Certificate handshake message failed" \
1074 -C "Ciphersuite is TLS-"
1075
1076run_test "keyUsage cli #5 (DigitalSignature, DHE-RSA: OK)" \
1077 "$O_SRV -key data_files/server2.key \
1078 -cert data_files/server2.ku-ds.crt" \
1079 "$P_CLI debug_level=2 \
1080 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1081 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001082 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001083 -C "Processing of the Certificate handshake message failed" \
1084 -c "Ciphersuite is TLS-"
1085
1086run_test "keyUsage cli #5 (DigitalSignature, RSA: fail)" \
1087 "$O_SRV -key data_files/server2.key \
1088 -cert data_files/server2.ku-ds.crt" \
1089 "$P_CLI debug_level=2 \
1090 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1091 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001092 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001093 -c "Processing of the Certificate handshake message failed" \
1094 -C "Ciphersuite is TLS-"
1095
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001096# Tests for keyUsage in leaf certificates, part 3:
1097# server-side checking of client cert
1098
1099run_test "keyUsage cli-auth #1 (RSA, DigitalSignature: OK)" \
1100 "$P_SRV debug_level=2 auth_mode=optional" \
1101 "$O_CLI -key data_files/server2.key \
1102 -cert data_files/server2.ku-ds.crt" \
1103 0 \
1104 -S "bad certificate (usage extensions)" \
1105 -S "Processing of the Certificate handshake message failed"
1106
1107run_test "keyUsage cli-auth #2 (RSA, KeyEncipherment: fail (soft))" \
1108 "$P_SRV debug_level=2 auth_mode=optional" \
1109 "$O_CLI -key data_files/server2.key \
1110 -cert data_files/server2.ku-ke.crt" \
1111 0 \
1112 -s "bad certificate (usage extensions)" \
1113 -S "Processing of the Certificate handshake message failed"
1114
1115run_test "keyUsage cli-auth #3 (RSA, KeyEncipherment: fail (hard))" \
1116 "$P_SRV debug_level=2 auth_mode=required" \
1117 "$O_CLI -key data_files/server2.key \
1118 -cert data_files/server2.ku-ke.crt" \
1119 1 \
1120 -s "bad certificate (usage extensions)" \
1121 -s "Processing of the Certificate handshake message failed"
1122
1123run_test "keyUsage cli-auth #4 (ECDSA, DigitalSignature: OK)" \
1124 "$P_SRV debug_level=2 auth_mode=optional" \
1125 "$O_CLI -key data_files/server5.key \
1126 -cert data_files/server5.ku-ds.crt" \
1127 0 \
1128 -S "bad certificate (usage extensions)" \
1129 -S "Processing of the Certificate handshake message failed"
1130
1131run_test "keyUsage cli-auth #5 (ECDSA, KeyAgreement: fail (soft))" \
1132 "$P_SRV debug_level=2 auth_mode=optional" \
1133 "$O_CLI -key data_files/server5.key \
1134 -cert data_files/server5.ku-ka.crt" \
1135 0 \
1136 -s "bad certificate (usage extensions)" \
1137 -S "Processing of the Certificate handshake message failed"
1138
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001139# Final report
1140
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01001141echo "------------------------------------------------------------------------"
1142
1143if [ $FAILS = 0 ]; then
1144 echo -n "PASSED"
1145else
1146 echo -n "FAILED"
1147fi
1148PASSES=`echo $TESTS - $FAILS | bc`
Manuel Pégourié-Gonnard4145b892014-02-24 13:20:14 +01001149echo " ($PASSES / $TESTS tests)"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01001150
1151exit $FAILS