Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant - WPA state machine and EAPOL-Key processing |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2018, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4 | * Copyright(c) 2015 Intel Deutschland GmbH |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include "includes.h" |
| 11 | |
| 12 | #include "common.h" |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 13 | #include "crypto/aes.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14 | #include "crypto/aes_wrap.h" |
| 15 | #include "crypto/crypto.h" |
| 16 | #include "crypto/random.h" |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 17 | #include "crypto/aes_siv.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 18 | #include "crypto/sha256.h" |
| 19 | #include "crypto/sha384.h" |
| 20 | #include "crypto/sha512.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 21 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 22 | #include "common/ieee802_11_common.h" |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 23 | #include "common/ocv.h" |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 24 | #include "common/dpp.h" |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 25 | #include "common/wpa_ctrl.h" |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 26 | #include "eap_common/eap_defs.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 27 | #include "eapol_supp/eapol_supp_sm.h" |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 28 | #include "drivers/driver.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 29 | #include "wpa.h" |
| 30 | #include "eloop.h" |
| 31 | #include "preauth.h" |
| 32 | #include "pmksa_cache.h" |
| 33 | #include "wpa_i.h" |
| 34 | #include "wpa_ie.h" |
Mir Ali | eaaf04e | 2021-06-07 12:17:29 +0530 | [diff] [blame] | 35 | #include "wpa_supplicant_i.h" |
| 36 | #include "driver_i.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 38 | static const u8 null_rsc[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 39 | |
| 40 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 41 | /** |
| 42 | * wpa_eapol_key_send - Send WPA/RSN EAPOL-Key message |
| 43 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 44 | * @ptk: PTK for Key Confirmation/Encryption Key |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 45 | * @ver: Version field from Key Info |
| 46 | * @dest: Destination address for the frame |
| 47 | * @proto: Ethertype (usually ETH_P_EAPOL) |
| 48 | * @msg: EAPOL-Key message |
| 49 | * @msg_len: Length of message |
| 50 | * @key_mic: Pointer to the buffer to which the EAPOL-Key MIC is written |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 51 | * Returns: >= 0 on success, < 0 on failure |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 52 | */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 53 | int wpa_eapol_key_send(struct wpa_sm *sm, struct wpa_ptk *ptk, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 54 | int ver, const u8 *dest, u16 proto, |
| 55 | u8 *msg, size_t msg_len, u8 *key_mic) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 56 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 57 | int ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 58 | size_t mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 59 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 60 | wpa_printf(MSG_DEBUG, "WPA: Send EAPOL-Key frame to " MACSTR |
| 61 | " ver=%d mic_len=%d key_mgmt=0x%x", |
| 62 | MAC2STR(dest), ver, (int) mic_len, sm->key_mgmt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 63 | if (is_zero_ether_addr(dest) && is_zero_ether_addr(sm->bssid)) { |
| 64 | /* |
| 65 | * Association event was not yet received; try to fetch |
| 66 | * BSSID from the driver. |
| 67 | */ |
| 68 | if (wpa_sm_get_bssid(sm, sm->bssid) < 0) { |
| 69 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 70 | "WPA: Failed to read BSSID for " |
| 71 | "EAPOL-Key destination address"); |
| 72 | } else { |
| 73 | dest = sm->bssid; |
| 74 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 75 | "WPA: Use BSSID (" MACSTR |
| 76 | ") as the destination for EAPOL-Key", |
| 77 | MAC2STR(dest)); |
| 78 | } |
| 79 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 80 | |
| 81 | if (mic_len) { |
| 82 | if (key_mic && (!ptk || !ptk->kck_len)) |
| 83 | goto out; |
| 84 | |
| 85 | if (key_mic && |
| 86 | wpa_eapol_key_mic(ptk->kck, ptk->kck_len, sm->key_mgmt, ver, |
| 87 | msg, msg_len, key_mic)) { |
| 88 | wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, |
| 89 | "WPA: Failed to generate EAPOL-Key version %d key_mgmt 0x%x MIC", |
| 90 | ver, sm->key_mgmt); |
| 91 | goto out; |
| 92 | } |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 93 | if (ptk) |
| 94 | wpa_hexdump_key(MSG_DEBUG, "WPA: KCK", |
| 95 | ptk->kck, ptk->kck_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 96 | wpa_hexdump(MSG_DEBUG, "WPA: Derived Key MIC", |
| 97 | key_mic, mic_len); |
| 98 | } else { |
| 99 | #ifdef CONFIG_FILS |
| 100 | /* AEAD cipher - Key MIC field not used */ |
| 101 | struct ieee802_1x_hdr *s_hdr, *hdr; |
| 102 | struct wpa_eapol_key *s_key, *key; |
| 103 | u8 *buf, *s_key_data, *key_data; |
| 104 | size_t buf_len = msg_len + AES_BLOCK_SIZE; |
| 105 | size_t key_data_len; |
| 106 | u16 eapol_len; |
| 107 | const u8 *aad[1]; |
| 108 | size_t aad_len[1]; |
| 109 | |
| 110 | if (!ptk || !ptk->kek_len) |
| 111 | goto out; |
| 112 | |
| 113 | key_data_len = msg_len - sizeof(struct ieee802_1x_hdr) - |
| 114 | sizeof(struct wpa_eapol_key) - 2; |
| 115 | |
| 116 | buf = os_malloc(buf_len); |
| 117 | if (!buf) |
| 118 | goto out; |
| 119 | |
| 120 | os_memcpy(buf, msg, msg_len); |
| 121 | hdr = (struct ieee802_1x_hdr *) buf; |
| 122 | key = (struct wpa_eapol_key *) (hdr + 1); |
| 123 | key_data = ((u8 *) (key + 1)) + 2; |
| 124 | |
| 125 | /* Update EAPOL header to include AES-SIV overhead */ |
| 126 | eapol_len = be_to_host16(hdr->length); |
| 127 | eapol_len += AES_BLOCK_SIZE; |
| 128 | hdr->length = host_to_be16(eapol_len); |
| 129 | |
| 130 | /* Update Key Data Length field to include AES-SIV overhead */ |
| 131 | WPA_PUT_BE16((u8 *) (key + 1), AES_BLOCK_SIZE + key_data_len); |
| 132 | |
| 133 | s_hdr = (struct ieee802_1x_hdr *) msg; |
| 134 | s_key = (struct wpa_eapol_key *) (s_hdr + 1); |
| 135 | s_key_data = ((u8 *) (s_key + 1)) + 2; |
| 136 | |
| 137 | wpa_hexdump_key(MSG_DEBUG, "WPA: Plaintext Key Data", |
| 138 | s_key_data, key_data_len); |
| 139 | |
| 140 | wpa_hexdump_key(MSG_DEBUG, "WPA: KEK", ptk->kek, ptk->kek_len); |
| 141 | /* AES-SIV AAD from EAPOL protocol version field (inclusive) to |
| 142 | * to Key Data (exclusive). */ |
| 143 | aad[0] = buf; |
| 144 | aad_len[0] = key_data - buf; |
| 145 | if (aes_siv_encrypt(ptk->kek, ptk->kek_len, |
| 146 | s_key_data, key_data_len, |
| 147 | 1, aad, aad_len, key_data) < 0) { |
| 148 | os_free(buf); |
| 149 | goto out; |
| 150 | } |
| 151 | |
| 152 | wpa_hexdump(MSG_DEBUG, "WPA: Encrypted Key Data from SIV", |
| 153 | key_data, AES_BLOCK_SIZE + key_data_len); |
| 154 | |
| 155 | os_free(msg); |
| 156 | msg = buf; |
| 157 | msg_len = buf_len; |
| 158 | #else /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 159 | goto out; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 160 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 161 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 162 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 163 | wpa_hexdump(MSG_MSGDUMP, "WPA: TX EAPOL-Key", msg, msg_len); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 164 | ret = wpa_sm_ether_send(sm, dest, proto, msg, msg_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 165 | eapol_sm_notify_tx_eapol_key(sm->eapol); |
| 166 | out: |
| 167 | os_free(msg); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 168 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | |
| 172 | /** |
| 173 | * wpa_sm_key_request - Send EAPOL-Key Request |
| 174 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 175 | * @error: Indicate whether this is an Michael MIC error report |
| 176 | * @pairwise: 1 = error report for pairwise packet, 0 = for group packet |
| 177 | * |
| 178 | * Send an EAPOL-Key Request to the current authenticator. This function is |
| 179 | * used to request rekeying and it is usually called when a local Michael MIC |
| 180 | * failure is detected. |
| 181 | */ |
| 182 | void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise) |
| 183 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 184 | size_t mic_len, hdrlen, rlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 185 | struct wpa_eapol_key *reply; |
| 186 | int key_info, ver; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 187 | u8 bssid[ETH_ALEN], *rbuf, *key_mic, *mic; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 188 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 189 | if (pairwise && sm->wpa_deny_ptk0_rekey && !sm->use_ext_key_id && |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 190 | wpa_sm_get_state(sm) == WPA_COMPLETED && !error) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 191 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 192 | "WPA: PTK0 rekey not allowed, reconnecting"); |
| 193 | wpa_sm_reconnect(sm); |
| 194 | return; |
| 195 | } |
| 196 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 197 | if (wpa_use_akm_defined(sm->key_mgmt)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 198 | ver = WPA_KEY_INFO_TYPE_AKM_DEFINED; |
| 199 | else if (wpa_key_mgmt_ft(sm->key_mgmt) || |
| 200 | wpa_key_mgmt_sha256(sm->key_mgmt)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 201 | ver = WPA_KEY_INFO_TYPE_AES_128_CMAC; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 202 | else if (sm->pairwise_cipher != WPA_CIPHER_TKIP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 203 | ver = WPA_KEY_INFO_TYPE_HMAC_SHA1_AES; |
| 204 | else |
| 205 | ver = WPA_KEY_INFO_TYPE_HMAC_MD5_RC4; |
| 206 | |
| 207 | if (wpa_sm_get_bssid(sm, bssid) < 0) { |
| 208 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 209 | "Failed to read BSSID for EAPOL-Key request"); |
| 210 | return; |
| 211 | } |
| 212 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 213 | mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 214 | hdrlen = sizeof(*reply) + mic_len + 2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 215 | rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 216 | hdrlen, &rlen, (void *) &reply); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 217 | if (rbuf == NULL) |
| 218 | return; |
| 219 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 220 | reply->type = (sm->proto == WPA_PROTO_RSN || |
| 221 | sm->proto == WPA_PROTO_OSEN) ? |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 222 | EAPOL_KEY_TYPE_RSN : EAPOL_KEY_TYPE_WPA; |
| 223 | key_info = WPA_KEY_INFO_REQUEST | ver; |
| 224 | if (sm->ptk_set) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 225 | key_info |= WPA_KEY_INFO_SECURE; |
| 226 | if (sm->ptk_set && mic_len) |
| 227 | key_info |= WPA_KEY_INFO_MIC; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 228 | if (error) |
| 229 | key_info |= WPA_KEY_INFO_ERROR; |
| 230 | if (pairwise) |
| 231 | key_info |= WPA_KEY_INFO_KEY_TYPE; |
| 232 | WPA_PUT_BE16(reply->key_info, key_info); |
| 233 | WPA_PUT_BE16(reply->key_length, 0); |
| 234 | os_memcpy(reply->replay_counter, sm->request_counter, |
| 235 | WPA_REPLAY_COUNTER_LEN); |
| 236 | inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN); |
| 237 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 238 | mic = (u8 *) (reply + 1); |
| 239 | WPA_PUT_BE16(mic + mic_len, 0); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 240 | if (!(key_info & WPA_KEY_INFO_MIC)) |
| 241 | key_mic = NULL; |
| 242 | else |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 243 | key_mic = mic; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 244 | |
| 245 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 246 | "WPA: Sending EAPOL-Key Request (error=%d " |
| 247 | "pairwise=%d ptk_set=%d len=%lu)", |
| 248 | error, pairwise, sm->ptk_set, (unsigned long) rlen); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 249 | wpa_eapol_key_send(sm, &sm->ptk, ver, bssid, ETH_P_EAPOL, rbuf, rlen, |
| 250 | key_mic); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 254 | static void wpa_supplicant_key_mgmt_set_pmk(struct wpa_sm *sm) |
| 255 | { |
| 256 | #ifdef CONFIG_IEEE80211R |
| 257 | if (sm->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) { |
| 258 | if (wpa_sm_key_mgmt_set_pmk(sm, sm->xxkey, sm->xxkey_len)) |
| 259 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 260 | "RSN: Cannot set low order 256 bits of MSK for key management offload"); |
| 261 | } else { |
| 262 | #endif /* CONFIG_IEEE80211R */ |
| 263 | if (wpa_sm_key_mgmt_set_pmk(sm, sm->pmk, sm->pmk_len)) |
| 264 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 265 | "RSN: Cannot set PMK for key management offload"); |
| 266 | #ifdef CONFIG_IEEE80211R |
| 267 | } |
| 268 | #endif /* CONFIG_IEEE80211R */ |
| 269 | } |
| 270 | |
| 271 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 272 | static int wpa_supplicant_get_pmk(struct wpa_sm *sm, |
| 273 | const unsigned char *src_addr, |
| 274 | const u8 *pmkid) |
| 275 | { |
| 276 | int abort_cached = 0; |
| 277 | |
| 278 | if (pmkid && !sm->cur_pmksa) { |
| 279 | /* When using drivers that generate RSN IE, wpa_supplicant may |
| 280 | * not have enough time to get the association information |
| 281 | * event before receiving this 1/4 message, so try to find a |
| 282 | * matching PMKSA cache entry here. */ |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 283 | sm->cur_pmksa = pmksa_cache_get(sm->pmksa, src_addr, pmkid, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 284 | NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 285 | if (sm->cur_pmksa) { |
| 286 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 287 | "RSN: found matching PMKID from PMKSA cache"); |
| 288 | } else { |
| 289 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 290 | "RSN: no matching PMKID found"); |
| 291 | abort_cached = 1; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | if (pmkid && sm->cur_pmksa && |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 296 | os_memcmp_const(pmkid, sm->cur_pmksa->pmkid, PMKID_LEN) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 297 | wpa_hexdump(MSG_DEBUG, "RSN: matched PMKID", pmkid, PMKID_LEN); |
| 298 | wpa_sm_set_pmk_from_pmksa(sm); |
| 299 | wpa_hexdump_key(MSG_DEBUG, "RSN: PMK from PMKSA cache", |
| 300 | sm->pmk, sm->pmk_len); |
| 301 | eapol_sm_notify_cached(sm->eapol); |
| 302 | #ifdef CONFIG_IEEE80211R |
| 303 | sm->xxkey_len = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 304 | #ifdef CONFIG_SAE |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 305 | if ((sm->key_mgmt == WPA_KEY_MGMT_FT_SAE || |
| 306 | sm->key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 307 | sm->pmk_len == PMK_LEN) { |
| 308 | /* Need to allow FT key derivation to proceed with |
| 309 | * PMK from SAE being used as the XXKey in cases where |
| 310 | * the PMKID in msg 1/4 matches the PMKSA entry that was |
| 311 | * just added based on SAE authentication for the |
| 312 | * initial mobility domain association. */ |
| 313 | os_memcpy(sm->xxkey, sm->pmk, sm->pmk_len); |
| 314 | sm->xxkey_len = sm->pmk_len; |
| 315 | } |
| 316 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 317 | #endif /* CONFIG_IEEE80211R */ |
| 318 | } else if (wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt) && sm->eapol) { |
| 319 | int res, pmk_len; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 320 | #ifdef CONFIG_IEEE80211R |
| 321 | u8 buf[2 * PMK_LEN]; |
| 322 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 323 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 324 | if (wpa_key_mgmt_sha384(sm->key_mgmt)) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 325 | pmk_len = PMK_LEN_SUITE_B_192; |
| 326 | else |
| 327 | pmk_len = PMK_LEN; |
| 328 | res = eapol_sm_get_key(sm->eapol, sm->pmk, pmk_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 329 | if (res) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 330 | if (pmk_len == PMK_LEN) { |
| 331 | /* |
| 332 | * EAP-LEAP is an exception from other EAP |
| 333 | * methods: it uses only 16-byte PMK. |
| 334 | */ |
| 335 | res = eapol_sm_get_key(sm->eapol, sm->pmk, 16); |
| 336 | pmk_len = 16; |
| 337 | } |
Hai Shalom | f1c9764 | 2019-07-19 23:42:07 +0000 | [diff] [blame] | 338 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 339 | #ifdef CONFIG_IEEE80211R |
| 340 | if (res == 0 && |
| 341 | eapol_sm_get_key(sm->eapol, buf, 2 * PMK_LEN) == 0) { |
| 342 | if (wpa_key_mgmt_sha384(sm->key_mgmt)) { |
| 343 | os_memcpy(sm->xxkey, buf, SHA384_MAC_LEN); |
| 344 | sm->xxkey_len = SHA384_MAC_LEN; |
| 345 | } else { |
| 346 | os_memcpy(sm->xxkey, buf + PMK_LEN, PMK_LEN); |
| 347 | sm->xxkey_len = PMK_LEN; |
| 348 | } |
| 349 | forced_memzero(buf, sizeof(buf)); |
| 350 | if (sm->proto == WPA_PROTO_RSN && |
| 351 | wpa_key_mgmt_ft(sm->key_mgmt)) { |
| 352 | struct rsn_pmksa_cache_entry *sa = NULL; |
| 353 | const u8 *fils_cache_id = NULL; |
| 354 | |
| 355 | #ifdef CONFIG_FILS |
| 356 | if (sm->fils_cache_id_set) |
| 357 | fils_cache_id = sm->fils_cache_id; |
| 358 | #endif /* CONFIG_FILS */ |
| 359 | wpa_hexdump_key(MSG_DEBUG, |
| 360 | "FT: Cache XXKey/MPMK", |
| 361 | sm->xxkey, sm->xxkey_len); |
| 362 | sa = pmksa_cache_add(sm->pmksa, |
| 363 | sm->xxkey, sm->xxkey_len, |
| 364 | NULL, NULL, 0, |
| 365 | src_addr, sm->own_addr, |
| 366 | sm->network_ctx, |
| 367 | sm->key_mgmt, |
| 368 | fils_cache_id); |
| 369 | if (!sm->cur_pmksa) |
| 370 | sm->cur_pmksa = sa; |
| 371 | } |
| 372 | } |
| 373 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 374 | if (res == 0) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 375 | struct rsn_pmksa_cache_entry *sa = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 376 | const u8 *fils_cache_id = NULL; |
| 377 | |
| 378 | #ifdef CONFIG_FILS |
| 379 | if (sm->fils_cache_id_set) |
| 380 | fils_cache_id = sm->fils_cache_id; |
| 381 | #endif /* CONFIG_FILS */ |
| 382 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 383 | wpa_hexdump_key(MSG_DEBUG, "WPA: PMK from EAPOL state " |
| 384 | "machines", sm->pmk, pmk_len); |
| 385 | sm->pmk_len = pmk_len; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 386 | wpa_supplicant_key_mgmt_set_pmk(sm); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 387 | if (sm->proto == WPA_PROTO_RSN && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 388 | !wpa_key_mgmt_suite_b(sm->key_mgmt) && |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 389 | !wpa_key_mgmt_ft(sm->key_mgmt)) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 390 | sa = pmksa_cache_add(sm->pmksa, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 391 | sm->pmk, pmk_len, NULL, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 392 | NULL, 0, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 393 | src_addr, sm->own_addr, |
| 394 | sm->network_ctx, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 395 | sm->key_mgmt, |
| 396 | fils_cache_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 397 | } |
| 398 | if (!sm->cur_pmksa && pmkid && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 399 | pmksa_cache_get(sm->pmksa, src_addr, pmkid, NULL, |
| 400 | 0)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 401 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 402 | "RSN: the new PMK matches with the " |
| 403 | "PMKID"); |
| 404 | abort_cached = 0; |
Jouni Malinen | 6ec3038 | 2015-07-08 20:48:18 +0300 | [diff] [blame] | 405 | } else if (sa && !sm->cur_pmksa && pmkid) { |
| 406 | /* |
| 407 | * It looks like the authentication server |
| 408 | * derived mismatching MSK. This should not |
| 409 | * really happen, but bugs happen.. There is not |
| 410 | * much we can do here without knowing what |
| 411 | * exactly caused the server to misbehave. |
| 412 | */ |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 413 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
Jouni Malinen | 6ec3038 | 2015-07-08 20:48:18 +0300 | [diff] [blame] | 414 | "RSN: PMKID mismatch - authentication server may have derived different MSK?!"); |
| 415 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 416 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 417 | |
| 418 | if (!sm->cur_pmksa) |
| 419 | sm->cur_pmksa = sa; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 420 | #ifdef CONFIG_IEEE80211R |
| 421 | } else if (wpa_key_mgmt_ft(sm->key_mgmt) && sm->ft_protocol) { |
| 422 | wpa_printf(MSG_DEBUG, |
| 423 | "FT: Continue 4-way handshake without PMK/PMKID for association using FT protocol"); |
| 424 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 425 | } else { |
| 426 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 427 | "WPA: Failed to get master session key from " |
| 428 | "EAPOL state machines - key handshake " |
| 429 | "aborted"); |
| 430 | if (sm->cur_pmksa) { |
| 431 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 432 | "RSN: Cancelled PMKSA caching " |
| 433 | "attempt"); |
| 434 | sm->cur_pmksa = NULL; |
| 435 | abort_cached = 1; |
| 436 | } else if (!abort_cached) { |
| 437 | return -1; |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 442 | if (abort_cached && wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 443 | !wpa_key_mgmt_suite_b(sm->key_mgmt) && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 444 | !wpa_key_mgmt_ft(sm->key_mgmt) && sm->key_mgmt != WPA_KEY_MGMT_OSEN) |
| 445 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 446 | /* Send EAPOL-Start to trigger full EAP authentication. */ |
| 447 | u8 *buf; |
| 448 | size_t buflen; |
| 449 | |
| 450 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 451 | "RSN: no PMKSA entry found - trigger " |
| 452 | "full EAP authentication"); |
| 453 | buf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_START, |
| 454 | NULL, 0, &buflen, NULL); |
| 455 | if (buf) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 456 | /* Set and reset eapFail to allow EAP state machine to |
| 457 | * proceed with new authentication. */ |
| 458 | eapol_sm_notify_eap_fail(sm->eapol, true); |
| 459 | eapol_sm_notify_eap_fail(sm->eapol, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 460 | wpa_sm_ether_send(sm, sm->bssid, ETH_P_EAPOL, |
| 461 | buf, buflen); |
| 462 | os_free(buf); |
| 463 | return -2; |
| 464 | } |
| 465 | |
| 466 | return -1; |
| 467 | } |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | |
| 473 | /** |
| 474 | * wpa_supplicant_send_2_of_4 - Send message 2 of WPA/RSN 4-Way Handshake |
| 475 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 476 | * @dst: Destination address for the frame |
| 477 | * @key: Pointer to the EAPOL-Key frame header |
| 478 | * @ver: Version bits from EAPOL-Key Key Info |
| 479 | * @nonce: Nonce value for the EAPOL-Key frame |
| 480 | * @wpa_ie: WPA/RSN IE |
| 481 | * @wpa_ie_len: Length of the WPA/RSN IE |
| 482 | * @ptk: PTK to use for keyed hash and encryption |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 483 | * Returns: >= 0 on success, < 0 on failure |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 484 | */ |
| 485 | int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst, |
| 486 | const struct wpa_eapol_key *key, |
| 487 | int ver, const u8 *nonce, |
| 488 | const u8 *wpa_ie, size_t wpa_ie_len, |
| 489 | struct wpa_ptk *ptk) |
| 490 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 491 | size_t mic_len, hdrlen, rlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 492 | struct wpa_eapol_key *reply; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 493 | u8 *rbuf, *key_mic; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 494 | u8 *rsn_ie_buf = NULL; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 495 | u16 key_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 496 | |
| 497 | if (wpa_ie == NULL) { |
| 498 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: No wpa_ie set - " |
| 499 | "cannot generate msg 2/4"); |
| 500 | return -1; |
| 501 | } |
| 502 | |
| 503 | #ifdef CONFIG_IEEE80211R |
| 504 | if (wpa_key_mgmt_ft(sm->key_mgmt)) { |
| 505 | int res; |
| 506 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 507 | wpa_hexdump(MSG_DEBUG, "WPA: WPA IE before FT processing", |
| 508 | wpa_ie, wpa_ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 509 | /* |
| 510 | * Add PMKR1Name into RSN IE (PMKID-List) and add MDIE and |
| 511 | * FTIE from (Re)Association Response. |
| 512 | */ |
| 513 | rsn_ie_buf = os_malloc(wpa_ie_len + 2 + 2 + PMKID_LEN + |
| 514 | sm->assoc_resp_ies_len); |
| 515 | if (rsn_ie_buf == NULL) |
| 516 | return -1; |
| 517 | os_memcpy(rsn_ie_buf, wpa_ie, wpa_ie_len); |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 518 | res = wpa_insert_pmkid(rsn_ie_buf, &wpa_ie_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 519 | sm->pmk_r1_name); |
| 520 | if (res < 0) { |
| 521 | os_free(rsn_ie_buf); |
| 522 | return -1; |
| 523 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 524 | wpa_hexdump(MSG_DEBUG, |
| 525 | "WPA: WPA IE after PMKID[PMKR1Name] addition into RSNE", |
| 526 | rsn_ie_buf, wpa_ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 527 | |
| 528 | if (sm->assoc_resp_ies) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 529 | wpa_hexdump(MSG_DEBUG, "WPA: Add assoc_resp_ies", |
| 530 | sm->assoc_resp_ies, |
| 531 | sm->assoc_resp_ies_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 532 | os_memcpy(rsn_ie_buf + wpa_ie_len, sm->assoc_resp_ies, |
| 533 | sm->assoc_resp_ies_len); |
| 534 | wpa_ie_len += sm->assoc_resp_ies_len; |
| 535 | } |
| 536 | |
| 537 | wpa_ie = rsn_ie_buf; |
| 538 | } |
| 539 | #endif /* CONFIG_IEEE80211R */ |
| 540 | |
| 541 | wpa_hexdump(MSG_DEBUG, "WPA: WPA IE for msg 2/4", wpa_ie, wpa_ie_len); |
| 542 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 543 | mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 544 | hdrlen = sizeof(*reply) + mic_len + 2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 545 | rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 546 | NULL, hdrlen + wpa_ie_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 547 | &rlen, (void *) &reply); |
| 548 | if (rbuf == NULL) { |
| 549 | os_free(rsn_ie_buf); |
| 550 | return -1; |
| 551 | } |
| 552 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 553 | reply->type = (sm->proto == WPA_PROTO_RSN || |
| 554 | sm->proto == WPA_PROTO_OSEN) ? |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 555 | EAPOL_KEY_TYPE_RSN : EAPOL_KEY_TYPE_WPA; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 556 | key_info = ver | WPA_KEY_INFO_KEY_TYPE; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 557 | if (sm->ptk_set && sm->proto != WPA_PROTO_WPA) |
| 558 | key_info |= WPA_KEY_INFO_SECURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 559 | if (mic_len) |
| 560 | key_info |= WPA_KEY_INFO_MIC; |
| 561 | else |
| 562 | key_info |= WPA_KEY_INFO_ENCR_KEY_DATA; |
| 563 | WPA_PUT_BE16(reply->key_info, key_info); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 564 | if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 565 | WPA_PUT_BE16(reply->key_length, 0); |
| 566 | else |
| 567 | os_memcpy(reply->key_length, key->key_length, 2); |
| 568 | os_memcpy(reply->replay_counter, key->replay_counter, |
| 569 | WPA_REPLAY_COUNTER_LEN); |
| 570 | wpa_hexdump(MSG_DEBUG, "WPA: Replay Counter", reply->replay_counter, |
| 571 | WPA_REPLAY_COUNTER_LEN); |
| 572 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 573 | key_mic = (u8 *) (reply + 1); |
| 574 | WPA_PUT_BE16(key_mic + mic_len, wpa_ie_len); /* Key Data Length */ |
| 575 | os_memcpy(key_mic + mic_len + 2, wpa_ie, wpa_ie_len); /* Key Data */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 576 | os_free(rsn_ie_buf); |
| 577 | |
| 578 | os_memcpy(reply->key_nonce, nonce, WPA_NONCE_LEN); |
| 579 | |
Roshan Pius | 5e7db94 | 2018-04-12 12:27:41 -0700 | [diff] [blame] | 580 | wpa_dbg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Sending EAPOL-Key 2/4"); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 581 | return wpa_eapol_key_send(sm, ptk, ver, dst, ETH_P_EAPOL, rbuf, rlen, |
| 582 | key_mic); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
| 586 | static int wpa_derive_ptk(struct wpa_sm *sm, const unsigned char *src_addr, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 587 | const struct wpa_eapol_key *key, struct wpa_ptk *ptk) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 588 | { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 589 | int ret; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 590 | const u8 *z = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 591 | size_t z_len = 0, kdk_len; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 592 | int akmp; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 593 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 594 | #ifdef CONFIG_IEEE80211R |
| 595 | if (wpa_key_mgmt_ft(sm->key_mgmt)) |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 596 | return wpa_derive_ptk_ft(sm, src_addr, key, ptk); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 597 | #endif /* CONFIG_IEEE80211R */ |
| 598 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 599 | #ifdef CONFIG_DPP2 |
| 600 | if (sm->key_mgmt == WPA_KEY_MGMT_DPP && sm->dpp_z) { |
| 601 | z = wpabuf_head(sm->dpp_z); |
| 602 | z_len = wpabuf_len(sm->dpp_z); |
| 603 | } |
| 604 | #endif /* CONFIG_DPP2 */ |
| 605 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 606 | akmp = sm->key_mgmt; |
| 607 | #ifdef CONFIG_OWE |
| 608 | if (sm->owe_ptk_workaround && akmp == WPA_KEY_MGMT_OWE && |
| 609 | sm->pmk_len > 32) { |
| 610 | wpa_printf(MSG_DEBUG, |
| 611 | "OWE: Force SHA256 for PTK derivation"); |
| 612 | akmp |= WPA_KEY_MGMT_PSK_SHA256; |
| 613 | } |
| 614 | #endif /* CONFIG_OWE */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 615 | |
| 616 | if (sm->force_kdk_derivation || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 617 | (sm->secure_ltf && |
| 618 | ieee802_11_rsnx_capab(sm->ap_rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF))) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 619 | kdk_len = WPA_KDK_MAX_LEN; |
| 620 | else |
| 621 | kdk_len = 0; |
| 622 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 623 | ret = wpa_pmk_to_ptk(sm->pmk, sm->pmk_len, "Pairwise key expansion", |
| 624 | sm->own_addr, sm->bssid, sm->snonce, |
| 625 | key->key_nonce, ptk, akmp, |
| 626 | sm->pairwise_cipher, z, z_len, |
| 627 | kdk_len); |
| 628 | if (ret) { |
| 629 | wpa_printf(MSG_ERROR, "WPA: PTK derivation failed"); |
| 630 | return ret; |
| 631 | } |
| 632 | |
| 633 | #ifdef CONFIG_PASN |
| 634 | if (sm->secure_ltf && |
| 635 | ieee802_11_rsnx_capab(sm->ap_rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF)) |
| 636 | ret = wpa_ltf_keyseed(ptk, akmp, sm->pairwise_cipher); |
| 637 | #endif /* CONFIG_PASN */ |
| 638 | |
| 639 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 643 | static int wpa_handle_ext_key_id(struct wpa_sm *sm, |
| 644 | struct wpa_eapol_ie_parse *kde) |
| 645 | { |
| 646 | if (sm->ext_key_id) { |
| 647 | u16 key_id; |
| 648 | |
| 649 | if (!kde->key_id) { |
| 650 | wpa_msg(sm->ctx->msg_ctx, |
| 651 | sm->use_ext_key_id ? MSG_INFO : MSG_DEBUG, |
| 652 | "RSN: No Key ID in Extended Key ID handshake"); |
| 653 | sm->keyidx_active = 0; |
| 654 | return sm->use_ext_key_id ? -1 : 0; |
| 655 | } |
| 656 | |
| 657 | key_id = kde->key_id[0] & 0x03; |
| 658 | if (key_id > 1) { |
| 659 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 660 | "RSN: Invalid Extended Key ID: %d", key_id); |
| 661 | return -1; |
| 662 | } |
| 663 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 664 | "RSN: Using Extended Key ID %d", key_id); |
| 665 | sm->keyidx_active = key_id; |
| 666 | sm->use_ext_key_id = 1; |
| 667 | } else { |
| 668 | if (kde->key_id && (kde->key_id[0] & 0x03)) { |
| 669 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 670 | "RSN: Non-zero Extended Key ID Key ID in PTK0 handshake"); |
| 671 | return -1; |
| 672 | } |
| 673 | |
| 674 | if (kde->key_id) { |
| 675 | /* This is not supposed to be included here, but ignore |
| 676 | * the case of matching Key ID 0 just in case. */ |
| 677 | wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 678 | "RSN: Extended Key ID Key ID 0 in PTK0 handshake"); |
| 679 | } |
| 680 | sm->keyidx_active = 0; |
| 681 | sm->use_ext_key_id = 0; |
| 682 | } |
| 683 | |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 688 | static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm, |
| 689 | const unsigned char *src_addr, |
| 690 | const struct wpa_eapol_key *key, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 691 | u16 ver, const u8 *key_data, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 692 | size_t key_data_len, |
| 693 | enum frame_encryption encrypted) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 694 | { |
| 695 | struct wpa_eapol_ie_parse ie; |
| 696 | struct wpa_ptk *ptk; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 697 | int res; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 698 | u8 *kde, *kde_buf = NULL; |
| 699 | size_t kde_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 700 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 701 | if (encrypted == FRAME_NOT_ENCRYPTED && sm->tk_set && |
| 702 | wpa_sm_pmf_enabled(sm)) { |
| 703 | wpa_printf(MSG_DEBUG, |
| 704 | "RSN: Discard unencrypted EAPOL-Key msg 1/4 when TK is set and PMF is enabled"); |
| 705 | return; |
| 706 | } |
| 707 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 708 | if (wpa_sm_get_network_ctx(sm) == NULL) { |
| 709 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: No SSID info " |
| 710 | "found (msg 1 of 4)"); |
| 711 | return; |
| 712 | } |
| 713 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 714 | if (sm->wpa_deny_ptk0_rekey && !sm->use_ext_key_id && |
| 715 | wpa_sm_get_state(sm) == WPA_COMPLETED) { |
| 716 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 717 | "WPA: PTK0 rekey not allowed, reconnecting"); |
| 718 | wpa_sm_reconnect(sm); |
| 719 | return; |
| 720 | } |
| 721 | |
Roshan Pius | 5e7db94 | 2018-04-12 12:27:41 -0700 | [diff] [blame] | 722 | wpa_dbg(sm->ctx->msg_ctx, MSG_INFO, "WPA: RX message 1 of 4-Way " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 723 | "Handshake from " MACSTR " (ver=%d)", MAC2STR(src_addr), ver); |
| 724 | |
| 725 | os_memset(&ie, 0, sizeof(ie)); |
| 726 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 727 | if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 728 | /* RSN: msg 1/4 should contain PMKID for the selected PMK */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 729 | wpa_hexdump(MSG_DEBUG, "RSN: msg 1/4 key data", |
| 730 | key_data, key_data_len); |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 731 | if (wpa_supplicant_parse_ies(key_data, key_data_len, &ie) < 0) { |
| 732 | wpa_printf(MSG_DEBUG, |
| 733 | "RSN: Discard EAPOL-Key msg 1/4 with invalid IEs/KDEs"); |
| 734 | return; |
| 735 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 736 | if (ie.pmkid) { |
| 737 | wpa_hexdump(MSG_DEBUG, "RSN: PMKID from " |
| 738 | "Authenticator", ie.pmkid, PMKID_LEN); |
| 739 | } |
| 740 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 741 | |
| 742 | res = wpa_supplicant_get_pmk(sm, src_addr, ie.pmkid); |
| 743 | if (res == -2) { |
| 744 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: Do not reply to " |
| 745 | "msg 1/4 - requesting full EAP authentication"); |
| 746 | return; |
| 747 | } |
| 748 | if (res) |
| 749 | goto failed; |
| 750 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 751 | wpa_sm_set_state(sm, WPA_4WAY_HANDSHAKE); |
| 752 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 753 | if (sm->renew_snonce) { |
| 754 | if (random_get_bytes(sm->snonce, WPA_NONCE_LEN)) { |
| 755 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 756 | "WPA: Failed to get random data for SNonce"); |
| 757 | goto failed; |
| 758 | } |
| 759 | sm->renew_snonce = 0; |
| 760 | wpa_hexdump(MSG_DEBUG, "WPA: Renewed SNonce", |
| 761 | sm->snonce, WPA_NONCE_LEN); |
| 762 | } |
| 763 | |
| 764 | /* Calculate PTK which will be stored as a temporary PTK until it has |
| 765 | * been verified when processing message 3/4. */ |
| 766 | ptk = &sm->tptk; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 767 | if (wpa_derive_ptk(sm, src_addr, key, ptk) < 0) |
| 768 | goto failed; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 769 | if (sm->pairwise_cipher == WPA_CIPHER_TKIP) { |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 770 | u8 buf[8]; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 771 | /* Supplicant: swap tx/rx Mic keys */ |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 772 | os_memcpy(buf, &ptk->tk[16], 8); |
| 773 | os_memcpy(&ptk->tk[16], &ptk->tk[24], 8); |
| 774 | os_memcpy(&ptk->tk[24], buf, 8); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 775 | forced_memzero(buf, sizeof(buf)); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 776 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 777 | sm->tptk_set = 1; |
| 778 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 779 | kde = sm->assoc_wpa_ie; |
| 780 | kde_len = sm->assoc_wpa_ie_len; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 781 | kde_buf = os_malloc(kde_len + |
| 782 | 2 + RSN_SELECTOR_LEN + 3 + |
| 783 | sm->assoc_rsnxe_len + |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 784 | 2 + RSN_SELECTOR_LEN + 1 + |
| 785 | 2 + RSN_SELECTOR_LEN + 2); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 786 | if (!kde_buf) |
| 787 | goto failed; |
| 788 | os_memcpy(kde_buf, kde, kde_len); |
| 789 | kde = kde_buf; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 790 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 791 | #ifdef CONFIG_OCV |
| 792 | if (wpa_sm_ocv_enabled(sm)) { |
| 793 | struct wpa_channel_info ci; |
| 794 | u8 *pos; |
| 795 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 796 | pos = kde + kde_len; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 797 | if (wpa_sm_channel_info(sm, &ci) != 0) { |
| 798 | wpa_printf(MSG_WARNING, |
| 799 | "Failed to get channel info for OCI element in EAPOL-Key 2/4"); |
| 800 | goto failed; |
| 801 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 802 | #ifdef CONFIG_TESTING_OPTIONS |
| 803 | if (sm->oci_freq_override_eapol) { |
| 804 | wpa_printf(MSG_INFO, |
| 805 | "TEST: Override OCI KDE frequency %d -> %d MHz", |
| 806 | ci.frequency, sm->oci_freq_override_eapol); |
| 807 | ci.frequency = sm->oci_freq_override_eapol; |
| 808 | } |
| 809 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 810 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 811 | if (ocv_insert_oci_kde(&ci, &pos) < 0) |
| 812 | goto failed; |
| 813 | kde_len = pos - kde; |
| 814 | } |
| 815 | #endif /* CONFIG_OCV */ |
| 816 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 817 | if (sm->assoc_rsnxe && sm->assoc_rsnxe_len) { |
| 818 | os_memcpy(kde + kde_len, sm->assoc_rsnxe, sm->assoc_rsnxe_len); |
| 819 | kde_len += sm->assoc_rsnxe_len; |
| 820 | } |
| 821 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 822 | #ifdef CONFIG_P2P |
| 823 | if (sm->p2p) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 824 | u8 *pos; |
| 825 | |
| 826 | wpa_printf(MSG_DEBUG, |
| 827 | "P2P: Add IP Address Request KDE into EAPOL-Key 2/4"); |
| 828 | pos = kde + kde_len; |
| 829 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 830 | *pos++ = RSN_SELECTOR_LEN + 1; |
| 831 | RSN_SELECTOR_PUT(pos, WFA_KEY_DATA_IP_ADDR_REQ); |
| 832 | pos += RSN_SELECTOR_LEN; |
| 833 | *pos++ = 0x01; |
| 834 | kde_len = pos - kde; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 835 | } |
| 836 | #endif /* CONFIG_P2P */ |
| 837 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 838 | #ifdef CONFIG_DPP2 |
| 839 | if (DPP_VERSION > 1 && sm->key_mgmt == WPA_KEY_MGMT_DPP) { |
| 840 | u8 *pos; |
| 841 | |
| 842 | wpa_printf(MSG_DEBUG, "DPP: Add DPP KDE into EAPOL-Key 2/4"); |
| 843 | pos = kde + kde_len; |
| 844 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 845 | *pos++ = RSN_SELECTOR_LEN + 2; |
| 846 | RSN_SELECTOR_PUT(pos, WFA_KEY_DATA_DPP); |
| 847 | pos += RSN_SELECTOR_LEN; |
| 848 | *pos++ = DPP_VERSION; /* Protocol Version */ |
| 849 | *pos = 0; /* Flags */ |
| 850 | if (sm->dpp_pfs == 0) |
| 851 | *pos |= DPP_KDE_PFS_ALLOWED; |
| 852 | else if (sm->dpp_pfs == 1) |
| 853 | *pos |= DPP_KDE_PFS_ALLOWED | DPP_KDE_PFS_REQUIRED; |
| 854 | pos++; |
| 855 | kde_len = pos - kde; |
| 856 | } |
| 857 | #endif /* CONFIG_DPP2 */ |
| 858 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 859 | if (wpa_supplicant_send_2_of_4(sm, sm->bssid, key, ver, sm->snonce, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 860 | kde, kde_len, ptk) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 861 | goto failed; |
| 862 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 863 | os_free(kde_buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 864 | os_memcpy(sm->anonce, key->key_nonce, WPA_NONCE_LEN); |
| 865 | return; |
| 866 | |
| 867 | failed: |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 868 | os_free(kde_buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 869 | wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); |
| 870 | } |
| 871 | |
| 872 | |
| 873 | static void wpa_sm_start_preauth(void *eloop_ctx, void *timeout_ctx) |
| 874 | { |
| 875 | struct wpa_sm *sm = eloop_ctx; |
| 876 | rsn_preauth_candidate_process(sm); |
| 877 | } |
| 878 | |
| 879 | |
| 880 | static void wpa_supplicant_key_neg_complete(struct wpa_sm *sm, |
| 881 | const u8 *addr, int secure) |
| 882 | { |
| 883 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 884 | "WPA: Key negotiation completed with " |
| 885 | MACSTR " [PTK=%s GTK=%s]", MAC2STR(addr), |
| 886 | wpa_cipher_txt(sm->pairwise_cipher), |
| 887 | wpa_cipher_txt(sm->group_cipher)); |
| 888 | wpa_sm_cancel_auth_timeout(sm); |
| 889 | wpa_sm_set_state(sm, WPA_COMPLETED); |
| 890 | |
| 891 | if (secure) { |
| 892 | wpa_sm_mlme_setprotection( |
| 893 | sm, addr, MLME_SETPROTECTION_PROTECT_TYPE_RX_TX, |
| 894 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 895 | eapol_sm_notify_portValid(sm->eapol, true); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 896 | if (wpa_key_mgmt_wpa_psk(sm->key_mgmt) || |
| 897 | sm->key_mgmt == WPA_KEY_MGMT_DPP || |
| 898 | sm->key_mgmt == WPA_KEY_MGMT_OWE) |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 899 | eapol_sm_notify_eap_success(sm->eapol, true); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 900 | /* |
| 901 | * Start preauthentication after a short wait to avoid a |
| 902 | * possible race condition between the data receive and key |
| 903 | * configuration after the 4-Way Handshake. This increases the |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 904 | * likelihood of the first preauth EAPOL-Start frame getting to |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 905 | * the target AP. |
| 906 | */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 907 | if (!dl_list_empty(&sm->pmksa_candidates)) |
| 908 | eloop_register_timeout(1, 0, wpa_sm_start_preauth, |
| 909 | sm, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | if (sm->cur_pmksa && sm->cur_pmksa->opportunistic) { |
| 913 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 914 | "RSN: Authenticator accepted " |
| 915 | "opportunistic PMKSA entry - marking it valid"); |
| 916 | sm->cur_pmksa->opportunistic = 0; |
| 917 | } |
| 918 | |
| 919 | #ifdef CONFIG_IEEE80211R |
| 920 | if (wpa_key_mgmt_ft(sm->key_mgmt)) { |
| 921 | /* Prepare for the next transition */ |
| 922 | wpa_ft_prepare_auth_request(sm, NULL); |
| 923 | } |
| 924 | #endif /* CONFIG_IEEE80211R */ |
| 925 | } |
| 926 | |
| 927 | |
| 928 | static void wpa_sm_rekey_ptk(void *eloop_ctx, void *timeout_ctx) |
| 929 | { |
| 930 | struct wpa_sm *sm = eloop_ctx; |
| 931 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Request PTK rekeying"); |
| 932 | wpa_sm_key_request(sm, 0, 1); |
| 933 | } |
| 934 | |
| 935 | |
| 936 | static int wpa_supplicant_install_ptk(struct wpa_sm *sm, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 937 | const struct wpa_eapol_key *key, |
| 938 | enum key_flag key_flag) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 939 | { |
| 940 | int keylen, rsclen; |
| 941 | enum wpa_alg alg; |
| 942 | const u8 *key_rsc; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 943 | |
Mathy Vanhoef | c66556c | 2017-09-29 04:22:51 +0200 | [diff] [blame] | 944 | if (sm->ptk.installed) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 945 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 946 | "WPA: Do not re-install same PTK to the driver"); |
| 947 | return 0; |
| 948 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 949 | |
| 950 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 951 | "WPA: Installing PTK to the driver"); |
| 952 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 953 | if (sm->pairwise_cipher == WPA_CIPHER_NONE) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 954 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Pairwise Cipher " |
| 955 | "Suite: NONE - do not use pairwise keys"); |
| 956 | return 0; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 960 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 961 | "WPA: Unsupported pairwise cipher %d", |
| 962 | sm->pairwise_cipher); |
| 963 | return -1; |
| 964 | } |
| 965 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 966 | alg = wpa_cipher_to_alg(sm->pairwise_cipher); |
| 967 | keylen = wpa_cipher_key_len(sm->pairwise_cipher); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 968 | if (keylen <= 0 || (unsigned int) keylen != sm->ptk.tk_len) { |
| 969 | wpa_printf(MSG_DEBUG, "WPA: TK length mismatch: %d != %lu", |
| 970 | keylen, (long unsigned int) sm->ptk.tk_len); |
| 971 | return -1; |
| 972 | } |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 973 | rsclen = wpa_cipher_rsc_len(sm->pairwise_cipher); |
| 974 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 975 | if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 976 | key_rsc = null_rsc; |
| 977 | } else { |
| 978 | key_rsc = key->key_rsc; |
| 979 | wpa_hexdump(MSG_DEBUG, "WPA: RSC", key_rsc, rsclen); |
| 980 | } |
| 981 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 982 | if (wpa_sm_set_key(sm, alg, sm->bssid, sm->keyidx_active, 1, key_rsc, |
| 983 | rsclen, sm->ptk.tk, keylen, |
| 984 | KEY_FLAG_PAIRWISE | key_flag) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 985 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 986 | "WPA: Failed to set PTK to the driver (alg=%d keylen=%d bssid=" |
| 987 | MACSTR " idx=%d key_flag=0x%x)", |
| 988 | alg, keylen, MAC2STR(sm->bssid), |
| 989 | sm->keyidx_active, key_flag); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 990 | return -1; |
| 991 | } |
| 992 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 993 | #ifdef CONFIG_PASN |
| 994 | if (sm->secure_ltf && |
| 995 | ieee802_11_rsnx_capab(sm->ap_rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF) && |
| 996 | wpa_sm_set_ltf_keyseed(sm, sm->own_addr, sm->bssid, |
| 997 | sm->ptk.ltf_keyseed_len, |
| 998 | sm->ptk.ltf_keyseed) < 0) { |
| 999 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1000 | "WPA: Failed to set LTF keyseed to the driver (keylen=%zu bssid=" |
| 1001 | MACSTR ")", sm->ptk.ltf_keyseed_len, |
| 1002 | MAC2STR(sm->bssid)); |
| 1003 | return -1; |
| 1004 | } |
| 1005 | #endif /* CONFIG_PASN */ |
| 1006 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1007 | wpa_sm_store_ptk(sm, sm->bssid, sm->pairwise_cipher, |
| 1008 | sm->dot11RSNAConfigPMKLifetime, &sm->ptk); |
| 1009 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1010 | /* TK is not needed anymore in supplicant */ |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1011 | os_memset(sm->ptk.tk, 0, WPA_TK_MAX_LEN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1012 | sm->ptk.tk_len = 0; |
Mathy Vanhoef | c66556c | 2017-09-29 04:22:51 +0200 | [diff] [blame] | 1013 | sm->ptk.installed = 1; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1014 | sm->tk_set = true; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1015 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1016 | if (sm->wpa_ptk_rekey) { |
| 1017 | eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL); |
| 1018 | eloop_register_timeout(sm->wpa_ptk_rekey, 0, wpa_sm_rekey_ptk, |
| 1019 | sm, NULL); |
| 1020 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1021 | return 0; |
| 1022 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1023 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1024 | |
| 1025 | static int wpa_supplicant_activate_ptk(struct wpa_sm *sm) |
| 1026 | { |
| 1027 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1028 | "WPA: Activate PTK (idx=%d bssid=" MACSTR ")", |
| 1029 | sm->keyidx_active, MAC2STR(sm->bssid)); |
| 1030 | |
| 1031 | if (wpa_sm_set_key(sm, 0, sm->bssid, sm->keyidx_active, 0, NULL, 0, |
| 1032 | NULL, 0, KEY_FLAG_PAIRWISE_RX_TX_MODIFY) < 0) { |
| 1033 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1034 | "WPA: Failed to activate PTK for TX (idx=%d bssid=" |
| 1035 | MACSTR ")", sm->keyidx_active, MAC2STR(sm->bssid)); |
| 1036 | return -1; |
| 1037 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | static int wpa_supplicant_check_group_cipher(struct wpa_sm *sm, |
| 1043 | int group_cipher, |
| 1044 | int keylen, int maxkeylen, |
| 1045 | int *key_rsc_len, |
| 1046 | enum wpa_alg *alg) |
| 1047 | { |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1048 | int klen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1049 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1050 | *alg = wpa_cipher_to_alg(group_cipher); |
| 1051 | if (*alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1052 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1053 | "WPA: Unsupported Group Cipher %d", |
| 1054 | group_cipher); |
| 1055 | return -1; |
| 1056 | } |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1057 | *key_rsc_len = wpa_cipher_rsc_len(group_cipher); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1058 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1059 | klen = wpa_cipher_key_len(group_cipher); |
| 1060 | if (keylen != klen || maxkeylen < klen) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1061 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1062 | "WPA: Unsupported %s Group Cipher key length %d (%d)", |
| 1063 | wpa_cipher_txt(group_cipher), keylen, maxkeylen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1064 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1065 | } |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1066 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | struct wpa_gtk_data { |
| 1071 | enum wpa_alg alg; |
| 1072 | int tx, key_rsc_len, keyidx; |
| 1073 | u8 gtk[32]; |
| 1074 | int gtk_len; |
| 1075 | }; |
| 1076 | |
| 1077 | |
| 1078 | static int wpa_supplicant_install_gtk(struct wpa_sm *sm, |
| 1079 | const struct wpa_gtk_data *gd, |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 1080 | const u8 *key_rsc, int wnm_sleep) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1081 | { |
| 1082 | const u8 *_gtk = gd->gtk; |
| 1083 | u8 gtk_buf[32]; |
| 1084 | |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1085 | /* Detect possible key reinstallation */ |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 1086 | if ((sm->gtk.gtk_len == (size_t) gd->gtk_len && |
| 1087 | os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) || |
| 1088 | (sm->gtk_wnm_sleep.gtk_len == (size_t) gd->gtk_len && |
| 1089 | os_memcmp(sm->gtk_wnm_sleep.gtk, gd->gtk, |
| 1090 | sm->gtk_wnm_sleep.gtk_len) == 0)) { |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1091 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1092 | "WPA: Not reinstalling already in-use GTK to the driver (keyidx=%d tx=%d len=%d)", |
| 1093 | gd->keyidx, gd->tx, gd->gtk_len); |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1097 | wpa_hexdump_key(MSG_DEBUG, "WPA: Group Key", gd->gtk, gd->gtk_len); |
| 1098 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1099 | "WPA: Installing GTK to the driver (keyidx=%d tx=%d len=%d)", |
| 1100 | gd->keyidx, gd->tx, gd->gtk_len); |
| 1101 | wpa_hexdump(MSG_DEBUG, "WPA: RSC", key_rsc, gd->key_rsc_len); |
| 1102 | if (sm->group_cipher == WPA_CIPHER_TKIP) { |
| 1103 | /* Swap Tx/Rx keys for Michael MIC */ |
| 1104 | os_memcpy(gtk_buf, gd->gtk, 16); |
| 1105 | os_memcpy(gtk_buf + 16, gd->gtk + 24, 8); |
| 1106 | os_memcpy(gtk_buf + 24, gd->gtk + 16, 8); |
| 1107 | _gtk = gtk_buf; |
| 1108 | } |
| 1109 | if (sm->pairwise_cipher == WPA_CIPHER_NONE) { |
| 1110 | if (wpa_sm_set_key(sm, gd->alg, NULL, |
| 1111 | gd->keyidx, 1, key_rsc, gd->key_rsc_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1112 | _gtk, gd->gtk_len, |
| 1113 | KEY_FLAG_GROUP_RX_TX_DEFAULT) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1114 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1115 | "WPA: Failed to set GTK to the driver " |
| 1116 | "(Group only)"); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1117 | forced_memzero(gtk_buf, sizeof(gtk_buf)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1118 | return -1; |
| 1119 | } |
| 1120 | } else if (wpa_sm_set_key(sm, gd->alg, broadcast_ether_addr, |
| 1121 | gd->keyidx, gd->tx, key_rsc, gd->key_rsc_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1122 | _gtk, gd->gtk_len, KEY_FLAG_GROUP_RX) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1123 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1124 | "WPA: Failed to set GTK to " |
| 1125 | "the driver (alg=%d keylen=%d keyidx=%d)", |
| 1126 | gd->alg, gd->gtk_len, gd->keyidx); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1127 | forced_memzero(gtk_buf, sizeof(gtk_buf)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1128 | return -1; |
| 1129 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1130 | forced_memzero(gtk_buf, sizeof(gtk_buf)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1131 | |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 1132 | if (wnm_sleep) { |
| 1133 | sm->gtk_wnm_sleep.gtk_len = gd->gtk_len; |
| 1134 | os_memcpy(sm->gtk_wnm_sleep.gtk, gd->gtk, |
| 1135 | sm->gtk_wnm_sleep.gtk_len); |
| 1136 | } else { |
| 1137 | sm->gtk.gtk_len = gd->gtk_len; |
| 1138 | os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len); |
| 1139 | } |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1140 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | static int wpa_supplicant_gtk_tx_bit_workaround(const struct wpa_sm *sm, |
| 1146 | int tx) |
| 1147 | { |
| 1148 | if (tx && sm->pairwise_cipher != WPA_CIPHER_NONE) { |
| 1149 | /* Ignore Tx bit for GTK if a pairwise key is used. One AP |
| 1150 | * seemed to set this bit (incorrectly, since Tx is only when |
| 1151 | * doing Group Key only APs) and without this workaround, the |
| 1152 | * data connection does not work because wpa_supplicant |
| 1153 | * configured non-zero keyidx to be used for unicast. */ |
| 1154 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1155 | "WPA: Tx bit set for GTK, but pairwise " |
| 1156 | "keys are used - ignore Tx bit"); |
| 1157 | return 0; |
| 1158 | } |
| 1159 | return tx; |
| 1160 | } |
| 1161 | |
| 1162 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1163 | static int wpa_supplicant_rsc_relaxation(const struct wpa_sm *sm, |
| 1164 | const u8 *rsc) |
| 1165 | { |
| 1166 | int rsclen; |
| 1167 | |
| 1168 | if (!sm->wpa_rsc_relaxation) |
| 1169 | return 0; |
| 1170 | |
| 1171 | rsclen = wpa_cipher_rsc_len(sm->group_cipher); |
| 1172 | |
| 1173 | /* |
| 1174 | * Try to detect RSC (endian) corruption issue where the AP sends |
| 1175 | * the RSC bytes in EAPOL-Key message in the wrong order, both if |
| 1176 | * it's actually a 6-byte field (as it should be) and if it treats |
| 1177 | * it as an 8-byte field. |
| 1178 | * An AP model known to have this bug is the Sapido RB-1632. |
| 1179 | */ |
| 1180 | if (rsclen == 6 && ((rsc[5] && !rsc[0]) || rsc[6] || rsc[7])) { |
| 1181 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1182 | "RSC %02x%02x%02x%02x%02x%02x%02x%02x is likely bogus, using 0", |
| 1183 | rsc[0], rsc[1], rsc[2], rsc[3], |
| 1184 | rsc[4], rsc[5], rsc[6], rsc[7]); |
| 1185 | |
| 1186 | return 1; |
| 1187 | } |
| 1188 | |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1193 | static int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm, |
| 1194 | const struct wpa_eapol_key *key, |
| 1195 | const u8 *gtk, size_t gtk_len, |
| 1196 | int key_info) |
| 1197 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1198 | struct wpa_gtk_data gd; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1199 | const u8 *key_rsc; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1200 | |
| 1201 | /* |
| 1202 | * IEEE Std 802.11i-2004 - 8.5.2 EAPOL-Key frames - Figure 43x |
| 1203 | * GTK KDE format: |
| 1204 | * KeyID[bits 0-1], Tx [bit 2], Reserved [bits 3-7] |
| 1205 | * Reserved [bits 0-7] |
| 1206 | * GTK |
| 1207 | */ |
| 1208 | |
| 1209 | os_memset(&gd, 0, sizeof(gd)); |
| 1210 | wpa_hexdump_key(MSG_DEBUG, "RSN: received GTK in pairwise handshake", |
| 1211 | gtk, gtk_len); |
| 1212 | |
| 1213 | if (gtk_len < 2 || gtk_len - 2 > sizeof(gd.gtk)) |
| 1214 | return -1; |
| 1215 | |
| 1216 | gd.keyidx = gtk[0] & 0x3; |
| 1217 | gd.tx = wpa_supplicant_gtk_tx_bit_workaround(sm, |
| 1218 | !!(gtk[0] & BIT(2))); |
| 1219 | gtk += 2; |
| 1220 | gtk_len -= 2; |
| 1221 | |
| 1222 | os_memcpy(gd.gtk, gtk, gtk_len); |
| 1223 | gd.gtk_len = gtk_len; |
| 1224 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1225 | key_rsc = key->key_rsc; |
| 1226 | if (wpa_supplicant_rsc_relaxation(sm, key->key_rsc)) |
| 1227 | key_rsc = null_rsc; |
| 1228 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1229 | if (sm->group_cipher != WPA_CIPHER_GTK_NOT_USED && |
| 1230 | (wpa_supplicant_check_group_cipher(sm, sm->group_cipher, |
| 1231 | gtk_len, gtk_len, |
| 1232 | &gd.key_rsc_len, &gd.alg) || |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 1233 | wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1234 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1235 | "RSN: Failed to install GTK"); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1236 | forced_memzero(&gd, sizeof(gd)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1237 | return -1; |
| 1238 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1239 | forced_memzero(&gd, sizeof(gd)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1240 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1241 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1245 | static int wpa_supplicant_install_igtk(struct wpa_sm *sm, |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 1246 | const struct wpa_igtk_kde *igtk, |
| 1247 | int wnm_sleep) |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1248 | { |
| 1249 | size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher); |
| 1250 | u16 keyidx = WPA_GET_LE16(igtk->keyid); |
| 1251 | |
| 1252 | /* Detect possible key reinstallation */ |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 1253 | if ((sm->igtk.igtk_len == len && |
| 1254 | os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) || |
| 1255 | (sm->igtk_wnm_sleep.igtk_len == len && |
| 1256 | os_memcmp(sm->igtk_wnm_sleep.igtk, igtk->igtk, |
| 1257 | sm->igtk_wnm_sleep.igtk_len) == 0)) { |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1258 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1259 | "WPA: Not reinstalling already in-use IGTK to the driver (keyidx=%d)", |
| 1260 | keyidx); |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
| 1264 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1265 | "WPA: IGTK keyid %d pn " COMPACT_MACSTR, |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1266 | keyidx, MAC2STR(igtk->pn)); |
| 1267 | wpa_hexdump_key(MSG_DEBUG, "WPA: IGTK", igtk->igtk, len); |
| 1268 | if (keyidx > 4095) { |
| 1269 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1270 | "WPA: Invalid IGTK KeyID %d", keyidx); |
| 1271 | return -1; |
| 1272 | } |
| 1273 | if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher), |
| 1274 | broadcast_ether_addr, |
| 1275 | keyidx, 0, igtk->pn, sizeof(igtk->pn), |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1276 | igtk->igtk, len, KEY_FLAG_GROUP_RX) < 0) { |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 1277 | if (keyidx == 0x0400 || keyidx == 0x0500) { |
| 1278 | /* Assume the AP has broken PMF implementation since it |
| 1279 | * seems to have swapped the KeyID bytes. The AP cannot |
| 1280 | * be trusted to implement BIP correctly or provide a |
| 1281 | * valid IGTK, so do not try to configure this key with |
| 1282 | * swapped KeyID bytes. Instead, continue without |
| 1283 | * configuring the IGTK so that the driver can drop any |
| 1284 | * received group-addressed robust management frames due |
| 1285 | * to missing keys. |
| 1286 | * |
| 1287 | * Normally, this error behavior would result in us |
| 1288 | * disconnecting, but there are number of deployed APs |
| 1289 | * with this broken behavior, so as an interoperability |
| 1290 | * workaround, allow the connection to proceed. */ |
| 1291 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1292 | "WPA: Ignore IGTK configuration error due to invalid IGTK KeyID byte order"); |
| 1293 | } else { |
| 1294 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1295 | "WPA: Failed to configure IGTK to the driver"); |
| 1296 | return -1; |
| 1297 | } |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1298 | } |
| 1299 | |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 1300 | if (wnm_sleep) { |
| 1301 | sm->igtk_wnm_sleep.igtk_len = len; |
| 1302 | os_memcpy(sm->igtk_wnm_sleep.igtk, igtk->igtk, |
| 1303 | sm->igtk_wnm_sleep.igtk_len); |
| 1304 | } else { |
| 1305 | sm->igtk.igtk_len = len; |
| 1306 | os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len); |
| 1307 | } |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1308 | |
| 1309 | return 0; |
| 1310 | } |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1311 | |
| 1312 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1313 | static int wpa_supplicant_install_bigtk(struct wpa_sm *sm, |
| 1314 | const struct wpa_bigtk_kde *bigtk, |
| 1315 | int wnm_sleep) |
| 1316 | { |
| 1317 | size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher); |
| 1318 | u16 keyidx = WPA_GET_LE16(bigtk->keyid); |
| 1319 | |
| 1320 | /* Detect possible key reinstallation */ |
| 1321 | if ((sm->bigtk.bigtk_len == len && |
| 1322 | os_memcmp(sm->bigtk.bigtk, bigtk->bigtk, |
| 1323 | sm->bigtk.bigtk_len) == 0) || |
| 1324 | (sm->bigtk_wnm_sleep.bigtk_len == len && |
| 1325 | os_memcmp(sm->bigtk_wnm_sleep.bigtk, bigtk->bigtk, |
| 1326 | sm->bigtk_wnm_sleep.bigtk_len) == 0)) { |
| 1327 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1328 | "WPA: Not reinstalling already in-use BIGTK to the driver (keyidx=%d)", |
| 1329 | keyidx); |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
| 1333 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1334 | "WPA: BIGTK keyid %d pn " COMPACT_MACSTR, |
| 1335 | keyidx, MAC2STR(bigtk->pn)); |
| 1336 | wpa_hexdump_key(MSG_DEBUG, "WPA: BIGTK", bigtk->bigtk, len); |
| 1337 | if (keyidx < 6 || keyidx > 7) { |
| 1338 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1339 | "WPA: Invalid BIGTK KeyID %d", keyidx); |
| 1340 | return -1; |
| 1341 | } |
| 1342 | if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher), |
| 1343 | broadcast_ether_addr, |
| 1344 | keyidx, 0, bigtk->pn, sizeof(bigtk->pn), |
| 1345 | bigtk->bigtk, len, KEY_FLAG_GROUP_RX) < 0) { |
| 1346 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1347 | "WPA: Failed to configure BIGTK to the driver"); |
| 1348 | return -1; |
| 1349 | } |
| 1350 | |
| 1351 | if (wnm_sleep) { |
| 1352 | sm->bigtk_wnm_sleep.bigtk_len = len; |
| 1353 | os_memcpy(sm->bigtk_wnm_sleep.bigtk, bigtk->bigtk, |
| 1354 | sm->bigtk_wnm_sleep.bigtk_len); |
| 1355 | } else { |
| 1356 | sm->bigtk.bigtk_len = len; |
| 1357 | os_memcpy(sm->bigtk.bigtk, bigtk->bigtk, sm->bigtk.bigtk_len); |
| 1358 | } |
| 1359 | |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
| 1363 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1364 | static int ieee80211w_set_keys(struct wpa_sm *sm, |
| 1365 | struct wpa_eapol_ie_parse *ie) |
| 1366 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1367 | size_t len; |
| 1368 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1369 | if (!wpa_cipher_valid_mgmt_group(sm->mgmt_group_cipher) || |
| 1370 | sm->mgmt_group_cipher == WPA_CIPHER_GTK_NOT_USED) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1371 | return 0; |
| 1372 | |
| 1373 | if (ie->igtk) { |
| 1374 | const struct wpa_igtk_kde *igtk; |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1375 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1376 | len = wpa_cipher_key_len(sm->mgmt_group_cipher); |
| 1377 | if (ie->igtk_len != WPA_IGTK_KDE_PREFIX_LEN + len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1378 | return -1; |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 1379 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1380 | igtk = (const struct wpa_igtk_kde *) ie->igtk; |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 1381 | if (wpa_supplicant_install_igtk(sm, igtk, 0) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1382 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1385 | if (ie->bigtk && sm->beacon_prot) { |
| 1386 | const struct wpa_bigtk_kde *bigtk; |
| 1387 | |
| 1388 | len = wpa_cipher_key_len(sm->mgmt_group_cipher); |
| 1389 | if (ie->bigtk_len != WPA_BIGTK_KDE_PREFIX_LEN + len) |
| 1390 | return -1; |
| 1391 | |
| 1392 | bigtk = (const struct wpa_bigtk_kde *) ie->bigtk; |
| 1393 | if (wpa_supplicant_install_bigtk(sm, bigtk, 0) < 0) |
| 1394 | return -1; |
| 1395 | } |
| 1396 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1397 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | |
| 1401 | static void wpa_report_ie_mismatch(struct wpa_sm *sm, |
| 1402 | const char *reason, const u8 *src_addr, |
| 1403 | const u8 *wpa_ie, size_t wpa_ie_len, |
| 1404 | const u8 *rsn_ie, size_t rsn_ie_len) |
| 1405 | { |
| 1406 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: %s (src=" MACSTR ")", |
| 1407 | reason, MAC2STR(src_addr)); |
| 1408 | |
| 1409 | if (sm->ap_wpa_ie) { |
| 1410 | wpa_hexdump(MSG_INFO, "WPA: WPA IE in Beacon/ProbeResp", |
| 1411 | sm->ap_wpa_ie, sm->ap_wpa_ie_len); |
| 1412 | } |
| 1413 | if (wpa_ie) { |
| 1414 | if (!sm->ap_wpa_ie) { |
| 1415 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1416 | "WPA: No WPA IE in Beacon/ProbeResp"); |
| 1417 | } |
| 1418 | wpa_hexdump(MSG_INFO, "WPA: WPA IE in 3/4 msg", |
| 1419 | wpa_ie, wpa_ie_len); |
| 1420 | } |
| 1421 | |
| 1422 | if (sm->ap_rsn_ie) { |
| 1423 | wpa_hexdump(MSG_INFO, "WPA: RSN IE in Beacon/ProbeResp", |
| 1424 | sm->ap_rsn_ie, sm->ap_rsn_ie_len); |
| 1425 | } |
| 1426 | if (rsn_ie) { |
| 1427 | if (!sm->ap_rsn_ie) { |
| 1428 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1429 | "WPA: No RSN IE in Beacon/ProbeResp"); |
| 1430 | } |
| 1431 | wpa_hexdump(MSG_INFO, "WPA: RSN IE in 3/4 msg", |
| 1432 | rsn_ie, rsn_ie_len); |
| 1433 | } |
| 1434 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1435 | wpa_sm_deauthenticate(sm, WLAN_REASON_IE_IN_4WAY_DIFFERS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | |
| 1439 | #ifdef CONFIG_IEEE80211R |
| 1440 | |
| 1441 | static int ft_validate_mdie(struct wpa_sm *sm, |
| 1442 | const unsigned char *src_addr, |
| 1443 | struct wpa_eapol_ie_parse *ie, |
| 1444 | const u8 *assoc_resp_mdie) |
| 1445 | { |
| 1446 | struct rsn_mdie *mdie; |
| 1447 | |
| 1448 | mdie = (struct rsn_mdie *) (ie->mdie + 2); |
| 1449 | if (ie->mdie == NULL || ie->mdie_len < 2 + sizeof(*mdie) || |
| 1450 | os_memcmp(mdie->mobility_domain, sm->mobility_domain, |
| 1451 | MOBILITY_DOMAIN_ID_LEN) != 0) { |
| 1452 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: MDIE in msg 3/4 did " |
| 1453 | "not match with the current mobility domain"); |
| 1454 | return -1; |
| 1455 | } |
| 1456 | |
| 1457 | if (assoc_resp_mdie && |
| 1458 | (assoc_resp_mdie[1] != ie->mdie[1] || |
| 1459 | os_memcmp(assoc_resp_mdie, ie->mdie, 2 + ie->mdie[1]) != 0)) { |
| 1460 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: MDIE mismatch"); |
| 1461 | wpa_hexdump(MSG_DEBUG, "FT: MDIE in EAPOL-Key msg 3/4", |
| 1462 | ie->mdie, 2 + ie->mdie[1]); |
| 1463 | wpa_hexdump(MSG_DEBUG, "FT: MDIE in (Re)Association Response", |
| 1464 | assoc_resp_mdie, 2 + assoc_resp_mdie[1]); |
| 1465 | return -1; |
| 1466 | } |
| 1467 | |
| 1468 | return 0; |
| 1469 | } |
| 1470 | |
| 1471 | |
| 1472 | static int ft_validate_ftie(struct wpa_sm *sm, |
| 1473 | const unsigned char *src_addr, |
| 1474 | struct wpa_eapol_ie_parse *ie, |
| 1475 | const u8 *assoc_resp_ftie) |
| 1476 | { |
| 1477 | if (ie->ftie == NULL) { |
| 1478 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1479 | "FT: No FTIE in EAPOL-Key msg 3/4"); |
| 1480 | return -1; |
| 1481 | } |
| 1482 | |
| 1483 | if (assoc_resp_ftie == NULL) |
| 1484 | return 0; |
| 1485 | |
| 1486 | if (assoc_resp_ftie[1] != ie->ftie[1] || |
| 1487 | os_memcmp(assoc_resp_ftie, ie->ftie, 2 + ie->ftie[1]) != 0) { |
| 1488 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: FTIE mismatch"); |
| 1489 | wpa_hexdump(MSG_DEBUG, "FT: FTIE in EAPOL-Key msg 3/4", |
| 1490 | ie->ftie, 2 + ie->ftie[1]); |
| 1491 | wpa_hexdump(MSG_DEBUG, "FT: FTIE in (Re)Association Response", |
| 1492 | assoc_resp_ftie, 2 + assoc_resp_ftie[1]); |
| 1493 | return -1; |
| 1494 | } |
| 1495 | |
| 1496 | return 0; |
| 1497 | } |
| 1498 | |
| 1499 | |
| 1500 | static int ft_validate_rsnie(struct wpa_sm *sm, |
| 1501 | const unsigned char *src_addr, |
| 1502 | struct wpa_eapol_ie_parse *ie) |
| 1503 | { |
| 1504 | struct wpa_ie_data rsn; |
| 1505 | |
| 1506 | if (!ie->rsn_ie) |
| 1507 | return 0; |
| 1508 | |
| 1509 | /* |
| 1510 | * Verify that PMKR1Name from EAPOL-Key message 3/4 |
| 1511 | * matches with the value we derived. |
| 1512 | */ |
| 1513 | if (wpa_parse_wpa_ie_rsn(ie->rsn_ie, ie->rsn_ie_len, &rsn) < 0 || |
| 1514 | rsn.num_pmkid != 1 || rsn.pmkid == NULL) { |
| 1515 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: No PMKR1Name in " |
| 1516 | "FT 4-way handshake message 3/4"); |
| 1517 | return -1; |
| 1518 | } |
| 1519 | |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 1520 | if (os_memcmp_const(rsn.pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN) != 0) |
| 1521 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1522 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1523 | "FT: PMKR1Name mismatch in " |
| 1524 | "FT 4-way handshake message 3/4"); |
| 1525 | wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from Authenticator", |
| 1526 | rsn.pmkid, WPA_PMK_NAME_LEN); |
| 1527 | wpa_hexdump(MSG_DEBUG, "FT: Derived PMKR1Name", |
| 1528 | sm->pmk_r1_name, WPA_PMK_NAME_LEN); |
| 1529 | return -1; |
| 1530 | } |
| 1531 | |
| 1532 | return 0; |
| 1533 | } |
| 1534 | |
| 1535 | |
| 1536 | static int wpa_supplicant_validate_ie_ft(struct wpa_sm *sm, |
| 1537 | const unsigned char *src_addr, |
| 1538 | struct wpa_eapol_ie_parse *ie) |
| 1539 | { |
| 1540 | const u8 *pos, *end, *mdie = NULL, *ftie = NULL; |
| 1541 | |
| 1542 | if (sm->assoc_resp_ies) { |
| 1543 | pos = sm->assoc_resp_ies; |
| 1544 | end = pos + sm->assoc_resp_ies_len; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1545 | while (end - pos > 2) { |
| 1546 | if (2 + pos[1] > end - pos) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1547 | break; |
| 1548 | switch (*pos) { |
| 1549 | case WLAN_EID_MOBILITY_DOMAIN: |
| 1550 | mdie = pos; |
| 1551 | break; |
| 1552 | case WLAN_EID_FAST_BSS_TRANSITION: |
| 1553 | ftie = pos; |
| 1554 | break; |
| 1555 | } |
| 1556 | pos += 2 + pos[1]; |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | if (ft_validate_mdie(sm, src_addr, ie, mdie) < 0 || |
| 1561 | ft_validate_ftie(sm, src_addr, ie, ftie) < 0 || |
| 1562 | ft_validate_rsnie(sm, src_addr, ie) < 0) |
| 1563 | return -1; |
| 1564 | |
| 1565 | return 0; |
| 1566 | } |
| 1567 | |
| 1568 | #endif /* CONFIG_IEEE80211R */ |
| 1569 | |
| 1570 | |
| 1571 | static int wpa_supplicant_validate_ie(struct wpa_sm *sm, |
| 1572 | const unsigned char *src_addr, |
| 1573 | struct wpa_eapol_ie_parse *ie) |
| 1574 | { |
| 1575 | if (sm->ap_wpa_ie == NULL && sm->ap_rsn_ie == NULL) { |
| 1576 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1577 | "WPA: No WPA/RSN IE for this AP known. " |
| 1578 | "Trying to get from scan results"); |
| 1579 | if (wpa_sm_get_beacon_ie(sm) < 0) { |
| 1580 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1581 | "WPA: Could not find AP from " |
| 1582 | "the scan results"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1583 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1584 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1585 | wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 1586 | "WPA: Found the current AP from updated scan results"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | if (ie->wpa_ie == NULL && ie->rsn_ie == NULL && |
| 1590 | (sm->ap_wpa_ie || sm->ap_rsn_ie)) { |
| 1591 | wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match " |
| 1592 | "with IE in Beacon/ProbeResp (no IE?)", |
| 1593 | src_addr, ie->wpa_ie, ie->wpa_ie_len, |
| 1594 | ie->rsn_ie, ie->rsn_ie_len); |
| 1595 | return -1; |
| 1596 | } |
| 1597 | |
| 1598 | if ((ie->wpa_ie && sm->ap_wpa_ie && |
| 1599 | (ie->wpa_ie_len != sm->ap_wpa_ie_len || |
| 1600 | os_memcmp(ie->wpa_ie, sm->ap_wpa_ie, ie->wpa_ie_len) != 0)) || |
| 1601 | (ie->rsn_ie && sm->ap_rsn_ie && |
| 1602 | wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm->key_mgmt), |
| 1603 | sm->ap_rsn_ie, sm->ap_rsn_ie_len, |
| 1604 | ie->rsn_ie, ie->rsn_ie_len))) { |
| 1605 | wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match " |
| 1606 | "with IE in Beacon/ProbeResp", |
| 1607 | src_addr, ie->wpa_ie, ie->wpa_ie_len, |
| 1608 | ie->rsn_ie, ie->rsn_ie_len); |
| 1609 | return -1; |
| 1610 | } |
| 1611 | |
| 1612 | if (sm->proto == WPA_PROTO_WPA && |
| 1613 | ie->rsn_ie && sm->ap_rsn_ie == NULL && sm->rsn_enabled) { |
| 1614 | wpa_report_ie_mismatch(sm, "Possible downgrade attack " |
| 1615 | "detected - RSN was enabled and RSN IE " |
| 1616 | "was in msg 3/4, but not in " |
| 1617 | "Beacon/ProbeResp", |
| 1618 | src_addr, ie->wpa_ie, ie->wpa_ie_len, |
| 1619 | ie->rsn_ie, ie->rsn_ie_len); |
| 1620 | return -1; |
| 1621 | } |
| 1622 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1623 | if (sm->proto == WPA_PROTO_RSN && |
| 1624 | ((sm->ap_rsnxe && !ie->rsnxe) || |
| 1625 | (!sm->ap_rsnxe && ie->rsnxe) || |
| 1626 | (sm->ap_rsnxe && ie->rsnxe && |
| 1627 | (sm->ap_rsnxe_len != ie->rsnxe_len || |
| 1628 | os_memcmp(sm->ap_rsnxe, ie->rsnxe, sm->ap_rsnxe_len) != 0)))) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1629 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1630 | "WPA: RSNXE mismatch between Beacon/ProbeResp and EAPOL-Key msg 3/4"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1631 | wpa_hexdump(MSG_INFO, "RSNXE in Beacon/ProbeResp", |
| 1632 | sm->ap_rsnxe, sm->ap_rsnxe_len); |
| 1633 | wpa_hexdump(MSG_INFO, "RSNXE in EAPOL-Key msg 3/4", |
| 1634 | ie->rsnxe, ie->rsnxe_len); |
| 1635 | wpa_sm_deauthenticate(sm, WLAN_REASON_IE_IN_4WAY_DIFFERS); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1636 | return -1; |
| 1637 | } |
| 1638 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1639 | #ifdef CONFIG_IEEE80211R |
| 1640 | if (wpa_key_mgmt_ft(sm->key_mgmt) && |
| 1641 | wpa_supplicant_validate_ie_ft(sm, src_addr, ie) < 0) |
| 1642 | return -1; |
| 1643 | #endif /* CONFIG_IEEE80211R */ |
| 1644 | |
| 1645 | return 0; |
| 1646 | } |
| 1647 | |
| 1648 | |
| 1649 | /** |
| 1650 | * wpa_supplicant_send_4_of_4 - Send message 4 of WPA/RSN 4-Way Handshake |
| 1651 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 1652 | * @dst: Destination address for the frame |
| 1653 | * @key: Pointer to the EAPOL-Key frame header |
| 1654 | * @ver: Version bits from EAPOL-Key Key Info |
| 1655 | * @key_info: Key Info |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1656 | * @ptk: PTK to use for keyed hash and encryption |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1657 | * Returns: >= 0 on success, < 0 on failure |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1658 | */ |
| 1659 | int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst, |
| 1660 | const struct wpa_eapol_key *key, |
| 1661 | u16 ver, u16 key_info, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1662 | struct wpa_ptk *ptk) |
| 1663 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1664 | size_t mic_len, hdrlen, rlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1665 | struct wpa_eapol_key *reply; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1666 | u8 *rbuf, *key_mic; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1667 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1668 | mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1669 | hdrlen = sizeof(*reply) + mic_len + 2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1670 | rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1671 | hdrlen, &rlen, (void *) &reply); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1672 | if (rbuf == NULL) |
| 1673 | return -1; |
| 1674 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1675 | reply->type = (sm->proto == WPA_PROTO_RSN || |
| 1676 | sm->proto == WPA_PROTO_OSEN) ? |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1677 | EAPOL_KEY_TYPE_RSN : EAPOL_KEY_TYPE_WPA; |
| 1678 | key_info &= WPA_KEY_INFO_SECURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1679 | key_info |= ver | WPA_KEY_INFO_KEY_TYPE; |
| 1680 | if (mic_len) |
| 1681 | key_info |= WPA_KEY_INFO_MIC; |
| 1682 | else |
| 1683 | key_info |= WPA_KEY_INFO_ENCR_KEY_DATA; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1684 | WPA_PUT_BE16(reply->key_info, key_info); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1685 | if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1686 | WPA_PUT_BE16(reply->key_length, 0); |
| 1687 | else |
| 1688 | os_memcpy(reply->key_length, key->key_length, 2); |
| 1689 | os_memcpy(reply->replay_counter, key->replay_counter, |
| 1690 | WPA_REPLAY_COUNTER_LEN); |
| 1691 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1692 | key_mic = (u8 *) (reply + 1); |
| 1693 | WPA_PUT_BE16(key_mic + mic_len, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1694 | |
Roshan Pius | 5e7db94 | 2018-04-12 12:27:41 -0700 | [diff] [blame] | 1695 | wpa_dbg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Sending EAPOL-Key 4/4"); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1696 | return wpa_eapol_key_send(sm, ptk, ver, dst, ETH_P_EAPOL, rbuf, rlen, |
| 1697 | key_mic); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | |
| 1701 | static void wpa_supplicant_process_3_of_4(struct wpa_sm *sm, |
| 1702 | const struct wpa_eapol_key *key, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 1703 | u16 ver, const u8 *key_data, |
| 1704 | size_t key_data_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1705 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 1706 | u16 key_info, keylen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1707 | struct wpa_eapol_ie_parse ie; |
| 1708 | |
| 1709 | wpa_sm_set_state(sm, WPA_4WAY_HANDSHAKE); |
Roshan Pius | 5e7db94 | 2018-04-12 12:27:41 -0700 | [diff] [blame] | 1710 | wpa_dbg(sm->ctx->msg_ctx, MSG_INFO, "WPA: RX message 3 of 4-Way " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1711 | "Handshake from " MACSTR " (ver=%d)", MAC2STR(sm->bssid), ver); |
| 1712 | |
| 1713 | key_info = WPA_GET_BE16(key->key_info); |
| 1714 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 1715 | wpa_hexdump(MSG_DEBUG, "WPA: IE KeyData", key_data, key_data_len); |
| 1716 | if (wpa_supplicant_parse_ies(key_data, key_data_len, &ie) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1717 | goto failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1718 | if (ie.gtk && !(key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) { |
| 1719 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1720 | "WPA: GTK IE in unencrypted key data"); |
| 1721 | goto failed; |
| 1722 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1723 | if (ie.igtk && !(key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) { |
| 1724 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1725 | "WPA: IGTK KDE in unencrypted key data"); |
| 1726 | goto failed; |
| 1727 | } |
| 1728 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1729 | if (ie.igtk && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1730 | sm->mgmt_group_cipher != WPA_CIPHER_GTK_NOT_USED && |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1731 | wpa_cipher_valid_mgmt_group(sm->mgmt_group_cipher) && |
| 1732 | ie.igtk_len != WPA_IGTK_KDE_PREFIX_LEN + |
| 1733 | (unsigned int) wpa_cipher_key_len(sm->mgmt_group_cipher)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1734 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1735 | "WPA: Invalid IGTK KDE length %lu", |
| 1736 | (unsigned long) ie.igtk_len); |
| 1737 | goto failed; |
| 1738 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1739 | |
| 1740 | if (wpa_supplicant_validate_ie(sm, sm->bssid, &ie) < 0) |
| 1741 | goto failed; |
| 1742 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1743 | if (wpa_handle_ext_key_id(sm, &ie)) |
| 1744 | goto failed; |
| 1745 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1746 | if (os_memcmp(sm->anonce, key->key_nonce, WPA_NONCE_LEN) != 0) { |
| 1747 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1748 | "WPA: ANonce from message 1 of 4-Way Handshake " |
| 1749 | "differs from 3 of 4-Way Handshake - drop packet (src=" |
| 1750 | MACSTR ")", MAC2STR(sm->bssid)); |
| 1751 | goto failed; |
| 1752 | } |
| 1753 | |
| 1754 | keylen = WPA_GET_BE16(key->key_length); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1755 | if (keylen != wpa_cipher_key_len(sm->pairwise_cipher)) { |
| 1756 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1757 | "WPA: Invalid %s key length %d (src=" MACSTR |
| 1758 | ")", wpa_cipher_txt(sm->pairwise_cipher), keylen, |
| 1759 | MAC2STR(sm->bssid)); |
| 1760 | goto failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1763 | #ifdef CONFIG_P2P |
| 1764 | if (ie.ip_addr_alloc) { |
| 1765 | os_memcpy(sm->p2p_ip_addr, ie.ip_addr_alloc, 3 * 4); |
| 1766 | wpa_hexdump(MSG_DEBUG, "P2P: IP address info", |
| 1767 | sm->p2p_ip_addr, sizeof(sm->p2p_ip_addr)); |
| 1768 | } |
| 1769 | #endif /* CONFIG_P2P */ |
| 1770 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1771 | #ifdef CONFIG_OCV |
| 1772 | if (wpa_sm_ocv_enabled(sm)) { |
| 1773 | struct wpa_channel_info ci; |
| 1774 | |
| 1775 | if (wpa_sm_channel_info(sm, &ci) != 0) { |
| 1776 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1777 | "Failed to get channel info to validate received OCI in EAPOL-Key 3/4"); |
| 1778 | return; |
| 1779 | } |
| 1780 | |
| 1781 | if (ocv_verify_tx_params(ie.oci, ie.oci_len, &ci, |
| 1782 | channel_width_to_int(ci.chanwidth), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1783 | ci.seg1_idx) != OCI_SUCCESS) { |
| 1784 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, OCV_FAILURE |
| 1785 | "addr=" MACSTR " frame=eapol-key-m3 error=%s", |
| 1786 | MAC2STR(sm->bssid), ocv_errorstr); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1787 | return; |
| 1788 | } |
| 1789 | } |
| 1790 | #endif /* CONFIG_OCV */ |
| 1791 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1792 | #ifdef CONFIG_DPP2 |
| 1793 | if (DPP_VERSION > 1 && ie.dpp_kde) { |
| 1794 | wpa_printf(MSG_DEBUG, |
| 1795 | "DPP: peer Protocol Version %u Flags 0x%x", |
| 1796 | ie.dpp_kde[0], ie.dpp_kde[1]); |
| 1797 | if (sm->key_mgmt == WPA_KEY_MGMT_DPP && sm->dpp_pfs != 2 && |
| 1798 | (ie.dpp_kde[1] & DPP_KDE_PFS_ALLOWED) && !sm->dpp_z) { |
| 1799 | wpa_printf(MSG_INFO, |
| 1800 | "DPP: Peer indicated it supports PFS and local configuration allows this, but PFS was not negotiated for the association"); |
| 1801 | goto failed; |
| 1802 | } |
| 1803 | } |
| 1804 | #endif /* CONFIG_DPP2 */ |
| 1805 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1806 | if (sm->use_ext_key_id && |
| 1807 | wpa_supplicant_install_ptk(sm, key, KEY_FLAG_RX)) |
| 1808 | goto failed; |
| 1809 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1810 | if (wpa_supplicant_send_4_of_4(sm, sm->bssid, key, ver, key_info, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1811 | &sm->ptk) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1812 | goto failed; |
| 1813 | } |
| 1814 | |
| 1815 | /* SNonce was successfully used in msg 3/4, so mark it to be renewed |
| 1816 | * for the next 4-Way Handshake. If msg 3 is received again, the old |
| 1817 | * SNonce will still be used to avoid changing PTK. */ |
| 1818 | sm->renew_snonce = 1; |
| 1819 | |
| 1820 | if (key_info & WPA_KEY_INFO_INSTALL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1821 | int res; |
| 1822 | |
| 1823 | if (sm->use_ext_key_id) |
| 1824 | res = wpa_supplicant_activate_ptk(sm); |
| 1825 | else |
| 1826 | res = wpa_supplicant_install_ptk(sm, key, |
| 1827 | KEY_FLAG_RX_TX); |
| 1828 | if (res) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1829 | goto failed; |
| 1830 | } |
| 1831 | |
| 1832 | if (key_info & WPA_KEY_INFO_SECURE) { |
| 1833 | wpa_sm_mlme_setprotection( |
| 1834 | sm, sm->bssid, MLME_SETPROTECTION_PROTECT_TYPE_RX, |
| 1835 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 1836 | eapol_sm_notify_portValid(sm->eapol, true); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1837 | } |
| 1838 | wpa_sm_set_state(sm, WPA_GROUP_HANDSHAKE); |
| 1839 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1840 | if (sm->group_cipher == WPA_CIPHER_GTK_NOT_USED) { |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 1841 | /* No GTK to be set to the driver */ |
| 1842 | } else if (!ie.gtk && sm->proto == WPA_PROTO_RSN) { |
| 1843 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1844 | "RSN: No GTK KDE included in EAPOL-Key msg 3/4"); |
| 1845 | goto failed; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1846 | } else if (ie.gtk && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1847 | wpa_supplicant_pairwise_gtk(sm, key, |
| 1848 | ie.gtk, ie.gtk_len, key_info) < 0) { |
| 1849 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1850 | "RSN: Failed to configure GTK"); |
| 1851 | goto failed; |
| 1852 | } |
| 1853 | |
| 1854 | if (ieee80211w_set_keys(sm, &ie) < 0) { |
| 1855 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1856 | "RSN: Failed to configure IGTK"); |
| 1857 | goto failed; |
| 1858 | } |
| 1859 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 1860 | if (sm->group_cipher == WPA_CIPHER_GTK_NOT_USED || ie.gtk) |
| 1861 | wpa_supplicant_key_neg_complete(sm, sm->bssid, |
| 1862 | key_info & WPA_KEY_INFO_SECURE); |
| 1863 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1864 | if (ie.gtk) |
| 1865 | wpa_sm_set_rekey_offload(sm); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1866 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1867 | /* Add PMKSA cache entry for Suite B AKMs here since PMKID can be |
| 1868 | * calculated only after KCK has been derived. Though, do not replace an |
| 1869 | * existing PMKSA entry after each 4-way handshake (i.e., new KCK/PMKID) |
| 1870 | * to avoid unnecessary changes of PMKID while continuing to use the |
| 1871 | * same PMK. */ |
| 1872 | if (sm->proto == WPA_PROTO_RSN && wpa_key_mgmt_suite_b(sm->key_mgmt) && |
| 1873 | !sm->cur_pmksa) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1874 | struct rsn_pmksa_cache_entry *sa; |
| 1875 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1876 | sa = pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len, NULL, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1877 | sm->ptk.kck, sm->ptk.kck_len, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1878 | sm->bssid, sm->own_addr, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1879 | sm->network_ctx, sm->key_mgmt, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1880 | if (!sm->cur_pmksa) |
| 1881 | sm->cur_pmksa = sa; |
| 1882 | } |
| 1883 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1884 | if (ie.transition_disable) |
| 1885 | wpa_sm_transition_disable(sm, ie.transition_disable[0]); |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 1886 | sm->msg_3_of_4_ok = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1887 | return; |
| 1888 | |
| 1889 | failed: |
| 1890 | wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); |
| 1891 | } |
| 1892 | |
| 1893 | |
| 1894 | static int wpa_supplicant_process_1_of_2_rsn(struct wpa_sm *sm, |
| 1895 | const u8 *keydata, |
| 1896 | size_t keydatalen, |
| 1897 | u16 key_info, |
| 1898 | struct wpa_gtk_data *gd) |
| 1899 | { |
| 1900 | int maxkeylen; |
| 1901 | struct wpa_eapol_ie_parse ie; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1902 | u16 gtk_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1903 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1904 | wpa_hexdump_key(MSG_DEBUG, "RSN: msg 1/2 key data", |
| 1905 | keydata, keydatalen); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1906 | if (wpa_supplicant_parse_ies(keydata, keydatalen, &ie) < 0) |
| 1907 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1908 | if (ie.gtk && !(key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) { |
| 1909 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1910 | "WPA: GTK IE in unencrypted key data"); |
| 1911 | return -1; |
| 1912 | } |
| 1913 | if (ie.gtk == NULL) { |
| 1914 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1915 | "WPA: No GTK IE in Group Key msg 1/2"); |
| 1916 | return -1; |
| 1917 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1918 | gtk_len = ie.gtk_len; |
| 1919 | if (gtk_len < 2) { |
| 1920 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1921 | "RSN: Invalid GTK KDE length (%u) in Group Key msg 1/2", |
| 1922 | gtk_len); |
| 1923 | return -1; |
| 1924 | } |
| 1925 | gtk_len -= 2; |
| 1926 | if (gtk_len > sizeof(gd->gtk)) { |
| 1927 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1928 | "RSN: Too long GTK in GTK KDE (len=%u)", gtk_len); |
| 1929 | return -1; |
| 1930 | } |
| 1931 | maxkeylen = gd->gtk_len = gtk_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1932 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1933 | #ifdef CONFIG_OCV |
| 1934 | if (wpa_sm_ocv_enabled(sm)) { |
| 1935 | struct wpa_channel_info ci; |
| 1936 | |
| 1937 | if (wpa_sm_channel_info(sm, &ci) != 0) { |
| 1938 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 1939 | "Failed to get channel info to validate received OCI in EAPOL-Key group msg 1/2"); |
| 1940 | return -1; |
| 1941 | } |
| 1942 | |
| 1943 | if (ocv_verify_tx_params(ie.oci, ie.oci_len, &ci, |
| 1944 | channel_width_to_int(ci.chanwidth), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1945 | ci.seg1_idx) != OCI_SUCCESS) { |
| 1946 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, OCV_FAILURE |
| 1947 | "addr=" MACSTR " frame=eapol-key-g1 error=%s", |
| 1948 | MAC2STR(sm->bssid), ocv_errorstr); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1949 | return -1; |
| 1950 | } |
| 1951 | } |
| 1952 | #endif /* CONFIG_OCV */ |
| 1953 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1954 | if (wpa_supplicant_check_group_cipher(sm, sm->group_cipher, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1955 | gtk_len, maxkeylen, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1956 | &gd->key_rsc_len, &gd->alg)) |
| 1957 | return -1; |
| 1958 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1959 | wpa_hexdump_key(MSG_DEBUG, "RSN: received GTK in group key handshake", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1960 | ie.gtk, 2 + gtk_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1961 | gd->keyidx = ie.gtk[0] & 0x3; |
| 1962 | gd->tx = wpa_supplicant_gtk_tx_bit_workaround(sm, |
| 1963 | !!(ie.gtk[0] & BIT(2))); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1964 | os_memcpy(gd->gtk, ie.gtk + 2, gtk_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1965 | |
| 1966 | if (ieee80211w_set_keys(sm, &ie) < 0) |
| 1967 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1968 | "RSN: Failed to configure IGTK"); |
| 1969 | |
| 1970 | return 0; |
| 1971 | } |
| 1972 | |
| 1973 | |
| 1974 | static int wpa_supplicant_process_1_of_2_wpa(struct wpa_sm *sm, |
| 1975 | const struct wpa_eapol_key *key, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 1976 | const u8 *key_data, |
| 1977 | size_t key_data_len, u16 key_info, |
| 1978 | u16 ver, struct wpa_gtk_data *gd) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1979 | { |
| 1980 | size_t maxkeylen; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1981 | u16 gtk_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1982 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1983 | gtk_len = WPA_GET_BE16(key->key_length); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 1984 | maxkeylen = key_data_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1985 | if (ver == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES) { |
| 1986 | if (maxkeylen < 8) { |
| 1987 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 1988 | "WPA: Too short maxkeylen (%lu)", |
| 1989 | (unsigned long) maxkeylen); |
| 1990 | return -1; |
| 1991 | } |
| 1992 | maxkeylen -= 8; |
| 1993 | } |
| 1994 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1995 | if (gtk_len > maxkeylen || |
| 1996 | wpa_supplicant_check_group_cipher(sm, sm->group_cipher, |
| 1997 | gtk_len, maxkeylen, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1998 | &gd->key_rsc_len, &gd->alg)) |
| 1999 | return -1; |
| 2000 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2001 | gd->gtk_len = gtk_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2002 | gd->keyidx = (key_info & WPA_KEY_INFO_KEY_INDEX_MASK) >> |
| 2003 | WPA_KEY_INFO_KEY_INDEX_SHIFT; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2004 | if (ver == WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 && sm->ptk.kek_len == 16) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2005 | #ifdef CONFIG_NO_RC4 |
| 2006 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2007 | "WPA: RC4 not supported in the build"); |
| 2008 | return -1; |
| 2009 | #else /* CONFIG_NO_RC4 */ |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 2010 | u8 ek[32]; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2011 | if (key_data_len > sizeof(gd->gtk)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2012 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2013 | "WPA: RC4 key data too long (%lu)", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2014 | (unsigned long) key_data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2015 | return -1; |
| 2016 | } |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 2017 | os_memcpy(ek, key->key_iv, 16); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2018 | os_memcpy(ek + 16, sm->ptk.kek, sm->ptk.kek_len); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2019 | os_memcpy(gd->gtk, key_data, key_data_len); |
| 2020 | if (rc4_skip(ek, 32, 256, gd->gtk, key_data_len)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2021 | forced_memzero(ek, sizeof(ek)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2022 | wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, |
| 2023 | "WPA: RC4 failed"); |
| 2024 | return -1; |
| 2025 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2026 | forced_memzero(ek, sizeof(ek)); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2027 | #endif /* CONFIG_NO_RC4 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2028 | } else if (ver == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2029 | if (maxkeylen % 8) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2030 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2031 | "WPA: Unsupported AES-WRAP len %lu", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2032 | (unsigned long) maxkeylen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2033 | return -1; |
| 2034 | } |
| 2035 | if (maxkeylen > sizeof(gd->gtk)) { |
| 2036 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2037 | "WPA: AES-WRAP key data " |
| 2038 | "too long (keydatalen=%lu maxkeylen=%lu)", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2039 | (unsigned long) key_data_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2040 | (unsigned long) maxkeylen); |
| 2041 | return -1; |
| 2042 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2043 | if (aes_unwrap(sm->ptk.kek, sm->ptk.kek_len, maxkeylen / 8, |
| 2044 | key_data, gd->gtk)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2045 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2046 | "WPA: AES unwrap failed - could not decrypt " |
| 2047 | "GTK"); |
| 2048 | return -1; |
| 2049 | } |
| 2050 | } else { |
| 2051 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2052 | "WPA: Unsupported key_info type %d", ver); |
| 2053 | return -1; |
| 2054 | } |
| 2055 | gd->tx = wpa_supplicant_gtk_tx_bit_workaround( |
| 2056 | sm, !!(key_info & WPA_KEY_INFO_TXRX)); |
| 2057 | return 0; |
| 2058 | } |
| 2059 | |
| 2060 | |
| 2061 | static int wpa_supplicant_send_2_of_2(struct wpa_sm *sm, |
| 2062 | const struct wpa_eapol_key *key, |
| 2063 | int ver, u16 key_info) |
| 2064 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2065 | size_t mic_len, hdrlen, rlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2066 | struct wpa_eapol_key *reply; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2067 | u8 *rbuf, *key_mic; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2068 | size_t kde_len = 0; |
| 2069 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2070 | #ifdef CONFIG_TESTING_OPTIONS |
| 2071 | if (sm->disable_eapol_g2_tx) { |
| 2072 | wpa_printf(MSG_INFO, "TEST: Disable sending EAPOL-Key 2/2"); |
| 2073 | return 0; |
| 2074 | } |
| 2075 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2076 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2077 | #ifdef CONFIG_OCV |
| 2078 | if (wpa_sm_ocv_enabled(sm)) |
| 2079 | kde_len = OCV_OCI_KDE_LEN; |
| 2080 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2081 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2082 | mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2083 | hdrlen = sizeof(*reply) + mic_len + 2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2084 | rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2085 | hdrlen + kde_len, &rlen, (void *) &reply); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2086 | if (rbuf == NULL) |
| 2087 | return -1; |
| 2088 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2089 | reply->type = (sm->proto == WPA_PROTO_RSN || |
| 2090 | sm->proto == WPA_PROTO_OSEN) ? |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2091 | EAPOL_KEY_TYPE_RSN : EAPOL_KEY_TYPE_WPA; |
| 2092 | key_info &= WPA_KEY_INFO_KEY_INDEX_MASK; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2093 | key_info |= ver | WPA_KEY_INFO_SECURE; |
| 2094 | if (mic_len) |
| 2095 | key_info |= WPA_KEY_INFO_MIC; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2096 | else |
| 2097 | key_info |= WPA_KEY_INFO_ENCR_KEY_DATA; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2098 | WPA_PUT_BE16(reply->key_info, key_info); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2099 | if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2100 | WPA_PUT_BE16(reply->key_length, 0); |
| 2101 | else |
| 2102 | os_memcpy(reply->key_length, key->key_length, 2); |
| 2103 | os_memcpy(reply->replay_counter, key->replay_counter, |
| 2104 | WPA_REPLAY_COUNTER_LEN); |
| 2105 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2106 | key_mic = (u8 *) (reply + 1); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2107 | WPA_PUT_BE16(key_mic + mic_len, kde_len); /* Key Data Length */ |
| 2108 | |
| 2109 | #ifdef CONFIG_OCV |
| 2110 | if (wpa_sm_ocv_enabled(sm)) { |
| 2111 | struct wpa_channel_info ci; |
| 2112 | u8 *pos; |
| 2113 | |
| 2114 | if (wpa_sm_channel_info(sm, &ci) != 0) { |
| 2115 | wpa_printf(MSG_WARNING, |
| 2116 | "Failed to get channel info for OCI element in EAPOL-Key 2/2"); |
| 2117 | os_free(rbuf); |
| 2118 | return -1; |
| 2119 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2120 | #ifdef CONFIG_TESTING_OPTIONS |
| 2121 | if (sm->oci_freq_override_eapol_g2) { |
| 2122 | wpa_printf(MSG_INFO, |
| 2123 | "TEST: Override OCI KDE frequency %d -> %d MHz", |
| 2124 | ci.frequency, |
| 2125 | sm->oci_freq_override_eapol_g2); |
| 2126 | ci.frequency = sm->oci_freq_override_eapol_g2; |
| 2127 | } |
| 2128 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2129 | |
| 2130 | pos = key_mic + mic_len + 2; /* Key Data */ |
| 2131 | if (ocv_insert_oci_kde(&ci, &pos) < 0) { |
| 2132 | os_free(rbuf); |
| 2133 | return -1; |
| 2134 | } |
| 2135 | } |
| 2136 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2137 | |
| 2138 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 2/2"); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2139 | return wpa_eapol_key_send(sm, &sm->ptk, ver, sm->bssid, ETH_P_EAPOL, |
| 2140 | rbuf, rlen, key_mic); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | |
| 2144 | static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm, |
| 2145 | const unsigned char *src_addr, |
| 2146 | const struct wpa_eapol_key *key, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2147 | const u8 *key_data, |
| 2148 | size_t key_data_len, u16 ver) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2149 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2150 | u16 key_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2151 | int rekey, ret; |
| 2152 | struct wpa_gtk_data gd; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2153 | const u8 *key_rsc; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2154 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2155 | if (!sm->msg_3_of_4_ok && !wpa_fils_is_completed(sm)) { |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 2156 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2157 | "WPA: Group Key Handshake started prior to completion of 4-way handshake"); |
| 2158 | goto failed; |
| 2159 | } |
| 2160 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2161 | os_memset(&gd, 0, sizeof(gd)); |
| 2162 | |
| 2163 | rekey = wpa_sm_get_state(sm) == WPA_COMPLETED; |
| 2164 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: RX message 1 of Group Key " |
| 2165 | "Handshake from " MACSTR " (ver=%d)", MAC2STR(src_addr), ver); |
| 2166 | |
| 2167 | key_info = WPA_GET_BE16(key->key_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2168 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2169 | if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2170 | ret = wpa_supplicant_process_1_of_2_rsn(sm, key_data, |
| 2171 | key_data_len, key_info, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2172 | &gd); |
| 2173 | } else { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2174 | ret = wpa_supplicant_process_1_of_2_wpa(sm, key, key_data, |
| 2175 | key_data_len, |
| 2176 | key_info, ver, &gd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | wpa_sm_set_state(sm, WPA_GROUP_HANDSHAKE); |
| 2180 | |
| 2181 | if (ret) |
| 2182 | goto failed; |
| 2183 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2184 | key_rsc = key->key_rsc; |
| 2185 | if (wpa_supplicant_rsc_relaxation(sm, key->key_rsc)) |
| 2186 | key_rsc = null_rsc; |
| 2187 | |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 2188 | if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2189 | wpa_supplicant_send_2_of_2(sm, key, ver, key_info) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2190 | goto failed; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2191 | forced_memzero(&gd, sizeof(gd)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2192 | |
| 2193 | if (rekey) { |
| 2194 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Group rekeying " |
| 2195 | "completed with " MACSTR " [GTK=%s]", |
| 2196 | MAC2STR(sm->bssid), wpa_cipher_txt(sm->group_cipher)); |
| 2197 | wpa_sm_cancel_auth_timeout(sm); |
| 2198 | wpa_sm_set_state(sm, WPA_COMPLETED); |
| 2199 | } else { |
| 2200 | wpa_supplicant_key_neg_complete(sm, sm->bssid, |
| 2201 | key_info & |
| 2202 | WPA_KEY_INFO_SECURE); |
| 2203 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2204 | |
| 2205 | wpa_sm_set_rekey_offload(sm); |
| 2206 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2207 | return; |
| 2208 | |
| 2209 | failed: |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2210 | forced_memzero(&gd, sizeof(gd)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2211 | wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); |
| 2212 | } |
| 2213 | |
| 2214 | |
| 2215 | static int wpa_supplicant_verify_eapol_key_mic(struct wpa_sm *sm, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2216 | struct wpa_eapol_key *key, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2217 | u16 ver, |
| 2218 | const u8 *buf, size_t len) |
| 2219 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2220 | u8 mic[WPA_EAPOL_KEY_MIC_MAX_LEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2221 | int ok = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2222 | size_t mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2223 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2224 | os_memcpy(mic, key + 1, mic_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2225 | if (sm->tptk_set) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2226 | os_memset(key + 1, 0, mic_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2227 | if (wpa_eapol_key_mic(sm->tptk.kck, sm->tptk.kck_len, |
| 2228 | sm->key_mgmt, |
| 2229 | ver, buf, len, (u8 *) (key + 1)) < 0 || |
| 2230 | os_memcmp_const(mic, key + 1, mic_len) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2231 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2232 | "WPA: Invalid EAPOL-Key MIC " |
| 2233 | "when using TPTK - ignoring TPTK"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2234 | #ifdef TEST_FUZZ |
| 2235 | wpa_printf(MSG_INFO, |
| 2236 | "TEST: Ignore Key MIC failure for fuzz testing"); |
| 2237 | goto continue_fuzz; |
| 2238 | #endif /* TEST_FUZZ */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2239 | } else { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2240 | #ifdef TEST_FUZZ |
| 2241 | continue_fuzz: |
| 2242 | #endif /* TEST_FUZZ */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2243 | ok = 1; |
| 2244 | sm->tptk_set = 0; |
| 2245 | sm->ptk_set = 1; |
| 2246 | os_memcpy(&sm->ptk, &sm->tptk, sizeof(sm->ptk)); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 2247 | os_memset(&sm->tptk, 0, sizeof(sm->tptk)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2248 | /* |
| 2249 | * This assures the same TPTK in sm->tptk can never be |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2250 | * copied twice to sm->ptk as the new PTK. In |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2251 | * combination with the installed flag in the wpa_ptk |
| 2252 | * struct, this assures the same PTK is only installed |
| 2253 | * once. |
| 2254 | */ |
| 2255 | sm->renew_snonce = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | if (!ok && sm->ptk_set) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2260 | os_memset(key + 1, 0, mic_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2261 | if (wpa_eapol_key_mic(sm->ptk.kck, sm->ptk.kck_len, |
| 2262 | sm->key_mgmt, |
| 2263 | ver, buf, len, (u8 *) (key + 1)) < 0 || |
| 2264 | os_memcmp_const(mic, key + 1, mic_len) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2265 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2266 | "WPA: Invalid EAPOL-Key MIC - " |
| 2267 | "dropping packet"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2268 | #ifdef TEST_FUZZ |
| 2269 | wpa_printf(MSG_INFO, |
| 2270 | "TEST: Ignore Key MIC failure for fuzz testing"); |
| 2271 | goto continue_fuzz2; |
| 2272 | #endif /* TEST_FUZZ */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2273 | return -1; |
| 2274 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2275 | #ifdef TEST_FUZZ |
| 2276 | continue_fuzz2: |
| 2277 | #endif /* TEST_FUZZ */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2278 | ok = 1; |
| 2279 | } |
| 2280 | |
| 2281 | if (!ok) { |
| 2282 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2283 | "WPA: Could not verify EAPOL-Key MIC - " |
| 2284 | "dropping packet"); |
| 2285 | return -1; |
| 2286 | } |
| 2287 | |
| 2288 | os_memcpy(sm->rx_replay_counter, key->replay_counter, |
| 2289 | WPA_REPLAY_COUNTER_LEN); |
| 2290 | sm->rx_replay_counter_set = 1; |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
| 2294 | |
| 2295 | /* Decrypt RSN EAPOL-Key key data (RC4 or AES-WRAP) */ |
| 2296 | static int wpa_supplicant_decrypt_key_data(struct wpa_sm *sm, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2297 | struct wpa_eapol_key *key, |
| 2298 | size_t mic_len, u16 ver, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2299 | u8 *key_data, size_t *key_data_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2300 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2301 | wpa_hexdump(MSG_DEBUG, "RSN: encrypted key data", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2302 | key_data, *key_data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2303 | if (!sm->ptk_set) { |
| 2304 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2305 | "WPA: PTK not available, cannot decrypt EAPOL-Key Key " |
| 2306 | "Data"); |
| 2307 | return -1; |
| 2308 | } |
| 2309 | |
| 2310 | /* Decrypt key data here so that this operation does not need |
| 2311 | * to be implemented separately for each message type. */ |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2312 | if (ver == WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 && sm->ptk.kek_len == 16) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2313 | #ifdef CONFIG_NO_RC4 |
| 2314 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2315 | "WPA: RC4 not supported in the build"); |
| 2316 | return -1; |
| 2317 | #else /* CONFIG_NO_RC4 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2318 | u8 ek[32]; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2319 | |
| 2320 | wpa_printf(MSG_DEBUG, "WPA: Decrypt Key Data using RC4"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2321 | os_memcpy(ek, key->key_iv, 16); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2322 | os_memcpy(ek + 16, sm->ptk.kek, sm->ptk.kek_len); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2323 | if (rc4_skip(ek, 32, 256, key_data, *key_data_len)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2324 | forced_memzero(ek, sizeof(ek)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2325 | wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, |
| 2326 | "WPA: RC4 failed"); |
| 2327 | return -1; |
| 2328 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2329 | forced_memzero(ek, sizeof(ek)); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2330 | #endif /* CONFIG_NO_RC4 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2331 | } else if (ver == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES || |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2332 | ver == WPA_KEY_INFO_TYPE_AES_128_CMAC || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2333 | wpa_use_aes_key_wrap(sm->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2334 | u8 *buf; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2335 | |
| 2336 | wpa_printf(MSG_DEBUG, |
| 2337 | "WPA: Decrypt Key Data using AES-UNWRAP (KEK length %u)", |
| 2338 | (unsigned int) sm->ptk.kek_len); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2339 | if (*key_data_len < 8 || *key_data_len % 8) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2340 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2341 | "WPA: Unsupported AES-WRAP len %u", |
| 2342 | (unsigned int) *key_data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2343 | return -1; |
| 2344 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2345 | *key_data_len -= 8; /* AES-WRAP adds 8 bytes */ |
| 2346 | buf = os_malloc(*key_data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2347 | if (buf == NULL) { |
| 2348 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2349 | "WPA: No memory for AES-UNWRAP buffer"); |
| 2350 | return -1; |
| 2351 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2352 | #ifdef TEST_FUZZ |
| 2353 | os_memset(buf, 0x11, *key_data_len); |
| 2354 | #endif /* TEST_FUZZ */ |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2355 | if (aes_unwrap(sm->ptk.kek, sm->ptk.kek_len, *key_data_len / 8, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2356 | key_data, buf)) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2357 | #ifdef TEST_FUZZ |
| 2358 | wpa_printf(MSG_INFO, |
| 2359 | "TEST: Ignore AES unwrap failure for fuzz testing"); |
| 2360 | goto continue_fuzz; |
| 2361 | #endif /* TEST_FUZZ */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2362 | bin_clear_free(buf, *key_data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2363 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2364 | "WPA: AES unwrap failed - " |
| 2365 | "could not decrypt EAPOL-Key key data"); |
| 2366 | return -1; |
| 2367 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2368 | #ifdef TEST_FUZZ |
| 2369 | continue_fuzz: |
| 2370 | #endif /* TEST_FUZZ */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2371 | os_memcpy(key_data, buf, *key_data_len); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2372 | bin_clear_free(buf, *key_data_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2373 | WPA_PUT_BE16(((u8 *) (key + 1)) + mic_len, *key_data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2374 | } else { |
| 2375 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2376 | "WPA: Unsupported key_info type %d", ver); |
| 2377 | return -1; |
| 2378 | } |
| 2379 | wpa_hexdump_key(MSG_DEBUG, "WPA: decrypted EAPOL-Key key data", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2380 | key_data, *key_data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | return 0; |
| 2382 | } |
| 2383 | |
| 2384 | |
| 2385 | /** |
| 2386 | * wpa_sm_aborted_cached - Notify WPA that PMKSA caching was aborted |
| 2387 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 2388 | */ |
| 2389 | void wpa_sm_aborted_cached(struct wpa_sm *sm) |
| 2390 | { |
| 2391 | if (sm && sm->cur_pmksa) { |
| 2392 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2393 | "RSN: Cancelling PMKSA caching attempt"); |
| 2394 | sm->cur_pmksa = NULL; |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2399 | void wpa_sm_aborted_external_cached(struct wpa_sm *sm) |
| 2400 | { |
| 2401 | if (sm && sm->cur_pmksa && sm->cur_pmksa->external) { |
| 2402 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2403 | "RSN: Cancelling external PMKSA caching attempt"); |
| 2404 | sm->cur_pmksa = NULL; |
| 2405 | } |
| 2406 | } |
| 2407 | |
| 2408 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2409 | static void wpa_eapol_key_dump(struct wpa_sm *sm, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2410 | const struct wpa_eapol_key *key, |
| 2411 | unsigned int key_data_len, |
| 2412 | const u8 *mic, unsigned int mic_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2413 | { |
| 2414 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 2415 | u16 key_info = WPA_GET_BE16(key->key_info); |
| 2416 | |
| 2417 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, " EAPOL-Key type=%d", key->type); |
| 2418 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2419 | " key_info 0x%x (ver=%d keyidx=%d rsvd=%d %s%s%s%s%s%s%s%s)", |
| 2420 | key_info, key_info & WPA_KEY_INFO_TYPE_MASK, |
| 2421 | (key_info & WPA_KEY_INFO_KEY_INDEX_MASK) >> |
| 2422 | WPA_KEY_INFO_KEY_INDEX_SHIFT, |
| 2423 | (key_info & (BIT(13) | BIT(14) | BIT(15))) >> 13, |
| 2424 | key_info & WPA_KEY_INFO_KEY_TYPE ? "Pairwise" : "Group", |
| 2425 | key_info & WPA_KEY_INFO_INSTALL ? " Install" : "", |
| 2426 | key_info & WPA_KEY_INFO_ACK ? " Ack" : "", |
| 2427 | key_info & WPA_KEY_INFO_MIC ? " MIC" : "", |
| 2428 | key_info & WPA_KEY_INFO_SECURE ? " Secure" : "", |
| 2429 | key_info & WPA_KEY_INFO_ERROR ? " Error" : "", |
| 2430 | key_info & WPA_KEY_INFO_REQUEST ? " Request" : "", |
| 2431 | key_info & WPA_KEY_INFO_ENCR_KEY_DATA ? " Encr" : ""); |
| 2432 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2433 | " key_length=%u key_data_length=%u", |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2434 | WPA_GET_BE16(key->key_length), key_data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2435 | wpa_hexdump(MSG_DEBUG, " replay_counter", |
| 2436 | key->replay_counter, WPA_REPLAY_COUNTER_LEN); |
| 2437 | wpa_hexdump(MSG_DEBUG, " key_nonce", key->key_nonce, WPA_NONCE_LEN); |
| 2438 | wpa_hexdump(MSG_DEBUG, " key_iv", key->key_iv, 16); |
| 2439 | wpa_hexdump(MSG_DEBUG, " key_rsc", key->key_rsc, 8); |
| 2440 | wpa_hexdump(MSG_DEBUG, " key_id (reserved)", key->key_id, 8); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2441 | wpa_hexdump(MSG_DEBUG, " key_mic", mic, mic_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2442 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
| 2443 | } |
| 2444 | |
| 2445 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2446 | #ifdef CONFIG_FILS |
| 2447 | static int wpa_supp_aead_decrypt(struct wpa_sm *sm, u8 *buf, size_t buf_len, |
| 2448 | size_t *key_data_len) |
| 2449 | { |
| 2450 | struct wpa_ptk *ptk; |
| 2451 | struct ieee802_1x_hdr *hdr; |
| 2452 | struct wpa_eapol_key *key; |
| 2453 | u8 *pos, *tmp; |
| 2454 | const u8 *aad[1]; |
| 2455 | size_t aad_len[1]; |
| 2456 | |
| 2457 | if (*key_data_len < AES_BLOCK_SIZE) { |
| 2458 | wpa_printf(MSG_INFO, "No room for AES-SIV data in the frame"); |
| 2459 | return -1; |
| 2460 | } |
| 2461 | |
| 2462 | if (sm->tptk_set) |
| 2463 | ptk = &sm->tptk; |
| 2464 | else if (sm->ptk_set) |
| 2465 | ptk = &sm->ptk; |
| 2466 | else |
| 2467 | return -1; |
| 2468 | |
| 2469 | hdr = (struct ieee802_1x_hdr *) buf; |
| 2470 | key = (struct wpa_eapol_key *) (hdr + 1); |
| 2471 | pos = (u8 *) (key + 1); |
| 2472 | pos += 2; /* Pointing at the Encrypted Key Data field */ |
| 2473 | |
| 2474 | tmp = os_malloc(*key_data_len); |
| 2475 | if (!tmp) |
| 2476 | return -1; |
| 2477 | |
| 2478 | /* AES-SIV AAD from EAPOL protocol version field (inclusive) to |
| 2479 | * to Key Data (exclusive). */ |
| 2480 | aad[0] = buf; |
| 2481 | aad_len[0] = pos - buf; |
| 2482 | if (aes_siv_decrypt(ptk->kek, ptk->kek_len, pos, *key_data_len, |
| 2483 | 1, aad, aad_len, tmp) < 0) { |
| 2484 | wpa_printf(MSG_INFO, "Invalid AES-SIV data in the frame"); |
| 2485 | bin_clear_free(tmp, *key_data_len); |
| 2486 | return -1; |
| 2487 | } |
| 2488 | |
| 2489 | /* AEAD decryption and validation completed successfully */ |
| 2490 | (*key_data_len) -= AES_BLOCK_SIZE; |
| 2491 | wpa_hexdump_key(MSG_DEBUG, "WPA: Decrypted Key Data", |
| 2492 | tmp, *key_data_len); |
| 2493 | |
| 2494 | /* Replace Key Data field with the decrypted version */ |
| 2495 | os_memcpy(pos, tmp, *key_data_len); |
| 2496 | pos -= 2; /* Key Data Length field */ |
| 2497 | WPA_PUT_BE16(pos, *key_data_len); |
| 2498 | bin_clear_free(tmp, *key_data_len); |
| 2499 | |
| 2500 | if (sm->tptk_set) { |
| 2501 | sm->tptk_set = 0; |
| 2502 | sm->ptk_set = 1; |
| 2503 | os_memcpy(&sm->ptk, &sm->tptk, sizeof(sm->ptk)); |
| 2504 | os_memset(&sm->tptk, 0, sizeof(sm->tptk)); |
| 2505 | } |
| 2506 | |
| 2507 | os_memcpy(sm->rx_replay_counter, key->replay_counter, |
| 2508 | WPA_REPLAY_COUNTER_LEN); |
| 2509 | sm->rx_replay_counter_set = 1; |
| 2510 | |
| 2511 | return 0; |
| 2512 | } |
| 2513 | #endif /* CONFIG_FILS */ |
| 2514 | |
| 2515 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2516 | /** |
| 2517 | * wpa_sm_rx_eapol - Process received WPA EAPOL frames |
| 2518 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 2519 | * @src_addr: Source MAC address of the EAPOL packet |
| 2520 | * @buf: Pointer to the beginning of the EAPOL data (EAPOL header) |
| 2521 | * @len: Length of the EAPOL frame |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 2522 | * @encrypted: Whether the frame was encrypted |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2523 | * Returns: 1 = WPA EAPOL-Key processed, 0 = not a WPA EAPOL-Key, -1 failure |
| 2524 | * |
| 2525 | * This function is called for each received EAPOL frame. Other than EAPOL-Key |
| 2526 | * frames can be skipped if filtering is done elsewhere. wpa_sm_rx_eapol() is |
| 2527 | * only processing WPA and WPA2 EAPOL-Key frames. |
| 2528 | * |
| 2529 | * The received EAPOL-Key packets are validated and valid packets are replied |
| 2530 | * to. In addition, key material (PTK, GTK) is configured at the end of a |
| 2531 | * successful key handshake. |
| 2532 | */ |
| 2533 | int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 2534 | const u8 *buf, size_t len, enum frame_encryption encrypted) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2535 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2536 | size_t plen, data_len, key_data_len; |
| 2537 | const struct ieee802_1x_hdr *hdr; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2538 | struct wpa_eapol_key *key; |
| 2539 | u16 key_info, ver; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2540 | u8 *tmp = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2541 | int ret = -1; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2542 | u8 *mic, *key_data; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2543 | size_t mic_len, keyhdrlen, pmk_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2544 | |
| 2545 | #ifdef CONFIG_IEEE80211R |
| 2546 | sm->ft_completed = 0; |
| 2547 | #endif /* CONFIG_IEEE80211R */ |
| 2548 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2549 | pmk_len = sm->pmk_len; |
| 2550 | if (!pmk_len && sm->cur_pmksa) |
| 2551 | pmk_len = sm->cur_pmksa->pmk_len; |
| 2552 | mic_len = wpa_mic_len(sm->key_mgmt, pmk_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2553 | keyhdrlen = sizeof(*key) + mic_len + 2; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2554 | |
| 2555 | if (len < sizeof(*hdr) + keyhdrlen) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2556 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2557 | "WPA: EAPOL frame too short to be a WPA " |
| 2558 | "EAPOL-Key (len %lu, expecting at least %lu)", |
| 2559 | (unsigned long) len, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2560 | (unsigned long) sizeof(*hdr) + keyhdrlen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2561 | return 0; |
| 2562 | } |
| 2563 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2564 | hdr = (const struct ieee802_1x_hdr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2565 | plen = be_to_host16(hdr->length); |
| 2566 | data_len = plen + sizeof(*hdr); |
| 2567 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2568 | "IEEE 802.1X RX: version=%d type=%d length=%lu", |
| 2569 | hdr->version, hdr->type, (unsigned long) plen); |
| 2570 | |
| 2571 | if (hdr->version < EAPOL_VERSION) { |
| 2572 | /* TODO: backwards compatibility */ |
| 2573 | } |
| 2574 | if (hdr->type != IEEE802_1X_TYPE_EAPOL_KEY) { |
| 2575 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2576 | "WPA: EAPOL frame (type %u) discarded, " |
| 2577 | "not a Key frame", hdr->type); |
| 2578 | ret = 0; |
| 2579 | goto out; |
| 2580 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2581 | wpa_hexdump(MSG_MSGDUMP, "WPA: RX EAPOL-Key", buf, len); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2582 | if (plen > len - sizeof(*hdr) || plen < keyhdrlen) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2583 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2584 | "WPA: EAPOL frame payload size %lu " |
| 2585 | "invalid (frame size %lu)", |
| 2586 | (unsigned long) plen, (unsigned long) len); |
| 2587 | ret = 0; |
| 2588 | goto out; |
| 2589 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2590 | if (data_len < len) { |
| 2591 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2592 | "WPA: ignoring %lu bytes after the IEEE 802.1X data", |
| 2593 | (unsigned long) len - data_len); |
| 2594 | } |
| 2595 | |
| 2596 | /* |
| 2597 | * Make a copy of the frame since we need to modify the buffer during |
| 2598 | * MAC validation and Key Data decryption. |
| 2599 | */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2600 | tmp = os_memdup(buf, data_len); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2601 | if (tmp == NULL) |
| 2602 | goto out; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2603 | key = (struct wpa_eapol_key *) (tmp + sizeof(struct ieee802_1x_hdr)); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2604 | mic = (u8 *) (key + 1); |
| 2605 | key_data = mic + mic_len + 2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2606 | |
| 2607 | if (key->type != EAPOL_KEY_TYPE_WPA && key->type != EAPOL_KEY_TYPE_RSN) |
| 2608 | { |
| 2609 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2610 | "WPA: EAPOL-Key type (%d) unknown, discarded", |
| 2611 | key->type); |
| 2612 | ret = 0; |
| 2613 | goto out; |
| 2614 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2615 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2616 | key_data_len = WPA_GET_BE16(mic + mic_len); |
| 2617 | wpa_eapol_key_dump(sm, key, key_data_len, mic, mic_len); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2618 | |
| 2619 | if (key_data_len > plen - keyhdrlen) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2620 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Invalid EAPOL-Key " |
| 2621 | "frame - key_data overflow (%u > %u)", |
| 2622 | (unsigned int) key_data_len, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2623 | (unsigned int) (plen - keyhdrlen)); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2624 | goto out; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2625 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2626 | |
| 2627 | eapol_sm_notify_lower_layer_success(sm->eapol, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2628 | key_info = WPA_GET_BE16(key->key_info); |
| 2629 | ver = key_info & WPA_KEY_INFO_TYPE_MASK; |
| 2630 | if (ver != WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2631 | ver != WPA_KEY_INFO_TYPE_AES_128_CMAC && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2632 | ver != WPA_KEY_INFO_TYPE_HMAC_SHA1_AES && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2633 | !wpa_use_akm_defined(sm->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2634 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2635 | "WPA: Unsupported EAPOL-Key descriptor version %d", |
| 2636 | ver); |
| 2637 | goto out; |
| 2638 | } |
| 2639 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2640 | if (wpa_use_akm_defined(sm->key_mgmt) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2641 | ver != WPA_KEY_INFO_TYPE_AKM_DEFINED) { |
| 2642 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2643 | "RSN: Unsupported EAPOL-Key descriptor version %d (expected AKM defined = 0)", |
| 2644 | ver); |
| 2645 | goto out; |
| 2646 | } |
| 2647 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2648 | #ifdef CONFIG_IEEE80211R |
| 2649 | if (wpa_key_mgmt_ft(sm->key_mgmt)) { |
| 2650 | /* IEEE 802.11r uses a new key_info type (AES-128-CMAC). */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2651 | if (ver != WPA_KEY_INFO_TYPE_AES_128_CMAC && |
| 2652 | !wpa_use_akm_defined(sm->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2653 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2654 | "FT: AP did not use AES-128-CMAC"); |
| 2655 | goto out; |
| 2656 | } |
| 2657 | } else |
| 2658 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2659 | if (wpa_key_mgmt_sha256(sm->key_mgmt)) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2660 | if (ver != WPA_KEY_INFO_TYPE_AES_128_CMAC && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2661 | !wpa_use_akm_defined(sm->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2662 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2663 | "WPA: AP did not use the " |
| 2664 | "negotiated AES-128-CMAC"); |
| 2665 | goto out; |
| 2666 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2667 | } else if (sm->pairwise_cipher == WPA_CIPHER_CCMP && |
| 2668 | !wpa_use_akm_defined(sm->key_mgmt) && |
| 2669 | ver != WPA_KEY_INFO_TYPE_HMAC_SHA1_AES) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2670 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2671 | "WPA: CCMP is used, but EAPOL-Key " |
| 2672 | "descriptor version (%d) is not 2", ver); |
| 2673 | if (sm->group_cipher != WPA_CIPHER_CCMP && |
| 2674 | !(key_info & WPA_KEY_INFO_KEY_TYPE)) { |
| 2675 | /* Earlier versions of IEEE 802.11i did not explicitly |
| 2676 | * require version 2 descriptor for all EAPOL-Key |
| 2677 | * packets, so allow group keys to use version 1 if |
| 2678 | * CCMP is not used for them. */ |
| 2679 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2680 | "WPA: Backwards compatibility: allow invalid " |
| 2681 | "version for non-CCMP group keys"); |
Jouni Malinen | 658fb4a | 2014-11-14 20:57:05 +0200 | [diff] [blame] | 2682 | } else if (ver == WPA_KEY_INFO_TYPE_AES_128_CMAC) { |
| 2683 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2684 | "WPA: Interoperability workaround: allow incorrect (should have been HMAC-SHA1), but stronger (is AES-128-CMAC), descriptor version to be used"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2685 | } else |
| 2686 | goto out; |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 2687 | } else if (sm->pairwise_cipher == WPA_CIPHER_GCMP && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2688 | !wpa_use_akm_defined(sm->key_mgmt) && |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 2689 | ver != WPA_KEY_INFO_TYPE_HMAC_SHA1_AES) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2690 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2691 | "WPA: GCMP is used, but EAPOL-Key " |
| 2692 | "descriptor version (%d) is not 2", ver); |
| 2693 | goto out; |
| 2694 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2695 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2696 | if (sm->rx_replay_counter_set && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2697 | os_memcmp(key->replay_counter, sm->rx_replay_counter, |
| 2698 | WPA_REPLAY_COUNTER_LEN) <= 0) { |
| 2699 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2700 | "WPA: EAPOL-Key Replay Counter did not increase - " |
| 2701 | "dropping packet"); |
| 2702 | goto out; |
| 2703 | } |
| 2704 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2705 | if (key_info & WPA_KEY_INFO_SMK_MESSAGE) { |
| 2706 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2707 | "WPA: Unsupported SMK bit in key_info"); |
| 2708 | goto out; |
| 2709 | } |
| 2710 | |
| 2711 | if (!(key_info & WPA_KEY_INFO_ACK)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2712 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2713 | "WPA: No Ack bit in key_info"); |
| 2714 | goto out; |
| 2715 | } |
| 2716 | |
| 2717 | if (key_info & WPA_KEY_INFO_REQUEST) { |
| 2718 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 2719 | "WPA: EAPOL-Key with Request bit - dropped"); |
| 2720 | goto out; |
| 2721 | } |
| 2722 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2723 | if ((key_info & WPA_KEY_INFO_MIC) && |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2724 | wpa_supplicant_verify_eapol_key_mic(sm, key, ver, tmp, data_len)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2725 | goto out; |
| 2726 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2727 | #ifdef CONFIG_FILS |
| 2728 | if (!mic_len && (key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) { |
| 2729 | if (wpa_supp_aead_decrypt(sm, tmp, data_len, &key_data_len)) |
| 2730 | goto out; |
| 2731 | } |
| 2732 | #endif /* CONFIG_FILS */ |
| 2733 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2734 | if ((sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) && |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2735 | (key_info & WPA_KEY_INFO_ENCR_KEY_DATA) && mic_len) { |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 2736 | /* |
| 2737 | * Only decrypt the Key Data field if the frame's authenticity |
| 2738 | * was verified. When using AES-SIV (FILS), the MIC flag is not |
| 2739 | * set, so this check should only be performed if mic_len != 0 |
| 2740 | * which is the case in this code branch. |
| 2741 | */ |
| 2742 | if (!(key_info & WPA_KEY_INFO_MIC)) { |
| 2743 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2744 | "WPA: Ignore EAPOL-Key with encrypted but unauthenticated data"); |
| 2745 | goto out; |
| 2746 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2747 | if (wpa_supplicant_decrypt_key_data(sm, key, mic_len, |
| 2748 | ver, key_data, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2749 | &key_data_len)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2750 | goto out; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | if (key_info & WPA_KEY_INFO_KEY_TYPE) { |
| 2754 | if (key_info & WPA_KEY_INFO_KEY_INDEX_MASK) { |
| 2755 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 2756 | "WPA: Ignored EAPOL-Key (Pairwise) with " |
| 2757 | "non-zero key index"); |
| 2758 | goto out; |
| 2759 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2760 | if (key_info & (WPA_KEY_INFO_MIC | |
| 2761 | WPA_KEY_INFO_ENCR_KEY_DATA)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2762 | /* 3/4 4-Way Handshake */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2763 | wpa_supplicant_process_3_of_4(sm, key, ver, key_data, |
| 2764 | key_data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2765 | } else { |
| 2766 | /* 1/4 4-Way Handshake */ |
| 2767 | wpa_supplicant_process_1_of_4(sm, src_addr, key, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2768 | ver, key_data, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 2769 | key_data_len, |
| 2770 | encrypted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2771 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2772 | } else { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2773 | if ((mic_len && (key_info & WPA_KEY_INFO_MIC)) || |
| 2774 | (!mic_len && (key_info & WPA_KEY_INFO_ENCR_KEY_DATA))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2775 | /* 1/2 Group Key Handshake */ |
| 2776 | wpa_supplicant_process_1_of_2(sm, src_addr, key, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 2777 | key_data, key_data_len, |
| 2778 | ver); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2779 | } else { |
| 2780 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2781 | "WPA: EAPOL-Key (Group) without Mic/Encr bit - " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2782 | "dropped"); |
| 2783 | } |
| 2784 | } |
| 2785 | |
| 2786 | ret = 1; |
| 2787 | |
| 2788 | out: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2789 | bin_clear_free(tmp, data_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2790 | return ret; |
| 2791 | } |
| 2792 | |
| 2793 | |
| 2794 | #ifdef CONFIG_CTRL_IFACE |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2795 | static u32 wpa_key_mgmt_suite(struct wpa_sm *sm) |
| 2796 | { |
| 2797 | switch (sm->key_mgmt) { |
| 2798 | case WPA_KEY_MGMT_IEEE8021X: |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2799 | return ((sm->proto == WPA_PROTO_RSN || |
| 2800 | sm->proto == WPA_PROTO_OSEN) ? |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2801 | RSN_AUTH_KEY_MGMT_UNSPEC_802_1X : |
| 2802 | WPA_AUTH_KEY_MGMT_UNSPEC_802_1X); |
| 2803 | case WPA_KEY_MGMT_PSK: |
| 2804 | return (sm->proto == WPA_PROTO_RSN ? |
| 2805 | RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X : |
| 2806 | WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X); |
| 2807 | #ifdef CONFIG_IEEE80211R |
| 2808 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 2809 | return RSN_AUTH_KEY_MGMT_FT_802_1X; |
| 2810 | case WPA_KEY_MGMT_FT_PSK: |
| 2811 | return RSN_AUTH_KEY_MGMT_FT_PSK; |
| 2812 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2813 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
| 2814 | return RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
| 2815 | case WPA_KEY_MGMT_PSK_SHA256: |
| 2816 | return RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2817 | case WPA_KEY_MGMT_CCKM: |
| 2818 | return (sm->proto == WPA_PROTO_RSN ? |
| 2819 | RSN_AUTH_KEY_MGMT_CCKM: |
| 2820 | WPA_AUTH_KEY_MGMT_CCKM); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2821 | case WPA_KEY_MGMT_WPA_NONE: |
| 2822 | return WPA_AUTH_KEY_MGMT_NONE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2823 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
| 2824 | return RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2825 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
| 2826 | return RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2827 | default: |
| 2828 | return 0; |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2833 | #define RSN_SUITE "%02x-%02x-%02x-%d" |
| 2834 | #define RSN_SUITE_ARG(s) \ |
| 2835 | ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff |
| 2836 | |
| 2837 | /** |
| 2838 | * wpa_sm_get_mib - Dump text list of MIB entries |
| 2839 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 2840 | * @buf: Buffer for the list |
| 2841 | * @buflen: Length of the buffer |
| 2842 | * Returns: Number of bytes written to buffer |
| 2843 | * |
| 2844 | * This function is used fetch dot11 MIB variables. |
| 2845 | */ |
| 2846 | int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen) |
| 2847 | { |
| 2848 | char pmkid_txt[PMKID_LEN * 2 + 1]; |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2849 | bool rsna; |
| 2850 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2851 | size_t len; |
| 2852 | |
| 2853 | if (sm->cur_pmksa) { |
| 2854 | wpa_snprintf_hex(pmkid_txt, sizeof(pmkid_txt), |
| 2855 | sm->cur_pmksa->pmkid, PMKID_LEN); |
| 2856 | } else |
| 2857 | pmkid_txt[0] = '\0'; |
| 2858 | |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2859 | rsna = (wpa_key_mgmt_wpa_psk(sm->key_mgmt) || |
| 2860 | wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt)) && |
| 2861 | sm->proto == WPA_PROTO_RSN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2862 | |
| 2863 | ret = os_snprintf(buf, buflen, |
| 2864 | "dot11RSNAOptionImplemented=TRUE\n" |
| 2865 | "dot11RSNAPreauthenticationImplemented=TRUE\n" |
| 2866 | "dot11RSNAEnabled=%s\n" |
| 2867 | "dot11RSNAPreauthenticationEnabled=%s\n" |
| 2868 | "dot11RSNAConfigVersion=%d\n" |
| 2869 | "dot11RSNAConfigPairwiseKeysSupported=5\n" |
| 2870 | "dot11RSNAConfigGroupCipherSize=%d\n" |
| 2871 | "dot11RSNAConfigPMKLifetime=%d\n" |
| 2872 | "dot11RSNAConfigPMKReauthThreshold=%d\n" |
| 2873 | "dot11RSNAConfigNumberOfPTKSAReplayCounters=1\n" |
| 2874 | "dot11RSNAConfigSATimeout=%d\n", |
| 2875 | rsna ? "TRUE" : "FALSE", |
| 2876 | rsna ? "TRUE" : "FALSE", |
| 2877 | RSN_VERSION, |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2878 | wpa_cipher_key_len(sm->group_cipher) * 8, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2879 | sm->dot11RSNAConfigPMKLifetime, |
| 2880 | sm->dot11RSNAConfigPMKReauthThreshold, |
| 2881 | sm->dot11RSNAConfigSATimeout); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2882 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2883 | return 0; |
| 2884 | len = ret; |
| 2885 | |
| 2886 | ret = os_snprintf( |
| 2887 | buf + len, buflen - len, |
| 2888 | "dot11RSNAAuthenticationSuiteSelected=" RSN_SUITE "\n" |
| 2889 | "dot11RSNAPairwiseCipherSelected=" RSN_SUITE "\n" |
| 2890 | "dot11RSNAGroupCipherSelected=" RSN_SUITE "\n" |
| 2891 | "dot11RSNAPMKIDUsed=%s\n" |
| 2892 | "dot11RSNAAuthenticationSuiteRequested=" RSN_SUITE "\n" |
| 2893 | "dot11RSNAPairwiseCipherRequested=" RSN_SUITE "\n" |
| 2894 | "dot11RSNAGroupCipherRequested=" RSN_SUITE "\n" |
| 2895 | "dot11RSNAConfigNumberOfGTKSAReplayCounters=0\n" |
| 2896 | "dot11RSNA4WayHandshakeFailures=%u\n", |
| 2897 | RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)), |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2898 | RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto, |
| 2899 | sm->pairwise_cipher)), |
| 2900 | RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto, |
| 2901 | sm->group_cipher)), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2902 | pmkid_txt, |
| 2903 | RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)), |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2904 | RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto, |
| 2905 | sm->pairwise_cipher)), |
| 2906 | RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto, |
| 2907 | sm->group_cipher)), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2908 | sm->dot11RSNA4WayHandshakeFailures); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2909 | if (!os_snprintf_error(buflen - len, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2910 | len += ret; |
| 2911 | |
| 2912 | return (int) len; |
| 2913 | } |
| 2914 | #endif /* CONFIG_CTRL_IFACE */ |
| 2915 | |
| 2916 | |
| 2917 | static void wpa_sm_pmksa_free_cb(struct rsn_pmksa_cache_entry *entry, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2918 | void *ctx, enum pmksa_free_reason reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2919 | { |
| 2920 | struct wpa_sm *sm = ctx; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2921 | int deauth = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2922 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2923 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: PMKSA cache entry free_cb: " |
| 2924 | MACSTR " reason=%d", MAC2STR(entry->aa), reason); |
| 2925 | |
| 2926 | if (sm->cur_pmksa == entry) { |
| 2927 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 2928 | "RSN: %s current PMKSA entry", |
| 2929 | reason == PMKSA_REPLACE ? "replaced" : "removed"); |
| 2930 | pmksa_cache_clear_current(sm); |
| 2931 | |
| 2932 | /* |
| 2933 | * If an entry is simply being replaced, there's no need to |
| 2934 | * deauthenticate because it will be immediately re-added. |
| 2935 | * This happens when EAP authentication is completed again |
| 2936 | * (reauth or failed PMKSA caching attempt). |
| 2937 | */ |
| 2938 | if (reason != PMKSA_REPLACE) |
| 2939 | deauth = 1; |
| 2940 | } |
| 2941 | |
| 2942 | if (reason == PMKSA_EXPIRE && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2943 | (sm->pmk_len == entry->pmk_len && |
| 2944 | os_memcmp(sm->pmk, entry->pmk, sm->pmk_len) == 0)) { |
| 2945 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2946 | "RSN: deauthenticating due to expired PMK"); |
| 2947 | pmksa_cache_clear_current(sm); |
| 2948 | deauth = 1; |
| 2949 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2950 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2951 | if (deauth) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2952 | sm->pmk_len = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2953 | os_memset(sm->pmk, 0, sizeof(sm->pmk)); |
| 2954 | wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); |
| 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2959 | static bool wpa_sm_pmksa_is_current_cb(struct rsn_pmksa_cache_entry *entry, |
| 2960 | void *ctx) |
| 2961 | { |
| 2962 | struct wpa_sm *sm = ctx; |
| 2963 | |
| 2964 | return sm->cur_pmksa == entry; |
| 2965 | } |
| 2966 | |
| 2967 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2968 | /** |
| 2969 | * wpa_sm_init - Initialize WPA state machine |
| 2970 | * @ctx: Context pointer for callbacks; this needs to be an allocated buffer |
| 2971 | * Returns: Pointer to the allocated WPA state machine data |
| 2972 | * |
| 2973 | * This function is used to allocate a new WPA state machine and the returned |
| 2974 | * value is passed to all WPA state machine calls. |
| 2975 | */ |
| 2976 | struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx) |
| 2977 | { |
| 2978 | struct wpa_sm *sm; |
| 2979 | |
| 2980 | sm = os_zalloc(sizeof(*sm)); |
| 2981 | if (sm == NULL) |
| 2982 | return NULL; |
| 2983 | dl_list_init(&sm->pmksa_candidates); |
| 2984 | sm->renew_snonce = 1; |
| 2985 | sm->ctx = ctx; |
| 2986 | |
| 2987 | sm->dot11RSNAConfigPMKLifetime = 43200; |
| 2988 | sm->dot11RSNAConfigPMKReauthThreshold = 70; |
| 2989 | sm->dot11RSNAConfigSATimeout = 60; |
| 2990 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2991 | sm->pmksa = pmksa_cache_init(wpa_sm_pmksa_free_cb, |
| 2992 | wpa_sm_pmksa_is_current_cb, sm, sm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2993 | if (sm->pmksa == NULL) { |
| 2994 | wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, |
| 2995 | "RSN: PMKSA cache initialization failed"); |
| 2996 | os_free(sm); |
| 2997 | return NULL; |
| 2998 | } |
| 2999 | |
| 3000 | return sm; |
| 3001 | } |
| 3002 | |
| 3003 | |
| 3004 | /** |
| 3005 | * wpa_sm_deinit - Deinitialize WPA state machine |
| 3006 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3007 | */ |
| 3008 | void wpa_sm_deinit(struct wpa_sm *sm) |
| 3009 | { |
| 3010 | if (sm == NULL) |
| 3011 | return; |
| 3012 | pmksa_cache_deinit(sm->pmksa); |
| 3013 | eloop_cancel_timeout(wpa_sm_start_preauth, sm, NULL); |
| 3014 | eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL); |
| 3015 | os_free(sm->assoc_wpa_ie); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3016 | os_free(sm->assoc_rsnxe); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3017 | os_free(sm->ap_wpa_ie); |
| 3018 | os_free(sm->ap_rsn_ie); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3019 | os_free(sm->ap_rsnxe); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3020 | wpa_sm_drop_sa(sm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3021 | os_free(sm->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3022 | #ifdef CONFIG_IEEE80211R |
| 3023 | os_free(sm->assoc_resp_ies); |
| 3024 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 3025 | #ifdef CONFIG_TESTING_OPTIONS |
| 3026 | wpabuf_free(sm->test_assoc_ie); |
| 3027 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3028 | #ifdef CONFIG_FILS_SK_PFS |
| 3029 | crypto_ecdh_deinit(sm->fils_ecdh); |
| 3030 | #endif /* CONFIG_FILS_SK_PFS */ |
| 3031 | #ifdef CONFIG_FILS |
| 3032 | wpabuf_free(sm->fils_ft_ies); |
| 3033 | #endif /* CONFIG_FILS */ |
| 3034 | #ifdef CONFIG_OWE |
| 3035 | crypto_ecdh_deinit(sm->owe_ecdh); |
| 3036 | #endif /* CONFIG_OWE */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3037 | #ifdef CONFIG_DPP2 |
| 3038 | wpabuf_clear_free(sm->dpp_z); |
| 3039 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3040 | os_free(sm); |
| 3041 | } |
| 3042 | |
| 3043 | |
| 3044 | /** |
| 3045 | * wpa_sm_notify_assoc - Notify WPA state machine about association |
| 3046 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3047 | * @bssid: The BSSID of the new association |
| 3048 | * |
| 3049 | * This function is called to let WPA state machine know that the connection |
| 3050 | * was established. |
| 3051 | */ |
| 3052 | void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid) |
| 3053 | { |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 3054 | int clear_keys = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3055 | |
| 3056 | if (sm == NULL) |
| 3057 | return; |
| 3058 | |
| 3059 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 3060 | "WPA: Association event - clear replay counter"); |
| 3061 | os_memcpy(sm->bssid, bssid, ETH_ALEN); |
| 3062 | os_memset(sm->rx_replay_counter, 0, WPA_REPLAY_COUNTER_LEN); |
| 3063 | sm->rx_replay_counter_set = 0; |
| 3064 | sm->renew_snonce = 1; |
| 3065 | if (os_memcmp(sm->preauth_bssid, bssid, ETH_ALEN) == 0) |
| 3066 | rsn_preauth_deinit(sm); |
| 3067 | |
| 3068 | #ifdef CONFIG_IEEE80211R |
| 3069 | if (wpa_ft_is_completed(sm)) { |
| 3070 | /* |
| 3071 | * Clear portValid to kick EAPOL state machine to re-enter |
| 3072 | * AUTHENTICATED state to get the EAPOL port Authorized. |
| 3073 | */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 3074 | eapol_sm_notify_portValid(sm->eapol, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3075 | wpa_supplicant_key_neg_complete(sm, sm->bssid, 1); |
| 3076 | |
| 3077 | /* Prepare for the next transition */ |
| 3078 | wpa_ft_prepare_auth_request(sm, NULL); |
| 3079 | |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 3080 | clear_keys = 0; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3081 | sm->ft_protocol = 1; |
| 3082 | } else { |
| 3083 | sm->ft_protocol = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3084 | } |
| 3085 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3086 | #ifdef CONFIG_FILS |
| 3087 | if (sm->fils_completed) { |
| 3088 | /* |
| 3089 | * Clear portValid to kick EAPOL state machine to re-enter |
| 3090 | * AUTHENTICATED state to get the EAPOL port Authorized. |
| 3091 | */ |
| 3092 | wpa_supplicant_key_neg_complete(sm, sm->bssid, 1); |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 3093 | clear_keys = 0; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3094 | } |
| 3095 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3096 | |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 3097 | if (clear_keys) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3098 | /* |
| 3099 | * IEEE 802.11, 8.4.10: Delete PTK SA on (re)association if |
| 3100 | * this is not part of a Fast BSS Transition. |
| 3101 | */ |
| 3102 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Clear old PTK"); |
| 3103 | sm->ptk_set = 0; |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 3104 | os_memset(&sm->ptk, 0, sizeof(sm->ptk)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3105 | sm->tptk_set = 0; |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 3106 | os_memset(&sm->tptk, 0, sizeof(sm->tptk)); |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 3107 | os_memset(&sm->gtk, 0, sizeof(sm->gtk)); |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 3108 | os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep)); |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 3109 | os_memset(&sm->igtk, 0, sizeof(sm->igtk)); |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 3110 | os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep)); |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 3111 | sm->tk_set = false; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | #ifdef CONFIG_TDLS |
| 3115 | wpa_tdls_assoc(sm); |
| 3116 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3117 | |
| 3118 | #ifdef CONFIG_P2P |
| 3119 | os_memset(sm->p2p_ip_addr, 0, sizeof(sm->p2p_ip_addr)); |
| 3120 | #endif /* CONFIG_P2P */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3121 | |
| 3122 | sm->keyidx_active = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | |
| 3126 | /** |
| 3127 | * wpa_sm_notify_disassoc - Notify WPA state machine about disassociation |
| 3128 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3129 | * |
| 3130 | * This function is called to let WPA state machine know that the connection |
| 3131 | * was lost. This will abort any existing pre-authentication session. |
| 3132 | */ |
| 3133 | void wpa_sm_notify_disassoc(struct wpa_sm *sm) |
| 3134 | { |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 3135 | eloop_cancel_timeout(wpa_sm_start_preauth, sm, NULL); |
| 3136 | eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3137 | rsn_preauth_deinit(sm); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3138 | pmksa_cache_clear_current(sm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3139 | if (wpa_sm_get_state(sm) == WPA_4WAY_HANDSHAKE) |
| 3140 | sm->dot11RSNA4WayHandshakeFailures++; |
| 3141 | #ifdef CONFIG_TDLS |
| 3142 | wpa_tdls_disassoc(sm); |
| 3143 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3144 | #ifdef CONFIG_FILS |
| 3145 | sm->fils_completed = 0; |
| 3146 | #endif /* CONFIG_FILS */ |
Jouni Malinen | 4283f9e | 2017-09-22 12:06:37 +0300 | [diff] [blame] | 3147 | #ifdef CONFIG_IEEE80211R |
| 3148 | sm->ft_reassoc_completed = 0; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3149 | sm->ft_protocol = 0; |
Jouni Malinen | 4283f9e | 2017-09-22 12:06:37 +0300 | [diff] [blame] | 3150 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3151 | |
| 3152 | /* Keys are not needed in the WPA state machine anymore */ |
| 3153 | wpa_sm_drop_sa(sm); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3154 | sm->keyidx_active = 0; |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 3155 | |
| 3156 | sm->msg_3_of_4_ok = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3157 | os_memset(sm->bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | |
| 3161 | /** |
| 3162 | * wpa_sm_set_pmk - Set PMK |
| 3163 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3164 | * @pmk: The new PMK |
| 3165 | * @pmk_len: The length of the new PMK in bytes |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3166 | * @pmkid: Calculated PMKID |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3167 | * @bssid: AA to add into PMKSA cache or %NULL to not cache the PMK |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3168 | * |
| 3169 | * Configure the PMK for WPA state machine. |
| 3170 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3171 | void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3172 | const u8 *pmkid, const u8 *bssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3173 | { |
| 3174 | if (sm == NULL) |
| 3175 | return; |
| 3176 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3177 | wpa_hexdump_key(MSG_DEBUG, "WPA: Set PMK based on external data", |
| 3178 | pmk, pmk_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3179 | sm->pmk_len = pmk_len; |
| 3180 | os_memcpy(sm->pmk, pmk, pmk_len); |
| 3181 | |
| 3182 | #ifdef CONFIG_IEEE80211R |
| 3183 | /* Set XXKey to be PSK for FT key derivation */ |
| 3184 | sm->xxkey_len = pmk_len; |
| 3185 | os_memcpy(sm->xxkey, pmk, pmk_len); |
| 3186 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3187 | |
| 3188 | if (bssid) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3189 | sm->cur_pmksa = pmksa_cache_add(sm->pmksa, pmk, pmk_len, |
| 3190 | pmkid, NULL, 0, bssid, |
| 3191 | sm->own_addr, |
| 3192 | sm->network_ctx, sm->key_mgmt, |
| 3193 | NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3194 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | |
| 3198 | /** |
| 3199 | * wpa_sm_set_pmk_from_pmksa - Set PMK based on the current PMKSA |
| 3200 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3201 | * |
| 3202 | * Take the PMK from the current PMKSA into use. If no PMKSA is active, the PMK |
| 3203 | * will be cleared. |
| 3204 | */ |
| 3205 | void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm) |
| 3206 | { |
| 3207 | if (sm == NULL) |
| 3208 | return; |
| 3209 | |
| 3210 | if (sm->cur_pmksa) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3211 | wpa_hexdump_key(MSG_DEBUG, |
| 3212 | "WPA: Set PMK based on current PMKSA", |
| 3213 | sm->cur_pmksa->pmk, sm->cur_pmksa->pmk_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3214 | sm->pmk_len = sm->cur_pmksa->pmk_len; |
| 3215 | os_memcpy(sm->pmk, sm->cur_pmksa->pmk, sm->pmk_len); |
| 3216 | } else { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3217 | wpa_printf(MSG_DEBUG, "WPA: No current PMKSA - clear PMK"); |
| 3218 | sm->pmk_len = 0; |
| 3219 | os_memset(sm->pmk, 0, PMK_LEN_MAX); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | |
| 3224 | /** |
| 3225 | * wpa_sm_set_fast_reauth - Set fast reauthentication (EAP) enabled/disabled |
| 3226 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3227 | * @fast_reauth: Whether fast reauthentication (EAP) is allowed |
| 3228 | */ |
| 3229 | void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth) |
| 3230 | { |
| 3231 | if (sm) |
| 3232 | sm->fast_reauth = fast_reauth; |
| 3233 | } |
| 3234 | |
| 3235 | |
| 3236 | /** |
| 3237 | * wpa_sm_set_scard_ctx - Set context pointer for smartcard callbacks |
| 3238 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3239 | * @scard_ctx: Context pointer for smartcard related callback functions |
| 3240 | */ |
| 3241 | void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx) |
| 3242 | { |
| 3243 | if (sm == NULL) |
| 3244 | return; |
| 3245 | sm->scard_ctx = scard_ctx; |
| 3246 | if (sm->preauth_eapol) |
| 3247 | eapol_sm_register_scard_ctx(sm->preauth_eapol, scard_ctx); |
| 3248 | } |
| 3249 | |
| 3250 | |
| 3251 | /** |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3252 | * wpa_sm_set_config - Notification of current configuration change |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3253 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3254 | * @config: Pointer to current network configuration |
| 3255 | * |
| 3256 | * Notify WPA state machine that configuration has changed. config will be |
| 3257 | * stored as a backpointer to network configuration. This can be %NULL to clear |
| 3258 | * the stored pointed. |
| 3259 | */ |
| 3260 | void wpa_sm_set_config(struct wpa_sm *sm, struct rsn_supp_config *config) |
| 3261 | { |
| 3262 | if (!sm) |
| 3263 | return; |
| 3264 | |
| 3265 | if (config) { |
| 3266 | sm->network_ctx = config->network_ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3267 | sm->allowed_pairwise_cipher = config->allowed_pairwise_cipher; |
| 3268 | sm->proactive_key_caching = config->proactive_key_caching; |
| 3269 | sm->eap_workaround = config->eap_workaround; |
| 3270 | sm->eap_conf_ctx = config->eap_conf_ctx; |
| 3271 | if (config->ssid) { |
| 3272 | os_memcpy(sm->ssid, config->ssid, config->ssid_len); |
| 3273 | sm->ssid_len = config->ssid_len; |
| 3274 | } else |
| 3275 | sm->ssid_len = 0; |
| 3276 | sm->wpa_ptk_rekey = config->wpa_ptk_rekey; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3277 | sm->p2p = config->p2p; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3278 | sm->wpa_rsc_relaxation = config->wpa_rsc_relaxation; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3279 | sm->owe_ptk_workaround = config->owe_ptk_workaround; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3280 | sm->force_kdk_derivation = config->force_kdk_derivation; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3281 | #ifdef CONFIG_FILS |
| 3282 | if (config->fils_cache_id) { |
| 3283 | sm->fils_cache_id_set = 1; |
| 3284 | os_memcpy(sm->fils_cache_id, config->fils_cache_id, |
| 3285 | FILS_CACHE_ID_LEN); |
| 3286 | } else { |
| 3287 | sm->fils_cache_id_set = 0; |
| 3288 | } |
| 3289 | #endif /* CONFIG_FILS */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3290 | sm->beacon_prot = config->beacon_prot; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3291 | } else { |
| 3292 | sm->network_ctx = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3293 | sm->allowed_pairwise_cipher = 0; |
| 3294 | sm->proactive_key_caching = 0; |
| 3295 | sm->eap_workaround = 0; |
| 3296 | sm->eap_conf_ctx = NULL; |
| 3297 | sm->ssid_len = 0; |
| 3298 | sm->wpa_ptk_rekey = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3299 | sm->p2p = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3300 | sm->wpa_rsc_relaxation = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3301 | sm->owe_ptk_workaround = 0; |
| 3302 | sm->beacon_prot = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3303 | sm->force_kdk_derivation = false; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3304 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | |
| 3308 | /** |
| 3309 | * wpa_sm_set_own_addr - Set own MAC address |
| 3310 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3311 | * @addr: Own MAC address |
| 3312 | */ |
| 3313 | void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr) |
| 3314 | { |
| 3315 | if (sm) |
| 3316 | os_memcpy(sm->own_addr, addr, ETH_ALEN); |
| 3317 | } |
| 3318 | |
| 3319 | |
| 3320 | /** |
| 3321 | * wpa_sm_set_ifname - Set network interface name |
| 3322 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3323 | * @ifname: Interface name |
| 3324 | * @bridge_ifname: Optional bridge interface name (for pre-auth) |
| 3325 | */ |
| 3326 | void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname, |
| 3327 | const char *bridge_ifname) |
| 3328 | { |
| 3329 | if (sm) { |
| 3330 | sm->ifname = ifname; |
| 3331 | sm->bridge_ifname = bridge_ifname; |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | |
| 3336 | /** |
| 3337 | * wpa_sm_set_eapol - Set EAPOL state machine pointer |
| 3338 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3339 | * @eapol: Pointer to EAPOL state machine allocated with eapol_sm_init() |
| 3340 | */ |
| 3341 | void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol) |
| 3342 | { |
| 3343 | if (sm) |
| 3344 | sm->eapol = eapol; |
| 3345 | } |
| 3346 | |
| 3347 | |
| 3348 | /** |
| 3349 | * wpa_sm_set_param - Set WPA state machine parameters |
| 3350 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3351 | * @param: Parameter field |
| 3352 | * @value: Parameter value |
| 3353 | * Returns: 0 on success, -1 on failure |
| 3354 | */ |
| 3355 | int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param, |
| 3356 | unsigned int value) |
| 3357 | { |
| 3358 | int ret = 0; |
| 3359 | |
| 3360 | if (sm == NULL) |
| 3361 | return -1; |
| 3362 | |
| 3363 | switch (param) { |
| 3364 | case RSNA_PMK_LIFETIME: |
| 3365 | if (value > 0) |
| 3366 | sm->dot11RSNAConfigPMKLifetime = value; |
| 3367 | else |
| 3368 | ret = -1; |
| 3369 | break; |
| 3370 | case RSNA_PMK_REAUTH_THRESHOLD: |
| 3371 | if (value > 0 && value <= 100) |
| 3372 | sm->dot11RSNAConfigPMKReauthThreshold = value; |
| 3373 | else |
| 3374 | ret = -1; |
| 3375 | break; |
| 3376 | case RSNA_SA_TIMEOUT: |
| 3377 | if (value > 0) |
| 3378 | sm->dot11RSNAConfigSATimeout = value; |
| 3379 | else |
| 3380 | ret = -1; |
| 3381 | break; |
| 3382 | case WPA_PARAM_PROTO: |
| 3383 | sm->proto = value; |
| 3384 | break; |
| 3385 | case WPA_PARAM_PAIRWISE: |
| 3386 | sm->pairwise_cipher = value; |
| 3387 | break; |
| 3388 | case WPA_PARAM_GROUP: |
| 3389 | sm->group_cipher = value; |
| 3390 | break; |
| 3391 | case WPA_PARAM_KEY_MGMT: |
| 3392 | sm->key_mgmt = value; |
| 3393 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3394 | case WPA_PARAM_MGMT_GROUP: |
| 3395 | sm->mgmt_group_cipher = value; |
| 3396 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3397 | case WPA_PARAM_RSN_ENABLED: |
| 3398 | sm->rsn_enabled = value; |
| 3399 | break; |
| 3400 | case WPA_PARAM_MFP: |
| 3401 | sm->mfp = value; |
| 3402 | break; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3403 | case WPA_PARAM_OCV: |
| 3404 | sm->ocv = value; |
| 3405 | break; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3406 | case WPA_PARAM_SAE_PWE: |
| 3407 | sm->sae_pwe = value; |
| 3408 | break; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3409 | case WPA_PARAM_SAE_PK: |
| 3410 | sm->sae_pk = value; |
| 3411 | break; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3412 | case WPA_PARAM_DENY_PTK0_REKEY: |
| 3413 | sm->wpa_deny_ptk0_rekey = value; |
| 3414 | break; |
| 3415 | case WPA_PARAM_EXT_KEY_ID: |
| 3416 | sm->ext_key_id = value; |
| 3417 | break; |
| 3418 | case WPA_PARAM_USE_EXT_KEY_ID: |
| 3419 | sm->use_ext_key_id = value; |
| 3420 | break; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3421 | #ifdef CONFIG_TESTING_OPTIONS |
| 3422 | case WPA_PARAM_FT_RSNXE_USED: |
| 3423 | sm->ft_rsnxe_used = value; |
| 3424 | break; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3425 | case WPA_PARAM_OCI_FREQ_EAPOL: |
| 3426 | sm->oci_freq_override_eapol = value; |
| 3427 | break; |
| 3428 | case WPA_PARAM_OCI_FREQ_EAPOL_G2: |
| 3429 | sm->oci_freq_override_eapol_g2 = value; |
| 3430 | break; |
| 3431 | case WPA_PARAM_OCI_FREQ_FT_ASSOC: |
| 3432 | sm->oci_freq_override_ft_assoc = value; |
| 3433 | break; |
| 3434 | case WPA_PARAM_OCI_FREQ_FILS_ASSOC: |
| 3435 | sm->oci_freq_override_fils_assoc = value; |
| 3436 | break; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 3437 | case WPA_PARAM_DISABLE_EAPOL_G2_TX: |
| 3438 | sm->disable_eapol_g2_tx = value; |
| 3439 | break; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3440 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3441 | #ifdef CONFIG_DPP2 |
| 3442 | case WPA_PARAM_DPP_PFS: |
| 3443 | sm->dpp_pfs = value; |
| 3444 | break; |
| 3445 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3446 | default: |
| 3447 | break; |
| 3448 | } |
| 3449 | |
| 3450 | return ret; |
| 3451 | } |
| 3452 | |
| 3453 | |
| 3454 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3455 | * wpa_sm_get_status - Get WPA state machine |
| 3456 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3457 | * @buf: Buffer for status information |
| 3458 | * @buflen: Maximum buffer length |
| 3459 | * @verbose: Whether to include verbose status information |
| 3460 | * Returns: Number of bytes written to buf. |
| 3461 | * |
| 3462 | * Query WPA state machine for status information. This function fills in |
| 3463 | * a text area with current status information. If the buffer (buf) is not |
| 3464 | * large enough, status information will be truncated to fit the buffer. |
| 3465 | */ |
| 3466 | int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen, |
| 3467 | int verbose) |
| 3468 | { |
| 3469 | char *pos = buf, *end = buf + buflen; |
| 3470 | int ret; |
| 3471 | |
| 3472 | ret = os_snprintf(pos, end - pos, |
| 3473 | "pairwise_cipher=%s\n" |
| 3474 | "group_cipher=%s\n" |
| 3475 | "key_mgmt=%s\n", |
| 3476 | wpa_cipher_txt(sm->pairwise_cipher), |
| 3477 | wpa_cipher_txt(sm->group_cipher), |
| 3478 | wpa_key_mgmt_txt(sm->key_mgmt, sm->proto)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3479 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3480 | return pos - buf; |
| 3481 | pos += ret; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3482 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3483 | #ifdef CONFIG_DPP2 |
| 3484 | if (sm->key_mgmt == WPA_KEY_MGMT_DPP && sm->dpp_z) { |
| 3485 | ret = os_snprintf(pos, end - pos, "dpp_pfs=1\n"); |
| 3486 | if (os_snprintf_error(end - pos, ret)) |
| 3487 | return pos - buf; |
| 3488 | pos += ret; |
| 3489 | } |
| 3490 | #endif /* CONFIG_DPP2 */ |
| 3491 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3492 | if (sm->mfp != NO_MGMT_FRAME_PROTECTION && sm->ap_rsn_ie) { |
| 3493 | struct wpa_ie_data rsn; |
| 3494 | if (wpa_parse_wpa_ie_rsn(sm->ap_rsn_ie, sm->ap_rsn_ie_len, &rsn) |
| 3495 | >= 0 && |
| 3496 | rsn.capabilities & (WPA_CAPABILITY_MFPR | |
| 3497 | WPA_CAPABILITY_MFPC)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3498 | ret = os_snprintf(pos, end - pos, "pmf=%d\n" |
| 3499 | "mgmt_group_cipher=%s\n", |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3500 | (rsn.capabilities & |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3501 | WPA_CAPABILITY_MFPR) ? 2 : 1, |
| 3502 | wpa_cipher_txt( |
| 3503 | sm->mgmt_group_cipher)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3504 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3505 | return pos - buf; |
| 3506 | pos += ret; |
| 3507 | } |
| 3508 | } |
| 3509 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3510 | return pos - buf; |
| 3511 | } |
| 3512 | |
| 3513 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3514 | int wpa_sm_pmf_enabled(struct wpa_sm *sm) |
| 3515 | { |
| 3516 | struct wpa_ie_data rsn; |
| 3517 | |
| 3518 | if (sm->mfp == NO_MGMT_FRAME_PROTECTION || !sm->ap_rsn_ie) |
| 3519 | return 0; |
| 3520 | |
| 3521 | if (wpa_parse_wpa_ie_rsn(sm->ap_rsn_ie, sm->ap_rsn_ie_len, &rsn) >= 0 && |
| 3522 | rsn.capabilities & (WPA_CAPABILITY_MFPR | WPA_CAPABILITY_MFPC)) |
| 3523 | return 1; |
| 3524 | |
| 3525 | return 0; |
| 3526 | } |
| 3527 | |
| 3528 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3529 | int wpa_sm_ext_key_id(struct wpa_sm *sm) |
| 3530 | { |
| 3531 | return sm ? sm->ext_key_id : 0; |
| 3532 | } |
| 3533 | |
| 3534 | |
| 3535 | int wpa_sm_ext_key_id_active(struct wpa_sm *sm) |
| 3536 | { |
| 3537 | return sm ? sm->use_ext_key_id : 0; |
| 3538 | } |
| 3539 | |
| 3540 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3541 | int wpa_sm_ocv_enabled(struct wpa_sm *sm) |
| 3542 | { |
| 3543 | struct wpa_ie_data rsn; |
| 3544 | |
| 3545 | if (!sm->ocv || !sm->ap_rsn_ie) |
| 3546 | return 0; |
| 3547 | |
| 3548 | return wpa_parse_wpa_ie_rsn(sm->ap_rsn_ie, sm->ap_rsn_ie_len, |
| 3549 | &rsn) >= 0 && |
| 3550 | (rsn.capabilities & WPA_CAPABILITY_OCVC); |
| 3551 | } |
| 3552 | |
| 3553 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3554 | /** |
| 3555 | * wpa_sm_set_assoc_wpa_ie_default - Generate own WPA/RSN IE from configuration |
| 3556 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3557 | * @wpa_ie: Pointer to buffer for WPA/RSN IE |
| 3558 | * @wpa_ie_len: Pointer to the length of the wpa_ie buffer |
| 3559 | * Returns: 0 on success, -1 on failure |
| 3560 | */ |
| 3561 | int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie, |
| 3562 | size_t *wpa_ie_len) |
| 3563 | { |
| 3564 | int res; |
| 3565 | |
| 3566 | if (sm == NULL) |
| 3567 | return -1; |
| 3568 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 3569 | #ifdef CONFIG_TESTING_OPTIONS |
| 3570 | if (sm->test_assoc_ie) { |
| 3571 | wpa_printf(MSG_DEBUG, |
| 3572 | "TESTING: Replace association WPA/RSN IE"); |
| 3573 | if (*wpa_ie_len < wpabuf_len(sm->test_assoc_ie)) |
| 3574 | return -1; |
| 3575 | os_memcpy(wpa_ie, wpabuf_head(sm->test_assoc_ie), |
| 3576 | wpabuf_len(sm->test_assoc_ie)); |
| 3577 | res = wpabuf_len(sm->test_assoc_ie); |
| 3578 | } else |
| 3579 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3580 | res = wpa_gen_wpa_ie(sm, wpa_ie, *wpa_ie_len); |
| 3581 | if (res < 0) |
| 3582 | return -1; |
| 3583 | *wpa_ie_len = res; |
| 3584 | |
| 3585 | wpa_hexdump(MSG_DEBUG, "WPA: Set own WPA IE default", |
| 3586 | wpa_ie, *wpa_ie_len); |
| 3587 | |
| 3588 | if (sm->assoc_wpa_ie == NULL) { |
| 3589 | /* |
| 3590 | * Make a copy of the WPA/RSN IE so that 4-Way Handshake gets |
| 3591 | * the correct version of the IE even if PMKSA caching is |
| 3592 | * aborted (which would remove PMKID from IE generation). |
| 3593 | */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3594 | sm->assoc_wpa_ie = os_memdup(wpa_ie, *wpa_ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3595 | if (sm->assoc_wpa_ie == NULL) |
| 3596 | return -1; |
| 3597 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3598 | sm->assoc_wpa_ie_len = *wpa_ie_len; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3599 | } else { |
| 3600 | wpa_hexdump(MSG_DEBUG, |
| 3601 | "WPA: Leave previously set WPA IE default", |
| 3602 | sm->assoc_wpa_ie, sm->assoc_wpa_ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | return 0; |
| 3606 | } |
| 3607 | |
| 3608 | |
| 3609 | /** |
| 3610 | * wpa_sm_set_assoc_wpa_ie - Set own WPA/RSN IE from (Re)AssocReq |
| 3611 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3612 | * @ie: Pointer to IE data (starting from id) |
| 3613 | * @len: IE length |
| 3614 | * Returns: 0 on success, -1 on failure |
| 3615 | * |
| 3616 | * Inform WPA state machine about the WPA/RSN IE used in (Re)Association |
| 3617 | * Request frame. The IE will be used to override the default value generated |
| 3618 | * with wpa_sm_set_assoc_wpa_ie_default(). |
| 3619 | */ |
| 3620 | int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len) |
| 3621 | { |
| 3622 | if (sm == NULL) |
| 3623 | return -1; |
| 3624 | |
| 3625 | os_free(sm->assoc_wpa_ie); |
| 3626 | if (ie == NULL || len == 0) { |
| 3627 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 3628 | "WPA: clearing own WPA/RSN IE"); |
| 3629 | sm->assoc_wpa_ie = NULL; |
| 3630 | sm->assoc_wpa_ie_len = 0; |
| 3631 | } else { |
| 3632 | wpa_hexdump(MSG_DEBUG, "WPA: set own WPA/RSN IE", ie, len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3633 | sm->assoc_wpa_ie = os_memdup(ie, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3634 | if (sm->assoc_wpa_ie == NULL) |
| 3635 | return -1; |
| 3636 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3637 | sm->assoc_wpa_ie_len = len; |
| 3638 | } |
| 3639 | |
| 3640 | return 0; |
| 3641 | } |
| 3642 | |
| 3643 | |
| 3644 | /** |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3645 | * wpa_sm_set_assoc_rsnxe_default - Generate own RSNXE from configuration |
| 3646 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3647 | * @rsnxe: Pointer to buffer for RSNXE |
| 3648 | * @rsnxe_len: Pointer to the length of the rsne buffer |
| 3649 | * Returns: 0 on success, -1 on failure |
| 3650 | */ |
| 3651 | int wpa_sm_set_assoc_rsnxe_default(struct wpa_sm *sm, u8 *rsnxe, |
| 3652 | size_t *rsnxe_len) |
| 3653 | { |
| 3654 | int res; |
| 3655 | |
| 3656 | if (!sm) |
| 3657 | return -1; |
| 3658 | |
| 3659 | res = wpa_gen_rsnxe(sm, rsnxe, *rsnxe_len); |
| 3660 | if (res < 0) |
| 3661 | return -1; |
| 3662 | *rsnxe_len = res; |
| 3663 | |
| 3664 | wpa_hexdump(MSG_DEBUG, "RSN: Set own RSNXE default", rsnxe, *rsnxe_len); |
| 3665 | |
| 3666 | if (sm->assoc_rsnxe) { |
| 3667 | wpa_hexdump(MSG_DEBUG, |
| 3668 | "RSN: Leave previously set RSNXE default", |
| 3669 | sm->assoc_rsnxe, sm->assoc_rsnxe_len); |
| 3670 | } else if (*rsnxe_len > 0) { |
| 3671 | /* |
| 3672 | * Make a copy of the RSNXE so that 4-Way Handshake gets the |
| 3673 | * correct version of the IE even if it gets changed. |
| 3674 | */ |
| 3675 | sm->assoc_rsnxe = os_memdup(rsnxe, *rsnxe_len); |
| 3676 | if (!sm->assoc_rsnxe) |
| 3677 | return -1; |
| 3678 | |
| 3679 | sm->assoc_rsnxe_len = *rsnxe_len; |
| 3680 | } |
| 3681 | |
| 3682 | return 0; |
| 3683 | } |
| 3684 | |
| 3685 | |
| 3686 | /** |
| 3687 | * wpa_sm_set_assoc_rsnxe - Set own RSNXE from (Re)AssocReq |
| 3688 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3689 | * @ie: Pointer to IE data (starting from id) |
| 3690 | * @len: IE length |
| 3691 | * Returns: 0 on success, -1 on failure |
| 3692 | * |
| 3693 | * Inform WPA state machine about the RSNXE used in (Re)Association Request |
| 3694 | * frame. The IE will be used to override the default value generated |
| 3695 | * with wpa_sm_set_assoc_rsnxe_default(). |
| 3696 | */ |
| 3697 | int wpa_sm_set_assoc_rsnxe(struct wpa_sm *sm, const u8 *ie, size_t len) |
| 3698 | { |
| 3699 | if (!sm) |
| 3700 | return -1; |
| 3701 | |
| 3702 | os_free(sm->assoc_rsnxe); |
| 3703 | if (!ie || len == 0) { |
| 3704 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 3705 | "RSN: clearing own RSNXE"); |
| 3706 | sm->assoc_rsnxe = NULL; |
| 3707 | sm->assoc_rsnxe_len = 0; |
| 3708 | } else { |
| 3709 | wpa_hexdump(MSG_DEBUG, "RSN: set own RSNXE", ie, len); |
| 3710 | sm->assoc_rsnxe = os_memdup(ie, len); |
| 3711 | if (!sm->assoc_rsnxe) |
| 3712 | return -1; |
| 3713 | |
| 3714 | sm->assoc_rsnxe_len = len; |
| 3715 | } |
| 3716 | |
| 3717 | return 0; |
| 3718 | } |
| 3719 | |
| 3720 | |
| 3721 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3722 | * wpa_sm_set_ap_wpa_ie - Set AP WPA IE from Beacon/ProbeResp |
| 3723 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3724 | * @ie: Pointer to IE data (starting from id) |
| 3725 | * @len: IE length |
| 3726 | * Returns: 0 on success, -1 on failure |
| 3727 | * |
| 3728 | * Inform WPA state machine about the WPA IE used in Beacon / Probe Response |
| 3729 | * frame. |
| 3730 | */ |
| 3731 | int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len) |
| 3732 | { |
| 3733 | if (sm == NULL) |
| 3734 | return -1; |
| 3735 | |
| 3736 | os_free(sm->ap_wpa_ie); |
| 3737 | if (ie == NULL || len == 0) { |
| 3738 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 3739 | "WPA: clearing AP WPA IE"); |
| 3740 | sm->ap_wpa_ie = NULL; |
| 3741 | sm->ap_wpa_ie_len = 0; |
| 3742 | } else { |
| 3743 | wpa_hexdump(MSG_DEBUG, "WPA: set AP WPA IE", ie, len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3744 | sm->ap_wpa_ie = os_memdup(ie, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3745 | if (sm->ap_wpa_ie == NULL) |
| 3746 | return -1; |
| 3747 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3748 | sm->ap_wpa_ie_len = len; |
| 3749 | } |
| 3750 | |
| 3751 | return 0; |
| 3752 | } |
| 3753 | |
| 3754 | |
| 3755 | /** |
| 3756 | * wpa_sm_set_ap_rsn_ie - Set AP RSN IE from Beacon/ProbeResp |
| 3757 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3758 | * @ie: Pointer to IE data (starting from id) |
| 3759 | * @len: IE length |
| 3760 | * Returns: 0 on success, -1 on failure |
| 3761 | * |
| 3762 | * Inform WPA state machine about the RSN IE used in Beacon / Probe Response |
| 3763 | * frame. |
| 3764 | */ |
| 3765 | int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, size_t len) |
| 3766 | { |
| 3767 | if (sm == NULL) |
| 3768 | return -1; |
| 3769 | |
| 3770 | os_free(sm->ap_rsn_ie); |
| 3771 | if (ie == NULL || len == 0) { |
| 3772 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 3773 | "WPA: clearing AP RSN IE"); |
| 3774 | sm->ap_rsn_ie = NULL; |
| 3775 | sm->ap_rsn_ie_len = 0; |
| 3776 | } else { |
| 3777 | wpa_hexdump(MSG_DEBUG, "WPA: set AP RSN IE", ie, len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3778 | sm->ap_rsn_ie = os_memdup(ie, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3779 | if (sm->ap_rsn_ie == NULL) |
| 3780 | return -1; |
| 3781 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3782 | sm->ap_rsn_ie_len = len; |
| 3783 | } |
| 3784 | |
| 3785 | return 0; |
| 3786 | } |
| 3787 | |
| 3788 | |
| 3789 | /** |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3790 | * wpa_sm_set_ap_rsnxe - Set AP RSNXE from Beacon/ProbeResp |
| 3791 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3792 | * @ie: Pointer to IE data (starting from id) |
| 3793 | * @len: IE length |
| 3794 | * Returns: 0 on success, -1 on failure |
| 3795 | * |
| 3796 | * Inform WPA state machine about the RSNXE used in Beacon / Probe Response |
| 3797 | * frame. |
| 3798 | */ |
| 3799 | int wpa_sm_set_ap_rsnxe(struct wpa_sm *sm, const u8 *ie, size_t len) |
| 3800 | { |
| 3801 | if (!sm) |
| 3802 | return -1; |
| 3803 | |
| 3804 | os_free(sm->ap_rsnxe); |
| 3805 | if (!ie || len == 0) { |
| 3806 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: clearing AP RSNXE"); |
| 3807 | sm->ap_rsnxe = NULL; |
| 3808 | sm->ap_rsnxe_len = 0; |
| 3809 | } else { |
| 3810 | wpa_hexdump(MSG_DEBUG, "WPA: set AP RSNXE", ie, len); |
| 3811 | sm->ap_rsnxe = os_memdup(ie, len); |
| 3812 | if (!sm->ap_rsnxe) |
| 3813 | return -1; |
| 3814 | |
| 3815 | sm->ap_rsnxe_len = len; |
| 3816 | } |
| 3817 | |
| 3818 | return 0; |
| 3819 | } |
| 3820 | |
| 3821 | |
| 3822 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3823 | * wpa_sm_parse_own_wpa_ie - Parse own WPA/RSN IE |
| 3824 | * @sm: Pointer to WPA state machine data from wpa_sm_init() |
| 3825 | * @data: Pointer to data area for parsing results |
| 3826 | * Returns: 0 on success, -1 if IE is not known, or -2 on parsing failure |
| 3827 | * |
| 3828 | * Parse the contents of the own WPA or RSN IE from (Re)AssocReq and write the |
| 3829 | * parsed data into data. |
| 3830 | */ |
| 3831 | int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data) |
| 3832 | { |
| 3833 | if (sm == NULL) |
| 3834 | return -1; |
| 3835 | |
| 3836 | if (sm->assoc_wpa_ie == NULL) { |
| 3837 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 3838 | "WPA: No WPA/RSN IE available from association info"); |
| 3839 | return -1; |
| 3840 | } |
| 3841 | if (wpa_parse_wpa_ie(sm->assoc_wpa_ie, sm->assoc_wpa_ie_len, data)) |
| 3842 | return -2; |
| 3843 | return 0; |
| 3844 | } |
| 3845 | |
| 3846 | |
| 3847 | int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len) |
| 3848 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3849 | return pmksa_cache_list(sm->pmksa, buf, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3853 | struct rsn_pmksa_cache_entry * wpa_sm_pmksa_cache_head(struct wpa_sm *sm) |
| 3854 | { |
| 3855 | return pmksa_cache_head(sm->pmksa); |
| 3856 | } |
| 3857 | |
| 3858 | |
| 3859 | struct rsn_pmksa_cache_entry * |
| 3860 | wpa_sm_pmksa_cache_add_entry(struct wpa_sm *sm, |
| 3861 | struct rsn_pmksa_cache_entry * entry) |
| 3862 | { |
| 3863 | return pmksa_cache_add_entry(sm->pmksa, entry); |
| 3864 | } |
| 3865 | |
| 3866 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3867 | void wpa_sm_pmksa_cache_add(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len, |
| 3868 | const u8 *pmkid, const u8 *bssid, |
| 3869 | const u8 *fils_cache_id) |
| 3870 | { |
| 3871 | sm->cur_pmksa = pmksa_cache_add(sm->pmksa, pmk, pmk_len, pmkid, NULL, 0, |
| 3872 | bssid, sm->own_addr, sm->network_ctx, |
| 3873 | sm->key_mgmt, fils_cache_id); |
| 3874 | } |
| 3875 | |
| 3876 | |
| 3877 | int wpa_sm_pmksa_exists(struct wpa_sm *sm, const u8 *bssid, |
| 3878 | const void *network_ctx) |
| 3879 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3880 | return pmksa_cache_get(sm->pmksa, bssid, NULL, network_ctx, 0) != NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3884 | struct rsn_pmksa_cache_entry * wpa_sm_pmksa_cache_get(struct wpa_sm *sm, |
| 3885 | const u8 *aa, |
| 3886 | const u8 *pmkid, |
| 3887 | const void *network_ctx, |
| 3888 | int akmp) |
| 3889 | { |
| 3890 | return pmksa_cache_get(sm->pmksa, aa, pmkid, network_ctx, akmp); |
| 3891 | } |
| 3892 | |
| 3893 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3894 | void wpa_sm_drop_sa(struct wpa_sm *sm) |
| 3895 | { |
| 3896 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Clear old PMK and PTK"); |
| 3897 | sm->ptk_set = 0; |
| 3898 | sm->tptk_set = 0; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 3899 | sm->tk_set = false; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3900 | sm->pmk_len = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3901 | os_memset(sm->pmk, 0, sizeof(sm->pmk)); |
| 3902 | os_memset(&sm->ptk, 0, sizeof(sm->ptk)); |
| 3903 | os_memset(&sm->tptk, 0, sizeof(sm->tptk)); |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 3904 | os_memset(&sm->gtk, 0, sizeof(sm->gtk)); |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 3905 | os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep)); |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 3906 | os_memset(&sm->igtk, 0, sizeof(sm->igtk)); |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 3907 | os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3908 | #ifdef CONFIG_IEEE80211R |
| 3909 | os_memset(sm->xxkey, 0, sizeof(sm->xxkey)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3910 | sm->xxkey_len = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3911 | os_memset(sm->pmk_r0, 0, sizeof(sm->pmk_r0)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3912 | sm->pmk_r0_len = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3913 | os_memset(sm->pmk_r1, 0, sizeof(sm->pmk_r1)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3914 | sm->pmk_r1_len = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3915 | #ifdef CONFIG_PASN |
| 3916 | os_free(sm->pasn_r1kh); |
| 3917 | sm->pasn_r1kh = NULL; |
| 3918 | sm->n_pasn_r1kh = 0; |
| 3919 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3920 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | |
| 3924 | int wpa_sm_has_ptk(struct wpa_sm *sm) |
| 3925 | { |
| 3926 | if (sm == NULL) |
| 3927 | return 0; |
| 3928 | return sm->ptk_set; |
| 3929 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3930 | |
| 3931 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3932 | int wpa_sm_has_ptk_installed(struct wpa_sm *sm) |
| 3933 | { |
| 3934 | if (!sm) |
| 3935 | return 0; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 3936 | return sm->tk_set || sm->ptk.installed; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3940 | void wpa_sm_update_replay_ctr(struct wpa_sm *sm, const u8 *replay_ctr) |
| 3941 | { |
| 3942 | os_memcpy(sm->rx_replay_counter, replay_ctr, WPA_REPLAY_COUNTER_LEN); |
| 3943 | } |
| 3944 | |
| 3945 | |
| 3946 | void wpa_sm_pmksa_cache_flush(struct wpa_sm *sm, void *network_ctx) |
| 3947 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3948 | pmksa_cache_flush(sm->pmksa, network_ctx, NULL, 0, false); |
| 3949 | } |
| 3950 | |
| 3951 | |
| 3952 | void wpa_sm_external_pmksa_cache_flush(struct wpa_sm *sm, void *network_ctx) |
| 3953 | { |
| 3954 | pmksa_cache_flush(sm->pmksa, network_ctx, NULL, 0, true); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3955 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3956 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3957 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3958 | void wpa_sm_install_pmk(struct wpa_sm *sm) |
| 3959 | { |
| 3960 | /* In case the driver wants to handle re-assocs, pass it down the PMK. */ |
| 3961 | if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->pairwise_cipher), NULL, 0, 0, NULL, 0, |
| 3962 | (u8*)sm->pmk, sm->pmk_len, KEY_FLAG_PMK) < 0) { |
| 3963 | wpa_hexdump(MSG_DEBUG, "PSK: Install PMK to the driver for driver reassociations", |
| 3964 | (u8*)sm->pmk, sm->pmk_len); |
| 3965 | /* No harm if the driver doesn't support. */ |
| 3966 | wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 3967 | "WPA: Failed to set PMK to the driver"); |
| 3968 | } |
| 3969 | } |
Mir Ali | eaaf04e | 2021-06-07 12:17:29 +0530 | [diff] [blame] | 3970 | |
| 3971 | void wpa_sm_notify_brcm_ft_reassoc(struct wpa_sm *sm, const u8 *bssid) |
| 3972 | { |
| 3973 | u8 buf[256]; |
| 3974 | struct wpa_supplicant *wpa_s = sm->ctx->ctx; |
| 3975 | |
| 3976 | wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, |
| 3977 | "WPA: BRCM FT Reassociation event - clear replay counter"); |
| 3978 | os_memcpy(sm->bssid, bssid, ETH_ALEN); |
| 3979 | os_memset(sm->rx_replay_counter, 0, WPA_REPLAY_COUNTER_LEN); |
| 3980 | sm->rx_replay_counter_set = 0; |
| 3981 | |
| 3982 | if (wpa_drv_driver_cmd(wpa_s, "GET_FTKEY", (char *)buf, sizeof(buf)) < 0) { |
| 3983 | wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, |
| 3984 | "WPA: Failed to get FT KEY information"); |
| 3985 | wpa_supplicant_deauthenticate( |
| 3986 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3987 | |
| 3988 | } else { |
| 3989 | /* update kck and kek */ |
| 3990 | os_memcpy(sm->ptk.kck, buf, 16); |
| 3991 | os_memcpy(sm->ptk.kek, buf + 16, 16); |
| 3992 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 3993 | "WPA: Updated KCK and KEK after FT reassoc"); |
| 3994 | } |
| 3995 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3996 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 3997 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3998 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3999 | #ifdef CONFIG_WNM |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4000 | int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf) |
| 4001 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4002 | u16 keyinfo; |
| 4003 | u8 keylen; /* plaintext key len */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4004 | u8 *key_rsc; |
| 4005 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4006 | if (subelem_id == WNM_SLEEP_SUBELEM_GTK) { |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 4007 | struct wpa_gtk_data gd; |
| 4008 | |
| 4009 | os_memset(&gd, 0, sizeof(gd)); |
| 4010 | keylen = wpa_cipher_key_len(sm->group_cipher); |
| 4011 | gd.key_rsc_len = wpa_cipher_rsc_len(sm->group_cipher); |
| 4012 | gd.alg = wpa_cipher_to_alg(sm->group_cipher); |
| 4013 | if (gd.alg == WPA_ALG_NONE) { |
| 4014 | wpa_printf(MSG_DEBUG, "Unsupported group cipher suite"); |
| 4015 | return -1; |
| 4016 | } |
| 4017 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4018 | key_rsc = buf + 5; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4019 | keyinfo = WPA_GET_LE16(buf + 2); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4020 | gd.gtk_len = keylen; |
| 4021 | if (gd.gtk_len != buf[4]) { |
| 4022 | wpa_printf(MSG_DEBUG, "GTK len mismatch len %d vs %d", |
| 4023 | gd.gtk_len, buf[4]); |
| 4024 | return -1; |
| 4025 | } |
| 4026 | gd.keyidx = keyinfo & 0x03; /* B0 - B1 */ |
| 4027 | gd.tx = wpa_supplicant_gtk_tx_bit_workaround( |
| 4028 | sm, !!(keyinfo & WPA_KEY_INFO_TXRX)); |
| 4029 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4030 | os_memcpy(gd.gtk, buf + 13, gd.gtk_len); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4031 | |
| 4032 | wpa_hexdump_key(MSG_DEBUG, "Install GTK (WNM SLEEP)", |
| 4033 | gd.gtk, gd.gtk_len); |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 4034 | if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 1)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4035 | forced_memzero(&gd, sizeof(gd)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4036 | wpa_printf(MSG_DEBUG, "Failed to install the GTK in " |
| 4037 | "WNM mode"); |
| 4038 | return -1; |
| 4039 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4040 | forced_memzero(&gd, sizeof(gd)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4041 | } else if (subelem_id == WNM_SLEEP_SUBELEM_IGTK) { |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 4042 | const struct wpa_igtk_kde *igtk; |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 4043 | |
Mathy Vanhoef | 10bfd64 | 2017-07-12 16:03:24 +0200 | [diff] [blame] | 4044 | igtk = (const struct wpa_igtk_kde *) (buf + 2); |
Jouni Malinen | 58c0e96 | 2017-10-01 12:12:24 +0300 | [diff] [blame] | 4045 | if (wpa_supplicant_install_igtk(sm, igtk, 1) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4046 | return -1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4047 | } else if (subelem_id == WNM_SLEEP_SUBELEM_BIGTK) { |
| 4048 | const struct wpa_bigtk_kde *bigtk; |
| 4049 | |
| 4050 | bigtk = (const struct wpa_bigtk_kde *) (buf + 2); |
| 4051 | if (sm->beacon_prot && |
| 4052 | wpa_supplicant_install_bigtk(sm, bigtk, 1) < 0) |
| 4053 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4054 | } else { |
| 4055 | wpa_printf(MSG_DEBUG, "Unknown element id"); |
| 4056 | return -1; |
| 4057 | } |
| 4058 | |
| 4059 | return 0; |
| 4060 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4061 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4062 | |
| 4063 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 4064 | #ifdef CONFIG_P2P |
| 4065 | |
| 4066 | int wpa_sm_get_p2p_ip_addr(struct wpa_sm *sm, u8 *buf) |
| 4067 | { |
| 4068 | if (sm == NULL || WPA_GET_BE32(sm->p2p_ip_addr) == 0) |
| 4069 | return -1; |
| 4070 | os_memcpy(buf, sm->p2p_ip_addr, 3 * 4); |
| 4071 | return 0; |
| 4072 | } |
| 4073 | |
| 4074 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4075 | |
| 4076 | |
| 4077 | void wpa_sm_set_rx_replay_ctr(struct wpa_sm *sm, const u8 *rx_replay_counter) |
| 4078 | { |
| 4079 | if (rx_replay_counter == NULL) |
| 4080 | return; |
| 4081 | |
| 4082 | os_memcpy(sm->rx_replay_counter, rx_replay_counter, |
| 4083 | WPA_REPLAY_COUNTER_LEN); |
| 4084 | sm->rx_replay_counter_set = 1; |
| 4085 | wpa_printf(MSG_DEBUG, "Updated key replay counter"); |
| 4086 | } |
| 4087 | |
| 4088 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4089 | void wpa_sm_set_ptk_kck_kek(struct wpa_sm *sm, |
| 4090 | const u8 *ptk_kck, size_t ptk_kck_len, |
| 4091 | const u8 *ptk_kek, size_t ptk_kek_len) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4092 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4093 | if (ptk_kck && ptk_kck_len <= WPA_KCK_MAX_LEN) { |
| 4094 | os_memcpy(sm->ptk.kck, ptk_kck, ptk_kck_len); |
| 4095 | sm->ptk.kck_len = ptk_kck_len; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4096 | wpa_printf(MSG_DEBUG, "Updated PTK KCK"); |
| 4097 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4098 | if (ptk_kek && ptk_kek_len <= WPA_KEK_MAX_LEN) { |
| 4099 | os_memcpy(sm->ptk.kek, ptk_kek, ptk_kek_len); |
| 4100 | sm->ptk.kek_len = ptk_kek_len; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4101 | wpa_printf(MSG_DEBUG, "Updated PTK KEK"); |
| 4102 | } |
| 4103 | sm->ptk_set = 1; |
| 4104 | } |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 4105 | |
| 4106 | |
| 4107 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4108 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 4109 | void wpa_sm_set_test_assoc_ie(struct wpa_sm *sm, struct wpabuf *buf) |
| 4110 | { |
| 4111 | wpabuf_free(sm->test_assoc_ie); |
| 4112 | sm->test_assoc_ie = buf; |
| 4113 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4114 | |
| 4115 | |
| 4116 | const u8 * wpa_sm_get_anonce(struct wpa_sm *sm) |
| 4117 | { |
| 4118 | return sm->anonce; |
| 4119 | } |
| 4120 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 4121 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4122 | |
| 4123 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4124 | unsigned int wpa_sm_get_key_mgmt(struct wpa_sm *sm) |
| 4125 | { |
| 4126 | return sm->key_mgmt; |
| 4127 | } |
| 4128 | |
| 4129 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4130 | #ifdef CONFIG_FILS |
| 4131 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4132 | struct wpabuf * fils_build_auth(struct wpa_sm *sm, int dh_group, const u8 *md) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4133 | { |
| 4134 | struct wpabuf *buf = NULL; |
| 4135 | struct wpabuf *erp_msg; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4136 | struct wpabuf *pub = NULL; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4137 | |
| 4138 | erp_msg = eapol_sm_build_erp_reauth_start(sm->eapol); |
| 4139 | if (!erp_msg && !sm->cur_pmksa) { |
| 4140 | wpa_printf(MSG_DEBUG, |
| 4141 | "FILS: Neither ERP EAP-Initiate/Re-auth nor PMKSA cache entry is available - skip FILS"); |
| 4142 | goto fail; |
| 4143 | } |
| 4144 | |
| 4145 | wpa_printf(MSG_DEBUG, "FILS: Try to use FILS (erp=%d pmksa_cache=%d)", |
| 4146 | erp_msg != NULL, sm->cur_pmksa != NULL); |
| 4147 | |
| 4148 | sm->fils_completed = 0; |
| 4149 | |
| 4150 | if (!sm->assoc_wpa_ie) { |
| 4151 | wpa_printf(MSG_INFO, "FILS: No own RSN IE set for FILS"); |
| 4152 | goto fail; |
| 4153 | } |
| 4154 | |
| 4155 | if (random_get_bytes(sm->fils_nonce, FILS_NONCE_LEN) < 0 || |
| 4156 | random_get_bytes(sm->fils_session, FILS_SESSION_LEN) < 0) |
| 4157 | goto fail; |
| 4158 | |
| 4159 | wpa_hexdump(MSG_DEBUG, "FILS: Generated FILS Nonce", |
| 4160 | sm->fils_nonce, FILS_NONCE_LEN); |
| 4161 | wpa_hexdump(MSG_DEBUG, "FILS: Generated FILS Session", |
| 4162 | sm->fils_session, FILS_SESSION_LEN); |
| 4163 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4164 | #ifdef CONFIG_FILS_SK_PFS |
| 4165 | sm->fils_dh_group = dh_group; |
| 4166 | if (dh_group) { |
| 4167 | crypto_ecdh_deinit(sm->fils_ecdh); |
| 4168 | sm->fils_ecdh = crypto_ecdh_init(dh_group); |
| 4169 | if (!sm->fils_ecdh) { |
| 4170 | wpa_printf(MSG_INFO, |
| 4171 | "FILS: Could not initialize ECDH with group %d", |
| 4172 | dh_group); |
| 4173 | goto fail; |
| 4174 | } |
| 4175 | pub = crypto_ecdh_get_pubkey(sm->fils_ecdh, 1); |
| 4176 | if (!pub) |
| 4177 | goto fail; |
| 4178 | wpa_hexdump_buf(MSG_DEBUG, "FILS: Element (DH public key)", |
| 4179 | pub); |
| 4180 | sm->fils_dh_elem_len = wpabuf_len(pub); |
| 4181 | } |
| 4182 | #endif /* CONFIG_FILS_SK_PFS */ |
| 4183 | |
| 4184 | buf = wpabuf_alloc(1000 + sm->assoc_wpa_ie_len + |
| 4185 | (pub ? wpabuf_len(pub) : 0)); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4186 | if (!buf) |
| 4187 | goto fail; |
| 4188 | |
| 4189 | /* Fields following the Authentication algorithm number field */ |
| 4190 | |
| 4191 | /* Authentication Transaction seq# */ |
| 4192 | wpabuf_put_le16(buf, 1); |
| 4193 | |
| 4194 | /* Status Code */ |
| 4195 | wpabuf_put_le16(buf, WLAN_STATUS_SUCCESS); |
| 4196 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4197 | /* TODO: FILS PK */ |
| 4198 | #ifdef CONFIG_FILS_SK_PFS |
| 4199 | if (dh_group) { |
| 4200 | /* Finite Cyclic Group */ |
| 4201 | wpabuf_put_le16(buf, dh_group); |
| 4202 | /* Element */ |
| 4203 | wpabuf_put_buf(buf, pub); |
| 4204 | } |
| 4205 | #endif /* CONFIG_FILS_SK_PFS */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4206 | |
| 4207 | /* RSNE */ |
| 4208 | wpa_hexdump(MSG_DEBUG, "FILS: RSNE in FILS Authentication frame", |
| 4209 | sm->assoc_wpa_ie, sm->assoc_wpa_ie_len); |
| 4210 | wpabuf_put_data(buf, sm->assoc_wpa_ie, sm->assoc_wpa_ie_len); |
| 4211 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4212 | if (md) { |
| 4213 | /* MDE when using FILS for FT initial association */ |
| 4214 | struct rsn_mdie *mdie; |
| 4215 | |
| 4216 | wpabuf_put_u8(buf, WLAN_EID_MOBILITY_DOMAIN); |
| 4217 | wpabuf_put_u8(buf, sizeof(*mdie)); |
| 4218 | mdie = wpabuf_put(buf, sizeof(*mdie)); |
| 4219 | os_memcpy(mdie->mobility_domain, md, MOBILITY_DOMAIN_ID_LEN); |
| 4220 | mdie->ft_capab = 0; |
| 4221 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4222 | |
| 4223 | /* FILS Nonce */ |
| 4224 | wpabuf_put_u8(buf, WLAN_EID_EXTENSION); /* Element ID */ |
| 4225 | wpabuf_put_u8(buf, 1 + FILS_NONCE_LEN); /* Length */ |
| 4226 | /* Element ID Extension */ |
| 4227 | wpabuf_put_u8(buf, WLAN_EID_EXT_FILS_NONCE); |
| 4228 | wpabuf_put_data(buf, sm->fils_nonce, FILS_NONCE_LEN); |
| 4229 | |
| 4230 | /* FILS Session */ |
| 4231 | wpabuf_put_u8(buf, WLAN_EID_EXTENSION); /* Element ID */ |
| 4232 | wpabuf_put_u8(buf, 1 + FILS_SESSION_LEN); /* Length */ |
| 4233 | /* Element ID Extension */ |
| 4234 | wpabuf_put_u8(buf, WLAN_EID_EXT_FILS_SESSION); |
| 4235 | wpabuf_put_data(buf, sm->fils_session, FILS_SESSION_LEN); |
| 4236 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4237 | /* Wrapped Data */ |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4238 | sm->fils_erp_pmkid_set = 0; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4239 | if (erp_msg) { |
| 4240 | wpabuf_put_u8(buf, WLAN_EID_EXTENSION); /* Element ID */ |
| 4241 | wpabuf_put_u8(buf, 1 + wpabuf_len(erp_msg)); /* Length */ |
| 4242 | /* Element ID Extension */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4243 | wpabuf_put_u8(buf, WLAN_EID_EXT_WRAPPED_DATA); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4244 | wpabuf_put_buf(buf, erp_msg); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4245 | /* Calculate pending PMKID here so that we do not need to |
| 4246 | * maintain a copy of the EAP-Initiate/Reauth message. */ |
| 4247 | if (fils_pmkid_erp(sm->key_mgmt, wpabuf_head(erp_msg), |
| 4248 | wpabuf_len(erp_msg), |
| 4249 | sm->fils_erp_pmkid) == 0) |
| 4250 | sm->fils_erp_pmkid_set = 1; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | wpa_hexdump_buf(MSG_DEBUG, "RSN: FILS fields for Authentication frame", |
| 4254 | buf); |
| 4255 | |
| 4256 | fail: |
| 4257 | wpabuf_free(erp_msg); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4258 | wpabuf_free(pub); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4259 | return buf; |
| 4260 | } |
| 4261 | |
| 4262 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4263 | int fils_process_auth(struct wpa_sm *sm, const u8 *bssid, const u8 *data, |
| 4264 | size_t len) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4265 | { |
| 4266 | const u8 *pos, *end; |
| 4267 | struct ieee802_11_elems elems; |
| 4268 | struct wpa_ie_data rsn; |
| 4269 | int pmkid_match = 0; |
| 4270 | u8 ick[FILS_ICK_MAX_LEN]; |
| 4271 | size_t ick_len; |
| 4272 | int res; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4273 | struct wpabuf *dh_ss = NULL; |
| 4274 | const u8 *g_sta = NULL; |
| 4275 | size_t g_sta_len = 0; |
| 4276 | const u8 *g_ap = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4277 | size_t g_ap_len = 0, kdk_len; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4278 | struct wpabuf *pub = NULL; |
| 4279 | |
| 4280 | os_memcpy(sm->bssid, bssid, ETH_ALEN); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4281 | |
| 4282 | wpa_hexdump(MSG_DEBUG, "FILS: Authentication frame fields", |
| 4283 | data, len); |
| 4284 | pos = data; |
| 4285 | end = data + len; |
| 4286 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4287 | /* TODO: FILS PK */ |
| 4288 | #ifdef CONFIG_FILS_SK_PFS |
| 4289 | if (sm->fils_dh_group) { |
| 4290 | u16 group; |
| 4291 | |
| 4292 | /* Using FILS PFS */ |
| 4293 | |
| 4294 | /* Finite Cyclic Group */ |
| 4295 | if (end - pos < 2) { |
| 4296 | wpa_printf(MSG_DEBUG, |
| 4297 | "FILS: No room for Finite Cyclic Group"); |
| 4298 | goto fail; |
| 4299 | } |
| 4300 | group = WPA_GET_LE16(pos); |
| 4301 | pos += 2; |
| 4302 | if (group != sm->fils_dh_group) { |
| 4303 | wpa_printf(MSG_DEBUG, |
| 4304 | "FILS: Unexpected change in Finite Cyclic Group: %u (expected %u)", |
| 4305 | group, sm->fils_dh_group); |
| 4306 | goto fail; |
| 4307 | } |
| 4308 | |
| 4309 | /* Element */ |
| 4310 | if ((size_t) (end - pos) < sm->fils_dh_elem_len) { |
| 4311 | wpa_printf(MSG_DEBUG, "FILS: No room for Element"); |
| 4312 | goto fail; |
| 4313 | } |
| 4314 | |
| 4315 | if (!sm->fils_ecdh) { |
| 4316 | wpa_printf(MSG_DEBUG, "FILS: No ECDH state available"); |
| 4317 | goto fail; |
| 4318 | } |
| 4319 | dh_ss = crypto_ecdh_set_peerkey(sm->fils_ecdh, 1, pos, |
| 4320 | sm->fils_dh_elem_len); |
| 4321 | if (!dh_ss) { |
| 4322 | wpa_printf(MSG_DEBUG, "FILS: ECDH operation failed"); |
| 4323 | goto fail; |
| 4324 | } |
| 4325 | wpa_hexdump_buf_key(MSG_DEBUG, "FILS: DH_SS", dh_ss); |
| 4326 | g_ap = pos; |
| 4327 | g_ap_len = sm->fils_dh_elem_len; |
| 4328 | pos += sm->fils_dh_elem_len; |
| 4329 | } |
| 4330 | #endif /* CONFIG_FILS_SK_PFS */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4331 | |
| 4332 | wpa_hexdump(MSG_DEBUG, "FILS: Remaining IEs", pos, end - pos); |
| 4333 | if (ieee802_11_parse_elems(pos, end - pos, &elems, 1) == ParseFailed) { |
| 4334 | wpa_printf(MSG_DEBUG, "FILS: Could not parse elements"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4335 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | /* RSNE */ |
| 4339 | wpa_hexdump(MSG_DEBUG, "FILS: RSN element", elems.rsn_ie, |
| 4340 | elems.rsn_ie_len); |
| 4341 | if (!elems.rsn_ie || |
| 4342 | wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2, |
| 4343 | &rsn) < 0) { |
| 4344 | wpa_printf(MSG_DEBUG, "FILS: No RSN element"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4345 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | if (!elems.fils_nonce) { |
| 4349 | wpa_printf(MSG_DEBUG, "FILS: No FILS Nonce field"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4350 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4351 | } |
| 4352 | os_memcpy(sm->fils_anonce, elems.fils_nonce, FILS_NONCE_LEN); |
| 4353 | wpa_hexdump(MSG_DEBUG, "FILS: ANonce", sm->fils_anonce, FILS_NONCE_LEN); |
| 4354 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4355 | #ifdef CONFIG_IEEE80211R |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4356 | if (wpa_key_mgmt_ft(sm->key_mgmt)) { |
| 4357 | struct wpa_ft_ies parse; |
| 4358 | |
| 4359 | if (!elems.mdie || !elems.ftie) { |
| 4360 | wpa_printf(MSG_DEBUG, "FILS+FT: No MDE or FTE"); |
| 4361 | goto fail; |
| 4362 | } |
| 4363 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4364 | if (wpa_ft_parse_ies(pos, end - pos, &parse, |
| 4365 | wpa_key_mgmt_sha384(sm->key_mgmt)) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4366 | wpa_printf(MSG_DEBUG, "FILS+FT: Failed to parse IEs"); |
| 4367 | goto fail; |
| 4368 | } |
| 4369 | |
| 4370 | if (!parse.r0kh_id) { |
| 4371 | wpa_printf(MSG_DEBUG, |
| 4372 | "FILS+FT: No R0KH-ID subelem in FTE"); |
| 4373 | goto fail; |
| 4374 | } |
| 4375 | os_memcpy(sm->r0kh_id, parse.r0kh_id, parse.r0kh_id_len); |
| 4376 | sm->r0kh_id_len = parse.r0kh_id_len; |
| 4377 | wpa_hexdump_ascii(MSG_DEBUG, "FILS+FT: R0KH-ID", |
| 4378 | sm->r0kh_id, sm->r0kh_id_len); |
| 4379 | |
| 4380 | if (!parse.r1kh_id) { |
| 4381 | wpa_printf(MSG_DEBUG, |
| 4382 | "FILS+FT: No R1KH-ID subelem in FTE"); |
| 4383 | goto fail; |
| 4384 | } |
| 4385 | os_memcpy(sm->r1kh_id, parse.r1kh_id, FT_R1KH_ID_LEN); |
| 4386 | wpa_hexdump(MSG_DEBUG, "FILS+FT: R1KH-ID", |
| 4387 | sm->r1kh_id, FT_R1KH_ID_LEN); |
| 4388 | |
| 4389 | /* TODO: Check MDE and FTE payload */ |
| 4390 | |
| 4391 | wpabuf_free(sm->fils_ft_ies); |
| 4392 | sm->fils_ft_ies = wpabuf_alloc(2 + elems.mdie_len + |
| 4393 | 2 + elems.ftie_len); |
| 4394 | if (!sm->fils_ft_ies) |
| 4395 | goto fail; |
| 4396 | wpabuf_put_data(sm->fils_ft_ies, elems.mdie - 2, |
| 4397 | 2 + elems.mdie_len); |
| 4398 | wpabuf_put_data(sm->fils_ft_ies, elems.ftie - 2, |
| 4399 | 2 + elems.ftie_len); |
| 4400 | } else { |
| 4401 | wpabuf_free(sm->fils_ft_ies); |
| 4402 | sm->fils_ft_ies = NULL; |
| 4403 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4404 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4405 | |
| 4406 | /* PMKID List */ |
| 4407 | if (rsn.pmkid && rsn.num_pmkid > 0) { |
| 4408 | wpa_hexdump(MSG_DEBUG, "FILS: PMKID List", |
| 4409 | rsn.pmkid, rsn.num_pmkid * PMKID_LEN); |
| 4410 | |
| 4411 | if (rsn.num_pmkid != 1) { |
| 4412 | wpa_printf(MSG_DEBUG, "FILS: Invalid PMKID selection"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4413 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4414 | } |
| 4415 | wpa_hexdump(MSG_DEBUG, "FILS: PMKID", rsn.pmkid, PMKID_LEN); |
| 4416 | if (os_memcmp(sm->cur_pmksa->pmkid, rsn.pmkid, PMKID_LEN) != 0) |
| 4417 | { |
| 4418 | wpa_printf(MSG_DEBUG, "FILS: PMKID mismatch"); |
| 4419 | wpa_hexdump(MSG_DEBUG, "FILS: Expected PMKID", |
| 4420 | sm->cur_pmksa->pmkid, PMKID_LEN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4421 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4422 | } |
| 4423 | wpa_printf(MSG_DEBUG, |
| 4424 | "FILS: Matching PMKID - continue using PMKSA caching"); |
| 4425 | pmkid_match = 1; |
| 4426 | } |
| 4427 | if (!pmkid_match && sm->cur_pmksa) { |
| 4428 | wpa_printf(MSG_DEBUG, |
| 4429 | "FILS: No PMKID match - cannot use cached PMKSA entry"); |
| 4430 | sm->cur_pmksa = NULL; |
| 4431 | } |
| 4432 | |
| 4433 | /* FILS Session */ |
| 4434 | if (!elems.fils_session) { |
| 4435 | wpa_printf(MSG_DEBUG, "FILS: No FILS Session element"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4436 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4437 | } |
| 4438 | wpa_hexdump(MSG_DEBUG, "FILS: FILS Session", elems.fils_session, |
| 4439 | FILS_SESSION_LEN); |
| 4440 | if (os_memcmp(sm->fils_session, elems.fils_session, FILS_SESSION_LEN) |
| 4441 | != 0) { |
| 4442 | wpa_printf(MSG_DEBUG, "FILS: Session mismatch"); |
| 4443 | wpa_hexdump(MSG_DEBUG, "FILS: Expected FILS Session", |
| 4444 | sm->fils_session, FILS_SESSION_LEN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4445 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4446 | } |
| 4447 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4448 | /* Wrapped Data */ |
| 4449 | if (!sm->cur_pmksa && elems.wrapped_data) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4450 | u8 rmsk[ERP_MAX_KEY_LEN]; |
| 4451 | size_t rmsk_len; |
| 4452 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4453 | wpa_hexdump(MSG_DEBUG, "FILS: Wrapped Data", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4454 | elems.wrapped_data, |
| 4455 | elems.wrapped_data_len); |
| 4456 | eapol_sm_process_erp_finish(sm->eapol, elems.wrapped_data, |
| 4457 | elems.wrapped_data_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4458 | if (eapol_sm_failed(sm->eapol)) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4459 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4460 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4461 | rmsk_len = ERP_MAX_KEY_LEN; |
| 4462 | res = eapol_sm_get_key(sm->eapol, rmsk, rmsk_len); |
| 4463 | if (res == PMK_LEN) { |
| 4464 | rmsk_len = PMK_LEN; |
| 4465 | res = eapol_sm_get_key(sm->eapol, rmsk, rmsk_len); |
| 4466 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4467 | if (res) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4468 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4469 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4470 | res = fils_rmsk_to_pmk(sm->key_mgmt, rmsk, rmsk_len, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4471 | sm->fils_nonce, sm->fils_anonce, |
| 4472 | dh_ss ? wpabuf_head(dh_ss) : NULL, |
| 4473 | dh_ss ? wpabuf_len(dh_ss) : 0, |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4474 | sm->pmk, &sm->pmk_len); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4475 | forced_memzero(rmsk, sizeof(rmsk)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4476 | |
| 4477 | /* Don't use DHss in PTK derivation if PMKSA caching is not |
| 4478 | * used. */ |
| 4479 | wpabuf_clear_free(dh_ss); |
| 4480 | dh_ss = NULL; |
| 4481 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4482 | if (res) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4483 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4484 | |
| 4485 | if (!sm->fils_erp_pmkid_set) { |
| 4486 | wpa_printf(MSG_DEBUG, "FILS: PMKID not available"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4487 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4488 | } |
| 4489 | wpa_hexdump(MSG_DEBUG, "FILS: PMKID", sm->fils_erp_pmkid, |
| 4490 | PMKID_LEN); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4491 | wpa_printf(MSG_DEBUG, "FILS: ERP processing succeeded - add PMKSA cache entry for the result"); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4492 | sm->cur_pmksa = pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len, |
| 4493 | sm->fils_erp_pmkid, NULL, 0, |
| 4494 | sm->bssid, sm->own_addr, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4495 | sm->network_ctx, sm->key_mgmt, |
| 4496 | NULL); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | if (!sm->cur_pmksa) { |
| 4500 | wpa_printf(MSG_DEBUG, |
| 4501 | "FILS: No remaining options to continue FILS authentication"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4502 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4503 | } |
| 4504 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4505 | if (sm->force_kdk_derivation || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4506 | (sm->secure_ltf && |
| 4507 | ieee802_11_rsnx_capab(sm->ap_rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF))) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4508 | kdk_len = WPA_KDK_MAX_LEN; |
| 4509 | else |
| 4510 | kdk_len = 0; |
| 4511 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4512 | if (fils_pmk_to_ptk(sm->pmk, sm->pmk_len, sm->own_addr, sm->bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4513 | sm->fils_nonce, sm->fils_anonce, |
| 4514 | dh_ss ? wpabuf_head(dh_ss) : NULL, |
| 4515 | dh_ss ? wpabuf_len(dh_ss) : 0, |
| 4516 | &sm->ptk, ick, &ick_len, |
| 4517 | sm->key_mgmt, sm->pairwise_cipher, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4518 | sm->fils_ft, &sm->fils_ft_len, |
| 4519 | kdk_len) < 0) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4520 | wpa_printf(MSG_DEBUG, "FILS: Failed to derive PTK"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4521 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4522 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4523 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 4524 | #ifdef CONFIG_PASN |
| 4525 | if (sm->secure_ltf && |
| 4526 | ieee802_11_rsnx_capab(sm->ap_rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF) && |
| 4527 | wpa_ltf_keyseed(&sm->ptk, sm->key_mgmt, sm->pairwise_cipher)) { |
| 4528 | wpa_printf(MSG_DEBUG, "FILS: Failed to derive LTF keyseed"); |
| 4529 | goto fail; |
| 4530 | } |
| 4531 | #endif /* CONFIG_PASN */ |
| 4532 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4533 | wpabuf_clear_free(dh_ss); |
| 4534 | dh_ss = NULL; |
| 4535 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4536 | sm->ptk_set = 1; |
| 4537 | sm->tptk_set = 0; |
| 4538 | os_memset(&sm->tptk, 0, sizeof(sm->tptk)); |
| 4539 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4540 | #ifdef CONFIG_FILS_SK_PFS |
| 4541 | if (sm->fils_dh_group) { |
| 4542 | if (!sm->fils_ecdh) { |
| 4543 | wpa_printf(MSG_INFO, "FILS: ECDH not initialized"); |
| 4544 | goto fail; |
| 4545 | } |
| 4546 | pub = crypto_ecdh_get_pubkey(sm->fils_ecdh, 1); |
| 4547 | if (!pub) |
| 4548 | goto fail; |
| 4549 | wpa_hexdump_buf(MSG_DEBUG, "FILS: gSTA", pub); |
| 4550 | g_sta = wpabuf_head(pub); |
| 4551 | g_sta_len = wpabuf_len(pub); |
| 4552 | if (!g_ap) { |
| 4553 | wpa_printf(MSG_INFO, "FILS: gAP not available"); |
| 4554 | goto fail; |
| 4555 | } |
| 4556 | wpa_hexdump(MSG_DEBUG, "FILS: gAP", g_ap, g_ap_len); |
| 4557 | } |
| 4558 | #endif /* CONFIG_FILS_SK_PFS */ |
| 4559 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4560 | res = fils_key_auth_sk(ick, ick_len, sm->fils_nonce, |
| 4561 | sm->fils_anonce, sm->own_addr, sm->bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4562 | g_sta, g_sta_len, g_ap, g_ap_len, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4563 | sm->key_mgmt, sm->fils_key_auth_sta, |
| 4564 | sm->fils_key_auth_ap, |
| 4565 | &sm->fils_key_auth_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4566 | wpabuf_free(pub); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4567 | forced_memzero(ick, sizeof(ick)); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4568 | return res; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4569 | fail: |
| 4570 | wpabuf_free(pub); |
| 4571 | wpabuf_clear_free(dh_ss); |
| 4572 | return -1; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4573 | } |
| 4574 | |
| 4575 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4576 | #ifdef CONFIG_IEEE80211R |
| 4577 | static int fils_ft_build_assoc_req_rsne(struct wpa_sm *sm, struct wpabuf *buf) |
| 4578 | { |
| 4579 | struct rsn_ie_hdr *rsnie; |
| 4580 | u16 capab; |
| 4581 | u8 *pos; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4582 | int use_sha384 = wpa_key_mgmt_sha384(sm->key_mgmt); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4583 | |
| 4584 | /* RSNIE[PMKR0Name/PMKR1Name] */ |
| 4585 | rsnie = wpabuf_put(buf, sizeof(*rsnie)); |
| 4586 | rsnie->elem_id = WLAN_EID_RSN; |
| 4587 | WPA_PUT_LE16(rsnie->version, RSN_VERSION); |
| 4588 | |
| 4589 | /* Group Suite Selector */ |
| 4590 | if (!wpa_cipher_valid_group(sm->group_cipher)) { |
| 4591 | wpa_printf(MSG_WARNING, "FT: Invalid group cipher (%d)", |
| 4592 | sm->group_cipher); |
| 4593 | return -1; |
| 4594 | } |
| 4595 | pos = wpabuf_put(buf, RSN_SELECTOR_LEN); |
| 4596 | RSN_SELECTOR_PUT(pos, wpa_cipher_to_suite(WPA_PROTO_RSN, |
| 4597 | sm->group_cipher)); |
| 4598 | |
| 4599 | /* Pairwise Suite Count */ |
| 4600 | wpabuf_put_le16(buf, 1); |
| 4601 | |
| 4602 | /* Pairwise Suite List */ |
| 4603 | if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) { |
| 4604 | wpa_printf(MSG_WARNING, "FT: Invalid pairwise cipher (%d)", |
| 4605 | sm->pairwise_cipher); |
| 4606 | return -1; |
| 4607 | } |
| 4608 | pos = wpabuf_put(buf, RSN_SELECTOR_LEN); |
| 4609 | RSN_SELECTOR_PUT(pos, wpa_cipher_to_suite(WPA_PROTO_RSN, |
| 4610 | sm->pairwise_cipher)); |
| 4611 | |
| 4612 | /* Authenticated Key Management Suite Count */ |
| 4613 | wpabuf_put_le16(buf, 1); |
| 4614 | |
| 4615 | /* Authenticated Key Management Suite List */ |
| 4616 | pos = wpabuf_put(buf, RSN_SELECTOR_LEN); |
| 4617 | if (sm->key_mgmt == WPA_KEY_MGMT_FT_FILS_SHA256) |
| 4618 | RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_FILS_SHA256); |
| 4619 | else if (sm->key_mgmt == WPA_KEY_MGMT_FT_FILS_SHA384) |
| 4620 | RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_FILS_SHA384); |
| 4621 | else { |
| 4622 | wpa_printf(MSG_WARNING, |
| 4623 | "FILS+FT: Invalid key management type (%d)", |
| 4624 | sm->key_mgmt); |
| 4625 | return -1; |
| 4626 | } |
| 4627 | |
| 4628 | /* RSN Capabilities */ |
| 4629 | capab = 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4630 | if (sm->mfp) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4631 | capab |= WPA_CAPABILITY_MFPC; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4632 | if (sm->mfp == 2) |
| 4633 | capab |= WPA_CAPABILITY_MFPR; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4634 | if (sm->ocv) |
| 4635 | capab |= WPA_CAPABILITY_OCVC; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4636 | if (sm->ext_key_id) |
| 4637 | capab |= WPA_CAPABILITY_EXT_KEY_ID_FOR_UNICAST; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4638 | wpabuf_put_le16(buf, capab); |
| 4639 | |
| 4640 | /* PMKID Count */ |
| 4641 | wpabuf_put_le16(buf, 1); |
| 4642 | |
| 4643 | /* PMKID List [PMKR1Name] */ |
| 4644 | wpa_hexdump_key(MSG_DEBUG, "FILS+FT: XXKey (FILS-FT)", |
| 4645 | sm->fils_ft, sm->fils_ft_len); |
| 4646 | wpa_hexdump_ascii(MSG_DEBUG, "FILS+FT: SSID", sm->ssid, sm->ssid_len); |
| 4647 | wpa_hexdump(MSG_DEBUG, "FILS+FT: MDID", |
| 4648 | sm->mobility_domain, MOBILITY_DOMAIN_ID_LEN); |
| 4649 | wpa_hexdump_ascii(MSG_DEBUG, "FILS+FT: R0KH-ID", |
| 4650 | sm->r0kh_id, sm->r0kh_id_len); |
| 4651 | if (wpa_derive_pmk_r0(sm->fils_ft, sm->fils_ft_len, sm->ssid, |
| 4652 | sm->ssid_len, sm->mobility_domain, |
| 4653 | sm->r0kh_id, sm->r0kh_id_len, sm->own_addr, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4654 | sm->pmk_r0, sm->pmk_r0_name, use_sha384) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4655 | wpa_printf(MSG_WARNING, "FILS+FT: Could not derive PMK-R0"); |
| 4656 | return -1; |
| 4657 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4658 | sm->pmk_r0_len = use_sha384 ? SHA384_MAC_LEN : PMK_LEN; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4659 | wpa_printf(MSG_DEBUG, "FILS+FT: R1KH-ID: " MACSTR, |
| 4660 | MAC2STR(sm->r1kh_id)); |
| 4661 | pos = wpabuf_put(buf, WPA_PMK_NAME_LEN); |
| 4662 | if (wpa_derive_pmk_r1_name(sm->pmk_r0_name, sm->r1kh_id, sm->own_addr, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4663 | sm->pmk_r1_name, use_sha384) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4664 | wpa_printf(MSG_WARNING, "FILS+FT: Could not derive PMKR1Name"); |
| 4665 | return -1; |
| 4666 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4667 | os_memcpy(pos, sm->pmk_r1_name, WPA_PMK_NAME_LEN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4668 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4669 | if (sm->mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC) { |
| 4670 | /* Management Group Cipher Suite */ |
| 4671 | pos = wpabuf_put(buf, RSN_SELECTOR_LEN); |
| 4672 | RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC); |
| 4673 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4674 | |
| 4675 | rsnie->len = ((u8 *) wpabuf_put(buf, 0) - (u8 *) rsnie) - 2; |
| 4676 | return 0; |
| 4677 | } |
| 4678 | #endif /* CONFIG_IEEE80211R */ |
| 4679 | |
| 4680 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4681 | struct wpabuf * fils_build_assoc_req(struct wpa_sm *sm, const u8 **kek, |
| 4682 | size_t *kek_len, const u8 **snonce, |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4683 | const u8 **anonce, |
| 4684 | const struct wpabuf **hlp, |
| 4685 | unsigned int num_hlp) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4686 | { |
| 4687 | struct wpabuf *buf; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4688 | size_t len; |
| 4689 | unsigned int i; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4690 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4691 | len = 1000; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4692 | #ifdef CONFIG_IEEE80211R |
| 4693 | if (sm->fils_ft_ies) |
| 4694 | len += wpabuf_len(sm->fils_ft_ies); |
| 4695 | if (wpa_key_mgmt_ft(sm->key_mgmt)) |
| 4696 | len += 256; |
| 4697 | #endif /* CONFIG_IEEE80211R */ |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4698 | for (i = 0; hlp && i < num_hlp; i++) |
| 4699 | len += 10 + wpabuf_len(hlp[i]); |
| 4700 | buf = wpabuf_alloc(len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4701 | if (!buf) |
| 4702 | return NULL; |
| 4703 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4704 | #ifdef CONFIG_IEEE80211R |
| 4705 | if (wpa_key_mgmt_ft(sm->key_mgmt) && sm->fils_ft_ies) { |
| 4706 | /* MDE and FTE when using FILS+FT */ |
| 4707 | wpabuf_put_buf(buf, sm->fils_ft_ies); |
| 4708 | /* RSNE with PMKR1Name in PMKID field */ |
| 4709 | if (fils_ft_build_assoc_req_rsne(sm, buf) < 0) { |
| 4710 | wpabuf_free(buf); |
| 4711 | return NULL; |
| 4712 | } |
| 4713 | } |
| 4714 | #endif /* CONFIG_IEEE80211R */ |
| 4715 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4716 | /* FILS Session */ |
| 4717 | wpabuf_put_u8(buf, WLAN_EID_EXTENSION); /* Element ID */ |
| 4718 | wpabuf_put_u8(buf, 1 + FILS_SESSION_LEN); /* Length */ |
| 4719 | /* Element ID Extension */ |
| 4720 | wpabuf_put_u8(buf, WLAN_EID_EXT_FILS_SESSION); |
| 4721 | wpabuf_put_data(buf, sm->fils_session, FILS_SESSION_LEN); |
| 4722 | |
| 4723 | /* Everything after FILS Session element gets encrypted in the driver |
| 4724 | * with KEK. The buffer returned from here is the plaintext version. */ |
| 4725 | |
| 4726 | /* TODO: FILS Public Key */ |
| 4727 | |
| 4728 | /* FILS Key Confirm */ |
| 4729 | wpabuf_put_u8(buf, WLAN_EID_EXTENSION); /* Element ID */ |
| 4730 | wpabuf_put_u8(buf, 1 + sm->fils_key_auth_len); /* Length */ |
| 4731 | /* Element ID Extension */ |
| 4732 | wpabuf_put_u8(buf, WLAN_EID_EXT_FILS_KEY_CONFIRM); |
| 4733 | wpabuf_put_data(buf, sm->fils_key_auth_sta, sm->fils_key_auth_len); |
| 4734 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4735 | /* FILS HLP Container */ |
| 4736 | for (i = 0; hlp && i < num_hlp; i++) { |
| 4737 | const u8 *pos = wpabuf_head(hlp[i]); |
| 4738 | size_t left = wpabuf_len(hlp[i]); |
| 4739 | |
| 4740 | wpabuf_put_u8(buf, WLAN_EID_EXTENSION); /* Element ID */ |
| 4741 | if (left <= 254) |
| 4742 | len = 1 + left; |
| 4743 | else |
| 4744 | len = 255; |
| 4745 | wpabuf_put_u8(buf, len); /* Length */ |
| 4746 | /* Element ID Extension */ |
| 4747 | wpabuf_put_u8(buf, WLAN_EID_EXT_FILS_HLP_CONTAINER); |
| 4748 | /* Destination MAC Address, Source MAC Address, HLP Packet. |
| 4749 | * HLP Packet is in MSDU format (i.e., included the LLC/SNAP |
| 4750 | * header when LPD is used). */ |
| 4751 | wpabuf_put_data(buf, pos, len - 1); |
| 4752 | pos += len - 1; |
| 4753 | left -= len - 1; |
| 4754 | while (left) { |
| 4755 | wpabuf_put_u8(buf, WLAN_EID_FRAGMENT); |
| 4756 | len = left > 255 ? 255 : left; |
| 4757 | wpabuf_put_u8(buf, len); |
| 4758 | wpabuf_put_data(buf, pos, len); |
| 4759 | pos += len; |
| 4760 | left -= len; |
| 4761 | } |
| 4762 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4763 | |
| 4764 | /* TODO: FILS IP Address Assignment */ |
| 4765 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4766 | #ifdef CONFIG_OCV |
| 4767 | if (wpa_sm_ocv_enabled(sm)) { |
| 4768 | struct wpa_channel_info ci; |
| 4769 | u8 *pos; |
| 4770 | |
| 4771 | if (wpa_sm_channel_info(sm, &ci) != 0) { |
| 4772 | wpa_printf(MSG_WARNING, |
| 4773 | "FILS: Failed to get channel info for OCI element"); |
| 4774 | wpabuf_free(buf); |
| 4775 | return NULL; |
| 4776 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4777 | #ifdef CONFIG_TESTING_OPTIONS |
| 4778 | if (sm->oci_freq_override_fils_assoc) { |
| 4779 | wpa_printf(MSG_INFO, |
| 4780 | "TEST: Override OCI KDE frequency %d -> %d MHz", |
| 4781 | ci.frequency, |
| 4782 | sm->oci_freq_override_fils_assoc); |
| 4783 | ci.frequency = sm->oci_freq_override_fils_assoc; |
| 4784 | } |
| 4785 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4786 | |
| 4787 | pos = wpabuf_put(buf, OCV_OCI_EXTENDED_LEN); |
| 4788 | if (ocv_insert_extended_oci(&ci, pos) < 0) { |
| 4789 | wpabuf_free(buf); |
| 4790 | return NULL; |
| 4791 | } |
| 4792 | } |
| 4793 | #endif /* CONFIG_OCV */ |
| 4794 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4795 | wpa_hexdump_buf(MSG_DEBUG, "FILS: Association Request plaintext", buf); |
| 4796 | |
| 4797 | *kek = sm->ptk.kek; |
| 4798 | *kek_len = sm->ptk.kek_len; |
| 4799 | wpa_hexdump_key(MSG_DEBUG, "FILS: KEK for AEAD", *kek, *kek_len); |
| 4800 | *snonce = sm->fils_nonce; |
| 4801 | wpa_hexdump(MSG_DEBUG, "FILS: SNonce for AEAD AAD", |
| 4802 | *snonce, FILS_NONCE_LEN); |
| 4803 | *anonce = sm->fils_anonce; |
| 4804 | wpa_hexdump(MSG_DEBUG, "FILS: ANonce for AEAD AAD", |
| 4805 | *anonce, FILS_NONCE_LEN); |
| 4806 | |
| 4807 | return buf; |
| 4808 | } |
| 4809 | |
| 4810 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4811 | static void fils_process_hlp_resp(struct wpa_sm *sm, const u8 *resp, size_t len) |
| 4812 | { |
| 4813 | const u8 *pos, *end; |
| 4814 | |
| 4815 | wpa_hexdump(MSG_MSGDUMP, "FILS: HLP response", resp, len); |
| 4816 | if (len < 2 * ETH_ALEN) |
| 4817 | return; |
| 4818 | pos = resp + 2 * ETH_ALEN; |
| 4819 | end = resp + len; |
| 4820 | if (end - pos >= 6 && |
| 4821 | os_memcmp(pos, "\xaa\xaa\x03\x00\x00\x00", 6) == 0) |
| 4822 | pos += 6; /* Remove SNAP/LLC header */ |
| 4823 | wpa_sm_fils_hlp_rx(sm, resp, resp + ETH_ALEN, pos, end - pos); |
| 4824 | } |
| 4825 | |
| 4826 | |
| 4827 | static void fils_process_hlp_container(struct wpa_sm *sm, const u8 *pos, |
| 4828 | size_t len) |
| 4829 | { |
| 4830 | const u8 *end = pos + len; |
| 4831 | u8 *tmp, *tmp_pos; |
| 4832 | |
| 4833 | /* Check if there are any FILS HLP Container elements */ |
| 4834 | while (end - pos >= 2) { |
| 4835 | if (2 + pos[1] > end - pos) |
| 4836 | return; |
| 4837 | if (pos[0] == WLAN_EID_EXTENSION && |
| 4838 | pos[1] >= 1 + 2 * ETH_ALEN && |
| 4839 | pos[2] == WLAN_EID_EXT_FILS_HLP_CONTAINER) |
| 4840 | break; |
| 4841 | pos += 2 + pos[1]; |
| 4842 | } |
| 4843 | if (end - pos < 2) |
| 4844 | return; /* No FILS HLP Container elements */ |
| 4845 | |
| 4846 | tmp = os_malloc(end - pos); |
| 4847 | if (!tmp) |
| 4848 | return; |
| 4849 | |
| 4850 | while (end - pos >= 2) { |
| 4851 | if (2 + pos[1] > end - pos || |
| 4852 | pos[0] != WLAN_EID_EXTENSION || |
| 4853 | pos[1] < 1 + 2 * ETH_ALEN || |
| 4854 | pos[2] != WLAN_EID_EXT_FILS_HLP_CONTAINER) |
| 4855 | break; |
| 4856 | tmp_pos = tmp; |
| 4857 | os_memcpy(tmp_pos, pos + 3, pos[1] - 1); |
| 4858 | tmp_pos += pos[1] - 1; |
| 4859 | pos += 2 + pos[1]; |
| 4860 | |
| 4861 | /* Add possible fragments */ |
| 4862 | while (end - pos >= 2 && pos[0] == WLAN_EID_FRAGMENT && |
| 4863 | 2 + pos[1] <= end - pos) { |
| 4864 | os_memcpy(tmp_pos, pos + 2, pos[1]); |
| 4865 | tmp_pos += pos[1]; |
| 4866 | pos += 2 + pos[1]; |
| 4867 | } |
| 4868 | |
| 4869 | fils_process_hlp_resp(sm, tmp, tmp_pos - tmp); |
| 4870 | } |
| 4871 | |
| 4872 | os_free(tmp); |
| 4873 | } |
| 4874 | |
| 4875 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4876 | int fils_process_assoc_resp(struct wpa_sm *sm, const u8 *resp, size_t len) |
| 4877 | { |
| 4878 | const struct ieee80211_mgmt *mgmt; |
| 4879 | const u8 *end, *ie_start; |
| 4880 | struct ieee802_11_elems elems; |
| 4881 | int keylen, rsclen; |
| 4882 | enum wpa_alg alg; |
| 4883 | struct wpa_gtk_data gd; |
| 4884 | int maxkeylen; |
| 4885 | struct wpa_eapol_ie_parse kde; |
| 4886 | |
| 4887 | if (!sm || !sm->ptk_set) { |
| 4888 | wpa_printf(MSG_DEBUG, "FILS: No KEK available"); |
| 4889 | return -1; |
| 4890 | } |
| 4891 | |
| 4892 | if (!wpa_key_mgmt_fils(sm->key_mgmt)) { |
| 4893 | wpa_printf(MSG_DEBUG, "FILS: Not a FILS AKM"); |
| 4894 | return -1; |
| 4895 | } |
| 4896 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4897 | if (sm->fils_completed) { |
| 4898 | wpa_printf(MSG_DEBUG, |
| 4899 | "FILS: Association has already been completed for this FILS authentication - ignore unexpected retransmission"); |
| 4900 | return -1; |
| 4901 | } |
| 4902 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4903 | wpa_hexdump(MSG_DEBUG, "FILS: (Re)Association Response frame", |
| 4904 | resp, len); |
| 4905 | |
| 4906 | mgmt = (const struct ieee80211_mgmt *) resp; |
| 4907 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_resp)) |
| 4908 | return -1; |
| 4909 | |
| 4910 | end = resp + len; |
| 4911 | /* Same offset for Association Response and Reassociation Response */ |
| 4912 | ie_start = mgmt->u.assoc_resp.variable; |
| 4913 | |
| 4914 | if (ieee802_11_parse_elems(ie_start, end - ie_start, &elems, 1) == |
| 4915 | ParseFailed) { |
| 4916 | wpa_printf(MSG_DEBUG, |
| 4917 | "FILS: Failed to parse decrypted elements"); |
| 4918 | goto fail; |
| 4919 | } |
| 4920 | |
| 4921 | if (!elems.fils_session) { |
| 4922 | wpa_printf(MSG_DEBUG, "FILS: No FILS Session element"); |
| 4923 | return -1; |
| 4924 | } |
| 4925 | if (os_memcmp(elems.fils_session, sm->fils_session, |
| 4926 | FILS_SESSION_LEN) != 0) { |
| 4927 | wpa_printf(MSG_DEBUG, "FILS: FILS Session mismatch"); |
| 4928 | wpa_hexdump(MSG_DEBUG, "FILS: Received FILS Session", |
| 4929 | elems.fils_session, FILS_SESSION_LEN); |
| 4930 | wpa_hexdump(MSG_DEBUG, "FILS: Expected FILS Session", |
| 4931 | sm->fils_session, FILS_SESSION_LEN); |
| 4932 | } |
| 4933 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4934 | if (!elems.rsn_ie) { |
| 4935 | wpa_printf(MSG_DEBUG, |
| 4936 | "FILS: No RSNE in (Re)Association Response"); |
| 4937 | /* As an interop workaround, allow this for now since IEEE Std |
| 4938 | * 802.11ai-2016 did not include all the needed changes to make |
| 4939 | * a FILS AP include RSNE in the frame. This workaround might |
| 4940 | * eventually be removed and replaced with rejection (goto fail) |
| 4941 | * to follow a strict interpretation of the standard. */ |
| 4942 | } else if (wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm->key_mgmt), |
| 4943 | sm->ap_rsn_ie, sm->ap_rsn_ie_len, |
| 4944 | elems.rsn_ie - 2, elems.rsn_ie_len + 2)) { |
| 4945 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, |
| 4946 | "FILS: RSNE mismatch between Beacon/Probe Response and (Re)Association Response"); |
| 4947 | wpa_hexdump(MSG_DEBUG, "FILS: RSNE in Beacon/Probe Response", |
| 4948 | sm->ap_rsn_ie, sm->ap_rsn_ie_len); |
| 4949 | wpa_hexdump(MSG_DEBUG, "FILS: RSNE in (Re)Association Response", |
| 4950 | elems.rsn_ie, elems.rsn_ie_len); |
| 4951 | goto fail; |
| 4952 | } |
| 4953 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4954 | /* TODO: FILS Public Key */ |
| 4955 | |
| 4956 | if (!elems.fils_key_confirm) { |
| 4957 | wpa_printf(MSG_DEBUG, "FILS: No FILS Key Confirm element"); |
| 4958 | goto fail; |
| 4959 | } |
| 4960 | if (elems.fils_key_confirm_len != sm->fils_key_auth_len) { |
| 4961 | wpa_printf(MSG_DEBUG, |
| 4962 | "FILS: Unexpected Key-Auth length %d (expected %d)", |
| 4963 | elems.fils_key_confirm_len, |
| 4964 | (int) sm->fils_key_auth_len); |
| 4965 | goto fail; |
| 4966 | } |
| 4967 | if (os_memcmp(elems.fils_key_confirm, sm->fils_key_auth_ap, |
| 4968 | sm->fils_key_auth_len) != 0) { |
| 4969 | wpa_printf(MSG_DEBUG, "FILS: Key-Auth mismatch"); |
| 4970 | wpa_hexdump(MSG_DEBUG, "FILS: Received Key-Auth", |
| 4971 | elems.fils_key_confirm, |
| 4972 | elems.fils_key_confirm_len); |
| 4973 | wpa_hexdump(MSG_DEBUG, "FILS: Expected Key-Auth", |
| 4974 | sm->fils_key_auth_ap, sm->fils_key_auth_len); |
| 4975 | goto fail; |
| 4976 | } |
| 4977 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4978 | #ifdef CONFIG_OCV |
| 4979 | if (wpa_sm_ocv_enabled(sm)) { |
| 4980 | struct wpa_channel_info ci; |
| 4981 | |
| 4982 | if (wpa_sm_channel_info(sm, &ci) != 0) { |
| 4983 | wpa_printf(MSG_WARNING, |
| 4984 | "Failed to get channel info to validate received OCI in FILS (Re)Association Response frame"); |
| 4985 | goto fail; |
| 4986 | } |
| 4987 | |
| 4988 | if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci, |
| 4989 | channel_width_to_int(ci.chanwidth), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4990 | ci.seg1_idx) != OCI_SUCCESS) { |
| 4991 | wpa_msg(sm->ctx->msg_ctx, MSG_INFO, OCV_FAILURE |
| 4992 | "addr=" MACSTR " frame=fils-assoc error=%s", |
| 4993 | MAC2STR(sm->bssid), ocv_errorstr); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4994 | goto fail; |
| 4995 | } |
| 4996 | } |
| 4997 | #endif /* CONFIG_OCV */ |
| 4998 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4999 | #ifdef CONFIG_IEEE80211R |
| 5000 | if (wpa_key_mgmt_ft(sm->key_mgmt) && sm->fils_ft_ies) { |
| 5001 | struct wpa_ie_data rsn; |
| 5002 | |
| 5003 | /* Check that PMKR1Name derived by the AP matches */ |
| 5004 | if (!elems.rsn_ie || |
| 5005 | wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2, |
| 5006 | &rsn) < 0 || |
| 5007 | !rsn.pmkid || rsn.num_pmkid != 1 || |
| 5008 | os_memcmp(rsn.pmkid, sm->pmk_r1_name, |
| 5009 | WPA_PMK_NAME_LEN) != 0) { |
| 5010 | wpa_printf(MSG_DEBUG, |
| 5011 | "FILS+FT: No RSNE[PMKR1Name] match in AssocResp"); |
| 5012 | goto fail; |
| 5013 | } |
| 5014 | } |
| 5015 | #endif /* CONFIG_IEEE80211R */ |
| 5016 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5017 | /* Key Delivery */ |
| 5018 | if (!elems.key_delivery) { |
| 5019 | wpa_printf(MSG_DEBUG, "FILS: No Key Delivery element"); |
| 5020 | goto fail; |
| 5021 | } |
| 5022 | |
| 5023 | /* Parse GTK and set the key to the driver */ |
| 5024 | os_memset(&gd, 0, sizeof(gd)); |
| 5025 | if (wpa_supplicant_parse_ies(elems.key_delivery + WPA_KEY_RSC_LEN, |
| 5026 | elems.key_delivery_len - WPA_KEY_RSC_LEN, |
| 5027 | &kde) < 0) { |
| 5028 | wpa_printf(MSG_DEBUG, "FILS: Failed to parse KDEs"); |
| 5029 | goto fail; |
| 5030 | } |
| 5031 | if (!kde.gtk) { |
| 5032 | wpa_printf(MSG_DEBUG, "FILS: No GTK KDE"); |
| 5033 | goto fail; |
| 5034 | } |
| 5035 | maxkeylen = gd.gtk_len = kde.gtk_len - 2; |
| 5036 | if (wpa_supplicant_check_group_cipher(sm, sm->group_cipher, |
| 5037 | gd.gtk_len, maxkeylen, |
| 5038 | &gd.key_rsc_len, &gd.alg)) |
| 5039 | goto fail; |
| 5040 | |
| 5041 | wpa_hexdump_key(MSG_DEBUG, "FILS: Received GTK", kde.gtk, kde.gtk_len); |
| 5042 | gd.keyidx = kde.gtk[0] & 0x3; |
| 5043 | gd.tx = wpa_supplicant_gtk_tx_bit_workaround(sm, |
| 5044 | !!(kde.gtk[0] & BIT(2))); |
| 5045 | if (kde.gtk_len - 2 > sizeof(gd.gtk)) { |
| 5046 | wpa_printf(MSG_DEBUG, "FILS: Too long GTK in GTK KDE (len=%lu)", |
| 5047 | (unsigned long) kde.gtk_len - 2); |
| 5048 | goto fail; |
| 5049 | } |
| 5050 | os_memcpy(gd.gtk, kde.gtk + 2, kde.gtk_len - 2); |
| 5051 | |
| 5052 | wpa_printf(MSG_DEBUG, "FILS: Set GTK to driver"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5053 | if (wpa_supplicant_install_gtk(sm, &gd, elems.key_delivery, 0) < 0) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5054 | wpa_printf(MSG_DEBUG, "FILS: Failed to set GTK"); |
| 5055 | goto fail; |
| 5056 | } |
| 5057 | |
| 5058 | if (ieee80211w_set_keys(sm, &kde) < 0) { |
| 5059 | wpa_printf(MSG_DEBUG, "FILS: Failed to set IGTK"); |
| 5060 | goto fail; |
| 5061 | } |
| 5062 | |
| 5063 | alg = wpa_cipher_to_alg(sm->pairwise_cipher); |
| 5064 | keylen = wpa_cipher_key_len(sm->pairwise_cipher); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5065 | if (keylen <= 0 || (unsigned int) keylen != sm->ptk.tk_len) { |
| 5066 | wpa_printf(MSG_DEBUG, "FILS: TK length mismatch: %u != %lu", |
| 5067 | keylen, (long unsigned int) sm->ptk.tk_len); |
| 5068 | goto fail; |
| 5069 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5070 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5071 | rsclen = wpa_cipher_rsc_len(sm->pairwise_cipher); |
| 5072 | wpa_hexdump_key(MSG_DEBUG, "FILS: Set TK to driver", |
| 5073 | sm->ptk.tk, keylen); |
| 5074 | if (wpa_sm_set_key(sm, alg, sm->bssid, 0, 1, null_rsc, rsclen, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5075 | sm->ptk.tk, keylen, KEY_FLAG_PAIRWISE_RX_TX) < 0) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5076 | wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, |
| 5077 | "FILS: Failed to set PTK to the driver (alg=%d keylen=%d bssid=" |
| 5078 | MACSTR ")", |
| 5079 | alg, keylen, MAC2STR(sm->bssid)); |
| 5080 | goto fail; |
| 5081 | } |
| 5082 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5083 | wpa_sm_store_ptk(sm, sm->bssid, sm->pairwise_cipher, |
| 5084 | sm->dot11RSNAConfigPMKLifetime, &sm->ptk); |
| 5085 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5086 | /* TODO: TK could be cleared after auth frame exchange now that driver |
| 5087 | * takes care of association frame encryption/decryption. */ |
| 5088 | /* TK is not needed anymore in supplicant */ |
| 5089 | os_memset(sm->ptk.tk, 0, WPA_TK_MAX_LEN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5090 | sm->ptk.tk_len = 0; |
Mathy Vanhoef | c66556c | 2017-09-29 04:22:51 +0200 | [diff] [blame] | 5091 | sm->ptk.installed = 1; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5092 | sm->tk_set = true; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5093 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5094 | /* FILS HLP Container */ |
| 5095 | fils_process_hlp_container(sm, ie_start, end - ie_start); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5096 | |
| 5097 | /* TODO: FILS IP Address Assignment */ |
| 5098 | |
| 5099 | wpa_printf(MSG_DEBUG, "FILS: Auth+Assoc completed successfully"); |
| 5100 | sm->fils_completed = 1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5101 | forced_memzero(&gd, sizeof(gd)); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5102 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5103 | if (kde.transition_disable) |
| 5104 | wpa_sm_transition_disable(sm, kde.transition_disable[0]); |
| 5105 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5106 | return 0; |
| 5107 | fail: |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5108 | forced_memzero(&gd, sizeof(gd)); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5109 | return -1; |
| 5110 | } |
| 5111 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5112 | |
| 5113 | void wpa_sm_set_reset_fils_completed(struct wpa_sm *sm, int set) |
| 5114 | { |
| 5115 | if (sm) |
| 5116 | sm->fils_completed = !!set; |
| 5117 | } |
| 5118 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5119 | #endif /* CONFIG_FILS */ |
| 5120 | |
| 5121 | |
| 5122 | int wpa_fils_is_completed(struct wpa_sm *sm) |
| 5123 | { |
| 5124 | #ifdef CONFIG_FILS |
| 5125 | return sm && sm->fils_completed; |
| 5126 | #else /* CONFIG_FILS */ |
| 5127 | return 0; |
| 5128 | #endif /* CONFIG_FILS */ |
| 5129 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5130 | |
| 5131 | |
| 5132 | #ifdef CONFIG_OWE |
| 5133 | |
| 5134 | struct wpabuf * owe_build_assoc_req(struct wpa_sm *sm, u16 group) |
| 5135 | { |
| 5136 | struct wpabuf *ie = NULL, *pub = NULL; |
| 5137 | size_t prime_len; |
| 5138 | |
| 5139 | if (group == 19) |
| 5140 | prime_len = 32; |
| 5141 | else if (group == 20) |
| 5142 | prime_len = 48; |
| 5143 | else if (group == 21) |
| 5144 | prime_len = 66; |
| 5145 | else |
| 5146 | return NULL; |
| 5147 | |
| 5148 | crypto_ecdh_deinit(sm->owe_ecdh); |
| 5149 | sm->owe_ecdh = crypto_ecdh_init(group); |
| 5150 | if (!sm->owe_ecdh) |
| 5151 | goto fail; |
| 5152 | sm->owe_group = group; |
| 5153 | pub = crypto_ecdh_get_pubkey(sm->owe_ecdh, 0); |
| 5154 | pub = wpabuf_zeropad(pub, prime_len); |
| 5155 | if (!pub) |
| 5156 | goto fail; |
| 5157 | |
| 5158 | ie = wpabuf_alloc(5 + wpabuf_len(pub)); |
| 5159 | if (!ie) |
| 5160 | goto fail; |
| 5161 | wpabuf_put_u8(ie, WLAN_EID_EXTENSION); |
| 5162 | wpabuf_put_u8(ie, 1 + 2 + wpabuf_len(pub)); |
| 5163 | wpabuf_put_u8(ie, WLAN_EID_EXT_OWE_DH_PARAM); |
| 5164 | wpabuf_put_le16(ie, group); |
| 5165 | wpabuf_put_buf(ie, pub); |
| 5166 | wpabuf_free(pub); |
| 5167 | wpa_hexdump_buf(MSG_DEBUG, "OWE: Diffie-Hellman Parameter element", |
| 5168 | ie); |
| 5169 | |
| 5170 | return ie; |
| 5171 | fail: |
| 5172 | wpabuf_free(pub); |
| 5173 | crypto_ecdh_deinit(sm->owe_ecdh); |
| 5174 | sm->owe_ecdh = NULL; |
| 5175 | return NULL; |
| 5176 | } |
| 5177 | |
| 5178 | |
| 5179 | int owe_process_assoc_resp(struct wpa_sm *sm, const u8 *bssid, |
| 5180 | const u8 *resp_ies, size_t resp_ies_len) |
| 5181 | { |
| 5182 | struct ieee802_11_elems elems; |
| 5183 | u16 group; |
| 5184 | struct wpabuf *secret, *pub, *hkey; |
| 5185 | int res; |
| 5186 | u8 prk[SHA512_MAC_LEN], pmkid[SHA512_MAC_LEN]; |
| 5187 | const char *info = "OWE Key Generation"; |
| 5188 | const u8 *addr[2]; |
| 5189 | size_t len[2]; |
| 5190 | size_t hash_len, prime_len; |
| 5191 | struct wpa_ie_data data; |
| 5192 | |
| 5193 | if (!resp_ies || |
| 5194 | ieee802_11_parse_elems(resp_ies, resp_ies_len, &elems, 1) == |
| 5195 | ParseFailed) { |
| 5196 | wpa_printf(MSG_INFO, |
| 5197 | "OWE: Could not parse Association Response frame elements"); |
| 5198 | return -1; |
| 5199 | } |
| 5200 | |
| 5201 | if (sm->cur_pmksa && elems.rsn_ie && |
| 5202 | wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, 2 + elems.rsn_ie_len, |
| 5203 | &data) == 0 && |
| 5204 | data.num_pmkid == 1 && data.pmkid && |
| 5205 | os_memcmp(sm->cur_pmksa->pmkid, data.pmkid, PMKID_LEN) == 0) { |
| 5206 | wpa_printf(MSG_DEBUG, "OWE: Use PMKSA caching"); |
| 5207 | wpa_sm_set_pmk_from_pmksa(sm); |
| 5208 | return 0; |
| 5209 | } |
| 5210 | |
| 5211 | if (!elems.owe_dh) { |
| 5212 | wpa_printf(MSG_INFO, |
| 5213 | "OWE: No Diffie-Hellman Parameter element found in Association Response frame"); |
| 5214 | return -1; |
| 5215 | } |
| 5216 | |
| 5217 | group = WPA_GET_LE16(elems.owe_dh); |
| 5218 | if (group != sm->owe_group) { |
| 5219 | wpa_printf(MSG_INFO, |
| 5220 | "OWE: Unexpected Diffie-Hellman group in response: %u", |
| 5221 | group); |
| 5222 | return -1; |
| 5223 | } |
| 5224 | |
| 5225 | if (!sm->owe_ecdh) { |
| 5226 | wpa_printf(MSG_INFO, "OWE: No ECDH state available"); |
| 5227 | return -1; |
| 5228 | } |
| 5229 | |
| 5230 | if (group == 19) |
| 5231 | prime_len = 32; |
| 5232 | else if (group == 20) |
| 5233 | prime_len = 48; |
| 5234 | else if (group == 21) |
| 5235 | prime_len = 66; |
| 5236 | else |
| 5237 | return -1; |
| 5238 | |
| 5239 | secret = crypto_ecdh_set_peerkey(sm->owe_ecdh, 0, |
| 5240 | elems.owe_dh + 2, |
| 5241 | elems.owe_dh_len - 2); |
| 5242 | secret = wpabuf_zeropad(secret, prime_len); |
| 5243 | if (!secret) { |
| 5244 | wpa_printf(MSG_DEBUG, "OWE: Invalid peer DH public key"); |
| 5245 | return -1; |
| 5246 | } |
| 5247 | wpa_hexdump_buf_key(MSG_DEBUG, "OWE: DH shared secret", secret); |
| 5248 | |
| 5249 | /* prk = HKDF-extract(C | A | group, z) */ |
| 5250 | |
| 5251 | pub = crypto_ecdh_get_pubkey(sm->owe_ecdh, 0); |
| 5252 | if (!pub) { |
| 5253 | wpabuf_clear_free(secret); |
| 5254 | return -1; |
| 5255 | } |
| 5256 | |
| 5257 | /* PMKID = Truncate-128(Hash(C | A)) */ |
| 5258 | addr[0] = wpabuf_head(pub); |
| 5259 | len[0] = wpabuf_len(pub); |
| 5260 | addr[1] = elems.owe_dh + 2; |
| 5261 | len[1] = elems.owe_dh_len - 2; |
| 5262 | if (group == 19) { |
| 5263 | res = sha256_vector(2, addr, len, pmkid); |
| 5264 | hash_len = SHA256_MAC_LEN; |
| 5265 | } else if (group == 20) { |
| 5266 | res = sha384_vector(2, addr, len, pmkid); |
| 5267 | hash_len = SHA384_MAC_LEN; |
| 5268 | } else if (group == 21) { |
| 5269 | res = sha512_vector(2, addr, len, pmkid); |
| 5270 | hash_len = SHA512_MAC_LEN; |
| 5271 | } else { |
| 5272 | res = -1; |
| 5273 | hash_len = 0; |
| 5274 | } |
| 5275 | pub = wpabuf_zeropad(pub, prime_len); |
| 5276 | if (res < 0 || !pub) { |
| 5277 | wpabuf_free(pub); |
| 5278 | wpabuf_clear_free(secret); |
| 5279 | return -1; |
| 5280 | } |
| 5281 | |
| 5282 | hkey = wpabuf_alloc(wpabuf_len(pub) + elems.owe_dh_len - 2 + 2); |
| 5283 | if (!hkey) { |
| 5284 | wpabuf_free(pub); |
| 5285 | wpabuf_clear_free(secret); |
| 5286 | return -1; |
| 5287 | } |
| 5288 | |
| 5289 | wpabuf_put_buf(hkey, pub); /* C */ |
| 5290 | wpabuf_free(pub); |
| 5291 | wpabuf_put_data(hkey, elems.owe_dh + 2, elems.owe_dh_len - 2); /* A */ |
| 5292 | wpabuf_put_le16(hkey, sm->owe_group); /* group */ |
| 5293 | if (group == 19) |
| 5294 | res = hmac_sha256(wpabuf_head(hkey), wpabuf_len(hkey), |
| 5295 | wpabuf_head(secret), wpabuf_len(secret), prk); |
| 5296 | else if (group == 20) |
| 5297 | res = hmac_sha384(wpabuf_head(hkey), wpabuf_len(hkey), |
| 5298 | wpabuf_head(secret), wpabuf_len(secret), prk); |
| 5299 | else if (group == 21) |
| 5300 | res = hmac_sha512(wpabuf_head(hkey), wpabuf_len(hkey), |
| 5301 | wpabuf_head(secret), wpabuf_len(secret), prk); |
| 5302 | wpabuf_clear_free(hkey); |
| 5303 | wpabuf_clear_free(secret); |
| 5304 | if (res < 0) |
| 5305 | return -1; |
| 5306 | |
| 5307 | wpa_hexdump_key(MSG_DEBUG, "OWE: prk", prk, hash_len); |
| 5308 | |
| 5309 | /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */ |
| 5310 | |
| 5311 | if (group == 19) |
| 5312 | res = hmac_sha256_kdf(prk, hash_len, NULL, (const u8 *) info, |
| 5313 | os_strlen(info), sm->pmk, hash_len); |
| 5314 | else if (group == 20) |
| 5315 | res = hmac_sha384_kdf(prk, hash_len, NULL, (const u8 *) info, |
| 5316 | os_strlen(info), sm->pmk, hash_len); |
| 5317 | else if (group == 21) |
| 5318 | res = hmac_sha512_kdf(prk, hash_len, NULL, (const u8 *) info, |
| 5319 | os_strlen(info), sm->pmk, hash_len); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5320 | forced_memzero(prk, SHA512_MAC_LEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5321 | if (res < 0) { |
| 5322 | sm->pmk_len = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5323 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5324 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5325 | sm->pmk_len = hash_len; |
| 5326 | |
| 5327 | wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sm->pmk, sm->pmk_len); |
| 5328 | wpa_hexdump(MSG_DEBUG, "OWE: PMKID", pmkid, PMKID_LEN); |
| 5329 | pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len, pmkid, NULL, 0, |
| 5330 | bssid, sm->own_addr, sm->network_ctx, sm->key_mgmt, |
| 5331 | NULL); |
| 5332 | |
| 5333 | return 0; |
| 5334 | } |
| 5335 | |
| 5336 | #endif /* CONFIG_OWE */ |
| 5337 | |
| 5338 | |
| 5339 | void wpa_sm_set_fils_cache_id(struct wpa_sm *sm, const u8 *fils_cache_id) |
| 5340 | { |
| 5341 | #ifdef CONFIG_FILS |
| 5342 | if (sm && fils_cache_id) { |
| 5343 | sm->fils_cache_id_set = 1; |
| 5344 | os_memcpy(sm->fils_cache_id, fils_cache_id, FILS_CACHE_ID_LEN); |
| 5345 | } |
| 5346 | #endif /* CONFIG_FILS */ |
| 5347 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5348 | |
| 5349 | |
| 5350 | #ifdef CONFIG_DPP2 |
| 5351 | void wpa_sm_set_dpp_z(struct wpa_sm *sm, const struct wpabuf *z) |
| 5352 | { |
| 5353 | if (sm) { |
| 5354 | wpabuf_clear_free(sm->dpp_z); |
| 5355 | sm->dpp_z = z ? wpabuf_dup(z) : NULL; |
| 5356 | } |
| 5357 | } |
| 5358 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5359 | |
| 5360 | |
| 5361 | #ifdef CONFIG_PASN |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 5362 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5363 | void wpa_pasn_pmksa_cache_add(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len, |
| 5364 | const u8 *pmkid, const u8 *bssid, int key_mgmt) |
| 5365 | { |
| 5366 | sm->cur_pmksa = pmksa_cache_add(sm->pmksa, pmk, pmk_len, pmkid, NULL, 0, |
| 5367 | bssid, sm->own_addr, NULL, |
| 5368 | key_mgmt, 0); |
| 5369 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 5370 | |
| 5371 | |
| 5372 | void wpa_pasn_sm_set_caps(struct wpa_sm *sm, unsigned int flags2) |
| 5373 | { |
| 5374 | if (flags2 & WPA_DRIVER_FLAGS2_SEC_LTF_STA) |
| 5375 | sm->secure_ltf = 1; |
| 5376 | if (flags2 & WPA_DRIVER_FLAGS2_SEC_RTT_STA) |
| 5377 | sm->secure_rtt = 1; |
| 5378 | if (flags2 & WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_STA) |
| 5379 | sm->prot_range_neg = 1; |
| 5380 | } |
| 5381 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5382 | #endif /* CONFIG_PASN */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5383 | |
| 5384 | |
| 5385 | void wpa_sm_pmksa_cache_reconfig(struct wpa_sm *sm) |
| 5386 | { |
| 5387 | if (sm) |
| 5388 | pmksa_cache_reconfig(sm->pmksa); |
| 5389 | } |