Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 1 | /* |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 Cisco and/or its affiliates. |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 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 | |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 16 | #include <vnet/session/application_interface.h> |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 17 | #include <vnet/session/application.h> |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 18 | #include <vnet/session/session.h> |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 19 | #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 Yu | 970a0b8 | 2018-07-19 10:51:09 -0400 | [diff] [blame] | 36 | #define TLS_DBG(_lvl, _fmt, _args...) |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | /* *INDENT-OFF* */ |
| 40 | typedef CLIB_PACKED (struct tls_cxt_id_ |
| 41 | { |
Florin Coras | df57ea0 | 2019-02-18 20:14:20 -0800 | [diff] [blame] | 42 | u32 parent_app_wrk_index; |
Florin Coras | 58a93e8 | 2019-01-14 23:33:46 -0800 | [diff] [blame] | 43 | union { |
| 44 | session_handle_t app_session_handle; |
| 45 | u32 parent_app_api_ctx; |
| 46 | }; |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 47 | session_handle_t tls_session_handle; |
Ping Yu | decda5b | 2018-08-13 06:20:00 -0400 | [diff] [blame] | 48 | u32 ssl_ctx; |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 49 | u32 listener_ctx_index; |
| 50 | u8 tcp_is_ip4; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 51 | u8 tls_engine_id; |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 52 | }) tls_ctx_id_t; |
| 53 | /* *INDENT-ON* */ |
| 54 | |
| 55 | STATIC_ASSERT (sizeof (tls_ctx_id_t) <= 42, "ctx id must be less than 42"); |
| 56 | |
| 57 | typedef struct tls_ctx_ |
| 58 | { |
| 59 | union |
| 60 | { |
| 61 | transport_connection_t connection; |
| 62 | tls_ctx_id_t c_tls_ctx_id; |
| 63 | }; |
Florin Coras | df57ea0 | 2019-02-18 20:14:20 -0800 | [diff] [blame] | 64 | #define parent_app_wrk_index c_tls_ctx_id.parent_app_wrk_index |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 65 | #define app_session_handle c_tls_ctx_id.app_session_handle |
| 66 | #define tls_session_handle c_tls_ctx_id.tls_session_handle |
| 67 | #define listener_ctx_index c_tls_ctx_id.listener_ctx_index |
| 68 | #define tcp_is_ip4 c_tls_ctx_id.tcp_is_ip4 |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 69 | #define tls_ctx_engine c_tls_ctx_id.tls_engine_id |
Ping Yu | decda5b | 2018-08-13 06:20:00 -0400 | [diff] [blame] | 70 | #define tls_ssl_ctx c_tls_ctx_id.ssl_ctx |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 71 | #define tls_ctx_handle c_c_index |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 72 | /* Temporary storage for session open opaque. Overwritten once |
| 73 | * underlying tcp connection is established */ |
Florin Coras | 58a93e8 | 2019-01-14 23:33:46 -0800 | [diff] [blame] | 74 | #define parent_app_api_context c_tls_ctx_id.parent_app_api_ctx |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 75 | |
| 76 | u8 is_passive_close; |
Ping Yu | e43832c | 2018-05-30 18:16:08 -0400 | [diff] [blame] | 77 | u8 resume; |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 78 | u8 *srv_hostname; |
| 79 | } tls_ctx_t; |
| 80 | |
| 81 | typedef struct tls_main_ |
| 82 | { |
| 83 | u32 app_index; |
| 84 | tls_ctx_t *listener_ctx_pool; |
| 85 | tls_ctx_t *half_open_ctx_pool; |
| 86 | clib_rwlock_t half_open_rwlock; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 87 | u8 **rx_bufs; |
| 88 | u8 **tx_bufs; |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Config |
| 92 | */ |
| 93 | u8 use_test_cert_in_ca; |
| 94 | char *ca_cert_path; |
Florin Coras | ddd98f3 | 2019-03-25 08:30:53 -0700 | [diff] [blame] | 95 | u64 first_seg_size; |
| 96 | u32 fifo_size; |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 97 | } tls_main_t; |
| 98 | |
| 99 | typedef struct tls_engine_vft_ |
| 100 | { |
| 101 | u32 (*ctx_alloc) (void); |
| 102 | void (*ctx_free) (tls_ctx_t * ctx); |
| 103 | tls_ctx_t *(*ctx_get) (u32 ctx_index); |
| 104 | tls_ctx_t *(*ctx_get_w_thread) (u32 ctx_index, u8 thread_index); |
| 105 | int (*ctx_init_client) (tls_ctx_t * ctx); |
| 106 | int (*ctx_init_server) (tls_ctx_t * ctx); |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 107 | int (*ctx_read) (tls_ctx_t * ctx, session_t * tls_session); |
| 108 | int (*ctx_write) (tls_ctx_t * ctx, session_t * app_session); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 109 | u8 (*ctx_handshake_is_over) (tls_ctx_t * ctx); |
Ping Yu | decda5b | 2018-08-13 06:20:00 -0400 | [diff] [blame] | 110 | int (*ctx_start_listen) (tls_ctx_t * ctx); |
| 111 | int (*ctx_stop_listen) (tls_ctx_t * ctx); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 112 | } tls_engine_vft_t; |
| 113 | |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 114 | tls_main_t *vnet_tls_get_main (void); |
| 115 | void tls_register_engine (const tls_engine_vft_t * vft, |
| 116 | tls_engine_type_t type); |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 117 | int tls_add_vpp_q_rx_evt (session_t * s); |
| 118 | int tls_add_vpp_q_tx_evt (session_t * s); |
| 119 | int tls_add_vpp_q_builtin_tx_evt (session_t * s); |
| 120 | int tls_add_vpp_q_builtin_rx_evt (session_t * s); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 121 | int tls_notify_app_accept (tls_ctx_t * ctx); |
| 122 | int tls_notify_app_connected (tls_ctx_t * ctx, u8 is_failed); |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 123 | void tls_notify_app_enqueue (tls_ctx_t * ctx, session_t * app_session); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 124 | #endif /* SRC_VNET_TLS_TLS_H_ */ |
Florin Coras | 54a51fd | 2019-02-07 15:34:52 -0800 | [diff] [blame] | 125 | |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 126 | /* |
| 127 | * fd.io coding-style-patch-verification: ON |
| 128 | * |
| 129 | * Local Variables: |
| 130 | * eval: (c-set-style "gnu") |
| 131 | * End: |
| 132 | */ |