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