blob: 38f4c4b8f812ba78c6dae47dbe0dc1b32a1b111d [file] [log] [blame]
Florin Corasd77eee62018-03-07 08:49:27 -08001/*
Florin Corasc9940fc2019-02-05 20:55:11 -08002 * Copyright (c) 2018-2019 Cisco and/or its affiliates.
Florin Corasd77eee62018-03-07 08:49:27 -08003 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
Florin Corasd77eee62018-03-07 08:49:27 -080016#include <vnet/session/application_interface.h>
Florin Corasc1a42652019-02-08 18:27:29 -080017#include <vnet/session/application.h>
Florin Corasc9940fc2019-02-05 20:55:11 -080018#include <vnet/session/session.h>
Florin Corasd77eee62018-03-07 08:49:27 -080019#include <vppinfra/lock.h>
20
21#ifndef SRC_VNET_TLS_TLS_H_
22#define SRC_VNET_TLS_TLS_H_
23
Florin Coras4b47ee22020-11-19 13:38:26 -080024#define TLS_DEBUG 0
Florin Corasd77eee62018-03-07 08:49:27 -080025#define TLS_DEBUG_LEVEL_CLIENT 0
26#define TLS_DEBUG_LEVEL_SERVER 0
27
28#define TLS_CHUNK_SIZE (1 << 14)
29#define TLS_CA_CERT_PATH "/etc/ssl/certs/ca-certificates.crt"
30
Florin Coras3fe610a2024-05-31 12:04:41 -070031#define TLS_INVALID_HANDLE ~0
32#define TLS_IDX_MASK 0x00FFFFFF
33#define TLS_ENGINE_TYPE_SHIFT 28
34
Florin Corasd77eee62018-03-07 08:49:27 -080035#if TLS_DEBUG
36#define TLS_DBG(_lvl, _fmt, _args...) \
37 if (_lvl <= TLS_DEBUG) \
38 clib_warning (_fmt, ##_args)
39#else
Ping Yu970a0b82018-07-19 10:51:09 -040040#define TLS_DBG(_lvl, _fmt, _args...)
Florin Corasd77eee62018-03-07 08:49:27 -080041#endif
42
Florin Coras854e0a22019-07-26 14:46:12 -070043typedef struct tls_cxt_id_
Florin Corasd77eee62018-03-07 08:49:27 -080044{
Florin Corase6d05dc2024-01-22 18:38:08 -080045 session_handle_t app_session_handle;
Florin Corasd77eee62018-03-07 08:49:27 -080046 session_handle_t tls_session_handle;
Florin Coras2c876f92021-05-10 21:12:27 -070047 void *migrate_ctx;
Florin Coras854e0a22019-07-26 14:46:12 -070048 u32 parent_app_wrk_index;
Ping Yudecda5b2018-08-13 06:20:00 -040049 u32 ssl_ctx;
Florin Corase6d05dc2024-01-22 18:38:08 -080050 union
51 {
52 u32 listener_ctx_index;
53 u32 parent_app_api_ctx;
54 };
Florin Corasd77eee62018-03-07 08:49:27 -080055 u8 tcp_is_ip4;
Florin Coras58d36f02018-03-09 13:05:53 -080056 u8 tls_engine_id;
Florin Coras854e0a22019-07-26 14:46:12 -070057} tls_ctx_id_t;
Florin Corasd77eee62018-03-07 08:49:27 -080058
Florin Coras854e0a22019-07-26 14:46:12 -070059STATIC_ASSERT (sizeof (tls_ctx_id_t) <= TRANSPORT_CONN_ID_LEN,
60 "ctx id must be less than TRANSPORT_CONN_ID_LEN");
Florin Corasd77eee62018-03-07 08:49:27 -080061
Florin Coras4a98b932024-01-31 13:45:39 -080062#define foreach_tls_conn_flags \
63 _ (HO_DONE, "ho-done") \
64 _ (PASSIVE_CLOSE, "passive-close") \
65 _ (APP_CLOSED, "app-closed") \
66 _ (MIGRATED, "migrated") \
67 _ (NO_APP_SESSION, "no-app-session") \
Florin Corasac60efd2024-03-13 22:03:33 -070068 _ (RESUME, "resume") \
69 _ (HS_DONE, "handshake-done")
Florin Corasa474bc82023-12-04 20:29:52 -080070
71typedef enum tls_conn_flags_bit_
72{
73#define _(sym, str) TLS_CONN_F_BIT_##sym,
74 foreach_tls_conn_flags
75#undef _
76} tls_conn_flags_bit_t;
77
78typedef enum tls_conn_flags_
79{
80#define _(sym, str) TLS_CONN_F_##sym = 1 << TLS_CONN_F_BIT_##sym,
81 foreach_tls_conn_flags
82#undef _
83} __clib_packed tls_conn_flags_t;
84
Florin Corasd77eee62018-03-07 08:49:27 -080085typedef struct tls_ctx_
86{
87 union
88 {
89 transport_connection_t connection;
90 tls_ctx_id_t c_tls_ctx_id;
91 };
Florin Corasdf57ea02019-02-18 20:14:20 -080092#define parent_app_wrk_index c_tls_ctx_id.parent_app_wrk_index
Florin Corasd77eee62018-03-07 08:49:27 -080093#define app_session_handle c_tls_ctx_id.app_session_handle
94#define tls_session_handle c_tls_ctx_id.tls_session_handle
95#define listener_ctx_index c_tls_ctx_id.listener_ctx_index
96#define tcp_is_ip4 c_tls_ctx_id.tcp_is_ip4
Florin Coras58d36f02018-03-09 13:05:53 -080097#define tls_ctx_engine c_tls_ctx_id.tls_engine_id
Ping Yudecda5b2018-08-13 06:20:00 -040098#define tls_ssl_ctx c_tls_ctx_id.ssl_ctx
Florin Coras58d36f02018-03-09 13:05:53 -080099#define tls_ctx_handle c_c_index
Florin Corasd77eee62018-03-07 08:49:27 -0800100 /* Temporary storage for session open opaque. Overwritten once
101 * underlying tcp connection is established */
Florin Coras58a93e82019-01-14 23:33:46 -0800102#define parent_app_api_context c_tls_ctx_id.parent_app_api_ctx
Florin Coras4b47ee22020-11-19 13:38:26 -0800103#define migration_ctx c_tls_ctx_id.migrate_ctx
Florin Corasd77eee62018-03-07 08:49:27 -0800104
Florin Corasa474bc82023-12-04 20:29:52 -0800105 tls_conn_flags_t flags;
Florin Corasd77eee62018-03-07 08:49:27 -0800106 u8 *srv_hostname;
Yu Pingf4a92f62020-01-21 05:07:30 +0800107 u32 evt_index;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +0200108 u32 ckpair_index;
Florin Coras4b47ee22020-11-19 13:38:26 -0800109 transport_proto_t tls_type;
Florin Corasd77eee62018-03-07 08:49:27 -0800110} tls_ctx_t;
111
112typedef struct tls_main_
113{
114 u32 app_index;
115 tls_ctx_t *listener_ctx_pool;
116 tls_ctx_t *half_open_ctx_pool;
Florin Corasa474bc82023-12-04 20:29:52 -0800117 u32 *postponed_ho_free;
118 u32 *ho_free_list;
Florin Coras58d36f02018-03-09 13:05:53 -0800119 u8 **rx_bufs;
120 u8 **tx_bufs;
Florin Corasd77eee62018-03-07 08:49:27 -0800121
122 /*
123 * Config
124 */
125 u8 use_test_cert_in_ca;
126 char *ca_cert_path;
Florin Corasddd98f32019-03-25 08:30:53 -0700127 u64 first_seg_size;
Florin Corasa3767bd2021-11-18 15:25:31 -0800128 u64 add_seg_size;
Florin Corasddd98f32019-03-25 08:30:53 -0700129 u32 fifo_size;
Florin Corasd77eee62018-03-07 08:49:27 -0800130} tls_main_t;
131
132typedef struct tls_engine_vft_
133{
134 u32 (*ctx_alloc) (void);
Florin Coras4b47ee22020-11-19 13:38:26 -0800135 u32 (*ctx_alloc_w_thread) (u32 thread_index);
Florin Corasd77eee62018-03-07 08:49:27 -0800136 void (*ctx_free) (tls_ctx_t * ctx);
Florin Coras4b47ee22020-11-19 13:38:26 -0800137 void *(*ctx_detach) (tls_ctx_t *ctx);
138 u32 (*ctx_attach) (u32 thread_index, void *ctx);
Florin Corasd77eee62018-03-07 08:49:27 -0800139 tls_ctx_t *(*ctx_get) (u32 ctx_index);
140 tls_ctx_t *(*ctx_get_w_thread) (u32 ctx_index, u8 thread_index);
141 int (*ctx_init_client) (tls_ctx_t * ctx);
142 int (*ctx_init_server) (tls_ctx_t * ctx);
Florin Coras288eaab2019-02-03 15:26:14 -0800143 int (*ctx_read) (tls_ctx_t * ctx, session_t * tls_session);
Florin Coras9f86d222020-03-23 15:34:22 +0000144 int (*ctx_write) (tls_ctx_t * ctx, session_t * app_session,
145 transport_send_params_t * sp);
Florin Corasd77eee62018-03-07 08:49:27 -0800146 u8 (*ctx_handshake_is_over) (tls_ctx_t * ctx);
Ping Yudecda5b2018-08-13 06:20:00 -0400147 int (*ctx_start_listen) (tls_ctx_t * ctx);
148 int (*ctx_stop_listen) (tls_ctx_t * ctx);
Florin Coras06a6a302019-04-17 14:19:12 -0700149 int (*ctx_transport_close) (tls_ctx_t * ctx);
Florin Corasea158d62024-02-26 18:11:43 -0800150 int (*ctx_transport_reset) (tls_ctx_t *ctx);
Florin Coras06a6a302019-04-17 14:19:12 -0700151 int (*ctx_app_close) (tls_ctx_t * ctx);
Saravanan Murugesand918cc52022-02-28 19:54:11 +0530152 int (*ctx_reinit_cachain) (void);
Florin Corasd77eee62018-03-07 08:49:27 -0800153} tls_engine_vft_t;
154
Florin Coras3fe610a2024-05-31 12:04:41 -0700155extern tls_engine_vft_t *tls_vfts;
156
Florin Corasd77eee62018-03-07 08:49:27 -0800157tls_main_t *vnet_tls_get_main (void);
158void tls_register_engine (const tls_engine_vft_t * vft,
Nathan Skrzypczak82fc5fd2019-09-13 10:20:15 +0200159 crypto_engine_type_t type);
Florin Coras288eaab2019-02-03 15:26:14 -0800160int tls_add_vpp_q_rx_evt (session_t * s);
161int tls_add_vpp_q_tx_evt (session_t * s);
162int tls_add_vpp_q_builtin_tx_evt (session_t * s);
163int tls_add_vpp_q_builtin_rx_evt (session_t * s);
Florin Coras58d36f02018-03-09 13:05:53 -0800164int tls_notify_app_accept (tls_ctx_t * ctx);
Florin Coras00e01d32019-10-21 16:07:46 -0700165int tls_notify_app_connected (tls_ctx_t * ctx, session_error_t err);
Florin Coras288eaab2019-02-03 15:26:14 -0800166void tls_notify_app_enqueue (tls_ctx_t * ctx, session_t * app_session);
Florin Coras8c5e5f62022-02-24 16:35:26 -0800167void tls_notify_app_io_error (tls_ctx_t *ctx);
Florin Coras06a6a302019-04-17 14:19:12 -0700168void tls_disconnect_transport (tls_ctx_t * ctx);
Florin Corasa474bc82023-12-04 20:29:52 -0800169
170void tls_add_postponed_ho_cleanups (u32 ho_index);
171void tls_flush_postponed_ho_cleanups ();
172
Florin Corasd77eee62018-03-07 08:49:27 -0800173#endif /* SRC_VNET_TLS_TLS_H_ */
Florin Coras54a51fd2019-02-07 15:34:52 -0800174
Florin Corasd77eee62018-03-07 08:49:27 -0800175/*
176 * fd.io coding-style-patch-verification: ON
177 *
178 * Local Variables:
179 * eval: (c-set-style "gnu")
180 * End:
181 */