blob: b6cbc2064e557ac0200f02e6202f0f5be5a2b5d6 [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
Remi Tricot-Le Bretonefcc5b22021-03-29 11:55:40 +020032 log stderr local0 debug err
33 option logasap
34 timeout connect 100ms
35 timeout client 1s
36 timeout server 1s
37
38 listen clear-lst
39 bind "fd@${clearlst}"
40 balance roundrobin
41 use_backend with_ca_be if { path /with-ca }
42 default_backend default_be
43
44 backend default_be
45 server s1 "${tmpdir}/ssl.sock" ssl verify none crt ${testdir}/set_cafile_client.pem sni str(www.test1.com)
46
47 backend with_ca_be
48 server s1 "${tmpdir}/ssl.sock" ssl verify none crt ${testdir}/set_cafile_client.pem sni str(with-ca.com)
49
50 listen ssl-lst
51 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
52 http-response add-header X-SSL-Client-Verify %[ssl_c_verify]
53 server s1 ${s1_addr}:${s1_port}
54} -start
55
56# Request using the default backend and the www.test1.com sni
57client c1 -connect ${h1_clearlst_sock} {
58 txreq
59 rxresp
60 expect resp.status == 200
61 # The CA file known by the frontend does not allow to verify the client's certificate
62 expect resp.http.X-SSL-Client-Verify == 21
63} -run
64
65# This connection should fail because the with-ca.com sni is not mentioned in the crt-list yet.
66client c1 -connect ${h1_clearlst_sock} {
67 txreq -url "/with-ca"
68 rxresp
69 expect resp.status == 503
70} -run
71
72# Create a new unlinked CA file
73haproxy h1 -cli {
74 send "new ssl ca-file new_cafile.crt"
75 expect ~ "New CA file created 'new_cafile.crt'!"
76}
77
78shell {
79 printf "set ssl ca-file new_cafile.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n\n" | socat "${tmpdir}/h1/stats" -
80 echo "commit ssl ca-file new_cafile.crt" | socat "${tmpdir}/h1/stats" -
81}
82
83haproxy h1 -cli {
84 send "show ssl ca-file"
85 expect ~ ".*new_cafile.crt - 1 certificate.*"
86
87 send "show ssl ca-file new_cafile.crt"
88 expect ~ ".*SHA1 FingerPrint: 4FFF535278883264693CEA72C4FAD13F995D0098"
89}
90
91# The new CA file is still not linked anywhere so the request should fail.
92client c1 -connect ${h1_clearlst_sock} {
93 txreq -url "/with-ca"
94 rxresp
95 expect resp.status == 503
96} -run
97
98# Add a new certificate that will use the new CA file
99shell {
100 echo "new ssl cert ${testdir}/set_cafile_server.pem" | socat "${tmpdir}/h1/stats" -
101 printf "set ssl cert ${testdir}/set_cafile_server.pem <<\n$(cat ${testdir}/set_cafile_server.pem)\n\n" | socat "${tmpdir}/h1/stats" -
102 echo "commit ssl cert ${testdir}/set_cafile_server.pem" | socat "${tmpdir}/h1/stats" -
103}
104
105# Create a new crt-list line that will use the new CA file
106shell {
107 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" -
108}
109
110client c1 -connect ${h1_clearlst_sock} {
111 txreq -url "/with-ca"
112 rxresp
113 expect resp.status == 200
114 # Thanks to the newly added CA file, the client's certificate can be verified
115 expect resp.http.X-SSL-Client-Verify == 0
116} -run
117
118# Delete the newly added crt-list line and CA file
119haproxy h1 -cli {
120 send "del ssl crt-list ${testdir}/localhost.crt-list ${testdir}/set_cafile_server.pem"
121 expect ~ "Entry '${testdir}/set_cafile_server.pem' deleted in crtlist '${testdir}/localhost.crt-list'!"
122
123 send "del ssl ca-file new_cafile.crt"
124 expect ~ "CA file 'new_cafile.crt' deleted!"
125
126 send "show ssl ca-file"
127 expect !~ "new_cafile.crt"
128}
129
130# The connection should now fail since the crt-list line was deleted
131client c1 -connect ${h1_clearlst_sock} {
132 txreq -url "/with-ca"
133 rxresp
134 expect resp.status == 503
135} -run
136