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 attribute = (vendor << 16) | attr;
93 da = dict_attrbyvalue(attribute);
96 * SHOULD check ((length & (1 << 30)) != 0)
97 * for the mandatory bit.
100 RDEBUG2("Fatal! Vendor %u, Attribute %u was not found in our dictionary. ",
105 data += 4; /* skip the vendor field */
106 offset += 4; /* offset to value field */
110 * Ignore the M bit. We support all RADIUS attributes...
114 * Get the length. If it's too big, die.
116 length &= 0x00ffffff;
119 * Too short or too long is bad.
121 if (length < offset) {
122 RDEBUG2("Tunneled attribute %d is too short (%d)to contain anything useful.", attr, length);
127 * EAP Messages cane be longer than MAX_STRING_LEN.
128 * Other attributes cannot be.
130 if ((attr != PW_EAP_MESSAGE) &&
131 (length > (MAX_STRING_LEN + 8))) {
132 RDEBUG2("Tunneled attribute %d is too long (%d) to pack into a RADIUS attribute.", attr, length);
136 if (length > data_left) {
137 RDEBUG2("Tunneled attribute %d is longer than room left in the packet (%d > %d).", attr, length, data_left);
142 * Check for broken implementations, which don't
143 * pad the AVP to a 4-octet boundary.
145 if (data_left == length) break;
148 * The length does NOT include the padding, so
149 * we've got to account for it here by rounding up
150 * to the nearest 4-byte boundary.
156 * If the rest of the diameter packet is larger than
157 * this attribute, continue.
159 * Otherwise, if the attribute over-flows the end
160 * of the packet, die.
162 if (data_left < length) {
163 RDEBUG2("ERROR! Diameter attribute overflows packet!");
168 * Check again for equality, now that we're padded
169 * length to a multiple of 4 octets.
171 if (data_left == length) break;
174 * data_left > length, continue.
177 data += length - offset;
181 * We got this far. It looks OK.
188 * Convert diameter attributes to our VALUE_PAIR's
190 static VALUE_PAIR *diameter2vp(REQUEST *request, SSL *ssl,
191 const uint8_t *data, size_t data_len)
197 size_t data_left = data_len;
198 VALUE_PAIR *first = NULL;
199 VALUE_PAIR **last = &first;
202 while (data_left > 0) {
203 rad_assert(data_left <= data_len);
204 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) {
220 memcpy(&vendor, data, sizeof(vendor));
221 vendor = ntohl(vendor);
224 RDEBUG2("Cannot handle vendor attributes greater than 65535");
229 if (vendor > 65535) {
230 RDEBUG2("Cannot handle vendor Id greater than 65535");
235 attr |= (vendor << 16);
237 data += 4; /* skip the vendor field, it's zero */
238 offset += 4; /* offset to value field */
242 * Vendor attributes can be larger than 255.
243 * Normal attributes cannot be.
245 if ((attr > 255) && (VENDOR(attr) == 0)) {
246 RDEBUG2("Cannot handle Diameter attributes");
252 * FIXME: Handle the M bit. For now, we assume that
253 * some other module takes care of any attribute
254 * with the M bit set.
260 length &= 0x00ffffff;
263 * Get the size of the value portion of the
266 size = length - offset;
271 vp = paircreate(attr, PW_TYPE_OCTETS);
273 RDEBUG2("Failure in creating VP");
279 * If it's a type from our dictionary, then
280 * we need to put the data in a relevant place.
283 case PW_TYPE_INTEGER:
285 if (size != vp->length) {
286 RDEBUG2("Invalid length attribute %d",
292 memcpy(&vp->vp_integer, data, vp->length);
295 * Stored in host byte order: change it.
297 vp->vp_integer = ntohl(vp->vp_integer);
301 if (size != vp->length) {
302 RDEBUG2("Invalid length attribute %d",
308 memcpy(&vp->vp_ipaddr, data, vp->length);
311 * Stored in network byte order: don't change it.
316 * String, octet, etc. Copy the data from the
317 * value field over verbatim.
319 * FIXME: Ipv6 attributes ?
323 if (attr == PW_EAP_MESSAGE) {
324 const uint8_t *eap_message = data;
327 * vp exists the first time around.
331 if (vp->length > 253) vp->length = 253;
332 memcpy(vp->vp_octets, eap_message,
336 eap_message += vp->length;
341 if (size == 0) break;
343 vp = paircreate(attr, PW_TYPE_OCTETS);
345 RDEBUG2("Failure in creating VP");
352 } /* else it's another kind of attribute */
357 memcpy(vp->vp_strvalue, data, vp->length);
362 * User-Password is NUL padded to a multiple
363 * of 16 bytes. Let's chop it to something
366 * NOTE: This means that the User-Password
367 * attribute CANNOT EVER have embedded zeros in it!
369 switch (vp->attribute) {
370 case PW_USER_PASSWORD:
372 * If the password is exactly 16 octets,
373 * it won't be zero-terminated.
375 vp->vp_strvalue[vp->length] = '\0';
376 vp->length = strlen(vp->vp_strvalue);
380 * Ensure that the client is using the
381 * correct challenge. This weirdness is
382 * to protect against against replay
383 * attacks, where anyone observing the
384 * CHAP exchange could pose as that user,
385 * by simply choosing to use the same
388 * By using a challenge based on
389 * information from the current session,
390 * we can guarantee that the client is
391 * not *choosing* a challenge.
393 * We're a little forgiving in that we
394 * have loose checks on the length, and
395 * we do NOT check the Id (first octet of
396 * the response to the challenge)
398 * But if the client gets the challenge correct,
399 * we're not too worried about the Id.
401 case PW_CHAP_CHALLENGE:
402 case PW_MSCHAP_CHALLENGE:
403 if ((vp->length < 8) ||
405 RDEBUG("Tunneled challenge has invalid length");
411 uint8_t challenge[16];
413 eapttls_gen_challenge(ssl, challenge,
416 if (memcmp(challenge, vp->vp_octets,
418 RDEBUG("Tunneled challenge is incorrect");
428 } /* switch over checking/re-writing of attributes. */
438 * Catch non-aligned attributes.
440 if (data_left == length) break;
443 * The length does NOT include the padding, so
444 * we've got to account for it here by rounding up
445 * to the nearest 4-byte boundary.
450 rad_assert(data_left >= length);
452 data += length - offset; /* already updated */
456 * We got this far. It looks OK.
462 * Convert VALUE_PAIR's to diameter attributes, and write them
465 * The ONLY VALUE_PAIR's which may be passed to this function
466 * are ones which can go inside of a RADIUS (i.e. diameter)
467 * packet. So no server-configuration attributes, or the like.
469 static int vp2diameter(REQUEST *request, tls_session_t *tls_session, VALUE_PAIR *first)
472 * RADIUS packets are no more than 4k in size, so if
473 * we've got more than 4k of data to write, it's very
476 uint8_t buffer[4096];
487 for (vp = first; vp != NULL; vp = vp->next) {
489 * Too much data: die.
491 if ((total + vp->length + 12) >= sizeof(buffer)) {
492 RDEBUG2("output buffer is full!");
497 * Hmm... we don't group multiple EAP-Messages
498 * together. Maybe we should...
502 * Length is no more than 253, due to RADIUS
506 vendor = (vp->attribute >> 16) & 0xffff;
508 attr = vp->attribute & 0xffff;
511 attr = vp->attribute;
515 * Hmm... set the M bit for all attributes?
521 memcpy(p, &attr, sizeof(attr));
525 length += 8; /* includes 8 bytes of attr & length */
528 length += 4; /* include 4 bytes of vendor */
530 length = ntohl(length);
531 memcpy(p, &length, sizeof(length));
535 vendor = ntohl(vendor);
536 memcpy(p, &vendor, sizeof(vendor));
540 length = ntohl(length);
541 memcpy(p, &length, sizeof(length));
547 case PW_TYPE_INTEGER:
549 attr = ntohl(vp->vp_integer); /* stored in host order */
550 memcpy(p, &attr, sizeof(attr));
555 memcpy(p, &vp->vp_ipaddr, 4); /* network order */
562 memcpy(p, vp->vp_strvalue, vp->length);
568 * Skip to the end of the data.
574 * Align the data to a multiple of 4 bytes.
576 if ((total & 0x03) != 0) {
579 length = 4 - (total & 0x03);
580 for (i = 0; i < length; i++) {
586 } /* loop over the VP's to write. */
589 * Write the data in the buffer to the SSL session.
595 if ((debug_flag > 2) && fr_log_fp) {
596 for (i = 0; i < total; i++) {
597 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data out %04x: ", (int) i);
599 fprintf(fr_log_fp, "%02x ", buffer[i]);
601 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
603 if ((total & 0x0f) != 0) fprintf(fr_log_fp, "\n");
607 (tls_session->record_plus)(&tls_session->clean_in, buffer, total);
610 * FIXME: Check the return code.
612 tls_handshake_send(tls_session);
622 * Use a reply packet to determine what to do.
624 static int process_reply(EAP_HANDLER *handler, tls_session_t *tls_session,
625 REQUEST *request, RADIUS_PACKET *reply)
627 int rcode = RLM_MODULE_REJECT;
629 ttls_tunnel_t *t = tls_session->opaque;
631 handler = handler; /* -Wunused */
634 * If the response packet was Access-Accept, then
635 * we're OK. If not, die horribly.
637 * FIXME: Take MS-CHAP2-Success attribute, and
638 * tunnel it back to the client, to authenticate
639 * ourselves to the client.
641 * FIXME: If we have an Access-Challenge, then
642 * the Reply-Message is tunneled back to the client.
644 * FIXME: If we have an EAP-Message, then that message
645 * must be tunneled back to the client.
647 * FIXME: If we have an Access-Challenge with a State
648 * attribute, then do we tunnel that to the client, or
649 * keep track of it ourselves?
651 * FIXME: EAP-Messages can only start with 'identity',
652 * NOT 'eap start', so we should check for that....
654 switch (reply->code) {
655 case PW_AUTHENTICATION_ACK:
656 RDEBUG("Got tunneled Access-Accept");
658 rcode = RLM_MODULE_OK;
661 * MS-CHAP2-Success means that we do NOT return
662 * an Access-Accept, but instead tunnel that
663 * attribute to the client, and keep going with
664 * the TTLS session. Once the client accepts
665 * our identity, it will respond with an empty
666 * packet, and we will send EAP-Success.
669 pairmove2(&vp, &reply->vps, PW_MSCHAP2_SUCCESS);
671 RDEBUG("Got MS-CHAP2-Success, tunneling it to the client in a challenge.");
672 rcode = RLM_MODULE_HANDLED;
673 t->authenticated = TRUE;
676 * Delete MPPE keys & encryption policy. We don't
679 pairdelete(&reply->vps, ((311 << 16) | 7));
680 pairdelete(&reply->vps, ((311 << 16) | 8));
681 pairdelete(&reply->vps, ((311 << 16) | 16));
682 pairdelete(&reply->vps, ((311 << 16) | 17));
685 * Use the tunneled reply, but not now.
687 if (t->use_tunneled_reply) {
688 t->accept_vps = reply->vps;
692 } else { /* no MS-CHAP2-Success */
694 * Can only have EAP-Message if there's
695 * no MS-CHAP2-Success. (FIXME: EAP-MSCHAP?)
697 * We also do NOT tunnel the EAP-Success
698 * attribute back to the client, as the client
699 * can figure it out, from the non-tunneled
700 * EAP-Success packet.
702 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
707 * Handle the ACK, by tunneling any necessary reply
708 * VP's back to the client.
711 vp2diameter(request, tls_session, vp);
716 * If we've been told to use the attributes from
717 * the reply, then do so.
719 * WARNING: This may leak information about the
722 if (t->use_tunneled_reply) {
723 pairdelete(&reply->vps, PW_PROXY_STATE);
724 pairadd(&request->reply->vps, reply->vps);
730 case PW_AUTHENTICATION_REJECT:
731 RDEBUG("Got tunneled Access-Reject");
732 rcode = RLM_MODULE_REJECT;
736 * Handle Access-Challenge, but only if we
737 * send tunneled reply data. This is because
738 * an Access-Challenge means that we MUST tunnel
739 * a Reply-Message to the client.
741 case PW_ACCESS_CHALLENGE:
742 RDEBUG("Got tunneled Access-Challenge");
745 * Keep the State attribute, if necessary.
747 * Get rid of the old State, too.
750 pairmove2(&t->state, &reply->vps, PW_STATE);
753 * We should really be a bit smarter about this,
754 * and move over only those attributes which
755 * are relevant to the authentication request,
756 * but that's a lot more work, and this "dumb"
757 * method works in 99.9% of the situations.
760 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
763 * There MUST be a Reply-Message in the challenge,
764 * which we tunnel back to the client.
766 * If there isn't one in the reply VP's, then
767 * we MUST create one, with an empty string as
770 pairmove2(&vp, &reply->vps, PW_REPLY_MESSAGE);
773 * Handle the ACK, by tunneling any necessary reply
774 * VP's back to the client.
777 vp2diameter(request, tls_session, vp);
780 rcode = RLM_MODULE_HANDLED;
784 RDEBUG("Unknown RADIUS packet type %d: rejecting tunneled user", reply->code);
785 rcode = RLM_MODULE_INVALID;
795 * Do post-proxy processing,
797 static int eapttls_postproxy(EAP_HANDLER *handler, void *data)
800 tls_session_t *tls_session = (tls_session_t *) data;
801 REQUEST *fake, *request = handler->request;
803 RDEBUG("Passing reply from proxy back into the tunnel.");
806 * If there was a fake request associated with the proxied
807 * request, do more processing of it.
809 fake = (REQUEST *) request_data_get(handler->request,
810 handler->request->proxy,
811 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK);
814 * Do the callback, if it exists, and if it was a success.
816 if (fake && (handler->request->proxy_reply->code == PW_AUTHENTICATION_ACK)) {
820 rad_assert(fake->packet == NULL);
821 fake->packet = request->proxy;
822 fake->packet->src_ipaddr = request->packet->src_ipaddr;
823 request->proxy = NULL;
825 rad_assert(fake->reply == NULL);
826 fake->reply = request->proxy_reply;
827 request->proxy_reply = NULL;
829 if ((debug_flag > 0) && fr_log_fp) {
830 fprintf(fr_log_fp, "server %s {\n",
831 (fake->server == NULL) ? "" : fake->server);
835 * Perform a post-auth stage for the tunneled
838 fake->options &= ~RAD_REQUEST_OPTION_PROXY_EAP;
839 rcode = rad_postauth(fake);
840 RDEBUG2("post-auth returns %d", rcode);
842 if ((debug_flag > 0) && fr_log_fp) {
843 fprintf(fr_log_fp, "} # server %s\n",
844 (fake->server == NULL) ? "" : fake->server);
846 RDEBUG("Final reply from tunneled session code %d",
848 debug_pair_list(fake->reply->vps);
854 request->proxy = fake->packet;
856 request->proxy_reply = fake->reply;
860 * And we're done with this request.
864 case RLM_MODULE_FAIL:
866 eaptls_fail(handler, 0);
870 default: /* Don't Do Anything */
871 RDEBUG2("sGot reply %d",
872 request->proxy_reply->code);
876 request_free(&fake); /* robust if fake == NULL */
879 * Process the reply from the home server.
881 rcode = process_reply(handler, tls_session, handler->request,
882 handler->request->proxy_reply);
885 * The proxy code uses the reply from the home server as
886 * the basis for the reply to the NAS. We don't want that,
887 * so we toss it, after we've had our way with it.
889 pairfree(&handler->request->proxy_reply->vps);
892 case RLM_MODULE_REJECT:
893 RDEBUG("Reply was rejected");
896 case RLM_MODULE_HANDLED:
897 RDEBUG("Reply was handled");
898 eaptls_request(handler->eap_ds, tls_session);
902 RDEBUG("Reply was OK");
905 * Success: Automatically return MPPE keys.
907 return eaptls_success(handler, 0);
910 RDEBUG("Reply was unknown.");
914 eaptls_fail(handler, 0);
922 static void my_request_free(void *data)
924 REQUEST *request = (REQUEST *)data;
926 request_free(&request);
928 #endif /* WITH_PROXY */
931 * Process the "diameter" contents of the tunneled data.
933 int eapttls_process(EAP_HANDLER *handler, tls_session_t *tls_session)
935 int rcode = PW_AUTHENTICATION_REJECT;
941 REQUEST *request = handler->request;
944 * Just look at the buffer directly, without doing
947 data_len = tls_session->clean_out.used;
948 tls_session->clean_out.used = 0;
949 data = tls_session->clean_out.data;
951 t = (ttls_tunnel_t *) tls_session->opaque;
954 * If there's no data, maybe this is an ACK to an
958 if (t->authenticated) {
959 RDEBUG("Got ACK, and the user was already authenticated.");
960 return PW_AUTHENTICATION_ACK;
961 } /* else no session, no data, die. */
964 * FIXME: Call SSL_get_error() to see what went
967 RDEBUG2("SSL_read Error");
968 return PW_AUTHENTICATION_REJECT;
972 if ((debug_flag > 2) && fr_log_fp) {
975 for (i = 0; i < data_len; i++) {
976 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " TTLS tunnel data in %04x: ", (int) i);
978 fprintf(fr_log_fp, "%02x ", data[i]);
980 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
982 if ((data_len & 0x0f) != 0) fprintf(fr_log_fp, "\n");
986 if (!diameter_verify(request, data, data_len)) {
987 return PW_AUTHENTICATION_REJECT;
991 * Allocate a fake REQUEST structe.
993 fake = request_alloc_fake(request);
995 rad_assert(fake->packet->vps == NULL);
998 * Add the tunneled attributes to the fake request.
1000 fake->packet->vps = diameter2vp(request, tls_session->ssl, data, data_len);
1001 if (!fake->packet->vps) {
1002 request_free(&fake);
1003 return PW_AUTHENTICATION_REJECT;
1007 * Tell the request that it's a fake one.
1009 vp = pairmake("Freeradius-Proxied-To", "127.0.0.1", T_OP_EQ);
1011 pairadd(&fake->packet->vps, vp);
1014 if ((debug_flag > 0) && fr_log_fp) {
1015 RDEBUG("Got tunneled request");
1017 debug_pair_list(fake->packet->vps);
1021 * Update other items in the REQUEST data structure.
1023 fake->username = pairfind(fake->packet->vps, PW_USER_NAME, 0);
1024 fake->password = pairfind(fake->packet->vps, PW_USER_PASSWORD, 0);
1027 * No User-Name, try to create one from stored data.
1029 if (!fake->username) {
1031 * No User-Name in the stored data, look for
1032 * an EAP-Identity, and pull it out of there.
1035 vp = pairfind(fake->packet->vps, PW_EAP_MESSAGE, 0);
1037 (vp->length >= EAP_HEADER_LEN + 2) &&
1038 (vp->vp_strvalue[0] == PW_EAP_RESPONSE) &&
1039 (vp->vp_strvalue[EAP_HEADER_LEN] == PW_EAP_IDENTITY) &&
1040 (vp->vp_strvalue[EAP_HEADER_LEN + 1] != 0)) {
1042 * Create & remember a User-Name
1044 t->username = pairmake("User-Name", "", T_OP_EQ);
1045 rad_assert(t->username != NULL);
1047 memcpy(t->username->vp_strvalue, vp->vp_strvalue + 5,
1049 t->username->length = vp->length - 5;
1050 t->username->vp_strvalue[t->username->length] = 0;
1052 RDEBUG("Got tunneled identity of %s",
1053 t->username->vp_strvalue);
1056 * If there's a default EAP type,
1059 if (t->default_eap_type != 0) {
1060 RDEBUG("Setting default EAP type for tunneled EAP session.");
1061 vp = paircreate(PW_EAP_TYPE,
1063 rad_assert(vp != NULL);
1064 vp->vp_integer = t->default_eap_type;
1065 pairadd(&fake->config_items, vp);
1070 * Don't reject the request outright,
1071 * as it's permitted to do EAP without
1074 RDEBUG2("WARNING! No EAP-Identity found to start EAP conversation.");
1076 } /* else there WAS a t->username */
1079 vp = paircopy(t->username);
1080 pairadd(&fake->packet->vps, vp);
1081 fake->username = pairfind(fake->packet->vps, PW_USER_NAME, 0);
1083 } /* else the request ALREADY had a User-Name */
1086 * Add the State attribute, too, if it exists.
1089 vp = paircopy(t->state);
1090 if (vp) pairadd(&fake->packet->vps, vp);
1094 * If this is set, we copy SOME of the request attributes
1095 * from outside of the tunnel to inside of the tunnel.
1097 * We copy ONLY those attributes which do NOT already
1098 * exist in the tunneled request.
1100 if (t->copy_request_to_tunnel) {
1103 for (vp = request->packet->vps; vp != NULL; vp = vp->next) {
1105 * The attribute is a server-side thingy,
1108 if ((vp->attribute > 255) &&
1109 (((vp->attribute >> 16) & 0xffff) == 0)) {
1114 * The outside attribute is already in the
1115 * tunnel, don't copy it.
1117 * This works for BOTH attributes which
1118 * are originally in the tunneled request,
1119 * AND attributes which are copied there
1122 if (pairfind(fake->packet->vps, vp->attribute)) {
1127 * Some attributes are handled specially.
1129 switch (vp->attribute) {
1131 * NEVER copy Message-Authenticator,
1132 * EAP-Message, or State. They're
1133 * only for outside of the tunnel.
1136 case PW_USER_PASSWORD:
1137 case PW_CHAP_PASSWORD:
1138 case PW_CHAP_CHALLENGE:
1139 case PW_PROXY_STATE:
1140 case PW_MESSAGE_AUTHENTICATOR:
1141 case PW_EAP_MESSAGE:
1147 * By default, copy it over.
1154 * Don't copy from the head, we've already
1157 copy = paircopy2(vp, vp->attribute);
1158 pairadd(&fake->packet->vps, copy);
1162 if ((vp = pairfind(request->config_items, PW_VIRTUAL_SERVER, 0)) != NULL) {
1163 fake->server = vp->vp_strvalue;
1165 } else if (t->virtual_server) {
1166 fake->server = t->virtual_server;
1168 } /* else fake->server == request->server */
1171 if ((debug_flag > 0) && fr_log_fp) {
1172 RDEBUG("Sending tunneled request");
1174 debug_pair_list(fake->packet->vps);
1176 fprintf(fr_log_fp, "server %s {\n",
1177 (fake->server == NULL) ? "" : fake->server);
1181 * Call authentication recursively, which will
1182 * do PAP, CHAP, MS-CHAP, etc.
1184 rad_authenticate(fake);
1187 * Note that we don't do *anything* with the reply
1190 if ((debug_flag > 0) && fr_log_fp) {
1191 fprintf(fr_log_fp, "} # server %s\n",
1192 (fake->server == NULL) ? "" : fake->server);
1194 RDEBUG("Got tunneled reply code %d", fake->reply->code);
1196 debug_pair_list(fake->reply->vps);
1200 * Decide what to do with the reply.
1202 switch (fake->reply->code) {
1203 case 0: /* No reply code, must be proxied... */
1205 vp = pairfind(fake->config_items, PW_PROXY_TO_REALM, 0);
1207 eap_tunnel_data_t *tunnel;
1208 RDEBUG("Tunneled authentication will be proxied to %s", vp->vp_strvalue);
1211 * Tell the original request that it's going
1214 pairmove2(&(request->config_items),
1215 &(fake->config_items),
1219 * Seed the proxy packet with the
1222 rad_assert(request->proxy == NULL);
1223 request->proxy = fake->packet;
1224 fake->packet = NULL;
1225 rad_free(&fake->reply);
1229 * Set up the callbacks for the tunnel
1231 tunnel = rad_malloc(sizeof(*tunnel));
1232 memset(tunnel, 0, sizeof(*tunnel));
1234 tunnel->tls_session = tls_session;
1235 tunnel->callback = eapttls_postproxy;
1238 * Associate the callback with the request.
1240 rcode = request_data_add(request,
1242 REQUEST_DATA_EAP_TUNNEL_CALLBACK,
1244 rad_assert(rcode == 0);
1247 * rlm_eap.c has taken care of associating
1248 * the handler with the fake request.
1250 * So we associate the fake request with
1253 rcode = request_data_add(request,
1255 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK,
1256 fake, my_request_free);
1257 rad_assert(rcode == 0);
1261 * Didn't authenticate the packet, but
1262 * we're proxying it.
1264 rcode = PW_STATUS_CLIENT;
1267 #endif /* WITH_PROXY */
1269 RDEBUG("No tunneled reply was found for request %d , and the request was not proxied: rejecting the user.",
1271 rcode = PW_AUTHENTICATION_REJECT;
1277 * Returns RLM_MODULE_FOO, and we want to return
1280 rcode = process_reply(handler, tls_session, request,
1283 case RLM_MODULE_REJECT:
1284 rcode = PW_AUTHENTICATION_REJECT;
1287 case RLM_MODULE_HANDLED:
1288 rcode = PW_ACCESS_CHALLENGE;
1292 rcode = PW_AUTHENTICATION_ACK;
1296 rcode = PW_AUTHENTICATION_REJECT;
1302 request_free(&fake);