blob: d3f8d75994aff84229598b649e5599195ea43ec8 [file] [log] [blame]
William Lallemand4781fad2020-03-31 14:48:34 +02001#REGTEST_TYPE=devel
William Lallemand2be4a2e2020-03-31 12:13:34 +02002
3# This reg-test uses the "add ssl crt-list" command to add a certificate over the CLI.
William Lallemand3ed722f2020-04-30 09:47:08 +02004# It requires socat to upload the certificate
5
6# this check does 2 requests, the first one will use "www.test1.com" as SNI, and
7# the second one will use "localhost". Since vtest can't do SSL, we use haproxy
8# as an SSL client with 2 chained listen section.
William Lallemand2be4a2e2020-03-31 12:13:34 +02009
10# If this test does not work anymore:
William Lallemand3ed722f2020-04-30 09:47:08 +020011# - Check that you have socat
William Lallemand2be4a2e2020-03-31 12:13:34 +020012
13varnishtest "Test the 'add ssl crt-list' feature of the CLI"
14#REQUIRE_VERSION=2.2
15#REQUIRE_OPTIONS=OPENSSL
Tim Duesterhus4ee192f2021-06-11 19:56:17 +020016feature cmd "command -v socat"
William Lallemand2be4a2e2020-03-31 12:13:34 +020017feature ignore_unknown_macro
18
William Lallemand3ed722f2020-04-30 09:47:08 +020019server s1 -repeat 2 {
20 rxreq
21 txresp
22} -start
William Lallemand2be4a2e2020-03-31 12:13:34 +020023
24haproxy h1 -conf {
William Lallemand3ed722f2020-04-30 09:47:08 +020025 global
26 tune.ssl.default-dh-param 2048
Marcin Deranek310a2602021-07-13 19:04:24 +020027 tune.ssl.capture-buffer-size 1
William Lallemand3ed722f2020-04-30 09:47:08 +020028 crt-base ${testdir}
29 stats socket "${tmpdir}/h1/stats" level admin
30
31 defaults
32 mode http
33 option httplog
William Lallemand3ed722f2020-04-30 09:47:08 +020034 log stderr local0 debug err
35 option logasap
36 timeout connect 1s
37 timeout client 1s
38 timeout server 1s
William Lallemand2be4a2e2020-03-31 12:13:34 +020039
William Lallemand3ed722f2020-04-30 09:47:08 +020040
41 listen clear-lst
42 bind "fd@${clearlst}"
43 balance roundrobin
44 server s1 "${tmpdir}/ssl.sock" ssl verify none sni str(www.test1.com)
45 server s2 "${tmpdir}/ssl.sock" ssl verify none sni str(localhost)
46
47
48 listen ssl-lst
49 mode http
William Lallemand3ed722f2020-04-30 09:47:08 +020050 bind "${tmpdir}/ssl.sock" ssl strict-sni crt-list ${testdir}/localhost.crt-list
51
52 server s1 ${s1_addr}:${s1_port}
William Lallemand2be4a2e2020-03-31 12:13:34 +020053} -start
54
55
56haproxy h1 -cli {
57 send "show ssl cert ${testdir}/common.pem"
58 expect ~ ".*SHA1 FingerPrint: 2195C9F0FD58470313013FC27C1B9CF9864BD1C6"
59}
60
William Lallemand3ed722f2020-04-30 09:47:08 +020061client c1 -connect ${h1_clearlst_sock} {
62 txreq
63 rxresp
64 expect resp.status == 200
65} -run
William Lallemand2be4a2e2020-03-31 12:13:34 +020066
67shell {
William Lallemand3ed722f2020-04-30 09:47:08 +020068 echo "new ssl cert ${testdir}/ecdsa.pem" | socat "${tmpdir}/h1/stats" -
69 printf "set ssl cert ${testdir}/ecdsa.pem <<\n$(cat ${testdir}/ecdsa.pem)\n\n" | socat "${tmpdir}/h1/stats" -
70 echo "commit ssl cert ${testdir}/ecdsa.pem" | socat "${tmpdir}/h1/stats" -
William Lallemand99cc2182020-06-25 15:19:51 +020071 printf "add ssl crt-list ${testdir}/localhost.crt-list/ <<\n${testdir}/ecdsa.pem [ssl-min-ver SSLv3 verify none allow-0rtt] localhost !www.test1.com\n\n" | socat "${tmpdir}/h1/stats" -
William Lallemand3ed722f2020-04-30 09:47:08 +020072 printf "add ssl crt-list ${testdir}/localhost.crt-list <<\n${testdir}/ecdsa.pem [verify none allow-0rtt]\n\n" | socat "${tmpdir}/h1/stats" -
William Lallemand99cc2182020-06-25 15:19:51 +020073 printf "add ssl crt-list ${testdir}/localhost.crt-list/// <<\n${testdir}/ecdsa.pem localhost !www.test1.com\n\n" | socat "${tmpdir}/h1/stats" -
74 printf "add ssl crt-list ${testdir}/localhost.crt-list///// <<\n${testdir}/ecdsa.pem\n\n" | socat "${tmpdir}/h1/stats" -
75 printf "add ssl crt-list ${testdir}/localhost.crt-list// ${testdir}/ecdsa.pem\n" | socat "${tmpdir}/h1/stats" -
William Lallemand2be4a2e2020-03-31 12:13:34 +020076}
77
78haproxy h1 -cli {
79 send "show ssl cert ${testdir}/ecdsa.pem"
80 expect ~ ".*SHA1 FingerPrint: A490D069DBAFBEE66DE434BEC34030ADE8BCCBF1"
81}
82
83haproxy h1 -cli {
William Lallemand99cc2182020-06-25 15:19:51 +020084 send "show ssl crt-list ${testdir}/localhost.crt-list//"
William Lallemandfdb6db42020-04-01 17:13:22 +020085 # check the options and the filters in any order
William Lallemand8177ad92020-05-20 16:49:02 +020086 expect ~ ".*${testdir}/ecdsa.pem \\[(?=.*verify none)(?=.*allow-0rtt)(?=.*ssl-min-ver SSLv3).*\\](?=.*!www.test1.com)(?=.*localhost).*"
William Lallemand2be4a2e2020-03-31 12:13:34 +020087}
88
William Lallemand3ed722f2020-04-30 09:47:08 +020089client c1 -connect ${h1_clearlst_sock} {
90 txreq
91 rxresp
92 expect resp.status == 200
93} -run
Remi Tricot-Le Bretonfb00f312021-03-23 16:41:53 +010094
95
96# Try to add a new line that mentions an "unknown" CA file (not loaded yet).
97# It should fail since no disk access are allowed during runtime.
98shell {
99 printf "add ssl crt-list ${testdir}/localhost.crt-list/ <<\n${testdir}/ecdsa.pem [ca-file ${testdir}/ca-auth.crt] localhost\n\n" | socat "${tmpdir}/h1/stats" - | grep "unable to load ${testdir}/ca-auth.crt"
100}
101shell {
102 printf "add ssl crt-list ${testdir}/localhost.crt-list/ <<\n${testdir}/ecdsa.pem [ca-verify-file ${testdir}/ca-auth.crt] localhost\n\n" | socat "${tmpdir}/h1/stats" - | grep "unable to load ${testdir}/ca-auth.crt"
103}
104shell {
105 printf "add ssl crt-list ${testdir}/localhost.crt-list/ <<\n${testdir}/ecdsa.pem [crl-file ${testdir}/ca-auth.crt] localhost\n\n" | socat "${tmpdir}/h1/stats" - | grep "unable to load ${testdir}/ca-auth.crt"
106}
107
108# Check that the new line was not added to the crt-list.
109haproxy h1 -cli {
110 send "show ssl crt-list ${testdir}/localhost.crt-list//"
111 expect !~ ".*ca-file ${testdir}/ca-auth.crt"
112}