Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / IEEE 802.1X-2004 Authenticator |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2019, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "utils/includes.h" |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 10 | #ifdef CONFIG_SQLITE |
| 11 | #include <sqlite3.h> |
| 12 | #endif /* CONFIG_SQLITE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13 | |
| 14 | #include "utils/common.h" |
| 15 | #include "utils/eloop.h" |
| 16 | #include "crypto/md5.h" |
| 17 | #include "crypto/crypto.h" |
| 18 | #include "crypto/random.h" |
| 19 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 20 | #include "radius/radius.h" |
| 21 | #include "radius/radius_client.h" |
| 22 | #include "eap_server/eap.h" |
| 23 | #include "eap_common/eap_wsc_common.h" |
| 24 | #include "eapol_auth/eapol_auth_sm.h" |
| 25 | #include "eapol_auth/eapol_auth_sm_i.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 26 | #include "p2p/p2p.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 27 | #include "hostapd.h" |
| 28 | #include "accounting.h" |
| 29 | #include "sta_info.h" |
| 30 | #include "wpa_auth.h" |
| 31 | #include "preauth_auth.h" |
| 32 | #include "pmksa_cache_auth.h" |
| 33 | #include "ap_config.h" |
| 34 | #include "ap_drv_ops.h" |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 35 | #include "wps_hostapd.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 36 | #include "hs20.h" |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 37 | /* FIX: Not really a good thing to require ieee802_11.h here.. (FILS) */ |
| 38 | #include "ieee802_11.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 39 | #include "ieee802_1x.h" |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 40 | #include "wpa_auth_kay.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 41 | |
| 42 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 43 | #ifdef CONFIG_HS20 |
| 44 | static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx); |
| 45 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 46 | static void ieee802_1x_finished(struct hostapd_data *hapd, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 47 | struct sta_info *sta, int success, |
| 48 | int remediation); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 49 | |
| 50 | |
| 51 | static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta, |
| 52 | u8 type, const u8 *data, size_t datalen) |
| 53 | { |
| 54 | u8 *buf; |
| 55 | struct ieee802_1x_hdr *xhdr; |
| 56 | size_t len; |
| 57 | int encrypt = 0; |
| 58 | |
| 59 | len = sizeof(*xhdr) + datalen; |
| 60 | buf = os_zalloc(len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 61 | if (!buf) { |
| 62 | wpa_printf(MSG_ERROR, "malloc() failed for %s(len=%lu)", |
| 63 | __func__, (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 64 | return; |
| 65 | } |
| 66 | |
| 67 | xhdr = (struct ieee802_1x_hdr *) buf; |
| 68 | xhdr->version = hapd->conf->eapol_version; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 69 | #ifdef CONFIG_MACSEC |
| 70 | if (xhdr->version > 2 && hapd->conf->macsec_policy == 0) |
| 71 | xhdr->version = 2; |
| 72 | #endif /* CONFIG_MACSEC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 73 | xhdr->type = type; |
| 74 | xhdr->length = host_to_be16(datalen); |
| 75 | |
| 76 | if (datalen > 0 && data != NULL) |
| 77 | os_memcpy(xhdr + 1, data, datalen); |
| 78 | |
| 79 | if (wpa_auth_pairwise_set(sta->wpa_sm)) |
| 80 | encrypt = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 81 | #ifdef CONFIG_TESTING_OPTIONS |
| 82 | if (hapd->ext_eapol_frame_io) { |
| 83 | size_t hex_len = 2 * len + 1; |
| 84 | char *hex = os_malloc(hex_len); |
| 85 | |
| 86 | if (hex) { |
| 87 | wpa_snprintf_hex(hex, hex_len, buf, len); |
| 88 | wpa_msg(hapd->msg_ctx, MSG_INFO, |
| 89 | "EAPOL-TX " MACSTR " %s", |
| 90 | MAC2STR(sta->addr), hex); |
| 91 | os_free(hex); |
| 92 | } |
| 93 | } else |
| 94 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 95 | if (sta->flags & WLAN_STA_PREAUTH) { |
| 96 | rsn_preauth_send(hapd, sta, buf, len); |
| 97 | } else { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 98 | hostapd_drv_hapd_send_eapol( |
| 99 | hapd, sta->addr, buf, len, |
| 100 | encrypt, hostapd_sta_flags_to_drv(sta->flags)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | os_free(buf); |
| 104 | } |
| 105 | |
| 106 | |
| 107 | void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd, |
| 108 | struct sta_info *sta, int authorized) |
| 109 | { |
| 110 | int res; |
| 111 | |
| 112 | if (sta->flags & WLAN_STA_PREAUTH) |
| 113 | return; |
| 114 | |
| 115 | if (authorized) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 116 | ap_sta_set_authorized(hapd, sta, 1); |
| 117 | res = hostapd_set_authorized(hapd, sta, 1); |
| 118 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
| 119 | HOSTAPD_LEVEL_DEBUG, "authorizing port"); |
| 120 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 121 | ap_sta_set_authorized(hapd, sta, 0); |
| 122 | res = hostapd_set_authorized(hapd, sta, 0); |
| 123 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
| 124 | HOSTAPD_LEVEL_DEBUG, "unauthorizing port"); |
| 125 | } |
| 126 | |
| 127 | if (res && errno != ENOENT) { |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 128 | wpa_printf(MSG_DEBUG, "Could not set station " MACSTR |
| 129 | " flags for kernel driver (errno=%d).", |
| 130 | MAC2STR(sta->addr), errno); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 133 | if (authorized) { |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 134 | os_get_reltime(&sta->connected_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 135 | accounting_sta_start(hapd, sta); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 136 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 140 | #ifndef CONFIG_FIPS |
| 141 | #ifndef CONFIG_NO_RC4 |
| 142 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 143 | static void ieee802_1x_tx_key_one(struct hostapd_data *hapd, |
| 144 | struct sta_info *sta, |
| 145 | int idx, int broadcast, |
| 146 | u8 *key_data, size_t key_len) |
| 147 | { |
| 148 | u8 *buf, *ekey; |
| 149 | struct ieee802_1x_hdr *hdr; |
| 150 | struct ieee802_1x_eapol_key *key; |
| 151 | size_t len, ekey_len; |
| 152 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 153 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 154 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 155 | return; |
| 156 | |
| 157 | len = sizeof(*key) + key_len; |
| 158 | buf = os_zalloc(sizeof(*hdr) + len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 159 | if (!buf) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 160 | return; |
| 161 | |
| 162 | hdr = (struct ieee802_1x_hdr *) buf; |
| 163 | key = (struct ieee802_1x_eapol_key *) (hdr + 1); |
| 164 | key->type = EAPOL_KEY_TYPE_RC4; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 165 | WPA_PUT_BE16(key->key_length, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 166 | wpa_get_ntp_timestamp(key->replay_counter); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 167 | if (os_memcmp(key->replay_counter, |
| 168 | hapd->last_1x_eapol_key_replay_counter, |
| 169 | IEEE8021X_REPLAY_COUNTER_LEN) <= 0) { |
| 170 | /* NTP timestamp did not increment from last EAPOL-Key frame; |
| 171 | * use previously used value + 1 instead. */ |
| 172 | inc_byte_array(hapd->last_1x_eapol_key_replay_counter, |
| 173 | IEEE8021X_REPLAY_COUNTER_LEN); |
| 174 | os_memcpy(key->replay_counter, |
| 175 | hapd->last_1x_eapol_key_replay_counter, |
| 176 | IEEE8021X_REPLAY_COUNTER_LEN); |
| 177 | } else { |
| 178 | os_memcpy(hapd->last_1x_eapol_key_replay_counter, |
| 179 | key->replay_counter, |
| 180 | IEEE8021X_REPLAY_COUNTER_LEN); |
| 181 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 182 | |
| 183 | if (random_get_bytes(key->key_iv, sizeof(key->key_iv))) { |
| 184 | wpa_printf(MSG_ERROR, "Could not get random numbers"); |
| 185 | os_free(buf); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | key->key_index = idx | (broadcast ? 0 : BIT(7)); |
| 190 | if (hapd->conf->eapol_key_index_workaround) { |
| 191 | /* According to some information, WinXP Supplicant seems to |
| 192 | * interpret bit7 as an indication whether the key is to be |
| 193 | * activated, so make it possible to enable workaround that |
| 194 | * sets this bit for all keys. */ |
| 195 | key->key_index |= BIT(7); |
| 196 | } |
| 197 | |
| 198 | /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and |
| 199 | * MSK[32..63] is used to sign the message. */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 200 | if (!sm->eap_if->eapKeyData || sm->eap_if->eapKeyDataLen < 64) { |
| 201 | wpa_printf(MSG_ERROR, |
| 202 | "No eapKeyData available for encrypting and signing EAPOL-Key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 203 | os_free(buf); |
| 204 | return; |
| 205 | } |
| 206 | os_memcpy((u8 *) (key + 1), key_data, key_len); |
| 207 | ekey_len = sizeof(key->key_iv) + 32; |
| 208 | ekey = os_malloc(ekey_len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 209 | if (!ekey) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 210 | wpa_printf(MSG_ERROR, "Could not encrypt key"); |
| 211 | os_free(buf); |
| 212 | return; |
| 213 | } |
| 214 | os_memcpy(ekey, key->key_iv, sizeof(key->key_iv)); |
| 215 | os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32); |
| 216 | rc4_skip(ekey, ekey_len, 0, (u8 *) (key + 1), key_len); |
| 217 | os_free(ekey); |
| 218 | |
| 219 | /* This header is needed here for HMAC-MD5, but it will be regenerated |
| 220 | * in ieee802_1x_send() */ |
| 221 | hdr->version = hapd->conf->eapol_version; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 222 | #ifdef CONFIG_MACSEC |
| 223 | if (hdr->version > 2) |
| 224 | hdr->version = 2; |
| 225 | #endif /* CONFIG_MACSEC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 226 | hdr->type = IEEE802_1X_TYPE_EAPOL_KEY; |
| 227 | hdr->length = host_to_be16(len); |
| 228 | hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len, |
| 229 | key->key_signature); |
| 230 | |
| 231 | wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR |
| 232 | " (%s index=%d)", MAC2STR(sm->addr), |
| 233 | broadcast ? "broadcast" : "unicast", idx); |
| 234 | ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len); |
| 235 | if (sta->eapol_sm) |
| 236 | sta->eapol_sm->dot1xAuthEapolFramesTx++; |
| 237 | os_free(buf); |
| 238 | } |
| 239 | |
| 240 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 241 | static void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 242 | { |
| 243 | struct eapol_authenticator *eapol = hapd->eapol_auth; |
| 244 | struct eapol_state_machine *sm = sta->eapol_sm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 245 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 246 | if (!sm || !sm->eap_if->eapKeyData) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 247 | return; |
| 248 | |
| 249 | wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR, |
| 250 | MAC2STR(sta->addr)); |
| 251 | |
| 252 | #ifndef CONFIG_NO_VLAN |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 253 | if (sta->vlan_id > 0) { |
Dmitry Shmidt | 5393a0f | 2013-08-08 11:23:34 -0700 | [diff] [blame] | 254 | wpa_printf(MSG_ERROR, "Using WEP with vlans is not supported."); |
| 255 | return; |
| 256 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 257 | #endif /* CONFIG_NO_VLAN */ |
Dmitry Shmidt | 5393a0f | 2013-08-08 11:23:34 -0700 | [diff] [blame] | 258 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 259 | if (eapol->default_wep_key) { |
| 260 | ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1, |
| 261 | eapol->default_wep_key, |
| 262 | hapd->conf->default_wep_key_len); |
| 263 | } |
| 264 | |
| 265 | if (hapd->conf->individual_wep_key_len > 0) { |
| 266 | u8 *ikey; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 267 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 268 | ikey = os_malloc(hapd->conf->individual_wep_key_len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 269 | if (!ikey || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 270 | random_get_bytes(ikey, hapd->conf->individual_wep_key_len)) |
| 271 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 272 | wpa_printf(MSG_ERROR, |
| 273 | "Could not generate random individual WEP key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 274 | os_free(ikey); |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | wpa_hexdump_key(MSG_DEBUG, "Individual WEP key", |
| 279 | ikey, hapd->conf->individual_wep_key_len); |
| 280 | |
| 281 | ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey, |
| 282 | hapd->conf->individual_wep_key_len); |
| 283 | |
| 284 | /* TODO: set encryption in TX callback, i.e., only after STA |
| 285 | * has ACKed EAPOL-Key frame */ |
| 286 | if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP, |
| 287 | sta->addr, 0, 1, NULL, 0, ikey, |
| 288 | hapd->conf->individual_wep_key_len)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 289 | wpa_printf(MSG_ERROR, |
| 290 | "Could not set individual WEP encryption"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | os_free(ikey); |
| 294 | } |
| 295 | } |
| 296 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 297 | #endif /* CONFIG_NO_RC4 */ |
| 298 | #endif /* CONFIG_FIPS */ |
| 299 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 300 | |
| 301 | const char *radius_mode_txt(struct hostapd_data *hapd) |
| 302 | { |
| 303 | switch (hapd->iface->conf->hw_mode) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 304 | case HOSTAPD_MODE_IEEE80211AD: |
| 305 | return "802.11ad"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 306 | case HOSTAPD_MODE_IEEE80211A: |
| 307 | return "802.11a"; |
| 308 | case HOSTAPD_MODE_IEEE80211G: |
| 309 | return "802.11g"; |
| 310 | case HOSTAPD_MODE_IEEE80211B: |
| 311 | default: |
| 312 | return "802.11b"; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | |
| 317 | int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta) |
| 318 | { |
| 319 | int i; |
| 320 | u8 rate = 0; |
| 321 | |
| 322 | for (i = 0; i < sta->supported_rates_len; i++) |
| 323 | if ((sta->supported_rates[i] & 0x7f) > rate) |
| 324 | rate = sta->supported_rates[i] & 0x7f; |
| 325 | |
| 326 | return rate; |
| 327 | } |
| 328 | |
| 329 | |
| 330 | #ifndef CONFIG_NO_RADIUS |
| 331 | static void ieee802_1x_learn_identity(struct hostapd_data *hapd, |
| 332 | struct eapol_state_machine *sm, |
| 333 | const u8 *eap, size_t len) |
| 334 | { |
| 335 | const u8 *identity; |
| 336 | size_t identity_len; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 337 | const struct eap_hdr *hdr = (const struct eap_hdr *) eap; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 338 | |
| 339 | if (len <= sizeof(struct eap_hdr) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 340 | (hdr->code == EAP_CODE_RESPONSE && |
| 341 | eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY) || |
| 342 | (hdr->code == EAP_CODE_INITIATE && |
| 343 | eap[sizeof(struct eap_hdr)] != EAP_ERP_TYPE_REAUTH) || |
| 344 | (hdr->code != EAP_CODE_RESPONSE && |
| 345 | hdr->code != EAP_CODE_INITIATE)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 346 | return; |
| 347 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 348 | eap_erp_update_identity(sm->eap, eap, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 349 | identity = eap_get_identity(sm->eap, &identity_len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 350 | if (!identity) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 351 | return; |
| 352 | |
| 353 | /* Save station identity for future RADIUS packets */ |
| 354 | os_free(sm->identity); |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 355 | sm->identity = (u8 *) dup_binstr(identity, identity_len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 356 | if (!sm->identity) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 357 | sm->identity_len = 0; |
| 358 | return; |
| 359 | } |
| 360 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 361 | sm->identity_len = identity_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 362 | hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X, |
| 363 | HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity); |
| 364 | sm->dot1xAuthEapolRespIdFramesRx++; |
| 365 | } |
| 366 | |
| 367 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 368 | static int add_common_radius_sta_attr_rsn(struct hostapd_data *hapd, |
| 369 | struct hostapd_radius_attr *req_attr, |
| 370 | struct sta_info *sta, |
| 371 | struct radius_msg *msg) |
| 372 | { |
| 373 | u32 suite; |
| 374 | int ver, val; |
| 375 | |
| 376 | ver = wpa_auth_sta_wpa_version(sta->wpa_sm); |
| 377 | val = wpa_auth_get_pairwise(sta->wpa_sm); |
| 378 | suite = wpa_cipher_to_suite(ver, val); |
| 379 | if (val != -1 && |
| 380 | !hostapd_config_get_radius_attr(req_attr, |
| 381 | RADIUS_ATTR_WLAN_PAIRWISE_CIPHER) && |
| 382 | !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_PAIRWISE_CIPHER, |
| 383 | suite)) { |
| 384 | wpa_printf(MSG_ERROR, "Could not add WLAN-Pairwise-Cipher"); |
| 385 | return -1; |
| 386 | } |
| 387 | |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 388 | suite = wpa_cipher_to_suite(((hapd->conf->wpa & 0x2) || |
| 389 | hapd->conf->osen) ? |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 390 | WPA_PROTO_RSN : WPA_PROTO_WPA, |
| 391 | hapd->conf->wpa_group); |
| 392 | if (!hostapd_config_get_radius_attr(req_attr, |
| 393 | RADIUS_ATTR_WLAN_GROUP_CIPHER) && |
| 394 | !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_GROUP_CIPHER, |
| 395 | suite)) { |
| 396 | wpa_printf(MSG_ERROR, "Could not add WLAN-Group-Cipher"); |
| 397 | return -1; |
| 398 | } |
| 399 | |
| 400 | val = wpa_auth_sta_key_mgmt(sta->wpa_sm); |
| 401 | suite = wpa_akm_to_suite(val); |
| 402 | if (val != -1 && |
| 403 | !hostapd_config_get_radius_attr(req_attr, |
| 404 | RADIUS_ATTR_WLAN_AKM_SUITE) && |
| 405 | !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_AKM_SUITE, |
| 406 | suite)) { |
| 407 | wpa_printf(MSG_ERROR, "Could not add WLAN-AKM-Suite"); |
| 408 | return -1; |
| 409 | } |
| 410 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 411 | if (hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { |
| 412 | suite = wpa_cipher_to_suite(WPA_PROTO_RSN, |
| 413 | hapd->conf->group_mgmt_cipher); |
| 414 | if (!hostapd_config_get_radius_attr( |
| 415 | req_attr, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER) && |
| 416 | !radius_msg_add_attr_int32( |
| 417 | msg, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER, suite)) { |
| 418 | wpa_printf(MSG_ERROR, |
| 419 | "Could not add WLAN-Group-Mgmt-Cipher"); |
| 420 | return -1; |
| 421 | } |
| 422 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 428 | static int add_common_radius_sta_attr(struct hostapd_data *hapd, |
| 429 | struct hostapd_radius_attr *req_attr, |
| 430 | struct sta_info *sta, |
| 431 | struct radius_msg *msg) |
| 432 | { |
| 433 | char buf[128]; |
| 434 | |
| 435 | if (!hostapd_config_get_radius_attr(req_attr, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 436 | RADIUS_ATTR_SERVICE_TYPE) && |
| 437 | !radius_msg_add_attr_int32(msg, RADIUS_ATTR_SERVICE_TYPE, |
| 438 | RADIUS_SERVICE_TYPE_FRAMED)) { |
| 439 | wpa_printf(MSG_ERROR, "Could not add Service-Type"); |
| 440 | return -1; |
| 441 | } |
| 442 | |
| 443 | if (!hostapd_config_get_radius_attr(req_attr, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 444 | RADIUS_ATTR_NAS_PORT) && |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 445 | sta->aid > 0 && |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 446 | !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) { |
| 447 | wpa_printf(MSG_ERROR, "Could not add NAS-Port"); |
| 448 | return -1; |
| 449 | } |
| 450 | |
| 451 | os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT, |
| 452 | MAC2STR(sta->addr)); |
| 453 | buf[sizeof(buf) - 1] = '\0'; |
| 454 | if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID, |
| 455 | (u8 *) buf, os_strlen(buf))) { |
| 456 | wpa_printf(MSG_ERROR, "Could not add Calling-Station-Id"); |
| 457 | return -1; |
| 458 | } |
| 459 | |
| 460 | if (sta->flags & WLAN_STA_PREAUTH) { |
| 461 | os_strlcpy(buf, "IEEE 802.11i Pre-Authentication", |
| 462 | sizeof(buf)); |
| 463 | } else { |
| 464 | os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s", |
| 465 | radius_sta_rate(hapd, sta) / 2, |
| 466 | (radius_sta_rate(hapd, sta) & 1) ? ".5" : "", |
| 467 | radius_mode_txt(hapd)); |
| 468 | buf[sizeof(buf) - 1] = '\0'; |
| 469 | } |
| 470 | if (!hostapd_config_get_radius_attr(req_attr, |
| 471 | RADIUS_ATTR_CONNECT_INFO) && |
| 472 | !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO, |
| 473 | (u8 *) buf, os_strlen(buf))) { |
| 474 | wpa_printf(MSG_ERROR, "Could not add Connect-Info"); |
| 475 | return -1; |
| 476 | } |
| 477 | |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 478 | if (sta->acct_session_id) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 479 | os_snprintf(buf, sizeof(buf), "%016llX", |
| 480 | (unsigned long long) sta->acct_session_id); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 481 | if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID, |
| 482 | (u8 *) buf, os_strlen(buf))) { |
| 483 | wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id"); |
| 484 | return -1; |
| 485 | } |
| 486 | } |
| 487 | |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 488 | if ((hapd->conf->wpa & 2) && |
| 489 | !hapd->conf->disable_pmksa_caching && |
| 490 | sta->eapol_sm && sta->eapol_sm->acct_multi_session_id) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 491 | os_snprintf(buf, sizeof(buf), "%016llX", |
| 492 | (unsigned long long) |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 493 | sta->eapol_sm->acct_multi_session_id); |
| 494 | if (!radius_msg_add_attr( |
| 495 | msg, RADIUS_ATTR_ACCT_MULTI_SESSION_ID, |
| 496 | (u8 *) buf, os_strlen(buf))) { |
| 497 | wpa_printf(MSG_INFO, |
| 498 | "Could not add Acct-Multi-Session-Id"); |
| 499 | return -1; |
| 500 | } |
| 501 | } |
| 502 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 503 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 504 | if (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) && |
| 505 | sta->wpa_sm && |
| 506 | (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm)) || |
| 507 | sta->auth_alg == WLAN_AUTH_FT) && |
| 508 | !hostapd_config_get_radius_attr(req_attr, |
| 509 | RADIUS_ATTR_MOBILITY_DOMAIN_ID) && |
| 510 | !radius_msg_add_attr_int32(msg, RADIUS_ATTR_MOBILITY_DOMAIN_ID, |
| 511 | WPA_GET_BE16( |
| 512 | hapd->conf->mobility_domain))) { |
| 513 | wpa_printf(MSG_ERROR, "Could not add Mobility-Domain-Id"); |
| 514 | return -1; |
| 515 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 516 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 517 | |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 518 | if ((hapd->conf->wpa || hapd->conf->osen) && sta->wpa_sm && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 519 | add_common_radius_sta_attr_rsn(hapd, req_attr, sta, msg) < 0) |
| 520 | return -1; |
| 521 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | |
| 526 | int add_common_radius_attr(struct hostapd_data *hapd, |
| 527 | struct hostapd_radius_attr *req_attr, |
| 528 | struct sta_info *sta, |
| 529 | struct radius_msg *msg) |
| 530 | { |
| 531 | char buf[128]; |
| 532 | struct hostapd_radius_attr *attr; |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 533 | int len; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 534 | |
| 535 | if (!hostapd_config_get_radius_attr(req_attr, |
| 536 | RADIUS_ATTR_NAS_IP_ADDRESS) && |
| 537 | hapd->conf->own_ip_addr.af == AF_INET && |
| 538 | !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS, |
| 539 | (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) { |
| 540 | wpa_printf(MSG_ERROR, "Could not add NAS-IP-Address"); |
| 541 | return -1; |
| 542 | } |
| 543 | |
| 544 | #ifdef CONFIG_IPV6 |
| 545 | if (!hostapd_config_get_radius_attr(req_attr, |
| 546 | RADIUS_ATTR_NAS_IPV6_ADDRESS) && |
| 547 | hapd->conf->own_ip_addr.af == AF_INET6 && |
| 548 | !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS, |
| 549 | (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) { |
| 550 | wpa_printf(MSG_ERROR, "Could not add NAS-IPv6-Address"); |
| 551 | return -1; |
| 552 | } |
| 553 | #endif /* CONFIG_IPV6 */ |
| 554 | |
| 555 | if (!hostapd_config_get_radius_attr(req_attr, |
| 556 | RADIUS_ATTR_NAS_IDENTIFIER) && |
| 557 | hapd->conf->nas_identifier && |
| 558 | !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER, |
| 559 | (u8 *) hapd->conf->nas_identifier, |
| 560 | os_strlen(hapd->conf->nas_identifier))) { |
| 561 | wpa_printf(MSG_ERROR, "Could not add NAS-Identifier"); |
| 562 | return -1; |
| 563 | } |
| 564 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 565 | len = os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":", |
| 566 | MAC2STR(hapd->own_addr)); |
| 567 | os_memcpy(&buf[len], hapd->conf->ssid.ssid, |
| 568 | hapd->conf->ssid.ssid_len); |
| 569 | len += hapd->conf->ssid.ssid_len; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 570 | if (!hostapd_config_get_radius_attr(req_attr, |
| 571 | RADIUS_ATTR_CALLED_STATION_ID) && |
| 572 | !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID, |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 573 | (u8 *) buf, len)) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 574 | wpa_printf(MSG_ERROR, "Could not add Called-Station-Id"); |
| 575 | return -1; |
| 576 | } |
| 577 | |
| 578 | if (!hostapd_config_get_radius_attr(req_attr, |
| 579 | RADIUS_ATTR_NAS_PORT_TYPE) && |
| 580 | !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE, |
| 581 | RADIUS_NAS_PORT_TYPE_IEEE_802_11)) { |
| 582 | wpa_printf(MSG_ERROR, "Could not add NAS-Port-Type"); |
| 583 | return -1; |
| 584 | } |
| 585 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 586 | #ifdef CONFIG_INTERWORKING |
| 587 | if (hapd->conf->interworking && |
| 588 | !is_zero_ether_addr(hapd->conf->hessid)) { |
| 589 | os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT, |
| 590 | MAC2STR(hapd->conf->hessid)); |
| 591 | buf[sizeof(buf) - 1] = '\0'; |
| 592 | if (!hostapd_config_get_radius_attr(req_attr, |
| 593 | RADIUS_ATTR_WLAN_HESSID) && |
| 594 | !radius_msg_add_attr(msg, RADIUS_ATTR_WLAN_HESSID, |
| 595 | (u8 *) buf, os_strlen(buf))) { |
| 596 | wpa_printf(MSG_ERROR, "Could not add WLAN-HESSID"); |
| 597 | return -1; |
| 598 | } |
| 599 | } |
| 600 | #endif /* CONFIG_INTERWORKING */ |
| 601 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 602 | if (sta && add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0) |
| 603 | return -1; |
| 604 | |
| 605 | for (attr = req_attr; attr; attr = attr->next) { |
| 606 | if (!radius_msg_add_attr(msg, attr->type, |
| 607 | wpabuf_head(attr->val), |
| 608 | wpabuf_len(attr->val))) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 609 | wpa_printf(MSG_ERROR, "Could not add RADIUS attribute"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 610 | return -1; |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 618 | int add_sqlite_radius_attr(struct hostapd_data *hapd, struct sta_info *sta, |
| 619 | struct radius_msg *msg, int acct) |
| 620 | { |
| 621 | #ifdef CONFIG_SQLITE |
| 622 | const char *attrtxt; |
| 623 | char addrtxt[3 * ETH_ALEN]; |
| 624 | char *sql; |
| 625 | sqlite3_stmt *stmt = NULL; |
| 626 | |
| 627 | if (!hapd->rad_attr_db) |
| 628 | return 0; |
| 629 | |
| 630 | os_snprintf(addrtxt, sizeof(addrtxt), MACSTR, MAC2STR(sta->addr)); |
| 631 | |
| 632 | sql = "SELECT attr FROM radius_attributes WHERE sta=? AND (reqtype=? OR reqtype IS NULL);"; |
| 633 | if (sqlite3_prepare_v2(hapd->rad_attr_db, sql, os_strlen(sql), &stmt, |
| 634 | NULL) != SQLITE_OK) { |
| 635 | wpa_printf(MSG_ERROR, "DB: Failed to prepare SQL statement: %s", |
| 636 | sqlite3_errmsg(hapd->rad_attr_db)); |
| 637 | return -1; |
| 638 | } |
| 639 | sqlite3_bind_text(stmt, 1, addrtxt, os_strlen(addrtxt), SQLITE_STATIC); |
| 640 | sqlite3_bind_text(stmt, 2, acct ? "acct" : "auth", 4, SQLITE_STATIC); |
| 641 | while (sqlite3_step(stmt) == SQLITE_ROW) { |
| 642 | struct hostapd_radius_attr *attr; |
| 643 | struct radius_attr_hdr *hdr; |
| 644 | |
| 645 | attrtxt = (const char *) sqlite3_column_text(stmt, 0); |
| 646 | attr = hostapd_parse_radius_attr(attrtxt); |
| 647 | if (!attr) { |
| 648 | wpa_printf(MSG_ERROR, |
| 649 | "Skipping invalid attribute from SQL: %s", |
| 650 | attrtxt); |
| 651 | continue; |
| 652 | } |
| 653 | wpa_printf(MSG_DEBUG, "Adding RADIUS attribute from SQL: %s", |
| 654 | attrtxt); |
| 655 | hdr = radius_msg_add_attr(msg, attr->type, |
| 656 | wpabuf_head(attr->val), |
| 657 | wpabuf_len(attr->val)); |
| 658 | hostapd_config_free_radius_attr(attr); |
| 659 | if (!hdr) { |
| 660 | wpa_printf(MSG_ERROR, |
| 661 | "Could not add RADIUS attribute from SQL"); |
| 662 | continue; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | sqlite3_reset(stmt); |
| 667 | sqlite3_clear_bindings(stmt); |
| 668 | sqlite3_finalize(stmt); |
| 669 | #endif /* CONFIG_SQLITE */ |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 675 | void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd, |
| 676 | struct sta_info *sta, |
| 677 | const u8 *eap, size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 678 | { |
| 679 | struct radius_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 680 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 681 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 682 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 683 | return; |
| 684 | |
| 685 | ieee802_1x_learn_identity(hapd, sm, eap, len); |
| 686 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 687 | wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS packet"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 688 | |
| 689 | sm->radius_identifier = radius_client_get_id(hapd->radius); |
| 690 | msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST, |
| 691 | sm->radius_identifier); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 692 | if (!msg) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 693 | wpa_printf(MSG_INFO, "Could not create new RADIUS packet"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 694 | return; |
| 695 | } |
| 696 | |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 697 | if (radius_msg_make_authenticator(msg) < 0) { |
| 698 | wpa_printf(MSG_INFO, "Could not make Request Authenticator"); |
| 699 | goto fail; |
| 700 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 701 | |
| 702 | if (sm->identity && |
| 703 | !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME, |
| 704 | sm->identity, sm->identity_len)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 705 | wpa_printf(MSG_INFO, "Could not add User-Name"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 706 | goto fail; |
| 707 | } |
| 708 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 709 | if (add_common_radius_attr(hapd, hapd->conf->radius_auth_req_attr, sta, |
| 710 | msg) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 711 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 712 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 713 | if (sta && add_sqlite_radius_attr(hapd, sta, msg, 0) < 0) |
| 714 | goto fail; |
| 715 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 716 | /* TODO: should probably check MTU from driver config; 2304 is max for |
| 717 | * IEEE 802.11, but use 1400 to avoid problems with too large packets |
| 718 | */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 719 | if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr, |
| 720 | RADIUS_ATTR_FRAMED_MTU) && |
| 721 | !radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 722 | wpa_printf(MSG_INFO, "Could not add Framed-MTU"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 723 | goto fail; |
| 724 | } |
| 725 | |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 726 | if (!radius_msg_add_eap(msg, eap, len)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 727 | wpa_printf(MSG_INFO, "Could not add EAP-Message"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 728 | goto fail; |
| 729 | } |
| 730 | |
| 731 | /* State attribute must be copied if and only if this packet is |
| 732 | * Access-Request reply to the previous Access-Challenge */ |
| 733 | if (sm->last_recv_radius && |
| 734 | radius_msg_get_hdr(sm->last_recv_radius)->code == |
| 735 | RADIUS_CODE_ACCESS_CHALLENGE) { |
| 736 | int res = radius_msg_copy_attr(msg, sm->last_recv_radius, |
| 737 | RADIUS_ATTR_STATE); |
| 738 | if (res < 0) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 739 | wpa_printf(MSG_INFO, |
| 740 | "Could not copy State attribute from previous Access-Challenge"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 741 | goto fail; |
| 742 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 743 | if (res > 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 744 | wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 747 | if (hapd->conf->radius_request_cui) { |
| 748 | const u8 *cui; |
| 749 | size_t cui_len; |
| 750 | /* Add previously learned CUI or nul CUI to request CUI */ |
| 751 | if (sm->radius_cui) { |
| 752 | cui = wpabuf_head(sm->radius_cui); |
| 753 | cui_len = wpabuf_len(sm->radius_cui); |
| 754 | } else { |
| 755 | cui = (const u8 *) "\0"; |
| 756 | cui_len = 1; |
| 757 | } |
| 758 | if (!radius_msg_add_attr(msg, |
| 759 | RADIUS_ATTR_CHARGEABLE_USER_IDENTITY, |
| 760 | cui, cui_len)) { |
| 761 | wpa_printf(MSG_ERROR, "Could not add CUI"); |
| 762 | goto fail; |
| 763 | } |
| 764 | } |
| 765 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 766 | #ifdef CONFIG_HS20 |
| 767 | if (hapd->conf->hs20) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 768 | u8 ver = hapd->conf->hs20_release - 1; |
| 769 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 770 | if (!radius_msg_add_wfa( |
| 771 | msg, RADIUS_VENDOR_ATTR_WFA_HS20_AP_VERSION, |
| 772 | &ver, 1)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 773 | wpa_printf(MSG_ERROR, |
| 774 | "Could not add HS 2.0 AP version"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 775 | goto fail; |
| 776 | } |
| 777 | |
| 778 | if (sta->hs20_ie && wpabuf_len(sta->hs20_ie) > 0) { |
| 779 | const u8 *pos; |
| 780 | u8 buf[3]; |
| 781 | u16 id; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 782 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 783 | pos = wpabuf_head_u8(sta->hs20_ie); |
| 784 | buf[0] = (*pos) >> 4; |
| 785 | if (((*pos) & HS20_PPS_MO_ID_PRESENT) && |
| 786 | wpabuf_len(sta->hs20_ie) >= 3) |
| 787 | id = WPA_GET_LE16(pos + 1); |
| 788 | else |
| 789 | id = 0; |
| 790 | WPA_PUT_BE16(buf + 1, id); |
| 791 | if (!radius_msg_add_wfa( |
| 792 | msg, |
| 793 | RADIUS_VENDOR_ATTR_WFA_HS20_STA_VERSION, |
| 794 | buf, sizeof(buf))) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 795 | wpa_printf(MSG_ERROR, |
| 796 | "Could not add HS 2.0 STA version"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 797 | goto fail; |
| 798 | } |
| 799 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 800 | |
| 801 | if (sta->roaming_consortium && |
| 802 | !radius_msg_add_wfa( |
| 803 | msg, RADIUS_VENDOR_ATTR_WFA_HS20_ROAMING_CONSORTIUM, |
| 804 | wpabuf_head(sta->roaming_consortium), |
| 805 | wpabuf_len(sta->roaming_consortium))) { |
| 806 | wpa_printf(MSG_ERROR, |
| 807 | "Could not add HS 2.0 Roaming Consortium"); |
| 808 | goto fail; |
| 809 | } |
| 810 | |
| 811 | if (hapd->conf->t_c_filename) { |
| 812 | be32 timestamp; |
| 813 | |
| 814 | if (!radius_msg_add_wfa( |
| 815 | msg, |
| 816 | RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILENAME, |
| 817 | (const u8 *) hapd->conf->t_c_filename, |
| 818 | os_strlen(hapd->conf->t_c_filename))) { |
| 819 | wpa_printf(MSG_ERROR, |
| 820 | "Could not add HS 2.0 T&C Filename"); |
| 821 | goto fail; |
| 822 | } |
| 823 | |
| 824 | timestamp = host_to_be32(hapd->conf->t_c_timestamp); |
| 825 | if (!radius_msg_add_wfa( |
| 826 | msg, |
| 827 | RADIUS_VENDOR_ATTR_WFA_HS20_TIMESTAMP, |
| 828 | (const u8 *) ×tamp, |
| 829 | sizeof(timestamp))) { |
| 830 | wpa_printf(MSG_ERROR, |
| 831 | "Could not add HS 2.0 Timestamp"); |
| 832 | goto fail; |
| 833 | } |
| 834 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 835 | } |
| 836 | #endif /* CONFIG_HS20 */ |
| 837 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 838 | if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr) < 0) |
| 839 | goto fail; |
| 840 | |
| 841 | return; |
| 842 | |
| 843 | fail: |
| 844 | radius_msg_free(msg); |
| 845 | } |
| 846 | #endif /* CONFIG_NO_RADIUS */ |
| 847 | |
| 848 | |
| 849 | static void handle_eap_response(struct hostapd_data *hapd, |
| 850 | struct sta_info *sta, struct eap_hdr *eap, |
| 851 | size_t len) |
| 852 | { |
| 853 | u8 type, *data; |
| 854 | struct eapol_state_machine *sm = sta->eapol_sm; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 855 | |
| 856 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 857 | return; |
| 858 | |
| 859 | data = (u8 *) (eap + 1); |
| 860 | |
| 861 | if (len < sizeof(*eap) + 1) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 862 | wpa_printf(MSG_INFO, "%s: too short response data", __func__); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 863 | return; |
| 864 | } |
| 865 | |
| 866 | sm->eap_type_supp = type = data[0]; |
| 867 | |
| 868 | hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X, |
| 869 | HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d " |
| 870 | "id=%d len=%d) from STA: EAP Response-%s (%d)", |
| 871 | eap->code, eap->identifier, be_to_host16(eap->length), |
| 872 | eap_server_get_name(0, type), type); |
| 873 | |
| 874 | sm->dot1xAuthEapolRespFramesRx++; |
| 875 | |
| 876 | wpabuf_free(sm->eap_if->eapRespData); |
| 877 | sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len); |
| 878 | sm->eapolEap = TRUE; |
| 879 | } |
| 880 | |
| 881 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 882 | static void handle_eap_initiate(struct hostapd_data *hapd, |
| 883 | struct sta_info *sta, struct eap_hdr *eap, |
| 884 | size_t len) |
| 885 | { |
| 886 | #ifdef CONFIG_ERP |
| 887 | u8 type, *data; |
| 888 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 889 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 890 | if (!sm) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 891 | return; |
| 892 | |
| 893 | if (len < sizeof(*eap) + 1) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 894 | wpa_printf(MSG_INFO, "%s: too short response data", __func__); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 895 | return; |
| 896 | } |
| 897 | |
| 898 | data = (u8 *) (eap + 1); |
| 899 | type = data[0]; |
| 900 | |
| 901 | hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 902 | HOSTAPD_LEVEL_DEBUG, |
| 903 | "received EAP packet (code=%d id=%d len=%d) from STA: EAP Initiate type %u", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 904 | eap->code, eap->identifier, be_to_host16(eap->length), |
| 905 | type); |
| 906 | |
| 907 | wpabuf_free(sm->eap_if->eapRespData); |
| 908 | sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len); |
| 909 | sm->eapolEap = TRUE; |
| 910 | #endif /* CONFIG_ERP */ |
| 911 | } |
| 912 | |
| 913 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 914 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 915 | static const char * eap_code_str(u8 code) |
| 916 | { |
| 917 | switch (code) { |
| 918 | case EAP_CODE_REQUEST: |
| 919 | return "request"; |
| 920 | case EAP_CODE_RESPONSE: |
| 921 | return "response"; |
| 922 | case EAP_CODE_SUCCESS: |
| 923 | return "success"; |
| 924 | case EAP_CODE_FAILURE: |
| 925 | return "failure"; |
| 926 | case EAP_CODE_INITIATE: |
| 927 | return "initiate"; |
| 928 | case EAP_CODE_FINISH: |
| 929 | return "finish"; |
| 930 | default: |
| 931 | return "unknown"; |
| 932 | } |
| 933 | } |
| 934 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
| 935 | |
| 936 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 937 | /* Process incoming EAP packet from Supplicant */ |
| 938 | static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta, |
| 939 | u8 *buf, size_t len) |
| 940 | { |
| 941 | struct eap_hdr *eap; |
| 942 | u16 eap_len; |
| 943 | |
| 944 | if (len < sizeof(*eap)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 945 | wpa_printf(MSG_INFO, " too short EAP packet"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 946 | return; |
| 947 | } |
| 948 | |
| 949 | eap = (struct eap_hdr *) buf; |
| 950 | |
| 951 | eap_len = be_to_host16(eap->length); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 952 | wpa_printf(MSG_DEBUG, "EAP: code=%d (%s) identifier=%d length=%d", |
| 953 | eap->code, eap_code_str(eap->code), eap->identifier, |
| 954 | eap_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 955 | if (eap_len < sizeof(*eap)) { |
| 956 | wpa_printf(MSG_DEBUG, " Invalid EAP length"); |
| 957 | return; |
| 958 | } else if (eap_len > len) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 959 | wpa_printf(MSG_DEBUG, |
| 960 | " Too short frame to contain this EAP packet"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 961 | return; |
| 962 | } else if (eap_len < len) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 963 | wpa_printf(MSG_DEBUG, |
| 964 | " Ignoring %lu extra bytes after EAP packet", |
| 965 | (unsigned long) len - eap_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | switch (eap->code) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 969 | case EAP_CODE_RESPONSE: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 970 | handle_eap_response(hapd, sta, eap, eap_len); |
| 971 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 972 | case EAP_CODE_INITIATE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 973 | handle_eap_initiate(hapd, sta, eap, eap_len); |
| 974 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
| 978 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 979 | struct eapol_state_machine * |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 980 | ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta) |
| 981 | { |
| 982 | int flags = 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 983 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 984 | if (sta->flags & WLAN_STA_PREAUTH) |
| 985 | flags |= EAPOL_SM_PREAUTH; |
| 986 | if (sta->wpa_sm) { |
| 987 | flags |= EAPOL_SM_USES_WPA; |
| 988 | if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) |
| 989 | flags |= EAPOL_SM_FROM_PMKSA_CACHE; |
| 990 | } |
| 991 | return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 992 | sta->wps_ie, sta->p2p_ie, sta, |
| 993 | sta->identity, sta->radius_cui); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 997 | static void ieee802_1x_save_eapol(struct sta_info *sta, const u8 *buf, |
| 998 | size_t len) |
| 999 | { |
| 1000 | if (sta->pending_eapol_rx) { |
| 1001 | wpabuf_free(sta->pending_eapol_rx->buf); |
| 1002 | } else { |
| 1003 | sta->pending_eapol_rx = |
| 1004 | os_malloc(sizeof(*sta->pending_eapol_rx)); |
| 1005 | if (!sta->pending_eapol_rx) |
| 1006 | return; |
| 1007 | } |
| 1008 | |
| 1009 | sta->pending_eapol_rx->buf = wpabuf_alloc_copy(buf, len); |
| 1010 | if (!sta->pending_eapol_rx->buf) { |
| 1011 | os_free(sta->pending_eapol_rx); |
| 1012 | sta->pending_eapol_rx = NULL; |
| 1013 | return; |
| 1014 | } |
| 1015 | |
| 1016 | os_get_reltime(&sta->pending_eapol_rx->rx_time); |
| 1017 | } |
| 1018 | |
| 1019 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1020 | /** |
| 1021 | * ieee802_1x_receive - Process the EAPOL frames from the Supplicant |
| 1022 | * @hapd: hostapd BSS data |
| 1023 | * @sa: Source address (sender of the EAPOL frame) |
| 1024 | * @buf: EAPOL frame |
| 1025 | * @len: Length of buf in octets |
| 1026 | * |
| 1027 | * This function is called for each incoming EAPOL frame from the interface |
| 1028 | */ |
| 1029 | void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf, |
| 1030 | size_t len) |
| 1031 | { |
| 1032 | struct sta_info *sta; |
| 1033 | struct ieee802_1x_hdr *hdr; |
| 1034 | struct ieee802_1x_eapol_key *key; |
| 1035 | u16 datalen; |
| 1036 | struct rsn_pmksa_cache_entry *pmksa; |
| 1037 | int key_mgmt; |
| 1038 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1039 | if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1040 | !hapd->conf->wps_state) |
| 1041 | return; |
| 1042 | |
| 1043 | wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR, |
| 1044 | (unsigned long) len, MAC2STR(sa)); |
| 1045 | sta = ap_get_sta(hapd, sa); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1046 | if (!sta || (!(sta->flags & (WLAN_STA_ASSOC | WLAN_STA_PREAUTH)) && |
| 1047 | !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED))) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1048 | wpa_printf(MSG_DEBUG, |
| 1049 | "IEEE 802.1X data frame from not associated/Pre-authenticating STA"); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 1050 | |
| 1051 | if (sta && (sta->flags & WLAN_STA_AUTH)) { |
| 1052 | wpa_printf(MSG_DEBUG, "Saving EAPOL frame from " MACSTR |
| 1053 | " for later use", MAC2STR(sta->addr)); |
| 1054 | ieee802_1x_save_eapol(sta, buf, len); |
| 1055 | } |
| 1056 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1057 | return; |
| 1058 | } |
| 1059 | |
| 1060 | if (len < sizeof(*hdr)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1061 | wpa_printf(MSG_INFO, " too short IEEE 802.1X packet"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1062 | return; |
| 1063 | } |
| 1064 | |
| 1065 | hdr = (struct ieee802_1x_hdr *) buf; |
| 1066 | datalen = be_to_host16(hdr->length); |
| 1067 | wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d", |
| 1068 | hdr->version, hdr->type, datalen); |
| 1069 | |
| 1070 | if (len - sizeof(*hdr) < datalen) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1071 | wpa_printf(MSG_INFO, |
| 1072 | " frame too short for this IEEE 802.1X packet"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1073 | if (sta->eapol_sm) |
| 1074 | sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++; |
| 1075 | return; |
| 1076 | } |
| 1077 | if (len - sizeof(*hdr) > datalen) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1078 | wpa_printf(MSG_DEBUG, |
| 1079 | " ignoring %lu extra octets after IEEE 802.1X packet", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1080 | (unsigned long) len - sizeof(*hdr) - datalen); |
| 1081 | } |
| 1082 | |
| 1083 | if (sta->eapol_sm) { |
| 1084 | sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version; |
| 1085 | sta->eapol_sm->dot1xAuthEapolFramesRx++; |
| 1086 | } |
| 1087 | |
| 1088 | key = (struct ieee802_1x_eapol_key *) (hdr + 1); |
| 1089 | if (datalen >= sizeof(struct ieee802_1x_eapol_key) && |
| 1090 | hdr->type == IEEE802_1X_TYPE_EAPOL_KEY && |
| 1091 | (key->type == EAPOL_KEY_TYPE_WPA || |
| 1092 | key->type == EAPOL_KEY_TYPE_RSN)) { |
| 1093 | wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr, |
| 1094 | sizeof(*hdr) + datalen); |
| 1095 | return; |
| 1096 | } |
| 1097 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1098 | if (!hapd->conf->ieee802_1x && !hapd->conf->osen && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1099 | !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1100 | wpa_printf(MSG_DEBUG, |
| 1101 | "IEEE 802.1X: Ignore EAPOL message - 802.1X not enabled and WPS not used"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1102 | return; |
| 1103 | } |
| 1104 | |
| 1105 | key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1106 | if (key_mgmt != -1 && |
| 1107 | (wpa_key_mgmt_wpa_psk(key_mgmt) || key_mgmt == WPA_KEY_MGMT_OWE || |
| 1108 | key_mgmt == WPA_KEY_MGMT_DPP)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1109 | wpa_printf(MSG_DEBUG, |
| 1110 | "IEEE 802.1X: Ignore EAPOL message - STA is using PSK"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1111 | return; |
| 1112 | } |
| 1113 | |
| 1114 | if (!sta->eapol_sm) { |
| 1115 | sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta); |
| 1116 | if (!sta->eapol_sm) |
| 1117 | return; |
| 1118 | |
| 1119 | #ifdef CONFIG_WPS |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1120 | if (!hapd->conf->ieee802_1x && hapd->conf->wps_state) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1121 | u32 wflags = sta->flags & (WLAN_STA_WPS | |
| 1122 | WLAN_STA_WPS2 | |
| 1123 | WLAN_STA_MAYBE_WPS); |
| 1124 | if (wflags == WLAN_STA_MAYBE_WPS || |
| 1125 | wflags == (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) { |
| 1126 | /* |
| 1127 | * Delay EAPOL frame transmission until a |
| 1128 | * possible WPS STA initiates the handshake |
| 1129 | * with EAPOL-Start. Only allow the wait to be |
| 1130 | * skipped if the STA is known to support WPS |
| 1131 | * 2.0. |
| 1132 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1133 | wpa_printf(MSG_DEBUG, |
| 1134 | "WPS: Do not start EAPOL until EAPOL-Start is received"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1135 | sta->eapol_sm->flags |= EAPOL_SM_WAIT_START; |
| 1136 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1137 | } |
| 1138 | #endif /* CONFIG_WPS */ |
| 1139 | |
| 1140 | sta->eapol_sm->eap_if->portEnabled = TRUE; |
| 1141 | } |
| 1142 | |
| 1143 | /* since we support version 1, we can ignore version field and proceed |
| 1144 | * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */ |
| 1145 | /* TODO: actually, we are not version 1 anymore.. However, Version 2 |
| 1146 | * does not change frame contents, so should be ok to process frames |
| 1147 | * more or less identically. Some changes might be needed for |
| 1148 | * verification of fields. */ |
| 1149 | |
| 1150 | switch (hdr->type) { |
| 1151 | case IEEE802_1X_TYPE_EAP_PACKET: |
| 1152 | handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen); |
| 1153 | break; |
| 1154 | |
| 1155 | case IEEE802_1X_TYPE_EAPOL_START: |
| 1156 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1157 | HOSTAPD_LEVEL_DEBUG, |
| 1158 | "received EAPOL-Start from STA"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1159 | sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START; |
| 1160 | pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm); |
| 1161 | if (pmksa) { |
| 1162 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1163 | HOSTAPD_LEVEL_DEBUG, |
| 1164 | "cached PMKSA available - ignore it since STA sent EAPOL-Start"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1165 | wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa); |
| 1166 | } |
| 1167 | sta->eapol_sm->eapolStart = TRUE; |
| 1168 | sta->eapol_sm->dot1xAuthEapolStartFramesRx++; |
| 1169 | eap_server_clear_identity(sta->eapol_sm->eap); |
| 1170 | wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL); |
| 1171 | break; |
| 1172 | |
| 1173 | case IEEE802_1X_TYPE_EAPOL_LOGOFF: |
| 1174 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1175 | HOSTAPD_LEVEL_DEBUG, |
| 1176 | "received EAPOL-Logoff from STA"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1177 | sta->acct_terminate_cause = |
| 1178 | RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 1179 | accounting_sta_stop(hapd, sta); |
| 1180 | sta->eapol_sm->eapolLogoff = TRUE; |
| 1181 | sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++; |
| 1182 | eap_server_clear_identity(sta->eapol_sm->eap); |
| 1183 | break; |
| 1184 | |
| 1185 | case IEEE802_1X_TYPE_EAPOL_KEY: |
| 1186 | wpa_printf(MSG_DEBUG, " EAPOL-Key"); |
| 1187 | if (!ap_sta_is_authorized(sta)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1188 | wpa_printf(MSG_DEBUG, |
| 1189 | " Dropped key data from unauthorized Supplicant"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1190 | break; |
| 1191 | } |
| 1192 | break; |
| 1193 | |
| 1194 | case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT: |
| 1195 | wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert"); |
| 1196 | /* TODO: implement support for this; show data */ |
| 1197 | break; |
| 1198 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1199 | #ifdef CONFIG_MACSEC |
| 1200 | case IEEE802_1X_TYPE_EAPOL_MKA: |
| 1201 | wpa_printf(MSG_EXCESSIVE, |
| 1202 | "EAPOL type %d will be handled by MKA", hdr->type); |
| 1203 | break; |
| 1204 | #endif /* CONFIG_MACSEC */ |
| 1205 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1206 | default: |
| 1207 | wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type"); |
| 1208 | sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++; |
| 1209 | break; |
| 1210 | } |
| 1211 | |
| 1212 | eapol_auth_step(sta->eapol_sm); |
| 1213 | } |
| 1214 | |
| 1215 | |
| 1216 | /** |
| 1217 | * ieee802_1x_new_station - Start IEEE 802.1X authentication |
| 1218 | * @hapd: hostapd BSS data |
| 1219 | * @sta: The station |
| 1220 | * |
| 1221 | * This function is called to start IEEE 802.1X authentication when a new |
| 1222 | * station completes IEEE 802.11 association. |
| 1223 | */ |
| 1224 | void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta) |
| 1225 | { |
| 1226 | struct rsn_pmksa_cache_entry *pmksa; |
| 1227 | int reassoc = 1; |
| 1228 | int force_1x = 0; |
| 1229 | int key_mgmt; |
| 1230 | |
| 1231 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1232 | if (hapd->conf->wps_state && |
| 1233 | ((hapd->conf->wpa && (sta->flags & WLAN_STA_MAYBE_WPS)) || |
| 1234 | (sta->flags & WLAN_STA_WPS))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1235 | /* |
| 1236 | * Need to enable IEEE 802.1X/EAPOL state machines for possible |
| 1237 | * WPS handshake even if IEEE 802.1X/EAPOL is not used for |
| 1238 | * authentication in this BSS. |
| 1239 | */ |
| 1240 | force_1x = 1; |
| 1241 | } |
| 1242 | #endif /* CONFIG_WPS */ |
| 1243 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1244 | if (!force_1x && !hapd->conf->ieee802_1x && !hapd->conf->osen) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1245 | wpa_printf(MSG_DEBUG, |
| 1246 | "IEEE 802.1X: Ignore STA - 802.1X not enabled or forced for WPS"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1247 | /* |
| 1248 | * Clear any possible EAPOL authenticator state to support |
| 1249 | * reassociation change from WPS to PSK. |
| 1250 | */ |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1251 | ieee802_1x_free_station(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1252 | return; |
| 1253 | } |
| 1254 | |
| 1255 | key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1256 | if (key_mgmt != -1 && |
| 1257 | (wpa_key_mgmt_wpa_psk(key_mgmt) || key_mgmt == WPA_KEY_MGMT_OWE || |
| 1258 | key_mgmt == WPA_KEY_MGMT_DPP)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1259 | wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - using PSK"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1260 | /* |
| 1261 | * Clear any possible EAPOL authenticator state to support |
| 1262 | * reassociation change from WPA-EAP to PSK. |
| 1263 | */ |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1264 | ieee802_1x_free_station(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1265 | return; |
| 1266 | } |
| 1267 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1268 | if (!sta->eapol_sm) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1269 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
| 1270 | HOSTAPD_LEVEL_DEBUG, "start authentication"); |
| 1271 | sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1272 | if (!sta->eapol_sm) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1273 | hostapd_logger(hapd, sta->addr, |
| 1274 | HOSTAPD_MODULE_IEEE8021X, |
| 1275 | HOSTAPD_LEVEL_INFO, |
| 1276 | "failed to allocate state machine"); |
| 1277 | return; |
| 1278 | } |
| 1279 | reassoc = 0; |
| 1280 | } |
| 1281 | |
| 1282 | #ifdef CONFIG_WPS |
| 1283 | sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1284 | if (!hapd->conf->ieee802_1x && hapd->conf->wps_state && |
| 1285 | !(sta->flags & WLAN_STA_WPS2)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1286 | /* |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1287 | * Delay EAPOL frame transmission until a possible WPS STA |
| 1288 | * initiates the handshake with EAPOL-Start. Only allow the |
| 1289 | * wait to be skipped if the STA is known to support WPS 2.0. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1290 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1291 | wpa_printf(MSG_DEBUG, |
| 1292 | "WPS: Do not start EAPOL until EAPOL-Start is received"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1293 | sta->eapol_sm->flags |= EAPOL_SM_WAIT_START; |
| 1294 | } |
| 1295 | #endif /* CONFIG_WPS */ |
| 1296 | |
| 1297 | sta->eapol_sm->eap_if->portEnabled = TRUE; |
| 1298 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1299 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1300 | if (sta->auth_alg == WLAN_AUTH_FT) { |
| 1301 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
| 1302 | HOSTAPD_LEVEL_DEBUG, |
| 1303 | "PMK from FT - skip IEEE 802.1X/EAP"); |
| 1304 | /* Setup EAPOL state machines to already authenticated state |
| 1305 | * because of existing FT information from R0KH. */ |
| 1306 | sta->eapol_sm->keyRun = TRUE; |
| 1307 | sta->eapol_sm->eap_if->eapKeyAvailable = TRUE; |
| 1308 | sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING; |
| 1309 | sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS; |
| 1310 | sta->eapol_sm->authSuccess = TRUE; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1311 | sta->eapol_sm->authFail = FALSE; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1312 | sta->eapol_sm->portValid = TRUE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1313 | if (sta->eapol_sm->eap) |
| 1314 | eap_sm_notify_cached(sta->eapol_sm->eap); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1315 | ap_sta_bind_vlan(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1316 | return; |
| 1317 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1318 | #endif /* CONFIG_IEEE80211R_AP */ |
| 1319 | |
| 1320 | #ifdef CONFIG_FILS |
| 1321 | if (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 1322 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 1323 | sta->auth_alg == WLAN_AUTH_FILS_PK) { |
| 1324 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
| 1325 | HOSTAPD_LEVEL_DEBUG, |
| 1326 | "PMK from FILS - skip IEEE 802.1X/EAP"); |
| 1327 | /* Setup EAPOL state machines to already authenticated state |
| 1328 | * because of existing FILS information. */ |
| 1329 | sta->eapol_sm->keyRun = TRUE; |
| 1330 | sta->eapol_sm->eap_if->eapKeyAvailable = TRUE; |
| 1331 | sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING; |
| 1332 | sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS; |
| 1333 | sta->eapol_sm->authSuccess = TRUE; |
| 1334 | sta->eapol_sm->authFail = FALSE; |
| 1335 | sta->eapol_sm->portValid = TRUE; |
| 1336 | if (sta->eapol_sm->eap) |
| 1337 | eap_sm_notify_cached(sta->eapol_sm->eap); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1338 | wpa_auth_set_ptk_rekey_timer(sta->wpa_sm); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1339 | return; |
| 1340 | } |
| 1341 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1342 | |
| 1343 | pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm); |
| 1344 | if (pmksa) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1345 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
| 1346 | HOSTAPD_LEVEL_DEBUG, |
| 1347 | "PMK from PMKSA cache - skip IEEE 802.1X/EAP"); |
| 1348 | /* Setup EAPOL state machines to already authenticated state |
| 1349 | * because of existing PMKSA information in the cache. */ |
| 1350 | sta->eapol_sm->keyRun = TRUE; |
| 1351 | sta->eapol_sm->eap_if->eapKeyAvailable = TRUE; |
| 1352 | sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING; |
| 1353 | sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS; |
| 1354 | sta->eapol_sm->authSuccess = TRUE; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1355 | sta->eapol_sm->authFail = FALSE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1356 | if (sta->eapol_sm->eap) |
| 1357 | eap_sm_notify_cached(sta->eapol_sm->eap); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1358 | pmksa_cache_to_eapol_data(hapd, pmksa, sta->eapol_sm); |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1359 | ap_sta_bind_vlan(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1360 | } else { |
| 1361 | if (reassoc) { |
| 1362 | /* |
| 1363 | * Force EAPOL state machines to start |
| 1364 | * re-authentication without having to wait for the |
| 1365 | * Supplicant to send EAPOL-Start. |
| 1366 | */ |
| 1367 | sta->eapol_sm->reAuthenticate = TRUE; |
| 1368 | } |
| 1369 | eapol_auth_step(sta->eapol_sm); |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1374 | void ieee802_1x_free_station(struct hostapd_data *hapd, struct sta_info *sta) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1375 | { |
| 1376 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 1377 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1378 | #ifdef CONFIG_HS20 |
| 1379 | eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta); |
| 1380 | #endif /* CONFIG_HS20 */ |
| 1381 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 1382 | if (sta->pending_eapol_rx) { |
| 1383 | wpabuf_free(sta->pending_eapol_rx->buf); |
| 1384 | os_free(sta->pending_eapol_rx); |
| 1385 | sta->pending_eapol_rx = NULL; |
| 1386 | } |
| 1387 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1388 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1389 | return; |
| 1390 | |
| 1391 | sta->eapol_sm = NULL; |
| 1392 | |
| 1393 | #ifndef CONFIG_NO_RADIUS |
| 1394 | radius_msg_free(sm->last_recv_radius); |
| 1395 | radius_free_class(&sm->radius_class); |
| 1396 | #endif /* CONFIG_NO_RADIUS */ |
| 1397 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1398 | eapol_auth_free(sm); |
| 1399 | } |
| 1400 | |
| 1401 | |
| 1402 | #ifndef CONFIG_NO_RADIUS |
| 1403 | static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd, |
| 1404 | struct sta_info *sta) |
| 1405 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1406 | struct wpabuf *eap; |
| 1407 | const struct eap_hdr *hdr; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1408 | int eap_type = -1; |
| 1409 | char buf[64]; |
| 1410 | struct radius_msg *msg; |
| 1411 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 1412 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1413 | if (!sm || !sm->last_recv_radius) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1414 | if (sm) |
| 1415 | sm->eap_if->aaaEapNoReq = TRUE; |
| 1416 | return; |
| 1417 | } |
| 1418 | |
| 1419 | msg = sm->last_recv_radius; |
| 1420 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1421 | eap = radius_msg_get_eap(msg); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1422 | if (!eap) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1423 | /* RFC 3579, Chap. 2.6.3: |
| 1424 | * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message |
| 1425 | * attribute */ |
| 1426 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1427 | HOSTAPD_LEVEL_WARNING, |
| 1428 | "could not extract EAP-Message from RADIUS message"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1429 | sm->eap_if->aaaEapNoReq = TRUE; |
| 1430 | return; |
| 1431 | } |
| 1432 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1433 | if (wpabuf_len(eap) < sizeof(*hdr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1434 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1435 | HOSTAPD_LEVEL_WARNING, |
| 1436 | "too short EAP packet received from authentication server"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1437 | wpabuf_free(eap); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1438 | sm->eap_if->aaaEapNoReq = TRUE; |
| 1439 | return; |
| 1440 | } |
| 1441 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1442 | if (wpabuf_len(eap) > sizeof(*hdr)) |
| 1443 | eap_type = (wpabuf_head_u8(eap))[sizeof(*hdr)]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1444 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1445 | hdr = wpabuf_head(eap); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1446 | switch (hdr->code) { |
| 1447 | case EAP_CODE_REQUEST: |
| 1448 | if (eap_type >= 0) |
| 1449 | sm->eap_type_authsrv = eap_type; |
| 1450 | os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)", |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1451 | eap_server_get_name(0, eap_type), eap_type); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1452 | break; |
| 1453 | case EAP_CODE_RESPONSE: |
| 1454 | os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)", |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1455 | eap_server_get_name(0, eap_type), eap_type); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1456 | break; |
| 1457 | case EAP_CODE_SUCCESS: |
| 1458 | os_strlcpy(buf, "EAP Success", sizeof(buf)); |
| 1459 | break; |
| 1460 | case EAP_CODE_FAILURE: |
| 1461 | os_strlcpy(buf, "EAP Failure", sizeof(buf)); |
| 1462 | break; |
| 1463 | default: |
| 1464 | os_strlcpy(buf, "unknown EAP code", sizeof(buf)); |
| 1465 | break; |
| 1466 | } |
| 1467 | buf[sizeof(buf) - 1] = '\0'; |
| 1468 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1469 | HOSTAPD_LEVEL_DEBUG, |
| 1470 | "decapsulated EAP packet (code=%d id=%d len=%d) from RADIUS server: %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1471 | hdr->code, hdr->identifier, be_to_host16(hdr->length), |
| 1472 | buf); |
| 1473 | sm->eap_if->aaaEapReq = TRUE; |
| 1474 | |
| 1475 | wpabuf_free(sm->eap_if->aaaEapReqData); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1476 | sm->eap_if->aaaEapReqData = eap; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | |
| 1480 | static void ieee802_1x_get_keys(struct hostapd_data *hapd, |
| 1481 | struct sta_info *sta, struct radius_msg *msg, |
| 1482 | struct radius_msg *req, |
| 1483 | const u8 *shared_secret, |
| 1484 | size_t shared_secret_len) |
| 1485 | { |
| 1486 | struct radius_ms_mppe_keys *keys; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1487 | u8 *buf; |
| 1488 | size_t len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1489 | struct eapol_state_machine *sm = sta->eapol_sm; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1490 | |
| 1491 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1492 | return; |
| 1493 | |
| 1494 | keys = radius_msg_get_ms_keys(msg, req, shared_secret, |
| 1495 | shared_secret_len); |
| 1496 | |
| 1497 | if (keys && keys->send && keys->recv) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1498 | len = keys->send_len + keys->recv_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1499 | wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key", |
| 1500 | keys->send, keys->send_len); |
| 1501 | wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key", |
| 1502 | keys->recv, keys->recv_len); |
| 1503 | |
| 1504 | os_free(sm->eap_if->aaaEapKeyData); |
| 1505 | sm->eap_if->aaaEapKeyData = os_malloc(len); |
| 1506 | if (sm->eap_if->aaaEapKeyData) { |
| 1507 | os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv, |
| 1508 | keys->recv_len); |
| 1509 | os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len, |
| 1510 | keys->send, keys->send_len); |
| 1511 | sm->eap_if->aaaEapKeyDataLen = len; |
| 1512 | sm->eap_if->aaaEapKeyAvailable = TRUE; |
| 1513 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1514 | } else { |
| 1515 | wpa_printf(MSG_DEBUG, |
| 1516 | "MS-MPPE: 1x_get_keys, could not get keys: %p send: %p recv: %p", |
| 1517 | keys, keys ? keys->send : NULL, |
| 1518 | keys ? keys->recv : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | if (keys) { |
| 1522 | os_free(keys->send); |
| 1523 | os_free(keys->recv); |
| 1524 | os_free(keys); |
| 1525 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1526 | |
| 1527 | if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_EAP_KEY_NAME, &buf, &len, |
| 1528 | NULL) == 0) { |
| 1529 | os_free(sm->eap_if->eapSessionId); |
| 1530 | sm->eap_if->eapSessionId = os_memdup(buf, len); |
| 1531 | if (sm->eap_if->eapSessionId) { |
| 1532 | sm->eap_if->eapSessionIdLen = len; |
| 1533 | wpa_hexdump(MSG_DEBUG, "EAP-Key Name", |
| 1534 | sm->eap_if->eapSessionId, |
| 1535 | sm->eap_if->eapSessionIdLen); |
| 1536 | } |
| 1537 | } else { |
| 1538 | sm->eap_if->eapSessionIdLen = 0; |
| 1539 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | |
| 1543 | static void ieee802_1x_store_radius_class(struct hostapd_data *hapd, |
| 1544 | struct sta_info *sta, |
| 1545 | struct radius_msg *msg) |
| 1546 | { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 1547 | u8 *attr_class; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1548 | size_t class_len; |
| 1549 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 1550 | int count, i; |
| 1551 | struct radius_attr_data *nclass; |
| 1552 | size_t nclass_count; |
| 1553 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1554 | if (!hapd->conf->radius->acct_server || !hapd->radius || !sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1555 | return; |
| 1556 | |
| 1557 | radius_free_class(&sm->radius_class); |
| 1558 | count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1); |
| 1559 | if (count <= 0) |
| 1560 | return; |
| 1561 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1562 | nclass = os_calloc(count, sizeof(struct radius_attr_data)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1563 | if (!nclass) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1564 | return; |
| 1565 | |
| 1566 | nclass_count = 0; |
| 1567 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 1568 | attr_class = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1569 | for (i = 0; i < count; i++) { |
| 1570 | do { |
| 1571 | if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 1572 | &attr_class, &class_len, |
| 1573 | attr_class) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1574 | i = count; |
| 1575 | break; |
| 1576 | } |
| 1577 | } while (class_len < 1); |
| 1578 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1579 | nclass[nclass_count].data = os_memdup(attr_class, class_len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1580 | if (!nclass[nclass_count].data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1581 | break; |
| 1582 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1583 | nclass[nclass_count].len = class_len; |
| 1584 | nclass_count++; |
| 1585 | } |
| 1586 | |
| 1587 | sm->radius_class.attr = nclass; |
| 1588 | sm->radius_class.count = nclass_count; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1589 | wpa_printf(MSG_DEBUG, |
| 1590 | "IEEE 802.1X: Stored %lu RADIUS Class attributes for " |
| 1591 | MACSTR, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1592 | (unsigned long) sm->radius_class.count, |
| 1593 | MAC2STR(sta->addr)); |
| 1594 | } |
| 1595 | |
| 1596 | |
| 1597 | /* Update sta->identity based on User-Name attribute in Access-Accept */ |
| 1598 | static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd, |
| 1599 | struct sta_info *sta, |
| 1600 | struct radius_msg *msg) |
| 1601 | { |
| 1602 | u8 *buf, *identity; |
| 1603 | size_t len; |
| 1604 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 1605 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1606 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1607 | return; |
| 1608 | |
| 1609 | if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len, |
| 1610 | NULL) < 0) |
| 1611 | return; |
| 1612 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 1613 | identity = (u8 *) dup_binstr(buf, len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1614 | if (!identity) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1615 | return; |
| 1616 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1617 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1618 | HOSTAPD_LEVEL_DEBUG, |
| 1619 | "old identity '%s' updated with User-Name from Access-Accept '%s'", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1620 | sm->identity ? (char *) sm->identity : "N/A", |
| 1621 | (char *) identity); |
| 1622 | |
| 1623 | os_free(sm->identity); |
| 1624 | sm->identity = identity; |
| 1625 | sm->identity_len = len; |
| 1626 | } |
| 1627 | |
| 1628 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1629 | /* Update CUI based on Chargeable-User-Identity attribute in Access-Accept */ |
| 1630 | static void ieee802_1x_update_sta_cui(struct hostapd_data *hapd, |
| 1631 | struct sta_info *sta, |
| 1632 | struct radius_msg *msg) |
| 1633 | { |
| 1634 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 1635 | struct wpabuf *cui; |
| 1636 | u8 *buf; |
| 1637 | size_t len; |
| 1638 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1639 | if (!sm) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1640 | return; |
| 1641 | |
| 1642 | if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY, |
| 1643 | &buf, &len, NULL) < 0) |
| 1644 | return; |
| 1645 | |
| 1646 | cui = wpabuf_alloc_copy(buf, len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1647 | if (!cui) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1648 | return; |
| 1649 | |
| 1650 | wpabuf_free(sm->radius_cui); |
| 1651 | sm->radius_cui = cui; |
| 1652 | } |
| 1653 | |
| 1654 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1655 | #ifdef CONFIG_HS20 |
| 1656 | |
| 1657 | static void ieee802_1x_hs20_sub_rem(struct sta_info *sta, u8 *pos, size_t len) |
| 1658 | { |
| 1659 | sta->remediation = 1; |
| 1660 | os_free(sta->remediation_url); |
| 1661 | if (len > 2) { |
| 1662 | sta->remediation_url = os_malloc(len); |
| 1663 | if (!sta->remediation_url) |
| 1664 | return; |
| 1665 | sta->remediation_method = pos[0]; |
| 1666 | os_memcpy(sta->remediation_url, pos + 1, len - 1); |
| 1667 | sta->remediation_url[len - 1] = '\0'; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1668 | wpa_printf(MSG_DEBUG, |
| 1669 | "HS 2.0: Subscription remediation needed for " |
| 1670 | MACSTR " - server method %u URL %s", |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1671 | MAC2STR(sta->addr), sta->remediation_method, |
| 1672 | sta->remediation_url); |
| 1673 | } else { |
| 1674 | sta->remediation_url = NULL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1675 | wpa_printf(MSG_DEBUG, |
| 1676 | "HS 2.0: Subscription remediation needed for " |
| 1677 | MACSTR, MAC2STR(sta->addr)); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1678 | } |
| 1679 | /* TODO: assign the STA into remediation VLAN or add filtering */ |
| 1680 | } |
| 1681 | |
| 1682 | |
| 1683 | static void ieee802_1x_hs20_deauth_req(struct hostapd_data *hapd, |
| 1684 | struct sta_info *sta, u8 *pos, |
| 1685 | size_t len) |
| 1686 | { |
| 1687 | if (len < 3) |
| 1688 | return; /* Malformed information */ |
| 1689 | sta->hs20_deauth_requested = 1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1690 | wpa_printf(MSG_DEBUG, |
| 1691 | "HS 2.0: Deauthentication request - Code %u Re-auth Delay %u", |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1692 | *pos, WPA_GET_LE16(pos + 1)); |
| 1693 | wpabuf_free(sta->hs20_deauth_req); |
| 1694 | sta->hs20_deauth_req = wpabuf_alloc(len + 1); |
| 1695 | if (sta->hs20_deauth_req) { |
| 1696 | wpabuf_put_data(sta->hs20_deauth_req, pos, 3); |
| 1697 | wpabuf_put_u8(sta->hs20_deauth_req, len - 3); |
| 1698 | wpabuf_put_data(sta->hs20_deauth_req, pos + 3, len - 3); |
| 1699 | } |
| 1700 | ap_sta_session_timeout(hapd, sta, hapd->conf->hs20_deauth_req_timeout); |
| 1701 | } |
| 1702 | |
| 1703 | |
| 1704 | static void ieee802_1x_hs20_session_info(struct hostapd_data *hapd, |
| 1705 | struct sta_info *sta, u8 *pos, |
| 1706 | size_t len, int session_timeout) |
| 1707 | { |
| 1708 | unsigned int swt; |
| 1709 | int warning_time, beacon_int; |
| 1710 | |
| 1711 | if (len < 1) |
| 1712 | return; /* Malformed information */ |
| 1713 | os_free(sta->hs20_session_info_url); |
| 1714 | sta->hs20_session_info_url = os_malloc(len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1715 | if (!sta->hs20_session_info_url) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1716 | return; |
| 1717 | swt = pos[0]; |
| 1718 | os_memcpy(sta->hs20_session_info_url, pos + 1, len - 1); |
| 1719 | sta->hs20_session_info_url[len - 1] = '\0'; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1720 | wpa_printf(MSG_DEBUG, |
| 1721 | "HS 2.0: Session Information URL='%s' SWT=%u (session_timeout=%d)", |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1722 | sta->hs20_session_info_url, swt, session_timeout); |
| 1723 | if (session_timeout < 0) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1724 | wpa_printf(MSG_DEBUG, |
| 1725 | "HS 2.0: No Session-Timeout set - ignore session info URL"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1726 | return; |
| 1727 | } |
| 1728 | if (swt == 255) |
| 1729 | swt = 1; /* Use one minute as the AP selected value */ |
| 1730 | |
| 1731 | if ((unsigned int) session_timeout < swt * 60) |
| 1732 | warning_time = 0; |
| 1733 | else |
| 1734 | warning_time = session_timeout - swt * 60; |
| 1735 | |
| 1736 | beacon_int = hapd->iconf->beacon_int; |
| 1737 | if (beacon_int < 1) |
| 1738 | beacon_int = 100; /* best guess */ |
| 1739 | sta->hs20_disassoc_timer = swt * 60 * 1000 / beacon_int * 125 / 128; |
| 1740 | if (sta->hs20_disassoc_timer > 65535) |
| 1741 | sta->hs20_disassoc_timer = 65535; |
| 1742 | |
| 1743 | ap_sta_session_warning_timeout(hapd, sta, warning_time); |
| 1744 | } |
| 1745 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1746 | |
| 1747 | static void ieee802_1x_hs20_t_c_filtering(struct hostapd_data *hapd, |
| 1748 | struct sta_info *sta, u8 *pos, |
| 1749 | size_t len) |
| 1750 | { |
| 1751 | if (len < 4) |
| 1752 | return; /* Malformed information */ |
| 1753 | wpa_printf(MSG_DEBUG, |
| 1754 | "HS 2.0: Terms and Conditions filtering %02x %02x %02x %02x", |
| 1755 | pos[0], pos[1], pos[2], pos[3]); |
| 1756 | hs20_t_c_filtering(hapd, sta, pos[0] & BIT(0)); |
| 1757 | } |
| 1758 | |
| 1759 | |
| 1760 | static void ieee802_1x_hs20_t_c_url(struct hostapd_data *hapd, |
| 1761 | struct sta_info *sta, u8 *pos, size_t len) |
| 1762 | { |
| 1763 | os_free(sta->t_c_url); |
| 1764 | sta->t_c_url = os_malloc(len + 1); |
| 1765 | if (!sta->t_c_url) |
| 1766 | return; |
| 1767 | os_memcpy(sta->t_c_url, pos, len); |
| 1768 | sta->t_c_url[len] = '\0'; |
| 1769 | wpa_printf(MSG_DEBUG, |
| 1770 | "HS 2.0: Terms and Conditions URL %s", sta->t_c_url); |
| 1771 | } |
| 1772 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1773 | #endif /* CONFIG_HS20 */ |
| 1774 | |
| 1775 | |
| 1776 | static void ieee802_1x_check_hs20(struct hostapd_data *hapd, |
| 1777 | struct sta_info *sta, |
| 1778 | struct radius_msg *msg, |
| 1779 | int session_timeout) |
| 1780 | { |
| 1781 | #ifdef CONFIG_HS20 |
| 1782 | u8 *buf, *pos, *end, type, sublen; |
| 1783 | size_t len; |
| 1784 | |
| 1785 | buf = NULL; |
| 1786 | sta->remediation = 0; |
| 1787 | sta->hs20_deauth_requested = 0; |
| 1788 | |
| 1789 | for (;;) { |
| 1790 | if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_VENDOR_SPECIFIC, |
| 1791 | &buf, &len, buf) < 0) |
| 1792 | break; |
| 1793 | if (len < 6) |
| 1794 | continue; |
| 1795 | pos = buf; |
| 1796 | end = buf + len; |
| 1797 | if (WPA_GET_BE32(pos) != RADIUS_VENDOR_ID_WFA) |
| 1798 | continue; |
| 1799 | pos += 4; |
| 1800 | |
| 1801 | type = *pos++; |
| 1802 | sublen = *pos++; |
| 1803 | if (sublen < 2) |
| 1804 | continue; /* invalid length */ |
| 1805 | sublen -= 2; /* skip header */ |
| 1806 | if (pos + sublen > end) |
| 1807 | continue; /* invalid WFA VSA */ |
| 1808 | |
| 1809 | switch (type) { |
| 1810 | case RADIUS_VENDOR_ATTR_WFA_HS20_SUBSCR_REMEDIATION: |
| 1811 | ieee802_1x_hs20_sub_rem(sta, pos, sublen); |
| 1812 | break; |
| 1813 | case RADIUS_VENDOR_ATTR_WFA_HS20_DEAUTH_REQ: |
| 1814 | ieee802_1x_hs20_deauth_req(hapd, sta, pos, sublen); |
| 1815 | break; |
| 1816 | case RADIUS_VENDOR_ATTR_WFA_HS20_SESSION_INFO_URL: |
| 1817 | ieee802_1x_hs20_session_info(hapd, sta, pos, sublen, |
| 1818 | session_timeout); |
| 1819 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1820 | case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILTERING: |
| 1821 | ieee802_1x_hs20_t_c_filtering(hapd, sta, pos, sublen); |
| 1822 | break; |
| 1823 | case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_URL: |
| 1824 | ieee802_1x_hs20_t_c_url(hapd, sta, pos, sublen); |
| 1825 | break; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1826 | } |
| 1827 | } |
| 1828 | #endif /* CONFIG_HS20 */ |
| 1829 | } |
| 1830 | |
| 1831 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1832 | struct sta_id_search { |
| 1833 | u8 identifier; |
| 1834 | struct eapol_state_machine *sm; |
| 1835 | }; |
| 1836 | |
| 1837 | |
| 1838 | static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd, |
| 1839 | struct sta_info *sta, |
| 1840 | void *ctx) |
| 1841 | { |
| 1842 | struct sta_id_search *id_search = ctx; |
| 1843 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 1844 | |
| 1845 | if (sm && sm->radius_identifier >= 0 && |
| 1846 | sm->radius_identifier == id_search->identifier) { |
| 1847 | id_search->sm = sm; |
| 1848 | return 1; |
| 1849 | } |
| 1850 | return 0; |
| 1851 | } |
| 1852 | |
| 1853 | |
| 1854 | static struct eapol_state_machine * |
| 1855 | ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier) |
| 1856 | { |
| 1857 | struct sta_id_search id_search; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1858 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1859 | id_search.identifier = identifier; |
| 1860 | id_search.sm = NULL; |
| 1861 | ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search); |
| 1862 | return id_search.sm; |
| 1863 | } |
| 1864 | |
| 1865 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1866 | #ifndef CONFIG_NO_VLAN |
| 1867 | static int ieee802_1x_update_vlan(struct radius_msg *msg, |
| 1868 | struct hostapd_data *hapd, |
| 1869 | struct sta_info *sta) |
| 1870 | { |
| 1871 | struct vlan_description vlan_desc; |
| 1872 | |
| 1873 | os_memset(&vlan_desc, 0, sizeof(vlan_desc)); |
| 1874 | vlan_desc.notempty = !!radius_msg_get_vlanid(msg, &vlan_desc.untagged, |
| 1875 | MAX_NUM_TAGGED_VLAN, |
| 1876 | vlan_desc.tagged); |
| 1877 | |
| 1878 | if (vlan_desc.notempty && |
| 1879 | !hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) { |
| 1880 | sta->eapol_sm->authFail = TRUE; |
| 1881 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
| 1882 | HOSTAPD_LEVEL_INFO, |
| 1883 | "Invalid VLAN %d%s received from RADIUS server", |
| 1884 | vlan_desc.untagged, |
| 1885 | vlan_desc.tagged[0] ? "+" : ""); |
| 1886 | os_memset(&vlan_desc, 0, sizeof(vlan_desc)); |
| 1887 | ap_sta_set_vlan(hapd, sta, &vlan_desc); |
| 1888 | return -1; |
| 1889 | } |
| 1890 | |
| 1891 | if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_REQUIRED && |
| 1892 | !vlan_desc.notempty) { |
| 1893 | sta->eapol_sm->authFail = TRUE; |
| 1894 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
| 1895 | HOSTAPD_LEVEL_INFO, |
| 1896 | "authentication server did not include required VLAN ID in Access-Accept"); |
| 1897 | return -1; |
| 1898 | } |
| 1899 | |
| 1900 | return ap_sta_set_vlan(hapd, sta, &vlan_desc); |
| 1901 | } |
| 1902 | #endif /* CONFIG_NO_VLAN */ |
| 1903 | |
| 1904 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1905 | /** |
| 1906 | * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server |
| 1907 | * @msg: RADIUS response message |
| 1908 | * @req: RADIUS request message |
| 1909 | * @shared_secret: RADIUS shared secret |
| 1910 | * @shared_secret_len: Length of shared_secret in octets |
| 1911 | * @data: Context data (struct hostapd_data *) |
| 1912 | * Returns: Processing status |
| 1913 | */ |
| 1914 | static RadiusRxResult |
| 1915 | ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req, |
| 1916 | const u8 *shared_secret, size_t shared_secret_len, |
| 1917 | void *data) |
| 1918 | { |
| 1919 | struct hostapd_data *hapd = data; |
| 1920 | struct sta_info *sta; |
| 1921 | u32 session_timeout = 0, termination_action, acct_interim_interval; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1922 | int session_timeout_set; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1923 | u32 reason_code; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1924 | struct eapol_state_machine *sm; |
| 1925 | int override_eapReq = 0; |
| 1926 | struct radius_hdr *hdr = radius_msg_get_hdr(msg); |
| 1927 | |
| 1928 | sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1929 | if (!sm) { |
| 1930 | wpa_printf(MSG_DEBUG, |
| 1931 | "IEEE 802.1X: Could not find matching station for this RADIUS message"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1932 | return RADIUS_RX_UNKNOWN; |
| 1933 | } |
| 1934 | sta = sm->sta; |
| 1935 | |
| 1936 | /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be |
| 1937 | * present when packet contains an EAP-Message attribute */ |
| 1938 | if (hdr->code == RADIUS_CODE_ACCESS_REJECT && |
| 1939 | radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL, |
| 1940 | 0) < 0 && |
| 1941 | radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1942 | wpa_printf(MSG_DEBUG, |
| 1943 | "Allowing RADIUS Access-Reject without Message-Authenticator since it does not include EAP-Message"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1944 | } else if (radius_msg_verify(msg, shared_secret, shared_secret_len, |
| 1945 | req, 1)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1946 | wpa_printf(MSG_INFO, |
| 1947 | "Incoming RADIUS packet did not have correct Message-Authenticator - dropped"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1948 | return RADIUS_RX_INVALID_AUTHENTICATOR; |
| 1949 | } |
| 1950 | |
| 1951 | if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT && |
| 1952 | hdr->code != RADIUS_CODE_ACCESS_REJECT && |
| 1953 | hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1954 | wpa_printf(MSG_INFO, "Unknown RADIUS message code"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1955 | return RADIUS_RX_UNKNOWN; |
| 1956 | } |
| 1957 | |
| 1958 | sm->radius_identifier = -1; |
| 1959 | wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR, |
| 1960 | MAC2STR(sta->addr)); |
| 1961 | |
| 1962 | radius_msg_free(sm->last_recv_radius); |
| 1963 | sm->last_recv_radius = msg; |
| 1964 | |
| 1965 | session_timeout_set = |
| 1966 | !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT, |
| 1967 | &session_timeout); |
| 1968 | if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION, |
| 1969 | &termination_action)) |
| 1970 | termination_action = RADIUS_TERMINATION_ACTION_DEFAULT; |
| 1971 | |
| 1972 | if (hapd->conf->acct_interim_interval == 0 && |
| 1973 | hdr->code == RADIUS_CODE_ACCESS_ACCEPT && |
| 1974 | radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL, |
| 1975 | &acct_interim_interval) == 0) { |
| 1976 | if (acct_interim_interval < 60) { |
| 1977 | hostapd_logger(hapd, sta->addr, |
| 1978 | HOSTAPD_MODULE_IEEE8021X, |
| 1979 | HOSTAPD_LEVEL_INFO, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 1980 | "ignored too small Acct-Interim-Interval %d", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1981 | acct_interim_interval); |
| 1982 | } else |
| 1983 | sta->acct_interim_interval = acct_interim_interval; |
| 1984 | } |
| 1985 | |
| 1986 | |
| 1987 | switch (hdr->code) { |
| 1988 | case RADIUS_CODE_ACCESS_ACCEPT: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1989 | #ifndef CONFIG_NO_VLAN |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1990 | if (hapd->conf->ssid.dynamic_vlan != DYNAMIC_VLAN_DISABLED && |
| 1991 | ieee802_1x_update_vlan(msg, hapd, sta) < 0) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1992 | break; |
| 1993 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1994 | if (sta->vlan_id > 0) { |
| 1995 | hostapd_logger(hapd, sta->addr, |
| 1996 | HOSTAPD_MODULE_RADIUS, |
| 1997 | HOSTAPD_LEVEL_INFO, |
| 1998 | "VLAN ID %d", sta->vlan_id); |
| 1999 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2000 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 2001 | if ((sta->flags & WLAN_STA_ASSOC) && |
| 2002 | ap_sta_bind_vlan(hapd, sta) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2003 | break; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2004 | #endif /* CONFIG_NO_VLAN */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2005 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2006 | sta->session_timeout_set = !!session_timeout_set; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2007 | os_get_reltime(&sta->session_timeout); |
| 2008 | sta->session_timeout.sec += session_timeout; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2009 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2010 | /* RFC 3580, Ch. 3.17 */ |
| 2011 | if (session_timeout_set && termination_action == |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2012 | RADIUS_TERMINATION_ACTION_RADIUS_REQUEST) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2013 | sm->reAuthPeriod = session_timeout; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2014 | else if (session_timeout_set) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2015 | ap_sta_session_timeout(hapd, sta, session_timeout); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2016 | else |
| 2017 | ap_sta_no_session_timeout(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2018 | |
| 2019 | sm->eap_if->aaaSuccess = TRUE; |
| 2020 | override_eapReq = 1; |
| 2021 | ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret, |
| 2022 | shared_secret_len); |
| 2023 | ieee802_1x_store_radius_class(hapd, sta, msg); |
| 2024 | ieee802_1x_update_sta_identity(hapd, sta, msg); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2025 | ieee802_1x_update_sta_cui(hapd, sta, msg); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2026 | ieee802_1x_check_hs20(hapd, sta, msg, |
| 2027 | session_timeout_set ? |
| 2028 | (int) session_timeout : -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2029 | break; |
| 2030 | case RADIUS_CODE_ACCESS_REJECT: |
| 2031 | sm->eap_if->aaaFail = TRUE; |
| 2032 | override_eapReq = 1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2033 | if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_WLAN_REASON_CODE, |
| 2034 | &reason_code) == 0) { |
| 2035 | wpa_printf(MSG_DEBUG, |
| 2036 | "RADIUS server indicated WLAN-Reason-Code %u in Access-Reject for " |
| 2037 | MACSTR, reason_code, MAC2STR(sta->addr)); |
| 2038 | sta->disconnect_reason_code = reason_code; |
| 2039 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2040 | break; |
| 2041 | case RADIUS_CODE_ACCESS_CHALLENGE: |
| 2042 | sm->eap_if->aaaEapReq = TRUE; |
| 2043 | if (session_timeout_set) { |
| 2044 | /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */ |
| 2045 | sm->eap_if->aaaMethodTimeout = session_timeout; |
| 2046 | hostapd_logger(hapd, sm->addr, |
| 2047 | HOSTAPD_MODULE_IEEE8021X, |
| 2048 | HOSTAPD_LEVEL_DEBUG, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2049 | "using EAP timeout of %d seconds (from RADIUS)", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2050 | sm->eap_if->aaaMethodTimeout); |
| 2051 | } else { |
| 2052 | /* |
| 2053 | * Use dynamic retransmission behavior per EAP |
| 2054 | * specification. |
| 2055 | */ |
| 2056 | sm->eap_if->aaaMethodTimeout = 0; |
| 2057 | } |
| 2058 | break; |
| 2059 | } |
| 2060 | |
| 2061 | ieee802_1x_decapsulate_radius(hapd, sta); |
| 2062 | if (override_eapReq) |
| 2063 | sm->eap_if->aaaEapReq = FALSE; |
| 2064 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2065 | #ifdef CONFIG_FILS |
| 2066 | #ifdef NEED_AP_MLME |
| 2067 | if (sta->flags & WLAN_STA_PENDING_FILS_ERP) { |
| 2068 | /* TODO: Add a PMKSA entry on success? */ |
| 2069 | ieee802_11_finish_fils_auth( |
| 2070 | hapd, sta, hdr->code == RADIUS_CODE_ACCESS_ACCEPT, |
| 2071 | sm->eap_if->aaaEapReqData, |
| 2072 | sm->eap_if->aaaEapKeyData, |
| 2073 | sm->eap_if->aaaEapKeyDataLen); |
| 2074 | } |
| 2075 | #endif /* NEED_AP_MLME */ |
| 2076 | #endif /* CONFIG_FILS */ |
| 2077 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2078 | eapol_auth_step(sm); |
| 2079 | |
| 2080 | return RADIUS_RX_QUEUED; |
| 2081 | } |
| 2082 | #endif /* CONFIG_NO_RADIUS */ |
| 2083 | |
| 2084 | |
| 2085 | void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta) |
| 2086 | { |
| 2087 | struct eapol_state_machine *sm = sta->eapol_sm; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2088 | |
| 2089 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2090 | return; |
| 2091 | |
| 2092 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
| 2093 | HOSTAPD_LEVEL_DEBUG, "aborting authentication"); |
| 2094 | |
| 2095 | #ifndef CONFIG_NO_RADIUS |
| 2096 | radius_msg_free(sm->last_recv_radius); |
| 2097 | sm->last_recv_radius = NULL; |
| 2098 | #endif /* CONFIG_NO_RADIUS */ |
| 2099 | |
| 2100 | if (sm->eap_if->eapTimeout) { |
| 2101 | /* |
| 2102 | * Disconnect the STA since it did not reply to the last EAP |
| 2103 | * request and we cannot continue EAP processing (EAP-Failure |
| 2104 | * could only be sent if the EAP peer actually replied). |
| 2105 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2106 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "EAP Timeout, STA " MACSTR, |
| 2107 | MAC2STR(sta->addr)); |
| 2108 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2109 | sm->eap_if->portEnabled = FALSE; |
| 2110 | ap_sta_disconnect(hapd, sta, sta->addr, |
| 2111 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | |
| 2116 | static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd) |
| 2117 | { |
| 2118 | struct eapol_authenticator *eapol = hapd->eapol_auth; |
| 2119 | |
| 2120 | if (hapd->conf->default_wep_key_len < 1) |
| 2121 | return 0; |
| 2122 | |
| 2123 | os_free(eapol->default_wep_key); |
| 2124 | eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2125 | if (!eapol->default_wep_key || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2126 | random_get_bytes(eapol->default_wep_key, |
| 2127 | hapd->conf->default_wep_key_len)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2128 | wpa_printf(MSG_INFO, "Could not generate random WEP key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2129 | os_free(eapol->default_wep_key); |
| 2130 | eapol->default_wep_key = NULL; |
| 2131 | return -1; |
| 2132 | } |
| 2133 | |
| 2134 | wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key", |
| 2135 | eapol->default_wep_key, |
| 2136 | hapd->conf->default_wep_key_len); |
| 2137 | |
| 2138 | return 0; |
| 2139 | } |
| 2140 | |
| 2141 | |
| 2142 | static int ieee802_1x_sta_key_available(struct hostapd_data *hapd, |
| 2143 | struct sta_info *sta, void *ctx) |
| 2144 | { |
| 2145 | if (sta->eapol_sm) { |
| 2146 | sta->eapol_sm->eap_if->eapKeyAvailable = TRUE; |
| 2147 | eapol_auth_step(sta->eapol_sm); |
| 2148 | } |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
| 2152 | |
| 2153 | static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx) |
| 2154 | { |
| 2155 | struct hostapd_data *hapd = eloop_ctx; |
| 2156 | struct eapol_authenticator *eapol = hapd->eapol_auth; |
| 2157 | |
| 2158 | if (eapol->default_wep_key_idx >= 3) |
| 2159 | eapol->default_wep_key_idx = |
| 2160 | hapd->conf->individual_wep_key_len > 0 ? 1 : 0; |
| 2161 | else |
| 2162 | eapol->default_wep_key_idx++; |
| 2163 | |
| 2164 | wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d", |
| 2165 | eapol->default_wep_key_idx); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2166 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2167 | if (ieee802_1x_rekey_broadcast(hapd)) { |
| 2168 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2169 | HOSTAPD_LEVEL_WARNING, |
| 2170 | "failed to generate a new broadcast key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2171 | os_free(eapol->default_wep_key); |
| 2172 | eapol->default_wep_key = NULL; |
| 2173 | return; |
| 2174 | } |
| 2175 | |
| 2176 | /* TODO: Could setup key for RX here, but change default TX keyid only |
| 2177 | * after new broadcast key has been sent to all stations. */ |
| 2178 | if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP, |
| 2179 | broadcast_ether_addr, |
| 2180 | eapol->default_wep_key_idx, 1, NULL, 0, |
| 2181 | eapol->default_wep_key, |
| 2182 | hapd->conf->default_wep_key_len)) { |
| 2183 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2184 | HOSTAPD_LEVEL_WARNING, |
| 2185 | "failed to configure a new broadcast key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2186 | os_free(eapol->default_wep_key); |
| 2187 | eapol->default_wep_key = NULL; |
| 2188 | return; |
| 2189 | } |
| 2190 | |
| 2191 | ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL); |
| 2192 | |
| 2193 | if (hapd->conf->wep_rekeying_period > 0) { |
| 2194 | eloop_register_timeout(hapd->conf->wep_rekeying_period, 0, |
| 2195 | ieee802_1x_rekey, hapd, NULL); |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | |
| 2200 | static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type, |
| 2201 | const u8 *data, size_t datalen) |
| 2202 | { |
| 2203 | #ifdef CONFIG_WPS |
| 2204 | struct sta_info *sta = sta_ctx; |
| 2205 | |
| 2206 | if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) == |
| 2207 | WLAN_STA_MAYBE_WPS) { |
| 2208 | const u8 *identity; |
| 2209 | size_t identity_len; |
| 2210 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 2211 | |
| 2212 | identity = eap_get_identity(sm->eap, &identity_len); |
| 2213 | if (identity && |
| 2214 | ((identity_len == WSC_ID_ENROLLEE_LEN && |
| 2215 | os_memcmp(identity, WSC_ID_ENROLLEE, |
| 2216 | WSC_ID_ENROLLEE_LEN) == 0) || |
| 2217 | (identity_len == WSC_ID_REGISTRAR_LEN && |
| 2218 | os_memcmp(identity, WSC_ID_REGISTRAR, |
| 2219 | WSC_ID_REGISTRAR_LEN) == 0))) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2220 | wpa_printf(MSG_DEBUG, |
| 2221 | "WPS: WLAN_STA_MAYBE_WPS -> WLAN_STA_WPS"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2222 | sta->flags |= WLAN_STA_WPS; |
| 2223 | } |
| 2224 | } |
| 2225 | #endif /* CONFIG_WPS */ |
| 2226 | |
| 2227 | ieee802_1x_send(ctx, sta_ctx, type, data, datalen); |
| 2228 | } |
| 2229 | |
| 2230 | |
| 2231 | static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx, |
| 2232 | const u8 *data, size_t datalen) |
| 2233 | { |
| 2234 | #ifndef CONFIG_NO_RADIUS |
| 2235 | struct hostapd_data *hapd = ctx; |
| 2236 | struct sta_info *sta = sta_ctx; |
| 2237 | |
| 2238 | ieee802_1x_encapsulate_radius(hapd, sta, data, datalen); |
| 2239 | #endif /* CONFIG_NO_RADIUS */ |
| 2240 | } |
| 2241 | |
| 2242 | |
| 2243 | static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2244 | int preauth, int remediation) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2245 | { |
| 2246 | struct hostapd_data *hapd = ctx; |
| 2247 | struct sta_info *sta = sta_ctx; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2248 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2249 | if (preauth) |
| 2250 | rsn_preauth_finished(hapd, sta, success); |
| 2251 | else |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2252 | ieee802_1x_finished(hapd, sta, success, remediation); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | |
| 2256 | static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity, |
| 2257 | size_t identity_len, int phase2, |
| 2258 | struct eap_user *user) |
| 2259 | { |
| 2260 | struct hostapd_data *hapd = ctx; |
| 2261 | const struct hostapd_eap_user *eap_user; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2262 | int i; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2263 | int rv = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2264 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2265 | eap_user = hostapd_get_eap_user(hapd, identity, identity_len, phase2); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2266 | if (!eap_user) |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2267 | goto out; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2268 | |
| 2269 | os_memset(user, 0, sizeof(*user)); |
| 2270 | user->phase2 = phase2; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2271 | for (i = 0; i < EAP_MAX_METHODS; i++) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2272 | user->methods[i].vendor = eap_user->methods[i].vendor; |
| 2273 | user->methods[i].method = eap_user->methods[i].method; |
| 2274 | } |
| 2275 | |
| 2276 | if (eap_user->password) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2277 | user->password = os_memdup(eap_user->password, |
| 2278 | eap_user->password_len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2279 | if (!user->password) |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2280 | goto out; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2281 | user->password_len = eap_user->password_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2282 | user->password_hash = eap_user->password_hash; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2283 | if (eap_user->salt && eap_user->salt_len) { |
| 2284 | user->salt = os_memdup(eap_user->salt, |
| 2285 | eap_user->salt_len); |
| 2286 | if (!user->salt) |
| 2287 | goto out; |
| 2288 | user->salt_len = eap_user->salt_len; |
| 2289 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2290 | } |
| 2291 | user->force_version = eap_user->force_version; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 2292 | user->macacl = eap_user->macacl; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2293 | user->ttls_auth = eap_user->ttls_auth; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2294 | user->remediation = eap_user->remediation; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2295 | rv = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2296 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2297 | out: |
| 2298 | if (rv) |
| 2299 | wpa_printf(MSG_DEBUG, "%s: Failed to find user", __func__); |
| 2300 | |
| 2301 | return rv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | |
| 2305 | static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr) |
| 2306 | { |
| 2307 | struct hostapd_data *hapd = ctx; |
| 2308 | struct sta_info *sta; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2309 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2310 | sta = ap_get_sta(hapd, addr); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2311 | if (!sta || !sta->eapol_sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2312 | return 0; |
| 2313 | return 1; |
| 2314 | } |
| 2315 | |
| 2316 | |
| 2317 | static void ieee802_1x_logger(void *ctx, const u8 *addr, |
| 2318 | eapol_logger_level level, const char *txt) |
| 2319 | { |
| 2320 | #ifndef CONFIG_NO_HOSTAPD_LOGGER |
| 2321 | struct hostapd_data *hapd = ctx; |
| 2322 | int hlevel; |
| 2323 | |
| 2324 | switch (level) { |
| 2325 | case EAPOL_LOGGER_WARNING: |
| 2326 | hlevel = HOSTAPD_LEVEL_WARNING; |
| 2327 | break; |
| 2328 | case EAPOL_LOGGER_INFO: |
| 2329 | hlevel = HOSTAPD_LEVEL_INFO; |
| 2330 | break; |
| 2331 | case EAPOL_LOGGER_DEBUG: |
| 2332 | default: |
| 2333 | hlevel = HOSTAPD_LEVEL_DEBUG; |
| 2334 | break; |
| 2335 | } |
| 2336 | |
| 2337 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s", |
| 2338 | txt); |
| 2339 | #endif /* CONFIG_NO_HOSTAPD_LOGGER */ |
| 2340 | } |
| 2341 | |
| 2342 | |
| 2343 | static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx, |
| 2344 | int authorized) |
| 2345 | { |
| 2346 | struct hostapd_data *hapd = ctx; |
| 2347 | struct sta_info *sta = sta_ctx; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2348 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2349 | ieee802_1x_set_sta_authorized(hapd, sta, authorized); |
| 2350 | } |
| 2351 | |
| 2352 | |
| 2353 | static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx) |
| 2354 | { |
| 2355 | struct hostapd_data *hapd = ctx; |
| 2356 | struct sta_info *sta = sta_ctx; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2357 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2358 | ieee802_1x_abort_auth(hapd, sta); |
| 2359 | } |
| 2360 | |
| 2361 | |
| 2362 | static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx) |
| 2363 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2364 | #ifndef CONFIG_FIPS |
| 2365 | #ifndef CONFIG_NO_RC4 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2366 | struct hostapd_data *hapd = ctx; |
| 2367 | struct sta_info *sta = sta_ctx; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2368 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2369 | ieee802_1x_tx_key(hapd, sta); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2370 | #endif /* CONFIG_NO_RC4 */ |
| 2371 | #endif /* CONFIG_FIPS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | |
| 2375 | static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx, |
| 2376 | enum eapol_event type) |
| 2377 | { |
| 2378 | /* struct hostapd_data *hapd = ctx; */ |
| 2379 | struct sta_info *sta = sta_ctx; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2380 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | switch (type) { |
| 2382 | case EAPOL_AUTH_SM_CHANGE: |
| 2383 | wpa_auth_sm_notify(sta->wpa_sm); |
| 2384 | break; |
| 2385 | case EAPOL_AUTH_REAUTHENTICATE: |
| 2386 | wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL); |
| 2387 | break; |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2392 | #ifdef CONFIG_ERP |
| 2393 | |
| 2394 | static struct eap_server_erp_key * |
| 2395 | ieee802_1x_erp_get_key(void *ctx, const char *keyname) |
| 2396 | { |
| 2397 | struct hostapd_data *hapd = ctx; |
| 2398 | struct eap_server_erp_key *erp; |
| 2399 | |
| 2400 | dl_list_for_each(erp, &hapd->erp_keys, struct eap_server_erp_key, |
| 2401 | list) { |
| 2402 | if (os_strcmp(erp->keyname_nai, keyname) == 0) |
| 2403 | return erp; |
| 2404 | } |
| 2405 | |
| 2406 | return NULL; |
| 2407 | } |
| 2408 | |
| 2409 | |
| 2410 | static int ieee802_1x_erp_add_key(void *ctx, struct eap_server_erp_key *erp) |
| 2411 | { |
| 2412 | struct hostapd_data *hapd = ctx; |
| 2413 | |
| 2414 | dl_list_add(&hapd->erp_keys, &erp->list); |
| 2415 | return 0; |
| 2416 | } |
| 2417 | |
| 2418 | #endif /* CONFIG_ERP */ |
| 2419 | |
| 2420 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2421 | int ieee802_1x_init(struct hostapd_data *hapd) |
| 2422 | { |
| 2423 | int i; |
| 2424 | struct eapol_auth_config conf; |
| 2425 | struct eapol_auth_cb cb; |
| 2426 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2427 | dl_list_init(&hapd->erp_keys); |
| 2428 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2429 | os_memset(&conf, 0, sizeof(conf)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2430 | conf.eap_cfg = hapd->eap_cfg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2431 | conf.ctx = hapd; |
| 2432 | conf.eap_reauth_period = hapd->conf->eap_reauth_period; |
| 2433 | conf.wpa = hapd->conf->wpa; |
| 2434 | conf.individual_wep_key_len = hapd->conf->individual_wep_key_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2435 | conf.eap_req_id_text = hapd->conf->eap_req_id_text; |
| 2436 | conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2437 | conf.erp_send_reauth_start = hapd->conf->erp_send_reauth_start; |
| 2438 | conf.erp_domain = hapd->conf->erp_domain; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2439 | |
| 2440 | os_memset(&cb, 0, sizeof(cb)); |
| 2441 | cb.eapol_send = ieee802_1x_eapol_send; |
| 2442 | cb.aaa_send = ieee802_1x_aaa_send; |
| 2443 | cb.finished = _ieee802_1x_finished; |
| 2444 | cb.get_eap_user = ieee802_1x_get_eap_user; |
| 2445 | cb.sta_entry_alive = ieee802_1x_sta_entry_alive; |
| 2446 | cb.logger = ieee802_1x_logger; |
| 2447 | cb.set_port_authorized = ieee802_1x_set_port_authorized; |
| 2448 | cb.abort_auth = _ieee802_1x_abort_auth; |
| 2449 | cb.tx_key = _ieee802_1x_tx_key; |
| 2450 | cb.eapol_event = ieee802_1x_eapol_event; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2451 | #ifdef CONFIG_ERP |
| 2452 | cb.erp_get_key = ieee802_1x_erp_get_key; |
| 2453 | cb.erp_add_key = ieee802_1x_erp_add_key; |
| 2454 | #endif /* CONFIG_ERP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2455 | |
| 2456 | hapd->eapol_auth = eapol_auth_init(&conf, &cb); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2457 | if (!hapd->eapol_auth) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2458 | return -1; |
| 2459 | |
| 2460 | if ((hapd->conf->ieee802_1x || hapd->conf->wpa) && |
| 2461 | hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1)) |
| 2462 | return -1; |
| 2463 | |
| 2464 | #ifndef CONFIG_NO_RADIUS |
| 2465 | if (radius_client_register(hapd->radius, RADIUS_AUTH, |
| 2466 | ieee802_1x_receive_auth, hapd)) |
| 2467 | return -1; |
| 2468 | #endif /* CONFIG_NO_RADIUS */ |
| 2469 | |
| 2470 | if (hapd->conf->default_wep_key_len) { |
| 2471 | for (i = 0; i < 4; i++) |
| 2472 | hostapd_drv_set_key(hapd->conf->iface, hapd, |
| 2473 | WPA_ALG_NONE, NULL, i, 0, NULL, 0, |
| 2474 | NULL, 0); |
| 2475 | |
| 2476 | ieee802_1x_rekey(hapd, NULL); |
| 2477 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2478 | if (!hapd->eapol_auth->default_wep_key) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2479 | return -1; |
| 2480 | } |
| 2481 | |
| 2482 | return 0; |
| 2483 | } |
| 2484 | |
| 2485 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2486 | void ieee802_1x_erp_flush(struct hostapd_data *hapd) |
| 2487 | { |
| 2488 | struct eap_server_erp_key *erp; |
| 2489 | |
| 2490 | while ((erp = dl_list_first(&hapd->erp_keys, struct eap_server_erp_key, |
| 2491 | list)) != NULL) { |
| 2492 | dl_list_del(&erp->list); |
| 2493 | bin_clear_free(erp, sizeof(*erp)); |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2498 | void ieee802_1x_deinit(struct hostapd_data *hapd) |
| 2499 | { |
| 2500 | eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL); |
| 2501 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2502 | if (hapd->driver && hapd->drv_priv && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2503 | (hapd->conf->ieee802_1x || hapd->conf->wpa)) |
| 2504 | hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0); |
| 2505 | |
| 2506 | eapol_auth_deinit(hapd->eapol_auth); |
| 2507 | hapd->eapol_auth = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2508 | |
| 2509 | ieee802_1x_erp_flush(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | |
| 2513 | int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta, |
| 2514 | const u8 *buf, size_t len, int ack) |
| 2515 | { |
| 2516 | struct ieee80211_hdr *hdr; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2517 | u8 *pos; |
| 2518 | const unsigned char rfc1042_hdr[ETH_ALEN] = |
| 2519 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 2520 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2521 | if (!sta) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2522 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2523 | if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2524 | return 0; |
| 2525 | |
| 2526 | hdr = (struct ieee80211_hdr *) buf; |
| 2527 | pos = (u8 *) (hdr + 1); |
| 2528 | if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0) |
| 2529 | return 0; |
| 2530 | pos += sizeof(rfc1042_hdr); |
| 2531 | if (WPA_GET_BE16(pos) != ETH_P_PAE) |
| 2532 | return 0; |
| 2533 | pos += 2; |
| 2534 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2535 | return ieee802_1x_eapol_tx_status(hapd, sta, pos, buf + len - pos, |
| 2536 | ack); |
| 2537 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2538 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2539 | |
| 2540 | int ieee802_1x_eapol_tx_status(struct hostapd_data *hapd, struct sta_info *sta, |
| 2541 | const u8 *buf, int len, int ack) |
| 2542 | { |
| 2543 | const struct ieee802_1x_hdr *xhdr = |
| 2544 | (const struct ieee802_1x_hdr *) buf; |
| 2545 | const u8 *pos = buf + sizeof(*xhdr); |
| 2546 | struct ieee802_1x_eapol_key *key; |
| 2547 | |
| 2548 | if (len < (int) sizeof(*xhdr)) |
| 2549 | return 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2550 | wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR |
| 2551 | " TX status - version=%d type=%d length=%d - ack=%d", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2552 | MAC2STR(sta->addr), xhdr->version, xhdr->type, |
| 2553 | be_to_host16(xhdr->length), ack); |
| 2554 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2555 | #ifdef CONFIG_WPS |
| 2556 | if (xhdr->type == IEEE802_1X_TYPE_EAP_PACKET && ack && |
| 2557 | (sta->flags & WLAN_STA_WPS) && |
| 2558 | ap_sta_pending_delayed_1x_auth_fail_disconnect(hapd, sta)) { |
| 2559 | wpa_printf(MSG_DEBUG, |
| 2560 | "WPS: Indicate EAP completion on ACK for EAP-Failure"); |
| 2561 | hostapd_wps_eap_completed(hapd); |
| 2562 | } |
| 2563 | #endif /* CONFIG_WPS */ |
| 2564 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2565 | if (xhdr->type != IEEE802_1X_TYPE_EAPOL_KEY) |
| 2566 | return 0; |
| 2567 | |
| 2568 | if (pos + sizeof(struct wpa_eapol_key) <= buf + len) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2569 | const struct wpa_eapol_key *wpa; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2570 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2571 | wpa = (const struct wpa_eapol_key *) pos; |
| 2572 | if (wpa->type == EAPOL_KEY_TYPE_RSN || |
| 2573 | wpa->type == EAPOL_KEY_TYPE_WPA) |
| 2574 | wpa_auth_eapol_key_tx_status(hapd->wpa_auth, |
| 2575 | sta->wpa_sm, ack); |
| 2576 | } |
| 2577 | |
| 2578 | /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant |
| 2579 | * or Authenticator state machines, but EAPOL-Key packets are not |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2580 | * retransmitted in case of failure. Try to re-send failed EAPOL-Key |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2581 | * packets couple of times because otherwise STA keys become |
| 2582 | * unsynchronized with AP. */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2583 | if (!ack && pos + sizeof(*key) <= buf + len) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2584 | key = (struct ieee802_1x_eapol_key *) pos; |
| 2585 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2586 | HOSTAPD_LEVEL_DEBUG, |
| 2587 | "did not Ack EAPOL-Key frame (%scast index=%d)", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2588 | key->key_index & BIT(7) ? "uni" : "broad", |
| 2589 | key->key_index & ~BIT(7)); |
| 2590 | /* TODO: re-send EAPOL-Key couple of times (with short delay |
| 2591 | * between them?). If all attempt fail, report error and |
| 2592 | * deauthenticate STA so that it will get new keys when |
| 2593 | * authenticating again (e.g., after returning in range). |
| 2594 | * Separate limit/transmit state needed both for unicast and |
| 2595 | * broadcast keys(?) */ |
| 2596 | } |
| 2597 | /* TODO: could move unicast key configuration from ieee802_1x_tx_key() |
| 2598 | * to here and change the key only if the EAPOL-Key packet was Acked. |
| 2599 | */ |
| 2600 | |
| 2601 | return 1; |
| 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len) |
| 2606 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2607 | if (!sm || !sm->identity) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2608 | return NULL; |
| 2609 | |
| 2610 | *len = sm->identity_len; |
| 2611 | return sm->identity; |
| 2612 | } |
| 2613 | |
| 2614 | |
| 2615 | u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len, |
| 2616 | int idx) |
| 2617 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2618 | if (!sm || !sm->radius_class.attr || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2619 | idx >= (int) sm->radius_class.count) |
| 2620 | return NULL; |
| 2621 | |
| 2622 | *len = sm->radius_class.attr[idx].len; |
| 2623 | return sm->radius_class.attr[idx].data; |
| 2624 | } |
| 2625 | |
| 2626 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2627 | struct wpabuf * ieee802_1x_get_radius_cui(struct eapol_state_machine *sm) |
| 2628 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2629 | if (!sm) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2630 | return NULL; |
| 2631 | return sm->radius_cui; |
| 2632 | } |
| 2633 | |
| 2634 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2635 | const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len) |
| 2636 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2637 | *len = 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2638 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2639 | return NULL; |
| 2640 | |
| 2641 | *len = sm->eap_if->eapKeyDataLen; |
| 2642 | return sm->eap_if->eapKeyData; |
| 2643 | } |
| 2644 | |
| 2645 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2646 | #ifdef CONFIG_MACSEC |
| 2647 | const u8 * ieee802_1x_get_session_id(struct eapol_state_machine *sm, |
| 2648 | size_t *len) |
| 2649 | { |
| 2650 | *len = 0; |
| 2651 | if (!sm || !sm->eap_if) |
| 2652 | return NULL; |
| 2653 | |
| 2654 | *len = sm->eap_if->eapSessionIdLen; |
| 2655 | return sm->eap_if->eapSessionId; |
| 2656 | } |
| 2657 | #endif /* CONFIG_MACSEC */ |
| 2658 | |
| 2659 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2660 | void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm, |
| 2661 | int enabled) |
| 2662 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2663 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2664 | return; |
| 2665 | sm->eap_if->portEnabled = enabled ? TRUE : FALSE; |
| 2666 | eapol_auth_step(sm); |
| 2667 | } |
| 2668 | |
| 2669 | |
| 2670 | void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm, |
| 2671 | int valid) |
| 2672 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2673 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2674 | return; |
| 2675 | sm->portValid = valid ? TRUE : FALSE; |
| 2676 | eapol_auth_step(sm); |
| 2677 | } |
| 2678 | |
| 2679 | |
| 2680 | void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth) |
| 2681 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2682 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2683 | return; |
| 2684 | if (pre_auth) |
| 2685 | sm->flags |= EAPOL_SM_PREAUTH; |
| 2686 | else |
| 2687 | sm->flags &= ~EAPOL_SM_PREAUTH; |
| 2688 | } |
| 2689 | |
| 2690 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2691 | static const char * bool_txt(Boolean val) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2692 | { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2693 | return val ? "TRUE" : "FALSE"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | |
| 2697 | int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen) |
| 2698 | { |
| 2699 | /* TODO */ |
| 2700 | return 0; |
| 2701 | } |
| 2702 | |
| 2703 | |
| 2704 | int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta, |
| 2705 | char *buf, size_t buflen) |
| 2706 | { |
| 2707 | int len = 0, ret; |
| 2708 | struct eapol_state_machine *sm = sta->eapol_sm; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2709 | struct os_reltime diff; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 2710 | const char *name1; |
| 2711 | const char *name2; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2712 | char *identity_buf = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2713 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame^] | 2714 | if (!sm) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2715 | return 0; |
| 2716 | |
| 2717 | ret = os_snprintf(buf + len, buflen - len, |
| 2718 | "dot1xPaePortNumber=%d\n" |
| 2719 | "dot1xPaePortProtocolVersion=%d\n" |
| 2720 | "dot1xPaePortCapabilities=1\n" |
| 2721 | "dot1xPaePortInitialize=%d\n" |
| 2722 | "dot1xPaePortReauthenticate=FALSE\n", |
| 2723 | sta->aid, |
| 2724 | EAPOL_VERSION, |
| 2725 | sm->initialize); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2726 | if (os_snprintf_error(buflen - len, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2727 | return len; |
| 2728 | len += ret; |
| 2729 | |
| 2730 | /* dot1xAuthConfigTable */ |
| 2731 | ret = os_snprintf(buf + len, buflen - len, |
| 2732 | "dot1xAuthPaeState=%d\n" |
| 2733 | "dot1xAuthBackendAuthState=%d\n" |
| 2734 | "dot1xAuthAdminControlledDirections=%d\n" |
| 2735 | "dot1xAuthOperControlledDirections=%d\n" |
| 2736 | "dot1xAuthAuthControlledPortStatus=%d\n" |
| 2737 | "dot1xAuthAuthControlledPortControl=%d\n" |
| 2738 | "dot1xAuthQuietPeriod=%u\n" |
| 2739 | "dot1xAuthServerTimeout=%u\n" |
| 2740 | "dot1xAuthReAuthPeriod=%u\n" |
| 2741 | "dot1xAuthReAuthEnabled=%s\n" |
| 2742 | "dot1xAuthKeyTxEnabled=%s\n", |
| 2743 | sm->auth_pae_state + 1, |
| 2744 | sm->be_auth_state + 1, |
| 2745 | sm->adminControlledDirections, |
| 2746 | sm->operControlledDirections, |
| 2747 | sm->authPortStatus, |
| 2748 | sm->portControl, |
| 2749 | sm->quietPeriod, |
| 2750 | sm->serverTimeout, |
| 2751 | sm->reAuthPeriod, |
| 2752 | bool_txt(sm->reAuthEnabled), |
| 2753 | bool_txt(sm->keyTxEnabled)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2754 | if (os_snprintf_error(buflen - len, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2755 | return len; |
| 2756 | len += ret; |
| 2757 | |
| 2758 | /* dot1xAuthStatsTable */ |
| 2759 | ret = os_snprintf(buf + len, buflen - len, |
| 2760 | "dot1xAuthEapolFramesRx=%u\n" |
| 2761 | "dot1xAuthEapolFramesTx=%u\n" |
| 2762 | "dot1xAuthEapolStartFramesRx=%u\n" |
| 2763 | "dot1xAuthEapolLogoffFramesRx=%u\n" |
| 2764 | "dot1xAuthEapolRespIdFramesRx=%u\n" |
| 2765 | "dot1xAuthEapolRespFramesRx=%u\n" |
| 2766 | "dot1xAuthEapolReqIdFramesTx=%u\n" |
| 2767 | "dot1xAuthEapolReqFramesTx=%u\n" |
| 2768 | "dot1xAuthInvalidEapolFramesRx=%u\n" |
| 2769 | "dot1xAuthEapLengthErrorFramesRx=%u\n" |
| 2770 | "dot1xAuthLastEapolFrameVersion=%u\n" |
| 2771 | "dot1xAuthLastEapolFrameSource=" MACSTR "\n", |
| 2772 | sm->dot1xAuthEapolFramesRx, |
| 2773 | sm->dot1xAuthEapolFramesTx, |
| 2774 | sm->dot1xAuthEapolStartFramesRx, |
| 2775 | sm->dot1xAuthEapolLogoffFramesRx, |
| 2776 | sm->dot1xAuthEapolRespIdFramesRx, |
| 2777 | sm->dot1xAuthEapolRespFramesRx, |
| 2778 | sm->dot1xAuthEapolReqIdFramesTx, |
| 2779 | sm->dot1xAuthEapolReqFramesTx, |
| 2780 | sm->dot1xAuthInvalidEapolFramesRx, |
| 2781 | sm->dot1xAuthEapLengthErrorFramesRx, |
| 2782 | sm->dot1xAuthLastEapolFrameVersion, |
| 2783 | MAC2STR(sm->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2784 | if (os_snprintf_error(buflen - len, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2785 | return len; |
| 2786 | len += ret; |
| 2787 | |
| 2788 | /* dot1xAuthDiagTable */ |
| 2789 | ret = os_snprintf(buf + len, buflen - len, |
| 2790 | "dot1xAuthEntersConnecting=%u\n" |
| 2791 | "dot1xAuthEapLogoffsWhileConnecting=%u\n" |
| 2792 | "dot1xAuthEntersAuthenticating=%u\n" |
| 2793 | "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n" |
| 2794 | "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n" |
| 2795 | "dot1xAuthAuthFailWhileAuthenticating=%u\n" |
| 2796 | "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n" |
| 2797 | "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n" |
| 2798 | "dot1xAuthAuthReauthsWhileAuthenticated=%u\n" |
| 2799 | "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n" |
| 2800 | "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n" |
| 2801 | "dot1xAuthBackendResponses=%u\n" |
| 2802 | "dot1xAuthBackendAccessChallenges=%u\n" |
| 2803 | "dot1xAuthBackendOtherRequestsToSupplicant=%u\n" |
| 2804 | "dot1xAuthBackendAuthSuccesses=%u\n" |
| 2805 | "dot1xAuthBackendAuthFails=%u\n", |
| 2806 | sm->authEntersConnecting, |
| 2807 | sm->authEapLogoffsWhileConnecting, |
| 2808 | sm->authEntersAuthenticating, |
| 2809 | sm->authAuthSuccessesWhileAuthenticating, |
| 2810 | sm->authAuthTimeoutsWhileAuthenticating, |
| 2811 | sm->authAuthFailWhileAuthenticating, |
| 2812 | sm->authAuthEapStartsWhileAuthenticating, |
| 2813 | sm->authAuthEapLogoffWhileAuthenticating, |
| 2814 | sm->authAuthReauthsWhileAuthenticated, |
| 2815 | sm->authAuthEapStartsWhileAuthenticated, |
| 2816 | sm->authAuthEapLogoffWhileAuthenticated, |
| 2817 | sm->backendResponses, |
| 2818 | sm->backendAccessChallenges, |
| 2819 | sm->backendOtherRequestsToSupplicant, |
| 2820 | sm->backendAuthSuccesses, |
| 2821 | sm->backendAuthFails); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2822 | if (os_snprintf_error(buflen - len, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2823 | return len; |
| 2824 | len += ret; |
| 2825 | |
| 2826 | /* dot1xAuthSessionStatsTable */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2827 | os_reltime_age(&sta->acct_session_start, &diff); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2828 | if (sm->eap && !sm->identity) { |
| 2829 | const u8 *id; |
| 2830 | size_t id_len; |
| 2831 | |
| 2832 | id = eap_get_identity(sm->eap, &id_len); |
| 2833 | if (id) |
| 2834 | identity_buf = dup_binstr(id, id_len); |
| 2835 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2836 | ret = os_snprintf(buf + len, buflen - len, |
| 2837 | /* TODO: dot1xAuthSessionOctetsRx */ |
| 2838 | /* TODO: dot1xAuthSessionOctetsTx */ |
| 2839 | /* TODO: dot1xAuthSessionFramesRx */ |
| 2840 | /* TODO: dot1xAuthSessionFramesTx */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2841 | "dot1xAuthSessionId=%016llX\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2842 | "dot1xAuthSessionAuthenticMethod=%d\n" |
| 2843 | "dot1xAuthSessionTime=%u\n" |
| 2844 | "dot1xAuthSessionTerminateCause=999\n" |
| 2845 | "dot1xAuthSessionUserName=%s\n", |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2846 | (unsigned long long) sta->acct_session_id, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2847 | (wpa_key_mgmt_wpa_ieee8021x( |
| 2848 | wpa_auth_sta_key_mgmt(sta->wpa_sm))) ? |
| 2849 | 1 : 2, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2850 | (unsigned int) diff.sec, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2851 | sm->identity ? (char *) sm->identity : |
| 2852 | (identity_buf ? identity_buf : "N/A")); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2853 | os_free(identity_buf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2854 | if (os_snprintf_error(buflen - len, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2855 | return len; |
| 2856 | len += ret; |
| 2857 | |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 2858 | if (sm->acct_multi_session_id) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2859 | ret = os_snprintf(buf + len, buflen - len, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2860 | "authMultiSessionId=%016llX\n", |
| 2861 | (unsigned long long) |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 2862 | sm->acct_multi_session_id); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2863 | if (os_snprintf_error(buflen - len, ret)) |
| 2864 | return len; |
| 2865 | len += ret; |
| 2866 | } |
| 2867 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 2868 | name1 = eap_server_get_name(0, sm->eap_type_authsrv); |
| 2869 | name2 = eap_server_get_name(0, sm->eap_type_supp); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2870 | ret = os_snprintf(buf + len, buflen - len, |
| 2871 | "last_eap_type_as=%d (%s)\n" |
| 2872 | "last_eap_type_sta=%d (%s)\n", |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2873 | sm->eap_type_authsrv, name1, |
| 2874 | sm->eap_type_supp, name2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2875 | if (os_snprintf_error(buflen - len, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2876 | return len; |
| 2877 | len += ret; |
| 2878 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2879 | return len; |
| 2880 | } |
| 2881 | |
| 2882 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 2883 | #ifdef CONFIG_HS20 |
| 2884 | static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx) |
| 2885 | { |
| 2886 | struct hostapd_data *hapd = eloop_ctx; |
| 2887 | struct sta_info *sta = timeout_ctx; |
| 2888 | |
| 2889 | if (sta->remediation) { |
| 2890 | wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to " |
| 2891 | MACSTR " to indicate Subscription Remediation", |
| 2892 | MAC2STR(sta->addr)); |
| 2893 | hs20_send_wnm_notification(hapd, sta->addr, |
| 2894 | sta->remediation_method, |
| 2895 | sta->remediation_url); |
| 2896 | os_free(sta->remediation_url); |
| 2897 | sta->remediation_url = NULL; |
| 2898 | } |
| 2899 | |
| 2900 | if (sta->hs20_deauth_req) { |
| 2901 | wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to " |
| 2902 | MACSTR " to indicate imminent deauthentication", |
| 2903 | MAC2STR(sta->addr)); |
| 2904 | hs20_send_wnm_notification_deauth_req(hapd, sta->addr, |
| 2905 | sta->hs20_deauth_req); |
| 2906 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2907 | |
| 2908 | if (sta->hs20_t_c_filtering) { |
| 2909 | wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to " |
| 2910 | MACSTR " to indicate Terms and Conditions filtering", |
| 2911 | MAC2STR(sta->addr)); |
| 2912 | hs20_send_wnm_notification_t_c(hapd, sta->addr, sta->t_c_url); |
| 2913 | os_free(sta->t_c_url); |
| 2914 | sta->t_c_url = NULL; |
| 2915 | } |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 2916 | } |
| 2917 | #endif /* CONFIG_HS20 */ |
| 2918 | |
| 2919 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2920 | static void ieee802_1x_finished(struct hostapd_data *hapd, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2921 | struct sta_info *sta, int success, |
| 2922 | int remediation) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2923 | { |
| 2924 | const u8 *key; |
| 2925 | size_t len; |
| 2926 | /* TODO: get PMKLifetime from WPA parameters */ |
| 2927 | static const int dot11RSNAConfigPMKLifetime = 43200; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2928 | unsigned int session_timeout; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2929 | struct os_reltime now, remaining; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2930 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2931 | #ifdef CONFIG_HS20 |
| 2932 | if (remediation && !sta->remediation) { |
| 2933 | sta->remediation = 1; |
| 2934 | os_free(sta->remediation_url); |
| 2935 | sta->remediation_url = |
| 2936 | os_strdup(hapd->conf->subscr_remediation_url); |
| 2937 | sta->remediation_method = 1; /* SOAP-XML SPP */ |
| 2938 | } |
| 2939 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2940 | if (success && (sta->remediation || sta->hs20_deauth_req || |
| 2941 | sta->hs20_t_c_filtering)) { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 2942 | wpa_printf(MSG_DEBUG, "HS 2.0: Schedule WNM-Notification to " |
| 2943 | MACSTR " in 100 ms", MAC2STR(sta->addr)); |
| 2944 | eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta); |
| 2945 | eloop_register_timeout(0, 100000, ieee802_1x_wnm_notif_send, |
| 2946 | hapd, sta); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2947 | } |
| 2948 | #endif /* CONFIG_HS20 */ |
| 2949 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2950 | #ifdef CONFIG_MACSEC |
| 2951 | ieee802_1x_notify_create_actor_hapd(hapd, sta); |
| 2952 | #endif /* CONFIG_MACSEC */ |
| 2953 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2954 | key = ieee802_1x_get_key(sta->eapol_sm, &len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2955 | if (sta->session_timeout_set) { |
| 2956 | os_get_reltime(&now); |
| 2957 | os_reltime_sub(&sta->session_timeout, &now, &remaining); |
| 2958 | session_timeout = (remaining.sec > 0) ? remaining.sec : 1; |
| 2959 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2960 | session_timeout = dot11RSNAConfigPMKLifetime; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2961 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2962 | if (success && key && len >= PMK_LEN && !sta->remediation && |
| 2963 | !sta->hs20_deauth_requested && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2964 | wpa_auth_pmksa_add(sta->wpa_sm, key, len, session_timeout, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2965 | sta->eapol_sm) == 0) { |
| 2966 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA, |
| 2967 | HOSTAPD_LEVEL_DEBUG, |
| 2968 | "Added PMKSA cache entry (IEEE 802.1X)"); |
| 2969 | } |
| 2970 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2971 | if (!success) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2972 | /* |
| 2973 | * Many devices require deauthentication after WPS provisioning |
| 2974 | * and some may not be be able to do that themselves, so |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2975 | * disconnect the client here. In addition, this may also |
| 2976 | * benefit IEEE 802.1X/EAPOL authentication cases, too since |
| 2977 | * the EAPOL PAE state machine would remain in HELD state for |
| 2978 | * considerable amount of time and some EAP methods, like |
| 2979 | * EAP-FAST with anonymous provisioning, may require another |
| 2980 | * EAPOL authentication to be started to complete connection. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2981 | */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2982 | ap_sta_delayed_1x_auth_fail_disconnect(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2983 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2984 | } |