2 * EAP peer method: EAP-FAST (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/tls.h"
13 #include "crypto/sha1.h"
14 #include "eap_common/eap_tlv_common.h"
16 #include "eap_tls_common.h"
17 #include "eap_config.h"
18 #include "eap_fast_pac.h"
20 #ifdef EAP_FAST_DYNAMIC
21 #include "eap_fast_pac.c"
22 #endif /* EAP_FAST_DYNAMIC */
25 * - test session resumption and enable it if it interoperates
26 * - password change (pending mschapv2 packet; replay decrypted packet)
30 static void eap_fast_deinit(struct eap_sm *sm, void *priv);
33 struct eap_fast_data {
34 struct eap_ssl_data ssl;
38 const struct eap_method *phase2_method;
42 struct eap_method_type phase2_type;
43 struct eap_method_type *phase2_types;
44 size_t num_phase2_types;
45 int resuming; /* starting a resumed session */
46 struct eap_fast_key_block_provisioning *key_block_p;
47 #define EAP_FAST_PROV_UNAUTH 1
48 #define EAP_FAST_PROV_AUTH 2
49 int provisioning_allowed; /* Allowed PAC provisioning modes */
50 int provisioning; /* doing PAC provisioning (not the normal auth) */
51 int anon_provisioning; /* doing anonymous (unauthenticated)
53 int session_ticket_used;
55 u8 key_data[EAP_FAST_KEY_LEN];
56 u8 emsk[EAP_EMSK_LEN];
59 struct eap_fast_pac *pac;
60 struct eap_fast_pac *current_pac;
61 size_t max_pac_list_len;
62 int use_pac_binary_format;
64 u8 simck[EAP_FAST_SIMCK_LEN];
67 struct wpabuf *pending_phase2_req;
71 static int eap_fast_session_ticket_cb(void *ctx, const u8 *ticket, size_t len,
72 const u8 *client_random,
73 const u8 *server_random,
76 struct eap_fast_data *data = ctx;
78 wpa_printf(MSG_DEBUG, "EAP-FAST: SessionTicket callback");
80 if (client_random == NULL || server_random == NULL ||
81 master_secret == NULL) {
82 wpa_printf(MSG_DEBUG, "EAP-FAST: SessionTicket failed - fall "
83 "back to full TLS handshake");
84 data->session_ticket_used = 0;
85 if (data->provisioning_allowed) {
86 wpa_printf(MSG_DEBUG, "EAP-FAST: Try to provision a "
88 data->provisioning = 1;
89 data->current_pac = NULL;
94 wpa_hexdump(MSG_DEBUG, "EAP-FAST: SessionTicket", ticket, len);
96 if (data->current_pac == NULL) {
97 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC-Key available for "
98 "using SessionTicket");
99 data->session_ticket_used = 0;
103 eap_fast_derive_master_secret(data->current_pac->pac_key,
104 server_random, client_random,
107 data->session_ticket_used = 1;
113 static int eap_fast_parse_phase1(struct eap_fast_data *data,
118 pos = os_strstr(phase1, "fast_provisioning=");
120 data->provisioning_allowed = atoi(pos + 18);
121 wpa_printf(MSG_DEBUG, "EAP-FAST: Automatic PAC provisioning "
122 "mode: %d", data->provisioning_allowed);
125 pos = os_strstr(phase1, "fast_max_pac_list_len=");
127 data->max_pac_list_len = atoi(pos + 22);
128 if (data->max_pac_list_len == 0)
129 data->max_pac_list_len = 1;
130 wpa_printf(MSG_DEBUG, "EAP-FAST: Maximum PAC list length: %lu",
131 (unsigned long) data->max_pac_list_len);
134 pos = os_strstr(phase1, "fast_pac_format=binary");
136 data->use_pac_binary_format = 1;
137 wpa_printf(MSG_DEBUG, "EAP-FAST: Using binary format for PAC "
145 static void * eap_fast_init(struct eap_sm *sm)
147 struct eap_fast_data *data;
148 struct eap_peer_config *config = eap_get_config(sm);
150 data = os_zalloc(sizeof(*data));
153 data->fast_version = EAP_FAST_VERSION;
154 data->max_pac_list_len = 10;
156 if (config && config->phase1 &&
157 eap_fast_parse_phase1(data, config->phase1) < 0) {
158 eap_fast_deinit(sm, data);
162 if (eap_peer_select_phase2_methods(config, "auth=",
164 &data->num_phase2_types) < 0) {
165 eap_fast_deinit(sm, data);
169 data->phase2_type.vendor = EAP_VENDOR_IETF;
170 data->phase2_type.method = EAP_TYPE_NONE;
172 if (eap_peer_tls_ssl_init(sm, &data->ssl, config, EAP_TYPE_FAST)) {
173 wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize SSL.");
174 eap_fast_deinit(sm, data);
178 if (tls_connection_set_session_ticket_cb(sm->ssl_ctx, data->ssl.conn,
179 eap_fast_session_ticket_cb,
181 wpa_printf(MSG_INFO, "EAP-FAST: Failed to set SessionTicket "
183 eap_fast_deinit(sm, data);
188 * The local RADIUS server in a Cisco AP does not seem to like empty
189 * fragments before data, so disable that workaround for CBC.
190 * TODO: consider making this configurable
192 if (tls_connection_enable_workaround(sm->ssl_ctx, data->ssl.conn)) {
193 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to enable TLS "
197 if (data->use_pac_binary_format &&
198 eap_fast_load_pac_bin(sm, &data->pac, config->pac_file) < 0) {
199 eap_fast_deinit(sm, data);
203 if (!data->use_pac_binary_format &&
204 eap_fast_load_pac(sm, &data->pac, config->pac_file) < 0) {
205 eap_fast_deinit(sm, data);
208 eap_fast_pac_list_truncate(data->pac, data->max_pac_list_len);
210 if (data->pac == NULL && !data->provisioning_allowed) {
211 wpa_printf(MSG_INFO, "EAP-FAST: No PAC configured and "
212 "provisioning disabled");
213 eap_fast_deinit(sm, data);
221 static void eap_fast_deinit(struct eap_sm *sm, void *priv)
223 struct eap_fast_data *data = priv;
224 struct eap_fast_pac *pac, *prev;
228 if (data->phase2_priv && data->phase2_method)
229 data->phase2_method->deinit(sm, data->phase2_priv);
230 os_free(data->phase2_types);
231 os_free(data->key_block_p);
232 eap_peer_tls_ssl_deinit(sm, &data->ssl);
239 eap_fast_free_pac(prev);
241 wpabuf_free(data->pending_phase2_req);
246 static int eap_fast_derive_msk(struct eap_fast_data *data)
248 eap_fast_derive_eap_msk(data->simck, data->key_data);
249 eap_fast_derive_eap_emsk(data->simck, data->emsk);
255 static void eap_fast_derive_key_auth(struct eap_sm *sm,
256 struct eap_fast_data *data)
260 /* RFC 4851, Section 5.1:
261 * Extra key material after TLS key_block: session_key_seed[40]
264 sks = eap_fast_derive_key(sm->ssl_ctx, data->ssl.conn, "key expansion",
267 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive "
273 * RFC 4851, Section 5.2:
274 * S-IMCK[0] = session_key_seed
276 wpa_hexdump_key(MSG_DEBUG,
277 "EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
278 sks, EAP_FAST_SKS_LEN);
280 os_memcpy(data->simck, sks, EAP_FAST_SIMCK_LEN);
285 static void eap_fast_derive_key_provisioning(struct eap_sm *sm,
286 struct eap_fast_data *data)
288 os_free(data->key_block_p);
289 data->key_block_p = (struct eap_fast_key_block_provisioning *)
290 eap_fast_derive_key(sm->ssl_ctx, data->ssl.conn,
292 sizeof(*data->key_block_p));
293 if (data->key_block_p == NULL) {
294 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive key block");
298 * RFC 4851, Section 5.2:
299 * S-IMCK[0] = session_key_seed
301 wpa_hexdump_key(MSG_DEBUG,
302 "EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
303 data->key_block_p->session_key_seed,
304 sizeof(data->key_block_p->session_key_seed));
306 os_memcpy(data->simck, data->key_block_p->session_key_seed,
308 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: server_challenge",
309 data->key_block_p->server_challenge,
310 sizeof(data->key_block_p->server_challenge));
311 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: client_challenge",
312 data->key_block_p->client_challenge,
313 sizeof(data->key_block_p->client_challenge));
317 static void eap_fast_derive_keys(struct eap_sm *sm, struct eap_fast_data *data)
319 if (data->anon_provisioning)
320 eap_fast_derive_key_provisioning(sm, data);
322 eap_fast_derive_key_auth(sm, data);
326 static int eap_fast_init_phase2_method(struct eap_sm *sm,
327 struct eap_fast_data *data)
329 data->phase2_method =
330 eap_peer_get_eap_method(data->phase2_type.vendor,
331 data->phase2_type.method);
332 if (data->phase2_method == NULL)
335 if (data->key_block_p) {
336 sm->auth_challenge = data->key_block_p->server_challenge;
337 sm->peer_challenge = data->key_block_p->client_challenge;
340 data->phase2_priv = data->phase2_method->init(sm);
342 sm->auth_challenge = NULL;
343 sm->peer_challenge = NULL;
345 return data->phase2_priv == NULL ? -1 : 0;
349 static int eap_fast_select_phase2_method(struct eap_fast_data *data, u8 type)
353 /* TODO: TNC with anonymous provisioning; need to require both
354 * completed MSCHAPv2 and TNC */
356 if (data->anon_provisioning && type != EAP_TYPE_MSCHAPV2) {
357 wpa_printf(MSG_INFO, "EAP-FAST: Only EAP-MSCHAPv2 is allowed "
358 "during unauthenticated provisioning; reject phase2"
364 if (type == EAP_TYPE_TNC) {
365 data->phase2_type.vendor = EAP_VENDOR_IETF;
366 data->phase2_type.method = EAP_TYPE_TNC;
367 wpa_printf(MSG_DEBUG, "EAP-FAST: Selected Phase 2 EAP "
368 "vendor %d method %d for TNC",
369 data->phase2_type.vendor,
370 data->phase2_type.method);
375 for (i = 0; i < data->num_phase2_types; i++) {
376 if (data->phase2_types[i].vendor != EAP_VENDOR_IETF ||
377 data->phase2_types[i].method != type)
380 data->phase2_type.vendor = data->phase2_types[i].vendor;
381 data->phase2_type.method = data->phase2_types[i].method;
382 wpa_printf(MSG_DEBUG, "EAP-FAST: Selected Phase 2 EAP "
383 "vendor %d method %d",
384 data->phase2_type.vendor,
385 data->phase2_type.method);
389 if (type != data->phase2_type.method || type == EAP_TYPE_NONE)
396 static int eap_fast_phase2_request(struct eap_sm *sm,
397 struct eap_fast_data *data,
398 struct eap_method_ret *ret,
400 struct wpabuf **resp)
402 size_t len = be_to_host16(hdr->length);
404 struct eap_method_ret iret;
405 struct eap_peer_config *config = eap_get_config(sm);
408 if (len <= sizeof(struct eap_hdr)) {
409 wpa_printf(MSG_INFO, "EAP-FAST: too short "
410 "Phase 2 request (len=%lu)", (unsigned long) len);
413 pos = (u8 *) (hdr + 1);
414 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 Request: type=%d", *pos);
415 if (*pos == EAP_TYPE_IDENTITY) {
416 *resp = eap_sm_buildIdentity(sm, hdr->identifier, 1);
420 if (data->phase2_priv && data->phase2_method &&
421 *pos != data->phase2_type.method) {
422 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 EAP sequence - "
423 "deinitialize previous method");
424 data->phase2_method->deinit(sm, data->phase2_priv);
425 data->phase2_method = NULL;
426 data->phase2_priv = NULL;
427 data->phase2_type.vendor = EAP_VENDOR_IETF;
428 data->phase2_type.method = EAP_TYPE_NONE;
431 if (data->phase2_type.vendor == EAP_VENDOR_IETF &&
432 data->phase2_type.method == EAP_TYPE_NONE &&
433 eap_fast_select_phase2_method(data, *pos) < 0) {
434 if (eap_peer_tls_phase2_nak(data->phase2_types,
435 data->num_phase2_types,
441 if ((data->phase2_priv == NULL &&
442 eap_fast_init_phase2_method(sm, data) < 0) ||
443 data->phase2_method == NULL) {
444 wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize "
445 "Phase 2 EAP method %d", *pos);
446 ret->methodState = METHOD_DONE;
447 ret->decision = DECISION_FAIL;
451 os_memset(&iret, 0, sizeof(iret));
452 wpabuf_set(&msg, hdr, len);
453 *resp = data->phase2_method->process(sm, data->phase2_priv, &iret,
456 (iret.methodState == METHOD_DONE &&
457 iret.decision == DECISION_FAIL)) {
458 ret->methodState = METHOD_DONE;
459 ret->decision = DECISION_FAIL;
460 } else if ((iret.methodState == METHOD_DONE ||
461 iret.methodState == METHOD_MAY_CONT) &&
462 (iret.decision == DECISION_UNCOND_SUCC ||
463 iret.decision == DECISION_COND_SUCC)) {
464 data->phase2_success = 1;
467 if (*resp == NULL && config &&
468 (config->pending_req_identity || config->pending_req_password ||
469 config->pending_req_otp || config->pending_req_new_password)) {
470 wpabuf_free(data->pending_phase2_req);
471 data->pending_phase2_req = wpabuf_alloc_copy(hdr, len);
472 } else if (*resp == NULL)
479 static struct wpabuf * eap_fast_tlv_nak(int vendor_id, int tlv_type)
482 struct eap_tlv_nak_tlv *nak;
483 buf = wpabuf_alloc(sizeof(*nak));
486 nak = wpabuf_put(buf, sizeof(*nak));
487 nak->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY | EAP_TLV_NAK_TLV);
488 nak->length = host_to_be16(6);
489 nak->vendor_id = host_to_be32(vendor_id);
490 nak->nak_type = host_to_be16(tlv_type);
495 static struct wpabuf * eap_fast_tlv_result(int status, int intermediate)
498 struct eap_tlv_intermediate_result_tlv *result;
499 buf = wpabuf_alloc(sizeof(*result));
502 wpa_printf(MSG_DEBUG, "EAP-FAST: Add %sResult TLV(status=%d)",
503 intermediate ? "Intermediate " : "", status);
504 result = wpabuf_put(buf, sizeof(*result));
505 result->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
507 EAP_TLV_INTERMEDIATE_RESULT_TLV :
508 EAP_TLV_RESULT_TLV));
509 result->length = host_to_be16(2);
510 result->status = host_to_be16(status);
515 static struct wpabuf * eap_fast_tlv_pac_ack(void)
518 struct eap_tlv_result_tlv *res;
519 struct eap_tlv_pac_ack_tlv *ack;
521 buf = wpabuf_alloc(sizeof(*res) + sizeof(*ack));
525 wpa_printf(MSG_DEBUG, "EAP-FAST: Add PAC TLV (ack)");
526 ack = wpabuf_put(buf, sizeof(*ack));
527 ack->tlv_type = host_to_be16(EAP_TLV_PAC_TLV |
528 EAP_TLV_TYPE_MANDATORY);
529 ack->length = host_to_be16(sizeof(*ack) - sizeof(struct eap_tlv_hdr));
530 ack->pac_type = host_to_be16(PAC_TYPE_PAC_ACKNOWLEDGEMENT);
531 ack->pac_len = host_to_be16(2);
532 ack->result = host_to_be16(EAP_TLV_RESULT_SUCCESS);
538 static struct wpabuf * eap_fast_process_eap_payload_tlv(
539 struct eap_sm *sm, struct eap_fast_data *data,
540 struct eap_method_ret *ret,
541 u8 *eap_payload_tlv, size_t eap_payload_tlv_len)
544 struct wpabuf *resp = NULL;
546 if (eap_payload_tlv_len < sizeof(*hdr)) {
547 wpa_printf(MSG_DEBUG, "EAP-FAST: too short EAP "
548 "Payload TLV (len=%lu)",
549 (unsigned long) eap_payload_tlv_len);
553 hdr = (struct eap_hdr *) eap_payload_tlv;
554 if (be_to_host16(hdr->length) > eap_payload_tlv_len) {
555 wpa_printf(MSG_DEBUG, "EAP-FAST: EAP packet overflow in "
560 if (hdr->code != EAP_CODE_REQUEST) {
561 wpa_printf(MSG_INFO, "EAP-FAST: Unexpected code=%d in "
562 "Phase 2 EAP header", hdr->code);
566 if (eap_fast_phase2_request(sm, data, ret, hdr, &resp)) {
567 wpa_printf(MSG_INFO, "EAP-FAST: Phase2 Request processing "
572 return eap_fast_tlv_eap_payload(resp);
576 static int eap_fast_validate_crypto_binding(
577 struct eap_tlv_crypto_binding_tlv *_bind)
579 wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV: Version %d "
580 "Received Version %d SubType %d",
581 _bind->version, _bind->received_version, _bind->subtype);
582 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
583 _bind->nonce, sizeof(_bind->nonce));
584 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
585 _bind->compound_mac, sizeof(_bind->compound_mac));
587 if (_bind->version != EAP_FAST_VERSION ||
588 _bind->received_version != EAP_FAST_VERSION ||
589 _bind->subtype != EAP_TLV_CRYPTO_BINDING_SUBTYPE_REQUEST) {
590 wpa_printf(MSG_INFO, "EAP-FAST: Invalid version/subtype in "
591 "Crypto-Binding TLV: Version %d "
592 "Received Version %d SubType %d",
593 _bind->version, _bind->received_version,
602 static void eap_fast_write_crypto_binding(
603 struct eap_tlv_crypto_binding_tlv *rbind,
604 struct eap_tlv_crypto_binding_tlv *_bind, const u8 *cmk)
606 rbind->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
607 EAP_TLV_CRYPTO_BINDING_TLV);
608 rbind->length = host_to_be16(sizeof(*rbind) -
609 sizeof(struct eap_tlv_hdr));
610 rbind->version = EAP_FAST_VERSION;
611 rbind->received_version = _bind->version;
612 rbind->subtype = EAP_TLV_CRYPTO_BINDING_SUBTYPE_RESPONSE;
613 os_memcpy(rbind->nonce, _bind->nonce, sizeof(_bind->nonce));
614 inc_byte_array(rbind->nonce, sizeof(rbind->nonce));
615 hmac_sha1(cmk, EAP_FAST_CMK_LEN, (u8 *) rbind, sizeof(*rbind),
616 rbind->compound_mac);
618 wpa_printf(MSG_DEBUG, "EAP-FAST: Reply Crypto-Binding TLV: Version %d "
619 "Received Version %d SubType %d",
620 rbind->version, rbind->received_version, rbind->subtype);
621 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
622 rbind->nonce, sizeof(rbind->nonce));
623 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
624 rbind->compound_mac, sizeof(rbind->compound_mac));
628 static int eap_fast_get_phase2_key(struct eap_sm *sm,
629 struct eap_fast_data *data,
630 u8 *isk, size_t isk_len)
635 os_memset(isk, 0, isk_len);
637 if (data->phase2_method == NULL || data->phase2_priv == NULL) {
638 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not "
643 if (data->phase2_method->isKeyAvailable == NULL ||
644 data->phase2_method->getKey == NULL)
647 if (!data->phase2_method->isKeyAvailable(sm, data->phase2_priv) ||
648 (key = data->phase2_method->getKey(sm, data->phase2_priv,
649 &key_len)) == NULL) {
650 wpa_printf(MSG_DEBUG, "EAP-FAST: Could not get key material "
655 if (key_len > isk_len)
658 data->phase2_method->vendor == EAP_VENDOR_IETF &&
659 data->phase2_method->method == EAP_TYPE_MSCHAPV2) {
661 * EAP-FAST uses reverse order for MS-MPPE keys when deriving
662 * MSK from EAP-MSCHAPv2. Swap the keys here to get the correct
663 * ISK for EAP-FAST cryptobinding.
665 os_memcpy(isk, key + 16, 16);
666 os_memcpy(isk + 16, key, 16);
668 os_memcpy(isk, key, key_len);
675 static int eap_fast_get_cmk(struct eap_sm *sm, struct eap_fast_data *data,
678 u8 isk[32], imck[60];
680 wpa_printf(MSG_DEBUG, "EAP-FAST: Determining CMK[%d] for Compound MIC "
681 "calculation", data->simck_idx + 1);
684 * RFC 4851, Section 5.2:
685 * IMCK[j] = T-PRF(S-IMCK[j-1], "Inner Methods Compound Keys",
687 * S-IMCK[j] = first 40 octets of IMCK[j]
688 * CMK[j] = last 20 octets of IMCK[j]
691 if (eap_fast_get_phase2_key(sm, data, isk, sizeof(isk)) < 0)
693 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: ISK[j]", isk, sizeof(isk));
694 sha1_t_prf(data->simck, EAP_FAST_SIMCK_LEN,
695 "Inner Methods Compound Keys",
696 isk, sizeof(isk), imck, sizeof(imck));
698 os_memcpy(data->simck, imck, EAP_FAST_SIMCK_LEN);
699 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: S-IMCK[j]",
700 data->simck, EAP_FAST_SIMCK_LEN);
701 os_memcpy(cmk, imck + EAP_FAST_SIMCK_LEN, EAP_FAST_CMK_LEN);
702 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: CMK[j]",
703 cmk, EAP_FAST_CMK_LEN);
709 static u8 * eap_fast_write_pac_request(u8 *pos, u16 pac_type)
711 struct eap_tlv_hdr *pac;
712 struct eap_tlv_request_action_tlv *act;
713 struct eap_tlv_pac_type_tlv *type;
715 act = (struct eap_tlv_request_action_tlv *) pos;
716 act->tlv_type = host_to_be16(EAP_TLV_REQUEST_ACTION_TLV);
717 act->length = host_to_be16(2);
718 act->action = host_to_be16(EAP_TLV_ACTION_PROCESS_TLV);
720 pac = (struct eap_tlv_hdr *) (act + 1);
721 pac->tlv_type = host_to_be16(EAP_TLV_PAC_TLV);
722 pac->length = host_to_be16(sizeof(*type));
724 type = (struct eap_tlv_pac_type_tlv *) (pac + 1);
725 type->tlv_type = host_to_be16(PAC_TYPE_PAC_TYPE);
726 type->length = host_to_be16(2);
727 type->pac_type = host_to_be16(pac_type);
729 return (u8 *) (type + 1);
733 static struct wpabuf * eap_fast_process_crypto_binding(
734 struct eap_sm *sm, struct eap_fast_data *data,
735 struct eap_method_ret *ret,
736 struct eap_tlv_crypto_binding_tlv *_bind, size_t bind_len)
740 u8 cmk[EAP_FAST_CMK_LEN], cmac[SHA1_MAC_LEN];
744 if (eap_fast_validate_crypto_binding(_bind) < 0)
747 if (eap_fast_get_cmk(sm, data, cmk) < 0)
750 /* Validate received Compound MAC */
751 os_memcpy(cmac, _bind->compound_mac, sizeof(cmac));
752 os_memset(_bind->compound_mac, 0, sizeof(cmac));
753 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Crypto-Binding TLV for Compound "
754 "MAC calculation", (u8 *) _bind, bind_len);
755 hmac_sha1(cmk, EAP_FAST_CMK_LEN, (u8 *) _bind, bind_len,
756 _bind->compound_mac);
757 res = os_memcmp(cmac, _bind->compound_mac, sizeof(cmac));
758 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Received Compound MAC",
760 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Calculated Compound MAC",
761 _bind->compound_mac, sizeof(cmac));
763 wpa_printf(MSG_INFO, "EAP-FAST: Compound MAC did not match");
764 os_memcpy(_bind->compound_mac, cmac, sizeof(cmac));
769 * Compound MAC was valid, so authentication succeeded. Reply with
770 * crypto binding to allow server to complete authentication.
773 len = sizeof(struct eap_tlv_crypto_binding_tlv);
774 resp = wpabuf_alloc(len);
778 if (!data->anon_provisioning && data->phase2_success &&
779 eap_fast_derive_msk(data) < 0) {
780 wpa_printf(MSG_INFO, "EAP-FAST: Failed to generate MSK");
781 ret->methodState = METHOD_DONE;
782 ret->decision = DECISION_FAIL;
783 data->phase2_success = 0;
788 pos = wpabuf_put(resp, sizeof(struct eap_tlv_crypto_binding_tlv));
789 eap_fast_write_crypto_binding((struct eap_tlv_crypto_binding_tlv *)
796 static void eap_fast_parse_pac_tlv(struct eap_fast_pac *entry, int type,
797 u8 *pos, size_t len, int *pac_key_found)
799 switch (type & 0x7fff) {
800 case PAC_TYPE_PAC_KEY:
801 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: PAC-Key", pos, len);
802 if (len != EAP_FAST_PAC_KEY_LEN) {
803 wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid PAC-Key "
804 "length %lu", (unsigned long) len);
808 os_memcpy(entry->pac_key, pos, len);
810 case PAC_TYPE_PAC_OPAQUE:
811 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Opaque", pos, len);
812 entry->pac_opaque = pos;
813 entry->pac_opaque_len = len;
815 case PAC_TYPE_PAC_INFO:
816 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Info", pos, len);
817 entry->pac_info = pos;
818 entry->pac_info_len = len;
821 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored unknown PAC type %d",
828 static int eap_fast_process_pac_tlv(struct eap_fast_pac *entry,
829 u8 *pac, size_t pac_len)
831 struct pac_tlv_hdr *hdr;
834 int type, pac_key_found = 0;
839 while (left > sizeof(*hdr)) {
840 hdr = (struct pac_tlv_hdr *) pos;
841 type = be_to_host16(hdr->type);
842 len = be_to_host16(hdr->len);
844 left -= sizeof(*hdr);
846 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV overrun "
847 "(type=%d len=%lu left=%lu)",
848 type, (unsigned long) len,
849 (unsigned long) left);
853 eap_fast_parse_pac_tlv(entry, type, pos, len, &pac_key_found);
859 if (!pac_key_found || !entry->pac_opaque || !entry->pac_info) {
860 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV does not include "
861 "all the required fields");
869 static int eap_fast_parse_pac_info(struct eap_fast_pac *entry, int type,
876 switch (type & 0x7fff) {
877 case PAC_TYPE_CRED_LIFETIME:
879 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Info - "
880 "Invalid CRED_LIFETIME length - ignored",
886 * This is not currently saved separately in PAC files since
887 * the server can automatically initiate PAC update when
888 * needed. Anyway, the information is available from PAC-Info
889 * dump if it is needed for something in the future.
891 lifetime = WPA_GET_BE32(pos);
893 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info - CRED_LIFETIME %d "
895 lifetime, (lifetime - (u32) now.sec) / 86400);
898 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - A-ID",
901 entry->a_id_len = len;
904 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - I-ID",
907 entry->i_id_len = len;
909 case PAC_TYPE_A_ID_INFO:
910 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - A-ID-Info",
912 entry->a_id_info = pos;
913 entry->a_id_info_len = len;
915 case PAC_TYPE_PAC_TYPE:
916 /* RFC 5422, Section 4.2.6 - PAC-Type TLV */
918 wpa_printf(MSG_INFO, "EAP-FAST: Invalid PAC-Type "
919 "length %lu (expected 2)",
920 (unsigned long) len);
921 wpa_hexdump_ascii(MSG_DEBUG,
922 "EAP-FAST: PAC-Info - PAC-Type",
926 pac_type = WPA_GET_BE16(pos);
927 if (pac_type != PAC_TYPE_TUNNEL_PAC &&
928 pac_type != PAC_TYPE_USER_AUTHORIZATION &&
929 pac_type != PAC_TYPE_MACHINE_AUTHENTICATION) {
930 wpa_printf(MSG_INFO, "EAP-FAST: Unsupported PAC Type "
935 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info - PAC-Type %d",
937 entry->pac_type = pac_type;
940 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored unknown PAC-Info "
949 static int eap_fast_process_pac_info(struct eap_fast_pac *entry)
951 struct pac_tlv_hdr *hdr;
956 /* RFC 5422, Section 4.2.4 */
958 /* PAC-Type defaults to Tunnel PAC (Type 1) */
959 entry->pac_type = PAC_TYPE_TUNNEL_PAC;
961 pos = entry->pac_info;
962 left = entry->pac_info_len;
963 while (left > sizeof(*hdr)) {
964 hdr = (struct pac_tlv_hdr *) pos;
965 type = be_to_host16(hdr->type);
966 len = be_to_host16(hdr->len);
968 left -= sizeof(*hdr);
970 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info overrun "
971 "(type=%d len=%lu left=%lu)",
972 type, (unsigned long) len,
973 (unsigned long) left);
977 if (eap_fast_parse_pac_info(entry, type, pos, len) < 0)
984 if (entry->a_id == NULL || entry->a_id_info == NULL) {
985 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info does not include "
986 "all the required fields");
994 static struct wpabuf * eap_fast_process_pac(struct eap_sm *sm,
995 struct eap_fast_data *data,
996 struct eap_method_ret *ret,
997 u8 *pac, size_t pac_len)
999 struct eap_peer_config *config = eap_get_config(sm);
1000 struct eap_fast_pac entry;
1002 os_memset(&entry, 0, sizeof(entry));
1003 if (eap_fast_process_pac_tlv(&entry, pac, pac_len) ||
1004 eap_fast_process_pac_info(&entry))
1007 eap_fast_add_pac(&data->pac, &data->current_pac, &entry);
1008 eap_fast_pac_list_truncate(data->pac, data->max_pac_list_len);
1009 if (data->use_pac_binary_format)
1010 eap_fast_save_pac_bin(sm, data->pac, config->pac_file);
1012 eap_fast_save_pac(sm, data->pac, config->pac_file);
1014 if (data->provisioning) {
1015 if (data->anon_provisioning) {
1017 * Unauthenticated provisioning does not provide keying
1018 * material and must end with an EAP-Failure.
1019 * Authentication will be done separately after this.
1022 ret->decision = DECISION_FAIL;
1025 * Server may or may not allow authenticated
1026 * provisioning also for key generation.
1028 ret->decision = DECISION_COND_SUCC;
1030 wpa_printf(MSG_DEBUG, "EAP-FAST: Send PAC-Acknowledgement TLV "
1031 "- Provisioning completed successfully");
1034 * This is PAC refreshing, i.e., normal authentication that is
1035 * expected to be completed with an EAP-Success. However,
1036 * RFC 5422, Section 3.5 allows EAP-Failure to be sent even
1037 * after protected success exchange in case of EAP-Fast
1038 * provisioning, so we better use DECISION_COND_SUCC here
1039 * instead of DECISION_UNCOND_SUCC.
1041 wpa_printf(MSG_DEBUG, "EAP-FAST: Send PAC-Acknowledgement TLV "
1042 "- PAC refreshing completed successfully");
1043 ret->decision = DECISION_COND_SUCC;
1045 ret->methodState = METHOD_DONE;
1046 return eap_fast_tlv_pac_ack();
1050 static int eap_fast_parse_decrypted(struct wpabuf *decrypted,
1051 struct eap_fast_tlv_parse *tlv,
1052 struct wpabuf **resp)
1054 int mandatory, tlv_type, len, res;
1057 os_memset(tlv, 0, sizeof(*tlv));
1059 /* Parse TLVs from the decrypted Phase 2 data */
1060 pos = wpabuf_mhead(decrypted);
1061 end = pos + wpabuf_len(decrypted);
1062 while (pos + 4 < end) {
1063 mandatory = pos[0] & 0x80;
1064 tlv_type = WPA_GET_BE16(pos) & 0x3fff;
1066 len = WPA_GET_BE16(pos);
1068 if (pos + len > end) {
1069 wpa_printf(MSG_INFO, "EAP-FAST: TLV overflow");
1072 wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: "
1073 "TLV type %d length %d%s",
1074 tlv_type, len, mandatory ? " (mandatory)" : "");
1076 res = eap_fast_parse_tlv(tlv, tlv_type, pos, len);
1081 wpa_printf(MSG_DEBUG, "EAP-FAST: Nak unknown "
1082 "mandatory TLV type %d", tlv_type);
1083 *resp = eap_fast_tlv_nak(0, tlv_type);
1086 wpa_printf(MSG_DEBUG, "EAP-FAST: ignored "
1087 "unknown optional TLV type %d",
1099 static int eap_fast_encrypt_response(struct eap_sm *sm,
1100 struct eap_fast_data *data,
1101 struct wpabuf *resp,
1102 u8 identifier, struct wpabuf **out_data)
1107 wpa_hexdump_buf(MSG_DEBUG, "EAP-FAST: Encrypting Phase 2 data",
1109 if (eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_FAST,
1110 data->fast_version, identifier,
1112 wpa_printf(MSG_INFO, "EAP-FAST: Failed to encrypt a Phase 2 "
1121 static struct wpabuf * eap_fast_pac_request(void)
1126 tmp = wpabuf_alloc(sizeof(struct eap_tlv_hdr) +
1127 sizeof(struct eap_tlv_request_action_tlv) +
1128 sizeof(struct eap_tlv_pac_type_tlv));
1132 pos = wpabuf_put(tmp, 0);
1133 pos2 = eap_fast_write_pac_request(pos, PAC_TYPE_TUNNEL_PAC);
1134 wpabuf_put(tmp, pos2 - pos);
1139 static int eap_fast_process_decrypted(struct eap_sm *sm,
1140 struct eap_fast_data *data,
1141 struct eap_method_ret *ret,
1142 const struct eap_hdr *req,
1143 struct wpabuf *decrypted,
1144 struct wpabuf **out_data)
1146 struct wpabuf *resp = NULL, *tmp;
1147 struct eap_fast_tlv_parse tlv;
1150 if (eap_fast_parse_decrypted(decrypted, &tlv, &resp) < 0)
1153 return eap_fast_encrypt_response(sm, data, resp,
1154 req->identifier, out_data);
1156 if (tlv.result == EAP_TLV_RESULT_FAILURE) {
1157 resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0);
1158 return eap_fast_encrypt_response(sm, data, resp,
1159 req->identifier, out_data);
1162 if (tlv.iresult == EAP_TLV_RESULT_FAILURE) {
1163 resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 1);
1164 return eap_fast_encrypt_response(sm, data, resp,
1165 req->identifier, out_data);
1168 if (tlv.crypto_binding) {
1169 tmp = eap_fast_process_crypto_binding(sm, data, ret,
1171 tlv.crypto_binding_len);
1175 resp = wpabuf_concat(resp, tmp);
1178 if (tlv.iresult == EAP_TLV_RESULT_SUCCESS) {
1179 tmp = eap_fast_tlv_result(failed ? EAP_TLV_RESULT_FAILURE :
1180 EAP_TLV_RESULT_SUCCESS, 1);
1181 resp = wpabuf_concat(resp, tmp);
1184 if (tlv.eap_payload_tlv) {
1185 tmp = eap_fast_process_eap_payload_tlv(
1186 sm, data, ret, tlv.eap_payload_tlv,
1187 tlv.eap_payload_tlv_len);
1188 resp = wpabuf_concat(resp, tmp);
1191 if (tlv.pac && tlv.result != EAP_TLV_RESULT_SUCCESS) {
1192 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV without Result TLV "
1193 "acknowledging success");
1195 } else if (tlv.pac && tlv.result == EAP_TLV_RESULT_SUCCESS) {
1196 tmp = eap_fast_process_pac(sm, data, ret, tlv.pac,
1198 resp = wpabuf_concat(resp, tmp);
1201 if (data->current_pac == NULL && data->provisioning &&
1202 !data->anon_provisioning && !tlv.pac &&
1203 (tlv.iresult == EAP_TLV_RESULT_SUCCESS ||
1204 tlv.result == EAP_TLV_RESULT_SUCCESS)) {
1206 * Need to request Tunnel PAC when using authenticated
1209 wpa_printf(MSG_DEBUG, "EAP-FAST: Request Tunnel PAC");
1210 tmp = eap_fast_pac_request();
1211 resp = wpabuf_concat(resp, tmp);
1214 if (tlv.result == EAP_TLV_RESULT_SUCCESS && !failed) {
1215 tmp = eap_fast_tlv_result(EAP_TLV_RESULT_SUCCESS, 0);
1216 resp = wpabuf_concat(tmp, resp);
1217 } else if (failed) {
1218 tmp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0);
1219 resp = wpabuf_concat(tmp, resp);
1222 if (resp && tlv.result == EAP_TLV_RESULT_SUCCESS && !failed &&
1223 tlv.crypto_binding && data->phase2_success) {
1224 if (data->anon_provisioning) {
1225 wpa_printf(MSG_DEBUG, "EAP-FAST: Unauthenticated "
1226 "provisioning completed successfully.");
1227 ret->methodState = METHOD_DONE;
1228 ret->decision = DECISION_FAIL;
1230 wpa_printf(MSG_DEBUG, "EAP-FAST: Authentication "
1231 "completed successfully.");
1232 if (data->provisioning)
1233 ret->methodState = METHOD_MAY_CONT;
1235 ret->methodState = METHOD_DONE;
1236 ret->decision = DECISION_UNCOND_SUCC;
1241 wpa_printf(MSG_DEBUG, "EAP-FAST: No recognized TLVs - send "
1242 "empty response packet");
1243 resp = wpabuf_alloc(1);
1246 return eap_fast_encrypt_response(sm, data, resp, req->identifier,
1251 static int eap_fast_decrypt(struct eap_sm *sm, struct eap_fast_data *data,
1252 struct eap_method_ret *ret,
1253 const struct eap_hdr *req,
1254 const struct wpabuf *in_data,
1255 struct wpabuf **out_data)
1257 struct wpabuf *in_decrypted;
1260 wpa_printf(MSG_DEBUG, "EAP-FAST: Received %lu bytes encrypted data for"
1261 " Phase 2", (unsigned long) wpabuf_len(in_data));
1263 if (data->pending_phase2_req) {
1264 wpa_printf(MSG_DEBUG, "EAP-FAST: Pending Phase 2 request - "
1265 "skip decryption and use old data");
1266 /* Clear TLS reassembly state. */
1267 eap_peer_tls_reset_input(&data->ssl);
1269 in_decrypted = data->pending_phase2_req;
1270 data->pending_phase2_req = NULL;
1274 if (wpabuf_len(in_data) == 0) {
1275 /* Received TLS ACK - requesting more fragments */
1276 return eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_FAST,
1278 req->identifier, NULL, out_data);
1281 res = eap_peer_tls_decrypt(sm, &data->ssl, in_data, &in_decrypted);
1286 wpa_hexdump_buf(MSG_MSGDUMP, "EAP-FAST: Decrypted Phase 2 TLV(s)",
1289 if (wpabuf_len(in_decrypted) < 4) {
1290 wpa_printf(MSG_INFO, "EAP-FAST: Too short Phase 2 "
1291 "TLV frame (len=%lu)",
1292 (unsigned long) wpabuf_len(in_decrypted));
1293 wpabuf_free(in_decrypted);
1297 res = eap_fast_process_decrypted(sm, data, ret, req,
1298 in_decrypted, out_data);
1300 wpabuf_free(in_decrypted);
1306 static const u8 * eap_fast_get_a_id(const u8 *buf, size_t len, size_t *id_len)
1309 struct pac_tlv_hdr *hdr;
1312 * Parse authority identity (A-ID) from the EAP-FAST/Start. This
1313 * supports both raw A-ID and one inside an A-ID TLV.
1317 if (len > sizeof(*hdr)) {
1319 hdr = (struct pac_tlv_hdr *) buf;
1320 tlen = be_to_host16(hdr->len);
1321 if (be_to_host16(hdr->type) == PAC_TYPE_A_ID &&
1322 sizeof(*hdr) + tlen <= len) {
1323 wpa_printf(MSG_DEBUG, "EAP-FAST: A-ID was in TLV "
1325 a_id = (u8 *) (hdr + 1);
1329 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: A-ID", a_id, *id_len);
1335 static void eap_fast_select_pac(struct eap_fast_data *data,
1336 const u8 *a_id, size_t a_id_len)
1338 data->current_pac = eap_fast_get_pac(data->pac, a_id, a_id_len,
1339 PAC_TYPE_TUNNEL_PAC);
1340 if (data->current_pac == NULL) {
1342 * Tunnel PAC was not available for this A-ID. Try to use
1343 * Machine Authentication PAC, if one is available.
1345 data->current_pac = eap_fast_get_pac(
1346 data->pac, a_id, a_id_len,
1347 PAC_TYPE_MACHINE_AUTHENTICATION);
1350 if (data->current_pac) {
1351 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC found for this A-ID "
1352 "(PAC-Type %d)", data->current_pac->pac_type);
1353 wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-FAST: A-ID-Info",
1354 data->current_pac->a_id_info,
1355 data->current_pac->a_id_info_len);
1360 static int eap_fast_use_pac_opaque(struct eap_sm *sm,
1361 struct eap_fast_data *data,
1362 struct eap_fast_pac *pac)
1365 size_t tlv_len, olen;
1366 struct eap_tlv_hdr *ehdr;
1368 olen = pac->pac_opaque_len;
1369 tlv_len = sizeof(*ehdr) + olen;
1370 tlv = os_malloc(tlv_len);
1372 ehdr = (struct eap_tlv_hdr *) tlv;
1373 ehdr->tlv_type = host_to_be16(PAC_TYPE_PAC_OPAQUE);
1374 ehdr->length = host_to_be16(olen);
1375 os_memcpy(ehdr + 1, pac->pac_opaque, olen);
1378 tls_connection_client_hello_ext(sm->ssl_ctx, data->ssl.conn,
1380 tlv, tlv_len) < 0) {
1381 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to add PAC-Opaque TLS "
1392 static int eap_fast_clear_pac_opaque_ext(struct eap_sm *sm,
1393 struct eap_fast_data *data)
1395 if (tls_connection_client_hello_ext(sm->ssl_ctx, data->ssl.conn,
1396 TLS_EXT_PAC_OPAQUE, NULL, 0) < 0) {
1397 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to remove PAC-Opaque "
1405 static int eap_fast_set_provisioning_ciphers(struct eap_sm *sm,
1406 struct eap_fast_data *data)
1411 if (data->provisioning_allowed & EAP_FAST_PROV_UNAUTH) {
1412 wpa_printf(MSG_DEBUG, "EAP-FAST: Enabling unauthenticated "
1413 "provisioning TLS cipher suites");
1414 ciphers[count++] = TLS_CIPHER_ANON_DH_AES128_SHA;
1417 if (data->provisioning_allowed & EAP_FAST_PROV_AUTH) {
1418 wpa_printf(MSG_DEBUG, "EAP-FAST: Enabling authenticated "
1419 "provisioning TLS cipher suites");
1420 ciphers[count++] = TLS_CIPHER_RSA_DHE_AES128_SHA;
1421 ciphers[count++] = TLS_CIPHER_AES128_SHA;
1422 ciphers[count++] = TLS_CIPHER_RC4_SHA;
1425 ciphers[count++] = TLS_CIPHER_NONE;
1427 if (tls_connection_set_cipher_list(sm->ssl_ctx, data->ssl.conn,
1429 wpa_printf(MSG_INFO, "EAP-FAST: Could not configure TLS "
1430 "cipher suites for provisioning");
1438 static int eap_fast_process_start(struct eap_sm *sm,
1439 struct eap_fast_data *data, u8 flags,
1440 const u8 *pos, size_t left)
1445 /* EAP-FAST Version negotiation (section 3.1) */
1446 wpa_printf(MSG_DEBUG, "EAP-FAST: Start (server ver=%d, own ver=%d)",
1447 flags & EAP_TLS_VERSION_MASK, data->fast_version);
1448 if ((flags & EAP_TLS_VERSION_MASK) < data->fast_version)
1449 data->fast_version = flags & EAP_TLS_VERSION_MASK;
1450 wpa_printf(MSG_DEBUG, "EAP-FAST: Using FAST version %d",
1451 data->fast_version);
1453 a_id = eap_fast_get_a_id(pos, left, &a_id_len);
1454 eap_fast_select_pac(data, a_id, a_id_len);
1456 if (data->resuming && data->current_pac) {
1457 wpa_printf(MSG_DEBUG, "EAP-FAST: Trying to resume session - "
1458 "do not add PAC-Opaque to TLS ClientHello");
1459 if (eap_fast_clear_pac_opaque_ext(sm, data) < 0)
1461 } else if (data->current_pac) {
1463 * PAC found for the A-ID and we are not resuming an old
1464 * session, so add PAC-Opaque extension to ClientHello.
1466 if (eap_fast_use_pac_opaque(sm, data, data->current_pac) < 0)
1469 /* No PAC found, so we must provision one. */
1470 if (!data->provisioning_allowed) {
1471 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC found and "
1472 "provisioning disabled");
1475 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC found - "
1476 "starting provisioning");
1477 if (eap_fast_set_provisioning_ciphers(sm, data) < 0 ||
1478 eap_fast_clear_pac_opaque_ext(sm, data) < 0)
1480 data->provisioning = 1;
1487 static struct wpabuf * eap_fast_process(struct eap_sm *sm, void *priv,
1488 struct eap_method_ret *ret,
1489 const struct wpabuf *reqData)
1491 const struct eap_hdr *req;
1495 struct wpabuf *resp;
1497 struct eap_fast_data *data = priv;
1499 pos = eap_peer_tls_process_init(sm, &data->ssl, EAP_TYPE_FAST, ret,
1500 reqData, &left, &flags);
1504 req = wpabuf_head(reqData);
1505 id = req->identifier;
1507 if (flags & EAP_TLS_FLAGS_START) {
1508 if (eap_fast_process_start(sm, data, flags, pos, left) < 0)
1511 left = 0; /* A-ID is not used in further packet processing */
1515 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn) &&
1517 /* Process tunneled (encrypted) phase 2 data. */
1519 wpabuf_set(&msg, pos, left);
1520 res = eap_fast_decrypt(sm, data, ret, req, &msg, &resp);
1522 ret->methodState = METHOD_DONE;
1523 ret->decision = DECISION_FAIL;
1525 * Ack possible Alert that may have caused failure in
1531 /* Continue processing TLS handshake (phase 1). */
1532 res = eap_peer_tls_process_helper(sm, &data->ssl,
1534 data->fast_version, id, pos,
1537 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn)) {
1539 wpa_printf(MSG_DEBUG,
1540 "EAP-FAST: TLS done, proceed to Phase 2");
1541 if (data->provisioning &&
1542 (!(data->provisioning_allowed &
1543 EAP_FAST_PROV_AUTH) ||
1544 tls_get_cipher(sm->ssl_ctx, data->ssl.conn,
1545 cipher, sizeof(cipher)) < 0 ||
1546 os_strstr(cipher, "ADH-") ||
1547 os_strstr(cipher, "anon"))) {
1548 wpa_printf(MSG_DEBUG, "EAP-FAST: Using "
1549 "anonymous (unauthenticated) "
1551 data->anon_provisioning = 1;
1553 data->anon_provisioning = 0;
1555 eap_fast_derive_keys(sm, data);
1561 * Application data included in the handshake message.
1563 wpabuf_free(data->pending_phase2_req);
1564 data->pending_phase2_req = resp;
1566 wpabuf_set(&msg, pos, left);
1567 res = eap_fast_decrypt(sm, data, ret, req, &msg,
1574 return eap_peer_tls_build_ack(id, EAP_TYPE_FAST,
1575 data->fast_version);
1583 static Boolean eap_fast_has_reauth_data(struct eap_sm *sm, void *priv)
1585 struct eap_fast_data *data = priv;
1586 return tls_connection_established(sm->ssl_ctx, data->ssl.conn);
1590 static void eap_fast_deinit_for_reauth(struct eap_sm *sm, void *priv)
1592 struct eap_fast_data *data = priv;
1593 os_free(data->key_block_p);
1594 data->key_block_p = NULL;
1595 wpabuf_free(data->pending_phase2_req);
1596 data->pending_phase2_req = NULL;
1600 static void * eap_fast_init_for_reauth(struct eap_sm *sm, void *priv)
1602 struct eap_fast_data *data = priv;
1603 if (eap_peer_tls_reauth_init(sm, &data->ssl)) {
1607 if (data->phase2_priv && data->phase2_method &&
1608 data->phase2_method->init_for_reauth)
1609 data->phase2_method->init_for_reauth(sm, data->phase2_priv);
1610 data->phase2_success = 0;
1612 data->provisioning = 0;
1613 data->anon_provisioning = 0;
1614 data->simck_idx = 0;
1620 static int eap_fast_get_status(struct eap_sm *sm, void *priv, char *buf,
1621 size_t buflen, int verbose)
1623 struct eap_fast_data *data = priv;
1626 len = eap_peer_tls_status(sm, &data->ssl, buf, buflen, verbose);
1627 if (data->phase2_method) {
1628 ret = os_snprintf(buf + len, buflen - len,
1629 "EAP-FAST Phase2 method=%s\n",
1630 data->phase2_method->name);
1631 if (ret < 0 || (size_t) ret >= buflen - len)
1639 static Boolean eap_fast_isKeyAvailable(struct eap_sm *sm, void *priv)
1641 struct eap_fast_data *data = priv;
1642 return data->success;
1646 static u8 * eap_fast_getKey(struct eap_sm *sm, void *priv, size_t *len)
1648 struct eap_fast_data *data = priv;
1654 key = os_malloc(EAP_FAST_KEY_LEN);
1658 *len = EAP_FAST_KEY_LEN;
1659 os_memcpy(key, data->key_data, EAP_FAST_KEY_LEN);
1665 static u8 * eap_fast_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
1667 struct eap_fast_data *data = priv;
1673 key = os_malloc(EAP_EMSK_LEN);
1677 *len = EAP_EMSK_LEN;
1678 os_memcpy(key, data->emsk, EAP_EMSK_LEN);
1684 int eap_peer_fast_register(void)
1686 struct eap_method *eap;
1689 eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
1690 EAP_VENDOR_IETF, EAP_TYPE_FAST, "FAST");
1694 eap->init = eap_fast_init;
1695 eap->deinit = eap_fast_deinit;
1696 eap->process = eap_fast_process;
1697 eap->isKeyAvailable = eap_fast_isKeyAvailable;
1698 eap->getKey = eap_fast_getKey;
1699 eap->get_status = eap_fast_get_status;
1701 eap->has_reauth_data = eap_fast_has_reauth_data;
1702 eap->deinit_for_reauth = eap_fast_deinit_for_reauth;
1703 eap->init_for_reauth = eap_fast_init_for_reauth;
1705 eap->get_emsk = eap_fast_get_emsk;
1707 ret = eap_peer_method_register(eap);
1709 eap_peer_method_free(eap);