summaryrefslogtreecommitdiffhomepage
path: root/src/event/quic/ngx_event_quic_ssl.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2025-05-23QUIC: using QUIC API introduced in OpenSSL 3.5.Sergey Kandaurov1-45/+366
Similarly to the QUIC API originated in BoringSSL, this API allows to register custom TLS callbacks for an external QUIC implementation. See the SSL_set_quic_tls_cbs manual page for details. Due to a different approach used in OpenSSL 3.5, handling of CRYPTO frames was streamlined to always write an incoming CRYPTO buffer to the crypto context. Using SSL_provide_quic_data(), this results in transient allocation of chain links and buffers for CRYPTO frames received in order. Testing didn't reveal performance degradation of QUIC handshakes, https://github.com/nginx/nginx/pull/646 provides specific results.
2025-05-23QUIC: better approach for premature handshake completion.Sergey Kandaurov1-1/+1
Using SSL_in_init() to inspect a handshake state was replaced with SSL_is_init_finished(). This represents a more complete fix to the BoringSSL issue addressed in 22671b37e. This provides awareness of the early data handshake state when using OpenSSL 3.5 TLS callbacks in 0-RTT enabled configurations, which, in particular, is used to avoid premature completion of the initial TLS handshake, before required client handshake messages are received. This is a non-functional change when using BoringSSL. It supersedes testing non-positive SSL_do_handshake() results in all supported SSL libraries, hence simplified. In preparation for using OpenSSL 3.5 TLS callbacks.
2025-05-23QUIC: ssl_encryption_level_t abstraction layer.Sergey Kandaurov1-27/+71
Encryption level values are decoupled from ssl_encryption_level_t, which is now limited to BoringSSL QUIC callbacks, with mappings provided. Although the values match, this provides a technically safe approach, in particular, to access protection level sized arrays. In preparation for using OpenSSL 3.5 TLS callbacks.
2025-05-23QUIC: factored out SSL_provide_quic_data() to the helper function.Sergey Kandaurov1-17/+36
It is now called from ngx_quic_handle_crypto_frame(), prior to proceeding with the handshake. With this logic removed, the handshake function is renamed to ngx_quic_handshake() to better match ngx_ssl_handshake().
2025-05-23QUIC: defined SSL API macros in a single place.Sergey Kandaurov1-10/+3
All definitions now set in ngx_event_quic.h, this includes moving NGX_QUIC_OPENSSL_COMPAT from autotests to compile time. Further, to improve code readability, a new NGX_QUIC_QUICTLS_API macro is used for QuicTLS that provides old BoringSSL QUIC API.
2025-05-23QUIC: logging missing mandatory TLS extensions only once.Sergey Kandaurov1-8/+15
Previously, they might be logged on every add_handshake_data callback invocation when using OpenSSL compat layer and processing coalesced handshake messages. Further, the ALPN error message is adjusted to signal the missing extension. Possible reasons were previously narrowed down with ebb6f7d65 changes in the ALPN callback that is invoked earlier in the handshake.
2025-05-23QUIC: reset qc->error to zero again.Sergey Kandaurov1-1/+1
Following the previous change that removed posting a close event in OpenSSL compat layer, now ngx_quic_close_connection() is always called on error path with either NGX_ERROR or qc->error set. This allows to remove a special value -1 served as a missing error, which simplifies the code. Partially reverts d3fb12d77. Also, this improves handling of the draining connection state, which consists of posting a close event with NGX_OK and no qc->error set, where it was previously converted to NGX_QUIC_ERR_INTERNAL_ERROR. Notably, this is rather a cosmetic fix, because drained connections do not send any packets including CONNECTION_CLOSE, and qc->error is not otherwise used.
2025-05-23QUIC: adjusted handling of callback errors.Sergey Kandaurov1-10/+17
Changed handshake callbacks to always return success. This allows to avoid logging SSL_do_handshake() errors with empty or cryptic "internal error" OpenSSL error messages at the inappropriate "crit" log level. Further, connections with failed callbacks are closed now right away when using OpenSSL compat layer. This change supersedes and reverts c37fdcdd1, with the conditions to check callbacks invocation kept to slightly improve code readability of control flow; they are optimized out in the resulting assembly code.
2025-05-23QUIC: logging of SSL library errors.Sergey Kandaurov1-4/+4
Logging level for such errors, which should not normally happen, is changed to NGX_LOG_ALERT, and ngx_log_error() is replaced with ngx_ssl_error() for consistency with the rest of the code.
2025-05-23QUIC: logging level of handshake errors.Sergey Kandaurov1-1/+1
Various errors reported by SSL_do_handshake() are now logged at the "info" or "crit" level, akin to handshakes on regular TCP connections.
2025-05-23QUIC: removed ALPN feature test.Sergey Kandaurov1-8/+2
ALPN support is present in all libraries that have QUIC support, it is safe to compile it unconditionally.
2025-05-23QUIC: removed excessive casts for ngx_ssl_get_connection().Sergey Kandaurov1-6/+6
They were blindly copied from ngx_ssl_info_callback(), where the ngx_ssl_conn_t pointer is passed with const qualifier.
2024-05-28QUIC: ignore CRYPTO frames after handshake completion.Roman Arutyunyan1-0/+5
Sending handshake-level CRYPTO frames after the client's Finished message could lead to memory disclosure and a potential segfault, if those frames are sent in one packet with the Finished frame.
2023-08-31QUIC: split keys availability checks to read and write sides.Sergey Kandaurov1-1/+1
Keys may be released by TLS stack in different times, so it makes sense to check this independently as well. This allows to fine-tune what key direction is used when checking keys availability. When discarding, server keys are now marked in addition to client keys.
2023-09-01QUIC: removed use of SSL_quic_read_level and SSL_quic_write_level.Sergey Kandaurov1-17/+7
As explained in BoringSSL change[1], levels were introduced in the original QUIC API to draw a line between when keys are released and when are active. In the new QUIC API they are released in separate calls when it's needed. BoringSSL has then a consideration to remove levels API, hence the change. If not available e.g. from a QUIC packet header, levels can be taken based on keys availability. The only real use of levels is to prevent using app keys before they are active in QuicTLS that provides the old BoringSSL QUIC API, it is replaced with an equivalent check of c->ssl->handshaked. This change also removes OpenSSL compat shims since they are no longer used. The only exception left is caching write level from the keylog callback in the internal field which is a handy equivalent of checking keys availability. [1] https://boringssl.googlesource.com/boringssl/+/1e859054
2023-08-25QUIC: posted generating TLS Key Update next keys.Sergey Kandaurov1-3/+1
Since at least f9fbeb4ee0de and certainly after 924882f42dea, which TLS Key Update support predates, queued data output is deferred to a posted push handler. To address timing signals after these changes, generating next keys is now posted to run after the push handler.
2023-08-14QUIC: path MTU discovery.Roman Arutyunyan1-0/+2
MTU selection starts by doubling the initial MTU until the first failure. Then binary search is used to find the path MTU.
2023-02-22QUIC: OpenSSL compatibility layer.Roman Arutyunyan1-3/+10
The change allows to compile QUIC with OpenSSL which lacks BoringSSL QUIC API. This implementation does not support 0-RTT.
2023-02-23QUIC: improved ssl_reject_handshake error logging.Sergey Kandaurov1-0/+8
The check follows the ngx_ssl_handshake() change in 59e1c73fe02b.
2023-02-23QUIC: using ngx_ssl_handshake_log().Sergey Kandaurov1-5/+3
2023-02-23QUIC: moved "handshake failed" reason to send_alert.Sergey Kandaurov1-1/+1
A QUIC handshake failure breaks down into several cases: - a handshake error which leads to a send_alert call - an error triggered by the add_handshake_data callback - internal errors (allocation etc) Previously, in the first case, only error code was set in the send_alert callback. Now the "handshake failed" reason phrase is set there as well. In the second case, both code and reason are set by add_handshake_data. In the last case, setting reason phrase is removed: returning NGX_ERROR now leads to closing the connection with just INTERNAL_ERROR. Reported by Jiuzhou Cui.
2023-02-23QUIC: using NGX_QUIC_ERR_CRYPTO macro in ALPN checks.Sergey Kandaurov1-1/+1
Patch by Jiuzhou Cui.
2023-01-31QUIC: ngx_quic_copy_buffer() function.Roman Arutyunyan1-21/+2
The function copies passed data to QUIC buffer chain and returns it. The chain can be used in ngx_quic_frame_t data field.
2023-01-10QUIC: relocated ngx_quic_init_streams() for 0-RTT.Roman Arutyunyan1-13/+9
Previously, streams were initialized in early keys handler. However, client transport parameters may not be available by then. This happens, for example, when using QuicTLS. Now streams are initialized in ngx_quic_crypto_input() after calling SSL_do_handshake() for both 0-RTT and 1-RTT.
2022-11-22QUIC: avoid using C99 designated initializers.Sergey Kandaurov1-20/+20
They are not supported by MSVC till 2012. SSL_QUIC_METHOD initialization is moved to run-time to preserve portability among SSL library implementations, which allows to reduce its visibility. Note using of a static storage to keep SSL_set_quic_method() reference valid.
2022-10-20QUIC: removed compatibility with older BoringSSL API.Sergey Kandaurov1-8/+4
SSL_CIPHER_get_protocol_id() appeared in BoringSSL somewhere between BORINGSSL_API_VERSION 12 and 13 for compatibility with OpenSSL 1.1.1. It was adopted without a proper macro test, which remained unnoticed. This justifies that such old BoringSSL API isn't widely used and its support can be dropped. While here, removed SSL_set_quic_use_legacy_codepoint() that became useless after the default was flipped in BoringSSL over a year ago.
2022-10-20QUIC: support for setting QUIC methods with LibreSSL.Sergey Kandaurov1-9/+9
Setting QUIC methods is converted to use C99 designated initializers for simplicity, as LibreSSL 3.6.0 has different SSL_QUIC_METHOD layout. Additionally, only set_read_secret/set_write_secret callbacks are set. Although they are preferred in LibreSSL over set_encryption_secrets, better be on a safe side as LibreSSL has unexpectedly incompatible set_encryption_secrets calling convention expressed in passing read and write secrets split in separate calls, unlike this is documented in old BoringSSL sources. To avoid introducing further changes for the old API, it is simply disabled.
2022-10-20QUIC: using SSL_set_quic_early_data_enabled() only with QuicTLS.Sergey Kandaurov1-1/+1
This function is present in QuicTLS only. After SSL_READ_EARLY_DATA_SUCCESS became visible in LibreSSL together with experimental QUIC API, this required to revise the conditional compilation test to use more narrow macros.
2022-07-27QUIC: avoided pool usage in ngx_quic_protection.c.Vladimir Homutov1-4/+4
2022-02-16QUIC: fixed indentation.Sergey Kandaurov1-8/+8
2022-02-14QUIC: eliminated ngx_quic_copy_buf().Roman Arutyunyan1-4/+25
Its only call is substituted with QUIC buffer write/read pair.
2022-02-14QUIC: ngx_quic_buffer_t object.Roman Arutyunyan1-37/+13
The object is used instead of ngx_chain_t pointer for buffer operations like ngx_quic_write_chain() and ngx_quic_read_chain(). These functions are renamed to ngx_quic_write_buffer() and ngx_quic_read_buffer().
2022-02-01QUIC: do not declare SSL buffering, it's not used.Sergey Kandaurov1-1/+1
No functional changes.
2022-01-27QUIC: limited SSL_set_quic_use_legacy_codepoint() API usage.Sergey Kandaurov1-1/+1
As advertised in BoringSSL a1d3bfb64fd7ef2cb178b5b515522ffd75d7b8c5, it may be dropped once callers implementing the draft versions cycle out.
2022-01-26QUIC: set to standard TLS codepoint after draft versions removal.Sergey Kandaurov1-1/+1
This is to ease transition with oldish BoringSSL versions, the default for SSL_set_quic_use_legacy_codepoint() has been flipped in BoringSSL a1d3bfb64fd7ef2cb178b5b515522ffd75d7b8c5.
2022-01-19QUIC: reworked migration handling.Vladimir Homutov1-3/+6
The quic connection now holds active, backup and probe paths instead of sockets. The number of migration paths is now limited and cannot be inflated by a bad client or an attacker. The client id is now associated with path rather than socket. This allows to simplify processing of output and connection ids handling. New migration abandons any previously started migrations. This allows to free consumed client ids and request new for use in future migrations and make progress in case when connection id limit is hit during migration. A path now can be revalidated without losing its state. The patch also fixes various issues with NAT rebinding case handling: - paths are now validated (previously, there was no validation and paths were left in limited state) - attempt to reuse id on different path is now again verified (this was broken in 40445fc7c403) - former path is now validated in case of apparent migration
2022-01-13QUIC: return written size from ngx_quic_write_chain().Roman Arutyunyan1-1/+1
This allows to escape calculating it before calling the function.
2021-12-16QUIC: renamed buffer-related functions.Roman Arutyunyan1-3/+3
ngx_quic_alloc_buf() -> ngx_quic_alloc_chain(), ngx_quic_free_bufs() -> ngx_quic_free_chain(), ngx_quic_trim_bufs() -> ngx_quic_trim_chain()
2021-12-24QUIC: refactored ngx_quic_order_bufs() and ngx_quic_split_bufs().Roman Arutyunyan1-2/+8
They are replaced with ngx_quic_write_chain() and ngx_quic_read_chain(). These functions represent the API to data buffering. The first function adds data of given size at given offset to the buffer. Now it returns the unwritten part of the chain similar to c->send_chain(). The second function returns data of given size from the beginning of the buffer. Its second argument and return value are swapped compared to ngx_quic_split_bufs() to better match ngx_quic_write_chain(). Added, returned and stored data are regular ngx_chain_t/ngx_buf_t chains. Missing data is marked with b->sync flag. The functions are now used in both send and recv data chains in QUIC streams.
2021-12-24QUIC: avoid excessive buffer allocations in stream output.Roman Arutyunyan1-1/+1
Previously, when a few bytes were send to a QUIC stream by the application, a 4K buffer was allocated for these bytes. Then a STREAM frame was created and that entire buffer was used as data for that frame. The frame with the buffer were in use up until the frame was acked by client. Meanwhile, when more bytes were send to the stream, more buffers were allocated and assigned as data to newer STREAM frames. In this scenario most buffer memory is unused. Now the unused part of the stream output buffer is available for further stream output while earlier parts of the buffer are waiting to be acked. This is achieved by splitting the output buffer.
2021-12-07QUIC: converted ngx_quic_keys_set_encryption_secret() to NGX codes.Sergey Kandaurov1-6/+18
While here, removed check for encryption level zero, redundant by its nature.
2021-11-30QUIC: ngx_quic_send_alert() callback moved to its place.Sergey Kandaurov1-0/+28
2021-11-03QUIC: connections with wrong ALPN protocols are now rejected.Vladimir Homutov1-12/+13
Previously, it was not enforced in the stream module. Now, since b9e02e9b2f1d it is possible to specify protocols. Since ALPN is always required, the 'require_alpn' setting is now obsolete.
2021-10-26QUIC: speeding up processing 0-RTT.Sergey Kandaurov1-2/+18
After fe919fd63b0b, processing QUIC streams was postponed until after handshake completion, which means that 0-RTT is effectively off. With ssl_ocsp enabled, it could be further delayed. This differs from how OCSP validation works with SSL_read_early_data(). With this change, processing QUIC streams is unlocked when obtaining 0-RTT secret.
2021-10-26QUIC: refactored OCSP validation in preparation for 0-RTT support.Sergey Kandaurov1-11/+1
2021-09-27Configure: check for QUIC 0-RTT support at compile time.Ruslan Ermilov1-1/+1
2021-09-09QUIC: macro style.Ruslan Ermilov1-1/+1
2021-08-24QUIC: removed duplicate logging of Stateless Reset Token.Sergey Kandaurov1-4/+0
2021-08-04QUIC: client certificate validation with OCSP.Sergey Kandaurov1-0/+14
2021-06-16QUIC: updated specification references.Sergey Kandaurov1-7/+10
This includes updating citations and further clarification.