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