blob: 880e7b0c9b6ada6c47923735e12cbf59bc2bfbc0 [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
Tim Duesterhus4ee192f2021-06-11 19:56:17 +02009feature cmd "command -v socat"
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010010feature 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
Marcin Deranek310a2602021-07-13 19:04:24 +020020 tune.ssl.capture-buffer-size 1
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010021 stats socket "${tmpdir}/h1/stats" level admin
William Lallemanda870a9c2021-02-01 14:37:36 +010022 nbthread 1
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010023
24 defaults
25 mode http
26 option httplog
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010027 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
William Lallemande0de0a62021-02-03 18:51:01 +010036 server s1 "${tmpdir}/ssl.sock" ssl verify none crt ${testdir}/client1.pem
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010037
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
William Lallemandff97eda2021-02-01 14:57:31 +010042 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
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010043
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
William Lallemand7b794242021-01-28 16:00:22 +010051 http-response add-header x-ssl-sha1 %[ssl_c_sha1,hex]
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010052
53 server s1 ${s1_addr}:${s1_port}
54} -start
55
56client c1 -connect ${h1_clearlst_sock} {
57 txreq
58 rxresp
59 expect resp.status == 200
William Lallemand7b794242021-01-28 16:00:22 +010060 expect resp.http.x-ssl-sha1 == "D9C3BAE37EA5A7EDB7B3C9BDD4DCB2FE58A412E4"
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010061 expect resp.http.x-ssl == "Ok"
62} -run
63
William Lallemand7e696372021-01-28 14:59:19 +010064haproxy h1 -cli {
65 send "show ssl cert ${testdir}/client1.pem"
66 expect ~ ".*SHA1 FingerPrint: D9C3BAE37EA5A7EDB7B3C9BDD4DCB2FE58A412E4"
67}
68
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010069# Replace certificate with an expired one
70shell {
71 printf "set ssl cert ${testdir}/client1.pem <<\n$(cat ${testdir}/client2_expired.pem)\n\n" | socat "${tmpdir}/h1/stats" -
72 echo "commit ssl cert ${testdir}/client1.pem" | socat "${tmpdir}/h1/stats" -
73}
74
William Lallemand7e696372021-01-28 14:59:19 +010075haproxy h1 -cli {
76 send "show ssl cert ${testdir}/client1.pem"
77 expect ~ ".*SHA1 FingerPrint: C625EB01A0A660294B9D7F44C5CEEE5AFC495BE4"
78}
79
80
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010081# The updated client certificate is an expired one so this request should fail
82client c1 -connect ${h1_clearlst_sock} {
83 txreq
84 rxresp
85 expect resp.status == 200
William Lallemand7b794242021-01-28 16:00:22 +010086 expect resp.http.x-ssl-sha1 == "C625EB01A0A660294B9D7F44C5CEEE5AFC495BE4"
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +010087 expect resp.http.x-ssl == "Expired"
88} -run
89
90# Replace certificate with a revoked one
91shell {
92 printf "set ssl cert ${testdir}/client1.pem <<\n$(cat ${testdir}/client3_revoked.pem)\n\n" | socat "${tmpdir}/h1/stats" -
93 echo "commit ssl cert ${testdir}/client1.pem" | socat "${tmpdir}/h1/stats" -
94}
95
William Lallemand7e696372021-01-28 14:59:19 +010096haproxy h1 -cli {
97 send "show ssl cert ${testdir}/client1.pem"
98 expect ~ ".*SHA1 FingerPrint: 992386628A40C9D49C89BAC0058B5D45D8575151"
99}
100
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +0100101# The updated client certificate is a revoked one so this request should fail
102client c1 -connect ${h1_clearlst_sock} {
103 txreq
104 rxresp
105 expect resp.status == 200
William Lallemand7b794242021-01-28 16:00:22 +0100106 expect resp.http.x-ssl-sha1 == "992386628A40C9D49C89BAC0058B5D45D8575151"
Remi Tricot-Le Bretonf3eedfe2021-01-25 17:19:44 +0100107 expect resp.http.x-ssl == "Revoked"
108} -run
109
William Lallemand8695ce02021-02-01 15:31:00 +0100110# Abort a transaction
111shell {
112 printf "set ssl cert ${testdir}/client1.pem <<\n$(cat ${testdir}/client3_revoked.pem)\n\n" | socat "${tmpdir}/h1/stats" -
113 echo "abort ssl cert ${testdir}/client1.pem" | socat "${tmpdir}/h1/stats" -
114}
115
116haproxy h1 -cli {
117 send "show ssl cert ${testdir}/client1.pem"
118 expect ~ ".*SHA1 FingerPrint: 992386628A40C9D49C89BAC0058B5D45D8575151"
119}
120
121# The certificate was not updated so it should still be revoked
122client c1 -connect ${h1_clearlst_sock} {
123 txreq
124 rxresp
125 expect resp.status == 200
126 expect resp.http.x-ssl == "Revoked"
127} -run
128
129