2 * EAP peer method: EAP-FAST (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.
19 #include "eap_tls_common.h"
20 #include "eap_config.h"
22 #include "eap_common/eap_tlv_common.h"
24 #include "eap_fast_pac.h"
26 #ifdef EAP_FAST_DYNAMIC
27 #include "eap_fast_pac.c"
28 #endif /* EAP_FAST_DYNAMIC */
31 * - test session resumption and enable it if it interoperates
32 * - password change (pending mschapv2 packet; replay decrypted packet)
36 static void eap_fast_deinit(struct eap_sm *sm, void *priv);
39 struct eap_fast_data {
40 struct eap_ssl_data ssl;
44 const struct eap_method *phase2_method;
48 struct eap_method_type phase2_type;
49 struct eap_method_type *phase2_types;
50 size_t num_phase2_types;
51 int resuming; /* starting a resumed session */
52 struct eap_fast_key_block_provisioning *key_block_p;
53 #define EAP_FAST_PROV_UNAUTH 1
54 #define EAP_FAST_PROV_AUTH 2
55 int provisioning_allowed; /* Allowed PAC provisioning modes */
56 int provisioning; /* doing PAC provisioning (not the normal auth) */
57 int anon_provisioning; /* doing anonymous (unauthenticated)
59 int session_ticket_used;
61 u8 key_data[EAP_FAST_KEY_LEN];
62 u8 emsk[EAP_EMSK_LEN];
65 struct eap_fast_pac *pac;
66 struct eap_fast_pac *current_pac;
67 size_t max_pac_list_len;
68 int use_pac_binary_format;
70 u8 simck[EAP_FAST_SIMCK_LEN];
73 struct wpabuf *pending_phase2_req;
77 static int eap_fast_session_ticket_cb(void *ctx, const u8 *ticket, size_t len,
78 const u8 *client_random,
79 const u8 *server_random,
82 struct eap_fast_data *data = ctx;
84 wpa_printf(MSG_DEBUG, "EAP-FAST: SessionTicket callback");
86 if (client_random == NULL || server_random == NULL ||
87 master_secret == NULL) {
88 wpa_printf(MSG_DEBUG, "EAP-FAST: SessionTicket failed - fall "
89 "back to full TLS handshake");
90 data->session_ticket_used = 0;
91 if (data->provisioning_allowed) {
92 wpa_printf(MSG_DEBUG, "EAP-FAST: Try to provision a "
94 data->provisioning = 1;
95 data->current_pac = NULL;
100 wpa_hexdump(MSG_DEBUG, "EAP-FAST: SessionTicket", ticket, len);
102 if (data->current_pac == NULL) {
103 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC-Key available for "
104 "using SessionTicket");
105 data->session_ticket_used = 0;
109 eap_fast_derive_master_secret(data->current_pac->pac_key,
110 server_random, client_random,
113 data->session_ticket_used = 1;
119 static int eap_fast_parse_phase1(struct eap_fast_data *data,
124 pos = os_strstr(phase1, "fast_provisioning=");
126 data->provisioning_allowed = atoi(pos + 18);
127 wpa_printf(MSG_DEBUG, "EAP-FAST: Automatic PAC provisioning "
128 "mode: %d", data->provisioning_allowed);
131 pos = os_strstr(phase1, "fast_max_pac_list_len=");
133 data->max_pac_list_len = atoi(pos + 22);
134 if (data->max_pac_list_len == 0)
135 data->max_pac_list_len = 1;
136 wpa_printf(MSG_DEBUG, "EAP-FAST: Maximum PAC list length: %lu",
137 (unsigned long) data->max_pac_list_len);
140 pos = os_strstr(phase1, "fast_pac_format=binary");
142 data->use_pac_binary_format = 1;
143 wpa_printf(MSG_DEBUG, "EAP-FAST: Using binary format for PAC "
151 static void * eap_fast_init(struct eap_sm *sm)
153 struct eap_fast_data *data;
154 struct eap_peer_config *config = eap_get_config(sm);
156 data = os_zalloc(sizeof(*data));
159 data->fast_version = EAP_FAST_VERSION;
160 data->max_pac_list_len = 10;
162 if (config && config->phase1 &&
163 eap_fast_parse_phase1(data, config->phase1) < 0) {
164 eap_fast_deinit(sm, data);
168 if (eap_peer_select_phase2_methods(config, "auth=",
170 &data->num_phase2_types) < 0) {
171 eap_fast_deinit(sm, data);
175 data->phase2_type.vendor = EAP_VENDOR_IETF;
176 data->phase2_type.method = EAP_TYPE_NONE;
178 if (eap_peer_tls_ssl_init(sm, &data->ssl, config)) {
179 wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize SSL.");
180 eap_fast_deinit(sm, data);
184 if (tls_connection_set_session_ticket_cb(sm->ssl_ctx, data->ssl.conn,
185 eap_fast_session_ticket_cb,
187 wpa_printf(MSG_INFO, "EAP-FAST: Failed to set SessionTicket "
189 eap_fast_deinit(sm, data);
194 * The local RADIUS server in a Cisco AP does not seem to like empty
195 * fragments before data, so disable that workaround for CBC.
196 * TODO: consider making this configurable
198 if (tls_connection_enable_workaround(sm->ssl_ctx, data->ssl.conn)) {
199 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to enable TLS "
203 if (data->use_pac_binary_format &&
204 eap_fast_load_pac_bin(sm, &data->pac, config->pac_file) < 0) {
205 eap_fast_deinit(sm, data);
209 if (!data->use_pac_binary_format &&
210 eap_fast_load_pac(sm, &data->pac, config->pac_file) < 0) {
211 eap_fast_deinit(sm, data);
214 eap_fast_pac_list_truncate(data->pac, data->max_pac_list_len);
216 if (data->pac == NULL && !data->provisioning_allowed) {
217 wpa_printf(MSG_INFO, "EAP-FAST: No PAC configured and "
218 "provisioning disabled");
219 eap_fast_deinit(sm, data);
227 static void eap_fast_deinit(struct eap_sm *sm, void *priv)
229 struct eap_fast_data *data = priv;
230 struct eap_fast_pac *pac, *prev;
234 if (data->phase2_priv && data->phase2_method)
235 data->phase2_method->deinit(sm, data->phase2_priv);
236 os_free(data->phase2_types);
237 os_free(data->key_block_p);
238 eap_peer_tls_ssl_deinit(sm, &data->ssl);
245 eap_fast_free_pac(prev);
247 wpabuf_free(data->pending_phase2_req);
252 static int eap_fast_derive_msk(struct eap_fast_data *data)
254 eap_fast_derive_eap_msk(data->simck, data->key_data);
255 eap_fast_derive_eap_emsk(data->simck, data->emsk);
261 static void eap_fast_derive_key_auth(struct eap_sm *sm,
262 struct eap_fast_data *data)
266 /* RFC 4851, Section 5.1:
267 * Extra key material after TLS key_block: session_key_seed[40]
270 sks = eap_fast_derive_key(sm->ssl_ctx, data->ssl.conn, "key expansion",
273 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive "
279 * RFC 4851, Section 5.2:
280 * S-IMCK[0] = session_key_seed
282 wpa_hexdump_key(MSG_DEBUG,
283 "EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
284 sks, EAP_FAST_SKS_LEN);
286 os_memcpy(data->simck, sks, EAP_FAST_SIMCK_LEN);
291 static void eap_fast_derive_key_provisioning(struct eap_sm *sm,
292 struct eap_fast_data *data)
294 os_free(data->key_block_p);
295 data->key_block_p = (struct eap_fast_key_block_provisioning *)
296 eap_fast_derive_key(sm->ssl_ctx, data->ssl.conn,
298 sizeof(*data->key_block_p));
299 if (data->key_block_p == NULL) {
300 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive key block");
304 * RFC 4851, Section 5.2:
305 * S-IMCK[0] = session_key_seed
307 wpa_hexdump_key(MSG_DEBUG,
308 "EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
309 data->key_block_p->session_key_seed,
310 sizeof(data->key_block_p->session_key_seed));
312 os_memcpy(data->simck, data->key_block_p->session_key_seed,
314 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: server_challenge",
315 data->key_block_p->server_challenge,
316 sizeof(data->key_block_p->server_challenge));
317 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: client_challenge",
318 data->key_block_p->client_challenge,
319 sizeof(data->key_block_p->client_challenge));
323 static void eap_fast_derive_keys(struct eap_sm *sm, struct eap_fast_data *data)
325 if (data->anon_provisioning)
326 eap_fast_derive_key_provisioning(sm, data);
328 eap_fast_derive_key_auth(sm, data);
332 static int eap_fast_init_phase2_method(struct eap_sm *sm,
333 struct eap_fast_data *data)
335 data->phase2_method =
336 eap_peer_get_eap_method(data->phase2_type.vendor,
337 data->phase2_type.method);
338 if (data->phase2_method == NULL)
341 if (data->key_block_p) {
342 sm->auth_challenge = data->key_block_p->server_challenge;
343 sm->peer_challenge = data->key_block_p->client_challenge;
346 data->phase2_priv = data->phase2_method->init(sm);
348 sm->auth_challenge = NULL;
349 sm->peer_challenge = NULL;
351 return data->phase2_priv == NULL ? -1 : 0;
355 static int eap_fast_select_phase2_method(struct eap_fast_data *data, u8 type)
359 /* TODO: TNC with anonymous provisioning; need to require both
360 * completed MSCHAPv2 and TNC */
362 if (data->anon_provisioning && type != EAP_TYPE_MSCHAPV2) {
363 wpa_printf(MSG_INFO, "EAP-FAST: Only EAP-MSCHAPv2 is allowed "
364 "during unauthenticated provisioning; reject phase2"
370 if (type == EAP_TYPE_TNC) {
371 data->phase2_type.vendor = EAP_VENDOR_IETF;
372 data->phase2_type.method = EAP_TYPE_TNC;
373 wpa_printf(MSG_DEBUG, "EAP-FAST: Selected Phase 2 EAP "
374 "vendor %d method %d for TNC",
375 data->phase2_type.vendor,
376 data->phase2_type.method);
381 for (i = 0; i < data->num_phase2_types; i++) {
382 if (data->phase2_types[i].vendor != EAP_VENDOR_IETF ||
383 data->phase2_types[i].method != type)
386 data->phase2_type.vendor = data->phase2_types[i].vendor;
387 data->phase2_type.method = data->phase2_types[i].method;
388 wpa_printf(MSG_DEBUG, "EAP-FAST: Selected Phase 2 EAP "
389 "vendor %d method %d",
390 data->phase2_type.vendor,
391 data->phase2_type.method);
395 if (type != data->phase2_type.method || type == EAP_TYPE_NONE)
402 static int eap_fast_phase2_request(struct eap_sm *sm,
403 struct eap_fast_data *data,
404 struct eap_method_ret *ret,
406 struct wpabuf **resp)
408 size_t len = be_to_host16(hdr->length);
410 struct eap_method_ret iret;
411 struct eap_peer_config *config = eap_get_config(sm);
414 if (len <= sizeof(struct eap_hdr)) {
415 wpa_printf(MSG_INFO, "EAP-FAST: too short "
416 "Phase 2 request (len=%lu)", (unsigned long) len);
419 pos = (u8 *) (hdr + 1);
420 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 Request: type=%d", *pos);
421 if (*pos == EAP_TYPE_IDENTITY) {
422 *resp = eap_sm_buildIdentity(sm, hdr->identifier, 1);
426 if (data->phase2_priv && data->phase2_method &&
427 *pos != data->phase2_type.method) {
428 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 EAP sequence - "
429 "deinitialize previous method");
430 data->phase2_method->deinit(sm, data->phase2_priv);
431 data->phase2_method = NULL;
432 data->phase2_priv = NULL;
433 data->phase2_type.vendor = EAP_VENDOR_IETF;
434 data->phase2_type.method = EAP_TYPE_NONE;
437 if (data->phase2_type.vendor == EAP_VENDOR_IETF &&
438 data->phase2_type.method == EAP_TYPE_NONE &&
439 eap_fast_select_phase2_method(data, *pos) < 0) {
440 if (eap_peer_tls_phase2_nak(data->phase2_types,
441 data->num_phase2_types,
447 if (data->phase2_priv == NULL &&
448 eap_fast_init_phase2_method(sm, data) < 0) {
449 wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize "
450 "Phase 2 EAP method %d", *pos);
451 ret->methodState = METHOD_DONE;
452 ret->decision = DECISION_FAIL;
456 os_memset(&iret, 0, sizeof(iret));
457 wpabuf_set(&msg, hdr, len);
458 *resp = data->phase2_method->process(sm, data->phase2_priv, &iret,
461 (iret.methodState == METHOD_DONE &&
462 iret.decision == DECISION_FAIL)) {
463 ret->methodState = METHOD_DONE;
464 ret->decision = DECISION_FAIL;
465 } else if ((iret.methodState == METHOD_DONE ||
466 iret.methodState == METHOD_MAY_CONT) &&
467 (iret.decision == DECISION_UNCOND_SUCC ||
468 iret.decision == DECISION_COND_SUCC)) {
469 data->phase2_success = 1;
472 if (*resp == NULL && config &&
473 (config->pending_req_identity || config->pending_req_password ||
474 config->pending_req_otp || config->pending_req_new_password)) {
475 wpabuf_free(data->pending_phase2_req);
476 data->pending_phase2_req = wpabuf_alloc_copy(hdr, len);
477 } else if (*resp == NULL)
484 static struct wpabuf * eap_fast_tlv_nak(int vendor_id, int tlv_type)
487 struct eap_tlv_nak_tlv *nak;
488 buf = wpabuf_alloc(sizeof(*nak));
491 nak = wpabuf_put(buf, sizeof(*nak));
492 nak->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY | EAP_TLV_NAK_TLV);
493 nak->length = host_to_be16(6);
494 nak->vendor_id = host_to_be32(vendor_id);
495 nak->nak_type = host_to_be16(tlv_type);
500 static struct wpabuf * eap_fast_tlv_result(int status, int intermediate)
503 struct eap_tlv_intermediate_result_tlv *result;
504 buf = wpabuf_alloc(sizeof(*result));
507 wpa_printf(MSG_DEBUG, "EAP-FAST: Add %sResult TLV(status=%d)",
508 intermediate ? "Intermediate " : "", status);
509 result = wpabuf_put(buf, sizeof(*result));
510 result->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
512 EAP_TLV_INTERMEDIATE_RESULT_TLV :
513 EAP_TLV_RESULT_TLV));
514 result->length = host_to_be16(2);
515 result->status = host_to_be16(status);
520 static struct wpabuf * eap_fast_tlv_pac_ack(void)
523 struct eap_tlv_result_tlv *res;
524 struct eap_tlv_pac_ack_tlv *ack;
526 buf = wpabuf_alloc(sizeof(*res) + sizeof(*ack));
530 wpa_printf(MSG_DEBUG, "EAP-FAST: Add PAC TLV (ack)");
531 ack = wpabuf_put(buf, sizeof(*ack));
532 ack->tlv_type = host_to_be16(EAP_TLV_PAC_TLV |
533 EAP_TLV_TYPE_MANDATORY);
534 ack->length = host_to_be16(sizeof(*ack) - sizeof(struct eap_tlv_hdr));
535 ack->pac_type = host_to_be16(PAC_TYPE_PAC_ACKNOWLEDGEMENT);
536 ack->pac_len = host_to_be16(2);
537 ack->result = host_to_be16(EAP_TLV_RESULT_SUCCESS);
543 static struct wpabuf * eap_fast_process_eap_payload_tlv(
544 struct eap_sm *sm, struct eap_fast_data *data,
545 struct eap_method_ret *ret, const struct eap_hdr *req,
546 u8 *eap_payload_tlv, size_t eap_payload_tlv_len)
549 struct wpabuf *resp = NULL;
551 if (eap_payload_tlv_len < sizeof(*hdr)) {
552 wpa_printf(MSG_DEBUG, "EAP-FAST: too short EAP "
553 "Payload TLV (len=%lu)",
554 (unsigned long) eap_payload_tlv_len);
558 hdr = (struct eap_hdr *) eap_payload_tlv;
559 if (be_to_host16(hdr->length) > eap_payload_tlv_len) {
560 wpa_printf(MSG_DEBUG, "EAP-FAST: EAP packet overflow in "
565 if (hdr->code != EAP_CODE_REQUEST) {
566 wpa_printf(MSG_INFO, "EAP-FAST: Unexpected code=%d in "
567 "Phase 2 EAP header", hdr->code);
571 if (eap_fast_phase2_request(sm, data, ret, hdr, &resp)) {
572 wpa_printf(MSG_INFO, "EAP-FAST: Phase2 Request processing "
577 return eap_fast_tlv_eap_payload(resp);
581 static int eap_fast_validate_crypto_binding(
582 struct eap_tlv_crypto_binding_tlv *_bind)
584 wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV: Version %d "
585 "Received Version %d SubType %d",
586 _bind->version, _bind->received_version, _bind->subtype);
587 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
588 _bind->nonce, sizeof(_bind->nonce));
589 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
590 _bind->compound_mac, sizeof(_bind->compound_mac));
592 if (_bind->version != EAP_FAST_VERSION ||
593 _bind->received_version != EAP_FAST_VERSION ||
594 _bind->subtype != EAP_TLV_CRYPTO_BINDING_SUBTYPE_REQUEST) {
595 wpa_printf(MSG_INFO, "EAP-FAST: Invalid version/subtype in "
596 "Crypto-Binding TLV: Version %d "
597 "Received Version %d SubType %d",
598 _bind->version, _bind->received_version,
607 static void eap_fast_write_crypto_binding(
608 struct eap_tlv_crypto_binding_tlv *rbind,
609 struct eap_tlv_crypto_binding_tlv *_bind, const u8 *cmk)
611 rbind->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
612 EAP_TLV_CRYPTO_BINDING_TLV);
613 rbind->length = host_to_be16(sizeof(*rbind) -
614 sizeof(struct eap_tlv_hdr));
615 rbind->version = EAP_FAST_VERSION;
616 rbind->received_version = _bind->version;
617 rbind->subtype = EAP_TLV_CRYPTO_BINDING_SUBTYPE_RESPONSE;
618 os_memcpy(rbind->nonce, _bind->nonce, sizeof(_bind->nonce));
619 inc_byte_array(rbind->nonce, sizeof(rbind->nonce));
620 hmac_sha1(cmk, EAP_FAST_CMK_LEN, (u8 *) rbind, sizeof(*rbind),
621 rbind->compound_mac);
623 wpa_printf(MSG_DEBUG, "EAP-FAST: Reply Crypto-Binding TLV: Version %d "
624 "Received Version %d SubType %d",
625 rbind->version, rbind->received_version, rbind->subtype);
626 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
627 rbind->nonce, sizeof(rbind->nonce));
628 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
629 rbind->compound_mac, sizeof(rbind->compound_mac));
633 static int eap_fast_get_phase2_key(struct eap_sm *sm,
634 struct eap_fast_data *data,
635 u8 *isk, size_t isk_len)
640 os_memset(isk, 0, isk_len);
642 if (data->phase2_method == NULL || data->phase2_priv == NULL) {
643 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not "
648 if (data->phase2_method->isKeyAvailable == NULL ||
649 data->phase2_method->getKey == NULL)
652 if (!data->phase2_method->isKeyAvailable(sm, data->phase2_priv) ||
653 (key = data->phase2_method->getKey(sm, data->phase2_priv,
654 &key_len)) == NULL) {
655 wpa_printf(MSG_DEBUG, "EAP-FAST: Could not get key material "
660 if (key_len > isk_len)
663 data->phase2_method->vendor == EAP_VENDOR_IETF &&
664 data->phase2_method->method == EAP_TYPE_MSCHAPV2) {
666 * EAP-FAST uses reverse order for MS-MPPE keys when deriving
667 * MSK from EAP-MSCHAPv2. Swap the keys here to get the correct
668 * ISK for EAP-FAST cryptobinding.
670 os_memcpy(isk, key + 16, 16);
671 os_memcpy(isk + 16, key, 16);
673 os_memcpy(isk, key, key_len);
680 static int eap_fast_get_cmk(struct eap_sm *sm, struct eap_fast_data *data,
683 u8 isk[32], imck[60];
685 wpa_printf(MSG_DEBUG, "EAP-FAST: Determining CMK[%d] for Compound MIC "
686 "calculation", data->simck_idx + 1);
689 * RFC 4851, Section 5.2:
690 * IMCK[j] = T-PRF(S-IMCK[j-1], "Inner Methods Compound Keys",
692 * S-IMCK[j] = first 40 octets of IMCK[j]
693 * CMK[j] = last 20 octets of IMCK[j]
696 if (eap_fast_get_phase2_key(sm, data, isk, sizeof(isk)) < 0)
698 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: ISK[j]", isk, sizeof(isk));
699 sha1_t_prf(data->simck, EAP_FAST_SIMCK_LEN,
700 "Inner Methods Compound Keys",
701 isk, sizeof(isk), imck, sizeof(imck));
703 os_memcpy(data->simck, imck, EAP_FAST_SIMCK_LEN);
704 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: S-IMCK[j]",
705 data->simck, EAP_FAST_SIMCK_LEN);
706 os_memcpy(cmk, imck + EAP_FAST_SIMCK_LEN, EAP_FAST_CMK_LEN);
707 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: CMK[j]",
708 cmk, EAP_FAST_CMK_LEN);
714 static u8 * eap_fast_write_pac_request(u8 *pos, u16 pac_type)
716 struct eap_tlv_hdr *pac;
717 struct eap_tlv_request_action_tlv *act;
718 struct eap_tlv_pac_type_tlv *type;
720 act = (struct eap_tlv_request_action_tlv *) pos;
721 act->tlv_type = host_to_be16(EAP_TLV_REQUEST_ACTION_TLV);
722 act->length = host_to_be16(2);
723 act->action = host_to_be16(EAP_TLV_ACTION_PROCESS_TLV);
725 pac = (struct eap_tlv_hdr *) (act + 1);
726 pac->tlv_type = host_to_be16(EAP_TLV_PAC_TLV);
727 pac->length = host_to_be16(sizeof(*type));
729 type = (struct eap_tlv_pac_type_tlv *) (pac + 1);
730 type->tlv_type = host_to_be16(PAC_TYPE_PAC_TYPE);
731 type->length = host_to_be16(2);
732 type->pac_type = host_to_be16(pac_type);
734 return (u8 *) (type + 1);
738 static struct wpabuf * eap_fast_process_crypto_binding(
739 struct eap_sm *sm, struct eap_fast_data *data,
740 struct eap_method_ret *ret,
741 struct eap_tlv_crypto_binding_tlv *_bind, size_t bind_len)
745 u8 cmk[EAP_FAST_CMK_LEN], cmac[SHA1_MAC_LEN];
749 if (eap_fast_validate_crypto_binding(_bind) < 0)
752 if (eap_fast_get_cmk(sm, data, cmk) < 0)
755 /* Validate received Compound MAC */
756 os_memcpy(cmac, _bind->compound_mac, sizeof(cmac));
757 os_memset(_bind->compound_mac, 0, sizeof(cmac));
758 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Crypto-Binding TLV for Compound "
759 "MAC calculation", (u8 *) _bind, bind_len);
760 hmac_sha1(cmk, EAP_FAST_CMK_LEN, (u8 *) _bind, bind_len,
761 _bind->compound_mac);
762 res = os_memcmp(cmac, _bind->compound_mac, sizeof(cmac));
763 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Received Compound MAC",
765 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Calculated Compound MAC",
766 _bind->compound_mac, sizeof(cmac));
768 wpa_printf(MSG_INFO, "EAP-FAST: Compound MAC did not match");
769 os_memcpy(_bind->compound_mac, cmac, sizeof(cmac));
774 * Compound MAC was valid, so authentication succeeded. Reply with
775 * crypto binding to allow server to complete authentication.
778 len = sizeof(struct eap_tlv_crypto_binding_tlv);
779 resp = wpabuf_alloc(len);
783 if (!data->anon_provisioning && data->phase2_success &&
784 eap_fast_derive_msk(data) < 0) {
785 wpa_printf(MSG_INFO, "EAP-FAST: Failed to generate MSK");
786 ret->methodState = METHOD_DONE;
787 ret->decision = DECISION_FAIL;
788 data->phase2_success = 0;
793 pos = wpabuf_put(resp, sizeof(struct eap_tlv_crypto_binding_tlv));
794 eap_fast_write_crypto_binding((struct eap_tlv_crypto_binding_tlv *)
801 static void eap_fast_parse_pac_tlv(struct eap_fast_pac *entry, int type,
802 u8 *pos, size_t len, int *pac_key_found)
804 switch (type & 0x7fff) {
805 case PAC_TYPE_PAC_KEY:
806 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: PAC-Key", pos, len);
807 if (len != EAP_FAST_PAC_KEY_LEN) {
808 wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid PAC-Key "
809 "length %lu", (unsigned long) len);
813 os_memcpy(entry->pac_key, pos, len);
815 case PAC_TYPE_PAC_OPAQUE:
816 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Opaque", pos, len);
817 entry->pac_opaque = pos;
818 entry->pac_opaque_len = len;
820 case PAC_TYPE_PAC_INFO:
821 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Info", pos, len);
822 entry->pac_info = pos;
823 entry->pac_info_len = len;
826 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored unknown PAC type %d",
833 static int eap_fast_process_pac_tlv(struct eap_fast_pac *entry,
834 u8 *pac, size_t pac_len)
836 struct pac_tlv_hdr *hdr;
839 int type, pac_key_found = 0;
844 while (left > sizeof(*hdr)) {
845 hdr = (struct pac_tlv_hdr *) pos;
846 type = be_to_host16(hdr->type);
847 len = be_to_host16(hdr->len);
849 left -= sizeof(*hdr);
851 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV overrun "
852 "(type=%d len=%lu left=%lu)",
853 type, (unsigned long) len,
854 (unsigned long) left);
858 eap_fast_parse_pac_tlv(entry, type, pos, len, &pac_key_found);
864 if (!pac_key_found || !entry->pac_opaque || !entry->pac_info) {
865 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV does not include "
866 "all the required fields");
874 static int eap_fast_parse_pac_info(struct eap_fast_pac *entry, int type,
881 switch (type & 0x7fff) {
882 case PAC_TYPE_CRED_LIFETIME:
884 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Info - "
885 "Invalid CRED_LIFETIME length - ignored",
891 * This is not currently saved separately in PAC files since
892 * the server can automatically initiate PAC update when
893 * needed. Anyway, the information is available from PAC-Info
894 * dump if it is needed for something in the future.
896 lifetime = WPA_GET_BE32(pos);
898 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info - CRED_LIFETIME %d "
900 lifetime, (lifetime - (u32) now.sec) / 86400);
903 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - A-ID",
906 entry->a_id_len = len;
909 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - I-ID",
912 entry->i_id_len = len;
914 case PAC_TYPE_A_ID_INFO:
915 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - A-ID-Info",
917 entry->a_id_info = pos;
918 entry->a_id_info_len = len;
920 case PAC_TYPE_PAC_TYPE:
922 * draft-cam-winget-eap-fast-provisioning-04.txt,
923 * Section 4.2.6 - PAC-Type TLV
926 wpa_printf(MSG_INFO, "EAP-FAST: Invalid PAC-Type "
927 "length %lu (expected 2)",
928 (unsigned long) len);
929 wpa_hexdump_ascii(MSG_DEBUG,
930 "EAP-FAST: PAC-Info - PAC-Type",
934 pac_type = WPA_GET_BE16(pos);
935 if (pac_type != PAC_TYPE_TUNNEL_PAC &&
936 pac_type != PAC_TYPE_USER_AUTHORIZATION &&
937 pac_type != PAC_TYPE_MACHINE_AUTHENTICATION) {
938 wpa_printf(MSG_INFO, "EAP-FAST: Unsupported PAC Type "
943 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info - PAC-Type %d",
945 entry->pac_type = pac_type;
948 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored unknown PAC-Info "
957 static int eap_fast_process_pac_info(struct eap_fast_pac *entry)
959 struct pac_tlv_hdr *hdr;
964 /* draft-cam-winget-eap-fast-provisioning-04.txt, Section 4.2.4 */
966 /* PAC-Type defaults to Tunnel PAC (Type 1) */
967 entry->pac_type = PAC_TYPE_TUNNEL_PAC;
969 pos = entry->pac_info;
970 left = entry->pac_info_len;
971 while (left > sizeof(*hdr)) {
972 hdr = (struct pac_tlv_hdr *) pos;
973 type = be_to_host16(hdr->type);
974 len = be_to_host16(hdr->len);
976 left -= sizeof(*hdr);
978 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info overrun "
979 "(type=%d len=%lu left=%lu)",
980 type, (unsigned long) len,
981 (unsigned long) left);
985 if (eap_fast_parse_pac_info(entry, type, pos, len) < 0)
992 if (entry->a_id == NULL || entry->a_id_info == NULL) {
993 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info does not include "
994 "all the required fields");
1002 static struct wpabuf * eap_fast_process_pac(struct eap_sm *sm,
1003 struct eap_fast_data *data,
1004 struct eap_method_ret *ret,
1005 u8 *pac, size_t pac_len)
1007 struct eap_peer_config *config = eap_get_config(sm);
1008 struct eap_fast_pac entry;
1010 os_memset(&entry, 0, sizeof(entry));
1011 if (eap_fast_process_pac_tlv(&entry, pac, pac_len) ||
1012 eap_fast_process_pac_info(&entry))
1015 eap_fast_add_pac(&data->pac, &data->current_pac, &entry);
1016 eap_fast_pac_list_truncate(data->pac, data->max_pac_list_len);
1017 if (data->use_pac_binary_format)
1018 eap_fast_save_pac_bin(sm, data->pac, config->pac_file);
1020 eap_fast_save_pac(sm, data->pac, config->pac_file);
1022 if (data->provisioning) {
1023 if (data->anon_provisioning) {
1025 * Unauthenticated provisioning does not provide keying
1026 * material and must end with an EAP-Failure.
1027 * Authentication will be done separately after this.
1030 ret->decision = DECISION_FAIL;
1033 * Server may or may not allow authenticated
1034 * provisioning also for key generation.
1036 ret->decision = DECISION_COND_SUCC;
1038 wpa_printf(MSG_DEBUG, "EAP-FAST: Send PAC-Acknowledgement TLV "
1039 "- Provisioning completed successfully");
1042 * This is PAC refreshing, i.e., normal authentication that is
1043 * expected to be completed with an EAP-Success.
1045 wpa_printf(MSG_DEBUG, "EAP-FAST: Send PAC-Acknowledgement TLV "
1046 "- PAC refreshing completed successfully");
1047 ret->decision = DECISION_UNCOND_SUCC;
1049 ret->methodState = METHOD_DONE;
1050 return eap_fast_tlv_pac_ack();
1054 static int eap_fast_parse_decrypted(struct wpabuf *decrypted,
1055 struct eap_fast_tlv_parse *tlv,
1056 struct wpabuf **resp)
1058 int mandatory, tlv_type, len, res;
1061 os_memset(tlv, 0, sizeof(*tlv));
1063 /* Parse TLVs from the decrypted Phase 2 data */
1064 pos = wpabuf_mhead(decrypted);
1065 end = pos + wpabuf_len(decrypted);
1066 while (pos + 4 < end) {
1067 mandatory = pos[0] & 0x80;
1068 tlv_type = WPA_GET_BE16(pos) & 0x3fff;
1070 len = WPA_GET_BE16(pos);
1072 if (pos + len > end) {
1073 wpa_printf(MSG_INFO, "EAP-FAST: TLV overflow");
1076 wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: "
1077 "TLV type %d length %d%s",
1078 tlv_type, len, mandatory ? " (mandatory)" : "");
1080 res = eap_fast_parse_tlv(tlv, tlv_type, pos, len);
1085 wpa_printf(MSG_DEBUG, "EAP-FAST: Nak unknown "
1086 "mandatory TLV type %d", tlv_type);
1087 *resp = eap_fast_tlv_nak(0, tlv_type);
1090 wpa_printf(MSG_DEBUG, "EAP-FAST: ignored "
1091 "unknown optional TLV type %d",
1103 static int eap_fast_encrypt_response(struct eap_sm *sm,
1104 struct eap_fast_data *data,
1105 struct wpabuf *resp,
1106 u8 identifier, struct wpabuf **out_data)
1111 wpa_hexdump_buf(MSG_DEBUG, "EAP-FAST: Encrypting Phase 2 data",
1113 if (eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_FAST,
1114 data->fast_version, identifier,
1116 wpa_printf(MSG_INFO, "EAP-FAST: Failed to encrypt a Phase 2 "
1125 static struct wpabuf * eap_fast_pac_request(void)
1130 tmp = wpabuf_alloc(sizeof(struct eap_tlv_hdr) +
1131 sizeof(struct eap_tlv_request_action_tlv) +
1132 sizeof(struct eap_tlv_pac_type_tlv));
1136 pos = wpabuf_put(tmp, 0);
1137 pos2 = eap_fast_write_pac_request(pos, PAC_TYPE_TUNNEL_PAC);
1138 wpabuf_put(tmp, pos2 - pos);
1143 static int eap_fast_process_decrypted(struct eap_sm *sm,
1144 struct eap_fast_data *data,
1145 struct eap_method_ret *ret,
1146 const struct eap_hdr *req,
1147 struct wpabuf *decrypted,
1148 struct wpabuf **out_data)
1150 struct wpabuf *resp = NULL, *tmp;
1151 struct eap_fast_tlv_parse tlv;
1154 if (eap_fast_parse_decrypted(decrypted, &tlv, &resp) < 0)
1157 return eap_fast_encrypt_response(sm, data, resp,
1158 req->identifier, out_data);
1160 if (tlv.result == EAP_TLV_RESULT_FAILURE) {
1161 resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0);
1162 return eap_fast_encrypt_response(sm, data, resp,
1163 req->identifier, out_data);
1166 if (tlv.iresult == EAP_TLV_RESULT_FAILURE) {
1167 resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 1);
1168 return eap_fast_encrypt_response(sm, data, resp,
1169 req->identifier, out_data);
1172 if (tlv.crypto_binding) {
1173 tmp = eap_fast_process_crypto_binding(sm, data, ret,
1175 tlv.crypto_binding_len);
1179 resp = wpabuf_concat(resp, tmp);
1182 if (tlv.iresult == EAP_TLV_RESULT_SUCCESS) {
1183 tmp = eap_fast_tlv_result(failed ? EAP_TLV_RESULT_FAILURE :
1184 EAP_TLV_RESULT_SUCCESS, 1);
1185 resp = wpabuf_concat(resp, tmp);
1188 if (tlv.eap_payload_tlv) {
1189 tmp = eap_fast_process_eap_payload_tlv(
1190 sm, data, ret, req, tlv.eap_payload_tlv,
1191 tlv.eap_payload_tlv_len);
1192 resp = wpabuf_concat(resp, tmp);
1195 if (tlv.pac && tlv.result != EAP_TLV_RESULT_SUCCESS) {
1196 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV without Result TLV "
1197 "acknowledging success");
1199 } else if (tlv.pac && tlv.result == EAP_TLV_RESULT_SUCCESS) {
1200 tmp = eap_fast_process_pac(sm, data, ret, tlv.pac,
1202 resp = wpabuf_concat(resp, tmp);
1205 if (data->current_pac == NULL && data->provisioning &&
1206 !data->anon_provisioning && !tlv.pac &&
1207 (tlv.iresult == EAP_TLV_RESULT_SUCCESS ||
1208 tlv.result == EAP_TLV_RESULT_SUCCESS)) {
1210 * Need to request Tunnel PAC when using authenticated
1213 wpa_printf(MSG_DEBUG, "EAP-FAST: Request Tunnel PAC");
1214 tmp = eap_fast_pac_request();
1215 resp = wpabuf_concat(resp, tmp);
1218 if (tlv.result == EAP_TLV_RESULT_SUCCESS && !failed) {
1219 tmp = eap_fast_tlv_result(EAP_TLV_RESULT_SUCCESS, 0);
1220 resp = wpabuf_concat(tmp, resp);
1221 } else if (failed) {
1222 tmp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0);
1223 resp = wpabuf_concat(tmp, resp);
1226 if (resp && tlv.result == EAP_TLV_RESULT_SUCCESS && !failed &&
1227 tlv.crypto_binding && data->phase2_success) {
1228 if (data->anon_provisioning) {
1229 wpa_printf(MSG_DEBUG, "EAP-FAST: Unauthenticated "
1230 "provisioning completed successfully.");
1231 ret->methodState = METHOD_DONE;
1232 ret->decision = DECISION_FAIL;
1234 wpa_printf(MSG_DEBUG, "EAP-FAST: Authentication "
1235 "completed successfully.");
1236 if (data->provisioning)
1237 ret->methodState = METHOD_MAY_CONT;
1239 ret->methodState = METHOD_DONE;
1240 ret->decision = DECISION_UNCOND_SUCC;
1245 wpa_printf(MSG_DEBUG, "EAP-FAST: No recognized TLVs - send "
1246 "empty response packet");
1247 resp = wpabuf_alloc(1);
1250 return eap_fast_encrypt_response(sm, data, resp, req->identifier,
1255 static int eap_fast_decrypt(struct eap_sm *sm, struct eap_fast_data *data,
1256 struct eap_method_ret *ret,
1257 const struct eap_hdr *req,
1258 const struct wpabuf *in_data,
1259 struct wpabuf **out_data)
1261 struct wpabuf *in_decrypted;
1264 wpa_printf(MSG_DEBUG, "EAP-FAST: Received %lu bytes encrypted data for"
1265 " Phase 2", (unsigned long) wpabuf_len(in_data));
1267 if (data->pending_phase2_req) {
1268 wpa_printf(MSG_DEBUG, "EAP-FAST: Pending Phase 2 request - "
1269 "skip decryption and use old data");
1270 /* Clear TLS reassembly state. */
1271 eap_peer_tls_reset_input(&data->ssl);
1273 in_decrypted = data->pending_phase2_req;
1274 data->pending_phase2_req = NULL;
1278 if (wpabuf_len(in_data) == 0) {
1279 /* Received TLS ACK - requesting more fragments */
1280 return eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_FAST,
1282 req->identifier, NULL, out_data);
1285 res = eap_peer_tls_decrypt(sm, &data->ssl, in_data, &in_decrypted);
1290 wpa_hexdump_buf(MSG_MSGDUMP, "EAP-FAST: Decrypted Phase 2 TLV(s)",
1293 if (wpabuf_len(in_decrypted) < 4) {
1294 wpa_printf(MSG_INFO, "EAP-FAST: Too short Phase 2 "
1295 "TLV frame (len=%lu)",
1296 (unsigned long) wpabuf_len(in_decrypted));
1297 wpabuf_free(in_decrypted);
1301 res = eap_fast_process_decrypted(sm, data, ret, req,
1302 in_decrypted, out_data);
1304 wpabuf_free(in_decrypted);
1310 static const u8 * eap_fast_get_a_id(const u8 *buf, size_t len, size_t *id_len)
1313 struct pac_tlv_hdr *hdr;
1316 * Parse authority identity (A-ID) from the EAP-FAST/Start. This
1317 * supports both raw A-ID and one inside an A-ID TLV.
1321 if (len > sizeof(*hdr)) {
1323 hdr = (struct pac_tlv_hdr *) buf;
1324 tlen = be_to_host16(hdr->len);
1325 if (be_to_host16(hdr->type) == PAC_TYPE_A_ID &&
1326 sizeof(*hdr) + tlen <= len) {
1327 wpa_printf(MSG_DEBUG, "EAP-FAST: A-ID was in TLV "
1329 a_id = (u8 *) (hdr + 1);
1333 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: A-ID", a_id, *id_len);
1339 static void eap_fast_select_pac(struct eap_fast_data *data,
1340 const u8 *a_id, size_t a_id_len)
1342 data->current_pac = eap_fast_get_pac(data->pac, a_id, a_id_len,
1343 PAC_TYPE_TUNNEL_PAC);
1344 if (data->current_pac == NULL) {
1346 * Tunnel PAC was not available for this A-ID. Try to use
1347 * Machine Authentication PAC, if one is available.
1349 data->current_pac = eap_fast_get_pac(
1350 data->pac, a_id, a_id_len,
1351 PAC_TYPE_MACHINE_AUTHENTICATION);
1354 if (data->current_pac) {
1355 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC found for this A-ID "
1356 "(PAC-Type %d)", data->current_pac->pac_type);
1357 wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-FAST: A-ID-Info",
1358 data->current_pac->a_id_info,
1359 data->current_pac->a_id_info_len);
1364 static int eap_fast_use_pac_opaque(struct eap_sm *sm,
1365 struct eap_fast_data *data,
1366 struct eap_fast_pac *pac)
1369 size_t tlv_len, olen;
1370 struct eap_tlv_hdr *ehdr;
1372 olen = pac->pac_opaque_len;
1373 tlv_len = sizeof(*ehdr) + olen;
1374 tlv = os_malloc(tlv_len);
1376 ehdr = (struct eap_tlv_hdr *) tlv;
1377 ehdr->tlv_type = host_to_be16(PAC_TYPE_PAC_OPAQUE);
1378 ehdr->length = host_to_be16(olen);
1379 os_memcpy(ehdr + 1, pac->pac_opaque, olen);
1382 tls_connection_client_hello_ext(sm->ssl_ctx, data->ssl.conn,
1384 tlv, tlv_len) < 0) {
1385 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to add PAC-Opaque TLS "
1396 static int eap_fast_clear_pac_opaque_ext(struct eap_sm *sm,
1397 struct eap_fast_data *data)
1399 if (tls_connection_client_hello_ext(sm->ssl_ctx, data->ssl.conn,
1400 TLS_EXT_PAC_OPAQUE, NULL, 0) < 0) {
1401 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to remove PAC-Opaque "
1409 static int eap_fast_set_provisioning_ciphers(struct eap_sm *sm,
1410 struct eap_fast_data *data)
1415 if (data->provisioning_allowed & EAP_FAST_PROV_UNAUTH) {
1416 wpa_printf(MSG_DEBUG, "EAP-FAST: Enabling unauthenticated "
1417 "provisioning TLS cipher suites");
1418 ciphers[count++] = TLS_CIPHER_ANON_DH_AES128_SHA;
1421 if (data->provisioning_allowed & EAP_FAST_PROV_AUTH) {
1422 wpa_printf(MSG_DEBUG, "EAP-FAST: Enabling authenticated "
1423 "provisioning TLS cipher suites");
1424 ciphers[count++] = TLS_CIPHER_RSA_DHE_AES128_SHA;
1425 ciphers[count++] = TLS_CIPHER_AES128_SHA;
1426 ciphers[count++] = TLS_CIPHER_RC4_SHA;
1429 ciphers[count++] = TLS_CIPHER_NONE;
1431 if (tls_connection_set_cipher_list(sm->ssl_ctx, data->ssl.conn,
1433 wpa_printf(MSG_INFO, "EAP-FAST: Could not configure TLS "
1434 "cipher suites for provisioning");
1442 static int eap_fast_process_start(struct eap_sm *sm,
1443 struct eap_fast_data *data, u8 flags,
1444 const u8 *pos, size_t left)
1449 /* EAP-FAST Version negotiation (section 3.1) */
1450 wpa_printf(MSG_DEBUG, "EAP-FAST: Start (server ver=%d, own ver=%d)",
1451 flags & EAP_PEAP_VERSION_MASK, data->fast_version);
1452 if ((flags & EAP_PEAP_VERSION_MASK) < data->fast_version)
1453 data->fast_version = flags & EAP_PEAP_VERSION_MASK;
1454 wpa_printf(MSG_DEBUG, "EAP-FAST: Using FAST version %d",
1455 data->fast_version);
1457 a_id = eap_fast_get_a_id(pos, left, &a_id_len);
1458 eap_fast_select_pac(data, a_id, a_id_len);
1460 if (data->resuming && data->current_pac) {
1461 wpa_printf(MSG_DEBUG, "EAP-FAST: Trying to resume session - "
1462 "do not add PAC-Opaque to TLS ClientHello");
1463 if (eap_fast_clear_pac_opaque_ext(sm, data) < 0)
1465 } else if (data->current_pac) {
1467 * PAC found for the A-ID and we are not resuming an old
1468 * session, so add PAC-Opaque extension to ClientHello.
1470 if (eap_fast_use_pac_opaque(sm, data, data->current_pac) < 0)
1473 /* No PAC found, so we must provision one. */
1474 if (!data->provisioning_allowed) {
1475 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC found and "
1476 "provisioning disabled");
1479 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC found - "
1480 "starting provisioning");
1481 if (eap_fast_set_provisioning_ciphers(sm, data) < 0 ||
1482 eap_fast_clear_pac_opaque_ext(sm, data) < 0)
1484 data->provisioning = 1;
1491 static struct wpabuf * eap_fast_process(struct eap_sm *sm, void *priv,
1492 struct eap_method_ret *ret,
1493 const struct wpabuf *reqData)
1495 const struct eap_hdr *req;
1499 struct wpabuf *resp;
1501 struct eap_fast_data *data = priv;
1503 pos = eap_peer_tls_process_init(sm, &data->ssl, EAP_TYPE_FAST, ret,
1504 reqData, &left, &flags);
1508 req = wpabuf_head(reqData);
1509 id = req->identifier;
1511 if (flags & EAP_TLS_FLAGS_START) {
1512 if (eap_fast_process_start(sm, data, flags, pos, left) < 0)
1515 left = 0; /* A-ID is not used in further packet processing */
1519 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn) &&
1521 /* Process tunneled (encrypted) phase 2 data. */
1523 wpabuf_set(&msg, pos, left);
1524 res = eap_fast_decrypt(sm, data, ret, req, &msg, &resp);
1526 ret->methodState = METHOD_DONE;
1527 ret->decision = DECISION_FAIL;
1529 * Ack possible Alert that may have caused failure in
1535 /* Continue processing TLS handshake (phase 1). */
1536 res = eap_peer_tls_process_helper(sm, &data->ssl,
1538 data->fast_version, id, pos,
1541 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn)) {
1543 wpa_printf(MSG_DEBUG,
1544 "EAP-FAST: TLS done, proceed to Phase 2");
1545 if (data->provisioning &&
1546 (!(data->provisioning_allowed &
1547 EAP_FAST_PROV_AUTH) ||
1548 tls_get_cipher(sm->ssl_ctx, data->ssl.conn,
1549 cipher, sizeof(cipher)) < 0 ||
1550 os_strstr(cipher, "ADH-") ||
1551 os_strstr(cipher, "anon"))) {
1552 wpa_printf(MSG_DEBUG, "EAP-FAST: Using "
1553 "anonymous (unauthenticated) "
1555 data->anon_provisioning = 1;
1557 data->anon_provisioning = 0;
1559 eap_fast_derive_keys(sm, data);
1565 * Application data included in the handshake message.
1567 wpabuf_free(data->pending_phase2_req);
1568 data->pending_phase2_req = resp;
1570 wpabuf_set(&msg, pos, left);
1571 res = eap_fast_decrypt(sm, data, ret, req, &msg,
1578 return eap_peer_tls_build_ack(id, EAP_TYPE_FAST,
1579 data->fast_version);
1587 static Boolean eap_fast_has_reauth_data(struct eap_sm *sm, void *priv)
1589 struct eap_fast_data *data = priv;
1590 return tls_connection_established(sm->ssl_ctx, data->ssl.conn);
1594 static void eap_fast_deinit_for_reauth(struct eap_sm *sm, void *priv)
1596 struct eap_fast_data *data = priv;
1597 os_free(data->key_block_p);
1598 data->key_block_p = NULL;
1599 wpabuf_free(data->pending_phase2_req);
1600 data->pending_phase2_req = NULL;
1604 static void * eap_fast_init_for_reauth(struct eap_sm *sm, void *priv)
1606 struct eap_fast_data *data = priv;
1607 if (eap_peer_tls_reauth_init(sm, &data->ssl)) {
1611 if (data->phase2_priv && data->phase2_method &&
1612 data->phase2_method->init_for_reauth)
1613 data->phase2_method->init_for_reauth(sm, data->phase2_priv);
1614 data->phase2_success = 0;
1616 data->provisioning = 0;
1617 data->anon_provisioning = 0;
1618 data->simck_idx = 0;
1624 static int eap_fast_get_status(struct eap_sm *sm, void *priv, char *buf,
1625 size_t buflen, int verbose)
1627 struct eap_fast_data *data = priv;
1630 len = eap_peer_tls_status(sm, &data->ssl, buf, buflen, verbose);
1631 if (data->phase2_method) {
1632 ret = os_snprintf(buf + len, buflen - len,
1633 "EAP-FAST Phase2 method=%s\n",
1634 data->phase2_method->name);
1635 if (ret < 0 || (size_t) ret >= buflen - len)
1643 static Boolean eap_fast_isKeyAvailable(struct eap_sm *sm, void *priv)
1645 struct eap_fast_data *data = priv;
1646 return data->success;
1650 static u8 * eap_fast_getKey(struct eap_sm *sm, void *priv, size_t *len)
1652 struct eap_fast_data *data = priv;
1658 key = os_malloc(EAP_FAST_KEY_LEN);
1662 *len = EAP_FAST_KEY_LEN;
1663 os_memcpy(key, data->key_data, EAP_FAST_KEY_LEN);
1669 static u8 * eap_fast_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
1671 struct eap_fast_data *data = priv;
1677 key = os_malloc(EAP_EMSK_LEN);
1681 *len = EAP_EMSK_LEN;
1682 os_memcpy(key, data->emsk, EAP_EMSK_LEN);
1688 int eap_peer_fast_register(void)
1690 struct eap_method *eap;
1693 eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
1694 EAP_VENDOR_IETF, EAP_TYPE_FAST, "FAST");
1698 eap->init = eap_fast_init;
1699 eap->deinit = eap_fast_deinit;
1700 eap->process = eap_fast_process;
1701 eap->isKeyAvailable = eap_fast_isKeyAvailable;
1702 eap->getKey = eap_fast_getKey;
1703 eap->get_status = eap_fast_get_status;
1705 eap->has_reauth_data = eap_fast_has_reauth_data;
1706 eap->deinit_for_reauth = eap_fast_deinit_for_reauth;
1707 eap->init_for_reauth = eap_fast_init_for_reauth;
1709 eap->get_emsk = eap_fast_get_emsk;
1711 ret = eap_peer_method_register(eap);
1713 eap_peer_method_free(eap);