eapol_supp_sm.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * EAPOL supplicant state machines
  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 EAPOL_SUPP_SM_H
  9. #define EAPOL_SUPP_SM_H
  10. #include "common/defs.h"
  11. typedef enum { Unauthorized, Authorized } PortStatus;
  12. typedef enum { Auto, ForceUnauthorized, ForceAuthorized } PortControl;
  13. /**
  14. * struct eapol_config - Per network configuration for EAPOL state machines
  15. */
  16. struct eapol_config {
  17. /**
  18. * accept_802_1x_keys - Accept IEEE 802.1X (non-WPA) EAPOL-Key frames
  19. *
  20. * This variable should be set to 1 when using EAPOL state machines
  21. * with non-WPA security policy to generate dynamic WEP keys. When
  22. * using WPA, this should be set to 0 so that WPA state machine can
  23. * process the EAPOL-Key frames.
  24. */
  25. int accept_802_1x_keys;
  26. #define EAPOL_REQUIRE_KEY_UNICAST BIT(0)
  27. #define EAPOL_REQUIRE_KEY_BROADCAST BIT(1)
  28. /**
  29. * required_keys - Which EAPOL-Key packets are required
  30. *
  31. * This variable determines which EAPOL-Key packets are required before
  32. * marking connection authenticated. This is a bit field of
  33. * EAPOL_REQUIRE_KEY_UNICAST and EAPOL_REQUIRE_KEY_BROADCAST flags.
  34. */
  35. int required_keys;
  36. /**
  37. * fast_reauth - Whether fast EAP reauthentication is enabled
  38. */
  39. int fast_reauth;
  40. /**
  41. * workaround - Whether EAP workarounds are enabled
  42. */
  43. unsigned int workaround;
  44. /**
  45. * eap_disabled - Whether EAP is disabled
  46. */
  47. int eap_disabled;
  48. /**
  49. * external_sim - Use external processing for SIM/USIM operations
  50. */
  51. int external_sim;
  52. };
  53. struct eapol_sm;
  54. struct wpa_config_blob;
  55. enum eapol_supp_result {
  56. EAPOL_SUPP_RESULT_FAILURE,
  57. EAPOL_SUPP_RESULT_SUCCESS,
  58. EAPOL_SUPP_RESULT_EXPECTED_FAILURE
  59. };
  60. /**
  61. * struct eapol_ctx - Global (for all networks) EAPOL state machine context
  62. */
  63. struct eapol_ctx {
  64. /**
  65. * ctx - Pointer to arbitrary upper level context
  66. */
  67. void *ctx;
  68. /**
  69. * preauth - IEEE 802.11i/RSN pre-authentication
  70. *
  71. * This EAPOL state machine is used for IEEE 802.11i/RSN
  72. * pre-authentication
  73. */
  74. int preauth;
  75. /**
  76. * cb - Function to be called when EAPOL negotiation has been completed
  77. * @eapol: Pointer to EAPOL state machine data
  78. * @result: Whether the authentication was completed successfully
  79. * @ctx: Pointer to context data (cb_ctx)
  80. *
  81. * This optional callback function will be called when the EAPOL
  82. * authentication has been completed. This allows the owner of the
  83. * EAPOL state machine to process the key and terminate the EAPOL state
  84. * machine. Currently, this is used only in RSN pre-authentication.
  85. */
  86. void (*cb)(struct eapol_sm *eapol, enum eapol_supp_result result,
  87. void *ctx);
  88. /**
  89. * cb_ctx - Callback context for cb()
  90. */
  91. void *cb_ctx;
  92. /**
  93. * msg_ctx - Callback context for wpa_msg() calls
  94. */
  95. void *msg_ctx;
  96. /**
  97. * scard_ctx - Callback context for PC/SC scard_*() function calls
  98. *
  99. * This context can be updated with eapol_sm_register_scard_ctx().
  100. */
  101. void *scard_ctx;
  102. /**
  103. * eapol_send_ctx - Callback context for eapol_send() calls
  104. */
  105. void *eapol_send_ctx;
  106. /**
  107. * eapol_done_cb - Function to be called at successful completion
  108. * @ctx: Callback context (ctx)
  109. *
  110. * This function is called at the successful completion of EAPOL
  111. * authentication. If dynamic WEP keys are used, this is called only
  112. * after all the expected keys have been received.
  113. */
  114. void (*eapol_done_cb)(void *ctx);
  115. /**
  116. * eapol_send - Send EAPOL packets
  117. * @ctx: Callback context (eapol_send_ctx)
  118. * @type: EAPOL type (IEEE802_1X_TYPE_*)
  119. * @buf: Pointer to EAPOL payload
  120. * @len: Length of the EAPOL payload
  121. * Returns: 0 on success, -1 on failure
  122. */
  123. int (*eapol_send)(void *ctx, int type, const u8 *buf, size_t len);
  124. /**
  125. * set_wep_key - Configure WEP keys
  126. * @ctx: Callback context (ctx)
  127. * @unicast: Non-zero = unicast, 0 = multicast/broadcast key
  128. * @keyidx: Key index (0..3)
  129. * @key: WEP key
  130. * @keylen: Length of the WEP key
  131. * Returns: 0 on success, -1 on failure
  132. */
  133. int (*set_wep_key)(void *ctx, int unicast, int keyidx,
  134. const u8 *key, size_t keylen);
  135. /**
  136. * set_config_blob - Set or add a named configuration blob
  137. * @ctx: Callback context (ctx)
  138. * @blob: New value for the blob
  139. *
  140. * Adds a new configuration blob or replaces the current value of an
  141. * existing blob.
  142. */
  143. void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob);
  144. /**
  145. * get_config_blob - Get a named configuration blob
  146. * @ctx: Callback context (ctx)
  147. * @name: Name of the blob
  148. * Returns: Pointer to blob data or %NULL if not found
  149. */
  150. const struct wpa_config_blob * (*get_config_blob)(void *ctx,
  151. const char *name);
  152. /**
  153. * aborted_cached - Notify that cached PMK attempt was aborted
  154. * @ctx: Callback context (ctx)
  155. */
  156. void (*aborted_cached)(void *ctx);
  157. /**
  158. * opensc_engine_path - Path to the OpenSSL engine for opensc
  159. *
  160. * This is an OpenSSL specific configuration option for loading OpenSC
  161. * engine (engine_opensc.so); if %NULL, this engine is not loaded.
  162. */
  163. const char *opensc_engine_path;
  164. /**
  165. * pkcs11_engine_path - Path to the OpenSSL engine for PKCS#11
  166. *
  167. * This is an OpenSSL specific configuration option for loading PKCS#11
  168. * engine (engine_pkcs11.so); if %NULL, this engine is not loaded.
  169. */
  170. const char *pkcs11_engine_path;
  171. /**
  172. * pkcs11_module_path - Path to the OpenSSL OpenSC/PKCS#11 module
  173. *
  174. * This is an OpenSSL specific configuration option for configuring
  175. * path to OpenSC/PKCS#11 engine (opensc-pkcs11.so); if %NULL, this
  176. * module is not loaded.
  177. */
  178. const char *pkcs11_module_path;
  179. /**
  180. * wps - WPS context data
  181. *
  182. * This is only used by EAP-WSC and can be left %NULL if not available.
  183. */
  184. struct wps_context *wps;
  185. /**
  186. * eap_param_needed - Notify that EAP parameter is needed
  187. * @ctx: Callback context (ctx)
  188. * @field: Field indicator (e.g., WPA_CTRL_REQ_EAP_IDENTITY)
  189. * @txt: User readable text describing the required parameter
  190. */
  191. void (*eap_param_needed)(void *ctx, enum wpa_ctrl_req_type field,
  192. const char *txt);
  193. /**
  194. * port_cb - Set port authorized/unauthorized callback (optional)
  195. * @ctx: Callback context (ctx)
  196. * @authorized: Whether the supplicant port is now in authorized state
  197. */
  198. void (*port_cb)(void *ctx, int authorized);
  199. /**
  200. * cert_cb - Notification of a peer certificate
  201. * @ctx: Callback context (ctx)
  202. * @depth: Depth in certificate chain (0 = server)
  203. * @subject: Subject of the peer certificate
  204. * @cert_hash: SHA-256 hash of the certificate
  205. * @cert: Peer certificate
  206. */
  207. void (*cert_cb)(void *ctx, int depth, const char *subject,
  208. const char *cert_hash, const struct wpabuf *cert);
  209. /**
  210. * cert_in_cb - Include server certificates in callback
  211. */
  212. int cert_in_cb;
  213. /**
  214. * status_cb - Notification of a change in EAP status
  215. * @ctx: Callback context (ctx)
  216. * @status: Step in the process of EAP authentication
  217. * @parameter: Step-specific parameter, e.g., EAP method name
  218. */
  219. void (*status_cb)(void *ctx, const char *status,
  220. const char *parameter);
  221. /**
  222. * set_anon_id - Set or add anonymous identity
  223. * @ctx: eapol_ctx from eap_peer_sm_init() call
  224. * @id: Anonymous identity (e.g., EAP-SIM pseudonym)
  225. * @len: Length of anonymous identity in octets
  226. */
  227. void (*set_anon_id)(void *ctx, const u8 *id, size_t len);
  228. };
  229. struct eap_peer_config;
  230. struct ext_password_data;
  231. #ifdef IEEE8021X_EAPOL
  232. struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx);
  233. void eapol_sm_deinit(struct eapol_sm *sm);
  234. void eapol_sm_step(struct eapol_sm *sm);
  235. int eapol_sm_get_status(struct eapol_sm *sm, char *buf, size_t buflen,
  236. int verbose);
  237. int eapol_sm_get_mib(struct eapol_sm *sm, char *buf, size_t buflen);
  238. void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod, int authPeriod,
  239. int startPeriod, int maxStart);
  240. int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src, const u8 *buf,
  241. size_t len);
  242. void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm);
  243. void eapol_sm_notify_portEnabled(struct eapol_sm *sm, Boolean enabled);
  244. void eapol_sm_notify_portValid(struct eapol_sm *sm, Boolean valid);
  245. void eapol_sm_notify_eap_success(struct eapol_sm *sm, Boolean success);
  246. void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail);
  247. void eapol_sm_notify_config(struct eapol_sm *sm,
  248. struct eap_peer_config *config,
  249. const struct eapol_config *conf);
  250. int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len);
  251. void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff);
  252. void eapol_sm_notify_cached(struct eapol_sm *sm);
  253. void eapol_sm_notify_pmkid_attempt(struct eapol_sm *sm, int attempt);
  254. void eapol_sm_register_scard_ctx(struct eapol_sm *sm, void *ctx);
  255. void eapol_sm_notify_portControl(struct eapol_sm *sm, PortControl portControl);
  256. void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm);
  257. void eapol_sm_notify_ctrl_response(struct eapol_sm *sm);
  258. void eapol_sm_request_reauth(struct eapol_sm *sm);
  259. void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm, int in_eapol_sm);
  260. void eapol_sm_invalidate_cached_session(struct eapol_sm *sm);
  261. const char * eapol_sm_get_method_name(struct eapol_sm *sm);
  262. void eapol_sm_set_ext_pw_ctx(struct eapol_sm *sm,
  263. struct ext_password_data *ext);
  264. int eapol_sm_failed(struct eapol_sm *sm);
  265. int eapol_sm_get_eap_proxy_imsi(struct eapol_sm *sm, char *imsi, size_t *len);
  266. #else /* IEEE8021X_EAPOL */
  267. static inline struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx)
  268. {
  269. free(ctx);
  270. return (struct eapol_sm *) 1;
  271. }
  272. static inline void eapol_sm_deinit(struct eapol_sm *sm)
  273. {
  274. }
  275. static inline void eapol_sm_step(struct eapol_sm *sm)
  276. {
  277. }
  278. static inline int eapol_sm_get_status(struct eapol_sm *sm, char *buf,
  279. size_t buflen, int verbose)
  280. {
  281. return 0;
  282. }
  283. static inline int eapol_sm_get_mib(struct eapol_sm *sm, char *buf,
  284. size_t buflen)
  285. {
  286. return 0;
  287. }
  288. static inline void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod,
  289. int authPeriod, int startPeriod,
  290. int maxStart)
  291. {
  292. }
  293. static inline int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src,
  294. const u8 *buf, size_t len)
  295. {
  296. return 0;
  297. }
  298. static inline void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm)
  299. {
  300. }
  301. static inline void eapol_sm_notify_portEnabled(struct eapol_sm *sm,
  302. Boolean enabled)
  303. {
  304. }
  305. static inline void eapol_sm_notify_portValid(struct eapol_sm *sm,
  306. Boolean valid)
  307. {
  308. }
  309. static inline void eapol_sm_notify_eap_success(struct eapol_sm *sm,
  310. Boolean success)
  311. {
  312. }
  313. static inline void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail)
  314. {
  315. }
  316. static inline void eapol_sm_notify_config(struct eapol_sm *sm,
  317. struct eap_peer_config *config,
  318. struct eapol_config *conf)
  319. {
  320. }
  321. static inline int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len)
  322. {
  323. return -1;
  324. }
  325. static inline void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff)
  326. {
  327. }
  328. static inline void eapol_sm_notify_cached(struct eapol_sm *sm)
  329. {
  330. }
  331. #define eapol_sm_notify_pmkid_attempt(sm, attempt) do { } while (0)
  332. #define eapol_sm_register_scard_ctx(sm, ctx) do { } while (0)
  333. static inline void eapol_sm_notify_portControl(struct eapol_sm *sm,
  334. PortControl portControl)
  335. {
  336. }
  337. static inline void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm)
  338. {
  339. }
  340. static inline void eapol_sm_notify_ctrl_response(struct eapol_sm *sm)
  341. {
  342. }
  343. static inline void eapol_sm_request_reauth(struct eapol_sm *sm)
  344. {
  345. }
  346. static inline void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm,
  347. int in_eapol_sm)
  348. {
  349. }
  350. static inline void eapol_sm_invalidate_cached_session(struct eapol_sm *sm)
  351. {
  352. }
  353. static inline const char * eapol_sm_get_method_name(struct eapol_sm *sm)
  354. {
  355. return NULL;
  356. }
  357. static inline void eapol_sm_set_ext_pw_ctx(struct eapol_sm *sm,
  358. struct ext_password_data *ext)
  359. {
  360. }
  361. static inline int eapol_sm_failed(struct eapol_sm *sm)
  362. {
  363. return 0;
  364. }
  365. #endif /* IEEE8021X_EAPOL */
  366. #endif /* EAPOL_SUPP_SM_H */