diff options
Diffstat (limited to 'src/plugins/quic')
-rw-r--r-- | src/plugins/quic/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/plugins/quic/quic.c | 97 | ||||
-rw-r--r-- | src/plugins/quic/quic.h | 3 | ||||
-rw-r--r-- | src/plugins/quic/quic_crypto.c | 116 | ||||
-rw-r--r-- | src/plugins/quic/quic_crypto.h | 13 |
5 files changed, 150 insertions, 86 deletions
diff --git a/src/plugins/quic/CMakeLists.txt b/src/plugins/quic/CMakeLists.txt index dfed91f51d9..65bdc32a239 100644 --- a/src/plugins/quic/CMakeLists.txt +++ b/src/plugins/quic/CMakeLists.txt @@ -12,8 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +if(NOT OPENSSL_FOUND) + message(WARNING "OpenSSL not found - quic plugin disabled") + return() +endif() + unset(QUIC_LINK_LIBRARIES) -set(EXPECTED_QUICLY_VERSION "0.1.3-vpp") +set(EXPECTED_QUICLY_VERSION "0.1.4-vpp") vpp_find_path(QUICLY_INCLUDE_DIR NAMES quicly.h) vpp_find_path(PICOTLS_INCLUDE_DIR NAMES picotls.h) diff --git a/src/plugins/quic/quic.c b/src/plugins/quic/quic.c index 26f2216a3d8..60d4ac21c19 100644 --- a/src/plugins/quic/quic.c +++ b/src/plugins/quic/quic.c @@ -14,6 +14,9 @@ */ #include <sys/socket.h> +#include <sys/syscall.h> + +#include <openssl/rand.h> #include <vnet/session/application.h> #include <vnet/session/transport.h> @@ -103,7 +106,6 @@ quic_app_cert_key_pair_delete_callback (app_cert_key_pair_t * ckpair) for (i = 0; i < num_threads; i++) { - /* *INDENT-OFF* */ pool_foreach (crctx, qm->wrk_ctx[i].crypto_ctx_pool) { if (crctx->ckpair_index == ckpair->cert_key_index) { @@ -111,7 +113,6 @@ quic_app_cert_key_pair_delete_callback (app_cert_key_pair_t * ckpair) clib_bihash_add_del_24_8 (&qm->wrk_ctx[i].crypto_context_hash, &kv, 0 /* is_add */ ); } } - /* *INDENT-ON* */ } return 0; } @@ -151,11 +152,9 @@ quic_list_crypto_context_command_fn (vlib_main_t * vm, int i, num_threads = 1 /* main thread */ + vtm->n_threads; for (i = 0; i < num_threads; i++) { - /* *INDENT-OFF* */ pool_foreach (crctx, qm->wrk_ctx[i].crypto_ctx_pool) { vlib_cli_output (vm, "[%d][Q]%U", i, format_crypto_context, crctx); } - /* *INDENT-ON* */ } return 0; } @@ -388,7 +387,8 @@ quic_ctx_alloc (u32 thread_index) quic_main_t *qm = &quic_main; quic_ctx_t *ctx; - pool_get (qm->ctx_pool[thread_index], ctx); + pool_get_aligned_safe (qm->ctx_pool[thread_index], ctx, + CLIB_CACHE_LINE_BYTES); clib_memset (ctx, 0, sizeof (quic_ctx_t)); ctx->c_thread_index = thread_index; @@ -675,6 +675,7 @@ quic_send_datagram (session_t *udp_session, struct iovec *packet, hdr.is_ip4 = tc->is_ip4; clib_memcpy (&hdr.lcl_ip, &tc->lcl_ip, sizeof (ip46_address_t)); hdr.lcl_port = tc->lcl_port; + hdr.gso_size = 0; /* Read dest address from quicly-provided sockaddr */ if (hdr.is_ip4) @@ -782,12 +783,10 @@ quic_on_stream_destroy (quicly_stream_t * stream, int err) quic_stream_data_t *stream_data = (quic_stream_data_t *) stream->data; quic_ctx_t *sctx = quic_ctx_get (stream_data->ctx_id, stream_data->thread_index); - session_t *stream_session = session_get (sctx->c_s_index, - sctx->c_thread_index); QUIC_DBG (2, "DESTROYED_STREAM: session 0x%lx (%U)", session_handle (stream_session), quic_format_err, err); - stream_session->session_state = SESSION_STATE_CLOSED; + session_transport_closing_notify (&sctx->connection); session_transport_delete_notify (&sctx->connection); quic_increment_counter (QUIC_ERROR_CLOSED_STREAM, 1); @@ -830,12 +829,13 @@ quic_on_receive (quicly_stream_t * stream, size_t off, const void *src, size_t len) { QUIC_DBG (3, "received data: %lu bytes, offset %lu", len, off); - u32 max_enq, rlen, rv; + u32 max_enq; quic_ctx_t *sctx; session_t *stream_session; app_worker_t *app_wrk; svm_fifo_t *f; quic_stream_data_t *stream_data; + int rlen; if (!len) return; @@ -876,6 +876,14 @@ quic_on_receive (quicly_stream_t * stream, size_t off, const void *src, { /* Streams live on the same thread so (f, stream_data) should stay consistent */ rlen = svm_fifo_enqueue (f, len, (u8 *) src); + if (PREDICT_FALSE (rlen < 0)) + { + /* + * drop, fifo full + * drop, fifo grow + */ + return; + } QUIC_DBG (3, "Session [idx %u, app_wrk %u, ti %u, rx-fifo 0x%llx]: " "Enqueuing %u (rlen %u) at off %u in %u space, ", stream_session->session_index, @@ -886,10 +894,7 @@ quic_on_receive (quicly_stream_t * stream, size_t off, const void *src, app_wrk = app_worker_get_if_valid (stream_session->app_wrk_index); if (PREDICT_TRUE (app_wrk != 0)) { - rv = app_worker_lock_and_send_event (app_wrk, stream_session, - SESSION_IO_EVT_RX); - if (rv) - QUIC_ERR ("Failed to ping app for RX"); + app_worker_rx_notify (app_wrk, stream_session); } quic_ack_rx_data (stream_session); } @@ -898,6 +903,14 @@ quic_on_receive (quicly_stream_t * stream, size_t off, const void *src, rlen = svm_fifo_enqueue_with_offset (f, off - stream_data->app_rx_data_len, len, (u8 *) src); + if (PREDICT_FALSE (rlen < 0)) + { + /* + * drop, fifo full + * drop, fifo grow + */ + return; + } QUIC_ASSERT (rlen == 0); } return; @@ -1031,6 +1044,8 @@ quic_on_stream_open (quicly_stream_open_t * self, quicly_stream_t * stream) stream_session->session_type = session_type_from_proto_and_ip (TRANSPORT_PROTO_QUIC, qctx->udp_is_ip4); quic_session = session_get (qctx->c_s_index, qctx->c_thread_index); + /* Make sure quic session is in listening state */ + quic_session->session_state = SESSION_STATE_LISTENING; stream_session->listener_handle = listen_session_get_handle (quic_session); app_wrk = app_worker_get (stream_session->app_wrk_index); @@ -1044,6 +1059,7 @@ quic_on_stream_open (quicly_stream_open_t * self, quicly_stream_t * stream) SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL | SVM_FIFO_WANT_DEQ_NOTIF_IF_EMPTY); + stream_session->session_state = SESSION_STATE_ACCEPTING; if ((rv = app_worker_accept_notify (app_wrk, stream_session))) { QUIC_ERR ("failed to notify accept worker app"); @@ -1139,9 +1155,8 @@ quic_update_timer (quic_ctx_t * ctx) quic_session = session_get (ctx->c_s_index, ctx->c_thread_index); if (svm_fifo_set_event (quic_session->tx_fifo)) { - rv = session_send_io_evt_to_thread_custom (quic_session, - quic_session->thread_index, - SESSION_IO_EVT_BUILTIN_TX); + rv = session_send_io_evt_to_thread_custom ( + quic_session, quic_session->thread_index, SESSION_IO_EVT_TX); if (PREDICT_FALSE (rv)) QUIC_ERR ("Failed to enqueue builtin_tx %d", rv); } @@ -1277,6 +1292,7 @@ quic_connect_stream (session_t * quic_session, session_endpoint_cfg_t * sep) stream_data->app_rx_data_len = 0; stream_data->app_tx_data_len = 0; stream_session->session_state = SESSION_STATE_READY; + stream_session->opaque = sep->opaque; /* For now we only reset streams. Cleanup will be triggered by timers */ if ((rv = app_worker_init_connected (app_wrk, stream_session))) @@ -1441,7 +1457,8 @@ quic_proto_on_close (u32 ctx_index, u32 thread_index) } static u32 -quic_start_listen (u32 quic_listen_session_index, transport_endpoint_t * tep) +quic_start_listen (u32 quic_listen_session_index, + transport_endpoint_cfg_t *tep) { vnet_listen_args_t _bargs, *args = &_bargs; transport_endpt_crypto_cfg_t *ccfg; @@ -1552,7 +1569,7 @@ format_quic_ctx (u8 * s, va_list * args) if (!ctx) return s; - str = format (str, "[#%d][Q] ", ctx->c_thread_index); + str = format (str, "[%d:%d][Q] ", ctx->c_thread_index, ctx->c_s_index); if (quic_ctx_is_listener (ctx)) str = format (str, "Listener, UDP %ld", ctx->udp_session_handle); @@ -1670,15 +1687,6 @@ quic_on_quic_session_connected (quic_ctx_t * ctx) quic_proto_on_close (ctx_id, thread_index); return; } - - /* If the app opens a stream in its callback it may invalidate ctx */ - ctx = quic_ctx_get (ctx_id, thread_index); - /* - * app_worker_connect_notify() might have reallocated pool, reload - * quic_session pointer - */ - quic_session = session_get (ctx->c_s_index, thread_index); - quic_session->session_state = SESSION_STATE_LISTENING; } static void @@ -2105,7 +2113,6 @@ quic_accept_connection (quic_rx_packet_ctx_t * pctx) quic_session = session_alloc (ctx->c_thread_index); QUIC_DBG (2, "Allocated quic_session, 0x%lx ctx %u", session_handle (quic_session), ctx->c_c_index); - quic_session->session_state = SESSION_STATE_LISTENING; ctx->c_s_index = quic_session->session_index; lctx = quic_ctx_get (ctx->listener_ctx_id, 0); @@ -2131,6 +2138,7 @@ quic_accept_connection (quic_rx_packet_ctx_t * pctx) } app_wrk = app_worker_get (quic_session->app_wrk_index); + quic_session->session_state = SESSION_STATE_ACCEPTING; if ((rv = app_worker_accept_notify (app_wrk, quic_session))) { QUIC_ERR ("failed to notify accept worker app"); @@ -2416,7 +2424,6 @@ quic_get_transport_endpoint (u32 ctx_index, u32 thread_index, quic_common_get_transport_endpoint (ctx, tep, is_lcl); } -/* *INDENT-OFF* */ static session_cb_vft_t quic_app_cb_vft = { .session_accept_callback = quic_udp_session_accepted_callback, .session_disconnect_callback = quic_udp_session_disconnect_callback, @@ -2452,7 +2459,6 @@ static const transport_proto_vft_t quic_proto = { .service_type = TRANSPORT_SERVICE_APP, }, }; -/* *INDENT-ON* */ static quicly_stream_open_t on_stream_open = { quic_on_stream_open }; static quicly_closed_by_remote_t on_closed_by_remote = { @@ -2498,6 +2504,11 @@ quic_init (vlib_main_t * vm) u64 options[APP_OPTIONS_N_OPTIONS]; quic_main_t *qm = &quic_main; u32 num_threads, i; + u8 seed[32]; + + if (syscall (SYS_getrandom, &seed, sizeof (seed), 0) != sizeof (seed)) + return clib_error_return_unix (0, "getrandom() failed"); + RAND_seed (seed, sizeof (seed)); num_threads = 1 /* main thread */ + vtm->n_threads; @@ -2550,6 +2561,7 @@ quic_init (vlib_main_t * vm) transport_register_protocol (TRANSPORT_PROTO_QUIC, &quic_proto, FIB_PROTOCOL_IP6, ~0); + quic_load_openssl3_legacy_provider (); clib_bitmap_alloc (qm->available_crypto_engines, app_crypto_engine_n_types ()); quic_register_cipher_suite (CRYPTO_ENGINE_PICOTLS, @@ -2563,14 +2575,19 @@ quic_init (vlib_main_t * vm) qm->vnet_crypto_enabled = 1; if (qm->vnet_crypto_enabled == 1) { + u8 empty_key[32] = {}; quic_register_cipher_suite (CRYPTO_ENGINE_VPP, quic_crypto_cipher_suites); qm->default_crypto_engine = CRYPTO_ENGINE_VPP; + vec_validate (qm->per_thread_crypto_key_indices, num_threads); + for (i = 0; i < num_threads; i++) + { + qm->per_thread_crypto_key_indices[i] = vnet_crypto_key_add ( + vm, VNET_CRYPTO_ALG_AES_256_CTR, empty_key, 32); + } } qm->max_packets_per_key = DEFAULT_MAX_PACKETS_PER_KEY; - clib_rwlock_init (&qm->crypto_keys_quic_rw_lock); - qm->default_quic_cc = QUIC_CC_RENO; vec_free (a->name); @@ -2651,7 +2668,6 @@ quic_get_counter_value (u32 event_code) u32 code, i; u64 c, sum = 0; - int index = 0; vm = vlib_get_main (); em = &vm->error_main; @@ -2666,7 +2682,6 @@ quic_get_counter_value (u32 event_code) if (i < vec_len (em->counters_last_clear)) c -= em->counters_last_clear[i]; sum += c; - index++; } return sum; } @@ -2683,7 +2698,6 @@ quic_show_aggregated_stats (vlib_main_t * vm) clib_memset (&agg_stats, 0, sizeof (agg_stats)); for (i = 0; i < num_workers + 1; i++) { - /* *INDENT-OFF* */ pool_foreach (ctx, qm->ctx_pool[i]) { if (quic_ctx_is_conn (ctx) && ctx->conn) @@ -2703,7 +2717,6 @@ quic_show_aggregated_stats (vlib_main_t * vm) else if (quic_ctx_is_stream (ctx)) nstream++; } - /* *INDENT-ON* */ } vlib_cli_output (vm, "-------- Connections --------"); vlib_cli_output (vm, "Current: %u", nconn); @@ -2878,7 +2891,6 @@ quic_show_connections_command_fn (vlib_main_t * vm, for (int i = 0; i < num_workers + 1; i++) { - /* *INDENT-OFF* */ pool_foreach (ctx, qm->ctx_pool[i]) { if (quic_ctx_is_stream (ctx) && show_stream) @@ -2888,7 +2900,6 @@ quic_show_connections_command_fn (vlib_main_t * vm, else if (quic_ctx_is_conn (ctx) && show_conn) vlib_cli_output (vm, "%U", quic_format_connection_ctx, ctx); } - /* *INDENT-ON* */ } done: @@ -2896,7 +2907,6 @@ done: return error; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (quic_plugin_crypto_command, static) = { .path = "quic set crypto api", .short_help = "quic set crypto api [picotls|vpp]", @@ -2937,7 +2947,6 @@ VLIB_PLUGIN_REGISTER () = .description = "Quic transport protocol", .default_disabled = 1, }; -/* *INDENT-ON* */ static clib_error_t * quic_config_fn (vlib_main_t * vm, unformat_input_t * input) @@ -2957,7 +2966,7 @@ quic_config_fn (vlib_main_t * vm, unformat_input_t * input) while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "fifo-size %U", unformat_memory_size, &tmp)) + if (unformat (line_input, "fifo-size %U", unformat_memory_size, &tmp)) { if (tmp >= 0x100000000ULL) { @@ -2968,9 +2977,9 @@ quic_config_fn (vlib_main_t * vm, unformat_input_t * input) } qm->udp_fifo_size = tmp; } - else if (unformat (input, "conn-timeout %u", &i)) + else if (unformat (line_input, "conn-timeout %u", &i)) qm->connection_timeout = i; - else if (unformat (input, "fifo-prealloc %u", &i)) + else if (unformat (line_input, "fifo-prealloc %u", &i)) qm->udp_fifo_prealloc = i; else { @@ -2993,7 +3002,6 @@ quic_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, return 0; } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (quic_input_node) = { .function = quic_node_fn, @@ -3003,7 +3011,6 @@ VLIB_REGISTER_NODE (quic_input_node) = .n_errors = ARRAY_LEN (quic_error_strings), .error_strings = quic_error_strings, }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON diff --git a/src/plugins/quic/quic.h b/src/plugins/quic/quic.h index 901bdbc39b2..2c5a21c01a4 100644 --- a/src/plugins/quic/quic.h +++ b/src/plugins/quic/quic.h @@ -263,8 +263,7 @@ typedef struct quic_main_ u32 connection_timeout; u8 vnet_crypto_enabled; - - clib_rwlock_t crypto_keys_quic_rw_lock; + u32 *per_thread_crypto_key_indices; } quic_main_t; #endif /* __included_quic_h__ */ diff --git a/src/plugins/quic/quic_crypto.c b/src/plugins/quic/quic_crypto.c index 602b3f8570c..c5cc5a4a714 100644 --- a/src/plugins/quic/quic_crypto.c +++ b/src/plugins/quic/quic_crypto.c @@ -15,22 +15,31 @@ #include <quic/quic.h> #include <quic/quic_crypto.h> +#include <vnet/session/session.h> #include <quicly.h> #include <picotls/openssl.h> +#include <pthread.h> #define QUICLY_EPOCH_1RTT 3 extern quic_main_t quic_main; -extern quic_ctx_t *quic_get_conn_ctx (quicly_conn_t * conn); +extern quic_ctx_t *quic_get_conn_ctx (quicly_conn_t *conn); vnet_crypto_main_t *cm = &crypto_main; +typedef struct crypto_key_ +{ + vnet_crypto_alg_t algo; + u8 key[32]; + u16 key_len; +} crypto_key_t; + struct cipher_context_t { ptls_cipher_context_t super; vnet_crypto_op_t op; vnet_crypto_op_id_t id; - u32 key_index; + crypto_key_t key; }; struct aead_crypto_context_t @@ -39,7 +48,8 @@ struct aead_crypto_context_t EVP_CIPHER_CTX *evp_ctx; uint8_t static_iv[PTLS_MAX_IV_SIZE]; vnet_crypto_op_t op; - u32 key_index; + crypto_key_t key; + vnet_crypto_op_id_t id; uint8_t iv[PTLS_MAX_IV_SIZE]; }; @@ -114,6 +124,29 @@ Exit: return ret; } +static u32 +quic_crypto_set_key (crypto_key_t *key) +{ + u8 thread_index = vlib_get_thread_index (); + u32 key_id = quic_main.per_thread_crypto_key_indices[thread_index]; + vnet_crypto_key_t *vnet_key = vnet_crypto_get_key (key_id); + vlib_main_t *vm = vlib_get_main (); + vnet_crypto_engine_t *engine; + + vec_foreach (engine, cm->engines) + if (engine->key_op_handler) + engine->key_op_handler (vm, VNET_CRYPTO_KEY_OP_DEL, key_id); + + vnet_key->alg = key->algo; + clib_memcpy (vnet_key->data, key->key, key->key_len); + + vec_foreach (engine, cm->engines) + if (engine->key_op_handler) + engine->key_op_handler (vm, VNET_CRYPTO_KEY_OP_ADD, key_id); + + return key_id; +} + static size_t quic_crypto_aead_decrypt (quic_ctx_t *qctx, ptls_aead_context_t *_ctx, void *_output, const void *input, size_t inlen, @@ -132,7 +165,7 @@ quic_crypto_aead_decrypt (quic_ctx_t *qctx, ptls_aead_context_t *_ctx, decrypted_pn); ctx->op.src = (u8 *) input; ctx->op.dst = _output; - ctx->op.key_index = ctx->key_index; + ctx->op.key_index = quic_crypto_set_key (&ctx->key); ctx->op.len = inlen - ctx->super.algo->tag_size; ctx->op.tag_len = ctx->super.algo->tag_size; ctx->op.tag = ctx->op.src + ctx->op.len; @@ -143,7 +176,7 @@ quic_crypto_aead_decrypt (quic_ctx_t *qctx, ptls_aead_context_t *_ctx, } void -quic_crypto_decrypt_packet (quic_ctx_t * qctx, quic_rx_packet_ctx_t * pctx) +quic_crypto_decrypt_packet (quic_ctx_t *qctx, quic_rx_packet_ctx_t *pctx) { ptls_cipher_context_t *header_protection = NULL; ptls_aead_context_t *aead = NULL; @@ -172,28 +205,26 @@ quic_crypto_decrypt_packet (quic_ctx_t * qctx, quic_rx_packet_ctx_t * pctx) /* decipher the header protection, as well as obtaining pnbits, pnlen */ if (encrypted_len < header_protection->algo->iv_size + QUICLY_MAX_PN_SIZE) return; - ptls_cipher_init (header_protection, - pctx->packet.octets.base + pctx->packet.encrypted_off + - QUICLY_MAX_PN_SIZE); + ptls_cipher_init (header_protection, pctx->packet.octets.base + + pctx->packet.encrypted_off + + QUICLY_MAX_PN_SIZE); ptls_cipher_encrypt (header_protection, hpmask, hpmask, sizeof (hpmask)); pctx->packet.octets.base[0] ^= - hpmask[0] & (QUICLY_PACKET_IS_LONG_HEADER (pctx->packet.octets.base[0]) ? - 0xf : 0x1f); + hpmask[0] & + (QUICLY_PACKET_IS_LONG_HEADER (pctx->packet.octets.base[0]) ? 0xf : 0x1f); pnlen = (pctx->packet.octets.base[0] & 0x3) + 1; for (i = 0; i != pnlen; ++i) { pctx->packet.octets.base[pctx->packet.encrypted_off + i] ^= hpmask[i + 1]; - pnbits = - (pnbits << 8) | pctx->packet.octets.base[pctx->packet.encrypted_off + - i]; + pnbits = (pnbits << 8) | + pctx->packet.octets.base[pctx->packet.encrypted_off + i]; } size_t aead_off = pctx->packet.encrypted_off + pnlen; - pn = - quicly_determine_packet_number (pnbits, pnlen * 8, - next_expected_packet_number); + pn = quicly_determine_packet_number (pnbits, pnlen * 8, + next_expected_packet_number); int key_phase_bit = (pctx->packet.octets.base[0] & QUICLY_KEY_PHASE_BIT) != 0; @@ -203,7 +234,7 @@ quic_crypto_decrypt_packet (quic_ctx_t * qctx, quic_rx_packet_ctx_t * pctx) pctx->packet.octets.base[0] ^= hpmask[0] & (QUICLY_PACKET_IS_LONG_HEADER (pctx->packet.octets.base[0]) ? 0xf : - 0x1f); + 0x1f); for (i = 0; i != pnlen; ++i) { pctx->packet.octets.base[pctx->packet.encrypted_off + i] ^= @@ -218,8 +249,8 @@ quic_crypto_decrypt_packet (quic_ctx_t * qctx, quic_rx_packet_ctx_t * pctx) pctx->packet.octets.len - aead_off, pn, pctx->packet.octets.base, aead_off)) == SIZE_MAX) { - fprintf (stderr, - "%s: aead decryption failure (pn: %d)\n", __FUNCTION__, pn); + fprintf (stderr, "%s: aead decryption failure (pn: %d)\n", __FUNCTION__, + pn); return; } @@ -260,7 +291,7 @@ quic_crypto_encrypt_packet (struct st_quicly_crypto_engine_t *engine, aead_ctx->op.iv = aead_ctx->iv; ptls_aead__build_iv (aead_ctx->super.algo, aead_ctx->op.iv, aead_ctx->static_iv, packet_number); - aead_ctx->op.key_index = aead_ctx->key_index; + aead_ctx->op.key_index = quic_crypto_set_key (&aead_ctx->key); aead_ctx->op.src = (u8 *) input; aead_ctx->op.dst = output; aead_ctx->op.len = inlen; @@ -280,7 +311,8 @@ quic_crypto_encrypt_packet (struct st_quicly_crypto_engine_t *engine, vnet_crypto_op_init (&hp_ctx->op, hp_ctx->id); memset (supp.output, 0, sizeof (supp.output)); hp_ctx->op.iv = (u8 *) supp.input; - hp_ctx->op.key_index = hp_ctx->key_index; + hp_ctx->op.key_index = quic_crypto_set_key (&hp_ctx->key); + ; hp_ctx->op.src = (u8 *) supp.output; hp_ctx->op.dst = (u8 *) supp.output; hp_ctx->op.len = sizeof (supp.output); @@ -301,7 +333,6 @@ quic_crypto_cipher_setup_crypto (ptls_cipher_context_t *_ctx, int is_enc, { struct cipher_context_t *ctx = (struct cipher_context_t *) _ctx; - vlib_main_t *vm = vlib_get_main (); vnet_crypto_alg_t algo; if (!strcmp (ctx->super.algo->name, "AES128-CTR")) { @@ -326,24 +357,26 @@ quic_crypto_cipher_setup_crypto (ptls_cipher_context_t *_ctx, int is_enc, if (quic_main.vnet_crypto_enabled) { - clib_rwlock_writer_lock (&quic_main.crypto_keys_quic_rw_lock); - ctx->key_index = - vnet_crypto_key_add (vm, algo, (u8 *) key, _ctx->algo->key_size); - clib_rwlock_writer_unlock (&quic_main.crypto_keys_quic_rw_lock); + // ctx->key_index = + // quic_crypto_go_setup_key (algo, key, _ctx->algo->key_size); + ctx->key.algo = algo; + ctx->key.key_len = _ctx->algo->key_size; + assert (ctx->key.key_len <= 32); + clib_memcpy (&ctx->key.key, key, ctx->key.key_len); } return 0; } static int -quic_crypto_aes128ctr_setup_crypto (ptls_cipher_context_t * ctx, int is_enc, +quic_crypto_aes128ctr_setup_crypto (ptls_cipher_context_t *ctx, int is_enc, const void *key) { return quic_crypto_cipher_setup_crypto (ctx, 1, key, EVP_aes_128_ctr ()); } static int -quic_crypto_aes256ctr_setup_crypto (ptls_cipher_context_t * ctx, int is_enc, +quic_crypto_aes256ctr_setup_crypto (ptls_cipher_context_t *ctx, int is_enc, const void *key) { return quic_crypto_cipher_setup_crypto (ctx, 1, key, EVP_aes_256_ctr ()); @@ -354,7 +387,6 @@ quic_crypto_aead_setup_crypto (ptls_aead_context_t *_ctx, int is_enc, const void *key, const void *iv, const EVP_CIPHER *cipher) { - vlib_main_t *vm = vlib_get_main (); struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx; vnet_crypto_alg_t algo; @@ -382,11 +414,12 @@ quic_crypto_aead_setup_crypto (ptls_aead_context_t *_ctx, int is_enc, if (quic_main.vnet_crypto_enabled) { clib_memcpy (ctx->static_iv, iv, ctx->super.algo->iv_size); - - clib_rwlock_writer_lock (&quic_main.crypto_keys_quic_rw_lock); - ctx->key_index = vnet_crypto_key_add (vm, algo, - (u8 *) key, _ctx->algo->key_size); - clib_rwlock_writer_unlock (&quic_main.crypto_keys_quic_rw_lock); + // ctx->key_index = + // quic_crypto_go_setup_key (algo, key, _ctx->algo->key_size); + ctx->key.algo = algo; + ctx->key.key_len = _ctx->algo->key_size; + assert (ctx->key.key_len <= 32); + clib_memcpy (&ctx->key.key, key, ctx->key.key_len); } return 0; @@ -469,6 +502,7 @@ ptls_cipher_algorithm_t quic_crypto_aes256ctr = { quic_crypto_aes256ctr_setup_crypto }; +#define PTLS_X86_CACHE_LINE_ALIGN_BITS 6 ptls_aead_algorithm_t quic_crypto_aes128gcm = { "AES128-GCM", PTLS_AESGCM_CONFIDENTIALITY_LIMIT, @@ -478,6 +512,9 @@ ptls_aead_algorithm_t quic_crypto_aes128gcm = { PTLS_AES128_KEY_SIZE, PTLS_AESGCM_IV_SIZE, PTLS_AESGCM_TAG_SIZE, + { PTLS_TLS12_AESGCM_FIXED_IV_SIZE, PTLS_TLS12_AESGCM_RECORD_IV_SIZE }, + 1, + PTLS_X86_CACHE_LINE_ALIGN_BITS, sizeof (struct aead_crypto_context_t), quic_crypto_aead_aes128gcm_setup_crypto }; @@ -491,18 +528,21 @@ ptls_aead_algorithm_t quic_crypto_aes256gcm = { PTLS_AES256_KEY_SIZE, PTLS_AESGCM_IV_SIZE, PTLS_AESGCM_TAG_SIZE, + { PTLS_TLS12_AESGCM_FIXED_IV_SIZE, PTLS_TLS12_AESGCM_RECORD_IV_SIZE }, + 1, + PTLS_X86_CACHE_LINE_ALIGN_BITS, sizeof (struct aead_crypto_context_t), quic_crypto_aead_aes256gcm_setup_crypto }; ptls_cipher_suite_t quic_crypto_aes128gcmsha256 = { - PTLS_CIPHER_SUITE_AES_128_GCM_SHA256, - &quic_crypto_aes128gcm, &ptls_openssl_sha256 + PTLS_CIPHER_SUITE_AES_128_GCM_SHA256, &quic_crypto_aes128gcm, + &ptls_openssl_sha256 }; ptls_cipher_suite_t quic_crypto_aes256gcmsha384 = { - PTLS_CIPHER_SUITE_AES_256_GCM_SHA384, - &quic_crypto_aes256gcm, &ptls_openssl_sha384 + PTLS_CIPHER_SUITE_AES_256_GCM_SHA384, &quic_crypto_aes256gcm, + &ptls_openssl_sha384 }; ptls_cipher_suite_t *quic_crypto_cipher_suites[] = { diff --git a/src/plugins/quic/quic_crypto.h b/src/plugins/quic/quic_crypto.h index 2adb20237a3..7299b613053 100644 --- a/src/plugins/quic/quic_crypto.h +++ b/src/plugins/quic/quic_crypto.h @@ -18,6 +18,19 @@ #include <quicly.h> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +#include <openssl/provider.h> + +#define quic_load_openssl3_legacy_provider() \ + do \ + { \ + (void) OSSL_PROVIDER_load (NULL, "legacy"); \ + } \ + while (0) +#else +#define quic_load_openssl3_legacy_provider() +#endif + struct quic_ctx_t; extern ptls_cipher_suite_t *quic_crypto_cipher_suites[]; |