William Lallemand | 4781fad | 2020-03-31 14:48:34 +0200 | [diff] [blame] | 1 | #REGTEST_TYPE=devel |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 2 | |
| 3 | # This reg-test uses the "add ssl crt-list" command to add a certificate over the CLI. |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 4 | # It requires socat to upload the certificate |
| 5 | |
| 6 | # this check does 2 requests, the first one will use "www.test1.com" as SNI, and |
| 7 | # the second one will use "localhost". Since vtest can't do SSL, we use haproxy |
| 8 | # as an SSL client with 2 chained listen section. |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 9 | |
| 10 | # If this test does not work anymore: |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 11 | # - Check that you have socat |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 12 | |
| 13 | varnishtest "Test the 'add ssl crt-list' feature of the CLI" |
| 14 | #REQUIRE_VERSION=2.2 |
| 15 | #REQUIRE_OPTIONS=OPENSSL |
Tim Duesterhus | 4ee192f | 2021-06-11 19:56:17 +0200 | [diff] [blame] | 16 | feature cmd "command -v socat" |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 17 | feature ignore_unknown_macro |
| 18 | |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 19 | server s1 -repeat 2 { |
| 20 | rxreq |
| 21 | txresp |
| 22 | } -start |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 23 | |
| 24 | haproxy h1 -conf { |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 25 | global |
| 26 | tune.ssl.default-dh-param 2048 |
Marcin Deranek | 310a260 | 2021-07-13 19:04:24 +0200 | [diff] [blame] | 27 | tune.ssl.capture-buffer-size 1 |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 28 | crt-base ${testdir} |
| 29 | stats socket "${tmpdir}/h1/stats" level admin |
| 30 | |
| 31 | defaults |
| 32 | mode http |
| 33 | option httplog |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 34 | log stderr local0 debug err |
| 35 | option logasap |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 36 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 37 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 38 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 39 | |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 40 | |
| 41 | listen clear-lst |
| 42 | bind "fd@${clearlst}" |
| 43 | balance roundrobin |
| 44 | server s1 "${tmpdir}/ssl.sock" ssl verify none sni str(www.test1.com) |
| 45 | server s2 "${tmpdir}/ssl.sock" ssl verify none sni str(localhost) |
| 46 | |
| 47 | |
| 48 | listen ssl-lst |
| 49 | mode http |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 50 | bind "${tmpdir}/ssl.sock" ssl strict-sni crt-list ${testdir}/localhost.crt-list |
| 51 | |
| 52 | server s1 ${s1_addr}:${s1_port} |
William Lallemand | cb6c5f4 | 2022-06-20 16:51:53 +0200 | [diff] [blame^] | 53 | server s2 ${s1_addr}:${s1_port} ssl crt "${testdir}/common.pem" weight 0 verify none |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 54 | } -start |
| 55 | |
| 56 | |
| 57 | haproxy h1 -cli { |
| 58 | send "show ssl cert ${testdir}/common.pem" |
| 59 | expect ~ ".*SHA1 FingerPrint: 2195C9F0FD58470313013FC27C1B9CF9864BD1C6" |
| 60 | } |
| 61 | |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 62 | client c1 -connect ${h1_clearlst_sock} { |
| 63 | txreq |
| 64 | rxresp |
| 65 | expect resp.status == 200 |
| 66 | } -run |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 67 | |
| 68 | shell { |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 69 | echo "new ssl cert ${testdir}/ecdsa.pem" | socat "${tmpdir}/h1/stats" - |
| 70 | printf "set ssl cert ${testdir}/ecdsa.pem <<\n$(cat ${testdir}/ecdsa.pem)\n\n" | socat "${tmpdir}/h1/stats" - |
| 71 | echo "commit ssl cert ${testdir}/ecdsa.pem" | socat "${tmpdir}/h1/stats" - |
William Lallemand | cb6c5f4 | 2022-06-20 16:51:53 +0200 | [diff] [blame^] | 72 | printf "add ssl crt-list ${testdir}/localhost.crt-list/ <<\n${testdir}/common.pem [ssl-min-ver SSLv3 verify none allow-0rtt] !*\n\n" | socat "${tmpdir}/h1/stats" - |
William Lallemand | 99cc218 | 2020-06-25 15:19:51 +0200 | [diff] [blame] | 73 | printf "add ssl crt-list ${testdir}/localhost.crt-list/ <<\n${testdir}/ecdsa.pem [ssl-min-ver SSLv3 verify none allow-0rtt] localhost !www.test1.com\n\n" | socat "${tmpdir}/h1/stats" - |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 74 | printf "add ssl crt-list ${testdir}/localhost.crt-list <<\n${testdir}/ecdsa.pem [verify none allow-0rtt]\n\n" | socat "${tmpdir}/h1/stats" - |
William Lallemand | 99cc218 | 2020-06-25 15:19:51 +0200 | [diff] [blame] | 75 | printf "add ssl crt-list ${testdir}/localhost.crt-list/// <<\n${testdir}/ecdsa.pem localhost !www.test1.com\n\n" | socat "${tmpdir}/h1/stats" - |
| 76 | printf "add ssl crt-list ${testdir}/localhost.crt-list///// <<\n${testdir}/ecdsa.pem\n\n" | socat "${tmpdir}/h1/stats" - |
| 77 | printf "add ssl crt-list ${testdir}/localhost.crt-list// ${testdir}/ecdsa.pem\n" | socat "${tmpdir}/h1/stats" - |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | haproxy h1 -cli { |
| 81 | send "show ssl cert ${testdir}/ecdsa.pem" |
| 82 | expect ~ ".*SHA1 FingerPrint: A490D069DBAFBEE66DE434BEC34030ADE8BCCBF1" |
| 83 | } |
| 84 | |
| 85 | haproxy h1 -cli { |
William Lallemand | 99cc218 | 2020-06-25 15:19:51 +0200 | [diff] [blame] | 86 | send "show ssl crt-list ${testdir}/localhost.crt-list//" |
William Lallemand | fdb6db4 | 2020-04-01 17:13:22 +0200 | [diff] [blame] | 87 | # check the options and the filters in any order |
William Lallemand | 8177ad9 | 2020-05-20 16:49:02 +0200 | [diff] [blame] | 88 | expect ~ ".*${testdir}/ecdsa.pem \\[(?=.*verify none)(?=.*allow-0rtt)(?=.*ssl-min-ver SSLv3).*\\](?=.*!www.test1.com)(?=.*localhost).*" |
William Lallemand | 2be4a2e | 2020-03-31 12:13:34 +0200 | [diff] [blame] | 89 | } |
| 90 | |
William Lallemand | 3ed722f | 2020-04-30 09:47:08 +0200 | [diff] [blame] | 91 | client c1 -connect ${h1_clearlst_sock} { |
| 92 | txreq |
| 93 | rxresp |
| 94 | expect resp.status == 200 |
| 95 | } -run |
Remi Tricot-Le Breton | fb00f31 | 2021-03-23 16:41:53 +0100 | [diff] [blame] | 96 | |
| 97 | |
| 98 | # Try to add a new line that mentions an "unknown" CA file (not loaded yet). |
| 99 | # It should fail since no disk access are allowed during runtime. |
| 100 | shell { |
| 101 | printf "add ssl crt-list ${testdir}/localhost.crt-list/ <<\n${testdir}/ecdsa.pem [ca-file ${testdir}/ca-auth.crt] localhost\n\n" | socat "${tmpdir}/h1/stats" - | grep "unable to load ${testdir}/ca-auth.crt" |
| 102 | } |
| 103 | shell { |
| 104 | printf "add ssl crt-list ${testdir}/localhost.crt-list/ <<\n${testdir}/ecdsa.pem [ca-verify-file ${testdir}/ca-auth.crt] localhost\n\n" | socat "${tmpdir}/h1/stats" - | grep "unable to load ${testdir}/ca-auth.crt" |
| 105 | } |
| 106 | shell { |
| 107 | printf "add ssl crt-list ${testdir}/localhost.crt-list/ <<\n${testdir}/ecdsa.pem [crl-file ${testdir}/ca-auth.crt] localhost\n\n" | socat "${tmpdir}/h1/stats" - | grep "unable to load ${testdir}/ca-auth.crt" |
| 108 | } |
| 109 | |
| 110 | # Check that the new line was not added to the crt-list. |
| 111 | haproxy h1 -cli { |
| 112 | send "show ssl crt-list ${testdir}/localhost.crt-list//" |
| 113 | expect !~ ".*ca-file ${testdir}/ca-auth.crt" |
| 114 | } |