William Lallemand | 4781fad | 2020-03-31 14:48:34 +0200 | [diff] [blame] | 1 | #REGTEST_TYPE=devel |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 2 | |
| 3 | # This reg-test uses the "set ssl cert" command to update a certificate over the CLI. |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 4 | # It requires socat to upload the certificate |
| 5 | # |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 6 | # This check has two separate parts. |
| 7 | # In the first part, there are 3 requests, the first one will use "www.test1.com" as SNI, |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 8 | # the second one with the same but that must fail and the third one will use |
| 9 | # "localhost". Since vtest can't do SSL, we use haproxy as an SSL client with 2 |
| 10 | # chained listen section. |
| 11 | # |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 12 | # In the second part, we check the update of a default certificate in a crt-list. |
| 13 | # This corresponds to a bug raised in https://github.com/haproxy/haproxy/issues/1143. |
| 14 | # A certificate is used as default certificate as well as regular one, and during the update |
| 15 | # the default certificate would not be properly updated if the default instance did not have |
| 16 | # any SNI. The test consists in checking that the used certificate is the right one after |
| 17 | # updating it via a "set ssl cert" call. |
| 18 | # |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 19 | # If this test does not work anymore: |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 20 | # - Check that you have socat |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 21 | |
| 22 | varnishtest "Test the 'set ssl cert' feature of the CLI" |
Willy Tarreau | fa10ffd | 2020-01-24 13:49:42 +0100 | [diff] [blame] | 23 | #REQUIRE_VERSION=2.2 |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 24 | #REQUIRE_OPTIONS=OPENSSL |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 25 | #REQUIRE_BINARIES=socat |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 26 | feature ignore_unknown_macro |
| 27 | |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 28 | server s1 -repeat 9 { |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 29 | rxreq |
| 30 | txresp |
| 31 | } -start |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 32 | |
| 33 | haproxy h1 -conf { |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 34 | global |
| 35 | tune.ssl.default-dh-param 2048 |
| 36 | tune.ssl.capture-cipherlist-size 1 |
| 37 | stats socket "${tmpdir}/h1/stats" level admin |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 38 | crt-base ${testdir} |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 39 | |
| 40 | defaults |
| 41 | mode http |
| 42 | option httplog |
| 43 | ${no-htx} option http-use-htx |
| 44 | log stderr local0 debug err |
| 45 | option logasap |
| 46 | timeout connect 100ms |
| 47 | timeout client 1s |
| 48 | timeout server 1s |
| 49 | |
| 50 | listen clear-lst |
| 51 | bind "fd@${clearlst}" |
| 52 | balance roundrobin |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 53 | |
| 54 | http-response set-header X-SSL-Server-SHA1 %[ssl_s_sha1,hex] |
| 55 | |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 56 | retries 0 # 2nd SSL connection must fail so skip the retry |
| 57 | server s1 "${tmpdir}/ssl.sock" ssl verify none sni str(www.test1.com) |
| 58 | server s2 "${tmpdir}/ssl.sock" ssl verify none sni str(www.test1.com) |
| 59 | server s3 "${tmpdir}/ssl.sock" ssl verify none sni str(localhost) |
| 60 | |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 61 | server s4 "${tmpdir}/other-ssl.sock" ssl verify none sni str(www.test1.com) |
| 62 | server s5 "${tmpdir}/other-ssl.sock" ssl verify none sni str(other.test1.com) # uses the default certificate |
| 63 | server s6 "${tmpdir}/other-ssl.sock" ssl verify none sni str(www.test1.com) |
| 64 | server s7 "${tmpdir}/other-ssl.sock" ssl verify none sni str(other.test1.com) # uses the default certificate |
| 65 | |
| 66 | server s8 "${tmpdir}/other-ssl.sock" ssl verify none sni str(www.test1.com) |
| 67 | server s9 "${tmpdir}/other-ssl.sock" ssl verify none sni str(other.test1.com) # uses the default certificate |
| 68 | |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 69 | listen ssl-lst |
| 70 | bind "${tmpdir}/ssl.sock" ssl crt ${testdir}/common.pem strict-sni |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 71 | server s1 ${s1_addr}:${s1_port} |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 72 | |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 73 | listen other-ssl-lst |
| 74 | bind "${tmpdir}/other-ssl.sock" ssl crt-list ${testdir}/set_default_cert.crt-list |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 75 | server s1 ${s1_addr}:${s1_port} |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 76 | |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 77 | } -start |
| 78 | |
| 79 | |
| 80 | haproxy h1 -cli { |
| 81 | send "show ssl cert ${testdir}/common.pem" |
| 82 | expect ~ ".*SHA1 FingerPrint: 2195C9F0FD58470313013FC27C1B9CF9864BD1C6" |
| 83 | } |
| 84 | |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 85 | client c1 -connect ${h1_clearlst_sock} { |
| 86 | txreq |
| 87 | rxresp |
| 88 | expect resp.status == 200 |
| 89 | } -run |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 90 | |
| 91 | shell { |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 92 | printf "set ssl cert ${testdir}/common.pem <<\n$(cat ${testdir}/ecdsa.pem)\n\n" | socat "${tmpdir}/h1/stats" - |
| 93 | echo "commit ssl cert ${testdir}/common.pem" | socat "${tmpdir}/h1/stats" - |
William Lallemand | 9c1aa0a | 2019-12-19 11:25:19 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | haproxy h1 -cli { |
| 97 | send "show ssl cert ${testdir}/common.pem" |
| 98 | expect ~ ".*SHA1 FingerPrint: A490D069DBAFBEE66DE434BEC34030ADE8BCCBF1" |
| 99 | } |
| 100 | |
William Lallemand | a911548 | 2020-04-30 10:19:40 +0200 | [diff] [blame] | 101 | # check that the "www.test1.com" SNI was removed |
| 102 | client c1 -connect ${h1_clearlst_sock} { |
| 103 | txreq |
| 104 | rxresp |
| 105 | expect resp.status == 503 |
| 106 | } -run |
| 107 | |
| 108 | client c1 -connect ${h1_clearlst_sock} { |
| 109 | txreq |
| 110 | rxresp |
| 111 | expect resp.status == 200 |
| 112 | } -run |
William Lallemand | 8695ce0 | 2021-02-01 15:31:00 +0100 | [diff] [blame] | 113 | |
| 114 | shell { |
| 115 | printf "set ssl cert ${testdir}/common.pem <<\n$(cat ${testdir}/common.pem)\n\n" | socat "${tmpdir}/h1/stats" - |
| 116 | echo "abort ssl cert ${testdir}/common.pem" | socat "${tmpdir}/h1/stats" - |
| 117 | } |
| 118 | |
| 119 | haproxy h1 -cli { |
| 120 | send "show ssl cert ${testdir}/common.pem" |
| 121 | expect ~ ".*SHA1 FingerPrint: A490D069DBAFBEE66DE434BEC34030ADE8BCCBF1" |
| 122 | } |
| 123 | |
Remi Tricot-Le Breton | 8218aed | 2021-03-17 14:56:54 +0100 | [diff] [blame] | 124 | |
| 125 | |
| 126 | # The following requests are aimed at a backend that uses the set_default_cert.crt-list file |
| 127 | |
| 128 | # Uses the www.test1.com sni |
| 129 | client c1 -connect ${h1_clearlst_sock} { |
| 130 | txreq |
| 131 | rxresp |
| 132 | expect resp.http.X-SSL-Server-SHA1 == "9DC18799428875976DDE706E9956035EE88A4CB3" |
| 133 | expect resp.status == 200 |
| 134 | } -run |
| 135 | |
| 136 | # Uses the other.test1.com sni and the default line of the crt-list |
| 137 | client c1 -connect ${h1_clearlst_sock} { |
| 138 | txreq |
| 139 | rxresp |
| 140 | expect resp.http.X-SSL-Server-SHA1 == "9DC18799428875976DDE706E9956035EE88A4CB3" |
| 141 | expect resp.status == 200 |
| 142 | } -run |
| 143 | |
| 144 | shell { |
| 145 | printf "set ssl cert ${testdir}/set_default_cert.pem <<\n$(cat ${testdir}/common.pem)\n\n" | socat "${tmpdir}/h1/stats" - |
| 146 | } |
| 147 | |
| 148 | # Certificate should not have changed yet |
| 149 | haproxy h1 -cli { |
| 150 | send "show ssl cert ${testdir}/set_default_cert.pem" |
| 151 | expect ~ ".*SHA1 FingerPrint: 9DC18799428875976DDE706E9956035EE88A4CB3" |
| 152 | } |
| 153 | |
| 154 | shell { |
| 155 | echo "commit ssl cert ${testdir}/set_default_cert.pem" | socat "${tmpdir}/h1/stats" - |
| 156 | } |
| 157 | |
| 158 | haproxy h1 -cli { |
| 159 | send "show ssl cert ${testdir}/set_default_cert.pem" |
| 160 | expect ~ ".*SHA1 FingerPrint: 2195C9F0FD58470313013FC27C1B9CF9864BD1C6" |
| 161 | } |
| 162 | |
| 163 | # Uses the www.test1.com sni |
| 164 | client c1 -connect ${h1_clearlst_sock} { |
| 165 | txreq |
| 166 | rxresp |
| 167 | expect resp.http.X-SSL-Server-SHA1 == "2195C9F0FD58470313013FC27C1B9CF9864BD1C6" |
| 168 | expect resp.status == 200 |
| 169 | } -run |
| 170 | |
| 171 | # Uses the other.test1.com sni and the default line of the crt-list |
| 172 | client c1 -connect ${h1_clearlst_sock} { |
| 173 | txreq |
| 174 | rxresp |
| 175 | expect resp.http.X-SSL-Server-SHA1 == "2195C9F0FD58470313013FC27C1B9CF9864BD1C6" |
| 176 | expect resp.status == 200 |
| 177 | } -run |
| 178 | |
| 179 | # Restore original certificate |
| 180 | shell { |
| 181 | printf "set ssl cert ${testdir}/set_default_cert.pem <<\n$(cat ${testdir}/set_default_cert.pem)\n\n" | socat "${tmpdir}/h1/stats" - |
| 182 | echo "commit ssl cert ${testdir}/set_default_cert.pem" | socat "${tmpdir}/h1/stats" - |
| 183 | } |
| 184 | |
| 185 | haproxy h1 -cli { |
| 186 | send "show ssl cert ${testdir}/set_default_cert.pem" |
| 187 | expect ~ ".*SHA1 FingerPrint: 9DC18799428875976DDE706E9956035EE88A4CB" |
| 188 | } |
| 189 | |
| 190 | # Uses the www.test1.com sni |
| 191 | client c1 -connect ${h1_clearlst_sock} { |
| 192 | txreq |
| 193 | rxresp |
| 194 | expect resp.http.X-SSL-Server-SHA1 == "9DC18799428875976DDE706E9956035EE88A4CB3" |
| 195 | expect resp.status == 200 |
| 196 | } -run |
| 197 | |
| 198 | # Uses the other.test1.com sni and the default line of the crt-list |
| 199 | client c1 -connect ${h1_clearlst_sock} { |
| 200 | txreq |
| 201 | rxresp |
| 202 | expect resp.http.X-SSL-Server-SHA1 == "9DC18799428875976DDE706E9956035EE88A4CB3" |
| 203 | expect resp.status == 200 |
| 204 | } -run |