blob: d950fe8262979e9aaecc23ec9097801c1a8cc442 [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
24#define TLS_DEBUG 0
25#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
31#if TLS_DEBUG
32#define TLS_DBG(_lvl, _fmt, _args...) \
33 if (_lvl <= TLS_DEBUG) \
34 clib_warning (_fmt, ##_args)
35#else
Ping Yu970a0b82018-07-19 10:51:09 -040036#define TLS_DBG(_lvl, _fmt, _args...)
Florin Corasd77eee62018-03-07 08:49:27 -080037#endif
38
39/* *INDENT-OFF* */
Florin Coras854e0a22019-07-26 14:46:12 -070040typedef struct tls_cxt_id_
Florin Corasd77eee62018-03-07 08:49:27 -080041{
Florin Coras58a93e82019-01-14 23:33:46 -080042 union {
43 session_handle_t app_session_handle;
44 u32 parent_app_api_ctx;
45 };
Florin Corasd77eee62018-03-07 08:49:27 -080046 session_handle_t tls_session_handle;
Florin Coras854e0a22019-07-26 14:46:12 -070047 u32 parent_app_wrk_index;
Ping Yudecda5b2018-08-13 06:20:00 -040048 u32 ssl_ctx;
Florin Corasd77eee62018-03-07 08:49:27 -080049 u32 listener_ctx_index;
50 u8 tcp_is_ip4;
Florin Coras58d36f02018-03-09 13:05:53 -080051 u8 tls_engine_id;
Florin Coras854e0a22019-07-26 14:46:12 -070052} tls_ctx_id_t;
Florin Corasd77eee62018-03-07 08:49:27 -080053/* *INDENT-ON* */
54
Florin Coras854e0a22019-07-26 14:46:12 -070055STATIC_ASSERT (sizeof (tls_ctx_id_t) <= TRANSPORT_CONN_ID_LEN,
56 "ctx id must be less than TRANSPORT_CONN_ID_LEN");
Florin Corasd77eee62018-03-07 08:49:27 -080057
58typedef struct tls_ctx_
59{
60 union
61 {
62 transport_connection_t connection;
63 tls_ctx_id_t c_tls_ctx_id;
64 };
Florin Corasdf57ea02019-02-18 20:14:20 -080065#define parent_app_wrk_index c_tls_ctx_id.parent_app_wrk_index
Florin Corasd77eee62018-03-07 08:49:27 -080066#define app_session_handle c_tls_ctx_id.app_session_handle
67#define tls_session_handle c_tls_ctx_id.tls_session_handle
68#define listener_ctx_index c_tls_ctx_id.listener_ctx_index
69#define tcp_is_ip4 c_tls_ctx_id.tcp_is_ip4
Florin Coras58d36f02018-03-09 13:05:53 -080070#define tls_ctx_engine c_tls_ctx_id.tls_engine_id
Ping Yudecda5b2018-08-13 06:20:00 -040071#define tls_ssl_ctx c_tls_ctx_id.ssl_ctx
Florin Coras58d36f02018-03-09 13:05:53 -080072#define tls_ctx_handle c_c_index
Florin Corasd77eee62018-03-07 08:49:27 -080073 /* Temporary storage for session open opaque. Overwritten once
74 * underlying tcp connection is established */
Florin Coras58a93e82019-01-14 23:33:46 -080075#define parent_app_api_context c_tls_ctx_id.parent_app_api_ctx
Florin Corasd77eee62018-03-07 08:49:27 -080076
77 u8 is_passive_close;
Ping Yue43832c2018-05-30 18:16:08 -040078 u8 resume;
Florin Corasef2b3352019-08-07 11:14:56 -070079 u8 app_closed;
80 u8 no_app_session;
Florin Corasd77eee62018-03-07 08:49:27 -080081 u8 *srv_hostname;
Yu Pingf4a92f62020-01-21 05:07:30 +080082 u32 evt_index;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +020083 u32 ckpair_index;
Florin Corasd77eee62018-03-07 08:49:27 -080084} tls_ctx_t;
85
86typedef struct tls_main_
87{
88 u32 app_index;
89 tls_ctx_t *listener_ctx_pool;
90 tls_ctx_t *half_open_ctx_pool;
91 clib_rwlock_t half_open_rwlock;
Florin Coras58d36f02018-03-09 13:05:53 -080092 u8 **rx_bufs;
93 u8 **tx_bufs;
Florin Corasd77eee62018-03-07 08:49:27 -080094
95 /*
96 * Config
97 */
98 u8 use_test_cert_in_ca;
99 char *ca_cert_path;
Florin Corasddd98f32019-03-25 08:30:53 -0700100 u64 first_seg_size;
101 u32 fifo_size;
Florin Corasd77eee62018-03-07 08:49:27 -0800102} tls_main_t;
103
104typedef struct tls_engine_vft_
105{
106 u32 (*ctx_alloc) (void);
107 void (*ctx_free) (tls_ctx_t * ctx);
108 tls_ctx_t *(*ctx_get) (u32 ctx_index);
109 tls_ctx_t *(*ctx_get_w_thread) (u32 ctx_index, u8 thread_index);
110 int (*ctx_init_client) (tls_ctx_t * ctx);
111 int (*ctx_init_server) (tls_ctx_t * ctx);
Florin Coras288eaab2019-02-03 15:26:14 -0800112 int (*ctx_read) (tls_ctx_t * ctx, session_t * tls_session);
Florin Coras9f86d222020-03-23 15:34:22 +0000113 int (*ctx_write) (tls_ctx_t * ctx, session_t * app_session,
114 transport_send_params_t * sp);
Florin Corasd77eee62018-03-07 08:49:27 -0800115 u8 (*ctx_handshake_is_over) (tls_ctx_t * ctx);
Ping Yudecda5b2018-08-13 06:20:00 -0400116 int (*ctx_start_listen) (tls_ctx_t * ctx);
117 int (*ctx_stop_listen) (tls_ctx_t * ctx);
Florin Coras06a6a302019-04-17 14:19:12 -0700118 int (*ctx_transport_close) (tls_ctx_t * ctx);
119 int (*ctx_app_close) (tls_ctx_t * ctx);
Florin Corasd77eee62018-03-07 08:49:27 -0800120} tls_engine_vft_t;
121
Florin Corasd77eee62018-03-07 08:49:27 -0800122tls_main_t *vnet_tls_get_main (void);
123void tls_register_engine (const tls_engine_vft_t * vft,
Nathan Skrzypczak82fc5fd2019-09-13 10:20:15 +0200124 crypto_engine_type_t type);
Florin Coras288eaab2019-02-03 15:26:14 -0800125int tls_add_vpp_q_rx_evt (session_t * s);
126int tls_add_vpp_q_tx_evt (session_t * s);
127int tls_add_vpp_q_builtin_tx_evt (session_t * s);
128int tls_add_vpp_q_builtin_rx_evt (session_t * s);
Florin Coras58d36f02018-03-09 13:05:53 -0800129int tls_notify_app_accept (tls_ctx_t * ctx);
Florin Coras00e01d32019-10-21 16:07:46 -0700130int tls_notify_app_connected (tls_ctx_t * ctx, session_error_t err);
Florin Coras288eaab2019-02-03 15:26:14 -0800131void tls_notify_app_enqueue (tls_ctx_t * ctx, session_t * app_session);
Florin Coras06a6a302019-04-17 14:19:12 -0700132void tls_disconnect_transport (tls_ctx_t * ctx);
Florin Corasd77eee62018-03-07 08:49:27 -0800133#endif /* SRC_VNET_TLS_TLS_H_ */
Florin Coras54a51fd2019-02-07 15:34:52 -0800134
Florin Corasd77eee62018-03-07 08:49:27 -0800135/*
136 * fd.io coding-style-patch-verification: ON
137 *
138 * Local Variables:
139 * eval: (c-set-style "gnu")
140 * End:
141 */