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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Copyright 2003 Alan DeKok <aland@freeradius.org>
26 * 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
27 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 * |V M r r r r r r| AVP Length |
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * Verify that the diameter packet is valid.
41 static int diameter_verify(const uint8_t *data, unsigned int data_len)
46 unsigned int data_left = data_len;
48 while (data_left > 0) {
50 DEBUG2(" rlm_eap_ttls: Diameter attribute is too small to contain a Diameter header");
54 rad_assert(data_left <= data_len);
55 memcpy(&attr, data, sizeof(attr));
59 DEBUG2(" rlm_eap_ttls: Non-RADIUS attribute in tunneled authentication is not supported");
63 memcpy(&length, data , sizeof(length));
65 length = ntohl(length);
68 * A "vendor" flag, with a vendor ID of zero,
69 * is equivalent to no vendor. This is stupid.
72 if ((length & (1 << 31)) != 0) {
77 memcpy(&vendor, data, sizeof(vendor));
78 vendor = ntohl(vendor);
81 DEBUG2(" rlm_eap_ttls: Vendor codes larger than 65535 are not supported");
85 attribute = (vendor << 16) | attr;
87 da = dict_attrbyvalue(attribute);
90 * SHOULD check ((length & (1 << 30)) != 0)
91 * for the mandatory bit.
94 DEBUG2(" rlm_eap_ttls: Fatal! Vendor %u, Attribute %u was not found in our dictionary. ",
99 data += 4; /* skip the vendor field */
100 offset += 4; /* offset to value field */
104 * Ignore the M bit. We support all RADIUS attributes...
108 * Get the length. If it's too big, die.
110 length &= 0x00ffffff;
113 * Too short or too long is bad.
117 if (length < offset) {
118 DEBUG2(" rlm_eap_ttls: Tunneled attribute %d is too short (%d)to contain anything useful.", attr, length);
122 if (length > (MAX_STRING_LEN + 8)) {
123 DEBUG2(" rlm_eap_ttls: Tunneled attribute %d is too long (%d) to pack into a RADIUS attribute.", attr, length);
127 if (length > data_left) {
128 DEBUG2(" rlm_eap_ttls: Tunneled attribute %d is longer than room left in the packet (%d > %d).", attr, length, data_left);
133 * Check for broken implementations, which don't
134 * pad the AVP to a 4-octet boundary.
136 if (data_left == length) break;
139 * The length does NOT include the padding, so
140 * we've got to account for it here by rounding up
141 * to the nearest 4-byte boundary.
147 * If the rest of the diameter packet is larger than
148 * this attribute, continue.
150 * Otherwise, if the attribute over-flows the end
151 * of the packet, die.
153 if (data_left < length) {
154 DEBUG2(" rlm_eap_ttls: ERROR! Diameter attribute overflows packet!");
159 * Check again for equality, now that we're padded
160 * length to a multiple of 4 octets.
162 if (data_left == length) break;
165 * data_left > length, continue.
168 data += length - offset;
172 * We got this far. It looks OK.
179 * Convert diameter attributes to our VALUE_PAIR's
181 static VALUE_PAIR *diameter2vp(SSL *ssl,
182 const uint8_t *data, unsigned int data_len)
188 unsigned int data_left = data_len;
189 VALUE_PAIR *first = NULL;
190 VALUE_PAIR **last = &first;
193 while (data_left > 0) {
194 rad_assert(data_left <= data_len);
195 memcpy(&attr, data, sizeof(attr));
199 memcpy(&length, data, sizeof(length));
201 length = ntohl(length);
204 * Ignore the M bit. We support all RADIUS attributes...
208 * A "vendor" flag, with a vendor ID of zero,
209 * is equivalent to no vendor. This is stupid.
212 if ((length & (1 << 31)) != 0) {
215 memcpy(&vendor, data, sizeof(vendor));
216 vendor = ntohl(vendor);
218 attr |= (vendor << 16);
220 data += 4; /* skip the vendor field, it's zero */
221 offset += 4; /* offset to value field */
227 length &= 0x00ffffff;
230 * diameter code + length, and it must fit in
233 rad_assert(length <= (offset + MAX_STRING_LEN));
236 * Get the size of the value portion of the
239 size = length - offset;
244 vp = paircreate(attr, PW_TYPE_OCTETS);
246 DEBUG2(" rlm_eap_ttls: Failure in creating VP");
252 * If it's a type from our dictionary, then
253 * we need to put the data in a relevant place.
256 case PW_TYPE_INTEGER:
258 if (size != vp->length) {
259 DEBUG2(" rlm_eap_ttls: Invalid length attribute %d",
264 memcpy(&vp->lvalue, data, vp->length);
267 * Stored in host byte order: change it.
269 vp->lvalue = ntohl(vp->lvalue);
273 if (size != vp->length) {
274 DEBUG2(" rlm_eap_ttls: Invalid length attribute %d",
279 memcpy(&vp->lvalue, data, vp->length);
282 * Stored in network byte order: don't change it.
287 * String, octet, etc. Copy the data from the
288 * value field over verbatim.
290 * FIXME: Ipv6 attributes ?
295 memcpy(vp->strvalue, data, vp->length);
300 * User-Password is NUL padded to a multiple
301 * of 16 bytes. Let's chop it to something
304 * NOTE: This means that the User-Password
305 * attribute CANNOT EVER have embedded zeros in it!
307 switch (vp->attribute) {
308 case PW_USER_PASSWORD:
309 rad_assert(vp->length <= 128); /* RFC requirements */
312 * If the password is exactly 16 octets,
313 * it won't be zero-terminated.
315 vp->strvalue[vp->length] = '\0';
316 vp->length = strlen(vp->strvalue);
320 * Ensure that the client is using the
321 * correct challenge. This weirdness is
322 * to protect against against replay
323 * attacks, where anyone observing the
324 * CHAP exchange could pose as that user,
325 * by simply choosing to use the same
328 * By using a challenge based on
329 * information from the current session,
330 * we can guarantee that the client is
331 * not *choosing* a challenge.
333 * We're a little forgiving in that we
334 * have loose checks on the length, and
335 * we do NOT check the Id (first octet of
336 * the response to the challenge)
338 * But if the client gets the challenge correct,
339 * we're not too worried about the Id.
341 case PW_CHAP_CHALLENGE:
342 case PW_MSCHAP_CHALLENGE:
343 if ((vp->length < 8) ||
345 DEBUG2(" TTLS: Tunneled challenge has invalid length");
351 uint8_t challenge[16];
353 eapttls_gen_challenge(ssl, challenge,
356 for (i = 0; i < vp->length; i++) {
357 if (challenge[i] != vp->strvalue[i]) {
358 DEBUG2(" TTLS: Tunneled challenge is incorrect");
368 } /* switch over checking/re-writing of attributes. */
377 * Catch non-aligned attributes.
379 if (data_left == length) break;
382 * The length does NOT include the padding, so
383 * we've got to account for it here by rounding up
384 * to the nearest 4-byte boundary.
389 rad_assert(data_left >= length);
391 data += length - offset; /* already updated */
395 * We got this far. It looks OK.
401 * Convert VALUE_PAIR's to diameter attributes, and write them
404 * The ONLY VALUE_PAIR's which may be passed to this function
405 * are ones which can go inside of a RADIUS (i.e. diameter)
406 * packet. So no server-configuration attributes, or the like.
408 static int vp2diameter(tls_session_t *tls_session, VALUE_PAIR *first)
411 * RADIUS packets are no more than 4k in size, so if
412 * we've got more than 4k of data to write, it's very
415 uint8_t buffer[4096];
426 for (vp = first; vp != NULL; vp = vp->next) {
428 * Too much data: die.
430 if ((total + vp->length + 12) >= sizeof(buffer)) {
431 DEBUG2(" TTLS output buffer is full!");
436 * Hmm... we don't group multiple EAP-Messages
437 * together. Maybe we should...
441 * Length is no more than 253, due to RADIUS
445 vendor = (vp->attribute >> 16) & 0xffff;
447 attr = vp->attribute & 0xffff;
450 attr = vp->attribute;
454 * Hmm... set the M bit for all attributes?
460 memcpy(p, &attr, sizeof(attr));
464 length += 8; /* includes 8 bytes of attr & length */
467 length += 4; /* include 4 bytes of vendor */
469 length = ntohl(length);
470 memcpy(p, &length, sizeof(length));
474 vendor = ntohl(vendor);
475 memcpy(p, &vendor, sizeof(vendor));
479 length = ntohl(length);
480 memcpy(p, &length, sizeof(length));
486 case PW_TYPE_INTEGER:
488 attr = ntohl(vp->lvalue); /* stored in host order */
489 memcpy(p, &attr, sizeof(attr));
494 attr = vp->lvalue; /* stored in network order */
495 memcpy(p, &attr, sizeof(attr));
502 memcpy(p, vp->strvalue, vp->length);
508 * Skip to the end of the data.
514 * Align the data to a multiple of 4 bytes.
516 if ((total & 0x03) != 0) {
519 length = 4 - (total & 0x03);
520 for (i = 0; i < length; i++) {
526 } /* loop over the VP's to write. */
529 * Write the data in the buffer to the SSL session.
535 if (debug_flag > 2) {
536 for (i = 0; i < total; i++) {
537 if ((i & 0x0f) == 0) printf(" TTLS tunnel data out %04x: ", i);
539 printf("%02x ", buffer[i]);
541 if ((i & 0x0f) == 0x0f) printf("\n");
543 if ((total & 0x0f) != 0) printf("\n");
547 (tls_session->record_plus)(&tls_session->clean_in, buffer, total);
550 * FIXME: Check the return code.
552 tls_handshake_send(tls_session);
562 * Use a reply packet to determine what to do.
564 static int process_reply(EAP_HANDLER *handler, tls_session_t *tls_session,
565 REQUEST *request, RADIUS_PACKET *reply)
567 int rcode = RLM_MODULE_REJECT;
569 ttls_tunnel_t *t = tls_session->opaque;
571 handler = handler; /* -Wunused */
574 * If the response packet was Access-Accept, then
575 * we're OK. If not, die horribly.
577 * FIXME: Take MS-CHAP2-Success attribute, and
578 * tunnel it back to the client, to authenticate
579 * ourselves to the client.
581 * FIXME: If we have an Access-Challenge, then
582 * the Reply-Message is tunneled back to the client.
584 * FIXME: If we have an EAP-Message, then that message
585 * must be tunneled back to the client.
587 * FIXME: If we have an Access-Challenge with a State
588 * attribute, then do we tunnel that to the client, or
589 * keep track of it ourselves?
591 * FIXME: EAP-Messages can only start with 'identity',
592 * NOT 'eap start', so we should check for that....
594 switch (reply->code) {
595 case PW_AUTHENTICATION_ACK:
596 DEBUG2(" TTLS: Got tunneled Access-Accept");
598 rcode = RLM_MODULE_OK;
601 * MS-CHAP2-Success means that we do NOT return
602 * an Access-Accept, but instead tunnel that
603 * attribute to the client, and keep going with
604 * the TTLS session. Once the client accepts
605 * our identity, it will respond with an empty
606 * packet, and we will send EAP-Success.
609 pairmove2(&vp, &reply->vps, PW_MSCHAP2_SUCCESS);
611 DEBUG2(" TTLS: Got MS-CHAP2-Success, tunneling it to the client in a challenge.");
612 rcode = RLM_MODULE_HANDLED;
613 t->authenticated = TRUE;
614 } else { /* no MS-CHAP2-Success */
616 * Can only have EAP-Message if there's
617 * no MS-CHAP2-Success. (FIXME: EAP-MSCHAP?)
619 * We also do NOT tunnel the EAP-Success
620 * attribute back to the client, as the client
621 * can figure it out, from the non-tunneled
622 * EAP-Success packet.
624 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
629 * Handle the ACK, by tunneling any necessary reply
630 * VP's back to the client.
633 vp2diameter(tls_session, vp);
638 * If we've been told to use the attributes from
639 * the reply, then do so.
641 * WARNING: This may leak information about the
644 if (t->use_tunneled_reply) {
645 pairdelete(&reply->vps, PW_PROXY_STATE);
646 pairadd(&request->reply->vps, reply->vps);
652 case PW_AUTHENTICATION_REJECT:
653 DEBUG2(" TTLS: Got tunneled Access-Reject");
654 rcode = RLM_MODULE_REJECT;
658 * Handle Access-Challenge, but only if we
659 * send tunneled reply data. This is because
660 * an Access-Challenge means that we MUST tunnel
661 * a Reply-Message to the client.
663 case PW_ACCESS_CHALLENGE:
664 DEBUG2(" TTLS: Got tunneled Access-Challenge");
667 * Keep the State attribute, if necessary.
669 * Get rid of the old State, too.
672 pairmove2(&t->state, &reply->vps, PW_STATE);
675 * We should really be a bit smarter about this,
676 * and move over only those attributes which
677 * are relevant to the authentication request,
678 * but that's a lot more work, and this "dumb"
679 * method works in 99.9% of the situations.
682 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
685 * There MUST be a Reply-Message in the challenge,
686 * which we tunnel back to the client.
688 * If there isn't one in the reply VP's, then
689 * we MUST create one, with an empty string as
692 pairmove2(&vp, &reply->vps, PW_REPLY_MESSAGE);
695 * Handle the ACK, by tunneling any necessary reply
696 * VP's back to the client.
699 vp2diameter(tls_session, vp);
702 rcode = RLM_MODULE_HANDLED;
706 DEBUG2(" TTLS: Unknown RADIUS packet type %d: rejecting tunneled user", reply->code);
707 rcode = RLM_MODULE_INVALID;
716 * Do post-proxy processing,
718 static int eapttls_postproxy(EAP_HANDLER *handler, void *data)
721 tls_session_t *tls_session = (tls_session_t *) data;
724 DEBUG2(" TTLS: Passing reply from proxy back into the tunnel.");
727 * If there was a fake request associated with the proxied
728 * request, do more processing of it.
730 fake = (REQUEST *) request_data_get(handler->request,
731 handler->request->proxy,
732 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK);
735 * Do the callback, if it exists, and if it was a success.
737 if (fake && (handler->request->proxy_reply->code == PW_AUTHENTICATION_ACK)) {
739 REQUEST *request = handler->request;
744 rad_assert(fake->packet == NULL);
745 fake->packet = request->proxy;
746 request->proxy = NULL;
748 rad_assert(fake->reply == NULL);
749 fake->reply = request->proxy_reply;
750 request->proxy_reply = NULL;
753 * Perform a post-auth stage for the tunneled
756 fake->options &= ~RAD_REQUEST_OPTION_PROXY_EAP;
757 rcode = rad_postauth(fake);
758 DEBUG2(" POST-AUTH %d", rcode);
761 if (debug_flag > 0) {
762 printf(" TTLS: Final reply from tunneled session code %d\n",
765 for (vp = fake->reply->vps; vp != NULL; vp = vp->next) {
766 putchar('\t');vp_print(stdout, vp);putchar('\n');
774 request->proxy = fake->packet;
776 request->proxy_reply = fake->reply;
780 * And we're done with this request.
784 case RLM_MODULE_FAIL:
786 eaptls_fail(handler->eap_ds, 0);
790 default: /* Don't Do Anything */
791 DEBUG2(" TTLS: Got reply %d",
792 request->proxy_reply->code);
796 request_free(&fake); /* robust if fake == NULL */
799 * Process the reply from the home server.
801 rcode = process_reply(handler, tls_session, handler->request,
802 handler->request->proxy_reply);
805 * The proxy code uses the reply from the home server as
806 * the basis for the reply to the NAS. We don't want that,
807 * so we toss it, after we've had our way with it.
809 pairfree(&handler->request->proxy_reply->vps);
812 case RLM_MODULE_REJECT:
813 DEBUG2(" TTLS: Reply was rejected");
816 case RLM_MODULE_HANDLED:
817 DEBUG2(" TTLS: Reply was handled");
818 eaptls_request(handler->eap_ds, tls_session);
822 DEBUG2(" TTLS: Reply was OK");
823 eaptls_success(handler->eap_ds, 0);
824 eaptls_gen_mppe_keys(&handler->request->reply->vps,
826 "ttls keying material");
830 DEBUG2(" TTLS: Reply was unknown.");
834 eaptls_fail(handler->eap_ds, 0);
842 static void my_request_free(void *data)
844 REQUEST *request = (REQUEST *)data;
846 request_free(&request);
851 * Process the "diameter" contents of the tunneled data.
853 int eapttls_process(EAP_HANDLER *handler, tls_session_t *tls_session)
856 int rcode = PW_AUTHENTICATION_REJECT;
861 unsigned int data_len;
863 REQUEST *request = handler->request;
866 * Grab the dirty data, and copy it to our buffer.
868 * I *really* don't like these 'record_t' things...
870 data_len = (tls_session->record_minus)(&tls_session->dirty_in, buffer, sizeof(buffer));
874 * Write the data from the dirty buffer (i.e. packet
875 * data) into the buffer which we will give to SSL for
878 * Some of this code COULD technically go into the TLS
879 * module, in eaptls_process(), where it returns EAPTLS_OK.
881 * Similarly, the writing of data to the SSL context could
884 BIO_write(tls_session->into_ssl, buffer, data_len);
885 (tls_session->record_init)(&tls_session->clean_out);
888 * Read (and decrypt) the tunneled data from the SSL session,
889 * and put it into the decrypted data buffer.
891 err = SSL_read(tls_session->ssl, tls_session->clean_out.data,
892 sizeof(tls_session->clean_out.data));
895 * FIXME: Call SSL_get_error() to see what went
898 radlog(L_INFO, "rlm_eap_ttls: SSL_read Error");
899 return PW_AUTHENTICATION_REJECT;
902 t = (ttls_tunnel_t *) tls_session->opaque;
905 * If there's no data, maybe this is an ACK to an
909 if (t->authenticated) {
910 DEBUG2(" TTLS: Got ACK, and the user was already authenticated.");
911 return PW_AUTHENTICATION_ACK;
912 } /* else no session, no data, die. */
915 * FIXME: Call SSL_get_error() to see what went
918 radlog(L_INFO, "rlm_eap_ttls: SSL_read Error");
919 return PW_AUTHENTICATION_REJECT;
922 data_len = tls_session->clean_out.used = err;
923 data = tls_session->clean_out.data;
926 if (debug_flag > 2) {
929 for (i = 0; i < data_len; i++) {
930 if ((i & 0x0f) == 0) printf(" TTLS tunnel data in %04x: ", i);
932 printf("%02x ", data[i]);
934 if ((i & 0x0f) == 0x0f) printf("\n");
936 if ((data_len & 0x0f) != 0) printf("\n");
940 if (!diameter_verify(data, data_len)) {
941 return PW_AUTHENTICATION_REJECT;
945 * Allocate a fake REQUEST structe.
947 fake = request_alloc_fake(request);
949 rad_assert(fake->packet->vps == NULL);
952 * Add the tunneled attributes to the fake request.
954 fake->packet->vps = diameter2vp(tls_session->ssl, data, data_len);
955 if (!fake->packet->vps) {
956 return PW_AUTHENTICATION_REJECT;
960 * Tell the request that it's a fake one.
962 vp = pairmake("Freeradius-Proxied-To", "127.0.0.1", T_OP_EQ);
964 pairadd(&fake->packet->vps, vp);
968 if (debug_flag > 0) {
969 printf(" TTLS: Got tunneled request\n");
971 for (vp = fake->packet->vps; vp != NULL; vp = vp->next) {
972 putchar('\t');vp_print(stdout, vp);putchar('\n');
978 * Update other items in the REQUEST data structure.
980 fake->username = pairfind(fake->packet->vps, PW_USER_NAME);
981 fake->password = pairfind(fake->packet->vps, PW_PASSWORD);
984 * No User-Name, try to create one from stored data.
986 if (!fake->username) {
988 * No User-Name in the stored data, look for
989 * an EAP-Identity, and pull it out of there.
992 vp = pairfind(fake->packet->vps, PW_EAP_MESSAGE);
994 (vp->length >= EAP_HEADER_LEN + 2) &&
995 (vp->strvalue[0] == PW_EAP_RESPONSE) &&
996 (vp->strvalue[EAP_HEADER_LEN] == PW_EAP_IDENTITY) &&
997 (vp->strvalue[EAP_HEADER_LEN + 1] != 0)) {
999 * Create & remember a User-Name
1001 t->username = pairmake("User-Name", "", T_OP_EQ);
1002 rad_assert(t->username != NULL);
1004 memcpy(t->username->strvalue, vp->strvalue + 5,
1006 t->username->length = vp->length - 5;
1007 t->username->strvalue[t->username->length] = 0;
1009 DEBUG2(" TTLS: Got tunneled identity of %s",
1010 t->username->strvalue);
1013 * If there's a default EAP type,
1016 if (t->default_eap_type != 0) {
1017 DEBUG2(" TTLS: Setting default EAP type for tunneled EAP session.");
1018 vp = paircreate(PW_EAP_TYPE,
1020 rad_assert(vp != NULL);
1021 vp->lvalue = t->default_eap_type;
1022 pairadd(&fake->config_items, vp);
1027 * Don't reject the request outright,
1028 * as it's permitted to do EAP without
1031 DEBUG2(" rlm_eap_ttls: WARNING! No EAP-Identity found to start EAP conversation.");
1033 } /* else there WAS a t->username */
1036 vp = paircopy(t->username);
1037 pairadd(&fake->packet->vps, vp);
1038 fake->username = pairfind(fake->packet->vps, PW_USER_NAME);
1040 } /* else the request ALREADY had a User-Name */
1043 * Add the State attribute, too, if it exists.
1046 DEBUG2(" TTLS: Adding old state with %02x %02x",
1047 t->state->strvalue[0], t->state->strvalue[1]);
1048 vp = paircopy(t->state);
1049 if (vp) pairadd(&fake->packet->vps, vp);
1053 * If this is set, we copy SOME of the request attributes
1054 * from outside of the tunnel to inside of the tunnel.
1056 * We copy ONLY those attributes which do NOT already
1057 * exist in the tunneled request.
1059 if (t->copy_request_to_tunnel) {
1062 for (vp = request->packet->vps; vp != NULL; vp = vp->next) {
1064 * The attribute is a server-side thingy,
1067 if ((vp->attribute > 255) &&
1068 (((vp->attribute >> 16) & 0xffff) == 0)) {
1073 * The outside attribute is already in the
1074 * tunnel, don't copy it.
1076 * This works for BOTH attributes which
1077 * are originally in the tunneled request,
1078 * AND attributes which are copied there
1081 if (pairfind(fake->packet->vps, vp->attribute)) {
1086 * Some attributes are handled specially.
1088 switch (vp->attribute) {
1090 * NEVER copy Message-Authenticator,
1091 * EAP-Message, or State. They're
1092 * only for outside of the tunnel.
1095 case PW_USER_PASSWORD:
1096 case PW_CHAP_PASSWORD:
1097 case PW_CHAP_CHALLENGE:
1098 case PW_PROXY_STATE:
1099 case PW_MESSAGE_AUTHENTICATOR:
1100 case PW_EAP_MESSAGE:
1106 * By default, copy it over.
1113 * Don't copy from the head, we've already
1116 copy = paircopy2(vp, vp->attribute);
1117 pairadd(&fake->packet->vps, copy);
1122 if (debug_flag > 0) {
1123 printf(" TTLS: Sending tunneled request\n");
1125 for (vp = fake->packet->vps; vp != NULL; vp = vp->next) {
1126 putchar('\t');vp_print(stdout, vp);putchar('\n');
1132 * Call authentication recursively, which will
1133 * do PAP, CHAP, MS-CHAP, etc.
1135 rad_authenticate(fake);
1138 * Note that we don't do *anything* with the reply
1142 if (debug_flag > 0) {
1143 printf(" TTLS: Got tunneled reply RADIUS code %d\n",
1146 for (vp = fake->reply->vps; vp != NULL; vp = vp->next) {
1147 putchar('\t');vp_print(stdout, vp);putchar('\n');
1153 * Decide what to do with the reply.
1155 switch (fake->reply->code) {
1156 case 0: /* No reply code, must be proxied... */
1157 vp = pairfind(fake->config_items, PW_PROXY_TO_REALM);
1159 eap_tunnel_data_t *tunnel;
1160 DEBUG2(" TTLS: Tunneled authentication will be proxied to %s", vp->strvalue);
1163 * Tell the original request that it's going
1166 pairmove2(&(request->config_items),
1167 &(fake->config_items),
1171 * Seed the proxy packet with the
1174 rad_assert(request->proxy == NULL);
1175 request->proxy = fake->packet;
1176 fake->packet = NULL;
1177 rad_free(&fake->reply);
1181 * Set up the callbacks for the tunnel
1183 tunnel = rad_malloc(sizeof(*tunnel));
1184 memset(tunnel, 0, sizeof(*tunnel));
1186 tunnel->tls_session = tls_session;
1187 tunnel->callback = eapttls_postproxy;
1190 * Associate the callback with the request.
1192 rcode = request_data_add(request,
1194 REQUEST_DATA_EAP_TUNNEL_CALLBACK,
1196 rad_assert(rcode == 0);
1199 * rlm_eap.c has taken care of associating
1200 * the handler with the fake request.
1202 * So we associate the fake request with
1205 rcode = request_data_add(request,
1207 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK,
1208 fake, my_request_free);
1209 rad_assert(rcode == 0);
1213 * Didn't authenticate the packet, but
1214 * we're proxying it.
1216 rcode = PW_STATUS_CLIENT;
1219 DEBUG2(" TTLS: No tunneled reply was found for request %d , and the request was not proxied: rejecting the user.",
1221 rcode = PW_AUTHENTICATION_REJECT;
1227 * Returns RLM_MODULE_FOO, and we want to return
1230 rcode = process_reply(handler, tls_session, request,
1233 case RLM_MODULE_REJECT:
1234 rcode = PW_AUTHENTICATION_REJECT;
1237 case RLM_MODULE_HANDLED:
1238 rcode = PW_ACCESS_CHALLENGE;
1242 rcode = PW_AUTHENTICATION_ACK;
1246 rcode = PW_AUTHENTICATION_REJECT;
1252 request_free(&fake);