Remi Tricot-Le Breton | f615070 | 2021-04-22 11:02:16 +0200 | [diff] [blame] | 1 | #REGTEST_TYPE=devel |
| 2 | |
| 3 | # This test uses the "new ssl crl-file" and "del ssl crl-file" commands to create |
| 4 | # a new CRL file or delete an unused CRL file. |
| 5 | # |
| 6 | # It requires socat to upload the CRL file. |
| 7 | # |
| 8 | # If this test does not work anymore: |
| 9 | # - Check that you have socat |
| 10 | |
| 11 | varnishtest "Test the 'new ssl crl-file' and 'del ssl crl-file' commands of the CLI" |
Tim Duesterhus | 5efc48d | 2021-06-11 19:56:15 +0200 | [diff] [blame] | 12 | feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev0)'" |
Tim Duesterhus | c957048 | 2021-06-11 19:56:16 +0200 | [diff] [blame] | 13 | feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'" |
Tim Duesterhus | 4ee192f | 2021-06-11 19:56:17 +0200 | [diff] [blame] | 14 | feature cmd "command -v socat" |
Remi Tricot-Le Breton | f615070 | 2021-04-22 11:02:16 +0200 | [diff] [blame] | 15 | feature ignore_unknown_macro |
| 16 | |
| 17 | server s1 -repeat 3 { |
| 18 | rxreq |
| 19 | txresp |
| 20 | } -start |
| 21 | |
| 22 | haproxy h1 -conf { |
| 23 | global |
| 24 | tune.ssl.default-dh-param 2048 |
| 25 | tune.ssl.capture-cipherlist-size 1 |
| 26 | stats socket "${tmpdir}/h1/stats" level admin |
| 27 | crt-base ${testdir} |
| 28 | |
| 29 | defaults |
| 30 | mode http |
| 31 | option httplog |
Remi Tricot-Le Breton | f615070 | 2021-04-22 11:02:16 +0200 | [diff] [blame] | 32 | log stderr local0 debug err |
| 33 | option logasap |
| 34 | timeout connect 100ms |
| 35 | timeout client 1s |
| 36 | timeout server 1s |
| 37 | |
| 38 | listen clear-lst |
| 39 | bind "fd@${clearlst}" |
| 40 | balance roundrobin |
| 41 | use_backend with_crl_be if { path /with-crl } |
| 42 | default_backend default_be |
| 43 | |
| 44 | backend default_be |
| 45 | server s1 "${tmpdir}/ssl.sock" ssl verify none crt ${testdir}/client3_revoked.pem sni str(www.test1.com) |
| 46 | |
| 47 | backend with_crl_be |
| 48 | server s1 "${tmpdir}/ssl.sock" ssl verify none crt ${testdir}/client3_revoked.pem sni str(with-crl.com) |
| 49 | |
| 50 | listen ssl-lst |
| 51 | bind "${tmpdir}/ssl.sock" ssl strict-sni crt-list ${testdir}/localhost.crt-list ca-file ${testdir}/ca-auth.crt verify required crt-ignore-err all |
| 52 | http-response add-header X-SSL-Client-Verify %[ssl_c_verify] |
| 53 | server s1 ${s1_addr}:${s1_port} |
| 54 | } -start |
| 55 | |
| 56 | # Request using the default backend and the www.test1.com sni |
| 57 | client c1 -connect ${h1_clearlst_sock} { |
| 58 | txreq |
| 59 | rxresp |
| 60 | expect resp.status == 200 |
| 61 | # The backend has no CRL so the connection should succeed |
| 62 | expect resp.http.X-SSL-Client-Verify == 0 |
| 63 | } -run |
| 64 | |
| 65 | # This connection should fail because the with-crl.com sni is not mentioned in the crt-list yet. |
| 66 | client c1 -connect ${h1_clearlst_sock} { |
| 67 | txreq -url "/with-crl" |
| 68 | rxresp |
| 69 | expect resp.status == 503 |
| 70 | } -run |
| 71 | |
| 72 | # Create a new unlinked CRL file |
| 73 | haproxy h1 -cli { |
| 74 | send "new ssl crl-file new_crlfile.crt" |
| 75 | expect ~ "New CRL file created 'new_crlfile.crt'!" |
| 76 | } |
| 77 | |
| 78 | shell { |
| 79 | printf "set ssl crl-file new_crlfile.crt <<\n$(cat ${testdir}/crl-auth.pem)\n\n" | socat "${tmpdir}/h1/stats" - |
| 80 | echo "commit ssl crl-file new_crlfile.crt" | socat "${tmpdir}/h1/stats" - |
| 81 | } |
| 82 | |
| 83 | haproxy h1 -cli { |
| 84 | send "show ssl crl-file" |
| 85 | expect ~ ".*new_crlfile.crt" |
| 86 | |
| 87 | send "show ssl crl-file new_crlfile.crt" |
| 88 | expect ~ ".*Issuer:.*/CN=HAProxy Technologies CA Test Client Auth" |
| 89 | } |
| 90 | |
| 91 | # Add a new certificate that will use the new CA file |
| 92 | shell { |
| 93 | echo "new ssl cert ${testdir}/set_cafile_server.pem" | socat "${tmpdir}/h1/stats" - |
| 94 | printf "set ssl cert ${testdir}/set_cafile_server.pem <<\n$(cat ${testdir}/set_cafile_server.pem)\n\n" | socat "${tmpdir}/h1/stats" - |
| 95 | echo "commit ssl cert ${testdir}/set_cafile_server.pem" | socat "${tmpdir}/h1/stats" - |
| 96 | } |
| 97 | |
| 98 | # Create a new crt-list line that will use the new CA file |
| 99 | shell { |
| 100 | printf "add ssl crt-list ${testdir}/localhost.crt-list <<\n${testdir}/set_cafile_server.pem [crl-file new_crlfile.crt] with-crl.com\n\n" | socat "${tmpdir}/h1/stats" - |
| 101 | } |
| 102 | |
| 103 | client c1 -connect ${h1_clearlst_sock} { |
| 104 | txreq -url "/with-crl" |
| 105 | rxresp |
| 106 | expect resp.status == 200 |
| 107 | # The frontend's certificate is revoked in the newly added CRL, connection should fail |
| 108 | expect resp.http.X-SSL-Client-Verify == 23 |
| 109 | } -run |
| 110 | |
| 111 | # Request using the default backend and the www.test1.com sni |
| 112 | client c1 -connect ${h1_clearlst_sock} { |
| 113 | txreq |
| 114 | rxresp |
| 115 | expect resp.status == 200 |
| 116 | # The backend has no CRL for this SNI so the connection should still succeed |
| 117 | expect resp.http.X-SSL-Client-Verify == 0 |
| 118 | } -run |
| 119 | |
| 120 | # Delete the newly added crt-list line and CRL file |
| 121 | haproxy h1 -cli { |
| 122 | send "del ssl crt-list ${testdir}/localhost.crt-list ${testdir}/set_cafile_server.pem" |
| 123 | expect ~ "Entry '${testdir}/set_cafile_server.pem' deleted in crtlist '${testdir}/localhost.crt-list'!" |
| 124 | |
| 125 | send "del ssl crl-file new_crlfile.crt" |
| 126 | expect ~ "CRL file 'new_crlfile.crt' deleted!" |
| 127 | |
| 128 | send "show ssl crl-file" |
| 129 | expect !~ "new_crlfile.crt" |
| 130 | } |
| 131 | |
| 132 | # The connection should now fail since the crt-list line was deleted |
| 133 | client c1 -connect ${h1_clearlst_sock} { |
| 134 | txreq -url "/with-crl" |
| 135 | rxresp |
| 136 | expect resp.status == 503 |
| 137 | } -run |
| 138 | |