2 * EAP-FAST server (RFC 4851)
3 * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "crypto/aes_wrap.h"
13 #include "crypto/sha1.h"
14 #include "crypto/tls.h"
15 #include "crypto/random.h"
16 #include "eap_common/eap_tlv_common.h"
17 #include "eap_common/eap_fast_common.h"
19 #include "eap_tls_common.h"
22 static void eap_fast_reset(struct eap_sm *sm, void *priv);
25 /* Private PAC-Opaque TLV types */
26 #define PAC_OPAQUE_TYPE_PAD 0
27 #define PAC_OPAQUE_TYPE_KEY 1
28 #define PAC_OPAQUE_TYPE_LIFETIME 2
29 #define PAC_OPAQUE_TYPE_IDENTITY 3
31 struct eap_fast_data {
32 struct eap_ssl_data ssl;
34 START, PHASE1, PHASE2_START, PHASE2_ID, PHASE2_METHOD,
35 CRYPTO_BINDING, REQUEST_PAC, SUCCESS, FAILURE
39 const struct eap_method *phase2_method;
44 u8 crypto_binding_nonce[32];
47 struct eap_fast_key_block_provisioning *key_block_p;
49 u8 simck[EAP_FAST_SIMCK_LEN];
50 u8 cmk[EAP_FAST_CMK_LEN];
53 u8 pac_opaque_encr[16];
58 int anon_provisioning;
59 int send_new_pac; /* server triggered re-keying of Tunnel PAC */
60 struct wpabuf *pending_phase2_resp;
61 u8 *identity; /* from PAC-Opaque */
67 int pac_key_refresh_time;
71 static int eap_fast_process_phase2_start(struct eap_sm *sm,
72 struct eap_fast_data *data);
75 static const char * eap_fast_state_txt(int state)
83 return "PHASE2_START";
87 return "PHASE2_METHOD";
89 return "CRYPTO_BINDING";
102 static void eap_fast_state(struct eap_fast_data *data, int state)
104 wpa_printf(MSG_DEBUG, "EAP-FAST: %s -> %s",
105 eap_fast_state_txt(data->state),
106 eap_fast_state_txt(state));
111 static EapType eap_fast_req_failure(struct eap_sm *sm,
112 struct eap_fast_data *data)
114 /* TODO: send Result TLV(FAILURE) */
115 eap_fast_state(data, FAILURE);
116 return EAP_TYPE_NONE;
120 static int eap_fast_session_ticket_cb(void *ctx, const u8 *ticket, size_t len,
121 const u8 *client_random,
122 const u8 *server_random,
125 struct eap_fast_data *data = ctx;
126 const u8 *pac_opaque;
127 size_t pac_opaque_len;
128 u8 *buf, *pos, *end, *pac_key = NULL;
129 os_time_t lifetime = 0;
132 size_t identity_len = 0;
134 wpa_printf(MSG_DEBUG, "EAP-FAST: SessionTicket callback");
135 wpa_hexdump(MSG_DEBUG, "EAP-FAST: SessionTicket (PAC-Opaque)",
138 if (len < 4 || WPA_GET_BE16(ticket) != PAC_TYPE_PAC_OPAQUE) {
139 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignore invalid "
144 pac_opaque_len = WPA_GET_BE16(ticket + 2);
145 pac_opaque = ticket + 4;
146 if (pac_opaque_len < 8 || pac_opaque_len % 8 ||
147 pac_opaque_len > len - 4) {
148 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignore invalid PAC-Opaque "
149 "(len=%lu left=%lu)",
150 (unsigned long) pac_opaque_len,
151 (unsigned long) len);
154 wpa_hexdump(MSG_DEBUG, "EAP-FAST: Received PAC-Opaque",
155 pac_opaque, pac_opaque_len);
157 buf = os_malloc(pac_opaque_len - 8);
159 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to allocate memory "
160 "for decrypting PAC-Opaque");
164 if (aes_unwrap(data->pac_opaque_encr, sizeof(data->pac_opaque_encr),
165 (pac_opaque_len - 8) / 8, pac_opaque, buf) < 0) {
166 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to decrypt "
170 * This may have been caused by server changing the PAC-Opaque
171 * encryption key, so just ignore this PAC-Opaque instead of
172 * failing the authentication completely. Provisioning can now
173 * be used to provision a new PAC.
178 end = buf + pac_opaque_len - 8;
179 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Decrypted PAC-Opaque",
183 while (end - pos > 1) {
188 if (elen > end - pos)
192 case PAC_OPAQUE_TYPE_PAD:
194 case PAC_OPAQUE_TYPE_KEY:
195 if (elen != EAP_FAST_PAC_KEY_LEN) {
196 wpa_printf(MSG_DEBUG,
197 "EAP-FAST: Invalid PAC-Key length %d",
203 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: PAC-Key from "
204 "decrypted PAC-Opaque",
205 pac_key, EAP_FAST_PAC_KEY_LEN);
207 case PAC_OPAQUE_TYPE_LIFETIME:
209 wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid "
210 "PAC-Key lifetime length %d",
215 lifetime = WPA_GET_BE32(pos);
217 case PAC_OPAQUE_TYPE_IDENTITY:
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,
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,
308 sizeof(*data->key_block_p));
309 if (data->key_block_p == NULL) {
310 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive key block");
314 * RFC 4851, Section 5.2:
315 * S-IMCK[0] = session_key_seed
317 wpa_hexdump_key(MSG_DEBUG,
318 "EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
319 data->key_block_p->session_key_seed,
320 sizeof(data->key_block_p->session_key_seed));
322 os_memcpy(data->simck, data->key_block_p->session_key_seed,
324 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: server_challenge",
325 data->key_block_p->server_challenge,
326 sizeof(data->key_block_p->server_challenge));
327 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: client_challenge",
328 data->key_block_p->client_challenge,
329 sizeof(data->key_block_p->client_challenge));
333 static int eap_fast_get_phase2_key(struct eap_sm *sm,
334 struct eap_fast_data *data,
335 u8 *isk, size_t isk_len)
340 os_memset(isk, 0, isk_len);
342 if (data->phase2_method == NULL || data->phase2_priv == NULL) {
343 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not "
348 if (data->phase2_method->getKey == NULL)
351 if ((key = data->phase2_method->getKey(sm, data->phase2_priv,
352 &key_len)) == NULL) {
353 wpa_printf(MSG_DEBUG, "EAP-FAST: Could not get key material "
358 if (key_len > isk_len)
361 data->phase2_method->vendor == EAP_VENDOR_IETF &&
362 data->phase2_method->method == EAP_TYPE_MSCHAPV2) {
364 * EAP-FAST uses reverse order for MS-MPPE keys when deriving
365 * MSK from EAP-MSCHAPv2. Swap the keys here to get the correct
366 * ISK for EAP-FAST cryptobinding.
368 os_memcpy(isk, key + 16, 16);
369 os_memcpy(isk + 16, key, 16);
371 os_memcpy(isk, key, key_len);
378 static int eap_fast_update_icmk(struct eap_sm *sm, struct eap_fast_data *data)
380 u8 isk[32], imck[60];
382 wpa_printf(MSG_DEBUG, "EAP-FAST: Deriving ICMK[%d] (S-IMCK and CMK)",
383 data->simck_idx + 1);
386 * RFC 4851, Section 5.2:
387 * IMCK[j] = T-PRF(S-IMCK[j-1], "Inner Methods Compound Keys",
389 * S-IMCK[j] = first 40 octets of IMCK[j]
390 * CMK[j] = last 20 octets of IMCK[j]
393 if (eap_fast_get_phase2_key(sm, data, isk, sizeof(isk)) < 0)
395 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: ISK[j]", isk, sizeof(isk));
396 sha1_t_prf(data->simck, EAP_FAST_SIMCK_LEN,
397 "Inner Methods Compound Keys",
398 isk, sizeof(isk), imck, sizeof(imck));
400 os_memcpy(data->simck, imck, EAP_FAST_SIMCK_LEN);
401 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: S-IMCK[j]",
402 data->simck, EAP_FAST_SIMCK_LEN);
403 os_memcpy(data->cmk, imck + EAP_FAST_SIMCK_LEN, EAP_FAST_CMK_LEN);
404 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: CMK[j]",
405 data->cmk, EAP_FAST_CMK_LEN);
411 static void * eap_fast_init(struct eap_sm *sm)
413 struct eap_fast_data *data;
415 TLS_CIPHER_ANON_DH_AES128_SHA,
416 TLS_CIPHER_AES128_SHA,
417 TLS_CIPHER_RSA_DHE_AES128_SHA,
419 TLS_CIPHER_RSA_DHE_AES256_SHA,
420 TLS_CIPHER_AES256_SHA,
424 data = os_zalloc(sizeof(*data));
427 data->fast_version = EAP_FAST_VERSION;
428 data->force_version = -1;
429 if (sm->user && sm->user->force_version >= 0) {
430 data->force_version = sm->user->force_version;
431 wpa_printf(MSG_DEBUG, "EAP-FAST: forcing version %d",
432 data->force_version);
433 data->fast_version = data->force_version;
437 if (eap_server_tls_ssl_init(sm, &data->ssl, 0, EAP_TYPE_FAST)) {
438 wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize SSL.");
439 eap_fast_reset(sm, data);
443 if (tls_connection_set_cipher_list(sm->ssl_ctx, data->ssl.conn,
445 wpa_printf(MSG_INFO, "EAP-FAST: Failed to set TLS cipher "
447 eap_fast_reset(sm, data);
451 if (tls_connection_set_session_ticket_cb(sm->ssl_ctx, data->ssl.conn,
452 eap_fast_session_ticket_cb,
454 wpa_printf(MSG_INFO, "EAP-FAST: Failed to set SessionTicket "
456 eap_fast_reset(sm, data);
460 if (sm->pac_opaque_encr_key == NULL) {
461 wpa_printf(MSG_INFO, "EAP-FAST: No PAC-Opaque encryption key "
463 eap_fast_reset(sm, data);
466 os_memcpy(data->pac_opaque_encr, sm->pac_opaque_encr_key,
467 sizeof(data->pac_opaque_encr));
469 if (sm->eap_fast_a_id == NULL) {
470 wpa_printf(MSG_INFO, "EAP-FAST: No A-ID configured");
471 eap_fast_reset(sm, data);
474 data->srv_id = os_malloc(sm->eap_fast_a_id_len);
475 if (data->srv_id == NULL) {
476 eap_fast_reset(sm, data);
479 os_memcpy(data->srv_id, sm->eap_fast_a_id, sm->eap_fast_a_id_len);
480 data->srv_id_len = sm->eap_fast_a_id_len;
482 if (sm->eap_fast_a_id_info == NULL) {
483 wpa_printf(MSG_INFO, "EAP-FAST: No A-ID-Info configured");
484 eap_fast_reset(sm, data);
487 data->srv_id_info = os_strdup(sm->eap_fast_a_id_info);
488 if (data->srv_id_info == NULL) {
489 eap_fast_reset(sm, data);
493 /* PAC-Key lifetime in seconds (hard limit) */
494 data->pac_key_lifetime = sm->pac_key_lifetime;
497 * PAC-Key refresh time in seconds (soft limit on remaining hard
498 * limit). The server will generate a new PAC-Key when this number of
499 * seconds (or fewer) of the lifetime remains.
501 data->pac_key_refresh_time = sm->pac_key_refresh_time;
507 static void eap_fast_reset(struct eap_sm *sm, void *priv)
509 struct eap_fast_data *data = priv;
512 if (data->phase2_priv && data->phase2_method)
513 data->phase2_method->reset(sm, data->phase2_priv);
514 eap_server_tls_ssl_deinit(sm, &data->ssl);
515 os_free(data->srv_id);
516 os_free(data->srv_id_info);
517 os_free(data->key_block_p);
518 wpabuf_free(data->pending_phase2_resp);
519 os_free(data->identity);
520 bin_clear_free(data, sizeof(*data));
524 static struct wpabuf * eap_fast_build_start(struct eap_sm *sm,
525 struct eap_fast_data *data, u8 id)
529 req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_FAST,
530 1 + sizeof(struct pac_tlv_hdr) + data->srv_id_len,
531 EAP_CODE_REQUEST, id);
533 wpa_printf(MSG_ERROR, "EAP-FAST: Failed to allocate memory for"
535 eap_fast_state(data, FAILURE);
539 wpabuf_put_u8(req, EAP_TLS_FLAGS_START | data->fast_version);
541 /* RFC 4851, 4.1.1. Authority ID Data */
542 eap_fast_put_tlv(req, PAC_TYPE_A_ID, data->srv_id, data->srv_id_len);
544 eap_fast_state(data, PHASE1);
550 static int eap_fast_phase1_done(struct eap_sm *sm, struct eap_fast_data *data)
554 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase1 done, starting Phase2");
556 if (tls_get_cipher(sm->ssl_ctx, data->ssl.conn, cipher, sizeof(cipher))
558 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to get cipher "
560 eap_fast_state(data, FAILURE);
563 data->anon_provisioning = os_strstr(cipher, "ADH") != NULL;
565 if (data->anon_provisioning) {
566 wpa_printf(MSG_DEBUG, "EAP-FAST: Anonymous provisioning");
567 eap_fast_derive_key_provisioning(sm, data);
569 eap_fast_derive_key_auth(sm, data);
571 eap_fast_state(data, PHASE2_START);
577 static struct wpabuf * eap_fast_build_phase2_req(struct eap_sm *sm,
578 struct eap_fast_data *data,
583 if (data->phase2_priv == NULL) {
584 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not "
588 req = data->phase2_method->buildReq(sm, data->phase2_priv, id);
592 wpa_hexdump_buf_key(MSG_MSGDUMP, "EAP-FAST: Phase 2 EAP-Request", req);
593 return eap_fast_tlv_eap_payload(req);
597 static struct wpabuf * eap_fast_build_crypto_binding(
598 struct eap_sm *sm, struct eap_fast_data *data)
601 struct eap_tlv_result_tlv *result;
602 struct eap_tlv_crypto_binding_tlv *binding;
604 buf = wpabuf_alloc(2 * sizeof(*result) + sizeof(*binding));
608 if (data->send_new_pac || data->anon_provisioning ||
610 data->final_result = 0;
612 data->final_result = 1;
614 if (!data->final_result || data->eap_seq > 1) {
615 /* Intermediate-Result */
616 wpa_printf(MSG_DEBUG, "EAP-FAST: Add Intermediate-Result TLV "
618 result = wpabuf_put(buf, sizeof(*result));
619 result->tlv_type = host_to_be16(
620 EAP_TLV_TYPE_MANDATORY |
621 EAP_TLV_INTERMEDIATE_RESULT_TLV);
622 result->length = host_to_be16(2);
623 result->status = host_to_be16(EAP_TLV_RESULT_SUCCESS);
626 if (data->final_result) {
628 wpa_printf(MSG_DEBUG, "EAP-FAST: Add Result TLV "
630 result = wpabuf_put(buf, sizeof(*result));
631 result->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
633 result->length = host_to_be16(2);
634 result->status = host_to_be16(EAP_TLV_RESULT_SUCCESS);
637 /* Crypto-Binding TLV */
638 binding = wpabuf_put(buf, sizeof(*binding));
639 binding->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
640 EAP_TLV_CRYPTO_BINDING_TLV);
641 binding->length = host_to_be16(sizeof(*binding) -
642 sizeof(struct eap_tlv_hdr));
643 binding->version = EAP_FAST_VERSION;
644 binding->received_version = data->peer_version;
645 binding->subtype = EAP_TLV_CRYPTO_BINDING_SUBTYPE_REQUEST;
646 if (random_get_bytes(binding->nonce, sizeof(binding->nonce)) < 0) {
652 * RFC 4851, Section 4.2.8:
653 * The nonce in a request MUST have its least significant bit set to 0.
655 binding->nonce[sizeof(binding->nonce) - 1] &= ~0x01;
657 os_memcpy(data->crypto_binding_nonce, binding->nonce,
658 sizeof(binding->nonce));
661 * RFC 4851, Section 5.3:
663 * Compound-MAC = HMAC-SHA1( CMK, Crypto-Binding TLV )
666 hmac_sha1(data->cmk, EAP_FAST_CMK_LEN,
667 (u8 *) binding, sizeof(*binding),
668 binding->compound_mac);
670 wpa_printf(MSG_DEBUG, "EAP-FAST: Add Crypto-Binding TLV: Version %d "
671 "Received Version %d SubType %d",
672 binding->version, binding->received_version,
674 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
675 binding->nonce, sizeof(binding->nonce));
676 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
677 binding->compound_mac, sizeof(binding->compound_mac));
683 static struct wpabuf * eap_fast_build_pac(struct eap_sm *sm,
684 struct eap_fast_data *data)
686 u8 pac_key[EAP_FAST_PAC_KEY_LEN];
687 u8 *pac_buf, *pac_opaque;
690 size_t buf_len, srv_id_info_len, pac_len;
691 struct eap_tlv_hdr *pac_tlv;
692 struct pac_tlv_hdr *pac_info;
693 struct eap_tlv_result_tlv *result;
696 if (random_get_bytes(pac_key, EAP_FAST_PAC_KEY_LEN) < 0 ||
697 os_get_time(&now) < 0)
699 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Generated PAC-Key",
700 pac_key, EAP_FAST_PAC_KEY_LEN);
702 pac_len = (2 + EAP_FAST_PAC_KEY_LEN) + (2 + 4) +
703 (2 + sm->identity_len) + 8;
704 pac_buf = os_malloc(pac_len);
708 srv_id_info_len = os_strlen(data->srv_id_info);
711 *pos++ = PAC_OPAQUE_TYPE_KEY;
712 *pos++ = EAP_FAST_PAC_KEY_LEN;
713 os_memcpy(pos, pac_key, EAP_FAST_PAC_KEY_LEN);
714 pos += EAP_FAST_PAC_KEY_LEN;
716 *pos++ = PAC_OPAQUE_TYPE_LIFETIME;
718 WPA_PUT_BE32(pos, now.sec + data->pac_key_lifetime);
722 *pos++ = PAC_OPAQUE_TYPE_IDENTITY;
723 *pos++ = sm->identity_len;
724 os_memcpy(pos, sm->identity, sm->identity_len);
725 pos += sm->identity_len;
728 pac_len = pos - pac_buf;
729 while (pac_len % 8) {
730 *pos++ = PAC_OPAQUE_TYPE_PAD;
734 pac_opaque = os_malloc(pac_len + 8);
735 if (pac_opaque == NULL) {
739 if (aes_wrap(data->pac_opaque_encr, sizeof(data->pac_opaque_encr),
740 pac_len / 8, pac_buf, pac_opaque) < 0) {
748 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Opaque",
749 pac_opaque, pac_len);
751 buf_len = sizeof(*pac_tlv) +
752 sizeof(struct pac_tlv_hdr) + EAP_FAST_PAC_KEY_LEN +
753 sizeof(struct pac_tlv_hdr) + pac_len +
754 data->srv_id_len + srv_id_info_len + 100 + sizeof(*result);
755 buf = wpabuf_alloc(buf_len);
762 wpa_printf(MSG_DEBUG, "EAP-FAST: Add Result TLV (status=SUCCESS)");
763 result = wpabuf_put(buf, sizeof(*result));
764 WPA_PUT_BE16((u8 *) &result->tlv_type,
765 EAP_TLV_TYPE_MANDATORY | EAP_TLV_RESULT_TLV);
766 WPA_PUT_BE16((u8 *) &result->length, 2);
767 WPA_PUT_BE16((u8 *) &result->status, EAP_TLV_RESULT_SUCCESS);
770 wpa_printf(MSG_DEBUG, "EAP-FAST: Add PAC TLV");
771 pac_tlv = wpabuf_put(buf, sizeof(*pac_tlv));
772 pac_tlv->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
776 eap_fast_put_tlv(buf, PAC_TYPE_PAC_KEY, pac_key, EAP_FAST_PAC_KEY_LEN);
779 eap_fast_put_tlv(buf, PAC_TYPE_PAC_OPAQUE, pac_opaque, pac_len);
783 pac_info = wpabuf_put(buf, sizeof(*pac_info));
784 pac_info->type = host_to_be16(PAC_TYPE_PAC_INFO);
786 /* PAC-Lifetime (inside PAC-Info) */
787 eap_fast_put_tlv_hdr(buf, PAC_TYPE_CRED_LIFETIME, 4);
788 wpabuf_put_be32(buf, now.sec + data->pac_key_lifetime);
790 /* A-ID (inside PAC-Info) */
791 eap_fast_put_tlv(buf, PAC_TYPE_A_ID, data->srv_id, data->srv_id_len);
793 /* Note: headers may be misaligned after A-ID */
796 eap_fast_put_tlv(buf, PAC_TYPE_I_ID, sm->identity,
800 /* A-ID-Info (inside PAC-Info) */
801 eap_fast_put_tlv(buf, PAC_TYPE_A_ID_INFO, data->srv_id_info,
804 /* PAC-Type (inside PAC-Info) */
805 eap_fast_put_tlv_hdr(buf, PAC_TYPE_PAC_TYPE, 2);
806 wpabuf_put_be16(buf, PAC_TYPE_TUNNEL_PAC);
808 /* Update PAC-Info and PAC TLV Length fields */
809 pos = wpabuf_put(buf, 0);
810 pac_info->len = host_to_be16(pos - (u8 *) (pac_info + 1));
811 pac_tlv->length = host_to_be16(pos - (u8 *) (pac_tlv + 1));
817 static int eap_fast_encrypt_phase2(struct eap_sm *sm,
818 struct eap_fast_data *data,
819 struct wpabuf *plain, int piggyback)
823 wpa_hexdump_buf_key(MSG_DEBUG, "EAP-FAST: Encrypting Phase 2 TLVs",
825 encr = eap_server_tls_encrypt(sm, &data->ssl, plain);
831 if (data->ssl.tls_out && piggyback) {
832 wpa_printf(MSG_DEBUG, "EAP-FAST: Piggyback Phase 2 data "
833 "(len=%d) with last Phase 1 Message (len=%d "
835 (int) wpabuf_len(encr),
836 (int) wpabuf_len(data->ssl.tls_out),
837 (int) data->ssl.tls_out_pos);
838 if (wpabuf_resize(&data->ssl.tls_out, wpabuf_len(encr)) < 0) {
839 wpa_printf(MSG_WARNING, "EAP-FAST: Failed to resize "
844 wpabuf_put_buf(data->ssl.tls_out, encr);
847 wpabuf_free(data->ssl.tls_out);
848 data->ssl.tls_out_pos = 0;
849 data->ssl.tls_out = encr;
856 static struct wpabuf * eap_fast_buildReq(struct eap_sm *sm, void *priv, u8 id)
858 struct eap_fast_data *data = priv;
859 struct wpabuf *req = NULL;
862 if (data->ssl.state == FRAG_ACK) {
863 return eap_server_tls_build_ack(id, EAP_TYPE_FAST,
867 if (data->ssl.state == WAIT_FRAG_ACK) {
868 return eap_server_tls_build_msg(&data->ssl, EAP_TYPE_FAST,
869 data->fast_version, id);
872 switch (data->state) {
874 return eap_fast_build_start(sm, data, id);
876 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn)) {
877 if (eap_fast_phase1_done(sm, data) < 0)
879 if (data->state == PHASE2_START) {
881 * Try to generate Phase 2 data to piggyback
882 * with the end of Phase 1 to avoid extra
885 wpa_printf(MSG_DEBUG, "EAP-FAST: Try to start "
887 if (eap_fast_process_phase2_start(sm, data))
889 req = eap_fast_build_phase2_req(sm, data, id);
896 req = eap_fast_build_phase2_req(sm, data, id);
899 req = eap_fast_build_crypto_binding(sm, data);
900 if (data->phase2_method) {
902 * Include the start of the next EAP method in the
903 * sequence in the same message with Crypto-Binding to
907 eap = eap_fast_build_phase2_req(sm, data, id);
908 req = wpabuf_concat(req, eap);
909 eap_fast_state(data, PHASE2_METHOD);
913 req = eap_fast_build_pac(sm, data);
916 wpa_printf(MSG_DEBUG, "EAP-FAST: %s - unexpected state %d",
917 __func__, data->state);
922 eap_fast_encrypt_phase2(sm, data, req, piggyback) < 0)
925 return eap_server_tls_build_msg(&data->ssl, EAP_TYPE_FAST,
926 data->fast_version, id);
930 static Boolean eap_fast_check(struct eap_sm *sm, void *priv,
931 struct wpabuf *respData)
936 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_FAST, respData, &len);
937 if (pos == NULL || len < 1) {
938 wpa_printf(MSG_INFO, "EAP-FAST: Invalid frame");
946 static int eap_fast_phase2_init(struct eap_sm *sm, struct eap_fast_data *data,
949 if (data->phase2_priv && data->phase2_method) {
950 data->phase2_method->reset(sm, data->phase2_priv);
951 data->phase2_method = NULL;
952 data->phase2_priv = NULL;
954 data->phase2_method = eap_server_get_eap_method(EAP_VENDOR_IETF,
956 if (!data->phase2_method)
959 if (data->key_block_p) {
960 sm->auth_challenge = data->key_block_p->server_challenge;
961 sm->peer_challenge = data->key_block_p->client_challenge;
964 data->phase2_priv = data->phase2_method->init(sm);
966 sm->auth_challenge = NULL;
967 sm->peer_challenge = NULL;
969 return data->phase2_priv == NULL ? -1 : 0;
973 static void eap_fast_process_phase2_response(struct eap_sm *sm,
974 struct eap_fast_data *data,
975 u8 *in_data, size_t in_len)
977 u8 next_type = EAP_TYPE_NONE;
982 const struct eap_method *m = data->phase2_method;
983 void *priv = data->phase2_priv;
986 wpa_printf(MSG_DEBUG, "EAP-FAST: %s - Phase2 not "
987 "initialized?!", __func__);
991 hdr = (struct eap_hdr *) in_data;
992 pos = (u8 *) (hdr + 1);
994 if (in_len > sizeof(*hdr) && *pos == EAP_TYPE_NAK) {
995 left = in_len - sizeof(*hdr);
996 wpa_hexdump(MSG_DEBUG, "EAP-FAST: Phase2 type Nak'ed; "
997 "allowed types", pos + 1, left - 1);
998 #ifdef EAP_SERVER_TNC
999 if (m && m->vendor == EAP_VENDOR_IETF &&
1000 m->method == EAP_TYPE_TNC) {
1001 wpa_printf(MSG_DEBUG, "EAP-FAST: Peer Nak'ed required "
1003 next_type = eap_fast_req_failure(sm, data);
1004 eap_fast_phase2_init(sm, data, next_type);
1007 #endif /* EAP_SERVER_TNC */
1008 eap_sm_process_nak(sm, pos + 1, left - 1);
1009 if (sm->user && sm->user_eap_method_index < EAP_MAX_METHODS &&
1010 sm->user->methods[sm->user_eap_method_index].method !=
1012 next_type = sm->user->methods[
1013 sm->user_eap_method_index++].method;
1014 wpa_printf(MSG_DEBUG, "EAP-FAST: try EAP type %d",
1017 next_type = eap_fast_req_failure(sm, data);
1019 eap_fast_phase2_init(sm, data, next_type);
1023 wpabuf_set(&buf, in_data, in_len);
1025 if (m->check(sm, priv, &buf)) {
1026 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 check() asked to "
1027 "ignore the packet");
1028 eap_fast_req_failure(sm, data);
1032 m->process(sm, priv, &buf);
1034 if (!m->isDone(sm, priv))
1037 if (!m->isSuccess(sm, priv)) {
1038 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 method failed");
1039 next_type = eap_fast_req_failure(sm, data);
1040 eap_fast_phase2_init(sm, data, next_type);
1044 switch (data->state) {
1046 if (eap_user_get(sm, sm->identity, sm->identity_len, 1) != 0) {
1047 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: Phase2 "
1048 "Identity not found in the user "
1050 sm->identity, sm->identity_len);
1051 next_type = eap_fast_req_failure(sm, data);
1055 eap_fast_state(data, PHASE2_METHOD);
1056 if (data->anon_provisioning) {
1058 * Only EAP-MSCHAPv2 is allowed for anonymous
1061 next_type = EAP_TYPE_MSCHAPV2;
1062 sm->user_eap_method_index = 0;
1064 next_type = sm->user->methods[0].method;
1065 sm->user_eap_method_index = 1;
1067 wpa_printf(MSG_DEBUG, "EAP-FAST: try EAP type %d", next_type);
1070 case CRYPTO_BINDING:
1071 eap_fast_update_icmk(sm, data);
1072 eap_fast_state(data, CRYPTO_BINDING);
1074 next_type = EAP_TYPE_NONE;
1075 #ifdef EAP_SERVER_TNC
1076 if (sm->tnc && !data->tnc_started) {
1077 wpa_printf(MSG_DEBUG, "EAP-FAST: Initialize TNC");
1078 next_type = EAP_TYPE_TNC;
1079 data->tnc_started = 1;
1081 #endif /* EAP_SERVER_TNC */
1086 wpa_printf(MSG_DEBUG, "EAP-FAST: %s - unexpected state %d",
1087 __func__, data->state);
1091 eap_fast_phase2_init(sm, data, next_type);
1095 static void eap_fast_process_phase2_eap(struct eap_sm *sm,
1096 struct eap_fast_data *data,
1097 u8 *in_data, size_t in_len)
1099 struct eap_hdr *hdr;
1102 hdr = (struct eap_hdr *) in_data;
1103 if (in_len < (int) sizeof(*hdr)) {
1104 wpa_printf(MSG_INFO, "EAP-FAST: Too short Phase 2 "
1105 "EAP frame (len=%lu)", (unsigned long) in_len);
1106 eap_fast_req_failure(sm, data);
1109 len = be_to_host16(hdr->length);
1111 wpa_printf(MSG_INFO, "EAP-FAST: Length mismatch in "
1112 "Phase 2 EAP frame (len=%lu hdr->length=%lu)",
1113 (unsigned long) in_len, (unsigned long) len);
1114 eap_fast_req_failure(sm, data);
1117 wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: code=%d "
1118 "identifier=%d length=%lu", hdr->code, hdr->identifier,
1119 (unsigned long) len);
1120 switch (hdr->code) {
1121 case EAP_CODE_RESPONSE:
1122 eap_fast_process_phase2_response(sm, data, (u8 *) hdr, len);
1125 wpa_printf(MSG_INFO, "EAP-FAST: Unexpected code=%d in "
1126 "Phase 2 EAP header", hdr->code);
1132 static int eap_fast_parse_tlvs(struct wpabuf *data,
1133 struct eap_fast_tlv_parse *tlv)
1135 int mandatory, tlv_type, res;
1139 os_memset(tlv, 0, sizeof(*tlv));
1141 pos = wpabuf_mhead(data);
1142 end = pos + wpabuf_len(data);
1143 while (end - pos > 4) {
1144 mandatory = pos[0] & 0x80;
1145 tlv_type = WPA_GET_BE16(pos) & 0x3fff;
1147 len = WPA_GET_BE16(pos);
1149 if (len > (size_t) (end - pos)) {
1150 wpa_printf(MSG_INFO, "EAP-FAST: TLV overflow");
1153 wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: "
1154 "TLV type %d length %u%s",
1155 tlv_type, (unsigned int) len,
1156 mandatory ? " (mandatory)" : "");
1158 res = eap_fast_parse_tlv(tlv, tlv_type, pos, len);
1163 wpa_printf(MSG_DEBUG, "EAP-FAST: Nak unknown "
1164 "mandatory TLV type %d", tlv_type);
1165 /* TODO: generate Nak TLV */
1168 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored "
1169 "unknown optional TLV type %d",
1181 static int eap_fast_validate_crypto_binding(
1182 struct eap_fast_data *data, struct eap_tlv_crypto_binding_tlv *b,
1185 u8 cmac[SHA1_MAC_LEN];
1187 wpa_printf(MSG_DEBUG, "EAP-FAST: Reply Crypto-Binding TLV: "
1188 "Version %d Received Version %d SubType %d",
1189 b->version, b->received_version, b->subtype);
1190 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
1191 b->nonce, sizeof(b->nonce));
1192 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
1193 b->compound_mac, sizeof(b->compound_mac));
1195 if (b->version != EAP_FAST_VERSION ||
1196 b->received_version != EAP_FAST_VERSION) {
1197 wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected version "
1198 "in Crypto-Binding: version %d "
1199 "received_version %d", b->version,
1200 b->received_version);
1204 if (b->subtype != EAP_TLV_CRYPTO_BINDING_SUBTYPE_RESPONSE) {
1205 wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected subtype in "
1206 "Crypto-Binding: %d", b->subtype);
1210 if (os_memcmp_const(data->crypto_binding_nonce, b->nonce, 31) != 0 ||
1211 (data->crypto_binding_nonce[31] | 1) != b->nonce[31]) {
1212 wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid nonce in "
1217 os_memcpy(cmac, b->compound_mac, sizeof(cmac));
1218 os_memset(b->compound_mac, 0, sizeof(cmac));
1219 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Crypto-Binding TLV for "
1220 "Compound MAC calculation",
1221 (u8 *) b, bind_len);
1222 hmac_sha1(data->cmk, EAP_FAST_CMK_LEN, (u8 *) b, bind_len,
1224 if (os_memcmp_const(cmac, b->compound_mac, sizeof(cmac)) != 0) {
1225 wpa_hexdump(MSG_MSGDUMP,
1226 "EAP-FAST: Calculated Compound MAC",
1227 b->compound_mac, sizeof(cmac));
1228 wpa_printf(MSG_INFO, "EAP-FAST: Compound MAC did not "
1237 static int eap_fast_pac_type(u8 *pac, size_t len, u16 type)
1239 struct eap_tlv_pac_type_tlv *tlv;
1241 if (pac == NULL || len != sizeof(*tlv))
1244 tlv = (struct eap_tlv_pac_type_tlv *) pac;
1246 return be_to_host16(tlv->tlv_type) == PAC_TYPE_PAC_TYPE &&
1247 be_to_host16(tlv->length) == 2 &&
1248 be_to_host16(tlv->pac_type) == type;
1252 static void eap_fast_process_phase2_tlvs(struct eap_sm *sm,
1253 struct eap_fast_data *data,
1254 struct wpabuf *in_data)
1256 struct eap_fast_tlv_parse tlv;
1257 int check_crypto_binding = data->state == CRYPTO_BINDING;
1259 if (eap_fast_parse_tlvs(in_data, &tlv) < 0) {
1260 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to parse received "
1265 if (tlv.result == EAP_TLV_RESULT_FAILURE) {
1266 wpa_printf(MSG_DEBUG, "EAP-FAST: Result TLV indicated "
1268 eap_fast_state(data, FAILURE);
1272 if (data->state == REQUEST_PAC) {
1274 if (tlv.pac == NULL || tlv.pac_len < 6) {
1275 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC "
1276 "Acknowledgement received");
1277 eap_fast_state(data, FAILURE);
1281 type = WPA_GET_BE16(tlv.pac);
1282 len = WPA_GET_BE16(tlv.pac + 2);
1283 res = WPA_GET_BE16(tlv.pac + 4);
1285 if (type != PAC_TYPE_PAC_ACKNOWLEDGEMENT || len != 2 ||
1286 res != EAP_TLV_RESULT_SUCCESS) {
1287 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV did not "
1288 "contain acknowledgement");
1289 eap_fast_state(data, FAILURE);
1293 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Acknowledgement received "
1294 "- PAC provisioning succeeded");
1295 eap_fast_state(data, (data->anon_provisioning ||
1296 data->send_new_pac == 2) ?
1301 if (check_crypto_binding) {
1302 if (tlv.crypto_binding == NULL) {
1303 wpa_printf(MSG_DEBUG, "EAP-FAST: No Crypto-Binding "
1305 eap_fast_state(data, FAILURE);
1309 if (data->final_result &&
1310 tlv.result != EAP_TLV_RESULT_SUCCESS) {
1311 wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV "
1312 "without Success Result");
1313 eap_fast_state(data, FAILURE);
1317 if (!data->final_result &&
1318 tlv.iresult != EAP_TLV_RESULT_SUCCESS) {
1319 wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV "
1320 "without intermediate Success Result");
1321 eap_fast_state(data, FAILURE);
1325 if (eap_fast_validate_crypto_binding(data, tlv.crypto_binding,
1326 tlv.crypto_binding_len)) {
1327 eap_fast_state(data, FAILURE);
1331 wpa_printf(MSG_DEBUG, "EAP-FAST: Valid Crypto-Binding TLV "
1333 if (data->final_result) {
1334 wpa_printf(MSG_DEBUG, "EAP-FAST: Authentication "
1335 "completed successfully");
1338 if (data->anon_provisioning &&
1339 sm->eap_fast_prov != ANON_PROV &&
1340 sm->eap_fast_prov != BOTH_PROV) {
1341 wpa_printf(MSG_DEBUG, "EAP-FAST: Client is trying to "
1342 "use unauthenticated provisioning which is "
1344 eap_fast_state(data, FAILURE);
1348 if (sm->eap_fast_prov != AUTH_PROV &&
1349 sm->eap_fast_prov != BOTH_PROV &&
1350 tlv.request_action == EAP_TLV_ACTION_PROCESS_TLV &&
1351 eap_fast_pac_type(tlv.pac, tlv.pac_len,
1352 PAC_TYPE_TUNNEL_PAC)) {
1353 wpa_printf(MSG_DEBUG, "EAP-FAST: Client is trying to "
1354 "use authenticated provisioning which is "
1356 eap_fast_state(data, FAILURE);
1360 if (data->anon_provisioning ||
1361 (tlv.request_action == EAP_TLV_ACTION_PROCESS_TLV &&
1362 eap_fast_pac_type(tlv.pac, tlv.pac_len,
1363 PAC_TYPE_TUNNEL_PAC))) {
1364 wpa_printf(MSG_DEBUG, "EAP-FAST: Requested a new "
1366 eap_fast_state(data, REQUEST_PAC);
1367 } else if (data->send_new_pac) {
1368 wpa_printf(MSG_DEBUG, "EAP-FAST: Server triggered "
1369 "re-keying of Tunnel PAC");
1370 eap_fast_state(data, REQUEST_PAC);
1371 } else if (data->final_result)
1372 eap_fast_state(data, SUCCESS);
1375 if (tlv.eap_payload_tlv) {
1376 eap_fast_process_phase2_eap(sm, data, tlv.eap_payload_tlv,
1377 tlv.eap_payload_tlv_len);
1382 static void eap_fast_process_phase2(struct eap_sm *sm,
1383 struct eap_fast_data *data,
1384 struct wpabuf *in_buf)
1386 struct wpabuf *in_decrypted;
1388 wpa_printf(MSG_DEBUG, "EAP-FAST: Received %lu bytes encrypted data for"
1389 " Phase 2", (unsigned long) wpabuf_len(in_buf));
1391 if (data->pending_phase2_resp) {
1392 wpa_printf(MSG_DEBUG, "EAP-PEAP: Pending Phase 2 response - "
1393 "skip decryption and use old data");
1394 eap_fast_process_phase2_tlvs(sm, data,
1395 data->pending_phase2_resp);
1396 wpabuf_free(data->pending_phase2_resp);
1397 data->pending_phase2_resp = NULL;
1401 in_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->ssl.conn,
1403 if (in_decrypted == NULL) {
1404 wpa_printf(MSG_INFO, "EAP-FAST: Failed to decrypt Phase 2 "
1406 eap_fast_state(data, FAILURE);
1410 wpa_hexdump_buf_key(MSG_DEBUG, "EAP-FAST: Decrypted Phase 2 TLVs",
1413 eap_fast_process_phase2_tlvs(sm, data, in_decrypted);
1415 if (sm->method_pending == METHOD_PENDING_WAIT) {
1416 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 method is in "
1417 "pending wait state - save decrypted response");
1418 wpabuf_free(data->pending_phase2_resp);
1419 data->pending_phase2_resp = in_decrypted;
1423 wpabuf_free(in_decrypted);
1427 static int eap_fast_process_version(struct eap_sm *sm, void *priv,
1430 struct eap_fast_data *data = priv;
1432 data->peer_version = peer_version;
1434 if (data->force_version >= 0 && peer_version != data->force_version) {
1435 wpa_printf(MSG_INFO, "EAP-FAST: peer did not select the forced"
1436 " version (forced=%d peer=%d) - reject",
1437 data->force_version, peer_version);
1441 if (peer_version < data->fast_version) {
1442 wpa_printf(MSG_DEBUG, "EAP-FAST: peer ver=%d, own ver=%d; "
1444 peer_version, data->fast_version, peer_version);
1445 data->fast_version = peer_version;
1452 static int eap_fast_process_phase1(struct eap_sm *sm,
1453 struct eap_fast_data *data)
1455 if (eap_server_tls_phase1(sm, &data->ssl) < 0) {
1456 wpa_printf(MSG_INFO, "EAP-FAST: TLS processing failed");
1457 eap_fast_state(data, FAILURE);
1461 if (!tls_connection_established(sm->ssl_ctx, data->ssl.conn) ||
1462 wpabuf_len(data->ssl.tls_out) > 0)
1466 * Phase 1 was completed with the received message (e.g., when using
1467 * abbreviated handshake), so Phase 2 can be started immediately
1468 * without having to send through an empty message to the peer.
1471 return eap_fast_phase1_done(sm, data);
1475 static int eap_fast_process_phase2_start(struct eap_sm *sm,
1476 struct eap_fast_data *data)
1480 if (data->identity) {
1481 os_free(sm->identity);
1482 sm->identity = data->identity;
1483 data->identity = NULL;
1484 sm->identity_len = data->identity_len;
1485 data->identity_len = 0;
1486 sm->require_identity_match = 1;
1487 if (eap_user_get(sm, sm->identity, sm->identity_len, 1) != 0) {
1488 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: "
1489 "Phase2 Identity not found "
1490 "in the user database",
1491 sm->identity, sm->identity_len);
1492 next_type = eap_fast_req_failure(sm, data);
1494 wpa_printf(MSG_DEBUG, "EAP-FAST: Identity already "
1495 "known - skip Phase 2 Identity Request");
1496 next_type = sm->user->methods[0].method;
1497 sm->user_eap_method_index = 1;
1500 eap_fast_state(data, PHASE2_METHOD);
1502 eap_fast_state(data, PHASE2_ID);
1503 next_type = EAP_TYPE_IDENTITY;
1506 return eap_fast_phase2_init(sm, data, next_type);
1510 static void eap_fast_process_msg(struct eap_sm *sm, void *priv,
1511 const struct wpabuf *respData)
1513 struct eap_fast_data *data = priv;
1515 switch (data->state) {
1517 if (eap_fast_process_phase1(sm, data))
1520 /* fall through to PHASE2_START */
1522 eap_fast_process_phase2_start(sm, data);
1526 case CRYPTO_BINDING:
1528 eap_fast_process_phase2(sm, data, data->ssl.tls_in);
1531 wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected state %d in %s",
1532 data->state, __func__);
1538 static void eap_fast_process(struct eap_sm *sm, void *priv,
1539 struct wpabuf *respData)
1541 struct eap_fast_data *data = priv;
1542 if (eap_server_tls_process(sm, &data->ssl, respData, data,
1543 EAP_TYPE_FAST, eap_fast_process_version,
1544 eap_fast_process_msg) < 0)
1545 eap_fast_state(data, FAILURE);
1549 static Boolean eap_fast_isDone(struct eap_sm *sm, void *priv)
1551 struct eap_fast_data *data = priv;
1552 return data->state == SUCCESS || data->state == FAILURE;
1556 static u8 * eap_fast_getKey(struct eap_sm *sm, void *priv, size_t *len)
1558 struct eap_fast_data *data = priv;
1561 if (data->state != SUCCESS)
1564 eapKeyData = os_malloc(EAP_FAST_KEY_LEN);
1565 if (eapKeyData == NULL)
1568 if (eap_fast_derive_eap_msk(data->simck, eapKeyData) < 0) {
1569 os_free(eapKeyData);
1572 *len = EAP_FAST_KEY_LEN;
1578 static u8 * eap_fast_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
1580 struct eap_fast_data *data = priv;
1583 if (data->state != SUCCESS)
1586 eapKeyData = os_malloc(EAP_EMSK_LEN);
1587 if (eapKeyData == NULL)
1590 if (eap_fast_derive_eap_emsk(data->simck, eapKeyData) < 0) {
1591 os_free(eapKeyData);
1594 *len = EAP_EMSK_LEN;
1600 static Boolean eap_fast_isSuccess(struct eap_sm *sm, void *priv)
1602 struct eap_fast_data *data = priv;
1603 return data->state == SUCCESS;
1607 static u8 * eap_fast_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
1609 struct eap_fast_data *data = priv;
1611 if (data->state != SUCCESS)
1614 return eap_server_tls_derive_session_id(sm, &data->ssl, EAP_TYPE_FAST,
1619 int eap_server_fast_register(void)
1621 struct eap_method *eap;
1623 eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
1624 EAP_VENDOR_IETF, EAP_TYPE_FAST, "FAST");
1628 eap->init = eap_fast_init;
1629 eap->reset = eap_fast_reset;
1630 eap->buildReq = eap_fast_buildReq;
1631 eap->check = eap_fast_check;
1632 eap->process = eap_fast_process;
1633 eap->isDone = eap_fast_isDone;
1634 eap->getKey = eap_fast_getKey;
1635 eap->get_emsk = eap_fast_get_emsk;
1636 eap->isSuccess = eap_fast_isSuccess;
1637 eap->getSessionId = eap_fast_get_session_id;
1639 return eap_server_method_register(eap);