blob: 61346e07e5991043f3cb6fd06315238318ecd830 [file] [log] [blame]
William Lallemanda870a9c2021-02-01 14:37:36 +01001#REGTEST_TYPE=devel
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +01002
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
William Lallemanda870a9c2021-02-01 14:37:36 +010022 nbthread 1
23 tune.ssl.cachesize 0
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010024
25 defaults
26 mode http
27 option httplog
28 ${no-htx} option http-use-htx
29 log stderr local0 debug err
30 option logasap
31 timeout connect 100ms
32 timeout client 1s
33 timeout server 1s
34
35 listen clear-lst
36 bind "fd@${clearlst}"
37 retries 0 # 2nd SSL connection must fail so skip the retry
38 server s1 "${tmpdir}/ssl.sock" ssl verify none crt ${testdir}/client1.pem
39
40 listen ssl-lst
41 # crt: certificate of the server
42 # ca-file: CA used for client authentication request
43 # crl-file: revocation list for client auth: the client1 certificate is revoked
William Lallemanda870a9c2021-02-01 14:37:36 +010044 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 no-tls-tickets
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010045
46 acl cert_expired ssl_c_verify 10
47 acl cert_revoked ssl_c_verify 23
48 acl cert_ok ssl_c_verify 0
49
50 http-response add-header X-SSL Ok if cert_ok
51 http-response add-header X-SSL Expired if cert_expired
52 http-response add-header X-SSL Revoked if cert_revoked
William Lallemand7b794242021-01-28 16:00:22 +010053 http-response add-header x-ssl-sha1 %[ssl_c_sha1,hex]
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010054
55 server s1 ${s1_addr}:${s1_port}
56} -start
57
58client c1 -connect ${h1_clearlst_sock} {
59 txreq
60 rxresp
61 expect resp.status == 200
William Lallemand7b794242021-01-28 16:00:22 +010062 expect resp.http.x-ssl-sha1 == "D9C3BAE37EA5A7EDB7B3C9BDD4DCB2FE58A412E4"
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010063 expect resp.http.x-ssl == "Ok"
64} -run
65
William Lallemand7e696372021-01-28 14:59:19 +010066haproxy h1 -cli {
67 send "show ssl cert ${testdir}/client1.pem"
68 expect ~ ".*SHA1 FingerPrint: D9C3BAE37EA5A7EDB7B3C9BDD4DCB2FE58A412E4"
69}
70
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010071# Replace certificate with an expired one
72shell {
73 printf "set ssl cert ${testdir}/client1.pem <<\n$(cat ${testdir}/client2_expired.pem)\n\n" | socat "${tmpdir}/h1/stats" -
74 echo "commit ssl cert ${testdir}/client1.pem" | socat "${tmpdir}/h1/stats" -
75}
76
William Lallemand7e696372021-01-28 14:59:19 +010077haproxy h1 -cli {
78 send "show ssl cert ${testdir}/client1.pem"
79 expect ~ ".*SHA1 FingerPrint: C625EB01A0A660294B9D7F44C5CEEE5AFC495BE4"
80}
81
82
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010083# The updated client certificate is an expired one so this request should fail
84client c1 -connect ${h1_clearlst_sock} {
85 txreq
86 rxresp
87 expect resp.status == 200
William Lallemand7b794242021-01-28 16:00:22 +010088 expect resp.http.x-ssl-sha1 == "C625EB01A0A660294B9D7F44C5CEEE5AFC495BE4"
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010089 expect resp.http.x-ssl == "Expired"
90} -run
91
92# Replace certificate with a revoked one
93shell {
94 printf "set ssl cert ${testdir}/client1.pem <<\n$(cat ${testdir}/client3_revoked.pem)\n\n" | socat "${tmpdir}/h1/stats" -
95 echo "commit ssl cert ${testdir}/client1.pem" | socat "${tmpdir}/h1/stats" -
96}
97
William Lallemand7e696372021-01-28 14:59:19 +010098haproxy h1 -cli {
99 send "show ssl cert ${testdir}/client1.pem"
100 expect ~ ".*SHA1 FingerPrint: 992386628A40C9D49C89BAC0058B5D45D8575151"
101}
102
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +0100103# The updated client certificate is a revoked one so this request should fail
104client c1 -connect ${h1_clearlst_sock} {
105 txreq
106 rxresp
107 expect resp.status == 200
William Lallemand7b794242021-01-28 16:00:22 +0100108 expect resp.http.x-ssl-sha1 == "992386628A40C9D49C89BAC0058B5D45D8575151"
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +0100109 expect resp.http.x-ssl == "Revoked"
110} -run
111