18dbcf02cSchristos /* 28dbcf02cSchristos * hostapd / EAP Full Authenticator state machine (RFC 4137) 3bb610346Schristos * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi> 48dbcf02cSchristos * 5e604d861Schristos * This software may be distributed under the terms of the BSD license. 6e604d861Schristos * See README for more details. 78dbcf02cSchristos */ 88dbcf02cSchristos 98dbcf02cSchristos #ifndef EAP_H 108dbcf02cSchristos #define EAP_H 118dbcf02cSchristos 128dbcf02cSchristos #include "common/defs.h" 13bb610346Schristos #include "utils/list.h" 148dbcf02cSchristos #include "eap_common/eap_defs.h" 158dbcf02cSchristos #include "eap_server/eap_methods.h" 168dbcf02cSchristos #include "wpabuf.h" 178dbcf02cSchristos 188dbcf02cSchristos struct eap_sm; 198dbcf02cSchristos 208dbcf02cSchristos #define EAP_TTLS_AUTH_PAP 1 218dbcf02cSchristos #define EAP_TTLS_AUTH_CHAP 2 228dbcf02cSchristos #define EAP_TTLS_AUTH_MSCHAP 4 238dbcf02cSchristos #define EAP_TTLS_AUTH_MSCHAPV2 8 248dbcf02cSchristos 258dbcf02cSchristos struct eap_user { 268dbcf02cSchristos struct { 278dbcf02cSchristos int vendor; 288dbcf02cSchristos u32 method; 298dbcf02cSchristos } methods[EAP_MAX_METHODS]; 308dbcf02cSchristos u8 *password; 318dbcf02cSchristos size_t password_len; 328dbcf02cSchristos int password_hash; /* whether password is hashed with 338dbcf02cSchristos * nt_password_hash() */ 340a73ee0aSchristos u8 *salt; 350a73ee0aSchristos size_t salt_len; 368dbcf02cSchristos int phase2; 378dbcf02cSchristos int force_version; 383c260e60Schristos unsigned int remediation:1; 393c260e60Schristos unsigned int macacl:1; 408dbcf02cSchristos int ttls_auth; /* bitfield of 418dbcf02cSchristos * EAP_TTLS_AUTH_{PAP,CHAP,MSCHAP,MSCHAPV2} */ 423c260e60Schristos struct hostapd_radius_attr *accept_attr; 430a73ee0aSchristos u32 t_c_timestamp; 448dbcf02cSchristos }; 458dbcf02cSchristos 468dbcf02cSchristos struct eap_eapol_interface { 478dbcf02cSchristos /* Lower layer to full authenticator variables */ 48*bb618362Schristos bool eapResp; /* shared with EAPOL Backend Authentication */ 498dbcf02cSchristos struct wpabuf *eapRespData; 50*bb618362Schristos bool portEnabled; 518dbcf02cSchristos int retransWhile; 52*bb618362Schristos bool eapRestart; /* shared with EAPOL Authenticator PAE */ 538dbcf02cSchristos int eapSRTT; 548dbcf02cSchristos int eapRTTVAR; 558dbcf02cSchristos 568dbcf02cSchristos /* Full authenticator to lower layer variables */ 57*bb618362Schristos bool eapReq; /* shared with EAPOL Backend Authentication */ 58*bb618362Schristos bool eapNoReq; /* shared with EAPOL Backend Authentication */ 59*bb618362Schristos bool eapSuccess; 60*bb618362Schristos bool eapFail; 61*bb618362Schristos bool eapTimeout; 628dbcf02cSchristos struct wpabuf *eapReqData; 638dbcf02cSchristos u8 *eapKeyData; 648dbcf02cSchristos size_t eapKeyDataLen; 65bb610346Schristos u8 *eapSessionId; 66bb610346Schristos size_t eapSessionIdLen; 67*bb618362Schristos bool eapKeyAvailable; /* called keyAvailable in IEEE 802.1X-2004 */ 688dbcf02cSchristos 698dbcf02cSchristos /* AAA interface to full authenticator variables */ 70*bb618362Schristos bool aaaEapReq; 71*bb618362Schristos bool aaaEapNoReq; 72*bb618362Schristos bool aaaSuccess; 73*bb618362Schristos bool aaaFail; 748dbcf02cSchristos struct wpabuf *aaaEapReqData; 758dbcf02cSchristos u8 *aaaEapKeyData; 768dbcf02cSchristos size_t aaaEapKeyDataLen; 77*bb618362Schristos bool aaaEapKeyAvailable; 788dbcf02cSchristos int aaaMethodTimeout; 798dbcf02cSchristos 808dbcf02cSchristos /* Full authenticator to AAA interface variables */ 81*bb618362Schristos bool aaaEapResp; 828dbcf02cSchristos struct wpabuf *aaaEapRespData; 838dbcf02cSchristos /* aaaIdentity -> eap_get_identity() */ 84*bb618362Schristos bool aaaTimeout; 858dbcf02cSchristos }; 868dbcf02cSchristos 87bb610346Schristos struct eap_server_erp_key { 88bb610346Schristos struct dl_list list; 89bb610346Schristos size_t rRK_len; 90bb610346Schristos size_t rIK_len; 91bb610346Schristos u8 rRK[ERP_MAX_KEY_LEN]; 92bb610346Schristos u8 rIK[ERP_MAX_KEY_LEN]; 93bb610346Schristos u32 recv_seq; 94bb610346Schristos u8 cryptosuite; 95bb610346Schristos char keyname_nai[]; 96bb610346Schristos }; 97bb610346Schristos 988dbcf02cSchristos struct eapol_callbacks { 998dbcf02cSchristos int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len, 1008dbcf02cSchristos int phase2, struct eap_user *user); 1018dbcf02cSchristos const char * (*get_eap_req_id_text)(void *ctx, size_t *len); 1023c260e60Schristos void (*log_msg)(void *ctx, const char *msg); 103bb610346Schristos int (*get_erp_send_reauth_start)(void *ctx); 104bb610346Schristos const char * (*get_erp_domain)(void *ctx); 105bb610346Schristos struct eap_server_erp_key * (*erp_get_key)(void *ctx, 106bb610346Schristos const char *keyname); 107bb610346Schristos int (*erp_add_key)(void *ctx, struct eap_server_erp_key *erp); 1088dbcf02cSchristos }; 1098dbcf02cSchristos 1108dbcf02cSchristos struct eap_config { 111*bb618362Schristos /** 112*bb618362Schristos * ssl_ctx - TLS context 113*bb618362Schristos * 114*bb618362Schristos * This is passed to the EAP server implementation as a callback 115*bb618362Schristos * context for TLS operations. 116*bb618362Schristos */ 1178dbcf02cSchristos void *ssl_ctx; 1188dbcf02cSchristos void *msg_ctx; 119*bb618362Schristos 120*bb618362Schristos /** 121*bb618362Schristos * eap_sim_db_priv - EAP-SIM/AKA database context 122*bb618362Schristos * 123*bb618362Schristos * This is passed to the EAP-SIM/AKA server implementation as a 124*bb618362Schristos * callback context. 125*bb618362Schristos */ 1268dbcf02cSchristos void *eap_sim_db_priv; 127*bb618362Schristos 128*bb618362Schristos struct crypto_rsa_key *imsi_privacy_key; 129*bb618362Schristos 130*bb618362Schristos bool backend_auth; 1318dbcf02cSchristos int eap_server; 132*bb618362Schristos 133*bb618362Schristos /** 134*bb618362Schristos * pwd_group - The D-H group assigned for EAP-pwd 135*bb618362Schristos * 136*bb618362Schristos * If EAP-pwd is not used it can be set to zero. 137*bb618362Schristos */ 138111b9fd8Schristos u16 pwd_group; 139*bb618362Schristos 140*bb618362Schristos /** 141*bb618362Schristos * pac_opaque_encr_key - PAC-Opaque encryption key for EAP-FAST 142*bb618362Schristos * 143*bb618362Schristos * This parameter is used to set a key for EAP-FAST to encrypt the 144*bb618362Schristos * PAC-Opaque data. It can be set to %NULL if EAP-FAST is not used. If 145*bb618362Schristos * set, must point to a 16-octet key. 146*bb618362Schristos */ 1478dbcf02cSchristos u8 *pac_opaque_encr_key; 148*bb618362Schristos 149*bb618362Schristos /** 150*bb618362Schristos * eap_fast_a_id - EAP-FAST authority identity (A-ID) 151*bb618362Schristos * 152*bb618362Schristos * If EAP-FAST is not used, this can be set to %NULL. In theory, this 153*bb618362Schristos * is a variable length field, but due to some existing implementations 154*bb618362Schristos * requiring A-ID to be 16 octets in length, it is recommended to use 155*bb618362Schristos * that length for the field to provide interoperability with deployed 156*bb618362Schristos * peer implementations. 157*bb618362Schristos */ 1588dbcf02cSchristos u8 *eap_fast_a_id; 159*bb618362Schristos 160*bb618362Schristos /** 161*bb618362Schristos * eap_fast_a_id_len - Length of eap_fast_a_id buffer in octets 162*bb618362Schristos */ 1638dbcf02cSchristos size_t eap_fast_a_id_len; 164*bb618362Schristos /** 165*bb618362Schristos * eap_fast_a_id_info - EAP-FAST authority identifier information 166*bb618362Schristos * 167*bb618362Schristos * This A-ID-Info contains a user-friendly name for the A-ID. For 168*bb618362Schristos * example, this could be the enterprise and server names in 169*bb618362Schristos * human-readable format. This field is encoded as UTF-8. If EAP-FAST 170*bb618362Schristos * is not used, this can be set to %NULL. 171*bb618362Schristos */ 1728dbcf02cSchristos char *eap_fast_a_id_info; 173*bb618362Schristos 174*bb618362Schristos /** 175*bb618362Schristos * eap_fast_prov - EAP-FAST provisioning modes 176*bb618362Schristos * 177*bb618362Schristos * 0 = provisioning disabled, 1 = only anonymous provisioning allowed, 178*bb618362Schristos * 2 = only authenticated provisioning allowed, 3 = both provisioning 179*bb618362Schristos * modes allowed. 180*bb618362Schristos */ 181*bb618362Schristos enum { 182*bb618362Schristos NO_PROV, ANON_PROV, AUTH_PROV, BOTH_PROV 183*bb618362Schristos } eap_fast_prov; 184*bb618362Schristos 185*bb618362Schristos /** 186*bb618362Schristos * pac_key_lifetime - EAP-FAST PAC-Key lifetime in seconds 187*bb618362Schristos * 188*bb618362Schristos * This is the hard limit on how long a provisioned PAC-Key can be 189*bb618362Schristos * used. 190*bb618362Schristos */ 1918dbcf02cSchristos int pac_key_lifetime; 192*bb618362Schristos 193*bb618362Schristos /** 194*bb618362Schristos * pac_key_refresh_time - EAP-FAST PAC-Key refresh time in seconds 195*bb618362Schristos * 196*bb618362Schristos * This is a soft limit on the PAC-Key. The server will automatically 197*bb618362Schristos * generate a new PAC-Key when this number of seconds (or fewer) of the 198*bb618362Schristos * lifetime remains. 199*bb618362Schristos */ 2008dbcf02cSchristos int pac_key_refresh_time; 2013d6c0713Schristos int eap_teap_auth; 2023d6c0713Schristos int eap_teap_pac_no_inner; 203*bb618362Schristos int eap_teap_separate_result; 204*bb618362Schristos enum eap_teap_id { 205*bb618362Schristos EAP_TEAP_ID_ALLOW_ANY = 0, 206*bb618362Schristos EAP_TEAP_ID_REQUIRE_USER = 1, 207*bb618362Schristos EAP_TEAP_ID_REQUIRE_MACHINE = 2, 208*bb618362Schristos EAP_TEAP_ID_REQUEST_USER_ACCEPT_MACHINE = 3, 209*bb618362Schristos EAP_TEAP_ID_REQUEST_MACHINE_ACCEPT_USER = 4, 210*bb618362Schristos EAP_TEAP_ID_REQUIRE_USER_AND_MACHINE = 5, 211*bb618362Schristos } eap_teap_id; 212*bb618362Schristos int eap_teap_method_sequence; 213*bb618362Schristos 214*bb618362Schristos /** 215*bb618362Schristos * eap_sim_aka_result_ind - EAP-SIM/AKA protected success indication 216*bb618362Schristos * 217*bb618362Schristos * This controls whether the protected success/failure indication 218*bb618362Schristos * (AT_RESULT_IND) is used with EAP-SIM and EAP-AKA. 219*bb618362Schristos */ 2208dbcf02cSchristos int eap_sim_aka_result_ind; 2213d6c0713Schristos int eap_sim_id; 222*bb618362Schristos 223*bb618362Schristos /* Maximum number of fast re-authentications allowed after each full 224*bb618362Schristos * EAP-SIM/AKA authentication. */ 225*bb618362Schristos int eap_sim_aka_fast_reauth_limit; 226*bb618362Schristos 227*bb618362Schristos /** 228*bb618362Schristos * tnc - Trusted Network Connect (TNC) 229*bb618362Schristos * 230*bb618362Schristos * This controls whether TNC is enabled and will be required before the 231*bb618362Schristos * peer is allowed to connect. Note: This is only used with EAP-TTLS 232*bb618362Schristos * and EAP-FAST. If any other EAP method is enabled, the peer will be 233*bb618362Schristos * allowed to connect without TNC. 234*bb618362Schristos */ 2358dbcf02cSchristos int tnc; 236*bb618362Schristos 237*bb618362Schristos /** 238*bb618362Schristos * wps - Wi-Fi Protected Setup context 239*bb618362Schristos * 240*bb618362Schristos * If WPS is used with an external RADIUS server (which is quite 241*bb618362Schristos * unlikely configuration), this is used to provide a pointer to WPS 242*bb618362Schristos * context data. Normally, this can be set to %NULL. 243*bb618362Schristos */ 2448dbcf02cSchristos struct wps_context *wps; 245111b9fd8Schristos int fragment_size; 246111b9fd8Schristos 247111b9fd8Schristos int pbc_in_m1; 2483c260e60Schristos 249*bb618362Schristos /** 250*bb618362Schristos * server_id - Server identity 251*bb618362Schristos */ 252*bb618362Schristos u8 *server_id; 2533c260e60Schristos size_t server_id_len; 254*bb618362Schristos 255*bb618362Schristos /** 256*bb618362Schristos * erp - Whether EAP Re-authentication Protocol (ERP) is enabled 257*bb618362Schristos * 258*bb618362Schristos * This controls whether the authentication server derives ERP key 259*bb618362Schristos * hierarchy (rRK and rIK) from full EAP authentication and allows 260*bb618362Schristos * these keys to be used to perform ERP to derive rMSK instead of full 261*bb618362Schristos * EAP authentication to derive MSK. 262*bb618362Schristos */ 263bb610346Schristos int erp; 26436ebd06eSchristos unsigned int tls_session_lifetime; 2650a73ee0aSchristos unsigned int tls_flags; 2663c260e60Schristos 267*bb618362Schristos unsigned int max_auth_rounds; 268*bb618362Schristos unsigned int max_auth_rounds_short; 269*bb618362Schristos 270*bb618362Schristos #ifdef CONFIG_TESTING_OPTIONS 271*bb618362Schristos bool skip_prot_success; 272*bb618362Schristos #endif /* CONFIG_TESTING_OPTIONS */ 273*bb618362Schristos }; 274*bb618362Schristos 275*bb618362Schristos struct eap_session_data { 276*bb618362Schristos const struct wpabuf *assoc_wps_ie; 277*bb618362Schristos const struct wpabuf *assoc_p2p_ie; 278*bb618362Schristos const u8 *peer_addr; 2793c260e60Schristos #ifdef CONFIG_TESTING_OPTIONS 2803c260e60Schristos u32 tls_test_flags; 2813c260e60Schristos #endif /* CONFIG_TESTING_OPTIONS */ 2828dbcf02cSchristos }; 2838dbcf02cSchristos 2848dbcf02cSchristos 2858dbcf02cSchristos struct eap_sm * eap_server_sm_init(void *eapol_ctx, 28636ebd06eSchristos const struct eapol_callbacks *eapol_cb, 287*bb618362Schristos const struct eap_config *conf, 288*bb618362Schristos const struct eap_session_data *sess); 2898dbcf02cSchristos void eap_server_sm_deinit(struct eap_sm *sm); 2908dbcf02cSchristos int eap_server_sm_step(struct eap_sm *sm); 2918dbcf02cSchristos void eap_sm_notify_cached(struct eap_sm *sm); 2928dbcf02cSchristos void eap_sm_pending_cb(struct eap_sm *sm); 2938dbcf02cSchristos int eap_sm_method_pending(struct eap_sm *sm); 2948dbcf02cSchristos const u8 * eap_get_identity(struct eap_sm *sm, size_t *len); 2950a73ee0aSchristos const char * eap_get_serial_num(struct eap_sm *sm); 2963d6c0713Schristos const char * eap_get_method(struct eap_sm *sm); 2973d6c0713Schristos const char * eap_get_imsi(struct eap_sm *sm); 2988dbcf02cSchristos struct eap_eapol_interface * eap_get_interface(struct eap_sm *sm); 299111b9fd8Schristos void eap_server_clear_identity(struct eap_sm *sm); 30036ebd06eSchristos void eap_server_mschap_rx_callback(struct eap_sm *sm, const char *source, 30136ebd06eSchristos const u8 *username, size_t username_len, 30236ebd06eSchristos const u8 *challenge, const u8 *response); 3030a73ee0aSchristos void eap_erp_update_identity(struct eap_sm *sm, const u8 *eap, size_t len); 3043d6c0713Schristos void eap_user_free(struct eap_user *user); 305*bb618362Schristos void eap_server_config_free(struct eap_config *cfg); 3068dbcf02cSchristos 3078dbcf02cSchristos #endif /* EAP_H */ 308