summaryrefslogtreecommitdiffhomepage
path: root/src/stream (follow)
AgeCommit message (Collapse)AuthorFilesLines
2025-12-01Add basic ECH shared-mode via OpenSSL.sftcd2-0/+22
2025-11-26Improved host header validation.Sergey Kandaurov1-32/+133
Validation is rewritten to follow RFC 3986 host syntax, based on ngx_http_parse_request_line(). The following is now rejected: - the rest of gen-delims "#", "?", "@", "[", "]" - other unwise delims <">, "<", ">", "\", "^", "`', "{", "|", "}" - IP literals with a trailing dot, missing closing bracket, or pct-encoded - a port subcomponent with invalid values - characters in upper half
2025-11-10SSL: ngx_ssl_set_client_hello_callback() error handling.Sergey Kandaurov1-1/+3
The function interface is changed to follow a common approach to other functions used to setup SSL_CTX, with an exception of "ngx_conf_t *cf" since it is not bound to nginx configuration. This is required to report and propagate SSL_CTX_set_ex_data() errors, as reminded by Coverity (CID 1668589).
2025-10-27OCSP: fixed invalid type for the 'ssl_ocsp' directive.Roman Semenov1-1/+1
2025-10-24Geo: the "volatile" parameter.Dmitry Plotnikov1-0/+12
Similar to map's volatile parameter, creates a non-cacheable geo variable.
2025-10-24SSL: $ssl_sigalg, $ssl_client_sigalg.Sergey Kandaurov1-0/+6
Variables contain the IANA name of the signature scheme[1] used to sign the TLS handshake. Variables are only meaningful when using OpenSSL 3.5 and above, with older versions they are empty. Moreover, since this data isn't stored in a serialized session, variables are only available for new sessions. [1] https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml Requested by willmafh.
2025-10-24Upstream: reset local address in case of error.Roman Arutyunyan1-0/+2
After f10bc5a763bb the address was set to NULL only when local address was not specified at all. In case complex value evaluated to an empty or invalid string, local address remained unchanged. Currenrly this is not a problem since the value is only set once. This change is a preparation for being able to change the local address after initial setting.
2025-10-08SSL: disabled using certificate compression with OCSP stapling.Sergey Kandaurov1-1/+7
OCSP response in TLSv1.3 is sent in the Certificate message. This is incompatible with pre-compression of the configured certificates.
2025-09-25SNI: support for early ClientHello callback with BoringSSL.Sergey Kandaurov1-0/+5
This brings feature parity with OpenSSL after the previous change, making it possible to set SSL protocols per virtual server.
2025-09-25SNI: using the ClientHello callback.Sergey Kandaurov1-35/+33
The change introduces an SNI based virtual server selection during early ClientHello processing. The callback is available since OpenSSL 1.1.1; for older OpenSSL versions, the previous behaviour is kept. Using the ClientHello callback sets a reasonable processing order for the "server_name" TLS extension. Notably, session resumption decision now happens after applying server configuration chosen by SNI, useful with enabled verification of client certificates, which brings consistency with BoringSSL behaviour. The change supersedes and reverts a fix made in 46b9f5d38 for TLSv1.3 resumed sessions. In addition, since the callback is invoked prior to the protocol version negotiation, this makes it possible to set "ssl_protocols" on a per-virtual server basis. To keep the $ssl_server_name variable working with TLSv1.2 resumed sessions, as previously fixed in fd97b2a80, a limited server name callback is preserved in order to acknowledge the extension. Note that to allow third-party modules to properly chain the call to ngx_ssl_client_hello_callback(), the servername callback function is passed through exdata.
2025-08-03SSL: support for compressed server certificates with OpenSSL.Sergey Kandaurov2-0/+19
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.
2025-04-10Upstream: fixed passwords support for dynamic certificates.Sergey Kandaurov1-10/+58
Passwords were not preserved in optimized SSL contexts, the bug had appeared in d791b4aab (1.23.1), as in the following configuration: server { proxy_ssl_password_file password; proxy_ssl_certificate $ssl_server_name.crt; proxy_ssl_certificate_key $ssl_server_name.key; location /original/ { proxy_pass https://u1/; } location /optimized/ { proxy_pass https://u2/; } } The fix is to always preserve passwords, by copying to the configuration pool, if dynamic certificates are used. This is done as part of merging "ssl_passwords" configuration. To minimize the number of copies, a preserved version is then used for inheritance. A notable exception is inheritance of preserved empty passwords to the context with statically configured certificates: server { proxy_ssl_certificate $ssl_server_name.crt; proxy_ssl_certificate_key $ssl_server_name.key; location / { proxy_pass ...; proxy_ssl_certificate example.com.crt; proxy_ssl_certificate_key example.com.key; } } In this case, an unmodified version (NULL) of empty passwords is set, to allow reading them from the password prompt on nginx startup. As an additional optimization, a preserved instance of inherited configured passwords is set to the previous level, to inherit it to other contexts: server { proxy_ssl_password_file password; location /1/ { proxy_pass https://u1/; proxy_ssl_certificate $ssl_server_name.crt; proxy_ssl_certificate_key $ssl_server_name.key; } location /2/ { proxy_pass https://u2/; proxy_ssl_certificate $ssl_server_name.crt; proxy_ssl_certificate_key $ssl_server_name.key; } }
2025-02-26SSL: removed stale comments.Sergey Kandaurov1-2/+0
It appears to be a relic from prototype locking removed in b0b7b5a35.
2025-02-26SSL: improved logging of saving sessions from upstream servers.Sergey Kandaurov1-3/+3
This makes it easier to understand why sessions may not be saved in shared memory due to size.
2025-02-26SSL: using static storage for NGX_SSL_MAX_SESSION_SIZE buffers.Sergey Kandaurov1-6/+4
All such transient buffers are converted to the single storage in BSS. In preparation to raise the limit.
2025-02-05SNI: added restriction for TLSv1.3 cross-SNI session resumption.Sergey Kandaurov1-2/+25
In OpenSSL, session resumption always happens in the default SSL context, prior to invoking the SNI callback. Further, unlike in TLSv1.2 and older protocols, SSL_get_servername() returns values received in the resumption handshake, which may be different from the value in the initial handshake. Notably, this makes the restriction added in b720f650b insufficient for sessions resumed with different SNI server name. Considering the example from b720f650b, previously, a client was able to request example.org by presenting a certificate for example.org, then to resume and request example.com. The fix is to reject handshakes resumed with a different server name, if verification of client certificates is enabled in a corresponding server configuration.
2025-01-17Upstream: caching certificates and certificate keys with variables.Sergey Kandaurov1-1/+110
Caching is enabled with proxy_ssl_certificate_cache and friends. Co-authored-by: Aleksei Bavshin <a.bavshin@nginx.com>
2025-01-17SSL: caching certificates and certificate keys with variables.Sergey Kandaurov3-33/+142
A new directive "ssl_certificate_cache max=N [valid=time] [inactive=time]" enables caching of SSL certificate chain and secret key objects specified by "ssl_certificate" and "ssl_certificate_key" directives with variables. Co-authored-by: Aleksei Bavshin <a.bavshin@nginx.com>
2024-11-22SSL: a new macro to set default protocol versions.Sergey Kandaurov2-18/+2
This simplifies merging protocol values after ea15896 and ebd18ec. Further, as outlined in ebd18ec18, for libraries preceeding TLSv1.2+ support, only meaningful versions TLSv1 and TLSv1.1 are set by default. While here, fixed indentation.
2024-11-11SSL: fixed MSVC compilation after ebd18ec1812b.蕭澧邦2-4/+12
MSVC generates a compilation error in case #if/#endif is used in a macro parameter.
2024-11-07Upstream: copy upstream zone DNS valid time during config reload.Mini Hawthorne2-1/+12
Previously, all upstream DNS entries would be immediately re-resolved on config reload. With a large number of upstreams, this creates a spike of DNS resolution requests. These spikes can overwhelm the DNS server or cause drops on the network. This patch retains the TTL of previous resolutions across reloads by copying each upstream's name's expiry time across configuration cycles. As a result, no additional resolutions are needed.
2024-11-07Upstream: per-upstream resolver.Vladimir Homutov2-6/+58
The "resolver" and "resolver_timeout" directives can now be specified directly in the "upstream" block.
2024-11-07Upstream: pre-resolve servers on reload.Ruslan Ermilov1-7/+194
After configuration is reloaded, it may take some time for the re-resolvable upstream servers to resolve and become available as peers. During this time, client requests might get dropped. Such servers are now pre-resolved using the "cache" of already resolved peers from the old shared memory zone.
2024-11-07Upstream: construct upstream peers from DNS SRV records.Dmitry Volyntsev5-35/+213
2024-11-07Upstream: re-resolvable servers.Ruslan Ermilov9-28/+847
Specifying the upstream server by a hostname together with the "resolve" parameter will make the hostname to be periodically resolved, and upstream servers added/removed as necessary. This requires a "resolver" at the "http" configuration block. The "resolver_timeout" parameter also affects when the failed DNS requests will be attempted again. Responses with NXDOMAIN will be attempted again in 10 seconds. Upstream has a configuration generation number that is incremented each time servers are added/removed to the primary/backup list. This number is remembered by the peer.init method, and if peer.get detects a change in configuration, it returns NGX_BUSY. Each server has a reference counter. It is incremented by peer.get and decremented by peer.free. When a server is removed, it is removed from the list of servers and is marked as "zombie". The memory allocated by a zombie peer is freed only when its reference count becomes zero. Co-authored-by: Roman Arutyunyan <arut@nginx.com> Co-authored-by: Sergey Kandaurov <pluknet@nginx.com> Co-authored-by: Vladimir Homutov <vl@nginx.com>
2024-10-31SSL: disabled TLSv1 and TLSv1.1 by default.Sergey Kandaurov2-0/+4
TLSv1 and TLSv1.1 are formally deprecated and forbidden to negotiate due to insufficient security reasons outlined in RFC 8996. TLSv1 and TLSv1.1 are disabled in BoringSSL e95b0cad9 and LibreSSL 3.8.1 in the way they cannot be enabled in nginx configuration. In OpenSSL 3.0, they are only permitted at security level 0 (disabled by default). The support is dropped in Chrome 84, Firefox 78, and deprecated in Safari. This change disables TLSv1 and TLSv1.1 by default for OpenSSL 1.0.1 and newer, where TLSv1.2 support is available. For older library versions, which do not have alternatives, these protocol versions remain enabled.
2024-09-20SSL: optional ssl_client_certificate for ssl_verify_client.Sergey Kandaurov1-2/+6
Starting from TLSv1.1 (as seen since draft-ietf-tls-rfc2246-bis-00), the "certificate_authorities" field grammar of the CertificateRequest message was redone to allow no distinguished names. In TLSv1.3, with the restructured CertificateRequest message, this can be similarly done by optionally including the "certificate_authorities" extension. This allows to avoid sending DNs at all. In practice, aside from published TLS specifications, all supported SSL/TLS libraries allow to request client certificates with an empty DN list for any protocol version. For instance, when operating in TLSv1, this results in sending the "certificate_authorities" list as a zero-length vector, which corresponds to the TLSv1.1 specification. Such behaviour goes back to SSLeay. The change relaxes the requirement to specify at least one trusted CA certificate in the ssl_client_certificate directive, which resulted in sending DNs of these certificates (closes #142). Instead, all trusted CA certificates can be specified now using the ssl_trusted_certificate directive if needed. A notable difference that certificates specified in ssl_trusted_certificate are always loaded remains (see 3648ba7db). Co-authored-by: Praveen Chaudhary <praveenc@nvidia.com>
2024-08-22Stream: OCSP stapling.Sergey Kandaurov2-10/+73
2024-08-22Stream: client certificate validation with OCSP.Sergey Kandaurov2-0/+159
2024-08-09Stream ssl_preread: do not reallocate a parsed SNI host.Sergey Kandaurov1-1/+1
We own this memory from the session pool.
2024-06-27Stream: allow servers with no handler.Roman Arutyunyan1-7/+7
Previously handlers were mandatory. However they are not always needed. For example, a server configured with ssl_reject_handshake does not need a handler. Such servers required a fake handler to pass the check. Now handler absence check is moved to runtime. If handler is missing, the connection is closed with 500 code.
2024-05-03Stream pass: disabled passing from or to udp.Roman Arutyunyan1-0/+9
Passing from udp was not possible for the most part due to preread buffer restriction. Passing to udp could occasionally work, but the connection would still be bound to the original listen rbtree, which prevented it from being deleted on connection closure.
2024-04-11Stream pass: limited the number of passes per connection.Roman Arutyunyan1-0/+51
Previously a cycle in pass configuration resulted in stack overflow.
2024-03-18Fixed undefined behaviour with IPv4-mapped IPv6 addresses.Sergey Kandaurov3-4/+4
Previously, it could result when left-shifting signed integer due to implicit integer promotion, such that the most significant bit appeared on the sign bit. In practice, though, this results in the same left value as with an explicit cast, at least on known compilers, such as GCC and Clang. The reason is that in_addr_t, which is equivalent to uint32_t and same as "unsigned int" in ILP32 and LP64 data type models, has the same type width as the intermediate after integer promotion, so there's no side effects such as sign-extension. This explains why adding an explicit cast does not change object files in practice. Found with UndefinedBehaviorSanitizer (shift). Based on a patch by Piotr Sikora.
2024-03-14Geo: fixed uninitialized memory access.Piotr Sikora1-3/+1
While copying ngx_http_variable_value_t structures to geo binary base in ngx_http_geo_copy_values(), and similarly in the stream module, uninitialized parts of these structures are copied as well. These include the "escape" field and possible holes. Calculating crc32 of this data triggers uninitialized memory access. Found with MemorySanitizer. Signed-off-by: Piotr Sikora <piotr@aviatrix.com>
2024-03-22Stream: $server_name.Sergey Kandaurov1-0/+23
2024-01-18Stream: moved fastopen compatibility check.Roman Arutyunyan1-6/+6
The move makes the code look similar to the corresponding code in http module.
2024-03-22Stream: the "setfib" parameter of the "listen" directive.Sergey Kandaurov3-0/+26
The FreeBSD SO_SETFIB support.
2024-03-22Stream: the "accept_filter" parameter of the "listen" directive.Sergey Kandaurov3-0/+28
The FreeBSD accept filters support.
2024-03-22Stream: the "deferred" parameter of the "listen" directive.Sergey Kandaurov3-0/+24
The Linux TCP_DEFER_ACCEPT support.
2024-03-22Stream: reshuffled ngx_stream_listen_opt_t fields.Sergey Kandaurov1-6/+7
In preparation for adding more parameters to the listen directive, and to be in sync with the corresponding structure in the http module. No functional changes.
2024-03-22Overhauled some diagnostic messages akin to 1b05b9bbcebf.Sergey Kandaurov1-2/+2
2024-03-22Stream: using ngx_stream_ssl_srv_conf_t *sscf naming convention.Sergey Kandaurov2-98/+98
Originally, the stream module was developed based on the mail module, following the existing style. Then it was diverged to closely follow the http module development. This change updates style to use sscf naming convention troughout the stream module, which matches the http module code style. No functional changes.
2024-02-21Stream: ngx_stream_pass_module.Roman Arutyunyan1-0/+276
The module allows to pass connections from Stream to other modules such as HTTP or Mail, as well as back to Stream. Previously, this was only possible with proxying. Connections with preread buffer read out from socket cannot be passed. The module allows selective SSL termination based on SNI. stream { server { listen 8000 default_server; ssl_preread on; ... } server { listen 8000; server_name foo.example.com; pass 127.0.0.1:8001; # to HTTP } server { listen 8000; server_name bar.example.com; ... } } http { server { listen 8001 ssl; ... location / { root html; } } }
2023-12-14Stream: virtual servers.Roman Arutyunyan7-354/+1416
Server name is taken either from ngx_stream_ssl_module or ngx_stream_ssl_preread_module. The change adds "default_server" parameter to the "listen" directive, as well as the following directives: "server_names_hash_max_size", "server_names_hash_bucket_size", "server_name" and "ssl_reject_handshake".
2023-12-13Stream: socket peek in preread phase.Roman Arutyunyan1-43/+146
Previously, preread buffer was always read out from socket, which made it impossible to terminate SSL on the connection without introducing additional SSL BIOs. The following patches will rely on this. Now, when possible, recv(MSG_PEEK) is used instead, which keeps data in socket. It's called if SSL is not already terminated and if an egde-triggered event method is used. For epoll, EPOLLRDHUP support is also required.
2023-03-24SSL: enabled TLSv1.3 by default.Maxim Dounin2-4/+6
2022-12-18Fixed port ranges support in the listen directive.Valentin Bartenev1-1/+1
Ports difference must be respected when checking addresses for duplicates, otherwise configurations like this are broken: listen 127.0.0.1:6000-6005 It was broken by 4cc2bfeff46c (nginx 1.23.3).
2022-12-01SSL: fixed ngx_ssl_recv() to reset c->read->ready after errors.Maxim Dounin1-3/+2
With this change, behaviour of ngx_ssl_recv() now matches ngx_unix_recv(), which used to always reset c->read->ready to 0 when returning errors. This fixes an infinite loop in unbuffered SSL proxying if writing to the client is blocked and an SSL error happens (ticket #2418). With this change, the fix for a similar issue in the stream module (6868:ee3645078759), which used a different approach of explicitly testing c->read->error instead, is no longer needed and was reverted.
2022-11-23Filtering duplicate addresses in listen (ticket #2400).Maxim Dounin1-13/+36
Due to the glibc bug[1], getaddrinfo("localhost") with AI_ADDRCONFIG on a typical host with glibc and without IPv6 returns two 127.0.0.1 addresses, and therefore "listen localhost:80;" used to result in "duplicate ... address and port pair" after 4f9b72a229c1. Fix is to explicitly filter out duplicate addresses returned during resolution of a name. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=14969