With OpenSSL and AWS-LC, a server whose curves are X25519:P-256 only
sends a key_share for X25519. Its handshake with a listener which only
accepts P-256 needs a HelloRetryRequest, and the one with a listener
which accepts X25519 does not. Both sides are checked, over TCP and
over QUIC.

The pools are poisoned with 0x51 instead of the default 0x50, which
leaves the bit of SSL_SOCK_F_HRR cleared: this way the test also fails
when the flags of an ssl_sock_ctx are not initialized.
---
 reg-tests/quic/ssl_hrr.vtc | 19 +++++++++++
 reg-tests/ssl/ssl_hrr.vtc  | 17 ++++++++++
 reg-tests/ssl/ssl_hrr.vtci | 67 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 103 insertions(+)
 create mode 100644 reg-tests/quic/ssl_hrr.vtc
 create mode 100644 reg-tests/ssl/ssl_hrr.vtc
 create mode 100644 reg-tests/ssl/ssl_hrr.vtci

diff --git a/reg-tests/quic/ssl_hrr.vtc b/reg-tests/quic/ssl_hrr.vtc
new file mode 100644
index 000000000..29a7682bb
--- /dev/null
+++ b/reg-tests/quic/ssl_hrr.vtc
@@ -0,0 +1,19 @@
+#REGTEST_TYPE=devel
+
+# This reg-test checks the ssl_fc_has_hrr and ssl_bc_has_hrr sample fetches
+# with two backends and their listener. The server of the first one sends a
+# key_share that its listener does not accept, so a HelloRetryRequest is sent
+# and both sides must report it. The listener of the second one accepts this
+# key_share and nothing must be reported.
+
+varnishtest "Tests for the ssl_fc_has_hrr and ssl_bc_has_hrr sample fetches"
+
+# QUIC backend are not supported with USE_QUIC_OPENSSL_COMPAT
+feature cmd "$HAPROXY_PROGRAM -cc 'feature(QUIC) && 
!feature(QUIC_OPENSSL_COMPAT)'"
+feature cmd "$HAPROXY_PROGRAM -cc 'ssllib_name_startswith(OpenSSL) && 
openssl_version_atleast(3.0.0) || ssllib_name_startswith(AWS-LC) && 
awslc_api_atleast(30)'"
+# This test configures the X25519 group, which is rejected by HAProxy's
+# FIPS compliance checks when the SSL library is running in FIPS mode.
+feature cmd "$HAPROXY_PROGRAM -cc '!fips_mode()'"
+
+setenv VTC_SOCK_TYPE quic
+include ${testdir}/../ssl/ssl_hrr.vtci
diff --git a/reg-tests/ssl/ssl_hrr.vtc b/reg-tests/ssl/ssl_hrr.vtc
new file mode 100644
index 000000000..066abb7d1
--- /dev/null
+++ b/reg-tests/ssl/ssl_hrr.vtc
@@ -0,0 +1,17 @@
+#REGTEST_TYPE=devel
+
+# This reg-test checks the ssl_fc_has_hrr and ssl_bc_has_hrr sample fetches
+# with two backends and their listener. The server of the first one sends a
+# key_share that its listener does not accept, so a HelloRetryRequest is sent
+# and both sides must report it. The listener of the second one accepts this
+# key_share and nothing must be reported.
+
+varnishtest "Tests for the ssl_fc_has_hrr and ssl_bc_has_hrr sample fetches"
+
+feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL) && 
ssllib_name_startswith(OpenSSL) && openssl_version_atleast(3.0.0) || 
feature(OPENSSL) && ssllib_name_startswith(AWS-LC) && awslc_api_atleast(30)'"
+# This test configures the X25519 group, which is rejected by HAProxy's
+# FIPS compliance checks when the SSL library is running in FIPS mode.
+feature cmd "$HAPROXY_PROGRAM -cc '!fips_mode()'"
+
+setenv VTC_SOCK_TYPE stream
+include ${testdir}/ssl_hrr.vtci
diff --git a/reg-tests/ssl/ssl_hrr.vtci b/reg-tests/ssl/ssl_hrr.vtci
new file mode 100644
index 000000000..888a9c3d6
--- /dev/null
+++ b/reg-tests/ssl/ssl_hrr.vtci
@@ -0,0 +1,67 @@
+feature ignore_unknown_macro
+
+server s1 -repeat 2 {
+    rxreq
+    txresp
+} -start
+
+# The pools are poisoned with a byte whose lowest bit is set, so that an
+# ssl_sock_ctx whose flags were not initialized reports a HelloRetryRequest.
+haproxy h1 -arg "-dM0x51" -conf {
+    global
+    .if streq("$VTC_SOCK_TYPE",quic)
+        # required for backend connections
+        expose-experimental-directives
+    .endif
+    .if feature(THREAD)
+        thread-groups 1
+    .endif
+
+    defaults
+        mode http
+        timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+        timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
+        timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"
+        retries 0
+
+    listen clearlst
+        bind fd@${clearlst}
+        use_backend hrr-be if { path /hrr }
+        default_backend nohrr-be
+
+    # The server only sends a key_share for X25519, the first of its curves,
+    # and the listener does not accept it: the listener has to send a
+    # HelloRetryRequest to get a P-256 one.
+    backend hrr-be
+        http-response add-header x-bc-has-hrr %[ssl_bc_has_hrr]
+        server s1 ${VTC_SOCK_TYPE}+${h1_hrr_lst_sock} ssl verify none curves 
X25519:P-256
+    listen hrr_lst
+        http-response add-header x-fc-has-hrr %[ssl_fc_has_hrr]
+        bind ${VTC_SOCK_TYPE}+fd@${hrr_lst} ssl crt 
${testdir}/certs/common.pem curves P-256
+        server s1 ${s1_sock}
+
+    # Same server, but the listener accepts X25519: no HelloRetryRequest.
+    backend nohrr-be
+        http-response add-header x-bc-has-hrr %[ssl_bc_has_hrr]
+        server s1 ${VTC_SOCK_TYPE}+${h1_nohrr_lst_sock} ssl verify none curves 
X25519:P-256
+    listen nohrr_lst
+        http-response add-header x-fc-has-hrr %[ssl_fc_has_hrr]
+        bind ${VTC_SOCK_TYPE}+fd@${nohrr_lst} ssl crt 
${testdir}/certs/common.pem curves X25519:P-256
+        server s1 ${s1_sock}
+} -start
+
+client c1 -connect ${h1_clearlst_sock} {
+    txreq -url "/hrr"
+    rxresp
+    expect resp.status == 200
+    expect resp.http.x-fc-has-hrr == 1
+    expect resp.http.x-bc-has-hrr == 1
+} -run
+
+client c2 -connect ${h1_clearlst_sock} {
+    txreq -url "/nohrr"
+    rxresp
+    expect resp.status == 200
+    expect resp.http.x-fc-has-hrr == 0
+    expect resp.http.x-bc-has-hrr == 0
+} -run
-- 
2.50.1 (Apple Git-155)



Reply via email to