blob: 0d652d4a08014e5bdb57115e0e04e1a6dea186bc [file] [log] [blame]
William Lallemand4f59c672021-07-29 16:00:24 +02001#REGTEST_TYPE=broken
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +02002
3# This reg-test checks that the connection and SSL sample fetches related to
4# errors are functioning properly. It also tests the proper behaviour of the
William Lallemand56f1f752021-08-02 10:25:30 +02005# default HTTPS log format and of the log-error-via-logformat option which enables
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +02006# or disables the output of a special error message in case of connection
7# failure (otherwise a line following the configured log-format is output).
8#
9# It works by sending request through three different paths, one using a custom
10# log-format line that contains the connection error and SSL handshake error
11# sample fetches, one using the default HTTPS log-format and one using the
12# legacy error log format.
13#
14# The output log lines are caught by syslog blocks (one for each path) and
15# compared to an expected format.
16# Since the syslog is not by design synchronized with the Varnish clients and
17# servers, synchronization is achieved through barriers, which ensure that
18# syslog messages arrive in the right order.
19#
20# In order to ensure that the log line raised in case of connection error if
William Lallemand56f1f752021-08-02 10:25:30 +020021# the log-error-via-logformat option is disabled still follows the
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +020022# log-separate-error option, the log lines raised by the https_fmt_lst listener
23# will be sent to two separate syslog servers.
24#
25
26varnishtest "Test the connection and SSL error fetches."
27feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev2)'"
28feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'"
29feature cmd "command -v socat"
30feature ignore_unknown_macro
31
32server s1 -repeat 3 {
33 rxreq
34 txresp
35} -start
36
37barrier b1 cond 4 -cyclic
38
39
40syslog Slg_cust_fmt -level info {
41 recv
Remi Tricot-Le Breton74f6ab62021-08-19 18:06:30 +020042 expect ~ ".*conn_status:\"0:Success\" hsk_err:\"0:-\" CN=\"/C=FR/O=HAProxy Technologies/CN=Client\",serial=1007,hash=063DCC2E6A9159E66994B325D6D2EF3D17A75B6F"
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +020043
44 barrier b1 sync
45
46 recv
Remi Tricot-Le Breton74f6ab62021-08-19 18:06:30 +020047 expect ~ ".*conn_status:\"30:SSL client CA chain cannot be verified\" hsk_err:\"337100934:error:1417C086:SSL routines:tls_process_client_certificate:certificate verify failed\" CN=\"/C=FR/O=HAProxy Technologies/CN=Client\",serial=1007,hash=063DCC2E6A9159E66994B325D6D2EF3D17A75B6F"
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +020048
49 barrier b1 sync
50
51 recv
Remi Tricot-Le Breton74f6ab62021-08-19 18:06:30 +020052 expect ~ ".*conn_status:\"31:SSL client certificate not trusted\" hsk_err:\"337100934:error:1417C086:SSL routines:tls_process_client_certificate:certificate verify failed\" CN=\"/C=FR/O=HAProxy Technologies/CN=Client\",serial=1007,hash=063DCC2E6A9159E66994B325D6D2EF3D17A75B6F"
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +020053
54 barrier b1 sync
55
Remi Tricot-Le Breton74f6ab62021-08-19 18:06:30 +020056 # In case of an error occuring before the certificate verification process,
57 # the client certificate chain is never parsed and verified so we can't
58 # have information about the client's certificate.
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +020059 recv
Remi Tricot-Le Breton74f6ab62021-08-19 18:06:30 +020060 expect ~ ".*conn_status:\"34:SSL handshake failure\" hsk_err:\"337678529:error:142090C1:SSL routines:tls_early_post_process_client_hello:no shared cipher\" CN=\"\",serial=-,hash=-"
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +020061} -start
62
63syslog Slg_https_fmt -level info {
64 recv
65 expect ~ ".*https_logfmt_ssl_lst~ https_logfmt_ssl_lst/s1.*0/0000000000000000/0/0 TLSv1.3/TLS_AES_256_GCM_SHA384"
66
67 barrier b1 sync
68} -start
69
70syslog Slg_https_fmt_err -level info {
71 recv
72 expect ~ ".*https_logfmt_ssl_lst~ https_logfmt_ssl_lst/<NOSRV>.*30/000000001417C086/0/2 TLSv1.3/TLS_AES_256_GCM_SHA384"
73
74 barrier b1 sync
75
76 recv
77 expect ~ ".*https_logfmt_ssl_lst~ https_logfmt_ssl_lst/<NOSRV>.*31/000000001417C086/20/0 TLSv1.3/TLS_AES_256_GCM_SHA384"
78
79 barrier b1 sync
80
81 recv
82 expect ~ ".*https_logfmt_ssl_lst~ https_logfmt_ssl_lst/<NOSRV>.*34/00000000142090C1/0/0 TLSv1.3/\\(NONE\\)"
83} -start
84
85syslog Slg_logconnerror -level info {
86 recv
87 expect ~ ".*logconnerror_ssl_lst~ logconnerror_ssl_lst/s1"
88
89 barrier b1 sync
90
91 recv
92 expect ~ ".*logconnerror_ssl_lst/1: SSL client CA chain cannot be verified"
93
94 barrier b1 sync
95
96 recv
97 expect ~ ".*logconnerror_ssl_lst/1: SSL client certificate not trusted"
98
99 barrier b1 sync
100
101 recv
102 expect ~ ".*logconnerror_ssl_lst/1: SSL handshake failure"
103} -start
104
105
106haproxy h1 -conf {
107 global
108 tune.ssl.default-dh-param 2048
109 tune.ssl.capture-cipherlist-size 1
110 stats socket "${tmpdir}/h1/stats" level admin
111
112 defaults
113 timeout connect 100ms
114 timeout client 1s
115 timeout server 1s
116 retries 0
117
118 listen clear_lst
119 bind "fd@${clearlst}"
120 default-server ssl crt ${testdir}/set_cafile_client.pem ca-file ${testdir}/set_cafile_interCA2.crt verify none no-ssl-reuse
121
122 balance roundrobin
123 server cust_fmt "${tmpdir}/cust_logfmt_ssl.sock"
124 server https_fmt "${tmpdir}/https_logfmt_ssl.sock"
125 server logconnerror "${tmpdir}/logconnerror_ssl.sock"
126
127
128 listen clear_wrong_ciphers_lst
129 bind "fd@${wrongcipherslst}"
130 default-server ssl crt ${testdir}/set_cafile_client.pem ca-file ${testdir}/set_cafile_interCA2.crt verify none no-ssl-reuse ciphersuites "TLS_AES_128_GCM_SHA256"
131
132 balance roundrobin
133 server cust_fmt "${tmpdir}/cust_logfmt_ssl.sock"
134 server https_fmt "${tmpdir}/https_logfmt_ssl.sock"
135 server logconnerror "${tmpdir}/logconnerror_ssl.sock"
136
137
138 listen cust_logfmt_ssl_lst
139 log ${Slg_cust_fmt_addr}:${Slg_cust_fmt_port} local0
William Lallemand56f1f752021-08-02 10:25:30 +0200140 option log-error-via-logformat
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +0200141 mode http
Remi Tricot-Le Breton74f6ab62021-08-19 18:06:30 +0200142 log-format "conn_status:\"%[fc_conn_err]:%[fc_conn_err_str]\" hsk_err:\"%[ssl_fc_hsk_err]:%[ssl_fc_hsk_err_str]\" CN=%{+Q}[ssl_c_s_dn],serial=%[ssl_c_serial,hex],hash=%[ssl_c_sha1,hex]"
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +0200143 bind "${tmpdir}/cust_logfmt_ssl.sock" ssl crt ${testdir}/set_cafile_server.pem ca-verify-file ${testdir}/set_cafile_rootCA.crt ca-file ${testdir}/set_cafile_interCA1.crt verify required ciphersuites "TLS_AES_256_GCM_SHA384"
144 server s1 ${s1_addr}:${s1_port}
145
146 listen https_logfmt_ssl_lst
147 log ${Slg_https_fmt_addr}:${Slg_https_fmt_port} local0 info
148 log ${Slg_https_fmt_err_addr}:${Slg_https_fmt_err_port} local0 err info
William Lallemand56f1f752021-08-02 10:25:30 +0200149 option log-error-via-logformat
Remi Tricot-Le Breton54f63832021-07-29 09:45:54 +0200150 option log-separate-errors
151 mode http
152 option httpslog
153 bind "${tmpdir}/https_logfmt_ssl.sock" ssl crt ${testdir}/set_cafile_server.pem ca-verify-file ${testdir}/set_cafile_rootCA.crt ca-file ${testdir}/set_cafile_interCA1.crt verify required ciphersuites "TLS_AES_256_GCM_SHA384"
154 server s1 ${s1_addr}:${s1_port}
155
156 listen logconnerror_ssl_lst
157 log ${Slg_logconnerror_addr}:${Slg_logconnerror_port} local0 info
158 mode http
159 option httplog
160 bind "${tmpdir}/logconnerror_ssl.sock" ssl crt ${testdir}/set_cafile_server.pem ca-verify-file ${testdir}/set_cafile_rootCA.crt ca-file ${testdir}/set_cafile_interCA1.crt verify required ciphersuites "TLS_AES_256_GCM_SHA384"
161 server s1 ${s1_addr}:${s1_port}
162
163} -start
164
165
166# The three following requests should all succeed
167client c1 -connect ${h1_clearlst_sock} {
168 txreq
169 rxresp
170 expect resp.status == 200
171} -run
172
173client c2 -connect ${h1_clearlst_sock} {
174 txreq
175 rxresp
176 expect resp.status == 200
177} -run
178
179client c3 -connect ${h1_clearlst_sock} {
180 txreq
181 rxresp
182 expect resp.status == 200
183} -run
184
185
186barrier b1 sync
187
188
189# Change the root CA in the frontends
190shell {
191 printf "set ssl ca-file ${testdir}/set_cafile_rootCA.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n\n" | socat "${tmpdir}/h1/stats" -
192 echo "commit ssl ca-file ${testdir}/set_cafile_rootCA.crt" | socat "${tmpdir}/h1/stats" -
193}
194
195client c4 -connect ${h1_clearlst_sock} {
196 txreq
197} -run
198
199client c5 -connect ${h1_clearlst_sock} {
200 txreq
201} -run
202
203client c6 -connect ${h1_clearlst_sock} {
204 txreq
205} -run
206
207barrier b1 sync
208
209
210
211# Restore the root CA
212shell {
213 printf "set ssl ca-file ${testdir}/set_cafile_rootCA.crt <<\n$(cat ${testdir}/set_cafile_rootCA.crt)\n\n" | socat "${tmpdir}/h1/stats" -
214 echo "commit ssl ca-file ${testdir}/set_cafile_rootCA.crt" | socat "${tmpdir}/h1/stats" -
215}
216
217# Change the intermediate CA in the frontends
218shell {
219 printf "set ssl ca-file ${testdir}/set_cafile_interCA1.crt <<\n$(cat ${testdir}/set_cafile_interCA2.crt)\n\n" | socat "${tmpdir}/h1/stats" -
220 echo "commit ssl ca-file ${testdir}/set_cafile_interCA1.crt" | socat "${tmpdir}/h1/stats" -
221}
222
223client c7 -connect ${h1_clearlst_sock} {
224 txreq
225} -run
226
227client c8 -connect ${h1_clearlst_sock} {
228 txreq
229} -run
230
231client c9 -connect ${h1_clearlst_sock} {
232 txreq
233} -run
234
235barrier b1 sync
236
237
238# Restore the intermediate CA in the frontends
239shell {
240 printf "set ssl ca-file ${testdir}/set_cafile_interCA1.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n\n" | socat "${tmpdir}/h1/stats" -
241 echo "commit ssl ca-file ${testdir}/set_cafile_interCA1.crt" | socat "${tmpdir}/h1/stats" -
242}
243
244# "No shared cipher" errors
245client c10 -connect ${h1_wrongcipherslst_sock} {
246 txreq
247} -run
248client c11 -connect ${h1_wrongcipherslst_sock} {
249 txreq
250} -run
251client c12 -connect ${h1_wrongcipherslst_sock} {
252 txreq
253} -run
254
255syslog Slg_cust_fmt -wait
256syslog Slg_https_fmt -wait
257syslog Slg_https_fmt_err -wait
258syslog Slg_logconnerror -wait