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 data_left = data_len;
54 while (data_left > 0) {
56 RDEBUG2(" Diameter attribute is too small to contain a Diameter header");
60 rad_assert(data_left <= data_len);
61 memcpy(&attr, data, sizeof(attr));
65 RDEBUG2(" Non-RADIUS attribute in tunneled authentication is not supported");
69 memcpy(&length, data , sizeof(length));
71 length = ntohl(length);
74 * A "vendor" flag, with a vendor ID of zero,
75 * is equivalent to no vendor. This is stupid.
78 if ((length & (1 << 31)) != 0) {
83 memcpy(&vendor, data, sizeof(vendor));
84 vendor = ntohl(vendor);
87 RDEBUG2("Vendor codes larger than 65535 are not supported");
91 da = dict_attrbyvalue(attribute, vendor);
94 * SHOULD check ((length & (1 << 30)) != 0)
95 * for the mandatory bit.
98 RDEBUG2("Fatal! Vendor %u, Attribute %u was not found in our dictionary. ",
103 data += 4; /* skip the vendor field */
104 offset += 4; /* offset to value field */
108 * Ignore the M bit. We support all RADIUS attributes...
112 * Get the length. If it's too big, die.
114 length &= 0x00ffffff;
117 * Too short or too long is bad.
119 if (length < offset) {
120 RDEBUG2("Tunneled attribute %d is too short (%d)to contain anything useful.", attr, length);
125 * EAP Messages cane be longer than MAX_STRING_LEN.
126 * Other attributes cannot be.
128 if ((attr != PW_EAP_MESSAGE) &&
129 (length > (MAX_STRING_LEN + 8))) {
130 RDEBUG2("Tunneled attribute %d is too long (%d) to pack into a RADIUS attribute.", attr, length);
134 if (length > data_left) {
135 RDEBUG2("Tunneled attribute %d is longer than room left in the packet (%d > %d).", attr, length, data_left);
140 * Check for broken implementations, which don't
141 * pad the AVP to a 4-octet boundary.
143 if (data_left == length) break;
146 * The length does NOT include the padding, so
147 * we've got to account for it here by rounding up
148 * to the nearest 4-byte boundary.
154 * If the rest of the diameter packet is larger than
155 * this attribute, continue.
157 * Otherwise, if the attribute over-flows the end
158 * of the packet, die.
160 if (data_left < length) {
161 RDEBUG2("ERROR! Diameter attribute overflows packet!");
166 * Check again for equality, now that we're padded
167 * length to a multiple of 4 octets.
169 if (data_left == length) break;
172 * data_left > length, continue.
175 data += length - offset;
179 * We got this far. It looks OK.
186 * Convert diameter attributes to our VALUE_PAIR's
188 static VALUE_PAIR *diameter2vp(REQUEST *request, SSL *ssl,
189 const uint8_t *data, size_t data_len)
196 size_t data_left = data_len;
197 VALUE_PAIR *first = NULL;
198 VALUE_PAIR **last = &first;
201 while (data_left > 0) {
202 rad_assert(data_left <= data_len);
203 memcpy(&attr, data, sizeof(attr));
208 memcpy(&length, data, sizeof(length));
210 length = ntohl(length);
213 * A "vendor" flag, with a vendor ID of zero,
214 * is equivalent to no vendor. This is stupid.
217 if ((length & (1 << 31)) != 0) {
218 memcpy(&vendor, data, sizeof(vendor));
219 vendor = ntohl(vendor);
222 RDEBUG2("Cannot handle vendor attributes greater than 65535");
227 if (vendor > 65535) {
228 RDEBUG2("Cannot handle vendor Id greater than 65535");
233 data += 4; /* skip the vendor field, it's zero */
234 offset += 4; /* offset to value field */
238 * Vendor attributes can be larger than 255.
239 * Normal attributes cannot be.
241 if ((attr > 255) && (vendor == 0)) {
242 RDEBUG2("Cannot handle Diameter attributes");
248 * FIXME: Handle the M bit. For now, we assume that
249 * some other module takes care of any attribute
250 * with the M bit set.
256 length &= 0x00ffffff;
259 * Get the size of the value portion of the
262 size = length - offset;
267 vp = paircreate(attr, vendor, PW_TYPE_OCTETS);
269 RDEBUG2("Failure in creating VP");
275 * If it's a type from our dictionary, then
276 * we need to put the data in a relevant place.
279 case PW_TYPE_INTEGER:
281 if (size != vp->length) {
282 RDEBUG2("Invalid length attribute %d",
288 memcpy(&vp->vp_integer, data, vp->length);
291 * Stored in host byte order: change it.
293 vp->vp_integer = ntohl(vp->vp_integer);
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 * String, octet, etc. Copy the data from the
313 * value field over verbatim.
315 * FIXME: Ipv6 attributes ?
319 if (attr == PW_EAP_MESSAGE) {
320 const uint8_t *eap_message = data;
323 * vp exists the first time around.
327 if (vp->length > 253) vp->length = 253;
328 memcpy(vp->vp_octets, eap_message,
332 eap_message += vp->length;
337 if (size == 0) break;
339 vp = paircreate(attr, vendor, PW_TYPE_OCTETS);
341 RDEBUG2("Failure in creating VP");
348 } /* else it's another kind of attribute */
353 memcpy(vp->vp_strvalue, data, vp->length);
358 * User-Password is NUL padded to a multiple
359 * of 16 bytes. Let's chop it to something
362 * NOTE: This means that the User-Password
363 * attribute CANNOT EVER have embedded zeros in it!
365 switch (vp->attribute) {
366 case PW_USER_PASSWORD:
368 * If the password is exactly 16 octets,
369 * it won't be zero-terminated.
371 vp->vp_strvalue[vp->length] = '\0';
372 vp->length = strlen(vp->vp_strvalue);
376 * Ensure that the client is using the
377 * correct challenge. This weirdness is
378 * to protect against against replay
379 * attacks, where anyone observing the
380 * CHAP exchange could pose as that user,
381 * by simply choosing to use the same
384 * By using a challenge based on
385 * information from the current session,
386 * we can guarantee that the client is
387 * not *choosing* a challenge.
389 * We're a little forgiving in that we
390 * have loose checks on the length, and
391 * we do NOT check the Id (first octet of
392 * the response to the challenge)
394 * But if the client gets the challenge correct,
395 * we're not too worried about the Id.
397 case PW_CHAP_CHALLENGE:
398 case PW_MSCHAP_CHALLENGE:
399 if ((vp->length < 8) ||
401 RDEBUG("Tunneled challenge has invalid length");
407 uint8_t challenge[16];
409 eapttls_gen_challenge(ssl, challenge,
412 if (memcmp(challenge, vp->vp_octets,
414 RDEBUG("Tunneled challenge is incorrect");
424 } /* switch over checking/re-writing of attributes. */
434 * Catch non-aligned attributes.
436 if (data_left == length) break;
439 * The length does NOT include the padding, so
440 * we've got to account for it here by rounding up
441 * to the nearest 4-byte boundary.
446 rad_assert(data_left >= length);
448 data += length - offset; /* already updated */
452 * We got this far. It looks OK.
458 * Convert VALUE_PAIR's to diameter attributes, and write them
461 * The ONLY VALUE_PAIR's which may be passed to this function
462 * are ones which can go inside of a RADIUS (i.e. diameter)
463 * packet. So no server-configuration attributes, or the like.
465 static int vp2diameter(REQUEST *request, tls_session_t *tls_session, VALUE_PAIR *first)
468 * RADIUS packets are no more than 4k in size, so if
469 * we've got more than 4k of data to write, it's very
472 uint8_t buffer[4096];
483 for (vp = first; vp != NULL; vp = vp->next) {
485 * Too much data: die.
487 if ((total + vp->length + 12) >= sizeof(buffer)) {
488 RDEBUG2("output buffer is full!");
493 * Hmm... we don't group multiple EAP-Messages
494 * together. Maybe we should...
498 * Length is no more than 253, due to RADIUS
502 vendor = (vp->attribute >> 16) & 0xffff;
504 attr = vp->attribute & 0xffff;
507 attr = vp->attribute;
511 * Hmm... set the M bit for all attributes?
517 memcpy(p, &attr, sizeof(attr));
521 length += 8; /* includes 8 bytes of attr & length */
524 length += 4; /* include 4 bytes of vendor */
526 length = ntohl(length);
527 memcpy(p, &length, sizeof(length));
531 vendor = ntohl(vendor);
532 memcpy(p, &vendor, sizeof(vendor));
536 length = ntohl(length);
537 memcpy(p, &length, sizeof(length));
543 case PW_TYPE_INTEGER:
545 attr = ntohl(vp->vp_integer); /* stored in host order */
546 memcpy(p, &attr, sizeof(attr));
551 memcpy(p, &vp->vp_ipaddr, 4); /* network order */
558 memcpy(p, vp->vp_strvalue, vp->length);
564 * Skip to the end of the data.
570 * Align the data to a multiple of 4 bytes.
572 if ((total & 0x03) != 0) {
575 length = 4 - (total & 0x03);
576 for (i = 0; i < length; i++) {
582 } /* loop over the VP's to write. */
585 * Write the data in the buffer to the SSL session.
591 if ((debug_flag > 2) && fr_log_fp) {
592 for (i = 0; i < total; i++) {
593 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data out %04x: ", (int) i);
595 fprintf(fr_log_fp, "%02x ", buffer[i]);
597 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
599 if ((total & 0x0f) != 0) fprintf(fr_log_fp, "\n");
603 (tls_session->record_plus)(&tls_session->clean_in, buffer, total);
606 * FIXME: Check the return code.
608 tls_handshake_send(tls_session);
618 * Use a reply packet to determine what to do.
620 static int process_reply(EAP_HANDLER *handler, tls_session_t *tls_session,
621 REQUEST *request, RADIUS_PACKET *reply)
623 int rcode = RLM_MODULE_REJECT;
625 ttls_tunnel_t *t = tls_session->opaque;
627 handler = handler; /* -Wunused */
630 * If the response packet was Access-Accept, then
631 * we're OK. If not, die horribly.
633 * FIXME: Take MS-CHAP2-Success attribute, and
634 * tunnel it back to the client, to authenticate
635 * ourselves to the client.
637 * FIXME: If we have an Access-Challenge, then
638 * the Reply-Message is tunneled back to the client.
640 * FIXME: If we have an EAP-Message, then that message
641 * must be tunneled back to the client.
643 * FIXME: If we have an Access-Challenge with a State
644 * attribute, then do we tunnel that to the client, or
645 * keep track of it ourselves?
647 * FIXME: EAP-Messages can only start with 'identity',
648 * NOT 'eap start', so we should check for that....
650 switch (reply->code) {
651 case PW_AUTHENTICATION_ACK:
652 RDEBUG("Got tunneled Access-Accept");
654 rcode = RLM_MODULE_OK;
657 * MS-CHAP2-Success means that we do NOT return
658 * an Access-Accept, but instead tunnel that
659 * attribute to the client, and keep going with
660 * the TTLS session. Once the client accepts
661 * our identity, it will respond with an empty
662 * packet, and we will send EAP-Success.
665 pairmove2(&vp, &reply->vps, PW_MSCHAP2_SUCCESS, VENDORPEC_MICROSOFT);
667 RDEBUG("Got MS-CHAP2-Success, tunneling it to the client in a challenge.");
668 rcode = RLM_MODULE_HANDLED;
669 t->authenticated = TRUE;
672 * Delete MPPE keys & encryption policy. We don't
675 pairdelete(&reply->vps, 7, VENDORPEC_MICROSOFT);
676 pairdelete(&reply->vps, 8, VENDORPEC_MICROSOFT);
677 pairdelete(&reply->vps, 16, VENDORPEC_MICROSOFT);
678 pairdelete(&reply->vps, 17, VENDORPEC_MICROSOFT);
681 * Use the tunneled reply, but not now.
683 if (t->use_tunneled_reply) {
684 t->accept_vps = reply->vps;
688 } else { /* no MS-CHAP2-Success */
690 * Can only have EAP-Message if there's
691 * no MS-CHAP2-Success. (FIXME: EAP-MSCHAP?)
693 * We also do NOT tunnel the EAP-Success
694 * attribute back to the client, as the client
695 * can figure it out, from the non-tunneled
696 * EAP-Success packet.
698 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE, 0);
703 * Handle the ACK, by tunneling any necessary reply
704 * VP's back to the client.
707 vp2diameter(request, tls_session, vp);
712 * If we've been told to use the attributes from
713 * the reply, then do so.
715 * WARNING: This may leak information about the
718 if (t->use_tunneled_reply) {
719 pairdelete(&reply->vps, PW_PROXY_STATE, 0);
720 pairadd(&request->reply->vps, reply->vps);
726 case PW_AUTHENTICATION_REJECT:
727 RDEBUG("Got tunneled Access-Reject");
728 rcode = RLM_MODULE_REJECT;
732 * Handle Access-Challenge, but only if we
733 * send tunneled reply data. This is because
734 * an Access-Challenge means that we MUST tunnel
735 * a Reply-Message to the client.
737 case PW_ACCESS_CHALLENGE:
738 RDEBUG("Got tunneled Access-Challenge");
741 * Keep the State attribute, if necessary.
743 * Get rid of the old State, too.
746 pairmove2(&t->state, &reply->vps, PW_STATE, 0);
749 * We should really be a bit smarter about this,
750 * and move over only those attributes which
751 * are relevant to the authentication request,
752 * but that's a lot more work, and this "dumb"
753 * method works in 99.9% of the situations.
756 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE, 0);
759 * There MUST be a Reply-Message in the challenge,
760 * which we tunnel back to the client.
762 * If there isn't one in the reply VP's, then
763 * we MUST create one, with an empty string as
766 pairmove2(&vp, &reply->vps, PW_REPLY_MESSAGE, 0);
769 * Handle the ACK, by tunneling any necessary reply
770 * VP's back to the client.
773 vp2diameter(request, tls_session, vp);
776 rcode = RLM_MODULE_HANDLED;
780 RDEBUG("Unknown RADIUS packet type %d: rejecting tunneled user", reply->code);
781 rcode = RLM_MODULE_INVALID;
791 * Do post-proxy processing,
793 static int eapttls_postproxy(EAP_HANDLER *handler, void *data)
796 tls_session_t *tls_session = (tls_session_t *) data;
797 REQUEST *fake, *request = handler->request;
799 RDEBUG("Passing reply from proxy back into the tunnel.");
802 * If there was a fake request associated with the proxied
803 * request, do more processing of it.
805 fake = (REQUEST *) request_data_get(handler->request,
806 handler->request->proxy,
807 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK);
810 * Do the callback, if it exists, and if it was a success.
812 if (fake && (handler->request->proxy_reply->code == PW_AUTHENTICATION_ACK)) {
816 rad_assert(fake->packet == NULL);
817 fake->packet = request->proxy;
818 fake->packet->src_ipaddr = request->packet->src_ipaddr;
819 request->proxy = NULL;
821 rad_assert(fake->reply == NULL);
822 fake->reply = request->proxy_reply;
823 request->proxy_reply = NULL;
825 if ((debug_flag > 0) && fr_log_fp) {
826 fprintf(fr_log_fp, "server %s {\n",
827 (fake->server == NULL) ? "" : fake->server);
831 * Perform a post-auth stage for the tunneled
834 fake->options &= ~RAD_REQUEST_OPTION_PROXY_EAP;
835 rcode = rad_postauth(fake);
836 RDEBUG2("post-auth returns %d", rcode);
838 if ((debug_flag > 0) && fr_log_fp) {
839 fprintf(fr_log_fp, "} # server %s\n",
840 (fake->server == NULL) ? "" : fake->server);
842 RDEBUG("Final reply from tunneled session code %d",
844 debug_pair_list(fake->reply->vps);
850 request->proxy = fake->packet;
852 request->proxy_reply = fake->reply;
856 * And we're done with this request.
860 case RLM_MODULE_FAIL:
862 eaptls_fail(handler, 0);
866 default: /* Don't Do Anything */
867 RDEBUG2("sGot reply %d",
868 request->proxy_reply->code);
872 request_free(&fake); /* robust if fake == NULL */
875 * Process the reply from the home server.
877 rcode = process_reply(handler, tls_session, handler->request,
878 handler->request->proxy_reply);
881 * The proxy code uses the reply from the home server as
882 * the basis for the reply to the NAS. We don't want that,
883 * so we toss it, after we've had our way with it.
885 pairfree(&handler->request->proxy_reply->vps);
888 case RLM_MODULE_REJECT:
889 RDEBUG("Reply was rejected");
892 case RLM_MODULE_HANDLED:
893 RDEBUG("Reply was handled");
894 eaptls_request(handler->eap_ds, tls_session);
898 RDEBUG("Reply was OK");
901 * Success: Automatically return MPPE keys.
903 return eaptls_success(handler, 0);
906 RDEBUG("Reply was unknown.");
910 eaptls_fail(handler, 0);
918 static void my_request_free(void *data)
920 REQUEST *request = (REQUEST *)data;
922 request_free(&request);
924 #endif /* WITH_PROXY */
927 * Process the "diameter" contents of the tunneled data.
929 int eapttls_process(EAP_HANDLER *handler, tls_session_t *tls_session)
931 int rcode = PW_AUTHENTICATION_REJECT;
937 REQUEST *request = handler->request;
940 * Just look at the buffer directly, without doing
943 data_len = tls_session->clean_out.used;
944 tls_session->clean_out.used = 0;
945 data = tls_session->clean_out.data;
947 t = (ttls_tunnel_t *) tls_session->opaque;
950 * If there's no data, maybe this is an ACK to an
954 if (t->authenticated) {
955 RDEBUG("Got ACK, and the user was already authenticated.");
956 return PW_AUTHENTICATION_ACK;
957 } /* else no session, no data, die. */
960 * FIXME: Call SSL_get_error() to see what went
963 RDEBUG2("SSL_read Error");
964 return PW_AUTHENTICATION_REJECT;
968 if ((debug_flag > 2) && fr_log_fp) {
971 for (i = 0; i < data_len; i++) {
972 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data in %04x: ", (int) i);
974 fprintf(fr_log_fp, "%02x ", data[i]);
976 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
978 if ((data_len & 0x0f) != 0) fprintf(fr_log_fp, "\n");
982 if (!diameter_verify(request, data, data_len)) {
983 return PW_AUTHENTICATION_REJECT;
987 * Allocate a fake REQUEST structe.
989 fake = request_alloc_fake(request);
991 rad_assert(fake->packet->vps == NULL);
994 * Add the tunneled attributes to the fake request.
996 fake->packet->vps = diameter2vp(request, tls_session->ssl, data, data_len);
997 if (!fake->packet->vps) {
999 return PW_AUTHENTICATION_REJECT;
1003 * Tell the request that it's a fake one.
1005 vp = pairmake("Freeradius-Proxied-To", "127.0.0.1", T_OP_EQ);
1007 pairadd(&fake->packet->vps, vp);
1010 if ((debug_flag > 0) && fr_log_fp) {
1011 RDEBUG("Got tunneled request");
1013 debug_pair_list(fake->packet->vps);
1017 * Update other items in the REQUEST data structure.
1019 fake->username = pairfind(fake->packet->vps, PW_USER_NAME, 0);
1020 fake->password = pairfind(fake->packet->vps, PW_USER_PASSWORD, 0);
1023 * No User-Name, try to create one from stored data.
1025 if (!fake->username) {
1027 * No User-Name in the stored data, look for
1028 * an EAP-Identity, and pull it out of there.
1031 vp = pairfind(fake->packet->vps, PW_EAP_MESSAGE, 0);
1033 (vp->length >= EAP_HEADER_LEN + 2) &&
1034 (vp->vp_strvalue[0] == PW_EAP_RESPONSE) &&
1035 (vp->vp_strvalue[EAP_HEADER_LEN] == PW_EAP_IDENTITY) &&
1036 (vp->vp_strvalue[EAP_HEADER_LEN + 1] != 0)) {
1038 * Create & remember a User-Name
1040 t->username = pairmake("User-Name", "", T_OP_EQ);
1041 rad_assert(t->username != NULL);
1043 memcpy(t->username->vp_strvalue, vp->vp_strvalue + 5,
1045 t->username->length = vp->length - 5;
1046 t->username->vp_strvalue[t->username->length] = 0;
1048 RDEBUG("Got tunneled identity of %s",
1049 t->username->vp_strvalue);
1052 * If there's a default EAP type,
1055 if (t->default_eap_type != 0) {
1056 RDEBUG("Setting default EAP type for tunneled EAP session.");
1057 vp = paircreate(PW_EAP_TYPE, 0,
1059 rad_assert(vp != NULL);
1060 vp->vp_integer = t->default_eap_type;
1061 pairadd(&fake->config_items, vp);
1066 * Don't reject the request outright,
1067 * as it's permitted to do EAP without
1070 RDEBUG2("WARNING! No EAP-Identity found to start EAP conversation.");
1072 } /* else there WAS a t->username */
1075 vp = paircopy(t->username);
1076 pairadd(&fake->packet->vps, vp);
1077 fake->username = pairfind(fake->packet->vps, PW_USER_NAME, 0);
1079 } /* else the request ALREADY had a User-Name */
1082 * Add the State attribute, too, if it exists.
1085 vp = paircopy(t->state);
1086 if (vp) pairadd(&fake->packet->vps, vp);
1090 * If this is set, we copy SOME of the request attributes
1091 * from outside of the tunnel to inside of the tunnel.
1093 * We copy ONLY those attributes which do NOT already
1094 * exist in the tunneled request.
1096 if (t->copy_request_to_tunnel) {
1099 for (vp = request->packet->vps; vp != NULL; vp = vp->next) {
1101 * The attribute is a server-side thingy,
1104 if ((vp->attribute > 255) &&
1105 (((vp->attribute >> 16) & 0xffff) == 0)) {
1110 * The outside attribute is already in the
1111 * tunnel, don't copy it.
1113 * This works for BOTH attributes which
1114 * are originally in the tunneled request,
1115 * AND attributes which are copied there
1118 if (pairfind(fake->packet->vps, vp->attribute, vp->vendor)) {
1123 * Some attributes are handled specially.
1125 switch (vp->attribute) {
1127 * NEVER copy Message-Authenticator,
1128 * EAP-Message, or State. They're
1129 * only for outside of the tunnel.
1132 case PW_USER_PASSWORD:
1133 case PW_CHAP_PASSWORD:
1134 case PW_CHAP_CHALLENGE:
1135 case PW_PROXY_STATE:
1136 case PW_MESSAGE_AUTHENTICATOR:
1137 case PW_EAP_MESSAGE:
1143 * By default, copy it over.
1150 * Don't copy from the head, we've already
1153 copy = paircopy2(vp, vp->attribute, vp->vendor);
1154 pairadd(&fake->packet->vps, copy);
1158 if ((vp = pairfind(request->config_items, PW_VIRTUAL_SERVER, 0)) != NULL) {
1159 fake->server = vp->vp_strvalue;
1161 } else if (t->virtual_server) {
1162 fake->server = t->virtual_server;
1164 } /* else fake->server == request->server */
1167 if ((debug_flag > 0) && fr_log_fp) {
1168 RDEBUG("Sending tunneled request");
1170 debug_pair_list(fake->packet->vps);
1172 fprintf(fr_log_fp, "server %s {\n",
1173 (fake->server == NULL) ? "" : fake->server);
1177 * Call authentication recursively, which will
1178 * do PAP, CHAP, MS-CHAP, etc.
1180 rad_authenticate(fake);
1183 * Note that we don't do *anything* with the reply
1186 if ((debug_flag > 0) && fr_log_fp) {
1187 fprintf(fr_log_fp, "} # server %s\n",
1188 (fake->server == NULL) ? "" : fake->server);
1190 RDEBUG("Got tunneled reply code %d", fake->reply->code);
1192 debug_pair_list(fake->reply->vps);
1196 * Decide what to do with the reply.
1198 switch (fake->reply->code) {
1199 case 0: /* No reply code, must be proxied... */
1201 vp = pairfind(fake->config_items, PW_PROXY_TO_REALM, 0);
1203 eap_tunnel_data_t *tunnel;
1204 RDEBUG("Tunneled authentication will be proxied to %s", vp->vp_strvalue);
1207 * Tell the original request that it's going
1210 pairmove2(&(request->config_items),
1211 &(fake->config_items),
1212 PW_PROXY_TO_REALM, 0);
1215 * Seed the proxy packet with the
1218 rad_assert(request->proxy == NULL);
1219 request->proxy = fake->packet;
1220 fake->packet = NULL;
1221 rad_free(&fake->reply);
1225 * Set up the callbacks for the tunnel
1227 tunnel = rad_malloc(sizeof(*tunnel));
1228 memset(tunnel, 0, sizeof(*tunnel));
1230 tunnel->tls_session = tls_session;
1231 tunnel->callback = eapttls_postproxy;
1234 * Associate the callback with the request.
1236 rcode = request_data_add(request,
1238 REQUEST_DATA_EAP_TUNNEL_CALLBACK,
1240 rad_assert(rcode == 0);
1243 * rlm_eap.c has taken care of associating
1244 * the handler with the fake request.
1246 * So we associate the fake request with
1249 rcode = request_data_add(request,
1251 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK,
1252 fake, my_request_free);
1253 rad_assert(rcode == 0);
1257 * Didn't authenticate the packet, but
1258 * we're proxying it.
1260 rcode = PW_STATUS_CLIENT;
1263 #endif /* WITH_PROXY */
1265 RDEBUG("No tunneled reply was found for request %d , and the request was not proxied: rejecting the user.",
1267 rcode = PW_AUTHENTICATION_REJECT;
1273 * Returns RLM_MODULE_FOO, and we want to return
1276 rcode = process_reply(handler, tls_session, request,
1279 case RLM_MODULE_REJECT:
1280 rcode = PW_AUTHENTICATION_REJECT;
1283 case RLM_MODULE_HANDLED:
1284 rcode = PW_ACCESS_CHALLENGE;
1288 rcode = PW_AUTHENTICATION_ACK;
1292 rcode = PW_AUTHENTICATION_REJECT;
1298 request_free(&fake);