The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
bio.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17#ifdef WITH_TLS
18/**
19 * $Id: 413339e8b612f8cf28e93f8bf68c78aebdb98687 $
20 *
21 * @file lib/tls/bio.h
22 * @brief Custom BIOs to pass to OpenSSL's functions
23 *
24 * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
25 */
26RCSIDH(bio_h, "$Id: 413339e8b612f8cf28e93f8bf68c78aebdb98687 $")
27
28#include "openssl_user_macros.h"
29
30#include <openssl/bio.h>
31#include <freeradius-devel/util/dbuff.h>
32
33/** An OpenSSL BIO whose backing store is a (possibly) talloc-extendable buffer
34 *
35 * The BIO has two dbuffs, a producer and a consumer. They have
36 * the same start pointers, but different end pointers. The producer
37 * writes more data to the memory buffer via fr_tls_bio_dbuff_in(),
38 * which updates its end pointer. The end pointer is shared with the
39 * consumer, which sees that data is available, and reads it via
40 * fr_tls_bio_dbuff_out().
41 *
42 * This design allows the producer and consumer to share an underlying
43 * memory block, which reduces copies.
44 *
45 * The dbuff can shift its memory contents around. A read shifts the
46 * data down to reclaim the space which was consumed, and a write
47 * shifts the data down in the same way. A write may also extend the
48 * buffer, and talloc extends a buffer by moving the buffer to a new
49 * address. Callers must therefore not cache any pointers, and
50 * instead always call the dbuff wrapper functions to get the current
51 * values.
52 */
53typedef struct fr_tls_bio_dbuff_s fr_tls_bio_dbuff_t;
54
55/** Window of datagrams which can be in a TLS BIO, but not yet written.
56 *
57 * The cap serves the same purpose as FR_TLS_MAX_ROUNDS in session.h:
58 * it stops the server from holding unbounded state. A handshake
59 * flight is a handful of datagrams even at the smallest possible MTU.
60 * Any write which would exceed this limit fails, rather than growing
61 * the queue.
62 */
63#define FR_TLS_MAX_DATAGRAMS (256)
64
65uint8_t *fr_tls_bio_dbuff_finalise(fr_tls_bio_dbuff_t *bd);
66
67char *fr_tls_bio_dbuff_finalise_bstr(fr_tls_bio_dbuff_t *bd);
68
69fr_dbuff_t *fr_tls_bio_dbuff_out(fr_tls_bio_dbuff_t *bd);
70
71fr_dbuff_t *fr_tls_bio_dbuff_in(fr_tls_bio_dbuff_t *bd);
72
73void fr_tls_bio_dbuff_reset(fr_tls_bio_dbuff_t *bd);
74
75void fr_tls_bio_dbuff_clear(fr_tls_bio_dbuff_t *bd);
76
77BIO *fr_tls_bio_dbuff_alloc(fr_tls_bio_dbuff_t **out, TALLOC_CTX *bio_ctx, TALLOC_CTX *buff_ctx,
78 size_t init, size_t max, bool free_buff);
79
80uint8_t *fr_tls_bio_dbuff_thread_local_finalise(void);
81
82char *fr_tls_bio_dbuff_thread_local_finalise_bstr(void);
83
84void fr_tls_bio_dbuff_thread_local_clear(void);
85
86BIO *fr_tls_bio_dbuff_thread_local(TALLOC_CTX *ctx, size_t init, size_t max);
87
88int fr_tls_bio_dbuff_datagram_init(fr_tls_bio_dbuff_t *bd);
89
90size_t fr_tls_bio_dbuff_datagram_len(fr_tls_bio_dbuff_t *bd);
91
92void fr_tls_bio_dbuff_datagram_sent(fr_tls_bio_dbuff_t *bd);
93
94int fr_tls_bio_init(void);
95
96void fr_tls_bio_free(void);
97
98#endif /* WITH_TLS */
#define RCSIDH(h, id)
Definition build.h:604
unsigned char uint8_t
init
Enter the EAP-IDENTITY state.
static fr_sbuff_err_t char size_t fr_sbuff_t size_t max
Definition value.h:1061
static fr_sbuff_err_t char ** out
Definition value.h:1061