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];
58 u8 emsk[EAP_EMSK_LEN];
61 struct eap_fast_pac *pac;
62 struct eap_fast_pac *current_pac;
63 size_t max_pac_list_len;
64 int use_pac_binary_format;
66 u8 simck[EAP_FAST_SIMCK_LEN];
69 struct wpabuf *pending_phase2_req;
73 static int eap_fast_session_ticket_cb(void *ctx, const u8 *ticket, size_t len,
74 const u8 *client_random,
75 const u8 *server_random,
78 struct eap_fast_data *data = ctx;
80 wpa_printf(MSG_DEBUG, "EAP-FAST: SessionTicket callback");
82 if (client_random == NULL || server_random == NULL ||
83 master_secret == NULL) {
84 wpa_printf(MSG_DEBUG, "EAP-FAST: SessionTicket failed - fall "
85 "back to full TLS handshake");
86 data->session_ticket_used = 0;
87 if (data->provisioning_allowed) {
88 wpa_printf(MSG_DEBUG, "EAP-FAST: Try to provision a "
90 data->provisioning = 1;
91 data->current_pac = NULL;
96 wpa_hexdump(MSG_DEBUG, "EAP-FAST: SessionTicket", ticket, len);
98 if (data->current_pac == NULL) {
99 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC-Key available for "
100 "using SessionTicket");
101 data->session_ticket_used = 0;
105 eap_fast_derive_master_secret(data->current_pac->pac_key,
106 server_random, client_random,
109 data->session_ticket_used = 1;
115 static int eap_fast_parse_phase1(struct eap_fast_data *data,
120 pos = os_strstr(phase1, "fast_provisioning=");
122 data->provisioning_allowed = atoi(pos + 18);
123 wpa_printf(MSG_DEBUG, "EAP-FAST: Automatic PAC provisioning "
124 "mode: %d", data->provisioning_allowed);
127 pos = os_strstr(phase1, "fast_max_pac_list_len=");
129 data->max_pac_list_len = atoi(pos + 22);
130 if (data->max_pac_list_len == 0)
131 data->max_pac_list_len = 1;
132 wpa_printf(MSG_DEBUG, "EAP-FAST: Maximum PAC list length: %lu",
133 (unsigned long) data->max_pac_list_len);
136 pos = os_strstr(phase1, "fast_pac_format=binary");
138 data->use_pac_binary_format = 1;
139 wpa_printf(MSG_DEBUG, "EAP-FAST: Using binary format for PAC "
147 static void * eap_fast_init(struct eap_sm *sm)
149 struct eap_fast_data *data;
150 struct eap_peer_config *config = eap_get_config(sm);
152 data = os_zalloc(sizeof(*data));
155 data->fast_version = EAP_FAST_VERSION;
156 data->max_pac_list_len = 10;
158 if (config && config->phase1 &&
159 eap_fast_parse_phase1(data, config->phase1) < 0) {
160 eap_fast_deinit(sm, data);
164 if (eap_peer_select_phase2_methods(config, "auth=",
166 &data->num_phase2_types) < 0) {
167 eap_fast_deinit(sm, data);
171 data->phase2_type.vendor = EAP_VENDOR_IETF;
172 data->phase2_type.method = EAP_TYPE_NONE;
174 if (eap_peer_tls_ssl_init(sm, &data->ssl, config, EAP_TYPE_FAST)) {
175 wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize SSL.");
176 eap_fast_deinit(sm, data);
180 if (tls_connection_set_session_ticket_cb(sm->ssl_ctx, data->ssl.conn,
181 eap_fast_session_ticket_cb,
183 wpa_printf(MSG_INFO, "EAP-FAST: Failed to set SessionTicket "
185 eap_fast_deinit(sm, data);
190 * The local RADIUS server in a Cisco AP does not seem to like empty
191 * fragments before data, so disable that workaround for CBC.
192 * TODO: consider making this configurable
194 if (tls_connection_enable_workaround(sm->ssl_ctx, data->ssl.conn)) {
195 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to enable TLS "
199 if (!config->pac_file) {
200 wpa_printf(MSG_INFO, "EAP-FAST: No PAC file configured");
201 eap_fast_deinit(sm, data);
205 if (data->use_pac_binary_format &&
206 eap_fast_load_pac_bin(sm, &data->pac, config->pac_file) < 0) {
207 wpa_printf(MSG_INFO, "EAP-FAST: Failed to load PAC file");
208 eap_fast_deinit(sm, data);
212 if (!data->use_pac_binary_format &&
213 eap_fast_load_pac(sm, &data->pac, config->pac_file) < 0) {
214 wpa_printf(MSG_INFO, "EAP-FAST: Failed to load PAC file");
215 eap_fast_deinit(sm, data);
218 eap_fast_pac_list_truncate(data->pac, data->max_pac_list_len);
220 if (data->pac == NULL && !data->provisioning_allowed) {
221 wpa_printf(MSG_INFO, "EAP-FAST: No PAC configured and "
222 "provisioning disabled");
223 eap_fast_deinit(sm, data);
231 static void eap_fast_deinit(struct eap_sm *sm, void *priv)
233 struct eap_fast_data *data = priv;
234 struct eap_fast_pac *pac, *prev;
238 if (data->phase2_priv && data->phase2_method)
239 data->phase2_method->deinit(sm, data->phase2_priv);
240 os_free(data->phase2_types);
241 os_free(data->key_block_p);
242 eap_peer_tls_ssl_deinit(sm, &data->ssl);
249 eap_fast_free_pac(prev);
251 os_free(data->session_id);
252 wpabuf_free(data->pending_phase2_req);
257 static int eap_fast_derive_msk(struct eap_fast_data *data)
259 eap_fast_derive_eap_msk(data->simck, data->key_data);
260 eap_fast_derive_eap_emsk(data->simck, data->emsk);
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 void eap_fast_derive_keys(struct eap_sm *sm, struct eap_fast_data *data)
330 if (data->anon_provisioning)
331 eap_fast_derive_key_provisioning(sm, data);
333 eap_fast_derive_key_auth(sm, data);
337 static int eap_fast_init_phase2_method(struct eap_sm *sm,
338 struct eap_fast_data *data)
340 data->phase2_method =
341 eap_peer_get_eap_method(data->phase2_type.vendor,
342 data->phase2_type.method);
343 if (data->phase2_method == NULL)
346 if (data->key_block_p) {
347 sm->auth_challenge = data->key_block_p->server_challenge;
348 sm->peer_challenge = data->key_block_p->client_challenge;
351 data->phase2_priv = data->phase2_method->init(sm);
353 sm->auth_challenge = NULL;
354 sm->peer_challenge = NULL;
356 return data->phase2_priv == NULL ? -1 : 0;
360 static int eap_fast_select_phase2_method(struct eap_fast_data *data, u8 type)
364 /* TODO: TNC with anonymous provisioning; need to require both
365 * completed MSCHAPv2 and TNC */
367 if (data->anon_provisioning && type != EAP_TYPE_MSCHAPV2) {
368 wpa_printf(MSG_INFO, "EAP-FAST: Only EAP-MSCHAPv2 is allowed "
369 "during unauthenticated provisioning; reject phase2"
375 if (type == EAP_TYPE_TNC) {
376 data->phase2_type.vendor = EAP_VENDOR_IETF;
377 data->phase2_type.method = EAP_TYPE_TNC;
378 wpa_printf(MSG_DEBUG, "EAP-FAST: Selected Phase 2 EAP "
379 "vendor %d method %d for TNC",
380 data->phase2_type.vendor,
381 data->phase2_type.method);
386 for (i = 0; i < data->num_phase2_types; i++) {
387 if (data->phase2_types[i].vendor != EAP_VENDOR_IETF ||
388 data->phase2_types[i].method != type)
391 data->phase2_type.vendor = data->phase2_types[i].vendor;
392 data->phase2_type.method = data->phase2_types[i].method;
393 wpa_printf(MSG_DEBUG, "EAP-FAST: Selected Phase 2 EAP "
394 "vendor %d method %d",
395 data->phase2_type.vendor,
396 data->phase2_type.method);
400 if (type != data->phase2_type.method || type == EAP_TYPE_NONE)
407 static int eap_fast_phase2_request(struct eap_sm *sm,
408 struct eap_fast_data *data,
409 struct eap_method_ret *ret,
411 struct wpabuf **resp)
413 size_t len = be_to_host16(hdr->length);
415 struct eap_method_ret iret;
416 struct eap_peer_config *config = eap_get_config(sm);
419 if (len <= sizeof(struct eap_hdr)) {
420 wpa_printf(MSG_INFO, "EAP-FAST: too short "
421 "Phase 2 request (len=%lu)", (unsigned long) len);
424 pos = (u8 *) (hdr + 1);
425 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 Request: type=%d", *pos);
426 if (*pos == EAP_TYPE_IDENTITY) {
427 *resp = eap_sm_buildIdentity(sm, hdr->identifier, 1);
431 if (data->phase2_priv && data->phase2_method &&
432 *pos != data->phase2_type.method) {
433 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 EAP sequence - "
434 "deinitialize previous method");
435 data->phase2_method->deinit(sm, data->phase2_priv);
436 data->phase2_method = NULL;
437 data->phase2_priv = NULL;
438 data->phase2_type.vendor = EAP_VENDOR_IETF;
439 data->phase2_type.method = EAP_TYPE_NONE;
442 if (data->phase2_type.vendor == EAP_VENDOR_IETF &&
443 data->phase2_type.method == EAP_TYPE_NONE &&
444 eap_fast_select_phase2_method(data, *pos) < 0) {
445 if (eap_peer_tls_phase2_nak(data->phase2_types,
446 data->num_phase2_types,
452 if ((data->phase2_priv == NULL &&
453 eap_fast_init_phase2_method(sm, data) < 0) ||
454 data->phase2_method == NULL) {
455 wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize "
456 "Phase 2 EAP method %d", *pos);
457 ret->methodState = METHOD_DONE;
458 ret->decision = DECISION_FAIL;
462 os_memset(&iret, 0, sizeof(iret));
463 wpabuf_set(&msg, hdr, len);
464 *resp = data->phase2_method->process(sm, data->phase2_priv, &iret,
467 (iret.methodState == METHOD_DONE &&
468 iret.decision == DECISION_FAIL)) {
469 ret->methodState = METHOD_DONE;
470 ret->decision = DECISION_FAIL;
471 } else if ((iret.methodState == METHOD_DONE ||
472 iret.methodState == METHOD_MAY_CONT) &&
473 (iret.decision == DECISION_UNCOND_SUCC ||
474 iret.decision == DECISION_COND_SUCC)) {
475 data->phase2_success = 1;
478 if (*resp == NULL && config &&
479 (config->pending_req_identity || config->pending_req_password ||
480 config->pending_req_otp || config->pending_req_new_password)) {
481 wpabuf_free(data->pending_phase2_req);
482 data->pending_phase2_req = wpabuf_alloc_copy(hdr, len);
483 } else if (*resp == NULL)
490 static struct wpabuf * eap_fast_tlv_nak(int vendor_id, int tlv_type)
493 struct eap_tlv_nak_tlv *nak;
494 buf = wpabuf_alloc(sizeof(*nak));
497 nak = wpabuf_put(buf, sizeof(*nak));
498 nak->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY | EAP_TLV_NAK_TLV);
499 nak->length = host_to_be16(6);
500 nak->vendor_id = host_to_be32(vendor_id);
501 nak->nak_type = host_to_be16(tlv_type);
506 static struct wpabuf * eap_fast_tlv_result(int status, int intermediate)
509 struct eap_tlv_intermediate_result_tlv *result;
510 buf = wpabuf_alloc(sizeof(*result));
513 wpa_printf(MSG_DEBUG, "EAP-FAST: Add %sResult TLV(status=%d)",
514 intermediate ? "Intermediate " : "", status);
515 result = wpabuf_put(buf, sizeof(*result));
516 result->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
518 EAP_TLV_INTERMEDIATE_RESULT_TLV :
519 EAP_TLV_RESULT_TLV));
520 result->length = host_to_be16(2);
521 result->status = host_to_be16(status);
526 static struct wpabuf * eap_fast_tlv_pac_ack(void)
529 struct eap_tlv_result_tlv *res;
530 struct eap_tlv_pac_ack_tlv *ack;
532 buf = wpabuf_alloc(sizeof(*res) + sizeof(*ack));
536 wpa_printf(MSG_DEBUG, "EAP-FAST: Add PAC TLV (ack)");
537 ack = wpabuf_put(buf, sizeof(*ack));
538 ack->tlv_type = host_to_be16(EAP_TLV_PAC_TLV |
539 EAP_TLV_TYPE_MANDATORY);
540 ack->length = host_to_be16(sizeof(*ack) - sizeof(struct eap_tlv_hdr));
541 ack->pac_type = host_to_be16(PAC_TYPE_PAC_ACKNOWLEDGEMENT);
542 ack->pac_len = host_to_be16(2);
543 ack->result = host_to_be16(EAP_TLV_RESULT_SUCCESS);
549 static struct wpabuf * eap_fast_process_eap_payload_tlv(
550 struct eap_sm *sm, struct eap_fast_data *data,
551 struct eap_method_ret *ret,
552 u8 *eap_payload_tlv, size_t eap_payload_tlv_len)
555 struct wpabuf *resp = NULL;
557 if (eap_payload_tlv_len < sizeof(*hdr)) {
558 wpa_printf(MSG_DEBUG, "EAP-FAST: too short EAP "
559 "Payload TLV (len=%lu)",
560 (unsigned long) eap_payload_tlv_len);
564 hdr = (struct eap_hdr *) eap_payload_tlv;
565 if (be_to_host16(hdr->length) > eap_payload_tlv_len) {
566 wpa_printf(MSG_DEBUG, "EAP-FAST: EAP packet overflow in "
571 if (hdr->code != EAP_CODE_REQUEST) {
572 wpa_printf(MSG_INFO, "EAP-FAST: Unexpected code=%d in "
573 "Phase 2 EAP header", hdr->code);
577 if (eap_fast_phase2_request(sm, data, ret, hdr, &resp)) {
578 wpa_printf(MSG_INFO, "EAP-FAST: Phase2 Request processing "
583 return eap_fast_tlv_eap_payload(resp);
587 static int eap_fast_validate_crypto_binding(
588 struct eap_tlv_crypto_binding_tlv *_bind)
590 wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV: Version %d "
591 "Received Version %d SubType %d",
592 _bind->version, _bind->received_version, _bind->subtype);
593 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
594 _bind->nonce, sizeof(_bind->nonce));
595 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
596 _bind->compound_mac, sizeof(_bind->compound_mac));
598 if (_bind->version != EAP_FAST_VERSION ||
599 _bind->received_version != EAP_FAST_VERSION ||
600 _bind->subtype != EAP_TLV_CRYPTO_BINDING_SUBTYPE_REQUEST) {
601 wpa_printf(MSG_INFO, "EAP-FAST: Invalid version/subtype in "
602 "Crypto-Binding TLV: Version %d "
603 "Received Version %d SubType %d",
604 _bind->version, _bind->received_version,
613 static void eap_fast_write_crypto_binding(
614 struct eap_tlv_crypto_binding_tlv *rbind,
615 struct eap_tlv_crypto_binding_tlv *_bind, const u8 *cmk)
617 rbind->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
618 EAP_TLV_CRYPTO_BINDING_TLV);
619 rbind->length = host_to_be16(sizeof(*rbind) -
620 sizeof(struct eap_tlv_hdr));
621 rbind->version = EAP_FAST_VERSION;
622 rbind->received_version = _bind->version;
623 rbind->subtype = EAP_TLV_CRYPTO_BINDING_SUBTYPE_RESPONSE;
624 os_memcpy(rbind->nonce, _bind->nonce, sizeof(_bind->nonce));
625 inc_byte_array(rbind->nonce, sizeof(rbind->nonce));
626 hmac_sha1(cmk, EAP_FAST_CMK_LEN, (u8 *) rbind, sizeof(*rbind),
627 rbind->compound_mac);
629 wpa_printf(MSG_DEBUG, "EAP-FAST: Reply Crypto-Binding TLV: Version %d "
630 "Received Version %d SubType %d",
631 rbind->version, rbind->received_version, rbind->subtype);
632 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
633 rbind->nonce, sizeof(rbind->nonce));
634 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
635 rbind->compound_mac, sizeof(rbind->compound_mac));
639 static int eap_fast_get_phase2_key(struct eap_sm *sm,
640 struct eap_fast_data *data,
641 u8 *isk, size_t isk_len)
646 os_memset(isk, 0, isk_len);
648 if (data->phase2_method == NULL || data->phase2_priv == NULL) {
649 wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not "
654 if (data->phase2_method->isKeyAvailable == NULL ||
655 data->phase2_method->getKey == NULL)
658 if (!data->phase2_method->isKeyAvailable(sm, data->phase2_priv) ||
659 (key = data->phase2_method->getKey(sm, data->phase2_priv,
660 &key_len)) == NULL) {
661 wpa_printf(MSG_DEBUG, "EAP-FAST: Could not get key material "
666 if (key_len > isk_len)
669 data->phase2_method->vendor == EAP_VENDOR_IETF &&
670 data->phase2_method->method == EAP_TYPE_MSCHAPV2) {
672 * EAP-FAST uses reverse order for MS-MPPE keys when deriving
673 * MSK from EAP-MSCHAPv2. Swap the keys here to get the correct
674 * ISK for EAP-FAST cryptobinding.
676 os_memcpy(isk, key + 16, 16);
677 os_memcpy(isk + 16, key, 16);
679 os_memcpy(isk, key, key_len);
686 static int eap_fast_get_cmk(struct eap_sm *sm, struct eap_fast_data *data,
689 u8 isk[32], imck[60];
691 wpa_printf(MSG_DEBUG, "EAP-FAST: Determining CMK[%d] for Compound MIC "
692 "calculation", data->simck_idx + 1);
695 * RFC 4851, Section 5.2:
696 * IMCK[j] = T-PRF(S-IMCK[j-1], "Inner Methods Compound Keys",
698 * S-IMCK[j] = first 40 octets of IMCK[j]
699 * CMK[j] = last 20 octets of IMCK[j]
702 if (eap_fast_get_phase2_key(sm, data, isk, sizeof(isk)) < 0)
704 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: ISK[j]", isk, sizeof(isk));
705 sha1_t_prf(data->simck, EAP_FAST_SIMCK_LEN,
706 "Inner Methods Compound Keys",
707 isk, sizeof(isk), imck, sizeof(imck));
709 os_memcpy(data->simck, imck, EAP_FAST_SIMCK_LEN);
710 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: S-IMCK[j]",
711 data->simck, EAP_FAST_SIMCK_LEN);
712 os_memcpy(cmk, imck + EAP_FAST_SIMCK_LEN, EAP_FAST_CMK_LEN);
713 wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: CMK[j]",
714 cmk, EAP_FAST_CMK_LEN);
720 static u8 * eap_fast_write_pac_request(u8 *pos, u16 pac_type)
722 struct eap_tlv_hdr *pac;
723 struct eap_tlv_request_action_tlv *act;
724 struct eap_tlv_pac_type_tlv *type;
726 act = (struct eap_tlv_request_action_tlv *) pos;
727 act->tlv_type = host_to_be16(EAP_TLV_REQUEST_ACTION_TLV);
728 act->length = host_to_be16(2);
729 act->action = host_to_be16(EAP_TLV_ACTION_PROCESS_TLV);
731 pac = (struct eap_tlv_hdr *) (act + 1);
732 pac->tlv_type = host_to_be16(EAP_TLV_PAC_TLV);
733 pac->length = host_to_be16(sizeof(*type));
735 type = (struct eap_tlv_pac_type_tlv *) (pac + 1);
736 type->tlv_type = host_to_be16(PAC_TYPE_PAC_TYPE);
737 type->length = host_to_be16(2);
738 type->pac_type = host_to_be16(pac_type);
740 return (u8 *) (type + 1);
744 static struct wpabuf * eap_fast_process_crypto_binding(
745 struct eap_sm *sm, struct eap_fast_data *data,
746 struct eap_method_ret *ret,
747 struct eap_tlv_crypto_binding_tlv *_bind, size_t bind_len)
751 u8 cmk[EAP_FAST_CMK_LEN], cmac[SHA1_MAC_LEN];
755 if (eap_fast_validate_crypto_binding(_bind) < 0)
758 if (eap_fast_get_cmk(sm, data, cmk) < 0)
761 /* Validate received Compound MAC */
762 os_memcpy(cmac, _bind->compound_mac, sizeof(cmac));
763 os_memset(_bind->compound_mac, 0, sizeof(cmac));
764 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Crypto-Binding TLV for Compound "
765 "MAC calculation", (u8 *) _bind, bind_len);
766 hmac_sha1(cmk, EAP_FAST_CMK_LEN, (u8 *) _bind, bind_len,
767 _bind->compound_mac);
768 res = os_memcmp(cmac, _bind->compound_mac, sizeof(cmac));
769 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Received Compound MAC",
771 wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Calculated Compound MAC",
772 _bind->compound_mac, sizeof(cmac));
774 wpa_printf(MSG_INFO, "EAP-FAST: Compound MAC did not match");
775 os_memcpy(_bind->compound_mac, cmac, sizeof(cmac));
780 * Compound MAC was valid, so authentication succeeded. Reply with
781 * crypto binding to allow server to complete authentication.
784 len = sizeof(struct eap_tlv_crypto_binding_tlv);
785 resp = wpabuf_alloc(len);
789 if (!data->anon_provisioning && data->phase2_success &&
790 eap_fast_derive_msk(data) < 0) {
791 wpa_printf(MSG_INFO, "EAP-FAST: Failed to generate MSK");
792 ret->methodState = METHOD_DONE;
793 ret->decision = DECISION_FAIL;
794 data->phase2_success = 0;
799 if (!data->anon_provisioning && data->phase2_success) {
800 os_free(data->session_id);
801 data->session_id = eap_peer_tls_derive_session_id(
802 sm, &data->ssl, EAP_TYPE_FAST, &data->id_len);
803 if (data->session_id) {
804 wpa_hexdump(MSG_DEBUG, "EAP-FAST: Derived Session-Id",
805 data->session_id, data->id_len);
807 wpa_printf(MSG_ERROR, "EAP-FAST: Failed to derive "
814 pos = wpabuf_put(resp, sizeof(struct eap_tlv_crypto_binding_tlv));
815 eap_fast_write_crypto_binding((struct eap_tlv_crypto_binding_tlv *)
822 static void eap_fast_parse_pac_tlv(struct eap_fast_pac *entry, int type,
823 u8 *pos, size_t len, int *pac_key_found)
825 switch (type & 0x7fff) {
826 case PAC_TYPE_PAC_KEY:
827 wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: PAC-Key", pos, len);
828 if (len != EAP_FAST_PAC_KEY_LEN) {
829 wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid PAC-Key "
830 "length %lu", (unsigned long) len);
834 os_memcpy(entry->pac_key, pos, len);
836 case PAC_TYPE_PAC_OPAQUE:
837 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Opaque", pos, len);
838 entry->pac_opaque = pos;
839 entry->pac_opaque_len = len;
841 case PAC_TYPE_PAC_INFO:
842 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Info", pos, len);
843 entry->pac_info = pos;
844 entry->pac_info_len = len;
847 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored unknown PAC type %d",
854 static int eap_fast_process_pac_tlv(struct eap_fast_pac *entry,
855 u8 *pac, size_t pac_len)
857 struct pac_tlv_hdr *hdr;
860 int type, pac_key_found = 0;
865 while (left > sizeof(*hdr)) {
866 hdr = (struct pac_tlv_hdr *) pos;
867 type = be_to_host16(hdr->type);
868 len = be_to_host16(hdr->len);
870 left -= sizeof(*hdr);
872 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV overrun "
873 "(type=%d len=%lu left=%lu)",
874 type, (unsigned long) len,
875 (unsigned long) left);
879 eap_fast_parse_pac_tlv(entry, type, pos, len, &pac_key_found);
885 if (!pac_key_found || !entry->pac_opaque || !entry->pac_info) {
886 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV does not include "
887 "all the required fields");
895 static int eap_fast_parse_pac_info(struct eap_fast_pac *entry, int type,
902 switch (type & 0x7fff) {
903 case PAC_TYPE_CRED_LIFETIME:
905 wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Info - "
906 "Invalid CRED_LIFETIME length - ignored",
912 * This is not currently saved separately in PAC files since
913 * the server can automatically initiate PAC update when
914 * needed. Anyway, the information is available from PAC-Info
915 * dump if it is needed for something in the future.
917 lifetime = WPA_GET_BE32(pos);
919 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info - CRED_LIFETIME %d "
921 lifetime, (lifetime - (u32) now.sec) / 86400);
924 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - A-ID",
927 entry->a_id_len = len;
930 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - I-ID",
933 entry->i_id_len = len;
935 case PAC_TYPE_A_ID_INFO:
936 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - A-ID-Info",
938 entry->a_id_info = pos;
939 entry->a_id_info_len = len;
941 case PAC_TYPE_PAC_TYPE:
942 /* RFC 5422, Section 4.2.6 - PAC-Type TLV */
944 wpa_printf(MSG_INFO, "EAP-FAST: Invalid PAC-Type "
945 "length %lu (expected 2)",
946 (unsigned long) len);
947 wpa_hexdump_ascii(MSG_DEBUG,
948 "EAP-FAST: PAC-Info - PAC-Type",
952 pac_type = WPA_GET_BE16(pos);
953 if (pac_type != PAC_TYPE_TUNNEL_PAC &&
954 pac_type != PAC_TYPE_USER_AUTHORIZATION &&
955 pac_type != PAC_TYPE_MACHINE_AUTHENTICATION) {
956 wpa_printf(MSG_INFO, "EAP-FAST: Unsupported PAC Type "
961 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info - PAC-Type %d",
963 entry->pac_type = pac_type;
966 wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored unknown PAC-Info "
975 static int eap_fast_process_pac_info(struct eap_fast_pac *entry)
977 struct pac_tlv_hdr *hdr;
982 /* RFC 5422, Section 4.2.4 */
984 /* PAC-Type defaults to Tunnel PAC (Type 1) */
985 entry->pac_type = PAC_TYPE_TUNNEL_PAC;
987 pos = entry->pac_info;
988 left = entry->pac_info_len;
989 while (left > sizeof(*hdr)) {
990 hdr = (struct pac_tlv_hdr *) pos;
991 type = be_to_host16(hdr->type);
992 len = be_to_host16(hdr->len);
994 left -= sizeof(*hdr);
996 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info overrun "
997 "(type=%d len=%lu left=%lu)",
998 type, (unsigned long) len,
999 (unsigned long) left);
1003 if (eap_fast_parse_pac_info(entry, type, pos, len) < 0)
1010 if (entry->a_id == NULL || entry->a_id_info == NULL) {
1011 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info does not include "
1012 "all the required fields");
1020 static struct wpabuf * eap_fast_process_pac(struct eap_sm *sm,
1021 struct eap_fast_data *data,
1022 struct eap_method_ret *ret,
1023 u8 *pac, size_t pac_len)
1025 struct eap_peer_config *config = eap_get_config(sm);
1026 struct eap_fast_pac entry;
1028 os_memset(&entry, 0, sizeof(entry));
1029 if (eap_fast_process_pac_tlv(&entry, pac, pac_len) ||
1030 eap_fast_process_pac_info(&entry))
1033 eap_fast_add_pac(&data->pac, &data->current_pac, &entry);
1034 eap_fast_pac_list_truncate(data->pac, data->max_pac_list_len);
1035 if (data->use_pac_binary_format)
1036 eap_fast_save_pac_bin(sm, data->pac, config->pac_file);
1038 eap_fast_save_pac(sm, data->pac, config->pac_file);
1040 if (data->provisioning) {
1041 if (data->anon_provisioning) {
1043 * Unauthenticated provisioning does not provide keying
1044 * material and must end with an EAP-Failure.
1045 * Authentication will be done separately after this.
1048 ret->decision = DECISION_FAIL;
1051 * Server may or may not allow authenticated
1052 * provisioning also for key generation.
1054 ret->decision = DECISION_COND_SUCC;
1056 wpa_printf(MSG_DEBUG, "EAP-FAST: Send PAC-Acknowledgement TLV "
1057 "- Provisioning completed successfully");
1058 sm->expected_failure = 1;
1061 * This is PAC refreshing, i.e., normal authentication that is
1062 * expected to be completed with an EAP-Success. However,
1063 * RFC 5422, Section 3.5 allows EAP-Failure to be sent even
1064 * after protected success exchange in case of EAP-Fast
1065 * provisioning, so we better use DECISION_COND_SUCC here
1066 * instead of DECISION_UNCOND_SUCC.
1068 wpa_printf(MSG_DEBUG, "EAP-FAST: Send PAC-Acknowledgement TLV "
1069 "- PAC refreshing completed successfully");
1070 ret->decision = DECISION_COND_SUCC;
1072 ret->methodState = METHOD_DONE;
1073 return eap_fast_tlv_pac_ack();
1077 static int eap_fast_parse_decrypted(struct wpabuf *decrypted,
1078 struct eap_fast_tlv_parse *tlv,
1079 struct wpabuf **resp)
1081 int mandatory, tlv_type, len, res;
1084 os_memset(tlv, 0, sizeof(*tlv));
1086 /* Parse TLVs from the decrypted Phase 2 data */
1087 pos = wpabuf_mhead(decrypted);
1088 end = pos + wpabuf_len(decrypted);
1089 while (pos + 4 < end) {
1090 mandatory = pos[0] & 0x80;
1091 tlv_type = WPA_GET_BE16(pos) & 0x3fff;
1093 len = WPA_GET_BE16(pos);
1095 if (pos + len > end) {
1096 wpa_printf(MSG_INFO, "EAP-FAST: TLV overflow");
1099 wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: "
1100 "TLV type %d length %d%s",
1101 tlv_type, len, mandatory ? " (mandatory)" : "");
1103 res = eap_fast_parse_tlv(tlv, tlv_type, pos, len);
1108 wpa_printf(MSG_DEBUG, "EAP-FAST: Nak unknown "
1109 "mandatory TLV type %d", tlv_type);
1110 *resp = eap_fast_tlv_nak(0, tlv_type);
1113 wpa_printf(MSG_DEBUG, "EAP-FAST: ignored "
1114 "unknown optional TLV type %d",
1126 static int eap_fast_encrypt_response(struct eap_sm *sm,
1127 struct eap_fast_data *data,
1128 struct wpabuf *resp,
1129 u8 identifier, struct wpabuf **out_data)
1134 wpa_hexdump_buf(MSG_DEBUG, "EAP-FAST: Encrypting Phase 2 data",
1136 if (eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_FAST,
1137 data->fast_version, identifier,
1139 wpa_printf(MSG_INFO, "EAP-FAST: Failed to encrypt a Phase 2 "
1148 static struct wpabuf * eap_fast_pac_request(void)
1153 tmp = wpabuf_alloc(sizeof(struct eap_tlv_hdr) +
1154 sizeof(struct eap_tlv_request_action_tlv) +
1155 sizeof(struct eap_tlv_pac_type_tlv));
1159 pos = wpabuf_put(tmp, 0);
1160 pos2 = eap_fast_write_pac_request(pos, PAC_TYPE_TUNNEL_PAC);
1161 wpabuf_put(tmp, pos2 - pos);
1166 static int eap_fast_process_decrypted(struct eap_sm *sm,
1167 struct eap_fast_data *data,
1168 struct eap_method_ret *ret,
1169 const struct eap_hdr *req,
1170 struct wpabuf *decrypted,
1171 struct wpabuf **out_data)
1173 struct wpabuf *resp = NULL, *tmp;
1174 struct eap_fast_tlv_parse tlv;
1177 if (eap_fast_parse_decrypted(decrypted, &tlv, &resp) < 0)
1180 return eap_fast_encrypt_response(sm, data, resp,
1181 req->identifier, out_data);
1183 if (tlv.result == EAP_TLV_RESULT_FAILURE) {
1184 resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0);
1185 return eap_fast_encrypt_response(sm, data, resp,
1186 req->identifier, out_data);
1189 if (tlv.iresult == EAP_TLV_RESULT_FAILURE) {
1190 resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 1);
1191 return eap_fast_encrypt_response(sm, data, resp,
1192 req->identifier, out_data);
1195 if (tlv.crypto_binding) {
1196 tmp = eap_fast_process_crypto_binding(sm, data, ret,
1198 tlv.crypto_binding_len);
1202 resp = wpabuf_concat(resp, tmp);
1205 if (tlv.iresult == EAP_TLV_RESULT_SUCCESS) {
1206 tmp = eap_fast_tlv_result(failed ? EAP_TLV_RESULT_FAILURE :
1207 EAP_TLV_RESULT_SUCCESS, 1);
1208 resp = wpabuf_concat(resp, tmp);
1211 if (tlv.eap_payload_tlv) {
1212 tmp = eap_fast_process_eap_payload_tlv(
1213 sm, data, ret, tlv.eap_payload_tlv,
1214 tlv.eap_payload_tlv_len);
1215 resp = wpabuf_concat(resp, tmp);
1218 if (tlv.pac && tlv.result != EAP_TLV_RESULT_SUCCESS) {
1219 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV without Result TLV "
1220 "acknowledging success");
1222 } else if (tlv.pac && tlv.result == EAP_TLV_RESULT_SUCCESS) {
1223 tmp = eap_fast_process_pac(sm, data, ret, tlv.pac,
1225 resp = wpabuf_concat(resp, tmp);
1228 if (data->current_pac == NULL && data->provisioning &&
1229 !data->anon_provisioning && !tlv.pac &&
1230 (tlv.iresult == EAP_TLV_RESULT_SUCCESS ||
1231 tlv.result == EAP_TLV_RESULT_SUCCESS)) {
1233 * Need to request Tunnel PAC when using authenticated
1236 wpa_printf(MSG_DEBUG, "EAP-FAST: Request Tunnel PAC");
1237 tmp = eap_fast_pac_request();
1238 resp = wpabuf_concat(resp, tmp);
1241 if (tlv.result == EAP_TLV_RESULT_SUCCESS && !failed) {
1242 tmp = eap_fast_tlv_result(EAP_TLV_RESULT_SUCCESS, 0);
1243 resp = wpabuf_concat(tmp, resp);
1244 } else if (failed) {
1245 tmp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0);
1246 resp = wpabuf_concat(tmp, resp);
1249 if (resp && tlv.result == EAP_TLV_RESULT_SUCCESS && !failed &&
1250 tlv.crypto_binding && data->phase2_success) {
1251 if (data->anon_provisioning) {
1252 wpa_printf(MSG_DEBUG, "EAP-FAST: Unauthenticated "
1253 "provisioning completed successfully.");
1254 ret->methodState = METHOD_DONE;
1255 ret->decision = DECISION_FAIL;
1256 sm->expected_failure = 1;
1258 wpa_printf(MSG_DEBUG, "EAP-FAST: Authentication "
1259 "completed successfully.");
1260 if (data->provisioning)
1261 ret->methodState = METHOD_MAY_CONT;
1263 ret->methodState = METHOD_DONE;
1264 ret->decision = DECISION_UNCOND_SUCC;
1269 wpa_printf(MSG_DEBUG, "EAP-FAST: No recognized TLVs - send "
1270 "empty response packet");
1271 resp = wpabuf_alloc(1);
1274 return eap_fast_encrypt_response(sm, data, resp, req->identifier,
1279 static int eap_fast_decrypt(struct eap_sm *sm, struct eap_fast_data *data,
1280 struct eap_method_ret *ret,
1281 const struct eap_hdr *req,
1282 const struct wpabuf *in_data,
1283 struct wpabuf **out_data)
1285 struct wpabuf *in_decrypted;
1288 wpa_printf(MSG_DEBUG, "EAP-FAST: Received %lu bytes encrypted data for"
1289 " Phase 2", (unsigned long) wpabuf_len(in_data));
1291 if (data->pending_phase2_req) {
1292 wpa_printf(MSG_DEBUG, "EAP-FAST: Pending Phase 2 request - "
1293 "skip decryption and use old data");
1294 /* Clear TLS reassembly state. */
1295 eap_peer_tls_reset_input(&data->ssl);
1297 in_decrypted = data->pending_phase2_req;
1298 data->pending_phase2_req = NULL;
1302 if (wpabuf_len(in_data) == 0) {
1303 /* Received TLS ACK - requesting more fragments */
1304 return eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_FAST,
1306 req->identifier, NULL, out_data);
1309 res = eap_peer_tls_decrypt(sm, &data->ssl, in_data, &in_decrypted);
1314 wpa_hexdump_buf(MSG_MSGDUMP, "EAP-FAST: Decrypted Phase 2 TLV(s)",
1317 if (wpabuf_len(in_decrypted) < 4) {
1318 wpa_printf(MSG_INFO, "EAP-FAST: Too short Phase 2 "
1319 "TLV frame (len=%lu)",
1320 (unsigned long) wpabuf_len(in_decrypted));
1321 wpabuf_free(in_decrypted);
1325 res = eap_fast_process_decrypted(sm, data, ret, req,
1326 in_decrypted, out_data);
1328 wpabuf_free(in_decrypted);
1334 static const u8 * eap_fast_get_a_id(const u8 *buf, size_t len, size_t *id_len)
1337 struct pac_tlv_hdr *hdr;
1340 * Parse authority identity (A-ID) from the EAP-FAST/Start. This
1341 * supports both raw A-ID and one inside an A-ID TLV.
1345 if (len > sizeof(*hdr)) {
1347 hdr = (struct pac_tlv_hdr *) buf;
1348 tlen = be_to_host16(hdr->len);
1349 if (be_to_host16(hdr->type) == PAC_TYPE_A_ID &&
1350 sizeof(*hdr) + tlen <= len) {
1351 wpa_printf(MSG_DEBUG, "EAP-FAST: A-ID was in TLV "
1353 a_id = (u8 *) (hdr + 1);
1357 wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: A-ID", a_id, *id_len);
1363 static void eap_fast_select_pac(struct eap_fast_data *data,
1364 const u8 *a_id, size_t a_id_len)
1366 data->current_pac = eap_fast_get_pac(data->pac, a_id, a_id_len,
1367 PAC_TYPE_TUNNEL_PAC);
1368 if (data->current_pac == NULL) {
1370 * Tunnel PAC was not available for this A-ID. Try to use
1371 * Machine Authentication PAC, if one is available.
1373 data->current_pac = eap_fast_get_pac(
1374 data->pac, a_id, a_id_len,
1375 PAC_TYPE_MACHINE_AUTHENTICATION);
1378 if (data->current_pac) {
1379 wpa_printf(MSG_DEBUG, "EAP-FAST: PAC found for this A-ID "
1380 "(PAC-Type %d)", data->current_pac->pac_type);
1381 wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-FAST: A-ID-Info",
1382 data->current_pac->a_id_info,
1383 data->current_pac->a_id_info_len);
1388 static int eap_fast_use_pac_opaque(struct eap_sm *sm,
1389 struct eap_fast_data *data,
1390 struct eap_fast_pac *pac)
1393 size_t tlv_len, olen;
1394 struct eap_tlv_hdr *ehdr;
1396 olen = pac->pac_opaque_len;
1397 tlv_len = sizeof(*ehdr) + olen;
1398 tlv = os_malloc(tlv_len);
1400 ehdr = (struct eap_tlv_hdr *) tlv;
1401 ehdr->tlv_type = host_to_be16(PAC_TYPE_PAC_OPAQUE);
1402 ehdr->length = host_to_be16(olen);
1403 os_memcpy(ehdr + 1, pac->pac_opaque, olen);
1406 tls_connection_client_hello_ext(sm->ssl_ctx, data->ssl.conn,
1408 tlv, tlv_len) < 0) {
1409 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to add PAC-Opaque TLS "
1420 static int eap_fast_clear_pac_opaque_ext(struct eap_sm *sm,
1421 struct eap_fast_data *data)
1423 if (tls_connection_client_hello_ext(sm->ssl_ctx, data->ssl.conn,
1424 TLS_EXT_PAC_OPAQUE, NULL, 0) < 0) {
1425 wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to remove PAC-Opaque "
1433 static int eap_fast_set_provisioning_ciphers(struct eap_sm *sm,
1434 struct eap_fast_data *data)
1439 if (data->provisioning_allowed & EAP_FAST_PROV_UNAUTH) {
1440 wpa_printf(MSG_DEBUG, "EAP-FAST: Enabling unauthenticated "
1441 "provisioning TLS cipher suites");
1442 ciphers[count++] = TLS_CIPHER_ANON_DH_AES128_SHA;
1445 if (data->provisioning_allowed & EAP_FAST_PROV_AUTH) {
1446 wpa_printf(MSG_DEBUG, "EAP-FAST: Enabling authenticated "
1447 "provisioning TLS cipher suites");
1448 ciphers[count++] = TLS_CIPHER_RSA_DHE_AES128_SHA;
1449 ciphers[count++] = TLS_CIPHER_AES128_SHA;
1450 ciphers[count++] = TLS_CIPHER_RC4_SHA;
1453 ciphers[count++] = TLS_CIPHER_NONE;
1455 if (tls_connection_set_cipher_list(sm->ssl_ctx, data->ssl.conn,
1457 wpa_printf(MSG_INFO, "EAP-FAST: Could not configure TLS "
1458 "cipher suites for provisioning");
1466 static int eap_fast_process_start(struct eap_sm *sm,
1467 struct eap_fast_data *data, u8 flags,
1468 const u8 *pos, size_t left)
1473 /* EAP-FAST Version negotiation (section 3.1) */
1474 wpa_printf(MSG_DEBUG, "EAP-FAST: Start (server ver=%d, own ver=%d)",
1475 flags & EAP_TLS_VERSION_MASK, data->fast_version);
1476 if ((flags & EAP_TLS_VERSION_MASK) < data->fast_version)
1477 data->fast_version = flags & EAP_TLS_VERSION_MASK;
1478 wpa_printf(MSG_DEBUG, "EAP-FAST: Using FAST version %d",
1479 data->fast_version);
1481 a_id = eap_fast_get_a_id(pos, left, &a_id_len);
1482 eap_fast_select_pac(data, a_id, a_id_len);
1484 if (data->resuming && data->current_pac) {
1485 wpa_printf(MSG_DEBUG, "EAP-FAST: Trying to resume session - "
1486 "do not add PAC-Opaque to TLS ClientHello");
1487 if (eap_fast_clear_pac_opaque_ext(sm, data) < 0)
1489 } else if (data->current_pac) {
1491 * PAC found for the A-ID and we are not resuming an old
1492 * session, so add PAC-Opaque extension to ClientHello.
1494 if (eap_fast_use_pac_opaque(sm, data, data->current_pac) < 0)
1497 /* No PAC found, so we must provision one. */
1498 if (!data->provisioning_allowed) {
1499 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC found and "
1500 "provisioning disabled");
1503 wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC found - "
1504 "starting provisioning");
1505 if (eap_fast_set_provisioning_ciphers(sm, data) < 0 ||
1506 eap_fast_clear_pac_opaque_ext(sm, data) < 0)
1508 data->provisioning = 1;
1515 static struct wpabuf * eap_fast_process(struct eap_sm *sm, void *priv,
1516 struct eap_method_ret *ret,
1517 const struct wpabuf *reqData)
1519 const struct eap_hdr *req;
1523 struct wpabuf *resp;
1525 struct eap_fast_data *data = priv;
1527 pos = eap_peer_tls_process_init(sm, &data->ssl, EAP_TYPE_FAST, ret,
1528 reqData, &left, &flags);
1532 req = wpabuf_head(reqData);
1533 id = req->identifier;
1535 if (flags & EAP_TLS_FLAGS_START) {
1536 if (eap_fast_process_start(sm, data, flags, pos, left) < 0)
1539 left = 0; /* A-ID is not used in further packet processing */
1543 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn) &&
1545 /* Process tunneled (encrypted) phase 2 data. */
1547 wpabuf_set(&msg, pos, left);
1548 res = eap_fast_decrypt(sm, data, ret, req, &msg, &resp);
1550 ret->methodState = METHOD_DONE;
1551 ret->decision = DECISION_FAIL;
1553 * Ack possible Alert that may have caused failure in
1559 /* Continue processing TLS handshake (phase 1). */
1560 res = eap_peer_tls_process_helper(sm, &data->ssl,
1562 data->fast_version, id, pos,
1565 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn)) {
1567 wpa_printf(MSG_DEBUG,
1568 "EAP-FAST: TLS done, proceed to Phase 2");
1569 if (data->provisioning &&
1570 (!(data->provisioning_allowed &
1571 EAP_FAST_PROV_AUTH) ||
1572 tls_get_cipher(sm->ssl_ctx, data->ssl.conn,
1573 cipher, sizeof(cipher)) < 0 ||
1574 os_strstr(cipher, "ADH-") ||
1575 os_strstr(cipher, "anon"))) {
1576 wpa_printf(MSG_DEBUG, "EAP-FAST: Using "
1577 "anonymous (unauthenticated) "
1579 data->anon_provisioning = 1;
1581 data->anon_provisioning = 0;
1583 eap_fast_derive_keys(sm, data);
1589 * Application data included in the handshake message.
1591 wpabuf_free(data->pending_phase2_req);
1592 data->pending_phase2_req = resp;
1594 wpabuf_set(&msg, pos, left);
1595 res = eap_fast_decrypt(sm, data, ret, req, &msg,
1602 return eap_peer_tls_build_ack(id, EAP_TYPE_FAST,
1603 data->fast_version);
1611 static Boolean eap_fast_has_reauth_data(struct eap_sm *sm, void *priv)
1613 struct eap_fast_data *data = priv;
1614 return tls_connection_established(sm->ssl_ctx, data->ssl.conn);
1618 static void eap_fast_deinit_for_reauth(struct eap_sm *sm, void *priv)
1620 struct eap_fast_data *data = priv;
1621 os_free(data->key_block_p);
1622 data->key_block_p = NULL;
1623 wpabuf_free(data->pending_phase2_req);
1624 data->pending_phase2_req = NULL;
1628 static void * eap_fast_init_for_reauth(struct eap_sm *sm, void *priv)
1630 struct eap_fast_data *data = priv;
1631 if (eap_peer_tls_reauth_init(sm, &data->ssl)) {
1635 os_free(data->session_id);
1636 data->session_id = NULL;
1637 if (data->phase2_priv && data->phase2_method &&
1638 data->phase2_method->init_for_reauth)
1639 data->phase2_method->init_for_reauth(sm, data->phase2_priv);
1640 data->phase2_success = 0;
1642 data->provisioning = 0;
1643 data->anon_provisioning = 0;
1644 data->simck_idx = 0;
1650 static int eap_fast_get_status(struct eap_sm *sm, void *priv, char *buf,
1651 size_t buflen, int verbose)
1653 struct eap_fast_data *data = priv;
1656 len = eap_peer_tls_status(sm, &data->ssl, buf, buflen, verbose);
1657 if (data->phase2_method) {
1658 ret = os_snprintf(buf + len, buflen - len,
1659 "EAP-FAST Phase2 method=%s\n",
1660 data->phase2_method->name);
1661 if (ret < 0 || (size_t) ret >= buflen - len)
1669 static Boolean eap_fast_isKeyAvailable(struct eap_sm *sm, void *priv)
1671 struct eap_fast_data *data = priv;
1672 return data->success;
1676 static u8 * eap_fast_getKey(struct eap_sm *sm, void *priv, size_t *len)
1678 struct eap_fast_data *data = priv;
1684 key = os_malloc(EAP_FAST_KEY_LEN);
1688 *len = EAP_FAST_KEY_LEN;
1689 os_memcpy(key, data->key_data, EAP_FAST_KEY_LEN);
1695 static u8 * eap_fast_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
1697 struct eap_fast_data *data = priv;
1703 id = os_malloc(data->id_len);
1707 *len = data->id_len;
1708 os_memcpy(id, data->session_id, data->id_len);
1714 static u8 * eap_fast_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
1716 struct eap_fast_data *data = priv;
1722 key = os_malloc(EAP_EMSK_LEN);
1726 *len = EAP_EMSK_LEN;
1727 os_memcpy(key, data->emsk, EAP_EMSK_LEN);
1733 int eap_peer_fast_register(void)
1735 struct eap_method *eap;
1738 eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
1739 EAP_VENDOR_IETF, EAP_TYPE_FAST, "FAST");
1743 eap->init = eap_fast_init;
1744 eap->deinit = eap_fast_deinit;
1745 eap->process = eap_fast_process;
1746 eap->isKeyAvailable = eap_fast_isKeyAvailable;
1747 eap->getKey = eap_fast_getKey;
1748 eap->getSessionId = eap_fast_get_session_id;
1749 eap->get_status = eap_fast_get_status;
1751 eap->has_reauth_data = eap_fast_has_reauth_data;
1752 eap->deinit_for_reauth = eap_fast_deinit_for_reauth;
1753 eap->init_for_reauth = eap_fast_init_for_reauth;
1755 eap->get_emsk = eap_fast_get_emsk;
1757 ret = eap_peer_method_register(eap);
1759 eap_peer_method_free(eap);