wpa_auth.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*
  2. * hostapd - IEEE 802.11i-2004 / WPA Authenticator
  3. * Copyright (c) 2004-2017, 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 WPA_AUTH_H
  9. #define WPA_AUTH_H
  10. #include "common/defs.h"
  11. #include "common/eapol_common.h"
  12. #include "common/wpa_common.h"
  13. #include "common/ieee802_11_defs.h"
  14. #define MAX_OWN_IE_OVERRIDE 256
  15. #ifdef _MSC_VER
  16. #pragma pack(push, 1)
  17. #endif /* _MSC_VER */
  18. /* IEEE Std 802.11r-2008, 11A.10.3 - Remote request/response frame definition
  19. */
  20. struct ft_rrb_frame {
  21. u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
  22. u8 packet_type; /* FT_PACKET_REQUEST/FT_PACKET_RESPONSE */
  23. le16 action_length; /* little endian length of action_frame */
  24. u8 ap_address[ETH_ALEN];
  25. /*
  26. * Followed by action_length bytes of FT Action frame (from Category
  27. * field to the end of Action Frame body.
  28. */
  29. } STRUCT_PACKED;
  30. #define RSN_REMOTE_FRAME_TYPE_FT_RRB 1
  31. #define FT_PACKET_REQUEST 0
  32. #define FT_PACKET_RESPONSE 1
  33. /* Vendor-specific types for R0KH-R1KH protocol; not defined in 802.11r. These
  34. * use OUI Extended EtherType as the encapsulating format. */
  35. #define FT_PACKET_R0KH_R1KH_PULL 0x01
  36. #define FT_PACKET_R0KH_R1KH_RESP 0x02
  37. #define FT_PACKET_R0KH_R1KH_PUSH 0x03
  38. #define FT_R0KH_R1KH_PULL_NONCE_LEN 16
  39. #define FT_R0KH_R1KH_PULL_DATA_LEN (FT_R0KH_R1KH_PULL_NONCE_LEN + \
  40. WPA_PMK_NAME_LEN + FT_R1KH_ID_LEN + \
  41. ETH_ALEN)
  42. #define FT_R0KH_R1KH_PULL_PAD_LEN ((8 - FT_R0KH_R1KH_PULL_DATA_LEN % 8) % 8)
  43. struct ft_r0kh_r1kh_pull_frame {
  44. u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN];
  45. u8 pmk_r0_name[WPA_PMK_NAME_LEN];
  46. u8 r1kh_id[FT_R1KH_ID_LEN];
  47. u8 s1kh_id[ETH_ALEN];
  48. u8 pad[FT_R0KH_R1KH_PULL_PAD_LEN]; /* 8-octet boundary for AES block */
  49. u8 key_wrap_extra[8];
  50. } STRUCT_PACKED;
  51. #define FT_R0KH_R1KH_RESP_DATA_LEN (FT_R0KH_R1KH_PULL_NONCE_LEN + \
  52. FT_R1KH_ID_LEN + ETH_ALEN + PMK_LEN + \
  53. WPA_PMK_NAME_LEN + 2)
  54. #define FT_R0KH_R1KH_RESP_PAD_LEN ((8 - FT_R0KH_R1KH_RESP_DATA_LEN % 8) % 8)
  55. struct ft_r0kh_r1kh_resp_frame {
  56. u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN]; /* copied from pull */
  57. u8 r1kh_id[FT_R1KH_ID_LEN]; /* copied from pull */
  58. u8 s1kh_id[ETH_ALEN]; /* copied from pull */
  59. u8 pmk_r1[PMK_LEN];
  60. u8 pmk_r1_name[WPA_PMK_NAME_LEN];
  61. le16 pairwise;
  62. u8 pad[FT_R0KH_R1KH_RESP_PAD_LEN]; /* 8-octet boundary for AES block */
  63. u8 key_wrap_extra[8];
  64. } STRUCT_PACKED;
  65. #define FT_R0KH_R1KH_PUSH_DATA_LEN (4 + FT_R1KH_ID_LEN + ETH_ALEN + \
  66. WPA_PMK_NAME_LEN + PMK_LEN + \
  67. WPA_PMK_NAME_LEN + 2)
  68. #define FT_R0KH_R1KH_PUSH_PAD_LEN ((8 - FT_R0KH_R1KH_PUSH_DATA_LEN % 8) % 8)
  69. struct ft_r0kh_r1kh_push_frame {
  70. /* Encrypted with AES key-wrap */
  71. u8 timestamp[4]; /* current time in seconds since unix epoch, little
  72. * endian */
  73. u8 r1kh_id[FT_R1KH_ID_LEN];
  74. u8 s1kh_id[ETH_ALEN];
  75. u8 pmk_r0_name[WPA_PMK_NAME_LEN];
  76. u8 pmk_r1[PMK_LEN];
  77. u8 pmk_r1_name[WPA_PMK_NAME_LEN];
  78. le16 pairwise;
  79. u8 pad[FT_R0KH_R1KH_PUSH_PAD_LEN]; /* 8-octet boundary for AES block */
  80. u8 key_wrap_extra[8];
  81. } STRUCT_PACKED;
  82. #ifdef _MSC_VER
  83. #pragma pack(pop)
  84. #endif /* _MSC_VER */
  85. /* per STA state machine data */
  86. struct wpa_authenticator;
  87. struct wpa_state_machine;
  88. struct rsn_pmksa_cache_entry;
  89. struct eapol_state_machine;
  90. struct ft_remote_r0kh {
  91. struct ft_remote_r0kh *next;
  92. u8 addr[ETH_ALEN];
  93. u8 id[FT_R0KH_ID_MAX_LEN];
  94. size_t id_len;
  95. u8 key[16];
  96. };
  97. struct ft_remote_r1kh {
  98. struct ft_remote_r1kh *next;
  99. u8 addr[ETH_ALEN];
  100. u8 id[FT_R1KH_ID_LEN];
  101. u8 key[16];
  102. };
  103. struct wpa_auth_config {
  104. int wpa;
  105. int wpa_key_mgmt;
  106. int wpa_pairwise;
  107. int wpa_group;
  108. int wpa_group_rekey;
  109. int wpa_strict_rekey;
  110. int wpa_gmk_rekey;
  111. int wpa_ptk_rekey;
  112. u32 wpa_group_update_count;
  113. u32 wpa_pairwise_update_count;
  114. int rsn_pairwise;
  115. int rsn_preauth;
  116. int eapol_version;
  117. int peerkey;
  118. int wmm_enabled;
  119. int wmm_uapsd;
  120. int disable_pmksa_caching;
  121. int okc;
  122. int tx_status;
  123. #ifdef CONFIG_IEEE80211W
  124. enum mfp_options ieee80211w;
  125. int group_mgmt_cipher;
  126. #endif /* CONFIG_IEEE80211W */
  127. #ifdef CONFIG_IEEE80211R_AP
  128. u8 ssid[SSID_MAX_LEN];
  129. size_t ssid_len;
  130. u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
  131. u8 r0_key_holder[FT_R0KH_ID_MAX_LEN];
  132. size_t r0_key_holder_len;
  133. u8 r1_key_holder[FT_R1KH_ID_LEN];
  134. u32 r0_key_lifetime;
  135. u32 reassociation_deadline;
  136. struct ft_remote_r0kh *r0kh_list;
  137. struct ft_remote_r1kh *r1kh_list;
  138. int pmk_r1_push;
  139. int ft_over_ds;
  140. int ft_psk_generate_local;
  141. #endif /* CONFIG_IEEE80211R_AP */
  142. int disable_gtk;
  143. int ap_mlme;
  144. #ifdef CONFIG_TESTING_OPTIONS
  145. double corrupt_gtk_rekey_mic_probability;
  146. u8 own_ie_override[MAX_OWN_IE_OVERRIDE];
  147. size_t own_ie_override_len;
  148. #endif /* CONFIG_TESTING_OPTIONS */
  149. #ifdef CONFIG_P2P
  150. u8 ip_addr_go[4];
  151. u8 ip_addr_mask[4];
  152. u8 ip_addr_start[4];
  153. u8 ip_addr_end[4];
  154. #endif /* CONFIG_P2P */
  155. #ifdef CONFIG_FILS
  156. unsigned int fils_cache_id_set:1;
  157. u8 fils_cache_id[FILS_CACHE_ID_LEN];
  158. #endif /* CONFIG_FILS */
  159. };
  160. typedef enum {
  161. LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
  162. } logger_level;
  163. typedef enum {
  164. WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
  165. WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
  166. WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
  167. } wpa_eapol_variable;
  168. struct wpa_auth_callbacks {
  169. void (*logger)(void *ctx, const u8 *addr, logger_level level,
  170. const char *txt);
  171. void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
  172. int (*mic_failure_report)(void *ctx, const u8 *addr);
  173. void (*psk_failure_report)(void *ctx, const u8 *addr);
  174. void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
  175. int value);
  176. int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
  177. const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *p2p_dev_addr,
  178. const u8 *prev_psk);
  179. int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
  180. int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
  181. const u8 *addr, int idx, u8 *key, size_t key_len);
  182. int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
  183. int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
  184. size_t data_len, int encrypt);
  185. int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
  186. void *ctx), void *cb_ctx);
  187. int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a,
  188. void *ctx), void *cb_ctx);
  189. int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data,
  190. size_t data_len);
  191. int (*send_oui)(void *ctx, const u8 *dst, u8 oui_suffix, const u8 *data,
  192. size_t data_len);
  193. #ifdef CONFIG_IEEE80211R_AP
  194. struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
  195. int (*send_ft_action)(void *ctx, const u8 *dst,
  196. const u8 *data, size_t data_len);
  197. int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
  198. size_t tspec_ielen);
  199. #endif /* CONFIG_IEEE80211R_AP */
  200. #ifdef CONFIG_MESH
  201. int (*start_ampe)(void *ctx, const u8 *sta_addr);
  202. #endif /* CONFIG_MESH */
  203. };
  204. struct wpa_authenticator * wpa_init(const u8 *addr,
  205. struct wpa_auth_config *conf,
  206. const struct wpa_auth_callbacks *cb,
  207. void *cb_ctx);
  208. int wpa_init_keys(struct wpa_authenticator *wpa_auth);
  209. void wpa_deinit(struct wpa_authenticator *wpa_auth);
  210. int wpa_reconfig(struct wpa_authenticator *wpa_auth,
  211. struct wpa_auth_config *conf);
  212. enum {
  213. WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
  214. WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
  215. WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
  216. WPA_INVALID_MDIE, WPA_INVALID_PROTO
  217. };
  218. int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
  219. struct wpa_state_machine *sm,
  220. const u8 *wpa_ie, size_t wpa_ie_len,
  221. const u8 *mdie, size_t mdie_len,
  222. const u8 *owe_dh, size_t owe_dh_len);
  223. int wpa_validate_osen(struct wpa_authenticator *wpa_auth,
  224. struct wpa_state_machine *sm,
  225. const u8 *osen_ie, size_t osen_ie_len);
  226. int wpa_auth_uses_mfp(struct wpa_state_machine *sm);
  227. struct wpa_state_machine *
  228. wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
  229. const u8 *p2p_dev_addr);
  230. int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
  231. struct wpa_state_machine *sm);
  232. void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
  233. void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
  234. void wpa_receive(struct wpa_authenticator *wpa_auth,
  235. struct wpa_state_machine *sm,
  236. u8 *data, size_t data_len);
  237. enum wpa_event {
  238. WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
  239. WPA_REAUTH_EAPOL, WPA_ASSOC_FT, WPA_ASSOC_FILS
  240. };
  241. void wpa_remove_ptk(struct wpa_state_machine *sm);
  242. int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event);
  243. void wpa_auth_sm_notify(struct wpa_state_machine *sm);
  244. void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
  245. int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
  246. int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
  247. void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
  248. int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
  249. int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
  250. int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
  251. int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
  252. int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
  253. struct rsn_pmksa_cache_entry *entry);
  254. struct rsn_pmksa_cache_entry *
  255. wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
  256. void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
  257. const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
  258. size_t *len);
  259. int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
  260. unsigned int pmk_len,
  261. int session_timeout, struct eapol_state_machine *eapol);
  262. int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
  263. const u8 *pmk, size_t len, const u8 *sta_addr,
  264. int session_timeout,
  265. struct eapol_state_machine *eapol);
  266. int wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
  267. const u8 *pmk, const u8 *pmkid);
  268. void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
  269. const u8 *sta_addr);
  270. int wpa_auth_pmksa_list(struct wpa_authenticator *wpa_auth, char *buf,
  271. size_t len);
  272. void wpa_auth_pmksa_flush(struct wpa_authenticator *wpa_auth);
  273. int wpa_auth_pmksa_list_mesh(struct wpa_authenticator *wpa_auth, const u8 *addr,
  274. char *buf, size_t len);
  275. struct rsn_pmksa_cache_entry *
  276. wpa_auth_pmksa_create_entry(const u8 *aa, const u8 *spa, const u8 *pmk,
  277. const u8 *pmkid, int expiration);
  278. int wpa_auth_pmksa_add_entry(struct wpa_authenticator *wpa_auth,
  279. struct rsn_pmksa_cache_entry *entry);
  280. struct rsn_pmksa_cache_entry *
  281. wpa_auth_pmksa_get(struct wpa_authenticator *wpa_auth, const u8 *sta_addr,
  282. const u8 *pmkid);
  283. struct rsn_pmksa_cache_entry *
  284. wpa_auth_pmksa_get_fils_cache_id(struct wpa_authenticator *wpa_auth,
  285. const u8 *sta_addr, const u8 *pmkid);
  286. void wpa_auth_pmksa_set_to_sm(struct rsn_pmksa_cache_entry *pmksa,
  287. struct wpa_state_machine *sm,
  288. struct wpa_authenticator *wpa_auth,
  289. u8 *pmkid, u8 *pmk);
  290. int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
  291. void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
  292. struct wpa_state_machine *sm, int ack);
  293. #ifdef CONFIG_IEEE80211R_AP
  294. u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
  295. size_t max_len, int auth_alg,
  296. const u8 *req_ies, size_t req_ies_len);
  297. void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
  298. u16 auth_transaction, const u8 *ies, size_t ies_len,
  299. void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
  300. u16 auth_transaction, u16 resp,
  301. const u8 *ies, size_t ies_len),
  302. void *ctx);
  303. u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
  304. size_t ies_len);
  305. int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
  306. int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
  307. const u8 *data, size_t data_len);
  308. void wpa_ft_rrb_oui_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
  309. const u8 *dst_addr, u8 oui_suffix, const u8 *data,
  310. size_t data_len);
  311. void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
  312. #endif /* CONFIG_IEEE80211R_AP */
  313. void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm);
  314. void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag);
  315. int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos);
  316. int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos);
  317. int wpa_auth_uses_sae(struct wpa_state_machine *sm);
  318. int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm);
  319. int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr);
  320. struct radius_das_attrs;
  321. int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
  322. struct radius_das_attrs *attr);
  323. void wpa_auth_reconfig_group_keys(struct wpa_authenticator *wpa_auth);
  324. int wpa_auth_ensure_group(struct wpa_authenticator *wpa_auth, int vlan_id);
  325. int wpa_auth_release_group(struct wpa_authenticator *wpa_auth, int vlan_id);
  326. int fils_auth_pmk_to_ptk(struct wpa_state_machine *sm, const u8 *pmk,
  327. size_t pmk_len, const u8 *snonce, const u8 *anonce);
  328. int fils_decrypt_assoc(struct wpa_state_machine *sm, const u8 *fils_session,
  329. const struct ieee80211_mgmt *mgmt, size_t frame_len,
  330. u8 *pos, size_t left);
  331. int fils_encrypt_assoc(struct wpa_state_machine *sm, u8 *buf,
  332. size_t current_len, size_t max_len,
  333. const struct wpabuf *hlp);
  334. int fils_set_tk(struct wpa_state_machine *sm);
  335. u8 * hostapd_eid_assoc_fils_session(struct wpa_state_machine *sm, u8 *eid,
  336. const u8 *fils_session);
  337. const u8 * wpa_fils_validate_fils_session(struct wpa_state_machine *sm,
  338. const u8 *ies, size_t ies_len,
  339. const u8 *fils_session);
  340. int wpa_fils_validate_key_confirm(struct wpa_state_machine *sm, const u8 *ies,
  341. size_t ies_len);
  342. int wpa_auth_write_fte(struct wpa_authenticator *wpa_auth, u8 *buf, size_t len);
  343. void wpa_auth_get_fils_aead_params(struct wpa_state_machine *sm,
  344. u8 *fils_anonce, u8 *fils_snonce,
  345. u8 *fils_kek, size_t *fils_kek_len);
  346. #endif /* WPA_AUTH_H */