summaryrefslogtreecommitdiffstats
path: root/reg-tests/ssl/set_ssl_cert_bundle.vtc
blob: 270cba6e02dbc8ef123603588303fd6675e07edd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#REGTEST_TYPE=devel

# This reg-test uses the "set ssl cert" command to update a multi-certificate
# bundle over the CLI.
# It requires socat to upload the certificate
#
# This regtests loads a multi-certificates bundle "cert1-example.com.pem"
# composed of a .rsa and a .ecdsa
#
# After verifying that the RSA and ECDSA algorithms were avalailble with the
# right certificate, the test changes the certificates and try new requests.
#
# If this test does not work anymore:
# - Check that you have socat
# - Check that you have at least OpenSSL 1.1.1

varnishtest "Test the 'set ssl cert' feature of the CLI with bundles"
# could work with haproxy 2.3 but the -cc is not available
feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev9)'"
feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL) && ssllib_name_startswith(OpenSSL) && openssl_version_atleast(1.1.1)'"
feature cmd "command -v socat"
feature ignore_unknown_macro

server s1 -repeat 9 {
  rxreq
  txresp
} -start

haproxy h1 -conf {
    global
        tune.ssl.default-dh-param 2048
        tune.ssl.capture-buffer-size 1
        stats socket "${tmpdir}/h1/stats" level admin
        crt-base ${testdir}

    defaults
        mode http
        option httplog
        log stderr local0 debug err
        option logasap
        timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
        timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
        timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"

    listen clear-lst
        bind "fd@${clearlst}"
        balance roundrobin

        http-response set-header X-SSL-Server-SHA1 %[ssl_s_sha1,hex]

        retries 0 # 2nd SSL connection must fail so skip the retry
        server s1 "${tmpdir}/ssl.sock" ssl verify none sni str(example.com) force-tlsv12 ciphers ECDHE-RSA-AES128-GCM-SHA256
        server s2 "${tmpdir}/ssl.sock" ssl verify none sni str(example.com) force-tlsv12 ciphers ECDHE-ECDSA-AES256-GCM-SHA384

        server s3 "${tmpdir}/ssl.sock" ssl verify none sni str(example.com) force-tlsv12 ciphers ECDHE-RSA-AES128-GCM-SHA256
        server s4 "${tmpdir}/ssl.sock" ssl verify none sni str(example.com) force-tlsv12 ciphers ECDHE-ECDSA-AES256-GCM-SHA384

    listen ssl-lst
        bind "${tmpdir}/ssl.sock" ssl crt ${testdir}/cert1-example.com.pem
        server s1 ${s1_addr}:${s1_port}

} -start


haproxy h1 -cli {
    send "show ssl cert ${testdir}/cert1-example.com.pem.rsa"
    expect ~ ".*SHA1 FingerPrint: 94F720DACA71B8B1A0AC9BD48C65BA688FF047DE"
    send "show ssl cert ${testdir}/cert1-example.com.pem.ecdsa"
    expect ~ ".*SHA1 FingerPrint: C1BA055D452F92EB02D449F0498C289F50698300"
}

client c1 -connect ${h1_clearlst_sock} {
# RSA
    txreq
    rxresp
    expect resp.http.X-SSL-Server-SHA1 == "94F720DACA71B8B1A0AC9BD48C65BA688FF047DE"
    expect resp.status == 200
# ECDSA
    txreq
    rxresp
    expect resp.http.X-SSL-Server-SHA1 == "C1BA055D452F92EB02D449F0498C289F50698300"
    expect resp.status == 200
} -run

shell {
    printf "set ssl cert ${testdir}/cert1-example.com.pem.rsa <<\n$(cat ${testdir}/cert2-example.com.pem.rsa)\n\n" | socat "${tmpdir}/h1/stats" -
    echo "commit ssl cert ${testdir}/cert1-example.com.pem.rsa" | socat "${tmpdir}/h1/stats" -
    printf "set ssl cert ${testdir}/cert1-example.com.pem.ecdsa <<\n$(cat ${testdir}/cert2-example.com.pem.ecdsa)\n\n" | socat "${tmpdir}/h1/stats" -
    echo "commit ssl cert ${testdir}/cert1-example.com.pem.ecdsa" | socat "${tmpdir}/h1/stats" -
}

haproxy h1 -cli {
    send "show ssl cert ${testdir}/cert1-example.com.pem.rsa"
    expect ~ ".*SHA1 FingerPrint: ADC863817FC40C2A9CA913CE45C9A92232558F90"
    send "show ssl cert ${testdir}/cert1-example.com.pem.ecdsa"
    expect ~ ".*SHA1 FingerPrint: F49FFA446D072262445C197B85D2F400B3F58808"
}

client c1 -connect ${h1_clearlst_sock} {
# RSA
    txreq
    rxresp
    expect resp.http.X-SSL-Server-SHA1 == "ADC863817FC40C2A9CA913CE45C9A92232558F90"
    expect resp.status == 200
# ECDSA
    txreq
    rxresp
    expect resp.http.X-SSL-Server-SHA1 == "F49FFA446D072262445C197B85D2F400B3F58808"
    expect resp.status == 200
} -run