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.
122 if (length < offset) {
123 DEBUG2(" rlm_eap_ttls: Tunneled attribute %d is too short (%d)to contain anything useful.", attr, length);
127 if (length > (MAX_STRING_LEN + 8)) {
128 DEBUG2(" rlm_eap_ttls: Tunneled attribute %d is too long (%d) to pack into a RADIUS attribute.", attr, length);
132 if (length > data_left) {
133 DEBUG2(" rlm_eap_ttls: Tunneled attribute %d is longer than room left in the packet (%d > %d).", attr, length, data_left);
138 * Check for broken implementations, which don't
139 * pad the AVP to a 4-octet boundary.
141 if (data_left == length) break;
144 * The length does NOT include the padding, so
145 * we've got to account for it here by rounding up
146 * to the nearest 4-byte boundary.
152 * If the rest of the diameter packet is larger than
153 * this attribute, continue.
155 * Otherwise, if the attribute over-flows the end
156 * of the packet, die.
158 if (data_left < length) {
159 DEBUG2(" rlm_eap_ttls: ERROR! Diameter attribute overflows packet!");
164 * Check again for equality, now that we're padded
165 * length to a multiple of 4 octets.
167 if (data_left == length) break;
170 * data_left > length, continue.
173 data += length - offset;
177 * We got this far. It looks OK.
184 * Convert diameter attributes to our VALUE_PAIR's
186 static VALUE_PAIR *diameter2vp(SSL *ssl,
187 const uint8_t *data, unsigned int data_len)
193 unsigned int data_left = data_len;
194 VALUE_PAIR *first = NULL;
195 VALUE_PAIR **last = &first;
198 while (data_left > 0) {
199 rad_assert(data_left <= data_len);
200 memcpy(&attr, data, sizeof(attr));
204 memcpy(&length, data, sizeof(length));
206 length = ntohl(length);
209 * Ignore the M bit. We support all RADIUS attributes...
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);
223 attr |= (vendor << 16);
225 data += 4; /* skip the vendor field, it's zero */
226 offset += 4; /* offset to value field */
232 length &= 0x00ffffff;
235 * diameter code + length, and it must fit in
238 rad_assert(length <= (offset + MAX_STRING_LEN));
241 * Get the size of the value portion of the
244 size = length - offset;
249 vp = paircreate(attr, PW_TYPE_OCTETS);
251 DEBUG2(" rlm_eap_ttls: Failure in creating VP");
257 * If it's a type from our dictionary, then
258 * we need to put the data in a relevant place.
261 case PW_TYPE_INTEGER:
263 if (size != vp->length) {
264 DEBUG2(" rlm_eap_ttls: Invalid length attribute %d",
269 memcpy(&vp->lvalue, data, vp->length);
272 * Stored in host byte order: change it.
274 vp->lvalue = ntohl(vp->lvalue);
278 if (size != vp->length) {
279 DEBUG2(" rlm_eap_ttls: Invalid length attribute %d",
284 memcpy(&vp->lvalue, data, vp->length);
287 * Stored in network byte order: don't change it.
292 * String, octet, etc. Copy the data from the
293 * value field over verbatim.
295 * FIXME: Ipv6 attributes ?
300 memcpy(vp->vp_strvalue, data, vp->length);
305 * User-Password is NUL padded to a multiple
306 * of 16 bytes. Let's chop it to something
309 * NOTE: This means that the User-Password
310 * attribute CANNOT EVER have embedded zeros in it!
312 switch (vp->attribute) {
313 case PW_USER_PASSWORD:
314 rad_assert(vp->length <= 128); /* RFC requirements */
317 * If the password is exactly 16 octets,
318 * it won't be zero-terminated.
320 vp->vp_strvalue[vp->length] = '\0';
321 vp->length = strlen(vp->vp_strvalue);
325 * Ensure that the client is using the
326 * correct challenge. This weirdness is
327 * to protect against against replay
328 * attacks, where anyone observing the
329 * CHAP exchange could pose as that user,
330 * by simply choosing to use the same
333 * By using a challenge based on
334 * information from the current session,
335 * we can guarantee that the client is
336 * not *choosing* a challenge.
338 * We're a little forgiving in that we
339 * have loose checks on the length, and
340 * we do NOT check the Id (first octet of
341 * the response to the challenge)
343 * But if the client gets the challenge correct,
344 * we're not too worried about the Id.
346 case PW_CHAP_CHALLENGE:
347 case PW_MSCHAP_CHALLENGE:
348 if ((vp->length < 8) ||
350 DEBUG2(" TTLS: Tunneled challenge has invalid length");
356 uint8_t challenge[16];
358 eapttls_gen_challenge(ssl, challenge,
361 for (i = 0; i < vp->length; i++) {
362 if (challenge[i] != vp->vp_strvalue[i]) {
363 DEBUG2(" TTLS: Tunneled challenge is incorrect");
373 } /* switch over checking/re-writing of attributes. */
382 * Catch non-aligned attributes.
384 if (data_left == length) break;
387 * The length does NOT include the padding, so
388 * we've got to account for it here by rounding up
389 * to the nearest 4-byte boundary.
394 rad_assert(data_left >= length);
396 data += length - offset; /* already updated */
400 * We got this far. It looks OK.
406 * Convert VALUE_PAIR's to diameter attributes, and write them
409 * The ONLY VALUE_PAIR's which may be passed to this function
410 * are ones which can go inside of a RADIUS (i.e. diameter)
411 * packet. So no server-configuration attributes, or the like.
413 static int vp2diameter(tls_session_t *tls_session, VALUE_PAIR *first)
416 * RADIUS packets are no more than 4k in size, so if
417 * we've got more than 4k of data to write, it's very
420 uint8_t buffer[4096];
431 for (vp = first; vp != NULL; vp = vp->next) {
433 * Too much data: die.
435 if ((total + vp->length + 12) >= sizeof(buffer)) {
436 DEBUG2(" TTLS output buffer is full!");
441 * Hmm... we don't group multiple EAP-Messages
442 * together. Maybe we should...
446 * Length is no more than 253, due to RADIUS
450 vendor = (vp->attribute >> 16) & 0xffff;
452 attr = vp->attribute & 0xffff;
455 attr = vp->attribute;
459 * Hmm... set the M bit for all attributes?
465 memcpy(p, &attr, sizeof(attr));
469 length += 8; /* includes 8 bytes of attr & length */
472 length += 4; /* include 4 bytes of vendor */
474 length = ntohl(length);
475 memcpy(p, &length, sizeof(length));
479 vendor = ntohl(vendor);
480 memcpy(p, &vendor, sizeof(vendor));
484 length = ntohl(length);
485 memcpy(p, &length, sizeof(length));
491 case PW_TYPE_INTEGER:
493 attr = ntohl(vp->lvalue); /* stored in host order */
494 memcpy(p, &attr, sizeof(attr));
499 attr = vp->lvalue; /* stored in network order */
500 memcpy(p, &attr, sizeof(attr));
507 memcpy(p, vp->vp_strvalue, vp->length);
513 * Skip to the end of the data.
519 * Align the data to a multiple of 4 bytes.
521 if ((total & 0x03) != 0) {
524 length = 4 - (total & 0x03);
525 for (i = 0; i < length; i++) {
531 } /* loop over the VP's to write. */
534 * Write the data in the buffer to the SSL session.
540 if (debug_flag > 2) {
541 for (i = 0; i < total; i++) {
542 if ((i & 0x0f) == 0) printf(" TTLS tunnel data out %04x: ", i);
544 printf("%02x ", buffer[i]);
546 if ((i & 0x0f) == 0x0f) printf("\n");
548 if ((total & 0x0f) != 0) printf("\n");
552 (tls_session->record_plus)(&tls_session->clean_in, buffer, total);
555 * FIXME: Check the return code.
557 tls_handshake_send(tls_session);
567 * Use a reply packet to determine what to do.
569 static int process_reply(EAP_HANDLER *handler, tls_session_t *tls_session,
570 REQUEST *request, RADIUS_PACKET *reply)
572 int rcode = RLM_MODULE_REJECT;
574 ttls_tunnel_t *t = tls_session->opaque;
576 handler = handler; /* -Wunused */
579 * If the response packet was Access-Accept, then
580 * we're OK. If not, die horribly.
582 * FIXME: Take MS-CHAP2-Success attribute, and
583 * tunnel it back to the client, to authenticate
584 * ourselves to the client.
586 * FIXME: If we have an Access-Challenge, then
587 * the Reply-Message is tunneled back to the client.
589 * FIXME: If we have an EAP-Message, then that message
590 * must be tunneled back to the client.
592 * FIXME: If we have an Access-Challenge with a State
593 * attribute, then do we tunnel that to the client, or
594 * keep track of it ourselves?
596 * FIXME: EAP-Messages can only start with 'identity',
597 * NOT 'eap start', so we should check for that....
599 switch (reply->code) {
600 case PW_AUTHENTICATION_ACK:
601 DEBUG2(" TTLS: Got tunneled Access-Accept");
603 rcode = RLM_MODULE_OK;
606 * MS-CHAP2-Success means that we do NOT return
607 * an Access-Accept, but instead tunnel that
608 * attribute to the client, and keep going with
609 * the TTLS session. Once the client accepts
610 * our identity, it will respond with an empty
611 * packet, and we will send EAP-Success.
614 pairmove2(&vp, &reply->vps, PW_MSCHAP2_SUCCESS);
616 DEBUG2(" TTLS: Got MS-CHAP2-Success, tunneling it to the client in a challenge.");
617 rcode = RLM_MODULE_HANDLED;
618 t->authenticated = TRUE;
619 } else { /* no MS-CHAP2-Success */
621 * Can only have EAP-Message if there's
622 * no MS-CHAP2-Success. (FIXME: EAP-MSCHAP?)
624 * We also do NOT tunnel the EAP-Success
625 * attribute back to the client, as the client
626 * can figure it out, from the non-tunneled
627 * EAP-Success packet.
629 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
634 * Handle the ACK, by tunneling any necessary reply
635 * VP's back to the client.
638 vp2diameter(tls_session, vp);
643 * If we've been told to use the attributes from
644 * the reply, then do so.
646 * WARNING: This may leak information about the
649 if (t->use_tunneled_reply) {
650 pairdelete(&reply->vps, PW_PROXY_STATE);
651 pairadd(&request->reply->vps, reply->vps);
657 case PW_AUTHENTICATION_REJECT:
658 DEBUG2(" TTLS: Got tunneled Access-Reject");
659 rcode = RLM_MODULE_REJECT;
663 * Handle Access-Challenge, but only if we
664 * send tunneled reply data. This is because
665 * an Access-Challenge means that we MUST tunnel
666 * a Reply-Message to the client.
668 case PW_ACCESS_CHALLENGE:
669 DEBUG2(" TTLS: Got tunneled Access-Challenge");
672 * Keep the State attribute, if necessary.
674 * Get rid of the old State, too.
677 pairmove2(&t->state, &reply->vps, PW_STATE);
680 * We should really be a bit smarter about this,
681 * and move over only those attributes which
682 * are relevant to the authentication request,
683 * but that's a lot more work, and this "dumb"
684 * method works in 99.9% of the situations.
687 pairmove2(&vp, &reply->vps, PW_EAP_MESSAGE);
690 * There MUST be a Reply-Message in the challenge,
691 * which we tunnel back to the client.
693 * If there isn't one in the reply VP's, then
694 * we MUST create one, with an empty string as
697 pairmove2(&vp, &reply->vps, PW_REPLY_MESSAGE);
700 * Handle the ACK, by tunneling any necessary reply
701 * VP's back to the client.
704 vp2diameter(tls_session, vp);
707 rcode = RLM_MODULE_HANDLED;
711 DEBUG2(" TTLS: Unknown RADIUS packet type %d: rejecting tunneled user", reply->code);
712 rcode = RLM_MODULE_INVALID;
721 * Do post-proxy processing,
723 static int eapttls_postproxy(EAP_HANDLER *handler, void *data)
726 tls_session_t *tls_session = (tls_session_t *) data;
729 DEBUG2(" TTLS: Passing reply from proxy back into the tunnel.");
732 * If there was a fake request associated with the proxied
733 * request, do more processing of it.
735 fake = (REQUEST *) request_data_get(handler->request,
736 handler->request->proxy,
737 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK);
740 * Do the callback, if it exists, and if it was a success.
742 if (fake && (handler->request->proxy_reply->code == PW_AUTHENTICATION_ACK)) {
744 REQUEST *request = handler->request;
749 rad_assert(fake->packet == NULL);
750 fake->packet = request->proxy;
751 request->proxy = NULL;
753 rad_assert(fake->reply == NULL);
754 fake->reply = request->proxy_reply;
755 request->proxy_reply = NULL;
758 * Perform a post-auth stage for the tunneled
761 fake->options &= ~RAD_REQUEST_OPTION_PROXY_EAP;
762 rcode = rad_postauth(fake);
763 DEBUG2(" POST-AUTH %d", rcode);
766 if (debug_flag > 0) {
767 printf(" TTLS: Final reply from tunneled session code %d\n",
770 for (vp = fake->reply->vps; vp != NULL; vp = vp->next) {
771 putchar('\t');vp_print(stdout, vp);putchar('\n');
779 request->proxy = fake->packet;
781 request->proxy_reply = fake->reply;
785 * And we're done with this request.
789 case RLM_MODULE_FAIL:
791 eaptls_fail(handler->eap_ds, 0);
795 default: /* Don't Do Anything */
796 DEBUG2(" TTLS: Got reply %d",
797 request->proxy_reply->code);
801 request_free(&fake); /* robust if fake == NULL */
804 * Process the reply from the home server.
806 rcode = process_reply(handler, tls_session, handler->request,
807 handler->request->proxy_reply);
810 * The proxy code uses the reply from the home server as
811 * the basis for the reply to the NAS. We don't want that,
812 * so we toss it, after we've had our way with it.
814 pairfree(&handler->request->proxy_reply->vps);
817 case RLM_MODULE_REJECT:
818 DEBUG2(" TTLS: Reply was rejected");
821 case RLM_MODULE_HANDLED:
822 DEBUG2(" TTLS: Reply was handled");
823 eaptls_request(handler->eap_ds, tls_session);
827 DEBUG2(" TTLS: Reply was OK");
828 eaptls_success(handler->eap_ds, 0);
829 eaptls_gen_mppe_keys(&handler->request->reply->vps,
831 "ttls keying material");
835 DEBUG2(" TTLS: Reply was unknown.");
839 eaptls_fail(handler->eap_ds, 0);
847 static void my_request_free(void *data)
849 REQUEST *request = (REQUEST *)data;
851 request_free(&request);
856 * Process the "diameter" contents of the tunneled data.
858 int eapttls_process(EAP_HANDLER *handler, tls_session_t *tls_session)
861 int rcode = PW_AUTHENTICATION_REJECT;
866 unsigned int data_len;
868 REQUEST *request = handler->request;
871 * Grab the dirty data, and copy it to our buffer.
873 * I *really* don't like these 'record_t' things...
875 data_len = (tls_session->record_minus)(&tls_session->dirty_in, buffer, sizeof(buffer));
879 * Write the data from the dirty buffer (i.e. packet
880 * data) into the buffer which we will give to SSL for
883 * Some of this code COULD technically go into the TLS
884 * module, in eaptls_process(), where it returns EAPTLS_OK.
886 * Similarly, the writing of data to the SSL context could
889 BIO_write(tls_session->into_ssl, buffer, data_len);
890 (tls_session->record_init)(&tls_session->clean_out);
893 * Read (and decrypt) the tunneled data from the SSL session,
894 * and put it into the decrypted data buffer.
896 err = SSL_read(tls_session->ssl, tls_session->clean_out.data,
897 sizeof(tls_session->clean_out.data));
900 * FIXME: Call SSL_get_error() to see what went
903 radlog(L_INFO, "rlm_eap_ttls: SSL_read Error");
904 return PW_AUTHENTICATION_REJECT;
907 t = (ttls_tunnel_t *) tls_session->opaque;
910 * If there's no data, maybe this is an ACK to an
914 if (t->authenticated) {
915 DEBUG2(" TTLS: Got ACK, and the user was already authenticated.");
916 return PW_AUTHENTICATION_ACK;
917 } /* else no session, no data, die. */
920 * FIXME: Call SSL_get_error() to see what went
923 radlog(L_INFO, "rlm_eap_ttls: SSL_read Error");
924 return PW_AUTHENTICATION_REJECT;
927 data_len = tls_session->clean_out.used = err;
928 data = tls_session->clean_out.data;
931 if (debug_flag > 2) {
934 for (i = 0; i < data_len; i++) {
935 if ((i & 0x0f) == 0) printf(" TTLS tunnel data in %04x: ", i);
937 printf("%02x ", data[i]);
939 if ((i & 0x0f) == 0x0f) printf("\n");
941 if ((data_len & 0x0f) != 0) printf("\n");
945 if (!diameter_verify(data, data_len)) {
946 return PW_AUTHENTICATION_REJECT;
950 * Allocate a fake REQUEST structe.
952 fake = request_alloc_fake(request);
954 rad_assert(fake->packet->vps == NULL);
957 * Add the tunneled attributes to the fake request.
959 fake->packet->vps = diameter2vp(tls_session->ssl, data, data_len);
960 if (!fake->packet->vps) {
961 return PW_AUTHENTICATION_REJECT;
965 * Tell the request that it's a fake one.
967 vp = pairmake("Freeradius-Proxied-To", "127.0.0.1", T_OP_EQ);
969 pairadd(&fake->packet->vps, vp);
973 if (debug_flag > 0) {
974 printf(" TTLS: Got tunneled request\n");
976 for (vp = fake->packet->vps; vp != NULL; vp = vp->next) {
977 putchar('\t');vp_print(stdout, vp);putchar('\n');
983 * Update other items in the REQUEST data structure.
985 fake->username = pairfind(fake->packet->vps, PW_USER_NAME);
986 fake->password = pairfind(fake->packet->vps, PW_USER_PASSWORD);
989 * No User-Name, try to create one from stored data.
991 if (!fake->username) {
993 * No User-Name in the stored data, look for
994 * an EAP-Identity, and pull it out of there.
997 vp = pairfind(fake->packet->vps, PW_EAP_MESSAGE);
999 (vp->length >= EAP_HEADER_LEN + 2) &&
1000 (vp->vp_strvalue[0] == PW_EAP_RESPONSE) &&
1001 (vp->vp_strvalue[EAP_HEADER_LEN] == PW_EAP_IDENTITY) &&
1002 (vp->vp_strvalue[EAP_HEADER_LEN + 1] != 0)) {
1004 * Create & remember a User-Name
1006 t->username = pairmake("User-Name", "", T_OP_EQ);
1007 rad_assert(t->username != NULL);
1009 memcpy(t->username->vp_strvalue, vp->vp_strvalue + 5,
1011 t->username->length = vp->length - 5;
1012 t->username->vp_strvalue[t->username->length] = 0;
1014 DEBUG2(" TTLS: Got tunneled identity of %s",
1015 t->username->vp_strvalue);
1018 * If there's a default EAP type,
1021 if (t->default_eap_type != 0) {
1022 DEBUG2(" TTLS: Setting default EAP type for tunneled EAP session.");
1023 vp = paircreate(PW_EAP_TYPE,
1025 rad_assert(vp != NULL);
1026 vp->lvalue = t->default_eap_type;
1027 pairadd(&fake->config_items, vp);
1032 * Don't reject the request outright,
1033 * as it's permitted to do EAP without
1036 DEBUG2(" rlm_eap_ttls: WARNING! No EAP-Identity found to start EAP conversation.");
1038 } /* else there WAS a t->username */
1041 vp = paircopy(t->username);
1042 pairadd(&fake->packet->vps, vp);
1043 fake->username = pairfind(fake->packet->vps, PW_USER_NAME);
1045 } /* else the request ALREADY had a User-Name */
1048 * Add the State attribute, too, if it exists.
1051 DEBUG2(" TTLS: Adding old state with %02x %02x",
1052 t->state->vp_strvalue[0], t->state->vp_strvalue[1]);
1053 vp = paircopy(t->state);
1054 if (vp) pairadd(&fake->packet->vps, vp);
1058 * If this is set, we copy SOME of the request attributes
1059 * from outside of the tunnel to inside of the tunnel.
1061 * We copy ONLY those attributes which do NOT already
1062 * exist in the tunneled request.
1064 if (t->copy_request_to_tunnel) {
1067 for (vp = request->packet->vps; vp != NULL; vp = vp->next) {
1069 * The attribute is a server-side thingy,
1072 if ((vp->attribute > 255) &&
1073 (((vp->attribute >> 16) & 0xffff) == 0)) {
1078 * The outside attribute is already in the
1079 * tunnel, don't copy it.
1081 * This works for BOTH attributes which
1082 * are originally in the tunneled request,
1083 * AND attributes which are copied there
1086 if (pairfind(fake->packet->vps, vp->attribute)) {
1091 * Some attributes are handled specially.
1093 switch (vp->attribute) {
1095 * NEVER copy Message-Authenticator,
1096 * EAP-Message, or State. They're
1097 * only for outside of the tunnel.
1100 case PW_USER_PASSWORD:
1101 case PW_CHAP_PASSWORD:
1102 case PW_CHAP_CHALLENGE:
1103 case PW_PROXY_STATE:
1104 case PW_MESSAGE_AUTHENTICATOR:
1105 case PW_EAP_MESSAGE:
1111 * By default, copy it over.
1118 * Don't copy from the head, we've already
1121 copy = paircopy2(vp, vp->attribute);
1122 pairadd(&fake->packet->vps, copy);
1127 if (debug_flag > 0) {
1128 printf(" TTLS: Sending tunneled request\n");
1130 for (vp = fake->packet->vps; vp != NULL; vp = vp->next) {
1131 putchar('\t');vp_print(stdout, vp);putchar('\n');
1137 * Call authentication recursively, which will
1138 * do PAP, CHAP, MS-CHAP, etc.
1140 rad_authenticate(fake);
1143 * Note that we don't do *anything* with the reply
1147 if (debug_flag > 0) {
1148 printf(" TTLS: Got tunneled reply RADIUS code %d\n",
1151 for (vp = fake->reply->vps; vp != NULL; vp = vp->next) {
1152 putchar('\t');vp_print(stdout, vp);putchar('\n');
1158 * Decide what to do with the reply.
1160 switch (fake->reply->code) {
1161 case 0: /* No reply code, must be proxied... */
1162 vp = pairfind(fake->config_items, PW_PROXY_TO_REALM);
1164 eap_tunnel_data_t *tunnel;
1165 DEBUG2(" TTLS: Tunneled authentication will be proxied to %s", vp->vp_strvalue);
1168 * Tell the original request that it's going
1171 pairmove2(&(request->config_items),
1172 &(fake->config_items),
1176 * Seed the proxy packet with the
1179 rad_assert(request->proxy == NULL);
1180 request->proxy = fake->packet;
1181 fake->packet = NULL;
1182 rad_free(&fake->reply);
1186 * Set up the callbacks for the tunnel
1188 tunnel = rad_malloc(sizeof(*tunnel));
1189 memset(tunnel, 0, sizeof(*tunnel));
1191 tunnel->tls_session = tls_session;
1192 tunnel->callback = eapttls_postproxy;
1195 * Associate the callback with the request.
1197 rcode = request_data_add(request,
1199 REQUEST_DATA_EAP_TUNNEL_CALLBACK,
1201 rad_assert(rcode == 0);
1204 * rlm_eap.c has taken care of associating
1205 * the handler with the fake request.
1207 * So we associate the fake request with
1210 rcode = request_data_add(request,
1212 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK,
1213 fake, my_request_free);
1214 rad_assert(rcode == 0);
1218 * Didn't authenticate the packet, but
1219 * we're proxying it.
1221 rcode = PW_STATUS_CLIENT;
1224 DEBUG2(" TTLS: No tunneled reply was found for request %d , and the request was not proxied: rejecting the user.",
1226 rcode = PW_AUTHENTICATION_REJECT;
1232 * Returns RLM_MODULE_FOO, and we want to return
1235 rcode = process_reply(handler, tls_session, request,
1238 case RLM_MODULE_REJECT:
1239 rcode = PW_AUTHENTICATION_REJECT;
1242 case RLM_MODULE_HANDLED:
1243 rcode = PW_ACCESS_CHALLENGE;
1247 rcode = PW_AUTHENTICATION_ACK;
1251 rcode = PW_AUTHENTICATION_REJECT;
1257 request_free(&fake);