blob: 5515cb25b8aa83a15cdfce38c95c9fc02dd8f162 [file] [log] [blame]
Florin Corasd77eee62018-03-07 08:49:27 -08001/*
2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * 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
16
17#include <vnet/session/application_interface.h>
18#include <vppinfra/lock.h>
19
20#ifndef SRC_VNET_TLS_TLS_H_
21#define SRC_VNET_TLS_TLS_H_
22
23#define TLS_DEBUG 0
24#define TLS_DEBUG_LEVEL_CLIENT 0
25#define TLS_DEBUG_LEVEL_SERVER 0
26
27#define TLS_CHUNK_SIZE (1 << 14)
28#define TLS_CA_CERT_PATH "/etc/ssl/certs/ca-certificates.crt"
29
30#if TLS_DEBUG
31#define TLS_DBG(_lvl, _fmt, _args...) \
32 if (_lvl <= TLS_DEBUG) \
33 clib_warning (_fmt, ##_args)
34#else
Ping Yu970a0b82018-07-19 10:51:09 -040035#define TLS_DBG(_lvl, _fmt, _args...)
Florin Corasd77eee62018-03-07 08:49:27 -080036#endif
37
38/* *INDENT-OFF* */
39typedef CLIB_PACKED (struct tls_cxt_id_
40{
41 u32 parent_app_index;
42 session_handle_t app_session_handle;
43 session_handle_t tls_session_handle;
Ping Yudecda5b2018-08-13 06:20:00 -040044 u32 ssl_ctx;
Florin Corasd77eee62018-03-07 08:49:27 -080045 u32 listener_ctx_index;
46 u8 tcp_is_ip4;
Florin Coras58d36f02018-03-09 13:05:53 -080047 u8 tls_engine_id;
Florin Corasd77eee62018-03-07 08:49:27 -080048}) tls_ctx_id_t;
49/* *INDENT-ON* */
50
51STATIC_ASSERT (sizeof (tls_ctx_id_t) <= 42, "ctx id must be less than 42");
52
53typedef struct tls_ctx_
54{
55 union
56 {
57 transport_connection_t connection;
58 tls_ctx_id_t c_tls_ctx_id;
59 };
60#define parent_app_index c_tls_ctx_id.parent_app_index
61#define app_session_handle c_tls_ctx_id.app_session_handle
62#define tls_session_handle c_tls_ctx_id.tls_session_handle
63#define listener_ctx_index c_tls_ctx_id.listener_ctx_index
64#define tcp_is_ip4 c_tls_ctx_id.tcp_is_ip4
Florin Coras58d36f02018-03-09 13:05:53 -080065#define tls_ctx_engine c_tls_ctx_id.tls_engine_id
Ping Yudecda5b2018-08-13 06:20:00 -040066#define tls_ssl_ctx c_tls_ctx_id.ssl_ctx
Florin Coras58d36f02018-03-09 13:05:53 -080067#define tls_ctx_handle c_c_index
Florin Corasd77eee62018-03-07 08:49:27 -080068 /* Temporary storage for session open opaque. Overwritten once
69 * underlying tcp connection is established */
70#define parent_app_api_context c_s_index
71
72 u8 is_passive_close;
Ping Yue43832c2018-05-30 18:16:08 -040073 u8 resume;
Florin Corasd77eee62018-03-07 08:49:27 -080074 u8 *srv_hostname;
75} tls_ctx_t;
76
77typedef struct tls_main_
78{
79 u32 app_index;
80 tls_ctx_t *listener_ctx_pool;
81 tls_ctx_t *half_open_ctx_pool;
82 clib_rwlock_t half_open_rwlock;
Florin Coras58d36f02018-03-09 13:05:53 -080083 u8 **rx_bufs;
84 u8 **tx_bufs;
Florin Corasd77eee62018-03-07 08:49:27 -080085
86 /*
87 * Config
88 */
89 u8 use_test_cert_in_ca;
90 char *ca_cert_path;
91} tls_main_t;
92
93typedef struct tls_engine_vft_
94{
95 u32 (*ctx_alloc) (void);
96 void (*ctx_free) (tls_ctx_t * ctx);
97 tls_ctx_t *(*ctx_get) (u32 ctx_index);
98 tls_ctx_t *(*ctx_get_w_thread) (u32 ctx_index, u8 thread_index);
99 int (*ctx_init_client) (tls_ctx_t * ctx);
100 int (*ctx_init_server) (tls_ctx_t * ctx);
Florin Coras58d36f02018-03-09 13:05:53 -0800101 int (*ctx_read) (tls_ctx_t * ctx, stream_session_t * tls_session);
102 int (*ctx_write) (tls_ctx_t * ctx, stream_session_t * app_session);
Florin Corasd77eee62018-03-07 08:49:27 -0800103 u8 (*ctx_handshake_is_over) (tls_ctx_t * ctx);
Ping Yudecda5b2018-08-13 06:20:00 -0400104 int (*ctx_start_listen) (tls_ctx_t * ctx);
105 int (*ctx_stop_listen) (tls_ctx_t * ctx);
Florin Corasd77eee62018-03-07 08:49:27 -0800106} tls_engine_vft_t;
107
Florin Corasd77eee62018-03-07 08:49:27 -0800108typedef enum tls_engine_type_
109{
Florin Coras58d36f02018-03-09 13:05:53 -0800110 TLS_ENGINE_NONE,
Florin Corasd77eee62018-03-07 08:49:27 -0800111 TLS_ENGINE_MBEDTLS,
112 TLS_ENGINE_OPENSSL,
113 TLS_N_ENGINES
114} tls_engine_type_t;
115
116tls_main_t *vnet_tls_get_main (void);
117void tls_register_engine (const tls_engine_vft_t * vft,
118 tls_engine_type_t type);
119int tls_add_vpp_q_evt (svm_fifo_t * f, u8 evt_type);
Florin Coras58d36f02018-03-09 13:05:53 -0800120int tls_notify_app_accept (tls_ctx_t * ctx);
121int tls_notify_app_connected (tls_ctx_t * ctx, u8 is_failed);
122void tls_notify_app_enqueue (tls_ctx_t * ctx, stream_session_t * app_session);
Florin Corasd77eee62018-03-07 08:49:27 -0800123#endif /* SRC_VNET_TLS_TLS_H_ */
124/*
125 * fd.io coding-style-patch-verification: ON
126 *
127 * Local Variables:
128 * eval: (c-set-style "gnu")
129 * End:
130 */