Remi Tricot-Le Breton | 17b7384 | 2022-02-11 12:04:46 +0100 | [diff] [blame] | 1 | #REGTEST_TYPE=devel |
| 2 | |
| 3 | # This reg-tests checks that the DH-related mechanisms works properly. |
| 4 | # When no DH is specified, either directly in the server's PEM or through a |
Remi Tricot-Le Breton | 1d6338e | 2022-04-12 11:31:55 +0200 | [diff] [blame] | 5 | # ssl-dh-param-file global option, and no tune.ssl.default-dh-param is defined, |
| 6 | # DHE ciphers are disabled. |
| 7 | # If a default-dh-param is defined, we will use DH parameters of the same size |
| 8 | # as the server's RSA or DSA key, or default-dh-param if it is smaller. |
Remi Tricot-Le Breton | 17b7384 | 2022-02-11 12:04:46 +0100 | [diff] [blame] | 9 | # This test has three distinct HAProxy instances, one with no DH-related option |
| 10 | # used, one with the tune.ssl.default-dh-param global parameter set, and one |
| 11 | # with an ssl-dh-param-file global option. |
| 12 | # We use "openssl s_client" calls in order to check the size of the "Server |
| 13 | # Temp Key" (which will be the same as the DH parameters in case a DHE cipher |
| 14 | # is used). |
| 15 | # |
| 16 | # The main goal of this test was to check that the newly added OpenSSLv3 |
| 17 | # specific DH code worked as before, since it needed to be created in order to |
| 18 | # stop using deprecated APIs. |
| 19 | |
| 20 | varnishtest "Test the DH related SSL options" |
| 21 | feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'" |
| 22 | feature cmd "command -v openssl && command -v grep && command -v socat" |
| 23 | feature ignore_unknown_macro |
| 24 | |
| 25 | server s1 -repeat 8 { |
| 26 | rxreq |
| 27 | txresp |
| 28 | } -start |
| 29 | |
| 30 | |
| 31 | haproxy h1 -conf { |
| 32 | global |
| 33 | stats socket "${tmpdir}/h1/stats" level admin |
| 34 | |
| 35 | defaults |
| 36 | mode http |
| 37 | option httpslog |
| 38 | log stderr local0 debug err |
| 39 | option logasap |
| 40 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 41 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 42 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
| 43 | retries 0 |
| 44 | |
| 45 | frontend clear-fe |
| 46 | bind "fd@${clearlst}" |
| 47 | use_backend gen_cert_be if { path /gencert } |
| 48 | default_backend dflt_be |
| 49 | |
| 50 | backend dflt_be |
| 51 | server s1 "${tmpdir}/ssl_dflt.sock" ssl verify none ssl-max-ver TLSv1.2 |
| 52 | |
| 53 | backend gen_cert_be |
| 54 | server s1 "${tmpdir}/ssl_dflt_gencert.sock" ssl verify none ssl-max-ver TLSv1.2 |
| 55 | |
| 56 | listen ssl-dflt-lst |
| 57 | bind "${tmpdir}/ssl_dflt.sock" ssl crt ${testdir}/common.pem ca-file ${testdir}/set_cafile_rootCA.crt verify optional ciphers "DHE-RSA-AES256-GCM-SHA384" ssl-max-ver TLSv1.2 |
| 58 | http-response set-header x-ssl-cipher %[ssl_fc_cipher] |
| 59 | server s1 ${s1_addr}:${s1_port} |
| 60 | |
| 61 | listen ssl-dflt-gencert-lst |
| 62 | bind "${tmpdir}/ssl_dflt_gencert.sock" ssl generate-certificates crt ${testdir}/common.pem ca-file ${testdir}/set_cafile_rootCA.crt ca-sign-file ${testdir}/generate_certificates/gen_cert_ca.pem verify optional ciphers "DHE-RSA-AES256-GCM-SHA384" ssl-max-ver TLSv1.2 |
| 63 | http-response set-header x-ssl-cipher %[ssl_fc_cipher] |
| 64 | server s1 ${s1_addr}:${s1_port} |
| 65 | } -start |
| 66 | |
| 67 | haproxy h2 -conf { |
| 68 | global |
| 69 | stats socket "${tmpdir}/h2/stats" level admin |
| 70 | |
| 71 | global |
| 72 | tune.ssl.default-dh-param 4096 |
| 73 | |
| 74 | defaults |
| 75 | mode http |
| 76 | option httpslog |
| 77 | log stderr local0 debug err |
| 78 | option logasap |
| 79 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 80 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 81 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
| 82 | retries 0 |
| 83 | |
| 84 | listen clear-lst |
| 85 | bind "fd@${clearlst_dfltdh}" |
| 86 | server s1 "${tmpdir}/ssl_dfltdh.sock" ssl verify none ssl-max-ver TLSv1.2 |
| 87 | |
| 88 | listen ssl-4096dh-dflt-lst |
| 89 | bind "${tmpdir}/ssl_dfltdh.sock" ssl crt ${testdir}/common.pem ca-file ${testdir}/set_cafile_rootCA.crt verify optional ciphers "DHE-RSA-AES256-GCM-SHA384" ssl-max-ver TLSv1.2 |
| 90 | http-response set-header x-ssl-cipher %[ssl_fc_cipher] |
| 91 | server s1 ${s1_addr}:${s1_port} |
| 92 | } -start |
| 93 | |
| 94 | haproxy h3 -conf { |
| 95 | global |
| 96 | stats socket "${tmpdir}/h3/stats" level admin |
| 97 | |
| 98 | global |
| 99 | ssl-dh-param-file ${testdir}/common.4096.dh |
| 100 | |
| 101 | defaults |
| 102 | mode http |
| 103 | option httpslog |
| 104 | log stderr local0 debug err |
| 105 | option logasap |
| 106 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 107 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 108 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
| 109 | retries 0 |
| 110 | |
| 111 | listen clear-lst |
| 112 | bind "fd@${clearlst_dhfile}" |
| 113 | server s1 "${tmpdir}/ssl_dhfile.sock" ssl verify none ssl-max-ver TLSv1.2 |
| 114 | |
| 115 | listen ssl-dhfile-lst |
| 116 | bind "${tmpdir}/ssl_dhfile.sock" ssl crt ${testdir}/common.pem ca-file ${testdir}/set_cafile_rootCA.crt verify optional ciphers "DHE-RSA-AES256-GCM-SHA384" ssl-max-ver TLSv1.2 |
| 117 | http-response set-header x-ssl-cipher %[ssl_fc_cipher] |
| 118 | server s1 ${s1_addr}:${s1_port} |
| 119 | } -start |
| 120 | |
| 121 | # |
| 122 | # Check that all the SSL backend <-> SSL frontend connections work |
| 123 | # |
| 124 | client c1 -connect ${h1_clearlst_sock} { |
| 125 | txreq |
| 126 | rxresp |
Remi Tricot-Le Breton | 1d6338e | 2022-04-12 11:31:55 +0200 | [diff] [blame] | 127 | # No DH parameters are defined, DHE ciphers are unavailable |
| 128 | expect resp.status == 503 |
Remi Tricot-Le Breton | 17b7384 | 2022-02-11 12:04:46 +0100 | [diff] [blame] | 129 | } -run |
| 130 | |
| 131 | client c2 -connect ${h2_clearlst_dfltdh_sock} { |
| 132 | txreq |
| 133 | rxresp |
| 134 | expect resp.status == 200 |
| 135 | expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384" |
| 136 | } -run |
| 137 | |
| 138 | client c3 -connect ${h3_clearlst_dhfile_sock} { |
| 139 | txreq |
| 140 | rxresp |
| 141 | expect resp.status == 200 |
| 142 | expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384" |
| 143 | } -run |
| 144 | |
| 145 | client c4 -connect ${h1_clearlst_sock} { |
| 146 | txreq -url "/gencert" |
| 147 | rxresp |
Remi Tricot-Le Breton | 1d6338e | 2022-04-12 11:31:55 +0200 | [diff] [blame] | 148 | # No DH parameters are defined, DHE ciphers are unavailable |
| 149 | expect resp.status == 503 |
Remi Tricot-Le Breton | 17b7384 | 2022-02-11 12:04:46 +0100 | [diff] [blame] | 150 | } -run |
| 151 | |
| 152 | |
Remi Tricot-Le Breton | 17b7384 | 2022-02-11 12:04:46 +0100 | [diff] [blame] | 153 | # On the second HAProxy instance, even if default-dh-param is set to 4096, this |
| 154 | # value is only considered as a maximum DH key length and we will always try to |
| 155 | # match the server's certificate key length in our DHE key exchange (2048 bits |
| 156 | # in the case of common.pem). |
| 157 | shell { |
| 158 | echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dfltdh.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 2048 bits" |
| 159 | } |
| 160 | |
| 161 | shell { |
| 162 | echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dhfile.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits" |
| 163 | } |
| 164 | |
Remi Tricot-Le Breton | 17b7384 | 2022-02-11 12:04:46 +0100 | [diff] [blame] | 165 | |
Remi Tricot-Le Breton | 17b7384 | 2022-02-11 12:04:46 +0100 | [diff] [blame] | 166 | # |
| 167 | # Add a custom DH to the server's PEM certificate |
| 168 | # |
| 169 | shell { |
| 170 | printf "set ssl cert ${testdir}/common.pem <<\n$(cat ${testdir}/common.pem)\n$(cat ${testdir}/common.4096.dh)\n\n" | socat "${tmpdir}/h1/stats" - |
| 171 | echo "commit ssl cert ${testdir}/common.pem" | socat "${tmpdir}/h1/stats" - |
| 172 | |
| 173 | printf "set ssl cert ${testdir}/common.pem <<\n$(cat ${testdir}/common.pem)\n$(cat ${testdir}/common.4096.dh)\n\n" | socat "${tmpdir}/h2/stats" - |
| 174 | echo "commit ssl cert ${testdir}/common.pem" | socat "${tmpdir}/h2/stats" - |
| 175 | |
| 176 | printf "set ssl cert ${testdir}/common.pem <<\n$(cat ${testdir}/common.pem)\n$(cat ${testdir}/common.4096.dh)\n\n" | socat "${tmpdir}/h3/stats" - |
| 177 | echo "commit ssl cert ${testdir}/common.pem" | socat "${tmpdir}/h3/stats" - |
| 178 | } |
| 179 | |
| 180 | |
| 181 | # |
| 182 | # Check that all the SSL backend <-> SSL frontend connections still work |
Remi Tricot-Le Breton | 1d6338e | 2022-04-12 11:31:55 +0200 | [diff] [blame] | 183 | # Common.pem now contains DH parameters so the first instance's frontends |
| 184 | # can now use DHE ciphers. |
Remi Tricot-Le Breton | 17b7384 | 2022-02-11 12:04:46 +0100 | [diff] [blame] | 185 | # |
| 186 | client c5 -connect ${h1_clearlst_sock} { |
| 187 | txreq |
| 188 | rxresp |
| 189 | expect resp.status == 200 |
| 190 | expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384" |
| 191 | } -run |
| 192 | |
| 193 | client c6 -connect ${h2_clearlst_dfltdh_sock} { |
| 194 | txreq |
| 195 | rxresp |
| 196 | expect resp.status == 200 |
| 197 | expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384" |
| 198 | } -run |
| 199 | |
| 200 | client c7 -connect ${h3_clearlst_dhfile_sock} { |
| 201 | txreq |
| 202 | rxresp |
| 203 | expect resp.status == 200 |
| 204 | expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384" |
| 205 | } -run |
| 206 | |
| 207 | client c8 -connect ${h1_clearlst_sock} { |
| 208 | txreq -url "/gencert" |
| 209 | rxresp |
| 210 | expect resp.status == 200 |
| 211 | expect resp.http.x-ssl-cipher == "DHE-RSA-AES256-GCM-SHA384" |
| 212 | } -run |
| 213 | |
| 214 | |
| 215 | |
| 216 | # |
| 217 | # Check the new size of the DH key |
| 218 | # |
| 219 | shell { |
| 220 | echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dflt.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits" |
| 221 | } |
| 222 | |
| 223 | shell { |
| 224 | echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dfltdh.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits" |
| 225 | } |
| 226 | |
| 227 | shell { |
| 228 | echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dhfile.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits" |
| 229 | } |
| 230 | |
| 231 | shell { |
| 232 | echo "Q" | openssl s_client -unix "${tmpdir}/ssl_dflt_gencert.sock" -tls1_2 2>/dev/null | grep -E "Server Temp Key: DH, 4096 bits" |
| 233 | } |