13ff40c12SJohn Marino /*
23ff40c12SJohn Marino * hostapd / EAP Full Authenticator state machine (RFC 4137)
3*a1157835SDaniel Fojt * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi>
43ff40c12SJohn Marino *
53ff40c12SJohn Marino * This software may be distributed under the terms of the BSD license.
63ff40c12SJohn Marino * See README for more details.
73ff40c12SJohn Marino *
83ff40c12SJohn Marino * This state machine is based on the full authenticator state machine defined
93ff40c12SJohn Marino * in RFC 4137. However, to support backend authentication in RADIUS
103ff40c12SJohn Marino * authentication server functionality, parts of backend authenticator (also
113ff40c12SJohn Marino * from RFC 4137) are mixed in. This functionality is enabled by setting
123ff40c12SJohn Marino * backend_auth configuration variable to TRUE.
133ff40c12SJohn Marino */
143ff40c12SJohn Marino
153ff40c12SJohn Marino #include "includes.h"
163ff40c12SJohn Marino
173ff40c12SJohn Marino #include "common.h"
18*a1157835SDaniel Fojt #include "crypto/sha256.h"
193ff40c12SJohn Marino #include "eap_i.h"
203ff40c12SJohn Marino #include "state_machine.h"
213ff40c12SJohn Marino #include "common/wpa_ctrl.h"
223ff40c12SJohn Marino
233ff40c12SJohn Marino #define STATE_MACHINE_DATA struct eap_sm
243ff40c12SJohn Marino #define STATE_MACHINE_DEBUG_PREFIX "EAP"
253ff40c12SJohn Marino
263ff40c12SJohn Marino #define EAP_MAX_AUTH_ROUNDS 50
273ff40c12SJohn Marino
283ff40c12SJohn Marino /* EAP state machines are described in RFC 4137 */
293ff40c12SJohn Marino
303ff40c12SJohn Marino static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
313ff40c12SJohn Marino int eapSRTT, int eapRTTVAR,
323ff40c12SJohn Marino int methodTimeout);
333ff40c12SJohn Marino static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp);
343ff40c12SJohn Marino static int eap_sm_getId(const struct wpabuf *data);
353ff40c12SJohn Marino static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id);
363ff40c12SJohn Marino static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id);
373ff40c12SJohn Marino static int eap_sm_nextId(struct eap_sm *sm, int id);
383ff40c12SJohn Marino static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
393ff40c12SJohn Marino size_t len);
403ff40c12SJohn Marino static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor);
413ff40c12SJohn Marino static int eap_sm_Policy_getDecision(struct eap_sm *sm);
423ff40c12SJohn Marino static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method);
433ff40c12SJohn Marino
443ff40c12SJohn Marino
eap_get_erp_send_reauth_start(struct eap_sm * sm)45*a1157835SDaniel Fojt static int eap_get_erp_send_reauth_start(struct eap_sm *sm)
46*a1157835SDaniel Fojt {
47*a1157835SDaniel Fojt if (sm->eapol_cb->get_erp_send_reauth_start)
48*a1157835SDaniel Fojt return sm->eapol_cb->get_erp_send_reauth_start(sm->eapol_ctx);
49*a1157835SDaniel Fojt return 0;
50*a1157835SDaniel Fojt }
51*a1157835SDaniel Fojt
52*a1157835SDaniel Fojt
eap_get_erp_domain(struct eap_sm * sm)53*a1157835SDaniel Fojt static const char * eap_get_erp_domain(struct eap_sm *sm)
54*a1157835SDaniel Fojt {
55*a1157835SDaniel Fojt if (sm->eapol_cb->get_erp_domain)
56*a1157835SDaniel Fojt return sm->eapol_cb->get_erp_domain(sm->eapol_ctx);
57*a1157835SDaniel Fojt return NULL;
58*a1157835SDaniel Fojt }
59*a1157835SDaniel Fojt
60*a1157835SDaniel Fojt
61*a1157835SDaniel Fojt #ifdef CONFIG_ERP
62*a1157835SDaniel Fojt
eap_erp_get_key(struct eap_sm * sm,const char * keyname)63*a1157835SDaniel Fojt static struct eap_server_erp_key * eap_erp_get_key(struct eap_sm *sm,
64*a1157835SDaniel Fojt const char *keyname)
65*a1157835SDaniel Fojt {
66*a1157835SDaniel Fojt if (sm->eapol_cb->erp_get_key)
67*a1157835SDaniel Fojt return sm->eapol_cb->erp_get_key(sm->eapol_ctx, keyname);
68*a1157835SDaniel Fojt return NULL;
69*a1157835SDaniel Fojt }
70*a1157835SDaniel Fojt
71*a1157835SDaniel Fojt
eap_erp_add_key(struct eap_sm * sm,struct eap_server_erp_key * erp)72*a1157835SDaniel Fojt static int eap_erp_add_key(struct eap_sm *sm, struct eap_server_erp_key *erp)
73*a1157835SDaniel Fojt {
74*a1157835SDaniel Fojt if (sm->eapol_cb->erp_add_key)
75*a1157835SDaniel Fojt return sm->eapol_cb->erp_add_key(sm->eapol_ctx, erp);
76*a1157835SDaniel Fojt return -1;
77*a1157835SDaniel Fojt }
78*a1157835SDaniel Fojt
79*a1157835SDaniel Fojt #endif /* CONFIG_ERP */
80*a1157835SDaniel Fojt
81*a1157835SDaniel Fojt
eap_sm_buildInitiateReauthStart(struct eap_sm * sm,u8 id)82*a1157835SDaniel Fojt static struct wpabuf * eap_sm_buildInitiateReauthStart(struct eap_sm *sm,
83*a1157835SDaniel Fojt u8 id)
84*a1157835SDaniel Fojt {
85*a1157835SDaniel Fojt const char *domain;
86*a1157835SDaniel Fojt size_t plen = 1;
87*a1157835SDaniel Fojt struct wpabuf *msg;
88*a1157835SDaniel Fojt size_t domain_len = 0;
89*a1157835SDaniel Fojt
90*a1157835SDaniel Fojt domain = eap_get_erp_domain(sm);
91*a1157835SDaniel Fojt if (domain) {
92*a1157835SDaniel Fojt domain_len = os_strlen(domain);
93*a1157835SDaniel Fojt plen += 2 + domain_len;
94*a1157835SDaniel Fojt }
95*a1157835SDaniel Fojt
96*a1157835SDaniel Fojt msg = eap_msg_alloc(EAP_VENDOR_IETF,
97*a1157835SDaniel Fojt (EapType) EAP_ERP_TYPE_REAUTH_START, plen,
98*a1157835SDaniel Fojt EAP_CODE_INITIATE, id);
99*a1157835SDaniel Fojt if (msg == NULL)
100*a1157835SDaniel Fojt return NULL;
101*a1157835SDaniel Fojt wpabuf_put_u8(msg, 0); /* Reserved */
102*a1157835SDaniel Fojt if (domain) {
103*a1157835SDaniel Fojt /* Domain name TLV */
104*a1157835SDaniel Fojt wpabuf_put_u8(msg, EAP_ERP_TLV_DOMAIN_NAME);
105*a1157835SDaniel Fojt wpabuf_put_u8(msg, domain_len);
106*a1157835SDaniel Fojt wpabuf_put_data(msg, domain, domain_len);
107*a1157835SDaniel Fojt }
108*a1157835SDaniel Fojt
109*a1157835SDaniel Fojt return msg;
110*a1157835SDaniel Fojt }
111*a1157835SDaniel Fojt
112*a1157835SDaniel Fojt
eap_copy_buf(struct wpabuf ** dst,const struct wpabuf * src)1133ff40c12SJohn Marino static int eap_copy_buf(struct wpabuf **dst, const struct wpabuf *src)
1143ff40c12SJohn Marino {
1153ff40c12SJohn Marino if (src == NULL)
1163ff40c12SJohn Marino return -1;
1173ff40c12SJohn Marino
1183ff40c12SJohn Marino wpabuf_free(*dst);
1193ff40c12SJohn Marino *dst = wpabuf_dup(src);
1203ff40c12SJohn Marino return *dst ? 0 : -1;
1213ff40c12SJohn Marino }
1223ff40c12SJohn Marino
1233ff40c12SJohn Marino
eap_copy_data(u8 ** dst,size_t * dst_len,const u8 * src,size_t src_len)1243ff40c12SJohn Marino static int eap_copy_data(u8 **dst, size_t *dst_len,
1253ff40c12SJohn Marino const u8 *src, size_t src_len)
1263ff40c12SJohn Marino {
1273ff40c12SJohn Marino if (src == NULL)
1283ff40c12SJohn Marino return -1;
1293ff40c12SJohn Marino
1303ff40c12SJohn Marino os_free(*dst);
1313ff40c12SJohn Marino *dst = os_malloc(src_len);
1323ff40c12SJohn Marino if (*dst) {
1333ff40c12SJohn Marino os_memcpy(*dst, src, src_len);
1343ff40c12SJohn Marino *dst_len = src_len;
1353ff40c12SJohn Marino return 0;
1363ff40c12SJohn Marino } else {
1373ff40c12SJohn Marino *dst_len = 0;
1383ff40c12SJohn Marino return -1;
1393ff40c12SJohn Marino }
1403ff40c12SJohn Marino }
1413ff40c12SJohn Marino
1423ff40c12SJohn Marino #define EAP_COPY(dst, src) \
1433ff40c12SJohn Marino eap_copy_data((dst), (dst ## Len), (src), (src ## Len))
1443ff40c12SJohn Marino
1453ff40c12SJohn Marino
1463ff40c12SJohn Marino /**
1473ff40c12SJohn Marino * eap_user_get - Fetch user information from the database
1483ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1493ff40c12SJohn Marino * @identity: Identity (User-Name) of the user
1503ff40c12SJohn Marino * @identity_len: Length of identity in bytes
1513ff40c12SJohn Marino * @phase2: 0 = EAP phase1 user, 1 = EAP phase2 (tunneled) user
1523ff40c12SJohn Marino * Returns: 0 on success, or -1 on failure
1533ff40c12SJohn Marino *
1543ff40c12SJohn Marino * This function is used to fetch user information for EAP. The user will be
1553ff40c12SJohn Marino * selected based on the specified identity. sm->user and
1563ff40c12SJohn Marino * sm->user_eap_method_index are updated for the new user when a matching user
1573ff40c12SJohn Marino * is found. sm->user can be used to get user information (e.g., password).
1583ff40c12SJohn Marino */
eap_user_get(struct eap_sm * sm,const u8 * identity,size_t identity_len,int phase2)1593ff40c12SJohn Marino int eap_user_get(struct eap_sm *sm, const u8 *identity, size_t identity_len,
1603ff40c12SJohn Marino int phase2)
1613ff40c12SJohn Marino {
1623ff40c12SJohn Marino struct eap_user *user;
1633ff40c12SJohn Marino
1643ff40c12SJohn Marino if (sm == NULL || sm->eapol_cb == NULL ||
1653ff40c12SJohn Marino sm->eapol_cb->get_eap_user == NULL)
1663ff40c12SJohn Marino return -1;
1673ff40c12SJohn Marino
1683ff40c12SJohn Marino eap_user_free(sm->user);
1693ff40c12SJohn Marino sm->user = NULL;
1703ff40c12SJohn Marino
1713ff40c12SJohn Marino user = os_zalloc(sizeof(*user));
1723ff40c12SJohn Marino if (user == NULL)
1733ff40c12SJohn Marino return -1;
1743ff40c12SJohn Marino
1753ff40c12SJohn Marino if (sm->eapol_cb->get_eap_user(sm->eapol_ctx, identity,
1763ff40c12SJohn Marino identity_len, phase2, user) != 0) {
1773ff40c12SJohn Marino eap_user_free(user);
1783ff40c12SJohn Marino return -1;
1793ff40c12SJohn Marino }
1803ff40c12SJohn Marino
1813ff40c12SJohn Marino sm->user = user;
1823ff40c12SJohn Marino sm->user_eap_method_index = 0;
1833ff40c12SJohn Marino
1843ff40c12SJohn Marino return 0;
1853ff40c12SJohn Marino }
1863ff40c12SJohn Marino
1873ff40c12SJohn Marino
eap_log_msg(struct eap_sm * sm,const char * fmt,...)188*a1157835SDaniel Fojt void eap_log_msg(struct eap_sm *sm, const char *fmt, ...)
189*a1157835SDaniel Fojt {
190*a1157835SDaniel Fojt va_list ap;
191*a1157835SDaniel Fojt char *buf;
192*a1157835SDaniel Fojt int buflen;
193*a1157835SDaniel Fojt
194*a1157835SDaniel Fojt if (sm == NULL || sm->eapol_cb == NULL || sm->eapol_cb->log_msg == NULL)
195*a1157835SDaniel Fojt return;
196*a1157835SDaniel Fojt
197*a1157835SDaniel Fojt va_start(ap, fmt);
198*a1157835SDaniel Fojt buflen = vsnprintf(NULL, 0, fmt, ap) + 1;
199*a1157835SDaniel Fojt va_end(ap);
200*a1157835SDaniel Fojt
201*a1157835SDaniel Fojt buf = os_malloc(buflen);
202*a1157835SDaniel Fojt if (buf == NULL)
203*a1157835SDaniel Fojt return;
204*a1157835SDaniel Fojt va_start(ap, fmt);
205*a1157835SDaniel Fojt vsnprintf(buf, buflen, fmt, ap);
206*a1157835SDaniel Fojt va_end(ap);
207*a1157835SDaniel Fojt
208*a1157835SDaniel Fojt sm->eapol_cb->log_msg(sm->eapol_ctx, buf);
209*a1157835SDaniel Fojt
210*a1157835SDaniel Fojt os_free(buf);
211*a1157835SDaniel Fojt }
212*a1157835SDaniel Fojt
213*a1157835SDaniel Fojt
SM_STATE(EAP,DISABLED)2143ff40c12SJohn Marino SM_STATE(EAP, DISABLED)
2153ff40c12SJohn Marino {
2163ff40c12SJohn Marino SM_ENTRY(EAP, DISABLED);
2173ff40c12SJohn Marino sm->num_rounds = 0;
2183ff40c12SJohn Marino }
2193ff40c12SJohn Marino
2203ff40c12SJohn Marino
SM_STATE(EAP,INITIALIZE)2213ff40c12SJohn Marino SM_STATE(EAP, INITIALIZE)
2223ff40c12SJohn Marino {
2233ff40c12SJohn Marino SM_ENTRY(EAP, INITIALIZE);
2243ff40c12SJohn Marino
2253ff40c12SJohn Marino if (sm->eap_if.eapRestart && !sm->eap_server && sm->identity) {
2263ff40c12SJohn Marino /*
2273ff40c12SJohn Marino * Need to allow internal Identity method to be used instead
2283ff40c12SJohn Marino * of passthrough at the beginning of reauthentication.
2293ff40c12SJohn Marino */
2303ff40c12SJohn Marino eap_server_clear_identity(sm);
2313ff40c12SJohn Marino }
2323ff40c12SJohn Marino
233*a1157835SDaniel Fojt sm->try_initiate_reauth = FALSE;
2343ff40c12SJohn Marino sm->currentId = -1;
2353ff40c12SJohn Marino sm->eap_if.eapSuccess = FALSE;
2363ff40c12SJohn Marino sm->eap_if.eapFail = FALSE;
2373ff40c12SJohn Marino sm->eap_if.eapTimeout = FALSE;
238*a1157835SDaniel Fojt bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
2393ff40c12SJohn Marino sm->eap_if.eapKeyData = NULL;
2403ff40c12SJohn Marino sm->eap_if.eapKeyDataLen = 0;
241*a1157835SDaniel Fojt os_free(sm->eap_if.eapSessionId);
242*a1157835SDaniel Fojt sm->eap_if.eapSessionId = NULL;
243*a1157835SDaniel Fojt sm->eap_if.eapSessionIdLen = 0;
2443ff40c12SJohn Marino sm->eap_if.eapKeyAvailable = FALSE;
2453ff40c12SJohn Marino sm->eap_if.eapRestart = FALSE;
2463ff40c12SJohn Marino
2473ff40c12SJohn Marino /*
2483ff40c12SJohn Marino * This is not defined in RFC 4137, but method state needs to be
2493ff40c12SJohn Marino * reseted here so that it does not remain in success state when
2503ff40c12SJohn Marino * re-authentication starts.
2513ff40c12SJohn Marino */
2523ff40c12SJohn Marino if (sm->m && sm->eap_method_priv) {
2533ff40c12SJohn Marino sm->m->reset(sm, sm->eap_method_priv);
2543ff40c12SJohn Marino sm->eap_method_priv = NULL;
2553ff40c12SJohn Marino }
2563ff40c12SJohn Marino sm->m = NULL;
2573ff40c12SJohn Marino sm->user_eap_method_index = 0;
2583ff40c12SJohn Marino
2593ff40c12SJohn Marino if (sm->backend_auth) {
2603ff40c12SJohn Marino sm->currentMethod = EAP_TYPE_NONE;
2613ff40c12SJohn Marino /* parse rxResp, respId, respMethod */
2623ff40c12SJohn Marino eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
2633ff40c12SJohn Marino if (sm->rxResp) {
2643ff40c12SJohn Marino sm->currentId = sm->respId;
2653ff40c12SJohn Marino }
2663ff40c12SJohn Marino }
2673ff40c12SJohn Marino sm->num_rounds = 0;
2683ff40c12SJohn Marino sm->method_pending = METHOD_PENDING_NONE;
2693ff40c12SJohn Marino
2703ff40c12SJohn Marino wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_STARTED
2713ff40c12SJohn Marino MACSTR, MAC2STR(sm->peer_addr));
2723ff40c12SJohn Marino }
2733ff40c12SJohn Marino
2743ff40c12SJohn Marino
SM_STATE(EAP,PICK_UP_METHOD)2753ff40c12SJohn Marino SM_STATE(EAP, PICK_UP_METHOD)
2763ff40c12SJohn Marino {
2773ff40c12SJohn Marino SM_ENTRY(EAP, PICK_UP_METHOD);
2783ff40c12SJohn Marino
2793ff40c12SJohn Marino if (eap_sm_Policy_doPickUp(sm, sm->respMethod)) {
2803ff40c12SJohn Marino sm->currentMethod = sm->respMethod;
2813ff40c12SJohn Marino if (sm->m && sm->eap_method_priv) {
2823ff40c12SJohn Marino sm->m->reset(sm, sm->eap_method_priv);
2833ff40c12SJohn Marino sm->eap_method_priv = NULL;
2843ff40c12SJohn Marino }
2853ff40c12SJohn Marino sm->m = eap_server_get_eap_method(EAP_VENDOR_IETF,
2863ff40c12SJohn Marino sm->currentMethod);
2873ff40c12SJohn Marino if (sm->m && sm->m->initPickUp) {
2883ff40c12SJohn Marino sm->eap_method_priv = sm->m->initPickUp(sm);
2893ff40c12SJohn Marino if (sm->eap_method_priv == NULL) {
2903ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Failed to "
2913ff40c12SJohn Marino "initialize EAP method %d",
2923ff40c12SJohn Marino sm->currentMethod);
2933ff40c12SJohn Marino sm->m = NULL;
2943ff40c12SJohn Marino sm->currentMethod = EAP_TYPE_NONE;
2953ff40c12SJohn Marino }
2963ff40c12SJohn Marino } else {
2973ff40c12SJohn Marino sm->m = NULL;
2983ff40c12SJohn Marino sm->currentMethod = EAP_TYPE_NONE;
2993ff40c12SJohn Marino }
3003ff40c12SJohn Marino }
3013ff40c12SJohn Marino
3023ff40c12SJohn Marino wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
3033ff40c12SJohn Marino "method=%u", sm->currentMethod);
3043ff40c12SJohn Marino }
3053ff40c12SJohn Marino
3063ff40c12SJohn Marino
SM_STATE(EAP,IDLE)3073ff40c12SJohn Marino SM_STATE(EAP, IDLE)
3083ff40c12SJohn Marino {
3093ff40c12SJohn Marino SM_ENTRY(EAP, IDLE);
3103ff40c12SJohn Marino
3113ff40c12SJohn Marino sm->eap_if.retransWhile = eap_sm_calculateTimeout(
3123ff40c12SJohn Marino sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
3133ff40c12SJohn Marino sm->methodTimeout);
3143ff40c12SJohn Marino }
3153ff40c12SJohn Marino
3163ff40c12SJohn Marino
SM_STATE(EAP,RETRANSMIT)3173ff40c12SJohn Marino SM_STATE(EAP, RETRANSMIT)
3183ff40c12SJohn Marino {
3193ff40c12SJohn Marino SM_ENTRY(EAP, RETRANSMIT);
3203ff40c12SJohn Marino
3213ff40c12SJohn Marino sm->retransCount++;
3223ff40c12SJohn Marino if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
3233ff40c12SJohn Marino if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
3243ff40c12SJohn Marino sm->eap_if.eapReq = TRUE;
3253ff40c12SJohn Marino }
326*a1157835SDaniel Fojt
327*a1157835SDaniel Fojt wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_RETRANSMIT MACSTR,
328*a1157835SDaniel Fojt MAC2STR(sm->peer_addr));
3293ff40c12SJohn Marino }
3303ff40c12SJohn Marino
3313ff40c12SJohn Marino
SM_STATE(EAP,RECEIVED)3323ff40c12SJohn Marino SM_STATE(EAP, RECEIVED)
3333ff40c12SJohn Marino {
3343ff40c12SJohn Marino SM_ENTRY(EAP, RECEIVED);
3353ff40c12SJohn Marino
3363ff40c12SJohn Marino /* parse rxResp, respId, respMethod */
3373ff40c12SJohn Marino eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
3383ff40c12SJohn Marino sm->num_rounds++;
3393ff40c12SJohn Marino }
3403ff40c12SJohn Marino
3413ff40c12SJohn Marino
SM_STATE(EAP,DISCARD)3423ff40c12SJohn Marino SM_STATE(EAP, DISCARD)
3433ff40c12SJohn Marino {
3443ff40c12SJohn Marino SM_ENTRY(EAP, DISCARD);
3453ff40c12SJohn Marino sm->eap_if.eapResp = FALSE;
3463ff40c12SJohn Marino sm->eap_if.eapNoReq = TRUE;
3473ff40c12SJohn Marino }
3483ff40c12SJohn Marino
3493ff40c12SJohn Marino
SM_STATE(EAP,SEND_REQUEST)3503ff40c12SJohn Marino SM_STATE(EAP, SEND_REQUEST)
3513ff40c12SJohn Marino {
3523ff40c12SJohn Marino SM_ENTRY(EAP, SEND_REQUEST);
3533ff40c12SJohn Marino
3543ff40c12SJohn Marino sm->retransCount = 0;
3553ff40c12SJohn Marino if (sm->eap_if.eapReqData) {
3563ff40c12SJohn Marino if (eap_copy_buf(&sm->lastReqData, sm->eap_if.eapReqData) == 0)
3573ff40c12SJohn Marino {
3583ff40c12SJohn Marino sm->eap_if.eapResp = FALSE;
3593ff40c12SJohn Marino sm->eap_if.eapReq = TRUE;
3603ff40c12SJohn Marino } else {
3613ff40c12SJohn Marino sm->eap_if.eapResp = FALSE;
3623ff40c12SJohn Marino sm->eap_if.eapReq = FALSE;
3633ff40c12SJohn Marino }
3643ff40c12SJohn Marino } else {
3653ff40c12SJohn Marino wpa_printf(MSG_INFO, "EAP: SEND_REQUEST - no eapReqData");
3663ff40c12SJohn Marino sm->eap_if.eapResp = FALSE;
3673ff40c12SJohn Marino sm->eap_if.eapReq = FALSE;
3683ff40c12SJohn Marino sm->eap_if.eapNoReq = TRUE;
3693ff40c12SJohn Marino }
3703ff40c12SJohn Marino }
3713ff40c12SJohn Marino
3723ff40c12SJohn Marino
SM_STATE(EAP,INTEGRITY_CHECK)3733ff40c12SJohn Marino SM_STATE(EAP, INTEGRITY_CHECK)
3743ff40c12SJohn Marino {
3753ff40c12SJohn Marino SM_ENTRY(EAP, INTEGRITY_CHECK);
3763ff40c12SJohn Marino
3773ff40c12SJohn Marino if (!eap_hdr_len_valid(sm->eap_if.eapRespData, 1)) {
3783ff40c12SJohn Marino sm->ignore = TRUE;
3793ff40c12SJohn Marino return;
3803ff40c12SJohn Marino }
3813ff40c12SJohn Marino
3823ff40c12SJohn Marino if (sm->m->check) {
3833ff40c12SJohn Marino sm->ignore = sm->m->check(sm, sm->eap_method_priv,
3843ff40c12SJohn Marino sm->eap_if.eapRespData);
3853ff40c12SJohn Marino }
3863ff40c12SJohn Marino }
3873ff40c12SJohn Marino
3883ff40c12SJohn Marino
SM_STATE(EAP,METHOD_REQUEST)3893ff40c12SJohn Marino SM_STATE(EAP, METHOD_REQUEST)
3903ff40c12SJohn Marino {
3913ff40c12SJohn Marino SM_ENTRY(EAP, METHOD_REQUEST);
3923ff40c12SJohn Marino
3933ff40c12SJohn Marino if (sm->m == NULL) {
3943ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: method not initialized");
3953ff40c12SJohn Marino return;
3963ff40c12SJohn Marino }
3973ff40c12SJohn Marino
3983ff40c12SJohn Marino sm->currentId = eap_sm_nextId(sm, sm->currentId);
3993ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: building EAP-Request: Identifier %d",
4003ff40c12SJohn Marino sm->currentId);
4013ff40c12SJohn Marino sm->lastId = sm->currentId;
4023ff40c12SJohn Marino wpabuf_free(sm->eap_if.eapReqData);
4033ff40c12SJohn Marino sm->eap_if.eapReqData = sm->m->buildReq(sm, sm->eap_method_priv,
4043ff40c12SJohn Marino sm->currentId);
4053ff40c12SJohn Marino if (sm->m->getTimeout)
4063ff40c12SJohn Marino sm->methodTimeout = sm->m->getTimeout(sm, sm->eap_method_priv);
4073ff40c12SJohn Marino else
4083ff40c12SJohn Marino sm->methodTimeout = 0;
4093ff40c12SJohn Marino }
4103ff40c12SJohn Marino
4113ff40c12SJohn Marino
eap_server_erp_init(struct eap_sm * sm)412*a1157835SDaniel Fojt static void eap_server_erp_init(struct eap_sm *sm)
413*a1157835SDaniel Fojt {
414*a1157835SDaniel Fojt #ifdef CONFIG_ERP
415*a1157835SDaniel Fojt u8 *emsk = NULL;
416*a1157835SDaniel Fojt size_t emsk_len = 0;
417*a1157835SDaniel Fojt u8 EMSKname[EAP_EMSK_NAME_LEN];
418*a1157835SDaniel Fojt u8 len[2], ctx[3];
419*a1157835SDaniel Fojt const char *domain;
420*a1157835SDaniel Fojt size_t domain_len, nai_buf_len;
421*a1157835SDaniel Fojt struct eap_server_erp_key *erp = NULL;
422*a1157835SDaniel Fojt int pos;
423*a1157835SDaniel Fojt
424*a1157835SDaniel Fojt domain = eap_get_erp_domain(sm);
425*a1157835SDaniel Fojt if (!domain)
426*a1157835SDaniel Fojt return;
427*a1157835SDaniel Fojt
428*a1157835SDaniel Fojt domain_len = os_strlen(domain);
429*a1157835SDaniel Fojt
430*a1157835SDaniel Fojt nai_buf_len = 2 * EAP_EMSK_NAME_LEN + 1 + domain_len;
431*a1157835SDaniel Fojt if (nai_buf_len > 253) {
432*a1157835SDaniel Fojt /*
433*a1157835SDaniel Fojt * keyName-NAI has a maximum length of 253 octet to fit in
434*a1157835SDaniel Fojt * RADIUS attributes.
435*a1157835SDaniel Fojt */
436*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
437*a1157835SDaniel Fojt "EAP: Too long realm for ERP keyName-NAI maximum length");
438*a1157835SDaniel Fojt return;
439*a1157835SDaniel Fojt }
440*a1157835SDaniel Fojt nai_buf_len++; /* null termination */
441*a1157835SDaniel Fojt erp = os_zalloc(sizeof(*erp) + nai_buf_len);
442*a1157835SDaniel Fojt if (erp == NULL)
443*a1157835SDaniel Fojt goto fail;
444*a1157835SDaniel Fojt erp->recv_seq = (u32) -1;
445*a1157835SDaniel Fojt
446*a1157835SDaniel Fojt emsk = sm->m->get_emsk(sm, sm->eap_method_priv, &emsk_len);
447*a1157835SDaniel Fojt if (!emsk || emsk_len == 0 || emsk_len > ERP_MAX_KEY_LEN) {
448*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
449*a1157835SDaniel Fojt "EAP: No suitable EMSK available for ERP");
450*a1157835SDaniel Fojt goto fail;
451*a1157835SDaniel Fojt }
452*a1157835SDaniel Fojt
453*a1157835SDaniel Fojt wpa_hexdump_key(MSG_DEBUG, "EAP: EMSK", emsk, emsk_len);
454*a1157835SDaniel Fojt
455*a1157835SDaniel Fojt WPA_PUT_BE16(len, EAP_EMSK_NAME_LEN);
456*a1157835SDaniel Fojt if (hmac_sha256_kdf(sm->eap_if.eapSessionId, sm->eap_if.eapSessionIdLen,
457*a1157835SDaniel Fojt "EMSK", len, sizeof(len),
458*a1157835SDaniel Fojt EMSKname, EAP_EMSK_NAME_LEN) < 0) {
459*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "EAP: Could not derive EMSKname");
460*a1157835SDaniel Fojt goto fail;
461*a1157835SDaniel Fojt }
462*a1157835SDaniel Fojt wpa_hexdump(MSG_DEBUG, "EAP: EMSKname", EMSKname, EAP_EMSK_NAME_LEN);
463*a1157835SDaniel Fojt
464*a1157835SDaniel Fojt pos = wpa_snprintf_hex(erp->keyname_nai, nai_buf_len,
465*a1157835SDaniel Fojt EMSKname, EAP_EMSK_NAME_LEN);
466*a1157835SDaniel Fojt erp->keyname_nai[pos] = '@';
467*a1157835SDaniel Fojt os_memcpy(&erp->keyname_nai[pos + 1], domain, domain_len);
468*a1157835SDaniel Fojt
469*a1157835SDaniel Fojt WPA_PUT_BE16(len, emsk_len);
470*a1157835SDaniel Fojt if (hmac_sha256_kdf(emsk, emsk_len,
471*a1157835SDaniel Fojt "EAP Re-authentication Root Key@ietf.org",
472*a1157835SDaniel Fojt len, sizeof(len), erp->rRK, emsk_len) < 0) {
473*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "EAP: Could not derive rRK for ERP");
474*a1157835SDaniel Fojt goto fail;
475*a1157835SDaniel Fojt }
476*a1157835SDaniel Fojt erp->rRK_len = emsk_len;
477*a1157835SDaniel Fojt wpa_hexdump_key(MSG_DEBUG, "EAP: ERP rRK", erp->rRK, erp->rRK_len);
478*a1157835SDaniel Fojt
479*a1157835SDaniel Fojt ctx[0] = EAP_ERP_CS_HMAC_SHA256_128;
480*a1157835SDaniel Fojt WPA_PUT_BE16(&ctx[1], erp->rRK_len);
481*a1157835SDaniel Fojt if (hmac_sha256_kdf(erp->rRK, erp->rRK_len,
482*a1157835SDaniel Fojt "Re-authentication Integrity Key@ietf.org",
483*a1157835SDaniel Fojt ctx, sizeof(ctx), erp->rIK, erp->rRK_len) < 0) {
484*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "EAP: Could not derive rIK for ERP");
485*a1157835SDaniel Fojt goto fail;
486*a1157835SDaniel Fojt }
487*a1157835SDaniel Fojt erp->rIK_len = erp->rRK_len;
488*a1157835SDaniel Fojt wpa_hexdump_key(MSG_DEBUG, "EAP: ERP rIK", erp->rIK, erp->rIK_len);
489*a1157835SDaniel Fojt
490*a1157835SDaniel Fojt if (eap_erp_add_key(sm, erp) == 0) {
491*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "EAP: Stored ERP keys %s",
492*a1157835SDaniel Fojt erp->keyname_nai);
493*a1157835SDaniel Fojt erp = NULL;
494*a1157835SDaniel Fojt }
495*a1157835SDaniel Fojt
496*a1157835SDaniel Fojt fail:
497*a1157835SDaniel Fojt bin_clear_free(emsk, emsk_len);
498*a1157835SDaniel Fojt bin_clear_free(erp, sizeof(*erp));
499*a1157835SDaniel Fojt #endif /* CONFIG_ERP */
500*a1157835SDaniel Fojt }
501*a1157835SDaniel Fojt
502*a1157835SDaniel Fojt
SM_STATE(EAP,METHOD_RESPONSE)5033ff40c12SJohn Marino SM_STATE(EAP, METHOD_RESPONSE)
5043ff40c12SJohn Marino {
5053ff40c12SJohn Marino SM_ENTRY(EAP, METHOD_RESPONSE);
5063ff40c12SJohn Marino
5073ff40c12SJohn Marino if (!eap_hdr_len_valid(sm->eap_if.eapRespData, 1))
5083ff40c12SJohn Marino return;
5093ff40c12SJohn Marino
5103ff40c12SJohn Marino sm->m->process(sm, sm->eap_method_priv, sm->eap_if.eapRespData);
5113ff40c12SJohn Marino if (sm->m->isDone(sm, sm->eap_method_priv)) {
5123ff40c12SJohn Marino eap_sm_Policy_update(sm, NULL, 0);
513*a1157835SDaniel Fojt bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
5143ff40c12SJohn Marino if (sm->m->getKey) {
5153ff40c12SJohn Marino sm->eap_if.eapKeyData = sm->m->getKey(
5163ff40c12SJohn Marino sm, sm->eap_method_priv,
5173ff40c12SJohn Marino &sm->eap_if.eapKeyDataLen);
5183ff40c12SJohn Marino } else {
5193ff40c12SJohn Marino sm->eap_if.eapKeyData = NULL;
5203ff40c12SJohn Marino sm->eap_if.eapKeyDataLen = 0;
5213ff40c12SJohn Marino }
522*a1157835SDaniel Fojt os_free(sm->eap_if.eapSessionId);
523*a1157835SDaniel Fojt sm->eap_if.eapSessionId = NULL;
524*a1157835SDaniel Fojt if (sm->m->getSessionId) {
525*a1157835SDaniel Fojt sm->eap_if.eapSessionId = sm->m->getSessionId(
526*a1157835SDaniel Fojt sm, sm->eap_method_priv,
527*a1157835SDaniel Fojt &sm->eap_if.eapSessionIdLen);
528*a1157835SDaniel Fojt wpa_hexdump(MSG_DEBUG, "EAP: Session-Id",
529*a1157835SDaniel Fojt sm->eap_if.eapSessionId,
530*a1157835SDaniel Fojt sm->eap_if.eapSessionIdLen);
531*a1157835SDaniel Fojt }
532*a1157835SDaniel Fojt if (sm->erp && sm->m->get_emsk && sm->eap_if.eapSessionId)
533*a1157835SDaniel Fojt eap_server_erp_init(sm);
5343ff40c12SJohn Marino sm->methodState = METHOD_END;
5353ff40c12SJohn Marino } else {
5363ff40c12SJohn Marino sm->methodState = METHOD_CONTINUE;
5373ff40c12SJohn Marino }
5383ff40c12SJohn Marino }
5393ff40c12SJohn Marino
5403ff40c12SJohn Marino
SM_STATE(EAP,PROPOSE_METHOD)5413ff40c12SJohn Marino SM_STATE(EAP, PROPOSE_METHOD)
5423ff40c12SJohn Marino {
5433ff40c12SJohn Marino int vendor;
5443ff40c12SJohn Marino EapType type;
5453ff40c12SJohn Marino
5463ff40c12SJohn Marino SM_ENTRY(EAP, PROPOSE_METHOD);
5473ff40c12SJohn Marino
548*a1157835SDaniel Fojt sm->try_initiate_reauth = FALSE;
5493ff40c12SJohn Marino try_another_method:
5503ff40c12SJohn Marino type = eap_sm_Policy_getNextMethod(sm, &vendor);
5513ff40c12SJohn Marino if (vendor == EAP_VENDOR_IETF)
5523ff40c12SJohn Marino sm->currentMethod = type;
5533ff40c12SJohn Marino else
5543ff40c12SJohn Marino sm->currentMethod = EAP_TYPE_EXPANDED;
5553ff40c12SJohn Marino if (sm->m && sm->eap_method_priv) {
5563ff40c12SJohn Marino sm->m->reset(sm, sm->eap_method_priv);
5573ff40c12SJohn Marino sm->eap_method_priv = NULL;
5583ff40c12SJohn Marino }
5593ff40c12SJohn Marino sm->m = eap_server_get_eap_method(vendor, type);
5603ff40c12SJohn Marino if (sm->m) {
5613ff40c12SJohn Marino sm->eap_method_priv = sm->m->init(sm);
5623ff40c12SJohn Marino if (sm->eap_method_priv == NULL) {
5633ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Failed to initialize EAP "
5643ff40c12SJohn Marino "method %d", sm->currentMethod);
5653ff40c12SJohn Marino sm->m = NULL;
5663ff40c12SJohn Marino sm->currentMethod = EAP_TYPE_NONE;
5673ff40c12SJohn Marino goto try_another_method;
5683ff40c12SJohn Marino }
5693ff40c12SJohn Marino }
5703ff40c12SJohn Marino if (sm->m == NULL) {
5713ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Could not find suitable EAP method");
572*a1157835SDaniel Fojt eap_log_msg(sm, "Could not find suitable EAP method");
5733ff40c12SJohn Marino sm->decision = DECISION_FAILURE;
5743ff40c12SJohn Marino return;
5753ff40c12SJohn Marino }
5763ff40c12SJohn Marino if (sm->currentMethod == EAP_TYPE_IDENTITY ||
5773ff40c12SJohn Marino sm->currentMethod == EAP_TYPE_NOTIFICATION)
5783ff40c12SJohn Marino sm->methodState = METHOD_CONTINUE;
5793ff40c12SJohn Marino else
5803ff40c12SJohn Marino sm->methodState = METHOD_PROPOSED;
5813ff40c12SJohn Marino
5823ff40c12SJohn Marino wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD
5833ff40c12SJohn Marino "vendor=%u method=%u", vendor, sm->currentMethod);
584*a1157835SDaniel Fojt eap_log_msg(sm, "Propose EAP method vendor=%u method=%u",
585*a1157835SDaniel Fojt vendor, sm->currentMethod);
5863ff40c12SJohn Marino }
5873ff40c12SJohn Marino
5883ff40c12SJohn Marino
SM_STATE(EAP,NAK)5893ff40c12SJohn Marino SM_STATE(EAP, NAK)
5903ff40c12SJohn Marino {
5913ff40c12SJohn Marino const struct eap_hdr *nak;
5923ff40c12SJohn Marino size_t len = 0;
5933ff40c12SJohn Marino const u8 *pos;
5943ff40c12SJohn Marino const u8 *nak_list = NULL;
5953ff40c12SJohn Marino
5963ff40c12SJohn Marino SM_ENTRY(EAP, NAK);
5973ff40c12SJohn Marino
5983ff40c12SJohn Marino if (sm->eap_method_priv) {
5993ff40c12SJohn Marino sm->m->reset(sm, sm->eap_method_priv);
6003ff40c12SJohn Marino sm->eap_method_priv = NULL;
6013ff40c12SJohn Marino }
6023ff40c12SJohn Marino sm->m = NULL;
6033ff40c12SJohn Marino
6043ff40c12SJohn Marino if (!eap_hdr_len_valid(sm->eap_if.eapRespData, 1))
6053ff40c12SJohn Marino return;
6063ff40c12SJohn Marino
6073ff40c12SJohn Marino nak = wpabuf_head(sm->eap_if.eapRespData);
6083ff40c12SJohn Marino if (nak && wpabuf_len(sm->eap_if.eapRespData) > sizeof(*nak)) {
6093ff40c12SJohn Marino len = be_to_host16(nak->length);
6103ff40c12SJohn Marino if (len > wpabuf_len(sm->eap_if.eapRespData))
6113ff40c12SJohn Marino len = wpabuf_len(sm->eap_if.eapRespData);
6123ff40c12SJohn Marino pos = (const u8 *) (nak + 1);
6133ff40c12SJohn Marino len -= sizeof(*nak);
6143ff40c12SJohn Marino if (*pos == EAP_TYPE_NAK) {
6153ff40c12SJohn Marino pos++;
6163ff40c12SJohn Marino len--;
6173ff40c12SJohn Marino nak_list = pos;
6183ff40c12SJohn Marino }
6193ff40c12SJohn Marino }
6203ff40c12SJohn Marino eap_sm_Policy_update(sm, nak_list, len);
6213ff40c12SJohn Marino }
6223ff40c12SJohn Marino
6233ff40c12SJohn Marino
SM_STATE(EAP,SELECT_ACTION)6243ff40c12SJohn Marino SM_STATE(EAP, SELECT_ACTION)
6253ff40c12SJohn Marino {
6263ff40c12SJohn Marino SM_ENTRY(EAP, SELECT_ACTION);
6273ff40c12SJohn Marino
6283ff40c12SJohn Marino sm->decision = eap_sm_Policy_getDecision(sm);
6293ff40c12SJohn Marino }
6303ff40c12SJohn Marino
6313ff40c12SJohn Marino
SM_STATE(EAP,TIMEOUT_FAILURE)6323ff40c12SJohn Marino SM_STATE(EAP, TIMEOUT_FAILURE)
6333ff40c12SJohn Marino {
6343ff40c12SJohn Marino SM_ENTRY(EAP, TIMEOUT_FAILURE);
6353ff40c12SJohn Marino
6363ff40c12SJohn Marino sm->eap_if.eapTimeout = TRUE;
637*a1157835SDaniel Fojt
638*a1157835SDaniel Fojt wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_TIMEOUT_FAILURE MACSTR,
639*a1157835SDaniel Fojt MAC2STR(sm->peer_addr));
6403ff40c12SJohn Marino }
6413ff40c12SJohn Marino
6423ff40c12SJohn Marino
SM_STATE(EAP,FAILURE)6433ff40c12SJohn Marino SM_STATE(EAP, FAILURE)
6443ff40c12SJohn Marino {
6453ff40c12SJohn Marino SM_ENTRY(EAP, FAILURE);
6463ff40c12SJohn Marino
6473ff40c12SJohn Marino wpabuf_free(sm->eap_if.eapReqData);
6483ff40c12SJohn Marino sm->eap_if.eapReqData = eap_sm_buildFailure(sm, sm->currentId);
6493ff40c12SJohn Marino wpabuf_free(sm->lastReqData);
6503ff40c12SJohn Marino sm->lastReqData = NULL;
6513ff40c12SJohn Marino sm->eap_if.eapFail = TRUE;
6523ff40c12SJohn Marino
6533ff40c12SJohn Marino wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
6543ff40c12SJohn Marino MACSTR, MAC2STR(sm->peer_addr));
6553ff40c12SJohn Marino }
6563ff40c12SJohn Marino
6573ff40c12SJohn Marino
SM_STATE(EAP,SUCCESS)6583ff40c12SJohn Marino SM_STATE(EAP, SUCCESS)
6593ff40c12SJohn Marino {
6603ff40c12SJohn Marino SM_ENTRY(EAP, SUCCESS);
6613ff40c12SJohn Marino
6623ff40c12SJohn Marino wpabuf_free(sm->eap_if.eapReqData);
6633ff40c12SJohn Marino sm->eap_if.eapReqData = eap_sm_buildSuccess(sm, sm->currentId);
6643ff40c12SJohn Marino wpabuf_free(sm->lastReqData);
6653ff40c12SJohn Marino sm->lastReqData = NULL;
6663ff40c12SJohn Marino if (sm->eap_if.eapKeyData)
6673ff40c12SJohn Marino sm->eap_if.eapKeyAvailable = TRUE;
6683ff40c12SJohn Marino sm->eap_if.eapSuccess = TRUE;
6693ff40c12SJohn Marino
6703ff40c12SJohn Marino wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
6713ff40c12SJohn Marino MACSTR, MAC2STR(sm->peer_addr));
6723ff40c12SJohn Marino }
6733ff40c12SJohn Marino
6743ff40c12SJohn Marino
SM_STATE(EAP,INITIATE_REAUTH_START)675*a1157835SDaniel Fojt SM_STATE(EAP, INITIATE_REAUTH_START)
676*a1157835SDaniel Fojt {
677*a1157835SDaniel Fojt SM_ENTRY(EAP, INITIATE_REAUTH_START);
678*a1157835SDaniel Fojt
679*a1157835SDaniel Fojt sm->initiate_reauth_start_sent = TRUE;
680*a1157835SDaniel Fojt sm->try_initiate_reauth = TRUE;
681*a1157835SDaniel Fojt sm->currentId = eap_sm_nextId(sm, sm->currentId);
682*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
683*a1157835SDaniel Fojt "EAP: building EAP-Initiate-Re-auth-Start: Identifier %d",
684*a1157835SDaniel Fojt sm->currentId);
685*a1157835SDaniel Fojt sm->lastId = sm->currentId;
686*a1157835SDaniel Fojt wpabuf_free(sm->eap_if.eapReqData);
687*a1157835SDaniel Fojt sm->eap_if.eapReqData = eap_sm_buildInitiateReauthStart(sm,
688*a1157835SDaniel Fojt sm->currentId);
689*a1157835SDaniel Fojt wpabuf_free(sm->lastReqData);
690*a1157835SDaniel Fojt sm->lastReqData = NULL;
691*a1157835SDaniel Fojt }
692*a1157835SDaniel Fojt
693*a1157835SDaniel Fojt
694*a1157835SDaniel Fojt #ifdef CONFIG_ERP
695*a1157835SDaniel Fojt
erp_send_finish_reauth(struct eap_sm * sm,struct eap_server_erp_key * erp,u8 id,u8 flags,u16 seq,const char * nai)696*a1157835SDaniel Fojt static void erp_send_finish_reauth(struct eap_sm *sm,
697*a1157835SDaniel Fojt struct eap_server_erp_key *erp, u8 id,
698*a1157835SDaniel Fojt u8 flags, u16 seq, const char *nai)
699*a1157835SDaniel Fojt {
700*a1157835SDaniel Fojt size_t plen;
701*a1157835SDaniel Fojt struct wpabuf *msg;
702*a1157835SDaniel Fojt u8 hash[SHA256_MAC_LEN];
703*a1157835SDaniel Fojt size_t hash_len;
704*a1157835SDaniel Fojt u8 seed[4];
705*a1157835SDaniel Fojt
706*a1157835SDaniel Fojt if (erp) {
707*a1157835SDaniel Fojt switch (erp->cryptosuite) {
708*a1157835SDaniel Fojt case EAP_ERP_CS_HMAC_SHA256_256:
709*a1157835SDaniel Fojt hash_len = 32;
710*a1157835SDaniel Fojt break;
711*a1157835SDaniel Fojt case EAP_ERP_CS_HMAC_SHA256_128:
712*a1157835SDaniel Fojt hash_len = 16;
713*a1157835SDaniel Fojt break;
714*a1157835SDaniel Fojt default:
715*a1157835SDaniel Fojt return;
716*a1157835SDaniel Fojt }
717*a1157835SDaniel Fojt } else
718*a1157835SDaniel Fojt hash_len = 0;
719*a1157835SDaniel Fojt
720*a1157835SDaniel Fojt plen = 1 + 2 + 2 + os_strlen(nai);
721*a1157835SDaniel Fojt if (hash_len)
722*a1157835SDaniel Fojt plen += 1 + hash_len;
723*a1157835SDaniel Fojt msg = eap_msg_alloc(EAP_VENDOR_IETF, (EapType) EAP_ERP_TYPE_REAUTH,
724*a1157835SDaniel Fojt plen, EAP_CODE_FINISH, id);
725*a1157835SDaniel Fojt if (msg == NULL)
726*a1157835SDaniel Fojt return;
727*a1157835SDaniel Fojt wpabuf_put_u8(msg, flags);
728*a1157835SDaniel Fojt wpabuf_put_be16(msg, seq);
729*a1157835SDaniel Fojt
730*a1157835SDaniel Fojt wpabuf_put_u8(msg, EAP_ERP_TLV_KEYNAME_NAI);
731*a1157835SDaniel Fojt wpabuf_put_u8(msg, os_strlen(nai));
732*a1157835SDaniel Fojt wpabuf_put_str(msg, nai);
733*a1157835SDaniel Fojt
734*a1157835SDaniel Fojt if (erp) {
735*a1157835SDaniel Fojt wpabuf_put_u8(msg, erp->cryptosuite);
736*a1157835SDaniel Fojt if (hmac_sha256(erp->rIK, erp->rIK_len,
737*a1157835SDaniel Fojt wpabuf_head(msg), wpabuf_len(msg), hash) < 0) {
738*a1157835SDaniel Fojt wpabuf_free(msg);
739*a1157835SDaniel Fojt return;
740*a1157835SDaniel Fojt }
741*a1157835SDaniel Fojt wpabuf_put_data(msg, hash, hash_len);
742*a1157835SDaniel Fojt }
743*a1157835SDaniel Fojt
744*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "EAP: Send EAP-Finish/Re-auth (%s)",
745*a1157835SDaniel Fojt flags & 0x80 ? "failure" : "success");
746*a1157835SDaniel Fojt
747*a1157835SDaniel Fojt sm->lastId = sm->currentId;
748*a1157835SDaniel Fojt sm->currentId = id;
749*a1157835SDaniel Fojt wpabuf_free(sm->eap_if.eapReqData);
750*a1157835SDaniel Fojt sm->eap_if.eapReqData = msg;
751*a1157835SDaniel Fojt wpabuf_free(sm->lastReqData);
752*a1157835SDaniel Fojt sm->lastReqData = NULL;
753*a1157835SDaniel Fojt
754*a1157835SDaniel Fojt if ((flags & 0x80) || !erp) {
755*a1157835SDaniel Fojt sm->eap_if.eapFail = TRUE;
756*a1157835SDaniel Fojt wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE
757*a1157835SDaniel Fojt MACSTR, MAC2STR(sm->peer_addr));
758*a1157835SDaniel Fojt return;
759*a1157835SDaniel Fojt }
760*a1157835SDaniel Fojt
761*a1157835SDaniel Fojt bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
762*a1157835SDaniel Fojt sm->eap_if.eapKeyDataLen = 0;
763*a1157835SDaniel Fojt sm->eap_if.eapKeyData = os_malloc(erp->rRK_len);
764*a1157835SDaniel Fojt if (!sm->eap_if.eapKeyData)
765*a1157835SDaniel Fojt return;
766*a1157835SDaniel Fojt
767*a1157835SDaniel Fojt WPA_PUT_BE16(seed, seq);
768*a1157835SDaniel Fojt WPA_PUT_BE16(&seed[2], erp->rRK_len);
769*a1157835SDaniel Fojt if (hmac_sha256_kdf(erp->rRK, erp->rRK_len,
770*a1157835SDaniel Fojt "Re-authentication Master Session Key@ietf.org",
771*a1157835SDaniel Fojt seed, sizeof(seed),
772*a1157835SDaniel Fojt sm->eap_if.eapKeyData, erp->rRK_len) < 0) {
773*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "EAP: Could not derive rMSK for ERP");
774*a1157835SDaniel Fojt bin_clear_free(sm->eap_if.eapKeyData, erp->rRK_len);
775*a1157835SDaniel Fojt sm->eap_if.eapKeyData = NULL;
776*a1157835SDaniel Fojt return;
777*a1157835SDaniel Fojt }
778*a1157835SDaniel Fojt sm->eap_if.eapKeyDataLen = erp->rRK_len;
779*a1157835SDaniel Fojt sm->eap_if.eapKeyAvailable = TRUE;
780*a1157835SDaniel Fojt wpa_hexdump_key(MSG_DEBUG, "EAP: ERP rMSK",
781*a1157835SDaniel Fojt sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
782*a1157835SDaniel Fojt sm->eap_if.eapSuccess = TRUE;
783*a1157835SDaniel Fojt
784*a1157835SDaniel Fojt wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS
785*a1157835SDaniel Fojt MACSTR, MAC2STR(sm->peer_addr));
786*a1157835SDaniel Fojt }
787*a1157835SDaniel Fojt
788*a1157835SDaniel Fojt
SM_STATE(EAP,INITIATE_RECEIVED)789*a1157835SDaniel Fojt SM_STATE(EAP, INITIATE_RECEIVED)
790*a1157835SDaniel Fojt {
791*a1157835SDaniel Fojt const u8 *pos, *end, *start, *tlvs, *hdr;
792*a1157835SDaniel Fojt const struct eap_hdr *ehdr;
793*a1157835SDaniel Fojt size_t len;
794*a1157835SDaniel Fojt u8 flags;
795*a1157835SDaniel Fojt u16 seq;
796*a1157835SDaniel Fojt char nai[254];
797*a1157835SDaniel Fojt struct eap_server_erp_key *erp;
798*a1157835SDaniel Fojt int max_len;
799*a1157835SDaniel Fojt u8 hash[SHA256_MAC_LEN];
800*a1157835SDaniel Fojt size_t hash_len;
801*a1157835SDaniel Fojt struct erp_tlvs parse;
802*a1157835SDaniel Fojt u8 resp_flags = 0x80; /* default to failure; cleared on success */
803*a1157835SDaniel Fojt
804*a1157835SDaniel Fojt SM_ENTRY(EAP, INITIATE_RECEIVED);
805*a1157835SDaniel Fojt
806*a1157835SDaniel Fojt sm->rxInitiate = FALSE;
807*a1157835SDaniel Fojt
808*a1157835SDaniel Fojt pos = eap_hdr_validate(EAP_VENDOR_IETF, (EapType) EAP_ERP_TYPE_REAUTH,
809*a1157835SDaniel Fojt sm->eap_if.eapRespData, &len);
810*a1157835SDaniel Fojt if (pos == NULL) {
811*a1157835SDaniel Fojt wpa_printf(MSG_INFO, "EAP-Initiate: Invalid frame");
812*a1157835SDaniel Fojt goto fail;
813*a1157835SDaniel Fojt }
814*a1157835SDaniel Fojt hdr = wpabuf_head(sm->eap_if.eapRespData);
815*a1157835SDaniel Fojt ehdr = wpabuf_head(sm->eap_if.eapRespData);
816*a1157835SDaniel Fojt
817*a1157835SDaniel Fojt wpa_hexdump(MSG_DEBUG, "EAP: EAP-Initiate/Re-Auth", pos, len);
818*a1157835SDaniel Fojt if (len < 4) {
819*a1157835SDaniel Fojt wpa_printf(MSG_INFO, "EAP: Too short EAP-Initiate/Re-auth");
820*a1157835SDaniel Fojt goto fail;
821*a1157835SDaniel Fojt }
822*a1157835SDaniel Fojt end = pos + len;
823*a1157835SDaniel Fojt
824*a1157835SDaniel Fojt flags = *pos++;
825*a1157835SDaniel Fojt seq = WPA_GET_BE16(pos);
826*a1157835SDaniel Fojt pos += 2;
827*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "EAP: Flags=0x%x SEQ=%u", flags, seq);
828*a1157835SDaniel Fojt tlvs = pos;
829*a1157835SDaniel Fojt
830*a1157835SDaniel Fojt /*
831*a1157835SDaniel Fojt * Parse TVs/TLVs. Since we do not yet know the length of the
832*a1157835SDaniel Fojt * Authentication Tag, stop parsing if an unknown TV/TLV is seen and
833*a1157835SDaniel Fojt * just try to find the keyName-NAI first so that we can check the
834*a1157835SDaniel Fojt * Authentication Tag.
835*a1157835SDaniel Fojt */
836*a1157835SDaniel Fojt if (erp_parse_tlvs(tlvs, end, &parse, 1) < 0)
837*a1157835SDaniel Fojt goto fail;
838*a1157835SDaniel Fojt
839*a1157835SDaniel Fojt if (!parse.keyname) {
840*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
841*a1157835SDaniel Fojt "EAP: No keyName-NAI in EAP-Initiate/Re-auth Packet");
842*a1157835SDaniel Fojt goto fail;
843*a1157835SDaniel Fojt }
844*a1157835SDaniel Fojt
845*a1157835SDaniel Fojt wpa_hexdump_ascii(MSG_DEBUG, "EAP: EAP-Initiate/Re-auth - keyName-NAI",
846*a1157835SDaniel Fojt parse.keyname, parse.keyname_len);
847*a1157835SDaniel Fojt if (parse.keyname_len > 253) {
848*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
849*a1157835SDaniel Fojt "EAP: Too long keyName-NAI in EAP-Initiate/Re-auth");
850*a1157835SDaniel Fojt goto fail;
851*a1157835SDaniel Fojt }
852*a1157835SDaniel Fojt os_memcpy(nai, parse.keyname, parse.keyname_len);
853*a1157835SDaniel Fojt nai[parse.keyname_len] = '\0';
854*a1157835SDaniel Fojt
855*a1157835SDaniel Fojt if (!sm->eap_server) {
856*a1157835SDaniel Fojt /*
857*a1157835SDaniel Fojt * In passthrough case, EAP-Initiate/Re-auth replaces
858*a1157835SDaniel Fojt * EAP Identity exchange. Use keyName-NAI as the user identity
859*a1157835SDaniel Fojt * and forward EAP-Initiate/Re-auth to the backend
860*a1157835SDaniel Fojt * authentication server.
861*a1157835SDaniel Fojt */
862*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
863*a1157835SDaniel Fojt "EAP: Use keyName-NAI as user identity for backend authentication");
864*a1157835SDaniel Fojt eap_server_clear_identity(sm);
865*a1157835SDaniel Fojt sm->identity = (u8 *) dup_binstr(parse.keyname,
866*a1157835SDaniel Fojt parse.keyname_len);
867*a1157835SDaniel Fojt if (!sm->identity)
868*a1157835SDaniel Fojt goto fail;
869*a1157835SDaniel Fojt sm->identity_len = parse.keyname_len;
870*a1157835SDaniel Fojt return;
871*a1157835SDaniel Fojt }
872*a1157835SDaniel Fojt
873*a1157835SDaniel Fojt erp = eap_erp_get_key(sm, nai);
874*a1157835SDaniel Fojt if (!erp) {
875*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "EAP: No matching ERP key found for %s",
876*a1157835SDaniel Fojt nai);
877*a1157835SDaniel Fojt goto report_error;
878*a1157835SDaniel Fojt }
879*a1157835SDaniel Fojt
880*a1157835SDaniel Fojt if (erp->recv_seq != (u32) -1 && erp->recv_seq >= seq) {
881*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
882*a1157835SDaniel Fojt "EAP: SEQ=%u replayed (already received SEQ=%u)",
883*a1157835SDaniel Fojt seq, erp->recv_seq);
884*a1157835SDaniel Fojt goto fail;
885*a1157835SDaniel Fojt }
886*a1157835SDaniel Fojt
887*a1157835SDaniel Fojt /* Is there enough room for Cryptosuite and Authentication Tag? */
888*a1157835SDaniel Fojt start = parse.keyname + parse.keyname_len;
889*a1157835SDaniel Fojt max_len = end - start;
890*a1157835SDaniel Fojt if (max_len <
891*a1157835SDaniel Fojt 1 + (erp->cryptosuite == EAP_ERP_CS_HMAC_SHA256_256 ? 32 : 16)) {
892*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
893*a1157835SDaniel Fojt "EAP: Not enough room for Authentication Tag");
894*a1157835SDaniel Fojt goto fail;
895*a1157835SDaniel Fojt }
896*a1157835SDaniel Fojt
897*a1157835SDaniel Fojt switch (erp->cryptosuite) {
898*a1157835SDaniel Fojt case EAP_ERP_CS_HMAC_SHA256_256:
899*a1157835SDaniel Fojt if (end[-33] != erp->cryptosuite) {
900*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
901*a1157835SDaniel Fojt "EAP: Different Cryptosuite used");
902*a1157835SDaniel Fojt goto fail;
903*a1157835SDaniel Fojt }
904*a1157835SDaniel Fojt hash_len = 32;
905*a1157835SDaniel Fojt break;
906*a1157835SDaniel Fojt case EAP_ERP_CS_HMAC_SHA256_128:
907*a1157835SDaniel Fojt if (end[-17] != erp->cryptosuite) {
908*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
909*a1157835SDaniel Fojt "EAP: Different Cryptosuite used");
910*a1157835SDaniel Fojt goto fail;
911*a1157835SDaniel Fojt }
912*a1157835SDaniel Fojt hash_len = 16;
913*a1157835SDaniel Fojt break;
914*a1157835SDaniel Fojt default:
915*a1157835SDaniel Fojt hash_len = 0;
916*a1157835SDaniel Fojt break;
917*a1157835SDaniel Fojt }
918*a1157835SDaniel Fojt
919*a1157835SDaniel Fojt if (hash_len) {
920*a1157835SDaniel Fojt if (hmac_sha256(erp->rIK, erp->rIK_len, hdr,
921*a1157835SDaniel Fojt end - hdr - hash_len, hash) < 0)
922*a1157835SDaniel Fojt goto fail;
923*a1157835SDaniel Fojt if (os_memcmp(end - hash_len, hash, hash_len) != 0) {
924*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
925*a1157835SDaniel Fojt "EAP: Authentication Tag mismatch");
926*a1157835SDaniel Fojt goto fail;
927*a1157835SDaniel Fojt }
928*a1157835SDaniel Fojt }
929*a1157835SDaniel Fojt
930*a1157835SDaniel Fojt /* Check if any supported CS results in matching tag */
931*a1157835SDaniel Fojt if (!hash_len && max_len >= 1 + 32 &&
932*a1157835SDaniel Fojt end[-33] == EAP_ERP_CS_HMAC_SHA256_256) {
933*a1157835SDaniel Fojt if (hmac_sha256(erp->rIK, erp->rIK_len, hdr,
934*a1157835SDaniel Fojt end - hdr - 32, hash) < 0)
935*a1157835SDaniel Fojt goto fail;
936*a1157835SDaniel Fojt if (os_memcmp(end - 32, hash, 32) == 0) {
937*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
938*a1157835SDaniel Fojt "EAP: Authentication Tag match using HMAC-SHA256-256");
939*a1157835SDaniel Fojt hash_len = 32;
940*a1157835SDaniel Fojt erp->cryptosuite = EAP_ERP_CS_HMAC_SHA256_256;
941*a1157835SDaniel Fojt }
942*a1157835SDaniel Fojt }
943*a1157835SDaniel Fojt
944*a1157835SDaniel Fojt if (!hash_len && end[-17] == EAP_ERP_CS_HMAC_SHA256_128) {
945*a1157835SDaniel Fojt if (hmac_sha256(erp->rIK, erp->rIK_len, hdr,
946*a1157835SDaniel Fojt end - hdr - 16, hash) < 0)
947*a1157835SDaniel Fojt goto fail;
948*a1157835SDaniel Fojt if (os_memcmp(end - 16, hash, 16) == 0) {
949*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
950*a1157835SDaniel Fojt "EAP: Authentication Tag match using HMAC-SHA256-128");
951*a1157835SDaniel Fojt hash_len = 16;
952*a1157835SDaniel Fojt erp->cryptosuite = EAP_ERP_CS_HMAC_SHA256_128;
953*a1157835SDaniel Fojt }
954*a1157835SDaniel Fojt }
955*a1157835SDaniel Fojt
956*a1157835SDaniel Fojt if (!hash_len) {
957*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
958*a1157835SDaniel Fojt "EAP: No supported cryptosuite matched Authentication Tag");
959*a1157835SDaniel Fojt goto fail;
960*a1157835SDaniel Fojt }
961*a1157835SDaniel Fojt end -= 1 + hash_len;
962*a1157835SDaniel Fojt
963*a1157835SDaniel Fojt /*
964*a1157835SDaniel Fojt * Parse TVs/TLVs again now that we know the exact part of the buffer
965*a1157835SDaniel Fojt * that contains them.
966*a1157835SDaniel Fojt */
967*a1157835SDaniel Fojt wpa_hexdump(MSG_DEBUG, "EAP: EAP-Initiate/Re-Auth TVs/TLVs",
968*a1157835SDaniel Fojt tlvs, end - tlvs);
969*a1157835SDaniel Fojt if (erp_parse_tlvs(tlvs, end, &parse, 0) < 0)
970*a1157835SDaniel Fojt goto fail;
971*a1157835SDaniel Fojt
972*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "EAP: ERP key %s SEQ updated to %u",
973*a1157835SDaniel Fojt erp->keyname_nai, seq);
974*a1157835SDaniel Fojt erp->recv_seq = seq;
975*a1157835SDaniel Fojt resp_flags &= ~0x80; /* R=0 - success */
976*a1157835SDaniel Fojt
977*a1157835SDaniel Fojt report_error:
978*a1157835SDaniel Fojt erp_send_finish_reauth(sm, erp, ehdr->identifier, resp_flags, seq, nai);
979*a1157835SDaniel Fojt return;
980*a1157835SDaniel Fojt
981*a1157835SDaniel Fojt fail:
982*a1157835SDaniel Fojt sm->ignore = TRUE;
983*a1157835SDaniel Fojt }
984*a1157835SDaniel Fojt
985*a1157835SDaniel Fojt #endif /* CONFIG_ERP */
986*a1157835SDaniel Fojt
987*a1157835SDaniel Fojt
SM_STATE(EAP,INITIALIZE_PASSTHROUGH)9883ff40c12SJohn Marino SM_STATE(EAP, INITIALIZE_PASSTHROUGH)
9893ff40c12SJohn Marino {
9903ff40c12SJohn Marino SM_ENTRY(EAP, INITIALIZE_PASSTHROUGH);
9913ff40c12SJohn Marino
9923ff40c12SJohn Marino wpabuf_free(sm->eap_if.aaaEapRespData);
9933ff40c12SJohn Marino sm->eap_if.aaaEapRespData = NULL;
994*a1157835SDaniel Fojt sm->try_initiate_reauth = FALSE;
9953ff40c12SJohn Marino }
9963ff40c12SJohn Marino
9973ff40c12SJohn Marino
SM_STATE(EAP,IDLE2)9983ff40c12SJohn Marino SM_STATE(EAP, IDLE2)
9993ff40c12SJohn Marino {
10003ff40c12SJohn Marino SM_ENTRY(EAP, IDLE2);
10013ff40c12SJohn Marino
10023ff40c12SJohn Marino sm->eap_if.retransWhile = eap_sm_calculateTimeout(
10033ff40c12SJohn Marino sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
10043ff40c12SJohn Marino sm->methodTimeout);
10053ff40c12SJohn Marino }
10063ff40c12SJohn Marino
10073ff40c12SJohn Marino
SM_STATE(EAP,RETRANSMIT2)10083ff40c12SJohn Marino SM_STATE(EAP, RETRANSMIT2)
10093ff40c12SJohn Marino {
10103ff40c12SJohn Marino SM_ENTRY(EAP, RETRANSMIT2);
10113ff40c12SJohn Marino
10123ff40c12SJohn Marino sm->retransCount++;
10133ff40c12SJohn Marino if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
10143ff40c12SJohn Marino if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
10153ff40c12SJohn Marino sm->eap_if.eapReq = TRUE;
10163ff40c12SJohn Marino }
1017*a1157835SDaniel Fojt
1018*a1157835SDaniel Fojt wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_RETRANSMIT2 MACSTR,
1019*a1157835SDaniel Fojt MAC2STR(sm->peer_addr));
10203ff40c12SJohn Marino }
10213ff40c12SJohn Marino
10223ff40c12SJohn Marino
SM_STATE(EAP,RECEIVED2)10233ff40c12SJohn Marino SM_STATE(EAP, RECEIVED2)
10243ff40c12SJohn Marino {
10253ff40c12SJohn Marino SM_ENTRY(EAP, RECEIVED2);
10263ff40c12SJohn Marino
10273ff40c12SJohn Marino /* parse rxResp, respId, respMethod */
10283ff40c12SJohn Marino eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
10293ff40c12SJohn Marino }
10303ff40c12SJohn Marino
10313ff40c12SJohn Marino
SM_STATE(EAP,DISCARD2)10323ff40c12SJohn Marino SM_STATE(EAP, DISCARD2)
10333ff40c12SJohn Marino {
10343ff40c12SJohn Marino SM_ENTRY(EAP, DISCARD2);
10353ff40c12SJohn Marino sm->eap_if.eapResp = FALSE;
10363ff40c12SJohn Marino sm->eap_if.eapNoReq = TRUE;
10373ff40c12SJohn Marino }
10383ff40c12SJohn Marino
10393ff40c12SJohn Marino
SM_STATE(EAP,SEND_REQUEST2)10403ff40c12SJohn Marino SM_STATE(EAP, SEND_REQUEST2)
10413ff40c12SJohn Marino {
10423ff40c12SJohn Marino SM_ENTRY(EAP, SEND_REQUEST2);
10433ff40c12SJohn Marino
10443ff40c12SJohn Marino sm->retransCount = 0;
10453ff40c12SJohn Marino if (sm->eap_if.eapReqData) {
10463ff40c12SJohn Marino if (eap_copy_buf(&sm->lastReqData, sm->eap_if.eapReqData) == 0)
10473ff40c12SJohn Marino {
10483ff40c12SJohn Marino sm->eap_if.eapResp = FALSE;
10493ff40c12SJohn Marino sm->eap_if.eapReq = TRUE;
10503ff40c12SJohn Marino } else {
10513ff40c12SJohn Marino sm->eap_if.eapResp = FALSE;
10523ff40c12SJohn Marino sm->eap_if.eapReq = FALSE;
10533ff40c12SJohn Marino }
10543ff40c12SJohn Marino } else {
10553ff40c12SJohn Marino wpa_printf(MSG_INFO, "EAP: SEND_REQUEST2 - no eapReqData");
10563ff40c12SJohn Marino sm->eap_if.eapResp = FALSE;
10573ff40c12SJohn Marino sm->eap_if.eapReq = FALSE;
10583ff40c12SJohn Marino sm->eap_if.eapNoReq = TRUE;
10593ff40c12SJohn Marino }
10603ff40c12SJohn Marino }
10613ff40c12SJohn Marino
10623ff40c12SJohn Marino
SM_STATE(EAP,AAA_REQUEST)10633ff40c12SJohn Marino SM_STATE(EAP, AAA_REQUEST)
10643ff40c12SJohn Marino {
10653ff40c12SJohn Marino SM_ENTRY(EAP, AAA_REQUEST);
10663ff40c12SJohn Marino
10673ff40c12SJohn Marino if (sm->eap_if.eapRespData == NULL) {
10683ff40c12SJohn Marino wpa_printf(MSG_INFO, "EAP: AAA_REQUEST - no eapRespData");
10693ff40c12SJohn Marino return;
10703ff40c12SJohn Marino }
10713ff40c12SJohn Marino
10723ff40c12SJohn Marino /*
10733ff40c12SJohn Marino * if (respMethod == IDENTITY)
10743ff40c12SJohn Marino * aaaIdentity = eapRespData
10753ff40c12SJohn Marino * This is already taken care of by the EAP-Identity method which
10763ff40c12SJohn Marino * stores the identity into sm->identity.
10773ff40c12SJohn Marino */
10783ff40c12SJohn Marino
10793ff40c12SJohn Marino eap_copy_buf(&sm->eap_if.aaaEapRespData, sm->eap_if.eapRespData);
10803ff40c12SJohn Marino }
10813ff40c12SJohn Marino
10823ff40c12SJohn Marino
SM_STATE(EAP,AAA_RESPONSE)10833ff40c12SJohn Marino SM_STATE(EAP, AAA_RESPONSE)
10843ff40c12SJohn Marino {
10853ff40c12SJohn Marino SM_ENTRY(EAP, AAA_RESPONSE);
10863ff40c12SJohn Marino
10873ff40c12SJohn Marino eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
10883ff40c12SJohn Marino sm->currentId = eap_sm_getId(sm->eap_if.eapReqData);
10893ff40c12SJohn Marino sm->methodTimeout = sm->eap_if.aaaMethodTimeout;
10903ff40c12SJohn Marino }
10913ff40c12SJohn Marino
10923ff40c12SJohn Marino
SM_STATE(EAP,AAA_IDLE)10933ff40c12SJohn Marino SM_STATE(EAP, AAA_IDLE)
10943ff40c12SJohn Marino {
10953ff40c12SJohn Marino SM_ENTRY(EAP, AAA_IDLE);
10963ff40c12SJohn Marino
10973ff40c12SJohn Marino sm->eap_if.aaaFail = FALSE;
10983ff40c12SJohn Marino sm->eap_if.aaaSuccess = FALSE;
10993ff40c12SJohn Marino sm->eap_if.aaaEapReq = FALSE;
11003ff40c12SJohn Marino sm->eap_if.aaaEapNoReq = FALSE;
11013ff40c12SJohn Marino sm->eap_if.aaaEapResp = TRUE;
11023ff40c12SJohn Marino }
11033ff40c12SJohn Marino
11043ff40c12SJohn Marino
SM_STATE(EAP,TIMEOUT_FAILURE2)11053ff40c12SJohn Marino SM_STATE(EAP, TIMEOUT_FAILURE2)
11063ff40c12SJohn Marino {
11073ff40c12SJohn Marino SM_ENTRY(EAP, TIMEOUT_FAILURE2);
11083ff40c12SJohn Marino
11093ff40c12SJohn Marino sm->eap_if.eapTimeout = TRUE;
1110*a1157835SDaniel Fojt
1111*a1157835SDaniel Fojt wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_TIMEOUT_FAILURE2 MACSTR,
1112*a1157835SDaniel Fojt MAC2STR(sm->peer_addr));
11133ff40c12SJohn Marino }
11143ff40c12SJohn Marino
11153ff40c12SJohn Marino
SM_STATE(EAP,FAILURE2)11163ff40c12SJohn Marino SM_STATE(EAP, FAILURE2)
11173ff40c12SJohn Marino {
11183ff40c12SJohn Marino SM_ENTRY(EAP, FAILURE2);
11193ff40c12SJohn Marino
11203ff40c12SJohn Marino eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
11213ff40c12SJohn Marino sm->eap_if.eapFail = TRUE;
1122*a1157835SDaniel Fojt
1123*a1157835SDaniel Fojt wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_FAILURE2 MACSTR,
1124*a1157835SDaniel Fojt MAC2STR(sm->peer_addr));
11253ff40c12SJohn Marino }
11263ff40c12SJohn Marino
11273ff40c12SJohn Marino
SM_STATE(EAP,SUCCESS2)11283ff40c12SJohn Marino SM_STATE(EAP, SUCCESS2)
11293ff40c12SJohn Marino {
11303ff40c12SJohn Marino SM_ENTRY(EAP, SUCCESS2);
11313ff40c12SJohn Marino
11323ff40c12SJohn Marino eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
11333ff40c12SJohn Marino
11343ff40c12SJohn Marino sm->eap_if.eapKeyAvailable = sm->eap_if.aaaEapKeyAvailable;
11353ff40c12SJohn Marino if (sm->eap_if.aaaEapKeyAvailable) {
11363ff40c12SJohn Marino EAP_COPY(&sm->eap_if.eapKeyData, sm->eap_if.aaaEapKeyData);
11373ff40c12SJohn Marino } else {
1138*a1157835SDaniel Fojt bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
11393ff40c12SJohn Marino sm->eap_if.eapKeyData = NULL;
11403ff40c12SJohn Marino sm->eap_if.eapKeyDataLen = 0;
11413ff40c12SJohn Marino }
11423ff40c12SJohn Marino
11433ff40c12SJohn Marino sm->eap_if.eapSuccess = TRUE;
11443ff40c12SJohn Marino
11453ff40c12SJohn Marino /*
11463ff40c12SJohn Marino * Start reauthentication with identity request even though we know the
11473ff40c12SJohn Marino * previously used identity. This is needed to get reauthentication
11483ff40c12SJohn Marino * started properly.
11493ff40c12SJohn Marino */
11503ff40c12SJohn Marino sm->start_reauth = TRUE;
1151*a1157835SDaniel Fojt
1152*a1157835SDaniel Fojt wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS2 MACSTR,
1153*a1157835SDaniel Fojt MAC2STR(sm->peer_addr));
11543ff40c12SJohn Marino }
11553ff40c12SJohn Marino
11563ff40c12SJohn Marino
SM_STEP(EAP)11573ff40c12SJohn Marino SM_STEP(EAP)
11583ff40c12SJohn Marino {
11593ff40c12SJohn Marino if (sm->eap_if.eapRestart && sm->eap_if.portEnabled)
11603ff40c12SJohn Marino SM_ENTER_GLOBAL(EAP, INITIALIZE);
11613ff40c12SJohn Marino else if (!sm->eap_if.portEnabled)
11623ff40c12SJohn Marino SM_ENTER_GLOBAL(EAP, DISABLED);
11633ff40c12SJohn Marino else if (sm->num_rounds > EAP_MAX_AUTH_ROUNDS) {
11643ff40c12SJohn Marino if (sm->num_rounds == EAP_MAX_AUTH_ROUNDS + 1) {
11653ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: more than %d "
11663ff40c12SJohn Marino "authentication rounds - abort",
11673ff40c12SJohn Marino EAP_MAX_AUTH_ROUNDS);
11683ff40c12SJohn Marino sm->num_rounds++;
11693ff40c12SJohn Marino SM_ENTER_GLOBAL(EAP, FAILURE);
11703ff40c12SJohn Marino }
11713ff40c12SJohn Marino } else switch (sm->EAP_state) {
11723ff40c12SJohn Marino case EAP_INITIALIZE:
11733ff40c12SJohn Marino if (sm->backend_auth) {
11743ff40c12SJohn Marino if (!sm->rxResp)
11753ff40c12SJohn Marino SM_ENTER(EAP, SELECT_ACTION);
11763ff40c12SJohn Marino else if (sm->rxResp &&
11773ff40c12SJohn Marino (sm->respMethod == EAP_TYPE_NAK ||
11783ff40c12SJohn Marino (sm->respMethod == EAP_TYPE_EXPANDED &&
11793ff40c12SJohn Marino sm->respVendor == EAP_VENDOR_IETF &&
11803ff40c12SJohn Marino sm->respVendorMethod == EAP_TYPE_NAK)))
11813ff40c12SJohn Marino SM_ENTER(EAP, NAK);
11823ff40c12SJohn Marino else
11833ff40c12SJohn Marino SM_ENTER(EAP, PICK_UP_METHOD);
11843ff40c12SJohn Marino } else {
11853ff40c12SJohn Marino SM_ENTER(EAP, SELECT_ACTION);
11863ff40c12SJohn Marino }
11873ff40c12SJohn Marino break;
11883ff40c12SJohn Marino case EAP_PICK_UP_METHOD:
11893ff40c12SJohn Marino if (sm->currentMethod == EAP_TYPE_NONE) {
11903ff40c12SJohn Marino SM_ENTER(EAP, SELECT_ACTION);
11913ff40c12SJohn Marino } else {
11923ff40c12SJohn Marino SM_ENTER(EAP, METHOD_RESPONSE);
11933ff40c12SJohn Marino }
11943ff40c12SJohn Marino break;
11953ff40c12SJohn Marino case EAP_DISABLED:
11963ff40c12SJohn Marino if (sm->eap_if.portEnabled)
11973ff40c12SJohn Marino SM_ENTER(EAP, INITIALIZE);
11983ff40c12SJohn Marino break;
11993ff40c12SJohn Marino case EAP_IDLE:
1200*a1157835SDaniel Fojt if (sm->eap_if.retransWhile == 0) {
1201*a1157835SDaniel Fojt if (sm->try_initiate_reauth) {
1202*a1157835SDaniel Fojt sm->try_initiate_reauth = FALSE;
1203*a1157835SDaniel Fojt SM_ENTER(EAP, SELECT_ACTION);
1204*a1157835SDaniel Fojt } else {
12053ff40c12SJohn Marino SM_ENTER(EAP, RETRANSMIT);
1206*a1157835SDaniel Fojt }
1207*a1157835SDaniel Fojt } else if (sm->eap_if.eapResp)
12083ff40c12SJohn Marino SM_ENTER(EAP, RECEIVED);
12093ff40c12SJohn Marino break;
12103ff40c12SJohn Marino case EAP_RETRANSMIT:
12113ff40c12SJohn Marino if (sm->retransCount > sm->MaxRetrans)
12123ff40c12SJohn Marino SM_ENTER(EAP, TIMEOUT_FAILURE);
12133ff40c12SJohn Marino else
12143ff40c12SJohn Marino SM_ENTER(EAP, IDLE);
12153ff40c12SJohn Marino break;
12163ff40c12SJohn Marino case EAP_RECEIVED:
12173ff40c12SJohn Marino if (sm->rxResp && (sm->respId == sm->currentId) &&
12183ff40c12SJohn Marino (sm->respMethod == EAP_TYPE_NAK ||
12193ff40c12SJohn Marino (sm->respMethod == EAP_TYPE_EXPANDED &&
12203ff40c12SJohn Marino sm->respVendor == EAP_VENDOR_IETF &&
12213ff40c12SJohn Marino sm->respVendorMethod == EAP_TYPE_NAK))
12223ff40c12SJohn Marino && (sm->methodState == METHOD_PROPOSED))
12233ff40c12SJohn Marino SM_ENTER(EAP, NAK);
12243ff40c12SJohn Marino else if (sm->rxResp && (sm->respId == sm->currentId) &&
12253ff40c12SJohn Marino ((sm->respMethod == sm->currentMethod) ||
12263ff40c12SJohn Marino (sm->respMethod == EAP_TYPE_EXPANDED &&
12273ff40c12SJohn Marino sm->respVendor == EAP_VENDOR_IETF &&
12283ff40c12SJohn Marino sm->respVendorMethod == sm->currentMethod)))
12293ff40c12SJohn Marino SM_ENTER(EAP, INTEGRITY_CHECK);
1230*a1157835SDaniel Fojt #ifdef CONFIG_ERP
1231*a1157835SDaniel Fojt else if (sm->rxInitiate)
1232*a1157835SDaniel Fojt SM_ENTER(EAP, INITIATE_RECEIVED);
1233*a1157835SDaniel Fojt #endif /* CONFIG_ERP */
12343ff40c12SJohn Marino else {
12353ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: RECEIVED->DISCARD: "
12363ff40c12SJohn Marino "rxResp=%d respId=%d currentId=%d "
12373ff40c12SJohn Marino "respMethod=%d currentMethod=%d",
12383ff40c12SJohn Marino sm->rxResp, sm->respId, sm->currentId,
12393ff40c12SJohn Marino sm->respMethod, sm->currentMethod);
1240*a1157835SDaniel Fojt eap_log_msg(sm, "Discard received EAP message");
12413ff40c12SJohn Marino SM_ENTER(EAP, DISCARD);
12423ff40c12SJohn Marino }
12433ff40c12SJohn Marino break;
12443ff40c12SJohn Marino case EAP_DISCARD:
12453ff40c12SJohn Marino SM_ENTER(EAP, IDLE);
12463ff40c12SJohn Marino break;
12473ff40c12SJohn Marino case EAP_SEND_REQUEST:
12483ff40c12SJohn Marino SM_ENTER(EAP, IDLE);
12493ff40c12SJohn Marino break;
12503ff40c12SJohn Marino case EAP_INTEGRITY_CHECK:
12513ff40c12SJohn Marino if (sm->ignore)
12523ff40c12SJohn Marino SM_ENTER(EAP, DISCARD);
12533ff40c12SJohn Marino else
12543ff40c12SJohn Marino SM_ENTER(EAP, METHOD_RESPONSE);
12553ff40c12SJohn Marino break;
12563ff40c12SJohn Marino case EAP_METHOD_REQUEST:
12573ff40c12SJohn Marino if (sm->m == NULL) {
12583ff40c12SJohn Marino /*
12593ff40c12SJohn Marino * This transition is not mentioned in RFC 4137, but it
12603ff40c12SJohn Marino * is needed to handle cleanly a case where EAP method
12613ff40c12SJohn Marino * initialization fails.
12623ff40c12SJohn Marino */
12633ff40c12SJohn Marino SM_ENTER(EAP, FAILURE);
12643ff40c12SJohn Marino break;
12653ff40c12SJohn Marino }
12663ff40c12SJohn Marino SM_ENTER(EAP, SEND_REQUEST);
1267*a1157835SDaniel Fojt if (sm->eap_if.eapNoReq && !sm->eap_if.eapReq) {
1268*a1157835SDaniel Fojt /*
1269*a1157835SDaniel Fojt * This transition is not mentioned in RFC 4137, but it
1270*a1157835SDaniel Fojt * is needed to handle cleanly a case where EAP method
1271*a1157835SDaniel Fojt * buildReq fails.
1272*a1157835SDaniel Fojt */
1273*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
1274*a1157835SDaniel Fojt "EAP: Method did not return a request");
1275*a1157835SDaniel Fojt SM_ENTER(EAP, FAILURE);
1276*a1157835SDaniel Fojt break;
1277*a1157835SDaniel Fojt }
12783ff40c12SJohn Marino break;
12793ff40c12SJohn Marino case EAP_METHOD_RESPONSE:
12803ff40c12SJohn Marino /*
12813ff40c12SJohn Marino * Note: Mechanism to allow EAP methods to wait while going
12823ff40c12SJohn Marino * through pending processing is an extension to RFC 4137
12833ff40c12SJohn Marino * which only defines the transits to SELECT_ACTION and
12843ff40c12SJohn Marino * METHOD_REQUEST from this METHOD_RESPONSE state.
12853ff40c12SJohn Marino */
12863ff40c12SJohn Marino if (sm->methodState == METHOD_END)
12873ff40c12SJohn Marino SM_ENTER(EAP, SELECT_ACTION);
12883ff40c12SJohn Marino else if (sm->method_pending == METHOD_PENDING_WAIT) {
12893ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Method has pending "
12903ff40c12SJohn Marino "processing - wait before proceeding to "
12913ff40c12SJohn Marino "METHOD_REQUEST state");
12923ff40c12SJohn Marino } else if (sm->method_pending == METHOD_PENDING_CONT) {
12933ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Method has completed "
12943ff40c12SJohn Marino "pending processing - reprocess pending "
12953ff40c12SJohn Marino "EAP message");
12963ff40c12SJohn Marino sm->method_pending = METHOD_PENDING_NONE;
12973ff40c12SJohn Marino SM_ENTER(EAP, METHOD_RESPONSE);
12983ff40c12SJohn Marino } else
12993ff40c12SJohn Marino SM_ENTER(EAP, METHOD_REQUEST);
13003ff40c12SJohn Marino break;
13013ff40c12SJohn Marino case EAP_PROPOSE_METHOD:
13023ff40c12SJohn Marino /*
13033ff40c12SJohn Marino * Note: Mechanism to allow EAP methods to wait while going
13043ff40c12SJohn Marino * through pending processing is an extension to RFC 4137
13053ff40c12SJohn Marino * which only defines the transit to METHOD_REQUEST from this
13063ff40c12SJohn Marino * PROPOSE_METHOD state.
13073ff40c12SJohn Marino */
13083ff40c12SJohn Marino if (sm->method_pending == METHOD_PENDING_WAIT) {
13093ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Method has pending "
13103ff40c12SJohn Marino "processing - wait before proceeding to "
13113ff40c12SJohn Marino "METHOD_REQUEST state");
13123ff40c12SJohn Marino if (sm->user_eap_method_index > 0)
13133ff40c12SJohn Marino sm->user_eap_method_index--;
13143ff40c12SJohn Marino } else if (sm->method_pending == METHOD_PENDING_CONT) {
13153ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Method has completed "
13163ff40c12SJohn Marino "pending processing - reprocess pending "
13173ff40c12SJohn Marino "EAP message");
13183ff40c12SJohn Marino sm->method_pending = METHOD_PENDING_NONE;
13193ff40c12SJohn Marino SM_ENTER(EAP, PROPOSE_METHOD);
13203ff40c12SJohn Marino } else
13213ff40c12SJohn Marino SM_ENTER(EAP, METHOD_REQUEST);
13223ff40c12SJohn Marino break;
13233ff40c12SJohn Marino case EAP_NAK:
13243ff40c12SJohn Marino SM_ENTER(EAP, SELECT_ACTION);
13253ff40c12SJohn Marino break;
13263ff40c12SJohn Marino case EAP_SELECT_ACTION:
13273ff40c12SJohn Marino if (sm->decision == DECISION_FAILURE)
13283ff40c12SJohn Marino SM_ENTER(EAP, FAILURE);
13293ff40c12SJohn Marino else if (sm->decision == DECISION_SUCCESS)
13303ff40c12SJohn Marino SM_ENTER(EAP, SUCCESS);
13313ff40c12SJohn Marino else if (sm->decision == DECISION_PASSTHROUGH)
13323ff40c12SJohn Marino SM_ENTER(EAP, INITIALIZE_PASSTHROUGH);
1333*a1157835SDaniel Fojt else if (sm->decision == DECISION_INITIATE_REAUTH_START)
1334*a1157835SDaniel Fojt SM_ENTER(EAP, INITIATE_REAUTH_START);
1335*a1157835SDaniel Fojt #ifdef CONFIG_ERP
1336*a1157835SDaniel Fojt else if (sm->eap_server && sm->erp && sm->rxInitiate)
1337*a1157835SDaniel Fojt SM_ENTER(EAP, INITIATE_RECEIVED);
1338*a1157835SDaniel Fojt #endif /* CONFIG_ERP */
13393ff40c12SJohn Marino else
13403ff40c12SJohn Marino SM_ENTER(EAP, PROPOSE_METHOD);
13413ff40c12SJohn Marino break;
1342*a1157835SDaniel Fojt case EAP_INITIATE_REAUTH_START:
1343*a1157835SDaniel Fojt SM_ENTER(EAP, SEND_REQUEST);
1344*a1157835SDaniel Fojt break;
1345*a1157835SDaniel Fojt case EAP_INITIATE_RECEIVED:
1346*a1157835SDaniel Fojt if (!sm->eap_server)
1347*a1157835SDaniel Fojt SM_ENTER(EAP, SELECT_ACTION);
1348*a1157835SDaniel Fojt break;
13493ff40c12SJohn Marino case EAP_TIMEOUT_FAILURE:
13503ff40c12SJohn Marino break;
13513ff40c12SJohn Marino case EAP_FAILURE:
13523ff40c12SJohn Marino break;
13533ff40c12SJohn Marino case EAP_SUCCESS:
13543ff40c12SJohn Marino break;
13553ff40c12SJohn Marino
13563ff40c12SJohn Marino case EAP_INITIALIZE_PASSTHROUGH:
13573ff40c12SJohn Marino if (sm->currentId == -1)
13583ff40c12SJohn Marino SM_ENTER(EAP, AAA_IDLE);
13593ff40c12SJohn Marino else
13603ff40c12SJohn Marino SM_ENTER(EAP, AAA_REQUEST);
13613ff40c12SJohn Marino break;
13623ff40c12SJohn Marino case EAP_IDLE2:
13633ff40c12SJohn Marino if (sm->eap_if.eapResp)
13643ff40c12SJohn Marino SM_ENTER(EAP, RECEIVED2);
13653ff40c12SJohn Marino else if (sm->eap_if.retransWhile == 0)
13663ff40c12SJohn Marino SM_ENTER(EAP, RETRANSMIT2);
13673ff40c12SJohn Marino break;
13683ff40c12SJohn Marino case EAP_RETRANSMIT2:
13693ff40c12SJohn Marino if (sm->retransCount > sm->MaxRetrans)
13703ff40c12SJohn Marino SM_ENTER(EAP, TIMEOUT_FAILURE2);
13713ff40c12SJohn Marino else
13723ff40c12SJohn Marino SM_ENTER(EAP, IDLE2);
13733ff40c12SJohn Marino break;
13743ff40c12SJohn Marino case EAP_RECEIVED2:
13753ff40c12SJohn Marino if (sm->rxResp && (sm->respId == sm->currentId))
13763ff40c12SJohn Marino SM_ENTER(EAP, AAA_REQUEST);
13773ff40c12SJohn Marino else
13783ff40c12SJohn Marino SM_ENTER(EAP, DISCARD2);
13793ff40c12SJohn Marino break;
13803ff40c12SJohn Marino case EAP_DISCARD2:
13813ff40c12SJohn Marino SM_ENTER(EAP, IDLE2);
13823ff40c12SJohn Marino break;
13833ff40c12SJohn Marino case EAP_SEND_REQUEST2:
13843ff40c12SJohn Marino SM_ENTER(EAP, IDLE2);
13853ff40c12SJohn Marino break;
13863ff40c12SJohn Marino case EAP_AAA_REQUEST:
13873ff40c12SJohn Marino SM_ENTER(EAP, AAA_IDLE);
13883ff40c12SJohn Marino break;
13893ff40c12SJohn Marino case EAP_AAA_RESPONSE:
13903ff40c12SJohn Marino SM_ENTER(EAP, SEND_REQUEST2);
13913ff40c12SJohn Marino break;
13923ff40c12SJohn Marino case EAP_AAA_IDLE:
13933ff40c12SJohn Marino if (sm->eap_if.aaaFail)
13943ff40c12SJohn Marino SM_ENTER(EAP, FAILURE2);
13953ff40c12SJohn Marino else if (sm->eap_if.aaaSuccess)
13963ff40c12SJohn Marino SM_ENTER(EAP, SUCCESS2);
13973ff40c12SJohn Marino else if (sm->eap_if.aaaEapReq)
13983ff40c12SJohn Marino SM_ENTER(EAP, AAA_RESPONSE);
13993ff40c12SJohn Marino else if (sm->eap_if.aaaTimeout)
14003ff40c12SJohn Marino SM_ENTER(EAP, TIMEOUT_FAILURE2);
14013ff40c12SJohn Marino break;
14023ff40c12SJohn Marino case EAP_TIMEOUT_FAILURE2:
14033ff40c12SJohn Marino break;
14043ff40c12SJohn Marino case EAP_FAILURE2:
14053ff40c12SJohn Marino break;
14063ff40c12SJohn Marino case EAP_SUCCESS2:
14073ff40c12SJohn Marino break;
14083ff40c12SJohn Marino }
14093ff40c12SJohn Marino }
14103ff40c12SJohn Marino
14113ff40c12SJohn Marino
eap_sm_calculateTimeout(struct eap_sm * sm,int retransCount,int eapSRTT,int eapRTTVAR,int methodTimeout)14123ff40c12SJohn Marino static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
14133ff40c12SJohn Marino int eapSRTT, int eapRTTVAR,
14143ff40c12SJohn Marino int methodTimeout)
14153ff40c12SJohn Marino {
14163ff40c12SJohn Marino int rto, i;
14173ff40c12SJohn Marino
1418*a1157835SDaniel Fojt if (sm->try_initiate_reauth) {
1419*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
1420*a1157835SDaniel Fojt "EAP: retransmit timeout 1 second for EAP-Initiate-Re-auth-Start");
1421*a1157835SDaniel Fojt return 1;
1422*a1157835SDaniel Fojt }
1423*a1157835SDaniel Fojt
14243ff40c12SJohn Marino if (methodTimeout) {
14253ff40c12SJohn Marino /*
14263ff40c12SJohn Marino * EAP method (either internal or through AAA server, provided
14273ff40c12SJohn Marino * timeout hint. Use that as-is as a timeout for retransmitting
14283ff40c12SJohn Marino * the EAP request if no response is received.
14293ff40c12SJohn Marino */
14303ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: retransmit timeout %d seconds "
14313ff40c12SJohn Marino "(from EAP method hint)", methodTimeout);
14323ff40c12SJohn Marino return methodTimeout;
14333ff40c12SJohn Marino }
14343ff40c12SJohn Marino
14353ff40c12SJohn Marino /*
14363ff40c12SJohn Marino * RFC 3748 recommends algorithms described in RFC 2988 for estimation
14373ff40c12SJohn Marino * of the retransmission timeout. This should be implemented once
14383ff40c12SJohn Marino * round-trip time measurements are available. For nowm a simple
14393ff40c12SJohn Marino * backoff mechanism is used instead if there are no EAP method
14403ff40c12SJohn Marino * specific hints.
14413ff40c12SJohn Marino *
14423ff40c12SJohn Marino * SRTT = smoothed round-trip time
14433ff40c12SJohn Marino * RTTVAR = round-trip time variation
14443ff40c12SJohn Marino * RTO = retransmission timeout
14453ff40c12SJohn Marino */
14463ff40c12SJohn Marino
14473ff40c12SJohn Marino /*
14483ff40c12SJohn Marino * RFC 2988, 2.1: before RTT measurement, set RTO to 3 seconds for
14493ff40c12SJohn Marino * initial retransmission and then double the RTO to provide back off
14503ff40c12SJohn Marino * per 5.5. Limit the maximum RTO to 20 seconds per RFC 3748, 4.3
14513ff40c12SJohn Marino * modified RTOmax.
14523ff40c12SJohn Marino */
14533ff40c12SJohn Marino rto = 3;
14543ff40c12SJohn Marino for (i = 0; i < retransCount; i++) {
14553ff40c12SJohn Marino rto *= 2;
14563ff40c12SJohn Marino if (rto >= 20) {
14573ff40c12SJohn Marino rto = 20;
14583ff40c12SJohn Marino break;
14593ff40c12SJohn Marino }
14603ff40c12SJohn Marino }
14613ff40c12SJohn Marino
14623ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: retransmit timeout %d seconds "
14633ff40c12SJohn Marino "(from dynamic back off; retransCount=%d)",
14643ff40c12SJohn Marino rto, retransCount);
14653ff40c12SJohn Marino
14663ff40c12SJohn Marino return rto;
14673ff40c12SJohn Marino }
14683ff40c12SJohn Marino
14693ff40c12SJohn Marino
eap_sm_parseEapResp(struct eap_sm * sm,const struct wpabuf * resp)14703ff40c12SJohn Marino static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp)
14713ff40c12SJohn Marino {
14723ff40c12SJohn Marino const struct eap_hdr *hdr;
14733ff40c12SJohn Marino size_t plen;
14743ff40c12SJohn Marino
14753ff40c12SJohn Marino /* parse rxResp, respId, respMethod */
14763ff40c12SJohn Marino sm->rxResp = FALSE;
1477*a1157835SDaniel Fojt sm->rxInitiate = FALSE;
14783ff40c12SJohn Marino sm->respId = -1;
14793ff40c12SJohn Marino sm->respMethod = EAP_TYPE_NONE;
14803ff40c12SJohn Marino sm->respVendor = EAP_VENDOR_IETF;
14813ff40c12SJohn Marino sm->respVendorMethod = EAP_TYPE_NONE;
14823ff40c12SJohn Marino
14833ff40c12SJohn Marino if (resp == NULL || wpabuf_len(resp) < sizeof(*hdr)) {
14843ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: parseEapResp: invalid resp=%p "
14853ff40c12SJohn Marino "len=%lu", resp,
14863ff40c12SJohn Marino resp ? (unsigned long) wpabuf_len(resp) : 0);
14873ff40c12SJohn Marino return;
14883ff40c12SJohn Marino }
14893ff40c12SJohn Marino
14903ff40c12SJohn Marino hdr = wpabuf_head(resp);
14913ff40c12SJohn Marino plen = be_to_host16(hdr->length);
14923ff40c12SJohn Marino if (plen > wpabuf_len(resp)) {
14933ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Ignored truncated EAP-Packet "
14943ff40c12SJohn Marino "(len=%lu plen=%lu)",
14953ff40c12SJohn Marino (unsigned long) wpabuf_len(resp),
14963ff40c12SJohn Marino (unsigned long) plen);
14973ff40c12SJohn Marino return;
14983ff40c12SJohn Marino }
14993ff40c12SJohn Marino
15003ff40c12SJohn Marino sm->respId = hdr->identifier;
15013ff40c12SJohn Marino
15023ff40c12SJohn Marino if (hdr->code == EAP_CODE_RESPONSE)
15033ff40c12SJohn Marino sm->rxResp = TRUE;
1504*a1157835SDaniel Fojt else if (hdr->code == EAP_CODE_INITIATE)
1505*a1157835SDaniel Fojt sm->rxInitiate = TRUE;
15063ff40c12SJohn Marino
15073ff40c12SJohn Marino if (plen > sizeof(*hdr)) {
15083ff40c12SJohn Marino u8 *pos = (u8 *) (hdr + 1);
15093ff40c12SJohn Marino sm->respMethod = *pos++;
15103ff40c12SJohn Marino if (sm->respMethod == EAP_TYPE_EXPANDED) {
15113ff40c12SJohn Marino if (plen < sizeof(*hdr) + 8) {
15123ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Ignored truncated "
15133ff40c12SJohn Marino "expanded EAP-Packet (plen=%lu)",
15143ff40c12SJohn Marino (unsigned long) plen);
15153ff40c12SJohn Marino return;
15163ff40c12SJohn Marino }
15173ff40c12SJohn Marino sm->respVendor = WPA_GET_BE24(pos);
15183ff40c12SJohn Marino pos += 3;
15193ff40c12SJohn Marino sm->respVendorMethod = WPA_GET_BE32(pos);
15203ff40c12SJohn Marino }
15213ff40c12SJohn Marino }
15223ff40c12SJohn Marino
1523*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
1524*a1157835SDaniel Fojt "EAP: parseEapResp: rxResp=%d rxInitiate=%d respId=%d respMethod=%u respVendor=%u respVendorMethod=%u",
1525*a1157835SDaniel Fojt sm->rxResp, sm->rxInitiate, sm->respId, sm->respMethod,
1526*a1157835SDaniel Fojt sm->respVendor, sm->respVendorMethod);
15273ff40c12SJohn Marino }
15283ff40c12SJohn Marino
15293ff40c12SJohn Marino
eap_sm_getId(const struct wpabuf * data)15303ff40c12SJohn Marino static int eap_sm_getId(const struct wpabuf *data)
15313ff40c12SJohn Marino {
15323ff40c12SJohn Marino const struct eap_hdr *hdr;
15333ff40c12SJohn Marino
15343ff40c12SJohn Marino if (data == NULL || wpabuf_len(data) < sizeof(*hdr))
15353ff40c12SJohn Marino return -1;
15363ff40c12SJohn Marino
15373ff40c12SJohn Marino hdr = wpabuf_head(data);
15383ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getId: id=%d", hdr->identifier);
15393ff40c12SJohn Marino return hdr->identifier;
15403ff40c12SJohn Marino }
15413ff40c12SJohn Marino
15423ff40c12SJohn Marino
eap_sm_buildSuccess(struct eap_sm * sm,u8 id)15433ff40c12SJohn Marino static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id)
15443ff40c12SJohn Marino {
15453ff40c12SJohn Marino struct wpabuf *msg;
15463ff40c12SJohn Marino struct eap_hdr *resp;
15473ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Building EAP-Success (id=%d)", id);
15483ff40c12SJohn Marino
15493ff40c12SJohn Marino msg = wpabuf_alloc(sizeof(*resp));
15503ff40c12SJohn Marino if (msg == NULL)
15513ff40c12SJohn Marino return NULL;
15523ff40c12SJohn Marino resp = wpabuf_put(msg, sizeof(*resp));
15533ff40c12SJohn Marino resp->code = EAP_CODE_SUCCESS;
15543ff40c12SJohn Marino resp->identifier = id;
15553ff40c12SJohn Marino resp->length = host_to_be16(sizeof(*resp));
15563ff40c12SJohn Marino
15573ff40c12SJohn Marino return msg;
15583ff40c12SJohn Marino }
15593ff40c12SJohn Marino
15603ff40c12SJohn Marino
eap_sm_buildFailure(struct eap_sm * sm,u8 id)15613ff40c12SJohn Marino static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id)
15623ff40c12SJohn Marino {
15633ff40c12SJohn Marino struct wpabuf *msg;
15643ff40c12SJohn Marino struct eap_hdr *resp;
15653ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Building EAP-Failure (id=%d)", id);
15663ff40c12SJohn Marino
15673ff40c12SJohn Marino msg = wpabuf_alloc(sizeof(*resp));
15683ff40c12SJohn Marino if (msg == NULL)
15693ff40c12SJohn Marino return NULL;
15703ff40c12SJohn Marino resp = wpabuf_put(msg, sizeof(*resp));
15713ff40c12SJohn Marino resp->code = EAP_CODE_FAILURE;
15723ff40c12SJohn Marino resp->identifier = id;
15733ff40c12SJohn Marino resp->length = host_to_be16(sizeof(*resp));
15743ff40c12SJohn Marino
15753ff40c12SJohn Marino return msg;
15763ff40c12SJohn Marino }
15773ff40c12SJohn Marino
15783ff40c12SJohn Marino
eap_sm_nextId(struct eap_sm * sm,int id)15793ff40c12SJohn Marino static int eap_sm_nextId(struct eap_sm *sm, int id)
15803ff40c12SJohn Marino {
15813ff40c12SJohn Marino if (id < 0) {
15823ff40c12SJohn Marino /* RFC 3748 Ch 4.1: recommended to initialize Identifier with a
15833ff40c12SJohn Marino * random number */
15843ff40c12SJohn Marino id = rand() & 0xff;
15853ff40c12SJohn Marino if (id != sm->lastId)
15863ff40c12SJohn Marino return id;
15873ff40c12SJohn Marino }
15883ff40c12SJohn Marino return (id + 1) & 0xff;
15893ff40c12SJohn Marino }
15903ff40c12SJohn Marino
15913ff40c12SJohn Marino
15923ff40c12SJohn Marino /**
15933ff40c12SJohn Marino * eap_sm_process_nak - Process EAP-Response/Nak
15943ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
15953ff40c12SJohn Marino * @nak_list: Nak list (allowed methods) from the supplicant
15963ff40c12SJohn Marino * @len: Length of nak_list in bytes
15973ff40c12SJohn Marino *
15983ff40c12SJohn Marino * This function is called when EAP-Response/Nak is received from the
15993ff40c12SJohn Marino * supplicant. This can happen for both phase 1 and phase 2 authentications.
16003ff40c12SJohn Marino */
eap_sm_process_nak(struct eap_sm * sm,const u8 * nak_list,size_t len)16013ff40c12SJohn Marino void eap_sm_process_nak(struct eap_sm *sm, const u8 *nak_list, size_t len)
16023ff40c12SJohn Marino {
16033ff40c12SJohn Marino int i;
16043ff40c12SJohn Marino size_t j;
16053ff40c12SJohn Marino
16063ff40c12SJohn Marino if (sm->user == NULL)
16073ff40c12SJohn Marino return;
16083ff40c12SJohn Marino
16093ff40c12SJohn Marino wpa_printf(MSG_MSGDUMP, "EAP: processing NAK (current EAP method "
16103ff40c12SJohn Marino "index %d)", sm->user_eap_method_index);
16113ff40c12SJohn Marino
16123ff40c12SJohn Marino wpa_hexdump(MSG_MSGDUMP, "EAP: configured methods",
16133ff40c12SJohn Marino (u8 *) sm->user->methods,
16143ff40c12SJohn Marino EAP_MAX_METHODS * sizeof(sm->user->methods[0]));
16153ff40c12SJohn Marino wpa_hexdump(MSG_MSGDUMP, "EAP: list of methods supported by the peer",
16163ff40c12SJohn Marino nak_list, len);
16173ff40c12SJohn Marino
16183ff40c12SJohn Marino i = sm->user_eap_method_index;
16193ff40c12SJohn Marino while (i < EAP_MAX_METHODS &&
16203ff40c12SJohn Marino (sm->user->methods[i].vendor != EAP_VENDOR_IETF ||
16213ff40c12SJohn Marino sm->user->methods[i].method != EAP_TYPE_NONE)) {
16223ff40c12SJohn Marino if (sm->user->methods[i].vendor != EAP_VENDOR_IETF)
16233ff40c12SJohn Marino goto not_found;
16243ff40c12SJohn Marino for (j = 0; j < len; j++) {
16253ff40c12SJohn Marino if (nak_list[j] == sm->user->methods[i].method) {
16263ff40c12SJohn Marino break;
16273ff40c12SJohn Marino }
16283ff40c12SJohn Marino }
16293ff40c12SJohn Marino
16303ff40c12SJohn Marino if (j < len) {
16313ff40c12SJohn Marino /* found */
16323ff40c12SJohn Marino i++;
16333ff40c12SJohn Marino continue;
16343ff40c12SJohn Marino }
16353ff40c12SJohn Marino
16363ff40c12SJohn Marino not_found:
16373ff40c12SJohn Marino /* not found - remove from the list */
16383ff40c12SJohn Marino if (i + 1 < EAP_MAX_METHODS) {
16393ff40c12SJohn Marino os_memmove(&sm->user->methods[i],
16403ff40c12SJohn Marino &sm->user->methods[i + 1],
16413ff40c12SJohn Marino (EAP_MAX_METHODS - i - 1) *
16423ff40c12SJohn Marino sizeof(sm->user->methods[0]));
16433ff40c12SJohn Marino }
16443ff40c12SJohn Marino sm->user->methods[EAP_MAX_METHODS - 1].vendor =
16453ff40c12SJohn Marino EAP_VENDOR_IETF;
16463ff40c12SJohn Marino sm->user->methods[EAP_MAX_METHODS - 1].method = EAP_TYPE_NONE;
16473ff40c12SJohn Marino }
16483ff40c12SJohn Marino
16493ff40c12SJohn Marino wpa_hexdump(MSG_MSGDUMP, "EAP: new list of configured methods",
16503ff40c12SJohn Marino (u8 *) sm->user->methods, EAP_MAX_METHODS *
16513ff40c12SJohn Marino sizeof(sm->user->methods[0]));
16523ff40c12SJohn Marino }
16533ff40c12SJohn Marino
16543ff40c12SJohn Marino
eap_sm_Policy_update(struct eap_sm * sm,const u8 * nak_list,size_t len)16553ff40c12SJohn Marino static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
16563ff40c12SJohn Marino size_t len)
16573ff40c12SJohn Marino {
16583ff40c12SJohn Marino if (nak_list == NULL || sm == NULL || sm->user == NULL)
16593ff40c12SJohn Marino return;
16603ff40c12SJohn Marino
16613ff40c12SJohn Marino if (sm->user->phase2) {
16623ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: EAP-Nak received after Phase2 user"
16633ff40c12SJohn Marino " info was selected - reject");
16643ff40c12SJohn Marino sm->decision = DECISION_FAILURE;
16653ff40c12SJohn Marino return;
16663ff40c12SJohn Marino }
16673ff40c12SJohn Marino
16683ff40c12SJohn Marino eap_sm_process_nak(sm, nak_list, len);
16693ff40c12SJohn Marino }
16703ff40c12SJohn Marino
16713ff40c12SJohn Marino
eap_sm_Policy_getNextMethod(struct eap_sm * sm,int * vendor)16723ff40c12SJohn Marino static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor)
16733ff40c12SJohn Marino {
16743ff40c12SJohn Marino EapType next;
16753ff40c12SJohn Marino int idx = sm->user_eap_method_index;
16763ff40c12SJohn Marino
16773ff40c12SJohn Marino /* In theory, there should be no problems with starting
16783ff40c12SJohn Marino * re-authentication with something else than EAP-Request/Identity and
16793ff40c12SJohn Marino * this does indeed work with wpa_supplicant. However, at least Funk
16803ff40c12SJohn Marino * Supplicant seemed to ignore re-auth if it skipped
16813ff40c12SJohn Marino * EAP-Request/Identity.
16823ff40c12SJohn Marino * Re-auth sets currentId == -1, so that can be used here to select
16833ff40c12SJohn Marino * whether Identity needs to be requested again. */
16843ff40c12SJohn Marino if (sm->identity == NULL || sm->currentId == -1) {
16853ff40c12SJohn Marino *vendor = EAP_VENDOR_IETF;
16863ff40c12SJohn Marino next = EAP_TYPE_IDENTITY;
16873ff40c12SJohn Marino sm->update_user = TRUE;
16883ff40c12SJohn Marino } else if (sm->user && idx < EAP_MAX_METHODS &&
16893ff40c12SJohn Marino (sm->user->methods[idx].vendor != EAP_VENDOR_IETF ||
16903ff40c12SJohn Marino sm->user->methods[idx].method != EAP_TYPE_NONE)) {
16913ff40c12SJohn Marino *vendor = sm->user->methods[idx].vendor;
16923ff40c12SJohn Marino next = sm->user->methods[idx].method;
16933ff40c12SJohn Marino sm->user_eap_method_index++;
16943ff40c12SJohn Marino } else {
16953ff40c12SJohn Marino *vendor = EAP_VENDOR_IETF;
16963ff40c12SJohn Marino next = EAP_TYPE_NONE;
16973ff40c12SJohn Marino }
16983ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getNextMethod: vendor %d type %d",
16993ff40c12SJohn Marino *vendor, next);
17003ff40c12SJohn Marino return next;
17013ff40c12SJohn Marino }
17023ff40c12SJohn Marino
17033ff40c12SJohn Marino
eap_sm_Policy_getDecision(struct eap_sm * sm)17043ff40c12SJohn Marino static int eap_sm_Policy_getDecision(struct eap_sm *sm)
17053ff40c12SJohn Marino {
17063ff40c12SJohn Marino if (!sm->eap_server && sm->identity && !sm->start_reauth) {
17073ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getDecision: -> PASSTHROUGH");
17083ff40c12SJohn Marino return DECISION_PASSTHROUGH;
17093ff40c12SJohn Marino }
17103ff40c12SJohn Marino
17113ff40c12SJohn Marino if (sm->m && sm->currentMethod != EAP_TYPE_IDENTITY &&
17123ff40c12SJohn Marino sm->m->isSuccess(sm, sm->eap_method_priv)) {
17133ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getDecision: method succeeded -> "
17143ff40c12SJohn Marino "SUCCESS");
17153ff40c12SJohn Marino sm->update_user = TRUE;
17163ff40c12SJohn Marino return DECISION_SUCCESS;
17173ff40c12SJohn Marino }
17183ff40c12SJohn Marino
17193ff40c12SJohn Marino if (sm->m && sm->m->isDone(sm, sm->eap_method_priv) &&
17203ff40c12SJohn Marino !sm->m->isSuccess(sm, sm->eap_method_priv)) {
17213ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getDecision: method failed -> "
17223ff40c12SJohn Marino "FAILURE");
17233ff40c12SJohn Marino sm->update_user = TRUE;
17243ff40c12SJohn Marino return DECISION_FAILURE;
17253ff40c12SJohn Marino }
17263ff40c12SJohn Marino
17273ff40c12SJohn Marino if ((sm->user == NULL || sm->update_user) && sm->identity &&
17283ff40c12SJohn Marino !sm->start_reauth) {
17293ff40c12SJohn Marino /*
17303ff40c12SJohn Marino * Allow Identity method to be started once to allow identity
17313ff40c12SJohn Marino * selection hint to be sent from the authentication server,
17323ff40c12SJohn Marino * but prevent a loop of Identity requests by only allowing
17333ff40c12SJohn Marino * this to happen once.
17343ff40c12SJohn Marino */
17353ff40c12SJohn Marino int id_req = 0;
17363ff40c12SJohn Marino if (sm->user && sm->currentMethod == EAP_TYPE_IDENTITY &&
17373ff40c12SJohn Marino sm->user->methods[0].vendor == EAP_VENDOR_IETF &&
17383ff40c12SJohn Marino sm->user->methods[0].method == EAP_TYPE_IDENTITY)
17393ff40c12SJohn Marino id_req = 1;
17403ff40c12SJohn Marino if (eap_user_get(sm, sm->identity, sm->identity_len, 0) != 0) {
17413ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getDecision: user not "
17423ff40c12SJohn Marino "found from database -> FAILURE");
17433ff40c12SJohn Marino return DECISION_FAILURE;
17443ff40c12SJohn Marino }
17453ff40c12SJohn Marino if (id_req && sm->user &&
17463ff40c12SJohn Marino sm->user->methods[0].vendor == EAP_VENDOR_IETF &&
17473ff40c12SJohn Marino sm->user->methods[0].method == EAP_TYPE_IDENTITY) {
17483ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getDecision: stop "
17493ff40c12SJohn Marino "identity request loop -> FAILURE");
17503ff40c12SJohn Marino sm->update_user = TRUE;
17513ff40c12SJohn Marino return DECISION_FAILURE;
17523ff40c12SJohn Marino }
17533ff40c12SJohn Marino sm->update_user = FALSE;
17543ff40c12SJohn Marino }
17553ff40c12SJohn Marino sm->start_reauth = FALSE;
17563ff40c12SJohn Marino
17573ff40c12SJohn Marino if (sm->user && sm->user_eap_method_index < EAP_MAX_METHODS &&
17583ff40c12SJohn Marino (sm->user->methods[sm->user_eap_method_index].vendor !=
17593ff40c12SJohn Marino EAP_VENDOR_IETF ||
17603ff40c12SJohn Marino sm->user->methods[sm->user_eap_method_index].method !=
17613ff40c12SJohn Marino EAP_TYPE_NONE)) {
17623ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getDecision: another method "
17633ff40c12SJohn Marino "available -> CONTINUE");
17643ff40c12SJohn Marino return DECISION_CONTINUE;
17653ff40c12SJohn Marino }
17663ff40c12SJohn Marino
1767*a1157835SDaniel Fojt if (!sm->identity && eap_get_erp_send_reauth_start(sm) &&
1768*a1157835SDaniel Fojt !sm->initiate_reauth_start_sent) {
1769*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG,
1770*a1157835SDaniel Fojt "EAP: getDecision: send EAP-Initiate/Re-auth-Start");
1771*a1157835SDaniel Fojt return DECISION_INITIATE_REAUTH_START;
1772*a1157835SDaniel Fojt }
1773*a1157835SDaniel Fojt
17743ff40c12SJohn Marino if (sm->identity == NULL || sm->currentId == -1) {
17753ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getDecision: no identity known "
17763ff40c12SJohn Marino "yet -> CONTINUE");
17773ff40c12SJohn Marino return DECISION_CONTINUE;
17783ff40c12SJohn Marino }
17793ff40c12SJohn Marino
17803ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: getDecision: no more methods available -> "
17813ff40c12SJohn Marino "FAILURE");
17823ff40c12SJohn Marino return DECISION_FAILURE;
17833ff40c12SJohn Marino }
17843ff40c12SJohn Marino
17853ff40c12SJohn Marino
eap_sm_Policy_doPickUp(struct eap_sm * sm,EapType method)17863ff40c12SJohn Marino static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method)
17873ff40c12SJohn Marino {
17883ff40c12SJohn Marino return method == EAP_TYPE_IDENTITY ? TRUE : FALSE;
17893ff40c12SJohn Marino }
17903ff40c12SJohn Marino
17913ff40c12SJohn Marino
17923ff40c12SJohn Marino /**
17933ff40c12SJohn Marino * eap_server_sm_step - Step EAP server state machine
17943ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
17953ff40c12SJohn Marino * Returns: 1 if EAP state was changed or 0 if not
17963ff40c12SJohn Marino *
17973ff40c12SJohn Marino * This function advances EAP state machine to a new state to match with the
17983ff40c12SJohn Marino * current variables. This should be called whenever variables used by the EAP
17993ff40c12SJohn Marino * state machine have changed.
18003ff40c12SJohn Marino */
eap_server_sm_step(struct eap_sm * sm)18013ff40c12SJohn Marino int eap_server_sm_step(struct eap_sm *sm)
18023ff40c12SJohn Marino {
18033ff40c12SJohn Marino int res = 0;
18043ff40c12SJohn Marino do {
18053ff40c12SJohn Marino sm->changed = FALSE;
18063ff40c12SJohn Marino SM_STEP_RUN(EAP);
18073ff40c12SJohn Marino if (sm->changed)
18083ff40c12SJohn Marino res = 1;
18093ff40c12SJohn Marino } while (sm->changed);
18103ff40c12SJohn Marino return res;
18113ff40c12SJohn Marino }
18123ff40c12SJohn Marino
18133ff40c12SJohn Marino
eap_user_free(struct eap_user * user)1814*a1157835SDaniel Fojt void eap_user_free(struct eap_user *user)
18153ff40c12SJohn Marino {
18163ff40c12SJohn Marino if (user == NULL)
18173ff40c12SJohn Marino return;
1818*a1157835SDaniel Fojt bin_clear_free(user->password, user->password_len);
18193ff40c12SJohn Marino user->password = NULL;
1820*a1157835SDaniel Fojt bin_clear_free(user->salt, user->salt_len);
1821*a1157835SDaniel Fojt user->salt = NULL;
18223ff40c12SJohn Marino os_free(user);
18233ff40c12SJohn Marino }
18243ff40c12SJohn Marino
18253ff40c12SJohn Marino
18263ff40c12SJohn Marino /**
18273ff40c12SJohn Marino * eap_server_sm_init - Allocate and initialize EAP server state machine
18283ff40c12SJohn Marino * @eapol_ctx: Context data to be used with eapol_cb calls
18293ff40c12SJohn Marino * @eapol_cb: Pointer to EAPOL callback functions
18303ff40c12SJohn Marino * @conf: EAP configuration
18313ff40c12SJohn Marino * Returns: Pointer to the allocated EAP state machine or %NULL on failure
18323ff40c12SJohn Marino *
18333ff40c12SJohn Marino * This function allocates and initializes an EAP state machine.
18343ff40c12SJohn Marino */
eap_server_sm_init(void * eapol_ctx,const struct eapol_callbacks * eapol_cb,struct eap_config * conf)18353ff40c12SJohn Marino struct eap_sm * eap_server_sm_init(void *eapol_ctx,
1836*a1157835SDaniel Fojt const struct eapol_callbacks *eapol_cb,
18373ff40c12SJohn Marino struct eap_config *conf)
18383ff40c12SJohn Marino {
18393ff40c12SJohn Marino struct eap_sm *sm;
18403ff40c12SJohn Marino
18413ff40c12SJohn Marino sm = os_zalloc(sizeof(*sm));
18423ff40c12SJohn Marino if (sm == NULL)
18433ff40c12SJohn Marino return NULL;
18443ff40c12SJohn Marino sm->eapol_ctx = eapol_ctx;
18453ff40c12SJohn Marino sm->eapol_cb = eapol_cb;
18463ff40c12SJohn Marino sm->MaxRetrans = 5; /* RFC 3748: max 3-5 retransmissions suggested */
18473ff40c12SJohn Marino sm->ssl_ctx = conf->ssl_ctx;
18483ff40c12SJohn Marino sm->msg_ctx = conf->msg_ctx;
18493ff40c12SJohn Marino sm->eap_sim_db_priv = conf->eap_sim_db_priv;
18503ff40c12SJohn Marino sm->backend_auth = conf->backend_auth;
18513ff40c12SJohn Marino sm->eap_server = conf->eap_server;
18523ff40c12SJohn Marino if (conf->pac_opaque_encr_key) {
18533ff40c12SJohn Marino sm->pac_opaque_encr_key = os_malloc(16);
18543ff40c12SJohn Marino if (sm->pac_opaque_encr_key) {
18553ff40c12SJohn Marino os_memcpy(sm->pac_opaque_encr_key,
18563ff40c12SJohn Marino conf->pac_opaque_encr_key, 16);
18573ff40c12SJohn Marino }
18583ff40c12SJohn Marino }
18593ff40c12SJohn Marino if (conf->eap_fast_a_id) {
18603ff40c12SJohn Marino sm->eap_fast_a_id = os_malloc(conf->eap_fast_a_id_len);
18613ff40c12SJohn Marino if (sm->eap_fast_a_id) {
18623ff40c12SJohn Marino os_memcpy(sm->eap_fast_a_id, conf->eap_fast_a_id,
18633ff40c12SJohn Marino conf->eap_fast_a_id_len);
18643ff40c12SJohn Marino sm->eap_fast_a_id_len = conf->eap_fast_a_id_len;
18653ff40c12SJohn Marino }
18663ff40c12SJohn Marino }
18673ff40c12SJohn Marino if (conf->eap_fast_a_id_info)
18683ff40c12SJohn Marino sm->eap_fast_a_id_info = os_strdup(conf->eap_fast_a_id_info);
18693ff40c12SJohn Marino sm->eap_fast_prov = conf->eap_fast_prov;
18703ff40c12SJohn Marino sm->pac_key_lifetime = conf->pac_key_lifetime;
18713ff40c12SJohn Marino sm->pac_key_refresh_time = conf->pac_key_refresh_time;
1872*a1157835SDaniel Fojt sm->eap_teap_auth = conf->eap_teap_auth;
1873*a1157835SDaniel Fojt sm->eap_teap_pac_no_inner = conf->eap_teap_pac_no_inner;
18743ff40c12SJohn Marino sm->eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
1875*a1157835SDaniel Fojt sm->eap_sim_id = conf->eap_sim_id;
18763ff40c12SJohn Marino sm->tnc = conf->tnc;
18773ff40c12SJohn Marino sm->wps = conf->wps;
18783ff40c12SJohn Marino if (conf->assoc_wps_ie)
18793ff40c12SJohn Marino sm->assoc_wps_ie = wpabuf_dup(conf->assoc_wps_ie);
18803ff40c12SJohn Marino if (conf->assoc_p2p_ie)
18813ff40c12SJohn Marino sm->assoc_p2p_ie = wpabuf_dup(conf->assoc_p2p_ie);
18823ff40c12SJohn Marino if (conf->peer_addr)
18833ff40c12SJohn Marino os_memcpy(sm->peer_addr, conf->peer_addr, ETH_ALEN);
18843ff40c12SJohn Marino sm->fragment_size = conf->fragment_size;
18853ff40c12SJohn Marino sm->pwd_group = conf->pwd_group;
18863ff40c12SJohn Marino sm->pbc_in_m1 = conf->pbc_in_m1;
18873ff40c12SJohn Marino sm->server_id = conf->server_id;
18883ff40c12SJohn Marino sm->server_id_len = conf->server_id_len;
1889*a1157835SDaniel Fojt sm->erp = conf->erp;
1890*a1157835SDaniel Fojt sm->tls_session_lifetime = conf->tls_session_lifetime;
1891*a1157835SDaniel Fojt sm->tls_flags = conf->tls_flags;
1892*a1157835SDaniel Fojt
1893*a1157835SDaniel Fojt #ifdef CONFIG_TESTING_OPTIONS
1894*a1157835SDaniel Fojt sm->tls_test_flags = conf->tls_test_flags;
1895*a1157835SDaniel Fojt #endif /* CONFIG_TESTING_OPTIONS */
18963ff40c12SJohn Marino
18973ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Server state machine created");
18983ff40c12SJohn Marino
18993ff40c12SJohn Marino return sm;
19003ff40c12SJohn Marino }
19013ff40c12SJohn Marino
19023ff40c12SJohn Marino
19033ff40c12SJohn Marino /**
19043ff40c12SJohn Marino * eap_server_sm_deinit - Deinitialize and free an EAP server state machine
19053ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
19063ff40c12SJohn Marino *
19073ff40c12SJohn Marino * This function deinitializes EAP state machine and frees all allocated
19083ff40c12SJohn Marino * resources.
19093ff40c12SJohn Marino */
eap_server_sm_deinit(struct eap_sm * sm)19103ff40c12SJohn Marino void eap_server_sm_deinit(struct eap_sm *sm)
19113ff40c12SJohn Marino {
19123ff40c12SJohn Marino if (sm == NULL)
19133ff40c12SJohn Marino return;
19143ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Server state machine removed");
19153ff40c12SJohn Marino if (sm->m && sm->eap_method_priv)
19163ff40c12SJohn Marino sm->m->reset(sm, sm->eap_method_priv);
19173ff40c12SJohn Marino wpabuf_free(sm->eap_if.eapReqData);
1918*a1157835SDaniel Fojt bin_clear_free(sm->eap_if.eapKeyData, sm->eap_if.eapKeyDataLen);
1919*a1157835SDaniel Fojt os_free(sm->eap_if.eapSessionId);
19203ff40c12SJohn Marino wpabuf_free(sm->lastReqData);
19213ff40c12SJohn Marino wpabuf_free(sm->eap_if.eapRespData);
19223ff40c12SJohn Marino os_free(sm->identity);
1923*a1157835SDaniel Fojt os_free(sm->serial_num);
19243ff40c12SJohn Marino os_free(sm->pac_opaque_encr_key);
19253ff40c12SJohn Marino os_free(sm->eap_fast_a_id);
19263ff40c12SJohn Marino os_free(sm->eap_fast_a_id_info);
19273ff40c12SJohn Marino wpabuf_free(sm->eap_if.aaaEapReqData);
19283ff40c12SJohn Marino wpabuf_free(sm->eap_if.aaaEapRespData);
1929*a1157835SDaniel Fojt bin_clear_free(sm->eap_if.aaaEapKeyData, sm->eap_if.aaaEapKeyDataLen);
19303ff40c12SJohn Marino eap_user_free(sm->user);
19313ff40c12SJohn Marino wpabuf_free(sm->assoc_wps_ie);
19323ff40c12SJohn Marino wpabuf_free(sm->assoc_p2p_ie);
19333ff40c12SJohn Marino os_free(sm);
19343ff40c12SJohn Marino }
19353ff40c12SJohn Marino
19363ff40c12SJohn Marino
19373ff40c12SJohn Marino /**
19383ff40c12SJohn Marino * eap_sm_notify_cached - Notify EAP state machine of cached PMK
19393ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
19403ff40c12SJohn Marino *
19413ff40c12SJohn Marino * This function is called when PMKSA caching is used to skip EAP
19423ff40c12SJohn Marino * authentication.
19433ff40c12SJohn Marino */
eap_sm_notify_cached(struct eap_sm * sm)19443ff40c12SJohn Marino void eap_sm_notify_cached(struct eap_sm *sm)
19453ff40c12SJohn Marino {
19463ff40c12SJohn Marino if (sm == NULL)
19473ff40c12SJohn Marino return;
19483ff40c12SJohn Marino
19493ff40c12SJohn Marino sm->EAP_state = EAP_SUCCESS;
19503ff40c12SJohn Marino }
19513ff40c12SJohn Marino
19523ff40c12SJohn Marino
19533ff40c12SJohn Marino /**
19543ff40c12SJohn Marino * eap_sm_pending_cb - EAP state machine callback for a pending EAP request
19553ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
19563ff40c12SJohn Marino *
19573ff40c12SJohn Marino * This function is called when data for a pending EAP-Request is received.
19583ff40c12SJohn Marino */
eap_sm_pending_cb(struct eap_sm * sm)19593ff40c12SJohn Marino void eap_sm_pending_cb(struct eap_sm *sm)
19603ff40c12SJohn Marino {
19613ff40c12SJohn Marino if (sm == NULL)
19623ff40c12SJohn Marino return;
19633ff40c12SJohn Marino wpa_printf(MSG_DEBUG, "EAP: Callback for pending request received");
19643ff40c12SJohn Marino if (sm->method_pending == METHOD_PENDING_WAIT)
19653ff40c12SJohn Marino sm->method_pending = METHOD_PENDING_CONT;
19663ff40c12SJohn Marino }
19673ff40c12SJohn Marino
19683ff40c12SJohn Marino
19693ff40c12SJohn Marino /**
19703ff40c12SJohn Marino * eap_sm_method_pending - Query whether EAP method is waiting for pending data
19713ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
19723ff40c12SJohn Marino * Returns: 1 if method is waiting for pending data or 0 if not
19733ff40c12SJohn Marino */
eap_sm_method_pending(struct eap_sm * sm)19743ff40c12SJohn Marino int eap_sm_method_pending(struct eap_sm *sm)
19753ff40c12SJohn Marino {
19763ff40c12SJohn Marino if (sm == NULL)
19773ff40c12SJohn Marino return 0;
19783ff40c12SJohn Marino return sm->method_pending == METHOD_PENDING_WAIT;
19793ff40c12SJohn Marino }
19803ff40c12SJohn Marino
19813ff40c12SJohn Marino
19823ff40c12SJohn Marino /**
19833ff40c12SJohn Marino * eap_get_identity - Get the user identity (from EAP-Response/Identity)
19843ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
19853ff40c12SJohn Marino * @len: Buffer for returning identity length
19863ff40c12SJohn Marino * Returns: Pointer to the user identity or %NULL if not available
19873ff40c12SJohn Marino */
eap_get_identity(struct eap_sm * sm,size_t * len)19883ff40c12SJohn Marino const u8 * eap_get_identity(struct eap_sm *sm, size_t *len)
19893ff40c12SJohn Marino {
19903ff40c12SJohn Marino *len = sm->identity_len;
19913ff40c12SJohn Marino return sm->identity;
19923ff40c12SJohn Marino }
19933ff40c12SJohn Marino
19943ff40c12SJohn Marino
19953ff40c12SJohn Marino /**
1996*a1157835SDaniel Fojt * eap_get_serial_num - Get the serial number of user certificate
1997*a1157835SDaniel Fojt * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
1998*a1157835SDaniel Fojt * Returns: Pointer to the serial number or %NULL if not available
1999*a1157835SDaniel Fojt */
eap_get_serial_num(struct eap_sm * sm)2000*a1157835SDaniel Fojt const char * eap_get_serial_num(struct eap_sm *sm)
2001*a1157835SDaniel Fojt {
2002*a1157835SDaniel Fojt return sm->serial_num;
2003*a1157835SDaniel Fojt }
2004*a1157835SDaniel Fojt
2005*a1157835SDaniel Fojt
2006*a1157835SDaniel Fojt /**
2007*a1157835SDaniel Fojt * eap_get_method - Get the used EAP method
2008*a1157835SDaniel Fojt * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
2009*a1157835SDaniel Fojt * Returns: Pointer to the method name or %NULL if not available
2010*a1157835SDaniel Fojt */
eap_get_method(struct eap_sm * sm)2011*a1157835SDaniel Fojt const char * eap_get_method(struct eap_sm *sm)
2012*a1157835SDaniel Fojt {
2013*a1157835SDaniel Fojt if (!sm || !sm->m)
2014*a1157835SDaniel Fojt return NULL;
2015*a1157835SDaniel Fojt return sm->m->name;
2016*a1157835SDaniel Fojt }
2017*a1157835SDaniel Fojt
2018*a1157835SDaniel Fojt
2019*a1157835SDaniel Fojt /**
2020*a1157835SDaniel Fojt * eap_get_imsi - Get IMSI of the user
2021*a1157835SDaniel Fojt * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
2022*a1157835SDaniel Fojt * Returns: Pointer to IMSI or %NULL if not available
2023*a1157835SDaniel Fojt */
eap_get_imsi(struct eap_sm * sm)2024*a1157835SDaniel Fojt const char * eap_get_imsi(struct eap_sm *sm)
2025*a1157835SDaniel Fojt {
2026*a1157835SDaniel Fojt if (!sm || sm->imsi[0] == '\0')
2027*a1157835SDaniel Fojt return NULL;
2028*a1157835SDaniel Fojt return sm->imsi;
2029*a1157835SDaniel Fojt }
2030*a1157835SDaniel Fojt
2031*a1157835SDaniel Fojt
eap_erp_update_identity(struct eap_sm * sm,const u8 * eap,size_t len)2032*a1157835SDaniel Fojt void eap_erp_update_identity(struct eap_sm *sm, const u8 *eap, size_t len)
2033*a1157835SDaniel Fojt {
2034*a1157835SDaniel Fojt #ifdef CONFIG_ERP
2035*a1157835SDaniel Fojt const struct eap_hdr *hdr;
2036*a1157835SDaniel Fojt const u8 *pos, *end;
2037*a1157835SDaniel Fojt struct erp_tlvs parse;
2038*a1157835SDaniel Fojt
2039*a1157835SDaniel Fojt if (len < sizeof(*hdr) + 1)
2040*a1157835SDaniel Fojt return;
2041*a1157835SDaniel Fojt hdr = (const struct eap_hdr *) eap;
2042*a1157835SDaniel Fojt end = eap + len;
2043*a1157835SDaniel Fojt pos = (const u8 *) (hdr + 1);
2044*a1157835SDaniel Fojt if (hdr->code != EAP_CODE_INITIATE || *pos != EAP_ERP_TYPE_REAUTH)
2045*a1157835SDaniel Fojt return;
2046*a1157835SDaniel Fojt pos++;
2047*a1157835SDaniel Fojt if (pos + 3 > end)
2048*a1157835SDaniel Fojt return;
2049*a1157835SDaniel Fojt
2050*a1157835SDaniel Fojt /* Skip Flags and SEQ */
2051*a1157835SDaniel Fojt pos += 3;
2052*a1157835SDaniel Fojt
2053*a1157835SDaniel Fojt if (erp_parse_tlvs(pos, end, &parse, 1) < 0 || !parse.keyname)
2054*a1157835SDaniel Fojt return;
2055*a1157835SDaniel Fojt wpa_hexdump_ascii(MSG_DEBUG,
2056*a1157835SDaniel Fojt "EAP: Update identity based on EAP-Initiate/Re-auth keyName-NAI",
2057*a1157835SDaniel Fojt parse.keyname, parse.keyname_len);
2058*a1157835SDaniel Fojt os_free(sm->identity);
2059*a1157835SDaniel Fojt sm->identity = os_malloc(parse.keyname_len);
2060*a1157835SDaniel Fojt if (sm->identity) {
2061*a1157835SDaniel Fojt os_memcpy(sm->identity, parse.keyname, parse.keyname_len);
2062*a1157835SDaniel Fojt sm->identity_len = parse.keyname_len;
2063*a1157835SDaniel Fojt } else {
2064*a1157835SDaniel Fojt sm->identity_len = 0;
2065*a1157835SDaniel Fojt }
2066*a1157835SDaniel Fojt #endif /* CONFIG_ERP */
2067*a1157835SDaniel Fojt }
2068*a1157835SDaniel Fojt
2069*a1157835SDaniel Fojt
2070*a1157835SDaniel Fojt /**
20713ff40c12SJohn Marino * eap_get_interface - Get pointer to EAP-EAPOL interface data
20723ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
20733ff40c12SJohn Marino * Returns: Pointer to the EAP-EAPOL interface data
20743ff40c12SJohn Marino */
eap_get_interface(struct eap_sm * sm)20753ff40c12SJohn Marino struct eap_eapol_interface * eap_get_interface(struct eap_sm *sm)
20763ff40c12SJohn Marino {
20773ff40c12SJohn Marino return &sm->eap_if;
20783ff40c12SJohn Marino }
20793ff40c12SJohn Marino
20803ff40c12SJohn Marino
20813ff40c12SJohn Marino /**
20823ff40c12SJohn Marino * eap_server_clear_identity - Clear EAP identity information
20833ff40c12SJohn Marino * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
20843ff40c12SJohn Marino *
20853ff40c12SJohn Marino * This function can be used to clear the EAP identity information in the EAP
20863ff40c12SJohn Marino * server context. This allows the EAP/Identity method to be used again after
20873ff40c12SJohn Marino * EAPOL-Start or EAPOL-Logoff.
20883ff40c12SJohn Marino */
eap_server_clear_identity(struct eap_sm * sm)20893ff40c12SJohn Marino void eap_server_clear_identity(struct eap_sm *sm)
20903ff40c12SJohn Marino {
20913ff40c12SJohn Marino os_free(sm->identity);
20923ff40c12SJohn Marino sm->identity = NULL;
20933ff40c12SJohn Marino }
2094*a1157835SDaniel Fojt
2095*a1157835SDaniel Fojt
2096*a1157835SDaniel Fojt #ifdef CONFIG_TESTING_OPTIONS
eap_server_mschap_rx_callback(struct eap_sm * sm,const char * source,const u8 * username,size_t username_len,const u8 * challenge,const u8 * response)2097*a1157835SDaniel Fojt void eap_server_mschap_rx_callback(struct eap_sm *sm, const char *source,
2098*a1157835SDaniel Fojt const u8 *username, size_t username_len,
2099*a1157835SDaniel Fojt const u8 *challenge, const u8 *response)
2100*a1157835SDaniel Fojt {
2101*a1157835SDaniel Fojt char hex_challenge[30], hex_response[90], user[100];
2102*a1157835SDaniel Fojt
2103*a1157835SDaniel Fojt /* Print out Challenge and Response in format supported by asleap. */
2104*a1157835SDaniel Fojt if (username)
2105*a1157835SDaniel Fojt printf_encode(user, sizeof(user), username, username_len);
2106*a1157835SDaniel Fojt else
2107*a1157835SDaniel Fojt user[0] = '\0';
2108*a1157835SDaniel Fojt wpa_snprintf_hex_sep(hex_challenge, sizeof(hex_challenge),
2109*a1157835SDaniel Fojt challenge, sizeof(challenge), ':');
2110*a1157835SDaniel Fojt wpa_snprintf_hex_sep(hex_response, sizeof(hex_response), response, 24,
2111*a1157835SDaniel Fojt ':');
2112*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "[%s/user=%s] asleap -C %s -R %s",
2113*a1157835SDaniel Fojt source, user, hex_challenge, hex_response);
2114*a1157835SDaniel Fojt }
2115*a1157835SDaniel Fojt #endif /* CONFIG_TESTING_OPTIONS */
2116