blob: 391a29b94875c492dbfa5349d91d2d28addd5e3d [file] [log] [blame]
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +01001#REGTEST_TYPE=devel
2
3# This reg-test uses the "set ssl cert" command to update a backend certificate over the CLI.
4# It requires socat to upload the certificate
5
6varnishtest "Test the 'set ssl cert' feature of the CLI"
7#REQUIRE_VERSION=2.4
8#REQUIRE_OPTIONS=OPENSSL
9#REQUIRE_BINARIES=socat
10feature ignore_unknown_macro
11
12server s1 -repeat 4 {
13 rxreq
14 txresp
15} -start
16
17haproxy h1 -conf {
18 global
19 tune.ssl.default-dh-param 2048
20 tune.ssl.capture-cipherlist-size 1
21 stats socket "${tmpdir}/h1/stats" level admin
22
23 defaults
24 mode http
25 option httplog
26 ${no-htx} option http-use-htx
27 log stderr local0 debug err
28 option logasap
29 timeout connect 100ms
30 timeout client 1s
31 timeout server 1s
32
33 listen clear-lst
34 bind "fd@${clearlst}"
35 retries 0 # 2nd SSL connection must fail so skip the retry
36 server s1 "${tmpdir}/ssl.sock" ssl verify none crt ${testdir}/client1.pem
37
38 listen ssl-lst
39 # crt: certificate of the server
40 # ca-file: CA used for client authentication request
41 # crl-file: revocation list for client auth: the client1 certificate is revoked
42 bind "${tmpdir}/ssl.sock" ssl crt ${testdir}/common.pem ca-file ${testdir}/ca-auth.crt verify optional crt-ignore-err all crl-file ${testdir}/crl-auth.pem
43
44 acl cert_expired ssl_c_verify 10
45 acl cert_revoked ssl_c_verify 23
46 acl cert_ok ssl_c_verify 0
47
48 http-response add-header X-SSL Ok if cert_ok
49 http-response add-header X-SSL Expired if cert_expired
50 http-response add-header X-SSL Revoked if cert_revoked
51
52 server s1 ${s1_addr}:${s1_port}
53} -start
54
55client c1 -connect ${h1_clearlst_sock} {
56 txreq
57 rxresp
58 expect resp.status == 200
59 expect resp.http.x-ssl == "Ok"
60} -run
61
William Lallemand7e696372021-01-28 14:59:19 +010062haproxy h1 -cli {
63 send "show ssl cert ${testdir}/client1.pem"
64 expect ~ ".*SHA1 FingerPrint: D9C3BAE37EA5A7EDB7B3C9BDD4DCB2FE58A412E4"
65}
66
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010067# Replace certificate with an expired one
68shell {
69 printf "set ssl cert ${testdir}/client1.pem <<\n$(cat ${testdir}/client2_expired.pem)\n\n" | socat "${tmpdir}/h1/stats" -
70 echo "commit ssl cert ${testdir}/client1.pem" | socat "${tmpdir}/h1/stats" -
71}
72
William Lallemand7e696372021-01-28 14:59:19 +010073haproxy h1 -cli {
74 send "show ssl cert ${testdir}/client1.pem"
75 expect ~ ".*SHA1 FingerPrint: C625EB01A0A660294B9D7F44C5CEEE5AFC495BE4"
76}
77
78
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010079# The updated client certificate is an expired one so this request should fail
80client c1 -connect ${h1_clearlst_sock} {
81 txreq
82 rxresp
83 expect resp.status == 200
84 expect resp.http.x-ssl == "Expired"
85} -run
86
87# Replace certificate with a revoked one
88shell {
89 printf "set ssl cert ${testdir}/client1.pem <<\n$(cat ${testdir}/client3_revoked.pem)\n\n" | socat "${tmpdir}/h1/stats" -
90 echo "commit ssl cert ${testdir}/client1.pem" | socat "${tmpdir}/h1/stats" -
91}
92
William Lallemand7e696372021-01-28 14:59:19 +010093haproxy h1 -cli {
94 send "show ssl cert ${testdir}/client1.pem"
95 expect ~ ".*SHA1 FingerPrint: 992386628A40C9D49C89BAC0058B5D45D8575151"
96}
97
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010098# The updated client certificate is a revoked one so this request should fail
99client c1 -connect ${h1_clearlst_sock} {
100 txreq
101 rxresp
102 expect resp.status == 200
103 expect resp.http.x-ssl == "Revoked"
104} -run
105