The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
tls.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 (at
6 * 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
18/**
19 * $Id: 48c46e7ffc3a5757d4275d8a18e81f4c6bd90677 $
20 * @file lib/eap/tls.h
21 * @brief Generic EAP over TLS API
22 *
23 * @copyright 2001 hereUare Communications, Inc. (raghud@hereuare.com)
24 * @copyright 2003 Alan DeKok (aland@freeradius.org)
25 * @copyright 2006 The FreeRADIUS server project
26 */
27
28RCSIDH(lib_eap_tls_h, "$Id: 48c46e7ffc3a5757d4275d8a18e81f4c6bd90677 $")
29USES_APPLE_DEPRECATED_API /* OpenSSL API has been deprecated by Apple */
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34#include <errno.h>
35#include <sys/types.h>
36#include <sys/socket.h>
37#include <netinet/in.h>
38#include <netinet/tcp.h>
39#include <netdb.h>
40#include <fcntl.h>
41#include <signal.h>
42
43#include <ctype.h>
44#include <sys/time.h>
45#include <arpa/inet.h>
46
47#ifdef HAVE_UNISTD_H
48# include <unistd.h>
49#endif
50
51#include <freeradius-devel/server/base.h>
52#include <freeradius-devel/tls/base.h>
53#include <freeradius-devel/eap/base.h>
54
55#define TLS_HEADER_LEN 4
56#define TLS_HEADER_LENGTH_FIELD_LEN 4
57
58/** Overhead subtracted from the MTU of an EAP-TLS session which is nested inside a tunneled method.
59 *
60 * The outer TLS session adds a 5 octet record header, plus the IV, MAC or tag, and padding of the cipher
61 * suite, to every inner EAP packet. This value is a conservative allowance and is not an exact figure.
62 */
63#define EAP_TLS_NESTED_OVERHEAD 100
64
65/*
66 * RFC 2716, Section 4.2:
67 *
68 * Flags
69 *
70 * 0 1 2 3 4 5 6 7 8
71 * +-+-+-+-+-+-+-+-+
72 * |L M S R R R R R|
73 * +-+-+-+-+-+-+-+-+
74 *
75 * L = Length included
76 * M = More fragments
77 * S = EAP-TLS start
78 * R = Reserved
79 */
80#define TLS_RESERVED4(x) (((x) & 0x01) != 0)
81#define TLS_RESERVED3(x) (((x) & 0x02) != 0)
82#define TLS_RESERVED2(x) (((x) & 0x04) != 0)
83#define TLS_RESERVED1(x) (((x) & 0x08) != 0)
84#define TLS_RESERVED0(x) (((x) & 0x10) != 0)
85#define TLS_START(x) (((x) & 0x20) != 0)
86#define TLS_MORE_FRAGMENTS(x) (((x) & 0x40) != 0)
87#define TLS_LENGTH_INCLUDED(x) (((x) & 0x80) != 0)
88
89#define SET_START(x) ((x) | (0x20))
90#define SET_MORE_FRAGMENTS(x) ((x) | (0x40))
91#define SET_LENGTH_INCLUDED(x) ((x) | (0x80))
92
93#define FR_TLS_EAP_BUFFER_SIZE_MIN (2048)
94#define FR_TLS_EAP_BUFFER_SIZE_MAX (65536)
95
96typedef enum : uint8_t {
97 EAP_TLS_INVALID = 0, //!< Invalid, don't reply.
98 EAP_TLS_ESTABLISHED, //!< Session established, send success (or start phase2).
99 EAP_TLS_FAIL, //!< Fail, send fail.
100 EAP_TLS_HANDLED, //!< TLS code has handled it.
101
102 /*
103 * Composition states, we need to
104 * compose a request of this type.
105 */
106 EAP_TLS_START_SEND, //!< We're starting a new TLS session.
107 EAP_TLS_RECORD_SEND, //!< We're sending a record.
108 EAP_TLS_ACK_SEND, //!< Acknowledge receipt of a record or record fragment.
109
110 /*
111 * Receive states, we received a
112 * response containing a fragment of a
113 * record.
114 */
115 EAP_TLS_RECORD_RECV_FIRST, //!< Received first fragment of a record.
116 EAP_TLS_RECORD_RECV_MORE, //!< Received additional fragment of a record.
117 EAP_TLS_RECORD_RECV_COMPLETE //!< Received final fragment of a record.
119
124
125/** Tracks the state of an EAP-TLS session
126 *
127 * Contains any EAP-TLS specific state information, such as whether we're
128 * sending/receiving fragments, and the progress of those operations.
129 *
130 * TLS session state is stored in a fr_tls_session_t accessed via the tls_session field.
131 */
132typedef struct {
133 eap_tls_status_t state; //!< The state of the EAP-TLS session.
134
135 fr_tls_session_t *tls_session; //!< TLS session used to authenticate peer
136 //!< or tunnel sensitive data.
137
138 int base_flags; //!< Some protocols use the reserved bits of the EAP-TLS
139 //!< flags (such as PEAP). This allows the base flags to
140 //!< be set.
141
142 bool phase2; //!< Whether we're in phase 2
143
144 bool include_length; //!< A flag to include length in every TLS Data/Alert packet.
145 //!< If set to no then only the first fragment contains length.
146
147 bool authentication_success; //! for methods with inner auth, if the inner auth succeeded.
148
149 bool record_out_started; //!< Whether a record transfer to the peer is currently
150 //!< in progress.
151 size_t record_out_total_len; //!< Actual/Total TLS message length we're sending.
152
153 bool record_in_started; //!< Whether a record transfer from the peer is currently
154 //!< in progress.
155 size_t record_in_total_len; //!< How long the peer indicated the complete tls record
156 //!< would be.
157 size_t record_in_recvd_len; //!< How much of the record we've received so far.
159
160typedef struct {
161 char const *keying_prf_label; //!< PRF label to use for generating keying material.
162 //!< If NULL, no MPPE keys will be generated.
163 size_t keying_prf_label_len; //!< length of the keying PRF label.
164
165 char const *sessid_prf_label; //!< PRF label to use when generating the session ID.
166 //!< If NULL, session ID will be based on client/server randoms.
167 size_t sessid_prf_label_len; //!< Length of the session ID PRF label.
168
169 uint8_t context[1]; //!< for TLS 1.3 context, is the EAP Type code
170 size_t context_len; //!< length of the context
171
172 int use_context; //!< for SSL_export_keying_material().
174
176extern size_t eap_tls_status_table_len;
177
178/*
179 * Externally exported TLS functions.
180 */
182
183int eap_tls_start(request_t *request, eap_session_t *eap_session) CC_HINT(nonnull);
184
186
188 /*!< The caller must set its result before calling this,
189 because the return value may be UNLANG_ACTION_PUSHED_CHILD. */
190
191int eap_tls_request(request_t *request, eap_session_t *eap_session) CC_HINT(nonnull);
192
194 eap_tls_status_t status, uint8_t flags,
195 fr_dbuff_t *record, size_t record_len, size_t frag_len);
196
197/* MPPE key generation */
199 char const *keying_prf_label, size_t keying_prf_label_len);
200
201int eap_crypto_mppe_keys(request_t *request, SSL *ssl, eap_tls_prf_label_t *prf_label) CC_HINT(nonnull);
202
203int eap_crypto_tls_session_id(TALLOC_CTX *ctx, request_t *request,
204 SSL *ssl, eap_tls_prf_label_t *prf_label, uint8_t **out,
206
207/* EAP-TLS framework */
209 SSL_CTX *ssl_ctx, bool client_cert) CC_HINT(nonnull);
210
211
212void eap_tls_conf_check(CONF_SECTION *cs, fr_tls_conf_t *tls_conf, bool delayed_tickets) CC_HINT(nonnull);
213
214int eap_tls_check_stateless(CONF_SECTION *cs, fr_tls_conf_t const *tls_conf) CC_HINT(nonnull);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
static int context
Definition radmin.c:69
static uint8_t request[4]
#define USES_APPLE_DEPRECATED_API
Definition build.h:596
#define RCSIDH(h, id)
Definition build.h:610
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
eap_type
Definition types.h:44
Tracks the progress of a single session of any EAP method.
Definition session.h:41
int base_flags
Some protocols use the reserved bits of the EAP-TLS flags (such as PEAP).
Definition tls.h:138
eap_tls_status_t
Definition tls.h:96
@ EAP_TLS_RECORD_RECV_FIRST
Received first fragment of a record.
Definition tls.h:115
@ EAP_TLS_INVALID
Invalid, don't reply.
Definition tls.h:97
@ EAP_TLS_HANDLED
TLS code has handled it.
Definition tls.h:100
@ EAP_TLS_RECORD_RECV_MORE
Received additional fragment of a record.
Definition tls.h:116
@ EAP_TLS_ACK_SEND
Acknowledge receipt of a record or record fragment.
Definition tls.h:108
@ EAP_TLS_RECORD_SEND
We're sending a record.
Definition tls.h:107
@ EAP_TLS_RECORD_RECV_COMPLETE
Received final fragment of a record.
Definition tls.h:117
@ EAP_TLS_START_SEND
We're starting a new TLS session.
Definition tls.h:106
@ EAP_TLS_FAIL
Fail, send fail.
Definition tls.h:99
@ EAP_TLS_ESTABLISHED
Session established, send success (or start phase2).
Definition tls.h:98
eap_tls_status_t state
The state of the EAP-TLS session.
Definition tls.h:133
bool phase2
Whether we're in phase 2.
Definition tls.h:142
eap_tls_session_t * eap_tls_session_init(request_t *request, eap_session_t *eap_session, SSL_CTX *ssl_ctx, bool client_cert)
Create a new fr_tls_session_t associated with an eap_session_t.
Definition tls.c:1218
fr_tls_session_t * tls_session
TLS session used to authenticate peer or tunnel sensitive data.
Definition tls.h:135
size_t keying_prf_label_len
length of the keying PRF label.
Definition tls.h:163
bool record_in_started
Whether a record transfer from the peer is currently in progress.
Definition tls.h:153
size_t record_out_total_len
Actual/Total TLS message length we're sending.
Definition tls.h:151
uint8_t flags
Definition tls.h:121
void eap_tls_conf_check(CONF_SECTION *cs, fr_tls_conf_t *tls_conf, bool delayed_tickets)
Apply the limits that EAP puts on a parsed tls { ... } section.
Definition tls.c:1396
char const * keying_prf_label
PRF label to use for generating keying material.
Definition tls.h:161
void eap_crypto_prf_label_init(eap_tls_prf_label_t *prf_label, eap_session_t *eap_session, char const *keying_prf_label, size_t keying_prf_label_len)
Initialize the PRF label fields.
Definition crypto.c:48
fr_table_num_ordered_t const eap_tls_status_table[]
Definition tls.c:80
size_t context_len
length of the context
Definition tls.h:170
size_t record_in_total_len
How long the peer indicated the complete tls record would be.
Definition tls.h:155
size_t eap_tls_status_table_len
Definition tls.c:94
int eap_tls_compose(request_t *request, eap_session_t *eap_session, eap_tls_status_t status, uint8_t flags, fr_dbuff_t *record, size_t record_len, size_t frag_len)
Convert the EAP-TLS reply packet into an EAP packet.
Definition tls.c:114
int eap_crypto_mppe_keys(request_t *request, SSL *ssl, eap_tls_prf_label_t *prf_label)
Generate keys according to RFC 5216 and add to the reply.
Definition crypto.c:83
int eap_tls_start(request_t *request, eap_session_t *eap_session)
Send an initial EAP-TLS request to the peer.
Definition tls.c:242
int eap_tls_request(request_t *request, eap_session_t *eap_session)
Frames the OpenSSL data that needs to be sent to the client in an EAP-Request.
Definition tls.c:392
char const * sessid_prf_label
PRF label to use when generating the session ID.
Definition tls.h:165
bool record_out_started
for methods with inner auth, if the inner auth succeeded.
Definition tls.h:149
int eap_tls_check_stateless(CONF_SECTION *cs, fr_tls_conf_t const *tls_conf)
Check that the TLS configuration does not need stateless session tickets.
Definition tls.c:1449
size_t record_in_recvd_len
How much of the record we've received so far.
Definition tls.h:157
int use_context
for SSL_export_keying_material().
Definition tls.h:172
int eap_crypto_tls_session_id(TALLOC_CTX *ctx, request_t *request, SSL *ssl, eap_tls_prf_label_t *prf_label, uint8_t **out, uint8_t eap_type)
Definition crypto.c:130
unlang_action_t eap_tls_fail(request_t *request, eap_session_t *eap_session)
Send an EAP-TLS failure.
Definition tls.c:339
unlang_action_t eap_tls_success(request_t *request, eap_session_t *eap_session, eap_tls_prf_label_t *prf_label))
Send an EAP-TLS success.
Definition tls.c:278
bool authentication_success
Definition tls.h:147
size_t sessid_prf_label_len
Length of the session ID PRF label.
Definition tls.h:167
bool include_length
A flag to include length in every TLS Data/Alert packet.
Definition tls.h:144
unlang_action_t eap_tls_process(request_t *request, eap_session_t *eap_session)
Process an EAP TLS request.
Definition tls.c:1043
Tracks the state of an EAP-TLS session.
Definition tls.h:132
unsigned char uint8_t
Signals that can be sent to a request.
An element in an arbitrarily ordered array of name to num mappings.
Definition table.h:57
static fr_slen_t data
Definition value.h:1366
static fr_sbuff_err_t char ** out
Definition value.h:1061
int nonnull(2, 5))