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(const uint8_t *data, unsigned int data_len)
51 unsigned int data_left = data_len;
53 while (data_left > 0) {
55 DEBUG2(" rlm_eap_ttls: Diameter attribute is too small to contain a Diameter header");
59 rad_assert(data_left <= data_len);
60 memcpy(&attr, data, sizeof(attr));
64 DEBUG2(" rlm_eap_ttls: Non-RADIUS attribute in tunneled authentication is not supported");
68 memcpy(&length, data , sizeof(length));
70 length = ntohl(length);
73 * A "vendor" flag, with a vendor ID of zero,
74 * is equivalent to no vendor. This is stupid.
77 if ((length & (1 << 31)) != 0) {
82 memcpy(&vendor, data, sizeof(vendor));
83 vendor = ntohl(vendor);
86 DEBUG2(" rlm_eap_ttls: Vendor codes larger than 65535 are not supported");
90 attribute = (vendor << 16) | attr;
92 da = dict_attrbyvalue(attribute);
95 * SHOULD check ((length & (1 << 30)) != 0)
96 * for the mandatory bit.
99 DEBUG2(" rlm_eap_ttls: Fatal! Vendor %u, Attribute %u was not found in our dictionary. ",
104 data += 4; /* skip the vendor field */
105 offset += 4; /* offset to value field */
109 * Ignore the M bit. We support all RADIUS attributes...
113 * Get the length. If it's too big, die.
115 length &= 0x00ffffff;
118 * Too short or too long is bad.
120 if (length < offset) {
121 DEBUG2(" rlm_eap_ttls: Tunneled attribute %d is too short (%d)to contain anything useful.", attr, length);
126 * EAP Messages cane be longer than MAX_STRING_LEN.
127 * Other attributes cannot be.
129 if ((attr != PW_EAP_MESSAGE) &&
130 (length > (MAX_STRING_LEN + 8))) {
131 DEBUG2(" rlm_eap_ttls: Tunneled attribute %d is too long (%d) to pack into a RADIUS attribute.", attr, length);
135 if (length > data_left) {
136 DEBUG2(" rlm_eap_ttls: Tunneled attribute %d is longer than room left in the packet (%d > %d).", attr, length, data_left);
141 * Check for broken implementations, which don't
142 * pad the AVP to a 4-octet boundary.
144 if (data_left == length) break;
147 * The length does NOT include the padding, so
148 * we've got to account for it here by rounding up
149 * to the nearest 4-byte boundary.
155 * If the rest of the diameter packet is larger than
156 * this attribute, continue.
158 * Otherwise, if the attribute over-flows the end
159 * of the packet, die.
161 if (data_left < length) {
162 DEBUG2(" rlm_eap_ttls: ERROR! Diameter attribute overflows packet!");
167 * Check again for equality, now that we're padded
168 * length to a multiple of 4 octets.
170 if (data_left == length) break;
173 * data_left > length, continue.
176 data += length - offset;
180 * We got this far. It looks OK.
187 * Convert diameter attributes to our VALUE_PAIR's
189 static VALUE_PAIR *diameter2vp(SSL *ssl,
190 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));
207 memcpy(&length, data, sizeof(length));
209 length = ntohl(length);
212 * A "vendor" flag, with a vendor ID of zero,
213 * is equivalent to no vendor. This is stupid.
216 if ((length & (1 << 31)) != 0) {
219 memcpy(&vendor, data, sizeof(vendor));
220 vendor = ntohl(vendor);
223 DEBUG2(" rlm_eap_ttls: Cannot handle vendor attributes greater than 65535");
228 if (vendor > 32767) {
229 DEBUG2(" rlm_eap_ttls: Cannot handle vendor Id greater than 32767");
234 attr |= (vendor << 16);
236 data += 4; /* skip the vendor field, it's zero */
237 offset += 4; /* offset to value field */
241 * Vendor attributes can be larger than 255.
242 * Normal attributes cannot be.
244 if ((attr > 255) && (VENDOR(attr) == 0)) {
245 DEBUG2(" rlm_eap_ttls: Cannot handle Diameter attributes");
251 * FIXME: Handle the M bit. For now, we assume that
252 * some other module takes care of any attribute
253 * with the M bit set.
259 length &= 0x00ffffff;
262 * Get the size of the value portion of the
265 size = length - offset;
270 vp = paircreate(attr, PW_TYPE_OCTETS);
272 DEBUG2(" rlm_eap_ttls: Failure in creating VP");
278 * If it's a type from our dictionary, then
279 * we need to put the data in a relevant place.
282 case PW_TYPE_INTEGER:
284 if (size != vp->length) {
285 DEBUG2(" rlm_eap_ttls: Invalid length attribute %d",
291 memcpy(&vp->vp_integer, data, vp->length);
294 * Stored in host byte order: change it.
296 vp->vp_integer = ntohl(vp->vp_integer);
300 if (size != vp->length) {
301 DEBUG2(" rlm_eap_ttls: Invalid length attribute %d",
307 memcpy(&vp->vp_ipaddr, data, vp->length);
310 * Stored in network byte order: don't change it.
315 * String, octet, etc. Copy the data from the
316 * value field over verbatim.
318 * FIXME: Ipv6 attributes ?
322 if (attr == PW_EAP_MESSAGE) {
323 const uint8_t *eap_message = data;
326 * vp exists the first time around.
330 if (vp->length > 253) vp->length = 253;
331 memcpy(vp->vp_octets, eap_message,
335 eap_message += vp->length;
340 if (size == 0) break;
342 vp = paircreate(attr, PW_TYPE_OCTETS);
344 DEBUG2(" rlm_eap_ttls: Failure in creating VP");
351 } /* else it's another kind of attribute */
356 memcpy(vp->vp_strvalue, data, vp->length);
361 * User-Password is NUL padded to a multiple
362 * of 16 bytes. Let's chop it to something
365 * NOTE: This means that the User-Password
366 * attribute CANNOT EVER have embedded zeros in it!
368 switch (vp->attribute) {
369 case PW_USER_PASSWORD:
371 * If the password is exactly 16 octets,
372 * it won't be zero-terminated.
374 vp->vp_strvalue[vp->length] = '\0';
375 vp->length = strlen(vp->vp_strvalue);
379 * Ensure that the client is using the
380 * correct challenge. This weirdness is
381 * to protect against against replay
382 * attacks, where anyone observing the
383 * CHAP exchange could pose as that user,
384 * by simply choosing to use the same
387 * By using a challenge based on
388 * information from the current session,
389 * we can guarantee that the client is
390 * not *choosing* a challenge.
392 * We're a little forgiving in that we
393 * have loose checks on the length, and
394 * we do NOT check the Id (first octet of
395 * the response to the challenge)
397 * But if the client gets the challenge correct,
398 * we're not too worried about the Id.
400 case PW_CHAP_CHALLENGE:
401 case PW_MSCHAP_CHALLENGE:
402 if ((vp->length < 8) ||
404 DEBUG2(" TTLS: Tunneled challenge has invalid length");
410 uint8_t challenge[16];
412 eapttls_gen_challenge(ssl, challenge,
415 if (memcmp(challenge, vp->vp_octets,
417 DEBUG2(" TTLS: Tunneled challenge is incorrect");
427 } /* switch over checking/re-writing of attributes. */
437 * Catch non-aligned attributes.
439 if (data_left == length) break;
442 * The length does NOT include the padding, so
443 * we've got to account for it here by rounding up
444 * to the nearest 4-byte boundary.
449 rad_assert(data_left >= length);
451 data += length - offset; /* already updated */
455 * We got this far. It looks OK.
461 * Convert VALUE_PAIR's to diameter attributes, and write them
464 * The ONLY VALUE_PAIR's which may be passed to this function
465 * are ones which can go inside of a RADIUS (i.e. diameter)
466 * packet. So no server-configuration attributes, or the like.
468 static int vp2diameter(tls_session_t *tls_session, VALUE_PAIR *first)
471 * RADIUS packets are no more than 4k in size, so if
472 * we've got more than 4k of data to write, it's very
475 uint8_t buffer[4096];
486 for (vp = first; vp != NULL; vp = vp->next) {
488 * Too much data: die.
490 if ((total + vp->length + 12) >= sizeof(buffer)) {
491 DEBUG2(" TTLS output buffer is full!");
496 * Hmm... we don't group multiple EAP-Messages
497 * together. Maybe we should...
501 * Length is no more than 253, due to RADIUS
505 vendor = (vp->attribute >> 16) & 0xffff;
507 attr = vp->attribute & 0xffff;
510 attr = vp->attribute;
514 * Hmm... set the M bit for all attributes?
520 memcpy(p, &attr, sizeof(attr));
524 length += 8; /* includes 8 bytes of attr & length */
527 length += 4; /* include 4 bytes of vendor */
529 length = ntohl(length);
530 memcpy(p, &length, sizeof(length));
534 vendor = ntohl(vendor);
535 memcpy(p, &vendor, sizeof(vendor));
539 length = ntohl(length);
540 memcpy(p, &length, sizeof(length));
546 case PW_TYPE_INTEGER:
548 attr = ntohl(vp->vp_integer); /* stored in host order */
549 memcpy(p, &attr, sizeof(attr));
554 memcpy(p, &vp->vp_ipaddr, 4); /* network order */
561 memcpy(p, vp->vp_strvalue, vp->length);
567 * Skip to the end of the data.
573 * Align the data to a multiple of 4 bytes.
575 if ((total & 0x03) != 0) {
578 length = 4 - (total & 0x03);
579 for (i = 0; i < length; i++) {
585 } /* loop over the VP's to write. */
588 * Write the data in the buffer to the SSL session.
594 if (debug_flag > 2) {
595 for (i = 0; i < total; i++) {
596 if ((i & 0x0f) == 0) printf(" TTLS tunnel data out %04x: ", i);
598 printf("%02x ", buffer[i]);
600 if ((i & 0x0f) == 0x0f) printf("\n");
602 if ((total & 0x0f) != 0) printf("\n");
606 (tls_session->record_plus)(&tls_session->clean_in, buffer, total);
609 * FIXME: Check the return code.
611 tls_handshake_send(tls_session);
621 * Use a reply packet to determine what to do.
623 static int process_reply(EAP_HANDLER *handler, tls_session_t *tls_session,
624 REQUEST *request, RADIUS_PACKET *reply)
626 int rcode = RLM_MODULE_REJECT;
628 ttls_tunnel_t *t = tls_session->opaque;
630 handler = handler; /* -Wunused */
633 * If the response packet was Access-Accept, then
634 * we're OK. If not, die horribly.
636 * FIXME: Take MS-CHAP2-Success attribute, and
637 * tunnel it back to the client, to authenticate
638 * ourselves to the client.
640 * FIXME: If we have an Access-Challenge, then
641 * the Reply-Message is tunneled back to the client.
643 * FIXME: If we have an EAP-Message, then that message
644 * must be tunneled back to the client.
646 * FIXME: If we have an Access-Challenge with a State
647 * attribute, then do we tunnel that to the client, or
648 * keep track of it ourselves?
650 * FIXME: EAP-Messages can only start with 'identity',
651 * NOT 'eap start', so we should check for that....
653 switch (reply->code) {
654 case PW_AUTHENTICATION_ACK:
655 DEBUG2(" TTLS: Got tunneled Access-Accept");
657 rcode = RLM_MODULE_OK;
660 * MS-CHAP2-Success means that we do NOT return
661 * an Access-Accept, but instead tunnel that
662 * attribute to the client, and keep going with
663 * the TTLS session. Once the client accepts
664 * our identity, it will respond with an empty
665 * packet, and we will send EAP-Success.
668 pairmove2(&vp, &reply->vps, PW_MSCHAP2_SUCCESS);
670 DEBUG2(" TTLS: Got MS-CHAP2-Success, tunneling it to the client in a challenge.");
671 rcode = RLM_MODULE_HANDLED;
672 t->authenticated = TRUE;
675 * Delete MPPE keys & encryption policy. We don't
678 pairdelete(&reply->vps, ((311 << 16) | 7));
679 pairdelete(&reply->vps, ((311 << 16) | 8));
680 pairdelete(&reply->vps, ((311 << 16) | 16));
681 pairdelete(&reply->vps, ((311 << 16) | 17));
684 * Use the tunneled reply, but not now.
686 if (t->use_tunneled_reply) {
687 t->reply = reply->vps;
691 } else { /* no MS-CHAP2-Success */
693 * Can only have EAP-Message if there's
694 * no MS-CHAP2-Success. (FIXME: EAP-MSCHAP?)
696 * We also do NOT tunnel the EAP-Success
697 * attribute back to the client, as the client
698 * can figure it out, from the non-tunneled
699 * EAP-Success packet.
701 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
706 * Handle the ACK, by tunneling any necessary reply
707 * VP's back to the client.
710 vp2diameter(tls_session, vp);
715 * If we've been told to use the attributes from
716 * the reply, then do so.
718 * WARNING: This may leak information about the
721 if (t->use_tunneled_reply) {
722 pairdelete(&reply->vps, PW_PROXY_STATE);
723 pairadd(&request->reply->vps, reply->vps);
729 case PW_AUTHENTICATION_REJECT:
730 DEBUG2(" TTLS: Got tunneled Access-Reject");
731 rcode = RLM_MODULE_REJECT;
735 * Handle Access-Challenge, but only if we
736 * send tunneled reply data. This is because
737 * an Access-Challenge means that we MUST tunnel
738 * a Reply-Message to the client.
740 case PW_ACCESS_CHALLENGE:
741 DEBUG2(" TTLS: Got tunneled Access-Challenge");
744 * Keep the State attribute, if necessary.
746 * Get rid of the old State, too.
749 pairmove2(&t->state, &reply->vps, PW_STATE);
752 * We should really be a bit smarter about this,
753 * and move over only those attributes which
754 * are relevant to the authentication request,
755 * but that's a lot more work, and this "dumb"
756 * method works in 99.9% of the situations.
759 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
762 * There MUST be a Reply-Message in the challenge,
763 * which we tunnel back to the client.
765 * If there isn't one in the reply VP's, then
766 * we MUST create one, with an empty string as
769 pairmove2(&vp, &reply->vps, PW_REPLY_MESSAGE);
772 * Handle the ACK, by tunneling any necessary reply
773 * VP's back to the client.
776 vp2diameter(tls_session, vp);
779 rcode = RLM_MODULE_HANDLED;
783 DEBUG2(" TTLS: Unknown RADIUS packet type %d: rejecting tunneled user", reply->code);
784 rcode = RLM_MODULE_INVALID;
793 * Do post-proxy processing,
795 static int eapttls_postproxy(EAP_HANDLER *handler, void *data)
798 tls_session_t *tls_session = (tls_session_t *) data;
801 DEBUG2(" TTLS: Passing reply from proxy back into the tunnel.");
804 * If there was a fake request associated with the proxied
805 * request, do more processing of it.
807 fake = (REQUEST *) request_data_get(handler->request,
808 handler->request->proxy,
809 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK);
812 * Do the callback, if it exists, and if it was a success.
814 if (fake && (handler->request->proxy_reply->code == PW_AUTHENTICATION_ACK)) {
816 REQUEST *request = handler->request;
821 rad_assert(fake->packet == NULL);
822 fake->packet = request->proxy;
823 request->proxy = NULL;
825 rad_assert(fake->reply == NULL);
826 fake->reply = request->proxy_reply;
827 request->proxy_reply = NULL;
830 * Perform a post-auth stage for the tunneled
833 fake->options &= ~RAD_REQUEST_OPTION_PROXY_EAP;
834 rcode = rad_postauth(fake);
835 DEBUG2(" POST-AUTH %d", rcode);
838 if (debug_flag > 0) {
839 printf(" TTLS: Final reply from tunneled session code %d\n",
842 for (vp = fake->reply->vps; vp != NULL; vp = vp->next) {
843 putchar('\t');vp_print(stdout, vp);putchar('\n');
851 request->proxy = fake->packet;
853 request->proxy_reply = fake->reply;
857 * And we're done with this request.
861 case RLM_MODULE_FAIL:
863 eaptls_fail(handler->eap_ds, 0);
867 default: /* Don't Do Anything */
868 DEBUG2(" TTLS: Got reply %d",
869 request->proxy_reply->code);
873 request_free(&fake); /* robust if fake == NULL */
876 * Process the reply from the home server.
878 rcode = process_reply(handler, tls_session, handler->request,
879 handler->request->proxy_reply);
882 * The proxy code uses the reply from the home server as
883 * the basis for the reply to the NAS. We don't want that,
884 * so we toss it, after we've had our way with it.
886 pairfree(&handler->request->proxy_reply->vps);
889 case RLM_MODULE_REJECT:
890 DEBUG2(" TTLS: Reply was rejected");
893 case RLM_MODULE_HANDLED:
894 DEBUG2(" TTLS: Reply was handled");
895 eaptls_request(handler->eap_ds, tls_session);
899 DEBUG2(" TTLS: Reply was OK");
900 eaptls_success(handler->eap_ds, 0);
901 eaptls_gen_mppe_keys(&handler->request->reply->vps,
903 "ttls keying material");
907 DEBUG2(" TTLS: Reply was unknown.");
911 eaptls_fail(handler->eap_ds, 0);
919 static void my_request_free(void *data)
921 REQUEST *request = (REQUEST *)data;
923 request_free(&request);
928 * Process the "diameter" contents of the tunneled data.
930 int eapttls_process(EAP_HANDLER *handler, tls_session_t *tls_session)
933 int rcode = PW_AUTHENTICATION_REJECT;
939 REQUEST *request = handler->request;
942 * FIXME: if the SSL session says "want read", or
943 * similar, leave the data in the clean_out buffer. This
944 * lets the application data be sent across multiple
947 err = tls_handshake_recv(tls_session);
949 DEBUG2(" rlm_eap_peap: Failed in SSL");
950 return RLM_MODULE_REJECT;
954 * Just look at the buffer directly, without doing
957 data_len = tls_session->clean_out.used;
958 data = tls_session->clean_out.data;
960 t = (ttls_tunnel_t *) tls_session->opaque;
963 * If there's no data, maybe this is an ACK to an
967 if (t->authenticated) {
968 DEBUG2(" TTLS: Got ACK, and the user was already authenticated.");
969 return PW_AUTHENTICATION_ACK;
970 } /* else no session, no data, die. */
973 * FIXME: Call SSL_get_error() to see what went
976 DEBUG2("rlm_eap_ttls: SSL_read Error");
977 return PW_AUTHENTICATION_REJECT;
981 if (debug_flag > 2) {
984 for (i = 0; i < data_len; i++) {
985 if ((i & 0x0f) == 0) printf(" TTLS tunnel data in %04x: ", i);
987 printf("%02x ", data[i]);
989 if ((i & 0x0f) == 0x0f) printf("\n");
991 if ((data_len & 0x0f) != 0) printf("\n");
995 if (!diameter_verify(data, data_len)) {
996 return PW_AUTHENTICATION_REJECT;
1000 * Allocate a fake REQUEST structe.
1002 fake = request_alloc_fake(request);
1004 rad_assert(fake->packet->vps == NULL);
1007 * Add the tunneled attributes to the fake request.
1009 fake->packet->vps = diameter2vp(tls_session->ssl, data, data_len);
1010 if (!fake->packet->vps) {
1011 request_free(&fake);
1012 return PW_AUTHENTICATION_REJECT;
1016 * Tell the request that it's a fake one.
1018 vp = pairmake("Freeradius-Proxied-To", "127.0.0.1", T_OP_EQ);
1020 pairadd(&fake->packet->vps, vp);
1024 if (debug_flag > 0) {
1025 printf(" TTLS: Got tunneled request\n");
1027 for (vp = fake->packet->vps; vp != NULL; vp = vp->next) {
1028 putchar('\t');vp_print(stdout, vp);putchar('\n');
1034 * Update other items in the REQUEST data structure.
1036 fake->username = pairfind(fake->packet->vps, PW_USER_NAME);
1037 fake->password = pairfind(fake->packet->vps, PW_USER_PASSWORD);
1040 * No User-Name, try to create one from stored data.
1042 if (!fake->username) {
1044 * No User-Name in the stored data, look for
1045 * an EAP-Identity, and pull it out of there.
1048 vp = pairfind(fake->packet->vps, PW_EAP_MESSAGE);
1050 (vp->length >= EAP_HEADER_LEN + 2) &&
1051 (vp->vp_strvalue[0] == PW_EAP_RESPONSE) &&
1052 (vp->vp_strvalue[EAP_HEADER_LEN] == PW_EAP_IDENTITY) &&
1053 (vp->vp_strvalue[EAP_HEADER_LEN + 1] != 0)) {
1055 * Create & remember a User-Name
1057 t->username = pairmake("User-Name", "", T_OP_EQ);
1058 rad_assert(t->username != NULL);
1060 memcpy(t->username->vp_strvalue, vp->vp_strvalue + 5,
1062 t->username->length = vp->length - 5;
1063 t->username->vp_strvalue[t->username->length] = 0;
1065 DEBUG2(" TTLS: Got tunneled identity of %s",
1066 t->username->vp_strvalue);
1069 * If there's a default EAP type,
1072 if (t->default_eap_type != 0) {
1073 DEBUG2(" TTLS: Setting default EAP type for tunneled EAP session.");
1074 vp = paircreate(PW_EAP_TYPE,
1076 rad_assert(vp != NULL);
1077 vp->vp_integer = t->default_eap_type;
1078 pairadd(&fake->config_items, vp);
1083 * Don't reject the request outright,
1084 * as it's permitted to do EAP without
1087 DEBUG2(" rlm_eap_ttls: WARNING! No EAP-Identity found to start EAP conversation.");
1089 } /* else there WAS a t->username */
1092 vp = paircopy(t->username);
1093 pairadd(&fake->packet->vps, vp);
1094 fake->username = pairfind(fake->packet->vps, PW_USER_NAME);
1096 } /* else the request ALREADY had a User-Name */
1099 * Add the State attribute, too, if it exists.
1102 DEBUG2(" TTLS: Adding old state with %02x %02x",
1103 t->state->vp_strvalue[0], t->state->vp_strvalue[1]);
1104 vp = paircopy(t->state);
1105 if (vp) pairadd(&fake->packet->vps, vp);
1109 * If this is set, we copy SOME of the request attributes
1110 * from outside of the tunnel to inside of the tunnel.
1112 * We copy ONLY those attributes which do NOT already
1113 * exist in the tunneled request.
1115 if (t->copy_request_to_tunnel) {
1118 for (vp = request->packet->vps; vp != NULL; vp = vp->next) {
1120 * The attribute is a server-side thingy,
1123 if ((vp->attribute > 255) &&
1124 (((vp->attribute >> 16) & 0xffff) == 0)) {
1129 * The outside attribute is already in the
1130 * tunnel, don't copy it.
1132 * This works for BOTH attributes which
1133 * are originally in the tunneled request,
1134 * AND attributes which are copied there
1137 if (pairfind(fake->packet->vps, vp->attribute)) {
1142 * Some attributes are handled specially.
1144 switch (vp->attribute) {
1146 * NEVER copy Message-Authenticator,
1147 * EAP-Message, or State. They're
1148 * only for outside of the tunnel.
1151 case PW_USER_PASSWORD:
1152 case PW_CHAP_PASSWORD:
1153 case PW_CHAP_CHALLENGE:
1154 case PW_PROXY_STATE:
1155 case PW_MESSAGE_AUTHENTICATOR:
1156 case PW_EAP_MESSAGE:
1162 * By default, copy it over.
1169 * Don't copy from the head, we've already
1172 copy = paircopy2(vp, vp->attribute);
1173 pairadd(&fake->packet->vps, copy);
1177 if ((vp = pairfind(request->config_items, PW_VIRTUAL_SERVER)) != NULL) {
1178 fake->server = vp->vp_strvalue;
1180 } else if (t->virtual_server) {
1181 fake->server = t->virtual_server;
1183 } /* else fake->server == request->server */
1187 if (debug_flag > 0) {
1188 printf(" TTLS: Sending tunneled request\n");
1190 for (vp = fake->packet->vps; vp != NULL; vp = vp->next) {
1191 putchar('\t');vp_print(stdout, vp);putchar('\n');
1194 printf("server %s {\n", fake->server);
1199 * Call authentication recursively, which will
1200 * do PAP, CHAP, MS-CHAP, etc.
1202 rad_authenticate(fake);
1205 * Note that we don't do *anything* with the reply
1209 if (debug_flag > 0) {
1210 printf("} # server %s\n", fake->server);
1212 printf(" TTLS: Got tunneled reply RADIUS code %d\n",
1215 for (vp = fake->reply->vps; vp != NULL; vp = vp->next) {
1216 putchar('\t');vp_print(stdout, vp);putchar('\n');
1222 * Decide what to do with the reply.
1224 switch (fake->reply->code) {
1225 case 0: /* No reply code, must be proxied... */
1226 vp = pairfind(fake->config_items, PW_PROXY_TO_REALM);
1228 eap_tunnel_data_t *tunnel;
1229 DEBUG2(" TTLS: Tunneled authentication will be proxied to %s", vp->vp_strvalue);
1232 * Tell the original request that it's going
1235 pairmove2(&(request->config_items),
1236 &(fake->config_items),
1240 * Seed the proxy packet with the
1243 rad_assert(request->proxy == NULL);
1244 request->proxy = fake->packet;
1245 fake->packet = NULL;
1246 rad_free(&fake->reply);
1250 * Set up the callbacks for the tunnel
1252 tunnel = rad_malloc(sizeof(*tunnel));
1253 memset(tunnel, 0, sizeof(*tunnel));
1255 tunnel->tls_session = tls_session;
1256 tunnel->callback = eapttls_postproxy;
1259 * Associate the callback with the request.
1261 rcode = request_data_add(request,
1263 REQUEST_DATA_EAP_TUNNEL_CALLBACK,
1265 rad_assert(rcode == 0);
1268 * rlm_eap.c has taken care of associating
1269 * the handler with the fake request.
1271 * So we associate the fake request with
1274 rcode = request_data_add(request,
1276 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK,
1277 fake, my_request_free);
1278 rad_assert(rcode == 0);
1282 * Didn't authenticate the packet, but
1283 * we're proxying it.
1285 rcode = PW_STATUS_CLIENT;
1288 DEBUG2(" TTLS: No tunneled reply was found for request %d , and the request was not proxied: rejecting the user.",
1290 rcode = PW_AUTHENTICATION_REJECT;
1296 * Returns RLM_MODULE_FOO, and we want to return
1299 rcode = process_reply(handler, tls_session, request,
1302 case RLM_MODULE_REJECT:
1303 rcode = PW_AUTHENTICATION_REJECT;
1306 case RLM_MODULE_HANDLED:
1307 rcode = PW_ACCESS_CHALLENGE;
1311 rcode = PW_AUTHENTICATION_ACK;
1315 rcode = PW_AUTHENTICATION_REJECT;
1321 request_free(&fake);