comparison src/event/quic/ngx_event_quic_ssl.c @ 9157:daf8f5ba23d8

QUIC: removed use of SSL_quic_read_level and SSL_quic_write_level. 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
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 01 Sep 2023 20:31:46 +0400
parents 2880f60a80c3
children ff98ae7d261e
comparison
equal deleted inserted replaced
9156:36b59521a41c 9157:daf8f5ba23d8
41 static int ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn, 41 static int ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
42 enum ssl_encryption_level_t level, const uint8_t *data, size_t len); 42 enum ssl_encryption_level_t level, const uint8_t *data, size_t len);
43 static int ngx_quic_flush_flight(ngx_ssl_conn_t *ssl_conn); 43 static int ngx_quic_flush_flight(ngx_ssl_conn_t *ssl_conn);
44 static int ngx_quic_send_alert(ngx_ssl_conn_t *ssl_conn, 44 static int ngx_quic_send_alert(ngx_ssl_conn_t *ssl_conn,
45 enum ssl_encryption_level_t level, uint8_t alert); 45 enum ssl_encryption_level_t level, uint8_t alert);
46 static ngx_int_t ngx_quic_crypto_input(ngx_connection_t *c, ngx_chain_t *data); 46 static ngx_int_t ngx_quic_crypto_input(ngx_connection_t *c, ngx_chain_t *data,
47 enum ssl_encryption_level_t level);
47 48
48 49
49 #if (NGX_QUIC_BORINGSSL_API) 50 #if (NGX_QUIC_BORINGSSL_API)
50 51
51 static int 52 static int
352 353
353 return NGX_OK; 354 return NGX_OK;
354 } 355 }
355 356
356 if (f->offset == ctx->crypto.offset) { 357 if (f->offset == ctx->crypto.offset) {
357 if (ngx_quic_crypto_input(c, frame->data) != NGX_OK) { 358 if (ngx_quic_crypto_input(c, frame->data, pkt->level) != NGX_OK) {
358 return NGX_ERROR; 359 return NGX_ERROR;
359 } 360 }
360 361
361 ngx_quic_skip_buffer(c, &ctx->crypto, last); 362 ngx_quic_skip_buffer(c, &ctx->crypto, last);
362 363
370 } 371 }
371 372
372 cl = ngx_quic_read_buffer(c, &ctx->crypto, (uint64_t) -1); 373 cl = ngx_quic_read_buffer(c, &ctx->crypto, (uint64_t) -1);
373 374
374 if (cl) { 375 if (cl) {
375 if (ngx_quic_crypto_input(c, cl) != NGX_OK) { 376 if (ngx_quic_crypto_input(c, cl, pkt->level) != NGX_OK) {
376 return NGX_ERROR; 377 return NGX_ERROR;
377 } 378 }
378 379
379 ngx_quic_free_chain(c, cl); 380 ngx_quic_free_chain(c, cl);
380 } 381 }
382 return NGX_OK; 383 return NGX_OK;
383 } 384 }
384 385
385 386
386 static ngx_int_t 387 static ngx_int_t
387 ngx_quic_crypto_input(ngx_connection_t *c, ngx_chain_t *data) 388 ngx_quic_crypto_input(ngx_connection_t *c, ngx_chain_t *data,
389 enum ssl_encryption_level_t level)
388 { 390 {
389 int n, sslerr; 391 int n, sslerr;
390 ngx_buf_t *b; 392 ngx_buf_t *b;
391 ngx_chain_t *cl; 393 ngx_chain_t *cl;
392 ngx_ssl_conn_t *ssl_conn; 394 ngx_ssl_conn_t *ssl_conn;
395 397
396 qc = ngx_quic_get_connection(c); 398 qc = ngx_quic_get_connection(c);
397 399
398 ssl_conn = c->ssl->connection; 400 ssl_conn = c->ssl->connection;
399 401
400 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
401 "quic SSL_quic_read_level:%d SSL_quic_write_level:%d",
402 (int) SSL_quic_read_level(ssl_conn),
403 (int) SSL_quic_write_level(ssl_conn));
404
405 for (cl = data; cl; cl = cl->next) { 402 for (cl = data; cl; cl = cl->next) {
406 b = cl->buf; 403 b = cl->buf;
407 404
408 if (!SSL_provide_quic_data(ssl_conn, SSL_quic_read_level(ssl_conn), 405 if (!SSL_provide_quic_data(ssl_conn, level, b->pos, b->last - b->pos)) {
409 b->pos, b->last - b->pos))
410 {
411 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, 406 ngx_ssl_error(NGX_LOG_INFO, c->log, 0,
412 "SSL_provide_quic_data() failed"); 407 "SSL_provide_quic_data() failed");
413 return NGX_ERROR; 408 return NGX_ERROR;
414 } 409 }
415 } 410 }
416 411
417 n = SSL_do_handshake(ssl_conn); 412 n = SSL_do_handshake(ssl_conn);
418
419 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
420 "quic SSL_quic_read_level:%d SSL_quic_write_level:%d",
421 (int) SSL_quic_read_level(ssl_conn),
422 (int) SSL_quic_write_level(ssl_conn));
423 413
424 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_do_handshake: %d", n); 414 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_do_handshake: %d", n);
425 415
426 if (n <= 0) { 416 if (n <= 0) {
427 sslerr = SSL_get_error(ssl_conn, n); 417 sslerr = SSL_get_error(ssl_conn, n);