8 #define MAX_QUEUE 12000 9 #define PTLS_MAX_PLAINTEXT_RECORD_SIZE 16384 23 (*ctx)->ctx.c_thread_index = thread_id;
26 (*ctx)->ptls_ctx_idx = ctx - pm->
ctx_pool[thread_id];
79 return ptls_handshake_is_complete (ptls_ctx->
tls);
84 session_t * tls_session, ptls_buffer_t * buf)
100 enq_now =
clib_min (enq_now, buf_left);
111 ptls_context_t *ptls_ctx;
114 static ptls_key_exchange_algorithm_t *key_exchange[] = {
115 #ifdef PTLS_OPENSSL_HAVE_X25519 116 &ptls_openssl_x25519,
118 #ifdef PTLS_OPENSSL_HAVE_SECP256r1 119 &ptls_openssl_secp256r1,
121 #ifdef PTLS_OPENSSL_HAVE_SECP384r1 122 &ptls_openssl_secp384r1,
124 #ifdef PTLS_OPENSSL_HAVE_SECP521r1 125 &ptls_openssl_secp521r1
130 if (!ckpair || !ckpair->
cert || !ckpair->
key)
132 TLS_DBG (1,
"tls cert and/or key not configured %d",
133 ctx->parent_app_wrk_index);
139 ptls_ctx = malloc (
sizeof (ptls_context_t));
142 memset (ptls_ctx, 0,
sizeof (ptls_context_t));
143 ptls_ctx->update_open_count =
NULL;
152 ptls_ctx->key_exchanges = key_exchange;
153 ptls_ctx->random_bytes = ptls_openssl_random_bytes;
154 ptls_ctx->cipher_suites = ptls_openssl_cipher_suites;
155 ptls_ctx->get_time = &ptls_get_time;
157 lctx->tls_ssl_ctx = ptls_lctx_idx;
168 ptls_lctx_index = lctx->tls_ssl_ctx;
201 ptls_free (ptls_ctx->
tls);
222 u8 * input,
int input_len)
224 ptls_t *tls = ptls_ctx->
tls;
226 int rv = PTLS_ERROR_IN_PROGRESS;
234 ptls_buffer_init (&buf,
"", 0);
235 size_t consumed = input_len - off;
236 rv = ptls_handshake (tls, &buf, input + off, &consumed,
NULL);
238 if ((rv == 0 || rv == PTLS_ERROR_IN_PROGRESS) && buf.off != 0)
243 ptls_buffer_dispose (&buf);
245 while (rv == PTLS_ERROR_IN_PROGRESS && input_len != off);
247 while (rv == PTLS_ERROR_IN_PROGRESS);
257 int to_read, from_tls_len = 0, to_app_len = 0, crypto_len, ret;
258 u32 deq_max, deq_now;
259 u32 enq_max, enq_now;
260 ptls_buffer_t _buf, *buf = &_buf;
264 tls_rx_fifo = tls_session->
rx_fifo;
270 memset (input, 0, deq_max);
277 if (from_tls_len <= 0)
282 if (from_tls_len < deq_max)
285 deq_max - from_tls_len);
287 input + from_tls_len);
299 app_rx_fifo = app_session->
rx_fifo;
301 ptls_buffer_init (buf,
"", 0);
315 if (from_tls_len <= 0)
320 if (from_tls_len < deq_max)
324 deq_max - from_tls_len);
330 ptls_ctx->
rx_len += from_tls_len;
335 if (ptls_ctx->
rx_len != 0)
352 crypto_len =
clib_min (crypto_len, from_tls_len);
357 size_t consumed = crypto_len - off;
359 ptls_receive (ptls_ctx->
tls, buf,
364 while (ret == 0 && off < crypto_len);
370 to_read =
clib_min (enq_max, buf->off);
373 if (to_app_len < buf->off)
377 buf->off - to_app_len);
384 ptls_buffer_dispose (buf);
398 int total_record_overhead,
int is_no_copy)
400 ptls_buffer_t _buf, *buf = &_buf;
401 int total_length = content_len + total_record_overhead;
405 ptls_buffer_init (buf,
svm_fifo_tail (dst_fifo), total_length);
408 assert (!buf->is_allocated);
413 to_dst_len = buf->off;
417 uint8_t *buf_content = malloc (total_length);
418 ptls_buffer_init (buf, buf_content, total_length);
424 if (to_dst_len < buf->off)
427 buf->base + to_dst_len);
428 ptls_buffer_dispose (buf);
437 u32 deq_max, deq_now;
438 u32 enq_max, enq_now;
439 int from_app_len = 0, to_tls_len = 0, is_nocopy = 0;
443 int record_overhead = ptls_get_record_overhead (ptls_ctx->
tls);
444 int num_records, total_overhead;
447 tls_tx_fifo = tls_session->
tx_fifo;
448 app_tx_fifo = app_session->
tx_fifo;
458 if (enq_max < record_overhead)
467 if (enq_now > record_overhead)
470 from_app_len =
clib_min (deq_now, enq_now);
473 total_overhead = num_records * record_overhead;
474 if (from_app_len + total_overhead > enq_now)
475 from_app_len = enq_now - total_overhead;
481 from_app_len =
clib_min (deq_now, enq_max);
484 total_overhead = num_records * record_overhead;
485 if (from_app_len + total_overhead > enq_max)
486 from_app_len = enq_max - total_overhead;
492 from_app_len, total_overhead, is_nocopy);
511 u32 ptls_lctx_idx = ctx->tls_ssl_ctx;
518 TLS_DBG (1,
"Failed to initialize ptls_ssl structure");
578 .version = VPP_BUILD_VER,
579 .description =
"Transport Layer Security (TLS) Engine, Picotls Based",
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static void picotls_confirm_app_close(tls_ctx_t *ctx)
picotls_main_t picotls_main
static u32 svm_fifo_max_enqueue_prod(svm_fifo_t *f)
Maximum number of bytes that can be enqueued into fifo.
tls_ctx_t * picotls_ctx_get_w_thread(u32 ctx_index, u8 thread_index)
void tls_disconnect_transport(tls_ctx_t *ctx)
static int picotls_ctx_write(tls_ctx_t *ctx, session_t *app_session)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
int tls_add_vpp_q_builtin_rx_evt(session_t *s)
void svm_fifo_enqueue_nocopy(svm_fifo_t *f, u32 len)
Advance tail.
static session_t * session_get(u32 si, u32 thread_index)
static int picotls_transport_close(tls_ctx_t *ctx)
static u8 picotls_handshake_is_over(tls_ctx_t *ctx)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static void picotls_listen_ctx_free(picotls_listen_ctx_t *lctx)
void tls_register_engine(const tls_engine_vft_t *vft, crypto_engine_type_t type)
static u8 * svm_fifo_tail(svm_fifo_t *f)
struct _svm_fifo svm_fifo_t
static int picotls_try_handshake_write(picotls_ctx_t *ptls_ctx, session_t *tls_session, ptls_buffer_t *buf)
static void picotls_ctx_free(tls_ctx_t *ctx)
#define VLIB_INIT_FUNCTION(x)
static int picotls_content_process(ptls_t *tls, svm_fifo_t *src_fifo, svm_fifo_t *dst_fifo, int content_len, int total_record_overhead, int is_no_copy)
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
picotls_listen_ctx_t * lctx_pool
static int picotls_ctx_read(tls_ctx_t *ctx, session_t *tls_session)
static u32 svm_fifo_max_write_chunk(svm_fifo_t *f)
Max contiguous chunk of data that can be written.
static void picotls_handle_handshake_failure(tls_ctx_t *ctx)
int svm_fifo_dequeue(svm_fifo_t *f, u32 len, u8 *dst)
Dequeue data from fifo.
#define SESSION_INVALID_HANDLE
static u8 * svm_fifo_head(svm_fifo_t *f)
static u32 picotls_listen_ctx_alloc(void)
int tls_add_vpp_q_builtin_tx_evt(session_t *s)
static u32 svm_fifo_max_read_chunk(svm_fifo_t *f)
Max contiguous chunk of data that can be read.
int session_dequeue_notify(session_t *s)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
picotls_listen_ctx_t * picotls_lctx_get(u32 lctx_index)
static session_t * session_get_from_handle(session_handle_t handle)
#define PTLS_MAX_PLAINTEXT_RECORD_SIZE
int svm_fifo_enqueue(svm_fifo_t *f, u32 len, const u8 *src)
Enqueue data to fifo.
#define SESSION_INVALID_INDEX
picotls_ctx_t *** ctx_pool
app_cert_key_pair_t * app_cert_key_pair_get_if_valid(u32 index)
static u8 svm_fifo_needs_deq_ntf(svm_fifo_t *f, u32 n_last_deq)
Check if fifo needs dequeue notification.
static_always_inline uword vlib_get_thread_index(void)
void session_free(session_t *s)
static clib_error_t * tls_picotls_init(vlib_main_t *vm)
int tls_add_vpp_q_tx_evt(session_t *s)
transport_connection_t connection
ptls_context_t * ptls_ctx
int load_bio_certificate_chain(ptls_context_t *ctx, const char *cert_data)
tls_ctx_t * picotls_ctx_get(u32 ctx_index)
#define pool_put_index(p, i)
Free pool element with given index.
static int picotls_app_close(tls_ctx_t *ctx)
static void clib_mem_free(void *p)
static void * clib_mem_alloc(uword size)
static int picotls_stop_listen(tls_ctx_t *lctx)
static int picotls_start_listen(tls_ctx_t *lctx)
static int picotls_do_handshake(picotls_ctx_t *ptls_ctx, session_t *tls_session, u8 *input, int input_len)
void session_transport_closed_notify(transport_connection_t *tc)
Notification from transport that it is closed.
static int picotls_ctx_init_server(tls_ctx_t *ctx)
int tls_notify_app_accept(tls_ctx_t *ctx)
void tls_notify_app_enqueue(tls_ctx_t *ctx, session_t *app_session)
static vlib_thread_main_t * vlib_get_thread_main()
static u32 picotls_ctx_alloc(void)
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
#define TLS_DBG(_lvl, _fmt, _args...)
int load_bio_private_key(ptls_context_t *ctx, const char *pk_data)