eap.h 11 KB

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