generate-certificates: bind alpn setting is not applied
Detailed Description of the Problem
On a bind line that uses generate-certificates, when a client connects with an SNI that is not matched by any crt / crt-list entry (HAProxy creates a certificate on the fly), the alpn setting from that same bind line is not applied to the connection.
- TCP bind,
alpn h2,http/1.1: handshake completes, generated cert is served, but theServerHellocontains no ALPN extension. HTTP/2-only clients fall back toHTTP/1.1. - QUIC bind,
alpn h3: the QUIC handshake is aborted (No ALPN negotiated). QUIC requires ALPN (RFC 9001), so the connection cannot be established at all.
For the identical bind lines, an SNI that is in crt-list negotiates h2 / h3 normally. The only variable is whether the cert came from crt / crt-list or from generate-certificates.
Expected Behavior
- The
alpnsettings on abindline should apply to connections served by agenerate-certificatescertificate exactly as they do forcrt/crt-listcertificates. - A
bindwithalpn h2,http/1.1should negotiateh2, and a QUICbindwithalpn h3should be usable regardless of whether the certificate was static or generated.
Steps to Reproduce the Behavior
setup.sh
#!/bin/sh
set -e
cd "$(dirname "$0")"
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
-keyout ca.key -out ca.crt -days 3650 -subj '/CN=gen-ca'
cat ca.key ca.crt > ca.pem
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
-keyout leaf.key -out leaf.crt -days 3650 \
-subj '/CN=in-list.example.com' -addext 'subjectAltName=DNS:in-list.example.com'
cat leaf.key leaf.crt > leaf.pem
echo 'leaf.pem' > crt-list.txthaproxy.cfg
global
log stdout format raw local0 debug
defaults
mode http
timeout connect 5s
timeout client 5s
timeout server 5s
frontend fe
bind [email protected]:8443 ssl crt-list crt-list.txt alpn h2,http/1.1 generate-certificates ca-sign-file ca.pem
bind [email protected]:8443 ssl crt-list crt-list.txt alpn h3 generate-certificates ca-sign-file ca.pem
http-request return status 200 content-type "text/plain" lf-string "ok alpn=%[ssl_fc_alpn]\n"test.sh
#!/bin/sh
set -e
cd "$(dirname "$0")"
NET=hap-repro-net
docker network create "$NET" >/dev/null 2>&1 || true
docker rm -f hap-repro >/dev/null 2>&1 || true
docker run -d --user 0 --network "$NET" --name hap-repro -v "$PWD":/w -w /w \
haproxytech/haproxy-debian:3.4.4 haproxy -f haproxy.cfg >/dev/null
sleep 1
docker run --rm --network "$NET" alpine:edge sh -ec '
apk add -q openssl
probe() { echo | openssl s_client "$@" -connect hap-repro:8443 2>&1 \
| grep -E "^subject=|ALPN protocol|No ALPN|quic_do_handshake"; }
echo "== TCP in-list =="; probe -servername in-list.example.com -alpn h2,http/1.1
echo "== TCP absent =="; probe -servername absent.example.com -alpn h2,http/1.1
echo "== QUIC in-list =="; probe -quic -servername in-list.example.com -alpn h3
echo "== QUIC absent =="; probe -quic -servername absent.example.com -alpn h3
'
docker rm -f hap-repro >/dev/null 2>&1 || true
docker network rm "$NET" >/dev/null 2>&1 || trueRun:
chmod +x *.sh
./setup.sh
./test.shin-list.example.com is in crt-list → h2 / h3. absent.example.com is not → cert is generated (subject shows CN=gen-ca, CN=absent.example.com) → no ALPN on TCP, QUIC handshake fails.
TL;DR
| Transport | SNI | Certificate source | Observed result |
|---|---|---|---|
TCP (alpn h2,http/1.1) |
in-list.example.com |
static crt-list entry |
ALPN protocol: h2 |
TCP (alpn h2,http/1.1) |
absent.example.com |
generate-certificates (on the fly) |
No ALPN negotiated -> downgrades to HTTP/1.1 |
QUIC (alpn h3) |
in-list.example.com |
static crt-list entry |
ALPN protocol: h3 |
QUIC (alpn h3) |
absent.example.com |
generate-certificates (on the fly) |
quic_do_handshake: protocol is shutdown / No ALPN negotiated —> connection fails |
| Transport | Certificate source | Expected | Observed |
|---|---|---|---|
| TCP | static crt-list |
ALPN h2 |
ALPN h2 |
| TCP | generate-certificates |
ALPN h2 |
No ALPN negotiated |
| QUIC | static crt-list |
ALPN h3 |
ALPN h3 |
| QUIC | generate-certificates |
ALPN h3 |
quic_do_handshake: protocol is shutdown |
Do you have any idea what may have caused this?
generate-certificatesbuilds itsSSL_CTXinssl_sock_do_create_cert(),src/ssl_gencert.c:109- The
SSL_CTXis created and configured atsrc/ssl_gencert.c:244-312:SSL_CTX_new(SSLv23_server_method())- It never calls
SSL_CTX_set_alpn_select_cb()/SSL_CTX_set_next_protos_advertised_cb()and it never goes throughssl_sock_prepare_ctx()(nor copies frombind_conf->initial_ctx). SSL_set_SSL_CTX(ssl, ssl_ctx)then points the session at the callback-less generated context, so OpenSSL negotiates no ALPN. TCP degrades toHTTP/1.1; QUIC aborts.
- It never calls
- The
For
crt/crt-listcertificates, the ALPN callback is installed byssl_sock_prepare_ctx(),src/ssl_sock.c:5081-5082
Do you have an idea how to solve the issue?
Route the generated context in ssl_sock_do_create_cert() through the common context-preparation path so the ALPN callback and other bind options get applied.
What is your configuration?
global
log stdout format raw local0 debug
defaults
mode http
timeout connect 5s
timeout client 5s
timeout server 5s
frontend fe
bind [email protected]:8443 ssl crt-list crt-list.txt alpn h2,http/1.1 generate-certificates ca-sign-file ca.pem
bind [email protected]:8443 ssl crt-list crt-list.txt alpn h3 generate-certificates ca-sign-file ca.pem
http-request return status 200 content-type "text/plain" lf-string "ok alpn=%[ssl_fc_alpn]\n"Output of haproxy -vv
HAProxy version 3.4.4-7f03ae6 2026/08/27 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2031.
Known bugs: http://www.haproxy.org/bugs/bugs-3.4.4.html
Running on: Linux 6.18.44-talos #1 SMP PREEMPT_DYNAMIC Mon Aug 17 12:09:22 UTC 2026 x86_64
Build options :
TARGET = linux-glibc
CC = cc
CFLAGS = -O2 -g -fwrapv -fvect-cost-model=very-cheap
OPTIONS = USE_PTHREAD_EMULATION=1 USE_LINUX_TPROXY=1 USE_GETADDRINFO=1 USE_OPENSSL_AWSLC=1 USE_LUA=1 USE_SLZ=1 USE_TFO=1 USE_QUIC=1 USE_PROMEX=1 USE_PCRE2=1 USE_PCRE2_JIT=1
DEBUG =
Feature list : -51DEGREES +ACCEPT4 +ACME +BACKTRACE -CLOSEFROM +CPU_AFFINITY +CRYPT_H -DEVICEATLAS +DL -ECH -ENGINE +EPOLL -EVPORTS +GETADDRINFO +HAVE_TCP_MD5SIG -KQUEUE +KTLS -LIBATOMIC +LIBCRYPT +LINUX_CAP +LINUX_SPLICE +LINUX_TPROXY +LUA +MATH -MEMORY_PROFILING +NETFILTER +NS -OBSOLETE_LINKER +OPENSSL +OPENSSL_AWSLC -OPENSSL_WOLFSSL -OT -PCRE +PCRE2 +PCRE2_JIT -PCRE_JIT +POLL +PRCTL -PROCCTL +PROMEX +PTHREAD_EMULATION +QUIC -QUIC_OPENSSL_COMPAT +RT +SHM_OPEN +SLZ +SSL -STATIC_PCRE -STATIC_PCRE2 +TFO +THREAD +THREAD_DUMP +TPROXY +TRACE -WURFL -ZLIB
Detected feature list : +HAVE_WORKING_TCP_MD5SIG
Default settings :
bufsize = 16384, maxrewrite = 1024, maxpollevents = 200
Built with multi-threading support (MAX_TGROUPS=32, MAX_THREADS=1024, default=4).
Built with SSL library version : OpenSSL 1.1.1 (compatible; AWS-LC 4.0.0)
Running on SSL library version : AWS-LC 4.0.0
SSL library supports TLS extensions : yes
SSL library supports SNI : yes
SSL library FIPS mode : no
SSL library default verify directory : /etc/ssl/certs
SSL library supports : TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3
QUIC: connection sock-per-conn mode support : yes
QUIC: GSO emission support : yes
Built with Lua version : Lua 5.4.7
Built with the Prometheus exporter as a service
Built with network namespace support.
Built with libslz for stateless compression.
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND
Built with PCRE2 version : 10.46 2025-08-27
PCRE2 library supports JIT : yes
Encrypted password support via crypt(3): yes
Built with gcc compiler version 14.2.0
Available polling systems :
epoll : pref=300, test result OK
poll : pref=200, test result OK
select : pref=150, test result OK
Total: 3 (3 usable), will use epoll.
Available multiplexer protocols :
(protocols marked as <default> cannot be specified using 'proto' keyword)
qmux : mode=HTTP side=FE|BE mux=QMUX flags=HTX|NO_UPG
quic : mode=HTTP side=FE|BE mux=QUIC flags=HTX|NO_UPG|FRAMED
h2 : mode=HTTP side=FE|BE mux=H2 flags=HTX|HOL_RISK|NO_UPG
<default> : mode=HTTP side=FE|BE mux=H1 flags=HTX
h1 : mode=HTTP side=FE|BE mux=H1 flags=HTX|NO_UPG
fcgi : mode=HTTP side=BE mux=FCGI flags=HTX|HOL_RISK|NO_UPG
<default> : mode=SPOP side=BE mux=SPOP flags=HOL_RISK|NO_UPG
spop : mode=SPOP side=BE mux=SPOP flags=HOL_RISK|NO_UPG
<default> : mode=TCP side=FE|BE mux=PASS flags=
none : mode=TCP side=FE|BE mux=PASS flags=NO_UPG
Available services : prometheus-exporter
Available filters :
[BWLIM] bwlim-in
[BWLIM] bwlim-out
[CACHE] cache
[COMP] comp-req
[COMP] comp-res
[COMP] compression
[FCGI] fcgi-app
[SPOE] spoe
[TRACE] traceLast Outputs and Backtraces
Additional Information
Somebody already noticed this behaviour Jan 2025: https://discourse.haproxy.org/t/alpn-negotiation-not-working-with-generate-certificates/11535
Source: haproxy/haproxy