The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
conf.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: 376524b9e68dd086cd1320a6da73687f2b436cb1 $
20 *
21 * @file lib/tls/conf.h
22 * @brief Structures for session-resumption management.
23 *
24 * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
25 */
26RCSIDH(conf_h, "$Id: 376524b9e68dd086cd1320a6da73687f2b436cb1 $")
27
28#include "openssl_user_macros.h"
29
30#include <openssl/ssl.h>
31#include <openssl/err.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36typedef struct fr_tls_conf_s fr_tls_conf_t;
37#ifdef __cplusplus
38}
39#endif
40
41#include "verify.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/** Different chain building modes
48 *
49 */
50typedef enum : uint8_t {
51 FR_TLS_CHAIN_VERIFY_INVALID = 0,
52
53 FR_TLS_CHAIN_VERIFY_HARD, //!< Fail if we can't build a complete chain from
54 ///< the leaf cert back to a root.
55 FR_TLS_CHAIN_VERIFY_SOFT, //!< Warn if we can't build a complete chain from
56 ///< the leaf cert back to a root.
57 FR_TLS_CHAIN_VERIFY_NONE //!< Don't verify/build the chain.
58} fr_tls_chain_verify_mode_t;
59
60/** Structure representing a certificate chain configuration
61 *
62 */
63typedef struct {
64 int file_format; //!< Whether the file is expected to be PEM encoded.
65 ///< This allows us to load multiple chained PEM certificates
66 ///< from a single file.
67
68 char const *certificate_file; //!< Path to certificate.
69
70 char const *password; //!< Password to decrypt the certificate(s).
71 char const *private_key_file; //!< Path to certificate.
72
73 char const **ca_files; //!< Extra certificates to load.
74 fr_tls_chain_verify_mode_t verify_mode; //!< How hard we try to build up a complete certificate
75 ///< chain.
76 bool include_root_ca; //!< Include the root ca in the chain we built.
77
78 /** @name Certificate data
79 *
80 * @{
81 */
82 X509 *leaf; //!< The certificate that we present to the peer, the
83 ///< first certificate in `certificate_file`.
84 STACK_OF(X509) *extra; //!< The remaining certificates in `certificate_file`,
85 ///< then one certificate from each `ca_file`.
86 EVP_PKEY *private_key; //!< The private key from `private_key_file`.
87 fr_unix_time_t valid_until; //!< The earliest notAfter of any certificate in `leaf` or `extra`.
88 /** @} */
89} fr_tls_chain_conf_t;
90
91/** Control what types of session resumption we allow
92 *
93 */
94typedef enum {
95 FR_TLS_TICKET_DISABLED = 0x00, //!< Disabled
96 FR_TLS_TICKET_STATEFUL = 0x01, //!< Session resumption information is stored on the server
97 ///< and an identifier is provided to the client.
98 FR_TLS_TICKET_STATELESS = 0x02, //!< A session ticket is provided to the client.
99 FR_TLS_TICKET_AUTO = FR_TLS_TICKET_STATEFUL | //!< We pick the correct cache type
100 ///< based on the TLS version and current
101 FR_TLS_TICKET_STATELESS ///< configuration.
102} fr_tls_ticket_mode_t;
103
104/** Maximum lifetime of a TLS session ticket.
105 *
106 * RFC 8446 mandates this for TLS. RFC 9190 mandates it for EAP-TLS.
107 */
108#define FR_TLS_MAX_SESSION_LIFETIME (7 * 86400)
109
110/** Bounds for `max_cert_list`
111 *
112 * `max_cert_list` is the size of the largest TLS Certificate handshake message that OpenSSL will accept from
113 * the peer. The Certificate message holds the whole certificate chain. The EAP code also uses
114 * `max_cert_list` as the limit on a reassembled EAP-TLS messages.
115 */
116#define FR_TLS_MAX_CERT_LIST_MIN (16 * 1024)
117#define FR_TLS_MAX_CERT_LIST_MAX SSL_MAX_CERT_LIST_DEFAULT
118
119/** Bounds for `max_datagram_len`
120 *
121 * `max_datagram_len` is the maximum length of a DTLS datagram which we will accept. In order to read a
122 * datagram, `dirty_in` must have at least that much space. Otherwise a UDP read() will truncate the packet.
123 *
124 * For IPv4 across the Internet, we have 576 - sizeof(ip_hdr) - sizeof(udp_hdr) = 508. But IPv6 is smaller,
125 * and if we add other IP options, the result is smaller yet. So we et it to a value which is low enough that
126 * no one should ever run into it.
127 *
128 * For the maximum, we set it to the size of an Ethernet jumbo frame, minus various overhead.
129 */
130#define FR_TLS_MAX_DATAGRAM_LEN_MIN (256)
131#define FR_TLS_MAX_DATAGRAM_LEN_MAX (9216 - (576 - 508))
132
133/** TLS 1.3 allows for padding, but it needs to be limited.
134 *
135 * Records will be padded to a multiple of the block size. It doesn't
136 * make a lot of sense to allow for large amounts of padding, so we
137 * limit that here.
138 */
139#define FR_TLS_MAX_BLOCK_PADDING (256)
140
141/** TLS 1.3 block sizes are a multiple of 16
142 *
143 * If we padd to any other multiple, then it will end up being 16 anyways.
144 */
145#define FR_TLS_BLOCK_PADDING_MULTIPLE (16)
146
147/** Cache configuration
148 *
149 */
150typedef struct {
151 fr_tls_ticket_mode_t mode; //!< What type of session resumption we're going to use.
152 bool mode_is_auto; //!< The configuration said `auto`. `mode` may have been
153 ///< rewritten to `stateless`, and this field keeps the original.
154
155 tmpl_t *id_name; //!< Context ID to allow multiple sessions stores to be defined.
156 char context_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
157
158 fr_time_delta_t lifetime; //!< The maximum period a session can be resumed after.
159
160 fr_time_delta_t min_lifetime; //!< The minimum lifetime of a session ticket.
161 ///< Tickets which has less than this lifetime are not resumed.
162 bool min_lifetime_is_set; //!< Whether `min_lifetime` came from the configuration
163
164 bool require_extms; //!< Only allow session resumption if the client/server
165 //!< supports the extended master session key. This protects
166 //!< against the triple handshake attack.
167
168 bool require_pfs; //!< Only allow session resumption if a cipher suite that
169 //!< supports perfect forward secrecy.
170
171 uint8_t const *session_ticket_key; //!< Raw input data. Is fed through HKDF to produce the
172 ///< actual session key we use.
173} fr_tls_ticket_conf_t;
174
175/** Certificate verification configuration
176 *
177 */
178typedef struct {
179 fr_tls_verify_mode_t mode; //!< What certificates we apply OpenSSL's pre-validation
180 ///< mode to.
181
182 fr_tls_verify_mode_t attribute_mode; //!< What set of certificates we're going to convert to
183 ///< pairs for verification.
184
185 bool der_decode; //!< Should certificates be passed to the DER decoder.
186} fr_tls_verify_conf_t;
187
188#ifdef PSK_MAX_IDENTITY_LEN
189/** A fixed pre-shared key
190 *
191 * A client sends the identity and uses the key. A server does not
192 * accept any other identity, and uses the key.
193 */
194typedef struct {
195 char const *identity; //!< The identity that selects the key.
196 uint8_t const *key; //!< The key as raw bytes. talloc_array_length()
197 ///< gives the length.
198} fr_tls_psk_conf_t;
199#endif
200
201/* configured values goes right here */
202struct fr_tls_conf_s {
203 CONF_SECTION *virtual_server; //!< The virtual server containing certificate validation
204 ///< policies, and cache control sections.
205
206 fr_tls_chain_conf_t **chains; //!< One or more certificates
207
208 char const *random_file; //!< If set, we read 10K of data (or the complete file)
209 //!< and use it to seed OpenSSL's PRNG.
210 char const *ca_path;
211 char const *ca_file;
212
213 char const *dh_file; //!< File to load DH Parameters from.
214
215 uint32_t verify_depth; //!< Maximum number of certificates we can traverse
216 //!< when attempting to reach the presented certificate
217 //!< from our Root CA.
218 bool disable_single_dh_use;
219
220 float tls_max_version; //!< Maximum TLS version allowed.
221 float tls_min_version; //!< Minimum TLS version allowed.
222
223 uint32_t fragment_size; //!< Maximum record fragment, or record size.
224 uint32_t min_fragment_size; //!< Smallest EAP (TLS) packet that we accept from the
225 ///< peer when the More (M) flag is set.
226 uint32_t buffer_size; //!< Size of the "clean" dbuffs for each session.
227 uint32_t max_cert_list; //!< Largest Certificate handshake message that we
228 ///< accept from the peer.
229 uint32_t max_datagram_len; //!< For DTLS, the free space which the input buffer needs
230 ///< before the connection reads a datagram.
231 uint32_t padding_block_size; //!< for TLS 1.3, pad blocks to multiple of this size.
232 ///< Zero means no padding.
233
234 char const *cipher_list; //!< Acceptable ciphers.
235 char const *cipher_suites; //!< Acceptable TLS 1.3 cipher suites.
236 bool cipher_server_preference; //!< use server preferences for cipher selection
237#ifdef SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS
238 bool allow_renegotiation; //!< Whether or not to allow cipher renegotiation.
239#endif
240 char const *group_list; //!< Supported groups.
241
242 bool require_client_cert;
243
244#ifndef OPENSSL_NO_ECDH
245 char const *ecdh_curve;
246#endif
247
248#ifdef PSK_MAX_IDENTITY_LEN
249 fr_tls_psk_conf_t psk; //!< A fixed pre-shared key. Both fields are NULL when the
250 ///< configuration sets neither `identity` nor `key`.
251#endif
252
253 char const *keylog_file; //!< for SSLKEYLOGFILE functionality.
254
255 fr_tls_ticket_conf_t cache; //!< Session cache configuration.
256 fr_tls_verify_conf_t verify;
257
258 bool delayed_tickets; //!< do we delay session tickets to after application data?
259 bool verify_certificate; //!< Does the "verify certificate" section exist.
260 bool new_session; //!< Does the "new session" section exist.
261 bool establish_session; //!< Does the "establish session" section exist.
262 bool fail_session; //!< Does the "fail session" section exist.
263
264 bool encode_session; //!< Does the "encode session" section exist.
265 bool decode_session; //!< Does the "decode session" section exist.
266 bool load_session; //!< Does the "load session" section exist.
267 bool store_session; //!< Does the "store session" section exist.
268 bool clear_session; //!< Does the "clear session" section exist.
269#ifdef PSK_MAX_IDENTITY_LEN
270 bool load_psk; //!< Does the "load psk" section exist.
271#endif
272 bool client_hello_parse; //!< Should attributes be extracted from Client Hello.
273
274 /** Application Layer Protocol Negotiation
275 *
276 * The ALPN strings (for now) must be set by the application. Only the application knows what the
277 * ALPN strings mean, and how to interpret them. Plus, the ALPN format used by OpenSSL is the raw
278 * wire format, which has a "length" prefix followed by the actual data. That's not trivially
279 * supportable by the configuration file parser.
280 *
281 * What we'd like to do is for the application to provide some kind of array of allowed ALPN
282 * strings, and then use that. The TLS code can then set a flag indicating which string was
283 * negotiated.
284 */
285 unsigned char const *alpn; //!< Protocol names, in the wire format ALPN uses: each
286 ///< name is one length octet followed by that many
287 ///< octets. NULL means we don't use ALPN.
288 size_t sizeof_alpn; //!< Length of `alpn`, which carries no terminator.
289 bool alpn_required; //!< Fail if no ALPN was negotiated.
290
291 struct fr_tls_alpn_s const *alpn_table; //!< Structure holding config -> ALPN mappings.
292 int *alpn_ids; //!< Ids of the entries of `alpn_table` which are on the list,
293 ///< in the order of preference.
294 size_t alpn_num; //!< Number of ids in `alpn_ids`.
295
296 /** Underlying transport.
297 *
298 * The TLS library does NOT manage any IO itself. However, it
299 * does need to know whether it's supposed to do TLS or DTLS.
300 * Instead of having a separate flag / enum, we just re-use
301 * SOCK_*. Only the application knows what IO method it's using,
302 * so it has to this field manually, just as with ALPN.
303 *
304 * If it's unset (i.e. zero), then we default to SOCK_STREAM.
305 */
306 int socket_type;
307};
308
309#ifdef __cplusplus
310}
311#endif
312#endif /* WITH_TLS */
#define RCSIDH(h, id)
Definition build.h:610
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
unsigned int uint32_t
unsigned char uint8_t
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"Unix" time.
Definition time.h:95