139beb93cSSam Leffler /* 239beb93cSSam Leffler * hostapd / EAP Full Authenticator state machine (RFC 4137) 35b9c547cSRui Paulo * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi> 439beb93cSSam Leffler * 5f05cddf9SRui Paulo * This software may be distributed under the terms of the BSD license. 6f05cddf9SRui Paulo * See README for more details. 739beb93cSSam Leffler */ 839beb93cSSam Leffler 939beb93cSSam Leffler #ifndef EAP_H 1039beb93cSSam Leffler #define EAP_H 1139beb93cSSam Leffler 12e28a4053SRui Paulo #include "common/defs.h" 135b9c547cSRui Paulo #include "utils/list.h" 1439beb93cSSam Leffler #include "eap_common/eap_defs.h" 1539beb93cSSam Leffler #include "eap_server/eap_methods.h" 1639beb93cSSam Leffler #include "wpabuf.h" 1739beb93cSSam Leffler 1839beb93cSSam Leffler struct eap_sm; 1939beb93cSSam Leffler 2039beb93cSSam Leffler #define EAP_TTLS_AUTH_PAP 1 2139beb93cSSam Leffler #define EAP_TTLS_AUTH_CHAP 2 2239beb93cSSam Leffler #define EAP_TTLS_AUTH_MSCHAP 4 2339beb93cSSam Leffler #define EAP_TTLS_AUTH_MSCHAPV2 8 2439beb93cSSam Leffler 2539beb93cSSam Leffler struct eap_user { 2639beb93cSSam Leffler struct { 2739beb93cSSam Leffler int vendor; 2839beb93cSSam Leffler u32 method; 2939beb93cSSam Leffler } methods[EAP_MAX_METHODS]; 3039beb93cSSam Leffler u8 *password; 3139beb93cSSam Leffler size_t password_len; 3239beb93cSSam Leffler int password_hash; /* whether password is hashed with 3339beb93cSSam Leffler * nt_password_hash() */ 3485732ac8SCy Schubert u8 *salt; 3585732ac8SCy Schubert size_t salt_len; 3639beb93cSSam Leffler int phase2; 3739beb93cSSam Leffler int force_version; 385b9c547cSRui Paulo unsigned int remediation:1; 395b9c547cSRui Paulo unsigned int macacl:1; 4039beb93cSSam Leffler int ttls_auth; /* bitfield of 4139beb93cSSam Leffler * EAP_TTLS_AUTH_{PAP,CHAP,MSCHAP,MSCHAPV2} */ 425b9c547cSRui Paulo struct hostapd_radius_attr *accept_attr; 4385732ac8SCy Schubert u32 t_c_timestamp; 4439beb93cSSam Leffler }; 4539beb93cSSam Leffler 4639beb93cSSam Leffler struct eap_eapol_interface { 4739beb93cSSam Leffler /* Lower layer to full authenticator variables */ 48c1d255d3SCy Schubert bool eapResp; /* shared with EAPOL Backend Authentication */ 4939beb93cSSam Leffler struct wpabuf *eapRespData; 50c1d255d3SCy Schubert bool portEnabled; 5139beb93cSSam Leffler int retransWhile; 52c1d255d3SCy Schubert bool eapRestart; /* shared with EAPOL Authenticator PAE */ 5339beb93cSSam Leffler int eapSRTT; 5439beb93cSSam Leffler int eapRTTVAR; 5539beb93cSSam Leffler 5639beb93cSSam Leffler /* Full authenticator to lower layer variables */ 57c1d255d3SCy Schubert bool eapReq; /* shared with EAPOL Backend Authentication */ 58c1d255d3SCy Schubert bool eapNoReq; /* shared with EAPOL Backend Authentication */ 59c1d255d3SCy Schubert bool eapSuccess; 60c1d255d3SCy Schubert bool eapFail; 61c1d255d3SCy Schubert bool eapTimeout; 6239beb93cSSam Leffler struct wpabuf *eapReqData; 6339beb93cSSam Leffler u8 *eapKeyData; 6439beb93cSSam Leffler size_t eapKeyDataLen; 655b9c547cSRui Paulo u8 *eapSessionId; 665b9c547cSRui Paulo size_t eapSessionIdLen; 67c1d255d3SCy Schubert bool eapKeyAvailable; /* called keyAvailable in IEEE 802.1X-2004 */ 6839beb93cSSam Leffler 6939beb93cSSam Leffler /* AAA interface to full authenticator variables */ 70c1d255d3SCy Schubert bool aaaEapReq; 71c1d255d3SCy Schubert bool aaaEapNoReq; 72c1d255d3SCy Schubert bool aaaSuccess; 73c1d255d3SCy Schubert bool aaaFail; 7439beb93cSSam Leffler struct wpabuf *aaaEapReqData; 7539beb93cSSam Leffler u8 *aaaEapKeyData; 7639beb93cSSam Leffler size_t aaaEapKeyDataLen; 77c1d255d3SCy Schubert bool aaaEapKeyAvailable; 7839beb93cSSam Leffler int aaaMethodTimeout; 7939beb93cSSam Leffler 8039beb93cSSam Leffler /* Full authenticator to AAA interface variables */ 81c1d255d3SCy Schubert bool aaaEapResp; 8239beb93cSSam Leffler struct wpabuf *aaaEapRespData; 8339beb93cSSam Leffler /* aaaIdentity -> eap_get_identity() */ 84c1d255d3SCy Schubert bool aaaTimeout; 8539beb93cSSam Leffler }; 8639beb93cSSam Leffler 875b9c547cSRui Paulo struct eap_server_erp_key { 885b9c547cSRui Paulo struct dl_list list; 895b9c547cSRui Paulo size_t rRK_len; 905b9c547cSRui Paulo size_t rIK_len; 915b9c547cSRui Paulo u8 rRK[ERP_MAX_KEY_LEN]; 925b9c547cSRui Paulo u8 rIK[ERP_MAX_KEY_LEN]; 935b9c547cSRui Paulo u32 recv_seq; 945b9c547cSRui Paulo u8 cryptosuite; 955b9c547cSRui Paulo char keyname_nai[]; 965b9c547cSRui Paulo }; 975b9c547cSRui Paulo 9839beb93cSSam Leffler struct eapol_callbacks { 9939beb93cSSam Leffler int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len, 10039beb93cSSam Leffler int phase2, struct eap_user *user); 10139beb93cSSam Leffler const char * (*get_eap_req_id_text)(void *ctx, size_t *len); 1025b9c547cSRui Paulo void (*log_msg)(void *ctx, const char *msg); 1035b9c547cSRui Paulo int (*get_erp_send_reauth_start)(void *ctx); 1045b9c547cSRui Paulo const char * (*get_erp_domain)(void *ctx); 1055b9c547cSRui Paulo struct eap_server_erp_key * (*erp_get_key)(void *ctx, 1065b9c547cSRui Paulo const char *keyname); 1075b9c547cSRui Paulo int (*erp_add_key)(void *ctx, struct eap_server_erp_key *erp); 10839beb93cSSam Leffler }; 10939beb93cSSam Leffler 11039beb93cSSam Leffler struct eap_config { 111c1d255d3SCy Schubert /** 112c1d255d3SCy Schubert * ssl_ctx - TLS context 113c1d255d3SCy Schubert * 114c1d255d3SCy Schubert * This is passed to the EAP server implementation as a callback 115c1d255d3SCy Schubert * context for TLS operations. 116c1d255d3SCy Schubert */ 11739beb93cSSam Leffler void *ssl_ctx; 118e28a4053SRui Paulo void *msg_ctx; 119c1d255d3SCy Schubert 120c1d255d3SCy Schubert /** 121c1d255d3SCy Schubert * eap_sim_db_priv - EAP-SIM/AKA database context 122c1d255d3SCy Schubert * 123c1d255d3SCy Schubert * This is passed to the EAP-SIM/AKA server implementation as a 124c1d255d3SCy Schubert * callback context. 125c1d255d3SCy Schubert */ 12639beb93cSSam Leffler void *eap_sim_db_priv; 127*a90b9d01SCy Schubert 128*a90b9d01SCy Schubert struct crypto_rsa_key *imsi_privacy_key; 129*a90b9d01SCy Schubert 130c1d255d3SCy Schubert bool backend_auth; 13139beb93cSSam Leffler int eap_server; 132c1d255d3SCy Schubert 133c1d255d3SCy Schubert /** 134c1d255d3SCy Schubert * pwd_group - The D-H group assigned for EAP-pwd 135c1d255d3SCy Schubert * 136c1d255d3SCy Schubert * If EAP-pwd is not used it can be set to zero. 137c1d255d3SCy Schubert */ 138f05cddf9SRui Paulo u16 pwd_group; 139c1d255d3SCy Schubert 140c1d255d3SCy Schubert /** 141c1d255d3SCy Schubert * pac_opaque_encr_key - PAC-Opaque encryption key for EAP-FAST 142c1d255d3SCy Schubert * 143c1d255d3SCy Schubert * This parameter is used to set a key for EAP-FAST to encrypt the 144c1d255d3SCy Schubert * PAC-Opaque data. It can be set to %NULL if EAP-FAST is not used. If 145c1d255d3SCy Schubert * set, must point to a 16-octet key. 146c1d255d3SCy Schubert */ 14739beb93cSSam Leffler u8 *pac_opaque_encr_key; 148c1d255d3SCy Schubert 149c1d255d3SCy Schubert /** 150c1d255d3SCy Schubert * eap_fast_a_id - EAP-FAST authority identity (A-ID) 151c1d255d3SCy Schubert * 152c1d255d3SCy Schubert * If EAP-FAST is not used, this can be set to %NULL. In theory, this 153c1d255d3SCy Schubert * is a variable length field, but due to some existing implementations 154c1d255d3SCy Schubert * requiring A-ID to be 16 octets in length, it is recommended to use 155c1d255d3SCy Schubert * that length for the field to provide interoperability with deployed 156c1d255d3SCy Schubert * peer implementations. 157c1d255d3SCy Schubert */ 15839beb93cSSam Leffler u8 *eap_fast_a_id; 159c1d255d3SCy Schubert 160c1d255d3SCy Schubert /** 161c1d255d3SCy Schubert * eap_fast_a_id_len - Length of eap_fast_a_id buffer in octets 162c1d255d3SCy Schubert */ 16339beb93cSSam Leffler size_t eap_fast_a_id_len; 164c1d255d3SCy Schubert /** 165c1d255d3SCy Schubert * eap_fast_a_id_info - EAP-FAST authority identifier information 166c1d255d3SCy Schubert * 167c1d255d3SCy Schubert * This A-ID-Info contains a user-friendly name for the A-ID. For 168c1d255d3SCy Schubert * example, this could be the enterprise and server names in 169c1d255d3SCy Schubert * human-readable format. This field is encoded as UTF-8. If EAP-FAST 170c1d255d3SCy Schubert * is not used, this can be set to %NULL. 171c1d255d3SCy Schubert */ 17239beb93cSSam Leffler char *eap_fast_a_id_info; 173c1d255d3SCy Schubert 174c1d255d3SCy Schubert /** 175c1d255d3SCy Schubert * eap_fast_prov - EAP-FAST provisioning modes 176c1d255d3SCy Schubert * 177c1d255d3SCy Schubert * 0 = provisioning disabled, 1 = only anonymous provisioning allowed, 178c1d255d3SCy Schubert * 2 = only authenticated provisioning allowed, 3 = both provisioning 179c1d255d3SCy Schubert * modes allowed. 180c1d255d3SCy Schubert */ 181c1d255d3SCy Schubert enum { 182c1d255d3SCy Schubert NO_PROV, ANON_PROV, AUTH_PROV, BOTH_PROV 183c1d255d3SCy Schubert } eap_fast_prov; 184c1d255d3SCy Schubert 185c1d255d3SCy Schubert /** 186c1d255d3SCy Schubert * pac_key_lifetime - EAP-FAST PAC-Key lifetime in seconds 187c1d255d3SCy Schubert * 188c1d255d3SCy Schubert * This is the hard limit on how long a provisioned PAC-Key can be 189c1d255d3SCy Schubert * used. 190c1d255d3SCy Schubert */ 19139beb93cSSam Leffler int pac_key_lifetime; 192c1d255d3SCy Schubert 193c1d255d3SCy Schubert /** 194c1d255d3SCy Schubert * pac_key_refresh_time - EAP-FAST PAC-Key refresh time in seconds 195c1d255d3SCy Schubert * 196c1d255d3SCy Schubert * This is a soft limit on the PAC-Key. The server will automatically 197c1d255d3SCy Schubert * generate a new PAC-Key when this number of seconds (or fewer) of the 198c1d255d3SCy Schubert * lifetime remains. 199c1d255d3SCy Schubert */ 20039beb93cSSam Leffler int pac_key_refresh_time; 201206b73d0SCy Schubert int eap_teap_auth; 202206b73d0SCy Schubert int eap_teap_pac_no_inner; 203c1d255d3SCy Schubert int eap_teap_separate_result; 204c1d255d3SCy Schubert enum eap_teap_id { 205c1d255d3SCy Schubert EAP_TEAP_ID_ALLOW_ANY = 0, 206c1d255d3SCy Schubert EAP_TEAP_ID_REQUIRE_USER = 1, 207c1d255d3SCy Schubert EAP_TEAP_ID_REQUIRE_MACHINE = 2, 208c1d255d3SCy Schubert EAP_TEAP_ID_REQUEST_USER_ACCEPT_MACHINE = 3, 209c1d255d3SCy Schubert EAP_TEAP_ID_REQUEST_MACHINE_ACCEPT_USER = 4, 210c1d255d3SCy Schubert EAP_TEAP_ID_REQUIRE_USER_AND_MACHINE = 5, 211c1d255d3SCy Schubert } eap_teap_id; 212*a90b9d01SCy Schubert int eap_teap_method_sequence; 213c1d255d3SCy Schubert 214c1d255d3SCy Schubert /** 215c1d255d3SCy Schubert * eap_sim_aka_result_ind - EAP-SIM/AKA protected success indication 216c1d255d3SCy Schubert * 217c1d255d3SCy Schubert * This controls whether the protected success/failure indication 218c1d255d3SCy Schubert * (AT_RESULT_IND) is used with EAP-SIM and EAP-AKA. 219c1d255d3SCy Schubert */ 22039beb93cSSam Leffler int eap_sim_aka_result_ind; 221206b73d0SCy Schubert int eap_sim_id; 222c1d255d3SCy Schubert 223*a90b9d01SCy Schubert /* Maximum number of fast re-authentications allowed after each full 224*a90b9d01SCy Schubert * EAP-SIM/AKA authentication. */ 225*a90b9d01SCy Schubert int eap_sim_aka_fast_reauth_limit; 226*a90b9d01SCy Schubert 227c1d255d3SCy Schubert /** 228c1d255d3SCy Schubert * tnc - Trusted Network Connect (TNC) 229c1d255d3SCy Schubert * 230c1d255d3SCy Schubert * This controls whether TNC is enabled and will be required before the 231c1d255d3SCy Schubert * peer is allowed to connect. Note: This is only used with EAP-TTLS 232c1d255d3SCy Schubert * and EAP-FAST. If any other EAP method is enabled, the peer will be 233c1d255d3SCy Schubert * allowed to connect without TNC. 234c1d255d3SCy Schubert */ 23539beb93cSSam Leffler int tnc; 236c1d255d3SCy Schubert 237c1d255d3SCy Schubert /** 238c1d255d3SCy Schubert * wps - Wi-Fi Protected Setup context 239c1d255d3SCy Schubert * 240c1d255d3SCy Schubert * If WPS is used with an external RADIUS server (which is quite 241c1d255d3SCy Schubert * unlikely configuration), this is used to provide a pointer to WPS 242c1d255d3SCy Schubert * context data. Normally, this can be set to %NULL. 243c1d255d3SCy Schubert */ 24439beb93cSSam Leffler struct wps_context *wps; 245f05cddf9SRui Paulo int fragment_size; 246f05cddf9SRui Paulo 247f05cddf9SRui Paulo int pbc_in_m1; 2485b9c547cSRui Paulo 249c1d255d3SCy Schubert /** 250c1d255d3SCy Schubert * server_id - Server identity 251c1d255d3SCy Schubert */ 252c1d255d3SCy Schubert u8 *server_id; 2535b9c547cSRui Paulo size_t server_id_len; 254c1d255d3SCy Schubert 255c1d255d3SCy Schubert /** 256c1d255d3SCy Schubert * erp - Whether EAP Re-authentication Protocol (ERP) is enabled 257c1d255d3SCy Schubert * 258c1d255d3SCy Schubert * This controls whether the authentication server derives ERP key 259c1d255d3SCy Schubert * hierarchy (rRK and rIK) from full EAP authentication and allows 260c1d255d3SCy Schubert * these keys to be used to perform ERP to derive rMSK instead of full 261c1d255d3SCy Schubert * EAP authentication to derive MSK. 262c1d255d3SCy Schubert */ 2635b9c547cSRui Paulo int erp; 264325151a3SRui Paulo unsigned int tls_session_lifetime; 26585732ac8SCy Schubert unsigned int tls_flags; 2665b9c547cSRui Paulo 267c1d255d3SCy Schubert unsigned int max_auth_rounds; 268c1d255d3SCy Schubert unsigned int max_auth_rounds_short; 269*a90b9d01SCy Schubert 270*a90b9d01SCy Schubert #ifdef CONFIG_TESTING_OPTIONS 271*a90b9d01SCy Schubert bool skip_prot_success; 272*a90b9d01SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */ 273c1d255d3SCy Schubert }; 274c1d255d3SCy Schubert 275c1d255d3SCy Schubert struct eap_session_data { 276c1d255d3SCy Schubert const struct wpabuf *assoc_wps_ie; 277c1d255d3SCy Schubert const struct wpabuf *assoc_p2p_ie; 278c1d255d3SCy Schubert const u8 *peer_addr; 2795b9c547cSRui Paulo #ifdef CONFIG_TESTING_OPTIONS 2805b9c547cSRui Paulo u32 tls_test_flags; 2815b9c547cSRui Paulo #endif /* CONFIG_TESTING_OPTIONS */ 28239beb93cSSam Leffler }; 28339beb93cSSam Leffler 28439beb93cSSam Leffler 28539beb93cSSam Leffler struct eap_sm * eap_server_sm_init(void *eapol_ctx, 286325151a3SRui Paulo const struct eapol_callbacks *eapol_cb, 287c1d255d3SCy Schubert const struct eap_config *conf, 288c1d255d3SCy Schubert const struct eap_session_data *sess); 28939beb93cSSam Leffler void eap_server_sm_deinit(struct eap_sm *sm); 29039beb93cSSam Leffler int eap_server_sm_step(struct eap_sm *sm); 29139beb93cSSam Leffler void eap_sm_notify_cached(struct eap_sm *sm); 29239beb93cSSam Leffler void eap_sm_pending_cb(struct eap_sm *sm); 29339beb93cSSam Leffler int eap_sm_method_pending(struct eap_sm *sm); 29439beb93cSSam Leffler const u8 * eap_get_identity(struct eap_sm *sm, size_t *len); 29585732ac8SCy Schubert const char * eap_get_serial_num(struct eap_sm *sm); 2964bc52338SCy Schubert const char * eap_get_method(struct eap_sm *sm); 2974bc52338SCy Schubert const char * eap_get_imsi(struct eap_sm *sm); 29839beb93cSSam Leffler struct eap_eapol_interface * eap_get_interface(struct eap_sm *sm); 299f05cddf9SRui Paulo void eap_server_clear_identity(struct eap_sm *sm); 300325151a3SRui Paulo void eap_server_mschap_rx_callback(struct eap_sm *sm, const char *source, 301325151a3SRui Paulo const u8 *username, size_t username_len, 302325151a3SRui Paulo const u8 *challenge, const u8 *response); 30385732ac8SCy Schubert void eap_erp_update_identity(struct eap_sm *sm, const u8 *eap, size_t len); 3044bc52338SCy Schubert void eap_user_free(struct eap_user *user); 305c1d255d3SCy Schubert void eap_server_config_free(struct eap_config *cfg); 30639beb93cSSam Leffler 30739beb93cSSam Leffler #endif /* EAP_H */ 308