blob: a1e3f511f6986e8a39acd412d24ca522c5f1474e [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é-Gonnardeaadc502014-02-20 11:01:30 +010013PROGS_DIR='../programs/ssl'
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010014P_SRV="$PROGS_DIR/ssl_server2 server_addr=0.0.0.0" # force IPv4 for OpenSSL
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +010015P_CLI="$PROGS_DIR/ssl_client2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010016
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010017O_ARGS="-www -cert data_files/server5.crt -key data_files/server5.key"
18O_CLI="echo 'GET / HTTP/1.0' | openssl s_client"
19
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010020TESTS=0
21FAILS=0
22
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010023MEMCHECK=0
24
25print_usage() {
26 echo "Usage: $0 [options]"
27 echo -e " -h, --help\tPrint this help."
28 echo -e " -m, --memcheck\tCheck memory leaks."
29}
30
31get_options() {
32 while [ $# -gt 0 ]; do
33 case "$1" in
34 -m|--memcheck)
35 MEMCHECK=1
36 ;;
37 -h|--help)
38 print_usage
39 exit 0
40 ;;
41 *)
42 echo "Unkown argument: '$1'"
43 print_usage
44 exit 1
45 ;;
46 esac
47 shift
48 done
49}
50
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010051# print_name <name>
52print_name() {
53 echo -n "$1 "
54 LEN=`echo "$1" | wc -c`
55 LEN=`echo 72 - $LEN | bc`
56 for i in `seq 1 $LEN`; do echo -n '.'; done
57 echo -n ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010058
59 TESTS=`echo $TESTS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010060}
61
62# fail <message>
63fail() {
64 echo "FAIL"
65 echo " $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010066
67 cp srv_out srv-${TESTS}.log
68 cp cli_out cli-${TESTS}.log
69 echo " outputs saved to srv-${TESTS}.log and cli-${TESTS}.log"
70
71 FAILS=`echo $FAILS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010072}
73
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +010074# is_polar <cmd_line>
75is_polar() {
76 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
77}
78
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010079# has_mem_err <log_file_name>
80has_mem_err() {
81 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
82 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
83 then
84 return 1 # false: does not have errors
85 else
86 return 0 # true: has errors
87 fi
88}
89
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010090# Usage: run_test name srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010091# Options: -s pattern pattern that must be present in server output
92# -c pattern pattern that must be present in client output
93# -S pattern pattern that must be absent in server output
94# -C pattern pattern that must be absent in client output
95run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010096 NAME="$1"
97 SRV_CMD="$2"
98 CLI_CMD="$3"
99 CLI_EXPECT="$4"
100 shift 4
101
102 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100103
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100104 # prepend valgrind to our commands if active
105 if [ "$MEMCHECK" -gt 0 ]; then
106 if is_polar "$SRV_CMD"; then
107 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
108 fi
109 if is_polar "$CLI_CMD"; then
110 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
111 fi
112 fi
113
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100114 # run the commands
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100115 $SHELL -c "$SRV_CMD" > srv_out 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100116 SRV_PID=$!
117 sleep 1
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100118 $SHELL -c "$CLI_CMD" > cli_out 2>&1
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100119 CLI_EXIT=$?
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100120 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100121 echo SERVERQUIT | openssl s_client -no_ticket \
122 -cert data_files/cli2.crt -key data_files/cli2.key \
123 >/dev/null 2>&1
124 else
125 kill $SRV_PID
126 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100127 wait $SRV_PID
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100128
129 # check if the client and server went at least to the handshake stage
130 # (usefull to avoid tests with only negative assertions and non-zero
131 # expected client exit to incorrectly succeed in case of catastrophic
132 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100133 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100134 if grep "Performing the SSL/TLS handshake" srv_out >/dev/null; then :;
135 else
136 fail "server failed to start"
137 return
138 fi
139 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100140 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100141 if grep "Performing the SSL/TLS handshake" cli_out >/dev/null; then :;
142 else
143 fail "client failed to start"
144 return
145 fi
146 fi
147
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100148 # check server exit code
149 if [ $? != 0 ]; then
150 fail "server fail"
151 return
152 fi
153
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100154 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100155 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
156 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100157 then
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100158 fail "bad client exit code"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100159 return
160 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100161
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100162 # check other assertions
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100163 while [ $# -gt 0 ]
164 do
165 case $1 in
166 "-s")
167 if grep "$2" srv_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100168 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100169 return
170 fi
171 ;;
172
173 "-c")
174 if grep "$2" cli_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100175 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100176 return
177 fi
178 ;;
179
180 "-S")
181 if grep "$2" srv_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100182 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100183 return
184 fi
185 ;;
186
187 "-C")
188 if grep "$2" cli_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100189 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100190 return
191 fi
192 ;;
193
194 *)
195 echo "Unkown test: $1" >&2
196 exit 1
197 esac
198 shift 2
199 done
200
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100201 # check valgrind's results
202 if [ "$MEMCHECK" -gt 0 ]; then
203 if is_polar "$SRV_CMD" && has_mem_err srv_out; then
204 fail "Server has memory errors"
205 return
206 fi
207 if is_polar "$CLI_CMD" && has_mem_err cli_out; then
208 fail "Client has memory errors"
209 return
210 fi
211 fi
212
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100213 # if we're here, everything is ok
214 echo "PASS"
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100215 rm -f srv_out cli_out
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100216}
217
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100218cleanup() {
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100219 rm -f cli_out srv_out sess
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100220 kill $SRV_PID
221 exit 1
222}
223
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100224#
225# MAIN
226#
227
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100228get_options "$@"
229
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100230killall -q openssl ssl_server ssl_server2
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100231trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100232
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100233# Test for SSLv2 ClientHello
234
235run_test "SSLv2 ClientHello #0 (reference)" \
236 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100237 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100238 0 \
239 -S "parse client hello v2" \
240 -S "ssl_handshake returned"
241
242# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
243run_test "SSLv2 ClientHello #1 (actual test)" \
244 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100245 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100246 0 \
247 -s "parse client hello v2" \
248 -S "ssl_handshake returned"
249
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100250# Tests for Truncated HMAC extension
251
252run_test "Truncated HMAC #0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100253 "$P_SRV debug_level=5" \
254 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100255 0 \
256 -s "dumping 'computed mac' (20 bytes)"
257
258run_test "Truncated HMAC #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100259 "$P_SRV debug_level=5" \
260 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100261 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100262 -s "dumping 'computed mac' (10 bytes)"
263
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100264# Tests for Session Tickets
265
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100266run_test "Session resume using tickets #1 (basic)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100267 "$P_SRV debug_level=4 tickets=1" \
268 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100269 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100270 -c "client hello, adding session ticket extension" \
271 -s "found session ticket extension" \
272 -s "server hello, adding session ticket extension" \
273 -c "found session_ticket extension" \
274 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100275 -S "session successfully restored from cache" \
276 -s "session successfully restored from ticket" \
277 -s "a session has been resumed" \
278 -c "a session has been resumed"
279
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100280run_test "Session resume using tickets #2 (cache disabled)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100281 "$P_SRV debug_level=4 tickets=1 cache_max=0" \
282 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100283 0 \
284 -c "client hello, adding session ticket extension" \
285 -s "found session ticket extension" \
286 -s "server hello, adding session ticket extension" \
287 -c "found session_ticket extension" \
288 -c "parse new session ticket" \
289 -S "session successfully restored from cache" \
290 -s "session successfully restored from ticket" \
291 -s "a session has been resumed" \
292 -c "a session has been resumed"
293
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100294run_test "Session resume using tickets #3 (timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100295 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=1" \
296 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100297 0 \
298 -c "client hello, adding session ticket extension" \
299 -s "found session ticket extension" \
300 -s "server hello, adding session ticket extension" \
301 -c "found session_ticket extension" \
302 -c "parse new session ticket" \
303 -S "session successfully restored from cache" \
304 -S "session successfully restored from ticket" \
305 -S "a session has been resumed" \
306 -C "a session has been resumed"
307
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100308run_test "Session resume using tickets #4 (openssl server)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100309 "openssl s_server $O_ARGS" \
310 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
311 0 \
312 -c "client hello, adding session ticket extension" \
313 -c "found session_ticket extension" \
314 -c "parse new session ticket" \
315 -c "a session has been resumed"
316
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100317run_test "Session resume using tickets #5 (openssl client)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100318 "$P_SRV debug_level=4 tickets=1" \
319 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
320 0 \
321 -s "found session ticket extension" \
322 -s "server hello, adding session ticket extension" \
323 -S "session successfully restored from cache" \
324 -s "session successfully restored from ticket" \
325 -s "a session has been resumed"
326
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100327# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100328
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100329run_test "Session resume using cache #1 (tickets enabled on client)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100330 "$P_SRV debug_level=4 tickets=0" \
331 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100332 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100333 -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" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100338 -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é-Gonnardc55a5b72014-02-20 22:50:56 +0100343run_test "Session resume using cache #2 (tickets enabled on server)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100344 "$P_SRV debug_level=4 tickets=1" \
345 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100346 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100347 -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" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100352 -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"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100356
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100357run_test "Session resume using cache #3 (cache_max=0)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100358 "$P_SRV debug_level=4 tickets=0 cache_max=0" \
359 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100360 0 \
361 -S "session successfully restored from cache" \
362 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100363 -S "a session has been resumed" \
364 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100365
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100366run_test "Session resume using cache #4 (cache_max=1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100367 "$P_SRV debug_level=4 tickets=0 cache_max=1" \
368 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100369 0 \
370 -s "session successfully restored from cache" \
371 -S "session successfully restored from ticket" \
372 -s "a session has been resumed" \
373 -c "a session has been resumed"
374
375run_test "Session resume using cache #5 (timemout > delay)" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100376 "$P_SRV debug_level=4 tickets=0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100377 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100378 0 \
379 -s "session successfully restored from cache" \
380 -S "session successfully restored from ticket" \
381 -s "a session has been resumed" \
382 -c "a session has been resumed"
383
384run_test "Session resume using cache #6 (timeout < delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100385 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
386 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100387 0 \
388 -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"
392
393run_test "Session resume using cache #7 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100394 "$P_SRV debug_level=4 tickets=0 cache_timeout=0" \
395 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
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" \
399 -s "a session has been resumed" \
400 -c "a session has been resumed"
401
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100402run_test "Session resume using cache #8 (openssl client)" \
403 "$P_SRV debug_level=4 tickets=0" \
404 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
405 0 \
406 -s "found session ticket extension" \
407 -S "server hello, adding session ticket extension" \
408 -s "session successfully restored from cache" \
409 -S "session successfully restored from ticket" \
410 -s "a session has been resumed"
411
412run_test "Session resume using cache #9 (openssl server)" \
413 "openssl s_server $O_ARGS" \
414 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
415 0 \
416 -C "found session_ticket extension" \
417 -C "parse new session ticket" \
418 -c "a session has been resumed"
419
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100420# Tests for Max Fragment Length extension
421
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100422run_test "Max fragment length #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100423 "$P_SRV debug_level=4" \
424 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100425 0 \
426 -C "client hello, adding max_fragment_length extension" \
427 -S "found max fragment length extension" \
428 -S "server hello, max_fragment_length extension" \
429 -C "found max_fragment_length extension"
430
431run_test "Max fragment length #2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100432 "$P_SRV debug_level=4" \
433 "$P_CLI debug_level=4 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100434 0 \
435 -c "client hello, adding max_fragment_length extension" \
436 -s "found max fragment length extension" \
437 -s "server hello, max_fragment_length extension" \
438 -c "found max_fragment_length extension"
439
440run_test "Max fragment length #3" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100441 "$P_SRV debug_level=4 max_frag_len=4096" \
442 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100443 0 \
444 -C "client hello, adding max_fragment_length extension" \
445 -S "found max fragment length extension" \
446 -S "server hello, max_fragment_length extension" \
447 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100448
449# Tests for renegotiation
450
451run_test "Renegotiation #0 (none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100452 "$P_SRV debug_level=4" \
453 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100454 0 \
455 -C "client hello, adding renegotiation extension" \
456 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
457 -S "found renegotiation extension" \
458 -s "server hello, secure renegotiation extension" \
459 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100460 -C "=> renegotiate" \
461 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100462 -S "write hello request"
463
464run_test "Renegotiation #1 (enabled, client-initiated)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100465 "$P_SRV debug_level=4" \
466 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100467 0 \
468 -c "client hello, adding renegotiation extension" \
469 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
470 -s "found renegotiation extension" \
471 -s "server hello, secure renegotiation extension" \
472 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100473 -c "=> renegotiate" \
474 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100475 -S "write hello request"
476
477run_test "Renegotiation #2 (enabled, server-initiated)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100478 "$P_SRV debug_level=4 renegotiate=1" \
479 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100480 0 \
481 -c "client hello, adding renegotiation extension" \
482 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
483 -s "found renegotiation extension" \
484 -s "server hello, secure renegotiation extension" \
485 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100486 -c "=> renegotiate" \
487 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100488 -s "write hello request"
489
490run_test "Renegotiation #3 (enabled, double)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100491 "$P_SRV debug_level=4 renegotiate=1" \
492 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100493 0 \
494 -c "client hello, adding renegotiation extension" \
495 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
496 -s "found renegotiation extension" \
497 -s "server hello, secure renegotiation extension" \
498 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100499 -c "=> renegotiate" \
500 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100501 -s "write hello request"
502
503run_test "Renegotiation #4 (client-initiated, server-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100504 "$P_SRV debug_level=4 renegotiation=0" \
505 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100506 1 \
507 -c "client hello, adding renegotiation extension" \
508 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
509 -S "found renegotiation extension" \
510 -s "server hello, secure renegotiation extension" \
511 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100512 -c "=> renegotiate" \
513 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100514 -S "write hello request"
515
516run_test "Renegotiation #5 (server-initiated, client-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100517 "$P_SRV debug_level=4 renegotiate=1" \
518 "$P_CLI debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100519 0 \
520 -C "client hello, adding renegotiation extension" \
521 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
522 -S "found renegotiation extension" \
523 -s "server hello, secure renegotiation extension" \
524 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100525 -C "=> renegotiate" \
526 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100527 -s "write hello request" \
528 -s "SSL - An unexpected message was received from our peer" \
529 -s "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100530
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100531# Tests for auth_mode
532
533run_test "Authentication #1 (server badcert, client required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100534 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100535 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100536 "$P_CLI debug_level=2 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100537 1 \
538 -c "x509_verify_cert() returned" \
539 -c "! self-signed or not signed by a trusted CA" \
540 -c "! ssl_handshake returned" \
541 -c "X509 - Certificate verification failed"
542
543run_test "Authentication #2 (server badcert, client optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100544 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100545 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100546 "$P_CLI debug_level=2 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100547 0 \
548 -c "x509_verify_cert() returned" \
549 -c "! self-signed or not signed by a trusted CA" \
550 -C "! ssl_handshake returned" \
551 -C "X509 - Certificate verification failed"
552
553run_test "Authentication #3 (server badcert, client none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100554 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100555 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100556 "$P_CLI debug_level=2 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100557 0 \
558 -C "x509_verify_cert() returned" \
559 -C "! self-signed or not signed by a trusted CA" \
560 -C "! ssl_handshake returned" \
561 -C "X509 - Certificate verification failed"
562
563run_test "Authentication #4 (client badcert, server required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100564 "$P_SRV debug_level=4 auth_mode=required" \
565 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100566 key_file=data_files/server5.key" \
567 1 \
568 -S "skip write certificate request" \
569 -C "skip parse certificate request" \
570 -c "got a certificate request" \
571 -C "skip write certificate" \
572 -C "skip write certificate verify" \
573 -S "skip parse certificate verify" \
574 -s "x509_verify_cert() returned" \
575 -S "! self-signed or not signed by a trusted CA" \
576 -s "! ssl_handshake returned" \
577 -c "! ssl_handshake returned" \
578 -s "X509 - Certificate verification failed"
579
580run_test "Authentication #5 (client badcert, server optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100581 "$P_SRV debug_level=4 auth_mode=optional" \
582 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100583 key_file=data_files/server5.key" \
584 0 \
585 -S "skip write certificate request" \
586 -C "skip parse certificate request" \
587 -c "got a certificate request" \
588 -C "skip write certificate" \
589 -C "skip write certificate verify" \
590 -S "skip parse certificate verify" \
591 -s "x509_verify_cert() returned" \
592 -s "! self-signed or not signed by a trusted CA" \
593 -S "! ssl_handshake returned" \
594 -C "! ssl_handshake returned" \
595 -S "X509 - Certificate verification failed"
596
597run_test "Authentication #6 (client badcert, server none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100598 "$P_SRV debug_level=4 auth_mode=none" \
599 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100600 key_file=data_files/server5.key" \
601 0 \
602 -s "skip write certificate request" \
603 -C "skip parse certificate request" \
604 -c "got no certificate request" \
605 -c "skip write certificate" \
606 -c "skip write certificate verify" \
607 -s "skip parse certificate verify" \
608 -S "x509_verify_cert() returned" \
609 -S "! self-signed or not signed by a trusted CA" \
610 -S "! ssl_handshake returned" \
611 -C "! ssl_handshake returned" \
612 -S "X509 - Certificate verification failed"
613
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100614# tests for SNI
615
616run_test "SNI #0 (no SNI callback)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100617 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100618 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100619 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100620 server_name=localhost" \
621 0 \
622 -S "parse ServerName extension" \
623 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
624 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
625
626run_test "SNI #1 (matching cert 1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100627 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100628 crt_file=data_files/server5.crt key_file=data_files/server5.key \
629 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 +0100630 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100631 server_name=localhost" \
632 0 \
633 -s "parse ServerName extension" \
634 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
635 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
636
637run_test "SNI #2 (matching cert 2)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100638 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100639 crt_file=data_files/server5.crt key_file=data_files/server5.key \
640 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 +0100641 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100642 server_name='PolarSSL Server 1'" \
643 0 \
644 -s "parse ServerName extension" \
645 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
646 -c "subject name *: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
647
648run_test "SNI #3 (no matching cert)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100649 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100650 crt_file=data_files/server5.crt key_file=data_files/server5.key \
651 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 +0100652 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100653 server_name='PolarSSL Server 2'" \
654 1 \
655 -s "parse ServerName extension" \
656 -s "ssl_sni_wrapper() returned" \
657 -s "ssl_handshake returned" \
658 -c "ssl_handshake returned" \
659 -c "SSL - A fatal alert message was received from our peer"
660
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +0100661# Tests for non-blocking I/O: exercise a variety of handshake flows
662
663run_test "Non-blocking I/O #1 (basic handshake)" \
664 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
665 "$P_CLI nbio=2 tickets=0" \
666 0 \
667 -S "ssl_handshake returned" \
668 -C "ssl_handshake returned" \
669 -c "Read from server: .* bytes read"
670
671run_test "Non-blocking I/O #2 (client auth)" \
672 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
673 "$P_CLI nbio=2 tickets=0" \
674 0 \
675 -S "ssl_handshake returned" \
676 -C "ssl_handshake returned" \
677 -c "Read from server: .* bytes read"
678
679run_test "Non-blocking I/O #3 (ticket)" \
680 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
681 "$P_CLI nbio=2 tickets=1" \
682 0 \
683 -S "ssl_handshake returned" \
684 -C "ssl_handshake returned" \
685 -c "Read from server: .* bytes read"
686
687run_test "Non-blocking I/O #4 (ticket + client auth)" \
688 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
689 "$P_CLI nbio=2 tickets=1" \
690 0 \
691 -S "ssl_handshake returned" \
692 -C "ssl_handshake returned" \
693 -c "Read from server: .* bytes read"
694
695run_test "Non-blocking I/O #5 (ticket + client auth + resume)" \
696 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
697 "$P_CLI nbio=2 tickets=1 reconnect=1" \
698 0 \
699 -S "ssl_handshake returned" \
700 -C "ssl_handshake returned" \
701 -c "Read from server: .* bytes read"
702
703run_test "Non-blocking I/O #6 (ticket + resume)" \
704 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
705 "$P_CLI nbio=2 tickets=1 reconnect=1" \
706 0 \
707 -S "ssl_handshake returned" \
708 -C "ssl_handshake returned" \
709 -c "Read from server: .* bytes read"
710
711run_test "Non-blocking I/O #7 (session-id resume)" \
712 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
713 "$P_CLI nbio=2 tickets=0 reconnect=1" \
714 0 \
715 -S "ssl_handshake returned" \
716 -C "ssl_handshake returned" \
717 -c "Read from server: .* bytes read"
718
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100719run_test "Version check #1 (all -> 1.2)" \
720 "$P_SRV" \
721 "$P_CLI" \
722 0 \
723 -S "ssl_handshake returned" \
724 -C "ssl_handshake returned" \
725 -s "Protocol is TLSv1.2" \
726 -c "Protocol is TLSv1.2"
727
728run_test "Version check #2 (cli max 1.1 -> 1.1)" \
729 "$P_SRV" \
730 "$P_CLI max_version=tls1_1" \
731 0 \
732 -S "ssl_handshake returned" \
733 -C "ssl_handshake returned" \
734 -s "Protocol is TLSv1.1" \
735 -c "Protocol is TLSv1.1"
736
737run_test "Version check #3 (srv max 1.1 -> 1.1)" \
738 "$P_SRV max_version=tls1_1" \
739 "$P_CLI" \
740 0 \
741 -S "ssl_handshake returned" \
742 -C "ssl_handshake returned" \
743 -s "Protocol is TLSv1.1" \
744 -c "Protocol is TLSv1.1"
745
746run_test "Version check #4 (cli+srv max 1.1 -> 1.1)" \
747 "$P_SRV max_version=tls1_1" \
748 "$P_CLI max_version=tls1_1" \
749 0 \
750 -S "ssl_handshake returned" \
751 -C "ssl_handshake returned" \
752 -s "Protocol is TLSv1.1" \
753 -c "Protocol is TLSv1.1"
754
755run_test "Version check #5 (cli max 1.1, srv min 1.1 -> 1.1)" \
756 "$P_SRV min_version=tls1_1" \
757 "$P_CLI max_version=tls1_1" \
758 0 \
759 -S "ssl_handshake returned" \
760 -C "ssl_handshake returned" \
761 -s "Protocol is TLSv1.1" \
762 -c "Protocol is TLSv1.1"
763
764run_test "Version check #6 (cli min 1.1, srv max 1.1 -> 1.1)" \
765 "$P_SRV max_version=tls1_1" \
766 "$P_CLI min_version=tls1_1" \
767 0 \
768 -S "ssl_handshake returned" \
769 -C "ssl_handshake returned" \
770 -s "Protocol is TLSv1.1" \
771 -c "Protocol is TLSv1.1"
772
773run_test "Version check #7 (cli min 1.2, srv max 1.1 -> fail)" \
774 "$P_SRV max_version=tls1_1" \
775 "$P_CLI min_version=tls1_2" \
776 1 \
777 -s "ssl_handshake returned" \
778 -c "ssl_handshake returned" \
779 -c "SSL - Handshake protocol not within min/max boundaries"
780
781run_test "Version check #8 (srv min 1.2, cli max 1.1 -> fail)" \
782 "$P_SRV min_version=tls1_2" \
783 "$P_CLI max_version=tls1_1" \
784 1 \
785 -s "ssl_handshake returned" \
786 -c "ssl_handshake returned" \
787 -s "SSL - Handshake protocol not within min/max boundaries"
788
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100789# Final report
790
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100791echo "------------------------------------------------------------------------"
792
793if [ $FAILS = 0 ]; then
794 echo -n "PASSED"
795else
796 echo -n "FAILED"
797fi
798PASSES=`echo $TESTS - $FAILS | bc`
Manuel Pégourié-Gonnard4145b892014-02-24 13:20:14 +0100799echo " ($PASSES / $TESTS tests)"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100800
801exit $FAILS