2 * EAP-FAST server (RFC 4851)
3 * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
21 #include "eap_tls_common.h"
23 #include "eap_common/eap_tlv_common.h"
24 #include "eap_common/eap_fast_common.h"
27 static void eap_fast_reset(struct eap_sm *sm, void *priv);
30 /* Private PAC-Opaque TLV types */
31 #define PAC_OPAQUE_TYPE_PAD 0
32 #define PAC_OPAQUE_TYPE_KEY 1
33 #define PAC_OPAQUE_TYPE_LIFETIME 2
34 #define PAC_OPAQUE_TYPE_IDENTITY 3
36 struct eap_fast_data {
37 struct eap_ssl_data ssl;
39 START, PHASE1, PHASE2_START, PHASE2_ID, PHASE2_METHOD,
40 CRYPTO_BINDING, REQUEST_PAC, SUCCESS, FAILURE
44 const struct eap_method *phase2_method;
49 u8 crypto_binding_nonce[32];
52 struct eap_fast_key_block_provisioning *key_block_p;
54 u8 simck[EAP_FAST_SIMCK_LEN];
55 u8 cmk[EAP_FAST_CMK_LEN];
58 u8 pac_opaque_encr[16];
63 int anon_provisioning;
64 int send_new_pac; /* server triggered re-keying of Tunnel PAC */
65 struct wpabuf *pending_phase2_resp;
66 u8 *identity; /* from PAC-Opaque */
72 int pac_key_refresh_time;
76 static int eap_fast_process_phase2_start(struct eap_sm *sm,
77 struct eap_fast_data *data);
80 static const char * eap_fast_state_txt(int state)
88 return "PHASE2_START";
92 return "PHASE2_METHOD";
94 return "CRYPTO_BINDING";
107 static void eap_fast_state(struct eap_fast_data *data, int state)
109 wpa_printf(MSG_DEBUG, "EAP-FAST: %s -> %s",
110 eap_fast_state_txt(data->state),
111 eap_fast_state_txt(state));
116 static EapType eap_fast_req_failure(struct eap_sm *sm,
117 struct eap_fast_data *data)
119 /* TODO: send Result TLV(FAILURE) */
120 eap_fast_state(data, FAILURE);
121 return EAP_TYPE_NONE;
125 static int eap_fast_session_ticket_cb(void *ctx, const u8 *ticket, size_t len,
126 const u8 *client_random,
127 const u8 *server_random,
130 struct eap_fast_data *data = ctx;
131 const u8 *pac_opaque;
132 size_t pac_opaque_len;
133 u8 *buf, *pos, *end, *pac_key = NULL;
134 os_time_t lifetime = 0;
137 size_t identity_len = 0;
139 wpa_printf(MSG_DEBUG, "EAP-FAST: SessionTicket callback");
140 wpa_hexdump(MSG_DEBUG, "EAP-FAST: SessionTicket (PAC-Opaque)",
143 if (len < 4 || WPA_GET_BE16(ticket) != PAC_TYPE_PAC_OPAQUE) {
144 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignore invalid "
149 pac_opaque_len = WPA_GET_BE16(ticket + 2);
150 pac_opaque = ticket + 4;
151 if (pac_opaque_len < 8 || pac_opaque_len % 8 ||
152 pac_opaque_len > len - 4) {
153 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignore invalid PAC-Opaque "
154 "(len=%lu left=%lu)",
155 (unsigned long) pac_opaque_len,
156 (unsigned long) len);
159 wpa_hexdump(MSG_DEBUG, "EAP-FAST: Received PAC-Opaque",
160 pac_opaque, pac_opaque_len);
162 buf = os_malloc(pac_opaque_len - 8);
164 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to allocate memory "
165 "for decrypting PAC-Opaque");
169 if (aes_unwrap(data->pac_opaque_encr, (pac_opaque_len - 8) / 8,
170 pac_opaque, buf) < 0) {
171 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to decrypt "
175 * This may have been caused by server changing the PAC-Opaque
176 * encryption key, so just ignore this PAC-Opaque instead of
177 * failing the authentication completely. Provisioning can now
178 * be used to provision a new PAC.
183 end = buf + pac_opaque_len - 8;
184 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Decrypted PAC-Opaque",
188 while (pos + 1 < end) {
189 if (pos + 2 + pos[1] > end)
193 case PAC_OPAQUE_TYPE_PAD:
196 case PAC_OPAQUE_TYPE_KEY:
197 if (pos[1] != EAP_FAST_PAC_KEY_LEN) {
198 wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid "
199 "PAC-Key length %d", pos[1]);
204 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: PAC-Key from "
205 "decrypted PAC-Opaque",
206 pac_key, EAP_FAST_PAC_KEY_LEN);
208 case PAC_OPAQUE_TYPE_LIFETIME:
210 wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid "
211 "PAC-Key lifetime length %d",
216 lifetime = WPA_GET_BE32(pos + 2);
218 case PAC_OPAQUE_TYPE_IDENTITY:
220 identity_len = pos[1];
227 if (pac_key == NULL) {
228 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC-Key included in "
235 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: Identity from "
236 "PAC-Opaque", identity, identity_len);
237 os_free(data->identity);
238 data->identity = os_malloc(identity_len);
239 if (data->identity) {
240 os_memcpy(data->identity, identity, identity_len);
241 data->identity_len = identity_len;
245 if (os_get_time(&now) < 0 || lifetime <= 0 || now.sec > lifetime) {
246 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Key not valid anymore "
247 "(lifetime=%ld now=%ld)", lifetime, now.sec);
248 data->send_new_pac = 2;
250 * Allow PAC to be used to allow a PAC update with some level
251 * of server authentication (i.e., do not fall back to full TLS
252 * handshake since we cannot be sure that the peer would be
253 * able to validate server certificate now). However, reject
254 * the authentication since the PAC was not valid anymore. Peer
255 * can connect again with the newly provisioned PAC after this.
257 } else if (lifetime - now.sec < data->pac_key_refresh_time) {
258 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Key soft timeout; send "
259 "an update if authentication succeeds");
260 data->send_new_pac = 1;
263 eap_fast_derive_master_secret(pac_key, server_random, client_random,
272 static void eap_fast_derive_key_auth(struct eap_sm *sm,
273 struct eap_fast_data *data)
277 /* RFC 4851, Section 5.1:
278 * Extra key material after TLS key_block: session_key_seed[40]
281 sks = eap_fast_derive_key(sm->ssl_ctx, data->ssl.conn, "key expansion",
284 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive "
290 * RFC 4851, Section 5.2:
291 * S-IMCK[0] = session_key_seed
293 wpa_hexdump_key(MSG_DEBUG,
294 "EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
295 sks, EAP_FAST_SKS_LEN);
297 os_memcpy(data->simck, sks, EAP_FAST_SIMCK_LEN);
302 static void eap_fast_derive_key_provisioning(struct eap_sm *sm,
303 struct eap_fast_data *data)
305 os_free(data->key_block_p);
306 data->key_block_p = (struct eap_fast_key_block_provisioning *)
307 eap_fast_derive_key(sm->ssl_ctx, data->ssl.conn,
309 sizeof(*data->key_block_p));
310 if (data->key_block_p == NULL) {
311 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive key block");
315 * RFC 4851, Section 5.2:
316 * S-IMCK[0] = session_key_seed
318 wpa_hexdump_key(MSG_DEBUG,
319 "EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
320 data->key_block_p->session_key_seed,
321 sizeof(data->key_block_p->session_key_seed));
323 os_memcpy(data->simck, data->key_block_p->session_key_seed,
325 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: server_challenge",
326 data->key_block_p->server_challenge,
327 sizeof(data->key_block_p->server_challenge));
328 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: client_challenge",
329 data->key_block_p->client_challenge,
330 sizeof(data->key_block_p->client_challenge));
334 static int eap_fast_get_phase2_key(struct eap_sm *sm,
335 struct eap_fast_data *data,
336 u8 *isk, size_t isk_len)
341 os_memset(isk, 0, isk_len);
343 if (data->phase2_method == NULL || data->phase2_priv == NULL) {
344 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not "
349 if (data->phase2_method->getKey == NULL)
352 if ((key = data->phase2_method->getKey(sm, data->phase2_priv,
353 &key_len)) == NULL) {
354 wpa_printf(MSG_DEBUG, "EAP-FAST: Could not get key material "
359 if (key_len > isk_len)
362 data->phase2_method->vendor == EAP_VENDOR_IETF &&
363 data->phase2_method->method == EAP_TYPE_MSCHAPV2) {
365 * EAP-FAST uses reverse order for MS-MPPE keys when deriving
366 * MSK from EAP-MSCHAPv2. Swap the keys here to get the correct
367 * ISK for EAP-FAST cryptobinding.
369 os_memcpy(isk, key + 16, 16);
370 os_memcpy(isk + 16, key, 16);
372 os_memcpy(isk, key, key_len);
379 static int eap_fast_update_icmk(struct eap_sm *sm, struct eap_fast_data *data)
381 u8 isk[32], imck[60];
383 wpa_printf(MSG_DEBUG, "EAP-FAST: Deriving ICMK[%d] (S-IMCK and CMK)",
384 data->simck_idx + 1);
387 * RFC 4851, Section 5.2:
388 * IMCK[j] = T-PRF(S-IMCK[j-1], "Inner Methods Compound Keys",
390 * S-IMCK[j] = first 40 octets of IMCK[j]
391 * CMK[j] = last 20 octets of IMCK[j]
394 if (eap_fast_get_phase2_key(sm, data, isk, sizeof(isk)) < 0)
396 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: ISK[j]", isk, sizeof(isk));
397 sha1_t_prf(data->simck, EAP_FAST_SIMCK_LEN,
398 "Inner Methods Compound Keys",
399 isk, sizeof(isk), imck, sizeof(imck));
401 os_memcpy(data->simck, imck, EAP_FAST_SIMCK_LEN);
402 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: S-IMCK[j]",
403 data->simck, EAP_FAST_SIMCK_LEN);
404 os_memcpy(data->cmk, imck + EAP_FAST_SIMCK_LEN, EAP_FAST_CMK_LEN);
405 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: CMK[j]",
406 data->cmk, EAP_FAST_CMK_LEN);
412 static void * eap_fast_init(struct eap_sm *sm)
414 struct eap_fast_data *data;
416 TLS_CIPHER_ANON_DH_AES128_SHA,
417 TLS_CIPHER_AES128_SHA,
418 TLS_CIPHER_RSA_DHE_AES128_SHA,
423 data = os_zalloc(sizeof(*data));
426 data->fast_version = EAP_FAST_VERSION;
427 data->force_version = -1;
428 if (sm->user && sm->user->force_version >= 0) {
429 data->force_version = sm->user->force_version;
430 wpa_printf(MSG_DEBUG, "EAP-FAST: forcing version %d",
431 data->force_version);
432 data->fast_version = data->force_version;
436 if (eap_server_tls_ssl_init(sm, &data->ssl, 0)) {
437 wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize SSL.");
438 eap_fast_reset(sm, data);
442 if (tls_connection_set_cipher_list(sm->ssl_ctx, data->ssl.conn,
444 wpa_printf(MSG_INFO, "EAP-FAST: Failed to set TLS cipher "
446 eap_fast_reset(sm, data);
450 if (tls_connection_set_session_ticket_cb(sm->ssl_ctx, data->ssl.conn,
451 eap_fast_session_ticket_cb,
453 wpa_printf(MSG_INFO, "EAP-FAST: Failed to set SessionTicket "
455 eap_fast_reset(sm, data);
459 if (sm->pac_opaque_encr_key == NULL) {
460 wpa_printf(MSG_INFO, "EAP-FAST: No PAC-Opaque encryption key "
462 eap_fast_reset(sm, data);
465 os_memcpy(data->pac_opaque_encr, sm->pac_opaque_encr_key,
466 sizeof(data->pac_opaque_encr));
468 if (sm->eap_fast_a_id == NULL) {
469 wpa_printf(MSG_INFO, "EAP-FAST: No A-ID configured");
470 eap_fast_reset(sm, data);
473 data->srv_id = os_malloc(sm->eap_fast_a_id_len);
474 if (data->srv_id == NULL) {
475 eap_fast_reset(sm, data);
478 os_memcpy(data->srv_id, sm->eap_fast_a_id, sm->eap_fast_a_id_len);
479 data->srv_id_len = sm->eap_fast_a_id_len;
481 if (sm->eap_fast_a_id_info == NULL) {
482 wpa_printf(MSG_INFO, "EAP-FAST: No A-ID-Info configured");
483 eap_fast_reset(sm, data);
486 data->srv_id_info = os_strdup(sm->eap_fast_a_id_info);
487 if (data->srv_id_info == NULL) {
488 eap_fast_reset(sm, data);
492 /* PAC-Key lifetime in seconds (hard limit) */
493 data->pac_key_lifetime = sm->pac_key_lifetime;
496 * PAC-Key refresh time in seconds (soft limit on remaining hard
497 * limit). The server will generate a new PAC-Key when this number of
498 * seconds (or fewer) of the lifetime remains.
500 data->pac_key_refresh_time = sm->pac_key_refresh_time;
506 static void eap_fast_reset(struct eap_sm *sm, void *priv)
508 struct eap_fast_data *data = priv;
511 if (data->phase2_priv && data->phase2_method)
512 data->phase2_method->reset(sm, data->phase2_priv);
513 eap_server_tls_ssl_deinit(sm, &data->ssl);
514 os_free(data->srv_id);
515 os_free(data->srv_id_info);
516 os_free(data->key_block_p);
517 wpabuf_free(data->pending_phase2_resp);
518 os_free(data->identity);
523 static struct wpabuf * eap_fast_build_start(struct eap_sm *sm,
524 struct eap_fast_data *data, u8 id)
528 req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_FAST,
529 1 + sizeof(struct pac_tlv_hdr) + data->srv_id_len,
530 EAP_CODE_REQUEST, id);
532 wpa_printf(MSG_ERROR, "EAP-FAST: Failed to allocate memory for"
534 eap_fast_state(data, FAILURE);
538 wpabuf_put_u8(req, EAP_TLS_FLAGS_START | data->fast_version);
540 /* RFC 4851, 4.1.1. Authority ID Data */
541 eap_fast_put_tlv(req, PAC_TYPE_A_ID, data->srv_id, data->srv_id_len);
543 eap_fast_state(data, PHASE1);
549 static int eap_fast_phase1_done(struct eap_sm *sm, struct eap_fast_data *data)
553 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase1 done, starting Phase2");
555 if (tls_get_cipher(sm->ssl_ctx, data->ssl.conn, cipher, sizeof(cipher))
557 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to get cipher "
559 eap_fast_state(data, FAILURE);
562 data->anon_provisioning = os_strstr(cipher, "ADH") != NULL;
564 if (data->anon_provisioning) {
565 wpa_printf(MSG_DEBUG, "EAP-FAST: Anonymous provisioning");
566 eap_fast_derive_key_provisioning(sm, data);
568 eap_fast_derive_key_auth(sm, data);
570 eap_fast_state(data, PHASE2_START);
576 static struct wpabuf * eap_fast_build_phase2_req(struct eap_sm *sm,
577 struct eap_fast_data *data,
582 if (data->phase2_priv == NULL) {
583 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not "
587 req = data->phase2_method->buildReq(sm, data->phase2_priv, id);
591 wpa_hexdump_buf_key(MSG_MSGDUMP, "EAP-FAST: Phase 2 EAP-Request", req);
592 return eap_fast_tlv_eap_payload(req);
596 static struct wpabuf * eap_fast_build_crypto_binding(
597 struct eap_sm *sm, struct eap_fast_data *data)
600 struct eap_tlv_result_tlv *result;
601 struct eap_tlv_crypto_binding_tlv *binding;
603 buf = wpabuf_alloc(2 * sizeof(*result) + sizeof(*binding));
607 if (data->send_new_pac || data->anon_provisioning ||
609 data->final_result = 0;
611 data->final_result = 1;
613 if (!data->final_result || data->eap_seq > 1) {
614 /* Intermediate-Result */
615 wpa_printf(MSG_DEBUG, "EAP-FAST: Add Intermediate-Result TLV "
617 result = wpabuf_put(buf, sizeof(*result));
618 result->tlv_type = host_to_be16(
619 EAP_TLV_TYPE_MANDATORY |
620 EAP_TLV_INTERMEDIATE_RESULT_TLV);
621 result->length = host_to_be16(2);
622 result->status = host_to_be16(EAP_TLV_RESULT_SUCCESS);
625 if (data->final_result) {
627 wpa_printf(MSG_DEBUG, "EAP-FAST: Add Result TLV "
629 result = wpabuf_put(buf, sizeof(*result));
630 result->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
632 result->length = host_to_be16(2);
633 result->status = host_to_be16(EAP_TLV_RESULT_SUCCESS);
636 /* Crypto-Binding TLV */
637 binding = wpabuf_put(buf, sizeof(*binding));
638 binding->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
639 EAP_TLV_CRYPTO_BINDING_TLV);
640 binding->length = host_to_be16(sizeof(*binding) -
641 sizeof(struct eap_tlv_hdr));
642 binding->version = EAP_FAST_VERSION;
643 binding->received_version = data->peer_version;
644 binding->subtype = EAP_TLV_CRYPTO_BINDING_SUBTYPE_REQUEST;
645 if (os_get_random(binding->nonce, sizeof(binding->nonce)) < 0) {
651 * RFC 4851, Section 4.2.8:
652 * The nonce in a request MUST have its least significant bit set to 0.
654 binding->nonce[sizeof(binding->nonce) - 1] &= ~0x01;
656 os_memcpy(data->crypto_binding_nonce, binding->nonce,
657 sizeof(binding->nonce));
660 * RFC 4851, Section 5.3:
662 * Compound-MAC = HMAC-SHA1( CMK, Crypto-Binding TLV )
665 hmac_sha1(data->cmk, EAP_FAST_CMK_LEN,
666 (u8 *) binding, sizeof(*binding),
667 binding->compound_mac);
669 wpa_printf(MSG_DEBUG, "EAP-FAST: Add Crypto-Binding TLV: Version %d "
670 "Received Version %d SubType %d",
671 binding->version, binding->received_version,
673 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
674 binding->nonce, sizeof(binding->nonce));
675 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
676 binding->compound_mac, sizeof(binding->compound_mac));
682 static struct wpabuf * eap_fast_build_pac(struct eap_sm *sm,
683 struct eap_fast_data *data)
685 u8 pac_key[EAP_FAST_PAC_KEY_LEN];
686 u8 *pac_buf, *pac_opaque;
689 size_t buf_len, srv_id_info_len, pac_len;
690 struct eap_tlv_hdr *pac_tlv;
691 struct pac_tlv_hdr *pac_info;
692 struct eap_tlv_result_tlv *result;
695 if (os_get_random(pac_key, EAP_FAST_PAC_KEY_LEN) < 0 ||
696 os_get_time(&now) < 0)
698 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Generated PAC-Key",
699 pac_key, EAP_FAST_PAC_KEY_LEN);
701 pac_len = (2 + EAP_FAST_PAC_KEY_LEN) + (2 + 4) +
702 (2 + sm->identity_len) + 8;
703 pac_buf = os_malloc(pac_len);
707 srv_id_info_len = os_strlen(data->srv_id_info);
710 *pos++ = PAC_OPAQUE_TYPE_KEY;
711 *pos++ = EAP_FAST_PAC_KEY_LEN;
712 os_memcpy(pos, pac_key, EAP_FAST_PAC_KEY_LEN);
713 pos += EAP_FAST_PAC_KEY_LEN;
715 *pos++ = PAC_OPAQUE_TYPE_LIFETIME;
717 WPA_PUT_BE32(pos, now.sec + data->pac_key_lifetime);
721 *pos++ = PAC_OPAQUE_TYPE_IDENTITY;
722 *pos++ = sm->identity_len;
723 os_memcpy(pos, sm->identity, sm->identity_len);
724 pos += sm->identity_len;
727 pac_len = pos - pac_buf;
728 while (pac_len % 8) {
729 *pos++ = PAC_OPAQUE_TYPE_PAD;
733 pac_opaque = os_malloc(pac_len + 8);
734 if (pac_opaque == NULL) {
738 if (aes_wrap(data->pac_opaque_encr, pac_len / 8, pac_buf,
747 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Opaque",
748 pac_opaque, pac_len);
750 buf_len = sizeof(*pac_tlv) +
751 sizeof(struct pac_tlv_hdr) + EAP_FAST_PAC_KEY_LEN +
752 sizeof(struct pac_tlv_hdr) + pac_len +
753 data->srv_id_len + srv_id_info_len + 100 + sizeof(*result);
754 buf = wpabuf_alloc(buf_len);
761 wpa_printf(MSG_DEBUG, "EAP-FAST: Add Result TLV (status=SUCCESS)");
762 result = wpabuf_put(buf, sizeof(*result));
763 WPA_PUT_BE16((u8 *) &result->tlv_type,
764 EAP_TLV_TYPE_MANDATORY | EAP_TLV_RESULT_TLV);
765 WPA_PUT_BE16((u8 *) &result->length, 2);
766 WPA_PUT_BE16((u8 *) &result->status, EAP_TLV_RESULT_SUCCESS);
769 wpa_printf(MSG_DEBUG, "EAP-FAST: Add PAC TLV");
770 pac_tlv = wpabuf_put(buf, sizeof(*pac_tlv));
771 pac_tlv->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
775 eap_fast_put_tlv(buf, PAC_TYPE_PAC_KEY, pac_key, EAP_FAST_PAC_KEY_LEN);
778 eap_fast_put_tlv(buf, PAC_TYPE_PAC_OPAQUE, pac_opaque, pac_len);
782 pac_info = wpabuf_put(buf, sizeof(*pac_info));
783 pac_info->type = host_to_be16(PAC_TYPE_PAC_INFO);
785 /* PAC-Lifetime (inside PAC-Info) */
786 eap_fast_put_tlv_hdr(buf, PAC_TYPE_CRED_LIFETIME, 4);
787 wpabuf_put_be32(buf, now.sec + data->pac_key_lifetime);
789 /* A-ID (inside PAC-Info) */
790 eap_fast_put_tlv(buf, PAC_TYPE_A_ID, data->srv_id, data->srv_id_len);
792 /* Note: headers may be misaligned after A-ID */
794 /* A-ID-Info (inside PAC-Info) */
795 eap_fast_put_tlv(buf, PAC_TYPE_A_ID_INFO, data->srv_id_info,
798 /* PAC-Type (inside PAC-Info) */
799 eap_fast_put_tlv_hdr(buf, PAC_TYPE_PAC_TYPE, 2);
800 wpabuf_put_be16(buf, PAC_TYPE_TUNNEL_PAC);
802 /* Update PAC-Info and PAC TLV Length fields */
803 pos = wpabuf_put(buf, 0);
804 pac_info->len = host_to_be16(pos - (u8 *) (pac_info + 1));
805 pac_tlv->length = host_to_be16(pos - (u8 *) (pac_tlv + 1));
811 static int eap_fast_encrypt_phase2(struct eap_sm *sm,
812 struct eap_fast_data *data,
813 struct wpabuf *plain, int piggyback)
817 wpa_hexdump_buf_key(MSG_DEBUG, "EAP-FAST: Encrypting Phase 2 TLVs",
819 encr = eap_server_tls_encrypt(sm, &data->ssl, wpabuf_mhead(plain),
823 if (data->ssl.out_buf && piggyback) {
824 wpa_printf(MSG_DEBUG, "EAP-FAST: Piggyback Phase 2 data "
825 "(len=%d) with last Phase 1 Message (len=%d "
827 (int) wpabuf_len(encr),
828 (int) wpabuf_len(data->ssl.out_buf),
829 (int) data->ssl.out_used);
830 if (wpabuf_resize(&data->ssl.out_buf, wpabuf_len(encr)) < 0) {
831 wpa_printf(MSG_WARNING, "EAP-FAST: Failed to resize "
836 wpabuf_put_buf(data->ssl.out_buf, encr);
839 wpabuf_free(data->ssl.out_buf);
840 data->ssl.out_used = 0;
841 data->ssl.out_buf = encr;
848 static struct wpabuf * eap_fast_buildReq(struct eap_sm *sm, void *priv, u8 id)
850 struct eap_fast_data *data = priv;
851 struct wpabuf *req = NULL;
854 if (data->ssl.state == FRAG_ACK) {
855 return eap_server_tls_build_ack(id, EAP_TYPE_FAST,
859 if (data->ssl.state == WAIT_FRAG_ACK) {
860 return eap_server_tls_build_msg(&data->ssl, EAP_TYPE_FAST,
861 data->fast_version, id);
864 switch (data->state) {
866 return eap_fast_build_start(sm, data, id);
868 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn)) {
869 if (eap_fast_phase1_done(sm, data) < 0)
871 if (data->state == PHASE2_START) {
873 * Try to generate Phase 2 data to piggyback
874 * with the end of Phase 1 to avoid extra
877 wpa_printf(MSG_DEBUG, "EAP-FAST: Try to start "
879 if (eap_fast_process_phase2_start(sm, data))
881 req = eap_fast_build_phase2_req(sm, data, id);
888 req = eap_fast_build_phase2_req(sm, data, id);
891 req = eap_fast_build_crypto_binding(sm, data);
892 if (data->phase2_method) {
894 * Include the start of the next EAP method in the
895 * sequence in the same message with Crypto-Binding to
899 eap = eap_fast_build_phase2_req(sm, data, id);
900 req = wpabuf_concat(req, eap);
901 eap_fast_state(data, PHASE2_METHOD);
905 req = eap_fast_build_pac(sm, data);
908 wpa_printf(MSG_DEBUG, "EAP-FAST: %s - unexpected state %d",
909 __func__, data->state);
914 eap_fast_encrypt_phase2(sm, data, req, piggyback) < 0)
917 return eap_server_tls_build_msg(&data->ssl, EAP_TYPE_FAST,
918 data->fast_version, id);
922 static Boolean eap_fast_check(struct eap_sm *sm, void *priv,
923 struct wpabuf *respData)
928 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_FAST, respData, &len);
929 if (pos == NULL || len < 1) {
930 wpa_printf(MSG_INFO, "EAP-FAST: Invalid frame");
938 static int eap_fast_phase2_init(struct eap_sm *sm, struct eap_fast_data *data,
941 if (data->phase2_priv && data->phase2_method) {
942 data->phase2_method->reset(sm, data->phase2_priv);
943 data->phase2_method = NULL;
944 data->phase2_priv = NULL;
946 data->phase2_method = eap_server_get_eap_method(EAP_VENDOR_IETF,
948 if (!data->phase2_method)
951 if (data->key_block_p) {
952 sm->auth_challenge = data->key_block_p->server_challenge;
953 sm->peer_challenge = data->key_block_p->client_challenge;
956 data->phase2_priv = data->phase2_method->init(sm);
958 sm->auth_challenge = NULL;
959 sm->peer_challenge = NULL;
961 return data->phase2_priv == NULL ? -1 : 0;
965 static void eap_fast_process_phase2_response(struct eap_sm *sm,
966 struct eap_fast_data *data,
967 u8 *in_data, size_t in_len)
969 u8 next_type = EAP_TYPE_NONE;
974 const struct eap_method *m = data->phase2_method;
975 void *priv = data->phase2_priv;
978 wpa_printf(MSG_DEBUG, "EAP-FAST: %s - Phase2 not "
979 "initialized?!", __func__);
983 hdr = (struct eap_hdr *) in_data;
984 pos = (u8 *) (hdr + 1);
986 if (in_len > sizeof(*hdr) && *pos == EAP_TYPE_NAK) {
987 left = in_len - sizeof(*hdr);
988 wpa_hexdump(MSG_DEBUG, "EAP-FAST: Phase2 type Nak'ed; "
989 "allowed types", pos + 1, left - 1);
991 if (m && m->vendor == EAP_VENDOR_IETF &&
992 m->method == EAP_TYPE_TNC) {
993 wpa_printf(MSG_DEBUG, "EAP-FAST: Peer Nak'ed required "
995 next_type = eap_fast_req_failure(sm, data);
996 eap_fast_phase2_init(sm, data, next_type);
1000 eap_sm_process_nak(sm, pos + 1, left - 1);
1001 if (sm->user && sm->user_eap_method_index < EAP_MAX_METHODS &&
1002 sm->user->methods[sm->user_eap_method_index].method !=
1004 next_type = sm->user->methods[
1005 sm->user_eap_method_index++].method;
1006 wpa_printf(MSG_DEBUG, "EAP-FAST: try EAP type %d",
1009 next_type = eap_fast_req_failure(sm, data);
1011 eap_fast_phase2_init(sm, data, next_type);
1015 wpabuf_set(&buf, in_data, in_len);
1017 if (m->check(sm, priv, &buf)) {
1018 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 check() asked to "
1019 "ignore the packet");
1020 next_type = eap_fast_req_failure(sm, data);
1024 m->process(sm, priv, &buf);
1026 if (!m->isDone(sm, priv))
1029 if (!m->isSuccess(sm, priv)) {
1030 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 method failed");
1031 next_type = eap_fast_req_failure(sm, data);
1032 eap_fast_phase2_init(sm, data, next_type);
1036 switch (data->state) {
1038 if (eap_user_get(sm, sm->identity, sm->identity_len, 1) != 0) {
1039 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: Phase2 "
1040 "Identity not found in the user "
1042 sm->identity, sm->identity_len);
1043 next_type = eap_fast_req_failure(sm, data);
1047 eap_fast_state(data, PHASE2_METHOD);
1048 if (data->anon_provisioning) {
1050 * Only EAP-MSCHAPv2 is allowed for anonymous
1053 next_type = EAP_TYPE_MSCHAPV2;
1054 sm->user_eap_method_index = 0;
1056 next_type = sm->user->methods[0].method;
1057 sm->user_eap_method_index = 1;
1059 wpa_printf(MSG_DEBUG, "EAP-FAST: try EAP type %d", next_type);
1062 case CRYPTO_BINDING:
1063 eap_fast_update_icmk(sm, data);
1064 eap_fast_state(data, CRYPTO_BINDING);
1066 next_type = EAP_TYPE_NONE;
1068 if (sm->tnc && !data->tnc_started) {
1069 wpa_printf(MSG_DEBUG, "EAP-FAST: Initialize TNC");
1070 next_type = EAP_TYPE_TNC;
1071 data->tnc_started = 1;
1073 #endif /* EAP_TNC */
1078 wpa_printf(MSG_DEBUG, "EAP-FAST: %s - unexpected state %d",
1079 __func__, data->state);
1083 eap_fast_phase2_init(sm, data, next_type);
1087 static void eap_fast_process_phase2_eap(struct eap_sm *sm,
1088 struct eap_fast_data *data,
1089 u8 *in_data, size_t in_len)
1091 struct eap_hdr *hdr;
1094 hdr = (struct eap_hdr *) in_data;
1095 if (in_len < (int) sizeof(*hdr)) {
1096 wpa_printf(MSG_INFO, "EAP-FAST: Too short Phase 2 "
1097 "EAP frame (len=%lu)", (unsigned long) in_len);
1098 eap_fast_req_failure(sm, data);
1101 len = be_to_host16(hdr->length);
1103 wpa_printf(MSG_INFO, "EAP-FAST: Length mismatch in "
1104 "Phase 2 EAP frame (len=%lu hdr->length=%lu)",
1105 (unsigned long) in_len, (unsigned long) len);
1106 eap_fast_req_failure(sm, data);
1109 wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: code=%d "
1110 "identifier=%d length=%lu", hdr->code, hdr->identifier,
1111 (unsigned long) len);
1112 switch (hdr->code) {
1113 case EAP_CODE_RESPONSE:
1114 eap_fast_process_phase2_response(sm, data, (u8 *) hdr, len);
1117 wpa_printf(MSG_INFO, "EAP-FAST: Unexpected code=%d in "
1118 "Phase 2 EAP header", hdr->code);
1124 static int eap_fast_parse_tlvs(u8 *data, size_t data_len,
1125 struct eap_fast_tlv_parse *tlv)
1127 int mandatory, tlv_type, len, res;
1130 os_memset(tlv, 0, sizeof(*tlv));
1133 end = data + data_len;
1134 while (pos + 4 < end) {
1135 mandatory = pos[0] & 0x80;
1136 tlv_type = WPA_GET_BE16(pos) & 0x3fff;
1138 len = WPA_GET_BE16(pos);
1140 if (pos + len > end) {
1141 wpa_printf(MSG_INFO, "EAP-FAST: TLV overflow");
1144 wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: "
1145 "TLV type %d length %d%s",
1146 tlv_type, len, mandatory ? " (mandatory)" : "");
1148 res = eap_fast_parse_tlv(tlv, tlv_type, pos, len);
1153 wpa_printf(MSG_DEBUG, "EAP-FAST: Nak unknown "
1154 "mandatory TLV type %d", tlv_type);
1155 /* TODO: generate Nak TLV */
1158 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored "
1159 "unknown optional TLV type %d",
1171 static int eap_fast_validate_crypto_binding(
1172 struct eap_fast_data *data, struct eap_tlv_crypto_binding_tlv *b,
1175 u8 cmac[SHA1_MAC_LEN];
1177 wpa_printf(MSG_DEBUG, "EAP-FAST: Reply Crypto-Binding TLV: "
1178 "Version %d Received Version %d SubType %d",
1179 b->version, b->received_version, b->subtype);
1180 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
1181 b->nonce, sizeof(b->nonce));
1182 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
1183 b->compound_mac, sizeof(b->compound_mac));
1185 if (b->version != EAP_FAST_VERSION ||
1186 b->received_version != EAP_FAST_VERSION) {
1187 wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected version "
1188 "in Crypto-Binding: version %d "
1189 "received_version %d", b->version,
1190 b->received_version);
1194 if (b->subtype != EAP_TLV_CRYPTO_BINDING_SUBTYPE_RESPONSE) {
1195 wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected subtype in "
1196 "Crypto-Binding: %d", b->subtype);
1200 if (os_memcmp(data->crypto_binding_nonce, b->nonce, 31) != 0 ||
1201 (data->crypto_binding_nonce[31] | 1) != b->nonce[31]) {
1202 wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid nonce in "
1207 os_memcpy(cmac, b->compound_mac, sizeof(cmac));
1208 os_memset(b->compound_mac, 0, sizeof(cmac));
1209 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Crypto-Binding TLV for "
1210 "Compound MAC calculation",
1211 (u8 *) b, bind_len);
1212 hmac_sha1(data->cmk, EAP_FAST_CMK_LEN, (u8 *) b, bind_len,
1214 if (os_memcmp(cmac, b->compound_mac, sizeof(cmac)) != 0) {
1215 wpa_hexdump(MSG_MSGDUMP,
1216 "EAP-FAST: Calculated Compound MAC",
1217 b->compound_mac, sizeof(cmac));
1218 wpa_printf(MSG_INFO, "EAP-FAST: Compound MAC did not "
1227 static int eap_fast_pac_type(u8 *pac, size_t len, u16 type)
1229 struct eap_tlv_pac_type_tlv *tlv;
1231 if (pac == NULL || len != sizeof(*tlv))
1234 tlv = (struct eap_tlv_pac_type_tlv *) pac;
1236 return be_to_host16(tlv->tlv_type) == PAC_TYPE_PAC_TYPE &&
1237 be_to_host16(tlv->length) == 2 &&
1238 be_to_host16(tlv->pac_type) == type;
1242 static void eap_fast_process_phase2_tlvs(struct eap_sm *sm,
1243 struct eap_fast_data *data,
1244 u8 *in_data, size_t in_len)
1246 struct eap_fast_tlv_parse tlv;
1247 int check_crypto_binding = data->state == CRYPTO_BINDING;
1249 if (eap_fast_parse_tlvs(in_data, in_len, &tlv) < 0) {
1250 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to parse received "
1255 if (tlv.result == EAP_TLV_RESULT_FAILURE) {
1256 wpa_printf(MSG_DEBUG, "EAP-FAST: Result TLV indicated "
1258 eap_fast_state(data, FAILURE);
1262 if (data->state == REQUEST_PAC) {
1264 if (tlv.pac == NULL || tlv.pac_len < 6) {
1265 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC "
1266 "Acknowledgement received");
1267 eap_fast_state(data, FAILURE);
1271 type = WPA_GET_BE16(tlv.pac);
1272 len = WPA_GET_BE16(tlv.pac + 2);
1273 res = WPA_GET_BE16(tlv.pac + 4);
1275 if (type != PAC_TYPE_PAC_ACKNOWLEDGEMENT || len != 2 ||
1276 res != EAP_TLV_RESULT_SUCCESS) {
1277 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV did not "
1278 "contain acknowledgement");
1279 eap_fast_state(data, FAILURE);
1283 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Acknowledgement received "
1284 "- PAC provisioning succeeded");
1285 eap_fast_state(data, (data->anon_provisioning ||
1286 data->send_new_pac == 2) ?
1291 if (check_crypto_binding) {
1292 if (tlv.crypto_binding == NULL) {
1293 wpa_printf(MSG_DEBUG, "EAP-FAST: No Crypto-Binding "
1295 eap_fast_state(data, FAILURE);
1299 if (data->final_result &&
1300 tlv.result != EAP_TLV_RESULT_SUCCESS) {
1301 wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV "
1302 "without Success Result");
1303 eap_fast_state(data, FAILURE);
1307 if (!data->final_result &&
1308 tlv.iresult != EAP_TLV_RESULT_SUCCESS) {
1309 wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV "
1310 "without intermediate Success Result");
1311 eap_fast_state(data, FAILURE);
1315 if (eap_fast_validate_crypto_binding(data, tlv.crypto_binding,
1316 tlv.crypto_binding_len)) {
1317 eap_fast_state(data, FAILURE);
1321 wpa_printf(MSG_DEBUG, "EAP-FAST: Valid Crypto-Binding TLV "
1323 if (data->final_result) {
1324 wpa_printf(MSG_DEBUG, "EAP-FAST: Authentication "
1325 "completed successfully");
1328 if (data->anon_provisioning &&
1329 sm->eap_fast_prov != ANON_PROV &&
1330 sm->eap_fast_prov != BOTH_PROV) {
1331 wpa_printf(MSG_DEBUG, "EAP-FAST: Client is trying to "
1332 "use unauthenticated provisioning which is "
1334 eap_fast_state(data, FAILURE);
1338 if (sm->eap_fast_prov != AUTH_PROV &&
1339 sm->eap_fast_prov != BOTH_PROV &&
1340 tlv.request_action == EAP_TLV_ACTION_PROCESS_TLV &&
1341 eap_fast_pac_type(tlv.pac, tlv.pac_len,
1342 PAC_TYPE_TUNNEL_PAC)) {
1343 wpa_printf(MSG_DEBUG, "EAP-FAST: Client is trying to "
1344 "use authenticated provisioning which is "
1346 eap_fast_state(data, FAILURE);
1350 if (data->anon_provisioning ||
1351 (tlv.request_action == EAP_TLV_ACTION_PROCESS_TLV &&
1352 eap_fast_pac_type(tlv.pac, tlv.pac_len,
1353 PAC_TYPE_TUNNEL_PAC))) {
1354 wpa_printf(MSG_DEBUG, "EAP-FAST: Requested a new "
1356 eap_fast_state(data, REQUEST_PAC);
1357 } else if (data->send_new_pac) {
1358 wpa_printf(MSG_DEBUG, "EAP-FAST: Server triggered "
1359 "re-keying of Tunnel PAC");
1360 eap_fast_state(data, REQUEST_PAC);
1361 } else if (data->final_result)
1362 eap_fast_state(data, SUCCESS);
1365 if (tlv.eap_payload_tlv) {
1366 eap_fast_process_phase2_eap(sm, data, tlv.eap_payload_tlv,
1367 tlv.eap_payload_tlv_len);
1372 static void eap_fast_process_phase2(struct eap_sm *sm,
1373 struct eap_fast_data *data,
1374 struct wpabuf *in_buf)
1382 in_data = wpabuf_mhead(in_buf);
1383 in_len = wpabuf_len(in_buf);
1385 wpa_printf(MSG_DEBUG, "EAP-FAST: Received %lu bytes encrypted data for"
1386 " Phase 2", (unsigned long) in_len);
1388 if (data->pending_phase2_resp) {
1389 wpa_printf(MSG_DEBUG, "EAP-PEAP: Pending Phase 2 response - "
1390 "skip decryption and use old data");
1391 eap_fast_process_phase2_tlvs(
1392 sm, data, wpabuf_mhead(data->pending_phase2_resp),
1393 wpabuf_len(data->pending_phase2_resp));
1394 wpabuf_free(data->pending_phase2_resp);
1395 data->pending_phase2_resp = NULL;
1401 * Even though we try to disable TLS compression, it is possible that
1402 * this cannot be done with all TLS libraries. Add extra buffer space
1403 * to handle the possibility of the decrypted data being longer than
1408 in_decrypted = os_malloc(buf_len);
1409 if (in_decrypted == NULL) {
1410 wpa_printf(MSG_WARNING, "EAP-FAST: Failed to allocate memory "
1415 len_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->ssl.conn,
1417 in_decrypted, buf_len);
1418 if (len_decrypted < 0) {
1419 wpa_printf(MSG_INFO, "EAP-FAST: Failed to decrypt Phase 2 "
1421 os_free(in_decrypted);
1422 eap_fast_state(data, FAILURE);
1426 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Decrypted Phase 2 TLVs",
1427 in_decrypted, len_decrypted);
1429 eap_fast_process_phase2_tlvs(sm, data, in_decrypted, len_decrypted);
1431 if (sm->method_pending == METHOD_PENDING_WAIT) {
1432 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 method is in "
1433 "pending wait state - save decrypted response");
1434 wpabuf_free(data->pending_phase2_resp);
1435 data->pending_phase2_resp = wpabuf_alloc_copy(in_decrypted,
1439 os_free(in_decrypted);
1443 static int eap_fast_process_version(struct eap_sm *sm, void *priv,
1446 struct eap_fast_data *data = priv;
1448 data->peer_version = peer_version;
1450 if (data->force_version >= 0 && peer_version != data->force_version) {
1451 wpa_printf(MSG_INFO, "EAP-FAST: peer did not select the forced"
1452 " version (forced=%d peer=%d) - reject",
1453 data->force_version, peer_version);
1457 if (peer_version < data->fast_version) {
1458 wpa_printf(MSG_DEBUG, "EAP-FAST: peer ver=%d, own ver=%d; "
1460 peer_version, data->fast_version, peer_version);
1461 data->fast_version = peer_version;
1468 static int eap_fast_process_phase1(struct eap_sm *sm,
1469 struct eap_fast_data *data)
1471 if (eap_server_tls_phase1(sm, &data->ssl) < 0) {
1472 wpa_printf(MSG_INFO, "EAP-FAST: TLS processing failed");
1473 eap_fast_state(data, FAILURE);
1477 if (!tls_connection_established(sm->ssl_ctx, data->ssl.conn) ||
1478 wpabuf_len(data->ssl.out_buf) > 0)
1482 * Phase 1 was completed with the received message (e.g., when using
1483 * abbreviated handshake), so Phase 2 can be started immediately
1484 * without having to send through an empty message to the peer.
1487 return eap_fast_phase1_done(sm, data);
1491 static int eap_fast_process_phase2_start(struct eap_sm *sm,
1492 struct eap_fast_data *data)
1496 if (data->identity) {
1497 os_free(sm->identity);
1498 sm->identity = data->identity;
1499 data->identity = NULL;
1500 sm->identity_len = data->identity_len;
1501 data->identity_len = 0;
1502 sm->require_identity_match = 1;
1503 if (eap_user_get(sm, sm->identity, sm->identity_len, 1) != 0) {
1504 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: "
1505 "Phase2 Identity not found "
1506 "in the user database",
1507 sm->identity, sm->identity_len);
1508 next_type = eap_fast_req_failure(sm, data);
1510 wpa_printf(MSG_DEBUG, "EAP-FAST: Identity already "
1511 "known - skip Phase 2 Identity Request");
1512 next_type = sm->user->methods[0].method;
1513 sm->user_eap_method_index = 1;
1516 eap_fast_state(data, PHASE2_METHOD);
1518 eap_fast_state(data, PHASE2_ID);
1519 next_type = EAP_TYPE_IDENTITY;
1522 return eap_fast_phase2_init(sm, data, next_type);
1526 static void eap_fast_process_msg(struct eap_sm *sm, void *priv,
1527 const struct wpabuf *respData)
1529 struct eap_fast_data *data = priv;
1531 switch (data->state) {
1533 if (eap_fast_process_phase1(sm, data))
1536 /* fall through to PHASE2_START */
1538 eap_fast_process_phase2_start(sm, data);
1542 case CRYPTO_BINDING:
1544 eap_fast_process_phase2(sm, data, data->ssl.in_buf);
1547 wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected state %d in %s",
1548 data->state, __func__);
1554 static void eap_fast_process(struct eap_sm *sm, void *priv,
1555 struct wpabuf *respData)
1557 struct eap_fast_data *data = priv;
1558 if (eap_server_tls_process(sm, &data->ssl, respData, data,
1559 EAP_TYPE_FAST, eap_fast_process_version,
1560 eap_fast_process_msg) < 0)
1561 eap_fast_state(data, FAILURE);
1565 static Boolean eap_fast_isDone(struct eap_sm *sm, void *priv)
1567 struct eap_fast_data *data = priv;
1568 return data->state == SUCCESS || data->state == FAILURE;
1572 static u8 * eap_fast_getKey(struct eap_sm *sm, void *priv, size_t *len)
1574 struct eap_fast_data *data = priv;
1577 if (data->state != SUCCESS)
1580 eapKeyData = os_malloc(EAP_FAST_KEY_LEN);
1581 if (eapKeyData == NULL)
1584 eap_fast_derive_eap_msk(data->simck, eapKeyData);
1585 *len = EAP_FAST_KEY_LEN;
1591 static u8 * eap_fast_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
1593 struct eap_fast_data *data = priv;
1596 if (data->state != SUCCESS)
1599 eapKeyData = os_malloc(EAP_EMSK_LEN);
1600 if (eapKeyData == NULL)
1603 eap_fast_derive_eap_emsk(data->simck, eapKeyData);
1604 *len = EAP_EMSK_LEN;
1610 static Boolean eap_fast_isSuccess(struct eap_sm *sm, void *priv)
1612 struct eap_fast_data *data = priv;
1613 return data->state == SUCCESS;
1617 int eap_server_fast_register(void)
1619 struct eap_method *eap;
1622 eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
1623 EAP_VENDOR_IETF, EAP_TYPE_FAST, "FAST");
1627 eap->init = eap_fast_init;
1628 eap->reset = eap_fast_reset;
1629 eap->buildReq = eap_fast_buildReq;
1630 eap->check = eap_fast_check;
1631 eap->process = eap_fast_process;
1632 eap->isDone = eap_fast_isDone;
1633 eap->getKey = eap_fast_getKey;
1634 eap->get_emsk = eap_fast_get_emsk;
1635 eap->isSuccess = eap_fast_isSuccess;
1637 ret = eap_server_method_register(eap);
1639 eap_server_method_free(eap);