blob: bda620f4e42decfe31d13e1bf27b16be5916963e [file] [log] [blame]
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +01001#REGTEST_TYPE=devel
2
3# This reg-test uses the "set ssl ca-file" command to update a CA file over the CLI.
Remi Tricot-Le Breton2a22e162021-03-16 11:19:33 +01004# It also tests the "abort ssl ca-file" and "show ssl ca-file" commands.
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +01005#
6# It is based on two CA certificates, set_cafile_interCA1.crt and set_cafile_interCA2.crt,
7# and a client certificate that was signed with set_cafile_interCA1.crt (set_cafile_client.pem)
8# and a server certificate that was signed with set_cafile_interCA2.crt (set_cafile_server.pem).
9# The CA files used by the client and the server will be updated through the CLI until a
10# proper connection can be established between them.
11#
12# It requires socat to upload the certificate
13#
14# If this test does not work anymore:
15# - Check that you have socat
16
17varnishtest "Test the 'set ssl ca-file' feature of the CLI"
Tim Duesterhus5efc48d2021-06-11 19:56:15 +020018feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev0)'"
Tim Duesterhusc9570482021-06-11 19:56:16 +020019feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'"
Tim Duesterhus4ee192f2021-06-11 19:56:17 +020020feature cmd "command -v socat"
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +010021feature ignore_unknown_macro
22
Remi Tricot-Le Bretond5fd09d2021-03-11 10:22:52 +010023server s1 -repeat 4 {
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +010024 rxreq
25 txresp
26} -start
27
28haproxy h1 -conf {
29 global
30 tune.ssl.default-dh-param 2048
Marcin Deranek310a2602021-07-13 19:04:24 +020031 tune.ssl.capture-buffer-size 1
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +010032 stats socket "${tmpdir}/h1/stats" level admin
33
34 defaults
35 mode http
36 option httplog
Willy Tarreauf6739232021-11-18 17:46:22 +010037 retries 0
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +010038 log stderr local0 debug err
39 option logasap
Willy Tarreauf6739232021-11-18 17:46:22 +010040 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
41 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
42 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +010043
44 listen clear-lst
45 bind "fd@${clearlst}"
William Lallemandae6547f2022-06-20 18:01:30 +020046 # dummy bind used to test a change when the same crt is used as server and bind
47 bind "fd@${foobarlst}" ssl crt ${testdir}/set_cafile_client.pem ca-file ${testdir}/set_cafile_interCA1.crt verify none
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +010048 server s1 "${tmpdir}/ssl.sock" ssl crt ${testdir}/set_cafile_client.pem ca-file ${testdir}/set_cafile_interCA1.crt verify none
49
50 listen clear-verified-lst
51 bind "fd@${clearverifiedlst}"
52 server s1 "${tmpdir}/ssl.sock" ssl crt ${testdir}/set_cafile_client.pem ca-file ${testdir}/set_cafile_interCA1.crt verify required
53
54 listen ssl-lst
55 # crt: certificate of the server
56 # ca-file: CA used for client authentication request
57 bind "${tmpdir}/ssl.sock" ssl crt ${testdir}/set_cafile_server.pem ca-verify-file ${testdir}/set_cafile_rootCA.crt ca-file ${testdir}/set_cafile_interCA2.crt verify required crt-ignore-err all
58 http-response add-header X-SSL-Client-Verify %[ssl_c_verify]
59 server s1 ${s1_addr}:${s1_port}
60} -start
61
62
Remi Tricot-Le Breton2a22e162021-03-16 11:19:33 +010063# Test the "show ssl ca-file" command
64haproxy h1 -cli {
65 send "show ssl ca-file"
66 expect ~ ".*${testdir}/set_cafile_interCA1.crt - 1 certificate.*"
67 send "show ssl ca-file"
68 expect ~ ".*${testdir}/set_cafile_interCA2.crt - 1 certificate.*"
69
70 send "show ssl ca-file ${testdir}/set_cafile_interCA2.crt"
71 expect ~ ".*SHA1 FingerPrint: 3D3D1D10AD74A8135F05A818E10E5FA91433954D"
72}
73
74
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +010075# This first connection should fail because the client's certificate was signed with the
76# set_cafile_interCA1.crt certificate which is not known by the backend.
77client c1 -connect ${h1_clearlst_sock} {
78 txreq
79 rxresp
80 expect resp.status == 200
81 # unable to verify the client certificate
Ilya Shipitsinfc112662021-12-04 14:32:23 +050082 expect resp.http.X-SSL-Client-Verify ~ "20|21"
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +010083} -run
84
Remi Tricot-Le Bretond5fd09d2021-03-11 10:22:52 +010085# Set a new ca-file without committing it and check that the new ca-file is not taken into account
86shell {
Remi Tricot-Le Breton2a22e162021-03-16 11:19:33 +010087 printf "set ssl ca-file ${testdir}/set_cafile_interCA2.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n\n" | socat "${tmpdir}/h1/stats" -
88}
89
90# Test the "show ssl ca-file" command
91# The transaction should be mentioned in the list
92haproxy h1 -cli {
93 send "show ssl ca-file"
94 expect ~ "\\*${testdir}/set_cafile_interCA2.crt - 1 certificate.*"
95
96# The original CA file did not change
97 send "show ssl ca-file ${testdir}/set_cafile_interCA2.crt"
98 expect ~ ".*SHA1 FingerPrint: 3D3D1D10AD74A8135F05A818E10E5FA91433954D"
99
100# Only the current transaction displays a new certificate
101 send "show ssl ca-file *${testdir}/set_cafile_interCA2.crt"
102 expect ~ ".*SHA1 FingerPrint: 4FFF535278883264693CEA72C4FAD13F995D0098"
Remi Tricot-Le Bretond5fd09d2021-03-11 10:22:52 +0100103}
104
105# This connection should still fail for the same reasons as previously
106client c1 -connect ${h1_clearlst_sock} {
107 txreq
108 rxresp
109 expect resp.status == 200
110 # unable to verify the client certificate
Ilya Shipitsinfc112662021-12-04 14:32:23 +0500111 expect resp.http.X-SSL-Client-Verify ~ "20|21"
Remi Tricot-Le Bretond5fd09d2021-03-11 10:22:52 +0100112} -run
113
114haproxy h1 -cli {
Remi Tricot-Le Breton2a22e162021-03-16 11:19:33 +0100115 send "abort ssl ca-file ${testdir}/set_cafile_interCA2.crt"
116 expect ~ "Transaction aborted for certificate '${testdir}/set_cafile_interCA2.crt'!"
117 send "commit ssl ca-file ${testdir}/set_cafile_interCA2.crt"
Remi Tricot-Le Bretond5fd09d2021-03-11 10:22:52 +0100118 expect ~ "No ongoing transaction!"
119}
120
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +0100121
122# Update the bind line's ca-file in order to accept the client certificate
123shell {
124 printf "set ssl ca-file ${testdir}/set_cafile_interCA2.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n$(cat ${testdir}/set_cafile_rootCA.crt)\n\n" | socat "${tmpdir}/h1/stats" -
125 echo "commit ssl ca-file ${testdir}/set_cafile_interCA2.crt" | socat "${tmpdir}/h1/stats" -
126}
127
128
129# The backend's certificate can't be verified by the frontend because it was signed with
130# the set_cafile_interCA2.crt certificate.
131client c1 -connect ${h1_clearverifiedlst_sock} {
132 txreq
133 rxresp
134 expect resp.status == 503
135} -run
136
137
138# Update the server line's ca-file. The server certificate should now be accepted by
139# the frontend. We replace the single CA by a list of CAs that includes the correct one.
140shell {
141 printf "set ssl ca-file ${testdir}/set_cafile_interCA1.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n$(cat ${testdir}/set_cafile_interCA2.crt)\n$(cat ${testdir}/set_cafile_rootCA.crt)\n\n" | socat "${tmpdir}/h1/stats" -
142 echo "commit ssl ca-file ${testdir}/set_cafile_interCA1.crt" | socat "${tmpdir}/h1/stats" -
143}
144
Remi Tricot-Le Breton2a22e162021-03-16 11:19:33 +0100145# Test the "show ssl ca-file" with a certificate index
146haproxy h1 -cli {
147 send "show ssl ca-file"
148 expect ~ ".*${testdir}/set_cafile_interCA1.crt - 3 certificate.*"
149
150 send "show ssl ca-file ${testdir}/set_cafile_interCA1.crt:1"
151 expect ~ ".*SHA1 FingerPrint: 4FFF535278883264693CEA72C4FAD13F995D0098"
152
153 send "show ssl ca-file ${testdir}/set_cafile_interCA1.crt:2"
154 expect !~ ".*SHA1 FingerPrint: 4FFF535278883264693CEA72C4FAD13F995D0098"
155 send "show ssl ca-file ${testdir}/set_cafile_interCA1.crt:2"
156 expect ~ ".*SHA1 FingerPrint: 3D3D1D10AD74A8135F05A818E10E5FA91433954D"
157}
Remi Tricot-Le Breton2db61012021-03-05 14:42:40 +0100158
159client c1 -connect ${h1_clearverifiedlst_sock} {
160 txreq
161 rxresp
162 expect resp.status == 200
163 # there should be no error on the backend side but one on the frontend side
164 expect resp.http.X-SSL-Client-Verify == 0
165} -run