summaryrefslogtreecommitdiffhomepage
path: root/src/event/quic/ngx_event_quic_output.c
diff options
context:
space:
mode:
authorSergey Kandaurov <pluknet@nginx.com>2023-10-20 18:05:07 +0400
committerSergey Kandaurov <pluknet@nginx.com>2023-10-20 18:05:07 +0400
commitfffd2823ba8bddcdfdffca47990c73cd4298208d (patch)
tree70bc64d02ec35c04a9386b95579912bf44463e0f /src/event/quic/ngx_event_quic_output.c
parentcd5f4cd8d3991414167a734f452e8e3fe98f3916 (diff)
downloadnginx-fffd2823ba8bddcdfdffca47990c73cd4298208d.tar.gz
nginx-fffd2823ba8bddcdfdffca47990c73cd4298208d.tar.bz2
QUIC: added safety belt to prevent using discarded keys.
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.
Diffstat (limited to 'src/event/quic/ngx_event_quic_output.c')
-rw-r--r--src/event/quic/ngx_event_quic_output.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/event/quic/ngx_event_quic_output.c b/src/event/quic/ngx_event_quic_output.c
index 587671bc6..bd3e7e3b0 100644
--- a/src/event/quic/ngx_event_quic_output.c
+++ b/src/event/quic/ngx_event_quic_output.c
@@ -519,6 +519,21 @@ ngx_quic_output_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx,
qc = ngx_quic_get_connection(c);
+ if (!ngx_quic_keys_available(qc->keys, ctx->level, 1)) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0, "quic %s write keys discarded",
+ ngx_quic_level_name(ctx->level));
+
+ while (!ngx_queue_empty(&ctx->frames)) {
+ q = ngx_queue_head(&ctx->frames);
+ ngx_queue_remove(q);
+
+ f = ngx_queue_data(q, ngx_quic_frame_t, queue);
+ ngx_quic_free_frame(c, f);
+ }
+
+ return 0;
+ }
+
ngx_quic_init_packet(c, ctx, &pkt, qc->path);
min_payload = ngx_quic_payload_size(&pkt, min);