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