blob: 25da041d776d1be22238f7adca6aecb546ee8531 [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#
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02009# Assumes a build with default options.
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010010
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010011set -u
12
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +010013# default values, can be overriden by the environment
14: ${P_SRV:=../programs/ssl/ssl_server2}
15: ${P_CLI:=../programs/ssl/ssl_client2}
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +020016: ${P_PXY:=../programs/test/udp_proxy}
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010017: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020018: ${GNUTLS_CLI:=gnutls-cli}
19: ${GNUTLS_SERV:=gnutls-serv}
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010020
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +020021O_SRV="$OPENSSL_CMD s_server -cert data_files/server5.crt -key data_files/server5.key"
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010022O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_CMD s_client"
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020023G_SRV="$GNUTLS_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
24G_CLI="$GNUTLS_CLI"
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010025
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010026TESTS=0
27FAILS=0
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020028SKIPS=0
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010029
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +020030CONFIG_H='../include/polarssl/config.h'
31
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010032MEMCHECK=0
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010033FILTER='.*'
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020034EXCLUDE='^$'
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010035
36print_usage() {
37 echo "Usage: $0 [options]"
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010038 echo -e " -h|--help\tPrint this help."
39 echo -e " -m|--memcheck\tCheck memory leaks and errors."
40 echo -e " -f|--filter\tOnly matching tests are executed (default: '$FILTER')"
41 echo -e " -e|--exclude\tMatching tests are excluded (default: '$EXCLUDE')"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010042}
43
44get_options() {
45 while [ $# -gt 0 ]; do
46 case "$1" in
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010047 -f|--filter)
48 shift; FILTER=$1
49 ;;
50 -e|--exclude)
51 shift; EXCLUDE=$1
52 ;;
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010053 -m|--memcheck)
54 MEMCHECK=1
55 ;;
56 -h|--help)
57 print_usage
58 exit 0
59 ;;
60 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +020061 echo "Unknown argument: '$1'"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010062 print_usage
63 exit 1
64 ;;
65 esac
66 shift
67 done
68}
69
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020070# skip next test if OpenSSL can't send SSLv2 ClientHello
71requires_openssl_with_sslv2() {
72 if [ -z "${OPENSSL_HAS_SSL2:-}" ]; then
Manuel Pégourié-Gonnarda4afadf2014-08-30 22:09:36 +020073 if $OPENSSL_CMD ciphers -ssl2 >/dev/null 2>&1; then
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020074 OPENSSL_HAS_SSL2="YES"
75 else
76 OPENSSL_HAS_SSL2="NO"
77 fi
78 fi
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +020079
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020080 if [ "$OPENSSL_HAS_SSL2" = "NO" ]; then
81 SKIP_NEXT="YES"
82 fi
83}
84
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020085# skip next test if GnuTLS isn't available
86requires_gnutls() {
87 if [ -z "${GNUTLS_AVAILABLE:-}" ]; then
88 if ( which "$GNUTLS_CLI" && which "$GNUTLS_SERV" ) >/dev/null; then
89 GNUTLS_AVAILABLE="YES"
90 else
91 GNUTLS_AVAILABLE="NO"
92 fi
93 fi
94 if [ "$GNUTLS_AVAILABLE" = "NO" ]; then
95 SKIP_NEXT="YES"
96 fi
97}
98
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +020099# skip next test if IPv6 isn't available on this host
100requires_ipv6() {
101 if [ -z "${HAS_IPV6:-}" ]; then
102 $P_SRV server_addr='::1' > $SRV_OUT 2>&1 &
103 SRV_PID=$!
104 sleep 1
105 kill $SRV_PID >/dev/null 2>&1
106 if grep "NET - Binding of the socket failed" $SRV_OUT >/dev/null; then
107 HAS_IPV6="NO"
108 else
109 HAS_IPV6="YES"
110 fi
111 rm -r $SRV_OUT
112 fi
113
114 if [ "$HAS_IPV6" = "NO" ]; then
115 SKIP_NEXT="YES"
116 fi
117}
118
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200119# multiply the client timeout delay by the given factor for the next test
120needs_more_time() {
121 CLI_DELAY_FACTOR=$1
122}
123
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100124# print_name <name>
125print_name() {
126 echo -n "$1 "
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200127 LEN=$(( 72 - `echo "$1" | wc -c` ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100128 for i in `seq 1 $LEN`; do echo -n '.'; done
129 echo -n ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100130
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200131 TESTS=$(( $TESTS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100132}
133
134# fail <message>
135fail() {
136 echo "FAIL"
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +0100137 echo " ! $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100138
Manuel Pégourié-Gonnardc2b00922014-08-31 16:46:04 +0200139 mv $SRV_OUT o-srv-${TESTS}.log
140 mv $CLI_OUT o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200141 if [ -n "$PXY_CMD" ]; then
142 mv $PXY_OUT o-pxy-${TESTS}.log
143 fi
144 echo " ! outputs saved to o-XXX-${TESTS}.log"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100145
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200146 if [ "X${USER:-}" = Xbuildbot -o "X${LOGNAME:-}" = Xbuildbot ]; then
147 echo " ! server output:"
148 cat o-srv-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200149 echo " ! ========================================================"
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200150 echo " ! client output:"
151 cat o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200152 if [ -n "$PXY_CMD" ]; then
153 echo " ! ========================================================"
154 echo " ! proxy output:"
155 cat o-pxy-${TESTS}.log
156 fi
157 echo ""
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200158 fi
159
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200160 FAILS=$(( $FAILS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100161}
162
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100163# is_polar <cmd_line>
164is_polar() {
165 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
166}
167
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100168# has_mem_err <log_file_name>
169has_mem_err() {
170 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
171 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
172 then
173 return 1 # false: does not have errors
174 else
175 return 0 # true: has errors
176 fi
177}
178
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200179# wait for server to start: two versions depending on lsof availability
180wait_server_start() {
181 if which lsof >/dev/null; then
182 # make sure we don't loop forever
183 ( sleep "$DOG_DELAY"; echo "SERVERSTART TIMEOUT"; kill $MAIN_PID ) &
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200184 DOG_PID=$!
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200185
186 # make a tight loop, server usually takes less than 1 sec to start
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200187 if [ "$DTLS" -eq 1 ]; then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200188 until lsof -nbi UDP:"$SRV_PORT" | grep UDP >/dev/null; do :; done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200189 else
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200190 until lsof -nbi TCP:"$SRV_PORT" | grep LISTEN >/dev/null; do :; done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200191 fi
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200192
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200193 kill $DOG_PID >/dev/null 2>&1
194 wait $DOG_PID
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200195 else
196 sleep "$START_DELAY"
197 fi
198}
199
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200200# wait for client to terminate and set CLI_EXIT
201# must be called right after starting the client
202wait_client_done() {
203 CLI_PID=$!
204
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200205 CLI_DELAY=$(( $DOG_DELAY * $CLI_DELAY_FACTOR ))
206 CLI_DELAY_FACTOR=1
207
208 ( sleep $CLI_DELAY; echo "TIMEOUT" >> $CLI_OUT; kill $CLI_PID ) &
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200209 DOG_PID=$!
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200210
211 wait $CLI_PID
212 CLI_EXIT=$?
213
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200214 kill $DOG_PID >/dev/null 2>&1
215 wait $DOG_PID
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200216
217 echo "EXIT: $CLI_EXIT" >> $CLI_OUT
218}
219
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200220# check if the given command uses dtls and sets global variable DTLS
221detect_dtls() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200222 if echo "$1" | grep 'dtls=1\|-dtls1\|-u' >/dev/null; then
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200223 DTLS=1
224 else
225 DTLS=0
226 fi
227}
228
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200229# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100230# Options: -s pattern pattern that must be present in server output
231# -c pattern pattern that must be present in client output
232# -S pattern pattern that must be absent in server output
233# -C pattern pattern that must be absent in client output
234run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100235 NAME="$1"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200236 shift 1
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100237
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100238 if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
239 else
240 return
241 fi
242
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100243 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100244
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200245 # should we skip?
246 if [ "X$SKIP_NEXT" = "XYES" ]; then
247 SKIP_NEXT="NO"
248 echo "SKIP"
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200249 SKIPS=$(( $SKIPS + 1 ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200250 return
251 fi
252
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200253 # does this test use a proxy?
254 if [ "X$1" = "X-p" ]; then
255 PXY_CMD="$2"
256 shift 2
257 else
258 PXY_CMD=""
259 fi
260
261 # get commands and client output
262 SRV_CMD="$1"
263 CLI_CMD="$2"
264 CLI_EXPECT="$3"
265 shift 3
266
267 # fix client port
268 if [ -n "$PXY_CMD" ]; then
269 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
270 else
271 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
272 fi
273
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200274 # update DTLS variable
275 detect_dtls "$SRV_CMD"
276
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100277 # prepend valgrind to our commands if active
278 if [ "$MEMCHECK" -gt 0 ]; then
279 if is_polar "$SRV_CMD"; then
280 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
281 fi
282 if is_polar "$CLI_CMD"; then
283 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
284 fi
285 fi
286
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100287 # run the commands
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200288 if [ -n "$PXY_CMD" ]; then
289 echo "$PXY_CMD" > $PXY_OUT
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200290 $PXY_CMD >> $PXY_OUT 2>&1 &
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200291 PXY_PID=$!
292 # assume proxy starts faster than server
293 fi
294
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200295 echo "$SRV_CMD" > $SRV_OUT
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200296 # "yes" is for servers without -www (openssl with DTLS)
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +0200297 yes blabla | $SRV_CMD >> $SRV_OUT 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100298 SRV_PID=$!
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200299 wait_server_start
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200300
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200301 echo "$CLI_CMD" > $CLI_OUT
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200302 eval "$CLI_CMD" >> $CLI_OUT 2>&1 &
303 wait_client_done
Manuel Pégourié-Gonnarde01af4c2014-03-25 14:16:44 +0100304
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200305 # terminate the server (and the proxy)
Manuel Pégourié-Gonnard74b11702014-08-14 15:47:33 +0200306 kill $SRV_PID
307 wait $SRV_PID
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200308 if [ -n "$PXY_CMD" ]; then
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200309 kill $PXY_PID >/dev/null 2>&1
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200310 wait $PXY_PID
311 fi
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100312
313 # check if the client and server went at least to the handshake stage
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200314 # (useful to avoid tests with only negative assertions and non-zero
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100315 # expected client exit to incorrectly succeed in case of catastrophic
316 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100317 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200318 if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100319 else
320 fail "server failed to start"
321 return
322 fi
323 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100324 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200325 if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100326 else
327 fail "client failed to start"
328 return
329 fi
330 fi
331
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100332 # check server exit code
333 if [ $? != 0 ]; then
334 fail "server fail"
335 return
336 fi
337
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100338 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100339 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
340 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100341 then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200342 fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100343 return
344 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100345
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100346 # check other assertions
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200347 # lines beginning with == are added by valgrind, ignore them
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100348 while [ $# -gt 0 ]
349 do
350 case $1 in
351 "-s")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200352 if grep -v '^==' $SRV_OUT | grep "$2" >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100353 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100354 return
355 fi
356 ;;
357
358 "-c")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200359 if grep -v '^==' $CLI_OUT | grep "$2" >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100360 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100361 return
362 fi
363 ;;
364
365 "-S")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200366 if grep -v '^==' $SRV_OUT | grep "$2" >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100367 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100368 return
369 fi
370 ;;
371
372 "-C")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200373 if grep -v '^==' $CLI_OUT | grep "$2" >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100374 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100375 return
376 fi
377 ;;
378
379 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200380 echo "Unknown test: $1" >&2
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100381 exit 1
382 esac
383 shift 2
384 done
385
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100386 # check valgrind's results
387 if [ "$MEMCHECK" -gt 0 ]; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200388 if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100389 fail "Server has memory errors"
390 return
391 fi
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200392 if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100393 fail "Client has memory errors"
394 return
395 fi
396 fi
397
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100398 # if we're here, everything is ok
399 echo "PASS"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200400 rm -f $SRV_OUT $CLI_OUT $PXY_OUT
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100401}
402
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100403cleanup() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200404 rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200405 test -n "${SRV_PID:-}" && kill $SRV_PID >/dev/null 2>&1
406 test -n "${PXY_PID:-}" && kill $PXY_PID >/dev/null 2>&1
407 test -n "${CLI_PID:-}" && kill $CLI_PID >/dev/null 2>&1
408 test -n "${DOG_PID:-}" && kill $DOG_PID >/dev/null 2>&1
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100409 exit 1
410}
411
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100412#
413# MAIN
414#
415
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100416get_options "$@"
417
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100418# sanity checks, avoid an avalanche of errors
419if [ ! -x "$P_SRV" ]; then
420 echo "Command '$P_SRV' is not an executable file"
421 exit 1
422fi
423if [ ! -x "$P_CLI" ]; then
424 echo "Command '$P_CLI' is not an executable file"
425 exit 1
426fi
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200427if [ ! -x "$P_PXY" ]; then
428 echo "Command '$P_PXY' is not an executable file"
429 exit 1
430fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100431if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
432 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100433 exit 1
434fi
435
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200436# used by watchdog
437MAIN_PID="$$"
438
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200439# be more patient with valgrind
440if [ "$MEMCHECK" -gt 0 ]; then
441 START_DELAY=3
442 DOG_DELAY=30
443else
444 START_DELAY=1
445 DOG_DELAY=10
446fi
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200447CLI_DELAY_FACTOR=1
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200448
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200449# Pick a "unique" server port in the range 10000-19999, and a proxy port
450PORT_BASE="0000$$"
451PORT_BASE="$( echo -n $PORT_BASE | tail -c 4 )"
452SRV_PORT="1$PORT_BASE"
453PXY_PORT="2$PORT_BASE"
454unset PORT_BASE
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200455
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200456# fix commands to use this port, force IPv4 while at it
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200457P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
458P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
459P_PXY="$P_PXY server_addr=127.0.0.1 server_port=$SRV_PORT listen_addr=127.0.0.1 listen_port=$PXY_PORT"
460O_SRV="$O_SRV -accept $SRV_PORT"
461O_CLI="$O_CLI -connect localhost:+SRV_PORT"
462G_SRV="$G_SRV -p $SRV_PORT"
463G_CLI="$G_CLI -p +SRV_PORT"
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200464
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200465# Also pick a unique name for intermediate files
466SRV_OUT="srv_out.$$"
467CLI_OUT="cli_out.$$"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200468PXY_OUT="pxy_out.$$"
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200469SESSION="session.$$"
470
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200471SKIP_NEXT="NO"
472
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100473trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100474
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200475# Basic test
476
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200477# Checks that:
478# - things work with all ciphersuites active (used with config-full in all.sh)
479# - the expected (highest security) parameters are selected
480# ("signature_algorithm ext: 6" means SHA-512 (highest common hash))
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200481run_test "Default" \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200482 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200483 "$P_CLI" \
484 0 \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200485 -s "Protocol is TLSv1.2" \
486 -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
487 -s "client hello v3, signature_algorithm ext: 6" \
488 -s "ECDHE curve: secp521r1" \
489 -S "error" \
490 -C "error"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200491
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100492# Test for SSLv2 ClientHello
493
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200494requires_openssl_with_sslv2
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200495run_test "SSLv2 ClientHello: reference" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100496 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100497 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100498 0 \
499 -S "parse client hello v2" \
500 -S "ssl_handshake returned"
501
502# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200503requires_openssl_with_sslv2
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200504run_test "SSLv2 ClientHello: actual test" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200505 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100506 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100507 0 \
508 -s "parse client hello v2" \
509 -S "ssl_handshake returned"
510
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100511# Tests for Truncated HMAC extension
512
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200513run_test "Truncated HMAC: reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200514 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100515 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100516 0 \
517 -s "dumping 'computed mac' (20 bytes)"
518
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200519run_test "Truncated HMAC: actual test" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200520 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100521 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100522 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100523 -s "dumping 'computed mac' (10 bytes)"
524
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100525# Tests for Session Tickets
526
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200527run_test "Session resume using tickets: basic" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200528 "$P_SRV debug_level=3 tickets=1" \
529 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100530 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100531 -c "client hello, adding session ticket extension" \
532 -s "found session ticket extension" \
533 -s "server hello, adding session ticket extension" \
534 -c "found session_ticket extension" \
535 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100536 -S "session successfully restored from cache" \
537 -s "session successfully restored from ticket" \
538 -s "a session has been resumed" \
539 -c "a session has been resumed"
540
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200541run_test "Session resume using tickets: cache disabled" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200542 "$P_SRV debug_level=3 tickets=1 cache_max=0" \
543 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100544 0 \
545 -c "client hello, adding session ticket extension" \
546 -s "found session ticket extension" \
547 -s "server hello, adding session ticket extension" \
548 -c "found session_ticket extension" \
549 -c "parse new session ticket" \
550 -S "session successfully restored from cache" \
551 -s "session successfully restored from ticket" \
552 -s "a session has been resumed" \
553 -c "a session has been resumed"
554
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200555run_test "Session resume using tickets: timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200556 "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
557 "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100558 0 \
559 -c "client hello, adding session ticket extension" \
560 -s "found session ticket extension" \
561 -s "server hello, adding session ticket extension" \
562 -c "found session_ticket extension" \
563 -c "parse new session ticket" \
564 -S "session successfully restored from cache" \
565 -S "session successfully restored from ticket" \
566 -S "a session has been resumed" \
567 -C "a session has been resumed"
568
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200569run_test "Session resume using tickets: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100570 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200571 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100572 0 \
573 -c "client hello, adding session ticket extension" \
574 -c "found session_ticket extension" \
575 -c "parse new session ticket" \
576 -c "a session has been resumed"
577
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200578run_test "Session resume using tickets: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200579 "$P_SRV debug_level=3 tickets=1" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200580 "( $O_CLI -sess_out $SESSION; \
581 $O_CLI -sess_in $SESSION; \
582 rm -f $SESSION )" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100583 0 \
584 -s "found session ticket extension" \
585 -s "server hello, adding session ticket extension" \
586 -S "session successfully restored from cache" \
587 -s "session successfully restored from ticket" \
588 -s "a session has been resumed"
589
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100590# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100591
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200592run_test "Session resume using cache: tickets enabled on client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200593 "$P_SRV debug_level=3 tickets=0" \
594 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100595 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100596 -c "client hello, adding session ticket extension" \
597 -s "found session ticket extension" \
598 -S "server hello, adding session ticket extension" \
599 -C "found session_ticket extension" \
600 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100601 -s "session successfully restored from cache" \
602 -S "session successfully restored from ticket" \
603 -s "a session has been resumed" \
604 -c "a session has been resumed"
605
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200606run_test "Session resume using cache: tickets enabled on server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200607 "$P_SRV debug_level=3 tickets=1" \
608 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100609 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100610 -C "client hello, adding session ticket extension" \
611 -S "found session ticket extension" \
612 -S "server hello, adding session ticket extension" \
613 -C "found session_ticket extension" \
614 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100615 -s "session successfully restored from cache" \
616 -S "session successfully restored from ticket" \
617 -s "a session has been resumed" \
618 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100619
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200620run_test "Session resume using cache: cache_max=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200621 "$P_SRV debug_level=3 tickets=0 cache_max=0" \
622 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100623 0 \
624 -S "session successfully restored from cache" \
625 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100626 -S "a session has been resumed" \
627 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100628
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200629run_test "Session resume using cache: cache_max=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200630 "$P_SRV debug_level=3 tickets=0 cache_max=1" \
631 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100632 0 \
633 -s "session successfully restored from cache" \
634 -S "session successfully restored from ticket" \
635 -s "a session has been resumed" \
636 -c "a session has been resumed"
637
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200638run_test "Session resume using cache: timemout > delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200639 "$P_SRV debug_level=3 tickets=0" \
640 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100641 0 \
642 -s "session successfully restored from cache" \
643 -S "session successfully restored from ticket" \
644 -s "a session has been resumed" \
645 -c "a session has been resumed"
646
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200647run_test "Session resume using cache: timeout < delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200648 "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
649 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100650 0 \
651 -S "session successfully restored from cache" \
652 -S "session successfully restored from ticket" \
653 -S "a session has been resumed" \
654 -C "a session has been resumed"
655
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200656run_test "Session resume using cache: no timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200657 "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
658 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100659 0 \
660 -s "session successfully restored from cache" \
661 -S "session successfully restored from ticket" \
662 -s "a session has been resumed" \
663 -c "a session has been resumed"
664
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200665run_test "Session resume using cache: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200666 "$P_SRV debug_level=3 tickets=0" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200667 "( $O_CLI -sess_out $SESSION; \
668 $O_CLI -sess_in $SESSION; \
669 rm -f $SESSION )" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100670 0 \
671 -s "found session ticket extension" \
672 -S "server hello, adding session ticket extension" \
673 -s "session successfully restored from cache" \
674 -S "session successfully restored from ticket" \
675 -s "a session has been resumed"
676
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200677run_test "Session resume using cache: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100678 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200679 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100680 0 \
681 -C "found session_ticket extension" \
682 -C "parse new session ticket" \
683 -c "a session has been resumed"
684
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100685# Tests for Max Fragment Length extension
686
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200687run_test "Max fragment length: not used, reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200688 "$P_SRV debug_level=3" \
689 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100690 0 \
691 -C "client hello, adding max_fragment_length extension" \
692 -S "found max fragment length extension" \
693 -S "server hello, max_fragment_length extension" \
694 -C "found max_fragment_length extension"
695
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200696run_test "Max fragment length: used by client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200697 "$P_SRV debug_level=3" \
698 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100699 0 \
700 -c "client hello, adding max_fragment_length extension" \
701 -s "found max fragment length extension" \
702 -s "server hello, max_fragment_length extension" \
703 -c "found max_fragment_length extension"
704
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200705run_test "Max fragment length: used by server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200706 "$P_SRV debug_level=3 max_frag_len=4096" \
707 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100708 0 \
709 -C "client hello, adding max_fragment_length extension" \
710 -S "found max fragment length extension" \
711 -S "server hello, max_fragment_length extension" \
712 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100713
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200714requires_gnutls
715run_test "Max fragment length: gnutls server" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200716 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200717 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200718 0 \
719 -c "client hello, adding max_fragment_length extension" \
720 -c "found max_fragment_length extension"
721
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100722# Tests for renegotiation
723
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200724run_test "Renegotiation: none, for reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200725 "$P_SRV debug_level=3 exchanges=2" \
726 "$P_CLI debug_level=3 exchanges=2" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100727 0 \
728 -C "client hello, adding renegotiation extension" \
729 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
730 -S "found renegotiation extension" \
731 -s "server hello, secure renegotiation extension" \
732 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100733 -C "=> renegotiate" \
734 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100735 -S "write hello request"
736
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200737run_test "Renegotiation: client-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200738 "$P_SRV debug_level=3 exchanges=2 renegotiation=1" \
739 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100740 0 \
741 -c "client hello, adding renegotiation extension" \
742 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
743 -s "found renegotiation extension" \
744 -s "server hello, secure renegotiation extension" \
745 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100746 -c "=> renegotiate" \
747 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100748 -S "write hello request"
749
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200750run_test "Renegotiation: server-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200751 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
752 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100753 0 \
754 -c "client hello, adding renegotiation extension" \
755 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
756 -s "found renegotiation extension" \
757 -s "server hello, secure renegotiation extension" \
758 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100759 -c "=> renegotiate" \
760 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100761 -s "write hello request"
762
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200763run_test "Renegotiation: double" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200764 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
765 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100766 0 \
767 -c "client hello, adding renegotiation extension" \
768 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
769 -s "found renegotiation extension" \
770 -s "server hello, secure renegotiation extension" \
771 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100772 -c "=> renegotiate" \
773 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100774 -s "write hello request"
775
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200776run_test "Renegotiation: client-initiated, server-rejected" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200777 "$P_SRV debug_level=3 exchanges=2 renegotiation=0" \
778 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100779 1 \
780 -c "client hello, adding renegotiation extension" \
781 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
782 -S "found renegotiation extension" \
783 -s "server hello, secure renegotiation extension" \
784 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100785 -c "=> renegotiate" \
786 -S "=> renegotiate" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200787 -S "write hello request" \
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +0200788 -c "SSL - Unexpected message at ServerHello in renegotiation" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200789 -c "failed"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100790
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200791run_test "Renegotiation: server-initiated, client-rejected, default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200792 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
793 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100794 0 \
795 -C "client hello, adding renegotiation extension" \
796 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
797 -S "found renegotiation extension" \
798 -s "server hello, secure renegotiation extension" \
799 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100800 -C "=> renegotiate" \
801 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100802 -s "write hello request" \
Manuel Pégourié-Gonnarda9964db2014-07-03 19:29:16 +0200803 -S "SSL - An unexpected message was received from our peer" \
804 -S "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100805
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200806run_test "Renegotiation: server-initiated, client-rejected, not enforced" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200807 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200808 renego_delay=-1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200809 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200810 0 \
811 -C "client hello, adding renegotiation extension" \
812 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
813 -S "found renegotiation extension" \
814 -s "server hello, secure renegotiation extension" \
815 -c "found renegotiation extension" \
816 -C "=> renegotiate" \
817 -S "=> renegotiate" \
818 -s "write hello request" \
819 -S "SSL - An unexpected message was received from our peer" \
820 -S "failed"
821
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200822# delay 2 for 1 alert record + 1 application data record
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200823run_test "Renegotiation: server-initiated, client-rejected, delay 2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200824 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200825 renego_delay=2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200826 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200827 0 \
828 -C "client hello, adding renegotiation extension" \
829 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
830 -S "found renegotiation extension" \
831 -s "server hello, secure renegotiation extension" \
832 -c "found renegotiation extension" \
833 -C "=> renegotiate" \
834 -S "=> renegotiate" \
835 -s "write hello request" \
836 -S "SSL - An unexpected message was received from our peer" \
837 -S "failed"
838
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200839run_test "Renegotiation: server-initiated, client-rejected, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200840 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200841 renego_delay=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200842 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200843 0 \
844 -C "client hello, adding renegotiation extension" \
845 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
846 -S "found renegotiation extension" \
847 -s "server hello, secure renegotiation extension" \
848 -c "found renegotiation extension" \
849 -C "=> renegotiate" \
850 -S "=> renegotiate" \
851 -s "write hello request" \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200852 -s "SSL - An unexpected message was received from our peer"
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200853
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200854run_test "Renegotiation: server-initiated, client-accepted, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200855 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200856 renego_delay=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200857 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200858 0 \
859 -c "client hello, adding renegotiation extension" \
860 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
861 -s "found renegotiation extension" \
862 -s "server hello, secure renegotiation extension" \
863 -c "found renegotiation extension" \
864 -c "=> renegotiate" \
865 -s "=> renegotiate" \
866 -s "write hello request" \
867 -S "SSL - An unexpected message was received from our peer" \
868 -S "failed"
869
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200870run_test "Renegotiation: nbio, client-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200871 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
872 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +0200873 0 \
874 -c "client hello, adding renegotiation extension" \
875 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
876 -s "found renegotiation extension" \
877 -s "server hello, secure renegotiation extension" \
878 -c "found renegotiation extension" \
879 -c "=> renegotiate" \
880 -s "=> renegotiate" \
881 -S "write hello request"
882
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200883run_test "Renegotiation: nbio, server-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200884 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
885 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +0200886 0 \
887 -c "client hello, adding renegotiation extension" \
888 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
889 -s "found renegotiation extension" \
890 -s "server hello, secure renegotiation extension" \
891 -c "found renegotiation extension" \
892 -c "=> renegotiate" \
893 -s "=> renegotiate" \
894 -s "write hello request"
895
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200896run_test "Renegotiation: openssl server, client-initiated" \
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +0200897 "$O_SRV -www" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200898 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200899 0 \
900 -c "client hello, adding renegotiation extension" \
901 -c "found renegotiation extension" \
902 -c "=> renegotiate" \
903 -C "ssl_handshake returned" \
904 -C "error" \
905 -c "HTTP/1.0 200 [Oo][Kk]"
906
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200907run_test "Renegotiation: gnutls server, client-initiated" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200908 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200909 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200910 0 \
911 -c "client hello, adding renegotiation extension" \
912 -c "found renegotiation extension" \
913 -c "=> renegotiate" \
914 -C "ssl_handshake returned" \
915 -C "error" \
916 -c "HTTP/1.0 200 [Oo][Kk]"
917
Manuel Pégourié-Gonnard30d16eb2014-08-19 17:43:50 +0200918run_test "Renegotiation: DTLS, client-initiated" \
919 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
920 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
921 0 \
922 -c "client hello, adding renegotiation extension" \
923 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
924 -s "found renegotiation extension" \
925 -s "server hello, secure renegotiation extension" \
926 -c "found renegotiation extension" \
927 -c "=> renegotiate" \
928 -s "=> renegotiate" \
929 -S "write hello request"
930
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +0200931run_test "Renegotiation: DTLS, server-initiated" \
932 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
933 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
934 0 \
935 -c "client hello, adding renegotiation extension" \
936 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
937 -s "found renegotiation extension" \
938 -s "server hello, secure renegotiation extension" \
939 -c "found renegotiation extension" \
940 -c "=> renegotiate" \
941 -s "=> renegotiate" \
942 -s "write hello request"
943
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +0200944run_test "Renegotiation: DTLS, gnutls server, client-initiated" \
945 "$G_SRV -u --mtu 4096" \
946 "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
947 0 \
948 -c "client hello, adding renegotiation extension" \
949 -c "found renegotiation extension" \
950 -c "=> renegotiate" \
951 -C "ssl_handshake returned" \
952 -C "error" \
953 -s "Extra-header:"
954
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100955# Tests for auth_mode
956
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200957run_test "Authentication: server badcert, client required" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100958 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100959 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200960 "$P_CLI debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100961 1 \
962 -c "x509_verify_cert() returned" \
963 -c "! self-signed or not signed by a trusted CA" \
964 -c "! ssl_handshake returned" \
965 -c "X509 - Certificate verification failed"
966
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200967run_test "Authentication: server badcert, client optional" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100968 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100969 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200970 "$P_CLI debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100971 0 \
972 -c "x509_verify_cert() returned" \
973 -c "! self-signed or not signed by a trusted CA" \
974 -C "! ssl_handshake returned" \
975 -C "X509 - Certificate verification failed"
976
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200977run_test "Authentication: server badcert, client none" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100978 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100979 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200980 "$P_CLI debug_level=1 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100981 0 \
982 -C "x509_verify_cert() returned" \
983 -C "! self-signed or not signed by a trusted CA" \
984 -C "! ssl_handshake returned" \
985 -C "X509 - Certificate verification failed"
986
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200987run_test "Authentication: client badcert, server required" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200988 "$P_SRV debug_level=3 auth_mode=required" \
989 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100990 key_file=data_files/server5.key" \
991 1 \
992 -S "skip write certificate request" \
993 -C "skip parse certificate request" \
994 -c "got a certificate request" \
995 -C "skip write certificate" \
996 -C "skip write certificate verify" \
997 -S "skip parse certificate verify" \
998 -s "x509_verify_cert() returned" \
999 -S "! self-signed or not signed by a trusted CA" \
1000 -s "! ssl_handshake returned" \
1001 -c "! ssl_handshake returned" \
1002 -s "X509 - Certificate verification failed"
1003
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001004run_test "Authentication: client badcert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001005 "$P_SRV debug_level=3 auth_mode=optional" \
1006 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001007 key_file=data_files/server5.key" \
1008 0 \
1009 -S "skip write certificate request" \
1010 -C "skip parse certificate request" \
1011 -c "got a certificate request" \
1012 -C "skip write certificate" \
1013 -C "skip write certificate verify" \
1014 -S "skip parse certificate verify" \
1015 -s "x509_verify_cert() returned" \
1016 -s "! self-signed or not signed by a trusted CA" \
1017 -S "! ssl_handshake returned" \
1018 -C "! ssl_handshake returned" \
1019 -S "X509 - Certificate verification failed"
1020
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001021run_test "Authentication: client badcert, server none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001022 "$P_SRV debug_level=3 auth_mode=none" \
1023 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001024 key_file=data_files/server5.key" \
1025 0 \
1026 -s "skip write certificate request" \
1027 -C "skip parse certificate request" \
1028 -c "got no certificate request" \
1029 -c "skip write certificate" \
1030 -c "skip write certificate verify" \
1031 -s "skip parse certificate verify" \
1032 -S "x509_verify_cert() returned" \
1033 -S "! self-signed or not signed by a trusted CA" \
1034 -S "! ssl_handshake returned" \
1035 -C "! ssl_handshake returned" \
1036 -S "X509 - Certificate verification failed"
1037
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001038run_test "Authentication: client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001039 "$P_SRV debug_level=3 auth_mode=optional" \
1040 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001041 0 \
1042 -S "skip write certificate request" \
1043 -C "skip parse certificate request" \
1044 -c "got a certificate request" \
1045 -C "skip write certificate$" \
1046 -C "got no certificate to send" \
1047 -S "SSLv3 client has no certificate" \
1048 -c "skip write certificate verify" \
1049 -s "skip parse certificate verify" \
1050 -s "! no client certificate sent" \
1051 -S "! ssl_handshake returned" \
1052 -C "! ssl_handshake returned" \
1053 -S "X509 - Certificate verification failed"
1054
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001055run_test "Authentication: openssl client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001056 "$P_SRV debug_level=3 auth_mode=optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001057 "$O_CLI" \
1058 0 \
1059 -S "skip write certificate request" \
1060 -s "skip parse certificate verify" \
1061 -s "! no client certificate sent" \
1062 -S "! ssl_handshake returned" \
1063 -S "X509 - Certificate verification failed"
1064
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001065run_test "Authentication: client no cert, openssl server optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001066 "$O_SRV -verify 10" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001067 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001068 0 \
1069 -C "skip parse certificate request" \
1070 -c "got a certificate request" \
1071 -C "skip write certificate$" \
1072 -c "skip write certificate verify" \
1073 -C "! ssl_handshake returned"
1074
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001075run_test "Authentication: client no cert, ssl3" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001076 "$P_SRV debug_level=3 auth_mode=optional force_version=ssl3" \
1077 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001078 0 \
1079 -S "skip write certificate request" \
1080 -C "skip parse certificate request" \
1081 -c "got a certificate request" \
1082 -C "skip write certificate$" \
1083 -c "skip write certificate verify" \
1084 -c "got no certificate to send" \
1085 -s "SSLv3 client has no certificate" \
1086 -s "skip parse certificate verify" \
1087 -s "! no client certificate sent" \
1088 -S "! ssl_handshake returned" \
1089 -C "! ssl_handshake returned" \
1090 -S "X509 - Certificate verification failed"
1091
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001092# tests for SNI
1093
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001094run_test "SNI: no SNI callback" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001095 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001096 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001097 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001098 0 \
1099 -S "parse ServerName extension" \
1100 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
1101 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
1102
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001103run_test "SNI: matching cert 1" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001104 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001105 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001106 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001107 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001108 0 \
1109 -s "parse ServerName extension" \
1110 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
1111 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
1112
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001113run_test "SNI: matching cert 2" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001114 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001115 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001116 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001117 "$P_CLI server_name=polarssl.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001118 0 \
1119 -s "parse ServerName extension" \
1120 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001121 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001122
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001123run_test "SNI: no matching cert" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001124 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001125 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001126 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001127 "$P_CLI server_name=nonesuch.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001128 1 \
1129 -s "parse ServerName extension" \
1130 -s "ssl_sni_wrapper() returned" \
1131 -s "ssl_handshake returned" \
1132 -c "ssl_handshake returned" \
1133 -c "SSL - A fatal alert message was received from our peer"
1134
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001135# Tests for non-blocking I/O: exercise a variety of handshake flows
1136
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001137run_test "Non-blocking I/O: basic handshake" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001138 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
1139 "$P_CLI nbio=2 tickets=0" \
1140 0 \
1141 -S "ssl_handshake returned" \
1142 -C "ssl_handshake returned" \
1143 -c "Read from server: .* bytes read"
1144
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001145run_test "Non-blocking I/O: client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001146 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
1147 "$P_CLI nbio=2 tickets=0" \
1148 0 \
1149 -S "ssl_handshake returned" \
1150 -C "ssl_handshake returned" \
1151 -c "Read from server: .* bytes read"
1152
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001153run_test "Non-blocking I/O: ticket" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001154 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
1155 "$P_CLI nbio=2 tickets=1" \
1156 0 \
1157 -S "ssl_handshake returned" \
1158 -C "ssl_handshake returned" \
1159 -c "Read from server: .* bytes read"
1160
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001161run_test "Non-blocking I/O: ticket + client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001162 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
1163 "$P_CLI nbio=2 tickets=1" \
1164 0 \
1165 -S "ssl_handshake returned" \
1166 -C "ssl_handshake returned" \
1167 -c "Read from server: .* bytes read"
1168
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001169run_test "Non-blocking I/O: ticket + client auth + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001170 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
1171 "$P_CLI nbio=2 tickets=1 reconnect=1" \
1172 0 \
1173 -S "ssl_handshake returned" \
1174 -C "ssl_handshake returned" \
1175 -c "Read from server: .* bytes read"
1176
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001177run_test "Non-blocking I/O: ticket + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001178 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
1179 "$P_CLI nbio=2 tickets=1 reconnect=1" \
1180 0 \
1181 -S "ssl_handshake returned" \
1182 -C "ssl_handshake returned" \
1183 -c "Read from server: .* bytes read"
1184
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001185run_test "Non-blocking I/O: session-id resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001186 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
1187 "$P_CLI nbio=2 tickets=0 reconnect=1" \
1188 0 \
1189 -S "ssl_handshake returned" \
1190 -C "ssl_handshake returned" \
1191 -c "Read from server: .* bytes read"
1192
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001193# Tests for version negotiation
1194
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001195run_test "Version check: all -> 1.2" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001196 "$P_SRV" \
1197 "$P_CLI" \
1198 0 \
1199 -S "ssl_handshake returned" \
1200 -C "ssl_handshake returned" \
1201 -s "Protocol is TLSv1.2" \
1202 -c "Protocol is TLSv1.2"
1203
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001204run_test "Version check: cli max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001205 "$P_SRV" \
1206 "$P_CLI max_version=tls1_1" \
1207 0 \
1208 -S "ssl_handshake returned" \
1209 -C "ssl_handshake returned" \
1210 -s "Protocol is TLSv1.1" \
1211 -c "Protocol is TLSv1.1"
1212
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001213run_test "Version check: srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001214 "$P_SRV max_version=tls1_1" \
1215 "$P_CLI" \
1216 0 \
1217 -S "ssl_handshake returned" \
1218 -C "ssl_handshake returned" \
1219 -s "Protocol is TLSv1.1" \
1220 -c "Protocol is TLSv1.1"
1221
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001222run_test "Version check: cli+srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001223 "$P_SRV max_version=tls1_1" \
1224 "$P_CLI max_version=tls1_1" \
1225 0 \
1226 -S "ssl_handshake returned" \
1227 -C "ssl_handshake returned" \
1228 -s "Protocol is TLSv1.1" \
1229 -c "Protocol is TLSv1.1"
1230
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001231run_test "Version check: cli max 1.1, srv min 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001232 "$P_SRV min_version=tls1_1" \
1233 "$P_CLI max_version=tls1_1" \
1234 0 \
1235 -S "ssl_handshake returned" \
1236 -C "ssl_handshake returned" \
1237 -s "Protocol is TLSv1.1" \
1238 -c "Protocol is TLSv1.1"
1239
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001240run_test "Version check: cli min 1.1, srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001241 "$P_SRV max_version=tls1_1" \
1242 "$P_CLI min_version=tls1_1" \
1243 0 \
1244 -S "ssl_handshake returned" \
1245 -C "ssl_handshake returned" \
1246 -s "Protocol is TLSv1.1" \
1247 -c "Protocol is TLSv1.1"
1248
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001249run_test "Version check: cli min 1.2, srv max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001250 "$P_SRV max_version=tls1_1" \
1251 "$P_CLI min_version=tls1_2" \
1252 1 \
1253 -s "ssl_handshake returned" \
1254 -c "ssl_handshake returned" \
1255 -c "SSL - Handshake protocol not within min/max boundaries"
1256
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001257run_test "Version check: srv min 1.2, cli max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001258 "$P_SRV min_version=tls1_2" \
1259 "$P_CLI max_version=tls1_1" \
1260 1 \
1261 -s "ssl_handshake returned" \
1262 -c "ssl_handshake returned" \
1263 -s "SSL - Handshake protocol not within min/max boundaries"
1264
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001265# Tests for ALPN extension
1266
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02001267if grep '^#define POLARSSL_SSL_ALPN' $CONFIG_H >/dev/null; then
1268
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001269run_test "ALPN: none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001270 "$P_SRV debug_level=3" \
1271 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001272 0 \
1273 -C "client hello, adding alpn extension" \
1274 -S "found alpn extension" \
1275 -C "got an alert message, type: \\[2:120]" \
1276 -S "server hello, adding alpn extension" \
1277 -C "found alpn extension " \
1278 -C "Application Layer Protocol is" \
1279 -S "Application Layer Protocol is"
1280
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001281run_test "ALPN: client only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001282 "$P_SRV debug_level=3" \
1283 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001284 0 \
1285 -c "client hello, adding alpn extension" \
1286 -s "found alpn extension" \
1287 -C "got an alert message, type: \\[2:120]" \
1288 -S "server hello, adding alpn extension" \
1289 -C "found alpn extension " \
1290 -c "Application Layer Protocol is (none)" \
1291 -S "Application Layer Protocol is"
1292
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001293run_test "ALPN: server only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001294 "$P_SRV debug_level=3 alpn=abc,1234" \
1295 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001296 0 \
1297 -C "client hello, adding alpn extension" \
1298 -S "found alpn extension" \
1299 -C "got an alert message, type: \\[2:120]" \
1300 -S "server hello, adding alpn extension" \
1301 -C "found alpn extension " \
1302 -C "Application Layer Protocol is" \
1303 -s "Application Layer Protocol is (none)"
1304
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001305run_test "ALPN: both, common cli1-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001306 "$P_SRV debug_level=3 alpn=abc,1234" \
1307 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001308 0 \
1309 -c "client hello, adding alpn extension" \
1310 -s "found alpn extension" \
1311 -C "got an alert message, type: \\[2:120]" \
1312 -s "server hello, adding alpn extension" \
1313 -c "found alpn extension" \
1314 -c "Application Layer Protocol is abc" \
1315 -s "Application Layer Protocol is abc"
1316
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001317run_test "ALPN: both, common cli2-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001318 "$P_SRV debug_level=3 alpn=abc,1234" \
1319 "$P_CLI debug_level=3 alpn=1234,abc" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001320 0 \
1321 -c "client hello, adding alpn extension" \
1322 -s "found alpn extension" \
1323 -C "got an alert message, type: \\[2:120]" \
1324 -s "server hello, adding alpn extension" \
1325 -c "found alpn extension" \
1326 -c "Application Layer Protocol is abc" \
1327 -s "Application Layer Protocol is abc"
1328
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001329run_test "ALPN: both, common cli1-srv2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001330 "$P_SRV debug_level=3 alpn=abc,1234" \
1331 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001332 0 \
1333 -c "client hello, adding alpn extension" \
1334 -s "found alpn extension" \
1335 -C "got an alert message, type: \\[2:120]" \
1336 -s "server hello, adding alpn extension" \
1337 -c "found alpn extension" \
1338 -c "Application Layer Protocol is 1234" \
1339 -s "Application Layer Protocol is 1234"
1340
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001341run_test "ALPN: both, no common" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001342 "$P_SRV debug_level=3 alpn=abc,123" \
1343 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001344 1 \
1345 -c "client hello, adding alpn extension" \
1346 -s "found alpn extension" \
1347 -c "got an alert message, type: \\[2:120]" \
1348 -S "server hello, adding alpn extension" \
1349 -C "found alpn extension" \
1350 -C "Application Layer Protocol is 1234" \
1351 -S "Application Layer Protocol is 1234"
1352
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02001353fi
1354
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001355# Tests for keyUsage in leaf certificates, part 1:
1356# server-side certificate/suite selection
1357
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001358run_test "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001359 "$P_SRV key_file=data_files/server2.key \
1360 crt_file=data_files/server2.ku-ds.crt" \
1361 "$P_CLI" \
1362 0 \
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02001363 -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001364
1365
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001366run_test "keyUsage srv: RSA, keyEncipherment -> RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001367 "$P_SRV key_file=data_files/server2.key \
1368 crt_file=data_files/server2.ku-ke.crt" \
1369 "$P_CLI" \
1370 0 \
1371 -c "Ciphersuite is TLS-RSA-WITH-"
1372
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001373run_test "keyUsage srv: RSA, keyAgreement -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001374 "$P_SRV key_file=data_files/server2.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001375 crt_file=data_files/server2.ku-ka.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001376 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001377 1 \
1378 -C "Ciphersuite is "
1379
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001380run_test "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001381 "$P_SRV key_file=data_files/server5.key \
1382 crt_file=data_files/server5.ku-ds.crt" \
1383 "$P_CLI" \
1384 0 \
1385 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
1386
1387
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001388run_test "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001389 "$P_SRV key_file=data_files/server5.key \
1390 crt_file=data_files/server5.ku-ka.crt" \
1391 "$P_CLI" \
1392 0 \
1393 -c "Ciphersuite is TLS-ECDH-"
1394
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001395run_test "keyUsage srv: ECDSA, keyEncipherment -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001396 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001397 crt_file=data_files/server5.ku-ke.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001398 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001399 1 \
1400 -C "Ciphersuite is "
1401
1402# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001403# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001404
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001405run_test "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001406 "$O_SRV -key data_files/server2.key \
1407 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001408 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001409 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1410 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001411 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001412 -C "Processing of the Certificate handshake message failed" \
1413 -c "Ciphersuite is TLS-"
1414
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001415run_test "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001416 "$O_SRV -key data_files/server2.key \
1417 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001418 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001419 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1420 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001421 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001422 -C "Processing of the Certificate handshake message failed" \
1423 -c "Ciphersuite is TLS-"
1424
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001425run_test "keyUsage cli: KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001426 "$O_SRV -key data_files/server2.key \
1427 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001428 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001429 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1430 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001431 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001432 -C "Processing of the Certificate handshake message failed" \
1433 -c "Ciphersuite is TLS-"
1434
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001435run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001436 "$O_SRV -key data_files/server2.key \
1437 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001438 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001439 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1440 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001441 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001442 -c "Processing of the Certificate handshake message failed" \
1443 -C "Ciphersuite is TLS-"
1444
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001445run_test "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001446 "$O_SRV -key data_files/server2.key \
1447 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001448 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001449 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1450 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001451 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001452 -C "Processing of the Certificate handshake message failed" \
1453 -c "Ciphersuite is TLS-"
1454
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001455run_test "keyUsage cli: DigitalSignature, RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001456 "$O_SRV -key data_files/server2.key \
1457 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001458 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001459 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1460 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001461 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001462 -c "Processing of the Certificate handshake message failed" \
1463 -C "Ciphersuite is TLS-"
1464
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001465# Tests for keyUsage in leaf certificates, part 3:
1466# server-side checking of client cert
1467
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001468run_test "keyUsage cli-auth: RSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001469 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001470 "$O_CLI -key data_files/server2.key \
1471 -cert data_files/server2.ku-ds.crt" \
1472 0 \
1473 -S "bad certificate (usage extensions)" \
1474 -S "Processing of the Certificate handshake message failed"
1475
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001476run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001477 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001478 "$O_CLI -key data_files/server2.key \
1479 -cert data_files/server2.ku-ke.crt" \
1480 0 \
1481 -s "bad certificate (usage extensions)" \
1482 -S "Processing of the Certificate handshake message failed"
1483
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001484run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001485 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001486 "$O_CLI -key data_files/server2.key \
1487 -cert data_files/server2.ku-ke.crt" \
1488 1 \
1489 -s "bad certificate (usage extensions)" \
1490 -s "Processing of the Certificate handshake message failed"
1491
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001492run_test "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001493 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001494 "$O_CLI -key data_files/server5.key \
1495 -cert data_files/server5.ku-ds.crt" \
1496 0 \
1497 -S "bad certificate (usage extensions)" \
1498 -S "Processing of the Certificate handshake message failed"
1499
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001500run_test "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001501 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001502 "$O_CLI -key data_files/server5.key \
1503 -cert data_files/server5.ku-ka.crt" \
1504 0 \
1505 -s "bad certificate (usage extensions)" \
1506 -S "Processing of the Certificate handshake message failed"
1507
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001508# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
1509
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001510run_test "extKeyUsage srv: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001511 "$P_SRV key_file=data_files/server5.key \
1512 crt_file=data_files/server5.eku-srv.crt" \
1513 "$P_CLI" \
1514 0
1515
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001516run_test "extKeyUsage srv: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001517 "$P_SRV key_file=data_files/server5.key \
1518 crt_file=data_files/server5.eku-srv.crt" \
1519 "$P_CLI" \
1520 0
1521
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001522run_test "extKeyUsage srv: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001523 "$P_SRV key_file=data_files/server5.key \
1524 crt_file=data_files/server5.eku-cs_any.crt" \
1525 "$P_CLI" \
1526 0
1527
1528# add psk to leave an option for client to send SERVERQUIT
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001529run_test "extKeyUsage srv: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001530 "$P_SRV psk=abc123 key_file=data_files/server5.key \
1531 crt_file=data_files/server5.eku-cli.crt" \
1532 "$P_CLI psk=badbad" \
1533 1
1534
1535# Tests for extendedKeyUsage, part 2: client-side checking of server cert
1536
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001537run_test "extKeyUsage cli: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001538 "$O_SRV -key data_files/server5.key \
1539 -cert data_files/server5.eku-srv.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001540 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001541 0 \
1542 -C "bad certificate (usage extensions)" \
1543 -C "Processing of the Certificate handshake message failed" \
1544 -c "Ciphersuite is TLS-"
1545
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001546run_test "extKeyUsage cli: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001547 "$O_SRV -key data_files/server5.key \
1548 -cert data_files/server5.eku-srv_cli.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001549 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001550 0 \
1551 -C "bad certificate (usage extensions)" \
1552 -C "Processing of the Certificate handshake message failed" \
1553 -c "Ciphersuite is TLS-"
1554
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001555run_test "extKeyUsage cli: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001556 "$O_SRV -key data_files/server5.key \
1557 -cert data_files/server5.eku-cs_any.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001558 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001559 0 \
1560 -C "bad certificate (usage extensions)" \
1561 -C "Processing of the Certificate handshake message failed" \
1562 -c "Ciphersuite is TLS-"
1563
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001564run_test "extKeyUsage cli: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001565 "$O_SRV -key data_files/server5.key \
1566 -cert data_files/server5.eku-cs.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001567 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001568 1 \
1569 -c "bad certificate (usage extensions)" \
1570 -c "Processing of the Certificate handshake message failed" \
1571 -C "Ciphersuite is TLS-"
1572
1573# Tests for extendedKeyUsage, part 3: server-side checking of client cert
1574
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001575run_test "extKeyUsage cli-auth: clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001576 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001577 "$O_CLI -key data_files/server5.key \
1578 -cert data_files/server5.eku-cli.crt" \
1579 0 \
1580 -S "bad certificate (usage extensions)" \
1581 -S "Processing of the Certificate handshake message failed"
1582
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001583run_test "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001584 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001585 "$O_CLI -key data_files/server5.key \
1586 -cert data_files/server5.eku-srv_cli.crt" \
1587 0 \
1588 -S "bad certificate (usage extensions)" \
1589 -S "Processing of the Certificate handshake message failed"
1590
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001591run_test "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001592 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001593 "$O_CLI -key data_files/server5.key \
1594 -cert data_files/server5.eku-cs_any.crt" \
1595 0 \
1596 -S "bad certificate (usage extensions)" \
1597 -S "Processing of the Certificate handshake message failed"
1598
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001599run_test "extKeyUsage cli-auth: codeSign -> fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001600 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001601 "$O_CLI -key data_files/server5.key \
1602 -cert data_files/server5.eku-cs.crt" \
1603 0 \
1604 -s "bad certificate (usage extensions)" \
1605 -S "Processing of the Certificate handshake message failed"
1606
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001607run_test "extKeyUsage cli-auth: codeSign -> fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001608 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001609 "$O_CLI -key data_files/server5.key \
1610 -cert data_files/server5.eku-cs.crt" \
1611 1 \
1612 -s "bad certificate (usage extensions)" \
1613 -s "Processing of the Certificate handshake message failed"
1614
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001615# Tests for DHM parameters loading
1616
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001617run_test "DHM parameters: reference" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001618 "$P_SRV" \
1619 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1620 debug_level=3" \
1621 0 \
1622 -c "value of 'DHM: P ' (2048 bits)" \
1623 -c "value of 'DHM: G ' (2048 bits)"
1624
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001625run_test "DHM parameters: other parameters" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001626 "$P_SRV dhm_file=data_files/dhparams.pem" \
1627 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1628 debug_level=3" \
1629 0 \
1630 -c "value of 'DHM: P ' (1024 bits)" \
1631 -c "value of 'DHM: G ' (2 bits)"
1632
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001633# Tests for PSK callback
1634
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001635run_test "PSK callback: psk, no callback" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001636 "$P_SRV psk=abc123 psk_identity=foo" \
1637 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1638 psk_identity=foo psk=abc123" \
1639 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001640 -S "SSL - The server has no ciphersuites in common" \
1641 -S "SSL - Unknown identity received" \
1642 -S "SSL - Verification of the message MAC failed"
1643
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001644run_test "PSK callback: no psk, no callback" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001645 "$P_SRV" \
1646 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1647 psk_identity=foo psk=abc123" \
1648 1 \
1649 -s "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001650 -S "SSL - Unknown identity received" \
1651 -S "SSL - Verification of the message MAC failed"
1652
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001653run_test "PSK callback: callback overrides other settings" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001654 "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
1655 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1656 psk_identity=foo psk=abc123" \
1657 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001658 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001659 -s "SSL - Unknown identity received" \
1660 -S "SSL - Verification of the message MAC failed"
1661
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001662run_test "PSK callback: first id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001663 "$P_SRV psk_list=abc,dead,def,beef" \
1664 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1665 psk_identity=abc psk=dead" \
1666 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001667 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001668 -S "SSL - Unknown identity received" \
1669 -S "SSL - Verification of the message MAC failed"
1670
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001671run_test "PSK callback: second id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001672 "$P_SRV psk_list=abc,dead,def,beef" \
1673 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1674 psk_identity=def psk=beef" \
1675 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001676 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001677 -S "SSL - Unknown identity received" \
1678 -S "SSL - Verification of the message MAC failed"
1679
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001680run_test "PSK callback: no match" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001681 "$P_SRV psk_list=abc,dead,def,beef" \
1682 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1683 psk_identity=ghi psk=beef" \
1684 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001685 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001686 -s "SSL - Unknown identity received" \
1687 -S "SSL - Verification of the message MAC failed"
1688
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001689run_test "PSK callback: wrong key" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001690 "$P_SRV psk_list=abc,dead,def,beef" \
1691 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1692 psk_identity=abc psk=beef" \
1693 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001694 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001695 -S "SSL - Unknown identity received" \
1696 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001697
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001698# Tests for ciphersuites per version
1699
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001700run_test "Per-version suites: SSL3" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001701 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1702 "$P_CLI force_version=ssl3" \
1703 0 \
1704 -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA"
1705
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001706run_test "Per-version suites: TLS 1.0" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001707 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1708 "$P_CLI force_version=tls1" \
1709 0 \
1710 -c "Ciphersuite is TLS-RSA-WITH-RC4-128-SHA"
1711
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001712run_test "Per-version suites: TLS 1.1" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001713 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1714 "$P_CLI force_version=tls1_1" \
1715 0 \
1716 -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA"
1717
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001718run_test "Per-version suites: TLS 1.2" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001719 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1720 "$P_CLI force_version=tls1_2" \
1721 0 \
1722 -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
1723
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001724# Tests for ssl_get_bytes_avail()
1725
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001726run_test "ssl_get_bytes_avail: no extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001727 "$P_SRV" \
1728 "$P_CLI request_size=100" \
1729 0 \
1730 -s "Read from client: 100 bytes read$"
1731
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001732run_test "ssl_get_bytes_avail: extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001733 "$P_SRV" \
1734 "$P_CLI request_size=500" \
1735 0 \
1736 -s "Read from client: 500 bytes read (.*+.*)"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001737
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02001738# Tests for small packets
1739
1740run_test "Small packet SSLv3 BlockCipher" \
1741 "$P_SRV" \
1742 "$P_CLI request_size=1 force_version=ssl3 \
1743 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1744 0 \
1745 -s "Read from client: 1 bytes read"
1746
1747run_test "Small packet SSLv3 StreamCipher" \
1748 "$P_SRV" \
1749 "$P_CLI request_size=1 force_version=ssl3 \
1750 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1751 0 \
1752 -s "Read from client: 1 bytes read"
1753
1754run_test "Small packet TLS 1.0 BlockCipher" \
1755 "$P_SRV" \
1756 "$P_CLI request_size=1 force_version=tls1 \
1757 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1758 0 \
1759 -s "Read from client: 1 bytes read"
1760
1761run_test "Small packet TLS 1.0 BlockCipher truncated MAC" \
1762 "$P_SRV" \
1763 "$P_CLI request_size=1 force_version=tls1 \
1764 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1765 trunc_hmac=1" \
1766 0 \
1767 -s "Read from client: 1 bytes read"
1768
1769run_test "Small packet TLS 1.0 StreamCipher truncated MAC" \
1770 "$P_SRV" \
1771 "$P_CLI request_size=1 force_version=tls1 \
1772 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1773 trunc_hmac=1" \
1774 0 \
1775 -s "Read from client: 1 bytes read"
1776
1777run_test "Small packet TLS 1.1 BlockCipher" \
1778 "$P_SRV" \
1779 "$P_CLI request_size=1 force_version=tls1_1 \
1780 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1781 0 \
1782 -s "Read from client: 1 bytes read"
1783
1784run_test "Small packet TLS 1.1 StreamCipher" \
1785 "$P_SRV" \
1786 "$P_CLI request_size=1 force_version=tls1_1 \
1787 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1788 0 \
1789 -s "Read from client: 1 bytes read"
1790
1791run_test "Small packet TLS 1.1 BlockCipher truncated MAC" \
1792 "$P_SRV" \
1793 "$P_CLI request_size=1 force_version=tls1_1 \
1794 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1795 trunc_hmac=1" \
1796 0 \
1797 -s "Read from client: 1 bytes read"
1798
1799run_test "Small packet TLS 1.1 StreamCipher truncated MAC" \
1800 "$P_SRV" \
1801 "$P_CLI request_size=1 force_version=tls1_1 \
1802 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1803 trunc_hmac=1" \
1804 0 \
1805 -s "Read from client: 1 bytes read"
1806
1807run_test "Small packet TLS 1.2 BlockCipher" \
1808 "$P_SRV" \
1809 "$P_CLI request_size=1 force_version=tls1_2 \
1810 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1811 0 \
1812 -s "Read from client: 1 bytes read"
1813
1814run_test "Small packet TLS 1.2 BlockCipher larger MAC" \
1815 "$P_SRV" \
1816 "$P_CLI request_size=1 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1817 0 \
1818 -s "Read from client: 1 bytes read"
1819
1820run_test "Small packet TLS 1.2 BlockCipher truncated MAC" \
1821 "$P_SRV" \
1822 "$P_CLI request_size=1 force_version=tls1_2 \
1823 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1824 trunc_hmac=1" \
1825 0 \
1826 -s "Read from client: 1 bytes read"
1827
1828run_test "Small packet TLS 1.2 StreamCipher" \
1829 "$P_SRV" \
1830 "$P_CLI request_size=1 force_version=tls1_2 \
1831 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1832 0 \
1833 -s "Read from client: 1 bytes read"
1834
1835run_test "Small packet TLS 1.2 StreamCipher truncated MAC" \
1836 "$P_SRV" \
1837 "$P_CLI request_size=1 force_version=tls1_2 \
1838 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1839 trunc_hmac=1" \
1840 0 \
1841 -s "Read from client: 1 bytes read"
1842
1843run_test "Small packet TLS 1.2 AEAD" \
1844 "$P_SRV" \
1845 "$P_CLI request_size=1 force_version=tls1_2 \
1846 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1847 0 \
1848 -s "Read from client: 1 bytes read"
1849
1850run_test "Small packet TLS 1.2 AEAD shorter tag" \
1851 "$P_SRV" \
1852 "$P_CLI request_size=1 force_version=tls1_2 \
1853 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
1854 0 \
1855 -s "Read from client: 1 bytes read"
1856
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02001857# Test for large packets
1858
1859run_test "Large packet SSLv3 BlockCipher" \
1860 "$P_SRV" \
1861 "$P_CLI request_size=16384 force_version=ssl3 \
1862 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1863 0 \
1864 -s "Read from client: 16384 bytes read"
1865
1866run_test "Large packet SSLv3 StreamCipher" \
1867 "$P_SRV" \
1868 "$P_CLI request_size=16384 force_version=ssl3 \
1869 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1870 0 \
1871 -s "Read from client: 16384 bytes read"
1872
1873run_test "Large packet TLS 1.0 BlockCipher" \
1874 "$P_SRV" \
1875 "$P_CLI request_size=16384 force_version=tls1 \
1876 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1877 0 \
1878 -s "Read from client: 16384 bytes read"
1879
1880run_test "Large packet TLS 1.0 BlockCipher truncated MAC" \
1881 "$P_SRV" \
1882 "$P_CLI request_size=16384 force_version=tls1 \
1883 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1884 trunc_hmac=1" \
1885 0 \
1886 -s "Read from client: 16384 bytes read"
1887
1888run_test "Large packet TLS 1.0 StreamCipher truncated MAC" \
1889 "$P_SRV" \
1890 "$P_CLI request_size=16384 force_version=tls1 \
1891 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1892 trunc_hmac=1" \
1893 0 \
1894 -s "Read from client: 16384 bytes read"
1895
1896run_test "Large packet TLS 1.1 BlockCipher" \
1897 "$P_SRV" \
1898 "$P_CLI request_size=16384 force_version=tls1_1 \
1899 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1900 0 \
1901 -s "Read from client: 16384 bytes read"
1902
1903run_test "Large packet TLS 1.1 StreamCipher" \
1904 "$P_SRV" \
1905 "$P_CLI request_size=16384 force_version=tls1_1 \
1906 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1907 0 \
1908 -s "Read from client: 16384 bytes read"
1909
1910run_test "Large packet TLS 1.1 BlockCipher truncated MAC" \
1911 "$P_SRV" \
1912 "$P_CLI request_size=16384 force_version=tls1_1 \
1913 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1914 trunc_hmac=1" \
1915 0 \
1916 -s "Read from client: 16384 bytes read"
1917
1918run_test "Large packet TLS 1.1 StreamCipher truncated MAC" \
1919 "$P_SRV" \
1920 "$P_CLI request_size=16384 force_version=tls1_1 \
1921 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1922 trunc_hmac=1" \
1923 0 \
1924 -s "Read from client: 16384 bytes read"
1925
1926run_test "Large packet TLS 1.2 BlockCipher" \
1927 "$P_SRV" \
1928 "$P_CLI request_size=16384 force_version=tls1_2 \
1929 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1930 0 \
1931 -s "Read from client: 16384 bytes read"
1932
1933run_test "Large packet TLS 1.2 BlockCipher larger MAC" \
1934 "$P_SRV" \
1935 "$P_CLI request_size=16384 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1936 0 \
1937 -s "Read from client: 16384 bytes read"
1938
1939run_test "Large packet TLS 1.2 BlockCipher truncated MAC" \
1940 "$P_SRV" \
1941 "$P_CLI request_size=16384 force_version=tls1_2 \
1942 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1943 trunc_hmac=1" \
1944 0 \
1945 -s "Read from client: 16384 bytes read"
1946
1947run_test "Large packet TLS 1.2 StreamCipher" \
1948 "$P_SRV" \
1949 "$P_CLI request_size=16384 force_version=tls1_2 \
1950 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1951 0 \
1952 -s "Read from client: 16384 bytes read"
1953
1954run_test "Large packet TLS 1.2 StreamCipher truncated MAC" \
1955 "$P_SRV" \
1956 "$P_CLI request_size=16384 force_version=tls1_2 \
1957 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1958 trunc_hmac=1" \
1959 0 \
1960 -s "Read from client: 16384 bytes read"
1961
1962run_test "Large packet TLS 1.2 AEAD" \
1963 "$P_SRV" \
1964 "$P_CLI request_size=16384 force_version=tls1_2 \
1965 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1966 0 \
1967 -s "Read from client: 16384 bytes read"
1968
1969run_test "Large packet TLS 1.2 AEAD shorter tag" \
1970 "$P_SRV" \
1971 "$P_CLI request_size=16384 force_version=tls1_2 \
1972 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
1973 0 \
1974 -s "Read from client: 16384 bytes read"
1975
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001976# Tests for DTLS HelloVerifyRequest
1977
1978run_test "DTLS cookie: enabled" \
1979 "$P_SRV dtls=1 debug_level=2" \
1980 "$P_CLI dtls=1 debug_level=2" \
1981 0 \
1982 -s "cookie verification failed" \
1983 -s "cookie verification passed" \
1984 -S "cookie verification skipped" \
1985 -c "received hello verify request" \
1986 -S "SSL - The requested feature is not available"
1987
1988run_test "DTLS cookie: disabled" \
1989 "$P_SRV dtls=1 debug_level=2 cookies=0" \
1990 "$P_CLI dtls=1 debug_level=2" \
1991 0 \
1992 -S "cookie verification failed" \
1993 -S "cookie verification passed" \
1994 -s "cookie verification skipped" \
1995 -C "received hello verify request" \
1996 -S "SSL - The requested feature is not available"
1997
1998# wait for client having a timeout, or server sending an alert
1999#run_test "DTLS cookie: default (failing)" \
2000# "$P_SRV dtls=1 debug_level=2 cookies=-1" \
2001# "$P_CLI dtls=1 debug_level=2" \
2002# 0 \
2003# -S "cookie verification failed" \
2004# -S "cookie verification passed" \
2005# -S "cookie verification skipped" \
2006# -C "received hello verify request" \
2007# -s "SSL - The requested feature is not available"
2008
2009requires_ipv6
2010run_test "DTLS cookie: enabled, IPv6" \
2011 "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
2012 "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
2013 0 \
2014 -s "cookie verification failed" \
2015 -s "cookie verification passed" \
2016 -S "cookie verification skipped" \
2017 -c "received hello verify request" \
2018 -S "SSL - The requested feature is not available"
2019
Manuel Pégourié-Gonnard502bf302014-08-20 13:12:58 +02002020# Tests for receiving fragmented handshake messages with DTLS
2021
2022requires_gnutls
2023run_test "DTLS reassembly: no fragmentation (gnutls server)" \
2024 "$G_SRV -u --mtu 2048 -a" \
2025 "$P_CLI dtls=1 debug_level=2" \
2026 0 \
2027 -C "found fragmented DTLS handshake message" \
2028 -C "error"
2029
2030requires_gnutls
2031run_test "DTLS reassembly: some fragmentation (gnutls server)" \
2032 "$G_SRV -u --mtu 512" \
2033 "$P_CLI dtls=1 debug_level=2" \
2034 0 \
2035 -c "found fragmented DTLS handshake message" \
2036 -C "error"
2037
2038requires_gnutls
2039run_test "DTLS reassembly: more fragmentation (gnutls server)" \
2040 "$G_SRV -u --mtu 128" \
2041 "$P_CLI dtls=1 debug_level=2" \
2042 0 \
2043 -c "found fragmented DTLS handshake message" \
2044 -C "error"
2045
2046requires_gnutls
2047run_test "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
2048 "$G_SRV -u --mtu 128" \
2049 "$P_CLI dtls=1 nbio=2 debug_level=2" \
2050 0 \
2051 -c "found fragmented DTLS handshake message" \
2052 -C "error"
2053
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002054requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002055run_test "DTLS reassembly: fragmentation, renego (gnutls server)" \
2056 "$G_SRV -u --mtu 256" \
2057 "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
2058 0 \
2059 -c "found fragmented DTLS handshake message" \
2060 -c "client hello, adding renegotiation extension" \
2061 -c "found renegotiation extension" \
2062 -c "=> renegotiate" \
2063 -C "ssl_handshake returned" \
2064 -C "error" \
2065 -s "Extra-header:"
2066
2067requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002068run_test "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
2069 "$G_SRV -u --mtu 256" \
2070 "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
2071 0 \
2072 -c "found fragmented DTLS handshake message" \
2073 -c "client hello, adding renegotiation extension" \
2074 -c "found renegotiation extension" \
2075 -c "=> renegotiate" \
2076 -C "ssl_handshake returned" \
2077 -C "error" \
2078 -s "Extra-header:"
2079
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02002080run_test "DTLS reassembly: no fragmentation (openssl server)" \
2081 "$O_SRV -dtls1 -mtu 2048" \
2082 "$P_CLI dtls=1 debug_level=2" \
2083 0 \
2084 -C "found fragmented DTLS handshake message" \
2085 -C "error"
2086
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02002087run_test "DTLS reassembly: fragmentation (openssl server)" \
2088 "$O_SRV -dtls1 -mtu 256" \
2089 "$P_CLI dtls=1 debug_level=2" \
2090 0 \
2091 -c "found fragmented DTLS handshake message" \
2092 -C "error"
2093
2094run_test "DTLS reassembly: fragmentation (openssl server)" \
2095 "$O_SRV -dtls1 -mtu 256" \
2096 "$P_CLI dtls=1 debug_level=2" \
2097 0 \
2098 -c "found fragmented DTLS handshake message" \
2099 -C "error"
2100
2101run_test "DTLS reassembly: fragmentation, nbio (openssl server)" \
2102 "$O_SRV -dtls1 -mtu 256" \
2103 "$P_CLI dtls=1 nbio=2 debug_level=2" \
2104 0 \
2105 -c "found fragmented DTLS handshake message" \
2106 -C "error"
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02002107
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002108# Tests with UDP proxy emulating unreliable transport
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002109
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002110run_test "DTLS proxy: reference" \
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002111 -p "$P_PXY" \
2112 "$P_SRV dtls=1" \
2113 "$P_CLI dtls=1" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002114 0 \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002115 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002116 -c "HTTP/1.0 200 OK"
2117
2118run_test "DTLS proxy: some duplication" \
2119 -p "$P_PXY duplicate=3" \
2120 "$P_SRV dtls=1" \
2121 "$P_CLI dtls=1" \
2122 0 \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002123 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002124 -c "HTTP/1.0 200 OK"
2125
2126run_test "DTLS proxy: lots of duplication" \
2127 -p "$P_PXY duplicate=1" \
2128 "$P_SRV dtls=1" \
2129 "$P_CLI dtls=1" \
2130 0 \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002131 -s "Extra-header:" \
2132 -c "HTTP/1.0 200 OK"
2133
2134run_test "DTLS proxy: inject invalid AD record" \
2135 -p "$P_PXY bad_ad=1" \
2136 "$P_SRV dtls=1" \
2137 "$P_CLI dtls=1" \
2138 0 \
2139 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002140 -c "HTTP/1.0 200 OK"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002141
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +02002142run_test "DTLS proxy: drop a few packets" \
2143 -p "$P_PXY drop=10" \
2144 "$P_SRV dtls=1" \
2145 "$P_CLI dtls=1" \
2146 0 \
2147 -s "Extra-header:" \
2148 -c "HTTP/1.0 200 OK"
2149
2150needs_more_time 2
2151run_test "DTLS proxy: drop a bit more packets" \
2152 -p "$P_PXY drop=6" \
2153 "$P_SRV dtls=1" \
2154 "$P_CLI dtls=1" \
2155 0 \
2156 -s "Extra-header:" \
2157 -c "HTTP/1.0 200 OK"
2158
2159needs_more_time 3
2160run_test "DTLS proxy: drop more packets" \
2161 -p "$P_PXY drop=3" \
2162 "$P_SRV dtls=1" \
2163 "$P_CLI dtls=1" \
2164 0 \
2165 -s "Extra-header:" \
2166 -c "HTTP/1.0 200 OK"
2167
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002168# Final report
2169
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01002170echo "------------------------------------------------------------------------"
2171
2172if [ $FAILS = 0 ]; then
2173 echo -n "PASSED"
2174else
2175 echo -n "FAILED"
2176fi
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +02002177PASSES=$(( $TESTS - $FAILS ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +02002178echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01002179
2180exit $FAILS