summaryrefslogtreecommitdiffhomepage
path: root/src/event/ngx_event_openssl.h (follow)
AgeCommit message (Collapse)AuthorFilesLines
2020-03-10Chacha20 header protection support with BoringSSL.Sergey Kandaurov1-0/+1
BoringSSL lacks EVP for Chacha20. Here we use CRYPTO_chacha_20() instead.
2020-02-28OpenSSL compatibility.Sergey Kandaurov1-0/+4
2020-02-28Initial QUIC support in http.Sergey Kandaurov1-0/+3
2019-12-24SSL: reworked posted next events.Maxim Dounin1-1/+0
Introduced in 9d2ad2fb4423 available bytes handling in SSL relied on connection read handler being overwritten to set the ready flag and the amount of available bytes. This approach is, however, does not work properly when connection read handler is changed, for example, when switching to a next pipelined request, and can result in unexpected connection timeouts, see here: http://mailman.nginx.org/pipermail/nginx-devel/2019-December/012825.html Fix is to introduce ngx_event_process_posted_next() instead, which will set ready and available regardless of how event handler is set.
2019-10-17SSL: available bytes handling (ticket #1431).Maxim Dounin1-0/+1
Added code to track number of bytes available in the socket. This makes it possible to avoid looping for a long time while working with fast enough peer when data are added to the socket buffer faster than we are able to read and process data. When kernel does not provide number of bytes available, it is retrieved using ioctl(FIONREAD) as long as a buffer is filled by SSL_read(). It is assumed that number of bytes returned by SSL_read() is close to the number of bytes read from the socket, as we do not use SSL compression. But even if it is not true for some reason, this is not important, as we post an additional reading event anyway. Note that data can be buffered at SSL layer, and it is not possible to simply stop reading at some point and wait till the event will be reported by the kernel again. This can be only done when there are no data in SSL buffers, and there is no good way to find out if it's the case. Instead of trying to figure out if SSL buffers are empty, this patch introduces events posted for the next event loop iteration - such events will be processed only on the next event loop iteration, after going into the kernel and retrieving additional events. This seems to be simple and reliable approach.
2019-02-25SSL: adjusted session id context with dynamic certificates.Maxim Dounin1-1/+2
Dynamic certificates re-introduce problem with incorrect session reuse (AKA "virtual host confusion", CVE-2014-3616), since there are no server certificates to generate session id context from. To prevent this, session id context is now generated from ssl_certificate directives as specified in the configuration. This approach prevents incorrect session reuse in most cases, while still allowing sharing sessions across multiple machines with ssl_session_ticket_key set as long as configurations are identical.
2019-02-25SSL: passwords support for dynamic certificate loading.Maxim Dounin1-0/+2
Passwords have to be copied to the configuration pool to be used at runtime. Also, to prevent blocking on stdin (with "daemon off;") an empty password list is provided. To make things simpler, password handling was modified to allow an empty array (with 0 elements and elts set to NULL) as an equivalent of an array with 1 empty password.
2019-02-25SSL: loading of connection-specific certificates.Maxim Dounin1-0/+4
2018-12-18SSL: avoid reading on pending SSL_write_early_data().Sergey Kandaurov1-0/+1
If SSL_write_early_data() returned SSL_ERROR_WANT_WRITE, stop further reading using a newly introduced c->ssl->write_blocked flag, as otherwise this would result in SSL error "ssl3_write_bytes:bad length". Eventually, normal reading will be restored by read event posted from successful SSL_write_early_data(). While here, place "SSL_write_early_data: want write" debug on the path.
2018-09-21SSL: support for TLSv1.3 early data with OpenSSL.Sergey Kandaurov1-0/+5
In collaboration with Maxim Dounin.
2018-08-10SSL: fixed build with LibreSSL 2.8.0 (ticket #1605).Maxim Dounin1-0/+4
LibreSSL 2.8.0 "added const annotations to many existing APIs from OpenSSL, making interoperability easier for downstream applications". This includes the const change in the SSL_CTX_sess_set_get_cb() callback function (see 9dd43f4ef67e), which breaks compilation. To fix this, added a condition on how we redefine OPENSSL_VERSION_NUMBER when working with LibreSSL (see 382fc7069e3a). With LibreSSL 2.8.0, we now set OPENSSL_VERSION_NUMBER to 0x1010000fL (OpenSSL 1.1.0), so the appropriate conditions in the code will use "const" as it happens with OpenSSL 1.1.0 and later versions.
2018-08-07SSL: support for TLSv1.3 early data with BoringSSL.Maxim Dounin1-0/+4
Early data AKA 0-RTT mode is enabled as long as "ssl_early_data on" is specified in the configuration (default is off). The $ssl_early_data variable evaluates to "1" if the SSL handshake isn't yet completed, and can be used to set the Early-Data header as per draft-ietf-httpbis-replay-04.
2018-07-17SSL: save sessions for upstream peers using a callback function.Sergey Kandaurov1-1/+7
In TLSv1.3, NewSessionTicket messages arrive after the handshake and can come at any time. Therefore we use a callback to save the session when we know about it. This approach works for < TLSv1.3 as well. The callback function is set once per location on merge phase. Since SSL_get_session() in BoringSSL returns an unresumable session for TLSv1.3, peer save_session() methods have been updated as well to use a session supplied within the callback. To preserve API, the session is cached in c->ssl->session. It is preferably accessed in save_session() methods by ngx_ssl_get_session() and ngx_ssl_get0_session() wrappers.
2017-10-11SSL: include <openssl/hmac.h>.Alessandro Ghedini1-0/+1
This header carries the definition of HMAC_Init_ex(). In OpenSSL this header is included by <openssl/ssl.h>, but it's not so in BoringSSL. It's probably a good idea to explicitly include this header anyway, regardless of whether it's included by other headers or not.
2017-08-22SSL: the $ssl_client_escaped_cert variable (ticket #857).Maxim Dounin1-0/+2
This variable contains URL-encoded client SSL certificate. In contrast to $ssl_client_cert, it doesn't depend on deprecated header continuation. The NGX_ESCAPE_URI_COMPONENT variant of encoding is used, so the resulting variable can be safely used not only in headers, but also as a request argument. The $ssl_client_cert variable should be considered deprecated now. The $ssl_client_raw_cert variable will be eventually renambed back to $ssl_client_cert.
2017-04-18SSL: disabled renegotiation detection in client mode.Sergey Kandaurov1-0/+5
CVE-2009-3555 is no longer relevant and mitigated by the renegotiation info extension (secure renegotiation). On the other hand, unexpected renegotiation still introduces potential security risks, and hence we do not allow renegotiation on the server side, as we never request renegotiation. On the client side the situation is different though. There are backends which explicitly request renegotiation, and disabled renegotiation introduces interoperability problems. This change allows renegotiation on the client side, and fixes interoperability problems as observed with such backends (ticket #872). Additionally, with TLSv1.3 the SSL_CB_HANDSHAKE_START flag is currently set by OpenSSL when receiving a NewSessionTicket message, and was detected by nginx as a renegotiation attempt. This looks like a bug in OpenSSL, though this change also allows better interoperability till the problem is fixed.
2017-04-18SSL: added support for TLSv1.3 in ssl_protocols directive.Sergey Kandaurov1-0/+1
Support for the TLSv1.3 protocol will be introduced in OpenSSL 1.1.1.
2016-12-23SSL: support AES256 encryption of tickets.Maxim Dounin1-2/+3
This implies ticket key size of 80 bytes instead of previously used 48, as both HMAC and AES keys are 32 bytes now. When an old 48-byte ticket key is provided, we fall back to using backward-compatible AES128 encryption. OpenSSL switched to using AES256 in 1.1.0, and we are providing equivalent security. While here, order of HMAC and AES keys was reverted to make the implementation compatible with keys used by OpenSSL with SSL_CTX_set_tlsext_ticket_keys(). Prodded by Christian Klinger.
2016-12-05SSL: $ssl_curves (ticket #1088).Maxim Dounin1-0/+2
The variable contains a list of curves as supported by the client. Known curves are listed by their names, unknown ones are shown in hex, e.g., "0x001d:prime256v1:secp521r1:secp384r1". Note that OpenSSL uses session data for SSL_get1_curves(), and it doesn't store full list of curves supported by the client when serializing a session. As a result $ssl_curves is only available for new sessions (and will be empty for reused ones). The variable is only meaningful when using OpenSSL 1.0.2 and above. With older versions the variable is empty.
2016-12-05SSL: $ssl_ciphers (ticket #870).Maxim Dounin1-0/+2
The variable contains list of ciphers as supported by the client. Known ciphers are listed by their names, unknown ones are shown in hex, e.g., ""AES128-SHA:AES256-SHA:0x00ff". The variable is fully supported only when using OpenSSL 1.0.2 and above. With older version there is an attempt to provide some information using SSL_get_shared_ciphers(). It only lists known ciphers though. Moreover, as OpenSSL uses session data for SSL_get_shared_ciphers(), and it doesn't store relevant data when serializing a session. As a result $ssl_ciphers is only available for new sessions (and not available for reused ones) when using OpenSSL older than 1.0.2.
2016-12-05SSL: $ssl_client_v_start, $ssl_client_v_end, $ssl_client_v_remain.Maxim Dounin1-0/+6
2016-12-05OCSP stapling: added certificate name to warnings.Maxim Dounin1-0/+1
2016-10-21SSL: RFC2253 compliant $ssl_client_s_dn and $ssl_client_i_dn.Dmitry Volyntsev1-0/+4
Originally, the variables kept a result of X509_NAME_oneline(), which is, according to the official documentation, a legacy function. It produces a non standard output form and has various quirks and inconsistencies. The RFC2253 compliant behavior is introduced for these variables. The original variables are available through $ssl_client_s_dn_legacy and $ssl_client_i_dn_legacy.
2016-10-10Modules compatibility: compatibility with NGX_HTTP_SSL.Maxim Dounin1-4/+4
With this change it is now possible to load modules compiled without the "--with-http_ssl_module" configure option into nginx binary compiled with it, and vice versa (if a module doesn't use ssl-specific functions), assuming both use the "--with-compat" option.
2016-06-15SSL: ngx_ssl_ciphers() to set list of ciphers.Tim Taubert1-0/+2
This patch moves various OpenSSL-specific function calls into the OpenSSL module and introduces ngx_ssl_ciphers() to make nginx more crypto-library-agnostic.
2016-05-19SSL: support for multiple certificates (ticket #814).Maxim Dounin1-0/+2
2016-05-19SSL: made it possible to iterate though all certificates.Maxim Dounin1-0/+1
A pointer to a previously configured certificate now stored in a certificate. This makes it possible to iterate though all certificates configured in the SSL context. This is now used to configure OCSP stapling for all certificates, and in ngx_ssl_session_id_context(). As SSL_CTX_use_certificate() frees previously loaded certificate of the same type, and we have no way to find out if it's the case, X509_free() calls are now posponed till ngx_ssl_cleanup_ctx(). Note that in OpenSSL 1.0.2+ this can be done without storing things in exdata using the SSL_CTX_set_current_cert() and SSL_CTX_get0_certificate() functions. These are not yet available in all supported versions though, so it's easier to continue to use exdata for now.
2016-03-31SSL: SSLeay_version() is deprecated in OpenSSL 1.1.0.Maxim Dounin1-0/+11
SSLeay_version() and SSLeay() are no longer available if OPENSSL_API_COMPAT is set to 0x10100000L. Switched to using OpenSSL_version() instead. Additionally, we now compare version strings instead of version numbers, and this correctly works for LibreSSL as well.
2016-03-31SSL: reasonable version for LibreSSL.Maxim Dounin1-0/+6
LibreSSL defines OPENSSL_VERSION_NUMBER to 0x20000000L, but uses an old API derived from OpenSSL at the time LibreSSL forked. As a result, every version check we use to test for new API elements in newer OpenSSL versions requires an explicit check for LibreSSL. To reduce clutter, redefine OPENSSL_VERSION_NUMBER to 0x1000107fL if LibreSSL is used. The same is done by FreeBSD port of LibreSSL.
2015-10-19SSL: preserve default server context in connection (ticket #235).Maxim Dounin1-0/+1
This context is needed for shared sessions cache to work in configurations with multiple virtual servers sharing the same port. Unfortunately, OpenSSL does not provide an API to access the session context, thus storing it separately. In collaboration with Vladimir Homutov.
2014-10-28Core: added limit to recv_chain().Roman Arutyunyan1-1/+1
2014-07-28SSL: fix build with OPENSSL_NO_ENGINE and/or OPENSSL_NO_OCSP.Piotr Sikora1-0/+4
This is really just a prerequisite for building against BoringSSL, which doesn't provide either of those features. Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2014-07-06SSL: include correct OpenSSL headers.Piotr Sikora1-0/+7
Previously, <bn.h>, <dh.h>, <rand.h> and <rsa.h> were pulled in by <engine.h> using OpenSSL's deprecated interface, which meant that nginx couldn't have been built with -DOPENSSL_NO_DEPRECATED. Both <x509.h> and <x509v3.h> are pulled in by <ocsp.h>, but we're calling X509 functions directly, so let's include those as well. <crypto.h> is pulled in by virtually everything, but we're calling CRYPTO_add() directly, so let's include it as well. Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2014-06-16SSL: the "ssl_password_file" directive.Valentin Bartenev1-1/+2
2014-05-20SSL: $ssl_client_fingerprint variable.Sergey Budnevitch1-0/+2
2014-04-18Upstream: proxy_ssl_verify and friends.Maxim Dounin1-0/+2
2014-04-18SSL: $ssl_server_name variable.Maxim Dounin1-0/+2
2014-02-11SSL: the $ssl_session_reused variable.Maxim Dounin1-0/+2
2013-12-20SSL: ssl_buffer_size directive.Maxim Dounin1-0/+2
2013-10-11SSL: added ability to set keys used for Session Tickets (RFC5077).Piotr Sikora1-0/+13
In order to support key rollover, ssl_session_ticket_key can be defined multiple times. The first key will be used to issue and resume Session Tickets, while the rest will be used only to resume them. ssl_session_ticket_key session_tickets/current.key; ssl_session_ticket_key session_tickets/prev-1h.key; ssl_session_ticket_key session_tickets/prev-2h.key; Please note that nginx supports Session Tickets even without explicit configuration of the keys and this feature should be only used in setups where SSL traffic is distributed across multiple nginx servers. Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2013-09-27SSL: adjust buffer used by OpenSSL during handshake (ticket #413).Maxim Dounin1-0/+1
2013-05-21Style: replace SSL *ssl with ngx_ssl_conn_t *ssl_conn.Piotr Sikora1-1/+2
No functional changes. Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2012-10-03SSL: the "ssl_verify_client" directive parameter "optional_no_ca".Maxim Dounin1-0/+7
This parameter allows to don't require certificate to be signed by a trusted CA, e.g. if CA certificate isn't known in advance, like in WebID protocol. Note that it doesn't add any security unless the certificate is actually checked to be trusted by some external means (e.g. by a backend). Patch by Mike Kazantsev, Eric O'Connor.
2012-10-01OCSP stapling: ssl_stapling_verify directive.Maxim Dounin1-1/+1
OCSP response verification is now switched off by default to simplify configuration, and the ssl_stapling_verify allows to switch it on. Note that for stapling OCSP response verification isn't something required as it will be done by a client anyway. But doing verification on a server allows to mitigate some attack vectors, most notably stop an attacker from presenting some specially crafted data to all site clients.
2012-10-01OCSP stapling: loading OCSP responses.Maxim Dounin1-1/+6
This includes the ssl_stapling_responder directive (defaults to OCSP responder set in certificate's AIA extension). OCSP response for a given certificate is requested once we get at least one connection with certificate_status extension in ClientHello, and certificate status won't be sent in the connection in question. This due to limitations in the OpenSSL API (certificate status callback is blocking). Note: SSL_CTX_use_certificate_chain_file() was reimplemented as it doesn't allow to access the certificate loaded via SSL_CTX.
2012-10-01OCSP stapling: ssl_stapling_file support.Maxim Dounin1-0/+2
Very basic version without any OCSP responder query code, assuming valid DER-encoded OCSP response is present in a ssl_stapling_file configured. Such file might be produced with openssl like this: openssl ocsp -issuer root.crt -cert domain.crt -respout domain.staple \ -url http://ocsp.example.com
2012-10-01OCSP stapling: ssl_trusted_certificate directive.Maxim Dounin1-0/+2
The directive allows to specify additional trusted Certificate Authority certificates to be used during certificate verification. In contrast to ssl_client_certificate DNs of these cerificates aren't sent to a client during handshake. Trusted certificates are loaded regardless of the fact whether client certificates verification is enabled as the same certificates will be used for OCSP stapling, during construction of an OCSP request and for verification of an OCSP response. The same applies to a CRL (which is now always loaded).
2012-01-18Copyright updated.Maxim Konovalov1-0/+1
2012-01-11Added support for TLSv1.1, TLSv1.2 in ssl_protocols directive.Maxim Dounin1-3/+5
Support for TLSv1.1 and TLSv1.2 protocols was introduced in OpenSSL 1.0.1 (-beta1 was recently released). This change makes it possible to disable these protocols and/or enable them without other protocols.
2011-08-04A new fix for the case when ssl_session_cache defined, but ssl is notIgor Sysoev1-0/+1
enabled in any server. The previous r1033 does not help when unused zone becomes used after reconfiguration, so it is backed out. The initial thought was to make SSL modules independed from SSL implementation and to keep OpenSSL code dependance as much as in separate files.