eap_i.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*
  2. * EAP peer state machines internal structures (RFC 4137)
  3. * Copyright (c) 2004-2014, 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_I_H
  9. #define EAP_I_H
  10. #include "wpabuf.h"
  11. #include "utils/list.h"
  12. #include "eap_peer/eap.h"
  13. #include "eap_common/eap_common.h"
  14. /* RFC 4137 - EAP Peer state machine */
  15. typedef enum {
  16. DECISION_FAIL, DECISION_COND_SUCC, DECISION_UNCOND_SUCC
  17. } EapDecision;
  18. typedef enum {
  19. METHOD_NONE, METHOD_INIT, METHOD_CONT, METHOD_MAY_CONT, METHOD_DONE
  20. } EapMethodState;
  21. /**
  22. * struct eap_method_ret - EAP return values from struct eap_method::process()
  23. *
  24. * These structure contains OUT variables for the interface between peer state
  25. * machine and methods (RFC 4137, Sect. 4.2). eapRespData will be returned as
  26. * the return value of struct eap_method::process() so it is not included in
  27. * this structure.
  28. */
  29. struct eap_method_ret {
  30. /**
  31. * ignore - Whether method decided to drop the current packed (OUT)
  32. */
  33. Boolean ignore;
  34. /**
  35. * methodState - Method-specific state (IN/OUT)
  36. */
  37. EapMethodState methodState;
  38. /**
  39. * decision - Authentication decision (OUT)
  40. */
  41. EapDecision decision;
  42. /**
  43. * allowNotifications - Whether method allows notifications (OUT)
  44. */
  45. Boolean allowNotifications;
  46. };
  47. /**
  48. * struct eap_method - EAP method interface
  49. * This structure defines the EAP method interface. Each method will need to
  50. * register its own EAP type, EAP name, and set of function pointers for method
  51. * specific operations. This interface is based on section 4.4 of RFC 4137.
  52. */
  53. struct eap_method {
  54. /**
  55. * vendor - EAP Vendor-ID (EAP_VENDOR_*) (0 = IETF)
  56. */
  57. int vendor;
  58. /**
  59. * method - EAP type number (EAP_TYPE_*)
  60. */
  61. EapType method;
  62. /**
  63. * name - Name of the method (e.g., "TLS")
  64. */
  65. const char *name;
  66. /**
  67. * init - Initialize an EAP method
  68. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  69. * Returns: Pointer to allocated private data, or %NULL on failure
  70. *
  71. * This function is used to initialize the EAP method explicitly
  72. * instead of using METHOD_INIT state as specific in RFC 4137. The
  73. * method is expected to initialize it method-specific state and return
  74. * a pointer that will be used as the priv argument to other calls.
  75. */
  76. void * (*init)(struct eap_sm *sm);
  77. /**
  78. * deinit - Deinitialize an EAP method
  79. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  80. * @priv: Pointer to private EAP method data from eap_method::init()
  81. *
  82. * Deinitialize the EAP method and free any allocated private data.
  83. */
  84. void (*deinit)(struct eap_sm *sm, void *priv);
  85. /**
  86. * process - Process an EAP request
  87. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  88. * @priv: Pointer to private EAP method data from eap_method::init()
  89. * @ret: Return values from EAP request validation and processing
  90. * @reqData: EAP request to be processed (eapReqData)
  91. * Returns: Pointer to allocated EAP response packet (eapRespData)
  92. *
  93. * This function is a combination of m.check(), m.process(), and
  94. * m.buildResp() procedures defined in section 4.4 of RFC 4137 In other
  95. * words, this function validates the incoming request, processes it,
  96. * and build a response packet. m.check() and m.process() return values
  97. * are returned through struct eap_method_ret *ret variable. Caller is
  98. * responsible for freeing the returned EAP response packet.
  99. */
  100. struct wpabuf * (*process)(struct eap_sm *sm, void *priv,
  101. struct eap_method_ret *ret,
  102. const struct wpabuf *reqData);
  103. /**
  104. * isKeyAvailable - Find out whether EAP method has keying material
  105. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  106. * @priv: Pointer to private EAP method data from eap_method::init()
  107. * Returns: %TRUE if key material (eapKeyData) is available
  108. */
  109. Boolean (*isKeyAvailable)(struct eap_sm *sm, void *priv);
  110. /**
  111. * getKey - Get EAP method specific keying material (eapKeyData)
  112. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  113. * @priv: Pointer to private EAP method data from eap_method::init()
  114. * @len: Pointer to variable to store key length (eapKeyDataLen)
  115. * Returns: Keying material (eapKeyData) or %NULL if not available
  116. *
  117. * This function can be used to get the keying material from the EAP
  118. * method. The key may already be stored in the method-specific private
  119. * data or this function may derive the key.
  120. */
  121. u8 * (*getKey)(struct eap_sm *sm, void *priv, size_t *len);
  122. /**
  123. * get_status - Get EAP method status
  124. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  125. * @priv: Pointer to private EAP method data from eap_method::init()
  126. * @buf: Buffer for status information
  127. * @buflen: Maximum buffer length
  128. * @verbose: Whether to include verbose status information
  129. * Returns: Number of bytes written to buf
  130. *
  131. * Query EAP method for status information. This function fills in a
  132. * text area with current status information from the EAP method. If
  133. * the buffer (buf) is not large enough, status information will be
  134. * truncated to fit the buffer.
  135. */
  136. int (*get_status)(struct eap_sm *sm, void *priv, char *buf,
  137. size_t buflen, int verbose);
  138. /**
  139. * has_reauth_data - Whether method is ready for fast reauthentication
  140. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  141. * @priv: Pointer to private EAP method data from eap_method::init()
  142. * Returns: %TRUE or %FALSE based on whether fast reauthentication is
  143. * possible
  144. *
  145. * This function is an optional handler that only EAP methods
  146. * supporting fast re-authentication need to implement.
  147. */
  148. Boolean (*has_reauth_data)(struct eap_sm *sm, void *priv);
  149. /**
  150. * deinit_for_reauth - Release data that is not needed for fast re-auth
  151. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  152. * @priv: Pointer to private EAP method data from eap_method::init()
  153. *
  154. * This function is an optional handler that only EAP methods
  155. * supporting fast re-authentication need to implement. This is called
  156. * when authentication has been completed and EAP state machine is
  157. * requesting that enough state information is maintained for fast
  158. * re-authentication
  159. */
  160. void (*deinit_for_reauth)(struct eap_sm *sm, void *priv);
  161. /**
  162. * init_for_reauth - Prepare for start of fast re-authentication
  163. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  164. * @priv: Pointer to private EAP method data from eap_method::init()
  165. *
  166. * This function is an optional handler that only EAP methods
  167. * supporting fast re-authentication need to implement. This is called
  168. * when EAP authentication is started and EAP state machine is
  169. * requesting fast re-authentication to be used.
  170. */
  171. void * (*init_for_reauth)(struct eap_sm *sm, void *priv);
  172. /**
  173. * get_identity - Get method specific identity for re-authentication
  174. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  175. * @priv: Pointer to private EAP method data from eap_method::init()
  176. * @len: Length of the returned identity
  177. * Returns: Pointer to the method specific identity or %NULL if default
  178. * identity is to be used
  179. *
  180. * This function is an optional handler that only EAP methods
  181. * that use method specific identity need to implement.
  182. */
  183. const u8 * (*get_identity)(struct eap_sm *sm, void *priv, size_t *len);
  184. /**
  185. * free - Free EAP method data
  186. * @method: Pointer to the method data registered with
  187. * eap_peer_method_register().
  188. *
  189. * This function will be called when the EAP method is being
  190. * unregistered. If the EAP method allocated resources during
  191. * registration (e.g., allocated struct eap_method), they should be
  192. * freed in this function. No other method functions will be called
  193. * after this call. If this function is not defined (i.e., function
  194. * pointer is %NULL), a default handler is used to release the method
  195. * data with free(method). This is suitable for most cases.
  196. */
  197. void (*free)(struct eap_method *method);
  198. #define EAP_PEER_METHOD_INTERFACE_VERSION 1
  199. /**
  200. * version - Version of the EAP peer method interface
  201. *
  202. * The EAP peer method implementation should set this variable to
  203. * EAP_PEER_METHOD_INTERFACE_VERSION. This is used to verify that the
  204. * EAP method is using supported API version when using dynamically
  205. * loadable EAP methods.
  206. */
  207. int version;
  208. /**
  209. * next - Pointer to the next EAP method
  210. *
  211. * This variable is used internally in the EAP method registration code
  212. * to create a linked list of registered EAP methods.
  213. */
  214. struct eap_method *next;
  215. #ifdef CONFIG_DYNAMIC_EAP_METHODS
  216. /**
  217. * dl_handle - Handle for the dynamic library
  218. *
  219. * This variable is used internally in the EAP method registration code
  220. * to store a handle for the dynamic library. If the method is linked
  221. * in statically, this is %NULL.
  222. */
  223. void *dl_handle;
  224. #endif /* CONFIG_DYNAMIC_EAP_METHODS */
  225. /**
  226. * get_emsk - Get EAP method specific keying extended material (EMSK)
  227. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  228. * @priv: Pointer to private EAP method data from eap_method::init()
  229. * @len: Pointer to a variable to store EMSK length
  230. * Returns: EMSK or %NULL if not available
  231. *
  232. * This function can be used to get the extended keying material from
  233. * the EAP method. The key may already be stored in the method-specific
  234. * private data or this function may derive the key.
  235. */
  236. u8 * (*get_emsk)(struct eap_sm *sm, void *priv, size_t *len);
  237. /**
  238. * getSessionId - Get EAP method specific Session-Id
  239. * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
  240. * @priv: Pointer to private EAP method data from eap_method::init()
  241. * @len: Pointer to a variable to store Session-Id length
  242. * Returns: Session-Id or %NULL if not available
  243. *
  244. * This function can be used to get the Session-Id from the EAP method.
  245. * The Session-Id may already be stored in the method-specific private
  246. * data or this function may derive the Session-Id.
  247. */
  248. u8 * (*getSessionId)(struct eap_sm *sm, void *priv, size_t *len);
  249. };
  250. struct eap_erp_key {
  251. struct dl_list list;
  252. size_t rRK_len;
  253. size_t rIK_len;
  254. u8 rRK[ERP_MAX_KEY_LEN];
  255. u8 rIK[ERP_MAX_KEY_LEN];
  256. u32 next_seq;
  257. char keyname_nai[];
  258. };
  259. /**
  260. * struct eap_sm - EAP state machine data
  261. */
  262. struct eap_sm {
  263. enum {
  264. EAP_INITIALIZE, EAP_DISABLED, EAP_IDLE, EAP_RECEIVED,
  265. EAP_GET_METHOD, EAP_METHOD, EAP_SEND_RESPONSE, EAP_DISCARD,
  266. EAP_IDENTITY, EAP_NOTIFICATION, EAP_RETRANSMIT, EAP_SUCCESS,
  267. EAP_FAILURE
  268. } EAP_state;
  269. /* Long-term local variables */
  270. EapType selectedMethod;
  271. EapMethodState methodState;
  272. int lastId;
  273. struct wpabuf *lastRespData;
  274. EapDecision decision;
  275. /* Short-term local variables */
  276. Boolean rxReq;
  277. Boolean rxSuccess;
  278. Boolean rxFailure;
  279. int reqId;
  280. EapType reqMethod;
  281. int reqVendor;
  282. u32 reqVendorMethod;
  283. Boolean ignore;
  284. /* Constants */
  285. int ClientTimeout;
  286. /* Miscellaneous variables */
  287. Boolean allowNotifications; /* peer state machine <-> methods */
  288. struct wpabuf *eapRespData; /* peer to lower layer */
  289. Boolean eapKeyAvailable; /* peer to lower layer */
  290. u8 *eapKeyData; /* peer to lower layer */
  291. size_t eapKeyDataLen; /* peer to lower layer */
  292. u8 *eapSessionId; /* peer to lower layer */
  293. size_t eapSessionIdLen; /* peer to lower layer */
  294. const struct eap_method *m; /* selected EAP method */
  295. /* not defined in RFC 4137 */
  296. Boolean changed;
  297. void *eapol_ctx;
  298. const struct eapol_callbacks *eapol_cb;
  299. void *eap_method_priv;
  300. int init_phase2;
  301. int fast_reauth;
  302. Boolean reauthInit; /* send EAP-Identity/Re-auth */
  303. u32 erp_seq;
  304. Boolean rxResp /* LEAP only */;
  305. Boolean leap_done;
  306. Boolean peap_done;
  307. u8 req_sha1[20]; /* SHA1() of the current EAP packet */
  308. u8 last_sha1[20]; /* SHA1() of the previously received EAP packet; used
  309. * in duplicate request detection. */
  310. void *msg_ctx;
  311. void *scard_ctx;
  312. void *ssl_ctx;
  313. void *ssl_ctx2;
  314. unsigned int workaround;
  315. /* Optional challenges generated in Phase 1 (EAP-FAST) */
  316. u8 *peer_challenge, *auth_challenge;
  317. int num_rounds;
  318. int force_disabled;
  319. struct wps_context *wps;
  320. int prev_failure;
  321. struct eap_peer_config *last_config;
  322. struct ext_password_data *ext_pw;
  323. struct wpabuf *ext_pw_buf;
  324. int external_sim;
  325. unsigned int expected_failure:1;
  326. unsigned int ext_cert_check:1;
  327. unsigned int waiting_ext_cert_check:1;
  328. struct dl_list erp_keys; /* struct eap_erp_key */
  329. };
  330. const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len);
  331. const u8 * eap_get_config_password(struct eap_sm *sm, size_t *len);
  332. const u8 * eap_get_config_password2(struct eap_sm *sm, size_t *len, int *hash);
  333. const u8 * eap_get_config_new_password(struct eap_sm *sm, size_t *len);
  334. const u8 * eap_get_config_otp(struct eap_sm *sm, size_t *len);
  335. void eap_clear_config_otp(struct eap_sm *sm);
  336. const char * eap_get_config_phase1(struct eap_sm *sm);
  337. const char * eap_get_config_phase2(struct eap_sm *sm);
  338. int eap_get_config_fragment_size(struct eap_sm *sm);
  339. struct eap_peer_config * eap_get_config(struct eap_sm *sm);
  340. void eap_set_config_blob(struct eap_sm *sm, struct wpa_config_blob *blob);
  341. const struct wpa_config_blob *
  342. eap_get_config_blob(struct eap_sm *sm, const char *name);
  343. void eap_notify_pending(struct eap_sm *sm);
  344. int eap_allowed_method(struct eap_sm *sm, int vendor, u32 method);
  345. #endif /* EAP_I_H */