blob: 7332af931254bc649224438e45149fd17b9413e3 [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}
16: ${OPENSSL:=openssl}
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010017
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +010018O_SRV="$OPENSSL s_server -www -cert data_files/server5.crt -key data_files/server5.key"
19O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL 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é-Gonnardc73339f2014-02-26 16:35:27 +010024MEMCHECK=0
25
26print_usage() {
27 echo "Usage: $0 [options]"
28 echo -e " -h, --help\tPrint this help."
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +010029 echo -e " -m, --memcheck\tCheck memory leaks and errors."
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010030}
31
32get_options() {
33 while [ $# -gt 0 ]; do
34 case "$1" in
35 -m|--memcheck)
36 MEMCHECK=1
37 ;;
38 -h|--help)
39 print_usage
40 exit 0
41 ;;
42 *)
43 echo "Unkown argument: '$1'"
44 print_usage
45 exit 1
46 ;;
47 esac
48 shift
49 done
50}
51
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010052# print_name <name>
53print_name() {
54 echo -n "$1 "
55 LEN=`echo "$1" | wc -c`
56 LEN=`echo 72 - $LEN | bc`
57 for i in `seq 1 $LEN`; do echo -n '.'; done
58 echo -n ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010059
60 TESTS=`echo $TESTS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010061}
62
63# fail <message>
64fail() {
65 echo "FAIL"
66 echo " $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010067
68 cp srv_out srv-${TESTS}.log
69 cp cli_out cli-${TESTS}.log
70 echo " outputs saved to srv-${TESTS}.log and cli-${TESTS}.log"
71
72 FAILS=`echo $FAILS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010073}
74
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +010075# is_polar <cmd_line>
76is_polar() {
77 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
78}
79
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010080# has_mem_err <log_file_name>
81has_mem_err() {
82 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
83 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
84 then
85 return 1 # false: does not have errors
86 else
87 return 0 # true: has errors
88 fi
89}
90
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010091# Usage: run_test name srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010092# Options: -s pattern pattern that must be present in server output
93# -c pattern pattern that must be present in client output
94# -S pattern pattern that must be absent in server output
95# -C pattern pattern that must be absent in client output
96run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010097 NAME="$1"
98 SRV_CMD="$2"
99 CLI_CMD="$3"
100 CLI_EXPECT="$4"
101 shift 4
102
103 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100104
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100105 # prepend valgrind to our commands if active
106 if [ "$MEMCHECK" -gt 0 ]; then
107 if is_polar "$SRV_CMD"; then
108 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
109 fi
110 if is_polar "$CLI_CMD"; then
111 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
112 fi
113 fi
114
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100115 # run the commands
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100116 $SHELL -c "$SRV_CMD" > srv_out 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100117 SRV_PID=$!
118 sleep 1
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100119 $SHELL -c "$CLI_CMD" > cli_out 2>&1
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100120 CLI_EXIT=$?
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100121 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100122 echo SERVERQUIT | $OPENSSL s_client -no_ticket \
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100123 -cert data_files/cli2.crt -key data_files/cli2.key \
124 >/dev/null 2>&1
125 else
126 kill $SRV_PID
127 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100128 wait $SRV_PID
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100129
130 # check if the client and server went at least to the handshake stage
131 # (usefull to avoid tests with only negative assertions and non-zero
132 # expected client exit to incorrectly succeed in case of catastrophic
133 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100134 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100135 if grep "Performing the SSL/TLS handshake" srv_out >/dev/null; then :;
136 else
137 fail "server failed to start"
138 return
139 fi
140 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100141 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100142 if grep "Performing the SSL/TLS handshake" cli_out >/dev/null; then :;
143 else
144 fail "client failed to start"
145 return
146 fi
147 fi
148
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100149 # check server exit code
150 if [ $? != 0 ]; then
151 fail "server fail"
152 return
153 fi
154
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100155 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100156 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
157 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100158 then
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100159 fail "bad client exit code"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100160 return
161 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100162
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100163 # check other assertions
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100164 while [ $# -gt 0 ]
165 do
166 case $1 in
167 "-s")
168 if grep "$2" srv_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100169 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100170 return
171 fi
172 ;;
173
174 "-c")
175 if grep "$2" cli_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100176 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100177 return
178 fi
179 ;;
180
181 "-S")
182 if grep "$2" srv_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100183 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100184 return
185 fi
186 ;;
187
188 "-C")
189 if grep "$2" cli_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100190 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100191 return
192 fi
193 ;;
194
195 *)
196 echo "Unkown test: $1" >&2
197 exit 1
198 esac
199 shift 2
200 done
201
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100202 # check valgrind's results
203 if [ "$MEMCHECK" -gt 0 ]; then
204 if is_polar "$SRV_CMD" && has_mem_err srv_out; then
205 fail "Server has memory errors"
206 return
207 fi
208 if is_polar "$CLI_CMD" && has_mem_err cli_out; then
209 fail "Client has memory errors"
210 return
211 fi
212 fi
213
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100214 # if we're here, everything is ok
215 echo "PASS"
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100216 rm -f srv_out cli_out
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100217}
218
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100219cleanup() {
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100220 rm -f cli_out srv_out sess
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100221 kill $SRV_PID
222 exit 1
223}
224
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100225#
226# MAIN
227#
228
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100229# sanity checks, avoid an avalanche of errors
230if [ ! -x "$P_SRV" ]; then
231 echo "Command '$P_SRV' is not an executable file"
232 exit 1
233fi
234if [ ! -x "$P_CLI" ]; then
235 echo "Command '$P_CLI' is not an executable file"
236 exit 1
237fi
238if which $OPENSSL >/dev/null 2>&1; then :; else
239 echo "Command '$OPENSSL' not found"
240 exit 1
241fi
242
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100243get_options "$@"
244
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100245killall -q openssl ssl_server ssl_server2
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100246trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100247
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100248# Test for SSLv2 ClientHello
249
250run_test "SSLv2 ClientHello #0 (reference)" \
251 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100252 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100253 0 \
254 -S "parse client hello v2" \
255 -S "ssl_handshake returned"
256
257# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
258run_test "SSLv2 ClientHello #1 (actual test)" \
259 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100260 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100261 0 \
262 -s "parse client hello v2" \
263 -S "ssl_handshake returned"
264
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100265# Tests for Truncated HMAC extension
266
267run_test "Truncated HMAC #0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100268 "$P_SRV debug_level=5" \
269 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100270 0 \
271 -s "dumping 'computed mac' (20 bytes)"
272
273run_test "Truncated HMAC #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100274 "$P_SRV debug_level=5" \
275 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100276 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100277 -s "dumping 'computed mac' (10 bytes)"
278
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100279# Tests for Session Tickets
280
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100281run_test "Session resume using tickets #1 (basic)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100282 "$P_SRV debug_level=4 tickets=1" \
283 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100284 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100285 -c "client hello, adding session ticket extension" \
286 -s "found session ticket extension" \
287 -s "server hello, adding session ticket extension" \
288 -c "found session_ticket extension" \
289 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100290 -S "session successfully restored from cache" \
291 -s "session successfully restored from ticket" \
292 -s "a session has been resumed" \
293 -c "a session has been resumed"
294
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100295run_test "Session resume using tickets #2 (cache disabled)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100296 "$P_SRV debug_level=4 tickets=1 cache_max=0" \
297 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100298 0 \
299 -c "client hello, adding session ticket extension" \
300 -s "found session ticket extension" \
301 -s "server hello, adding session ticket extension" \
302 -c "found session_ticket extension" \
303 -c "parse new session ticket" \
304 -S "session successfully restored from cache" \
305 -s "session successfully restored from ticket" \
306 -s "a session has been resumed" \
307 -c "a session has been resumed"
308
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100309run_test "Session resume using tickets #3 (timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100310 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=1" \
311 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100312 0 \
313 -c "client hello, adding session ticket extension" \
314 -s "found session ticket extension" \
315 -s "server hello, adding session ticket extension" \
316 -c "found session_ticket extension" \
317 -c "parse new session ticket" \
318 -S "session successfully restored from cache" \
319 -S "session successfully restored from ticket" \
320 -S "a session has been resumed" \
321 -C "a session has been resumed"
322
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100323run_test "Session resume using tickets #4 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100324 "$O_SRV" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100325 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
326 0 \
327 -c "client hello, adding session ticket extension" \
328 -c "found session_ticket extension" \
329 -c "parse new session ticket" \
330 -c "a session has been resumed"
331
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100332run_test "Session resume using tickets #5 (openssl client)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100333 "$P_SRV debug_level=4 tickets=1" \
334 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
335 0 \
336 -s "found session ticket extension" \
337 -s "server hello, adding session ticket extension" \
338 -S "session successfully restored from cache" \
339 -s "session successfully restored from ticket" \
340 -s "a session has been resumed"
341
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100342# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100343
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100344run_test "Session resume using cache #1 (tickets enabled on client)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100345 "$P_SRV debug_level=4 tickets=0" \
346 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100347 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100348 -c "client hello, adding session ticket extension" \
349 -s "found session ticket extension" \
350 -S "server hello, adding session ticket extension" \
351 -C "found session_ticket extension" \
352 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100353 -s "session successfully restored from cache" \
354 -S "session successfully restored from ticket" \
355 -s "a session has been resumed" \
356 -c "a session has been resumed"
357
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100358run_test "Session resume using cache #2 (tickets enabled on server)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100359 "$P_SRV debug_level=4 tickets=1" \
360 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100361 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100362 -C "client hello, adding session ticket extension" \
363 -S "found session ticket extension" \
364 -S "server hello, adding session ticket extension" \
365 -C "found session_ticket extension" \
366 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100367 -s "session successfully restored from cache" \
368 -S "session successfully restored from ticket" \
369 -s "a session has been resumed" \
370 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100371
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100372run_test "Session resume using cache #3 (cache_max=0)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100373 "$P_SRV debug_level=4 tickets=0 cache_max=0" \
374 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100375 0 \
376 -S "session successfully restored from cache" \
377 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100378 -S "a session has been resumed" \
379 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100380
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100381run_test "Session resume using cache #4 (cache_max=1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100382 "$P_SRV debug_level=4 tickets=0 cache_max=1" \
383 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100384 0 \
385 -s "session successfully restored from cache" \
386 -S "session successfully restored from ticket" \
387 -s "a session has been resumed" \
388 -c "a session has been resumed"
389
390run_test "Session resume using cache #5 (timemout > delay)" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100391 "$P_SRV debug_level=4 tickets=0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100392 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100393 0 \
394 -s "session successfully restored from cache" \
395 -S "session successfully restored from ticket" \
396 -s "a session has been resumed" \
397 -c "a session has been resumed"
398
399run_test "Session resume using cache #6 (timeout < delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100400 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
401 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100402 0 \
403 -S "session successfully restored from cache" \
404 -S "session successfully restored from ticket" \
405 -S "a session has been resumed" \
406 -C "a session has been resumed"
407
408run_test "Session resume using cache #7 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100409 "$P_SRV debug_level=4 tickets=0 cache_timeout=0" \
410 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100411 0 \
412 -s "session successfully restored from cache" \
413 -S "session successfully restored from ticket" \
414 -s "a session has been resumed" \
415 -c "a session has been resumed"
416
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100417run_test "Session resume using cache #8 (openssl client)" \
418 "$P_SRV debug_level=4 tickets=0" \
419 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
420 0 \
421 -s "found session ticket extension" \
422 -S "server hello, adding session ticket extension" \
423 -s "session successfully restored from cache" \
424 -S "session successfully restored from ticket" \
425 -s "a session has been resumed"
426
427run_test "Session resume using cache #9 (openssl server)" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100428 "$O_SRV" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100429 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
430 0 \
431 -C "found session_ticket extension" \
432 -C "parse new session ticket" \
433 -c "a session has been resumed"
434
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100435# Tests for Max Fragment Length extension
436
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100437run_test "Max fragment length #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100438 "$P_SRV debug_level=4" \
439 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100440 0 \
441 -C "client hello, adding max_fragment_length extension" \
442 -S "found max fragment length extension" \
443 -S "server hello, max_fragment_length extension" \
444 -C "found max_fragment_length extension"
445
446run_test "Max fragment length #2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100447 "$P_SRV debug_level=4" \
448 "$P_CLI debug_level=4 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100449 0 \
450 -c "client hello, adding max_fragment_length extension" \
451 -s "found max fragment length extension" \
452 -s "server hello, max_fragment_length extension" \
453 -c "found max_fragment_length extension"
454
455run_test "Max fragment length #3" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100456 "$P_SRV debug_level=4 max_frag_len=4096" \
457 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100458 0 \
459 -C "client hello, adding max_fragment_length extension" \
460 -S "found max fragment length extension" \
461 -S "server hello, max_fragment_length extension" \
462 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100463
464# Tests for renegotiation
465
466run_test "Renegotiation #0 (none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100467 "$P_SRV debug_level=4" \
468 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100469 0 \
470 -C "client hello, adding renegotiation extension" \
471 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
472 -S "found renegotiation extension" \
473 -s "server hello, secure renegotiation extension" \
474 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100475 -C "=> renegotiate" \
476 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100477 -S "write hello request"
478
479run_test "Renegotiation #1 (enabled, client-initiated)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100480 "$P_SRV debug_level=4" \
481 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100482 0 \
483 -c "client hello, adding renegotiation extension" \
484 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
485 -s "found renegotiation extension" \
486 -s "server hello, secure renegotiation extension" \
487 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100488 -c "=> renegotiate" \
489 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100490 -S "write hello request"
491
492run_test "Renegotiation #2 (enabled, server-initiated)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100493 "$P_SRV debug_level=4 renegotiate=1" \
494 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100495 0 \
496 -c "client hello, adding renegotiation extension" \
497 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
498 -s "found renegotiation extension" \
499 -s "server hello, secure renegotiation extension" \
500 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100501 -c "=> renegotiate" \
502 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100503 -s "write hello request"
504
505run_test "Renegotiation #3 (enabled, double)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100506 "$P_SRV debug_level=4 renegotiate=1" \
507 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100508 0 \
509 -c "client hello, adding renegotiation extension" \
510 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
511 -s "found renegotiation extension" \
512 -s "server hello, secure renegotiation extension" \
513 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100514 -c "=> renegotiate" \
515 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100516 -s "write hello request"
517
518run_test "Renegotiation #4 (client-initiated, server-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100519 "$P_SRV debug_level=4 renegotiation=0" \
520 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100521 1 \
522 -c "client hello, adding renegotiation extension" \
523 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
524 -S "found renegotiation extension" \
525 -s "server hello, secure renegotiation extension" \
526 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100527 -c "=> renegotiate" \
528 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100529 -S "write hello request"
530
531run_test "Renegotiation #5 (server-initiated, client-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100532 "$P_SRV debug_level=4 renegotiate=1" \
533 "$P_CLI debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100534 0 \
535 -C "client hello, adding renegotiation extension" \
536 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
537 -S "found renegotiation extension" \
538 -s "server hello, secure renegotiation extension" \
539 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100540 -C "=> renegotiate" \
541 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100542 -s "write hello request" \
543 -s "SSL - An unexpected message was received from our peer" \
544 -s "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100545
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100546# Tests for auth_mode
547
548run_test "Authentication #1 (server badcert, client required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100549 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100550 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100551 "$P_CLI debug_level=2 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100552 1 \
553 -c "x509_verify_cert() returned" \
554 -c "! self-signed or not signed by a trusted CA" \
555 -c "! ssl_handshake returned" \
556 -c "X509 - Certificate verification failed"
557
558run_test "Authentication #2 (server badcert, client optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100559 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100560 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100561 "$P_CLI debug_level=2 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100562 0 \
563 -c "x509_verify_cert() returned" \
564 -c "! self-signed or not signed by a trusted CA" \
565 -C "! ssl_handshake returned" \
566 -C "X509 - Certificate verification failed"
567
568run_test "Authentication #3 (server badcert, client none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100569 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100570 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100571 "$P_CLI debug_level=2 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100572 0 \
573 -C "x509_verify_cert() returned" \
574 -C "! self-signed or not signed by a trusted CA" \
575 -C "! ssl_handshake returned" \
576 -C "X509 - Certificate verification failed"
577
578run_test "Authentication #4 (client badcert, server required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100579 "$P_SRV debug_level=4 auth_mode=required" \
580 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100581 key_file=data_files/server5.key" \
582 1 \
583 -S "skip write certificate request" \
584 -C "skip parse certificate request" \
585 -c "got a certificate request" \
586 -C "skip write certificate" \
587 -C "skip write certificate verify" \
588 -S "skip parse certificate verify" \
589 -s "x509_verify_cert() returned" \
590 -S "! self-signed or not signed by a trusted CA" \
591 -s "! ssl_handshake returned" \
592 -c "! ssl_handshake returned" \
593 -s "X509 - Certificate verification failed"
594
595run_test "Authentication #5 (client badcert, server optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100596 "$P_SRV debug_level=4 auth_mode=optional" \
597 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100598 key_file=data_files/server5.key" \
599 0 \
600 -S "skip write certificate request" \
601 -C "skip parse certificate request" \
602 -c "got a certificate request" \
603 -C "skip write certificate" \
604 -C "skip write certificate verify" \
605 -S "skip parse certificate verify" \
606 -s "x509_verify_cert() returned" \
607 -s "! self-signed or not signed by a trusted CA" \
608 -S "! ssl_handshake returned" \
609 -C "! ssl_handshake returned" \
610 -S "X509 - Certificate verification failed"
611
612run_test "Authentication #6 (client badcert, server none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100613 "$P_SRV debug_level=4 auth_mode=none" \
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 0 \
617 -s "skip write certificate request" \
618 -C "skip parse certificate request" \
619 -c "got no 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
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100629# tests for SNI
630
631run_test "SNI #0 (no SNI callback)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100632 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100633 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100634 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100635 server_name=localhost" \
636 0 \
637 -S "parse ServerName extension" \
638 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
639 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
640
641run_test "SNI #1 (matching cert 1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100642 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100643 crt_file=data_files/server5.crt key_file=data_files/server5.key \
644 sni='localhost,data_files/server2.crt,data_files/server2.key,PolarSSL Server 1,data_files/server1.crt,data_files/server1.key'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100645 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100646 server_name=localhost" \
647 0 \
648 -s "parse ServerName extension" \
649 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
650 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
651
652run_test "SNI #2 (matching cert 2)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100653 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100654 crt_file=data_files/server5.crt key_file=data_files/server5.key \
655 sni='localhost,data_files/server2.crt,data_files/server2.key,PolarSSL Server 1,data_files/server1.crt,data_files/server1.key'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100656 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100657 server_name='PolarSSL Server 1'" \
658 0 \
659 -s "parse ServerName extension" \
660 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
661 -c "subject name *: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
662
663run_test "SNI #3 (no matching cert)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100664 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100665 crt_file=data_files/server5.crt key_file=data_files/server5.key \
666 sni='localhost,data_files/server2.crt,data_files/server2.key,PolarSSL Server 1,data_files/server1.crt,data_files/server1.key'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100667 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100668 server_name='PolarSSL Server 2'" \
669 1 \
670 -s "parse ServerName extension" \
671 -s "ssl_sni_wrapper() returned" \
672 -s "ssl_handshake returned" \
673 -c "ssl_handshake returned" \
674 -c "SSL - A fatal alert message was received from our peer"
675
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +0100676# Tests for non-blocking I/O: exercise a variety of handshake flows
677
678run_test "Non-blocking I/O #1 (basic handshake)" \
679 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
680 "$P_CLI nbio=2 tickets=0" \
681 0 \
682 -S "ssl_handshake returned" \
683 -C "ssl_handshake returned" \
684 -c "Read from server: .* bytes read"
685
686run_test "Non-blocking I/O #2 (client auth)" \
687 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
688 "$P_CLI nbio=2 tickets=0" \
689 0 \
690 -S "ssl_handshake returned" \
691 -C "ssl_handshake returned" \
692 -c "Read from server: .* bytes read"
693
694run_test "Non-blocking I/O #3 (ticket)" \
695 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
696 "$P_CLI nbio=2 tickets=1" \
697 0 \
698 -S "ssl_handshake returned" \
699 -C "ssl_handshake returned" \
700 -c "Read from server: .* bytes read"
701
702run_test "Non-blocking I/O #4 (ticket + client auth)" \
703 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
704 "$P_CLI nbio=2 tickets=1" \
705 0 \
706 -S "ssl_handshake returned" \
707 -C "ssl_handshake returned" \
708 -c "Read from server: .* bytes read"
709
710run_test "Non-blocking I/O #5 (ticket + client auth + resume)" \
711 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
712 "$P_CLI nbio=2 tickets=1 reconnect=1" \
713 0 \
714 -S "ssl_handshake returned" \
715 -C "ssl_handshake returned" \
716 -c "Read from server: .* bytes read"
717
718run_test "Non-blocking I/O #6 (ticket + resume)" \
719 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
720 "$P_CLI nbio=2 tickets=1 reconnect=1" \
721 0 \
722 -S "ssl_handshake returned" \
723 -C "ssl_handshake returned" \
724 -c "Read from server: .* bytes read"
725
726run_test "Non-blocking I/O #7 (session-id resume)" \
727 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
728 "$P_CLI nbio=2 tickets=0 reconnect=1" \
729 0 \
730 -S "ssl_handshake returned" \
731 -C "ssl_handshake returned" \
732 -c "Read from server: .* bytes read"
733
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100734run_test "Version check #1 (all -> 1.2)" \
735 "$P_SRV" \
736 "$P_CLI" \
737 0 \
738 -S "ssl_handshake returned" \
739 -C "ssl_handshake returned" \
740 -s "Protocol is TLSv1.2" \
741 -c "Protocol is TLSv1.2"
742
743run_test "Version check #2 (cli max 1.1 -> 1.1)" \
744 "$P_SRV" \
745 "$P_CLI max_version=tls1_1" \
746 0 \
747 -S "ssl_handshake returned" \
748 -C "ssl_handshake returned" \
749 -s "Protocol is TLSv1.1" \
750 -c "Protocol is TLSv1.1"
751
752run_test "Version check #3 (srv max 1.1 -> 1.1)" \
753 "$P_SRV max_version=tls1_1" \
754 "$P_CLI" \
755 0 \
756 -S "ssl_handshake returned" \
757 -C "ssl_handshake returned" \
758 -s "Protocol is TLSv1.1" \
759 -c "Protocol is TLSv1.1"
760
761run_test "Version check #4 (cli+srv max 1.1 -> 1.1)" \
762 "$P_SRV max_version=tls1_1" \
763 "$P_CLI max_version=tls1_1" \
764 0 \
765 -S "ssl_handshake returned" \
766 -C "ssl_handshake returned" \
767 -s "Protocol is TLSv1.1" \
768 -c "Protocol is TLSv1.1"
769
770run_test "Version check #5 (cli max 1.1, srv min 1.1 -> 1.1)" \
771 "$P_SRV min_version=tls1_1" \
772 "$P_CLI max_version=tls1_1" \
773 0 \
774 -S "ssl_handshake returned" \
775 -C "ssl_handshake returned" \
776 -s "Protocol is TLSv1.1" \
777 -c "Protocol is TLSv1.1"
778
779run_test "Version check #6 (cli min 1.1, srv max 1.1 -> 1.1)" \
780 "$P_SRV max_version=tls1_1" \
781 "$P_CLI min_version=tls1_1" \
782 0 \
783 -S "ssl_handshake returned" \
784 -C "ssl_handshake returned" \
785 -s "Protocol is TLSv1.1" \
786 -c "Protocol is TLSv1.1"
787
788run_test "Version check #7 (cli min 1.2, srv max 1.1 -> fail)" \
789 "$P_SRV max_version=tls1_1" \
790 "$P_CLI min_version=tls1_2" \
791 1 \
792 -s "ssl_handshake returned" \
793 -c "ssl_handshake returned" \
794 -c "SSL - Handshake protocol not within min/max boundaries"
795
796run_test "Version check #8 (srv min 1.2, cli max 1.1 -> fail)" \
797 "$P_SRV min_version=tls1_2" \
798 "$P_CLI max_version=tls1_1" \
799 1 \
800 -s "ssl_handshake returned" \
801 -c "ssl_handshake returned" \
802 -s "SSL - Handshake protocol not within min/max boundaries"
803
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100804# Final report
805
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100806echo "------------------------------------------------------------------------"
807
808if [ $FAILS = 0 ]; then
809 echo -n "PASSED"
810else
811 echo -n "FAILED"
812fi
813PASSES=`echo $TESTS - $FAILS | bc`
Manuel Pégourié-Gonnard4145b892014-02-24 13:20:14 +0100814echo " ($PASSES / $TESTS tests)"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100815
816exit $FAILS