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