2 * peap.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>
30 * Send protected EAP-Failure
32 * Result-TLV = Failure
34 static int eappeap_failure(EAP_HANDLER *handler, tls_session_t *tls_session)
36 uint8_t tlv_packet[11];
37 REQUEST *request = handler->request;
41 tlv_packet[0] = PW_EAP_REQUEST;
42 tlv_packet[1] = handler->eap_ds->response->id +1;
44 tlv_packet[3] = 11; /* length of this packet */
45 tlv_packet[4] = PW_EAP_TLV;
47 tlv_packet[6] = EAP_TLV_ACK_RESULT;
49 tlv_packet[8] = 2; /* length of the data portion */
51 tlv_packet[10] = EAP_TLV_FAILURE;
53 (tls_session->record_plus)(&tls_session->clean_in, tlv_packet, 11);
56 * FIXME: Check the return code.
58 tls_handshake_send(request, tls_session);
65 * Send protected EAP-Success
67 * Result-TLV = Success
69 static int eappeap_success(EAP_HANDLER *handler, tls_session_t *tls_session)
71 uint8_t tlv_packet[11];
72 REQUEST *request = handler->request;
76 tlv_packet[0] = PW_EAP_REQUEST;
77 tlv_packet[1] = handler->eap_ds->response->id +1;
79 tlv_packet[3] = 11; /* length of this packet */
80 tlv_packet[4] = PW_EAP_TLV;
81 tlv_packet[5] = 0x80; /* mandatory AVP */
82 tlv_packet[6] = EAP_TLV_ACK_RESULT;
84 tlv_packet[8] = 2; /* length of the data portion */
86 tlv_packet[10] = EAP_TLV_SUCCESS;
88 (tls_session->record_plus)(&tls_session->clean_in, tlv_packet, 11);
91 * FIXME: Check the return code.
93 tls_handshake_send(request, tls_session);
99 static int eappeap_identity(EAP_HANDLER *handler, tls_session_t *tls_session)
101 eap_packet_t eap_packet;
103 eap_packet.code = PW_EAP_REQUEST;
104 eap_packet.id = handler->eap_ds->response->id + 1;
105 eap_packet.length[0] = 0;
106 eap_packet.length[1] = EAP_HEADER_LEN + 1;
107 eap_packet.data[0] = PW_EAP_IDENTITY;
109 (tls_session->record_plus)(&tls_session->clean_in,
110 &eap_packet, sizeof(eap_packet));
112 tls_handshake_send(handler->request, tls_session);
113 (tls_session->record_init)(&tls_session->clean_in);
120 * Verify the tunneled EAP message.
122 static int eapmessage_verify(REQUEST *request,
123 const uint8_t *data, unsigned int data_len)
125 const eap_packet_t *eap_packet = (const eap_packet_t *) data;
130 * No data, OR only 1 byte of EAP type.
132 if (!data || (data_len == 0) ||
133 ((data_len <= 1) && (data[0] != PW_EAP_IDENTITY))) {
139 case PW_EAP_IDENTITY:
141 RDEBUG2("Identity - ");
144 RDEBUG2("Identity - %*s",
145 data_len - 1, data + 1);
150 * If the first byte of the packet is
151 * EAP-Response, and the EAP data is a TLV,
152 * then it looks OK...
154 case PW_EAP_RESPONSE:
155 if (eap_packet->data[0] == PW_EAP_TLV) {
156 RDEBUG2("Received EAP-TLV response.");
159 RDEBUG2("Got something weird.");
164 * We normally do Microsoft MS-CHAPv2 (26), versus
165 * Cisco MS-CHAPv2 (29).
167 case PW_EAP_MSCHAPV2:
169 RDEBUG2("EAP type %s",
170 eaptype_type2name(eap_type,
171 buffer, sizeof(buffer)));
180 * Convert a pseudo-EAP packet to a list of VALUE_PAIR's.
182 static VALUE_PAIR *eap2vp(REQUEST *request, EAP_DS *eap_ds,
183 const uint8_t *data, size_t data_len)
186 VALUE_PAIR *vp = NULL, *head, **tail;
188 if (data_len > 65535) return NULL; /* paranoia */
190 vp = paircreate(PW_EAP_MESSAGE, 0, PW_TYPE_OCTETS);
192 RDEBUG2("Failure in creating VP");
197 if (total > 249) total = 249;
200 * Hand-build an EAP packet from the crap in PEAP version 0.
202 vp->vp_octets[0] = PW_EAP_RESPONSE;
203 vp->vp_octets[1] = eap_ds->response->id;
204 vp->vp_octets[2] = (data_len + EAP_HEADER_LEN) >> 8;
205 vp->vp_octets[3] = (data_len + EAP_HEADER_LEN) & 0xff;
207 memcpy(vp->vp_octets + EAP_HEADER_LEN, data, total);
208 vp->length = EAP_HEADER_LEN + total;
212 while (total < data_len) {
216 vp = paircreate(PW_EAP_MESSAGE, 0, PW_TYPE_OCTETS);
218 RDEBUG2("Failure in creating VP");
222 vp_len = (data_len - total);
223 if (vp_len > 253) vp_len = 253;
225 memcpy(vp->vp_octets, data + total, vp_len);
238 * Convert a list of VALUE_PAIR's to an EAP packet, through the
239 * simple expedient of dumping the EAP message
241 static int vp2eap(REQUEST *request, tls_session_t *tls_session, VALUE_PAIR *vp)
244 * Skip the id, code, and length. Just write the EAP
245 * type & data to the client.
248 if ((debug_flag > 2) && fr_log_fp) {
254 for (this = vp; this != NULL; this = this->next) {
257 if (this == vp) start = EAP_HEADER_LEN;
259 for (i = start; i < vp->length; i++) {
260 if ((total & 0x0f) == 0) fprintf(fr_log_fp, " PEAP tunnel data out %04x: ", (int) total);
262 fprintf(fr_log_fp, "%02x ", vp->vp_octets[i]);
264 if ((total & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
268 if ((total & 0x0f) != 0) fprintf(fr_log_fp, "\n");
273 * Send the EAP data, WITHOUT the header.
275 (tls_session->record_plus)(&tls_session->clean_in,
276 vp->vp_octets + EAP_HEADER_LEN,
277 vp->length - EAP_HEADER_LEN);
280 * Send the rest of the EAP data.
282 for (vp = vp->next; vp != NULL; vp = vp->next) {
283 (tls_session->record_plus)(&tls_session->clean_in,
284 vp->vp_octets, vp->length);
287 tls_handshake_send(request, tls_session);
294 * See if there's a TLV in the response.
296 static int eappeap_check_tlv(REQUEST *request, const uint8_t *data)
298 const eap_packet_t *eap_packet = (const eap_packet_t *) data;
301 * Look for success or failure.
303 if ((eap_packet->code == PW_EAP_RESPONSE) &&
304 (eap_packet->data[0] == PW_EAP_TLV)) {
305 if (data[10] == EAP_TLV_SUCCESS) {
309 if (data[10] == EAP_TLV_FAILURE) {
310 RDEBUG2("Client rejected our response. The password is probably incorrect.");
320 * Use a reply packet to determine what to do.
322 static int process_reply(EAP_HANDLER *handler, tls_session_t *tls_session,
323 REQUEST *request, RADIUS_PACKET *reply)
325 int rcode = RLM_MODULE_REJECT;
327 peap_tunnel_t *t = tls_session->opaque;
329 if ((debug_flag > 0) && fr_log_fp) {
330 RDEBUG("Got tunneled reply RADIUS code %d",
333 debug_pair_list(reply->vps);
336 switch (reply->code) {
337 case PW_AUTHENTICATION_ACK:
338 RDEBUG2("Tunneled authentication was successful.");
339 t->status = PEAP_STATUS_SENT_TLV_SUCCESS;
340 eappeap_success(handler, tls_session);
341 rcode = RLM_MODULE_HANDLED;
344 * If we've been told to use the attributes from
345 * the reply, then do so.
347 * WARNING: This may leak information about the
350 if (t->use_tunneled_reply) {
351 RDEBUG2("Saving tunneled attributes for later");
354 * Clean up the tunneled reply.
356 pairdelete(&reply->vps, PW_PROXY_STATE, 0);
357 pairdelete(&reply->vps, PW_EAP_MESSAGE, 0);
358 pairdelete(&reply->vps, PW_MESSAGE_AUTHENTICATOR, 0);
361 * Delete MPPE keys & encryption policy. We don't
364 pairdelete(&reply->vps, 7, VENDORPEC_MICROSOFT);
365 pairdelete(&reply->vps, 8, VENDORPEC_MICROSOFT);
366 pairdelete(&reply->vps, 16, VENDORPEC_MICROSOFT);
367 pairdelete(&reply->vps, 17, VENDORPEC_MICROSOFT);
369 t->accept_vps = reply->vps;
374 case PW_AUTHENTICATION_REJECT:
375 RDEBUG2("Tunneled authentication was rejected.");
376 t->status = PEAP_STATUS_SENT_TLV_FAILURE;
377 eappeap_failure(handler, tls_session);
378 rcode = RLM_MODULE_HANDLED;
381 case PW_ACCESS_CHALLENGE:
382 RDEBUG2("Got tunneled Access-Challenge");
385 * Keep the State attribute, if necessary.
387 * Get rid of the old State, too.
390 pairmove2(&t->state, &(reply->vps), PW_STATE, 0);
393 * PEAP takes only EAP-Message attributes inside
394 * of the tunnel. Any Reply-Message in the
395 * Access-Challenge is ignored.
398 pairmove2(&vp, &(reply->vps), PW_EAP_MESSAGE, 0);
401 * Handle EAP-MSCHAP-V2, where Access-Accept's
402 * from the home server may contain MS-CHAP-Success,
403 * which the module turns into challenges, so that
404 * the client may respond to the challenge with
407 if (t->home_access_accept && t->use_tunneled_reply) {
408 RDEBUG2("Saving tunneled attributes for later");
411 * Clean up the tunneled reply.
413 pairdelete(&reply->vps, PW_PROXY_STATE, 0);
414 pairdelete(&reply->vps, PW_MESSAGE_AUTHENTICATOR, 0);
416 t->accept_vps = reply->vps;
421 * Handle the ACK, by tunneling any necessary reply
422 * VP's back to the client.
425 vp2eap(request, tls_session, vp);
429 rcode = RLM_MODULE_HANDLED;
433 RDEBUG2("Unknown RADIUS packet type %d: rejecting tunneled user", reply->code);
434 rcode = RLM_MODULE_REJECT;
443 * Do post-proxy processing,
445 static int eappeap_postproxy(EAP_HANDLER *handler, void *data)
448 tls_session_t *tls_session = (tls_session_t *) data;
449 REQUEST *fake, *request = handler->request;
451 RDEBUG2("Passing reply from proxy back into the tunnel.");
454 * If there was a fake request associated with the proxied
455 * request, do more processing of it.
457 fake = (REQUEST *) request_data_get(handler->request,
458 handler->request->proxy,
459 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK);
462 * Do the callback, if it exists, and if it was a success.
464 if (fake && (handler->request->proxy_reply->code == PW_AUTHENTICATION_ACK)) {
465 peap_tunnel_t *t = tls_session->opaque;
467 t->home_access_accept = TRUE;
472 rad_assert(fake->packet == NULL);
473 fake->packet = request->proxy;
474 fake->packet->src_ipaddr = request->packet->src_ipaddr;
475 request->proxy = NULL;
477 rad_assert(fake->reply == NULL);
478 fake->reply = request->proxy_reply;
479 request->proxy_reply = NULL;
481 if ((debug_flag > 0) && fr_log_fp) {
482 fprintf(fr_log_fp, "server %s {\n", fake->server);
486 * Perform a post-auth stage, which will get the EAP
489 fake->options &= ~RAD_REQUEST_OPTION_PROXY_EAP;
490 RDEBUG2("Passing reply back for EAP-MS-CHAP-V2");
491 rcode = module_post_proxy(0, fake);
494 * FIXME: If rcode returns fail, do something
497 rcode = rad_postauth(fake);
499 if ((debug_flag > 0) && fr_log_fp) {
500 fprintf(fr_log_fp, "} # server %s\n", fake->server);
502 RDEBUG("Final reply from tunneled session code %d",
505 debug_pair_list(fake->reply->vps);
511 request->proxy = fake->packet;
513 request->proxy_reply = fake->reply;
517 * And we're done with this request.
521 case RLM_MODULE_FAIL:
523 eaptls_fail(handler, 0);
527 default: /* Don't Do Anything */
528 RDEBUG2("Got reply %d", request->proxy_reply->code);
532 request_free(&fake); /* robust if fake == NULL */
535 * If there was no EAP-Message in the reply packet, then
536 * we know that we're supposed to re-run the "authenticate"
537 * stage, in order to get the right kind of handling...
541 * Process the reply from the home server.
544 rcode = process_reply(handler, tls_session, handler->request,
545 handler->request->proxy_reply);
548 * The proxy code uses the reply from the home server as
549 * the basis for the reply to the NAS. We don't want that,
550 * so we toss it, after we've had our way with it.
552 pairfree(&handler->request->proxy_reply->vps);
555 case RLM_MODULE_REJECT:
556 RDEBUG2("Reply was rejected");
557 eaptls_fail(handler, 0);
560 case RLM_MODULE_HANDLED:
561 RDEBUG2("Reply was handled");
562 eaptls_request(handler->eap_ds, tls_session);
566 RDEBUG2("Reply was OK");
569 * Success: Automatically return MPPE keys.
571 return eaptls_success(handler, 0);
574 RDEBUG2("Reply was unknown.");
578 eaptls_fail(handler, 0);
585 static void my_request_free(void *data)
587 REQUEST *request = (REQUEST *)data;
589 request_free(&request);
594 static const char *peap_state(peap_tunnel_t *t)
597 case PEAP_STATUS_TUNNEL_ESTABLISHED:
598 return "TUNNEL ESTABLISHED";
599 case PEAP_STATUS_INNER_IDENTITY_REQ_SENT:
600 return "WAITING FOR INNER IDENTITY";
601 case PEAP_STATUS_SENT_TLV_SUCCESS:
602 return "send tlv success";
603 case PEAP_STATUS_SENT_TLV_FAILURE:
604 return "send tlv failure";
605 case PEAP_STATUS_PHASE2_INIT:
606 return "phase2_init";
607 case PEAP_STATUS_PHASE2:
615 static void print_tunneled_data(const uint8_t *data, size_t data_len)
619 if ((debug_flag > 2) && fr_log_fp) {
620 for (i = 0; i < data_len; i++) {
621 if ((i & 0x0f) == 0) fprintf(fr_log_fp, " PEAP tunnel data in %02x: ", (int) i);
623 fprintf(fr_log_fp, "%02x ", data[i]);
625 if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
627 if ((data_len & 0x0f) != 0) fprintf(fr_log_fp, "\n");
633 * Process the pseudo-EAP contents of the tunneled data.
635 int eappeap_process(EAP_HANDLER *handler, tls_session_t *tls_session)
637 peap_tunnel_t *t = tls_session->opaque;
640 int rcode = RLM_MODULE_REJECT;
642 unsigned int data_len;
644 REQUEST *request = handler->request;
645 EAP_DS *eap_ds = handler->eap_ds;
648 * Just look at the buffer directly, without doing
649 * record_minus. This lets us avoid another data copy.
651 data_len = tls_session->clean_out.used;
652 tls_session->clean_out.used = 0;
653 data = tls_session->clean_out.data;
655 RDEBUG2("Peap state %s", peap_state(t));
657 if ((t->status != PEAP_STATUS_TUNNEL_ESTABLISHED) &&
658 !eapmessage_verify(request, data, data_len)) {
659 RDEBUG2("FAILED processing PEAP: Tunneled data is invalid.");
660 if (debug_flag > 2) print_tunneled_data(data, data_len);
661 return RLM_MODULE_REJECT;
665 case PEAP_STATUS_TUNNEL_ESTABLISHED:
666 /* FIXME: should be no data in the buffer here, check & assert? */
668 if (SSL_session_reused(tls_session->ssl)) {
669 RDEBUG2("Skipping Phase2 because of session resumption");
670 t->session_resumption_state = PEAP_RESUMPTION_YES;
672 /* we're good, send success TLV */
673 t->status = PEAP_STATUS_SENT_TLV_SUCCESS;
674 eappeap_success(handler, tls_session);
677 /* send an identity request */
678 t->session_resumption_state = PEAP_RESUMPTION_NO;
679 t->status = PEAP_STATUS_INNER_IDENTITY_REQ_SENT;
680 eappeap_identity(handler, tls_session);
682 return RLM_MODULE_HANDLED;
684 case PEAP_STATUS_INNER_IDENTITY_REQ_SENT:
685 /* we're expecting an identity response */
686 if (data[0] != PW_EAP_IDENTITY) {
687 RDEBUG("Expected EAP-Identity, got something else.");
688 return RLM_MODULE_REJECT;
691 if (data_len >= sizeof(t->username->vp_strvalue)) {
692 RDEBUG("EAP-Identity is too long");
693 return RLM_MODULE_REJECT;
699 t->username = pairmake("User-Name", "", T_OP_EQ);
700 rad_assert(t->username != NULL);
702 memcpy(t->username->vp_strvalue, data + 1, data_len - 1);
703 t->username->length = data_len - 1;
704 t->username->vp_strvalue[t->username->length] = 0;
705 RDEBUG("Got inner identity '%s'", t->username->vp_strvalue);
707 t->status = PEAP_STATUS_PHASE2_INIT;
711 * If we authenticated the user, then it's OK.
713 case PEAP_STATUS_SENT_TLV_SUCCESS:
714 if (eappeap_check_tlv(request, data)) {
716 return RLM_MODULE_OK;
720 * Otherwise, the client rejected the session
721 * resumption. If the session is being re-used,
722 * we need to do a full authentication.
724 * We do this by sending an EAP-Identity request
725 * inside of the PEAP tunnel.
727 if (t->session_resumption_state == PEAP_RESUMPTION_YES) {
728 RDEBUG2("Client rejected session resumption. Re-starting full authentication");
731 * Mark session resumption status.
733 t->status = PEAP_STATUS_INNER_IDENTITY_REQ_SENT;
734 t->session_resumption_state = PEAP_RESUMPTION_NO;
736 eappeap_identity(handler, tls_session);
737 return RLM_MODULE_HANDLED;
740 RDEBUG2("We sent a success, but received something weird in return.");
741 return RLM_MODULE_REJECT;
744 * Damned if I know why the clients continue sending EAP
745 * packets after we told them to f*ck off.
747 case PEAP_STATUS_SENT_TLV_FAILURE:
748 RDEBUG(" The users session was previously rejected: returning reject (again.)");
749 RDEBUG(" *** This means you need to read the PREVIOUS messages in the debug output");
750 RDEBUG(" *** to find out the reason why the user was rejected.");
751 RDEBUG(" *** Look for \"reject\" or \"fail\". Those earlier messages will tell you.");
752 RDEBUG(" *** what went wrong, and how to fix the problem.");
753 return RLM_MODULE_REJECT;
755 case PEAP_STATUS_PHASE2_INIT:
756 RDEBUG("In state machine in phase2 init?");
758 case PEAP_STATUS_PHASE2:
762 RDEBUG2("Unhandled state in peap");
763 return RLM_MODULE_REJECT;
766 fake = request_alloc_fake(request);
768 rad_assert(fake->packet->vps == NULL);
772 * If we're in PHASE2_INIT, the phase2 method hasn't been
773 * sent an Identity packet yet; do so from the stored
774 * username and this will kick off the phase2 eap method
777 case PEAP_STATUS_PHASE2_INIT: {
778 int len = t->username->length + EAP_HEADER_LEN + 1;
780 t->status = PEAP_STATUS_PHASE2;
782 vp = paircreate(PW_EAP_MESSAGE, 0, PW_TYPE_OCTETS);
784 vp->vp_octets[0] = PW_EAP_RESPONSE;
785 vp->vp_octets[1] = eap_ds->response->id;
786 vp->vp_octets[2] = (len >> 8) & 0xff;
787 vp->vp_octets[3] = len & 0xff;
788 vp->vp_octets[4] = PW_EAP_IDENTITY;
790 memcpy(vp->vp_octets + EAP_HEADER_LEN + 1, t->username->vp_strvalue, t->username->length);
793 pairadd(&fake->packet->vps, vp);
795 if (t->default_eap_type != 0) {
796 RDEBUG2("Setting default EAP type for tunneled EAP session.");
797 vp = pairmake("EAP-Type", "0", T_OP_EQ);
798 vp->vp_integer = t->default_eap_type;
799 pairadd(&fake->config_items, vp);
803 case PEAP_STATUS_PHASE2:
804 fake->packet->vps = eap2vp(request, eap_ds, data, data_len);
805 if (!fake->packet->vps) {
807 RDEBUG2("Unable to convert tunneled EAP packet to internal server data structures");
808 return PW_AUTHENTICATION_REJECT;
813 RDEBUG("Invalid state change in PEAP.");
814 return PW_AUTHENTICATION_REJECT;
817 if ((debug_flag > 0) && fr_log_fp) {
818 RDEBUG("Got tunneled request");
820 debug_pair_list(fake->packet->vps);
822 fprintf(fr_log_fp, "server %s {\n",
823 (fake->server == NULL) ? "" : fake->server);
827 * Tell the request that it's a fake one.
829 vp = pairmake("Freeradius-Proxied-To", "127.0.0.1", T_OP_EQ);
831 pairadd(&fake->packet->vps, vp);
835 * Update other items in the REQUEST data structure.
839 * There's no User-Name in the tunneled session,
840 * so we add one here, by pulling it out of the
841 * EAP-Identity packet.
843 if ((data[0] == PW_EAP_IDENTITY) && (data_len > 1)) {
844 t->username = pairmake("User-Name", "", T_OP_EQ);
845 rad_assert(t->username != NULL);
847 memcpy(t->username->vp_strvalue, data + 1, data_len - 1);
848 t->username->length = data_len - 1;
849 t->username->vp_strvalue[t->username->length] = 0;
850 DEBUG2(" PEAP: Got tunneled identity of %s", t->username->vp_strvalue);
853 * If there's a default EAP type,
856 if (t->default_eap_type != 0) {
857 DEBUG2(" PEAP: Setting default EAP type for tunneled EAP session.");
858 vp = pairmake("EAP-Type", "0", T_OP_EQ);
859 vp->vp_integer = t->default_eap_type;
860 pairadd(&fake->config_items, vp);
863 } /* else there WAS a t->username */
866 vp = paircopy(t->username);
867 pairadd(&fake->packet->vps, vp);
868 fake->username = pairfind(fake->packet->vps, PW_USER_NAME, 0);
869 DEBUG2(" PEAP: Setting User-Name to %s",
870 fake->username->vp_strvalue);
874 * Add the State attribute, too, if it exists.
877 vp = paircopy(t->state);
878 if (vp) pairadd(&fake->packet->vps, vp);
882 * If this is set, we copy SOME of the request attributes
883 * from outside of the tunnel to inside of the tunnel.
885 * We copy ONLY those attributes which do NOT already
886 * exist in the tunneled request.
888 * This code is copied from ../rlm_eap_ttls/ttls.c
890 if (t->copy_request_to_tunnel) {
893 for (vp = request->packet->vps; vp != NULL; vp = vp->next) {
895 * The attribute is a server-side thingy,
898 if ((vp->attribute > 255) &&
904 * The outside attribute is already in the
905 * tunnel, don't copy it.
907 * This works for BOTH attributes which
908 * are originally in the tunneled request,
909 * AND attributes which are copied there
912 if (pairfind(fake->packet->vps, vp->attribute, vp->vendor)) {
917 * Some attributes are handled specially.
919 switch (vp->attribute) {
921 * NEVER copy Message-Authenticator,
922 * EAP-Message, or State. They're
923 * only for outside of the tunnel.
926 case PW_USER_PASSWORD:
927 case PW_CHAP_PASSWORD:
928 case PW_CHAP_CHALLENGE:
930 case PW_MESSAGE_AUTHENTICATOR:
937 * By default, copy it over.
944 * Don't copy from the head, we've already
947 copy = paircopy2(vp, vp->attribute, vp->vendor);
948 pairadd(&fake->packet->vps, copy);
952 if ((vp = pairfind(request->config_items, PW_VIRTUAL_SERVER, 0)) != NULL) {
953 fake->server = vp->vp_strvalue;
955 } else if (t->virtual_server) {
956 fake->server = t->virtual_server;
958 } /* else fake->server == request->server */
960 if ((debug_flag > 0) && fr_log_fp) {
961 fprintf(fr_log_fp, "Sending tunneled request\n");
963 debug_pair_list(fake->packet->vps);
965 fprintf(fr_log_fp, "server %s {\n",
966 (fake->server == NULL) ? "" : fake->server);
970 * Call authentication recursively, which will
971 * do PAP, CHAP, MS-CHAP, etc.
973 rad_authenticate(fake);
976 * Note that we don't do *anything* with the reply
979 if ((debug_flag > 0) && fr_log_fp) {
980 fprintf(fr_log_fp, "} # server %s\n",
981 (fake->server == NULL) ? "" : fake->server);
983 RDEBUG("Got tunneled reply code %d", fake->reply->code);
985 debug_pair_list(fake->reply->vps);
989 * Decide what to do with the reply.
991 switch (fake->reply->code) {
992 case 0: /* No reply code, must be proxied... */
994 vp = pairfind(fake->config_items, PW_PROXY_TO_REALM, 0);
997 eap_tunnel_data_t *tunnel;
1000 * The tunneled request was NOT handled,
1001 * it has to be proxied. This means that
1002 * the "authenticate" stage was never
1005 * If we are told to NOT proxy the
1006 * tunneled request as EAP, then this
1007 * means that we've got to decode it,
1008 * which means that we MUST run the
1009 * "authenticate" portion by hand, here.
1011 * Once the tunneled EAP session is ALMOST
1012 * done, THEN we proxy it...
1014 if (!t->proxy_tunneled_request_as_eap) {
1015 fake->options |= RAD_REQUEST_OPTION_PROXY_EAP;
1018 * Hmm... should we check for
1019 * Auth-Type & EAP-Message here?
1024 * Run the EAP authentication.
1026 DEBUG2(" PEAP: Calling authenticate in order to initiate tunneled EAP session.");
1027 rcode = module_authenticate(PW_AUTHTYPE_EAP, fake);
1028 if (rcode == RLM_MODULE_OK) {
1030 * Authentication succeeded! Rah!
1032 fake->reply->code = PW_AUTHENTICATION_ACK;
1036 if (rcode != RLM_MODULE_HANDLED) {
1037 DEBUG2(" PEAP: Can't handle the return code %d", rcode);
1038 rcode = RLM_MODULE_REJECT;
1043 * The module decided it wasn't
1044 * done. Handle it like normal.
1046 if ((fake->options & RAD_REQUEST_OPTION_PROXY_EAP) == 0) {
1047 DEBUG2(" PEAP: Cancelling proxy to realm %s until the tunneled EAP session has been established", vp->vp_strvalue);
1052 * The module has decoded the
1053 * EAP-Message into another set
1056 pairdelete(&fake->packet->vps,
1060 DEBUG2(" PEAP: Tunneled authentication will be proxied to %s", vp->vp_strvalue);
1063 * Tell the original request that it's going
1066 pairmove2(&(request->config_items),
1067 &(fake->config_items),
1068 PW_PROXY_TO_REALM, 0);
1071 * Seed the proxy packet with the
1074 rad_assert(request->proxy == NULL);
1075 request->proxy = fake->packet;
1076 memset(&request->proxy->src_ipaddr, 0,
1077 sizeof(request->proxy->src_ipaddr));
1078 memset(&request->proxy->src_ipaddr, 0,
1079 sizeof(request->proxy->src_ipaddr));
1080 request->proxy->src_port = 0;
1081 request->proxy->dst_port = 0;
1082 fake->packet = NULL;
1083 rad_free(&fake->reply);
1087 * Set up the callbacks for the tunnel
1089 tunnel = rad_malloc(sizeof(*tunnel));
1090 memset(tunnel, 0, sizeof(*tunnel));
1092 tunnel->tls_session = tls_session;
1093 tunnel->callback = eappeap_postproxy;
1096 * Associate the callback with the request.
1098 rcode = request_data_add(request,
1100 REQUEST_DATA_EAP_TUNNEL_CALLBACK,
1102 rad_assert(rcode == 0);
1105 * We're not proxying it as EAP, so we've got
1106 * to do the callback later.
1108 if ((fake->options & RAD_REQUEST_OPTION_PROXY_EAP) != 0) {
1109 DEBUG2(" PEAP: Remembering to do EAP-MS-CHAP-V2 post-proxy.");
1112 * rlm_eap.c has taken care of associating
1113 * the handler with the fake request.
1115 * So we associate the fake request with
1118 rcode = request_data_add(request,
1120 REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK,
1121 fake, my_request_free);
1122 rad_assert(rcode == 0);
1125 * Do NOT free the fake request!
1127 return RLM_MODULE_UPDATED;
1131 * Didn't authenticate the packet, but
1132 * we're proxying it.
1134 rcode = RLM_MODULE_UPDATED;
1137 #endif /* WITH_PROXY */
1139 DEBUG2(" PEAP: Unknown RADIUS packet type %d: rejecting tunneled user", fake->reply->code);
1140 rcode = RLM_MODULE_REJECT;
1146 rcode = process_reply(handler, tls_session, request,
1152 request_free(&fake);