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
24 #include <freeradius-devel/ident.h>
31 * 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
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * |V M r r r r r r| AVP Length |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * Verify that the diameter packet is valid.
46 static int diameter_verify(REQUEST *request,
47 const uint8_t *data, unsigned int data_len)
52 unsigned int remaining = data_len;
54 while (remaining > 0) {
57 if (remaining < hdr_len) {
58 RDEBUG2(" Diameter attribute is too small (%u) to contain a Diameter header", remaining);
62 memcpy(&attr, data, sizeof(attr));
64 memcpy(&length, data + 4, sizeof(length));
65 length = ntohl(length);
67 if ((data[4] & 0x80) != 0) {
69 RDEBUG2(" Diameter attribute is too small to contain a Diameter header with Vendor-Id");
77 * Get the length. If it's too big, die.
82 * Too short or too long is bad.
84 if (length <= (hdr_len - 4)) {
85 RDEBUG2("Tunneled attribute %u is too short (%u < %u) to contain anything useful.", attr, length, hdr_len);
89 if (length > remaining) {
90 RDEBUG2("Tunneled attribute %u is longer than room remaining in the packet (%u > %u).", attr, length, remaining);
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 RDEBUG2("ERROR! 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, SSL *ssl,
138 const uint8_t *data, size_t data_len)
145 size_t data_left = data_len;
146 VALUE_PAIR *first = NULL;
147 VALUE_PAIR **last = &first;
150 while (data_left > 0) {
151 rad_assert(data_left <= data_len);
152 memcpy(&attr, data, sizeof(attr));
157 memcpy(&length, data, sizeof(length));
159 length = ntohl(length);
162 * A "vendor" flag, with a vendor ID of zero,
163 * is equivalent to no vendor. This is stupid.
166 if ((length & (1 << 31)) != 0) {
167 memcpy(&vendor, data, sizeof(vendor));
168 vendor = ntohl(vendor);
170 data += 4; /* skip the vendor field, it's zero */
171 offset += 4; /* offset to value field */
173 if (attr > 65535) goto next_attr;
174 if (vendor > FR_MAX_VENDOR) goto next_attr;
178 * FIXME: Handle the M bit. For now, we assume that
179 * some other module takes care of any attribute
180 * with the M bit set.
186 length &= 0x00ffffff;
189 * Get the size of the value portion of the
192 size = length - offset;
195 * Vendor attributes can be larger than 255.
196 * Normal attributes cannot be.
198 if ((attr > 255) && (vendor == 0)) {
199 RDEBUG2("WARNING: Skipping Diameter attribute %u",
205 RDEBUG2("WARNING: diameter2vp skipping long attribute %u, attr");
210 * RADIUS VSAs are handled as Diameter attributes
211 * with Vendor-Id == 0, and the VSA data packed
212 * into the "String" field as per normal.
214 * EXCEPT for the MS-CHAP attributes.
216 if ((vendor == 0) && (attr == PW_VENDOR_SPECIFIC)) {
220 buffer[0] = PW_VENDOR_SPECIFIC;
221 buffer[1] = size + 2;
222 memcpy(buffer + 2, data, size);
225 decoded = rad_attr2vp_vsa(NULL, NULL, NULL,
226 buffer, size + 2, &vp);
228 RDEBUG2("ERROR: diameter2vp failed decoding attr: %s",
233 if ((size_t) decoded != size + 2) {
234 RDEBUG2("ERROR: diameter2vp failed to entirely decode VSA");
243 } while (vp != NULL);
249 * Create it. If this fails, it's because we're OOM.
252 vp = paircreate(attr, vendor, PW_TYPE_OCTETS);
254 RDEBUG2("Failure in creating VP");
260 * If it's a type from our dictionary, then
261 * we need to put the data in a relevant place.
264 case PW_TYPE_INTEGER:
266 if (size != vp->length) {
268 * Bad format. Create a "raw"
272 vp = paircreate_raw(vp->attribute, vp->vendor,
275 memcpy(vp->vp_octets, data, vp->length);
278 memcpy(&vp->vp_integer, data, vp->length);
281 * Stored in host byte order: change it.
283 vp->vp_integer = ntohl(vp->vp_integer);
286 case PW_TYPE_INTEGER64:
287 if (size != vp->length) goto raw;
288 memcpy(&vp->vp_integer64, data, vp->length);
291 * Stored in host byte order: change it.
293 vp->vp_integer64 = ntohll(vp->vp_integer64);
297 if (size != vp->length) {
298 RDEBUG2("Invalid length attribute %d",
304 memcpy(&vp->vp_ipaddr, data, vp->length);
307 * Stored in network byte order: don't change it.
312 if (size != vp->length) goto raw;
313 vp->vp_integer = data[0];
317 if (size != vp->length) goto raw;
318 vp->vp_integer = (data[0] * 256) + data[1];
322 if (size != vp->length) goto raw;
323 memcpy(&vp->vp_signed, data, vp->length);
324 vp->vp_signed = ntohl(vp->vp_signed);
327 case PW_TYPE_IPV6ADDR:
328 if (size != vp->length) goto raw;
329 memcpy(&vp->vp_ipv6addr, data, vp->length);
332 case PW_TYPE_IPV6PREFIX:
333 if (size != vp->length) goto raw;
334 memcpy(&vp->vp_ipv6prefix, data, vp->length);
338 * String, octet, etc. Copy the data from the
339 * value field over verbatim.
342 if (attr == PW_EAP_MESSAGE) {
343 const uint8_t *eap_message = data;
346 * vp exists the first time around.
350 if (vp->length > 253) vp->length = 253;
351 memcpy(vp->vp_octets, eap_message,
355 eap_message += vp->length;
360 if (size == 0) break;
362 vp = paircreate(attr, vendor, PW_TYPE_OCTETS);
364 RDEBUG2("Failure in creating VP");
371 } /* else it's another kind of attribute */
376 memcpy(vp->vp_strvalue, data, vp->length);
381 * User-Password is NUL padded to a multiple
382 * of 16 bytes. Let's chop it to something
385 * NOTE: This means that the User-Password
386 * attribute CANNOT EVER have embedded zeros in it!
388 if ((vp->vendor == 0) && (vp->attribute == PW_USER_PASSWORD)) {
390 * If the password is exactly 16 octets,
391 * it won't be zero-terminated.
393 vp->vp_strvalue[vp->length] = '\0';
394 vp->length = strlen(vp->vp_strvalue);
398 * Ensure that the client is using the
399 * correct challenge. This weirdness is
400 * to protect against against replay
401 * attacks, where anyone observing the
402 * CHAP exchange could pose as that user,
403 * by simply choosing to use the same
406 * By using a challenge based on
407 * information from the current session,
408 * we can guarantee that the client is
409 * not *choosing* a challenge.
411 * We're a little forgiving in that we
412 * have loose checks on the length, and
413 * we do NOT check the Id (first octet of
414 * the response to the challenge)
416 * But if the client gets the challenge correct,
417 * we're not too worried about the Id.
419 if (((vp->vendor == 0) && (vp->attribute == PW_CHAP_CHALLENGE)) ||
420 ((vp->vendor == VENDORPEC_MICROSOFT) && (vp->attribute == PW_MSCHAP_CHALLENGE))) {
421 uint8_t challenge[16];
423 if ((vp->length < 8) ||
425 RDEBUG("Tunneled challenge has invalid length");
431 eapttls_gen_challenge(ssl, challenge,
434 if (memcmp(challenge, vp->vp_octets,
436 RDEBUG("Tunneled challenge is incorrect");
451 * Catch non-aligned attributes.
453 if (data_left == length) break;
456 * The length does NOT include the padding, so
457 * we've got to account for it here by rounding up
458 * to the nearest 4-byte boundary.
463 rad_assert(data_left >= length);
465 data += length - offset; /* already updated */
469 * We got this far. It looks OK.
475 * Convert VALUE_PAIR's to diameter attributes, and write them
478 * The ONLY VALUE_PAIR's which may be passed to this function
479 * are ones which can go inside of a RADIUS (i.e. diameter)
480 * packet. So no server-configuration attributes, or the like.
482 static int vp2diameter(REQUEST *request, tls_session_t *tls_session, VALUE_PAIR *first)
485 * RADIUS packets are no more than 4k in size, so if
486 * we've got more than 4k of data to write, it's very
489 uint8_t buffer[4096];
501 for (vp = first; vp != NULL; vp = vp->next) {
503 * Too much data: die.
505 if ((total + vp->length + 12) >= sizeof(buffer)) {
506 RDEBUG2("output buffer is full!");
511 * Hmm... we don't group multiple EAP-Messages
512 * together. Maybe we should...
516 * Length is no more than 253, due to RADIUS
522 attr = vp->attribute & 0xffff;
525 attr = vp->attribute;
529 * Hmm... set the M bit for all attributes?
535 memcpy(p, &attr, sizeof(attr));
539 length += 8; /* includes 8 bytes of attr & length */
542 length += 4; /* include 4 bytes of vendor */
544 length = ntohl(length);
545 memcpy(p, &length, sizeof(length));
549 vendor = ntohl(vendor);
550 memcpy(p, &vendor, sizeof(vendor));
554 length = ntohl(length);
555 memcpy(p, &length, sizeof(length));
561 case PW_TYPE_INTEGER:
563 attr = htonl(vp->vp_integer); /* stored in host order */
564 memcpy(p, &attr, sizeof(attr));
568 case PW_TYPE_INTEGER64:
569 attr64 = htonll(vp->vp_integer64); /* stored in host order */
570 memcpy(p, &attr64, sizeof(attr64));
575 memcpy(p, &vp->vp_ipaddr, 4); /* network order */
582 memcpy(p, vp->vp_strvalue, vp->length);
588 * Skip to the end of the data.
594 * Align the data to a multiple of 4 bytes.
596 if ((total & 0x03) != 0) {
599 length = 4 - (total & 0x03);
600 for (i = 0; i < length; i++) {
606 } /* loop over the VP's to write. */
609 * Write the data in the buffer to the SSL session.
615 if ((debug_flag > 2) && fr_log_fp) {
616 for (i = 0; i < total; i++) {
617 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data out %04x: ", (int) i);
619 fprintf(fr_log_fp, "%02x ", buffer[i]);
621 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
623 if ((total & 0x0f) != 0) fprintf(fr_log_fp, "\n");
627 (tls_session->record_plus)(&tls_session->clean_in, buffer, total);
630 * FIXME: Check the return code.
632 tls_handshake_send(request, tls_session);
642 * Use a reply packet to determine what to do.
644 static int process_reply(EAP_HANDLER *handler, tls_session_t *tls_session,
645 REQUEST *request, RADIUS_PACKET *reply)
647 int rcode = RLM_MODULE_REJECT;
649 ttls_tunnel_t *t = tls_session->opaque;
651 handler = handler; /* -Wunused */
652 rad_assert(request != NULL);
653 rad_assert(handler->request == request);
656 * If the response packet was Access-Accept, then
657 * we're OK. If not, die horribly.
659 * FIXME: Take MS-CHAP2-Success attribute, and
660 * tunnel it back to the client, to authenticate
661 * ourselves to the client.
663 * FIXME: If we have an Access-Challenge, then
664 * the Reply-Message is tunneled back to the client.
666 * FIXME: If we have an EAP-Message, then that message
667 * must be tunneled back to the client.
669 * FIXME: If we have an Access-Challenge with a State
670 * attribute, then do we tunnel that to the client, or
671 * keep track of it ourselves?
673 * FIXME: EAP-Messages can only start with 'identity',
674 * NOT 'eap start', so we should check for that....
676 switch (reply->code) {
677 case PW_AUTHENTICATION_ACK:
678 RDEBUG("Got tunneled Access-Accept");
680 rcode = RLM_MODULE_OK;
683 * MS-CHAP2-Success means that we do NOT return
684 * an Access-Accept, but instead tunnel that
685 * attribute to the client, and keep going with
686 * the TTLS session. Once the client accepts
687 * our identity, it will respond with an empty
688 * packet, and we will send EAP-Success.
691 pairmove2(&vp, &reply->vps, PW_MSCHAP2_SUCCESS, VENDORPEC_MICROSOFT);
693 RDEBUG("Got MS-CHAP2-Success, tunneling it to the client in a challenge.");
694 rcode = RLM_MODULE_HANDLED;
695 t->authenticated = TRUE;
698 * Delete MPPE keys & encryption policy. We don't
701 pairdelete(&reply->vps, 7, VENDORPEC_MICROSOFT);
702 pairdelete(&reply->vps, 8, VENDORPEC_MICROSOFT);
703 pairdelete(&reply->vps, 16, VENDORPEC_MICROSOFT);
704 pairdelete(&reply->vps, 17, VENDORPEC_MICROSOFT);
707 * Use the tunneled reply, but not now.
709 if (t->use_tunneled_reply) {
710 t->accept_vps = reply->vps;
714 } else { /* no MS-CHAP2-Success */
716 * Can only have EAP-Message if there's
717 * no MS-CHAP2-Success. (FIXME: EAP-MSCHAP?)
719 * We also do NOT tunnel the EAP-Success
720 * attribute back to the client, as the client
721 * can figure it out, from the non-tunneled
722 * EAP-Success packet.
724 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE, 0);
729 * Handle the ACK, by tunneling any necessary reply
730 * VP's back to the client.
733 vp2diameter(request, tls_session, vp);
738 * If we've been told to use the attributes from
739 * the reply, then do so.
741 * WARNING: This may leak information about the
744 if (t->use_tunneled_reply) {
745 pairdelete(&reply->vps, PW_PROXY_STATE, 0);
746 pairadd(&request->reply->vps, reply->vps);
752 case PW_AUTHENTICATION_REJECT:
753 RDEBUG("Got tunneled Access-Reject");
754 rcode = RLM_MODULE_REJECT;
758 * Handle Access-Challenge, but only if we
759 * send tunneled reply data. This is because
760 * an Access-Challenge means that we MUST tunnel
761 * a Reply-Message to the client.
763 case PW_ACCESS_CHALLENGE:
764 RDEBUG("Got tunneled Access-Challenge");
767 * Keep the State attribute, if necessary.
769 * Get rid of the old State, too.
772 pairmove2(&t->state, &reply->vps, PW_STATE, 0);
775 * We should really be a bit smarter about this,
776 * and move over only those attributes which
777 * are relevant to the authentication request,
778 * but that's a lot more work, and this "dumb"
779 * method works in 99.9% of the situations.
782 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE, 0);
785 * There MUST be a Reply-Message in the challenge,
786 * which we tunnel back to the client.
788 * If there isn't one in the reply VP's, then
789 * we MUST create one, with an empty string as
792 pairmove2(&vp, &reply->vps, PW_REPLY_MESSAGE, 0);
795 * Handle the ACK, by tunneling any necessary reply
796 * VP's back to the client.
799 vp2diameter(request, tls_session, vp);
802 rcode = RLM_MODULE_HANDLED;
806 RDEBUG("Unknown RADIUS packet type %d: rejecting tunneled user", reply->code);
807 rcode = RLM_MODULE_INVALID;
817 * Do post-proxy processing,
819 static int eapttls_postproxy(EAP_HANDLER *handler, void *data)
822 tls_session_t *tls_session = (tls_session_t *) data;
823 REQUEST *fake, *request = handler->request;
825 rad_assert(request != NULL);
826 RDEBUG("Passing reply from proxy back into the tunnel.");
829 * If there was a fake request associated with the proxied
830 * request, do more processing of it.
832 fake = (REQUEST *) request_data_get(handler->request,
833 handler->request->proxy,
834 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK);
837 * Do the callback, if it exists, and if it was a success.
840 handler->request->proxy_reply &&
841 (handler->request->proxy_reply->code == PW_AUTHENTICATION_ACK)) {
845 rad_assert(fake->packet == NULL);
846 fake->packet = request->proxy;
847 fake->packet->src_ipaddr = request->packet->src_ipaddr;
848 request->proxy = NULL;
850 rad_assert(fake->reply == NULL);
851 fake->reply = request->proxy_reply;
852 request->proxy_reply = NULL;
854 if ((debug_flag > 0) && fr_log_fp) {
855 fprintf(fr_log_fp, "server %s {\n",
856 (fake->server == NULL) ? "" : fake->server);
860 * Perform a post-auth stage for the tunneled
863 fake->options &= ~RAD_REQUEST_OPTION_PROXY_EAP;
864 rcode = rad_postauth(fake);
865 RDEBUG2("post-auth returns %d", rcode);
867 if ((debug_flag > 0) && fr_log_fp) {
868 fprintf(fr_log_fp, "} # server %s\n",
869 (fake->server == NULL) ? "" : fake->server);
871 RDEBUG("Final reply from tunneled session code %d",
873 debug_pair_list(fake->reply->vps);
879 request->proxy = fake->packet;
881 request->proxy_reply = fake->reply;
885 * And we're done with this request.
889 case RLM_MODULE_FAIL:
891 eaptls_fail(handler, 0);
895 default: /* Don't Do Anything */
896 RDEBUG2("Got reply %d",
897 request->proxy_reply->code);
901 request_free(&fake); /* robust if fake == NULL */
904 * Process the reply from the home server.
906 rcode = process_reply(handler, tls_session, handler->request,
907 handler->request->proxy_reply);
910 * The proxy code uses the reply from the home server as
911 * the basis for the reply to the NAS. We don't want that,
912 * so we toss it, after we've had our way with it.
914 pairfree(&handler->request->proxy_reply->vps);
917 case RLM_MODULE_REJECT:
918 RDEBUG("Reply was rejected");
921 case RLM_MODULE_HANDLED:
922 RDEBUG("Reply was handled");
923 eaptls_request(handler->eap_ds, tls_session);
927 RDEBUG("Reply was OK");
930 * Success: Automatically return MPPE keys.
932 return eaptls_success(handler, 0);
935 RDEBUG("Reply was unknown.");
939 eaptls_fail(handler, 0);
947 static void my_request_free(void *data)
949 REQUEST *request = (REQUEST *)data;
951 request_free(&request);
953 #endif /* WITH_PROXY */
956 * Process the "diameter" contents of the tunneled data.
958 int eapttls_process(EAP_HANDLER *handler, tls_session_t *tls_session)
960 int rcode = PW_AUTHENTICATION_REJECT;
966 REQUEST *request = handler->request;
968 rad_assert(request != NULL);
971 * Just look at the buffer directly, without doing
974 data_len = tls_session->clean_out.used;
975 tls_session->clean_out.used = 0;
976 data = tls_session->clean_out.data;
978 t = (ttls_tunnel_t *) tls_session->opaque;
981 * If there's no data, maybe this is an ACK to an
985 if (t->authenticated) {
986 RDEBUG("Got ACK, and the user was already authenticated.");
987 return PW_AUTHENTICATION_ACK;
988 } /* else no session, no data, die. */
991 * FIXME: Call SSL_get_error() to see what went
994 RDEBUG2("SSL_read Error");
995 return PW_AUTHENTICATION_REJECT;
999 if ((debug_flag > 2) && fr_log_fp) {
1002 for (i = 0; i < data_len; i++) {
1003 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data in %04x: ", (int) i);
1005 fprintf(fr_log_fp, "%02x ", data[i]);
1007 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
1009 if ((data_len & 0x0f) != 0) fprintf(fr_log_fp, "\n");
1013 if (!diameter_verify(request, data, data_len)) {
1014 return PW_AUTHENTICATION_REJECT;
1018 * Allocate a fake REQUEST structe.
1020 fake = request_alloc_fake(request);
1022 rad_assert(fake->packet->vps == NULL);
1025 * Add the tunneled attributes to the fake request.
1027 fake->packet->vps = diameter2vp(request, tls_session->ssl, data, data_len);
1028 if (!fake->packet->vps) {
1029 request_free(&fake);
1030 return PW_AUTHENTICATION_REJECT;
1034 * Tell the request that it's a fake one.
1036 vp = pairmake("Freeradius-Proxied-To", "127.0.0.1", T_OP_EQ);
1038 pairadd(&fake->packet->vps, vp);
1041 if ((debug_flag > 0) && fr_log_fp) {
1042 RDEBUG("Got tunneled request");
1044 debug_pair_list(fake->packet->vps);
1048 * Update other items in the REQUEST data structure.
1050 fake->username = pairfind(fake->packet->vps, PW_USER_NAME, 0);
1051 fake->password = pairfind(fake->packet->vps, PW_USER_PASSWORD, 0);
1054 * No User-Name, try to create one from stored data.
1056 if (!fake->username) {
1058 * No User-Name in the stored data, look for
1059 * an EAP-Identity, and pull it out of there.
1062 vp = pairfind(fake->packet->vps, PW_EAP_MESSAGE, 0);
1064 (vp->length >= EAP_HEADER_LEN + 2) &&
1065 (vp->vp_strvalue[0] == PW_EAP_RESPONSE) &&
1066 (vp->vp_strvalue[EAP_HEADER_LEN] == PW_EAP_IDENTITY) &&
1067 (vp->vp_strvalue[EAP_HEADER_LEN + 1] != 0)) {
1069 * Create & remember a User-Name
1071 t->username = pairmake("User-Name", "", T_OP_EQ);
1072 rad_assert(t->username != NULL);
1074 memcpy(t->username->vp_strvalue, vp->vp_strvalue + 5,
1076 t->username->length = vp->length - 5;
1077 t->username->vp_strvalue[t->username->length] = 0;
1079 RDEBUG("Got tunneled identity of %s",
1080 t->username->vp_strvalue);
1083 * If there's a default EAP type,
1086 if (t->default_eap_type != 0) {
1087 RDEBUG("Setting default EAP type for tunneled EAP session.");
1088 vp = paircreate(PW_EAP_TYPE, 0,
1090 rad_assert(vp != NULL);
1091 vp->vp_integer = t->default_eap_type;
1092 pairadd(&fake->config_items, vp);
1097 * Don't reject the request outright,
1098 * as it's permitted to do EAP without
1101 RDEBUG2("WARNING! No EAP-Identity found to start EAP conversation.");
1103 } /* else there WAS a t->username */
1106 vp = paircopy(t->username);
1107 pairadd(&fake->packet->vps, vp);
1108 fake->username = pairfind(fake->packet->vps, PW_USER_NAME, 0);
1110 } /* else the request ALREADY had a User-Name */
1113 * Add the State attribute, too, if it exists.
1116 vp = paircopy(t->state);
1117 if (vp) pairadd(&fake->packet->vps, vp);
1121 * If this is set, we copy SOME of the request attributes
1122 * from outside of the tunnel to inside of the tunnel.
1124 * We copy ONLY those attributes which do NOT already
1125 * exist in the tunneled request.
1127 if (t->copy_request_to_tunnel) {
1130 for (vp = request->packet->vps; vp != NULL; vp = vp->next) {
1132 * The attribute is a server-side thingy,
1135 if ((vp->attribute > 255) &&
1136 (vp->vendor == 0)) {
1141 * The outside attribute is already in the
1142 * tunnel, don't copy it.
1144 * This works for BOTH attributes which
1145 * are originally in the tunneled request,
1146 * AND attributes which are copied there
1149 if (pairfind(fake->packet->vps, vp->attribute, vp->vendor)) {
1154 * Some attributes are handled specially.
1156 switch (vp->attribute) {
1158 * NEVER copy Message-Authenticator,
1159 * EAP-Message, or State. They're
1160 * only for outside of the tunnel.
1163 case PW_USER_PASSWORD:
1164 case PW_CHAP_PASSWORD:
1165 case PW_CHAP_CHALLENGE:
1166 case PW_PROXY_STATE:
1167 case PW_MESSAGE_AUTHENTICATOR:
1168 case PW_EAP_MESSAGE:
1174 * By default, copy it over.
1181 * Don't copy from the head, we've already
1184 copy = paircopy2(vp, vp->attribute, vp->vendor);
1185 pairadd(&fake->packet->vps, copy);
1189 if ((vp = pairfind(request->config_items, PW_VIRTUAL_SERVER, 0)) != NULL) {
1190 fake->server = vp->vp_strvalue;
1192 } else if (t->virtual_server) {
1193 fake->server = t->virtual_server;
1195 } /* else fake->server == request->server */
1198 if ((debug_flag > 0) && fr_log_fp) {
1199 RDEBUG("Sending tunneled request");
1201 debug_pair_list(fake->packet->vps);
1203 fprintf(fr_log_fp, "server %s {\n",
1204 (fake->server == NULL) ? "" : fake->server);
1208 * Call authentication recursively, which will
1209 * do PAP, CHAP, MS-CHAP, etc.
1211 rad_virtual_server(fake);
1214 * Note that we don't do *anything* with the reply
1217 if ((debug_flag > 0) && fr_log_fp) {
1218 fprintf(fr_log_fp, "} # server %s\n",
1219 (fake->server == NULL) ? "" : fake->server);
1221 RDEBUG("Got tunneled reply code %d", fake->reply->code);
1223 debug_pair_list(fake->reply->vps);
1227 * Decide what to do with the reply.
1229 switch (fake->reply->code) {
1230 case 0: /* No reply code, must be proxied... */
1232 vp = pairfind(fake->config_items, PW_PROXY_TO_REALM, 0);
1234 eap_tunnel_data_t *tunnel;
1235 RDEBUG("Tunneled authentication will be proxied to %s", vp->vp_strvalue);
1238 * Tell the original request that it's going
1241 pairmove2(&(request->config_items),
1242 &(fake->config_items),
1243 PW_PROXY_TO_REALM, 0);
1246 * Seed the proxy packet with the
1249 rad_assert(request->proxy == NULL);
1250 request->proxy = fake->packet;
1251 memset(&request->proxy->src_ipaddr, 0,
1252 sizeof(request->proxy->src_ipaddr));
1253 memset(&request->proxy->src_ipaddr, 0,
1254 sizeof(request->proxy->src_ipaddr));
1255 request->proxy->src_port = 0;
1256 request->proxy->dst_port = 0;
1257 fake->packet = NULL;
1258 rad_free(&fake->reply);
1262 * Set up the callbacks for the tunnel
1264 tunnel = rad_malloc(sizeof(*tunnel));
1265 memset(tunnel, 0, sizeof(*tunnel));
1267 tunnel->tls_session = tls_session;
1268 tunnel->callback = eapttls_postproxy;
1271 * Associate the callback with the request.
1273 rcode = request_data_add(request,
1275 REQUEST_DATA_EAP_TUNNEL_CALLBACK,
1277 rad_assert(rcode == 0);
1280 * rlm_eap.c has taken care of associating
1281 * the handler with the fake request.
1283 * So we associate the fake request with
1286 rcode = request_data_add(request,
1288 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK,
1289 fake, my_request_free);
1290 rad_assert(rcode == 0);
1294 * Didn't authenticate the packet, but
1295 * we're proxying it.
1297 rcode = PW_STATUS_CLIENT;
1300 #endif /* WITH_PROXY */
1302 RDEBUG("No tunneled reply was found for request %d , and the request was not proxied: rejecting the user.",
1304 rcode = PW_AUTHENTICATION_REJECT;
1310 * Returns RLM_MODULE_FOO, and we want to return
1313 rcode = process_reply(handler, tls_session, request,
1316 case RLM_MODULE_REJECT:
1317 rcode = PW_AUTHENTICATION_REJECT;
1320 case RLM_MODULE_HANDLED:
1321 rcode = PW_ACCESS_CHALLENGE;
1325 rcode = PW_AUTHENTICATION_ACK;
1329 rcode = PW_AUTHENTICATION_REJECT;
1335 request_free(&fake);