The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
rlm_eap_ttls.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: 2f6f457265b58a1af469cde9fbbd4352c5dfb3cc $
19 * @file rlm_eap_ttls.c
20 * @brief EAP-TTLS as defined by RFC 5281
21 *
22 * @copyright 2003 Alan DeKok (aland@freeradius.org)
23 * @copyright 2006 The FreeRADIUS server project
24 */
25
26RCSID("$Id: 2f6f457265b58a1af469cde9fbbd4352c5dfb3cc $")
27USES_APPLE_DEPRECATED_API /* OpenSSL API has been deprecated by Apple */
28
29#include <freeradius-devel/eap/tls.h>
30#include <freeradius-devel/eap/chbind.h>
31#include <freeradius-devel/tls/strerror.h>
32
33typedef struct {
34 SSL_CTX *ssl_ctx; //!< Thread local SSL_CTX.
36
37typedef struct {
38 fr_tls_conf_t *tls_conf; //!< TLS configuration
39
40 /*
41 * RFC 5281 (TTLS) says that the length field MUST NOT be
42 * in fragments after the first one. However, we've done
43 * it that way for years, and no one has complained.
44 *
45 * In the interests of allowing the server to follow the
46 * RFC, we add the option here. If set to "no", it sends
47 * the length field in ONLY the first fragment.
48 */
50
51 virtual_server_t *virtual_server; //!< Virtual server for inner tunnel session.
52
53 virtual_server_t *resume_virtual_server; //!< Virtual server to send resumed sessions through.
54
55 bool req_client_cert; //!< Do we do require a client cert?
57
62
64 { FR_CONF_SUBSECTION_ALLOC("tls", CONF_FLAG_REQUIRED, rlm_eap_ttls_t, tls_conf, fr_tls_server_config),
65 .subcs_type = "fr_tls_conf_t" },
66 { FR_CONF_V3_DEPRECATED("copy_request_to_tunnel", rlm_eap_ttls_t, NULL), .dflt = "no" },
67 { FR_CONF_V3_DEPRECATED("use_tunneled_reply", rlm_eap_ttls_t, NULL), .dflt = "no" },
70 .uctx = &(virtual_server_cf_parse_uctx_t){ .process_module_name = "radius"} },
71 { FR_CONF_OFFSET_TYPE_FLAGS("resume_virtual_server", FR_TYPE_VOID, CONF_FLAG_NOT_EMPTY, rlm_eap_ttls_t, resume_virtual_server),
73 .uctx = &(virtual_server_cf_parse_uctx_t){ .process_module_name = "radius"} },
74 { FR_CONF_OFFSET("include_length", rlm_eap_ttls_t, include_length), .dflt = "yes" },
75 { FR_CONF_OFFSET("require_client_cert", rlm_eap_ttls_t, req_client_cert), .dflt = "no" },
77};
78
80static fr_dict_t const *dict_radius;
81
84 { .out = &dict_freeradius, .proto = "freeradius" },
85 { .out = &dict_radius, .proto = "radius" },
87};
88
90
100
103 { .out = &attr_eap_tls_require_client_cert, .name = "EAP-TLS-Require-Client-Cert", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
104
105 { .out = &attr_chap_challenge, .name = "CHAP-Challenge", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
106 { .out = &attr_eap_message, .name = "EAP-Message", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
107 { .out = &attr_ms_chap_challenge, .name = "Vendor-Specific.Microsoft.CHAP-Challenge", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
108 { .out = &attr_ms_chap2_success, .name = "Vendor-Specific.Microsoft.CHAP2-Success", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
109 { .out = &attr_reply_message, .name = "Reply-Message", .type = FR_TYPE_STRING, .dict = &dict_radius },
110 { .out = &attr_eap_channel_binding_message, .name = "Vendor-Specific.UKERNA.EAP-Channel-Binding-Message", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
111 { .out = &attr_user_name, .name = "User-Name", .type = FR_TYPE_STRING, .dict = &dict_radius },
112 { .out = &attr_user_password, .name = "User-Password", .type = FR_TYPE_STRING, .dict = &dict_radius },
113 { .out = &attr_vendor_specific, .name = "Vendor-Specific", .type = FR_TYPE_VSA, .dict = &dict_radius },
115};
116
117
118#define FR_DIAMETER_AVP_FLAG_VENDOR 0x80
119#define FR_DIAMETER_AVP_FLAG_MANDATORY 0x40
120/*
121 * 0 1 2 3
122 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
123 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
124 * | AVP Code |
125 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126 * |V M r r r r r r| AVP Length |
127 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128 * | Vendor-ID (opt) |
129 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130 * | Data ...
131 * +-+-+-+-+-+-+-+-+
132 */
133
134/*
135 * Verify that the diameter packet is valid.
136 */
137static int diameter_verify(request_t *request, uint8_t const *data, unsigned int data_len)
138{
139 uint32_t attr;
140 uint32_t length;
141 unsigned int hdr_len;
142 unsigned int remaining = data_len;
143
144 while (remaining > 0) {
145 hdr_len = 8; /* 4 octet attr + 4 octet length */
146
147 if (remaining < hdr_len) {
148 RDEBUG2("Diameter attribute is too small (%u) to contain a Diameter header", remaining);
149 return 0;
150 }
151
152 memcpy(&attr, data, sizeof(attr));
153 attr = ntohl(attr);
154 memcpy(&length, data + 4, sizeof(length));
155 length = ntohl(length);
156
157 if ((data[4] & 0x80) != 0) {
158 hdr_len += 4;
159
160 if (remaining < hdr_len) {
161 RDEBUG2("Diameter attribute is too small to contain a Diameter header with Vendor-Id");
162 return 0;
163 }
164 }
165
166 /*
167 * Get the length. If it's too big, die.
168 */
169 length &= 0x00ffffff;
170
171 /*
172 * Too short or too long is bad.
173 */
174 if (length < hdr_len) {
175 RDEBUG2("Tunneled attribute %u is too short (%u < %u) to contain anything useful.", attr,
176 length, hdr_len);
177 return 0;
178 }
179
180 if (length > remaining) {
181 RDEBUG2("Tunneled attribute %u is longer than room remaining in the packet (%u > %u).", attr,
182 length, remaining);
183 return 0;
184 }
185
186 /*
187 * Check for broken implementations, which don't
188 * pad the AVP to a 4-octet boundary.
189 */
190 if (remaining == length) break;
191
192 /*
193 * The length does NOT include the padding, so
194 * we've got to account for it here by rounding up
195 * to the nearest 4-byte boundary.
196 */
197 length += 0x03;
198 length &= ~0x03;
199
200 /*
201 * If the rest of the diameter packet is larger than
202 * this attribute, continue.
203 *
204 * Otherwise, if the attribute over-flows the end
205 * of the packet, die.
206 */
207 if (remaining < length) {
208 REDEBUG2("Diameter attribute overflows packet!");
209 return 0;
210 }
211
212 /*
213 * remaining > length, continue.
214 */
215 remaining -= length;
216 data += length;
217 }
218
219 /*
220 * We got this far. It looks OK.
221 */
222 return 1;
223}
224
225/*
226 * Convert diameter attributes to our fr_pair_t's
227 */
229 fr_dict_attr_t const *parent,
230 uint8_t const *data, size_t data_len,
231 void *decode_ctx)
232{
233 uint8_t const *p = data, *end = p + data_len;
234
235 fr_pair_t *vp = NULL;
236 SSL *ssl = decode_ctx;
237 fr_dict_attr_t const *attr_radius;
238 fr_dict_attr_t const *da, *da_unknown;
239 TALLOC_CTX *tmp_ctx = NULL;
240
241 attr_radius = fr_dict_root(dict_radius);
242
243 while (p < end) {
244 ssize_t ret;
245 uint32_t attr, vendor;
246 uint64_t value_len;
247 uint8_t flags;
248 fr_dict_attr_t const *our_parent = parent;
249
250 if ((end - p) < 8) {
251 fr_strerror_printf("Malformed diameter attribute at offset %td. Needed at least 8 bytes, got %td bytes",
252 p - data, end - p);
253 error:
254 talloc_free(tmp_ctx);
256 return -1;
257 }
258
259 RDEBUG3("%04td %02x%02x%02x%02x %02x%02x%02x%02x ...", p - data,
260 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
261
262 attr = fr_nbo_to_uint32(p);
263 p += 4;
264
265 flags = p[0];
266 p++;
267
268 value_len = fr_nbo_to_uint64v(p, 3); /* Yes, that is a 24 bit length field */
269 p += 3;
270
271 if (value_len < 8) {
272 fr_strerror_printf("Malformed diameter attribute at offset %td. Needed at least length of 8, got %u",
273 p - data, (unsigned int) value_len);
274 goto error;
275 }
276
277 /*
278 * Account for the 8 bytes we've already read from the packet.
279 */
280 if ((p + ((value_len + 0x03) & ~0x03)) - 8 > end) {
281 overflow:
282 fr_strerror_printf("Malformed diameter attribute at offset %td. Value length %u overflows input",
283 p - data, (unsigned int) value_len);
284 goto error;
285 }
286
287 value_len -= 8; /* -= 8 for AVP code (4), flags (1), AVP length (3) */
288
289 /*
290 * Do we have a vendor field?
291 */
292 if (flags & FR_DIAMETER_AVP_FLAG_VENDOR) {
293 vendor = fr_nbo_to_uint32(p);
294 p += 4;
295
296 if (value_len <= 4) goto overflow;
297
298 value_len -= 4; /* -= 4 for the vendor ID field */
299
301 if (!our_parent) {
302 if (flags & FR_DIAMETER_AVP_FLAG_MANDATORY) {
303 fr_strerror_printf("Mandatory bit set and no vendor %u found", vendor);
304 goto error;
305 }
306
307 if (!tmp_ctx) {
309
310 MEM(our_parent = n = fr_dict_attr_unknown_vendor_afrom_num(ctx, parent, vendor));
311 tmp_ctx = n;
312 } else {
313 MEM(our_parent = fr_dict_attr_unknown_vendor_afrom_num(tmp_ctx, parent, vendor));
314 }
315 }
316 } else {
317 our_parent = attr_radius;
318 }
319
320 /*
321 * Is the attribute known?
322 */
323 da_unknown = NULL;
324 da = fr_dict_attr_child_by_num(our_parent, attr);
325 if (!da) {
326 if (flags & FR_DIAMETER_AVP_FLAG_MANDATORY) {
327 fr_strerror_printf("Mandatory bit set and no attribute %u defined for parent %s", attr, parent->name);
328 goto error;
329 }
330
331 MEM(da_unknown = fr_dict_attr_unknown_raw_afrom_num(ctx, our_parent, attr));
332 da = da_unknown;
333 }
334
335 MEM(vp = fr_pair_afrom_da_nested(ctx, out, da));
336 fr_dict_attr_unknown_free(&da_unknown);
337
338 ret = fr_value_box_from_network(vp, &vp->data, vp->vp_type, vp->da,
339 &FR_DBUFF_TMP(p, (size_t)value_len), value_len, true);
340 if (ret < 0) {
341 /*
342 * Mandatory bit is set, and the attribute
343 * is malformed. Fail.
344 */
345 if (flags & FR_DIAMETER_AVP_FLAG_MANDATORY) {
346 fr_strerror_const("Mandatory bit is set and attribute is malformed");
347 goto error;
348 }
349
350 fr_pair_raw_afrom_pair(vp, p, value_len);
351 }
352
353 /*
354 * The length does NOT include the padding, so
355 * we've got to account for it here by rounding up
356 * to the nearest 4-byte boundary.
357 */
358 p += (value_len + 0x03) & ~0x03;
359
360 if (vp->da->flags.is_unknown) continue;
361
362 /*
363 * Ensure that the client is using the correct challenge.
364 *
365 * This weirdness is to protect against against replay
366 * attacks, where anyone observing the CHAP exchange could
367 * pose as that user, by simply choosing to use the same
368 * challenge.
369 * By using a challenge based on information from the
370 * current session, we can guarantee that the client is
371 * not *choosing* a challenge. We're a little forgiving in
372 * that we have loose checks on the length, and we do NOT
373 * check the Id (first octet of the response to the
374 * challenge) But if the client gets the challenge correct,
375 * we're not too worried about the Id.
376 */
378 uint8_t challenge[17];
379 static const char label[] = "ttls challenge";
380
381 if ((vp->vp_length < 8) || (vp->vp_length > 16)) {
382 fr_strerror_const("Tunneled challenge has invalid length");
383 goto error;
384 }
385
386 /*
387 * TLSv1.3 exports a different key depending on the length
388 * requested so ask for *exactly* what the spec requires
389 */
390 if (SSL_export_keying_material(ssl, challenge, vp->vp_length + 1,
391 label, sizeof(label) - 1, NULL, 0, 0) != 1) {
392 fr_tls_strerror_printf("Failed generating phase2 challenge");
393 goto error;
394 }
395
396 if (memcmp(challenge, vp->vp_octets, vp->vp_length) != 0) {
397 fr_strerror_const("Tunneled challenge is incorrect");
398 goto error;
399 }
400 }
401
402 /*
403 * Diameter pads strings (i.e. User-Password) with trailing zeros.
404 */
405 if (vp->vp_type == FR_TYPE_STRING) fr_pair_value_strtrim(vp);
406 }
407
408 /*
409 * We got this far. It looks OK.
410 */
411 talloc_free(tmp_ctx);
412 return p - data;
413}
414
415/*
416 * Convert fr_pair_t's to diameter attributes, and write them
417 * to an SSL session.
418 *
419 * The ONLY fr_pair_t's which may be passed to this function
420 * are ones which can go inside of a RADIUS (i.e. diameter)
421 * packet. So no server-configuration attributes, or the like.
422 */
423static int vp2diameter(request_t *request, fr_tls_session_t *tls_session, fr_pair_list_t *list)
424{
425 /*
426 * RADIUS packets are no more than 4k in size, so if
427 * we've got more than 4k of data to write, it's very
428 * bad.
429 */
430 uint8_t buffer[4096];
431 uint8_t *p;
432 uint32_t attr;
433 uint32_t length;
434 uint32_t vendor;
435 size_t total;
436 uint64_t attr64;
437 fr_pair_t *vp;
438
439 p = buffer;
440 total = 0;
441
442 for (vp = fr_pair_list_head(list);
443 vp;
444 vp = fr_pair_list_next(list, vp)) {
445 /*
446 * Too much data: die.
447 */
448 if ((total + vp->vp_length + 12 + 3) >= sizeof(buffer)) {
449 RDEBUG2("output buffer is full!");
450 return 0;
451 }
452
453 /*
454 * Hmm... we don't group multiple EAP-Messages
455 * together. Maybe we should...
456 */
457
458 length = vp->vp_length;
459 if (length >= ((1 << 24) - 12)) {
460 RDEBUG2("Attribute is too long!");
461 return 0;
462 }
463
464 vendor = fr_dict_vendor_num_by_da(vp->da);
465 if (vendor != 0) {
466 attr = vp->da->attr & 0xffff;
467 length |= ((uint32_t)1 << 31);
468 } else {
469 attr = vp->da->attr;
470 }
471
472 /*
473 * Hmm... set the M bit for all attributes?
474 */
475 length |= (1 << 30);
476
477 attr = ntohl(attr);
478
479 memcpy(p, &attr, sizeof(attr));
480 p += 4;
481 total += 4;
482
483 length += 8; /* includes 8 bytes of attr & length */
484
485 if (vendor != 0) {
486 length += 4; /* include 4 bytes of vendor */
487
488 length = ntohl(length);
489 memcpy(p, &length, sizeof(length));
490 p += 4;
491 total += 4;
492
493 vendor = ntohl(vendor);
494 memcpy(p, &vendor, sizeof(vendor));
495 p += 4;
496 total += 4;
497 } else {
498 length = ntohl(length);
499 memcpy(p, &length, sizeof(length));
500 p += 4;
501 total += 4;
502 }
503
504 switch (vp->vp_type) {
505 case FR_TYPE_DATE:
506 attr = htonl(fr_unix_time_to_sec(vp->vp_date)); /* stored in host order */
507 memcpy(p, &attr, sizeof(attr));
508 length = 4;
509 break;
510
511 case FR_TYPE_UINT32:
512 attr = htonl(vp->vp_uint32); /* stored in host order */
513 memcpy(p, &attr, sizeof(attr));
514 length = 4;
515 break;
516
517 case FR_TYPE_UINT64:
518 attr64 = htonll(vp->vp_uint64); /* stored in host order */
519 memcpy(p, &attr64, sizeof(attr64));
520 length = 8;
521 break;
522
524 memcpy(p, &vp->vp_ipv4addr, 4); /* network order */
525 length = 4;
526 break;
527
528 case FR_TYPE_STRING:
529 case FR_TYPE_OCTETS:
530 default:
531 memcpy(p, vp->vp_strvalue, vp->vp_length);
532 length = vp->vp_length;
533 break;
534 }
535
536 /*
537 * Skip to the end of the data.
538 */
539 p += length;
540 total += length;
541
542 /*
543 * Align the data to a multiple of 4 bytes.
544 */
545 if ((total & 0x03) != 0) {
546 size_t i;
547
548 length = 4 - (total & 0x03);
549 for (i = 0; i < length; i++) {
550 *p = '\0';
551 p++;
552 total++;
553 }
554 }
555 } /* loop over the VP's to write. */
556
557 /*
558 * Write the data in the buffer to the SSL session.
559 */
560 if (total > 0) {
561 (void) fr_dbuff_in_memcpy_partial(&tls_session->clean_in, buffer, total);
562
563 /*
564 * FIXME: Check the return code.
565 */
566 fr_tls_session_send(request, tls_session);
567 }
568
569 /*
570 * Everything's OK.
571 */
572 return 1;
573}
574
575
577{
578 eap_tls_prf_label_t prf_label;
579
580 eap_crypto_prf_label_init(&prf_label, eap_session,
581 "ttls keying material",
582 sizeof("ttls keying material") - 1);
583
584 p_result->rcode = RLM_MODULE_OK;
585 return eap_tls_success(request, eap_session, &prf_label);
586}
587
588
589/*
590 * Use a reply packet to determine what to do.
591 *
592 * This runs in the child request, after the inner tunnel has run. The TLS session is bound
593 * to the parent request, so everything which writes to the TLS session takes the parent.
594 * The result of this function is the result of the child, and process_rcode() reads the
595 * result in the parent.
596 */
598{
599 eap_session_t *eap_session = talloc_get_type_abort(uctx, eap_session_t);
600 eap_tls_session_t *eap_tls_session = talloc_get_type_abort(eap_session->opaque, eap_tls_session_t);
601 fr_tls_session_t *tls_session = eap_tls_session->tls_session;
602 fr_pair_t *vp = NULL, *copy;
603 fr_pair_list_t tunnel_vps;
604 ttls_tunnel_t *t = tls_session->opaque;
605 request_t *parent = request->parent;
606 fr_packet_t *reply = request->reply;
607
608 fr_pair_list_init(&tunnel_vps);
609 fr_assert(eap_session->request == parent->parent);
610
611 p_result->priority = MOD_PRIORITY_MAX;
612
613 /*
614 * If the response packet was Access-Accept, then
615 * we're OK. If not, die horribly.
616 *
617 * FIXME: Take MS-CHAP2-Success attribute, and
618 * tunnel it back to the client, to authenticate
619 * ourselves to the client.
620 *
621 * FIXME: If we have an Access-Challenge, then
622 * the Reply-Message is tunneled back to the client.
623 *
624 * FIXME: If we have an EAP-Message, then that message
625 * must be tunneled back to the client.
626 *
627 * FIXME: If we have an Access-Challenge with a State
628 * attribute, then do we tunnel that to the client, or
629 * keep track of it ourselves?
630 *
631 * FIXME: EAP-Messages can only start with 'identity',
632 * NOT 'eap start', so we should check for that....
633 */
634 switch (reply->code) {
636 /*
637 * Copy what we need into the TTLS tunnel and leave
638 * the rest to be cleaned up.
639 */
641 RDEBUG2("Got MS-CHAP2-Success, tunneling it to the client in a challenge");
642 } else {
644 }
645 if (vp) {
646 t->authenticated = true;
647 MEM(copy = fr_pair_copy(tls_session, vp));
648 fr_pair_prepend(&tunnel_vps, copy);
650 break;
651 }
652
653 /*
654 * Success: process_rcode() automatically returns MPPE keys.
655 */
657
660
661 /*
662 * Handle Access-Challenge, but only if we
663 * send tunneled reply data. This is because
664 * an Access-Challenge means that we MUST tunnel
665 * a Reply-Message to the client.
666 */
668 /*
669 * Copy what we need into the TTLS tunnel and leave
670 * the rest to be cleaned up.
671 */
672 vp = NULL;
673 while ((vp = fr_pair_list_next(&request->reply_pairs, vp))) {
674 if ((vp->da == attr_eap_message) || (vp->da == attr_reply_message)) {
675 MEM(copy = fr_pair_copy(tls_session, vp));
676 fr_pair_prepend(&tunnel_vps, copy);
677 } else if (vp->da == attr_eap_channel_binding_message) {
678 MEM(copy = fr_pair_copy(tls_session, vp));
679 fr_pair_prepend(&tunnel_vps, copy);
680 }
681 }
682 break;
683
684 default:
685 REDEBUG("Unknown RADIUS packet type %u: rejecting tunneled user", reply->code);
687 }
688
689
690 /*
691 * Pack any tunneled VPs and send them back
692 * to the supplicant.
693 */
694 if (!fr_pair_list_empty(&tunnel_vps)) {
695 RDEBUG2("Sending tunneled reply attributes");
696 log_request_pair_list(L_DBG_LVL_2, request, NULL, &tunnel_vps, NULL);
697
698 vp2diameter(parent, tls_session, &tunnel_vps);
699 fr_pair_list_free(&tunnel_vps);
700 }
701
703}
704
705/*
706 * Construct the reply appropriately based on the rcode from TTLS processing.
707 *
708 * This runs in the request which holds the TLS session, once the child has finished.
709 */
711{
712 eap_session_t *eap_session = talloc_get_type_abort(mctx->rctx, eap_session_t);
713
714 RDEBUG3("Tunneled request complete");
715
716 switch (eap_session->submodule_result.rcode) {
717 case RLM_MODULE_OK:
718 return eap_ttls_success(p_result, request, eap_session);
719
721 eap_tls_request(request, eap_session);
723
724 default:
725 p_result->rcode = eap_session->submodule_result.rcode;
726 return eap_tls_fail(request, eap_session);
727 }
728}
729
730/*
731 * Process the "diameter" contents of the tunneled data.
732 *
733 * The inner tunnel runs in a child request, so that the session-state list of the TLS
734 * session stays in this request. The state code moves the session-state list out of the
735 * request which ran the inner tunnel, and the TLS session needs the list when it stores
736 * a session ticket.
737 */
739 request_t *request, eap_session_t *eap_session, fr_tls_session_t *tls_session)
740{
741 fr_pair_t *vp = NULL;
742 ttls_tunnel_t *t;
743 uint8_t const *data;
744 size_t data_len;
745 chbind_packet_t *chbind;
746 fr_pair_t *username;
747 request_t *child = NULL;
748 rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_eap_ttls_t);
750
751 /*
752 * Read the buffer directly, rather than copying the
753 * octets out of it.
754 */
755 data_len = fr_dbuff_used(&tls_session->clean_out);
756 data = fr_dbuff_start(&tls_session->clean_out);
757 fr_tls_record_init(&tls_session->clean_out);
758
759 t = (ttls_tunnel_t *) tls_session->opaque;
760
761 /*
762 * If there's no data, maybe this is an ACK to an
763 * MS-CHAP2-Success.
764 */
765 if (data_len == 0) {
766 if (t->authenticated) {
767 RDEBUG2("Got ACK, and the user was already authenticated");
769 } /* else no session, no data, die. */
770
771 /*
772 * FIXME: Call SSL_get_error() to see what went
773 * wrong.
774 */
775 RDEBUG2("SSL_read Error");
777 }
778
780
781 MEM(child = unlang_subrequest_alloc(request, request->proto_dict));
782 fr_assert(fr_pair_list_empty(&child->request_pairs));
783
784 /*
785 * Add the tunneled attributes to the child request.
786 */
787 if (eap_ttls_decode_pair(request, child->request_ctx, &child->request_pairs, fr_dict_root(fr_dict_internal()),
788 data, data_len, tls_session->ssl) < 0) {
789 RPEDEBUG("Decoding TTLS TLVs failed");
790 goto finish;
791 }
792
793 /*
794 * Update other items in the request_t data structure.
795 */
796
797 /*
798 * No User-Name, try to create one from stored data.
799 */
800 username = fr_pair_find_by_da(&child->request_pairs, NULL, attr_user_name);
801 if (!username) {
802 /*
803 * No User-Name in the stored data, look for
804 * an EAP-Identity, and pull it out of there.
805 */
806 if (!t->username) {
807 vp = fr_pair_find_by_da(&child->request_pairs, NULL, attr_eap_message);
808 if (vp &&
809 (vp->vp_length >= EAP_HEADER_LEN + 2) &&
810 (vp->vp_strvalue[0] == FR_EAP_CODE_RESPONSE) &&
811 (vp->vp_strvalue[EAP_HEADER_LEN] == FR_EAP_METHOD_IDENTITY) &&
812 (vp->vp_strvalue[EAP_HEADER_LEN + 1] != 0)) {
813 /*
814 * Create & remember a User-Name
815 */
817 t->username->vp_tainted = true;
818
820 (char const *)vp->vp_octets + 5, vp->vp_length - 5, true);
821
822 RDEBUG2("Got tunneled identity of %pV", &t->username->data);
823 } else {
824 /*
825 * Don't reject the request outright,
826 * as it's permitted to do EAP without
827 * user-name.
828 */
829 RWDEBUG2("No EAP-Identity found to start EAP conversation");
830 }
831 } /* else there WAS a t->username */
832
833 if (t->username) {
834 MEM(vp = fr_pair_copy(child->request_ctx, t->username));
835 fr_pair_append(&child->request_pairs, vp);
836 }
837 } /* else the request ALREADY had a User-Name */
838
839 /*
840 * Process channel binding.
841 */
842 chbind = eap_chbind_vp2packet(child, &child->request_pairs);
843 if (chbind) {
844 fr_radius_packet_code_t chbind_code;
845 CHBIND_REQ *req = talloc_zero(child, CHBIND_REQ);
846
847 RDEBUG2("received chbind request");
848 req->request = chbind;
849 if (username) {
850 req->username = username;
851 } else {
852 req->username = NULL;
853 }
854 chbind_code = chbind_process(child, req);
855
856 /* encapsulate response here */
857 if (req->response) {
858 RDEBUG2("sending chbind response");
859 fr_pair_append(&child->reply_pairs,
860 eap_chbind_packet2vp(child->reply_ctx, req->response));
861 } else {
862 RDEBUG2("no chbind response");
863 }
864
865 /* clean up chbind req */
866 talloc_free(req);
867
868 if (chbind_code != FR_RADIUS_CODE_ACCESS_ACCEPT) goto finish;
869 }
870
871 RDEBUG2("Got tunneled request");
872 log_request_pair_list(L_DBG_LVL_2, request, NULL, &child->request_pairs, NULL);
873
874 /*
875 * Set the child up for execution.
876 */
877 if (unlang_subrequest_child_push(&eap_session->submodule_result, child,
878 child,
879 false, UNLANG_SUB_FRAME) < 0) goto finish;
880
881 /*
882 * Set up a function in the child to process the result of the inner tunnel. The function
883 * runs in the child after the virtual server executes. The function sets the rcode of the
884 * subrequest, which is written to eap_session->submodule_result.
885 */
887 child,
888 NULL,
890 NULL, FR_SIGNAL_NONE,
891 UNLANG_SUB_FRAME, eap_session) != UNLANG_ACTION_PUSHED_CHILD) goto finish;
892
893 /*
894 * Call authentication recursively, which will
895 * do PAP, CHAP, MS-CHAP, etc.
896 */
897 if (unlikely(eap_virtual_server(child, eap_session, inst->virtual_server) == UNLANG_ACTION_FAIL)) goto finish;
898
899 /*
900 * We now yield to the subrequest. unlang_subrequest_child_push
901 * pushed a new frame in the context of the parent which'll start
902 * the subrequest.
903 */
905
906finish:
907 if (child) {
908 /*
909 * We can't just free the child, we need to detach it
910 * and then let the interpreter to unwind and eventually
911 * free the request.
912 */
913 request_detach(child);
915 }
916
917 RETURN_UNLANG_RCODE(rcode);
918}
919
920/*
921 * Allocate the TTLS per-session data
922 */
923static ttls_tunnel_t *ttls_alloc(TALLOC_CTX *ctx)
924{
925 ttls_tunnel_t *t;
926
927 t = talloc_zero(ctx, ttls_tunnel_t);
928
929 return t;
930}
931
933{
934#ifndef NDEBUG
935 eap_session_t *eap_session = talloc_get_type_abort(uctx, eap_session_t);
936 request_t *parent = request->parent;
937#endif
938
939 fr_assert(eap_session->request == parent->parent);
940
941 p_result->priority = MOD_PRIORITY_MAX;
942
943 switch (request->reply->code) {
946
947 default:
949 }
950}
951
953{
954 eap_session_t *eap_session = talloc_get_type_abort(mctx->rctx, 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
958 ttls_tunnel_t *tunnel = talloc_get_type_abort(tls_session->opaque, ttls_tunnel_t);
959
960 if ((eap_tls_session->state == EAP_TLS_INVALID) || (eap_tls_session->state == EAP_TLS_FAIL)) {
961 REDEBUG("[eap-tls process] = %s", fr_table_str_by_value(eap_tls_status_table, eap_tls_session->state, "<INVALID>"));
962 } else {
963 RDEBUG2("[eap-tls process] = %s", fr_table_str_by_value(eap_tls_status_table, eap_tls_session->state, "<INVALID>"));
964 }
965
966 switch (eap_tls_session->state) {
967 /*
968 * EAP-TLS handshake was successful, tell the
969 * client to keep talking.
970 *
971 * If this was EAP-TLS, we would just return
972 * an EAP-TLS-Success packet here.
973 */
975 if (SSL_session_reused(tls_session->ssl)) {
976 rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_eap_ttls_t);
977 request_t *child;
978
979 RDEBUG2("Skipping Phase2 due to session resumption");
980
981 /*
982 * A simplified version of the code used to process tunnelled TTLS data.
983 *
984 * In this case, the request is populated with pairs restored from
985 * the cached session-state.
986 */
987 (void) unlang_module_yield(request, process_rcode, NULL, FR_SIGNAL_NONE, eap_session);
988
989 MEM(child = unlang_subrequest_alloc(request, request->proto_dict));
990
991 if (unlikely(fr_pair_list_copy(child->request_ctx, &child->request_pairs,
992 &request->session_state_pairs) < 0)) {
993 error:
994 request_detach(child);
997 }
998
999 RDEBUG2("Resumed session-state:");
1000 log_request_pair_list(L_DBG_LVL_2, request, NULL, &child->request_pairs, NULL);
1001
1002 if (unlang_subrequest_child_push(&eap_session->submodule_result, child, child,
1003 false, UNLANG_SUB_FRAME) < 0) goto error;
1004
1005 if (unlang_function_push_with_result(NULL, child, NULL, process_resume_reply, NULL,
1007 eap_session) != UNLANG_ACTION_PUSHED_CHILD) goto error;
1008
1009 if (unlikely(eap_virtual_server(child, eap_session,
1010 inst->resume_virtual_server) == UNLANG_ACTION_FAIL)) goto error;
1011
1013 }
1014
1015 if (tunnel && tunnel->authenticated) return eap_ttls_success(p_result, request, eap_session);
1016
1017 /*
1018 * Some supplicants send application data in the same packet as
1019 * the end of the handshake - continue to process that data.
1020 */
1021 if (fr_dbuff_used(&tls_session->clean_out) > 0) break;
1022
1023 eap_tls_request(request, eap_session);
1025
1026 /*
1027 * The TLS code is still working on the TLS
1028 * exchange, and it's a valid TLS request.
1029 * do nothing.
1030 */
1031 case EAP_TLS_HANDLED:
1033
1034 /*
1035 * Handshake is done, proceed with decoding tunneled
1036 * data.
1037 */
1039 break;
1040
1041 /*
1042 * Anything else: fail.
1043 */
1044 default:
1045 p_result->rcode = RLM_MODULE_FAIL;
1046 return eap_tls_fail(request, eap_session);
1047 }
1048
1049 /*
1050 * Session is established, proceed with decoding
1051 * tunneled data.
1052 */
1053 RDEBUG2("Session established. Decoding Diameter attributes");
1054
1055 /*
1056 * Set up the resume point to prepare the correct reply based on
1057 * the rcode coming back from the inner tunnel.
1058 */
1059 (void) unlang_module_yield(request, process_rcode, NULL, FR_SIGNAL_NONE, eap_session);
1060
1061 /*
1062 * Process the TTLS portion of the request.
1063 */
1064 return eap_ttls_process(&eap_session->submodule_result, mctx, request, eap_session, tls_session);
1065}
1066
1067/*
1068 * Do authentication, by letting EAP-TLS do most of the work.
1069 */
1072{
1073 eap_session_t *eap_session = eap_session_get(request->parent);
1074
1075 /*
1076 * Setup the resumption frame to process the result
1077 */
1079
1080 /*
1081 * Process TLS layer until done.
1082 */
1083 return eap_tls_process(request, eap_session);
1084}
1085
1087{
1088 rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_eap_ttls_t);
1089 rlm_eap_ttls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_ttls_thread_t);
1090 eap_session_t *eap_session = eap_session_get(request->parent);
1091
1092 eap_tls_session_t *eap_tls_session;
1093 fr_tls_session_t *tls_session;
1094 fr_pair_t *vp;
1095 bool client_cert;
1096
1097 /*
1098 * EAP-TLS-Require-Client-Cert attribute will override
1099 * the require_client_cert configuration option.
1100 */
1102 if (vp) {
1103 client_cert = vp->vp_uint32 ? true : false;
1104 } else {
1105 client_cert = inst->req_client_cert;
1106 }
1107
1108 eap_session->opaque = eap_tls_session = eap_tls_session_init(request, eap_session, t->ssl_ctx, client_cert);
1109 if (!eap_tls_session) RETURN_UNLANG_FAIL;
1110 tls_session = eap_tls_session->tls_session;
1111
1112 eap_tls_session->include_length = inst->include_length;
1113
1114 /*
1115 * TLS session initialization is over. Now handle TLS
1116 * related handshaking or application data.
1117 */
1118 if (eap_tls_start(request, eap_session) < 0) {
1119 talloc_free(eap_tls_session);
1121 }
1122
1123 tls_session->opaque = ttls_alloc(tls_session);
1124
1125 eap_session->process = mod_handshake_process;
1126
1128}
1129
1130/*
1131 * Send an initial eap-tls request to the peer, using the libeap functions.
1132 */
1134{
1135 rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_eap_ttls_t);
1136 eap_session_t *eap_session = eap_session_get(request->parent);
1137
1138 eap_session->tls = true;
1139
1141
1142 if (inst->tls_conf->new_session) return fr_tls_new_session_push(request, inst->tls_conf);
1143
1145}
1146
1148{
1149 rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_eap_ttls_t);
1150 rlm_eap_ttls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_ttls_thread_t);
1151
1152 t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false);
1153 if (!t->ssl_ctx) return -1;
1154
1155 return 0;
1156}
1157
1159{
1160 rlm_eap_ttls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_ttls_thread_t);
1161
1162 if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx);
1163 t->ssl_ctx = NULL;
1164
1165 return 0;
1166}
1167
1168/*
1169 * Attach the module.
1170 */
1171static int mod_instantiate(module_inst_ctx_t const *mctx)
1172{
1173 rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_eap_ttls_t);
1174 CONF_SECTION *conf = mctx->mi->conf;
1175
1176 eap_tls_conf_check(conf, inst->tls_conf, true);
1177
1178 if (eap_tls_check_stateless(conf, inst->tls_conf) < 0) return -1;
1179
1180 if (!inst->resume_virtual_server) inst->resume_virtual_server = inst->virtual_server;
1181
1182 return 0;
1183}
1184
1185/*
1186 * The module name should be the only globally exported symbol.
1187 * That is, everything else should be 'static'.
1188 */
1191 .common = {
1192 .magic = MODULE_MAGIC_INIT,
1193 .name = "eap_ttls",
1194
1195 .inst_size = sizeof(rlm_eap_ttls_t),
1197 .instantiate = mod_instantiate, /* Create new submodule instance */
1198
1199 .thread_inst_size = sizeof(rlm_eap_ttls_thread_t),
1200 .thread_instantiate = mod_thread_instantiate,
1201 .thread_detach = mod_thread_detach,
1202 },
1203 .provides = { FR_EAP_METHOD_TTLS },
1204 .session_init = mod_session_init, /* Initialise a new EAP session */
1205 .tunnel = true
1206};
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
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:38
static int const char char buffer[256]
Definition acutest.h:641
int n
Definition acutest.h:642
static uint8_t request[4]
static uint8_t reply[4]
static uint8_t overflow[100]
#define USES_APPLE_DEPRECATED_API
Definition build.h:596
#define RCSID(id)
Definition build.h:609
#define NDEBUG_UNUSED
Definition build.h:426
#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_V3_DEPRECATED(_name, _struct, _field)
conf_parser_t entry which raises an error if a deprecated v3 item is found
Definition cf_parse.h:446
#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_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
fr_pair_t * eap_chbind_packet2vp(TALLOC_CTX *ctx, chbind_packet_t *chbind)
Definition chbind.c:318
fr_radius_packet_code_t chbind_process(request_t *request, CHBIND_REQ *chbind)
Definition chbind.c:174
chbind_packet_t * eap_chbind_vp2packet(TALLOC_CTX *ctx, fr_pair_list_t *vps)
Definition chbind.c:273
chbind_packet_t * response
Definition chbind.h:49
fr_pair_t * username
Definition chbind.h:47
chbind_packet_t * request
Definition chbind.h:48
#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_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
#define MEM(x)
Definition debug.h:38
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
static fr_dict_attr_t * fr_dict_attr_unknown_vendor_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int vendor)
Definition dict.h:628
static fr_dict_attr_t * fr_dict_attr_unknown_raw_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr)
Definition dict.h:635
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 * fr_dict_vendor_da_by_num(fr_dict_attr_t const *vendor_root, uint32_t vendor_pen)
Return vendor attribute for the specified dictionary and pen.
Definition dict_util.c:3039
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
void fr_dict_attr_unknown_free(fr_dict_attr_t const **da)
Free dynamically allocated (unknown attributes)
fr_dict_t const * fr_dict_internal(void)
Definition dict_util.c:5080
#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
static uint32_t fr_dict_vendor_num_by_da(fr_dict_attr_t const *da)
Return the vendor number for an attribute.
Definition dict_ext.h:177
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
@ FR_EAP_METHOD_TTLS
Definition types.h:66
@ FR_EAP_METHOD_IDENTITY
Definition types.h:46
#define EAP_HEADER_LEN
Definition types.h:34
@ FR_EAP_CODE_RESPONSE
Definition types.h:38
#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)
void unlang_interpret_signal(request_t *request, fr_signal_t action)
Send a signal (usually stop) to a request.
Definition interpret.c:1806
unlang_mod_action_t priority
The priority or action for that rcode.
Definition interpret.h:142
#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_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
static eap_session_t * eap_session_get(request_t *request)
Definition session.h:97
void * opaque
Opaque data used by EAP methods.
Definition session.h:69
bool tls
Whether EAP method uses TLS.
Definition session.h:78
module_method_t process
Callback that should be used to process the next round.
Definition session.h:71
unlang_result_t submodule_result
Result of last submodule call.
Definition session.h:53
request_t * request
Current request.
Definition session.h:58
Tracks the progress of a single session of any EAP method.
Definition session.h:47
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:308
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:1377
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:1606
int eap_tls_start(request_t *request, eap_session_t *eap_session)
Send an initial EAP-TLS request to the peer.
Definition tls.c:272
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:422
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:1702
unlang_action_t eap_tls_fail(request_t *request, eap_session_t *eap_session)
Send an EAP-TLS failure.
Definition tls.c:369
USES_APPLE_DEPRECATED_API fr_table_num_ordered_t const eap_tls_status_table[]
Definition tls.c:82
unlang_action_t eap_tls_process(request_t *request, eap_session_t *eap_session)
Process an EAP TLS request.
Definition tls.c:1178
@ EAP_TLS_INVALID
Invalid, don't reply.
Definition tls.h:121
@ EAP_TLS_HANDLED
TLS code has handled it.
Definition tls.h:124
@ EAP_TLS_RECORD_RECV_COMPLETE
Received final fragment of a record.
Definition tls.h:141
@ EAP_TLS_FAIL
Fail, send fail.
Definition tls.h:123
@ EAP_TLS_ESTABLISHED
Session established, send success (or start phase2).
Definition tls.h:122
eap_tls_status_t state
The state of the EAP-TLS session.
Definition tls.h:157
fr_tls_session_t * tls_session
TLS session used to authenticate peer or tunnel sensitive data.
Definition tls.h:159
bool include_length
A flag to include length in every TLS Data/Alert packet.
Definition tls.h:168
Tracks the state of an EAP-TLS session.
Definition tls.h:156
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 RPEDEBUG(fmt,...)
Definition log.h:393
#define REDEBUG2(fmt,...)
Definition log.h:389
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
Definition log.h:68
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
@ FR_TYPE_OCTETS
Raw octets.
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
@ MOD_PRIORITY_MAX
Definition mod_action.h:61
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 uint64_t fr_nbo_to_uint64v(uint8_t const *data, size_t data_len)
Read an unsigned 64bit integer from wire format (big endian) with a variable length encoding.
Definition nbo.h:196
static uint32_t fr_nbo_to_uint32(uint8_t const data[static sizeof(uint32_t)])
Read an unsigned 32bit integer from wire format (big endian)
Definition nbo.h:167
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
Definition pair.c:2312
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_value_strtrim(fr_pair_t *vp)
Trim the length of the string buffer to match the length of the C string.
Definition pair.c:2650
fr_pair_t * fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da)
Create a pair (and all intermediate parents), and append it to the list.
Definition pair.c:486
int fr_pair_prepend(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the start of the list.
Definition pair.c:1275
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
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG2(fmt,...)
Definition radclient.h:54
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_OK
The module is OK, continue.
Definition rcode.h:49
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:48
@ 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_INVALID
Definition rcode.h:72
#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)
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_user_password
bool req_client_cert
Do we do require a client cert?
virtual_server_t * virtual_server
Virtual server for inner tunnel session.
static fr_dict_attr_t const * attr_eap_message
static fr_dict_attr_t const * attr_eap_channel_binding_message
#define FR_DIAMETER_AVP_FLAG_MANDATORY
static fr_dict_t const * dict_freeradius
static fr_dict_attr_t const * attr_eap_tls_require_client_cert
fr_pair_t * username
virtual_server_t * resume_virtual_server
Virtual server to send resumed sessions through.
SSL_CTX * ssl_ctx
Thread local SSL_CTX.
static unlang_action_t process_reply(unlang_result_t *p_result, request_t *request, void *uctx)
static fr_dict_attr_t const * attr_ms_chap2_success
static unlang_action_t mod_session_init_resume(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
static fr_dict_t const * dict_radius
static fr_dict_attr_t const * attr_ms_chap_challenge
static fr_dict_attr_t const * attr_chap_challenge
static fr_dict_attr_t const * attr_vendor_specific
static fr_dict_attr_t const * attr_reply_message
static unlang_action_t eap_ttls_success(unlang_result_t *p_result, request_t *request, eap_session_t *eap_session)
static int vp2diameter(request_t *request, fr_tls_session_t *tls_session, fr_pair_list_t *list)
static int diameter_verify(request_t *request, uint8_t const *data, unsigned int data_len)
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
static unlang_action_t process_resume_reply(unlang_result_t *p_result, request_t *request, NDEBUG_UNUSED void *uctx)
static unlang_action_t process_rcode(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
fr_tls_conf_t * tls_conf
TLS configuration.
static ssize_t eap_ttls_decode_pair(request_t *request, TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
static fr_dict_attr_t const * attr_user_name
static conf_parser_t submodule_config[]
#define FR_DIAMETER_AVP_FLAG_VENDOR
static unlang_action_t mod_session_init(UNUSED unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
fr_dict_attr_autoload_t rlm_eap_ttls_dict_attr[]
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
static unlang_action_t eap_ttls_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request, eap_session_t *eap_session, fr_tls_session_t *tls_session)
static int mod_instantiate(module_inst_ctx_t const *mctx)
fr_dict_autoload_t rlm_eap_ttls_dict[]
rlm_eap_submodule_t rlm_eap_ttls
static ttls_tunnel_t * ttls_alloc(TALLOC_CTX *ctx)
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:356
size_t inst_size
Size of the module's instance data.
Definition module.h:214
void * data
Module's instance data.
Definition module.h:298
@ 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
static int64_t fr_unix_time_to_sec(fr_unix_time_t delta)
Definition time.h:506
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
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
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_const(_msg)
Definition strerror.h:223
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
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.