-
Notifications
You must be signed in to change notification settings - Fork 14
/
test.sh
executable file
·439 lines (403 loc) · 9.18 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#!/bin/bash
NGINX_SRC="../nginx"
if [ "$NGINX_BIN" = "" ]; then
NGINX_BIN="${NGINX_SRC}/objs/nginx"
fi
if [ "$WOLFSSL_SOURCE" = "" ]; then
WOLFSSL_SOURCE="../wolfssl"
fi
WOLFSSL_CLIENT="./examples/client/client"
NGINX_CONF="./conf/nginx.conf"
NGINX_TLS13_CONF="./conf/nginx_tls13.conf"
CLIENT_TMP="/tmp/nginx_client.$$"
SERVER_TMP="/tmp/nginx_server.$$"
OCSP_GOOD="ocsp-good-status.der"
OCSP_BAD="ocsp-bad-status.der"
WN_PATH=`pwd`
WN_OCSP_GOOD="$WN_PATH/conf/$OCSP_GOOD"
WN_OCSP_BAD="$WN_PATH/conf/$OCSP_BAD"
WN_LOGS="$WN_PATH/logs"
WN_ERROR_LOG="$WN_LOGS/error.log"
HOST="127.0.0.1"
if [ "$IPV6" != "" ]; then
HOST="::ffff:127.0.0.1"
fi
while [ $# -gt 0 ]
do
case $1 in
-tls13)
TLS13=1
NGINX_CONF=$NGINX_TLS13_CONF
;;
*)
echo "Unrecognized option: $1"
exit 1
;;
esac
shift
done
if [ ! -f $NGINX_BIN ]; then
echo "Could not find Nginx exe: ${NGINX_BIN}"
echo "Stopping - FAIL"
exit 1
fi
echo "Ngninx binary: $NGINX_BIN"
echo "wolfSSL Source directory: $WOLFSSL_SOURCE"
if [ ! -d $WOLFSSL_SOURCE ]; then
echo "Could not find wolfSSL source directory: ${WOLFSSL_SOURCE}"
echo "Stopping - FAIL"
exit 1
fi
echo "Changing into wolfSSL source directory"
cd $WOLFSSL_SOURCE
if [ ! -e $WOLFSSL_CLIENT ]; then
echo "Could not find wolfSSL client: ${WOLFSSL_CLIENT}"
echo "Stopping - FAIL"
exit 1
fi
OPENSSL=`which openssl`
if [ "$?" = "1" ]; then
echo "Could not find openssl superapp"
echo "Stopping - FAIL"
exit 1
fi
echo "OpenSSL superapp found: $OPENSSL"
echo
if [ ! -d $WN_LOGS ]; then
echo "Making directory: ${WN_LOGS}"
mkdir ${WN_LOGS}
fi
# Number of minutes OCSP responses will be valid for
VALID_MIN=60
declare -a EXPECT
declare -a EXPECT_SERVER
declare -a EXP
SERVER_PID=0
OCSP_PID=0
PASS=0
FAIL=0
UNKNOWN=0
run_nginx() {
# valgrind --leak-check=full
echo ${NGINX_BIN} -p ${WN_PATH} \
-c $NGINX_CONF \
-g "error_log ${WN_ERROR_LOG} debug;" \
${NGINX_OPTS}
${NGINX_BIN} -p ${WN_PATH} \
-c $NGINX_CONF \
-g "error_log ${WN_ERROR_LOG} debug;" \
${NGINX_OPTS}
RES=$?
}
do_cleanup() {
echo "# In cleanup"
NGINX_OPTS="-s stop"
run_nginx
rm -f $CLIENT_TMP
rm -f $SERVER_TMP
if [ $SERVER_PID != '0' ]
then
echo "# Killing server"
kill -9 $SERVER_PID
fi
if [ $OCSP_PID != '0' ]
then
echo "# Killing OCSP responder"
kill -9 $OCSP_PID
fi
cd $WN_PATH
rm -rf client_body_temp fastcgi_temp proxy_temp scgi_temp uwsgi_temp
}
do_trap() {
echo "# Got trap"
do_cleanup
exit 1
}
trap do_trap INT TERM
check_log() {
DUMP_LOG="no"
if [ "$EXP" != "" ]; then
for I in ${!EXP[@]}
do
if grep "${EXP[$I]}" $LOG; then
echo "# PASS: Found: ${EXP[$I]}"
echo
PASS=$(($PASS + 1))
else
echo "# FAIL: Didn't find: ${EXP[$I]}"
echo
DUMP_LOG="yes"
FAIL=$(($FAIL + 1))
fi
done
else
DUMP_LOG="yes"
UNKNOWN=$(($UNKNOWN + 1))
fi
if [ "$DUMP_LOG" = "yes" ]; then
cat $LOG
fi
}
client() {
${WOLFSSL_CLIENT} -r -g -p $PORT -h $HOST $OPTS >$CLIENT_TMP 2>&1
echo "# Client Output"
LOG=$CLIENT_TMP
EXP=("${EXPECT[@]}")
check_log
}
client_test() {
OPTS="$OPTS -r"
client
}
stapling_test() {
OPTS="$OPTS -C -A ${WN_PATH}/conf/ocsp-root-ca-cert.pem -W 1"
client
}
# Start the OSCP responder and generate the response files
${OPENSSL} ocsp -port 22221 -nmin ${VALID_MIN} -index ${WN_PATH}/conf/ocsp-index.txt -rsigner ${WN_PATH}/conf/ocsp-responder-cert.pem -rkey ${WN_PATH}/conf/ocsp-responder-key.pem -CA ${WN_PATH}/conf/ocsp-intermediate-ca-cert.pem >/dev/null 2>&1 &
OCSP_PID=$!
# Generate OCSP response file that indicates certificate is good.
${OPENSSL} ocsp -issuer ${WN_PATH}/conf/ocsp-intermediate-ca-cert.pem -cert ${WN_PATH}/conf/ocsp-good-cert.pem -url http://localhost:22221 -resp_text -respout ${WN_OCSP_GOOD} -no_nonce >/dev/null 2>&1
# Generate OCSP response file that indicates certificate is revoked.
${OPENSSL} ocsp -issuer ${WN_PATH}/conf/ocsp-intermediate-ca-cert.pem -cert ${WN_PATH}/conf/ocsp-bad-cert.pem -url http://localhost:22221 -resp_text -respout ${WN_OCSP_BAD} -no_nonce >/dev/null 2>&1
if [ ! -f $WN_OCSP_GOOD ]; then
echo "Could not find OCSP output file: ${WN_OCSP_GOOD}"
echo "Stopping - FAIL"
exit 1
fi
if [ ! -f $WN_OCSP_BAD ]; then
echo "Could not find OCSP output file: ${WN_OCSP_BAD}"
echo "Stopping - FAIL"
exit 1
fi
echo "Stopping Nginx ..."
NGINX_OPTS="-s stop"
run_nginx
echo "Starting Nginx ..."
# Start Nginx
NGINX_OPTS=
run_nginx
if [ "$RES" != "0" ]; then
echo "Failed to start Nginx"
exit 1
fi
# Default certificate, DH KEA
echo
echo '#'
echo '# DH Key Exchange'
echo '#'
PORT=11443
echo "# Port: $PORT"
OPTS=
EXPECT=("2048" "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" "HTTP/1.1 200 OK" "resume response")
client_test
# Default certificate, DH, verify client
echo
echo '#'
echo '# DH Key Exchange verify client'
echo '#'
PORT=11444
echo "# Port: $PORT"
OPTS="-x"
EXPECT=("400 No required SSL certificate was sent")
client_test
# Default certificate, ECDH with SECP384R1
echo
echo '#'
echo '# ECDH Key Exchange: SECP384R1'
echo '#'
PORT=11445
echo "# Port: $PORT"
OPTS=
EXPECT=("SECP384R1" "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" "HTTP/1.1 200 OK")
client_test
# ECC certificate, ECDH with default curve (prime256v1)
echo
echo '#'
echo '# ECC Certificate, ECDH Key Exchange: default curve (prime256v1)'
echo '#'
PORT=11446
echo "# Port: $PORT"
OPTS="-A certs/ca-ecc-cert.pem"
EXPECT=("SECP256R1" "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" "HTTP/1.1 200 OK")
client_test
if [ "$TLS13" != "" ]; then
# TLS v1.3
echo
echo '#'
echo '# TLS v1.3 client connecting to nginx server'
echo '#'
PORT=11447
echo "# Port: $PORT"
OPTS="-v 4"
EXPECT=("SECP256R1" "TLS_AES_128_GCM_SHA256" "HTTP/1.1 200 OK")
client_test
fi
# Session tickets file
echo
echo '#'
echo '# Session ticket file'
echo '#'
PORT=11450
echo "# Port: $PORT"
OPTS=
EXPECT=("Session Ticket CB" "HTTP/1.1 200 OK")
client_test
echo
echo '#'
echo '# Session cache off'
echo '#'
PORT=11455
echo "# Port: $PORT"
OPTS=
EXPECT=("didn't reuse session id!!!" "HTTP/1.1 200 OK")
client_test
echo
echo '#'
echo '# Session cache none'
echo '#'
PORT=11456
echo "# Port: $PORT"
OPTS=
EXPECT=("didn't reuse session id!!!" "HTTP/1.1 200 OK")
client_test
echo
echo '#'
echo '# Session cache builtin'
echo '#'
PORT=11457
echo "# Port: $PORT"
OPTS=
if [ "$TLS13" != "" ]; then
EXPECT=("HTTP/1.1 200 OK")
else
EXPECT=("reused session id" "HTTP/1.1 200 OK")
fi
client_test
# Proxy to localhost:11111 - DHE-RSA
echo
echo '#'
echo '# Proxy - DHE-RSA'
echo '#'
PORT=11460
echo "# Port: $PORT"
OPTS=
SERVER_OPTS=
EXPECT=("HTTP/1.1 200 OK" "Welcome to wolf")
client_test
# Proxy to localhost:11111 - ECDHE-RSA
echo
echo '#'
echo '# Proxy - ECDHE-RSA'
echo '#'
PORT=11461
echo "# Port: $PORT"
OPTS=
SERVER_OPTS=
EXPECT=("HTTP/1.1 200 OK" "Welcome to wolf")
client_test
# Proxy to localhost:11111 - ECDHE-ECDSA
echo
echo '#'
echo '# Proxy - ECDHE-ECDSA'
echo '#'
PORT=11462
echo "# Port: $PORT"
OPTS=
SERVER_OPTS="-c certs/server-ecc.pem -k certs/ecc-key.pem"
EXPECT=("HTTP/1.1 200 OK" "Welcome to wolf")
client_test
# Proxy to localhost:11111 - ECDHE-ECDSA
echo
echo '#'
echo '# Proxy - ECDHE-ECDSA'
echo '#'
PORT=11463
echo "# Port: $PORT"
OPTS=
SERVER_OPTS="-c certs/server-ecc.pem -k certs/ecc-key.pem"
EXPECT=("HTTP/1.1 200 OK" "Welcome to wolf")
client_test
# Proxy to localhost:11111 - ECDHE-ECDSA
echo
echo '#'
echo '# Proxy - ECDHE-ECDSA'
echo '#'
PORT=11464
echo "# Port: $PORT"
OPTS=
SERVER_OPTS="-c certs/server-ecc.pem -k certs/ecc-key.pem"
EXPECT=("HTTP/1.1 502")
client_test
# Proxy to localhost:11111 - Revoked certificate in CRL
echo
echo '#'
echo '# Proxy - Revoked certificate in CRL'
echo '#'
PORT=11465
echo "# Port: $PORT"
OPTS=
SERVER_OPTS=
EXPECT=("HTTP/1.1 502")
client_test
# OCSP Stapling
# Good certificate
echo
echo '#'
echo '# OCSP Stapling - Good Certificate (Using OCSP Responder)'
echo '#'
PORT=11470
echo "# Port: $PORT"
OPTS=
EXPECT=("HTTP/1.1 200 OK")
stapling_test
stapling_test
# Revoked certificate
echo
echo '#'
echo '# OCSP Stapling - Revoked Certificate (Using OCSP Responder)'
echo '#'
PORT=11471
echo "# Port: $PORT"
OPTS=
EXPECT=("err" "360")
stapling_test
stapling_test
# Good certificate - response file
echo
echo '#'
echo '# OCSP Stapling - Good Certificate (Using pre-generated file)'
echo '#'
PORT=11472
echo "# Port: $PORT"
OPTS=
EXPECT=("HTTP/1.1 200 OK")
stapling_test
# Revoked certificate - response file
echo
echo '#'
echo '# OCSP Stapling - Revoked Certificate (Using pre-generated file)'
echo '#'
PORT=11473
echo "# Port: $PORT"
OPTS=
EXPECT=("err" "360")
stapling_test
# No certificate for verification of OCSP response
echo
echo '#'
echo '# OCSP Stapling - Using OCSP Responder but no cert to verify'
echo '#'
PORT=11474
echo "# Port: $PORT"
OPTS=
EXPECT=("HTTP/1.1 200 OK")
stapling_test
stapling_test
do_cleanup
echo
echo "##############"
echo "# PASS : $PASS"
echo "# FAIL : $FAIL"
echo "# UNKNOWN : $UNKNOWN"
echo "##############"