blob: 801ba607a20ccd32a927371dabc3b7594ea1d8f2 [file] [log] [blame]
Remi Tricot-Le Breton17b73842022-02-11 12:04:46 +01001#REGTEST_TYPE=devel
2
3# This reg-tests checks that the DH-related mechanisms works properly.
4# When no DH is specified, either directly in the server's PEM or through a
5# ssl-dh-param-file global option, in case of DHE negotiation, the hard coded
6# DH parameters included in the sources will be used. We will use DH parameters
7# of the same size as the server's RSA or DSA key.
8# This test has three distinct HAProxy instances, one with no DH-related option
9# used, one with the tune.ssl.default-dh-param global parameter set, and one
10# with an ssl-dh-param-file global option.
11# We use "openssl s_client" calls in order to check the size of the "Server
12# Temp Key" (which will be the same as the DH parameters in case a DHE cipher
13# is used).
14#
15# The main goal of this test was to check that the newly added OpenSSLv3
16# specific DH code worked as before, since it needed to be created in order to
17# stop using deprecated APIs.
18
19varnishtest "Test the DH related SSL options"
20feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'"
21feature cmd "command -v openssl && command -v grep && command -v socat"
22feature ignore_unknown_macro
23
24server s1 -repeat 8 {
25 rxreq
26 txresp
27} -start
28
29
30haproxy h1 -conf {
31 global
32 stats socket "${tmpdir}/h1/stats" level admin
33
34 defaults
35 mode http
36 option httpslog
37 log stderr local0 debug err
38 option logasap
39 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
40 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
41 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
42 retries 0
43
44 frontend clear-fe
45 bind "fd@${clearlst}"
46 use_backend gen_cert_be if { path /gencert }
47 default_backend dflt_be
48
49 backend dflt_be
50 server s1 "${tmpdir}/ssl_dflt.sock" ssl verify none ssl-max-ver TLSv1.2
51
52 backend gen_cert_be
53 server s1 "${tmpdir}/ssl_dflt_gencert.sock" ssl verify none ssl-max-ver TLSv1.2
54
55 listen ssl-dflt-lst
56 bind "${tmpdir}/ssl_dflt.sock" ssl crt ${testdir}/common.pem ca-file ${testdir}/set_cafile_rootCA.crt verify optional ciphers "DHE-RSA-AES256-GCM-SHA384" ssl-max-ver TLSv1.2
57 http-response set-header x-ssl-cipher %[ssl_fc_cipher]
58 server s1 ${s1_addr}:${s1_port}
59
60 listen ssl-dflt-gencert-lst
61 bind "${tmpdir}/ssl_dflt_gencert.sock" ssl generate-certificates crt ${testdir}/common.pem ca-file ${testdir}/set_cafile_rootCA.crt ca-sign-file ${testdir}/generate_certificates/gen_cert_ca.pem verify optional ciphers "DHE-RSA-AES256-GCM-SHA384" ssl-max-ver TLSv1.2
62 http-response set-header x-ssl-cipher %[ssl_fc_cipher]
63 server s1 ${s1_addr}:${s1_port}
64} -start
65
66haproxy h2 -conf {
67 global
68 stats socket "${tmpdir}/h2/stats" level admin
69
70 global
71 tune.ssl.default-dh-param 4096
72
73 defaults
74 mode http
75 option httpslog
76 log stderr local0 debug err
77 option logasap
78 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
79 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
80 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
81 retries 0
82
83 listen clear-lst
84 bind "fd@${clearlst_dfltdh}"
85 server s1 "${tmpdir}/ssl_dfltdh.sock" ssl verify none ssl-max-ver TLSv1.2
86
87 listen ssl-4096dh-dflt-lst
88 bind "${tmpdir}/ssl_dfltdh.sock" ssl crt ${testdir}/common.pem ca-file ${testdir}/set_cafile_rootCA.crt verify optional ciphers "DHE-RSA-AES256-GCM-SHA384" ssl-max-ver TLSv1.2
89 http-response set-header x-ssl-cipher %[ssl_fc_cipher]
90 server s1 ${s1_addr}:${s1_port}
91} -start
92
93haproxy h3 -conf {
94 global
95 stats socket "${tmpdir}/h3/stats" level admin
96
97 global
98 ssl-dh-param-file ${testdir}/common.4096.dh
99
100 defaults
101 mode http
102 option httpslog
103 log stderr local0 debug err
104 option logasap
105 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
106 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
107 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
108 retries 0
109
110 listen clear-lst
111 bind "fd@${clearlst_dhfile}"
112 server s1 "${tmpdir}/ssl_dhfile.sock" ssl verify none ssl-max-ver TLSv1.2
113
114 listen ssl-dhfile-lst
115 bind "${tmpdir}/ssl_dhfile.sock" ssl crt ${testdir}/common.pem ca-file ${testdir}/set_cafile_rootCA.crt verify optional ciphers "DHE-RSA-AES256-GCM-SHA384" ssl-max-ver TLSv1.2
116 http-response set-header x-ssl-cipher %[ssl_fc_cipher]
117 server s1 ${s1_addr}:${s1_port}
118} -start
119
120#
121# Check that all the SSL backend <-> SSL frontend connections work
122#
123client c1 -connect ${h1_clearlst_sock} {
124 txreq
125 rxresp
126 expect resp.status == 200
127 expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384"
128} -run
129
130client c2 -connect ${h2_clearlst_dfltdh_sock} {
131 txreq
132 rxresp
133 expect resp.status == 200
134 expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384"
135} -run
136
137client c3 -connect ${h3_clearlst_dhfile_sock} {
138 txreq
139 rxresp
140 expect resp.status == 200
141 expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384"
142} -run
143
144client c4 -connect ${h1_clearlst_sock} {
145 txreq -url "/gencert"
146 rxresp
147 expect resp.status == 200
148 expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384"
149} -run
150
151
152#
153# Check the size of the DH key
154#
155shell {
156 echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dflt.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 2048 bits"
157}
158
159# On the second HAProxy instance, even if default-dh-param is set to 4096, this
160# value is only considered as a maximum DH key length and we will always try to
161# match the server's certificate key length in our DHE key exchange (2048 bits
162# in the case of common.pem).
163shell {
164 echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dfltdh.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 2048 bits"
165}
166
167shell {
168 echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dhfile.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits"
169}
170
171shell {
172 echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dflt_gencert.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 2048 bits"
173}
174
175
176
177#
178# Add a custom DH to the server's PEM certificate
179#
180shell {
181 printf "set ssl cert ${testdir}/common.pem <<\n$(cat ${testdir}/common.pem)\n$(cat ${testdir}/common.4096.dh)\n\n" | socat "${tmpdir}/h1/stats" -
182 echo "commit ssl cert ${testdir}/common.pem" | socat "${tmpdir}/h1/stats" -
183
184 printf "set ssl cert ${testdir}/common.pem <<\n$(cat ${testdir}/common.pem)\n$(cat ${testdir}/common.4096.dh)\n\n" | socat "${tmpdir}/h2/stats" -
185 echo "commit ssl cert ${testdir}/common.pem" | socat "${tmpdir}/h2/stats" -
186
187 printf "set ssl cert ${testdir}/common.pem <<\n$(cat ${testdir}/common.pem)\n$(cat ${testdir}/common.4096.dh)\n\n" | socat "${tmpdir}/h3/stats" -
188 echo "commit ssl cert ${testdir}/common.pem" | socat "${tmpdir}/h3/stats" -
189}
190
191
192#
193# Check that all the SSL backend <-> SSL frontend connections still work
194#
195client c5 -connect ${h1_clearlst_sock} {
196 txreq
197 rxresp
198 expect resp.status == 200
199 expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384"
200} -run
201
202client c6 -connect ${h2_clearlst_dfltdh_sock} {
203 txreq
204 rxresp
205 expect resp.status == 200
206 expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384"
207} -run
208
209client c7 -connect ${h3_clearlst_dhfile_sock} {
210 txreq
211 rxresp
212 expect resp.status == 200
213 expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384"
214} -run
215
216client c8 -connect ${h1_clearlst_sock} {
217 txreq -url "/gencert"
218 rxresp
219 expect resp.status == 200
220 expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384"
221} -run
222
223
224
225#
226# Check the new size of the DH key
227#
228shell {
229 echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dflt.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits"
230}
231
232shell {
233 echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dfltdh.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits"
234}
235
236shell {
237 echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dhfile.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits"
238}
239
240shell {
241 echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dflt_gencert.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits"
242}