eap_server_fast.c revision 8d520ff1dc2da35cdca849e982051b86468016d8
18d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt/* 28d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * EAP-FAST server (RFC 4851) 38d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi> 48d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * 58d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * This program is free software; you can redistribute it and/or modify 68d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * it under the terms of the GNU General Public License version 2 as 78d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * published by the Free Software Foundation. 88d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * 98d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Alternatively, this software may be distributed under the terms of BSD 108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * license. 118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * 128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * See README and COPYING for more details. 138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "includes.h" 168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "common.h" 188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "crypto/aes_wrap.h" 198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "crypto/sha1.h" 208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "crypto/tls.h" 218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "crypto/random.h" 228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "eap_common/eap_tlv_common.h" 238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "eap_common/eap_fast_common.h" 248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "eap_i.h" 258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "eap_tls_common.h" 268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_reset(struct eap_sm *sm, void *priv); 298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt/* Private PAC-Opaque TLV types */ 328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define PAC_OPAQUE_TYPE_PAD 0 338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define PAC_OPAQUE_TYPE_KEY 1 348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define PAC_OPAQUE_TYPE_LIFETIME 2 358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define PAC_OPAQUE_TYPE_IDENTITY 3 368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstruct eap_fast_data { 388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_ssl_data ssl; 398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt enum { 408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt START, PHASE1, PHASE2_START, PHASE2_ID, PHASE2_METHOD, 418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt CRYPTO_BINDING, REQUEST_PAC, SUCCESS, FAILURE 428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } state; 438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int fast_version; 458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt const struct eap_method *phase2_method; 468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt void *phase2_priv; 478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int force_version; 488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int peer_version; 498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 crypto_binding_nonce[32]; 518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int final_result; 528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_key_block_provisioning *key_block_p; 548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 simck[EAP_FAST_SIMCK_LEN]; 568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 cmk[EAP_FAST_CMK_LEN]; 578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int simck_idx; 588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 pac_opaque_encr[16]; 608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *srv_id; 618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t srv_id_len; 628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt char *srv_id_info; 638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int anon_provisioning; 658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int send_new_pac; /* server triggered re-keying of Tunnel PAC */ 668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *pending_phase2_resp; 678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *identity; /* from PAC-Opaque */ 688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t identity_len; 698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int eap_seq; 708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int tnc_started; 718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int pac_key_lifetime; 738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int pac_key_refresh_time; 748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt}; 758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_process_phase2_start(struct eap_sm *sm, 788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data); 798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic const char * eap_fast_state_txt(int state) 828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (state) { 848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case START: 858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "START"; 868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE1: 878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "PHASE1"; 888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_START: 898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "PHASE2_START"; 908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_ID: 918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "PHASE2_ID"; 928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_METHOD: 938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "PHASE2_METHOD"; 948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case CRYPTO_BINDING: 958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "CRYPTO_BINDING"; 968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case REQUEST_PAC: 978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "REQUEST_PAC"; 988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case SUCCESS: 998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "SUCCESS"; 1008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case FAILURE: 1018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "FAILURE"; 1028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt default: 1038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return "Unknown?!"; 1048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 1058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_state(struct eap_fast_data *data, int state) 1098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 1108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: %s -> %s", 1118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state_txt(data->state), 1128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state_txt(state)); 1138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->state = state; 1148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic EapType eap_fast_req_failure(struct eap_sm *sm, 1188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data) 1198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 1208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* TODO: send Result TLV(FAILURE) */ 1218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 1228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return EAP_TYPE_NONE; 1238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_session_ticket_cb(void *ctx, const u8 *ticket, size_t len, 1278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt const u8 *client_random, 1288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt const u8 *server_random, 1298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *master_secret) 1308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 1318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = ctx; 1328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt const u8 *pac_opaque; 1338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t pac_opaque_len; 1348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *buf, *pos, *end, *pac_key = NULL; 1358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_time_t lifetime = 0; 1368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct os_time now; 1378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *identity = NULL; 1388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t identity_len = 0; 1398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: SessionTicket callback"); 1418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_DEBUG, "EAP-FAST: SessionTicket (PAC-Opaque)", 1428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ticket, len); 1438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (len < 4 || WPA_GET_BE16(ticket) != PAC_TYPE_PAC_OPAQUE) { 1458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Ignore invalid " 1468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "SessionTicket"); 1478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 1488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 1498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_opaque_len = WPA_GET_BE16(ticket + 2); 1518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_opaque = ticket + 4; 1528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pac_opaque_len < 8 || pac_opaque_len % 8 || 1538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_opaque_len > len - 4) { 1548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Ignore invalid PAC-Opaque " 1558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "(len=%lu left=%lu)", 1568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (unsigned long) pac_opaque_len, 1578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (unsigned long) len); 1588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 1598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 1608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_DEBUG, "EAP-FAST: Received PAC-Opaque", 1618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_opaque, pac_opaque_len); 1628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt buf = os_malloc(pac_opaque_len - 8); 1648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (buf == NULL) { 1658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to allocate memory " 1668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "for decrypting PAC-Opaque"); 1678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 1688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 1698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (aes_unwrap(data->pac_opaque_encr, (pac_opaque_len - 8) / 8, 1718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_opaque, buf) < 0) { 1728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to decrypt " 1738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "PAC-Opaque"); 1748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 1758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 1768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * This may have been caused by server changing the PAC-Opaque 1778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * encryption key, so just ignore this PAC-Opaque instead of 1788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * failing the authentication completely. Provisioning can now 1798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * be used to provision a new PAC. 1808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 1818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 1828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 1838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt end = buf + pac_opaque_len - 8; 1858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Decrypted PAC-Opaque", 1868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt buf, end - buf); 1878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos = buf; 1898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt while (pos + 1 < end) { 1908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pos + 2 + pos[1] > end) 1918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 1928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (*pos) { 1948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PAC_OPAQUE_TYPE_PAD: 1958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos = end; 1968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 1978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PAC_OPAQUE_TYPE_KEY: 1988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pos[1] != EAP_FAST_PAC_KEY_LEN) { 1998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid " 2008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "PAC-Key length %d", pos[1]); 2018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 2028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 2038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_key = pos + 2; 2058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: PAC-Key from " 2068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "decrypted PAC-Opaque", 2078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_key, EAP_FAST_PAC_KEY_LEN); 2088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 2098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PAC_OPAQUE_TYPE_LIFETIME: 2108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pos[1] != 4) { 2118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid " 2128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "PAC-Key lifetime length %d", 2138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos[1]); 2148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 2158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 2168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt lifetime = WPA_GET_BE32(pos + 2); 2188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 2198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PAC_OPAQUE_TYPE_IDENTITY: 2208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt identity = pos + 2; 2218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt identity_len = pos[1]; 2228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 2238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += 2 + pos[1]; 2268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pac_key == NULL) { 2298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC-Key included in " 2308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "PAC-Opaque"); 2318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 2328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 2338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (identity) { 2368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: Identity from " 2378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "PAC-Opaque", identity, identity_len); 2388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(data->identity); 2398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->identity = os_malloc(identity_len); 2408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->identity) { 2418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(data->identity, identity, identity_len); 2428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->identity_len = identity_len; 2438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (os_get_time(&now) < 0 || lifetime <= 0 || now.sec > lifetime) { 2478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Key not valid anymore " 2488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "(lifetime=%ld now=%ld)", lifetime, now.sec); 2498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->send_new_pac = 2; 2508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 2518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Allow PAC to be used to allow a PAC update with some level 2528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * of server authentication (i.e., do not fall back to full TLS 2538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * handshake since we cannot be sure that the peer would be 2548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * able to validate server certificate now). However, reject 2558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * the authentication since the PAC was not valid anymore. Peer 2568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * can connect again with the newly provisioned PAC after this. 2578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 2588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else if (lifetime - now.sec < data->pac_key_refresh_time) { 2598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Key soft timeout; send " 2608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "an update if authentication succeeds"); 2618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->send_new_pac = 1; 2628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_derive_master_secret(pac_key, server_random, client_random, 2658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt master_secret); 2668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 2688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 1; 2708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 2718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_derive_key_auth(struct eap_sm *sm, 2748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data) 2758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 2768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *sks; 2778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* RFC 4851, Section 5.1: 2798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Extra key material after TLS key_block: session_key_seed[40] 2808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 2818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sks = eap_fast_derive_key(sm->ssl_ctx, data->ssl.conn, "key expansion", 2838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_FAST_SKS_LEN); 2848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sks == NULL) { 2858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive " 2868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "session_key_seed"); 2878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 2888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 2918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * RFC 4851, Section 5.2: 2928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * S-IMCK[0] = session_key_seed 2938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 2948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_DEBUG, 2958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "EAP-FAST: session_key_seed (SKS = S-IMCK[0])", 2968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sks, EAP_FAST_SKS_LEN); 2978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->simck_idx = 0; 2988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(data->simck, sks, EAP_FAST_SIMCK_LEN); 2998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(sks); 3008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 3018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_derive_key_provisioning(struct eap_sm *sm, 3048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data) 3058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 3068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(data->key_block_p); 3078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->key_block_p = (struct eap_fast_key_block_provisioning *) 3088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_derive_key(sm->ssl_ctx, data->ssl.conn, 3098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "key expansion", 3108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(*data->key_block_p)); 3118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->key_block_p == NULL) { 3128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive key block"); 3138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 3148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 3158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 3168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * RFC 4851, Section 5.2: 3178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * S-IMCK[0] = session_key_seed 3188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 3198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_DEBUG, 3208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "EAP-FAST: session_key_seed (SKS = S-IMCK[0])", 3218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->key_block_p->session_key_seed, 3228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(data->key_block_p->session_key_seed)); 3238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->simck_idx = 0; 3248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(data->simck, data->key_block_p->session_key_seed, 3258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_FAST_SIMCK_LEN); 3268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: server_challenge", 3278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->key_block_p->server_challenge, 3288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(data->key_block_p->server_challenge)); 3298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: client_challenge", 3308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->key_block_p->client_challenge, 3318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(data->key_block_p->client_challenge)); 3328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 3338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_get_phase2_key(struct eap_sm *sm, 3368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data, 3378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *isk, size_t isk_len) 3388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 3398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *key; 3408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t key_len; 3418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(isk, 0, isk_len); 3438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->phase2_method == NULL || data->phase2_priv == NULL) { 3458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not " 3468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "available"); 3478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 3488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 3498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->phase2_method->getKey == NULL) 3518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 3528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if ((key = data->phase2_method->getKey(sm, data->phase2_priv, 3548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt &key_len)) == NULL) { 3558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Could not get key material " 3568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "from Phase 2"); 3578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 3588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 3598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (key_len > isk_len) 3618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt key_len = isk_len; 3628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (key_len == 32 && 3638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->phase2_method->vendor == EAP_VENDOR_IETF && 3648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->phase2_method->method == EAP_TYPE_MSCHAPV2) { 3658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 3668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * EAP-FAST uses reverse order for MS-MPPE keys when deriving 3678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * MSK from EAP-MSCHAPv2. Swap the keys here to get the correct 3688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * ISK for EAP-FAST cryptobinding. 3698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 3708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(isk, key + 16, 16); 3718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(isk + 16, key, 16); 3728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else 3738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(isk, key, key_len); 3748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(key); 3758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 3778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 3788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_update_icmk(struct eap_sm *sm, struct eap_fast_data *data) 3818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 3828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 isk[32], imck[60]; 3838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Deriving ICMK[%d] (S-IMCK and CMK)", 3858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->simck_idx + 1); 3868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 3888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * RFC 4851, Section 5.2: 3898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * IMCK[j] = T-PRF(S-IMCK[j-1], "Inner Methods Compound Keys", 3908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * MSK[j], 60) 3918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * S-IMCK[j] = first 40 octets of IMCK[j] 3928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * CMK[j] = last 20 octets of IMCK[j] 3938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 3948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_fast_get_phase2_key(sm, data, isk, sizeof(isk)) < 0) 3968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 3978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: ISK[j]", isk, sizeof(isk)); 3988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sha1_t_prf(data->simck, EAP_FAST_SIMCK_LEN, 3998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Inner Methods Compound Keys", 4008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt isk, sizeof(isk), imck, sizeof(imck)); 4018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->simck_idx++; 4028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(data->simck, imck, EAP_FAST_SIMCK_LEN); 4038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: S-IMCK[j]", 4048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->simck, EAP_FAST_SIMCK_LEN); 4058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(data->cmk, imck + EAP_FAST_SIMCK_LEN, EAP_FAST_CMK_LEN); 4068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: CMK[j]", 4078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->cmk, EAP_FAST_CMK_LEN); 4088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 4108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 4118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void * eap_fast_init(struct eap_sm *sm) 4148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 4158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data; 4168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 ciphers[5] = { 4178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt TLS_CIPHER_ANON_DH_AES128_SHA, 4188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt TLS_CIPHER_AES128_SHA, 4198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt TLS_CIPHER_RSA_DHE_AES128_SHA, 4208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt TLS_CIPHER_RC4_SHA, 4218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt TLS_CIPHER_NONE 4228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt }; 4238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data = os_zalloc(sizeof(*data)); 4258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data == NULL) 4268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 4278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->fast_version = EAP_FAST_VERSION; 4288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->force_version = -1; 4298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->user && sm->user->force_version >= 0) { 4308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->force_version = sm->user->force_version; 4318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: forcing version %d", 4328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->force_version); 4338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->fast_version = data->force_version; 4348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->state = START; 4368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_server_tls_ssl_init(sm, &data->ssl, 0)) { 4388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize SSL."); 4398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_reset(sm, data); 4408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 4418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (tls_connection_set_cipher_list(sm->ssl_ctx, data->ssl.conn, 4448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ciphers) < 0) { 4458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: Failed to set TLS cipher " 4468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "suites"); 4478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_reset(sm, data); 4488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 4498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (tls_connection_set_session_ticket_cb(sm->ssl_ctx, data->ssl.conn, 4528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_session_ticket_cb, 4538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data) < 0) { 4548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: Failed to set SessionTicket " 4558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "callback"); 4568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_reset(sm, data); 4578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 4588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->pac_opaque_encr_key == NULL) { 4618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: No PAC-Opaque encryption key " 4628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "configured"); 4638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_reset(sm, data); 4648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 4658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(data->pac_opaque_encr, sm->pac_opaque_encr_key, 4678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(data->pac_opaque_encr)); 4688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->eap_fast_a_id == NULL) { 4708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: No A-ID configured"); 4718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_reset(sm, data); 4728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 4738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->srv_id = os_malloc(sm->eap_fast_a_id_len); 4758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->srv_id == NULL) { 4768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_reset(sm, data); 4778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 4788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(data->srv_id, sm->eap_fast_a_id, sm->eap_fast_a_id_len); 4808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->srv_id_len = sm->eap_fast_a_id_len; 4818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->eap_fast_a_id_info == NULL) { 4838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: No A-ID-Info configured"); 4848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_reset(sm, data); 4858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 4868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->srv_id_info = os_strdup(sm->eap_fast_a_id_info); 4888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->srv_id_info == NULL) { 4898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_reset(sm, data); 4908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 4918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* PAC-Key lifetime in seconds (hard limit) */ 4948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->pac_key_lifetime = sm->pac_key_lifetime; 4958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 4978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * PAC-Key refresh time in seconds (soft limit on remaining hard 4988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * limit). The server will generate a new PAC-Key when this number of 4998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * seconds (or fewer) of the lifetime remains. 5008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 5018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->pac_key_refresh_time = sm->pac_key_refresh_time; 5028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return data; 5048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 5058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_reset(struct eap_sm *sm, void *priv) 5088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 5098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = priv; 5108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data == NULL) 5118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 5128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->phase2_priv && data->phase2_method) 5138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->phase2_method->reset(sm, data->phase2_priv); 5148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_server_tls_ssl_deinit(sm, &data->ssl); 5158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(data->srv_id); 5168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(data->srv_id_info); 5178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(data->key_block_p); 5188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_free(data->pending_phase2_resp); 5198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(data->identity); 5208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(data); 5218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 5228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic struct wpabuf * eap_fast_build_start(struct eap_sm *sm, 5258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data, u8 id) 5268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 5278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *req; 5288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_FAST, 5308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1 + sizeof(struct pac_tlv_hdr) + data->srv_id_len, 5318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_CODE_REQUEST, id); 5328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (req == NULL) { 5338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "EAP-FAST: Failed to allocate memory for" 5348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt " request"); 5358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 5368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 5378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 5388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_put_u8(req, EAP_TLS_FLAGS_START | data->fast_version); 5408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* RFC 4851, 4.1.1. Authority ID Data */ 5428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_put_tlv(req, PAC_TYPE_A_ID, data->srv_id, data->srv_id_len); 5438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, PHASE1); 5458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return req; 5478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 5488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_phase1_done(struct eap_sm *sm, struct eap_fast_data *data) 5518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 5528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt char cipher[64]; 5538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Phase1 done, starting Phase2"); 5558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (tls_get_cipher(sm->ssl_ctx, data->ssl.conn, cipher, sizeof(cipher)) 5578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt < 0) { 5588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to get cipher " 5598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "information"); 5608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 5618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 5628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 5638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->anon_provisioning = os_strstr(cipher, "ADH") != NULL; 5648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->anon_provisioning) { 5668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Anonymous provisioning"); 5678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_derive_key_provisioning(sm, data); 5688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else 5698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_derive_key_auth(sm, data); 5708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, PHASE2_START); 5728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 5748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 5758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic struct wpabuf * eap_fast_build_phase2_req(struct eap_sm *sm, 5788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data, 5798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 id) 5808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 5818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *req; 5828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->phase2_priv == NULL) { 5848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not " 5858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "initialized"); 5868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 5878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 5888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt req = data->phase2_method->buildReq(sm, data->phase2_priv, id); 5898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (req == NULL) 5908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 5918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_buf_key(MSG_MSGDUMP, "EAP-FAST: Phase 2 EAP-Request", req); 5938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return eap_fast_tlv_eap_payload(req); 5948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 5958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic struct wpabuf * eap_fast_build_crypto_binding( 5988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_sm *sm, struct eap_fast_data *data) 5998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 6008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *buf; 6018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_tlv_result_tlv *result; 6028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_tlv_crypto_binding_tlv *binding; 6038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt buf = wpabuf_alloc(2 * sizeof(*result) + sizeof(*binding)); 6058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (buf == NULL) 6068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 6078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->send_new_pac || data->anon_provisioning || 6098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->phase2_method) 6108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->final_result = 0; 6118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt else 6128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->final_result = 1; 6138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!data->final_result || data->eap_seq > 1) { 6158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* Intermediate-Result */ 6168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Add Intermediate-Result TLV " 6178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "(status=SUCCESS)"); 6188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result = wpabuf_put(buf, sizeof(*result)); 6198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->tlv_type = host_to_be16( 6208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_TLV_TYPE_MANDATORY | 6218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_TLV_INTERMEDIATE_RESULT_TLV); 6228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->length = host_to_be16(2); 6238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->status = host_to_be16(EAP_TLV_RESULT_SUCCESS); 6248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 6258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->final_result) { 6278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* Result TLV */ 6288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Add Result TLV " 6298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "(status=SUCCESS)"); 6308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result = wpabuf_put(buf, sizeof(*result)); 6318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY | 6328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_TLV_RESULT_TLV); 6338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->length = host_to_be16(2); 6348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->status = host_to_be16(EAP_TLV_RESULT_SUCCESS); 6358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 6368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* Crypto-Binding TLV */ 6388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding = wpabuf_put(buf, sizeof(*binding)); 6398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY | 6408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_TLV_CRYPTO_BINDING_TLV); 6418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->length = host_to_be16(sizeof(*binding) - 6428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(struct eap_tlv_hdr)); 6438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->version = EAP_FAST_VERSION; 6448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->received_version = data->peer_version; 6458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->subtype = EAP_TLV_CRYPTO_BINDING_SUBTYPE_REQUEST; 6468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (random_get_bytes(binding->nonce, sizeof(binding->nonce)) < 0) { 6478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_free(buf); 6488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 6498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 6508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 6528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * RFC 4851, Section 4.2.8: 6538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * The nonce in a request MUST have its least significant bit set to 0. 6548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 6558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->nonce[sizeof(binding->nonce) - 1] &= ~0x01; 6568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(data->crypto_binding_nonce, binding->nonce, 6588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(binding->nonce)); 6598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 6618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * RFC 4851, Section 5.3: 6628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * CMK = CMK[j] 6638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Compound-MAC = HMAC-SHA1( CMK, Crypto-Binding TLV ) 6648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 6658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt hmac_sha1(data->cmk, EAP_FAST_CMK_LEN, 6678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (u8 *) binding, sizeof(*binding), 6688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->compound_mac); 6698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Add Crypto-Binding TLV: Version %d " 6718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Received Version %d SubType %d", 6728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->version, binding->received_version, 6738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->subtype); 6748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE", 6758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->nonce, sizeof(binding->nonce)); 6768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC", 6778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt binding->compound_mac, sizeof(binding->compound_mac)); 6788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return buf; 6808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 6818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic struct wpabuf * eap_fast_build_pac(struct eap_sm *sm, 6848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data) 6858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 6868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 pac_key[EAP_FAST_PAC_KEY_LEN]; 6878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *pac_buf, *pac_opaque; 6888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *buf; 6898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *pos; 6908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t buf_len, srv_id_info_len, pac_len; 6918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_tlv_hdr *pac_tlv; 6928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct pac_tlv_hdr *pac_info; 6938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_tlv_result_tlv *result; 6948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct os_time now; 6958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (random_get_bytes(pac_key, EAP_FAST_PAC_KEY_LEN) < 0 || 6978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_get_time(&now) < 0) 6988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 6998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Generated PAC-Key", 7008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_key, EAP_FAST_PAC_KEY_LEN); 7018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_len = (2 + EAP_FAST_PAC_KEY_LEN) + (2 + 4) + 7038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (2 + sm->identity_len) + 8; 7048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_buf = os_malloc(pac_len); 7058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pac_buf == NULL) 7068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 7078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt srv_id_info_len = os_strlen(data->srv_id_info); 7098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos = pac_buf; 7118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = PAC_OPAQUE_TYPE_KEY; 7128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = EAP_FAST_PAC_KEY_LEN; 7138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(pos, pac_key, EAP_FAST_PAC_KEY_LEN); 7148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += EAP_FAST_PAC_KEY_LEN; 7158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = PAC_OPAQUE_TYPE_LIFETIME; 7178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = 4; 7188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_PUT_BE32(pos, now.sec + data->pac_key_lifetime); 7198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += 4; 7208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->identity) { 7228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = PAC_OPAQUE_TYPE_IDENTITY; 7238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = sm->identity_len; 7248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(pos, sm->identity, sm->identity_len); 7258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += sm->identity_len; 7268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_len = pos - pac_buf; 7298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt while (pac_len % 8) { 7308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = PAC_OPAQUE_TYPE_PAD; 7318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_len++; 7328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_opaque = os_malloc(pac_len + 8); 7358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pac_opaque == NULL) { 7368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(pac_buf); 7378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 7388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (aes_wrap(data->pac_opaque_encr, pac_len / 8, pac_buf, 7408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_opaque) < 0) { 7418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(pac_buf); 7428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(pac_opaque); 7438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 7448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(pac_buf); 7468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_len += 8; 7488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Opaque", 7498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_opaque, pac_len); 7508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt buf_len = sizeof(*pac_tlv) + 7528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(struct pac_tlv_hdr) + EAP_FAST_PAC_KEY_LEN + 7538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(struct pac_tlv_hdr) + pac_len + 7548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->srv_id_len + srv_id_info_len + 100 + sizeof(*result); 7558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt buf = wpabuf_alloc(buf_len); 7568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (buf == NULL) { 7578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(pac_opaque); 7588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 7598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* Result TLV */ 7628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Add Result TLV (status=SUCCESS)"); 7638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result = wpabuf_put(buf, sizeof(*result)); 7648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_PUT_BE16((u8 *) &result->tlv_type, 7658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_TLV_TYPE_MANDATORY | EAP_TLV_RESULT_TLV); 7668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_PUT_BE16((u8 *) &result->length, 2); 7678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_PUT_BE16((u8 *) &result->status, EAP_TLV_RESULT_SUCCESS); 7688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* PAC TLV */ 7708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Add PAC TLV"); 7718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_tlv = wpabuf_put(buf, sizeof(*pac_tlv)); 7728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_tlv->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY | 7738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_TLV_PAC_TLV); 7748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* PAC-Key */ 7768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_put_tlv(buf, PAC_TYPE_PAC_KEY, pac_key, EAP_FAST_PAC_KEY_LEN); 7778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* PAC-Opaque */ 7798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_put_tlv(buf, PAC_TYPE_PAC_OPAQUE, pac_opaque, pac_len); 7808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(pac_opaque); 7818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* PAC-Info */ 7838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_info = wpabuf_put(buf, sizeof(*pac_info)); 7848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_info->type = host_to_be16(PAC_TYPE_PAC_INFO); 7858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* PAC-Lifetime (inside PAC-Info) */ 7878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_put_tlv_hdr(buf, PAC_TYPE_CRED_LIFETIME, 4); 7888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_put_be32(buf, now.sec + data->pac_key_lifetime); 7898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* A-ID (inside PAC-Info) */ 7918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_put_tlv(buf, PAC_TYPE_A_ID, data->srv_id, data->srv_id_len); 7928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* Note: headers may be misaligned after A-ID */ 7948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->identity) { 7968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_put_tlv(buf, PAC_TYPE_I_ID, sm->identity, 7978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->identity_len); 7988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* A-ID-Info (inside PAC-Info) */ 8018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_put_tlv(buf, PAC_TYPE_A_ID_INFO, data->srv_id_info, 8028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt srv_id_info_len); 8038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* PAC-Type (inside PAC-Info) */ 8058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_put_tlv_hdr(buf, PAC_TYPE_PAC_TYPE, 2); 8068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_put_be16(buf, PAC_TYPE_TUNNEL_PAC); 8078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* Update PAC-Info and PAC TLV Length fields */ 8098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos = wpabuf_put(buf, 0); 8108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_info->len = host_to_be16(pos - (u8 *) (pac_info + 1)); 8118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pac_tlv->length = host_to_be16(pos - (u8 *) (pac_tlv + 1)); 8128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return buf; 8148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 8158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_encrypt_phase2(struct eap_sm *sm, 8188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data, 8198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *plain, int piggyback) 8208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 8218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *encr; 8228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_buf_key(MSG_DEBUG, "EAP-FAST: Encrypting Phase 2 TLVs", 8248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt plain); 8258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt encr = eap_server_tls_encrypt(sm, &data->ssl, plain); 8268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_free(plain); 8278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->ssl.tls_out && piggyback) { 8298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Piggyback Phase 2 data " 8308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "(len=%d) with last Phase 1 Message (len=%d " 8318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "used=%d)", 8328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (int) wpabuf_len(encr), 8338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (int) wpabuf_len(data->ssl.tls_out), 8348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (int) data->ssl.tls_out_pos); 8358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (wpabuf_resize(&data->ssl.tls_out, wpabuf_len(encr)) < 0) { 8368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_WARNING, "EAP-FAST: Failed to resize " 8378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "output buffer"); 8388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_free(encr); 8398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 8408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_put_buf(data->ssl.tls_out, encr); 8428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_free(encr); 8438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 8448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_free(data->ssl.tls_out); 8458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->ssl.tls_out_pos = 0; 8468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->ssl.tls_out = encr; 8478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 8508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 8518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic struct wpabuf * eap_fast_buildReq(struct eap_sm *sm, void *priv, u8 id) 8548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 8558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = priv; 8568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *req = NULL; 8578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int piggyback = 0; 8588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->ssl.state == FRAG_ACK) { 8608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return eap_server_tls_build_ack(id, EAP_TYPE_FAST, 8618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->fast_version); 8628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->ssl.state == WAIT_FRAG_ACK) { 8658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return eap_server_tls_build_msg(&data->ssl, EAP_TYPE_FAST, 8668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->fast_version, id); 8678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (data->state) { 8708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case START: 8718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return eap_fast_build_start(sm, data, id); 8728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE1: 8738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (tls_connection_established(sm->ssl_ctx, data->ssl.conn)) { 8748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_fast_phase1_done(sm, data) < 0) 8758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 8768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->state == PHASE2_START) { 8778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 8788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Try to generate Phase 2 data to piggyback 8798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * with the end of Phase 1 to avoid extra 8808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * roundtrip. 8818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 8828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Try to start " 8838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Phase 2"); 8848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_fast_process_phase2_start(sm, data)) 8858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 8868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt req = eap_fast_build_phase2_req(sm, data, id); 8878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt piggyback = 1; 8888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 8918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_ID: 8928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_METHOD: 8938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt req = eap_fast_build_phase2_req(sm, data, id); 8948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 8958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case CRYPTO_BINDING: 8968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt req = eap_fast_build_crypto_binding(sm, data); 8978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->phase2_method) { 8988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 8998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Include the start of the next EAP method in the 9008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * sequence in the same message with Crypto-Binding to 9018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * save a round-trip. 9028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 9038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *eap; 9048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap = eap_fast_build_phase2_req(sm, data, id); 9058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt req = wpabuf_concat(req, eap); 9068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, PHASE2_METHOD); 9078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 9088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 9098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case REQUEST_PAC: 9108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt req = eap_fast_build_pac(sm, data); 9118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 9128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt default: 9138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: %s - unexpected state %d", 9148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, data->state); 9158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 9168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 9178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (req && 9198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_encrypt_phase2(sm, data, req, piggyback) < 0) 9208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 9218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return eap_server_tls_build_msg(&data->ssl, EAP_TYPE_FAST, 9238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->fast_version, id); 9248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic Boolean eap_fast_check(struct eap_sm *sm, void *priv, 9288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *respData) 9298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt const u8 *pos; 9318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t len; 9328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_FAST, respData, &len); 9348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pos == NULL || len < 1) { 9358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: Invalid frame"); 9368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return TRUE; 9378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 9388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return FALSE; 9408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_phase2_init(struct eap_sm *sm, struct eap_fast_data *data, 9448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EapType eap_type) 9458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->phase2_priv && data->phase2_method) { 9478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->phase2_method->reset(sm, data->phase2_priv); 9488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->phase2_method = NULL; 9498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->phase2_priv = NULL; 9508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 9518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->phase2_method = eap_server_get_eap_method(EAP_VENDOR_IETF, 9528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_type); 9538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!data->phase2_method) 9548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 9558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->key_block_p) { 9578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->auth_challenge = data->key_block_p->server_challenge; 9588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->peer_challenge = data->key_block_p->client_challenge; 9598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 9608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->init_phase2 = 1; 9618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->phase2_priv = data->phase2_method->init(sm); 9628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->init_phase2 = 0; 9638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->auth_challenge = NULL; 9648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->peer_challenge = NULL; 9658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return data->phase2_priv == NULL ? -1 : 0; 9678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_process_phase2_response(struct eap_sm *sm, 9718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data, 9728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *in_data, size_t in_len) 9738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 next_type = EAP_TYPE_NONE; 9758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_hdr *hdr; 9768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *pos; 9778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t left; 9788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf buf; 9798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt const struct eap_method *m = data->phase2_method; 9808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt void *priv = data->phase2_priv; 9818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (priv == NULL) { 9838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: %s - Phase2 not " 9848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "initialized?!", __func__); 9858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 9868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 9878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt hdr = (struct eap_hdr *) in_data; 9898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos = (u8 *) (hdr + 1); 9908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (in_len > sizeof(*hdr) && *pos == EAP_TYPE_NAK) { 9928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt left = in_len - sizeof(*hdr); 9938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_DEBUG, "EAP-FAST: Phase2 type Nak'ed; " 9948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "allowed types", pos + 1, left - 1); 9958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef EAP_SERVER_TNC 9968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (m && m->vendor == EAP_VENDOR_IETF && 9978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt m->method == EAP_TYPE_TNC) { 9988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Peer Nak'ed required " 9998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "TNC negotiation"); 10008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = eap_fast_req_failure(sm, data); 10018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_phase2_init(sm, data, next_type); 10028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 10038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* EAP_SERVER_TNC */ 10058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_sm_process_nak(sm, pos + 1, left - 1); 10068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->user && sm->user_eap_method_index < EAP_MAX_METHODS && 10078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->user->methods[sm->user_eap_method_index].method != 10088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_TYPE_NONE) { 10098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = sm->user->methods[ 10108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->user_eap_method_index++].method; 10118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: try EAP type %d", 10128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type); 10138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 10148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = eap_fast_req_failure(sm, data); 10158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_phase2_init(sm, data, next_type); 10178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 10188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_set(&buf, in_data, in_len); 10218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (m->check(sm, priv, &buf)) { 10238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 check() asked to " 10248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "ignore the packet"); 10258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = eap_fast_req_failure(sm, data); 10268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 10278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt m->process(sm, priv, &buf); 10308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!m->isDone(sm, priv)) 10328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 10338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!m->isSuccess(sm, priv)) { 10358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 method failed"); 10368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = eap_fast_req_failure(sm, data); 10378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_phase2_init(sm, data, next_type); 10388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 10398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (data->state) { 10428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_ID: 10438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_user_get(sm, sm->identity, sm->identity_len, 1) != 0) { 10448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: Phase2 " 10458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Identity not found in the user " 10468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "database", 10478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->identity, sm->identity_len); 10488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = eap_fast_req_failure(sm, data); 10498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 10508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, PHASE2_METHOD); 10538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->anon_provisioning) { 10548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 10558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Only EAP-MSCHAPv2 is allowed for anonymous 10568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * provisioning. 10578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 10588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = EAP_TYPE_MSCHAPV2; 10598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->user_eap_method_index = 0; 10608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 10618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = sm->user->methods[0].method; 10628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->user_eap_method_index = 1; 10638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: try EAP type %d", next_type); 10658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 10668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_METHOD: 10678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case CRYPTO_BINDING: 10688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_update_icmk(sm, data); 10698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, CRYPTO_BINDING); 10708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->eap_seq++; 10718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = EAP_TYPE_NONE; 10728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef EAP_SERVER_TNC 10738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->tnc && !data->tnc_started) { 10748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Initialize TNC"); 10758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = EAP_TYPE_TNC; 10768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->tnc_started = 1; 10778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* EAP_SERVER_TNC */ 10798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 10808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case FAILURE: 10818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 10828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt default: 10838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: %s - unexpected state %d", 10848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, data->state); 10858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 10868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_phase2_init(sm, data, next_type); 10898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 10908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_process_phase2_eap(struct eap_sm *sm, 10938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data, 10948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *in_data, size_t in_len) 10958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 10968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_hdr *hdr; 10978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t len; 10988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt hdr = (struct eap_hdr *) in_data; 11008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (in_len < (int) sizeof(*hdr)) { 11018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: Too short Phase 2 " 11028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "EAP frame (len=%lu)", (unsigned long) in_len); 11038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_req_failure(sm, data); 11048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 11058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt len = be_to_host16(hdr->length); 11078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (len > in_len) { 11088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: Length mismatch in " 11098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Phase 2 EAP frame (len=%lu hdr->length=%lu)", 11108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (unsigned long) in_len, (unsigned long) len); 11118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_req_failure(sm, data); 11128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 11138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: code=%d " 11158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "identifier=%d length=%lu", hdr->code, hdr->identifier, 11168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (unsigned long) len); 11178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (hdr->code) { 11188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case EAP_CODE_RESPONSE: 11198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_process_phase2_response(sm, data, (u8 *) hdr, len); 11208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 11218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt default: 11228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: Unexpected code=%d in " 11238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Phase 2 EAP header", hdr->code); 11248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 11258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 11278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_parse_tlvs(struct wpabuf *data, 11308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_tlv_parse *tlv) 11318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 11328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int mandatory, tlv_type, len, res; 11338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *pos, *end; 11348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(tlv, 0, sizeof(*tlv)); 11368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos = wpabuf_mhead(data); 11388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt end = pos + wpabuf_len(data); 11398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt while (pos + 4 < end) { 11408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mandatory = pos[0] & 0x80; 11418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tlv_type = WPA_GET_BE16(pos) & 0x3fff; 11428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += 2; 11438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt len = WPA_GET_BE16(pos); 11448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += 2; 11458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pos + len > end) { 11468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: TLV overflow"); 11478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: " 11508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "TLV type %d length %d%s", 11518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tlv_type, len, mandatory ? " (mandatory)" : ""); 11528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt res = eap_fast_parse_tlv(tlv, tlv_type, pos, len); 11548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (res == -2) 11558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 11568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (res < 0) { 11578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (mandatory) { 11588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Nak unknown " 11598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "mandatory TLV type %d", tlv_type); 11608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* TODO: generate Nak TLV */ 11618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 11628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 11638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored " 11648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "unknown optional TLV type %d", 11658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tlv_type); 11668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += len; 11708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 11738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 11748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_validate_crypto_binding( 11778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data, struct eap_tlv_crypto_binding_tlv *b, 11788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t bind_len) 11798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 11808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 cmac[SHA1_MAC_LEN]; 11818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Reply Crypto-Binding TLV: " 11838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Version %d Received Version %d SubType %d", 11848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt b->version, b->received_version, b->subtype); 11858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE", 11868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt b->nonce, sizeof(b->nonce)); 11878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC", 11888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt b->compound_mac, sizeof(b->compound_mac)); 11898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (b->version != EAP_FAST_VERSION || 11918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt b->received_version != EAP_FAST_VERSION) { 11928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected version " 11938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "in Crypto-Binding: version %d " 11948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "received_version %d", b->version, 11958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt b->received_version); 11968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (b->subtype != EAP_TLV_CRYPTO_BINDING_SUBTYPE_RESPONSE) { 12008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected subtype in " 12018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Crypto-Binding: %d", b->subtype); 12028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 12038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (os_memcmp(data->crypto_binding_nonce, b->nonce, 31) != 0 || 12068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (data->crypto_binding_nonce[31] | 1) != b->nonce[31]) { 12078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid nonce in " 12088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Crypto-Binding"); 12098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 12108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(cmac, b->compound_mac, sizeof(cmac)); 12138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(b->compound_mac, 0, sizeof(cmac)); 12148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Crypto-Binding TLV for " 12158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Compound MAC calculation", 12168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (u8 *) b, bind_len); 12178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt hmac_sha1(data->cmk, EAP_FAST_CMK_LEN, (u8 *) b, bind_len, 12188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt b->compound_mac); 12198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (os_memcmp(cmac, b->compound_mac, sizeof(cmac)) != 0) { 12208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_MSGDUMP, 12218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "EAP-FAST: Calculated Compound MAC", 12228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt b->compound_mac, sizeof(cmac)); 12238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: Compound MAC did not " 12248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "match"); 12258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 12268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 12298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 12308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_pac_type(u8 *pac, size_t len, u16 type) 12338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 12348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_tlv_pac_type_tlv *tlv; 12358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (pac == NULL || len != sizeof(*tlv)) 12378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 12388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tlv = (struct eap_tlv_pac_type_tlv *) pac; 12408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return be_to_host16(tlv->tlv_type) == PAC_TYPE_PAC_TYPE && 12428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt be_to_host16(tlv->length) == 2 && 12438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt be_to_host16(tlv->pac_type) == type; 12448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 12458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_process_phase2_tlvs(struct eap_sm *sm, 12488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data, 12498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *in_data) 12508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 12518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_tlv_parse tlv; 12528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int check_crypto_binding = data->state == CRYPTO_BINDING; 12538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_fast_parse_tlvs(in_data, &tlv) < 0) { 12558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to parse received " 12568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Phase 2 TLVs"); 12578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 12588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (tlv.result == EAP_TLV_RESULT_FAILURE) { 12618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Result TLV indicated " 12628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "failure"); 12638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 12648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 12658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->state == REQUEST_PAC) { 12688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u16 type, len, res; 12698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (tlv.pac == NULL || tlv.pac_len < 6) { 12708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC " 12718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Acknowledgement received"); 12728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 12738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 12748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt type = WPA_GET_BE16(tlv.pac); 12778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt len = WPA_GET_BE16(tlv.pac + 2); 12788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt res = WPA_GET_BE16(tlv.pac + 4); 12798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (type != PAC_TYPE_PAC_ACKNOWLEDGEMENT || len != 2 || 12818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt res != EAP_TLV_RESULT_SUCCESS) { 12828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV did not " 12838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "contain acknowledgement"); 12848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 12858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 12868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Acknowledgement received " 12898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "- PAC provisioning succeeded"); 12908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, (data->anon_provisioning || 12918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->send_new_pac == 2) ? 12928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt FAILURE : SUCCESS); 12938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 12948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (check_crypto_binding) { 12978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (tlv.crypto_binding == NULL) { 12988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: No Crypto-Binding " 12998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "TLV received"); 13008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 13018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 13028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->final_result && 13058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tlv.result != EAP_TLV_RESULT_SUCCESS) { 13068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV " 13078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "without Success Result"); 13088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 13098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 13108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!data->final_result && 13138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tlv.iresult != EAP_TLV_RESULT_SUCCESS) { 13148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV " 13158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "without intermediate Success Result"); 13168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 13178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 13188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_fast_validate_crypto_binding(data, tlv.crypto_binding, 13218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tlv.crypto_binding_len)) { 13228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 13238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 13248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Valid Crypto-Binding TLV " 13278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "received"); 13288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->final_result) { 13298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Authentication " 13308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "completed successfully"); 13318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->anon_provisioning && 13348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->eap_fast_prov != ANON_PROV && 13358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->eap_fast_prov != BOTH_PROV) { 13368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Client is trying to " 13378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "use unauthenticated provisioning which is " 13388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "disabled"); 13398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 13408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 13418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->eap_fast_prov != AUTH_PROV && 13448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->eap_fast_prov != BOTH_PROV && 13458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tlv.request_action == EAP_TLV_ACTION_PROCESS_TLV && 13468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_pac_type(tlv.pac, tlv.pac_len, 13478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt PAC_TYPE_TUNNEL_PAC)) { 13488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Client is trying to " 13498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "use authenticated provisioning which is " 13508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "disabled"); 13518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 13528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 13538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->anon_provisioning || 13568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (tlv.request_action == EAP_TLV_ACTION_PROCESS_TLV && 13578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_pac_type(tlv.pac, tlv.pac_len, 13588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt PAC_TYPE_TUNNEL_PAC))) { 13598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Requested a new " 13608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Tunnel PAC"); 13618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, REQUEST_PAC); 13628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else if (data->send_new_pac) { 13638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Server triggered " 13648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "re-keying of Tunnel PAC"); 13658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, REQUEST_PAC); 13668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else if (data->final_result) 13678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, SUCCESS); 13688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (tlv.eap_payload_tlv) { 13718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_process_phase2_eap(sm, data, tlv.eap_payload_tlv, 13728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tlv.eap_payload_tlv_len); 13738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 13758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_process_phase2(struct eap_sm *sm, 13788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data, 13798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *in_buf) 13808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 13818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *in_decrypted; 13828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Received %lu bytes encrypted data for" 13848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt " Phase 2", (unsigned long) wpabuf_len(in_buf)); 13858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->pending_phase2_resp) { 13878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-PEAP: Pending Phase 2 response - " 13888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "skip decryption and use old data"); 13898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_process_phase2_tlvs(sm, data, 13908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->pending_phase2_resp); 13918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_free(data->pending_phase2_resp); 13928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->pending_phase2_resp = NULL; 13938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 13948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt in_decrypted = tls_connection_decrypt(sm->ssl_ctx, data->ssl.conn, 13978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt in_buf); 13988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (in_decrypted == NULL) { 13998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: Failed to decrypt Phase 2 " 14008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "data"); 14018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 14028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 14038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 14048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_buf_key(MSG_DEBUG, "EAP-FAST: Decrypted Phase 2 TLVs", 14068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt in_decrypted); 14078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_process_phase2_tlvs(sm, data, in_decrypted); 14098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sm->method_pending == METHOD_PENDING_WAIT) { 14118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Phase2 method is in " 14128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "pending wait state - save decrypted response"); 14138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_free(data->pending_phase2_resp); 14148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->pending_phase2_resp = in_decrypted; 14158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 14168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 14178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_free(in_decrypted); 14198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 14208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_process_version(struct eap_sm *sm, void *priv, 14238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int peer_version) 14248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 14258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = priv; 14268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->peer_version = peer_version; 14288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->force_version >= 0 && peer_version != data->force_version) { 14308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: peer did not select the forced" 14318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt " version (forced=%d peer=%d) - reject", 14328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->force_version, peer_version); 14338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 14348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 14358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (peer_version < data->fast_version) { 14378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: peer ver=%d, own ver=%d; " 14388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "use version %d", 14398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt peer_version, data->fast_version, peer_version); 14408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->fast_version = peer_version; 14418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 14428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 14448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 14458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_process_phase1(struct eap_sm *sm, 14488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data) 14498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 14508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_server_tls_phase1(sm, &data->ssl) < 0) { 14518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_INFO, "EAP-FAST: TLS processing failed"); 14528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 14538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 14548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 14558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!tls_connection_established(sm->ssl_ctx, data->ssl.conn) || 14578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpabuf_len(data->ssl.tls_out) > 0) 14588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 1; 14598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 14618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Phase 1 was completed with the received message (e.g., when using 14628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * abbreviated handshake), so Phase 2 can be started immediately 14638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * without having to send through an empty message to the peer. 14648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 14658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return eap_fast_phase1_done(sm, data); 14678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 14688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int eap_fast_process_phase2_start(struct eap_sm *sm, 14718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data) 14728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 14738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 next_type; 14748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->identity) { 14768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(sm->identity); 14778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->identity = data->identity; 14788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->identity = NULL; 14798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->identity_len = data->identity_len; 14808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->identity_len = 0; 14818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->require_identity_match = 1; 14828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_user_get(sm, sm->identity, sm->identity_len, 1) != 0) { 14838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: " 14848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Phase2 Identity not found " 14858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "in the user database", 14868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->identity, sm->identity_len); 14878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = eap_fast_req_failure(sm, data); 14888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 14898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Identity already " 14908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "known - skip Phase 2 Identity Request"); 14918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = sm->user->methods[0].method; 14928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sm->user_eap_method_index = 1; 14938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 14948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, PHASE2_METHOD); 14968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 14978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, PHASE2_ID); 14988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt next_type = EAP_TYPE_IDENTITY; 14998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 15008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return eap_fast_phase2_init(sm, data, next_type); 15028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_process_msg(struct eap_sm *sm, void *priv, 15068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt const struct wpabuf *respData) 15078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 15088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = priv; 15098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (data->state) { 15118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE1: 15128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_fast_process_phase1(sm, data)) 15138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 15148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* fall through to PHASE2_START */ 15168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_START: 15178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_process_phase2_start(sm, data); 15188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 15198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_ID: 15208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case PHASE2_METHOD: 15218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case CRYPTO_BINDING: 15228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case REQUEST_PAC: 15238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_process_phase2(sm, data, data->ssl.tls_in); 15248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 15258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt default: 15268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "EAP-FAST: Unexpected state %d in %s", 15278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->state, __func__); 15288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 15298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 15308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void eap_fast_process(struct eap_sm *sm, void *priv, 15348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpabuf *respData) 15358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 15368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = priv; 15378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap_server_tls_process(sm, &data->ssl, respData, data, 15388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_TYPE_FAST, eap_fast_process_version, 15398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_process_msg) < 0) 15408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_state(data, FAILURE); 15418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic Boolean eap_fast_isDone(struct eap_sm *sm, void *priv) 15458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 15468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = priv; 15478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return data->state == SUCCESS || data->state == FAILURE; 15488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic u8 * eap_fast_getKey(struct eap_sm *sm, void *priv, size_t *len) 15528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 15538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = priv; 15548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *eapKeyData; 15558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->state != SUCCESS) 15578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 15588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eapKeyData = os_malloc(EAP_FAST_KEY_LEN); 15608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eapKeyData == NULL) 15618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 15628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_derive_eap_msk(data->simck, eapKeyData); 15648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *len = EAP_FAST_KEY_LEN; 15658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return eapKeyData; 15678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic u8 * eap_fast_get_emsk(struct eap_sm *sm, void *priv, size_t *len) 15718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 15728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = priv; 15738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *eapKeyData; 15748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (data->state != SUCCESS) 15768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 15778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eapKeyData = os_malloc(EAP_EMSK_LEN); 15798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eapKeyData == NULL) 15808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 15818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_fast_derive_eap_emsk(data->simck, eapKeyData); 15838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *len = EAP_EMSK_LEN; 15848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return eapKeyData; 15868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic Boolean eap_fast_isSuccess(struct eap_sm *sm, void *priv) 15908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 15918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_fast_data *data = priv; 15928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return data->state == SUCCESS; 15938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtint eap_server_fast_register(void) 15978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 15988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct eap_method *eap; 15998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int ret; 16008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 16018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION, 16028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EAP_VENDOR_IETF, EAP_TYPE_FAST, "FAST"); 16038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (eap == NULL) 16048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 16058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 16068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap->init = eap_fast_init; 16078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap->reset = eap_fast_reset; 16088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap->buildReq = eap_fast_buildReq; 16098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap->check = eap_fast_check; 16108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap->process = eap_fast_process; 16118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap->isDone = eap_fast_isDone; 16128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap->getKey = eap_fast_getKey; 16138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap->get_emsk = eap_fast_get_emsk; 16148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap->isSuccess = eap_fast_isSuccess; 16158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 16168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ret = eap_server_method_register(eap); 16178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ret) 16188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eap_server_method_free(eap); 16198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return ret; 16208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1621