blob: 2123fb030c508ad77d769233899e51f2141a8c3a [file] [log] [blame]
Remi Tricot-Le Bretonefcc5b22021-03-29 11:55:40 +02001#REGTEST_TYPE=devel
2
3# This test uses the "new ssl ca-file" and "del ssl ca-file" commands to create
4# a new CA file or delete an unused CA file.
5#
6# It requires socat to upload the CA file.
7#
8# If this test does not work anymore:
9# - Check that you have socat
10
11varnishtest "Test the 'new ssl ca-file' and 'del ssl ca-file' commands of the CLI"
Tim Duesterhus5efc48d2021-06-11 19:56:15 +020012feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev0)'"
Tim Duesterhusc9570482021-06-11 19:56:16 +020013feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'"
Tim Duesterhus4ee192f2021-06-11 19:56:17 +020014feature cmd "command -v socat"
Remi Tricot-Le Bretonefcc5b22021-03-29 11:55:40 +020015feature ignore_unknown_macro
16
17server s1 -repeat 2 {
18 rxreq
19 txresp
20} -start
21
22haproxy h1 -conf {
23 global
24 tune.ssl.default-dh-param 2048
Marcin Deranek310a2602021-07-13 19:04:24 +020025 tune.ssl.capture-buffer-size 1
Remi Tricot-Le Bretonefcc5b22021-03-29 11:55:40 +020026 stats socket "${tmpdir}/h1/stats" level admin
27 crt-base ${testdir}
28
29 defaults
30 mode http
31 option httplog
Willy Tarreauf6739232021-11-18 17:46:22 +010032 retries 0
Remi Tricot-Le Bretonefcc5b22021-03-29 11:55:40 +020033 log stderr local0 debug err
34 option logasap
Willy Tarreauf6739232021-11-18 17:46:22 +010035 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
36 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
37 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Remi Tricot-Le Bretonefcc5b22021-03-29 11:55:40 +020038
39 listen clear-lst
40 bind "fd@${clearlst}"
41 balance roundrobin
42 use_backend with_ca_be if { path /with-ca }
43 default_backend default_be
44
45 backend default_be
46 server s1 "${tmpdir}/ssl.sock" ssl verify none crt ${testdir}/set_cafile_client.pem sni str(www.test1.com)
47
48 backend with_ca_be
49 server s1 "${tmpdir}/ssl.sock" ssl verify none crt ${testdir}/set_cafile_client.pem sni str(with-ca.com)
50
51 listen ssl-lst
52 bind "${tmpdir}/ssl.sock" ssl strict-sni crt-list ${testdir}/localhost.crt-list ca-verify-file ${testdir}/set_cafile_rootCA.crt ca-file ${testdir}/set_cafile_interCA2.crt verify required crt-ignore-err all
53 http-response add-header X-SSL-Client-Verify %[ssl_c_verify]
54 server s1 ${s1_addr}:${s1_port}
55} -start
56
57# Request using the default backend and the www.test1.com sni
58client c1 -connect ${h1_clearlst_sock} {
59 txreq
60 rxresp
61 expect resp.status == 200
62 # The CA file known by the frontend does not allow to verify the client's certificate
Ilya Shipitsinfc112662021-12-04 14:32:23 +050063 expect resp.http.X-SSL-Client-Verify ~ "20|21"
Remi Tricot-Le Bretonefcc5b22021-03-29 11:55:40 +020064} -run
65
66# This connection should fail because the with-ca.com sni is not mentioned in the crt-list yet.
67client c1 -connect ${h1_clearlst_sock} {
68 txreq -url "/with-ca"
69 rxresp
70 expect resp.status == 503
71} -run
72
73# Create a new unlinked CA file
74haproxy h1 -cli {
75 send "new ssl ca-file new_cafile.crt"
76 expect ~ "New CA file created 'new_cafile.crt'!"
77}
78
79shell {
80 printf "set ssl ca-file new_cafile.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n\n" | socat "${tmpdir}/h1/stats" -
81 echo "commit ssl ca-file new_cafile.crt" | socat "${tmpdir}/h1/stats" -
82}
83
William Lallemand62c0b992022-07-29 17:50:58 +020084# Remove the unliked CA file and create a new one with the "add ssl ca-file method"
85
86haproxy h1 -cli {
87 send "del ssl ca-file new_cafile.crt"
88 expect ~ "CA file 'new_cafile.crt' deleted!"
89
90 send "new ssl ca-file new_cafile.crt"
91 expect ~ "New CA file created 'new_cafile.crt'!"
92}
93
94shell {
95 printf "add ssl ca-file new_cafile.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n\n" | socat "${tmpdir}/h1/stats" -
96 echo "commit ssl ca-file new_cafile.crt" | socat "${tmpdir}/h1/stats" -
97}
98
99shell {
100 printf "set ssl ca-file new_cafile.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n\n" | socat "${tmpdir}/h1/stats" -
101 echo "commit ssl ca-file new_cafile.crt" | socat "${tmpdir}/h1/stats" -
102}
103
Remi Tricot-Le Bretonefcc5b22021-03-29 11:55:40 +0200104haproxy h1 -cli {
105 send "show ssl ca-file"
106 expect ~ ".*new_cafile.crt - 1 certificate.*"
107
108 send "show ssl ca-file new_cafile.crt"
109 expect ~ ".*SHA1 FingerPrint: 4FFF535278883264693CEA72C4FAD13F995D0098"
110}
111
112# The new CA file is still not linked anywhere so the request should fail.
113client c1 -connect ${h1_clearlst_sock} {
114 txreq -url "/with-ca"
115 rxresp
116 expect resp.status == 503
117} -run
118
119# Add a new certificate that will use the new CA file
120shell {
121 echo "new ssl cert ${testdir}/set_cafile_server.pem" | socat "${tmpdir}/h1/stats" -
122 printf "set ssl cert ${testdir}/set_cafile_server.pem <<\n$(cat ${testdir}/set_cafile_server.pem)\n\n" | socat "${tmpdir}/h1/stats" -
123 echo "commit ssl cert ${testdir}/set_cafile_server.pem" | socat "${tmpdir}/h1/stats" -
124}
125
126# Create a new crt-list line that will use the new CA file
127shell {
128 printf "add ssl crt-list ${testdir}/localhost.crt-list <<\n${testdir}/set_cafile_server.pem [ca-file new_cafile.crt] with-ca.com\n\n" | socat "${tmpdir}/h1/stats" -
129}
130
131client c1 -connect ${h1_clearlst_sock} {
132 txreq -url "/with-ca"
133 rxresp
134 expect resp.status == 200
135 # Thanks to the newly added CA file, the client's certificate can be verified
136 expect resp.http.X-SSL-Client-Verify == 0
137} -run
138
139# Delete the newly added crt-list line and CA file
140haproxy h1 -cli {
141 send "del ssl crt-list ${testdir}/localhost.crt-list ${testdir}/set_cafile_server.pem"
142 expect ~ "Entry '${testdir}/set_cafile_server.pem' deleted in crtlist '${testdir}/localhost.crt-list'!"
143
144 send "del ssl ca-file new_cafile.crt"
145 expect ~ "CA file 'new_cafile.crt' deleted!"
146
147 send "show ssl ca-file"
148 expect !~ "new_cafile.crt"
149}
150
151# The connection should now fail since the crt-list line was deleted
152client c1 -connect ${h1_clearlst_sock} {
153 txreq -url "/with-ca"
154 rxresp
155 expect resp.status == 503
156} -run
157