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) {
58 RDEBUG2(" Diameter attribute is too small to contain a Diameter header");
62 memcpy(&attr, data, 4);
64 memcpy(&length, data + 4, 4);
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");
79 * Too short or too long is bad.
81 if (length <= (hdr_len - 4)) {
82 RDEBUG2("Tunneled attribute %u is too short (%u < %u) to contain anything useful.", attr, length, hdr_len);
86 if (length > data_left) {
87 RDEBUG2("Tunneled attribute %u is longer than room left in the packet (%u > %u).", attr, length, data_left);
92 * Check for broken implementations, which don't
93 * pad the AVP to a 4-octet boundary.
95 if (data_left == length) break;
98 * The length does NOT include the padding, so
99 * we've got to account for it here by rounding up
100 * to the nearest 4-byte boundary.
106 * If the rest of the diameter packet is larger than
107 * this attribute, continue.
109 * Otherwise, if the attribute over-flows the end
110 * of the packet, die.
112 if (data_left < length) {
113 RDEBUG2("ERROR! Diameter attribute overflows packet!");
118 * data_left > length, continue.
125 * We got this far. It looks OK.
132 * Convert diameter attributes to our VALUE_PAIR's
134 static VALUE_PAIR *diameter2vp(REQUEST *request, SSL *ssl,
135 const uint8_t *data, size_t data_len)
141 size_t data_left = data_len;
142 VALUE_PAIR *first = NULL;
143 VALUE_PAIR **last = &first;
146 while (data_left > 0) {
147 rad_assert(data_left <= data_len);
148 memcpy(&attr, data, sizeof(attr));
152 memcpy(&length, data, sizeof(length));
154 length = ntohl(length);
157 * A "vendor" flag, with a vendor ID of zero,
158 * is equivalent to no vendor. This is stupid.
161 if ((length & (1 << 31)) != 0) {
164 memcpy(&vendor, data, sizeof(vendor));
165 vendor = ntohl(vendor);
167 data += 4; /* skip the vendor field, it's zero */
168 offset += 4; /* offset to value field */
169 length &= 0x00ffffff;
171 if (attr > 65535) goto next_attr;
172 if (vendor > 65535) goto next_attr;
174 attr |= (vendor << 16);
180 length &= 0x00ffffff;
183 * FIXME: Handle the M bit. For now, we assume that
184 * some other module takes care of any attribute
185 * with the M bit set.
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(attr) == 0)) {
199 RDEBUG2("WARNING: Skipping Diameter attribute %u",
205 RDEBUG2("WARNING: diameter2vp skipping long attribute %u, attr");
210 * Create it. If this fails, it's because we're OOM.
212 vp = paircreate(attr, PW_TYPE_OCTETS);
214 RDEBUG2("diameter2vp: Failed creating attribute %u", attr);
220 * If it's a type from our dictionary, then
221 * we need to put the data in a relevant place.
224 case PW_TYPE_INTEGER:
226 if (size != vp->length) {
228 * Bad format. Create a "raw"
232 vp = paircreate_raw(vp->attribute,
235 memcpy(vp->vp_octets, data, vp->length);
238 memcpy(&vp->vp_integer, data, vp->length);
241 * Stored in host byte order: change it.
243 vp->vp_integer = ntohl(vp->vp_integer);
247 if (size != vp->length) goto raw;
248 memcpy(&vp->vp_ipaddr, data, vp->length);
251 * Stored in network byte order: don't change it.
256 if (size != vp->length) goto raw;
257 vp->vp_integer = data[0];
261 if (size != vp->length) goto raw;
262 vp->vp_integer = (data[0] * 256) + data[1];
266 if (size != vp->length) goto raw;
267 memcpy(&vp->vp_signed, data, vp->length);
268 vp->vp_signed = ntohl(vp->vp_signed);
271 case PW_TYPE_IPV6ADDR:
272 if (size != vp->length) goto raw;
273 memcpy(&vp->vp_ipv6addr, data, vp->length);
276 case PW_TYPE_IPV6PREFIX:
277 if (size != vp->length) goto raw;
278 memcpy(&vp->vp_ipv6prefix, data, vp->length);
282 * String, octet, etc. Copy the data from the
283 * value field over verbatim.
285 * FIXME: Ipv6 attributes ?
289 if (attr == PW_EAP_MESSAGE) {
290 const uint8_t *eap_message = data;
293 * vp exists the first time around.
297 if (vp->length > 253) vp->length = 253;
298 memcpy(vp->vp_octets, eap_message,
302 eap_message += vp->length;
307 if (size == 0) break;
309 vp = paircreate(attr, PW_TYPE_OCTETS);
311 RDEBUG2("Failed creating EAP-Message");
318 } /* else it's another kind of attribute */
323 memcpy(vp->vp_octets, data, vp->length);
328 * User-Password is NUL padded to a multiple
329 * of 16 bytes. Let's chop it to something
332 * NOTE: This means that the User-Password
333 * attribute CANNOT EVER have embedded zeros in it!
335 switch (vp->attribute) {
336 case PW_USER_PASSWORD:
338 * If the password is exactly 16 octets,
339 * it won't be zero-terminated.
341 vp->vp_strvalue[vp->length] = '\0';
342 vp->length = strlen(vp->vp_strvalue);
346 * Ensure that the client is using the
347 * correct challenge. This weirdness is
348 * to protect against against replay
349 * attacks, where anyone observing the
350 * CHAP exchange could pose as that user,
351 * by simply choosing to use the same
354 * By using a challenge based on
355 * information from the current session,
356 * we can guarantee that the client is
357 * not *choosing* a challenge.
359 * We're a little forgiving in that we
360 * have loose checks on the length, and
361 * we do NOT check the Id (first octet of
362 * the response to the challenge)
364 * But if the client gets the challenge correct,
365 * we're not too worried about the Id.
367 case PW_CHAP_CHALLENGE:
368 case PW_MSCHAP_CHALLENGE:
369 if ((vp->length < 8) ||
371 RDEBUG("Tunneled challenge has invalid length");
377 uint8_t challenge[16];
379 eapttls_gen_challenge(ssl, challenge,
382 if (memcmp(challenge, vp->vp_octets,
384 RDEBUG("Tunneled challenge is incorrect");
394 } /* switch over checking/re-writing of attributes. */
404 * Catch non-aligned attributes.
406 if (data_left == length) break;
409 * The length does NOT include the padding, so
410 * we've got to account for it here by rounding up
411 * to the nearest 4-byte boundary.
416 rad_assert(data_left >= length);
418 data += length - offset; /* already updated */
422 * We got this far. It looks OK.
428 * Convert VALUE_PAIR's to diameter attributes, and write them
431 * The ONLY VALUE_PAIR's which may be passed to this function
432 * are ones which can go inside of a RADIUS (i.e. diameter)
433 * packet. So no server-configuration attributes, or the like.
435 static int vp2diameter(REQUEST *request, tls_session_t *tls_session, VALUE_PAIR *first)
438 * RADIUS packets are no more than 4k in size, so if
439 * we've got more than 4k of data to write, it's very
442 uint8_t buffer[4096];
453 for (vp = first; vp != NULL; vp = vp->next) {
455 * Too much data: die.
457 if ((total + vp->length + 12) >= sizeof(buffer)) {
458 RDEBUG2("output buffer is full!");
463 * Hmm... we don't group multiple EAP-Messages
464 * together. Maybe we should...
468 * Length is no more than 253, due to RADIUS
472 vendor = (vp->attribute >> 16) & 0xffff;
474 attr = vp->attribute & 0xffff;
477 attr = vp->attribute;
481 * Hmm... set the M bit for all attributes?
487 memcpy(p, &attr, sizeof(attr));
491 length += 8; /* includes 8 bytes of attr & length */
494 length += 4; /* include 4 bytes of vendor */
496 length = ntohl(length);
497 memcpy(p, &length, sizeof(length));
501 vendor = ntohl(vendor);
502 memcpy(p, &vendor, sizeof(vendor));
506 length = ntohl(length);
507 memcpy(p, &length, sizeof(length));
513 case PW_TYPE_INTEGER:
515 attr = ntohl(vp->vp_integer); /* stored in host order */
516 memcpy(p, &attr, sizeof(attr));
521 memcpy(p, &vp->vp_ipaddr, 4); /* network order */
528 memcpy(p, vp->vp_strvalue, vp->length);
534 * Skip to the end of the data.
540 * Align the data to a multiple of 4 bytes.
542 if ((total & 0x03) != 0) {
545 length = 4 - (total & 0x03);
546 for (i = 0; i < length; i++) {
552 } /* loop over the VP's to write. */
555 * Write the data in the buffer to the SSL session.
561 if ((debug_flag > 2) && fr_log_fp) {
562 for (i = 0; i < total; i++) {
563 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data out %04x: ", (int) i);
565 fprintf(fr_log_fp, "%02x ", buffer[i]);
567 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
569 if ((total & 0x0f) != 0) fprintf(fr_log_fp, "\n");
573 (tls_session->record_plus)(&tls_session->clean_in, buffer, total);
576 * FIXME: Check the return code.
578 tls_handshake_send(request, tls_session);
588 * Use a reply packet to determine what to do.
590 static int process_reply(EAP_HANDLER *handler, tls_session_t *tls_session,
591 REQUEST *request, RADIUS_PACKET *reply)
593 int rcode = RLM_MODULE_REJECT;
595 ttls_tunnel_t *t = tls_session->opaque;
597 handler = handler; /* -Wunused */
600 * If the response packet was Access-Accept, then
601 * we're OK. If not, die horribly.
603 * FIXME: Take MS-CHAP2-Success attribute, and
604 * tunnel it back to the client, to authenticate
605 * ourselves to the client.
607 * FIXME: If we have an Access-Challenge, then
608 * the Reply-Message is tunneled back to the client.
610 * FIXME: If we have an EAP-Message, then that message
611 * must be tunneled back to the client.
613 * FIXME: If we have an Access-Challenge with a State
614 * attribute, then do we tunnel that to the client, or
615 * keep track of it ourselves?
617 * FIXME: EAP-Messages can only start with 'identity',
618 * NOT 'eap start', so we should check for that....
620 switch (reply->code) {
621 case PW_AUTHENTICATION_ACK:
622 RDEBUG("Got tunneled Access-Accept");
624 rcode = RLM_MODULE_OK;
627 * MS-CHAP2-Success means that we do NOT return
628 * an Access-Accept, but instead tunnel that
629 * attribute to the client, and keep going with
630 * the TTLS session. Once the client accepts
631 * our identity, it will respond with an empty
632 * packet, and we will send EAP-Success.
635 pairmove2(&vp, &reply->vps, PW_MSCHAP2_SUCCESS);
637 RDEBUG("Got MS-CHAP2-Success, tunneling it to the client in a challenge.");
638 rcode = RLM_MODULE_HANDLED;
639 t->authenticated = TRUE;
642 * Delete MPPE keys & encryption policy. We don't
645 pairdelete(&reply->vps, ((311 << 16) | 7));
646 pairdelete(&reply->vps, ((311 << 16) | 8));
647 pairdelete(&reply->vps, ((311 << 16) | 16));
648 pairdelete(&reply->vps, ((311 << 16) | 17));
651 * Use the tunneled reply, but not now.
653 if (t->use_tunneled_reply) {
654 t->accept_vps = reply->vps;
658 } else { /* no MS-CHAP2-Success */
660 * Can only have EAP-Message if there's
661 * no MS-CHAP2-Success. (FIXME: EAP-MSCHAP?)
663 * We also do NOT tunnel the EAP-Success
664 * attribute back to the client, as the client
665 * can figure it out, from the non-tunneled
666 * EAP-Success packet.
668 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
673 * Handle the ACK, by tunneling any necessary reply
674 * VP's back to the client.
677 vp2diameter(request, tls_session, vp);
682 * If we've been told to use the attributes from
683 * the reply, then do so.
685 * WARNING: This may leak information about the
688 if (t->use_tunneled_reply) {
689 pairdelete(&reply->vps, PW_PROXY_STATE);
690 pairadd(&request->reply->vps, reply->vps);
696 case PW_AUTHENTICATION_REJECT:
697 RDEBUG("Got tunneled Access-Reject");
698 rcode = RLM_MODULE_REJECT;
702 * Handle Access-Challenge, but only if we
703 * send tunneled reply data. This is because
704 * an Access-Challenge means that we MUST tunnel
705 * a Reply-Message to the client.
707 case PW_ACCESS_CHALLENGE:
708 RDEBUG("Got tunneled Access-Challenge");
711 * Keep the State attribute, if necessary.
713 * Get rid of the old State, too.
716 pairmove2(&t->state, &reply->vps, PW_STATE);
719 * We should really be a bit smarter about this,
720 * and move over only those attributes which
721 * are relevant to the authentication request,
722 * but that's a lot more work, and this "dumb"
723 * method works in 99.9% of the situations.
726 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
729 * There MUST be a Reply-Message in the challenge,
730 * which we tunnel back to the client.
732 * If there isn't one in the reply VP's, then
733 * we MUST create one, with an empty string as
736 pairmove2(&vp, &reply->vps, PW_REPLY_MESSAGE);
739 * Handle the ACK, by tunneling any necessary reply
740 * VP's back to the client.
743 vp2diameter(request, tls_session, vp);
746 rcode = RLM_MODULE_HANDLED;
750 RDEBUG("Unknown RADIUS packet type %d: rejecting tunneled user", reply->code);
751 rcode = RLM_MODULE_INVALID;
761 * Do post-proxy processing,
763 static int eapttls_postproxy(EAP_HANDLER *handler, void *data)
766 tls_session_t *tls_session = (tls_session_t *) data;
767 REQUEST *fake, *request = handler->request;
769 RDEBUG("Passing reply from proxy back into the tunnel.");
772 * If there was a fake request associated with the proxied
773 * request, do more processing of it.
775 fake = (REQUEST *) request_data_get(handler->request,
776 handler->request->proxy,
777 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK);
780 * Do the callback, if it exists, and if it was a success.
783 handler->request->proxy_reply &&
784 (handler->request->proxy_reply->code == PW_AUTHENTICATION_ACK)) {
788 rad_assert(fake->packet == NULL);
789 fake->packet = request->proxy;
790 fake->packet->src_ipaddr = request->packet->src_ipaddr;
791 request->proxy = NULL;
793 rad_assert(fake->reply == NULL);
794 fake->reply = request->proxy_reply;
795 request->proxy_reply = NULL;
797 if ((debug_flag > 0) && fr_log_fp) {
798 fprintf(fr_log_fp, "server %s {\n",
799 (fake->server == NULL) ? "" : fake->server);
803 * Perform a post-auth stage for the tunneled
806 fake->options &= ~RAD_REQUEST_OPTION_PROXY_EAP;
807 rcode = rad_postauth(fake);
808 RDEBUG2("post-auth returns %d", rcode);
810 if ((debug_flag > 0) && fr_log_fp) {
811 fprintf(fr_log_fp, "} # server %s\n",
812 (fake->server == NULL) ? "" : fake->server);
814 RDEBUG("Final reply from tunneled session code %d",
816 debug_pair_list(fake->reply->vps);
822 request->proxy = fake->packet;
824 request->proxy_reply = fake->reply;
828 * And we're done with this request.
832 case RLM_MODULE_FAIL:
834 eaptls_fail(handler, 0);
838 default: /* Don't Do Anything */
839 RDEBUG2("Got reply %d",
840 request->proxy_reply->code);
844 request_free(&fake); /* robust if fake == NULL */
847 * Process the reply from the home server.
849 rcode = process_reply(handler, tls_session, handler->request,
850 handler->request->proxy_reply);
853 * The proxy code uses the reply from the home server as
854 * the basis for the reply to the NAS. We don't want that,
855 * so we toss it, after we've had our way with it.
857 pairfree(&handler->request->proxy_reply->vps);
860 case RLM_MODULE_REJECT:
861 RDEBUG("Reply was rejected");
864 case RLM_MODULE_HANDLED:
865 RDEBUG("Reply was handled");
866 eaptls_request(handler->eap_ds, tls_session);
870 RDEBUG("Reply was OK");
873 * Success: Automatically return MPPE keys.
875 return eaptls_success(handler, 0);
878 RDEBUG("Reply was unknown.");
882 eaptls_fail(handler, 0);
890 static void my_request_free(void *data)
892 REQUEST *request = (REQUEST *)data;
894 request_free(&request);
896 #endif /* WITH_PROXY */
899 * Process the "diameter" contents of the tunneled data.
901 int eapttls_process(EAP_HANDLER *handler, tls_session_t *tls_session)
903 int rcode = PW_AUTHENTICATION_REJECT;
909 REQUEST *request = handler->request;
912 * Just look at the buffer directly, without doing
915 data_len = tls_session->clean_out.used;
916 tls_session->clean_out.used = 0;
917 data = tls_session->clean_out.data;
919 t = (ttls_tunnel_t *) tls_session->opaque;
922 * If there's no data, maybe this is an ACK to an
926 if (t->authenticated) {
927 RDEBUG("Got ACK, and the user was already authenticated.");
928 return PW_AUTHENTICATION_ACK;
929 } /* else no session, no data, die. */
932 * FIXME: Call SSL_get_error() to see what went
935 RDEBUG2("SSL_read Error");
936 return PW_AUTHENTICATION_REJECT;
940 if ((debug_flag > 2) && fr_log_fp) {
943 for (i = 0; i < data_len; i++) {
944 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data in %04x: ", (int) i);
946 fprintf(fr_log_fp, "%02x ", data[i]);
948 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
950 if ((data_len & 0x0f) != 0) fprintf(fr_log_fp, "\n");
954 if (!diameter_verify(request, data, data_len)) {
955 return PW_AUTHENTICATION_REJECT;
959 * Allocate a fake REQUEST structe.
961 fake = request_alloc_fake(request);
963 rad_assert(fake->packet->vps == NULL);
966 * Add the tunneled attributes to the fake request.
968 fake->packet->vps = diameter2vp(request, tls_session->ssl, data, data_len);
969 if (!fake->packet->vps) {
971 return PW_AUTHENTICATION_REJECT;
975 * Tell the request that it's a fake one.
977 vp = pairmake("Freeradius-Proxied-To", "127.0.0.1", T_OP_EQ);
979 pairadd(&fake->packet->vps, vp);
982 if ((debug_flag > 0) && fr_log_fp) {
983 RDEBUG("Got tunneled request");
985 debug_pair_list(fake->packet->vps);
989 * Update other items in the REQUEST data structure.
991 fake->username = pairfind(fake->packet->vps, PW_USER_NAME);
992 fake->password = pairfind(fake->packet->vps, PW_USER_PASSWORD);
995 * No User-Name, try to create one from stored data.
997 if (!fake->username) {
999 * No User-Name in the stored data, look for
1000 * an EAP-Identity, and pull it out of there.
1003 vp = pairfind(fake->packet->vps, PW_EAP_MESSAGE);
1005 (vp->length >= EAP_HEADER_LEN + 2) &&
1006 (vp->vp_strvalue[0] == PW_EAP_RESPONSE) &&
1007 (vp->vp_strvalue[EAP_HEADER_LEN] == PW_EAP_IDENTITY) &&
1008 (vp->vp_strvalue[EAP_HEADER_LEN + 1] != 0)) {
1010 * Create & remember a User-Name
1012 t->username = pairmake("User-Name", "", T_OP_EQ);
1013 rad_assert(t->username != NULL);
1015 memcpy(t->username->vp_strvalue, vp->vp_strvalue + 5,
1017 t->username->length = vp->length - 5;
1018 t->username->vp_strvalue[t->username->length] = 0;
1020 RDEBUG("Got tunneled identity of %s",
1021 t->username->vp_strvalue);
1024 * If there's a default EAP type,
1027 if (t->default_eap_type != 0) {
1028 RDEBUG("Setting default EAP type for tunneled EAP session.");
1029 vp = paircreate(PW_EAP_TYPE,
1031 rad_assert(vp != NULL);
1032 vp->vp_integer = t->default_eap_type;
1033 pairadd(&fake->config_items, vp);
1038 * Don't reject the request outright,
1039 * as it's permitted to do EAP without
1042 RDEBUG2("WARNING! No EAP-Identity found to start EAP conversation.");
1044 } /* else there WAS a t->username */
1047 vp = paircopy(t->username);
1048 pairadd(&fake->packet->vps, vp);
1049 fake->username = pairfind(fake->packet->vps, PW_USER_NAME);
1051 } /* else the request ALREADY had a User-Name */
1054 * Add the State attribute, too, if it exists.
1057 vp = paircopy(t->state);
1058 if (vp) pairadd(&fake->packet->vps, vp);
1062 * If this is set, we copy SOME of the request attributes
1063 * from outside of the tunnel to inside of the tunnel.
1065 * We copy ONLY those attributes which do NOT already
1066 * exist in the tunneled request.
1068 if (t->copy_request_to_tunnel) {
1071 for (vp = request->packet->vps; vp != NULL; vp = vp->next) {
1073 * The attribute is a server-side thingy,
1076 if ((vp->attribute > 255) &&
1077 (((vp->attribute >> 16) & 0xffff) == 0)) {
1082 * The outside attribute is already in the
1083 * tunnel, don't copy it.
1085 * This works for BOTH attributes which
1086 * are originally in the tunneled request,
1087 * AND attributes which are copied there
1090 if (pairfind(fake->packet->vps, vp->attribute)) {
1095 * Some attributes are handled specially.
1097 switch (vp->attribute) {
1099 * NEVER copy Message-Authenticator,
1100 * EAP-Message, or State. They're
1101 * only for outside of the tunnel.
1104 case PW_USER_PASSWORD:
1105 case PW_CHAP_PASSWORD:
1106 case PW_CHAP_CHALLENGE:
1107 case PW_PROXY_STATE:
1108 case PW_MESSAGE_AUTHENTICATOR:
1109 case PW_EAP_MESSAGE:
1115 * By default, copy it over.
1122 * Don't copy from the head, we've already
1125 copy = paircopy2(vp, vp->attribute);
1126 pairadd(&fake->packet->vps, copy);
1130 if ((vp = pairfind(request->config_items, PW_VIRTUAL_SERVER)) != NULL) {
1131 fake->server = vp->vp_strvalue;
1133 } else if (t->virtual_server) {
1134 fake->server = t->virtual_server;
1136 } /* else fake->server == request->server */
1139 if ((debug_flag > 0) && fr_log_fp) {
1140 RDEBUG("Sending tunneled request");
1142 debug_pair_list(fake->packet->vps);
1144 fprintf(fr_log_fp, "server %s {\n",
1145 (fake->server == NULL) ? "" : fake->server);
1149 * Call authentication recursively, which will
1150 * do PAP, CHAP, MS-CHAP, etc.
1152 rad_authenticate(fake);
1155 * Note that we don't do *anything* with the reply
1158 if ((debug_flag > 0) && fr_log_fp) {
1159 fprintf(fr_log_fp, "} # server %s\n",
1160 (fake->server == NULL) ? "" : fake->server);
1162 RDEBUG("Got tunneled reply code %d", fake->reply->code);
1164 debug_pair_list(fake->reply->vps);
1168 * Decide what to do with the reply.
1170 switch (fake->reply->code) {
1171 case 0: /* No reply code, must be proxied... */
1173 vp = pairfind(fake->config_items, PW_PROXY_TO_REALM);
1175 eap_tunnel_data_t *tunnel;
1176 RDEBUG("Tunneled authentication will be proxied to %s", vp->vp_strvalue);
1179 * Tell the original request that it's going
1182 pairmove2(&(request->config_items),
1183 &(fake->config_items),
1187 * Seed the proxy packet with the
1190 rad_assert(request->proxy == NULL);
1191 request->proxy = fake->packet;
1192 memset(&request->proxy->src_ipaddr, 0,
1193 sizeof(request->proxy->src_ipaddr));
1194 memset(&request->proxy->src_ipaddr, 0,
1195 sizeof(request->proxy->src_ipaddr));
1196 request->proxy->src_port = 0;
1197 request->proxy->dst_port = 0;
1198 fake->packet = NULL;
1199 rad_free(&fake->reply);
1203 * Set up the callbacks for the tunnel
1205 tunnel = rad_malloc(sizeof(*tunnel));
1206 memset(tunnel, 0, sizeof(*tunnel));
1208 tunnel->tls_session = tls_session;
1209 tunnel->callback = eapttls_postproxy;
1212 * Associate the callback with the request.
1214 rcode = request_data_add(request,
1216 REQUEST_DATA_EAP_TUNNEL_CALLBACK,
1218 rad_assert(rcode == 0);
1221 * rlm_eap.c has taken care of associating
1222 * the handler with the fake request.
1224 * So we associate the fake request with
1227 rcode = request_data_add(request,
1229 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK,
1230 fake, my_request_free);
1231 rad_assert(rcode == 0);
1235 * Didn't authenticate the packet, but
1236 * we're proxying it.
1238 rcode = PW_STATUS_CLIENT;
1241 #endif /* WITH_PROXY */
1243 RDEBUG("No tunneled reply was found for request %d , and the request was not proxied: rejecting the user.",
1245 rcode = PW_AUTHENTICATION_REJECT;
1251 * Returns RLM_MODULE_FOO, and we want to return
1254 rcode = process_reply(handler, tls_session, request,
1257 case RLM_MODULE_REJECT:
1258 rcode = PW_AUTHENTICATION_REJECT;
1261 case RLM_MODULE_HANDLED:
1262 rcode = PW_ACCESS_CHALLENGE;
1266 rcode = PW_AUTHENTICATION_ACK;
1270 rcode = PW_AUTHENTICATION_REJECT;
1276 request_free(&fake);