eap.h revision 61d9df3e62aaa0e87ad05452fcb95142159a17b6
1/* 2 * EAP peer state machine functions (RFC 4137) 3 * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9#ifndef EAP_H 10#define EAP_H 11 12#include "common/defs.h" 13#include "eap_common/eap_defs.h" 14#include "eap_peer/eap_methods.h" 15 16struct eap_sm; 17struct wpa_config_blob; 18struct wpabuf; 19 20struct eap_method_type { 21 int vendor; 22 u32 method; 23}; 24 25#ifdef IEEE8021X_EAPOL 26 27/** 28 * enum eapol_bool_var - EAPOL boolean state variables for EAP state machine 29 * 30 * These variables are used in the interface between EAP peer state machine and 31 * lower layer. These are defined in RFC 4137, Sect. 4.1. Lower layer code is 32 * expected to maintain these variables and register a callback functions for 33 * EAP state machine to get and set the variables. 34 */ 35enum eapol_bool_var { 36 /** 37 * EAPOL_eapSuccess - EAP SUCCESS state reached 38 * 39 * EAP state machine reads and writes this value. 40 */ 41 EAPOL_eapSuccess, 42 43 /** 44 * EAPOL_eapRestart - Lower layer request to restart authentication 45 * 46 * Set to TRUE in lower layer, FALSE in EAP state machine. 47 */ 48 EAPOL_eapRestart, 49 50 /** 51 * EAPOL_eapFail - EAP FAILURE state reached 52 * 53 * EAP state machine writes this value. 54 */ 55 EAPOL_eapFail, 56 57 /** 58 * EAPOL_eapResp - Response to send 59 * 60 * Set to TRUE in EAP state machine, FALSE in lower layer. 61 */ 62 EAPOL_eapResp, 63 64 /** 65 * EAPOL_eapNoResp - Request has been process; no response to send 66 * 67 * Set to TRUE in EAP state machine, FALSE in lower layer. 68 */ 69 EAPOL_eapNoResp, 70 71 /** 72 * EAPOL_eapReq - EAP request available from lower layer 73 * 74 * Set to TRUE in lower layer, FALSE in EAP state machine. 75 */ 76 EAPOL_eapReq, 77 78 /** 79 * EAPOL_portEnabled - Lower layer is ready for communication 80 * 81 * EAP state machines reads this value. 82 */ 83 EAPOL_portEnabled, 84 85 /** 86 * EAPOL_altAccept - Alternate indication of success (RFC3748) 87 * 88 * EAP state machines reads this value. 89 */ 90 EAPOL_altAccept, 91 92 /** 93 * EAPOL_altReject - Alternate indication of failure (RFC3748) 94 * 95 * EAP state machines reads this value. 96 */ 97 EAPOL_altReject 98}; 99 100/** 101 * enum eapol_int_var - EAPOL integer state variables for EAP state machine 102 * 103 * These variables are used in the interface between EAP peer state machine and 104 * lower layer. These are defined in RFC 4137, Sect. 4.1. Lower layer code is 105 * expected to maintain these variables and register a callback functions for 106 * EAP state machine to get and set the variables. 107 */ 108enum eapol_int_var { 109 /** 110 * EAPOL_idleWhile - Outside time for EAP peer timeout 111 * 112 * This integer variable is used to provide an outside timer that the 113 * external (to EAP state machine) code must decrement by one every 114 * second until the value reaches zero. This is used in the same way as 115 * EAPOL state machine timers. EAP state machine reads and writes this 116 * value. 117 */ 118 EAPOL_idleWhile 119}; 120 121/** 122 * struct eapol_callbacks - Callback functions from EAP to lower layer 123 * 124 * This structure defines the callback functions that EAP state machine 125 * requires from the lower layer (usually EAPOL state machine) for updating 126 * state variables and requesting information. eapol_ctx from 127 * eap_peer_sm_init() call will be used as the ctx parameter for these 128 * callback functions. 129 */ 130struct eapol_callbacks { 131 /** 132 * get_config - Get pointer to the current network configuration 133 * @ctx: eapol_ctx from eap_peer_sm_init() call 134 */ 135 struct eap_peer_config * (*get_config)(void *ctx); 136 137 /** 138 * get_bool - Get a boolean EAPOL state variable 139 * @variable: EAPOL boolean variable to get 140 * Returns: Value of the EAPOL variable 141 */ 142 Boolean (*get_bool)(void *ctx, enum eapol_bool_var variable); 143 144 /** 145 * set_bool - Set a boolean EAPOL state variable 146 * @ctx: eapol_ctx from eap_peer_sm_init() call 147 * @variable: EAPOL boolean variable to set 148 * @value: Value for the EAPOL variable 149 */ 150 void (*set_bool)(void *ctx, enum eapol_bool_var variable, 151 Boolean value); 152 153 /** 154 * get_int - Get an integer EAPOL state variable 155 * @ctx: eapol_ctx from eap_peer_sm_init() call 156 * @variable: EAPOL integer variable to get 157 * Returns: Value of the EAPOL variable 158 */ 159 unsigned int (*get_int)(void *ctx, enum eapol_int_var variable); 160 161 /** 162 * set_int - Set an integer EAPOL state variable 163 * @ctx: eapol_ctx from eap_peer_sm_init() call 164 * @variable: EAPOL integer variable to set 165 * @value: Value for the EAPOL variable 166 */ 167 void (*set_int)(void *ctx, enum eapol_int_var variable, 168 unsigned int value); 169 170 /** 171 * get_eapReqData - Get EAP-Request data 172 * @ctx: eapol_ctx from eap_peer_sm_init() call 173 * @len: Pointer to variable that will be set to eapReqDataLen 174 * Returns: Reference to eapReqData (EAP state machine will not free 175 * this) or %NULL if eapReqData not available. 176 */ 177 struct wpabuf * (*get_eapReqData)(void *ctx); 178 179 /** 180 * set_config_blob - Set named configuration blob 181 * @ctx: eapol_ctx from eap_peer_sm_init() call 182 * @blob: New value for the blob 183 * 184 * Adds a new configuration blob or replaces the current value of an 185 * existing blob. 186 */ 187 void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob); 188 189 /** 190 * get_config_blob - Get a named configuration blob 191 * @ctx: eapol_ctx from eap_peer_sm_init() call 192 * @name: Name of the blob 193 * Returns: Pointer to blob data or %NULL if not found 194 */ 195 const struct wpa_config_blob * (*get_config_blob)(void *ctx, 196 const char *name); 197 198 /** 199 * notify_pending - Notify that a pending request can be retried 200 * @ctx: eapol_ctx from eap_peer_sm_init() call 201 * 202 * An EAP method can perform a pending operation (e.g., to get a 203 * response from an external process). Once the response is available, 204 * this callback function can be used to request EAPOL state machine to 205 * retry delivering the previously received (and still unanswered) EAP 206 * request to EAP state machine. 207 */ 208 void (*notify_pending)(void *ctx); 209 210 /** 211 * eap_param_needed - Notify that EAP parameter is needed 212 * @ctx: eapol_ctx from eap_peer_sm_init() call 213 * @field: Field indicator (e.g., WPA_CTRL_REQ_EAP_IDENTITY) 214 * @txt: User readable text describing the required parameter 215 */ 216 void (*eap_param_needed)(void *ctx, enum wpa_ctrl_req_type field, 217 const char *txt); 218 219 /** 220 * notify_cert - Notification of a peer certificate 221 * @ctx: eapol_ctx from eap_peer_sm_init() call 222 * @depth: Depth in certificate chain (0 = server) 223 * @subject: Subject of the peer certificate 224 * @cert_hash: SHA-256 hash of the certificate 225 * @cert: Peer certificate 226 */ 227 void (*notify_cert)(void *ctx, int depth, const char *subject, 228 const char *cert_hash, const struct wpabuf *cert); 229 230 /** 231 * notify_status - Notification of the current EAP state 232 * @ctx: eapol_ctx from eap_peer_sm_init() call 233 * @status: Step in the process of EAP authentication 234 * @parameter: Step-specific parameter, e.g., EAP method name 235 */ 236 void (*notify_status)(void *ctx, const char *status, 237 const char *parameter); 238}; 239 240/** 241 * struct eap_config - Configuration for EAP state machine 242 */ 243struct eap_config { 244 /** 245 * opensc_engine_path - OpenSC engine for OpenSSL engine support 246 * 247 * Usually, path to engine_opensc.so. 248 */ 249 const char *opensc_engine_path; 250 /** 251 * pkcs11_engine_path - PKCS#11 engine for OpenSSL engine support 252 * 253 * Usually, path to engine_pkcs11.so. 254 */ 255 const char *pkcs11_engine_path; 256 /** 257 * pkcs11_module_path - OpenSC PKCS#11 module for OpenSSL engine 258 * 259 * Usually, path to opensc-pkcs11.so. 260 */ 261 const char *pkcs11_module_path; 262 /** 263 * wps - WPS context data 264 * 265 * This is only used by EAP-WSC and can be left %NULL if not available. 266 */ 267 struct wps_context *wps; 268 269 /** 270 * cert_in_cb - Include server certificates in callback 271 */ 272 int cert_in_cb; 273}; 274 275struct eap_sm * eap_peer_sm_init(void *eapol_ctx, 276 struct eapol_callbacks *eapol_cb, 277 void *msg_ctx, struct eap_config *conf); 278void eap_peer_sm_deinit(struct eap_sm *sm); 279int eap_peer_sm_step(struct eap_sm *sm); 280void eap_sm_abort(struct eap_sm *sm); 281int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen, 282 int verbose); 283const char * eap_sm_get_method_name(struct eap_sm *sm); 284struct wpabuf * eap_sm_buildIdentity(struct eap_sm *sm, int id, int encrypted); 285void eap_sm_request_identity(struct eap_sm *sm); 286void eap_sm_request_password(struct eap_sm *sm); 287void eap_sm_request_new_password(struct eap_sm *sm); 288void eap_sm_request_pin(struct eap_sm *sm); 289void eap_sm_request_otp(struct eap_sm *sm, const char *msg, size_t msg_len); 290void eap_sm_request_passphrase(struct eap_sm *sm); 291void eap_sm_notify_ctrl_attached(struct eap_sm *sm); 292u32 eap_get_phase2_type(const char *name, int *vendor); 293struct eap_method_type * eap_get_phase2_types(struct eap_peer_config *config, 294 size_t *count); 295void eap_set_fast_reauth(struct eap_sm *sm, int enabled); 296void eap_set_workaround(struct eap_sm *sm, unsigned int workaround); 297void eap_set_force_disabled(struct eap_sm *sm, int disabled); 298int eap_key_available(struct eap_sm *sm); 299void eap_notify_success(struct eap_sm *sm); 300void eap_notify_lower_layer_success(struct eap_sm *sm); 301const u8 * eap_get_eapKeyData(struct eap_sm *sm, size_t *len); 302struct wpabuf * eap_get_eapRespData(struct eap_sm *sm); 303void eap_register_scard_ctx(struct eap_sm *sm, void *ctx); 304void eap_invalidate_cached_session(struct eap_sm *sm); 305 306int eap_is_wps_pbc_enrollee(struct eap_peer_config *conf); 307int eap_is_wps_pin_enrollee(struct eap_peer_config *conf); 308 309struct ext_password_data; 310void eap_sm_set_ext_pw_ctx(struct eap_sm *sm, struct ext_password_data *ext); 311 312#endif /* IEEE8021X_EAPOL */ 313 314#endif /* EAP_H */ 315