blob: 7af8b9b98acc061611d50147b4a034b61f940532 [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é-Gonnardf8bdbb52014-02-21 09:20:14 +010023# print_name <name>
24print_name() {
25 echo -n "$1 "
26 LEN=`echo "$1" | wc -c`
27 LEN=`echo 72 - $LEN | bc`
28 for i in `seq 1 $LEN`; do echo -n '.'; done
29 echo -n ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010030
31 TESTS=`echo $TESTS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010032}
33
34# fail <message>
35fail() {
36 echo "FAIL"
37 echo " $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010038
39 cp srv_out srv-${TESTS}.log
40 cp cli_out cli-${TESTS}.log
41 echo " outputs saved to srv-${TESTS}.log and cli-${TESTS}.log"
42
43 FAILS=`echo $FAILS + 1 | bc`
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010044}
45
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +010046# is_polar <cmd_line>
47is_polar() {
48 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
49}
50
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010051# Usage: run_test name srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010052# Options: -s pattern pattern that must be present in server output
53# -c pattern pattern that must be present in client output
54# -S pattern pattern that must be absent in server output
55# -C pattern pattern that must be absent in client output
56run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010057 NAME="$1"
58 SRV_CMD="$2"
59 CLI_CMD="$3"
60 CLI_EXPECT="$4"
61 shift 4
62
63 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010064
65 # run the commands
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010066 $SHELL -c "$SRV_CMD" > srv_out 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010067 SRV_PID=$!
68 sleep 1
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010069 $SHELL -c "$CLI_CMD" > cli_out 2>&1
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010070 CLI_EXIT=$?
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010071 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +010072 echo SERVERQUIT | openssl s_client -no_ticket \
73 -cert data_files/cli2.crt -key data_files/cli2.key \
74 >/dev/null 2>&1
75 else
76 kill $SRV_PID
77 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010078 wait $SRV_PID
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +010079
80 # check if the client and server went at least to the handshake stage
81 # (usefull to avoid tests with only negative assertions and non-zero
82 # expected client exit to incorrectly succeed in case of catastrophic
83 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010084 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +010085 if grep "Performing the SSL/TLS handshake" srv_out >/dev/null; then :;
86 else
87 fail "server failed to start"
88 return
89 fi
90 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010091 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +010092 if grep "Performing the SSL/TLS handshake" cli_out >/dev/null; then :;
93 else
94 fail "client failed to start"
95 return
96 fi
97 fi
98
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +010099 # check server exit code
100 if [ $? != 0 ]; then
101 fail "server fail"
102 return
103 fi
104
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100105 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100106 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
107 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100108 then
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100109 fail "bad client exit code"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100110 return
111 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100112
113 # check options
114 while [ $# -gt 0 ]
115 do
116 case $1 in
117 "-s")
118 if grep "$2" srv_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100119 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100120 return
121 fi
122 ;;
123
124 "-c")
125 if grep "$2" cli_out >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100126 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100127 return
128 fi
129 ;;
130
131 "-S")
132 if grep "$2" srv_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100133 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100134 return
135 fi
136 ;;
137
138 "-C")
139 if grep "$2" cli_out >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100140 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100141 return
142 fi
143 ;;
144
145 *)
146 echo "Unkown test: $1" >&2
147 exit 1
148 esac
149 shift 2
150 done
151
152 # if we're here, everything is ok
153 echo "PASS"
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100154 rm -f srv_out cli_out
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100155}
156
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100157cleanup() {
158 kill $SRV_PID
159 exit 1
160}
161
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100162killall -q openssl ssl_server ssl_server2
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100163trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100164
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100165# Test for SSLv2 ClientHello
166
167run_test "SSLv2 ClientHello #0 (reference)" \
168 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100169 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100170 0 \
171 -S "parse client hello v2" \
172 -S "ssl_handshake returned"
173
174# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
175run_test "SSLv2 ClientHello #1 (actual test)" \
176 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100177 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100178 0 \
179 -s "parse client hello v2" \
180 -S "ssl_handshake returned"
181
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100182# Tests for Truncated HMAC extension
183
184run_test "Truncated HMAC #0" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100185 "$P_SRV debug_level=5" \
186 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100187 0 \
188 -s "dumping 'computed mac' (20 bytes)"
189
190run_test "Truncated HMAC #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100191 "$P_SRV debug_level=5" \
192 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100193 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100194 -s "dumping 'computed mac' (10 bytes)"
195
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100196# Tests for Session Tickets
197
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100198run_test "Session resume using tickets #1 (basic)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100199 "$P_SRV debug_level=4 tickets=1" \
200 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100201 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100202 -c "client hello, adding session ticket extension" \
203 -s "found session ticket extension" \
204 -s "server hello, adding session ticket extension" \
205 -c "found session_ticket extension" \
206 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100207 -S "session successfully restored from cache" \
208 -s "session successfully restored from ticket" \
209 -s "a session has been resumed" \
210 -c "a session has been resumed"
211
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100212run_test "Session resume using tickets #2 (cache disabled)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100213 "$P_SRV debug_level=4 tickets=1 cache_max=0" \
214 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100215 0 \
216 -c "client hello, adding session ticket extension" \
217 -s "found session ticket extension" \
218 -s "server hello, adding session ticket extension" \
219 -c "found session_ticket extension" \
220 -c "parse new session ticket" \
221 -S "session successfully restored from cache" \
222 -s "session successfully restored from ticket" \
223 -s "a session has been resumed" \
224 -c "a session has been resumed"
225
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100226run_test "Session resume using tickets #3 (timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100227 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=1" \
228 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100229 0 \
230 -c "client hello, adding session ticket extension" \
231 -s "found session ticket extension" \
232 -s "server hello, adding session ticket extension" \
233 -c "found session_ticket extension" \
234 -c "parse new session ticket" \
235 -S "session successfully restored from cache" \
236 -S "session successfully restored from ticket" \
237 -S "a session has been resumed" \
238 -C "a session has been resumed"
239
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100240run_test "Session resume using tickets #4 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100241 "$P_SRV debug_level=4 tickets=1 cache_max=0 ticket_timeout=2" \
242 "$P_CLI debug_level=4 tickets=1 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100243 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100244 -c "client hello, adding session ticket extension" \
245 -s "found session ticket extension" \
246 -s "server hello, adding session ticket extension" \
247 -c "found session_ticket extension" \
248 -c "parse new session ticket" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100249 -S "session successfully restored from cache" \
250 -s "session successfully restored from ticket" \
251 -s "a session has been resumed" \
252 -c "a session has been resumed"
253
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100254run_test "Session resume using tickets #5 (openssl server)" \
255 "openssl s_server $O_ARGS" \
256 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
257 0 \
258 -c "client hello, adding session ticket extension" \
259 -c "found session_ticket extension" \
260 -c "parse new session ticket" \
261 -c "a session has been resumed"
262
263run_test "Session resume using tickets #6 (openssl client)" \
264 "$P_SRV debug_level=4 tickets=1" \
265 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
266 0 \
267 -s "found session ticket extension" \
268 -s "server hello, adding session ticket extension" \
269 -S "session successfully restored from cache" \
270 -s "session successfully restored from ticket" \
271 -s "a session has been resumed"
272
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100273# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100274
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100275run_test "Session resume using cache #1 (tickets enabled on client)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100276 "$P_SRV debug_level=4 tickets=0" \
277 "$P_CLI debug_level=4 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100278 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100279 -c "client hello, adding session ticket extension" \
280 -s "found session ticket extension" \
281 -S "server hello, adding session ticket extension" \
282 -C "found session_ticket extension" \
283 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100284 -s "session successfully restored from cache" \
285 -S "session successfully restored from ticket" \
286 -s "a session has been resumed" \
287 -c "a session has been resumed"
288
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100289run_test "Session resume using cache #2 (tickets enabled on server)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100290 "$P_SRV debug_level=4 tickets=1" \
291 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100292 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100293 -C "client hello, adding session ticket extension" \
294 -S "found session ticket extension" \
295 -S "server hello, adding session ticket extension" \
296 -C "found session_ticket extension" \
297 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100298 -s "session successfully restored from cache" \
299 -S "session successfully restored from ticket" \
300 -s "a session has been resumed" \
301 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100302
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100303run_test "Session resume using cache #3 (cache_max=0)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100304 "$P_SRV debug_level=4 tickets=0 cache_max=0" \
305 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100306 0 \
307 -S "session successfully restored from cache" \
308 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100309 -S "a session has been resumed" \
310 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100311
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100312run_test "Session resume using cache #4 (cache_max=1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100313 "$P_SRV debug_level=4 tickets=0 cache_max=1" \
314 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100315 0 \
316 -s "session successfully restored from cache" \
317 -S "session successfully restored from ticket" \
318 -s "a session has been resumed" \
319 -c "a session has been resumed"
320
321run_test "Session resume using cache #5 (timemout > delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100322 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
323 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100324 0 \
325 -s "session successfully restored from cache" \
326 -S "session successfully restored from ticket" \
327 -s "a session has been resumed" \
328 -c "a session has been resumed"
329
330run_test "Session resume using cache #6 (timeout < delay)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100331 "$P_SRV debug_level=4 tickets=0 cache_timeout=1" \
332 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100333 0 \
334 -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
339run_test "Session resume using cache #7 (no timeout)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100340 "$P_SRV debug_level=4 tickets=0 cache_timeout=0" \
341 "$P_CLI debug_level=4 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100342 0 \
343 -s "session successfully restored from cache" \
344 -S "session successfully restored from ticket" \
345 -s "a session has been resumed" \
346 -c "a session has been resumed"
347
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100348run_test "Session resume using cache #8 (openssl client)" \
349 "$P_SRV debug_level=4 tickets=0" \
350 "($O_CLI -sess_out sess; $O_CLI -sess_in sess; rm -f sess)" \
351 0 \
352 -s "found session ticket extension" \
353 -S "server hello, adding session ticket extension" \
354 -s "session successfully restored from cache" \
355 -S "session successfully restored from ticket" \
356 -s "a session has been resumed"
357
358run_test "Session resume using cache #9 (openssl server)" \
359 "openssl s_server $O_ARGS" \
360 "$P_CLI debug_level=4 tickets=0 reconnect=1" \
361 0 \
362 -C "found session_ticket extension" \
363 -C "parse new session ticket" \
364 -c "a session has been resumed"
365
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100366# Tests for Max Fragment Length extension
367
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100368run_test "Max fragment length #1" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100369 "$P_SRV debug_level=4" \
370 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100371 0 \
372 -C "client hello, adding max_fragment_length extension" \
373 -S "found max fragment length extension" \
374 -S "server hello, max_fragment_length extension" \
375 -C "found max_fragment_length extension"
376
377run_test "Max fragment length #2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100378 "$P_SRV debug_level=4" \
379 "$P_CLI debug_level=4 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100380 0 \
381 -c "client hello, adding max_fragment_length extension" \
382 -s "found max fragment length extension" \
383 -s "server hello, max_fragment_length extension" \
384 -c "found max_fragment_length extension"
385
386run_test "Max fragment length #3" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100387 "$P_SRV debug_level=4 max_frag_len=4096" \
388 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100389 0 \
390 -C "client hello, adding max_fragment_length extension" \
391 -S "found max fragment length extension" \
392 -S "server hello, max_fragment_length extension" \
393 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100394
395# Tests for renegotiation
396
397run_test "Renegotiation #0 (none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100398 "$P_SRV debug_level=4" \
399 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100400 0 \
401 -C "client hello, adding renegotiation extension" \
402 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
403 -S "found renegotiation extension" \
404 -s "server hello, secure renegotiation extension" \
405 -c "found renegotiation extension" \
406 -C "renegotiate" \
407 -S "renegotiate" \
408 -S "write hello request"
409
410run_test "Renegotiation #1 (enabled, client-initiated)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100411 "$P_SRV debug_level=4" \
412 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100413 0 \
414 -c "client hello, adding renegotiation extension" \
415 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
416 -s "found renegotiation extension" \
417 -s "server hello, secure renegotiation extension" \
418 -c "found renegotiation extension" \
419 -c "renegotiate" \
420 -s "renegotiate" \
421 -S "write hello request"
422
423run_test "Renegotiation #2 (enabled, server-initiated)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100424 "$P_SRV debug_level=4 renegotiate=1" \
425 "$P_CLI debug_level=4" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100426 0 \
427 -c "client hello, adding renegotiation extension" \
428 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
429 -s "found renegotiation extension" \
430 -s "server hello, secure renegotiation extension" \
431 -c "found renegotiation extension" \
432 -c "renegotiate" \
433 -s "renegotiate" \
434 -s "write hello request"
435
436run_test "Renegotiation #3 (enabled, double)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100437 "$P_SRV debug_level=4 renegotiate=1" \
438 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100439 0 \
440 -c "client hello, adding renegotiation extension" \
441 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
442 -s "found renegotiation extension" \
443 -s "server hello, secure renegotiation extension" \
444 -c "found renegotiation extension" \
445 -c "renegotiate" \
446 -s "renegotiate" \
447 -s "write hello request"
448
449run_test "Renegotiation #4 (client-initiated, server-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100450 "$P_SRV debug_level=4 renegotiation=0" \
451 "$P_CLI debug_level=4 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100452 1 \
453 -c "client hello, adding renegotiation extension" \
454 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
455 -S "found renegotiation extension" \
456 -s "server hello, secure renegotiation extension" \
457 -c "found renegotiation extension" \
458 -c "renegotiate" \
459 -S "renegotiate" \
460 -S "write hello request"
461
462run_test "Renegotiation #5 (server-initiated, client-rejected)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100463 "$P_SRV debug_level=4 renegotiate=1" \
464 "$P_CLI debug_level=4 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100465 0 \
466 -C "client hello, adding renegotiation extension" \
467 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
468 -S "found renegotiation extension" \
469 -s "server hello, secure renegotiation extension" \
470 -c "found renegotiation extension" \
471 -C "renegotiate" \
472 -S "renegotiate" \
473 -s "write hello request" \
474 -s "SSL - An unexpected message was received from our peer" \
475 -s "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100476
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100477# Tests for auth_mode
478
479run_test "Authentication #1 (server badcert, client required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100480 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100481 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100482 "$P_CLI debug_level=2 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100483 1 \
484 -c "x509_verify_cert() returned" \
485 -c "! self-signed or not signed by a trusted CA" \
486 -c "! ssl_handshake returned" \
487 -c "X509 - Certificate verification failed"
488
489run_test "Authentication #2 (server badcert, client optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100490 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100491 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100492 "$P_CLI debug_level=2 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100493 0 \
494 -c "x509_verify_cert() returned" \
495 -c "! self-signed or not signed by a trusted CA" \
496 -C "! ssl_handshake returned" \
497 -C "X509 - Certificate verification failed"
498
499run_test "Authentication #3 (server badcert, client none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100500 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100501 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100502 "$P_CLI debug_level=2 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100503 0 \
504 -C "x509_verify_cert() returned" \
505 -C "! self-signed or not signed by a trusted CA" \
506 -C "! ssl_handshake returned" \
507 -C "X509 - Certificate verification failed"
508
509run_test "Authentication #4 (client badcert, server required)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100510 "$P_SRV debug_level=4 auth_mode=required" \
511 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100512 key_file=data_files/server5.key" \
513 1 \
514 -S "skip write certificate request" \
515 -C "skip parse certificate request" \
516 -c "got a certificate request" \
517 -C "skip write certificate" \
518 -C "skip write certificate verify" \
519 -S "skip parse certificate verify" \
520 -s "x509_verify_cert() returned" \
521 -S "! self-signed or not signed by a trusted CA" \
522 -s "! ssl_handshake returned" \
523 -c "! ssl_handshake returned" \
524 -s "X509 - Certificate verification failed"
525
526run_test "Authentication #5 (client badcert, server optional)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100527 "$P_SRV debug_level=4 auth_mode=optional" \
528 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100529 key_file=data_files/server5.key" \
530 0 \
531 -S "skip write certificate request" \
532 -C "skip parse certificate request" \
533 -c "got a certificate request" \
534 -C "skip write certificate" \
535 -C "skip write certificate verify" \
536 -S "skip parse certificate verify" \
537 -s "x509_verify_cert() returned" \
538 -s "! self-signed or not signed by a trusted CA" \
539 -S "! ssl_handshake returned" \
540 -C "! ssl_handshake returned" \
541 -S "X509 - Certificate verification failed"
542
543run_test "Authentication #6 (client badcert, server none)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100544 "$P_SRV debug_level=4 auth_mode=none" \
545 "$P_CLI debug_level=4 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100546 key_file=data_files/server5.key" \
547 0 \
548 -s "skip write certificate request" \
549 -C "skip parse certificate request" \
550 -c "got no certificate request" \
551 -c "skip write certificate" \
552 -c "skip write certificate verify" \
553 -s "skip parse certificate verify" \
554 -S "x509_verify_cert() returned" \
555 -S "! self-signed or not signed by a trusted CA" \
556 -S "! ssl_handshake returned" \
557 -C "! ssl_handshake returned" \
558 -S "X509 - Certificate verification failed"
559
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100560# tests for SNI
561
562run_test "SNI #0 (no SNI callback)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100563 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100564 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100565 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100566 server_name=localhost" \
567 0 \
568 -S "parse ServerName extension" \
569 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
570 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
571
572run_test "SNI #1 (matching cert 1)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100573 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100574 crt_file=data_files/server5.crt key_file=data_files/server5.key \
575 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 +0100576 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100577 server_name=localhost" \
578 0 \
579 -s "parse ServerName extension" \
580 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
581 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
582
583run_test "SNI #2 (matching cert 2)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100584 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100585 crt_file=data_files/server5.crt key_file=data_files/server5.key \
586 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 +0100587 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100588 server_name='PolarSSL Server 1'" \
589 0 \
590 -s "parse ServerName extension" \
591 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
592 -c "subject name *: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
593
594run_test "SNI #3 (no matching cert)" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100595 "$P_SRV debug_level=4 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100596 crt_file=data_files/server5.crt key_file=data_files/server5.key \
597 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 +0100598 "$P_CLI debug_level=0 server_addr=127.0.0.1 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +0100599 server_name='PolarSSL Server 2'" \
600 1 \
601 -s "parse ServerName extension" \
602 -s "ssl_sni_wrapper() returned" \
603 -s "ssl_handshake returned" \
604 -c "ssl_handshake returned" \
605 -c "SSL - A fatal alert message was received from our peer"
606
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +0100607# Tests for non-blocking I/O: exercise a variety of handshake flows
608
609run_test "Non-blocking I/O #1 (basic handshake)" \
610 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
611 "$P_CLI nbio=2 tickets=0" \
612 0 \
613 -S "ssl_handshake returned" \
614 -C "ssl_handshake returned" \
615 -c "Read from server: .* bytes read"
616
617run_test "Non-blocking I/O #2 (client auth)" \
618 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
619 "$P_CLI nbio=2 tickets=0" \
620 0 \
621 -S "ssl_handshake returned" \
622 -C "ssl_handshake returned" \
623 -c "Read from server: .* bytes read"
624
625run_test "Non-blocking I/O #3 (ticket)" \
626 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
627 "$P_CLI nbio=2 tickets=1" \
628 0 \
629 -S "ssl_handshake returned" \
630 -C "ssl_handshake returned" \
631 -c "Read from server: .* bytes read"
632
633run_test "Non-blocking I/O #4 (ticket + client auth)" \
634 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
635 "$P_CLI nbio=2 tickets=1" \
636 0 \
637 -S "ssl_handshake returned" \
638 -C "ssl_handshake returned" \
639 -c "Read from server: .* bytes read"
640
641run_test "Non-blocking I/O #5 (ticket + client auth + resume)" \
642 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
643 "$P_CLI nbio=2 tickets=1 reconnect=1" \
644 0 \
645 -S "ssl_handshake returned" \
646 -C "ssl_handshake returned" \
647 -c "Read from server: .* bytes read"
648
649run_test "Non-blocking I/O #6 (ticket + resume)" \
650 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
651 "$P_CLI nbio=2 tickets=1 reconnect=1" \
652 0 \
653 -S "ssl_handshake returned" \
654 -C "ssl_handshake returned" \
655 -c "Read from server: .* bytes read"
656
657run_test "Non-blocking I/O #7 (session-id resume)" \
658 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
659 "$P_CLI nbio=2 tickets=0 reconnect=1" \
660 0 \
661 -S "ssl_handshake returned" \
662 -C "ssl_handshake returned" \
663 -c "Read from server: .* bytes read"
664
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100665run_test "Version check #1 (all -> 1.2)" \
666 "$P_SRV" \
667 "$P_CLI" \
668 0 \
669 -S "ssl_handshake returned" \
670 -C "ssl_handshake returned" \
671 -s "Protocol is TLSv1.2" \
672 -c "Protocol is TLSv1.2"
673
674run_test "Version check #2 (cli max 1.1 -> 1.1)" \
675 "$P_SRV" \
676 "$P_CLI max_version=tls1_1" \
677 0 \
678 -S "ssl_handshake returned" \
679 -C "ssl_handshake returned" \
680 -s "Protocol is TLSv1.1" \
681 -c "Protocol is TLSv1.1"
682
683run_test "Version check #3 (srv max 1.1 -> 1.1)" \
684 "$P_SRV max_version=tls1_1" \
685 "$P_CLI" \
686 0 \
687 -S "ssl_handshake returned" \
688 -C "ssl_handshake returned" \
689 -s "Protocol is TLSv1.1" \
690 -c "Protocol is TLSv1.1"
691
692run_test "Version check #4 (cli+srv max 1.1 -> 1.1)" \
693 "$P_SRV max_version=tls1_1" \
694 "$P_CLI max_version=tls1_1" \
695 0 \
696 -S "ssl_handshake returned" \
697 -C "ssl_handshake returned" \
698 -s "Protocol is TLSv1.1" \
699 -c "Protocol is TLSv1.1"
700
701run_test "Version check #5 (cli max 1.1, srv min 1.1 -> 1.1)" \
702 "$P_SRV min_version=tls1_1" \
703 "$P_CLI max_version=tls1_1" \
704 0 \
705 -S "ssl_handshake returned" \
706 -C "ssl_handshake returned" \
707 -s "Protocol is TLSv1.1" \
708 -c "Protocol is TLSv1.1"
709
710run_test "Version check #6 (cli min 1.1, srv max 1.1 -> 1.1)" \
711 "$P_SRV max_version=tls1_1" \
712 "$P_CLI min_version=tls1_1" \
713 0 \
714 -S "ssl_handshake returned" \
715 -C "ssl_handshake returned" \
716 -s "Protocol is TLSv1.1" \
717 -c "Protocol is TLSv1.1"
718
719run_test "Version check #7 (cli min 1.2, srv max 1.1 -> fail)" \
720 "$P_SRV max_version=tls1_1" \
721 "$P_CLI min_version=tls1_2" \
722 1 \
723 -s "ssl_handshake returned" \
724 -c "ssl_handshake returned" \
725 -c "SSL - Handshake protocol not within min/max boundaries"
726
727run_test "Version check #8 (srv min 1.2, cli max 1.1 -> fail)" \
728 "$P_SRV min_version=tls1_2" \
729 "$P_CLI max_version=tls1_1" \
730 1 \
731 -s "ssl_handshake returned" \
732 -c "ssl_handshake returned" \
733 -s "SSL - Handshake protocol not within min/max boundaries"
734
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100735# Final report
736
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100737echo "------------------------------------------------------------------------"
738
739if [ $FAILS = 0 ]; then
740 echo -n "PASSED"
741else
742 echo -n "FAILED"
743fi
744PASSES=`echo $TESTS - $FAILS | bc`
Manuel Pégourié-Gonnard4145b892014-02-24 13:20:14 +0100745echo " ($PASSES / $TESTS tests)"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100746
747exit $FAILS