blob: 3867eee84f32186bfa385329695b9ac33a60fa99 [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é-Gonnardc73339f2014-02-26 16:35:27 +0100224get_options "$@"
225
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100226killall -q openssl ssl_server ssl_server2
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100227trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100228
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100229# Test for SSLv2 ClientHello
230
231run_test "SSLv2 ClientHello #0 (reference)" \
232 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100233 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100234 0 \
235 -S "parse client hello v2" \
236 -S "ssl_handshake returned"
237
238# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
239run_test "SSLv2 ClientHello #1 (actual test)" \
240 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100241 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100242 0 \
243 -s "parse client hello v2" \
244 -S "ssl_handshake returned"
245
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100246# Tests for Truncated HMAC extension
247
248run_test "Truncated HMAC #0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100249 "$P_SRV debug_level=5" \
250 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100251 0 \
252 -s "dumping 'computed mac' (20 bytes)"
253
254run_test "Truncated HMAC #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100255 "$P_SRV debug_level=5" \
256 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100257 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100258 -s "dumping 'computed mac' (10 bytes)"
259
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100260# Tests for Session Tickets
261
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100262run_test "Session resume using tickets #1 (basic)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100263 "$P_SRV debug_level=4 tickets=1" \
264 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100265 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100266 -c "client hello, adding session ticket extension" \
267 -s "found session ticket extension" \
268 -s "server hello, adding session ticket extension" \
269 -c "found session_ticket extension" \
270 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100271 -S "session successfully restored from cache" \
272 -s "session successfully restored from ticket" \
273 -s "a session has been resumed" \
274 -c "a session has been resumed"
275
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100276run_test "Session resume using tickets #2 (cache disabled)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100277 "$P_SRV debug_level=4 tickets=1 cache_max=0" \
278 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100279 0 \
280 -c "client hello, adding session ticket extension" \
281 -s "found session ticket extension" \
282 -s "server hello, adding session ticket extension" \
283 -c "found session_ticket extension" \
284 -c "parse new session ticket" \
285 -S "session successfully restored from cache" \
286 -s "session successfully restored from ticket" \
287 -s "a session has been resumed" \
288 -c "a session has been resumed"
289
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100290run_test "Session resume using tickets #3 (timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100291 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=1" \
292 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100293 0 \
294 -c "client hello, adding session ticket extension" \
295 -s "found session ticket extension" \
296 -s "server hello, adding session ticket extension" \
297 -c "found session_ticket extension" \
298 -c "parse new session ticket" \
299 -S "session successfully restored from cache" \
300 -S "session successfully restored from ticket" \
301 -S "a session has been resumed" \
302 -C "a session has been resumed"
303
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100304run_test "Session resume using tickets #4 (openssl server)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100305 "openssl s_server $O_ARGS" \
306 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
307 0 \
308 -c "client hello, adding session ticket extension" \
309 -c "found session_ticket extension" \
310 -c "parse new session ticket" \
311 -c "a session has been resumed"
312
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100313run_test "Session resume using tickets #5 (openssl client)" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100314 "$P_SRV debug_level=4 tickets=1" \
315 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
316 0 \
317 -s "found session ticket extension" \
318 -s "server hello, adding session ticket extension" \
319 -S "session successfully restored from cache" \
320 -s "session successfully restored from ticket" \
321 -s "a session has been resumed"
322
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100323# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100324
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100325run_test "Session resume using cache #1 (tickets enabled on client)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100326 "$P_SRV debug_level=4 tickets=0" \
327 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100328 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100329 -c "client hello, adding session ticket extension" \
330 -s "found session ticket extension" \
331 -S "server hello, adding session ticket extension" \
332 -C "found session_ticket extension" \
333 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100334 -s "session successfully restored from cache" \
335 -S "session successfully restored from ticket" \
336 -s "a session has been resumed" \
337 -c "a session has been resumed"
338
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100339run_test "Session resume using cache #2 (tickets enabled on server)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100340 "$P_SRV debug_level=4 tickets=1" \
341 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100342 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100343 -C "client hello, adding session ticket extension" \
344 -S "found session ticket extension" \
345 -S "server hello, adding session ticket extension" \
346 -C "found session_ticket extension" \
347 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100348 -s "session successfully restored from cache" \
349 -S "session successfully restored from ticket" \
350 -s "a session has been resumed" \
351 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100352
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100353run_test "Session resume using cache #3 (cache_max=0)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100354 "$P_SRV debug_level=4 tickets=0 cache_max=0" \
355 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100356 0 \
357 -S "session successfully restored from cache" \
358 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100359 -S "a session has been resumed" \
360 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100361
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100362run_test "Session resume using cache #4 (cache_max=1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100363 "$P_SRV debug_level=4 tickets=0 cache_max=1" \
364 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100365 0 \
366 -s "session successfully restored from cache" \
367 -S "session successfully restored from ticket" \
368 -s "a session has been resumed" \
369 -c "a session has been resumed"
370
371run_test "Session resume using cache #5 (timemout > delay)" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100372 "$P_SRV debug_level=4 tickets=0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100373 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100374 0 \
375 -s "session successfully restored from cache" \
376 -S "session successfully restored from ticket" \
377 -s "a session has been resumed" \
378 -c "a session has been resumed"
379
380run_test "Session resume using cache #6 (timeout < delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100381 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
382 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100383 0 \
384 -S "session successfully restored from cache" \
385 -S "session successfully restored from ticket" \
386 -S "a session has been resumed" \
387 -C "a session has been resumed"
388
389run_test "Session resume using cache #7 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100390 "$P_SRV debug_level=4 tickets=0 cache_timeout=0" \
391 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100392 0 \
393 -s "session successfully restored from cache" \
394 -S "session successfully restored from ticket" \
395 -s "a session has been resumed" \
396 -c "a session has been resumed"
397
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100398run_test "Session resume using cache #8 (openssl client)" \
399 "$P_SRV debug_level=4 tickets=0" \
400 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
401 0 \
402 -s "found session ticket extension" \
403 -S "server hello, adding session ticket extension" \
404 -s "session successfully restored from cache" \
405 -S "session successfully restored from ticket" \
406 -s "a session has been resumed"
407
408run_test "Session resume using cache #9 (openssl server)" \
409 "openssl s_server $O_ARGS" \
410 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
411 0 \
412 -C "found session_ticket extension" \
413 -C "parse new session ticket" \
414 -c "a session has been resumed"
415
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100416# Tests for Max Fragment Length extension
417
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100418run_test "Max fragment length #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100419 "$P_SRV debug_level=4" \
420 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100421 0 \
422 -C "client hello, adding max_fragment_length extension" \
423 -S "found max fragment length extension" \
424 -S "server hello, max_fragment_length extension" \
425 -C "found max_fragment_length extension"
426
427run_test "Max fragment length #2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100428 "$P_SRV debug_level=4" \
429 "$P_CLI debug_level=4 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100430 0 \
431 -c "client hello, adding max_fragment_length extension" \
432 -s "found max fragment length extension" \
433 -s "server hello, max_fragment_length extension" \
434 -c "found max_fragment_length extension"
435
436run_test "Max fragment length #3" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100437 "$P_SRV debug_level=4 max_frag_len=4096" \
438 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100439 0 \
440 -C "client hello, adding max_fragment_length extension" \
441 -S "found max fragment length extension" \
442 -S "server hello, max_fragment_length extension" \
443 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100444
445# Tests for renegotiation
446
447run_test "Renegotiation #0 (none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100448 "$P_SRV debug_level=4" \
449 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100450 0 \
451 -C "client hello, adding renegotiation extension" \
452 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
453 -S "found renegotiation extension" \
454 -s "server hello, secure renegotiation extension" \
455 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100456 -C "=> renegotiate" \
457 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100458 -S "write hello request"
459
460run_test "Renegotiation #1 (enabled, client-initiated)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100461 "$P_SRV debug_level=4" \
462 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100463 0 \
464 -c "client hello, adding renegotiation extension" \
465 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
466 -s "found renegotiation extension" \
467 -s "server hello, secure renegotiation extension" \
468 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100469 -c "=> renegotiate" \
470 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100471 -S "write hello request"
472
473run_test "Renegotiation #2 (enabled, server-initiated)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100474 "$P_SRV debug_level=4 renegotiate=1" \
475 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100476 0 \
477 -c "client hello, adding renegotiation extension" \
478 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
479 -s "found renegotiation extension" \
480 -s "server hello, secure renegotiation extension" \
481 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100482 -c "=> renegotiate" \
483 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100484 -s "write hello request"
485
486run_test "Renegotiation #3 (enabled, double)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100487 "$P_SRV debug_level=4 renegotiate=1" \
488 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100489 0 \
490 -c "client hello, adding renegotiation extension" \
491 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
492 -s "found renegotiation extension" \
493 -s "server hello, secure renegotiation extension" \
494 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100495 -c "=> renegotiate" \
496 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100497 -s "write hello request"
498
499run_test "Renegotiation #4 (client-initiated, server-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100500 "$P_SRV debug_level=4 renegotiation=0" \
501 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100502 1 \
503 -c "client hello, adding renegotiation extension" \
504 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
505 -S "found renegotiation extension" \
506 -s "server hello, secure renegotiation extension" \
507 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100508 -c "=> renegotiate" \
509 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100510 -S "write hello request"
511
512run_test "Renegotiation #5 (server-initiated, client-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100513 "$P_SRV debug_level=4 renegotiate=1" \
514 "$P_CLI debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100515 0 \
516 -C "client hello, adding renegotiation extension" \
517 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
518 -S "found renegotiation extension" \
519 -s "server hello, secure renegotiation extension" \
520 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100521 -C "=> renegotiate" \
522 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100523 -s "write hello request" \
524 -s "SSL - An unexpected message was received from our peer" \
525 -s "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100526
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100527# Tests for auth_mode
528
529run_test "Authentication #1 (server badcert, client required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100530 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100531 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100532 "$P_CLI debug_level=2 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100533 1 \
534 -c "x509_verify_cert() returned" \
535 -c "! self-signed or not signed by a trusted CA" \
536 -c "! ssl_handshake returned" \
537 -c "X509 - Certificate verification failed"
538
539run_test "Authentication #2 (server badcert, client optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100540 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100541 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100542 "$P_CLI debug_level=2 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100543 0 \
544 -c "x509_verify_cert() returned" \
545 -c "! self-signed or not signed by a trusted CA" \
546 -C "! ssl_handshake returned" \
547 -C "X509 - Certificate verification failed"
548
549run_test "Authentication #3 (server badcert, client none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100550 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100551 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100552 "$P_CLI debug_level=2 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100553 0 \
554 -C "x509_verify_cert() returned" \
555 -C "! self-signed or not signed by a trusted CA" \
556 -C "! ssl_handshake returned" \
557 -C "X509 - Certificate verification failed"
558
559run_test "Authentication #4 (client badcert, server required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100560 "$P_SRV debug_level=4 auth_mode=required" \
561 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100562 key_file=data_files/server5.key" \
563 1 \
564 -S "skip write certificate request" \
565 -C "skip parse certificate request" \
566 -c "got a certificate request" \
567 -C "skip write certificate" \
568 -C "skip write certificate verify" \
569 -S "skip parse certificate verify" \
570 -s "x509_verify_cert() returned" \
571 -S "! self-signed or not signed by a trusted CA" \
572 -s "! ssl_handshake returned" \
573 -c "! ssl_handshake returned" \
574 -s "X509 - Certificate verification failed"
575
576run_test "Authentication #5 (client badcert, server optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100577 "$P_SRV debug_level=4 auth_mode=optional" \
578 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100579 key_file=data_files/server5.key" \
580 0 \
581 -S "skip write certificate request" \
582 -C "skip parse certificate request" \
583 -c "got a certificate request" \
584 -C "skip write certificate" \
585 -C "skip write certificate verify" \
586 -S "skip parse certificate verify" \
587 -s "x509_verify_cert() returned" \
588 -s "! self-signed or not signed by a trusted CA" \
589 -S "! ssl_handshake returned" \
590 -C "! ssl_handshake returned" \
591 -S "X509 - Certificate verification failed"
592
593run_test "Authentication #6 (client badcert, server none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100594 "$P_SRV debug_level=4 auth_mode=none" \
595 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100596 key_file=data_files/server5.key" \
597 0 \
598 -s "skip write certificate request" \
599 -C "skip parse certificate request" \
600 -c "got no certificate request" \
601 -c "skip write certificate" \
602 -c "skip write certificate verify" \
603 -s "skip parse certificate verify" \
604 -S "x509_verify_cert() returned" \
605 -S "! self-signed or not signed by a trusted CA" \
606 -S "! ssl_handshake returned" \
607 -C "! ssl_handshake returned" \
608 -S "X509 - Certificate verification failed"
609
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100610# tests for SNI
611
612run_test "SNI #0 (no SNI callback)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100613 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100614 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100615 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100616 server_name=localhost" \
617 0 \
618 -S "parse ServerName extension" \
619 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
620 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
621
622run_test "SNI #1 (matching cert 1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100623 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100624 crt_file=data_files/server5.crt key_file=data_files/server5.key \
625 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 +0100626 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100627 server_name=localhost" \
628 0 \
629 -s "parse ServerName extension" \
630 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
631 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
632
633run_test "SNI #2 (matching cert 2)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100634 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100635 crt_file=data_files/server5.crt key_file=data_files/server5.key \
636 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 +0100637 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100638 server_name='PolarSSL Server 1'" \
639 0 \
640 -s "parse ServerName extension" \
641 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
642 -c "subject name *: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
643
644run_test "SNI #3 (no matching cert)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100645 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100646 crt_file=data_files/server5.crt key_file=data_files/server5.key \
647 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 +0100648 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100649 server_name='PolarSSL Server 2'" \
650 1 \
651 -s "parse ServerName extension" \
652 -s "ssl_sni_wrapper() returned" \
653 -s "ssl_handshake returned" \
654 -c "ssl_handshake returned" \
655 -c "SSL - A fatal alert message was received from our peer"
656
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +0100657# Tests for non-blocking I/O: exercise a variety of handshake flows
658
659run_test "Non-blocking I/O #1 (basic handshake)" \
660 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
661 "$P_CLI nbio=2 tickets=0" \
662 0 \
663 -S "ssl_handshake returned" \
664 -C "ssl_handshake returned" \
665 -c "Read from server: .* bytes read"
666
667run_test "Non-blocking I/O #2 (client auth)" \
668 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
669 "$P_CLI nbio=2 tickets=0" \
670 0 \
671 -S "ssl_handshake returned" \
672 -C "ssl_handshake returned" \
673 -c "Read from server: .* bytes read"
674
675run_test "Non-blocking I/O #3 (ticket)" \
676 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
677 "$P_CLI nbio=2 tickets=1" \
678 0 \
679 -S "ssl_handshake returned" \
680 -C "ssl_handshake returned" \
681 -c "Read from server: .* bytes read"
682
683run_test "Non-blocking I/O #4 (ticket + client auth)" \
684 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
685 "$P_CLI nbio=2 tickets=1" \
686 0 \
687 -S "ssl_handshake returned" \
688 -C "ssl_handshake returned" \
689 -c "Read from server: .* bytes read"
690
691run_test "Non-blocking I/O #5 (ticket + client auth + resume)" \
692 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
693 "$P_CLI nbio=2 tickets=1 reconnect=1" \
694 0 \
695 -S "ssl_handshake returned" \
696 -C "ssl_handshake returned" \
697 -c "Read from server: .* bytes read"
698
699run_test "Non-blocking I/O #6 (ticket + resume)" \
700 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
701 "$P_CLI nbio=2 tickets=1 reconnect=1" \
702 0 \
703 -S "ssl_handshake returned" \
704 -C "ssl_handshake returned" \
705 -c "Read from server: .* bytes read"
706
707run_test "Non-blocking I/O #7 (session-id resume)" \
708 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
709 "$P_CLI nbio=2 tickets=0 reconnect=1" \
710 0 \
711 -S "ssl_handshake returned" \
712 -C "ssl_handshake returned" \
713 -c "Read from server: .* bytes read"
714
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100715run_test "Version check #1 (all -> 1.2)" \
716 "$P_SRV" \
717 "$P_CLI" \
718 0 \
719 -S "ssl_handshake returned" \
720 -C "ssl_handshake returned" \
721 -s "Protocol is TLSv1.2" \
722 -c "Protocol is TLSv1.2"
723
724run_test "Version check #2 (cli max 1.1 -> 1.1)" \
725 "$P_SRV" \
726 "$P_CLI max_version=tls1_1" \
727 0 \
728 -S "ssl_handshake returned" \
729 -C "ssl_handshake returned" \
730 -s "Protocol is TLSv1.1" \
731 -c "Protocol is TLSv1.1"
732
733run_test "Version check #3 (srv max 1.1 -> 1.1)" \
734 "$P_SRV max_version=tls1_1" \
735 "$P_CLI" \
736 0 \
737 -S "ssl_handshake returned" \
738 -C "ssl_handshake returned" \
739 -s "Protocol is TLSv1.1" \
740 -c "Protocol is TLSv1.1"
741
742run_test "Version check #4 (cli+srv max 1.1 -> 1.1)" \
743 "$P_SRV max_version=tls1_1" \
744 "$P_CLI max_version=tls1_1" \
745 0 \
746 -S "ssl_handshake returned" \
747 -C "ssl_handshake returned" \
748 -s "Protocol is TLSv1.1" \
749 -c "Protocol is TLSv1.1"
750
751run_test "Version check #5 (cli max 1.1, srv min 1.1 -> 1.1)" \
752 "$P_SRV min_version=tls1_1" \
753 "$P_CLI max_version=tls1_1" \
754 0 \
755 -S "ssl_handshake returned" \
756 -C "ssl_handshake returned" \
757 -s "Protocol is TLSv1.1" \
758 -c "Protocol is TLSv1.1"
759
760run_test "Version check #6 (cli min 1.1, srv max 1.1 -> 1.1)" \
761 "$P_SRV max_version=tls1_1" \
762 "$P_CLI min_version=tls1_1" \
763 0 \
764 -S "ssl_handshake returned" \
765 -C "ssl_handshake returned" \
766 -s "Protocol is TLSv1.1" \
767 -c "Protocol is TLSv1.1"
768
769run_test "Version check #7 (cli min 1.2, srv max 1.1 -> fail)" \
770 "$P_SRV max_version=tls1_1" \
771 "$P_CLI min_version=tls1_2" \
772 1 \
773 -s "ssl_handshake returned" \
774 -c "ssl_handshake returned" \
775 -c "SSL - Handshake protocol not within min/max boundaries"
776
777run_test "Version check #8 (srv min 1.2, cli max 1.1 -> fail)" \
778 "$P_SRV min_version=tls1_2" \
779 "$P_CLI max_version=tls1_1" \
780 1 \
781 -s "ssl_handshake returned" \
782 -c "ssl_handshake returned" \
783 -s "SSL - Handshake protocol not within min/max boundaries"
784
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100785# Final report
786
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100787echo "------------------------------------------------------------------------"
788
789if [ $FAILS = 0 ]; then
790 echo -n "PASSED"
791else
792 echo -n "FAILED"
793fi
794PASSES=`echo $TESTS - $FAILS | bc`
Manuel Pégourié-Gonnard4145b892014-02-24 13:20:14 +0100795echo " ($PASSES / $TESTS tests)"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100796
797exit $FAILS