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 2001 hereUare Communications, Inc. <raghud@hereuare.com>
21 * Copyright 2003 Alan DeKok <aland@freeradius.org>
22 * Copyright 2006 The FreeRADIUS server project
27 * TLS Packet Format in EAP
28 * --- ------ ------ -- ---
30 * 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
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Code | Identifier | Length |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Type | Flags | TLS Message Length
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * | TLS Message Length | TLS Data...
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 #include <freeradius-devel/ident.h>
44 #include <freeradius-devel/autoconf.h>
49 * Allocate a new TLS_PACKET
51 EAPTLS_PACKET *eaptls_alloc(void)
55 if ((rp = malloc(sizeof(EAPTLS_PACKET))) == NULL) {
56 radlog(L_ERR, "rlm_eap_tls: out of memory");
59 memset(rp, 0, sizeof(EAPTLS_PACKET));
66 void eaptls_free(EAPTLS_PACKET **eaptls_packet_ptr)
68 EAPTLS_PACKET *eaptls_packet;
70 if (!eaptls_packet_ptr) return;
71 eaptls_packet = *eaptls_packet_ptr;
72 if (eaptls_packet == NULL) return;
74 if (eaptls_packet->data) {
75 free(eaptls_packet->data);
76 eaptls_packet->data = NULL;
80 *eaptls_packet_ptr = NULL;
84 The S flag is set only within the EAP-TLS start message
85 sent from the EAP server to the peer.
87 int eaptls_start(EAP_DS *eap_ds, int peap_flag)
91 reply.code = EAPTLS_START;
92 reply.length = TLS_HEADER_LEN + 1/*flags*/;
94 reply.flags = peap_flag;
95 reply.flags = SET_START(reply.flags);
100 eaptls_compose(eap_ds, &reply);
105 int eaptls_success(EAP_DS *eap_ds, int peap_flag)
109 reply.code = EAPTLS_SUCCESS;
110 reply.length = TLS_HEADER_LEN;
111 reply.flags = peap_flag;
115 eaptls_compose(eap_ds, &reply);
120 int eaptls_fail(EAP_DS *eap_ds, int peap_flag)
124 reply.code = EAPTLS_FAIL;
125 reply.length = TLS_HEADER_LEN;
126 reply.flags = peap_flag;
130 eaptls_compose(eap_ds, &reply);
136 A single TLS record may be up to 16384 octets in length, but a TLS
137 message may span multiple TLS records, and a TLS certificate message
138 may in principle be as long as 16MB.
142 * Frame the Dirty data that needs to be send to the client in an
143 * EAP-Request. We always embed the TLS-length in all EAP-TLS
144 * packets that we send, for easy reference purpose. Handle
145 * fragmentation and sending the next fragment etc.
147 int eaptls_request(EAP_DS *eap_ds, tls_session_t *ssn)
152 unsigned int lbit = 0;
154 /* This value determines whether we set (L)ength flag for
155 EVERY packet we send and add corresponding
156 "TLS Message Length" field.
159 This means we include L flag and "TLS Msg Len" in EVERY
163 This means we include L flag and "TLS Msg Len" **ONLY**
164 in First packet of a fragment series. We do not use
167 Having L flag in every packet is prefered.
170 if (ssn->length_flag) {
173 if (ssn->fragment == 0) {
174 ssn->tls_msg_len = ssn->dirty_out.used;
177 reply.code = EAPTLS_REQUEST;
178 reply.flags = ssn->peap_flag;
180 /* Send data, NOT more than the FRAGMENT size */
181 if (ssn->dirty_out.used > ssn->offset) {
183 reply.flags = SET_MORE_FRAGMENTS(reply.flags);
184 /* Length MUST be included if it is the First Fragment */
185 if (ssn->fragment == 0) {
190 size = ssn->dirty_out.used;
194 reply.dlen = lbit + size;
195 reply.length = TLS_HEADER_LEN + 1/*flags*/ + reply.dlen;
197 reply.data = malloc(reply.dlen);
199 nlen = htonl(ssn->tls_msg_len);
200 memcpy(reply.data, &nlen, lbit);
201 reply.flags = SET_LENGTH_INCLUDED(reply.flags);
203 (ssn->record_minus)(&ssn->dirty_out, reply.data + lbit, size);
205 eaptls_compose(eap_ds, &reply);
213 * Acknowledge received is for one of the following messages sent earlier
214 * 1. Handshake completed Message, so now send, EAP-Success
215 * 2. Alert Message, now send, EAP-Failure
216 * 3. Fragment Message, now send, next Fragment
218 static eaptls_status_t eaptls_ack_handler(EAP_HANDLER *handler)
220 tls_session_t *tls_session;
221 REQUEST *request = handler->request;
223 tls_session = (tls_session_t *)handler->opaque;
224 if (tls_session == NULL){
225 radlog_request(L_ERR, 0, request, "Unexpected ACK received");
228 if (tls_session->info.initialized == 0) {
229 RDEBUG("No SSL info available. Waiting for more SSL data.");
230 return EAPTLS_REQUEST;
232 if (tls_session->info.origin == 0) {
233 radlog_request(L_ERR, 0, request, "Unexpected ACK received");
237 switch (tls_session->info.content_type) {
239 RDEBUG2("ACK alert");
240 eaptls_fail(handler->eap_ds, tls_session->peap_flag);
244 if ((tls_session->info.handshake_type == finished) &&
245 (tls_session->dirty_out.used == 0)) {
246 RDEBUG2("ACK handshake is finished");
247 return EAPTLS_SUCCESS;
248 } /* else more data to send */
250 RDEBUG2("ACK handshake fragment handler");
251 /* Fragmentation handler, send next fragment */
252 return EAPTLS_REQUEST;
255 * For the rest of the conditions, switch over
256 * to the default section below.
259 RDEBUG2("ACK default");
260 radlog_request(L_ERR, 0, request, "Invalid ACK received: %d",
261 tls_session->info.content_type);
267 * Similarly, when the EAP server receives an EAP-Response with
268 * the M bit set, it MUST respond with an EAP-Request with
269 * EAP-Type=EAP-TLS and no data. This serves as a fragment ACK.
271 * In order to prevent errors in the processing of fragments, the
272 * EAP server MUST use increment the Identifier value for each
273 * fragment ACK contained within an EAP-Request, and the peer
274 * MUST include this Identifier value in the subsequent fragment
275 * contained within an EAP- Reponse.
277 * EAP server sends an ACK when it determines there are More
278 * fragments to receive to make the complete
279 * TLS-record/TLS-Message
281 static int eaptls_send_ack(EAP_DS *eap_ds, int peap_flag)
285 reply.code = EAPTLS_ACK;
286 reply.length = TLS_HEADER_LEN + 1/*flags*/;
287 reply.flags = peap_flag;
291 eaptls_compose(eap_ds, &reply);
297 * The S flag is set only within the EAP-TLS start message sent
298 * from the EAP server to the peer.
300 * Similarly, when the EAP server receives an EAP-Response with
301 * the M bit set, it MUST respond with an EAP-Request with
302 * EAP-Type=EAP-TLS and no data. This serves as a fragment
303 * ACK. The EAP peer MUST wait.
305 static eaptls_status_t eaptls_verify(EAP_HANDLER *handler)
307 EAP_DS *eap_ds = handler->eap_ds;
308 EAP_DS *prev_eap_ds = handler->prev_eapds;
309 eaptls_packet_t *eaptls_packet, *eaptls_prev = NULL;
310 REQUEST *request = handler->request;
313 * We don't check ANY of the input parameters. It's all
314 * code which works together, so if something is wrong,
315 * we SHOULD core dump.
317 * e.g. if eap_ds is NULL, of if eap_ds->response is
318 * NULL, of if it's NOT an EAP-Response, or if the packet
319 * is too short. See eap_validation()., in ../../eap.c
321 * Also, eaptype_select() takes care of selecting the
322 * appropriate type, so we don't need to check
323 * eap_ds->response->type.type == PW_EAP_TLS, or anything
326 eaptls_packet = (eaptls_packet_t *)eap_ds->response->type.data;
327 if (prev_eap_ds && prev_eap_ds->response)
328 eaptls_prev = (eaptls_packet_t *)prev_eap_ds->response->type.data;
333 * If there's no TLS data, or there's 1 byte of TLS data,
334 * with the flags set to zero, then it's an ACK.
336 * Find if this is a reply to the previous request sent
338 if ((eaptls_packet == NULL) ||
339 ((eap_ds->response->length == EAP_HEADER_LEN + 2) &&
340 ((eaptls_packet->flags & 0xc0) == 0x00))) {
344 * Un-comment this for TLS inside of TTLS/PEAP
346 RDEBUG2("Received EAP-TLS ACK message");
347 return eaptls_ack_handler(handler);
349 if (prev_eap_ds->request->id == eap_ds->response->id) {
351 * Run the ACK handler directly from here.
353 RDEBUG2("Received TLS ACK");
354 return eaptls_ack_handler(handler);
356 radlog_request(L_ERR, 0, request, "Received Invalid TLS ACK");
357 return EAPTLS_INVALID;
363 * We send TLS_START, but do not receive it.
365 if (TLS_START(eaptls_packet->flags)) {
366 radlog(L_ERR, "rlm_eap_tls: Received unexpected EAP-TLS Start message");
367 return EAPTLS_INVALID;
371 * The L bit (length included) is set to indicate the
372 * presence of the four octet TLS Message Length field,
373 * and MUST be set for the first fragment of a fragmented
374 * TLS message or set of messages.
376 * The M bit (more fragments) is set on all but the last
379 * The S bit (EAP-TLS start) is set in an EAP-TLS Start
380 * message. This differentiates the EAP-TLS Start message
381 * from a fragment acknowledgement.
383 if (TLS_LENGTH_INCLUDED(eaptls_packet->flags)) {
384 DEBUG2(" TLS Length %d",
385 eaptls_packet->data[2] * 256 | eaptls_packet->data[3]);
386 if (TLS_MORE_FRAGMENTS(eaptls_packet->flags)) {
388 * FIRST_FRAGMENT is identified
389 * 1. If there is no previous EAP-response received.
390 * 2. If EAP-response received, then its M bit not set.
391 * (It is because Last fragment will not have M bit set)
394 (prev_eap_ds->response == NULL) ||
395 (eaptls_prev == NULL) ||
396 !TLS_MORE_FRAGMENTS(eaptls_prev->flags)) {
398 DEBUG2("rlm_eap_tls: Received EAP-TLS First Fragment of the message");
399 return EAPTLS_FIRST_FRAGMENT;
402 DEBUG2("rlm_eap_tls: More Fragments with length included");
403 return EAPTLS_MORE_FRAGMENTS_WITH_LENGTH;
406 DEBUG2("rlm_eap_tls: Length Included");
407 return EAPTLS_LENGTH_INCLUDED;
411 if (TLS_MORE_FRAGMENTS(eaptls_packet->flags)) {
412 DEBUG2("rlm_eap_tls: More fragments to follow");
413 return EAPTLS_MORE_FRAGMENTS;
417 * None of the flags are set, but it's still a valid
427 * length = code + id + length + flags + tlsdata
428 * = 1 + 1 + 2 + 1 + X
429 * length = EAP-length - 1(EAP-Type = 1 octet)
430 * flags = EAP-typedata[0] (1 octet)
431 * dlen = EAP-typedata[1-4] (4 octets), if L flag set
432 * = length - 5(code+id+length+flags), otherwise
433 * data = EAP-typedata[5-n], if L flag set
434 * = EAP-typedata[1-n], otherwise
435 * packet = EAP-typedata (complete typedata)
437 * Points to consider during EAP-TLS data extraction
438 * 1. In the received packet, No data will be present incase of ACK-NAK
439 * 2. Incase if more fragments need to be received then ACK after retreiving this fragment.
441 * RFC 2716 Section 4.2. PPP EAP TLS Request Packet
444 * 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
445 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
446 * | Code | Identifier | Length |
447 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
448 * | Type | Flags | TLS Message Length
449 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
450 * | TLS Message Length | TLS Data...
451 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
453 * The Length field is two octets and indicates the length of the EAP
454 * packet including the Code, Identifir, Length, Type, and TLS data
457 static EAPTLS_PACKET *eaptls_extract(EAP_DS *eap_ds, eaptls_status_t status)
459 EAPTLS_PACKET *tlspacket;
460 uint32_t data_len = 0;
462 uint8_t *data = NULL;
464 if (status == EAPTLS_INVALID)
468 * The main EAP code & eaptls_verify() take care of
469 * ensuring that the packet is OK, and that we can
470 * extract the various fields we want.
472 * e.g. a TLS packet with zero data is allowed as an ACK,
473 * but we will never see it here, as we will simply
474 * send another fragment, instead of trying to extract
477 * MUST have TLS type octet, followed by flags, followed
480 assert(eap_ds->response->length > 2);
482 tlspacket = eaptls_alloc();
483 if (tlspacket == NULL) return NULL;
486 * Code & id for EAPTLS & EAP are same
487 * but eaptls_length = eap_length - 1(EAP-Type = 1 octet)
489 * length = code + id + length + type + tlsdata
490 * = 1 + 1 + 2 + 1 + X
492 tlspacket->code = eap_ds->response->code;
493 tlspacket->id = eap_ds->response->id;
494 tlspacket->length = eap_ds->response->length - 1; /* EAP type */
495 tlspacket->flags = eap_ds->response->type.data[0];
498 * A quick sanity check of the flags. If we've been told
499 * that there's a length, and there isn't one, then stop.
501 if (TLS_LENGTH_INCLUDED(tlspacket->flags) &&
502 (tlspacket->length < 5)) { /* flags + TLS message length */
503 radlog(L_ERR, "rlm_eap_tls: Invalid EAP-TLS packet received. (Length bit is set, but no length was found.)");
504 eaptls_free(&tlspacket);
509 * If the final TLS packet is larger than we can handle, die
512 * Likewise, if the EAP packet says N bytes, and the TLS
513 * packet says there's fewer bytes, it's a problem.
515 * FIXME: Try to ensure that the claimed length is
516 * consistent across multiple TLS fragments.
518 if (TLS_LENGTH_INCLUDED(tlspacket->flags)) {
519 memcpy(&data_len, &eap_ds->response->type.data[1], 4);
520 data_len = ntohl(data_len);
521 if (data_len > MAX_RECORD_SIZE) {
522 radlog(L_ERR, "rlm_eap_tls: The EAP-TLS packet will contain more data than we can process.");
523 eaptls_free(&tlspacket);
528 DEBUG2(" TLS: %d %d\n", data_len, tlspacket->length);
530 if (data_len < tlspacket->length) {
531 radlog(L_ERR, "rlm_eap_tls: EAP-TLS packet claims to be smaller than the encapsulating EAP packet.");
532 eaptls_free(&tlspacket);
540 * The TLS Message Length field is four octets, and
541 * provides the total length of the TLS message or set of
542 * messages that is being fragmented; this simplifies
545 * Dynamic allocation of buffers as & when we know the
546 * length should solve the problem.
548 case EAPTLS_FIRST_FRAGMENT:
549 case EAPTLS_LENGTH_INCLUDED:
550 case EAPTLS_MORE_FRAGMENTS_WITH_LENGTH:
551 if (tlspacket->length < 5) { /* flags + TLS message length */
552 radlog(L_ERR, "rlm_eap_tls: Invalid EAP-TLS packet received. (Expected length, got none.)");
553 eaptls_free(&tlspacket);
558 * Extract all the TLS fragments from the
559 * previous eap_ds Start appending this
560 * fragment to the above ds
562 memcpy(&data_len, &eap_ds->response->type.data[1], sizeof(uint32_t));
563 data_len = ntohl(data_len);
564 data = (eap_ds->response->type.data + 5/*flags+TLS-Length*/);
565 len = eap_ds->response->type.length - 5/*flags+TLS-Length*/;
568 * Hmm... this should be an error, too.
570 if (data_len > len) {
576 * Data length is implicit, from the EAP header.
578 case EAPTLS_MORE_FRAGMENTS:
580 data_len = eap_ds->response->type.length - 1/*flags*/;
581 data = eap_ds->response->type.data + 1/*flags*/;
585 radlog(L_ERR, "rlm_eap_tls: Invalid EAP-TLS packet received");
586 eaptls_free(&tlspacket);
590 tlspacket->dlen = data_len;
592 tlspacket->data = (unsigned char *)malloc(data_len);
593 if (tlspacket->data == NULL) {
594 radlog(L_ERR, "rlm_eap_tls: out of memory");
595 eaptls_free(&tlspacket);
598 memcpy(tlspacket->data, data, data_len);
607 * To process the TLS,
609 * 1. EAP-TLS should get the compelete TLS data from the peer.
610 * 2. Store that data in a data structure with any other required info
611 * 3. Handle that data structure to the TLS module.
612 * 4. TLS module will perform its operations on the data and
613 * handle back to EAP-TLS
616 * 1. EAP-TLS if necessary will fragment it and send it to the
619 * During EAP-TLS initialization, TLS Context object will be
620 * initialized and stored. For every new authentication
621 * requests, TLS will open a new session object and that session
622 * object should be maintained even after the session is
623 * completed for session resumption. (Probably later as a feature
624 * as we donot know who maintains these session objects ie,
625 * SSL_CTX (internally) or TLS module(explicitly). If TLS module,
626 * then how to let SSL API know about these sessions.)
628 static void eaptls_operation(EAPTLS_PACKET *eaptls_packet UNUSED,
629 eaptls_status_t status, EAP_HANDLER *handler)
631 tls_session_t *tls_session;
633 tls_session = (tls_session_t *)handler->opaque;
635 if ((status == EAPTLS_MORE_FRAGMENTS) ||
636 (status == EAPTLS_MORE_FRAGMENTS_WITH_LENGTH) ||
637 (status == EAPTLS_FIRST_FRAGMENT)) {
641 eaptls_send_ack(handler->eap_ds, tls_session->peap_flag);
646 * We have the complete TLS-data or TLS-message.
648 * Clean the dirty message.
650 * Authenticate the user and send
654 * is required then send another request.
656 rcode = tls_handshake_recv(tls_session);
659 * FIXME: return success/fail.
661 * TLS proper can decide what to do, then.
663 eaptls_request(handler->eap_ds, tls_session);
666 * TLS returns 0 or 1.
667 * anything else is application-specific.
669 * In our code, this means "session
670 * resumption was OK".
672 } else if (rcode == 0xea) {
674 * FIXME: hard-code key based on EAP type.
675 * Also, this code is duplicated all over
678 eaptls_success(handler->eap_ds, 0);
679 eaptls_gen_mppe_keys(&handler->request->reply->vps,
681 "client EAP encryption");
684 eaptls_fail(handler->eap_ds, tls_session->peap_flag);
693 * In the actual authentication first verify the packet and then create the data structure
696 * To process the TLS,
698 * 1. EAP-TLS should get the compelete TLS data from the peer.
699 * 2. Store that data in a data structure with any other required info
700 * 3. Hand this data structure to the TLS module.
701 * 4. TLS module will perform its operations on the data and hands back to EAP-TLS
703 * 1. EAP-TLS if necessary will fragment it and send it to the destination.
705 * During EAP-TLS initialization, TLS Context object will be
706 * initialized and stored. For every new authentication
707 * requests, TLS will open a new session object and that
708 * session object SHOULD be maintained even after the session
709 * is completed, for session resumption. (Probably later as a
710 * feature, as we do not know who maintains these session
711 * objects ie, SSL_CTX (internally) or TLS module (explicitly). If
712 * TLS module, then how to let SSL API know about these
717 * Process an EAP request
719 eaptls_status_t eaptls_process(EAP_HANDLER *handler)
721 tls_session_t *tls_session = (tls_session_t *) handler->opaque;
722 EAPTLS_PACKET *tlspacket;
723 eaptls_status_t status;
724 REQUEST *request = handler->request;
726 RDEBUG2("processing EAP-TLS");
728 /* This case is when SSL generates Alert then we
729 * send that alert to the client and then send the EAP-Failure
731 status = eaptls_verify(handler);
732 RDEBUG2("eaptls_verify returned %d\n", status);
740 * Success means that we're done the initial
741 * handshake. For TTLS, this means send stuff
742 * back to the client, and the client sends us
743 * more tunneled data.
750 * Normal TLS request, continue with the "get rest
751 * of fragments" phase.
754 eaptls_request(handler->eap_ds, tls_session);
755 return EAPTLS_HANDLED;
759 * The handshake is done, and we're in the "tunnel
763 RDEBUG2("Done initial handshake");
766 * Get the rest of the fragments.
768 case EAPTLS_FIRST_FRAGMENT:
769 case EAPTLS_MORE_FRAGMENTS:
770 case EAPTLS_LENGTH_INCLUDED:
771 case EAPTLS_MORE_FRAGMENTS_WITH_LENGTH:
776 * Extract the TLS packet from the buffer.
778 if ((tlspacket = eaptls_extract(handler->eap_ds, status)) == NULL)
782 * Get the session struct from the handler
784 * update the dirty_in buffer
786 * NOTE: This buffer will contain partial data when M bit is set.
788 * CAUTION while reinitializing this buffer, it should be
789 * reinitialized only when this M bit is NOT set.
791 if (tlspacket->dlen !=
792 (tls_session->record_plus)(&tls_session->dirty_in, tlspacket->data, tlspacket->dlen)) {
793 eaptls_free(&tlspacket);
794 radlog(L_ERR, "rlm_eap_tls: Exceeded maximum record size");
799 * SSL initalization is done. Return.
801 * The TLS data will be in the tls_session structure.
803 if (SSL_is_init_finished(tls_session->ssl)) {
804 eaptls_free(&tlspacket);
809 * Continue the handshake.
811 eaptls_operation(tlspacket, status, handler);
813 eaptls_free(&tlspacket);
814 return EAPTLS_HANDLED;
819 * compose the TLS reply packet in the EAP reply typedata
821 int eaptls_compose(EAP_DS *eap_ds, EAPTLS_PACKET *reply)
826 * Don't set eap_ds->request->type.type, as the main EAP
827 * handler will do that for us. This allows the TLS
828 * module to be called from TTLS & PEAP.
832 * When the EAP server receives an EAP-Response with the
833 * M bit set, it MUST respond with an EAP-Request with
834 * EAP-Type=EAP-TLS and no data. This serves as a
835 * fragment ACK. The EAP peer MUST wait until it receives
836 * the EAP-Request before sending another fragment.
838 * In order to prevent errors in the processing of
839 * fragments, the EAP server MUST use increment the
840 * Identifier value for each fragment ACK contained
841 * within an EAP-Request, and the peer MUST include this
842 * Identifier value in the subsequent fragment contained
843 * within an EAP- Reponse.
845 eap_ds->request->type.data = malloc(reply->length - TLS_HEADER_LEN + 1);
846 if (eap_ds->request->type.data == NULL) {
847 radlog(L_ERR, "rlm_eap_tls: out of memory");
851 /* EAPTLS Header length is excluded while computing EAP typelen */
852 eap_ds->request->type.length = reply->length - TLS_HEADER_LEN;
854 ptr = eap_ds->request->type.data;
855 *ptr++ = (uint8_t)(reply->flags & 0xFF);
857 if (reply->dlen) memcpy(ptr, reply->data, reply->dlen);
859 switch (reply->code) {
863 eap_ds->request->code = PW_EAP_REQUEST;
866 eap_ds->request->code = PW_EAP_SUCCESS;
869 eap_ds->request->code = PW_EAP_FAILURE;
872 /* Should never enter here */
873 eap_ds->request->code = PW_EAP_FAILURE;