eap_i.h 12 KB

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