summaryrefslogtreecommitdiffhomepage
path: root/src/event
diff options
context:
space:
mode:
authorSergey Kandaurov <pluknet@nginx.com>2025-07-09 19:02:09 +0400
committerpluknet <pluknet@nginx.com>2025-08-03 19:15:16 +0400
commit251444fcf4434bfddbe3394a568c51d4f7bd857f (patch)
tree0ce5a7855799986f3370c93aba5a2cf8cf43134f /src/event
parented99269eed283e474590bbe951bad1d74b721955 (diff)
downloadnginx-251444fcf4434bfddbe3394a568c51d4f7bd857f.tar.gz
nginx-251444fcf4434bfddbe3394a568c51d4f7bd857f.tar.bz2
SSL: support for compressed server certificates with OpenSSL.
The ssl_certificate_compression directive allows to send compressed server certificates. In OpenSSL, they are pre-compressed on startup. To simplify configuration, the SSL_OP_NO_TX_CERTIFICATE_COMPRESSION option is automatically cleared if certificates were pre-compressed. SSL_CTX_compress_certs() may return an error in legitimate cases, e.g., when none of compression algorithms is available or if the resulting compressed size is larger than the original one, thus it is silently ignored. Certificate compression is supported in Chrome with brotli only, in Safari with zlib only, and in Firefox with all listed algorithms. It is supported since Ubuntu 24.10, which has OpenSSL with enabled zlib and zstd support. The actual list of algorithms supported in OpenSSL depends on how the library was configured; it can be brotli, zlib, zstd as listed in RFC 8879.
Diffstat (limited to 'src/event')
-rw-r--r--src/event/ngx_event_openssl.c30
-rw-r--r--src/event/ngx_event_openssl.h2
2 files changed, 32 insertions, 0 deletions
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
index 0c23c3f2f..e36f30c74 100644
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -665,6 +665,36 @@ retry:
ngx_int_t
+ngx_ssl_certificate_compression(ngx_conf_t *cf, ngx_ssl_t *ssl,
+ ngx_uint_t enable)
+{
+ if (!enable) {
+ return NGX_OK;
+ }
+
+#ifdef SSL_OP_NO_TX_CERTIFICATE_COMPRESSION
+
+ if (SSL_CTX_compress_certs(ssl->ctx, 0) == 0) {
+ ngx_ssl_error(NGX_LOG_WARN, ssl->log, 0,
+ "SSL_CTX_compress_certs() failed, ignored");
+ return NGX_OK;
+ }
+
+ SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TX_CERTIFICATE_COMPRESSION);
+
+#else
+
+ ngx_log_error(NGX_LOG_WARN, ssl->log, 0,
+ "\"ssl_certificate_compression\" is not supported "
+ "on this platform, ignored");
+
+#endif
+
+ return NGX_OK;
+}
+
+
+ngx_int_t
ngx_ssl_ciphers(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *ciphers,
ngx_uint_t prefer_server_ciphers)
{
diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h
index 0c9e9e840..e7ccd51e8 100644
--- a/src/event/ngx_event_openssl.h
+++ b/src/event/ngx_event_openssl.h
@@ -236,6 +236,8 @@ ngx_int_t ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
ngx_int_t ngx_ssl_connection_certificate(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *cert, ngx_str_t *key, ngx_ssl_cache_t *cache,
ngx_array_t *passwords);
+ngx_int_t ngx_ssl_certificate_compression(ngx_conf_t *cf, ngx_ssl_t *ssl,
+ ngx_uint_t enable);
ngx_int_t ngx_ssl_ciphers(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *ciphers,
ngx_uint_t prefer_server_ciphers);