Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 1 | #REGTEST_TYPE=devel |
| 2 | |
| 3 | # This reg-test uses the "set ssl ca-file" command to update a CA file over the CLI. |
Remi Tricot-Le Breton | 2a22e16 | 2021-03-16 11:19:33 +0100 | [diff] [blame] | 4 | # It also tests the "abort ssl ca-file" and "show ssl ca-file" commands. |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 5 | # |
| 6 | # It is based on two CA certificates, set_cafile_interCA1.crt and set_cafile_interCA2.crt, |
| 7 | # and a client certificate that was signed with set_cafile_interCA1.crt (set_cafile_client.pem) |
| 8 | # and a server certificate that was signed with set_cafile_interCA2.crt (set_cafile_server.pem). |
| 9 | # The CA files used by the client and the server will be updated through the CLI until a |
| 10 | # proper connection can be established between them. |
| 11 | # |
| 12 | # It requires socat to upload the certificate |
| 13 | # |
| 14 | # If this test does not work anymore: |
| 15 | # - Check that you have socat |
| 16 | |
| 17 | varnishtest "Test the 'set ssl ca-file' feature of the CLI" |
Tim Duesterhus | 5efc48d | 2021-06-11 19:56:15 +0200 | [diff] [blame] | 18 | feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev0)'" |
Tim Duesterhus | c957048 | 2021-06-11 19:56:16 +0200 | [diff] [blame] | 19 | feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'" |
Tim Duesterhus | 4ee192f | 2021-06-11 19:56:17 +0200 | [diff] [blame] | 20 | feature cmd "command -v socat" |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 21 | feature ignore_unknown_macro |
| 22 | |
Remi Tricot-Le Breton | d5fd09d | 2021-03-11 10:22:52 +0100 | [diff] [blame] | 23 | server s1 -repeat 4 { |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 24 | rxreq |
| 25 | txresp |
| 26 | } -start |
| 27 | |
| 28 | haproxy h1 -conf { |
| 29 | global |
| 30 | tune.ssl.default-dh-param 2048 |
Marcin Deranek | 310a260 | 2021-07-13 19:04:24 +0200 | [diff] [blame] | 31 | tune.ssl.capture-buffer-size 1 |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 32 | stats socket "${tmpdir}/h1/stats" level admin |
| 33 | |
| 34 | defaults |
| 35 | mode http |
| 36 | option httplog |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 37 | retries 0 |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 38 | log stderr local0 debug err |
| 39 | option logasap |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 40 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 41 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 42 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 43 | |
| 44 | listen clear-lst |
| 45 | bind "fd@${clearlst}" |
William Lallemand | ae6547f | 2022-06-20 18:01:30 +0200 | [diff] [blame] | 46 | # dummy bind used to test a change when the same crt is used as server and bind |
| 47 | bind "fd@${foobarlst}" ssl crt ${testdir}/set_cafile_client.pem ca-file ${testdir}/set_cafile_interCA1.crt verify none |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 48 | server s1 "${tmpdir}/ssl.sock" ssl crt ${testdir}/set_cafile_client.pem ca-file ${testdir}/set_cafile_interCA1.crt verify none |
| 49 | |
| 50 | listen clear-verified-lst |
| 51 | bind "fd@${clearverifiedlst}" |
| 52 | server s1 "${tmpdir}/ssl.sock" ssl crt ${testdir}/set_cafile_client.pem ca-file ${testdir}/set_cafile_interCA1.crt verify required |
| 53 | |
| 54 | listen ssl-lst |
| 55 | # crt: certificate of the server |
| 56 | # ca-file: CA used for client authentication request |
| 57 | bind "${tmpdir}/ssl.sock" ssl crt ${testdir}/set_cafile_server.pem ca-verify-file ${testdir}/set_cafile_rootCA.crt ca-file ${testdir}/set_cafile_interCA2.crt verify required crt-ignore-err all |
| 58 | http-response add-header X-SSL-Client-Verify %[ssl_c_verify] |
| 59 | server s1 ${s1_addr}:${s1_port} |
| 60 | } -start |
| 61 | |
| 62 | |
Remi Tricot-Le Breton | 2a22e16 | 2021-03-16 11:19:33 +0100 | [diff] [blame] | 63 | # Test the "show ssl ca-file" command |
| 64 | haproxy h1 -cli { |
| 65 | send "show ssl ca-file" |
| 66 | expect ~ ".*${testdir}/set_cafile_interCA1.crt - 1 certificate.*" |
| 67 | send "show ssl ca-file" |
| 68 | expect ~ ".*${testdir}/set_cafile_interCA2.crt - 1 certificate.*" |
| 69 | |
| 70 | send "show ssl ca-file ${testdir}/set_cafile_interCA2.crt" |
| 71 | expect ~ ".*SHA1 FingerPrint: 3D3D1D10AD74A8135F05A818E10E5FA91433954D" |
| 72 | } |
| 73 | |
| 74 | |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 75 | # This first connection should fail because the client's certificate was signed with the |
| 76 | # set_cafile_interCA1.crt certificate which is not known by the backend. |
| 77 | client c1 -connect ${h1_clearlst_sock} { |
| 78 | txreq |
| 79 | rxresp |
| 80 | expect resp.status == 200 |
| 81 | # unable to verify the client certificate |
Ilya Shipitsin | fc11266 | 2021-12-04 14:32:23 +0500 | [diff] [blame] | 82 | expect resp.http.X-SSL-Client-Verify ~ "20|21" |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 83 | } -run |
| 84 | |
Remi Tricot-Le Breton | d5fd09d | 2021-03-11 10:22:52 +0100 | [diff] [blame] | 85 | # Set a new ca-file without committing it and check that the new ca-file is not taken into account |
| 86 | shell { |
Remi Tricot-Le Breton | 2a22e16 | 2021-03-16 11:19:33 +0100 | [diff] [blame] | 87 | printf "set ssl ca-file ${testdir}/set_cafile_interCA2.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n\n" | socat "${tmpdir}/h1/stats" - |
| 88 | } |
| 89 | |
| 90 | # Test the "show ssl ca-file" command |
| 91 | # The transaction should be mentioned in the list |
| 92 | haproxy h1 -cli { |
| 93 | send "show ssl ca-file" |
| 94 | expect ~ "\\*${testdir}/set_cafile_interCA2.crt - 1 certificate.*" |
| 95 | |
| 96 | # The original CA file did not change |
| 97 | send "show ssl ca-file ${testdir}/set_cafile_interCA2.crt" |
| 98 | expect ~ ".*SHA1 FingerPrint: 3D3D1D10AD74A8135F05A818E10E5FA91433954D" |
| 99 | |
| 100 | # Only the current transaction displays a new certificate |
| 101 | send "show ssl ca-file *${testdir}/set_cafile_interCA2.crt" |
| 102 | expect ~ ".*SHA1 FingerPrint: 4FFF535278883264693CEA72C4FAD13F995D0098" |
Remi Tricot-Le Breton | d5fd09d | 2021-03-11 10:22:52 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | # This connection should still fail for the same reasons as previously |
| 106 | client c1 -connect ${h1_clearlst_sock} { |
| 107 | txreq |
| 108 | rxresp |
| 109 | expect resp.status == 200 |
| 110 | # unable to verify the client certificate |
Ilya Shipitsin | fc11266 | 2021-12-04 14:32:23 +0500 | [diff] [blame] | 111 | expect resp.http.X-SSL-Client-Verify ~ "20|21" |
Remi Tricot-Le Breton | d5fd09d | 2021-03-11 10:22:52 +0100 | [diff] [blame] | 112 | } -run |
| 113 | |
| 114 | haproxy h1 -cli { |
Remi Tricot-Le Breton | 2a22e16 | 2021-03-16 11:19:33 +0100 | [diff] [blame] | 115 | send "abort ssl ca-file ${testdir}/set_cafile_interCA2.crt" |
| 116 | expect ~ "Transaction aborted for certificate '${testdir}/set_cafile_interCA2.crt'!" |
| 117 | send "commit ssl ca-file ${testdir}/set_cafile_interCA2.crt" |
Remi Tricot-Le Breton | d5fd09d | 2021-03-11 10:22:52 +0100 | [diff] [blame] | 118 | expect ~ "No ongoing transaction!" |
| 119 | } |
| 120 | |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 121 | |
| 122 | # Update the bind line's ca-file in order to accept the client certificate |
| 123 | shell { |
| 124 | printf "set ssl ca-file ${testdir}/set_cafile_interCA2.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n$(cat ${testdir}/set_cafile_rootCA.crt)\n\n" | socat "${tmpdir}/h1/stats" - |
| 125 | echo "commit ssl ca-file ${testdir}/set_cafile_interCA2.crt" | socat "${tmpdir}/h1/stats" - |
| 126 | } |
| 127 | |
| 128 | |
| 129 | # The backend's certificate can't be verified by the frontend because it was signed with |
| 130 | # the set_cafile_interCA2.crt certificate. |
| 131 | client c1 -connect ${h1_clearverifiedlst_sock} { |
| 132 | txreq |
| 133 | rxresp |
| 134 | expect resp.status == 503 |
| 135 | } -run |
| 136 | |
| 137 | |
| 138 | # Update the server line's ca-file. The server certificate should now be accepted by |
| 139 | # the frontend. We replace the single CA by a list of CAs that includes the correct one. |
| 140 | shell { |
| 141 | printf "set ssl ca-file ${testdir}/set_cafile_interCA1.crt <<\n$(cat ${testdir}/set_cafile_interCA1.crt)\n$(cat ${testdir}/set_cafile_interCA2.crt)\n$(cat ${testdir}/set_cafile_rootCA.crt)\n\n" | socat "${tmpdir}/h1/stats" - |
| 142 | echo "commit ssl ca-file ${testdir}/set_cafile_interCA1.crt" | socat "${tmpdir}/h1/stats" - |
| 143 | } |
| 144 | |
Remi Tricot-Le Breton | 2a22e16 | 2021-03-16 11:19:33 +0100 | [diff] [blame] | 145 | # Test the "show ssl ca-file" with a certificate index |
| 146 | haproxy h1 -cli { |
| 147 | send "show ssl ca-file" |
| 148 | expect ~ ".*${testdir}/set_cafile_interCA1.crt - 3 certificate.*" |
| 149 | |
| 150 | send "show ssl ca-file ${testdir}/set_cafile_interCA1.crt:1" |
| 151 | expect ~ ".*SHA1 FingerPrint: 4FFF535278883264693CEA72C4FAD13F995D0098" |
| 152 | |
| 153 | send "show ssl ca-file ${testdir}/set_cafile_interCA1.crt:2" |
| 154 | expect !~ ".*SHA1 FingerPrint: 4FFF535278883264693CEA72C4FAD13F995D0098" |
| 155 | send "show ssl ca-file ${testdir}/set_cafile_interCA1.crt:2" |
| 156 | expect ~ ".*SHA1 FingerPrint: 3D3D1D10AD74A8135F05A818E10E5FA91433954D" |
| 157 | } |
Remi Tricot-Le Breton | 2db6101 | 2021-03-05 14:42:40 +0100 | [diff] [blame] | 158 | |
| 159 | client c1 -connect ${h1_clearverifiedlst_sock} { |
| 160 | txreq |
| 161 | rxresp |
| 162 | expect resp.status == 200 |
| 163 | # there should be no error on the backend side but one on the frontend side |
| 164 | expect resp.http.X-SSL-Client-Verify == 0 |
| 165 | } -run |