blob: c9ac904617a8903b897edb3247cf0223d4ccbad3 [file] [log] [blame]
Remi Tricot-Le Bretona3b2e092021-04-23 18:35:25 +02001#REGTEST_TYPE=devel
2
3# This reg-test uses the "set ssl crl-file" command to update a CRL file over the CLI.
4# It also tests the "abort ssl crl-file" and "show ssl crl-file" commands.
5#
6# The frontend's certificate is signed by set_cafile_interCA1.crt and is revoked in interCA1_crl.pem
7# but not in interCA1_crl_empty.pem.
8# The backend's certificate is signed by set_cafile_interCA2.crt and is revoked in interCA2_crl.pem
9# but not in interCA2_crl_empty.pem.
10#
11# The test consists in replacing the two empty CRLs by their not empty equivalent thanks to CLI
12# calls and to check that the certificates (frontend and backend) are indeed revoked after the
13# update.
14#
15# It requires socat to upload the certificate
16#
17# If this test does not work anymore:
18# - Check that you have socat
19
20varnishtest "Test the 'set ssl crl-file' feature of the CLI"
Tim Duesterhus5efc48d2021-06-11 19:56:15 +020021feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev0)'"
Tim Duesterhusc9570482021-06-11 19:56:16 +020022feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'"
Tim Duesterhus4ee192f2021-06-11 19:56:17 +020023feature cmd "command -v socat"
Remi Tricot-Le Bretona3b2e092021-04-23 18:35:25 +020024feature ignore_unknown_macro
25
26server s1 -repeat 4 {
27 rxreq
28 txresp
29} -start
30
31haproxy h1 -conf {
32 global
33 tune.ssl.default-dh-param 2048
Marcin Deranek310a2602021-07-13 19:04:24 +020034 tune.ssl.capture-buffer-size 1
Remi Tricot-Le Bretona3b2e092021-04-23 18:35:25 +020035 stats socket "${tmpdir}/h1/stats" level admin
36
37 defaults
38 mode http
39 option httplog
Willy Tarreauf6739232021-11-18 17:46:22 +010040 retries 0
Remi Tricot-Le Bretona3b2e092021-04-23 18:35:25 +020041 log stderr local0 debug err
42 option logasap
Willy Tarreauf6739232021-11-18 17:46:22 +010043 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
44 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
45 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Remi Tricot-Le Bretona3b2e092021-04-23 18:35:25 +020046
47 listen clear-lst
48 bind "fd@${clearlst}"
49 server s1 "${tmpdir}/ssl.sock" ssl crt ${testdir}/set_cafile_client.pem ca-file ${testdir}/set_cafile_interCA2.crt crl-file ${testdir}/interCA2_crl_empty.pem verify required
50
51 listen ssl-lst
52 # crt: certificate of the server
53 # ca-file: CA used for client authentication request
54 # crl-file: revocation list for client auth
55 bind "${tmpdir}/ssl.sock" ssl crt ${testdir}/set_cafile_server.pem ca-file ${testdir}/set_cafile_interCA1.crt ca-verify-file ${testdir}/set_cafile_rootCA.crt crl-file ${testdir}/interCA1_crl_empty.pem verify required crt-ignore-err all
56 http-response add-header X-SSL-Client-Verify %[ssl_c_verify]
57 server s1 ${s1_addr}:${s1_port}
58} -start
59
60# Test the "show ssl ca-file" command
61haproxy h1 -cli {
62 send "show ssl ca-file"
63 expect ~ ".*${testdir}/set_cafile_interCA1.crt - 1 certificate.*"
64 send "show ssl ca-file"
65 expect ~ ".*${testdir}/set_cafile_interCA2.crt - 1 certificate.*"
66}
67
68# Add the rootCA certificate to set_cafile_interCA2.crt in order for the frontend to
69# be able to validate the server's certificate
70shell {
71 printf "set ssl ca-file ${testdir}/set_cafile_interCA2.crt <<\n$(cat ${testdir}/set_cafile_interCA2.crt)\n$(cat ${testdir}/set_cafile_rootCA.crt)\n\n" | socat "${tmpdir}/h1/stats" -
72 echo "commit ssl ca-file ${testdir}/set_cafile_interCA2.crt" | socat "${tmpdir}/h1/stats" -
73}
74
75haproxy h1 -cli {
76 send "show ssl ca-file"
77 expect ~ ".*${testdir}/set_cafile_interCA2.crt - 2 certificate.*"
78
79 send "show ssl ca-file ${testdir}/set_cafile_interCA2.crt"
80 expect ~ ".*Subject.*/CN=Root CA"
81}
82
83# This first connection should succeed
84client c1 -connect ${h1_clearlst_sock} {
85 txreq
86 rxresp
87 expect resp.status == 200
88 expect resp.http.X-SSL-Client-Verify == 0
89} -run
90
91# Change the frontend's crl-file to one in which the server certificate is revoked
92shell {
93 printf "set ssl crl-file ${testdir}/interCA2_crl_empty.pem <<\n$(cat ${testdir}/interCA2_crl.pem)\n\n" | socat "${tmpdir}/h1/stats" -
94}
95
96# Check that the transaction is displayed in the output of "show ssl crl-list"
97haproxy h1 -cli {
98 send "show ssl crl-file"
99 expect ~ "\\*${testdir}/interCA2_crl_empty.pem"
100
101 send "show ssl crl-file \\*${testdir}/interCA2_crl_empty.pem"
102 expect ~ "Revoked Certificates:"
103 send "show ssl crl-file \\*${testdir}/interCA2_crl_empty.pem:1"
104 expect ~ "Serial Number: 1008"
105}
106
107# This connection should still succeed since the transaction was not committed
108client c1 -connect ${h1_clearlst_sock} {
109 txreq
110 rxresp
111 expect resp.status == 200
112 expect resp.http.X-SSL-Client-Verify == 0
113} -run
114
115haproxy h1 -cli {
116 send "commit ssl crl-file ${testdir}/interCA2_crl_empty.pem"
117 expect ~ "Committing ${testdir}/interCA2_crl_empty.pem"
118}
119
120# This connection should fail, the server's certificate is revoked in the newly updated CRL file
121client c1 -connect ${h1_clearlst_sock} {
122 txreq
123 rxresp
124 expect resp.status == 503
125} -run
126
127# Restore the frontend's CRL
128shell {
129 printf "set ssl crl-file ${testdir}/interCA2_crl_empty.pem <<\n$(cat ${testdir}/interCA2_crl_empty.pem)\n\n" | socat "${tmpdir}/h1/stats" -
130 echo "commit ssl crl-file ${testdir}/interCA2_crl_empty.pem" | socat "${tmpdir}/h1/stats" -
131}
132
133# Change the backend's CRL file to one in which the frontend's certificate is revoked
134shell {
135 printf "set ssl crl-file ${testdir}/interCA1_crl_empty.pem <<\n$(cat ${testdir}/interCA1_crl.pem)\n\n" | socat "${tmpdir}/h1/stats" -
136 echo "commit ssl crl-file ${testdir}/interCA1_crl_empty.pem" | socat "${tmpdir}/h1/stats" -
137}
138
139# This connection should fail, the client's certificate is revoked in the newly updated CRL file
140client c1 -connect ${h1_clearlst_sock} {
141 txreq
142 rxresp
143 expect resp.status == 200
144 # Revoked certificate
145 expect resp.http.X-SSL-Client-Verify == 23
146} -run