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