summaryrefslogtreecommitdiffhomepage
path: root/src/event (follow)
AgeCommit message (Collapse)AuthorFilesLines
2024-11-25QUIC: prevented BIO leak in case of error.Roman Arutyunyan1-0/+1
2024-11-22SSL: a new macro to set default protocol versions.Sergey Kandaurov1-0/+7
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-20Fixed missing double quote.Nathan Mentze1-1/+1
2024-11-19SSL: error message default in object caching API.Sergey Kandaurov1-0/+4
This change initializes the "err" variable, used to produce a meaningful diagnostics on error path, to a good safe value.
2024-10-08QUIC: prevent deleted stream frame retransmissions.nandsky1-7/+6
Since a2a513b93cae, stream frames no longer need to be retransmitted after it was deleted. The frames which were retransmitted before, could be stream data frames sent prior to a RESET_STREAM. Such retransmissions are explicitly prohibited by RFC 9000, Section 19.4.
2024-10-01SSL: caching CA certificates.Sergey Kandaurov3-28/+185
This can potentially provide a large amount of savings, because CA certificates can be quite large. Based on previous work by Mini Hawthorne.
2024-10-01SSL: caching CRLs.Sergey Kandaurov3-17/+164
Based on previous work by Mini Hawthorne.
2024-10-01SSL: caching certificate keys.Sergey Kandaurov3-151/+172
EVP_KEY objects are a reference-counted container for key material, shallow copies and OpenSSL stack management aren't needed as with certificates. Based on previous work by Mini Hawthorne.
2024-10-01SSL: caching certificates.Sergey Kandaurov3-102/+173
Certificate chains are now loaded once. The certificate cache provides each chain as a unique stack of reference counted elements. This shallow copy is required because OpenSSL stacks aren't reference counted. Based on previous work by Mini Hawthorne.
2024-10-01SSL: object caching.Sergey Kandaurov2-0/+316
Added ngx_openssl_cache_module, which indexes a type-aware object cache. It maps an id to a unique instance, and provides references to it, which are dropped when the cycle's pool is destroyed. The cache will be used in subsequent patches. Based on previous work by Mini Hawthorne.
2024-10-01SSL: moved certificate storage out of exdata.Sergey Kandaurov3-66/+89
Instead of cross-linking the objects using exdata, pointers to configured certificates are now stored in ngx_ssl_t, and OCSP staples are now accessed with rbtree in it. This allows sharing these objects between SSL contexts. Based on previous work by Mini Hawthorne.
2024-09-24Fixed a typo of bpf makefile debug option.tzssangglass1-1/+1
2024-08-09QUIC: zero out existing keying material only.Sergey Kandaurov1-6/+23
Previously, this used to have extra ngx_explicit_memzero() calls from within ngx_quic_keys_cleanup(), which might be suboptimal.
2024-08-09QUIC: discarding 0-RTT keys.Sergey Kandaurov1-0/+10
For simplicity, this is done on successful decryption of a 1-RTT packet.
2024-05-28QUIC: ngx_quic_buffer_t use-after-free protection.Roman Arutyunyan1-0/+1
Previously the last chain field of ngx_quic_buffer_t could still reference freed chains and buffers after calling ngx_quic_free_buffer(). While normally an ngx_quic_buffer_t object should not be used after freeing, resetting last_chain field would prevent a potential use-after-free.
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.
2024-05-28QUIC: client transport parameter data length checking.Sergey Kandaurov1-0/+8
2024-05-03SSL: fixed possible configuration overwrite loading "engine:" keys.Sergey Kandaurov1-2/+2
When loading certificate keys via ENGINE_load_private_key() in runtime, it was possible to overwrite configuration on ENGINE_by_id() failure. OpenSSL documention doesn't describe errors in details, the only reason I found in the comment to example is when the engine is not available.
2024-04-10QUIC: fixed close timer processing with early data.Vladimir Khomutov1-1/+4
The ngx_quic_run() function uses qc->close timer to limit the handshake duration. Normally it is removed by ngx_quic_do_init_streams() which is called once when we are done with initial SSL processing. The problem happens when the client sends early data and streams are initialized in the ngx_quic_run() -> ngx_quic_handle_datagram() call. The order of set/remove timer calls is now reversed; the close timer is set up and the timer fires when assigned, starting the unexpected connection close process. The fix is to skip setting the timer if streams were initialized during handling of the initial datagram. The idle timer for quic is set anyway, and stream-related timeouts are managed by application layer.
2024-02-14QUIC: fixed stream cleanup (ticket #2586).Roman Arutyunyan1-0/+1
Stream connection cleanup handler ngx_quic_stream_cleanup_handler() calls ngx_quic_shutdown_stream() after which it resets the pointer from quic stream to the connection (sc->connection = NULL). Previously if this call failed, sc->connection retained the old value, while the connection was freed by the application code. This resulted later in a second attempt to close the freed connection, which lead to allocator double free error. The fix is to reset the sc->connection pointer in case of error.
2024-02-14QUIC: trial packet decryption in response to invalid key update.Sergey Kandaurov1-2/+13
Inspired by RFC 9001, Section 6.3, trial packet decryption with the current keys is now used to avoid a timing side-channel signal. Further, this fixes segfault while accessing missing next keys (ticket #2585).
2024-02-14QUIC: fixed unsent MTU probe acknowledgement.Roman Arutyunyan1-7/+12
Previously if an MTU probe send failed early in ngx_quic_frame_sendto() due to allocation error or congestion control, the application level packet number was not increased, but was still saved as MTU probe packet number. Later when a packet with this number was acknowledged, the unsent MTU probe was acknowledged as well. This could result in discovering a bigger MTU than supported by the path, which could lead to EMSGSIZE (Message too long) errors while sending further packets. The problem existed since PMTUD was introduced in 58afcd72446f (1.25.2). Back then only the unlikely memory allocation error could trigger it. However in efcdaa66df2e congestion control was added to ngx_quic_frame_sendto() which can now trigger the issue with a higher probability.
2024-01-30SSL: fixed $ssl_curves allocation error handling.Sergey Kandaurov1-0/+3
2024-01-30Upstream: fixed usage of closed sockets with filter finalization.Maxim Dounin1-2/+6
When filter finalization is triggered when working with an upstream server, and error_page redirects request processing to some simple handler, ngx_http_request_finalize() triggers request termination when the response is sent. In particular, via the upstream cleanup handler, nginx will close the upstream connection and the corresponding socket. Still, this can happen to be with ngx_event_pipe() on stack. While the code will set p->downstream_error due to NGX_ERROR returned from the output filter chain by filter finalization, otherwise the error will be ignored till control returns to ngx_http_upstream_process_request(). And event pipe might try reading from the (already closed) socket, resulting in "readv() failed (9: Bad file descriptor) while reading upstream" errors (or even segfaults with SSL). Such errors were seen with the following configuration: location /t2 { proxy_pass http://127.0.0.1:8080/big; image_filter_buffer 10m; image_filter resize 150 100; error_page 415 = /empty; } location /empty { return 204; } location /big { # big enough static file } Fix is to clear p->upstream in ngx_http_upstream_finalize_request(), and ensure that p->upstream is checked in ngx_event_pipe_read_upstream() and when handling events at ngx_event_pipe() exit.
2023-12-25SSL: reasonable version for LibreSSL adjusted.Sergey Kandaurov2-2/+2
OPENSSL_VERSION_NUMBER is now redefined to 0x1010000fL for LibreSSL 3.5.0 and above. Building with older LibreSSL versions, such as 2.8.0, may now produce warnings (see cab37803ebb3) and may require appropriate compiler options to suppress them. Notably, this allows to start using SSL_get0_verified_chain() appeared in OpenSSL 1.1.0 and LibreSSL 3.5.0, without additional macro tests. Prodded by Ilya Shipitsin.
2023-12-25SSL: disabled renegotiation checks with LibreSSL.Sergey Kandaurov1-7/+8
Similar to 7356:e3ba4026c02d, as long as SSL_OP_NO_CLIENT_RENEGOTIATION is defined, it is the library responsibility to prevent renegotiation. Additionally, this allows to raise LibreSSL version used to redefine OPENSSL_VERSION_NUMBER to 0x1010000fL, such that this won't result in attempts to dereference SSL objects made opaque in LibreSSL 3.4.0. Patch by Maxim Dounin.
2023-12-16QUIC: fixed format specifier after a6f79f044de5.Sergey Kandaurov1-1/+1
2023-12-12QUIC: path aware in-flight bytes accounting.Sergey Kandaurov3-0/+16
On-packet acknowledgement is made path aware, as per RFC 9000, Section 9.4: Packets sent on the old path MUST NOT contribute to congestion control or RTT estimation for the new path. To make this possible in a single congestion control context, the first packet to be sent after the new path has been validated, which includes resetting the congestion controller and RTT estimator, is now remembered in the connection. Packets sent previously, such as on the old path, are not taken into account. Note that although the packet number is saved per-connection, the added checks affect application level packets only. For non-application level packets, which are only processed prior to the handshake is complete, the remembered packet number remains set to zero.
2023-12-12QUIC: reset RTT estimator for the new path.Sergey Kandaurov3-8/+10
RTT is a property of the path, it must be reset on confirming a peer's ownership of its new address.
2023-11-29QUIC: path revalidation after expansion failure.Roman Arutyunyan2-4/+19
As per RFC 9000, Section 8.2.1: When an endpoint is unable to expand the datagram size to 1200 bytes due to the anti-amplification limit, the path MTU will not be validated. To ensure that the path MTU is large enough, the endpoint MUST perform a second path validation by sending a PATH_CHALLENGE frame in a datagram of at least 1200 bytes.
2023-11-30QUIC: ngx_quic_frame_t time fields cleanup.Roman Arutyunyan3-25/+24
The field "first" is removed. It's unused since 909b989ec088. The field "last" is renamed to "send_time". It holds frame send time.
2023-11-29QUIC: congestion control in ngx_quic_frame_sendto().Roman Arutyunyan4-40/+107
Previously ngx_quic_frame_sendto() ignored congestion control and did not contribute to in_flight counter. Now congestion control window is checked unless ignore_congestion flag is set. Also, in_flight counter is incremented and the frame is stored in ctx->sent queue if it's ack-eliciting. This behavior is now similar to ngx_quic_output_packet().
2023-11-22QUIC: ignore duplicate PATH_CHALLENGE frames.Roman Arutyunyan2-0/+9
According to RFC 9000, an endpoint SHOULD NOT send multiple PATH_CHALLENGE frames in a single packet. The change adds a check to enforce this claim to optimize server behavior. Previously each PATH_CHALLENGE always resulted in a single response datagram being sent to client. The effect of this was however limited by QUIC flood protection. Also, PATH_CHALLENGE is explicitly disabled in Initial and Handshake levels, see RFC 9000, Table 3. However, technically it may be sent by client in 0-RTT over a new path without actual migration, even though the migration itself is prohibited during handshake. This allows client to coalesce multiple 0-RTT packets each carrying a PATH_CHALLENGE and end up with multiple PATH_CHALLENGEs per datagram. This again leads to suboptimal behavior, see above. Since the purpose of sending PATH_CHALLENGE frames in 0-RTT is unclear, these frames are now only allowed in 1-RTT. For 0-RTT they are silently ignored.
2023-11-22QUIC: fixed anti-amplification with explicit send.Roman Arutyunyan2-8/+22
Previously, when using ngx_quic_frame_sendto() to explicitly send a packet with a single frame, anti-amplification limit was not properly enforced. Even when there was no quota left for the packet, it was sent anyway, but with no padding. Now the packet is not sent at all. This function is called to send PATH_CHALLENGE/PATH_RESPONSE, PMTUD and probe packets. For all these cases packet send is retried later in case the send was not successful.
2023-11-29QUIC: avoid partial expansion of PATH_CHALLENGE/PATH_RESPONSE.Roman Arutyunyan4-29/+31
By default packets with these frames are expanded to 1200 bytes. Previously, if anti-amplification limit did not allow this expansion, it was limited to whatever size was allowed. However RFC 9000 clearly states no partial expansion should happen in both cases. Section 8.2.1. Initiating Path Validation: An endpoint MUST expand datagrams that contain a PATH_CHALLENGE frame to at least the smallest allowed maximum datagram size of 1200 bytes, unless the anti-amplification limit for the path does not permit sending a datagram of this size. Section 8.2.2. Path Validation Responses: An endpoint MUST expand datagrams that contain a PATH_RESPONSE frame to at least the smallest allowed maximum datagram size of 1200 bytes. ... However, an endpoint MUST NOT expand the datagram containing the PATH_RESPONSE if the resulting data exceeds the anti-amplification limit.
2023-10-26QUIC: improved packet and frames debug tracing.Vladimir Khomutov3-16/+32
Currently, packets generated by ngx_quic_frame_sendto() and ngx_quic_send_early_cc() are not logged, thus making it hard to read logs due to gaps appearing in packet numbers sequence. At frames level, it is handy to see immediately packet number in which they arrived or being sent.
2023-10-20QUIC: explicitly zero out unused keying material.Sergey Kandaurov2-9/+22
2023-10-20QUIC: removed key field from ngx_quic_secret_t.Sergey Kandaurov3-29/+47
It is made local as it is only needed now when creating crypto context. BoringSSL lacks EVP interface for ChaCha20, providing instead a function for one-shot encryption, thus hp is still preserved. Based on a patch by Roman Arutyunyan.
2023-10-20QUIC: simplified ngx_quic_ciphers() API.Sergey Kandaurov3-15/+9
After conversion to reusable crypto ctx, now there's enough caller context to remove the "level" argument from ngx_quic_ciphers().
2023-10-20QUIC: cleaned up now unused ngx_quic_ciphers() calls.Sergey Kandaurov2-34/+16
2023-10-20QUIC: reusing crypto contexts for header protection.Sergey Kandaurov2-28/+75
2023-10-20QUIC: common code for crypto open and seal operations.Sergey Kandaurov1-76/+63
2023-10-20QUIC: reusing crypto contexts for packet protection.Sergey Kandaurov5-121/+213
2023-10-20QUIC: renamed protection functions.Sergey Kandaurov3-15/+16
Now these functions have names ngx_quic_crypto_XXX(): - ngx_quic_tls_open() -> ngx_quic_crypto_open() - ngx_quic_tls_seal() -> ngx_quic_crypto_seal() - ngx_quic_tls_hp() -> ngx_quic_crypto_hp()
2023-10-20QUIC: prevented generating ACK frames with discarded keys.Sergey Kandaurov1-0/+4
Previously it was possible to generate ACK frames using formally discarded protection keys, in particular, when acknowledging a client Handshake packet used to complete the TLS handshake and to discard handshake protection keys. As it happens late in packet processing, it could be possible to generate ACK frames after the keys were already discarded. ACK frames are generated from ngx_quic_ack_packet(), either using a posted push event, which envolves ngx_quic_generate_ack() as a part of the final packet assembling, or directly in ngx_quic_ack_packet(), such as when there is no room to add a new ACK range or when the received packet is out of order. The added keys availability check is used to avoid generating late ACK frames in both cases.
2023-10-20QUIC: added safety belt to prevent using discarded keys.Sergey Kandaurov1-0/+15
In addition to triggering alert, it ensures that such packets won't be sent. With the previous change that marks server keys as discarded by zeroing the key lengh, it is now an error to send packets with discarded keys. OpenSSL based stacks tolerate such behaviour because key length isn't used in packet protection, but BoringSSL will raise the UNSUPPORTED_KEY_SIZE cipher error. It won't be possible to use discarded keys with reused crypto contexts as it happens in subsequent changes.
2023-08-31QUIC: split keys availability checks to read and write sides.Sergey Kandaurov4-7/+14
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-22QUIC: handle callback errors in compat.Vladimir Khomutov1-2/+12
The error may be triggered in add_handhshake_data() by incorrect transport parameter sent by client. The expected behaviour in this case is to close connection complaining about incorrect parameter. Currently the connection just times out.
2023-09-14QUIC: simplified setting close timer when closing connection.Roman Arutyunyan1-1/+1
Previously, the timer was never reset due to an explicit check. The check was added in 36b59521a41c as part of connection close simplification. The reason was to retain the earliest timeout. However, the timeouts are all the same while QUIC handshake is in progress and resetting the timer for the same value has no performance implications. After handshake completion there's only application level. The change removes the check.
2023-09-21QUIC: do not call shutdown() when handshake is in progress.Roman Arutyunyan1-1/+1
Instead, when worker is shutting down and handshake is not yet completed, connection is terminated immediately. Previously the callback could be called while QUIC handshake was in progress and, what's more important, before the init() callback. Now it's postponed after init(). This change is a preparation to postponing HTTP/3 session creation to init().