The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
rlm_eap_fast.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 7cc9b02fe5c66edacafc15b189b4331ce6729b0b $
19 * @file rlm_eap_fast.c
20 * @brief contains the interfaces that are called from eap
21 *
22 * @author Alexander Clouter (alex@digriz.org.uk)
23 *
24 * @copyright 2016 Alan DeKok (aland@freeradius.org)
25 * @copyright 2016 The FreeRADIUS server project
26 */
27RCSID("$Id: 7cc9b02fe5c66edacafc15b189b4331ce6729b0b $")
28USES_APPLE_DEPRECATED_API /* OpenSSL API has been deprecated by Apple */
29
30#include <freeradius-devel/util/md5.h>
31#include <freeradius-devel/tls/utils.h>
32#include <freeradius-devel/unlang/function.h>
33#include <openssl/rand.h>
34#include "eap_fast.h"
35#include "eap_fast_crypto.h"
36
37typedef struct {
38 SSL_CTX *ssl_ctx; //!< Thread local SSL_CTX.
40
41/*
42 * An instance of EAP-FAST
43 */
44typedef struct {
45 fr_tls_conf_t *tls_conf; //!< Parsed from the `tls { ... }` subsection.
46
49
50 virtual_server_t *virtual_server; //!< Virtual server to use for processing
51 //!< inner EAP method.
52 char const *cipher_list; //!< cipher list specific to EAP-FAST
53 bool req_client_cert; //!< Whether we require a client cert
54 //!< in the outer tunnel.
55
56 int stage; //!< Processing stage.
57
58 fr_time_delta_t pac_lifetime; //!< seconds to add to current time to describe PAC lifetime
59 char const *authority_identity; //!< The identity we present in the EAP-TLS
60 uint8_t a_id[PAC_A_ID_LENGTH]; //!< The identity we present in the EAP-TLS
61 char const *pac_opaque_key; //!< The key used to encrypt PAC-Opaque
63
64
66 { FR_CONF_SUBSECTION_ALLOC("tls", CONF_FLAG_REQUIRED, rlm_eap_fast_t, tls_conf, fr_tls_server_config),
67 .subcs_type = "fr_tls_conf_t" },
68
69 { FR_CONF_OFFSET("default_provisioning_eap_type", rlm_eap_fast_t, default_provisioning_method_name), .dflt = "mschapv2" },
70
73 .uctx = &(virtual_server_cf_parse_uctx_t){ .process_module_name = "radius"} },
74
75 { FR_CONF_OFFSET("cipher_list", rlm_eap_fast_t, cipher_list) },
76
77 { FR_CONF_OFFSET("require_client_cert", rlm_eap_fast_t, req_client_cert), .dflt = "no" },
78
79 { FR_CONF_OFFSET("pac_lifetime", rlm_eap_fast_t, pac_lifetime), .dflt = "604800" },
80 { FR_CONF_OFFSET_FLAGS("authority_identity", CONF_FLAG_REQUIRED, rlm_eap_fast_t, authority_identity) },
81 { FR_CONF_OFFSET_FLAGS("pac_opaque_key", CONF_FLAG_REQUIRED, rlm_eap_fast_t, pac_opaque_key) },
82
84};
85
87static fr_dict_t const *dict_radius;
89
92 { .out = &dict_freeradius, .proto = "freeradius" },
93 { .out = &dict_radius, .proto = "radius" },
94 { .out = &dict_eap_fast, .base_dir = "eap/fast", .proto = "eap-fast" },
96};
97
104
111
138
141 { .out = &attr_eap_emsk, .name = "EAP-EMSK", .type = FR_TYPE_OCTETS, .dict = &dict_freeradius },
142 { .out = &attr_eap_msk, .name = "EAP-MSK", .type = FR_TYPE_OCTETS, .dict = &dict_freeradius },
143 { .out = &attr_eap_tls_require_client_cert, .name = "EAP-TLS-Require-Client-Cert", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
144 { .out = &attr_eap_type, .name = "EAP-Type", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
145 { .out = &attr_microsoft, .name = "Vendor-Specific.Microsoft", .type = FR_TYPE_VENDOR, .dict = &dict_radius },
146 { .out = &attr_ms_chap_challenge, .name = "Vendor-Specific.Microsoft.CHAP-Challenge", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
147 { .out = &attr_ms_chap_peer_challenge, .name = "MS-CHAP-Peer-Challenge", .type = FR_TYPE_OCTETS, .dict = &dict_freeradius },
148
149 { .out = &attr_eap_message, .name = "EAP-Message", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
150 { .out = &attr_ms_mppe_send_key, .name = "Vendor-Specific.Microsoft.MPPE-Send-Key", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
151 { .out = &attr_ms_mppe_recv_key, .name = "Vendor-Specific.Microsoft.MPPE-Recv-Key", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
152 { .out = &attr_user_name, .name = "User-Name", .type = FR_TYPE_STRING, .dict = &dict_radius },
153 { .out = &attr_user_password, .name = "User-Password", .type = FR_TYPE_STRING, .dict = &dict_radius },
154
155 { .out = &attr_eap_fast_crypto_binding, .name = "Crypto-Binding", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
156 { .out = &attr_eap_fast_eap_payload, .name = "EAP-Payload", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
157 { .out = &attr_eap_fast_error, .name = "Error", .type = FR_TYPE_UINT32, .dict = &dict_eap_fast },
158 { .out = &attr_eap_fast_intermediate_result, .name = "Intermediate-Result", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
159 { .out = &attr_eap_fast_nak, .name = "NAK", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
160 { .out = &attr_eap_fast_pac_a_id, .name = "PAC.A-ID", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
161 { .out = &attr_eap_fast_pac_a_id_info, .name = "PAC.A-ID-Info", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
162 { .out = &attr_eap_fast_pac_acknowledge, .name = "PAC.Acknowledge", .type = FR_TYPE_UINT16, .dict = &dict_eap_fast },
163 { .out = &attr_eap_fast_pac_i_id, .name = "PAC.I-ID", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
164 { .out = &attr_eap_fast_pac_info_a_id, .name = "PAC.Info.A-ID", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
165 { .out = &attr_eap_fast_pac_info_a_id_info, .name = "PAC.Info.A-ID-Info", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
166 { .out = &attr_eap_fast_pac_info_i_id, .name = "PAC.Info.I-ID", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
167 { .out = &attr_eap_fast_pac_info_pac_lifetime, .name = "PAC.Info.PAC-Lifetime", .type = FR_TYPE_UINT32, .dict = &dict_eap_fast },
168 { .out = &attr_eap_fast_pac_info_pac_type, .name = "PAC.Info.PAC-Type", .type = FR_TYPE_UINT16, .dict = &dict_eap_fast },
169 { .out = &attr_eap_fast_pac_info_tlv, .name = "PAC.Info", .type = FR_TYPE_TLV, .dict = &dict_eap_fast },
170 { .out = &attr_eap_fast_pac_key, .name = "PAC.Key", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
171 { .out = &attr_eap_fast_pac_lifetime, .name = "PAC.Lifetime", .type = FR_TYPE_UINT32, .dict = &dict_eap_fast },
172 { .out = &attr_eap_fast_pac_opaque_i_id, .name = "PAC.Opaque.I-ID", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
173 { .out = &attr_eap_fast_pac_opaque_pac_key, .name = "PAC.Opaque.PAC-Key", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
174 { .out = &attr_eap_fast_pac_opaque_pac_lifetime, .name = "PAC.Opaque.PAC-Lifetime", .type = FR_TYPE_UINT32, .dict = &dict_eap_fast },
175 { .out = &attr_eap_fast_pac_opaque_pac_type, .name = "PAC.Opaque.PAC-Type", .type = FR_TYPE_UINT16, .dict = &dict_eap_fast },
176 { .out = &attr_eap_fast_pac_opaque_tlv, .name = "PAC.Opaque", .type = FR_TYPE_TLV, .dict = &dict_eap_fast },
177 { .out = &attr_eap_fast_pac_tlv, .name = "PAC", .type = FR_TYPE_TLV, .dict = &dict_eap_fast },
178 { .out = &attr_eap_fast_pac_type, .name = "PAC.Type", .type = FR_TYPE_UINT16, .dict = &dict_eap_fast },
179 { .out = &attr_eap_fast_result, .name = "Result", .type = FR_TYPE_UINT16, .dict = &dict_eap_fast },
180 { .out = &attr_eap_fast_vendor_specific, .name = "Vendor-Specific", .type = FR_TYPE_OCTETS, .dict = &dict_eap_fast },
181
183};
184
185#define RANDFILL(x) do { fr_assert(sizeof(x) % sizeof(uint32_t) == 0); for (size_t i = 0; i < sizeof(x); i += sizeof(uint32_t)) *((uint32_t *)&x[i]) = fr_rand(); } while(0)
186
187/**
188 * RFC 4851 section 5.1 - EAP-FAST Authentication Phase 1: Key Derivations
189 */
190static void eap_fast_init_keys(request_t *request, fr_tls_session_t *tls_session)
191{
192 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
193 uint8_t *buf;
194 uint8_t *scratch;
195 size_t ksize;
196
197 RDEBUG2("Deriving EAP-FAST keys");
198
199 fr_assert(t->s_imck == NULL);
200
201 ksize = fr_tls_utils_keyblock_size_get(request, tls_session->ssl);
202 fr_assert(ksize > 0);
203 buf = talloc_array(request, uint8_t, ksize + sizeof(*t->keyblock));
204 scratch = talloc_array(request, uint8_t, ksize + sizeof(*t->keyblock));
205
206 t->keyblock = talloc(t, eap_fast_keyblock_t);
207
208 eap_fast_tls_gen_challenge(tls_session->ssl, SSL_version(tls_session->ssl), buf, scratch,
209 ksize + sizeof(*t->keyblock), "key expansion");
210 memcpy(t->keyblock, &buf[ksize], sizeof(*t->keyblock));
211 memset(buf, 0, ksize + sizeof(*t->keyblock));
212
213 t->s_imck = talloc_array(t, uint8_t, EAP_FAST_SIMCK_LEN);
214 memcpy(t->s_imck, t->keyblock, EAP_FAST_SKS_LEN); /* S-IMCK[0] = session_key_seed */
215
216 t->cmk = talloc_array(t, uint8_t, EAP_FAST_CMK_LEN); /* note that CMK[0] is not defined */
217 t->imck_count = 0;
218
219 talloc_free(buf);
220 talloc_free(scratch);
221}
222
223/**
224 * RFC 4851 section 5.2 - Intermediate Compound Key Derivations
225 */
226static void eap_fast_update_icmk(request_t *request, fr_tls_session_t *tls_session, uint8_t *msk)
227{
228 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
230
231 RDEBUG2("Updating ICMK");
232
233 T_PRF(t->s_imck, EAP_FAST_SIMCK_LEN, "Inner Methods Compound Keys", msk, 32, imck, sizeof(imck)); //-V512
234
235 memcpy(t->s_imck, imck, EAP_FAST_SIMCK_LEN);
236 RHEXDUMP3(t->s_imck, EAP_FAST_SIMCK_LEN, "S-IMCK[j]");
237
238 memcpy(t->cmk, &imck[EAP_FAST_SIMCK_LEN], EAP_FAST_CMK_LEN);
239 RHEXDUMP3(t->cmk, EAP_FAST_CMK_LEN, "CMK[j]");
240
241 t->imck_count++;
242
243 /*
244 * Calculate MSK/EMSK at the same time as they are coupled to ICMK
245 *
246 * RFC 4851 section 5.4 - EAP Master Session Key Generation
247 */
248 t->msk = talloc_array(t, uint8_t, EAP_FAST_KEY_LEN);
249 T_PRF(t->s_imck, EAP_FAST_SIMCK_LEN, "Session Key Generating Function", NULL, 0, t->msk, EAP_FAST_KEY_LEN);
250 RHEXDUMP3(t->msk, EAP_FAST_KEY_LEN, "MSK");
251
252 t->emsk = talloc_array(t, uint8_t, EAP_EMSK_LEN);
253 T_PRF(t->s_imck, EAP_FAST_SIMCK_LEN, "Extended Session Key Generating Function", NULL, 0, t->emsk, EAP_EMSK_LEN);
254 RHEXDUMP3(t->emsk, EAP_EMSK_LEN, "EMSK");
255}
256
257static void eap_fast_tlv_append(fr_tls_session_t *tls_session, fr_dict_attr_t const *tlv, bool mandatory, size_t length, void const *data)
258{
259 uint16_t hdr[2];
260
261 hdr[0] = (mandatory) ? htons(tlv->attr | EAP_FAST_TLV_MANDATORY) : htons(tlv->attr);
262 hdr[1] = htons(length);
263
264 (void) fr_dbuff_in_memcpy_partial(&tls_session->clean_in, (uint8_t const *) &hdr, (size_t) 4);
265 (void) fr_dbuff_in_memcpy_partial(&tls_session->clean_in, (uint8_t const *) data, length);
266}
267
268static void eap_fast_send_error(fr_tls_session_t *tls_session, int error)
269{
271 value = htonl(error);
272
273 eap_fast_tlv_append(tls_session, attr_eap_fast_error, true, sizeof(value), &value);
274}
275
276static void eap_fast_append_result(fr_tls_session_t *tls_session, fr_radius_packet_code_t code)
277{
278 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
279 uint16_t state;
280 fr_dict_attr_t const *da;
281
282
285
286 eap_fast_tlv_append(tls_session, da, true, sizeof(state), &state);
287}
288
289static void eap_fast_send_identity_request(request_t *request, fr_tls_session_t *tls_session, eap_session_t *eap_session)
290{
291 eap_packet_hdr_t eap_packet;
292
293 RDEBUG2("Sending EAP-Identity");
294
295 eap_packet.code = FR_EAP_CODE_REQUEST;
296 eap_packet.id = eap_session->this_round->response->id + 1;
297 eap_packet.length[0] = 0;
298 eap_packet.length[1] = EAP_HEADER_LEN + 1;
299 eap_packet.data[0] = FR_EAP_METHOD_IDENTITY;
300
301 eap_fast_tlv_append(tls_session, attr_eap_fast_eap_payload, true, sizeof(eap_packet), &eap_packet);
302}
303
304static void eap_fast_send_pac_tunnel(request_t *request, fr_tls_session_t *tls_session)
305{
306 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
307 eap_fast_pac_t pac;
309 size_t alen;
310 int dlen;
311
312 memset(&pac, 0, sizeof(pac));
313 memset(&opaque_plaintext, 0, sizeof(opaque_plaintext));
314
315 RDEBUG2("Sending Tunnel PAC");
316
318 pac.key.hdr.length = htons(sizeof(pac.key.data));
319 fr_assert(sizeof(pac.key.data) % sizeof(uint32_t) == 0);
320 RANDFILL(pac.key.data);
321
323 pac.info.lifetime.hdr.length = htons(sizeof(pac.info.lifetime.data));
324 pac.info.lifetime.data = htonl(fr_time_to_sec(fr_time_add(request->packet->timestamp, t->pac_lifetime)));
325
327 pac.info.a_id.hdr.length = htons(sizeof(pac.info.a_id.data));
328 memcpy(pac.info.a_id.data, t->a_id, sizeof(pac.info.a_id.data));
329
331 pac.info.a_id_info.hdr.length = htons(sizeof(pac.info.a_id_info.data));
332
333#define MIN(a,b) (((a)>(b)) ? (b) : (a))
334 alen = MIN(talloc_strlen(t->authority_identity), sizeof(pac.info.a_id_info.data));
335 memcpy(pac.info.a_id_info.data, t->authority_identity, alen);
336
338 pac.info.type.hdr.length = htons(sizeof(pac.info.type.data));
339 pac.info.type.data = htons(PAC_TYPE_TUNNEL);
340
342 pac.info.hdr.length = htons(sizeof(pac.info.lifetime)
343 + sizeof(pac.info.a_id)
344 + sizeof(pac.info.a_id_info)
345 + sizeof(pac.info.type));
346
347 memcpy(&opaque_plaintext.type, &pac.info.type, sizeof(opaque_plaintext.type));
348 memcpy(&opaque_plaintext.lifetime, &pac.info.lifetime, sizeof(opaque_plaintext.lifetime));
349 memcpy(&opaque_plaintext.key, &pac.key, sizeof(opaque_plaintext.key));
350
351 RHEXDUMP3((uint8_t const *)&opaque_plaintext, sizeof(opaque_plaintext), "PAC-Opaque plaintext data section");
352
353 fr_assert(PAC_A_ID_LENGTH <= EVP_GCM_TLS_TAG_LEN);
354 memcpy(pac.opaque.aad, t->a_id, PAC_A_ID_LENGTH);
355
356 /*
357 * Generating the IV is not optional. Do NOT put the
358 * call to RAND_bytes() into an assertion, because the
359 * build compiles assertions out when the build defines
360 * NDEBUG.
361 */
362 if (RAND_bytes(pac.opaque.iv, sizeof(pac.opaque.iv)) != 1) {
363 RERROR("Failed generating random IV for the PAC-Opaque");
364 return;
365 }
366
367 dlen = eap_fast_encrypt((unsigned const char *)&opaque_plaintext, sizeof(opaque_plaintext),
369 pac.opaque.data, pac.opaque.tag);
370
372 pac.opaque.hdr.length = htons(sizeof(pac.opaque) - sizeof(pac.opaque.hdr) - sizeof(pac.opaque.data) + dlen);
373 RHEXDUMP3((uint8_t const *)&pac.opaque, sizeof(pac.opaque) - sizeof(pac.opaque.data) + dlen, "PAC-Opaque");
374
375 eap_fast_tlv_append(tls_session, attr_eap_fast_pac_tlv, true, sizeof(pac) - sizeof(pac.opaque.data) + dlen, &pac);
376}
377
378static void eap_fast_append_crypto_binding(request_t *request, fr_tls_session_t *tls_session)
379{
380 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
381 eap_tlv_crypto_binding_tlv_t binding = {};
382 int const len = sizeof(binding) - (&binding.reserved - (uint8_t *)&binding);
383
384 RDEBUG2("Sending Cryptobinding");
385
387 binding.length = htons(len);
388 binding.version = EAP_FAST_VERSION;
389 binding.received_version = EAP_FAST_VERSION; /* FIXME use the clients value */
391
392 fr_assert(sizeof(binding.nonce) % sizeof(uint32_t) == 0);
393 RANDFILL(binding.nonce);
394 binding.nonce[sizeof(binding.nonce) - 1] &= ~0x01; /* RFC 4851 section 4.2.8 */
395 RHEXDUMP3(binding.nonce, sizeof(binding.nonce), "NONCE");
396
397 RHEXDUMP3((uint8_t const *) &binding, sizeof(binding), "Crypto-Binding TLV for Compound MAC calculation");
398
399 fr_hmac_sha1(binding.compound_mac, (uint8_t *)&binding, sizeof(binding), t->cmk, EAP_FAST_CMK_LEN);
400 RHEXDUMP3(binding.compound_mac, sizeof(binding.compound_mac), "Compound MAC");
401
402 eap_fast_tlv_append(tls_session, attr_eap_fast_crypto_binding, true, len, &binding.reserved);
403}
404
405#define EAP_FAST_TLV_MAX 13
406
407static int eap_fast_verify(request_t *request, fr_tls_session_t *tls_session, uint8_t const *data, unsigned int data_len)
408{
409 uint16_t attr;
410 uint16_t length;
411 unsigned int remaining = data_len;
412 int total = 0;
413 int num[EAP_FAST_TLV_MAX + 1] = {0};
414 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
415 uint32_t present = 0;
416 fr_dict_attr_t const *da = NULL, *tlv_da = fr_dict_root(dict_eap_fast);
417
418 fr_assert(sizeof(present) * 8 > EAP_FAST_TLV_MAX);
419
420 while (remaining > 0) {
421 if (remaining < 4) {
422 REDEBUG2("EAP-FAST TLV is too small (%u) to contain a EAP-FAST TLV header", remaining);
423 return 0;
424 }
425
426 memcpy(&attr, data, sizeof(attr));
427 attr = ntohs(attr) & EAP_FAST_TLV_TYPE;
428
429 da = fr_dict_attr_child_by_num(tlv_da, attr);
430
431 if (da && (attr < EAP_FAST_TLV_MAX)) {
432 num[attr]++;
433 present |= 1 << attr;
434
435 if (num[attr_eap_fast_eap_payload->attr] > 1) {
436 REDEBUG("Too many EAP-Payload TLVs");
437unexpected:
438 for (int i = 0; i < EAP_FAST_TLV_MAX; i++) {
439 if (present & (1 << i)) RDEBUG2(" - attribute %d is present", i);
440 }
442 return 0;
443 }
444
445 if (num[attr_eap_fast_intermediate_result->attr] > 1) {
446 REDEBUG("Too many Intermediate-Result TLVs");
447 goto unexpected;
448 }
449 } else {
450 if (!da && ((data[0] & 0x80) != 0)) {
451 REDEBUG("Unknown mandatory TLV %02x", attr);
452 goto unexpected;
453 }
454
455 num[0]++;
456 }
457
458 total++;
459
460 memcpy(&length, data + 2, sizeof(length));
461 length = ntohs(length);
462
463 data += 4;
464 remaining -= 4;
465
466 if (length > remaining) {
467 REDEBUG2("EAP-FAST TLV %s is longer than room remaining in the packet (%u > %u).",
468 da ? da->name : "<unknown>", length, remaining);
469 return 0;
470 }
471
472 /*
473 * If the rest of the TLVs are larger than
474 * this attribute, continue.
475 *
476 * Otherwise, if the attribute over-flows the end
477 * of the TLCs, die.
478 */
479 if (remaining < length) {
480 REDEBUG2("EAP-FAST TLV %s overflows packet!", da ? da->name : "<unknown>");
481 return 0;
482 }
483
484 /*
485 * If there's an error, we bail out of the
486 * authentication process before allocating
487 * memory.
488 */
490 uint16_t status;
491
492#ifdef __clang_analyzer__
493 /*
494 * Clang scan doesn't realise that the condition above means da is populated
495 */
496 if (!da) return 0;
497#endif
498
499 if (length < 2) {
500 REDEBUG("EAP-FAST TLV %s is too short. Expected 2, got %d", da->name, length);
501 return 0;
502 }
503
504 memcpy(&status, data, 2);
505 status = ntohs(status);
506
507 if (status == EAP_FAST_TLV_RESULT_FAILURE) {
508 REDEBUG("EAP-FAST TLV %s value %d indicates failure. Rejecting request", da->name, status);
509 return 0;
510 }
511
512 if (status != EAP_FAST_TLV_RESULT_SUCCESS) {
513 REDEBUG("EAP-FAST TLV %s contains unknown value %d. Rejecting request", da->name, status);
514 goto unexpected;
515 }
516 }
517
518 /*
519 * remaining > length, continue.
520 */
521 remaining -= length;
522 data += length;
523 }
524
525 /*
526 * Check if the peer mixed & matched TLVs.
527 */
528 if ((num[attr_eap_fast_nak->attr] > 0) && (num[attr_eap_fast_nak->attr] != total)) {
529 REDEBUG("NAK TLV sent with non-NAK TLVs. Rejecting request");
530 goto unexpected;
531 }
532
533 /*
534 * Check mandatory or not mandatory TLVs.
535 */
536 switch (t->stage) {
538 if (present) {
539 REDEBUG("Unexpected TLVs in TLS Session Handshake stage");
540 goto unexpected;
541 }
542 break;
544 if (present != (uint32_t)(1 << attr_eap_fast_eap_payload->attr)) {
545 REDEBUG("Unexpected TLVs in authentication stage");
546 goto unexpected;
547 }
548 break;
550 {
551 uint32_t bits = (t->result_final)
552 ? 1 << attr_eap_fast_result->attr
554 if (present & ~(bits | (1 << attr_eap_fast_crypto_binding->attr) | (1 << attr_eap_fast_pac_tlv->attr))) {
555 REDEBUG("Unexpected TLVs in cryptobind checking stage");
556 goto unexpected;
557 }
558 break;
559 }
561 if (present & ~((1 << attr_eap_fast_pac_tlv->attr) | (1 << attr_eap_fast_result->attr))) {
562 REDEBUG("Unexpected TLVs in provisioning stage");
563 goto unexpected;
564 }
565 break;
567 if (present) {
568 REDEBUG("Unexpected TLVs in complete stage");
569 goto unexpected;
570 }
571 break;
572 default:
573 REDEBUG("Unexpected stage %u", t->stage);
574 return 0;
575 }
576
577 /*
578 * We got this far. It looks OK.
579 */
580 return 1;
581}
582
583/**
584 *
585 * FIXME do something with mandatory
586 */
588 fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len)
589{
590 fr_dict_attr_t const *da;
591 uint8_t const *p = data, *end = p + data_len;
592
593 /*
594 * Decode the TLVs
595 */
596 while ((p + 4) <= end) {
597 ssize_t ret;
598 uint16_t attr;
600 fr_pair_t *vp;
601
603 p += 2;
605 p += 2;
606
607 /*
608 * eap_fast_verify() only checks the lengths of the top-level TLVs. We need to check the
609 * length of every TLV here, including the nested TLVs.
610 */
611 if ((size_t)(end - p) < len) {
612 REDEBUG2("FAST TLV %d is longer than room remaining (%u > %zu)", attr, len, (size_t)(end - p));
613 return -1;
614 }
615
617 if (!da) {
618 REDEBUG2("Unknown FAST TLV attribute %d", attr);
619 return -1;
620 }
621
622 MEM(vp = fr_pair_afrom_da(ctx, da));
623
624 if (da->type == FR_TYPE_TLV) {
625 ret = eap_fast_decode_pair(vp, request, &vp->vp_group, da, p, len);
626 if (ret < 0) return -1;
627
628 /*
629 * The recursive call stops when fewer than 4 bytes remain, so
630 * "ret" can be smaller than "len". Skip the whole value, or
631 * the unused bytes are read as the header of the next TLV.
632 */
633 p += len;
635 continue;
636 }
637
638 ret = fr_value_box_from_network(vp, &vp->data, vp->vp_type, vp->da,
639 &FR_DBUFF_TMP(p, (size_t)len), len, true);
640 if (ret != len) {
642 }
644 p += len;
645 }
646
647 return p - data;
648}
649
650
651/*
652 * Use a reply packet to determine what to do.
653 */
655{
656 eap_session_t *eap_session = talloc_get_type_abort(uctx, eap_session_t);
657 eap_tls_session_t *eap_tls_session = talloc_get_type_abort(eap_session->opaque, eap_tls_session_t);
658 fr_tls_session_t *tls_session = eap_tls_session->tls_session;
660 fr_dcursor_t cursor;
661 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
662 fr_packet_t *reply = request->reply;
663
664 /*
665 * If the response packet was Access-Accept, then
666 * we're OK. If not, die horribly.
667 *
668 * FIXME: EAP-Messages can only start with 'identity',
669 * NOT 'eap start', so we should check for that....
670 */
671 switch (reply->code) {
673 {
675 if (!ms_vp) break;
676
677 rcode = RLM_MODULE_OK;
679
680 /*
681 * Copy what we need into the FAST tunnel and leave
682 * the rest to be cleaned up.
683 */
684 fr_pair_list_foreach(&ms_vp->vp_group, vp){
685 /* FIXME must be a better way to capture/re-derive this later for ISK */
686 switch (vp->da->attr) {
688 if (vp->vp_length != MD5_DIGEST_LENGTH) {
689 wrong_length:
690 REDEBUG("Found %s with incorrect length. Expected %zu, got %zu",
691 vp->da->name, (size_t)MD5_DIGEST_LENGTH, vp->vp_length);
692 rcode = RLM_MODULE_INVALID;
693 break;
694 }
695
696 memcpy(t->isk.mppe_send, vp->vp_octets, MD5_DIGEST_LENGTH);
697 break;
698
700 if (vp->vp_length != MD5_DIGEST_LENGTH) goto wrong_length;
701 memcpy(t->isk.mppe_recv, vp->vp_octets, MD5_DIGEST_LENGTH);
702 break;
703
705 RDEBUG2("Got %s, tunneling it to the client in a challenge", vp->da->name);
706 rcode = RLM_MODULE_HANDLED;
707 t->authenticated = true;
708 break;
709
710 default:
711 break;
712 }
713 }
714 RHEXDUMP3((uint8_t *)&t->isk, 2 * MD5_DIGEST_LENGTH, "ISK[j]"); /* FIXME (part of above) */
715 }
716 break;
717
719 rcode = RLM_MODULE_REJECT;
720 break;
721
723 {
724 fr_pair_t *vp;
725
726 /*
727 * Copy the EAP-Message back to the tunnel.
728 */
729 for (vp = fr_pair_dcursor_by_da_init(&cursor, &request->reply_pairs, attr_eap_message);
730 vp;
731 vp = fr_dcursor_next(&cursor)) {
732 eap_fast_tlv_append(tls_session, attr_eap_fast_eap_payload, true, vp->vp_length, vp->vp_octets);
733 }
734
735 rcode = RLM_MODULE_HANDLED;
736 }
737 break;
738
739 default:
740 REDEBUG("Unknown RADIUS packet type %u: rejecting tunneled user", reply->code);
741 rcode = RLM_MODULE_INVALID;
742 break;
743 }
744
745 RETURN_UNLANG_RCODE(rcode);
746}
747
749 fr_tls_session_t *tls_session, fr_pair_t *tlv_eap_payload)
750{
751 fr_pair_t *vp;
753 request_t *child;
754
755 RDEBUG2("Processing received EAP Payload");
756
757 MEM(child = unlang_subrequest_alloc(request, request->proto_dict));
758 fr_assert(fr_pair_list_empty(&child->request_pairs));
759
760 t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
761
762 /*
763 * Add the tunneled EAP-Message to the child request.
764 */
765 MEM(vp = fr_pair_afrom_da(child->request_ctx, attr_eap_message));
766 fr_pair_append(&child->request_pairs, vp);
767 fr_pair_value_memdup(vp, tlv_eap_payload->vp_octets, tlv_eap_payload->vp_length, false);
768
769 RDEBUG2("Got tunneled request");
770 log_request_pair_list(L_DBG_LVL_2, child, NULL, &child->request_pairs, NULL);
771
772 /*
773 * If there's no User-Name in the stored data, look for
774 * an EAP-Identity, and pull it out of there.
775 */
776 if (!t->username) {
777 fr_assert(vp->da == attr_eap_message); /* cached from above */
778
779 if ((vp->vp_length >= EAP_HEADER_LEN + 2) &&
780 (vp->vp_strvalue[0] == FR_EAP_CODE_RESPONSE) &&
781 (vp->vp_strvalue[EAP_HEADER_LEN] == FR_EAP_METHOD_IDENTITY) &&
782 (vp->vp_strvalue[EAP_HEADER_LEN + 1] != 0)) {
783 /*
784 * Create and remember a User-Name
785 */
787 t->username->vp_tainted = true;
788 fr_pair_value_bstrndup(t->username, (char const *)vp->vp_octets + 5, vp->vp_length - 5, true);
789
790 RDEBUG2("Got tunneled identity of %pV", &t->username->data);
791 } else {
792 /*
793 * Don't reject the request outright,
794 * as it's permitted to do EAP without
795 * user-name.
796 */
797 RWDEBUG2("No EAP-Identity found to start EAP conversation");
798 }
799 } /* else there WAS a t->username */
800
801 if (t->username) {
802 MEM(vp = fr_pair_copy(child->request_ctx, t->username));
803 fr_pair_append(&child->request_pairs, vp);
804 }
805
806 if (t->stage == EAP_FAST_AUTHENTICATION) { /* FIXME do this only for MSCHAPv2 */
807 fr_pair_t *tvp;
808
809 MEM(tvp = fr_pair_afrom_da(child->control_ctx, attr_eap_type));
810 tvp->vp_uint32 = t->default_provisioning_method;
811 fr_pair_append(&child->control_pairs, tvp);
812
813 /*
814 * RFC 5422 section 3.2.3 - Authenticating Using EAP-FAST-MSCHAPv2
815 */
817 MEM(tvp = fr_pair_afrom_da(child->control_ctx, attr_ms_chap_challenge));
819 fr_pair_append(&child->control_pairs, tvp);
820 RHEXDUMP3(t->keyblock->server_challenge, MD5_DIGEST_LENGTH, "MSCHAPv2 auth_challenge");
821
822 MEM(tvp = fr_pair_afrom_da(child->control_ctx, attr_ms_chap_peer_challenge));
824 fr_pair_append(&child->control_pairs, tvp);
825 RHEXDUMP3(t->keyblock->client_challenge, MD5_DIGEST_LENGTH, "MSCHAPv2 peer_challenge");
826 }
827 }
828
829 if (unlang_subrequest_child_push(&eap_session->submodule_result, child, child,
830 false, UNLANG_SUB_FRAME) < 0) {
831 fail:
832 /*
833 * We can't just free the child, we need to detach it
834 * and then let the interpreter to unwind and eventually
835 * free the request.
836 */
837 request_detach(child);
839
841 }
842
844 UNLANG_SUB_FRAME, eap_session) != UNLANG_ACTION_PUSHED_CHILD) goto fail;
845
846 /*
847 * Call inner-tunnel virtual server, which will do PAP, CHAP, MS-CHAP, etc.
848 */
849 if (unlikely(eap_virtual_server(child, eap_session, t->virtual_server) == UNLANG_ACTION_FAIL)) goto fail;
850
852}
853
855 fr_tls_session_t *tls_session, eap_tlv_crypto_binding_tlv_t *binding)
856{
857 uint8_t cmac[sizeof(binding->compound_mac)];
858 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
859
860 memcpy(cmac, binding->compound_mac, sizeof(cmac));
861 memset(binding->compound_mac, 0, sizeof(binding->compound_mac));
862
863 RHEXDUMP3((uint8_t const *) binding, sizeof(*binding), "Crypto-Binding TLV for Compound MAC calculation");
864 RHEXDUMP3(cmac, sizeof(cmac), "Received Compound MAC");
865
866 fr_hmac_sha1(binding->compound_mac, (uint8_t *)binding, sizeof(*binding), t->cmk, EAP_FAST_CMK_LEN);
867 if (memcmp(binding->compound_mac, cmac, sizeof(cmac))) {
868 RDEBUG2("Crypto-Binding TLV mismatch");
869 RHEXDUMP3((uint8_t const *) binding->compound_mac,
870 sizeof(binding->compound_mac), "Calculated Compound MAC");
871 return -1;
872 }
873
874 return 0;
875}
876
878{
879 eap_session_t *eap_session = talloc_get_type_abort(uctx, eap_session_t);
880 eap_tls_session_t *eap_tls_session = talloc_get_type_abort(eap_session->opaque, eap_tls_session_t);
881 fr_tls_session_t *tls_session = eap_tls_session->tls_session;
882 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
883
885
887
888 switch (t->stage) {
891
893 {
894 if (t->mode != EAP_FAST_PROVISIONING_ANON && !t->pac.send)
895 t->result_final = true;
896
898
899 eap_fast_update_icmk(request, tls_session, (uint8_t *)&t->isk);
901
903 }
905 t->result_final = true;
906
908
909 if (t->pac.send) {
910 RDEBUG2("Peer requires new PAC");
911 eap_fast_send_pac_tunnel(request, tls_session);
913 }
914
917
919 /*
920 * RFC 5422 section 3.5 - Network Access after EAP-FAST Provisioning
921 */
922 if (t->pac.type && t->pac.expired) {
923 REDEBUG("Rejecting expired PAC.");
925 }
926
928 REDEBUG("Rejecting unauthenticated provisioning");
930 }
931
932 /*
933 * eap_crypto_mppe_keys() is unsuitable for EAP-FAST as Cisco decided
934 * it would be a great idea to flip the recv/send keys around
935 */
936 #define EAPTLS_MPPE_KEY_LEN 32
941
942 break;
943
944 default:
945 RERROR("Internal sanity check failed in EAP-FAST at %u", t->stage);
947 }
948
950}
951
953{
954 eap_session_t *eap_session = talloc_get_type_abort(uctx, eap_session_t);
955 eap_tls_session_t *eap_tls_session = talloc_get_type_abort(eap_session->opaque, eap_tls_session_t);
956 fr_tls_session_t *tls_session = eap_tls_session->tls_session;
957 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
958 eap_tlv_crypto_binding_tlv_t my_binding, *binding = NULL;
960
961 /*
962 * Cache if a Crypto-Binding TLV is required, as the loop changes t->stage when it sees a Result
963 * TLV.
964 */
965 bool need_cryptobind = (t->stage == EAP_FAST_CRYPTOBIND_CHECK);
966
969 return eap_fast_eap_payload(p_result, request, eap_session, tls_session, vp);
970 } else if ((vp->da == attr_eap_fast_result) ||
972 rcode = RLM_MODULE_OK;
974 } else if (vp->da == attr_eap_fast_crypto_binding) {
975 if (vp->vp_length == (sizeof(*binding) - 2 * sizeof(uint16_t))) {
977 my_binding.length = htons(sizeof(*binding) - 2 * sizeof(uint16_t));
978 memcpy(&my_binding.reserved, vp->vp_octets, sizeof(my_binding) - 4);
979 binding = &my_binding;
980 }
981 continue;
982 } else if (vp->da == attr_eap_fast_pac_tlv) {
983 fr_pair_list_foreach(&vp->vp_group, pac_vp) {
984 if (pac_vp->da == attr_eap_fast_pac_acknowledge) {
985 if (pac_vp->vp_uint32 == EAP_FAST_TLV_RESULT_SUCCESS) {
986 t->pac.expires = fr_time_max();
987 t->pac.expired = false;
989 }
990 break;
991 } else if (pac_vp->da == attr_eap_fast_pac_info_pac_type) {
992 if (pac_vp->vp_uint32 != PAC_TYPE_TUNNEL) {
993 RDEBUG2("only able to serve Tunnel PAC's, ignoring request");
994 continue;
995 }
996 t->pac.send = true;
997 continue;
998 } else {
999 RDEBUG2("ignoring unknown EAP-FAST-PAC-TLV %pP", vp);
1000 continue;
1001 }
1002 }
1003 break;
1004 } else {
1005 RDEBUG3("Ignoring %pP", vp);
1006 continue;
1007 }
1008
1010 }
1011
1012 if (need_cryptobind && !binding) {
1013 REDEBUG("Missing or malformed Crypto-Binding TLV");
1015 }
1016
1017 if (binding) {
1018 if (eap_fast_crypto_binding(request, eap_session, tls_session, binding) < 0) RETURN_UNLANG_REJECT;
1020 }
1021
1022 return eap_fast_process_tlvs_result(p_result, request, uctx);
1023}
1024
1025/*
1026 * Send the tunneled challenge, once any session ticket has been written.
1027 */
1029{
1030 eap_session_t *eap_session = talloc_get_type_abort(uctx, eap_session_t);
1031 eap_tls_session_t *eap_tls_session = talloc_get_type_abort(eap_session->opaque, eap_tls_session_t);
1032
1033 fr_tls_session_send(request, eap_tls_session->tls_session);
1034 eap_tls_request(request, eap_session);
1036}
1037
1039{
1040 eap_session_t *eap_session = talloc_get_type_abort(mctx->rctx, eap_session_t);
1041 eap_tls_session_t *eap_tls_session = talloc_get_type_abort(eap_session->opaque, eap_tls_session_t);
1042 fr_tls_session_t *tls_session = eap_tls_session->tls_session;
1043
1044 RDEBUG3("Tunneled request complete");
1045
1046 switch (eap_session->submodule_result.rcode) {
1047 case RLM_MODULE_REJECT:
1048 p_result->rcode = RLM_MODULE_REJECT;
1049 return eap_tls_fail(request, eap_session);
1050
1051 /*
1052 * Access-Challenge, continue tunneled conversation.
1053 */
1054 case RLM_MODULE_HANDLED:
1055 {
1056 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
1057
1058 /*
1059 * The last message from the server carries any stateless session ticket. EAP-FAST ends
1060 * with a message from the server, so the ticket and the message leave in the same EAP
1061 * request.
1062 */
1063 if (t->result_final) {
1064 return fr_tls_ticket_stateless_issue(p_result, request, tls_session,
1065 mod_challenge_send, eap_session);
1066 }
1067 }
1068 return mod_challenge_send(p_result, request, eap_session);
1069
1070 /*
1071 * Success.
1072 */
1073 case RLM_MODULE_OK:
1074 p_result->rcode = RLM_MODULE_OK;
1075 return eap_tls_success(request, eap_session, NULL);
1076
1077 default:
1078 break;
1079 }
1080
1081 /*
1082 * Something we don't understand: Reject it.
1083 */
1084 p_result->rcode = RLM_MODULE_FAIL;
1085 return eap_tls_fail(request, eap_session);
1086}
1087
1088/*
1089 * Process the inner tunnel data
1090 */
1092 eap_session_t *eap_session, fr_tls_session_t *tls_session)
1093{
1094 uint8_t const *data;
1095 size_t data_len;
1097
1098 /*
1099 * Read the buffer directly, rather than copying the
1100 * octets out of it.
1101 */
1102 data_len = fr_dbuff_used(&tls_session->clean_out);
1103 data = fr_dbuff_start(&tls_session->clean_out);
1104 fr_tls_record_init(&tls_session->clean_out);
1105
1106 t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
1107
1109
1110 /*
1111 * See if the tunneled data is well formed.
1112 */
1113 if (!eap_fast_verify(request, tls_session, data, data_len)) RETURN_UNLANG_REJECT;
1114
1116 char buf[256];
1117
1119
1120 if (strstr(SSL_CIPHER_description(SSL_get_current_cipher(tls_session->ssl),
1121 buf, sizeof(buf)), "Au=None")) {
1122 /* FIXME enforce MSCHAPv2 - RFC 5422 section 3.2.2 */
1123 RDEBUG2("Using anonymous provisioning");
1125 t->pac.send = true;
1126 } else {
1127 fr_time_t renew;
1128
1129 if (SSL_session_reused(tls_session->ssl)) {
1130 RDEBUG2("Session Resumed from PAC");
1132 } else {
1133 RDEBUG2("Using authenticated provisioning");
1135 }
1136
1137 /*
1138 * Send a new pac at 60% of the lifetime,
1139 * or if the PAC has expired, or if no lifetime was set.
1140 */
1141 renew = fr_time_add(request->packet->timestamp,
1143
1144 if (t->pac.expired || fr_time_eq(t->pac.expires, fr_time_wrap(0)) ||
1145 fr_time_lteq(t->pac.expires, renew)) {
1146 t->pac.send = true;
1147 }
1148 }
1149
1150 eap_fast_init_keys(request, tls_session);
1151
1152 eap_fast_send_identity_request(request, tls_session, eap_session);
1153
1156 }
1157
1159 data, data_len) < 0) RETURN_UNLANG_REJECT;
1160
1161 RDEBUG2("Got Tunneled FAST TLVs");
1163
1165 NULL, FR_SIGNAL_NONE, UNLANG_SUB_FRAME, eap_session);
1166}
1167
1168/** Allocate the FAST per-session data
1169 *
1170 */
1171static eap_fast_tunnel_t *eap_fast_alloc(TALLOC_CTX *ctx, rlm_eap_fast_t const *inst)
1172{
1173 eap_fast_tunnel_t *t = talloc_zero(ctx, eap_fast_tunnel_t);
1174
1177
1178 t->default_provisioning_method = inst->default_provisioning_method;
1179
1180 t->pac_lifetime = inst->pac_lifetime;
1181 t->authority_identity = inst->authority_identity;
1182 t->a_id = inst->a_id;
1183 t->pac_opaque_key = (uint8_t const *)inst->pac_opaque_key;
1184 t->virtual_server = inst->virtual_server;
1185
1186 return t;
1187}
1188
1189static void eap_fast_session_ticket(fr_tls_session_t *tls_session, const SSL *s,
1190 uint8_t *secret, int *secret_len)
1191{
1192 eap_fast_tunnel_t *t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
1193 uint8_t seed[2 * SSL3_RANDOM_SIZE];
1194
1195 fr_assert(t->pac.key);
1196
1197 SSL_get_server_random(s, seed, SSL3_RANDOM_SIZE);
1198 SSL_get_client_random(s, &seed[SSL3_RANDOM_SIZE], SSL3_RANDOM_SIZE);
1199
1200 T_PRF(t->pac.key, PAC_KEY_LENGTH, "PAC to master secret label hash",
1201 seed, sizeof(seed), secret, SSL_MAX_MASTER_KEY_LENGTH);
1202 *secret_len = SSL_MAX_MASTER_KEY_LENGTH;
1203}
1204
1205static int _session_secret(SSL *s, void *secret, int *secret_len,
1206 UNUSED STACK_OF(SSL_CIPHER) *peer_ciphers,
1207 UNUSED SSL_CIPHER const **cipher, void *arg)
1208{
1209 // FIXME enforce non-anon cipher
1210
1211 request_t *request = fr_tls_session_request(s);
1212 fr_tls_session_t *tls_session = arg;
1214
1215 if (!tls_session) return 0;
1216
1217 t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
1218
1219 if (!t->pac.key) return 0;
1220
1221 RDEBUG2("processing PAC-Opaque");
1222
1223 eap_fast_session_ticket(tls_session, s, secret, secret_len);
1224
1225 memset(t->pac.key, 0, PAC_KEY_LENGTH);
1226 talloc_free(t->pac.key);
1227 t->pac.key = NULL;
1228
1229 return 1;
1230}
1231
1232/*
1233 * hints from hostap:src/crypto/tls_openssl.c:fr_tls_session_ticket_ext_cb()
1234 *
1235 * N.B. we actually always tell OpenSSL we have digested the ticket so that
1236 * it does not cause a fail loop and enables us to update the PAC easily
1237 *
1238 */
1239static int _session_ticket(SSL *s, uint8_t const *data, int len, void *arg)
1240{
1241 fr_tls_session_t *tls_session = talloc_get_type_abort(arg, fr_tls_session_t);
1242 request_t *request = fr_tls_session_request(s);
1244 fr_pair_list_t fast_vps;
1245 fr_pair_t *vp;
1246 char const *errmsg;
1247 int dlen, plen;
1248 uint16_t length;
1250 eap_fast_attr_pac_opaque_t opaque_plaintext;
1251
1252 if (!tls_session) return 0;
1253
1254 fr_pair_list_init(&fast_vps);
1255 t = talloc_get_type_abort(tls_session->opaque, eap_fast_tunnel_t);
1256
1257 RDEBUG2("PAC provided via ClientHello SessionTicket extension");
1258 RHEXDUMP3(data, len, "PAC-Opaque");
1259
1260 /*
1261 * Check that the ticket is large enough to contain a
1262 * header, before we read the header.
1263 */
1264 if (len < (int) sizeof(opaque->hdr)) {
1265 errmsg = "PAC is too small to contain a header";
1266 goto error;
1267 }
1268
1269 if ((ntohs(opaque->hdr.type) & EAP_FAST_TLV_TYPE) != attr_eap_fast_pac_opaque_tlv->attr) {
1270 errmsg = "PAC is not of type Opaque";
1271error:
1272 RERROR("%s, sending alert to client", errmsg);
1273 if (fr_tls_session_alert(request, tls_session, SSL3_AL_FATAL, SSL_AD_BAD_CERTIFICATE)) {
1274 RERROR("too many alerts");
1275 return 0;
1276 }
1277 if (t->pac.key) talloc_free(t->pac.key);
1278
1279 memset(&t->pac, 0, sizeof(t->pac));
1280 if (!fr_pair_list_empty(&fast_vps)) fr_pair_list_free(&fast_vps);
1281 return 1;
1282 }
1283
1284 /*
1285 * we would like to use the length of the SessionTicket
1286 * but Cisco hates everyone and sends a zero padding payload
1287 * so we have to use the length in the PAC-Opaque header
1288 */
1289 length = ntohs(opaque->hdr.length);
1290 if (length > ((size_t) len - sizeof(opaque->hdr))) {
1291 errmsg = "PAC has bad length in header";
1292 goto error;
1293 }
1294
1295 if (length < PAC_A_ID_LENGTH + EVP_MAX_IV_LENGTH + EVP_GCM_TLS_TAG_LEN + 1) {
1296 errmsg = "PAC file too short";
1297 goto error;
1298 }
1299
1300 /*
1301 * eap_fast_decrypt() writes the decrypted data to
1302 * opaque_plaintext, which is a fixed-size structure on
1303 * the stack. Bound the length by that structure, and
1304 * not by the size of the ticket that the peer sent.
1305 */
1306 if ((size_t) length > sizeof(*opaque) - sizeof(opaque->hdr)) {
1307 errmsg = "PAC is too long";
1308 goto error;
1309 }
1310
1311 if (memcmp(opaque->aad, t->a_id, PAC_A_ID_LENGTH)) {
1312 errmsg = "PAC has incorrect A_ID";
1313 goto error;
1314 }
1315
1316 dlen = length - sizeof(opaque->aad) - sizeof(opaque->iv) - sizeof(opaque->tag);
1317 plen = eap_fast_decrypt(opaque->data, dlen, opaque->aad, PAC_A_ID_LENGTH,
1318 (uint8_t const *) opaque->tag, t->pac_opaque_key, opaque->iv,
1319 (uint8_t *)&opaque_plaintext);
1320 if (plen == -1) {
1321 errmsg = "PAC failed to decrypt";
1322 goto error;
1323 }
1324
1325 RHEXDUMP3((uint8_t const *)&opaque_plaintext, plen, "PAC-Opaque plaintext data section");
1326
1327 if (eap_fast_decode_pair(tls_session, request, &fast_vps, attr_eap_fast_pac_opaque_tlv,
1328 (uint8_t *)&opaque_plaintext, plen) < 0) {
1329 errmsg = fr_strerror();
1330 goto error;
1331 }
1332
1333 RDEBUG2("Got FAST TLVs from session ticket");
1334 log_request_pair_list(L_DBG_LVL_2, request, NULL, &fast_vps, NULL);
1335
1336 for (vp = fr_pair_list_head(&fast_vps);
1337 vp;
1338 vp = fr_pair_list_next(&fast_vps, vp)) {
1340 fr_assert(t->pac.type == 0);
1341 t->pac.type = vp->vp_uint16;
1343 fr_assert(fr_time_eq(t->pac.expires, fr_time_wrap(0)));
1344 t->pac.expires = fr_time_add(request->packet->timestamp, vp->vp_time_delta);
1345 t->pac.expired = false;
1346 } else if (vp->da == attr_eap_fast_pac_opaque_pac_key) {
1347 fr_assert(t->pac.key == NULL);
1348 fr_assert(vp->vp_length == PAC_KEY_LENGTH);
1349 t->pac.key = talloc_array(t, uint8_t, PAC_KEY_LENGTH);
1350 fr_assert(t->pac.key != NULL);
1351 memcpy(t->pac.key, vp->vp_octets, PAC_KEY_LENGTH);
1352 } else {
1353 RERROR("unknown TLV: %pP", vp);
1354 errmsg = "unknown TLV";
1355 goto error;
1356 }
1357 }
1358
1359 fr_pair_list_free(&fast_vps);
1360
1361 if (!t->pac.type) {
1362 errmsg = "PAC missing type TLV";
1363 goto error;
1364 }
1365
1366 if (t->pac.type != PAC_TYPE_TUNNEL) {
1367 errmsg = "PAC is of not of tunnel type";
1368 goto error;
1369 }
1370
1371 if (fr_time_eq(t->pac.expires, fr_time_wrap(0))) {
1372 errmsg = "PAC missing lifetime TLV";
1373 goto error;
1374 }
1375
1376 if (!t->pac.key) {
1377 errmsg = "PAC missing key TLV";
1378 goto error;
1379 }
1380
1381 if (!SSL_set_session_secret_cb(tls_session->ssl, _session_secret, tls_session)) {
1382 RERROR("Failed setting SSL session secret callback");
1383 return 0;
1384 }
1385
1386 return 1;
1387}
1388
1390{
1391 eap_session_t *eap_session = talloc_get_type_abort(mctx->rctx, eap_session_t);
1392 eap_tls_session_t *eap_tls_session = talloc_get_type_abort(eap_session->opaque, eap_tls_session_t);
1393 fr_tls_session_t *tls_session = eap_tls_session->tls_session;
1394
1395 if ((eap_tls_session->state == EAP_TLS_INVALID) || (eap_tls_session->state == EAP_TLS_FAIL)) {
1396 REDEBUG("[eap-tls process] = %s", fr_table_str_by_value(eap_tls_status_table, eap_tls_session->state, "<INVALID>"));
1397 } else {
1398 RDEBUG2("[eap-tls process] = %s", fr_table_str_by_value(eap_tls_status_table, eap_tls_session->state, "<INVALID>"));
1399 }
1400
1401 switch (eap_tls_session->state) {
1402 /*
1403 * EAP-TLS handshake was successful, tell the
1404 * client to keep talking.
1405 *
1406 * If this was EAP-TLS, we would just return
1407 * an EAP-TLS-Success packet here.
1408 */
1410 fr_tls_session_send(request, tls_session);
1411 fr_assert(tls_session->opaque != NULL);
1412 break;
1413
1414 /*
1415 * The TLS code is still working on the TLS
1416 * exchange, and it's a valid TLS request.
1417 * do nothing.
1418 */
1419 case EAP_TLS_HANDLED:
1421
1422 /*
1423 * Handshake is done, proceed with decoding tunneled
1424 * data.
1425 */
1427 break;
1428
1429 /*
1430 * Anything else: fail.
1431 */
1432 default:
1433 p_result->rcode = RLM_MODULE_FAIL;
1434 return eap_tls_fail(request, eap_session);
1435 }
1436
1437 /*
1438 * Session is established, proceed with decoding
1439 * tunneled data.
1440 */
1441 RDEBUG2("Session established. Proceeding to decode tunneled attributes");
1442
1443 (void) unlang_module_yield(request, process_rcode, NULL, FR_SIGNAL_NONE, eap_session);
1444
1445 return eap_fast_process(&eap_session->submodule_result, request, eap_session, tls_session);
1446}
1447
1448/*
1449 * Do authentication, by letting EAP-TLS do most of the work.
1450 */
1453{
1454 eap_session_t *eap_session = eap_session_get(request->parent);
1455
1456 /*
1457 * Setup the resumption frame to process the result
1458 */
1460
1461 /*
1462 * Process TLS layer until done.
1463 */
1464 return eap_tls_process(request, eap_session);
1465}
1466
1467/*
1468 * Send an initial eap-tls request to the peer, using the libeap functions.
1469 */
1471{
1473 rlm_eap_fast_thread_t *thread = talloc_get_type_abort(mctx->thread, rlm_eap_fast_thread_t);
1474 eap_session_t *eap_session = eap_session_get(request->parent);
1475 eap_tls_session_t *eap_tls_session;
1476 fr_tls_session_t *tls_session;
1477
1478 fr_pair_t *vp;
1479 bool client_cert;
1480
1481 eap_session->tls = true;
1482
1483 /*
1484 * EAP-TLS-Require-Client-Cert attribute will override
1485 * the require_client_cert configuration option.
1486 */
1488 if (vp) {
1489 client_cert = vp->vp_uint32 ? true : false;
1490 } else {
1491 client_cert = inst->req_client_cert;
1492 }
1493
1494 eap_session->opaque = eap_tls_session = eap_tls_session_init(request, eap_session, thread->ssl_ctx, client_cert);
1495 if (!eap_tls_session) RETURN_UNLANG_FAIL;
1496
1497 tls_session = eap_tls_session->tls_session;
1498
1499 if (inst->cipher_list) {
1500 RDEBUG2("Over-riding main cipher list with '%s'", inst->cipher_list);
1501
1502 if (!SSL_set_cipher_list(tls_session->ssl, inst->cipher_list)) {
1503 REDEBUG("Failed over-riding cipher list to '%s'. EAP-FAST will likely not work",
1504 inst->cipher_list);
1505 }
1506 }
1507
1508 /*
1509 * Push TLV of authority_identity into tls_record
1510 * call eap_tls_compose() with args
1511 *
1512 * RFC 4851 section 4.1.1
1513 * N.B. mandatory/reserved flags are not applicable here
1514 */
1516
1517 /*
1518 * TLS session initialization is over. Now handle TLS
1519 * related handshaking or application data.
1520 */
1521 /*
1522 * eap_tls_compose() reads from clean_in, so clean_in stops
1523 * filling and starts draining for the duration of the call.
1524 */
1525 fr_tls_record_drain(&tls_session->clean_in);
1526
1527 if (eap_tls_compose(request, eap_session, EAP_TLS_START_SEND,
1528 SET_START(eap_tls_session->base_flags) | EAP_FAST_VERSION,
1529 &tls_session->clean_in, fr_dbuff_remaining(&tls_session->clean_in),
1530 fr_dbuff_remaining(&tls_session->clean_in)) < 0) {
1531 talloc_free(tls_session);
1533 }
1534
1535 fr_tls_record_init(&tls_session->clean_in); /* done draining, fill it again */
1536
1537 tls_session->opaque = eap_fast_alloc(tls_session, inst);
1538 eap_session->process = mod_handshake_process;
1539
1540 if (!SSL_set_session_ticket_ext_cb(tls_session->ssl, _session_ticket, tls_session)) {
1541 RERROR("Failed setting SSL session ticket callback");
1543 }
1544
1546}
1547
1549{
1550 rlm_eap_fast_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_eap_fast_t);
1551 rlm_eap_fast_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_fast_thread_t);
1552
1553 t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false);
1554 if (!t->ssl_ctx) return -1;
1555
1556 return 0;
1557}
1558
1560{
1561 rlm_eap_fast_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_fast_thread_t);
1562
1563 if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx);
1564 t->ssl_ctx = NULL;
1565
1566 return 0;
1567}
1568
1569/*
1570 * Attach the module.
1571 */
1572static int mod_instantiate(module_inst_ctx_t const *mctx)
1573{
1574 rlm_eap_fast_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_eap_fast_t);
1575 CONF_SECTION *conf = mctx->mi->conf;
1576
1577 inst->default_provisioning_method = eap_name2type(inst->default_provisioning_method_name);
1578 if (!inst->default_provisioning_method) {
1579 cf_log_err_by_child(conf, "default_provisioning_eap_type", "Unknown EAP type %s",
1580 inst->default_provisioning_method_name);
1581 return -1;
1582 }
1583
1584 eap_tls_conf_check(conf, inst->tls_conf, true);
1585
1586 /*
1587 * Limit TLS version to 1.2. More work is needed to support TLS 1.3
1588 */
1589 if ((inst->tls_conf->tls_max_version <= (float) 0.0) || (inst->tls_conf->tls_max_version > (float) 1.2)) {
1590 cf_log_warn(conf, "Max TLS version supported for EAP-FAST is 1.2");
1591 inst->tls_conf->tls_max_version = (float) 1.2;
1592 }
1593
1594 if (talloc_strlen(inst->pac_opaque_key) != 32) {
1595 cf_log_err_by_child(conf, "pac_opaque_key", "Must be 32 bytes long");
1596 return -1;
1597 }
1598
1599 if (!fr_time_delta_ispos(inst->pac_lifetime)) {
1600 cf_log_err_by_child(conf, "pac_lifetime", "must be non-zero");
1601 return -1;
1602 }
1603
1605
1606 fr_md5_calc(inst->a_id, (uint8_t const *)inst->authority_identity,
1607 talloc_strlen(inst->authority_identity));
1608
1609 return 0;
1610}
1611
1612/*
1613 * The module name should be the only globally exported symbol.
1614 * That is, everything else should be 'static'.
1615 */
1618 .common = {
1619 .magic = MODULE_MAGIC_INIT,
1620 .name = "eap_fast",
1621
1622 .inst_size = sizeof(rlm_eap_fast_t),
1624 .instantiate = mod_instantiate, /* Create new submodule instance */
1625
1626 .thread_inst_size = sizeof(rlm_eap_fast_thread_t),
1627 .thread_instantiate = mod_thread_instantiate,
1628 .thread_detach = mod_thread_detach,
1629 },
1630 .provides = { FR_EAP_METHOD_FAST },
1631 .session_init = mod_session_init, /* Initialise a new EAP session */
1632 .tunnel = true
1633};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
Definition action.h:40
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
Definition action.h:36
static uint8_t request[4]
static uint8_t reply[4]
#define USES_APPLE_DEPRECATED_API
Definition build.h:596
#define RCSID(id)
Definition build.h:609
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:422
#define unlikely(_x)
Definition build.h:492
#define UNUSED
Definition build.h:415
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:722
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:666
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:280
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:466
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
Definition cf_parse.h:484
#define FR_CONF_SUBSECTION_ALLOC(_name, _flags, _struct, _field, _subcs)
conf_parser_t which allocates a struct and populates it from a subsection
Definition cf_parse.h:384
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:268
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:238
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:649
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
#define cf_log_err_by_child(_parent, _child, _fmt,...)
Log an error message against a specified child.
Definition cf_util.h:367
#define cf_log_warn(_cf, _fmt,...)
Definition cf_util.h:341
eap_packet_t * response
Packet we received from the peer.
Definition compose.h:48
uint8_t id
Definition compose.h:36
#define fr_dbuff_used(_dbuff_or_marker)
Return the number of bytes remaining between the start of the dbuff or marker and the current positio...
Definition dbuff.h:819
#define fr_dbuff_start(_dbuff_or_marker)
Return the 'start' position of a dbuff or marker.
Definition dbuff.h:950
#define fr_dbuff_remaining(_dbuff_or_marker)
Return the number of bytes remaining between the dbuff or marker and the end of the buffer.
Definition dbuff.h:795
#define fr_dbuff_in_memcpy_partial(_out, _in, _inlen)
Copy at most _inlen bytes into the dbuff.
Definition dbuff.h:1491
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
Definition dbuff.h:556
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:288
#define MEM(x)
Definition debug.h:38
#define FR_MSCHAP_MPPE_RECV_KEY
Definition defs.h:162
fr_radius_packet_code_t
RADIUS packet codes.
Definition defs.h:31
@ FR_RADIUS_CODE_ACCESS_CHALLENGE
RFC2865 - Access-Challenge.
Definition defs.h:43
@ FR_RADIUS_CODE_ACCESS_ACCEPT
RFC2865 - Access-Accept.
Definition defs.h:34
@ FR_RADIUS_CODE_ACCESS_REJECT
RFC2865 - Access-Reject.
Definition defs.h:35
#define FR_MSCHAP_MPPE_SEND_KEY
Definition defs.h:161
#define FR_MSCHAP2_SUCCESS
Definition defs.h:164
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2725
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:316
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:329
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:335
fr_dict_attr_t const * fr_dict_attr_child_by_num(fr_dict_attr_t const *parent, unsigned int attr)
Check if a child attribute exists in a parent using an attribute number.
Definition dict_util.c:3675
Specifies an attribute which must be present for the module to function.
Definition dict.h:315
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:328
Test enumeration values.
Definition dict_test.h:92
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
eap_type_t eap_name2type(char const *name)
Return an EAP-Type for a particular name.
Definition types.c:38
@ FR_EAP_METHOD_IDENTITY
Definition types.h:46
@ FR_EAP_METHOD_FAST
Definition types.h:89
uint8_t id
Definition types.h:133
uint8_t code
Definition types.h:132
uint8_t length[2]
Definition types.h:134
#define EAP_HEADER_LEN
Definition types.h:34
@ FR_EAP_CODE_RESPONSE
Definition types.h:38
@ FR_EAP_CODE_REQUEST
Definition types.h:37
uint8_t data[1]
Definition types.h:135
When we need to create a base EAP packet.
Definition types.h:131
Function declarations and packet structures.
#define EAP_FAST_TLV_MANDATORY
Definition eap_fast.h:42
uint8_t const * a_id
Definition eap_fast.h:191
#define EAP_FAST_SKS_LEN
Definition eap_fast.h:38
@ PAC_TYPE_TUNNEL
Definition eap_fast.h:68
unsigned char aad[PAC_A_ID_LENGTH]
Definition eap_fast.h:122
eap_fast_pac_attr_lifetime_t lifetime
Definition eap_fast.h:116
eap_fast_pac_attr_hdr_t hdr
Definition eap_fast.h:100
uint8_t client_challenge[MD5_DIGEST_LENGTH]
Definition eap_fast.h:163
eap_fast_pac_attr_lifetime_t lifetime
Definition eap_fast.h:130
eap_fast_stage_t stage
Definition eap_fast.h:174
#define EAP_FAST_KEY_LEN
Definition eap_fast.h:36
#define PAC_A_ID_LENGTH
Definition eap_fast.h:75
eap_fast_pac_attr_pac_key_t key
Definition eap_fast.h:137
#define EAP_FAST_VERSION
Definition eap_fast.h:34
eap_fast_keyblock_t * keyblock
Definition eap_fast.h:175
eap_fast_pac_attr_hdr_t hdr
Definition eap_fast.h:85
fr_time_delta_t pac_lifetime
Definition eap_fast.h:189
uint8_t * s_imck
Definition eap_fast.h:176
@ EAP_FAST_COMPLETE
Definition eap_fast.h:57
@ EAP_FAST_AUTHENTICATION
Definition eap_fast.h:54
@ EAP_FAST_CRYPTOBIND_CHECK
Definition eap_fast.h:55
@ EAP_FAST_PROVISIONING
Definition eap_fast.h:56
@ EAP_FAST_TLS_SESSION_HANDSHAKE
Definition eap_fast.h:53
#define EAP_FAST_SIMCK_LEN
Definition eap_fast.h:39
eap_fast_pac_attr_a_id_info_t a_id_info
Definition eap_fast.h:132
#define EAP_FAST_TLV_TYPE
Definition eap_fast.h:43
uint8_t data[PAC_A_ID_INFO_LENGTH]
Definition eap_fast.h:101
fr_pair_list_t fast_vps
Pairs extracted from FAST data.
Definition eap_fast.h:169
int default_provisioning_method
Definition eap_fast.h:187
eap_fast_pac_attr_hdr_t hdr
Definition eap_fast.h:129
unsigned char iv[EVP_MAX_IV_LENGTH]
Definition eap_fast.h:123
uint8_t data[PAC_KEY_LENGTH]
Definition eap_fast.h:111
fr_pair_t * username
Definition eap_fast.h:167
eap_fast_pac_attr_hdr_t hdr
Definition eap_fast.h:121
unsigned char tag[EVP_GCM_TLS_TAG_LEN]
Definition eap_fast.h:124
@ EAP_FAST_TLV_CRYPTO_BINDING_SUBTYPE_REQUEST
Definition eap_fast.h:155
uint8_t * emsk
Definition eap_fast.h:184
eap_fast_pac_attr_hdr_t hdr
Definition eap_fast.h:110
eap_fast_attr_pac_opaque_t opaque
Definition eap_fast.h:139
#define EAP_FAST_TLV_RESULT_SUCCESS
Definition eap_fast.h:49
eap_fast_pac_attr_pac_type_t type
Definition eap_fast.h:115
#define EAP_FAST_ERR_UNEXPECTED_TLV
Definition eap_fast.h:47
virtual_server_t * virtual_server
To run inner tunnel authentication through.
Definition eap_fast.h:204
struct eap_fast_tunnel_t::@198 isk
eap_fast_pac_attr_hdr_t hdr
Definition eap_fast.h:90
uint8_t data[PAC_A_ID_LENGTH]
Definition eap_fast.h:91
char const * authority_identity
Definition eap_fast.h:190
eap_fast_attr_pac_info_t info
Definition eap_fast.h:138
eap_fast_pac_attr_a_id_t a_id
Definition eap_fast.h:131
eap_fast_pac_attr_hdr_t hdr
Definition eap_fast.h:105
uint8_t * cmk
Definition eap_fast.h:177
uint8_t server_challenge[MD5_DIGEST_LENGTH]
Definition eap_fast.h:162
uint8_t data[sizeof(eap_fast_attr_pac_opaque_plaintext_t) *2]
Definition eap_fast.h:125
eap_fast_pac_attr_pac_type_t type
Definition eap_fast.h:133
#define PAC_KEY_LENGTH
Definition eap_fast.h:74
@ EAP_FAST_UNKNOWN
Definition eap_fast.h:61
@ EAP_FAST_NORMAL_AUTH
Definition eap_fast.h:64
@ EAP_FAST_PROVISIONING_ANON
Definition eap_fast.h:62
@ EAP_FAST_PROVISIONING_AUTH
Definition eap_fast.h:63
eap_fast_pac_attr_pac_key_t key
Definition eap_fast.h:117
#define EAP_EMSK_LEN
Definition eap_fast.h:37
#define EAP_FAST_TLV_RESULT_FAILURE
Definition eap_fast.h:50
uint8_t const * pac_opaque_key
Definition eap_fast.h:192
struct eap_fast_tunnel_t::@199 pac
#define EAP_FAST_CMK_LEN
Definition eap_fast.h:40
uint8_t * msk
Definition eap_fast.h:183
int eap_fast_decrypt(uint8_t const *ciphertext, size_t ciphertext_len, uint8_t const *aad, size_t aad_len, uint8_t const *tag, uint8_t const *key, uint8_t const *iv, uint8_t *plaintext)
int eap_fast_encrypt(uint8_t const *plaintext, size_t plaintext_len, uint8_t const *aad, size_t aad_len, uint8_t const *key, uint8_t *iv, unsigned char *ciphertext, uint8_t *tag)
void eap_fast_tls_gen_challenge(SSL *s, int version, uint8_t *buffer, uint8_t *scratch, size_t size, char const *prf_label)
USES_APPLE_DEPRECATED_API void T_PRF(unsigned char const *secret, unsigned int secret_len, char const *prf_label, unsigned char const *seed, unsigned int seed_len, unsigned char *out, unsigned int out_len)
Crypto function declarations.
#define unlang_function_push_with_result(_result_p, _request, _func, _repeat, _signal, _sigmask, _top_frame, _uctx)
Push a generic function onto the unlang stack that produces a result.
Definition function.h:146
talloc_free(hp)
int fr_hmac_sha1(uint8_t digest[static SHA1_DIGEST_LENGTH], uint8_t const *in, size_t inlen, uint8_t const *key, size_t key_len)
Calculate HMAC using internal SHA1 implementation.
Definition hmac_sha1.c:123
void unlang_interpret_signal(request_t *request, fr_signal_t action)
Send a signal (usually stop) to a request.
Definition interpret.c:1794
#define UNLANG_SUB_FRAME
Definition interpret.h:37
rlm_rcode_t rcode
The current rcode, from executing the instruction or merging the result from a frame.
Definition interpret.h:140
unlang_action_t eap_virtual_server(request_t *request, eap_session_t *eap_session, virtual_server_t *virtual_server)
Run a subrequest through a virtual server.
Definition base.c:385
void eap_add_reply(request_t *request, fr_dict_attr_t const *da, uint8_t const *value, int len)
Definition base.c:345
static eap_session_t * eap_session_get(request_t *request)
Definition session.h:90
void * opaque
Opaque data used by EAP methods.
Definition session.h:63
bool tls
Whether EAP method uses TLS.
Definition session.h:71
module_method_t process
Callback that should be used to process the next round.
Definition session.h:65
unlang_result_t submodule_result
Result of last submodule call.
Definition session.h:47
eap_round_t * this_round
The EAP response we're processing, and the EAP request we're building.
Definition session.h:60
Tracks the progress of a single session of any EAP method.
Definition session.h:41
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
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
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
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_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
unlang_action_t eap_tls_fail(request_t *request, eap_session_t *eap_session)
Send an EAP-TLS failure.
Definition tls.c:339
USES_APPLE_DEPRECATED_API fr_table_num_ordered_t const eap_tls_status_table[]
Definition tls.c:80
unlang_action_t eap_tls_process(request_t *request, eap_session_t *eap_session)
Process an EAP TLS request.
Definition tls.c:1043
int base_flags
Some protocols use the reserved bits of the EAP-TLS flags (such as PEAP).
Definition tls.h:138
@ 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_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
fr_tls_session_t * tls_session
TLS session used to authenticate peer or tunnel sensitive data.
Definition tls.h:135
#define SET_START(x)
Definition tls.h:89
Tracks the state of an EAP-TLS session.
Definition tls.h:132
void log_request_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a fr_pair_list_t.
Definition log.c:831
#define RDEBUG3(fmt,...)
Definition log.h:360
#define RWDEBUG2(fmt,...)
Definition log.h:379
#define RERROR(fmt,...)
Definition log.h:315
#define RHEXDUMP3(_data, _len, _fmt,...)
Definition log.h:724
#define REDEBUG2(fmt,...)
Definition log.h:389
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
Definition log.h:68
#define MD5_DIGEST_LENGTH
unsigned short uint16_t
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_OCTETS
Raw octets.
unsigned int uint32_t
long int ssize_t
void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Perform a single digest operation on a single input buffer.
unsigned char uint8_t
unsigned long int size_t
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
void * thread
Thread specific instance data.
Definition module_ctx.h:43
void * rctx
Resume ctx that a module previously set.
Definition module_ctx.h:45
void * thread
Thread instance data.
Definition module_ctx.h:67
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:64
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
Temporary structure to hold arguments for thread_instantiation calls.
Definition module_ctx.h:63
static uint16_t fr_nbo_to_uint16(uint8_t const data[static sizeof(uint16_t)])
Read an unsigned 16bit integer from wire format (big endian)
Definition nbo.h:146
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
Definition pair.c:2906
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
Definition pair.c:791
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:716
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1306
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:284
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:47
int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted)
Copy data into a "string" type value pair.
Definition pair.c:2756
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
Definition pair.c:509
int fr_pair_raw_afrom_pair(fr_pair_t *vp, uint8_t const *data, size_t data_len)
Mark malformed attribute as raw.
Definition pair.c:618
static const conf_parser_t config[]
Definition base.c:164
#define fr_assert(_expr)
Definition rad_assert.h:37
static char * secret
#define REDEBUG(fmt,...)
#define RDEBUG2(fmt,...)
static rs_t * conf
Definition radsniff.c:52
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:44
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:51
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:49
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:48
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:47
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:50
#define RETURN_UNLANG_HANDLED
Definition rcode.h:71
#define RETURN_UNLANG_RCODE(_rcode)
Definition rcode.h:67
#define RETURN_UNLANG_FAIL
Definition rcode.h:69
#define RETURN_UNLANG_REJECT
Definition rcode.h:68
#define RETURN_UNLANG_OK
Definition rcode.h:70
int request_detach(request_t *child)
Unlink a subrequest from its parent.
Definition request.c:560
static unlang_action_t mod_handshake_process(UNUSED unlang_result_t *p_result, UNUSED module_ctx_t const *mctx, request_t *request)
int stage
Processing stage.
static unlang_action_t eap_fast_process(unlang_result_t *p_result, request_t *request, eap_session_t *eap_session, fr_tls_session_t *tls_session)
static fr_dict_attr_t const * attr_microsoft
static unlang_action_t mod_handshake_resume(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
static fr_dict_attr_t const * attr_eap_fast_pac_a_id_info
static fr_dict_attr_t const * attr_eap_fast_pac_lifetime
fr_dict_autoload_t rlm_eap_fast_dict[]
static fr_dict_attr_t const * attr_eap_fast_pac_i_id
static fr_dict_attr_t const * attr_user_password
static int eap_fast_verify(request_t *request, fr_tls_session_t *tls_session, uint8_t const *data, unsigned int data_len)
static fr_dict_attr_t const * attr_eap_fast_pac_type
static unlang_action_t eap_fast_eap_payload(unlang_result_t *p_result, request_t *request, eap_session_t *eap_session, fr_tls_session_t *tls_session, fr_pair_t *tlv_eap_payload)
#define RANDFILL(x)
static int eap_fast_crypto_binding(request_t *request, UNUSED eap_session_t *eap_session, fr_tls_session_t *tls_session, eap_tlv_crypto_binding_tlv_t *binding)
static fr_dict_attr_t const * attr_eap_fast_pac_opaque_tlv
char const * cipher_list
cipher list specific to EAP-FAST
static fr_dict_attr_t const * attr_eap_fast_intermediate_result
virtual_server_t * virtual_server
Virtual server to use for processing inner EAP method.
static fr_dict_attr_t const * attr_eap_message
static fr_dict_attr_t const * attr_eap_type
static fr_dict_attr_t const * attr_eap_msk
static fr_dict_attr_t const * attr_eap_fast_pac_opaque_pac_key
#define MIN(a, b)
static fr_dict_attr_t const * attr_eap_fast_pac_info_i_id
static void eap_fast_send_identity_request(request_t *request, fr_tls_session_t *tls_session, eap_session_t *eap_session)
static fr_dict_attr_t const * attr_eap_fast_pac_info_a_id_info
static fr_dict_attr_t const * attr_eap_fast_pac_info_pac_lifetime
#define EAPTLS_MPPE_KEY_LEN
fr_dict_attr_autoload_t rlm_eap_fast_dict_attr[]
static fr_dict_t const * dict_freeradius
static fr_dict_attr_t const * attr_eap_tls_require_client_cert
static fr_dict_attr_t const * attr_eap_fast_pac_tlv
static ssize_t eap_fast_decode_pair(TALLOC_CTX *ctx, request_t *request, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len)
FIXME do something with mandatory.
SSL_CTX * ssl_ctx
Thread local SSL_CTX.
static fr_dict_attr_t const * attr_eap_fast_eap_payload
static unlang_action_t process_reply(unlang_result_t *p_result, request_t *request, void *uctx)
static fr_dict_t const * dict_radius
static fr_dict_attr_t const * attr_ms_chap_challenge
static fr_dict_attr_t const * attr_eap_fast_pac_key
static fr_dict_attr_t const * attr_eap_fast_crypto_binding
rlm_eap_submodule_t rlm_eap_fast
static int _session_secret(SSL *s, void *secret, int *secret_len, UNUSED STACK_OF(SSL_CIPHER) *peer_ciphers, UNUSED SSL_CIPHER const **cipher, void *arg)
static fr_dict_attr_t const * attr_eap_fast_pac_acknowledge
fr_time_delta_t pac_lifetime
seconds to add to current time to describe PAC lifetime
static void eap_fast_append_result(fr_tls_session_t *tls_session, fr_radius_packet_code_t code)
static void eap_fast_session_ticket(fr_tls_session_t *tls_session, const SSL *s, uint8_t *secret, int *secret_len)
static void eap_fast_send_error(fr_tls_session_t *tls_session, int error)
char const * pac_opaque_key
The key used to encrypt PAC-Opaque.
static fr_dict_attr_t const * attr_eap_fast_pac_info_tlv
static fr_dict_attr_t const * attr_eap_emsk
static void eap_fast_init_keys(request_t *request, fr_tls_session_t *tls_session)
RFC 4851 section 5.1 - EAP-FAST Authentication Phase 1: Key Derivations.
char const * default_provisioning_method_name
static fr_dict_attr_t const * attr_ms_mppe_send_key
static fr_dict_attr_t const * attr_eap_fast_pac_info_a_id
char const * authority_identity
The identity we present in the EAP-TLS.
static fr_dict_t const * dict_eap_fast
#define EAP_FAST_TLV_MAX
static unlang_action_t eap_fast_process_tlvs(unlang_result_t *p_result, request_t *request, void *uctx)
int default_provisioning_method
static fr_dict_attr_t const * attr_eap_fast_pac_info_pac_type
static fr_dict_attr_t const * attr_eap_fast_pac_a_id
static void eap_fast_tlv_append(fr_tls_session_t *tls_session, fr_dict_attr_t const *tlv, bool mandatory, size_t length, void const *data)
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
static fr_dict_attr_t const * attr_eap_fast_nak
static void eap_fast_send_pac_tunnel(request_t *request, fr_tls_session_t *tls_session)
static fr_dict_attr_t const * attr_eap_fast_pac_opaque_pac_type
static fr_dict_attr_t const * attr_eap_fast_error
static unlang_action_t process_rcode(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
static fr_dict_attr_t const * attr_eap_fast_pac_opaque_pac_lifetime
static void eap_fast_append_crypto_binding(request_t *request, fr_tls_session_t *tls_session)
static unlang_action_t mod_challenge_send(unlang_result_t *p_result, request_t *request, void *uctx)
static fr_dict_attr_t const * attr_user_name
static eap_fast_tunnel_t * eap_fast_alloc(TALLOC_CTX *ctx, rlm_eap_fast_t const *inst)
Allocate the FAST per-session data.
static fr_dict_attr_t const * attr_ms_mppe_recv_key
static conf_parser_t submodule_config[]
static fr_dict_attr_t const * attr_eap_fast_result
fr_tls_conf_t * tls_conf
Parsed from the tls { ... } subsection.
bool req_client_cert
Whether we require a client cert in the outer tunnel.
static fr_dict_attr_t const * attr_eap_fast_pac_opaque_i_id
static unlang_action_t eap_fast_process_tlvs_result(unlang_result_t *p_result, request_t *request, void *uctx)
static fr_dict_attr_t const * attr_ms_chap_peer_challenge
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
static unlang_action_t mod_session_init(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
static fr_dict_attr_t const * attr_eap_fast_vendor_specific
static int mod_instantiate(module_inst_ctx_t const *mctx)
static int _session_ticket(SSL *s, uint8_t const *data, int len, void *arg)
static void eap_fast_update_icmk(request_t *request, fr_tls_session_t *tls_session, uint8_t *msk)
RFC 4851 section 5.2 - Intermediate Compound Key Derivations.
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:355
size_t inst_size
Size of the module's instance data.
Definition module.h:213
void * data
Module's instance data.
Definition module.h:297
@ FR_SIGNAL_NONE
No signals.
Definition signal.h:39
@ FR_SIGNAL_CANCEL
Request has been cancelled.
Definition signal.h:40
unlang_action_t unlang_module_yield(request_t *request, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition module.c:431
eap_aka_sim_process_conf_t * inst
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
module_t common
Common fields provided by all modules.
Definition submodule.h:50
Interface exported by EAP submodules.
Definition submodule.h:49
request_t * unlang_subrequest_alloc(request_t *parent, fr_dict_t const *namespace)
Allocate a subrequest to run through a virtual server at some point in the future.
Definition subrequest.c:316
int unlang_subrequest_child_push(unlang_result_t *p_result, request_t *child, void const *unique_session_ptr, bool free_child, bool top_frame)
Push a pre-existing child back onto the stack as a subrequest.
Definition subrequest.c:440
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:804
#define talloc_get_type_abort_const
Definition talloc.h:117
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
Definition talloc.h:143
static int64_t fr_time_to_sec(fr_time_t when)
Convert an fr_time_t (internal time) to number of sec since the unix epoch (wallclock time)
Definition time.h:749
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
Definition time.h:154
#define fr_time_delta_wrap(_time)
Definition time.h:152
#define fr_time_wrap(_time)
Definition time.h:145
#define fr_time_lteq(_a, _b)
Definition time.h:240
#define fr_time_delta_ispos(_a)
Definition time.h:290
#define fr_time_eq(_a, _b)
Definition time.h:241
#define fr_time_add(_a, _b)
Add a time/time delta together.
Definition time.h:196
#define fr_time_max()
Definition time.h:143
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
#define fr_pair_dcursor_by_da_init(_cursor, _list, _da)
Initialise a cursor that will return only attributes matching the specified fr_dict_attr_t.
Definition pair.h:640
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
Definition pair_inline.c:69
#define fr_pair_list_foreach(_list_head, _iter)
Iterate over the contents of a fr_pair_list_t.
Definition pair.h:285
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
Definition pair_inline.c:42
static fr_slen_t parent
Definition pair.h:864
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:558
int fr_tls_utils_keyblock_size_get(request_t *request, SSL *ssl)
Returns the OpenSSL keyblock size.
Definition utils.c:80
ssize_t fr_value_box_from_network(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted)
Decode a fr_value_box_t from serialized binary data.
Definition value.c:1942
static fr_slen_t data
Definition value.h:1366
static fr_sbuff_err_t char ** out
Definition value.h:1061
static fr_sbuff_err_t char size_t * len
Definition value.h:1061
int virtual_server_cf_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Wrapper for the config parser to allow pass1 resolution of virtual servers.
Additional validation rules for virtual server lookup.