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: 0ef9a3e35c99fa8ccfa51987522d2ebc33ec6713 $
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: 0ef9a3e35c99fa8ccfa51987522d2ebc33ec6713 $")
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
93typedef enum : uint8_t {
94 EAP_TLS_INVALID = 0, //!< Invalid, don't reply.
95 EAP_TLS_ESTABLISHED, //!< Session established, send success (or start phase2).
96 EAP_TLS_FAIL, //!< Fail, send fail.
97 EAP_TLS_HANDLED, //!< TLS code has handled it.
98
99 /*
100 * Composition states, we need to
101 * compose a request of this type.
102 */
103 EAP_TLS_START_SEND, //!< We're starting a new TLS session.
104 EAP_TLS_RECORD_SEND, //!< We're sending a record.
105 EAP_TLS_ACK_SEND, //!< Acknowledge receipt of a record or record fragment.
106
107 /*
108 * Receive states, we received a
109 * response containing a fragment of a
110 * record.
111 */
112 EAP_TLS_RECORD_RECV_FIRST, //!< Received first fragment of a record.
113 EAP_TLS_RECORD_RECV_MORE, //!< Received additional fragment of a record.
114 EAP_TLS_RECORD_RECV_COMPLETE //!< Received final fragment of a record.
116
121
122/** Tracks the state of an EAP-TLS session
123 *
124 * Contains any EAP-TLS specific state information, such as whether we're
125 * sending/receiving fragments, and the progress of those operations.
126 *
127 * TLS session state is stored in a fr_tls_session_t accessed via the tls_session field.
128 */
129typedef struct {
130 eap_tls_status_t state; //!< The state of the EAP-TLS session.
131
132 fr_tls_session_t *tls_session; //!< TLS session used to authenticate peer
133 //!< or tunnel sensitive data.
134
135 int base_flags; //!< Some protocols use the reserved bits of the EAP-TLS
136 //!< flags (such as PEAP). This allows the base flags to
137 //!< be set.
138
139 bool phase2; //!< Whether we're in phase 2
140
141 bool include_length; //!< A flag to include length in every TLS Data/Alert packet.
142 //!< If set to no then only the first fragment contains length.
143
144 bool authentication_success; //! for methods with inner auth, if the inner auth succeeded.
145
146 bool record_out_started; //!< Whether a record transfer to the peer is currently
147 //!< in progress.
148 size_t record_out_total_len; //!< Actual/Total TLS message length we're sending.
149
150 bool record_in_started; //!< Whether a record transfer from the peer is currently
151 //!< in progress.
152 size_t record_in_total_len; //!< How long the peer indicated the complete tls record
153 //!< would be.
154 size_t record_in_recvd_len; //!< How much of the record we've received so far.
156
157typedef struct {
158 char const *keying_prf_label; //!< PRF label to use for generating keying material.
159 //!< If NULL, no MPPE keys will be generated.
160 size_t keying_prf_label_len; //!< length of the keying PRF label.
161
162 char const *sessid_prf_label; //!< PRF label to use when generating the session ID.
163 //!< If NULL, session ID will be based on client/server randoms.
164 size_t sessid_prf_label_len; //!< Length of the session ID PRF label.
165
166 uint8_t context[1]; //!< for TLS 1.3 context, is the EAP Type code
167 size_t context_len; //!< length of the context
168
169 int use_context; //!< for SSL_export_keying_material().
171
173extern size_t eap_tls_status_table_len;
174
175/*
176 * Externally exported TLS functions.
177 */
179
180int eap_tls_start(request_t *request, eap_session_t *eap_session) CC_HINT(nonnull);
181
183
185 /*!< The caller must set its result before calling this,
186 because the return value may be UNLANG_ACTION_PUSHED_CHILD. */
187
188int eap_tls_request(request_t *request, eap_session_t *eap_session) CC_HINT(nonnull);
189
191 eap_tls_status_t status, uint8_t flags,
192 fr_dbuff_t *record, size_t record_len, size_t frag_len);
193
194/* MPPE key generation */
196 char const *keying_prf_label, size_t keying_prf_label_len);
197
198int eap_crypto_mppe_keys(request_t *request, SSL *ssl, eap_tls_prf_label_t *prf_label) CC_HINT(nonnull);
199
200int eap_crypto_tls_session_id(TALLOC_CTX *ctx, request_t *request,
201 SSL *ssl, eap_tls_prf_label_t *prf_label, uint8_t **out,
203
204/* EAP-TLS framework */
206 SSL_CTX *ssl_ctx, bool client_cert) CC_HINT(nonnull);
207
208
209void eap_tls_conf_check(CONF_SECTION *cs, fr_tls_conf_t *tls_conf, bool delayed_tickets) CC_HINT(nonnull);
210
211int 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:590
#define RCSIDH(h, id)
Definition build.h:604
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
int base_flags
Some protocols use the reserved bits of the EAP-TLS flags (such as PEAP).
Definition tls.h:135
eap_tls_status_t
Definition tls.h:93
@ EAP_TLS_RECORD_RECV_FIRST
Received first fragment of a record.
Definition tls.h:112
@ EAP_TLS_INVALID
Invalid, don't reply.
Definition tls.h:94
@ EAP_TLS_HANDLED
TLS code has handled it.
Definition tls.h:97
@ EAP_TLS_RECORD_RECV_MORE
Received additional fragment of a record.
Definition tls.h:113
@ EAP_TLS_ACK_SEND
Acknowledge receipt of a record or record fragment.
Definition tls.h:105
@ EAP_TLS_RECORD_SEND
We're sending a record.
Definition tls.h:104
@ EAP_TLS_RECORD_RECV_COMPLETE
Received final fragment of a record.
Definition tls.h:114
@ EAP_TLS_START_SEND
We're starting a new TLS session.
Definition tls.h:103
@ EAP_TLS_FAIL
Fail, send fail.
Definition tls.h:96
@ EAP_TLS_ESTABLISHED
Session established, send success (or start phase2).
Definition tls.h:95
eap_tls_status_t state
The state of the EAP-TLS session.
Definition tls.h:130
bool phase2
Whether we're in phase 2.
Definition tls.h:139
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:1215
fr_tls_session_t * tls_session
TLS session used to authenticate peer or tunnel sensitive data.
Definition tls.h:132
size_t keying_prf_label_len
length of the keying PRF label.
Definition tls.h:160
bool record_in_started
Whether a record transfer from the peer is currently in progress.
Definition tls.h:150
size_t record_out_total_len
Actual/Total TLS message length we're sending.
Definition tls.h:148
uint8_t flags
Definition tls.h:118
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:1393
char const * keying_prf_label
PRF label to use for generating keying material.
Definition tls.h:158
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:167
size_t record_in_total_len
How long the peer indicated the complete tls record would be.
Definition tls.h:152
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:162
bool record_out_started
for methods with inner auth, if the inner auth succeeded.
Definition tls.h:146
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:1432
size_t record_in_recvd_len
How much of the record we've received so far.
Definition tls.h:154
int use_context
for SSL_export_keying_material().
Definition tls.h:169
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:144
size_t sessid_prf_label_len
Length of the session ID PRF label.
Definition tls.h:164
bool include_length
A flag to include length in every TLS Data/Alert packet.
Definition tls.h:141
unlang_action_t eap_tls_process(request_t *request, eap_session_t *eap_session)
Process an EAP TLS request.
Definition tls.c:1040
Tracks the state of an EAP-TLS session.
Definition tls.h:129
eap_type
Definition types.h:44
Tracks the progress of a single session of any EAP method.
Definition session.h:41
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))