blob: 270cba6e02dbc8ef123603588303fd6675e07edd [file] [log] [blame]
William Lallemande5dfd402021-10-14 11:06:16 +02001#REGTEST_TYPE=devel
William Lallemand35201832021-04-02 15:23:14 +02002
3# This reg-test uses the "set ssl cert" command to update a multi-certificate
4# bundle over the CLI.
5# It requires socat to upload the certificate
6#
7# This regtests loads a multi-certificates bundle "cert1-example.com.pem"
8# composed of a .rsa and a .ecdsa
9#
10# After verifying that the RSA and ECDSA algorithms were avalailble with the
11# right certificate, the test changes the certificates and try new requests.
12#
13# If this test does not work anymore:
14# - Check that you have socat
William Lallemande5dfd402021-10-14 11:06:16 +020015# - Check that you have at least OpenSSL 1.1.1
William Lallemand35201832021-04-02 15:23:14 +020016
17varnishtest "Test the 'set ssl cert' feature of the CLI with bundles"
William Lallemande5dfd402021-10-14 11:06:16 +020018# could work with haproxy 2.3 but the -cc is not available
19feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev9)'"
20feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL) && ssllib_name_startswith(OpenSSL) && openssl_version_atleast(1.1.1)'"
Tim Duesterhus4ee192f2021-06-11 19:56:17 +020021feature cmd "command -v socat"
William Lallemand35201832021-04-02 15:23:14 +020022feature ignore_unknown_macro
23
24server s1 -repeat 9 {
25 rxreq
26 txresp
27} -start
28
29haproxy h1 -conf {
30 global
31 tune.ssl.default-dh-param 2048
Marcin Deranek310a2602021-07-13 19:04:24 +020032 tune.ssl.capture-buffer-size 1
William Lallemand35201832021-04-02 15:23:14 +020033 stats socket "${tmpdir}/h1/stats" level admin
34 crt-base ${testdir}
35
36 defaults
37 mode http
38 option httplog
William Lallemand35201832021-04-02 15:23:14 +020039 log stderr local0 debug err
40 option logasap
Willy Tarreauf6739232021-11-18 17:46:22 +010041 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
42 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
43 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
William Lallemand35201832021-04-02 15:23:14 +020044
45 listen clear-lst
46 bind "fd@${clearlst}"
47 balance roundrobin
48
49 http-response set-header X-SSL-Server-SHA1 %[ssl_s_sha1,hex]
50
51 retries 0 # 2nd SSL connection must fail so skip the retry
52 server s1 "${tmpdir}/ssl.sock" ssl verify none sni str(example.com) force-tlsv12 ciphers ECDHE-RSA-AES128-GCM-SHA256
53 server s2 "${tmpdir}/ssl.sock" ssl verify none sni str(example.com) force-tlsv12 ciphers ECDHE-ECDSA-AES256-GCM-SHA384
54
55 server s3 "${tmpdir}/ssl.sock" ssl verify none sni str(example.com) force-tlsv12 ciphers ECDHE-RSA-AES128-GCM-SHA256
56 server s4 "${tmpdir}/ssl.sock" ssl verify none sni str(example.com) force-tlsv12 ciphers ECDHE-ECDSA-AES256-GCM-SHA384
57
58 listen ssl-lst
59 bind "${tmpdir}/ssl.sock" ssl crt ${testdir}/cert1-example.com.pem
60 server s1 ${s1_addr}:${s1_port}
61
62} -start
63
64
65haproxy h1 -cli {
66 send "show ssl cert ${testdir}/cert1-example.com.pem.rsa"
67 expect ~ ".*SHA1 FingerPrint: 94F720DACA71B8B1A0AC9BD48C65BA688FF047DE"
68 send "show ssl cert ${testdir}/cert1-example.com.pem.ecdsa"
69 expect ~ ".*SHA1 FingerPrint: C1BA055D452F92EB02D449F0498C289F50698300"
70}
71
72client c1 -connect ${h1_clearlst_sock} {
73# RSA
74 txreq
75 rxresp
76 expect resp.http.X-SSL-Server-SHA1 == "94F720DACA71B8B1A0AC9BD48C65BA688FF047DE"
77 expect resp.status == 200
78# ECDSA
79 txreq
80 rxresp
81 expect resp.http.X-SSL-Server-SHA1 == "C1BA055D452F92EB02D449F0498C289F50698300"
82 expect resp.status == 200
83} -run
84
85shell {
86 printf "set ssl cert ${testdir}/cert1-example.com.pem.rsa <<\n$(cat ${testdir}/cert2-example.com.pem.rsa)\n\n" | socat "${tmpdir}/h1/stats" -
87 echo "commit ssl cert ${testdir}/cert1-example.com.pem.rsa" | socat "${tmpdir}/h1/stats" -
88 printf "set ssl cert ${testdir}/cert1-example.com.pem.ecdsa <<\n$(cat ${testdir}/cert2-example.com.pem.ecdsa)\n\n" | socat "${tmpdir}/h1/stats" -
89 echo "commit ssl cert ${testdir}/cert1-example.com.pem.ecdsa" | socat "${tmpdir}/h1/stats" -
90}
91
92haproxy h1 -cli {
93 send "show ssl cert ${testdir}/cert1-example.com.pem.rsa"
94 expect ~ ".*SHA1 FingerPrint: ADC863817FC40C2A9CA913CE45C9A92232558F90"
95 send "show ssl cert ${testdir}/cert1-example.com.pem.ecdsa"
96 expect ~ ".*SHA1 FingerPrint: F49FFA446D072262445C197B85D2F400B3F58808"
97}
98
99client c1 -connect ${h1_clearlst_sock} {
100# RSA
101 txreq
102 rxresp
103 expect resp.http.X-SSL-Server-SHA1 == "ADC863817FC40C2A9CA913CE45C9A92232558F90"
104 expect resp.status == 200
105# ECDSA
106 txreq
107 rxresp
108 expect resp.http.X-SSL-Server-SHA1 == "F49FFA446D072262445C197B85D2F400B3F58808"
109 expect resp.status == 200
110} -run
111