eapol_supp_sm.h 12 KB

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