eap_i.h revision 189251
1189251Ssam/* 2189251Ssam * EAP peer state machines internal structures (RFC 4137) 3189251Ssam * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi> 4189251Ssam * 5189251Ssam * This program is free software; you can redistribute it and/or modify 6189251Ssam * it under the terms of the GNU General Public License version 2 as 7189251Ssam * published by the Free Software Foundation. 8189251Ssam * 9189251Ssam * Alternatively, this software may be distributed under the terms of BSD 10189251Ssam * license. 11189251Ssam * 12189251Ssam * See README and COPYING for more details. 13189251Ssam */ 14189251Ssam 15189251Ssam#ifndef EAP_I_H 16189251Ssam#define EAP_I_H 17189251Ssam 18189251Ssam#include "wpabuf.h" 19189251Ssam#include "eap_peer/eap.h" 20189251Ssam#include "eap_common/eap_common.h" 21189251Ssam 22189251Ssam/* RFC 4137 - EAP Peer state machine */ 23189251Ssam 24189251Ssamtypedef enum { 25189251Ssam DECISION_FAIL, DECISION_COND_SUCC, DECISION_UNCOND_SUCC 26189251Ssam} EapDecision; 27189251Ssam 28189251Ssamtypedef enum { 29189251Ssam METHOD_NONE, METHOD_INIT, METHOD_CONT, METHOD_MAY_CONT, METHOD_DONE 30189251Ssam} EapMethodState; 31189251Ssam 32189251Ssam/** 33189251Ssam * struct eap_method_ret - EAP return values from struct eap_method::process() 34189251Ssam * 35189251Ssam * These structure contains OUT variables for the interface between peer state 36189251Ssam * machine and methods (RFC 4137, Sect. 4.2). eapRespData will be returned as 37189251Ssam * the return value of struct eap_method::process() so it is not included in 38189251Ssam * this structure. 39189251Ssam */ 40189251Ssamstruct eap_method_ret { 41189251Ssam /** 42189251Ssam * ignore - Whether method decided to drop the current packed (OUT) 43189251Ssam */ 44189251Ssam Boolean ignore; 45189251Ssam 46189251Ssam /** 47189251Ssam * methodState - Method-specific state (IN/OUT) 48189251Ssam */ 49189251Ssam EapMethodState methodState; 50189251Ssam 51189251Ssam /** 52189251Ssam * decision - Authentication decision (OUT) 53189251Ssam */ 54189251Ssam EapDecision decision; 55189251Ssam 56189251Ssam /** 57189251Ssam * allowNotifications - Whether method allows notifications (OUT) 58189251Ssam */ 59189251Ssam Boolean allowNotifications; 60189251Ssam}; 61189251Ssam 62189251Ssam 63189251Ssam/** 64189251Ssam * struct eap_method - EAP method interface 65189251Ssam * This structure defines the EAP method interface. Each method will need to 66189251Ssam * register its own EAP type, EAP name, and set of function pointers for method 67189251Ssam * specific operations. This interface is based on section 4.4 of RFC 4137. 68189251Ssam */ 69189251Ssamstruct eap_method { 70189251Ssam /** 71189251Ssam * vendor - EAP Vendor-ID (EAP_VENDOR_*) (0 = IETF) 72189251Ssam */ 73189251Ssam int vendor; 74189251Ssam 75189251Ssam /** 76189251Ssam * method - EAP type number (EAP_TYPE_*) 77189251Ssam */ 78189251Ssam EapType method; 79189251Ssam 80189251Ssam /** 81189251Ssam * name - Name of the method (e.g., "TLS") 82189251Ssam */ 83189251Ssam const char *name; 84189251Ssam 85189251Ssam /** 86189251Ssam * init - Initialize an EAP method 87189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 88189251Ssam * Returns: Pointer to allocated private data, or %NULL on failure 89189251Ssam * 90189251Ssam * This function is used to initialize the EAP method explicitly 91189251Ssam * instead of using METHOD_INIT state as specific in RFC 4137. The 92189251Ssam * method is expected to initialize it method-specific state and return 93189251Ssam * a pointer that will be used as the priv argument to other calls. 94189251Ssam */ 95189251Ssam void * (*init)(struct eap_sm *sm); 96189251Ssam 97189251Ssam /** 98189251Ssam * deinit - Deinitialize an EAP method 99189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 100189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 101189251Ssam * 102189251Ssam * Deinitialize the EAP method and free any allocated private data. 103189251Ssam */ 104189251Ssam void (*deinit)(struct eap_sm *sm, void *priv); 105189251Ssam 106189251Ssam /** 107189251Ssam * process - Process an EAP request 108189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 109189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 110189251Ssam * @ret: Return values from EAP request validation and processing 111189251Ssam * @reqData: EAP request to be processed (eapReqData) 112189251Ssam * Returns: Pointer to allocated EAP response packet (eapRespData) 113189251Ssam * 114189251Ssam * This function is a combination of m.check(), m.process(), and 115189251Ssam * m.buildResp() procedures defined in section 4.4 of RFC 4137 In other 116189251Ssam * words, this function validates the incoming request, processes it, 117189251Ssam * and build a response packet. m.check() and m.process() return values 118189251Ssam * are returned through struct eap_method_ret *ret variable. Caller is 119189251Ssam * responsible for freeing the returned EAP response packet. 120189251Ssam */ 121189251Ssam struct wpabuf * (*process)(struct eap_sm *sm, void *priv, 122189251Ssam struct eap_method_ret *ret, 123189251Ssam const struct wpabuf *reqData); 124189251Ssam 125189251Ssam /** 126189251Ssam * isKeyAvailable - Find out whether EAP method has keying material 127189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 128189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 129189251Ssam * Returns: %TRUE if key material (eapKeyData) is available 130189251Ssam */ 131189251Ssam Boolean (*isKeyAvailable)(struct eap_sm *sm, void *priv); 132189251Ssam 133189251Ssam /** 134189251Ssam * getKey - Get EAP method specific keying material (eapKeyData) 135189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 136189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 137189251Ssam * @len: Pointer to variable to store key length (eapKeyDataLen) 138189251Ssam * Returns: Keying material (eapKeyData) or %NULL if not available 139189251Ssam * 140189251Ssam * This function can be used to get the keying material from the EAP 141189251Ssam * method. The key may already be stored in the method-specific private 142189251Ssam * data or this function may derive the key. 143189251Ssam */ 144189251Ssam u8 * (*getKey)(struct eap_sm *sm, void *priv, size_t *len); 145189251Ssam 146189251Ssam /** 147189251Ssam * get_status - Get EAP method status 148189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 149189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 150189251Ssam * @buf: Buffer for status information 151189251Ssam * @buflen: Maximum buffer length 152189251Ssam * @verbose: Whether to include verbose status information 153189251Ssam * Returns: Number of bytes written to buf 154189251Ssam * 155189251Ssam * Query EAP method for status information. This function fills in a 156189251Ssam * text area with current status information from the EAP method. If 157189251Ssam * the buffer (buf) is not large enough, status information will be 158189251Ssam * truncated to fit the buffer. 159189251Ssam */ 160189251Ssam int (*get_status)(struct eap_sm *sm, void *priv, char *buf, 161189251Ssam size_t buflen, int verbose); 162189251Ssam 163189251Ssam /** 164189251Ssam * has_reauth_data - Whether method is ready for fast reauthentication 165189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 166189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 167189251Ssam * Returns: %TRUE or %FALSE based on whether fast reauthentication is 168189251Ssam * possible 169189251Ssam * 170189251Ssam * This function is an optional handler that only EAP methods 171189251Ssam * supporting fast re-authentication need to implement. 172189251Ssam */ 173189251Ssam Boolean (*has_reauth_data)(struct eap_sm *sm, void *priv); 174189251Ssam 175189251Ssam /** 176189251Ssam * deinit_for_reauth - Release data that is not needed for fast re-auth 177189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 178189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 179189251Ssam * 180189251Ssam * This function is an optional handler that only EAP methods 181189251Ssam * supporting fast re-authentication need to implement. This is called 182189251Ssam * when authentication has been completed and EAP state machine is 183189251Ssam * requesting that enough state information is maintained for fast 184189251Ssam * re-authentication 185189251Ssam */ 186189251Ssam void (*deinit_for_reauth)(struct eap_sm *sm, void *priv); 187189251Ssam 188189251Ssam /** 189189251Ssam * init_for_reauth - Prepare for start of fast re-authentication 190189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 191189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 192189251Ssam * 193189251Ssam * This function is an optional handler that only EAP methods 194189251Ssam * supporting fast re-authentication need to implement. This is called 195189251Ssam * when EAP authentication is started and EAP state machine is 196189251Ssam * requesting fast re-authentication to be used. 197189251Ssam */ 198189251Ssam void * (*init_for_reauth)(struct eap_sm *sm, void *priv); 199189251Ssam 200189251Ssam /** 201189251Ssam * get_identity - Get method specific identity for re-authentication 202189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 203189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 204189251Ssam * @len: Length of the returned identity 205189251Ssam * Returns: Pointer to the method specific identity or %NULL if default 206189251Ssam * identity is to be used 207189251Ssam * 208189251Ssam * This function is an optional handler that only EAP methods 209189251Ssam * that use method specific identity need to implement. 210189251Ssam */ 211189251Ssam const u8 * (*get_identity)(struct eap_sm *sm, void *priv, size_t *len); 212189251Ssam 213189251Ssam /** 214189251Ssam * free - Free EAP method data 215189251Ssam * @method: Pointer to the method data registered with 216189251Ssam * eap_peer_method_register(). 217189251Ssam * 218189251Ssam * This function will be called when the EAP method is being 219189251Ssam * unregistered. If the EAP method allocated resources during 220189251Ssam * registration (e.g., allocated struct eap_method), they should be 221189251Ssam * freed in this function. No other method functions will be called 222189251Ssam * after this call. If this function is not defined (i.e., function 223189251Ssam * pointer is %NULL), a default handler is used to release the method 224189251Ssam * data with free(method). This is suitable for most cases. 225189251Ssam */ 226189251Ssam void (*free)(struct eap_method *method); 227189251Ssam 228189251Ssam#define EAP_PEER_METHOD_INTERFACE_VERSION 1 229189251Ssam /** 230189251Ssam * version - Version of the EAP peer method interface 231189251Ssam * 232189251Ssam * The EAP peer method implementation should set this variable to 233189251Ssam * EAP_PEER_METHOD_INTERFACE_VERSION. This is used to verify that the 234189251Ssam * EAP method is using supported API version when using dynamically 235189251Ssam * loadable EAP methods. 236189251Ssam */ 237189251Ssam int version; 238189251Ssam 239189251Ssam /** 240189251Ssam * next - Pointer to the next EAP method 241189251Ssam * 242189251Ssam * This variable is used internally in the EAP method registration code 243189251Ssam * to create a linked list of registered EAP methods. 244189251Ssam */ 245189251Ssam struct eap_method *next; 246189251Ssam 247189251Ssam#ifdef CONFIG_DYNAMIC_EAP_METHODS 248189251Ssam /** 249189251Ssam * dl_handle - Handle for the dynamic library 250189251Ssam * 251189251Ssam * This variable is used internally in the EAP method registration code 252189251Ssam * to store a handle for the dynamic library. If the method is linked 253189251Ssam * in statically, this is %NULL. 254189251Ssam */ 255189251Ssam void *dl_handle; 256189251Ssam#endif /* CONFIG_DYNAMIC_EAP_METHODS */ 257189251Ssam 258189251Ssam /** 259189251Ssam * get_emsk - Get EAP method specific keying extended material (EMSK) 260189251Ssam * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() 261189251Ssam * @priv: Pointer to private EAP method data from eap_method::init() 262189251Ssam * @len: Pointer to a variable to store EMSK length 263189251Ssam * Returns: EMSK or %NULL if not available 264189251Ssam * 265189251Ssam * This function can be used to get the extended keying material from 266189251Ssam * the EAP method. The key may already be stored in the method-specific 267189251Ssam * private data or this function may derive the key. 268189251Ssam */ 269189251Ssam u8 * (*get_emsk)(struct eap_sm *sm, void *priv, size_t *len); 270189251Ssam}; 271189251Ssam 272189251Ssam 273189251Ssam/** 274189251Ssam * struct eap_sm - EAP state machine data 275189251Ssam */ 276189251Ssamstruct eap_sm { 277189251Ssam enum { 278189251Ssam EAP_INITIALIZE, EAP_DISABLED, EAP_IDLE, EAP_RECEIVED, 279189251Ssam EAP_GET_METHOD, EAP_METHOD, EAP_SEND_RESPONSE, EAP_DISCARD, 280189251Ssam EAP_IDENTITY, EAP_NOTIFICATION, EAP_RETRANSMIT, EAP_SUCCESS, 281189251Ssam EAP_FAILURE 282189251Ssam } EAP_state; 283189251Ssam /* Long-term local variables */ 284189251Ssam EapType selectedMethod; 285189251Ssam EapMethodState methodState; 286189251Ssam int lastId; 287189251Ssam struct wpabuf *lastRespData; 288189251Ssam EapDecision decision; 289189251Ssam /* Short-term local variables */ 290189251Ssam Boolean rxReq; 291189251Ssam Boolean rxSuccess; 292189251Ssam Boolean rxFailure; 293189251Ssam int reqId; 294189251Ssam EapType reqMethod; 295189251Ssam int reqVendor; 296189251Ssam u32 reqVendorMethod; 297189251Ssam Boolean ignore; 298189251Ssam /* Constants */ 299189251Ssam int ClientTimeout; 300189251Ssam 301189251Ssam /* Miscellaneous variables */ 302189251Ssam Boolean allowNotifications; /* peer state machine <-> methods */ 303189251Ssam struct wpabuf *eapRespData; /* peer to lower layer */ 304189251Ssam Boolean eapKeyAvailable; /* peer to lower layer */ 305189251Ssam u8 *eapKeyData; /* peer to lower layer */ 306189251Ssam size_t eapKeyDataLen; /* peer to lower layer */ 307189251Ssam const struct eap_method *m; /* selected EAP method */ 308189251Ssam /* not defined in RFC 4137 */ 309189251Ssam Boolean changed; 310189251Ssam void *eapol_ctx; 311189251Ssam struct eapol_callbacks *eapol_cb; 312189251Ssam void *eap_method_priv; 313189251Ssam int init_phase2; 314189251Ssam int fast_reauth; 315189251Ssam 316189251Ssam Boolean rxResp /* LEAP only */; 317189251Ssam Boolean leap_done; 318189251Ssam Boolean peap_done; 319189251Ssam u8 req_md5[16]; /* MD5() of the current EAP packet */ 320189251Ssam u8 last_md5[16]; /* MD5() of the previously received EAP packet; used 321189251Ssam * in duplicate request detection. */ 322189251Ssam 323189251Ssam void *msg_ctx; 324189251Ssam void *scard_ctx; 325189251Ssam void *ssl_ctx; 326189251Ssam 327189251Ssam unsigned int workaround; 328189251Ssam 329189251Ssam /* Optional challenges generated in Phase 1 (EAP-FAST) */ 330189251Ssam u8 *peer_challenge, *auth_challenge; 331189251Ssam 332189251Ssam int num_rounds; 333189251Ssam int force_disabled; 334189251Ssam 335189251Ssam struct wps_context *wps; 336189251Ssam 337189251Ssam int prev_failure; 338189251Ssam}; 339189251Ssam 340189251Ssamconst u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len); 341189251Ssamconst u8 * eap_get_config_password(struct eap_sm *sm, size_t *len); 342189251Ssamconst u8 * eap_get_config_password2(struct eap_sm *sm, size_t *len, int *hash); 343189251Ssamconst u8 * eap_get_config_new_password(struct eap_sm *sm, size_t *len); 344189251Ssamconst u8 * eap_get_config_otp(struct eap_sm *sm, size_t *len); 345189251Ssamvoid eap_clear_config_otp(struct eap_sm *sm); 346189251Ssamconst char * eap_get_config_phase1(struct eap_sm *sm); 347189251Ssamconst char * eap_get_config_phase2(struct eap_sm *sm); 348189251Ssamstruct eap_peer_config * eap_get_config(struct eap_sm *sm); 349189251Ssamvoid eap_set_config_blob(struct eap_sm *sm, struct wpa_config_blob *blob); 350189251Ssamconst struct wpa_config_blob * 351189251Ssameap_get_config_blob(struct eap_sm *sm, const char *name); 352189251Ssamvoid eap_notify_pending(struct eap_sm *sm); 353189251Ssamint eap_allowed_method(struct eap_sm *sm, int vendor, u32 method); 354189251Ssam 355189251Ssam#endif /* EAP_I_H */ 356