2 * rlm_eap_ttls.c contains the interfaces that are called from eap
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2003 Alan DeKok <aland@freeradius.org>
21 * Copyright 2006 The FreeRADIUS server project
30 * 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
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * |V M r r r r r r| AVP Length |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * Verify that the diameter packet is valid.
45 static int diameter_verify(REQUEST *request, uint8_t const *data, unsigned int data_len)
50 unsigned int remaining = data_len;
52 while (remaining > 0) {
55 if (remaining < hdr_len) {
56 RDEBUG2("Diameter attribute is too small (%u) to contain a Diameter header", remaining);
60 memcpy(&attr, data, sizeof(attr));
62 memcpy(&length, data + 4, sizeof(length));
63 length = ntohl(length);
65 if ((data[4] & 0x80) != 0) {
67 RDEBUG2("Diameter attribute is too small to contain a Diameter header with Vendor-Id");
75 * Get the length. If it's too big, die.
80 * Too short or too long is bad.
82 if (length <= (hdr_len - 4)) {
83 RDEBUG2("Tunneled attribute %u is too short (%u < %u) to contain anything useful.", attr,
88 if (length > remaining) {
89 RDEBUG2("Tunneled attribute %u is longer than room remaining in the packet (%u > %u).", attr,
95 * Check for broken implementations, which don't
96 * pad the AVP to a 4-octet boundary.
98 if (remaining == length) break;
101 * The length does NOT include the padding, so
102 * we've got to account for it here by rounding up
103 * to the nearest 4-byte boundary.
109 * If the rest of the diameter packet is larger than
110 * this attribute, continue.
112 * Otherwise, if the attribute over-flows the end
113 * of the packet, die.
115 if (remaining < length) {
116 REDEBUG2("Diameter attribute overflows packet!");
121 * remaining > length, continue.
128 * We got this far. It looks OK.
135 * Convert diameter attributes to our VALUE_PAIR's
137 static VALUE_PAIR *diameter2vp(REQUEST *request, REQUEST *fake, SSL *ssl,
138 uint8_t const *data, size_t data_len)
145 size_t data_left = data_len;
147 VALUE_PAIR *first = NULL;
149 RADIUS_PACKET *packet = fake->packet; /* FIXME: api issues */
152 fr_cursor_init(&out, &first);
154 while (data_left > 0) {
155 rad_assert(data_left <= data_len);
156 memcpy(&attr, data, sizeof(attr));
161 memcpy(&length, data, sizeof(length));
163 length = ntohl(length);
166 * A "vendor" flag, with a vendor ID of zero,
167 * is equivalent to no vendor. This is stupid.
170 if ((length & (1 << 31)) != 0) {
171 memcpy(&vendor, data, sizeof(vendor));
172 vendor = ntohl(vendor);
174 data += 4; /* skip the vendor field, it's zero */
175 offset += 4; /* offset to value field */
177 if (attr > 65535) goto next_attr;
178 if (vendor > FR_MAX_VENDOR) goto next_attr;
182 * FIXME: Handle the M bit. For now, we assume that
183 * some other module takes care of any attribute
184 * with the M bit set.
190 length &= 0x00ffffff;
193 * Get the size of the value portion of the
196 size = length - offset;
199 * Vendor attributes can be larger than 255.
200 * Normal attributes cannot be.
202 if ((attr > 255) && (vendor == 0)) {
203 RWDEBUG2("Skipping Diameter attribute %u", attr);
208 * EAP-Message AVPs can be larger than 253 octets.
210 * For now, we rely on the main decoder in
211 * src/lib/radius to decode data into VPs. This
212 * means putting the data into a RADIUS attribute
213 * format. It also means that we can't handle
214 * "extended" attributes in the Diameter space. Oh well...
216 if ((size > 253) && !((vendor == 0) && (attr == PW_EAP_MESSAGE))) {
217 RWDEBUG2("diameter2vp skipping long attribute %u", attr);
222 * RADIUS VSAs are handled as Diameter attributes
223 * with Vendor-Id == 0, and the VSA data packed
224 * into the "String" field as per normal.
226 * EXCEPT for the MS-CHAP attributes.
228 if ((vendor == 0) && (attr == PW_VENDOR_SPECIFIC)) {
232 buffer[0] = PW_VENDOR_SPECIFIC;
233 buffer[1] = size + 2;
234 memcpy(buffer + 2, data, size);
237 decoded = rad_attr2vp(packet, NULL, NULL, NULL,
238 buffer, size + 2, &vp);
240 REDEBUG2("diameter2vp failed decoding attr: %s",
245 if ((size_t) decoded != size + 2) {
246 REDEBUG2("diameter2vp failed to entirely decode VSA");
251 fr_cursor_insert(&out, vp);
257 * Create it. If this fails, it's because we're OOM.
260 vp = paircreate(packet, attr, vendor);
262 RDEBUG2("Failure in creating VP");
268 * If it's a type from our dictionary, then
269 * we need to put the data in a relevant place.
271 * @todo: Export the lib/radius.c decoder, and use it here!
273 switch (vp->da->type) {
274 case PW_TYPE_INTEGER:
276 if (size != vp->length) {
280 * Bad format. Create a "raw"
284 if (vp) pairfree(&vp);
285 da = dict_attrunknown(attr, vendor, true);
286 if (!da) return NULL;
287 vp = pairalloc(packet, da);
288 if (!vp) return NULL;
289 pairmemcpy(vp, data, size);
292 memcpy(&vp->vp_integer, data, vp->length);
295 * Stored in host byte order: change it.
297 vp->vp_integer = ntohl(vp->vp_integer);
300 case PW_TYPE_INTEGER64:
301 if (size != vp->length) goto raw;
302 memcpy(&vp->vp_integer64, data, vp->length);
305 * Stored in host byte order: change it.
307 vp->vp_integer64 = ntohll(vp->vp_integer64);
310 case PW_TYPE_IPV4_ADDR:
311 if (size != vp->length) {
312 RDEBUG2("Invalid length attribute %d",
318 memcpy(&vp->vp_ipaddr, data, vp->length);
321 * Stored in network byte order: don't change it.
326 if (size != vp->length) goto raw;
327 vp->vp_integer = data[0];
331 if (size != vp->length) goto raw;
332 vp->vp_integer = (data[0] * 256) + data[1];
336 if (size != vp->length) goto raw;
337 memcpy(&vp->vp_signed, data, vp->length);
338 vp->vp_signed = ntohl(vp->vp_signed);
341 case PW_TYPE_IPV6_ADDR:
342 if (size != vp->length) goto raw;
343 memcpy(&vp->vp_ipv6addr, data, vp->length);
346 case PW_TYPE_IPV6_PREFIX:
347 if (size != vp->length) goto raw;
348 memcpy(&vp->vp_ipv6prefix, data, vp->length);
352 * Ensure it's NUL terminated.
355 vp->vp_strvalue = p = talloc_array(vp, char, size + 1);
357 memcpy(p, data, size);
359 vp->length = strlen(p);
363 * Copy it over verbatim.
367 pairmemcpy(vp, data, size);
372 * Ensure that the client is using the
373 * correct challenge. This weirdness is
374 * to protect against against replay
375 * attacks, where anyone observing the
376 * CHAP exchange could pose as that user,
377 * by simply choosing to use the same
380 * By using a challenge based on
381 * information from the current session,
382 * we can guarantee that the client is
383 * not *choosing* a challenge.
385 * We're a little forgiving in that we
386 * have loose checks on the length, and
387 * we do NOT check the Id (first octet of
388 * the response to the challenge)
390 * But if the client gets the challenge correct,
391 * we're not too worried about the Id.
393 if (((vp->da->vendor == 0) && (vp->da->attr == PW_CHAP_CHALLENGE)) ||
394 ((vp->da->vendor == VENDORPEC_MICROSOFT) && (vp->da->attr == PW_MSCHAP_CHALLENGE))) {
395 uint8_t challenge[16];
397 if ((vp->length < 8) ||
399 RDEBUG("Tunneled challenge has invalid length");
405 eapttls_gen_challenge(ssl, challenge,
408 if (memcmp(challenge, vp->vp_octets,
410 RDEBUG("Tunneled challenge is incorrect");
420 fr_cursor_insert(&out, vp);
424 * Catch non-aligned attributes.
426 if (data_left == length) break;
429 * The length does NOT include the padding, so
430 * we've got to account for it here by rounding up
431 * to the nearest 4-byte boundary.
436 rad_assert(data_left >= length);
438 data += length - offset; /* already updated */
442 * We got this far. It looks OK.
448 * Convert VALUE_PAIR's to diameter attributes, and write them
451 * The ONLY VALUE_PAIR's which may be passed to this function
452 * are ones which can go inside of a RADIUS (i.e. diameter)
453 * packet. So no server-configuration attributes, or the like.
455 static int vp2diameter(REQUEST *request, tls_session_t *tls_session, VALUE_PAIR *first)
458 * RADIUS packets are no more than 4k in size, so if
459 * we've got more than 4k of data to write, it's very
462 uint8_t buffer[4096];
475 for (vp = fr_cursor_init(&cursor, &first); vp; vp = fr_cursor_next(&cursor)) {
477 * Too much data: die.
479 if ((total + vp->length + 12) >= sizeof(buffer)) {
480 RDEBUG2("output buffer is full!");
485 * Hmm... we don't group multiple EAP-Messages
486 * together. Maybe we should...
490 vendor = vp->da->vendor;
492 attr = vp->da->attr & 0xffff;
499 * Hmm... set the M bit for all attributes?
505 memcpy(p, &attr, sizeof(attr));
509 length += 8; /* includes 8 bytes of attr & length */
512 length += 4; /* include 4 bytes of vendor */
514 length = ntohl(length);
515 memcpy(p, &length, sizeof(length));
519 vendor = ntohl(vendor);
520 memcpy(p, &vendor, sizeof(vendor));
524 length = ntohl(length);
525 memcpy(p, &length, sizeof(length));
530 switch (vp->da->type) {
531 case PW_TYPE_INTEGER:
533 attr = htonl(vp->vp_integer); /* stored in host order */
534 memcpy(p, &attr, sizeof(attr));
538 case PW_TYPE_INTEGER64:
539 attr64 = htonll(vp->vp_integer64); /* stored in host order */
540 memcpy(p, &attr64, sizeof(attr64));
544 case PW_TYPE_IPV4_ADDR:
545 memcpy(p, &vp->vp_ipaddr, 4); /* network order */
552 memcpy(p, vp->vp_strvalue, vp->length);
558 * Skip to the end of the data.
564 * Align the data to a multiple of 4 bytes.
566 if ((total & 0x03) != 0) {
569 length = 4 - (total & 0x03);
570 for (i = 0; i < length; i++) {
576 } /* loop over the VP's to write. */
579 * Write the data in the buffer to the SSL session.
585 if ((debug_flag > 2) && fr_log_fp) {
586 for (i = 0; i < total; i++) {
587 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data out %04x: ", (int) i);
589 fprintf(fr_log_fp, "%02x ", buffer[i]);
591 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
593 if ((total & 0x0f) != 0) fprintf(fr_log_fp, "\n");
597 (tls_session->record_plus)(&tls_session->clean_in, buffer, total);
600 * FIXME: Check the return code.
602 tls_handshake_send(request, tls_session);
612 * Use a reply packet to determine what to do.
614 static rlm_rcode_t CC_HINT(nonnull) process_reply(UNUSED eap_handler_t *handler, tls_session_t *tls_session,
615 REQUEST *request, RADIUS_PACKET *reply)
617 rlm_rcode_t rcode = RLM_MODULE_REJECT;
619 ttls_tunnel_t *t = tls_session->opaque;
621 rad_assert(handler->request == request);
624 * If the response packet was Access-Accept, then
625 * we're OK. If not, die horribly.
627 * FIXME: Take MS-CHAP2-Success attribute, and
628 * tunnel it back to the client, to authenticate
629 * ourselves to the client.
631 * FIXME: If we have an Access-Challenge, then
632 * the Reply-Message is tunneled back to the client.
634 * FIXME: If we have an EAP-Message, then that message
635 * must be tunneled back to the client.
637 * FIXME: If we have an Access-Challenge with a State
638 * attribute, then do we tunnel that to the client, or
639 * keep track of it ourselves?
641 * FIXME: EAP-Messages can only start with 'identity',
642 * NOT 'eap start', so we should check for that....
644 switch (reply->code) {
645 case PW_CODE_AUTHENTICATION_ACK:
646 RDEBUG("Got tunneled Access-Accept");
648 rcode = RLM_MODULE_OK;
651 * MS-CHAP2-Success means that we do NOT return
652 * an Access-Accept, but instead tunnel that
653 * attribute to the client, and keep going with
654 * the TTLS session. Once the client accepts
655 * our identity, it will respond with an empty
656 * packet, and we will send EAP-Success.
659 pairfilter(tls_session, &vp, &reply->vps, PW_MSCHAP2_SUCCESS, VENDORPEC_MICROSOFT, TAG_ANY);
661 RDEBUG("Got MS-CHAP2-Success, tunneling it to the client in a challenge");
662 rcode = RLM_MODULE_HANDLED;
663 t->authenticated = true;
666 * Delete MPPE keys & encryption policy. We don't
669 pairdelete(&reply->vps, 7, VENDORPEC_MICROSOFT, TAG_ANY);
670 pairdelete(&reply->vps, 8, VENDORPEC_MICROSOFT, TAG_ANY);
671 pairdelete(&reply->vps, 16, VENDORPEC_MICROSOFT, TAG_ANY);
672 pairdelete(&reply->vps, 17, VENDORPEC_MICROSOFT, TAG_ANY);
675 * Use the tunneled reply, but not now.
677 if (t->use_tunneled_reply) {
678 rad_assert(!t->accept_vps);
679 pairfilter(t, &t->accept_vps, &reply->vps,
681 rad_assert(!reply->vps);
684 } else { /* no MS-CHAP2-Success */
686 * Can only have EAP-Message if there's
687 * no MS-CHAP2-Success. (FIXME: EAP-MSCHAP?)
689 * We also do NOT tunnel the EAP-Success
690 * attribute back to the client, as the client
691 * can figure it out, from the non-tunneled
692 * EAP-Success packet.
694 pairfilter(tls_session, &vp, &reply->vps, PW_EAP_MESSAGE, 0, TAG_ANY);
699 * Handle the ACK, by tunneling any necessary reply
700 * VP's back to the client.
703 vp2diameter(request, tls_session, vp);
708 * If we've been told to use the attributes from
709 * the reply, then do so.
711 * WARNING: This may leak information about the
714 if (t->use_tunneled_reply) {
715 pairdelete(&reply->vps, PW_PROXY_STATE, 0, TAG_ANY);
716 pairfilter(request->reply, &request->reply->vps,
717 &reply->vps, 0, 0, TAG_ANY);
722 case PW_CODE_AUTHENTICATION_REJECT:
723 RDEBUG("Got tunneled Access-Reject");
724 rcode = RLM_MODULE_REJECT;
728 * Handle Access-Challenge, but only if we
729 * send tunneled reply data. This is because
730 * an Access-Challenge means that we MUST tunnel
731 * a Reply-Message to the client.
733 case PW_CODE_ACCESS_CHALLENGE:
734 RDEBUG("Got tunneled Access-Challenge");
737 * Keep the State attribute, if necessary.
739 * Get rid of the old State, too.
742 pairfilter(t, &t->state, &reply->vps, PW_STATE, 0, TAG_ANY);
745 * We should really be a bit smarter about this,
746 * and move over only those attributes which
747 * are relevant to the authentication request,
748 * but that's a lot more work, and this "dumb"
749 * method works in 99.9% of the situations.
752 pairfilter(t, &vp, &reply->vps, PW_EAP_MESSAGE, 0, TAG_ANY);
755 * There MUST be a Reply-Message in the challenge,
756 * which we tunnel back to the client.
758 * If there isn't one in the reply VP's, then
759 * we MUST create one, with an empty string as
762 pairfilter(t, &vp, &reply->vps, PW_REPLY_MESSAGE, 0, TAG_ANY);
765 * Handle the ACK, by tunneling any necessary reply
766 * VP's back to the client.
769 vp2diameter(request, tls_session, vp);
772 rcode = RLM_MODULE_HANDLED;
776 RDEBUG("Unknown RADIUS packet type %d: rejecting tunneled user", reply->code);
777 rcode = RLM_MODULE_INVALID;
787 * Do post-proxy processing,
789 static int CC_HINT(nonnull) eapttls_postproxy(eap_handler_t *handler, void *data)
792 tls_session_t *tls_session = (tls_session_t *) data;
793 REQUEST *fake, *request = handler->request;
795 RDEBUG("Passing reply from proxy back into the tunnel");
798 * If there was a fake request associated with the proxied
799 * request, do more processing of it.
801 fake = (REQUEST *) request_data_get(handler->request,
802 handler->request->proxy,
803 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK);
806 * Do the callback, if it exists, and if it was a success.
808 if (fake && (handler->request->proxy_reply->code == PW_CODE_AUTHENTICATION_ACK)) {
812 rad_assert(!fake->packet);
813 fake->packet = talloc_steal(fake, request->proxy);
814 fake->packet->src_ipaddr = request->packet->src_ipaddr;
815 request->proxy = NULL;
817 rad_assert(!fake->reply);
818 fake->reply = talloc_steal(fake, request->proxy_reply);
819 request->proxy_reply = NULL;
821 if ((debug_flag > 0) && fr_log_fp) {
822 fprintf(fr_log_fp, "server %s {\n",
823 (!fake->server) ? "" : fake->server);
827 * Perform a post-auth stage for the tunneled
830 fake->log.lvl &= ~RAD_REQUEST_OPTION_PROXY_EAP;
831 rcode = rad_postauth(fake);
832 RDEBUG2("post-auth returns %d", rcode);
834 if ((debug_flag > 0) && fr_log_fp) {
835 fprintf(fr_log_fp, "} # server %s\n",
836 (!fake->server) ? "" : fake->server);
838 RDEBUG("Final reply from tunneled session code %d",
840 debug_pair_list(fake->reply->vps);
846 request->proxy = talloc_steal(request, fake->packet);
848 request->proxy_reply = talloc_steal(request, fake->reply);
852 * And we're done with this request.
856 case RLM_MODULE_FAIL:
858 eaptls_fail(handler, 0);
861 default: /* Don't Do Anything */
862 RDEBUG2("Got reply %d",
863 request->proxy_reply->code);
867 talloc_free(fake); /* robust if !fake */
870 * Process the reply from the home server.
872 rcode = process_reply(handler, tls_session, handler->request, handler->request->proxy_reply);
875 * The proxy code uses the reply from the home server as
876 * the basis for the reply to the NAS. We don't want that,
877 * so we toss it, after we've had our way with it.
879 pairfree(&handler->request->proxy_reply->vps);
882 case RLM_MODULE_REJECT:
883 RDEBUG("Reply was rejected");
886 case RLM_MODULE_HANDLED:
887 RDEBUG("Reply was handled");
888 eaptls_request(handler->eap_ds, tls_session);
889 request->proxy_reply->code = PW_CODE_ACCESS_CHALLENGE;
893 RDEBUG("Reply was OK");
896 * Success: Automatically return MPPE keys.
898 return eaptls_success(handler, 0);
901 RDEBUG("Reply was unknown");
905 eaptls_fail(handler, 0);
909 #endif /* WITH_PROXY */
912 * Process the "diameter" contents of the tunneled data.
914 int eapttls_process(eap_handler_t *handler, tls_session_t *tls_session)
916 int code = PW_CODE_AUTHENTICATION_REJECT;
923 REQUEST *request = handler->request;
926 * Just look at the buffer directly, without doing
929 data_len = tls_session->clean_out.used;
930 tls_session->clean_out.used = 0;
931 data = tls_session->clean_out.data;
933 t = (ttls_tunnel_t *) tls_session->opaque;
936 * If there's no data, maybe this is an ACK to an
940 if (t->authenticated) {
941 RDEBUG("Got ACK, and the user was already authenticated");
942 return PW_CODE_AUTHENTICATION_ACK;
943 } /* else no session, no data, die. */
946 * FIXME: Call SSL_get_error() to see what went
949 RDEBUG2("SSL_read Error");
950 return PW_CODE_AUTHENTICATION_REJECT;
954 if ((debug_flag > 2) && fr_log_fp) {
957 for (i = 0; i < data_len; i++) {
958 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data in %04x: ", (int) i);
960 fprintf(fr_log_fp, "%02x ", data[i]);
962 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
964 if ((data_len & 0x0f) != 0) fprintf(fr_log_fp, "\n");
968 if (!diameter_verify(request, data, data_len)) {
969 return PW_CODE_AUTHENTICATION_REJECT;
973 * Allocate a fake REQUEST structe.
975 fake = request_alloc_fake(request);
977 rad_assert(!fake->packet->vps);
980 * Add the tunneled attributes to the fake request.
982 fake->packet->vps = diameter2vp(request, fake, tls_session->ssl, data, data_len);
983 if (!fake->packet->vps) {
985 return PW_CODE_AUTHENTICATION_REJECT;
989 * Tell the request that it's a fake one.
991 pairmake_packet("Freeradius-Proxied-To", "127.0.0.1", T_OP_EQ);
993 if ((debug_flag > 0) && fr_log_fp) {
994 RDEBUG("Got tunneled request");
996 debug_pair_list(fake->packet->vps);
1000 * Update other items in the REQUEST data structure.
1002 fake->username = pairfind(fake->packet->vps, PW_USER_NAME, 0, TAG_ANY);
1003 fake->password = pairfind(fake->packet->vps, PW_USER_PASSWORD, 0, TAG_ANY);
1006 * No User-Name, try to create one from stored data.
1008 if (!fake->username) {
1010 * No User-Name in the stored data, look for
1011 * an EAP-Identity, and pull it out of there.
1014 vp = pairfind(fake->packet->vps, PW_EAP_MESSAGE, 0, TAG_ANY);
1016 (vp->length >= EAP_HEADER_LEN + 2) &&
1017 (vp->vp_strvalue[0] == PW_EAP_RESPONSE) &&
1018 (vp->vp_strvalue[EAP_HEADER_LEN] == PW_EAP_IDENTITY) &&
1019 (vp->vp_strvalue[EAP_HEADER_LEN + 1] != 0)) {
1023 * Create & remember a User-Name
1025 t->username = pairmake(t, NULL, "User-Name", NULL, T_OP_EQ);
1026 rad_assert(t->username != NULL);
1027 t->username->length = vp->length - 5;
1029 t->username->vp_strvalue = p = talloc_array(t->username, char,
1030 t->username->length + 1);
1031 memcpy(p, vp->vp_octets + 5, t->username->length);
1032 p[t->username->length] = 0;
1034 RDEBUG("Got tunneled identity of %s",
1035 t->username->vp_strvalue);
1038 * If there's a default EAP type,
1041 if (t->default_method != 0) {
1042 RDEBUG("Setting default EAP type for tunneled EAP session");
1043 vp = paircreate(fake, PW_EAP_TYPE, 0);
1044 rad_assert(vp != NULL);
1045 vp->vp_integer = t->default_method;
1046 pairadd(&fake->config_items, vp);
1051 * Don't reject the request outright,
1052 * as it's permitted to do EAP without
1055 RWDEBUG2("No EAP-Identity found to start EAP conversation");
1057 } /* else there WAS a t->username */
1060 vp = paircopy(fake->packet, t->username);
1061 pairadd(&fake->packet->vps, vp);
1062 fake->username = pairfind(fake->packet->vps, PW_USER_NAME, 0, TAG_ANY);
1064 } /* else the request ALREADY had a User-Name */
1067 * Add the State attribute, too, if it exists.
1070 vp = paircopy(fake->packet, t->state);
1071 if (vp) pairadd(&fake->packet->vps, vp);
1075 * If this is set, we copy SOME of the request attributes
1076 * from outside of the tunnel to inside of the tunnel.
1078 * We copy ONLY those attributes which do NOT already
1079 * exist in the tunneled request.
1081 if (t->copy_request_to_tunnel) {
1085 for (vp = fr_cursor_init(&cursor, &request->packet->vps); vp; vp = fr_cursor_next(&cursor)) {
1087 * The attribute is a server-side thingy,
1090 if ((vp->da->attr > 255) &&
1091 (vp->da->vendor == 0)) {
1096 * The outside attribute is already in the
1097 * tunnel, don't copy it.
1099 * This works for BOTH attributes which
1100 * are originally in the tunneled request,
1101 * AND attributes which are copied there
1104 if (pairfind(fake->packet->vps, vp->da->attr, vp->da->vendor, TAG_ANY)) {
1109 * Some attributes are handled specially.
1111 switch (vp->da->attr) {
1113 * NEVER copy Message-Authenticator,
1114 * EAP-Message, or State. They're
1115 * only for outside of the tunnel.
1118 case PW_USER_PASSWORD:
1119 case PW_CHAP_PASSWORD:
1120 case PW_CHAP_CHALLENGE:
1121 case PW_PROXY_STATE:
1122 case PW_MESSAGE_AUTHENTICATOR:
1123 case PW_EAP_MESSAGE:
1129 * By default, copy it over.
1136 * Don't copy from the head, we've already
1139 copy = paircopy2(fake->packet, vp, vp->da->attr, vp->da->vendor, TAG_ANY);
1140 pairadd(&fake->packet->vps, copy);
1144 if ((vp = pairfind(request->config_items, PW_VIRTUAL_SERVER, 0, TAG_ANY)) != NULL) {
1145 fake->server = vp->vp_strvalue;
1147 } else if (t->virtual_server) {
1148 fake->server = t->virtual_server;
1150 } /* else fake->server == request->server */
1153 if ((debug_flag > 0) && fr_log_fp) {
1154 RDEBUG("Sending tunneled request");
1156 debug_pair_list(fake->packet->vps);
1158 fprintf(fr_log_fp, "server %s {\n",
1159 (!fake->server) ? "" : fake->server);
1163 * Call authentication recursively, which will
1164 * do PAP, CHAP, MS-CHAP, etc.
1166 rad_virtual_server(fake);
1169 * Note that we don't do *anything* with the reply
1172 if ((debug_flag > 0) && fr_log_fp) {
1173 fprintf(fr_log_fp, "} # server %s\n",
1174 (!fake->server) ? "" : fake->server);
1176 RDEBUG("Got tunneled reply code %d", fake->reply->code);
1178 debug_pair_list(fake->reply->vps);
1182 * Decide what to do with the reply.
1184 switch (fake->reply->code) {
1185 case 0: /* No reply code, must be proxied... */
1187 vp = pairfind(fake->config_items, PW_PROXY_TO_REALM, 0, TAG_ANY);
1189 eap_tunnel_data_t *tunnel;
1190 RDEBUG("Tunneled authentication will be proxied to %s", vp->vp_strvalue);
1193 * Tell the original request that it's going
1196 pairfilter(request, &(request->config_items),
1197 &(fake->config_items),
1198 PW_PROXY_TO_REALM, 0, TAG_ANY);
1201 * Seed the proxy packet with the
1204 rad_assert(!request->proxy);
1205 request->proxy = talloc_steal(request, fake->packet);
1206 memset(&request->proxy->src_ipaddr, 0,
1207 sizeof(request->proxy->src_ipaddr));
1208 memset(&request->proxy->src_ipaddr, 0,
1209 sizeof(request->proxy->src_ipaddr));
1210 request->proxy->src_port = 0;
1211 request->proxy->dst_port = 0;
1212 fake->packet = NULL;
1213 rad_free(&fake->reply);
1217 * Set up the callbacks for the tunnel
1219 tunnel = talloc_zero(request, eap_tunnel_data_t);
1220 tunnel->tls_session = tls_session;
1221 tunnel->callback = eapttls_postproxy;
1224 * Associate the callback with the request.
1226 code = request_data_add(request, request->proxy, REQUEST_DATA_EAP_TUNNEL_CALLBACK,
1228 rad_assert(code == 0);
1231 * rlm_eap.c has taken care of associating
1232 * the handler with the fake request.
1234 * So we associate the fake request with
1237 talloc_set_destructor(fake, request_opaque_free);
1238 code = request_data_add(request, request->proxy, REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK,
1240 rad_assert(code == 0);
1244 * Didn't authenticate the packet, but
1245 * we're proxying it.
1247 code = PW_CODE_STATUS_CLIENT;
1250 #endif /* WITH_PROXY */
1252 RDEBUG("No tunneled reply was found for request %d , and the request was not proxied: rejecting the user.",
1254 code = PW_CODE_AUTHENTICATION_REJECT;
1260 * Returns RLM_MODULE_FOO, and we want to return PW_FOO
1262 rcode = process_reply(handler, tls_session, request, fake->reply);
1264 case RLM_MODULE_REJECT:
1265 code = PW_CODE_AUTHENTICATION_REJECT;
1268 case RLM_MODULE_HANDLED:
1269 code = PW_CODE_ACCESS_CHALLENGE;
1273 code = PW_CODE_AUTHENTICATION_ACK;
1277 code = PW_CODE_AUTHENTICATION_REJECT;