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 /* PAC-Key lifetime in seconds (hard limit) */
37 #define PAC_KEY_LIFETIME (7 * 24 * 60 * 60)
40 * PAC-Key refresh time in seconds (soft limit on remaining hard limit). The
41 * server will generate a new PAC-Key when this number of seconds (or fewer)
44 #define PAC_KEY_REFRESH_TIME (1 * 24 * 60 * 60)
47 struct eap_fast_data
{
48 struct eap_ssl_data ssl
;
50 START
, PHASE1
, PHASE2_START
, PHASE2_ID
, PHASE2_METHOD
,
51 CRYPTO_BINDING
, REQUEST_PAC
, SUCCESS
, FAILURE
55 const struct eap_method
*phase2_method
;
60 u8 crypto_binding_nonce
[32];
63 struct eap_fast_key_block_provisioning
*key_block_p
;
65 u8 simck
[EAP_FAST_SIMCK_LEN
];
66 u8 cmk
[EAP_FAST_CMK_LEN
];
69 u8 pac_opaque_encr
[16];
72 int anon_provisioning
;
73 int send_new_pac
; /* server triggered re-keying of Tunnel PAC */
74 struct wpabuf
*pending_phase2_resp
;
75 u8
*identity
; /* from PAC-Opaque */
82 static const char * eap_fast_state_txt(int state
)
90 return "PHASE2_START";
94 return "PHASE2_METHOD";
96 return "CRYPTO_BINDING";
109 static void eap_fast_state(struct eap_fast_data
*data
, int state
)
111 wpa_printf(MSG_DEBUG
, "EAP-FAST: %s -> %s",
112 eap_fast_state_txt(data
->state
),
113 eap_fast_state_txt(state
));
118 static EapType
eap_fast_req_failure(struct eap_sm
*sm
,
119 struct eap_fast_data
*data
)
121 /* TODO: send Result TLV(FAILURE) */
122 eap_fast_state(data
, FAILURE
);
123 return EAP_TYPE_NONE
;
127 static int eap_fast_session_ticket_cb(void *ctx
, const u8
*ticket
, size_t len
,
128 const u8
*client_random
,
129 const u8
*server_random
,
132 struct eap_fast_data
*data
= ctx
;
133 const u8
*pac_opaque
;
134 size_t pac_opaque_len
;
135 u8
*buf
, *pos
, *end
, *pac_key
= NULL
;
136 os_time_t lifetime
= 0;
139 size_t identity_len
= 0;
141 wpa_printf(MSG_DEBUG
, "EAP-FAST: SessionTicket callback");
142 wpa_hexdump(MSG_DEBUG
, "EAP-FAST: SessionTicket (PAC-Opaque)",
145 if (len
< 4 || WPA_GET_BE16(ticket
) != PAC_TYPE_PAC_OPAQUE
) {
146 wpa_printf(MSG_DEBUG
, "EAP-FAST: Ignore invalid "
151 pac_opaque_len
= WPA_GET_BE16(ticket
+ 2);
152 pac_opaque
= ticket
+ 4;
153 if (pac_opaque_len
< 8 || pac_opaque_len
% 8 ||
154 pac_opaque_len
> len
- 4) {
155 wpa_printf(MSG_DEBUG
, "EAP-FAST: Ignore invalid PAC-Opaque "
156 "(len=%lu left=%lu)",
157 (unsigned long) pac_opaque_len
,
158 (unsigned long) len
);
161 wpa_hexdump(MSG_DEBUG
, "EAP-FAST: Received PAC-Opaque",
162 pac_opaque
, pac_opaque_len
);
164 buf
= os_malloc(pac_opaque_len
- 8);
166 wpa_printf(MSG_DEBUG
, "EAP-FAST: Failed to allocate memory "
167 "for decrypting PAC-Opaque");
171 if (aes_unwrap(data
->pac_opaque_encr
, (pac_opaque_len
- 8) / 8,
172 pac_opaque
, buf
) < 0) {
173 wpa_printf(MSG_DEBUG
, "EAP-FAST: Failed to decrypt "
177 * This may have been caused by server changing the PAC-Opaque
178 * encryption key, so just ignore this PAC-Opaque instead of
179 * failing the authentication completely. Provisioning can now
180 * be used to provision a new PAC.
185 end
= buf
+ pac_opaque_len
- 8;
186 wpa_hexdump_key(MSG_DEBUG
, "EAP-FAST: Decrypted PAC-Opaque",
190 while (pos
+ 1 < end
) {
191 if (pos
+ 2 + pos
[1] > end
)
195 case PAC_OPAQUE_TYPE_PAD
:
198 case PAC_OPAQUE_TYPE_KEY
:
199 if (pos
[1] != EAP_FAST_PAC_KEY_LEN
) {
200 wpa_printf(MSG_DEBUG
, "EAP-FAST: Invalid "
201 "PAC-Key length %d", pos
[1]);
206 wpa_hexdump_key(MSG_DEBUG
, "EAP-FAST: PAC-Key from "
207 "decrypted PAC-Opaque",
208 pac_key
, EAP_FAST_PAC_KEY_LEN
);
210 case PAC_OPAQUE_TYPE_LIFETIME
:
212 wpa_printf(MSG_DEBUG
, "EAP-FAST: Invalid "
213 "PAC-Key lifetime length %d",
218 lifetime
= WPA_GET_BE32(pos
+ 2);
220 case PAC_OPAQUE_TYPE_IDENTITY
:
222 identity_len
= pos
[1];
229 if (pac_key
== NULL
) {
230 wpa_printf(MSG_DEBUG
, "EAP-FAST: No PAC-Key included in "
237 wpa_hexdump_ascii(MSG_DEBUG
, "EAP-FAST: Identity from "
238 "PAC-Opaque", identity
, identity_len
);
239 os_free(data
->identity
);
240 data
->identity
= os_malloc(identity_len
);
241 if (data
->identity
) {
242 os_memcpy(data
->identity
, identity
, identity_len
);
243 data
->identity_len
= identity_len
;
247 if (os_get_time(&now
) < 0 || lifetime
<= 0 || now
.sec
> lifetime
) {
248 wpa_printf(MSG_DEBUG
, "EAP-FAST: PAC-Key not valid anymore "
249 "(lifetime=%ld now=%ld)", lifetime
, now
.sec
);
254 if (lifetime
- now
.sec
< PAC_KEY_REFRESH_TIME
)
255 data
->send_new_pac
= 1;
257 eap_fast_derive_master_secret(pac_key
, server_random
, client_random
,
266 static void eap_fast_derive_key_auth(struct eap_sm
*sm
,
267 struct eap_fast_data
*data
)
271 /* RFC 4851, Section 5.1:
272 * Extra key material after TLS key_block: session_key_seed[40]
275 sks
= eap_fast_derive_key(sm
->ssl_ctx
, data
->ssl
.conn
, "key expansion",
278 wpa_printf(MSG_DEBUG
, "EAP-FAST: Failed to derive "
284 * RFC 4851, Section 5.2:
285 * S-IMCK[0] = session_key_seed
287 wpa_hexdump_key(MSG_DEBUG
,
288 "EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
289 sks
, EAP_FAST_SKS_LEN
);
291 os_memcpy(data
->simck
, sks
, EAP_FAST_SIMCK_LEN
);
296 static void eap_fast_derive_key_provisioning(struct eap_sm
*sm
,
297 struct eap_fast_data
*data
)
299 os_free(data
->key_block_p
);
300 data
->key_block_p
= (struct eap_fast_key_block_provisioning
*)
301 eap_fast_derive_key(sm
->ssl_ctx
, data
->ssl
.conn
,
303 sizeof(*data
->key_block_p
));
304 if (data
->key_block_p
== NULL
) {
305 wpa_printf(MSG_DEBUG
, "EAP-FAST: Failed to derive key block");
309 * RFC 4851, Section 5.2:
310 * S-IMCK[0] = session_key_seed
312 wpa_hexdump_key(MSG_DEBUG
,
313 "EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
314 data
->key_block_p
->session_key_seed
,
315 sizeof(data
->key_block_p
->session_key_seed
));
317 os_memcpy(data
->simck
, data
->key_block_p
->session_key_seed
,
319 wpa_hexdump_key(MSG_DEBUG
, "EAP-FAST: server_challenge",
320 data
->key_block_p
->server_challenge
,
321 sizeof(data
->key_block_p
->server_challenge
));
322 wpa_hexdump_key(MSG_DEBUG
, "EAP-FAST: client_challenge",
323 data
->key_block_p
->client_challenge
,
324 sizeof(data
->key_block_p
->client_challenge
));
328 static int eap_fast_get_phase2_key(struct eap_sm
*sm
,
329 struct eap_fast_data
*data
,
330 u8
*isk
, size_t isk_len
)
335 os_memset(isk
, 0, isk_len
);
337 if (data
->phase2_method
== NULL
|| data
->phase2_priv
== NULL
) {
338 wpa_printf(MSG_DEBUG
, "EAP-FAST: Phase 2 method not "
343 if (data
->phase2_method
->getKey
== NULL
)
346 if ((key
= data
->phase2_method
->getKey(sm
, data
->phase2_priv
,
347 &key_len
)) == NULL
) {
348 wpa_printf(MSG_DEBUG
, "EAP-FAST: Could not get key material "
353 if (key_len
> isk_len
)
355 os_memcpy(isk
, key
, key_len
);
362 static int eap_fast_update_icmk(struct eap_sm
*sm
, struct eap_fast_data
*data
)
364 u8 isk
[32], imck
[60];
366 wpa_printf(MSG_DEBUG
, "EAP-FAST: Deriving ICMK[%d] (S-IMCK and CMK)",
367 data
->simck_idx
+ 1);
370 * RFC 4851, Section 5.2:
371 * IMCK[j] = T-PRF(S-IMCK[j-1], "Inner Methods Compound Keys",
373 * S-IMCK[j] = first 40 octets of IMCK[j]
374 * CMK[j] = last 20 octets of IMCK[j]
377 if (eap_fast_get_phase2_key(sm
, data
, isk
, sizeof(isk
)) < 0)
379 wpa_hexdump_key(MSG_MSGDUMP
, "EAP-FAST: ISK[j]", isk
, sizeof(isk
));
380 sha1_t_prf(data
->simck
, EAP_FAST_SIMCK_LEN
,
381 "Inner Methods Compound Keys",
382 isk
, sizeof(isk
), imck
, sizeof(imck
));
384 os_memcpy(data
->simck
, imck
, EAP_FAST_SIMCK_LEN
);
385 wpa_hexdump_key(MSG_MSGDUMP
, "EAP-FAST: S-IMCK[j]",
386 data
->simck
, EAP_FAST_SIMCK_LEN
);
387 os_memcpy(data
->cmk
, imck
+ EAP_FAST_SIMCK_LEN
, EAP_FAST_CMK_LEN
);
388 wpa_hexdump_key(MSG_MSGDUMP
, "EAP-FAST: CMK[j]",
389 data
->cmk
, EAP_FAST_CMK_LEN
);
395 static void * eap_fast_init(struct eap_sm
*sm
)
397 struct eap_fast_data
*data
;
399 TLS_CIPHER_ANON_DH_AES128_SHA
,
400 TLS_CIPHER_AES128_SHA
,
401 TLS_CIPHER_RSA_DHE_AES128_SHA
,
406 data
= os_zalloc(sizeof(*data
));
409 data
->fast_version
= EAP_FAST_VERSION
;
410 data
->force_version
= -1;
411 if (sm
->user
&& sm
->user
->force_version
>= 0) {
412 data
->force_version
= sm
->user
->force_version
;
413 wpa_printf(MSG_DEBUG
, "EAP-FAST: forcing version %d",
414 data
->force_version
);
415 data
->fast_version
= data
->force_version
;
419 if (eap_server_tls_ssl_init(sm
, &data
->ssl
, 0)) {
420 wpa_printf(MSG_INFO
, "EAP-FAST: Failed to initialize SSL.");
421 eap_fast_reset(sm
, data
);
425 if (tls_connection_set_cipher_list(sm
->ssl_ctx
, data
->ssl
.conn
,
427 wpa_printf(MSG_INFO
, "EAP-FAST: Failed to set TLS cipher "
429 eap_fast_reset(sm
, data
);
433 if (tls_connection_set_session_ticket_cb(sm
->ssl_ctx
, data
->ssl
.conn
,
434 eap_fast_session_ticket_cb
,
436 wpa_printf(MSG_INFO
, "EAP-FAST: Failed to set SessionTicket "
438 eap_fast_reset(sm
, data
);
442 if (sm
->pac_opaque_encr_key
== NULL
) {
443 wpa_printf(MSG_INFO
, "EAP-FAST: No PAC-Opaque encryption key "
445 eap_fast_reset(sm
, data
);
448 os_memcpy(data
->pac_opaque_encr
, sm
->pac_opaque_encr_key
,
449 sizeof(data
->pac_opaque_encr
));
451 if (sm
->eap_fast_a_id
== NULL
) {
452 wpa_printf(MSG_INFO
, "EAP-FAST: No A-ID configured");
453 eap_fast_reset(sm
, data
);
456 data
->srv_id
= os_strdup(sm
->eap_fast_a_id
);
457 if (data
->srv_id
== NULL
) {
458 eap_fast_reset(sm
, data
);
466 static void eap_fast_reset(struct eap_sm
*sm
, void *priv
)
468 struct eap_fast_data
*data
= priv
;
471 if (data
->phase2_priv
&& data
->phase2_method
)
472 data
->phase2_method
->reset(sm
, data
->phase2_priv
);
473 eap_server_tls_ssl_deinit(sm
, &data
->ssl
);
474 os_free(data
->srv_id
);
475 os_free(data
->key_block_p
);
476 wpabuf_free(data
->pending_phase2_resp
);
477 os_free(data
->identity
);
482 static struct wpabuf
* eap_fast_build_start(struct eap_sm
*sm
,
483 struct eap_fast_data
*data
, u8 id
)
486 size_t srv_id_len
= os_strlen(data
->srv_id
);
488 req
= eap_msg_alloc(EAP_VENDOR_IETF
, EAP_TYPE_FAST
,
489 1 + sizeof(struct pac_tlv_hdr
) + srv_id_len
,
490 EAP_CODE_REQUEST
, id
);
492 wpa_printf(MSG_ERROR
, "EAP-FAST: Failed to allocate memory for"
494 eap_fast_state(data
, FAILURE
);
498 wpabuf_put_u8(req
, EAP_TLS_FLAGS_START
| data
->fast_version
);
500 /* RFC 4851, 4.1.1. Authority ID Data */
501 eap_fast_put_tlv(req
, PAC_TYPE_A_ID
, data
->srv_id
, srv_id_len
);
503 eap_fast_state(data
, PHASE1
);
509 static int eap_fast_phase1_done(struct eap_sm
*sm
, struct eap_fast_data
*data
)
513 wpa_printf(MSG_DEBUG
, "EAP-FAST: Phase1 done, starting Phase2");
515 if (tls_get_cipher(sm
->ssl_ctx
, data
->ssl
.conn
, cipher
, sizeof(cipher
))
517 wpa_printf(MSG_DEBUG
, "EAP-FAST: Failed to get cipher "
519 eap_fast_state(data
, FAILURE
);
522 data
->anon_provisioning
= os_strstr(cipher
, "ADH") != NULL
;
524 if (data
->anon_provisioning
) {
525 wpa_printf(MSG_DEBUG
, "EAP-FAST: Anonymous provisioning");
526 eap_fast_derive_key_provisioning(sm
, data
);
528 eap_fast_derive_key_auth(sm
, data
);
530 eap_fast_state(data
, PHASE2_START
);
536 static struct wpabuf
* eap_fast_build_phase2_req(struct eap_sm
*sm
,
537 struct eap_fast_data
*data
,
542 if (data
->phase2_priv
== NULL
) {
543 wpa_printf(MSG_DEBUG
, "EAP-FAST: Phase 2 method not "
547 req
= data
->phase2_method
->buildReq(sm
, data
->phase2_priv
, id
);
551 wpa_hexdump_buf_key(MSG_MSGDUMP
, "EAP-FAST: Phase 2 EAP-Request", req
);
552 return eap_fast_tlv_eap_payload(req
);
556 static struct wpabuf
* eap_fast_build_crypto_binding(
557 struct eap_sm
*sm
, struct eap_fast_data
*data
)
560 struct eap_tlv_result_tlv
*result
;
561 struct eap_tlv_crypto_binding_tlv
*binding
;
563 buf
= wpabuf_alloc(2 * sizeof(*result
) + sizeof(*binding
));
567 if (data
->send_new_pac
|| data
->anon_provisioning
||
569 data
->final_result
= 0;
571 data
->final_result
= 1;
573 if (!data
->final_result
|| data
->eap_seq
> 1) {
574 /* Intermediate-Result */
575 wpa_printf(MSG_DEBUG
, "EAP-FAST: Add Intermediate-Result TLV "
577 result
= wpabuf_put(buf
, sizeof(*result
));
578 result
->tlv_type
= host_to_be16(
579 EAP_TLV_TYPE_MANDATORY
|
580 EAP_TLV_INTERMEDIATE_RESULT_TLV
);
581 result
->length
= host_to_be16(2);
582 result
->status
= host_to_be16(EAP_TLV_RESULT_SUCCESS
);
585 if (data
->final_result
) {
587 wpa_printf(MSG_DEBUG
, "EAP-FAST: Add Result TLV "
589 result
= wpabuf_put(buf
, sizeof(*result
));
590 result
->tlv_type
= host_to_be16(EAP_TLV_TYPE_MANDATORY
|
592 result
->length
= host_to_be16(2);
593 result
->status
= host_to_be16(EAP_TLV_RESULT_SUCCESS
);
596 /* Crypto-Binding TLV */
597 binding
= wpabuf_put(buf
, sizeof(*binding
));
598 binding
->tlv_type
= host_to_be16(EAP_TLV_TYPE_MANDATORY
|
599 EAP_TLV_CRYPTO_BINDING_TLV
);
600 binding
->length
= host_to_be16(sizeof(*binding
) -
601 sizeof(struct eap_tlv_hdr
));
602 binding
->version
= EAP_FAST_VERSION
;
603 binding
->received_version
= data
->peer_version
;
604 binding
->subtype
= EAP_TLV_CRYPTO_BINDING_SUBTYPE_REQUEST
;
605 if (os_get_random(binding
->nonce
, sizeof(binding
->nonce
)) < 0) {
611 * RFC 4851, Section 4.2.8:
612 * The nonce in a request MUST have its least significant bit set to 0.
614 binding
->nonce
[sizeof(binding
->nonce
) - 1] &= ~0x01;
616 os_memcpy(data
->crypto_binding_nonce
, binding
->nonce
,
617 sizeof(binding
->nonce
));
620 * RFC 4851, Section 5.3:
622 * Compound-MAC = HMAC-SHA1( CMK, Crypto-Binding TLV )
625 hmac_sha1(data
->cmk
, EAP_FAST_CMK_LEN
,
626 (u8
*) binding
, sizeof(*binding
),
627 binding
->compound_mac
);
629 wpa_printf(MSG_DEBUG
, "EAP-FAST: Add Crypto-Binding TLV: Version %d "
630 "Received Version %d SubType %d",
631 binding
->version
, binding
->received_version
,
633 wpa_hexdump(MSG_MSGDUMP
, "EAP-FAST: NONCE",
634 binding
->nonce
, sizeof(binding
->nonce
));
635 wpa_hexdump(MSG_MSGDUMP
, "EAP-FAST: Compound MAC",
636 binding
->compound_mac
, sizeof(binding
->compound_mac
));
642 static struct wpabuf
* eap_fast_build_pac(struct eap_sm
*sm
,
643 struct eap_fast_data
*data
)
645 u8 pac_key
[EAP_FAST_PAC_KEY_LEN
];
646 u8
*pac_buf
, *pac_opaque
;
649 size_t buf_len
, srv_id_len
, pac_len
;
650 struct eap_tlv_hdr
*pac_tlv
;
651 struct pac_tlv_hdr
*pac_info
;
652 struct eap_tlv_result_tlv
*result
;
655 if (os_get_random(pac_key
, EAP_FAST_PAC_KEY_LEN
) < 0 ||
656 os_get_time(&now
) < 0)
658 wpa_hexdump_key(MSG_DEBUG
, "EAP-FAST: Generated PAC-Key",
659 pac_key
, EAP_FAST_PAC_KEY_LEN
);
661 pac_len
= (2 + EAP_FAST_PAC_KEY_LEN
) + (2 + 4) +
662 (2 + sm
->identity_len
) + 8;
663 pac_buf
= os_malloc(pac_len
);
667 srv_id_len
= os_strlen(data
->srv_id
);
670 *pos
++ = PAC_OPAQUE_TYPE_KEY
;
671 *pos
++ = EAP_FAST_PAC_KEY_LEN
;
672 os_memcpy(pos
, pac_key
, EAP_FAST_PAC_KEY_LEN
);
673 pos
+= EAP_FAST_PAC_KEY_LEN
;
675 *pos
++ = PAC_OPAQUE_TYPE_LIFETIME
;
677 WPA_PUT_BE32(pos
, now
.sec
+ PAC_KEY_LIFETIME
);
681 *pos
++ = PAC_OPAQUE_TYPE_IDENTITY
;
682 *pos
++ = sm
->identity_len
;
683 os_memcpy(pos
, sm
->identity
, sm
->identity_len
);
684 pos
+= sm
->identity_len
;
687 pac_len
= pos
- pac_buf
;
689 *pos
++ = PAC_OPAQUE_TYPE_PAD
;
693 pac_opaque
= os_malloc(pac_len
+ 8);
694 if (pac_opaque
== NULL
) {
698 if (aes_wrap(data
->pac_opaque_encr
, pac_len
/ 8, pac_buf
,
707 wpa_hexdump(MSG_DEBUG
, "EAP-FAST: PAC-Opaque",
708 pac_opaque
, pac_len
);
710 buf_len
= sizeof(*pac_tlv
) +
711 sizeof(struct pac_tlv_hdr
) + EAP_FAST_PAC_KEY_LEN
+
712 sizeof(struct pac_tlv_hdr
) + pac_len
+
713 2 * srv_id_len
+ 100 + sizeof(*result
);
714 buf
= wpabuf_alloc(buf_len
);
721 wpa_printf(MSG_DEBUG
, "EAP-FAST: Add PAC TLV");
722 pac_tlv
= wpabuf_put(buf
, sizeof(*pac_tlv
));
723 pac_tlv
->tlv_type
= host_to_be16(EAP_TLV_TYPE_MANDATORY
|
727 eap_fast_put_tlv(buf
, PAC_TYPE_PAC_KEY
, pac_key
, EAP_FAST_PAC_KEY_LEN
);
730 eap_fast_put_tlv(buf
, PAC_TYPE_PAC_OPAQUE
, pac_opaque
, pac_len
);
734 pac_info
= wpabuf_put(buf
, sizeof(*pac_info
));
735 pac_info
->type
= host_to_be16(PAC_TYPE_PAC_INFO
);
737 /* PAC-Lifetime (inside PAC-Info) */
738 eap_fast_put_tlv_hdr(buf
, PAC_TYPE_CRED_LIFETIME
, 4);
739 wpabuf_put_be32(buf
, now
.sec
+ PAC_KEY_LIFETIME
);
741 /* A-ID (inside PAC-Info) */
742 eap_fast_put_tlv(buf
, PAC_TYPE_A_ID
, data
->srv_id
, srv_id_len
);
744 /* Note: headers may be misaligned after A-ID */
746 /* A-ID-Info (inside PAC-Info) */
747 eap_fast_put_tlv(buf
, PAC_TYPE_A_ID_INFO
, data
->srv_id
, srv_id_len
);
749 /* PAC-Type (inside PAC-Info) */
750 eap_fast_put_tlv_hdr(buf
, PAC_TYPE_PAC_TYPE
, 2);
751 wpabuf_put_be16(buf
, PAC_TYPE_TUNNEL_PAC
);
753 /* Update PAC-Info and PAC TLV Length fields */
754 pos
= wpabuf_put(buf
, 0);
755 pac_info
->len
= host_to_be16(pos
- (u8
*) (pac_info
+ 1));
756 pac_tlv
->length
= host_to_be16(pos
- (u8
*) (pac_tlv
+ 1));
759 wpa_printf(MSG_DEBUG
, "EAP-FAST: Add Result TLV (status=SUCCESS)");
760 result
= wpabuf_put(buf
, sizeof(*result
));
761 WPA_PUT_BE16((u8
*) &result
->tlv_type
,
762 EAP_TLV_TYPE_MANDATORY
| EAP_TLV_RESULT_TLV
);
763 WPA_PUT_BE16((u8
*) &result
->length
, 2);
764 WPA_PUT_BE16((u8
*) &result
->status
, EAP_TLV_RESULT_SUCCESS
);
770 static struct wpabuf
* eap_fast_buildReq(struct eap_sm
*sm
, void *priv
, u8 id
)
772 struct eap_fast_data
*data
= priv
;
773 struct wpabuf
*req
= NULL
;
776 if (data
->ssl
.state
== FRAG_ACK
) {
777 return eap_server_tls_build_ack(id
, EAP_TYPE_FAST
,
781 if (data
->ssl
.state
== WAIT_FRAG_ACK
) {
782 return eap_server_tls_build_msg(&data
->ssl
, EAP_TYPE_FAST
,
783 data
->fast_version
, id
);
786 switch (data
->state
) {
788 return eap_fast_build_start(sm
, data
, id
);
790 if (tls_connection_established(sm
->ssl_ctx
, data
->ssl
.conn
)) {
791 if (eap_fast_phase1_done(sm
, data
) < 0)
797 req
= eap_fast_build_phase2_req(sm
, data
, id
);
800 req
= eap_fast_build_crypto_binding(sm
, data
);
801 if (data
->phase2_method
) {
803 * Include the start of the next EAP method in the
804 * sequence in the same message with Crypto-Binding to
808 eap
= eap_fast_build_phase2_req(sm
, data
, id
);
809 req
= wpabuf_concat(req
, eap
);
810 eap_fast_state(data
, PHASE2_METHOD
);
814 req
= eap_fast_build_pac(sm
, data
);
817 wpa_printf(MSG_DEBUG
, "EAP-FAST: %s - unexpected state %d",
818 __func__
, data
->state
);
823 wpa_hexdump_buf_key(MSG_DEBUG
, "EAP-FAST: Encrypting Phase 2 "
825 encr
= eap_server_tls_encrypt(sm
, &data
->ssl
,
830 wpabuf_free(data
->ssl
.out_buf
);
831 data
->ssl
.out_used
= 0;
832 data
->ssl
.out_buf
= encr
;
835 return eap_server_tls_build_msg(&data
->ssl
, EAP_TYPE_FAST
,
836 data
->fast_version
, id
);
840 static Boolean
eap_fast_check(struct eap_sm
*sm
, void *priv
,
841 struct wpabuf
*respData
)
846 pos
= eap_hdr_validate(EAP_VENDOR_IETF
, EAP_TYPE_FAST
, respData
, &len
);
847 if (pos
== NULL
|| len
< 1) {
848 wpa_printf(MSG_INFO
, "EAP-FAST: Invalid frame");
856 static int eap_fast_phase2_init(struct eap_sm
*sm
, struct eap_fast_data
*data
,
859 if (data
->phase2_priv
&& data
->phase2_method
) {
860 data
->phase2_method
->reset(sm
, data
->phase2_priv
);
861 data
->phase2_method
= NULL
;
862 data
->phase2_priv
= NULL
;
864 data
->phase2_method
= eap_server_get_eap_method(EAP_VENDOR_IETF
,
866 if (!data
->phase2_method
)
869 if (data
->key_block_p
) {
870 sm
->auth_challenge
= data
->key_block_p
->server_challenge
;
871 sm
->peer_challenge
= data
->key_block_p
->client_challenge
;
874 data
->phase2_priv
= data
->phase2_method
->init(sm
);
876 sm
->auth_challenge
= NULL
;
877 sm
->peer_challenge
= NULL
;
879 return data
->phase2_priv
== NULL
? -1 : 0;
883 static void eap_fast_process_phase2_response(struct eap_sm
*sm
,
884 struct eap_fast_data
*data
,
885 u8
*in_data
, size_t in_len
)
887 u8 next_type
= EAP_TYPE_NONE
;
892 const struct eap_method
*m
= data
->phase2_method
;
893 void *priv
= data
->phase2_priv
;
896 wpa_printf(MSG_DEBUG
, "EAP-FAST: %s - Phase2 not "
897 "initialized?!", __func__
);
901 hdr
= (struct eap_hdr
*) in_data
;
902 pos
= (u8
*) (hdr
+ 1);
904 if (in_len
> sizeof(*hdr
) && *pos
== EAP_TYPE_NAK
) {
905 left
= in_len
- sizeof(*hdr
);
906 wpa_hexdump(MSG_DEBUG
, "EAP-FAST: Phase2 type Nak'ed; "
907 "allowed types", pos
+ 1, left
- 1);
909 if (m
&& m
->vendor
== EAP_VENDOR_IETF
&&
910 m
->method
== EAP_TYPE_TNC
) {
911 wpa_printf(MSG_DEBUG
, "EAP-FAST: Peer Nak'ed required "
913 next_type
= eap_fast_req_failure(sm
, data
);
914 eap_fast_phase2_init(sm
, data
, next_type
);
918 eap_sm_process_nak(sm
, pos
+ 1, left
- 1);
919 if (sm
->user
&& sm
->user_eap_method_index
< EAP_MAX_METHODS
&&
920 sm
->user
->methods
[sm
->user_eap_method_index
].method
!=
922 next_type
= sm
->user
->methods
[
923 sm
->user_eap_method_index
++].method
;
924 wpa_printf(MSG_DEBUG
, "EAP-FAST: try EAP type %d",
927 next_type
= eap_fast_req_failure(sm
, data
);
929 eap_fast_phase2_init(sm
, data
, next_type
);
933 wpabuf_set(&buf
, in_data
, in_len
);
935 if (m
->check(sm
, priv
, &buf
)) {
936 wpa_printf(MSG_DEBUG
, "EAP-FAST: Phase2 check() asked to "
937 "ignore the packet");
938 next_type
= eap_fast_req_failure(sm
, data
);
942 m
->process(sm
, priv
, &buf
);
944 if (!m
->isDone(sm
, priv
))
947 if (!m
->isSuccess(sm
, priv
)) {
948 wpa_printf(MSG_DEBUG
, "EAP-FAST: Phase2 method failed");
949 next_type
= eap_fast_req_failure(sm
, data
);
950 eap_fast_phase2_init(sm
, data
, next_type
);
954 switch (data
->state
) {
956 if (eap_user_get(sm
, sm
->identity
, sm
->identity_len
, 1) != 0) {
957 wpa_hexdump_ascii(MSG_DEBUG
, "EAP-FAST: Phase2 "
958 "Identity not found in the user "
960 sm
->identity
, sm
->identity_len
);
961 next_type
= eap_fast_req_failure(sm
, data
);
965 eap_fast_state(data
, PHASE2_METHOD
);
966 if (data
->anon_provisioning
) {
968 * Only EAP-MSCHAPv2 is allowed for anonymous
971 next_type
= EAP_TYPE_MSCHAPV2
;
972 sm
->user_eap_method_index
= 0;
974 next_type
= sm
->user
->methods
[0].method
;
975 sm
->user_eap_method_index
= 1;
977 wpa_printf(MSG_DEBUG
, "EAP-FAST: try EAP type %d", next_type
);
981 eap_fast_update_icmk(sm
, data
);
982 eap_fast_state(data
, CRYPTO_BINDING
);
984 next_type
= EAP_TYPE_NONE
;
986 if (sm
->tnc
&& !data
->tnc_started
) {
987 wpa_printf(MSG_DEBUG
, "EAP-FAST: Initialize TNC");
988 next_type
= EAP_TYPE_TNC
;
989 data
->tnc_started
= 1;
996 wpa_printf(MSG_DEBUG
, "EAP-FAST: %s - unexpected state %d",
997 __func__
, data
->state
);
1001 eap_fast_phase2_init(sm
, data
, next_type
);
1005 static void eap_fast_process_phase2_eap(struct eap_sm
*sm
,
1006 struct eap_fast_data
*data
,
1007 u8
*in_data
, size_t in_len
)
1009 struct eap_hdr
*hdr
;
1012 hdr
= (struct eap_hdr
*) in_data
;
1013 if (in_len
< (int) sizeof(*hdr
)) {
1014 wpa_printf(MSG_INFO
, "EAP-FAST: Too short Phase 2 "
1015 "EAP frame (len=%d)", in_len
);
1016 eap_fast_req_failure(sm
, data
);
1019 len
= be_to_host16(hdr
->length
);
1021 wpa_printf(MSG_INFO
, "EAP-FAST: Length mismatch in "
1022 "Phase 2 EAP frame (len=%d hdr->length=%d)",
1024 eap_fast_req_failure(sm
, data
);
1027 wpa_printf(MSG_DEBUG
, "EAP-FAST: Received Phase 2: code=%d "
1028 "identifier=%d length=%d", hdr
->code
, hdr
->identifier
, len
);
1029 switch (hdr
->code
) {
1030 case EAP_CODE_RESPONSE
:
1031 eap_fast_process_phase2_response(sm
, data
, (u8
*) hdr
, len
);
1034 wpa_printf(MSG_INFO
, "EAP-FAST: Unexpected code=%d in "
1035 "Phase 2 EAP header", hdr
->code
);
1041 static int eap_fast_parse_tlvs(u8
*data
, size_t data_len
,
1042 struct eap_fast_tlv_parse
*tlv
)
1044 int mandatory
, tlv_type
, len
, res
;
1047 os_memset(tlv
, 0, sizeof(*tlv
));
1050 end
= data
+ data_len
;
1051 while (pos
+ 4 < end
) {
1052 mandatory
= pos
[0] & 0x80;
1053 tlv_type
= WPA_GET_BE16(pos
) & 0x3fff;
1055 len
= WPA_GET_BE16(pos
);
1057 if (pos
+ len
> end
) {
1058 wpa_printf(MSG_INFO
, "EAP-FAST: TLV overflow");
1061 wpa_printf(MSG_DEBUG
, "EAP-FAST: Received Phase 2: "
1062 "TLV type %d length %d%s",
1063 tlv_type
, len
, mandatory
? " (mandatory)" : "");
1065 res
= eap_fast_parse_tlv(tlv
, tlv_type
, pos
, len
);
1070 wpa_printf(MSG_DEBUG
, "EAP-FAST: Nak unknown "
1071 "mandatory TLV type %d", tlv_type
);
1072 /* TODO: generate Nak TLV */
1075 wpa_printf(MSG_DEBUG
, "EAP-FAST: Ignored "
1076 "unknown optional TLV type %d",
1088 static int eap_fast_validate_crypto_binding(
1089 struct eap_fast_data
*data
, struct eap_tlv_crypto_binding_tlv
*b
,
1092 u8 cmac
[SHA1_MAC_LEN
];
1094 wpa_printf(MSG_DEBUG
, "EAP-FAST: Reply Crypto-Binding TLV: "
1095 "Version %d Received Version %d SubType %d",
1096 b
->version
, b
->received_version
, b
->subtype
);
1097 wpa_hexdump(MSG_MSGDUMP
, "EAP-FAST: NONCE",
1098 b
->nonce
, sizeof(b
->nonce
));
1099 wpa_hexdump(MSG_MSGDUMP
, "EAP-FAST: Compound MAC",
1100 b
->compound_mac
, sizeof(b
->compound_mac
));
1102 if (b
->version
!= EAP_FAST_VERSION
||
1103 b
->received_version
!= EAP_FAST_VERSION
) {
1104 wpa_printf(MSG_DEBUG
, "EAP-FAST: Unexpected version "
1105 "in Crypto-Binding: version %d "
1106 "received_version %d", b
->version
,
1107 b
->received_version
);
1111 if (b
->subtype
!= EAP_TLV_CRYPTO_BINDING_SUBTYPE_RESPONSE
) {
1112 wpa_printf(MSG_DEBUG
, "EAP-FAST: Unexpected subtype in "
1113 "Crypto-Binding: %d", b
->subtype
);
1117 if (os_memcmp(data
->crypto_binding_nonce
, b
->nonce
, 31) != 0 ||
1118 (data
->crypto_binding_nonce
[31] | 1) != b
->nonce
[31]) {
1119 wpa_printf(MSG_DEBUG
, "EAP-FAST: Invalid nonce in "
1124 os_memcpy(cmac
, b
->compound_mac
, sizeof(cmac
));
1125 os_memset(b
->compound_mac
, 0, sizeof(cmac
));
1126 wpa_hexdump(MSG_MSGDUMP
, "EAP-FAST: Crypto-Binding TLV for "
1127 "Compound MAC calculation",
1128 (u8
*) b
, bind_len
);
1129 hmac_sha1(data
->cmk
, EAP_FAST_CMK_LEN
, (u8
*) b
, bind_len
,
1131 if (os_memcmp(cmac
, b
->compound_mac
, sizeof(cmac
)) != 0) {
1132 wpa_hexdump(MSG_MSGDUMP
,
1133 "EAP-FAST: Calculated Compound MAC",
1134 b
->compound_mac
, sizeof(cmac
));
1135 wpa_printf(MSG_INFO
, "EAP-FAST: Compound MAC did not "
1144 static int eap_fast_pac_type(u8
*pac
, size_t len
, u16 type
)
1146 struct eap_tlv_pac_type_tlv
*tlv
;
1148 if (pac
== NULL
|| len
!= sizeof(*tlv
))
1151 tlv
= (struct eap_tlv_pac_type_tlv
*) pac
;
1153 return be_to_host16(tlv
->tlv_type
) == PAC_TYPE_PAC_TYPE
&&
1154 be_to_host16(tlv
->length
) == 2 &&
1155 be_to_host16(tlv
->pac_type
) == type
;
1159 static void eap_fast_process_phase2_tlvs(struct eap_sm
*sm
,
1160 struct eap_fast_data
*data
,
1161 u8
*in_data
, size_t in_len
)
1163 struct eap_fast_tlv_parse tlv
;
1164 int check_crypto_binding
= data
->state
== CRYPTO_BINDING
;
1166 if (eap_fast_parse_tlvs(in_data
, in_len
, &tlv
) < 0) {
1167 wpa_printf(MSG_DEBUG
, "EAP-FAST: Failed to parse received "
1172 if (tlv
.result
== EAP_TLV_RESULT_FAILURE
) {
1173 wpa_printf(MSG_DEBUG
, "EAP-FAST: Result TLV indicated "
1175 eap_fast_state(data
, FAILURE
);
1179 if (data
->state
== REQUEST_PAC
) {
1181 if (tlv
.pac
== NULL
|| tlv
.pac_len
< 6) {
1182 wpa_printf(MSG_DEBUG
, "EAP-FAST: No PAC "
1183 "Acknowledgement received");
1184 eap_fast_state(data
, FAILURE
);
1188 type
= WPA_GET_BE16(tlv
.pac
);
1189 len
= WPA_GET_BE16(tlv
.pac
+ 2);
1190 res
= WPA_GET_BE16(tlv
.pac
+ 4);
1192 if (type
!= PAC_TYPE_PAC_ACKNOWLEDGEMENT
|| len
!= 2 ||
1193 res
!= EAP_TLV_RESULT_SUCCESS
) {
1194 wpa_printf(MSG_DEBUG
, "EAP-FAST: PAC TLV did not "
1195 "contain acknowledgement");
1196 eap_fast_state(data
, FAILURE
);
1200 wpa_printf(MSG_DEBUG
, "EAP-FAST: PAC-Acknowledgement received "
1201 "- PAC provisioning succeeded");
1202 eap_fast_state(data
, data
->anon_provisioning
?
1207 if (check_crypto_binding
) {
1208 if (tlv
.crypto_binding
== NULL
) {
1209 wpa_printf(MSG_DEBUG
, "EAP-FAST: No Crypto-Binding "
1211 eap_fast_state(data
, FAILURE
);
1215 if (data
->final_result
&&
1216 tlv
.result
!= EAP_TLV_RESULT_SUCCESS
) {
1217 wpa_printf(MSG_DEBUG
, "EAP-FAST: Crypto-Binding TLV "
1218 "without Success Result");
1219 eap_fast_state(data
, FAILURE
);
1223 if (!data
->final_result
&&
1224 tlv
.iresult
!= EAP_TLV_RESULT_SUCCESS
) {
1225 wpa_printf(MSG_DEBUG
, "EAP-FAST: Crypto-Binding TLV "
1226 "without intermediate Success Result");
1227 eap_fast_state(data
, FAILURE
);
1231 if (eap_fast_validate_crypto_binding(data
, tlv
.crypto_binding
,
1232 tlv
.crypto_binding_len
)) {
1233 eap_fast_state(data
, FAILURE
);
1237 wpa_printf(MSG_DEBUG
, "EAP-FAST: Valid Crypto-Binding TLV "
1239 if (data
->final_result
) {
1240 wpa_printf(MSG_DEBUG
, "EAP-FAST: Authentication "
1241 "completed successfully");
1244 if (data
->anon_provisioning
||
1245 (tlv
.request_action
== EAP_TLV_ACTION_PROCESS_TLV
&&
1246 eap_fast_pac_type(tlv
.pac
, tlv
.pac_len
,
1247 PAC_TYPE_TUNNEL_PAC
))) {
1248 wpa_printf(MSG_DEBUG
, "EAP-FAST: Requested a new "
1250 eap_fast_state(data
, REQUEST_PAC
);
1251 } else if (data
->send_new_pac
) {
1252 wpa_printf(MSG_DEBUG
, "EAP-FAST: Server triggered "
1253 "re-keying of Tunnel PAC");
1254 eap_fast_state(data
, REQUEST_PAC
);
1255 } else if (data
->final_result
)
1256 eap_fast_state(data
, SUCCESS
);
1259 if (tlv
.eap_payload_tlv
) {
1260 eap_fast_process_phase2_eap(sm
, data
, tlv
.eap_payload_tlv
,
1261 tlv
.eap_payload_tlv_len
);
1266 static void eap_fast_process_phase2(struct eap_sm
*sm
,
1267 struct eap_fast_data
*data
,
1268 struct wpabuf
*in_buf
)
1276 in_data
= wpabuf_mhead(in_buf
);
1277 in_len
= wpabuf_len(in_buf
);
1279 wpa_printf(MSG_DEBUG
, "EAP-FAST: Received %lu bytes encrypted data for"
1280 " Phase 2", (unsigned long) in_len
);
1282 if (data
->pending_phase2_resp
) {
1283 wpa_printf(MSG_DEBUG
, "EAP-PEAP: Pending Phase 2 response - "
1284 "skip decryption and use old data");
1285 eap_fast_process_phase2_tlvs(
1286 sm
, data
, wpabuf_mhead(data
->pending_phase2_resp
),
1287 wpabuf_len(data
->pending_phase2_resp
));
1288 wpabuf_free(data
->pending_phase2_resp
);
1289 data
->pending_phase2_resp
= NULL
;
1295 * Even though we try to disable TLS compression, it is possible that
1296 * this cannot be done with all TLS libraries. Add extra buffer space
1297 * to handle the possibility of the decrypted data being longer than
1302 in_decrypted
= os_malloc(buf_len
);
1303 if (in_decrypted
== NULL
) {
1304 wpa_printf(MSG_WARNING
, "EAP-FAST: Failed to allocate memory "
1309 len_decrypted
= tls_connection_decrypt(sm
->ssl_ctx
, data
->ssl
.conn
,
1311 in_decrypted
, buf_len
);
1312 if (len_decrypted
< 0) {
1313 wpa_printf(MSG_INFO
, "EAP-FAST: Failed to decrypt Phase 2 "
1315 os_free(in_decrypted
);
1316 eap_fast_state(data
, FAILURE
);
1320 wpa_hexdump_key(MSG_DEBUG
, "EAP-FAST: Decrypted Phase 2 TLVs",
1321 in_decrypted
, len_decrypted
);
1323 eap_fast_process_phase2_tlvs(sm
, data
, in_decrypted
, len_decrypted
);
1325 if (sm
->method_pending
== METHOD_PENDING_WAIT
) {
1326 wpa_printf(MSG_DEBUG
, "EAP-FAST: Phase2 method is in "
1327 "pending wait state - save decrypted response");
1328 wpabuf_free(data
->pending_phase2_resp
);
1329 data
->pending_phase2_resp
= wpabuf_alloc_copy(in_decrypted
,
1333 os_free(in_decrypted
);
1337 static int eap_fast_process_version(struct eap_sm
*sm
, void *priv
,
1340 struct eap_fast_data
*data
= priv
;
1342 data
->peer_version
= peer_version
;
1344 if (data
->force_version
>= 0 && peer_version
!= data
->force_version
) {
1345 wpa_printf(MSG_INFO
, "EAP-FAST: peer did not select the forced"
1346 " version (forced=%d peer=%d) - reject",
1347 data
->force_version
, peer_version
);
1351 if (peer_version
< data
->fast_version
) {
1352 wpa_printf(MSG_DEBUG
, "EAP-FAST: peer ver=%d, own ver=%d; "
1354 peer_version
, data
->fast_version
, peer_version
);
1355 data
->fast_version
= peer_version
;
1362 static int eap_fast_process_phase1(struct eap_sm
*sm
,
1363 struct eap_fast_data
*data
)
1365 if (eap_server_tls_phase1(sm
, &data
->ssl
) < 0) {
1366 wpa_printf(MSG_INFO
, "EAP-FAST: TLS processing failed");
1367 eap_fast_state(data
, FAILURE
);
1371 if (!tls_connection_established(sm
->ssl_ctx
, data
->ssl
.conn
) ||
1372 wpabuf_len(data
->ssl
.out_buf
) > 0)
1376 * Phase 1 was completed with the received message (e.g., when using
1377 * abbreviated handshake), so Phase 2 can be started immediately
1378 * without having to send through an empty message to the peer.
1381 return eap_fast_phase1_done(sm
, data
);
1385 static void eap_fast_process_phase2_start(struct eap_sm
*sm
,
1386 struct eap_fast_data
*data
)
1390 if (data
->identity
) {
1391 os_free(sm
->identity
);
1392 sm
->identity
= data
->identity
;
1393 data
->identity
= NULL
;
1394 sm
->identity_len
= data
->identity_len
;
1395 data
->identity_len
= 0;
1396 sm
->require_identity_match
= 1;
1397 if (eap_user_get(sm
, sm
->identity
, sm
->identity_len
, 1) != 0) {
1398 wpa_hexdump_ascii(MSG_DEBUG
, "EAP-FAST: "
1399 "Phase2 Identity not found "
1400 "in the user database",
1401 sm
->identity
, sm
->identity_len
);
1402 next_type
= eap_fast_req_failure(sm
, data
);
1404 wpa_printf(MSG_DEBUG
, "EAP-FAST: Identity already "
1405 "known - skip Phase 2 Identity Request");
1406 next_type
= sm
->user
->methods
[0].method
;
1407 sm
->user_eap_method_index
= 1;
1410 eap_fast_state(data
, PHASE2_METHOD
);
1412 eap_fast_state(data
, PHASE2_ID
);
1413 next_type
= EAP_TYPE_IDENTITY
;
1416 eap_fast_phase2_init(sm
, data
, next_type
);
1420 static void eap_fast_process_msg(struct eap_sm
*sm
, void *priv
,
1421 const struct wpabuf
*respData
)
1423 struct eap_fast_data
*data
= priv
;
1425 switch (data
->state
) {
1427 if (eap_fast_process_phase1(sm
, data
))
1430 /* fall through to PHASE2_START */
1432 eap_fast_process_phase2_start(sm
, data
);
1436 case CRYPTO_BINDING
:
1438 eap_fast_process_phase2(sm
, data
, data
->ssl
.in_buf
);
1441 wpa_printf(MSG_DEBUG
, "EAP-FAST: Unexpected state %d in %s",
1442 data
->state
, __func__
);
1448 static void eap_fast_process(struct eap_sm
*sm
, void *priv
,
1449 struct wpabuf
*respData
)
1451 struct eap_fast_data
*data
= priv
;
1452 if (eap_server_tls_process(sm
, &data
->ssl
, respData
, data
,
1453 EAP_TYPE_FAST
, eap_fast_process_version
,
1454 eap_fast_process_msg
) < 0)
1455 eap_fast_state(data
, FAILURE
);
1459 static Boolean
eap_fast_isDone(struct eap_sm
*sm
, void *priv
)
1461 struct eap_fast_data
*data
= priv
;
1462 return data
->state
== SUCCESS
|| data
->state
== FAILURE
;
1466 static u8
* eap_fast_getKey(struct eap_sm
*sm
, void *priv
, size_t *len
)
1468 struct eap_fast_data
*data
= priv
;
1471 if (data
->state
!= SUCCESS
)
1474 eapKeyData
= os_malloc(EAP_FAST_KEY_LEN
);
1475 if (eapKeyData
== NULL
)
1478 eap_fast_derive_eap_msk(data
->simck
, eapKeyData
);
1479 *len
= EAP_FAST_KEY_LEN
;
1485 static u8
* eap_fast_get_emsk(struct eap_sm
*sm
, void *priv
, size_t *len
)
1487 struct eap_fast_data
*data
= priv
;
1490 if (data
->state
!= SUCCESS
)
1493 eapKeyData
= os_malloc(EAP_EMSK_LEN
);
1494 if (eapKeyData
== NULL
)
1497 eap_fast_derive_eap_emsk(data
->simck
, eapKeyData
);
1498 *len
= EAP_EMSK_LEN
;
1504 static Boolean
eap_fast_isSuccess(struct eap_sm
*sm
, void *priv
)
1506 struct eap_fast_data
*data
= priv
;
1507 return data
->state
== SUCCESS
;
1511 int eap_server_fast_register(void)
1513 struct eap_method
*eap
;
1516 eap
= eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION
,
1517 EAP_VENDOR_IETF
, EAP_TYPE_FAST
, "FAST");
1521 eap
->init
= eap_fast_init
;
1522 eap
->reset
= eap_fast_reset
;
1523 eap
->buildReq
= eap_fast_buildReq
;
1524 eap
->check
= eap_fast_check
;
1525 eap
->process
= eap_fast_process
;
1526 eap
->isDone
= eap_fast_isDone
;
1527 eap
->getKey
= eap_fast_getKey
;
1528 eap
->get_emsk
= eap_fast_get_emsk
;
1529 eap
->isSuccess
= eap_fast_isSuccess
;
1531 ret
= eap_server_method_register(eap
);
1533 eap_server_method_free(eap
);