Conversation
TLS 1.3 certificate compression (RFC 8879) never reached the certificates installed from Lua. OpenSSL only sends a CompressedCertificate for a chain that was pre-compressed beforehand: get_compressed_certificate_alg() picks an algorithm only among the ones whose comp_cert entry is populated. nginx populates those for ssl_certificate when ssl_certificate_compression is on, and ngx.ssl.clear_certs() drops them together with the certificates they belong to, so a dynamic chain always went out in the clear. Add ngx_http_lua_ffi_ssl_compress_certs(), which pre-compresses the chain the connection currently holds. SSL_compress_certs() cannot do this from a certificate callback: it reaches ssl_get_cert_to_compress(), which gives up unless SSL_in_before(), and by then the handshake has started. So compress on a throw-away connection holding the same chain and install the result with SSL_set1_compressed_cert(), which has no such restriction. Requires OpenSSL 3.2.0 or later, where the RFC 8879 API arrived; every other TLS library gets the version error instead.
u5surf
marked this pull request as ready for review
September 25, 2026 21:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2516.
Problem
With
ssl_certificate_compression on;(nginx 1.29.1+) and OpenSSL 3.2+, a statically configured certificate is sent as a TLS 1.3CompressedCertificate(RFC 8879). One installed fromssl_certificate_by_lua*is not.OpenSSL sends only a chain that was pre-compressed beforehand —
get_compressed_certificate_alg()chooses among the algorithms whosecomp_cert[]entry is populated. nginx populates those at configuration time forssl_certificate;ngx.ssl.clear_certs()drops them together with the certificates they belong to, andset_cert()does not create new ones.Approach
SSL_compress_certs()cannot do this from a certificate callback: it reachesssl_get_cert_to_compress(), which gives up unlessSSL_in_before(), and by then the handshake has started. Implemented that way first, it failed on every handshake.ngx_http_lua_ffi_ssl_compress_certs(r, alg, err)therefore compresses on a throw-awaySSLmade from the connection'sSSL_CTX— a fresh object is in thebeforestate — and installs the result on the live connection withSSL_set1_compressed_cert(), which checks onlysc->serverand so is allowed mid-handshake.SSL_CTX_compress_certs()works the same way internally.algis the RFC 8879 number, or 0 for every algorithm the library has, matchingSSL_CTX_compress_certs(). LibreSSL, BoringSSL/AWS-LC and OpenSSL < 3.2.0 getat least OpenSSL 3.2.0 required but found ....The Lua API
ngx.ssl.compress_certs()is in openresty/lua-resty-core#540.Verification
nginx 1.31.6 with this module against an OpenSSL 3.5.4 configured with
zlib-dynamic, certificate installed from Lua, observed withopenssl s_client -trace:ssl_certificate_compression on;aloneCertificate, Length=1566ssl.compress_certs("zlib")CompressedCertificate, Length=1396Tests
t/194-ssl-cert-compression.tcovers the dynamic certificate, an unknown algorithm, and compressing with no certificate on the connection. Whether OpenSSL was built with zlib, brotli or zstd is not visible fromnginx -V, so the first block accepts either outcome unlessTEST_NGINX_CERT_COMP_ALGS=1says the library has one; the other two are deterministic everywhere.I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.