2 * WPA Supplicant - WPA state machine and EAPOL-Key processing
3 * Copyright (c) 2003-2018, Jouni Malinen <j@w1.fi>
4 * Copyright(c) 2015 Intel Deutschland GmbH
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
13 #include "crypto/aes.h"
14 #include "crypto/aes_wrap.h"
15 #include "crypto/crypto.h"
16 #include "crypto/random.h"
17 #include "crypto/aes_siv.h"
18 #include "crypto/sha256.h"
19 #include "crypto/sha384.h"
20 #include "crypto/sha512.h"
21 #include "common/ieee802_11_defs.h"
22 #include "common/ieee802_11_common.h"
23 #include "common/ocv.h"
24 #include "eap_common/eap_defs.h"
25 #include "eapol_supp/eapol_supp_sm.h"
26 #include "drivers/driver.h"
30 #include "pmksa_cache.h"
35 static const u8 null_rsc
[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
39 * wpa_eapol_key_send - Send WPA/RSN EAPOL-Key message
40 * @sm: Pointer to WPA state machine data from wpa_sm_init()
41 * @ptk: PTK for Key Confirmation/Encryption Key
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
48 * Returns: >= 0 on success, < 0 on failure
50 int wpa_eapol_key_send(struct wpa_sm
*sm
, struct wpa_ptk
*ptk
,
51 int ver
, const u8
*dest
, u16 proto
,
52 u8
*msg
, size_t msg_len
, u8
*key_mic
)
55 size_t mic_len
= wpa_mic_len(sm
->key_mgmt
, sm
->pmk_len
);
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
);
60 if (is_zero_ether_addr(dest
) && is_zero_ether_addr(sm
->bssid
)) {
62 * Association event was not yet received; try to fetch
63 * BSSID from the driver.
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");
71 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
72 "WPA: Use BSSID (" MACSTR
73 ") as the destination for EAPOL-Key",
79 if (key_mic
&& (!ptk
|| !ptk
->kck_len
))
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",
91 wpa_hexdump_key(MSG_DEBUG
, "WPA: KCK",
92 ptk
->kck
, ptk
->kck_len
);
93 wpa_hexdump(MSG_DEBUG
, "WPA: Derived Key MIC",
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
;
107 if (!ptk
|| !ptk
->kek_len
)
110 key_data_len
= msg_len
- sizeof(struct ieee802_1x_hdr
) -
111 sizeof(struct wpa_eapol_key
) - 2;
113 buf
= os_malloc(buf_len
);
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;
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
);
127 /* Update Key Data Length field to include AES-SIV overhead */
128 WPA_PUT_BE16((u8
*) (key
+ 1), AES_BLOCK_SIZE
+ key_data_len
);
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;
134 wpa_hexdump_key(MSG_DEBUG
, "WPA: Plaintext Key Data",
135 s_key_data
, key_data_len
);
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). */
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) {
149 wpa_hexdump(MSG_DEBUG
, "WPA: Encrypted Key Data from SIV",
150 key_data
, AES_BLOCK_SIZE
+ key_data_len
);
155 #else /* CONFIG_FILS */
157 #endif /* CONFIG_FILS */
160 wpa_hexdump(MSG_MSGDUMP
, "WPA: TX EAPOL-Key", msg
, msg_len
);
161 ret
= wpa_sm_ether_send(sm
, dest
, proto
, msg
, msg_len
);
162 eapol_sm_notify_tx_eapol_key(sm
->eapol
);
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
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.
179 void wpa_sm_key_request(struct wpa_sm
*sm
, int error
, int pairwise
)
181 size_t mic_len
, hdrlen
, rlen
;
182 struct wpa_eapol_key
*reply
;
184 u8 bssid
[ETH_ALEN
], *rbuf
, *key_mic
, *mic
;
186 if (wpa_use_akm_defined(sm
->key_mgmt
))
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
))
190 ver
= WPA_KEY_INFO_TYPE_AES_128_CMAC
;
191 else if (sm
->pairwise_cipher
!= WPA_CIPHER_TKIP
)
192 ver
= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
;
194 ver
= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
;
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");
202 mic_len
= wpa_mic_len(sm
->key_mgmt
, sm
->pmk_len
);
203 hdrlen
= sizeof(*reply
) + mic_len
+ 2;
204 rbuf
= wpa_sm_alloc_eapol(sm
, IEEE802_1X_TYPE_EAPOL_KEY
, NULL
,
205 hdrlen
, &rlen
, (void *) &reply
);
209 reply
->type
= (sm
->proto
== WPA_PROTO_RSN
||
210 sm
->proto
== WPA_PROTO_OSEN
) ?
211 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
212 key_info
= WPA_KEY_INFO_REQUEST
| ver
;
214 key_info
|= WPA_KEY_INFO_SECURE
;
215 if (sm
->ptk_set
&& mic_len
)
216 key_info
|= WPA_KEY_INFO_MIC
;
218 key_info
|= WPA_KEY_INFO_ERROR
;
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
);
227 mic
= (u8
*) (reply
+ 1);
228 WPA_PUT_BE16(mic
+ mic_len
, 0);
229 if (!(key_info
& WPA_KEY_INFO_MIC
))
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
);
238 wpa_eapol_key_send(sm
, &sm
->ptk
, ver
, bssid
, ETH_P_EAPOL
, rbuf
, rlen
,
243 static void wpa_supplicant_key_mgmt_set_pmk(struct wpa_sm
*sm
)
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");
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
257 #endif /* CONFIG_IEEE80211R */
261 static int wpa_supplicant_get_pmk(struct wpa_sm
*sm
,
262 const unsigned char *src_addr
,
265 int abort_cached
= 0;
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. */
272 sm
->cur_pmksa
= pmksa_cache_get(sm
->pmksa
, src_addr
, pmkid
,
275 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
276 "RSN: found matching PMKID from PMKSA cache");
278 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
279 "RSN: no matching PMKID found");
284 if (pmkid
&& sm
->cur_pmksa
&&
285 os_memcmp_const(pmkid
, sm
->cur_pmksa
->pmkid
, PMKID_LEN
) == 0) {
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
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
;
304 #endif /* CONFIG_SAE */
305 #endif /* CONFIG_IEEE80211R */
306 } else if (wpa_key_mgmt_wpa_ieee8021x(sm
->key_mgmt
) && sm
->eapol
) {
308 #ifdef CONFIG_IEEE80211R
310 #endif /* CONFIG_IEEE80211R */
312 if (wpa_key_mgmt_sha384(sm
->key_mgmt
))
313 pmk_len
= PMK_LEN_SUITE_B_192
;
316 res
= eapol_sm_get_key(sm
->eapol
, sm
->pmk
, pmk_len
);
318 if (pmk_len
== PMK_LEN
) {
320 * EAP-LEAP is an exception from other EAP
321 * methods: it uses only 16-byte PMK.
323 res
= eapol_sm_get_key(sm
->eapol
, sm
->pmk
, 16);
327 #ifdef CONFIG_IEEE80211R
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
;
334 os_memcpy(sm
->xxkey
, buf
+ PMK_LEN
, PMK_LEN
);
335 sm
->xxkey_len
= PMK_LEN
;
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
;
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
,
353 src_addr
, sm
->own_addr
,
361 #endif /* CONFIG_IEEE80211R */
363 struct rsn_pmksa_cache_entry
*sa
= NULL
;
364 const u8
*fils_cache_id
= NULL
;
367 if (sm
->fils_cache_id_set
)
368 fils_cache_id
= sm
->fils_cache_id
;
369 #endif /* CONFIG_FILS */
371 wpa_hexdump_key(MSG_DEBUG
, "WPA: PMK from EAPOL state "
372 "machines", sm
->pmk
, pmk_len
);
373 sm
->pmk_len
= pmk_len
;
374 wpa_supplicant_key_mgmt_set_pmk(sm
);
375 if (sm
->proto
== WPA_PROTO_RSN
&&
376 !wpa_key_mgmt_suite_b(sm
->key_mgmt
) &&
377 !wpa_key_mgmt_ft(sm
->key_mgmt
)) {
378 sa
= pmksa_cache_add(sm
->pmksa
,
379 sm
->pmk
, pmk_len
, NULL
,
381 src_addr
, sm
->own_addr
,
386 if (!sm
->cur_pmksa
&& pmkid
&&
387 pmksa_cache_get(sm
->pmksa
, src_addr
, pmkid
, NULL
,
389 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
390 "RSN: the new PMK matches with the "
393 } else if (sa
&& !sm
->cur_pmksa
&& pmkid
) {
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.
401 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
402 "RSN: PMKID mismatch - authentication server may have derived different MSK?!");
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 */
414 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
415 "WPA: Failed to get master session key from "
416 "EAPOL state machines - key handshake "
419 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
420 "RSN: Cancelled PMKSA caching "
422 sm
->cur_pmksa
= NULL
;
424 } else if (!abort_cached
) {
430 if (abort_cached
&& wpa_key_mgmt_wpa_ieee8021x(sm
->key_mgmt
) &&
431 !wpa_key_mgmt_suite_b(sm
->key_mgmt
) &&
432 !wpa_key_mgmt_ft(sm
->key_mgmt
) && sm
->key_mgmt
!= WPA_KEY_MGMT_OSEN
)
434 /* Send EAPOL-Start to trigger full EAP authentication. */
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
);
444 wpa_sm_ether_send(sm
, sm
->bssid
, ETH_P_EAPOL
,
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
467 * Returns: >= 0 on success, < 0 on failure
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
,
475 size_t mic_len
, hdrlen
, rlen
;
476 struct wpa_eapol_key
*reply
;
478 u8
*rsn_ie_buf
= NULL
;
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");
487 #ifdef CONFIG_IEEE80211R
488 if (wpa_key_mgmt_ft(sm
->key_mgmt
)) {
491 wpa_hexdump(MSG_DEBUG
, "WPA: WPA IE before FT processing",
494 * Add PMKR1Name into RSN IE (PMKID-List) and add MDIE and
495 * FTIE from (Re)Association Response.
497 rsn_ie_buf
= os_malloc(wpa_ie_len
+ 2 + 2 + PMKID_LEN
+
498 sm
->assoc_resp_ies_len
);
499 if (rsn_ie_buf
== NULL
)
501 os_memcpy(rsn_ie_buf
, wpa_ie
, wpa_ie_len
);
502 res
= wpa_insert_pmkid(rsn_ie_buf
, &wpa_ie_len
,
508 wpa_hexdump(MSG_DEBUG
,
509 "WPA: WPA IE after PMKID[PMKR1Name] addition into RSNE",
510 rsn_ie_buf
, wpa_ie_len
);
512 if (sm
->assoc_resp_ies
) {
513 wpa_hexdump(MSG_DEBUG
, "WPA: Add assoc_resp_ies",
515 sm
->assoc_resp_ies_len
);
516 os_memcpy(rsn_ie_buf
+ wpa_ie_len
, sm
->assoc_resp_ies
,
517 sm
->assoc_resp_ies_len
);
518 wpa_ie_len
+= sm
->assoc_resp_ies_len
;
523 #endif /* CONFIG_IEEE80211R */
525 wpa_hexdump(MSG_DEBUG
, "WPA: WPA IE for msg 2/4", wpa_ie
, wpa_ie_len
);
527 mic_len
= wpa_mic_len(sm
->key_mgmt
, sm
->pmk_len
);
528 hdrlen
= sizeof(*reply
) + mic_len
+ 2;
529 rbuf
= wpa_sm_alloc_eapol(sm
, IEEE802_1X_TYPE_EAPOL_KEY
,
530 NULL
, hdrlen
+ wpa_ie_len
,
531 &rlen
, (void *) &reply
);
537 reply
->type
= (sm
->proto
== WPA_PROTO_RSN
||
538 sm
->proto
== WPA_PROTO_OSEN
) ?
539 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
540 key_info
= ver
| WPA_KEY_INFO_KEY_TYPE
;
542 key_info
|= WPA_KEY_INFO_MIC
;
544 key_info
|= WPA_KEY_INFO_ENCR_KEY_DATA
;
545 WPA_PUT_BE16(reply
->key_info
, key_info
);
546 if (sm
->proto
== WPA_PROTO_RSN
|| sm
->proto
== WPA_PROTO_OSEN
)
547 WPA_PUT_BE16(reply
->key_length
, 0);
549 os_memcpy(reply
->key_length
, key
->key_length
, 2);
550 os_memcpy(reply
->replay_counter
, key
->replay_counter
,
551 WPA_REPLAY_COUNTER_LEN
);
552 wpa_hexdump(MSG_DEBUG
, "WPA: Replay Counter", reply
->replay_counter
,
553 WPA_REPLAY_COUNTER_LEN
);
555 key_mic
= (u8
*) (reply
+ 1);
556 WPA_PUT_BE16(key_mic
+ mic_len
, wpa_ie_len
); /* Key Data Length */
557 os_memcpy(key_mic
+ mic_len
+ 2, wpa_ie
, wpa_ie_len
); /* Key Data */
560 os_memcpy(reply
->key_nonce
, nonce
, WPA_NONCE_LEN
);
562 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: Sending EAPOL-Key 2/4");
563 return wpa_eapol_key_send(sm
, ptk
, ver
, dst
, ETH_P_EAPOL
, rbuf
, rlen
,
568 static int wpa_derive_ptk(struct wpa_sm
*sm
, const unsigned char *src_addr
,
569 const struct wpa_eapol_key
*key
, struct wpa_ptk
*ptk
)
575 #ifdef CONFIG_IEEE80211R
576 if (wpa_key_mgmt_ft(sm
->key_mgmt
))
577 return wpa_derive_ptk_ft(sm
, src_addr
, key
, ptk
);
578 #endif /* CONFIG_IEEE80211R */
581 if (sm
->key_mgmt
== WPA_KEY_MGMT_DPP
&& sm
->dpp_z
) {
582 z
= wpabuf_head(sm
->dpp_z
);
583 z_len
= wpabuf_len(sm
->dpp_z
);
585 #endif /* CONFIG_DPP2 */
589 if (sm
->owe_ptk_workaround
&& akmp
== WPA_KEY_MGMT_OWE
&&
591 wpa_printf(MSG_DEBUG
,
592 "OWE: Force SHA256 for PTK derivation");
593 akmp
= WPA_KEY_MGMT_PSK_SHA256
;
595 #endif /* CONFIG_OWE */
596 return wpa_pmk_to_ptk(sm
->pmk
, sm
->pmk_len
, "Pairwise key expansion",
597 sm
->own_addr
, sm
->bssid
, sm
->snonce
,
598 key
->key_nonce
, ptk
, akmp
,
599 sm
->pairwise_cipher
, z
, z_len
);
603 static void wpa_supplicant_process_1_of_4(struct wpa_sm
*sm
,
604 const unsigned char *src_addr
,
605 const struct wpa_eapol_key
*key
,
606 u16 ver
, const u8
*key_data
,
609 struct wpa_eapol_ie_parse ie
;
612 u8
*kde
, *kde_buf
= NULL
;
615 if (wpa_sm_get_network_ctx(sm
) == NULL
) {
616 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
, "WPA: No SSID info "
617 "found (msg 1 of 4)");
621 wpa_sm_set_state(sm
, WPA_4WAY_HANDSHAKE
);
622 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: RX message 1 of 4-Way "
623 "Handshake from " MACSTR
" (ver=%d)", MAC2STR(src_addr
), ver
);
625 os_memset(&ie
, 0, sizeof(ie
));
627 if (sm
->proto
== WPA_PROTO_RSN
|| sm
->proto
== WPA_PROTO_OSEN
) {
628 /* RSN: msg 1/4 should contain PMKID for the selected PMK */
629 wpa_hexdump(MSG_DEBUG
, "RSN: msg 1/4 key data",
630 key_data
, key_data_len
);
631 if (wpa_supplicant_parse_ies(key_data
, key_data_len
, &ie
) < 0)
634 wpa_hexdump(MSG_DEBUG
, "RSN: PMKID from "
635 "Authenticator", ie
.pmkid
, PMKID_LEN
);
639 res
= wpa_supplicant_get_pmk(sm
, src_addr
, ie
.pmkid
);
641 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "RSN: Do not reply to "
642 "msg 1/4 - requesting full EAP authentication");
648 if (sm
->renew_snonce
) {
649 if (random_get_bytes(sm
->snonce
, WPA_NONCE_LEN
)) {
650 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
651 "WPA: Failed to get random data for SNonce");
654 sm
->renew_snonce
= 0;
655 wpa_hexdump(MSG_DEBUG
, "WPA: Renewed SNonce",
656 sm
->snonce
, WPA_NONCE_LEN
);
659 /* Calculate PTK which will be stored as a temporary PTK until it has
660 * been verified when processing message 3/4. */
662 if (wpa_derive_ptk(sm
, src_addr
, key
, ptk
) < 0)
664 if (sm
->pairwise_cipher
== WPA_CIPHER_TKIP
) {
666 /* Supplicant: swap tx/rx Mic keys */
667 os_memcpy(buf
, &ptk
->tk
[16], 8);
668 os_memcpy(&ptk
->tk
[16], &ptk
->tk
[24], 8);
669 os_memcpy(&ptk
->tk
[24], buf
, 8);
670 forced_memzero(buf
, sizeof(buf
));
674 kde
= sm
->assoc_wpa_ie
;
675 kde_len
= sm
->assoc_wpa_ie_len
;
676 kde_buf
= os_malloc(kde_len
+
677 2 + RSN_SELECTOR_LEN
+ 3 +
678 sm
->assoc_rsnxe_len
+
679 2 + RSN_SELECTOR_LEN
+ 1);
682 os_memcpy(kde_buf
, kde
, kde_len
);
686 if (wpa_sm_ocv_enabled(sm
)) {
687 struct wpa_channel_info ci
;
691 if (wpa_sm_channel_info(sm
, &ci
) != 0) {
692 wpa_printf(MSG_WARNING
,
693 "Failed to get channel info for OCI element in EAPOL-Key 2/4");
697 if (ocv_insert_oci_kde(&ci
, &pos
) < 0)
701 #endif /* CONFIG_OCV */
703 if (sm
->assoc_rsnxe
&& sm
->assoc_rsnxe_len
) {
704 os_memcpy(kde
+ kde_len
, sm
->assoc_rsnxe
, sm
->assoc_rsnxe_len
);
705 kde_len
+= sm
->assoc_rsnxe_len
;
712 wpa_printf(MSG_DEBUG
,
713 "P2P: Add IP Address Request KDE into EAPOL-Key 2/4");
715 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
716 *pos
++ = RSN_SELECTOR_LEN
+ 1;
717 RSN_SELECTOR_PUT(pos
, WFA_KEY_DATA_IP_ADDR_REQ
);
718 pos
+= RSN_SELECTOR_LEN
;
722 #endif /* CONFIG_P2P */
724 if (wpa_supplicant_send_2_of_4(sm
, sm
->bssid
, key
, ver
, sm
->snonce
,
725 kde
, kde_len
, ptk
) < 0)
729 os_memcpy(sm
->anonce
, key
->key_nonce
, WPA_NONCE_LEN
);
734 wpa_sm_deauthenticate(sm
, WLAN_REASON_UNSPECIFIED
);
738 static void wpa_sm_start_preauth(void *eloop_ctx
, void *timeout_ctx
)
740 struct wpa_sm
*sm
= eloop_ctx
;
741 rsn_preauth_candidate_process(sm
);
745 static void wpa_supplicant_key_neg_complete(struct wpa_sm
*sm
,
746 const u8
*addr
, int secure
)
748 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
749 "WPA: Key negotiation completed with "
750 MACSTR
" [PTK=%s GTK=%s]", MAC2STR(addr
),
751 wpa_cipher_txt(sm
->pairwise_cipher
),
752 wpa_cipher_txt(sm
->group_cipher
));
753 wpa_sm_cancel_auth_timeout(sm
);
754 wpa_sm_set_state(sm
, WPA_COMPLETED
);
757 wpa_sm_mlme_setprotection(
758 sm
, addr
, MLME_SETPROTECTION_PROTECT_TYPE_RX_TX
,
759 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
760 eapol_sm_notify_portValid(sm
->eapol
, TRUE
);
761 if (wpa_key_mgmt_wpa_psk(sm
->key_mgmt
) ||
762 sm
->key_mgmt
== WPA_KEY_MGMT_DPP
||
763 sm
->key_mgmt
== WPA_KEY_MGMT_OWE
)
764 eapol_sm_notify_eap_success(sm
->eapol
, TRUE
);
766 * Start preauthentication after a short wait to avoid a
767 * possible race condition between the data receive and key
768 * configuration after the 4-Way Handshake. This increases the
769 * likelihood of the first preauth EAPOL-Start frame getting to
772 if (!dl_list_empty(&sm
->pmksa_candidates
))
773 eloop_register_timeout(1, 0, wpa_sm_start_preauth
,
777 if (sm
->cur_pmksa
&& sm
->cur_pmksa
->opportunistic
) {
778 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
779 "RSN: Authenticator accepted "
780 "opportunistic PMKSA entry - marking it valid");
781 sm
->cur_pmksa
->opportunistic
= 0;
784 #ifdef CONFIG_IEEE80211R
785 if (wpa_key_mgmt_ft(sm
->key_mgmt
)) {
786 /* Prepare for the next transition */
787 wpa_ft_prepare_auth_request(sm
, NULL
);
789 #endif /* CONFIG_IEEE80211R */
793 static void wpa_sm_rekey_ptk(void *eloop_ctx
, void *timeout_ctx
)
795 struct wpa_sm
*sm
= eloop_ctx
;
796 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: Request PTK rekeying");
797 wpa_sm_key_request(sm
, 0, 1);
801 static int wpa_supplicant_install_ptk(struct wpa_sm
*sm
,
802 const struct wpa_eapol_key
*key
,
803 enum key_flag key_flag
)
809 if (sm
->ptk
.installed
) {
810 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
811 "WPA: Do not re-install same PTK to the driver");
815 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
816 "WPA: Installing PTK to the driver");
818 if (sm
->pairwise_cipher
== WPA_CIPHER_NONE
) {
819 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: Pairwise Cipher "
820 "Suite: NONE - do not use pairwise keys");
824 if (!wpa_cipher_valid_pairwise(sm
->pairwise_cipher
)) {
825 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
826 "WPA: Unsupported pairwise cipher %d",
827 sm
->pairwise_cipher
);
831 alg
= wpa_cipher_to_alg(sm
->pairwise_cipher
);
832 keylen
= wpa_cipher_key_len(sm
->pairwise_cipher
);
833 if (keylen
<= 0 || (unsigned int) keylen
!= sm
->ptk
.tk_len
) {
834 wpa_printf(MSG_DEBUG
, "WPA: TK length mismatch: %d != %lu",
835 keylen
, (long unsigned int) sm
->ptk
.tk_len
);
838 rsclen
= wpa_cipher_rsc_len(sm
->pairwise_cipher
);
840 if (sm
->proto
== WPA_PROTO_RSN
|| sm
->proto
== WPA_PROTO_OSEN
) {
843 key_rsc
= key
->key_rsc
;
844 wpa_hexdump(MSG_DEBUG
, "WPA: RSC", key_rsc
, rsclen
);
847 if (wpa_sm_set_key(sm
, alg
, sm
->bssid
, 0, 1, key_rsc
, rsclen
,
849 KEY_FLAG_PAIRWISE
| key_flag
) < 0) {
850 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
851 "WPA: Failed to set PTK to the "
852 "driver (alg=%d keylen=%d bssid=" MACSTR
")",
853 alg
, keylen
, MAC2STR(sm
->bssid
));
857 /* TK is not needed anymore in supplicant */
858 os_memset(sm
->ptk
.tk
, 0, WPA_TK_MAX_LEN
);
860 sm
->ptk
.installed
= 1;
862 if (sm
->wpa_ptk_rekey
) {
863 eloop_cancel_timeout(wpa_sm_rekey_ptk
, sm
, NULL
);
864 eloop_register_timeout(sm
->wpa_ptk_rekey
, 0, wpa_sm_rekey_ptk
,
872 static int wpa_supplicant_check_group_cipher(struct wpa_sm
*sm
,
874 int keylen
, int maxkeylen
,
880 *alg
= wpa_cipher_to_alg(group_cipher
);
881 if (*alg
== WPA_ALG_NONE
) {
882 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
883 "WPA: Unsupported Group Cipher %d",
887 *key_rsc_len
= wpa_cipher_rsc_len(group_cipher
);
889 klen
= wpa_cipher_key_len(group_cipher
);
890 if (keylen
!= klen
|| maxkeylen
< klen
) {
891 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
892 "WPA: Unsupported %s Group Cipher key length %d (%d)",
893 wpa_cipher_txt(group_cipher
), keylen
, maxkeylen
);
900 struct wpa_gtk_data
{
902 int tx
, key_rsc_len
, keyidx
;
908 static int wpa_supplicant_install_gtk(struct wpa_sm
*sm
,
909 const struct wpa_gtk_data
*gd
,
910 const u8
*key_rsc
, int wnm_sleep
)
912 const u8
*_gtk
= gd
->gtk
;
915 /* Detect possible key reinstallation */
916 if ((sm
->gtk
.gtk_len
== (size_t) gd
->gtk_len
&&
917 os_memcmp(sm
->gtk
.gtk
, gd
->gtk
, sm
->gtk
.gtk_len
) == 0) ||
918 (sm
->gtk_wnm_sleep
.gtk_len
== (size_t) gd
->gtk_len
&&
919 os_memcmp(sm
->gtk_wnm_sleep
.gtk
, gd
->gtk
,
920 sm
->gtk_wnm_sleep
.gtk_len
) == 0)) {
921 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
922 "WPA: Not reinstalling already in-use GTK to the driver (keyidx=%d tx=%d len=%d)",
923 gd
->keyidx
, gd
->tx
, gd
->gtk_len
);
927 wpa_hexdump_key(MSG_DEBUG
, "WPA: Group Key", gd
->gtk
, gd
->gtk_len
);
928 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
929 "WPA: Installing GTK to the driver (keyidx=%d tx=%d len=%d)",
930 gd
->keyidx
, gd
->tx
, gd
->gtk_len
);
931 wpa_hexdump(MSG_DEBUG
, "WPA: RSC", key_rsc
, gd
->key_rsc_len
);
932 if (sm
->group_cipher
== WPA_CIPHER_TKIP
) {
933 /* Swap Tx/Rx keys for Michael MIC */
934 os_memcpy(gtk_buf
, gd
->gtk
, 16);
935 os_memcpy(gtk_buf
+ 16, gd
->gtk
+ 24, 8);
936 os_memcpy(gtk_buf
+ 24, gd
->gtk
+ 16, 8);
939 if (sm
->pairwise_cipher
== WPA_CIPHER_NONE
) {
940 if (wpa_sm_set_key(sm
, gd
->alg
, NULL
,
941 gd
->keyidx
, 1, key_rsc
, gd
->key_rsc_len
,
943 KEY_FLAG_GROUP_RX_TX_DEFAULT
) < 0) {
944 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
945 "WPA: Failed to set GTK to the driver "
947 forced_memzero(gtk_buf
, sizeof(gtk_buf
));
950 } else if (wpa_sm_set_key(sm
, gd
->alg
, broadcast_ether_addr
,
951 gd
->keyidx
, gd
->tx
, key_rsc
, gd
->key_rsc_len
,
952 _gtk
, gd
->gtk_len
, KEY_FLAG_GROUP_RX
) < 0) {
953 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
954 "WPA: Failed to set GTK to "
955 "the driver (alg=%d keylen=%d keyidx=%d)",
956 gd
->alg
, gd
->gtk_len
, gd
->keyidx
);
957 forced_memzero(gtk_buf
, sizeof(gtk_buf
));
960 forced_memzero(gtk_buf
, sizeof(gtk_buf
));
963 sm
->gtk_wnm_sleep
.gtk_len
= gd
->gtk_len
;
964 os_memcpy(sm
->gtk_wnm_sleep
.gtk
, gd
->gtk
,
965 sm
->gtk_wnm_sleep
.gtk_len
);
967 sm
->gtk
.gtk_len
= gd
->gtk_len
;
968 os_memcpy(sm
->gtk
.gtk
, gd
->gtk
, sm
->gtk
.gtk_len
);
975 static int wpa_supplicant_gtk_tx_bit_workaround(const struct wpa_sm
*sm
,
978 if (tx
&& sm
->pairwise_cipher
!= WPA_CIPHER_NONE
) {
979 /* Ignore Tx bit for GTK if a pairwise key is used. One AP
980 * seemed to set this bit (incorrectly, since Tx is only when
981 * doing Group Key only APs) and without this workaround, the
982 * data connection does not work because wpa_supplicant
983 * configured non-zero keyidx to be used for unicast. */
984 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
985 "WPA: Tx bit set for GTK, but pairwise "
986 "keys are used - ignore Tx bit");
993 static int wpa_supplicant_rsc_relaxation(const struct wpa_sm
*sm
,
998 if (!sm
->wpa_rsc_relaxation
)
1001 rsclen
= wpa_cipher_rsc_len(sm
->group_cipher
);
1004 * Try to detect RSC (endian) corruption issue where the AP sends
1005 * the RSC bytes in EAPOL-Key message in the wrong order, both if
1006 * it's actually a 6-byte field (as it should be) and if it treats
1007 * it as an 8-byte field.
1008 * An AP model known to have this bug is the Sapido RB-1632.
1010 if (rsclen
== 6 && ((rsc
[5] && !rsc
[0]) || rsc
[6] || rsc
[7])) {
1011 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1012 "RSC %02x%02x%02x%02x%02x%02x%02x%02x is likely bogus, using 0",
1013 rsc
[0], rsc
[1], rsc
[2], rsc
[3],
1014 rsc
[4], rsc
[5], rsc
[6], rsc
[7]);
1023 static int wpa_supplicant_pairwise_gtk(struct wpa_sm
*sm
,
1024 const struct wpa_eapol_key
*key
,
1025 const u8
*gtk
, size_t gtk_len
,
1028 struct wpa_gtk_data gd
;
1032 * IEEE Std 802.11i-2004 - 8.5.2 EAPOL-Key frames - Figure 43x
1034 * KeyID[bits 0-1], Tx [bit 2], Reserved [bits 3-7]
1035 * Reserved [bits 0-7]
1039 os_memset(&gd
, 0, sizeof(gd
));
1040 wpa_hexdump_key(MSG_DEBUG
, "RSN: received GTK in pairwise handshake",
1043 if (gtk_len
< 2 || gtk_len
- 2 > sizeof(gd
.gtk
))
1046 gd
.keyidx
= gtk
[0] & 0x3;
1047 gd
.tx
= wpa_supplicant_gtk_tx_bit_workaround(sm
,
1048 !!(gtk
[0] & BIT(2)));
1052 os_memcpy(gd
.gtk
, gtk
, gtk_len
);
1053 gd
.gtk_len
= gtk_len
;
1055 key_rsc
= key
->key_rsc
;
1056 if (wpa_supplicant_rsc_relaxation(sm
, key
->key_rsc
))
1059 if (sm
->group_cipher
!= WPA_CIPHER_GTK_NOT_USED
&&
1060 (wpa_supplicant_check_group_cipher(sm
, sm
->group_cipher
,
1062 &gd
.key_rsc_len
, &gd
.alg
) ||
1063 wpa_supplicant_install_gtk(sm
, &gd
, key_rsc
, 0))) {
1064 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
1065 "RSN: Failed to install GTK");
1066 forced_memzero(&gd
, sizeof(gd
));
1069 forced_memzero(&gd
, sizeof(gd
));
1075 static int wpa_supplicant_install_igtk(struct wpa_sm
*sm
,
1076 const struct wpa_igtk_kde
*igtk
,
1079 size_t len
= wpa_cipher_key_len(sm
->mgmt_group_cipher
);
1080 u16 keyidx
= WPA_GET_LE16(igtk
->keyid
);
1082 /* Detect possible key reinstallation */
1083 if ((sm
->igtk
.igtk_len
== len
&&
1084 os_memcmp(sm
->igtk
.igtk
, igtk
->igtk
, sm
->igtk
.igtk_len
) == 0) ||
1085 (sm
->igtk_wnm_sleep
.igtk_len
== len
&&
1086 os_memcmp(sm
->igtk_wnm_sleep
.igtk
, igtk
->igtk
,
1087 sm
->igtk_wnm_sleep
.igtk_len
) == 0)) {
1088 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
1089 "WPA: Not reinstalling already in-use IGTK to the driver (keyidx=%d)",
1094 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
1095 "WPA: IGTK keyid %d pn " COMPACT_MACSTR
,
1096 keyidx
, MAC2STR(igtk
->pn
));
1097 wpa_hexdump_key(MSG_DEBUG
, "WPA: IGTK", igtk
->igtk
, len
);
1098 if (keyidx
> 4095) {
1099 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1100 "WPA: Invalid IGTK KeyID %d", keyidx
);
1103 if (wpa_sm_set_key(sm
, wpa_cipher_to_alg(sm
->mgmt_group_cipher
),
1104 broadcast_ether_addr
,
1105 keyidx
, 0, igtk
->pn
, sizeof(igtk
->pn
),
1106 igtk
->igtk
, len
, KEY_FLAG_GROUP_RX
) < 0) {
1107 if (keyidx
== 0x0400 || keyidx
== 0x0500) {
1108 /* Assume the AP has broken PMF implementation since it
1109 * seems to have swapped the KeyID bytes. The AP cannot
1110 * be trusted to implement BIP correctly or provide a
1111 * valid IGTK, so do not try to configure this key with
1112 * swapped KeyID bytes. Instead, continue without
1113 * configuring the IGTK so that the driver can drop any
1114 * received group-addressed robust management frames due
1117 * Normally, this error behavior would result in us
1118 * disconnecting, but there are number of deployed APs
1119 * with this broken behavior, so as an interoperability
1120 * workaround, allow the connection to proceed. */
1121 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1122 "WPA: Ignore IGTK configuration error due to invalid IGTK KeyID byte order");
1124 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1125 "WPA: Failed to configure IGTK to the driver");
1131 sm
->igtk_wnm_sleep
.igtk_len
= len
;
1132 os_memcpy(sm
->igtk_wnm_sleep
.igtk
, igtk
->igtk
,
1133 sm
->igtk_wnm_sleep
.igtk_len
);
1135 sm
->igtk
.igtk_len
= len
;
1136 os_memcpy(sm
->igtk
.igtk
, igtk
->igtk
, sm
->igtk
.igtk_len
);
1143 static int ieee80211w_set_keys(struct wpa_sm
*sm
,
1144 struct wpa_eapol_ie_parse
*ie
)
1146 if (!wpa_cipher_valid_mgmt_group(sm
->mgmt_group_cipher
))
1151 const struct wpa_igtk_kde
*igtk
;
1153 len
= wpa_cipher_key_len(sm
->mgmt_group_cipher
);
1154 if (ie
->igtk_len
!= WPA_IGTK_KDE_PREFIX_LEN
+ len
)
1157 igtk
= (const struct wpa_igtk_kde
*) ie
->igtk
;
1158 if (wpa_supplicant_install_igtk(sm
, igtk
, 0) < 0)
1166 static void wpa_report_ie_mismatch(struct wpa_sm
*sm
,
1167 const char *reason
, const u8
*src_addr
,
1168 const u8
*wpa_ie
, size_t wpa_ie_len
,
1169 const u8
*rsn_ie
, size_t rsn_ie_len
)
1171 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
, "WPA: %s (src=" MACSTR
")",
1172 reason
, MAC2STR(src_addr
));
1174 if (sm
->ap_wpa_ie
) {
1175 wpa_hexdump(MSG_INFO
, "WPA: WPA IE in Beacon/ProbeResp",
1176 sm
->ap_wpa_ie
, sm
->ap_wpa_ie_len
);
1179 if (!sm
->ap_wpa_ie
) {
1180 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1181 "WPA: No WPA IE in Beacon/ProbeResp");
1183 wpa_hexdump(MSG_INFO
, "WPA: WPA IE in 3/4 msg",
1184 wpa_ie
, wpa_ie_len
);
1187 if (sm
->ap_rsn_ie
) {
1188 wpa_hexdump(MSG_INFO
, "WPA: RSN IE in Beacon/ProbeResp",
1189 sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
);
1192 if (!sm
->ap_rsn_ie
) {
1193 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1194 "WPA: No RSN IE in Beacon/ProbeResp");
1196 wpa_hexdump(MSG_INFO
, "WPA: RSN IE in 3/4 msg",
1197 rsn_ie
, rsn_ie_len
);
1200 wpa_sm_deauthenticate(sm
, WLAN_REASON_IE_IN_4WAY_DIFFERS
);
1204 #ifdef CONFIG_IEEE80211R
1206 static int ft_validate_mdie(struct wpa_sm
*sm
,
1207 const unsigned char *src_addr
,
1208 struct wpa_eapol_ie_parse
*ie
,
1209 const u8
*assoc_resp_mdie
)
1211 struct rsn_mdie
*mdie
;
1213 mdie
= (struct rsn_mdie
*) (ie
->mdie
+ 2);
1214 if (ie
->mdie
== NULL
|| ie
->mdie_len
< 2 + sizeof(*mdie
) ||
1215 os_memcmp(mdie
->mobility_domain
, sm
->mobility_domain
,
1216 MOBILITY_DOMAIN_ID_LEN
) != 0) {
1217 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "FT: MDIE in msg 3/4 did "
1218 "not match with the current mobility domain");
1222 if (assoc_resp_mdie
&&
1223 (assoc_resp_mdie
[1] != ie
->mdie
[1] ||
1224 os_memcmp(assoc_resp_mdie
, ie
->mdie
, 2 + ie
->mdie
[1]) != 0)) {
1225 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "FT: MDIE mismatch");
1226 wpa_hexdump(MSG_DEBUG
, "FT: MDIE in EAPOL-Key msg 3/4",
1227 ie
->mdie
, 2 + ie
->mdie
[1]);
1228 wpa_hexdump(MSG_DEBUG
, "FT: MDIE in (Re)Association Response",
1229 assoc_resp_mdie
, 2 + assoc_resp_mdie
[1]);
1237 static int ft_validate_ftie(struct wpa_sm
*sm
,
1238 const unsigned char *src_addr
,
1239 struct wpa_eapol_ie_parse
*ie
,
1240 const u8
*assoc_resp_ftie
)
1242 if (ie
->ftie
== NULL
) {
1243 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
1244 "FT: No FTIE in EAPOL-Key msg 3/4");
1248 if (assoc_resp_ftie
== NULL
)
1251 if (assoc_resp_ftie
[1] != ie
->ftie
[1] ||
1252 os_memcmp(assoc_resp_ftie
, ie
->ftie
, 2 + ie
->ftie
[1]) != 0) {
1253 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "FT: FTIE mismatch");
1254 wpa_hexdump(MSG_DEBUG
, "FT: FTIE in EAPOL-Key msg 3/4",
1255 ie
->ftie
, 2 + ie
->ftie
[1]);
1256 wpa_hexdump(MSG_DEBUG
, "FT: FTIE in (Re)Association Response",
1257 assoc_resp_ftie
, 2 + assoc_resp_ftie
[1]);
1265 static int ft_validate_rsnie(struct wpa_sm
*sm
,
1266 const unsigned char *src_addr
,
1267 struct wpa_eapol_ie_parse
*ie
)
1269 struct wpa_ie_data rsn
;
1275 * Verify that PMKR1Name from EAPOL-Key message 3/4
1276 * matches with the value we derived.
1278 if (wpa_parse_wpa_ie_rsn(ie
->rsn_ie
, ie
->rsn_ie_len
, &rsn
) < 0 ||
1279 rsn
.num_pmkid
!= 1 || rsn
.pmkid
== NULL
) {
1280 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "FT: No PMKR1Name in "
1281 "FT 4-way handshake message 3/4");
1285 if (os_memcmp_const(rsn
.pmkid
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
) != 0)
1287 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
1288 "FT: PMKR1Name mismatch in "
1289 "FT 4-way handshake message 3/4");
1290 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name from Authenticator",
1291 rsn
.pmkid
, WPA_PMK_NAME_LEN
);
1292 wpa_hexdump(MSG_DEBUG
, "FT: Derived PMKR1Name",
1293 sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
);
1301 static int wpa_supplicant_validate_ie_ft(struct wpa_sm
*sm
,
1302 const unsigned char *src_addr
,
1303 struct wpa_eapol_ie_parse
*ie
)
1305 const u8
*pos
, *end
, *mdie
= NULL
, *ftie
= NULL
;
1307 if (sm
->assoc_resp_ies
) {
1308 pos
= sm
->assoc_resp_ies
;
1309 end
= pos
+ sm
->assoc_resp_ies_len
;
1310 while (end
- pos
> 2) {
1311 if (2 + pos
[1] > end
- pos
)
1314 case WLAN_EID_MOBILITY_DOMAIN
:
1317 case WLAN_EID_FAST_BSS_TRANSITION
:
1325 if (ft_validate_mdie(sm
, src_addr
, ie
, mdie
) < 0 ||
1326 ft_validate_ftie(sm
, src_addr
, ie
, ftie
) < 0 ||
1327 ft_validate_rsnie(sm
, src_addr
, ie
) < 0)
1333 #endif /* CONFIG_IEEE80211R */
1336 static int wpa_supplicant_validate_ie(struct wpa_sm
*sm
,
1337 const unsigned char *src_addr
,
1338 struct wpa_eapol_ie_parse
*ie
)
1340 if (sm
->ap_wpa_ie
== NULL
&& sm
->ap_rsn_ie
== NULL
) {
1341 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
1342 "WPA: No WPA/RSN IE for this AP known. "
1343 "Trying to get from scan results");
1344 if (wpa_sm_get_beacon_ie(sm
) < 0) {
1345 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1346 "WPA: Could not find AP from "
1347 "the scan results");
1349 wpa_msg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
1350 "WPA: Found the current AP from "
1351 "updated scan results");
1355 if (ie
->wpa_ie
== NULL
&& ie
->rsn_ie
== NULL
&&
1356 (sm
->ap_wpa_ie
|| sm
->ap_rsn_ie
)) {
1357 wpa_report_ie_mismatch(sm
, "IE in 3/4 msg does not match "
1358 "with IE in Beacon/ProbeResp (no IE?)",
1359 src_addr
, ie
->wpa_ie
, ie
->wpa_ie_len
,
1360 ie
->rsn_ie
, ie
->rsn_ie_len
);
1364 if ((ie
->wpa_ie
&& sm
->ap_wpa_ie
&&
1365 (ie
->wpa_ie_len
!= sm
->ap_wpa_ie_len
||
1366 os_memcmp(ie
->wpa_ie
, sm
->ap_wpa_ie
, ie
->wpa_ie_len
) != 0)) ||
1367 (ie
->rsn_ie
&& sm
->ap_rsn_ie
&&
1368 wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm
->key_mgmt
),
1369 sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
,
1370 ie
->rsn_ie
, ie
->rsn_ie_len
))) {
1371 wpa_report_ie_mismatch(sm
, "IE in 3/4 msg does not match "
1372 "with IE in Beacon/ProbeResp",
1373 src_addr
, ie
->wpa_ie
, ie
->wpa_ie_len
,
1374 ie
->rsn_ie
, ie
->rsn_ie_len
);
1378 if (sm
->proto
== WPA_PROTO_WPA
&&
1379 ie
->rsn_ie
&& sm
->ap_rsn_ie
== NULL
&& sm
->rsn_enabled
) {
1380 wpa_report_ie_mismatch(sm
, "Possible downgrade attack "
1381 "detected - RSN was enabled and RSN IE "
1382 "was in msg 3/4, but not in "
1384 src_addr
, ie
->wpa_ie
, ie
->wpa_ie_len
,
1385 ie
->rsn_ie
, ie
->rsn_ie_len
);
1389 if ((sm
->ap_rsnxe
&& !ie
->rsnxe
) ||
1390 (!sm
->ap_rsnxe
&& ie
->rsnxe
) ||
1391 (sm
->ap_rsnxe
&& ie
->rsnxe
&&
1392 (sm
->ap_rsnxe_len
!= ie
->rsnxe_len
||
1393 os_memcmp(sm
->ap_rsnxe
, ie
->rsnxe
, sm
->ap_rsnxe_len
) != 0))) {
1394 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1395 "WPA: RSNXE mismatch between Beacon/ProbeResp and EAPOL-Key msg 3/4");
1399 #ifdef CONFIG_IEEE80211R
1400 if (wpa_key_mgmt_ft(sm
->key_mgmt
) &&
1401 wpa_supplicant_validate_ie_ft(sm
, src_addr
, ie
) < 0)
1403 #endif /* CONFIG_IEEE80211R */
1410 * wpa_supplicant_send_4_of_4 - Send message 4 of WPA/RSN 4-Way Handshake
1411 * @sm: Pointer to WPA state machine data from wpa_sm_init()
1412 * @dst: Destination address for the frame
1413 * @key: Pointer to the EAPOL-Key frame header
1414 * @ver: Version bits from EAPOL-Key Key Info
1415 * @key_info: Key Info
1416 * @ptk: PTK to use for keyed hash and encryption
1417 * Returns: >= 0 on success, < 0 on failure
1419 int wpa_supplicant_send_4_of_4(struct wpa_sm
*sm
, const unsigned char *dst
,
1420 const struct wpa_eapol_key
*key
,
1421 u16 ver
, u16 key_info
,
1422 struct wpa_ptk
*ptk
)
1424 size_t mic_len
, hdrlen
, rlen
;
1425 struct wpa_eapol_key
*reply
;
1428 mic_len
= wpa_mic_len(sm
->key_mgmt
, sm
->pmk_len
);
1429 hdrlen
= sizeof(*reply
) + mic_len
+ 2;
1430 rbuf
= wpa_sm_alloc_eapol(sm
, IEEE802_1X_TYPE_EAPOL_KEY
, NULL
,
1431 hdrlen
, &rlen
, (void *) &reply
);
1435 reply
->type
= (sm
->proto
== WPA_PROTO_RSN
||
1436 sm
->proto
== WPA_PROTO_OSEN
) ?
1437 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
1438 key_info
&= WPA_KEY_INFO_SECURE
;
1439 key_info
|= ver
| WPA_KEY_INFO_KEY_TYPE
;
1441 key_info
|= WPA_KEY_INFO_MIC
;
1443 key_info
|= WPA_KEY_INFO_ENCR_KEY_DATA
;
1444 WPA_PUT_BE16(reply
->key_info
, key_info
);
1445 if (sm
->proto
== WPA_PROTO_RSN
|| sm
->proto
== WPA_PROTO_OSEN
)
1446 WPA_PUT_BE16(reply
->key_length
, 0);
1448 os_memcpy(reply
->key_length
, key
->key_length
, 2);
1449 os_memcpy(reply
->replay_counter
, key
->replay_counter
,
1450 WPA_REPLAY_COUNTER_LEN
);
1452 key_mic
= (u8
*) (reply
+ 1);
1453 WPA_PUT_BE16(key_mic
+ mic_len
, 0);
1455 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: Sending EAPOL-Key 4/4");
1456 return wpa_eapol_key_send(sm
, ptk
, ver
, dst
, ETH_P_EAPOL
, rbuf
, rlen
,
1461 static void wpa_supplicant_process_3_of_4(struct wpa_sm
*sm
,
1462 const struct wpa_eapol_key
*key
,
1463 u16 ver
, const u8
*key_data
,
1464 size_t key_data_len
)
1466 u16 key_info
, keylen
;
1467 struct wpa_eapol_ie_parse ie
;
1469 wpa_sm_set_state(sm
, WPA_4WAY_HANDSHAKE
);
1470 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: RX message 3 of 4-Way "
1471 "Handshake from " MACSTR
" (ver=%d)", MAC2STR(sm
->bssid
), ver
);
1473 key_info
= WPA_GET_BE16(key
->key_info
);
1475 wpa_hexdump(MSG_DEBUG
, "WPA: IE KeyData", key_data
, key_data_len
);
1476 if (wpa_supplicant_parse_ies(key_data
, key_data_len
, &ie
) < 0)
1478 if (ie
.gtk
&& !(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
1479 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1480 "WPA: GTK IE in unencrypted key data");
1483 if (ie
.igtk
&& !(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
1484 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1485 "WPA: IGTK KDE in unencrypted key data");
1490 wpa_cipher_valid_mgmt_group(sm
->mgmt_group_cipher
) &&
1491 ie
.igtk_len
!= WPA_IGTK_KDE_PREFIX_LEN
+
1492 (unsigned int) wpa_cipher_key_len(sm
->mgmt_group_cipher
)) {
1493 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1494 "WPA: Invalid IGTK KDE length %lu",
1495 (unsigned long) ie
.igtk_len
);
1499 if (wpa_supplicant_validate_ie(sm
, sm
->bssid
, &ie
) < 0)
1502 if (os_memcmp(sm
->anonce
, key
->key_nonce
, WPA_NONCE_LEN
) != 0) {
1503 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1504 "WPA: ANonce from message 1 of 4-Way Handshake "
1505 "differs from 3 of 4-Way Handshake - drop packet (src="
1506 MACSTR
")", MAC2STR(sm
->bssid
));
1510 keylen
= WPA_GET_BE16(key
->key_length
);
1511 if (keylen
!= wpa_cipher_key_len(sm
->pairwise_cipher
)) {
1512 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1513 "WPA: Invalid %s key length %d (src=" MACSTR
1514 ")", wpa_cipher_txt(sm
->pairwise_cipher
), keylen
,
1515 MAC2STR(sm
->bssid
));
1520 if (ie
.ip_addr_alloc
) {
1521 os_memcpy(sm
->p2p_ip_addr
, ie
.ip_addr_alloc
, 3 * 4);
1522 wpa_hexdump(MSG_DEBUG
, "P2P: IP address info",
1523 sm
->p2p_ip_addr
, sizeof(sm
->p2p_ip_addr
));
1525 #endif /* CONFIG_P2P */
1528 if (wpa_sm_ocv_enabled(sm
)) {
1529 struct wpa_channel_info ci
;
1531 if (wpa_sm_channel_info(sm
, &ci
) != 0) {
1532 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1533 "Failed to get channel info to validate received OCI in EAPOL-Key 3/4");
1537 if (ocv_verify_tx_params(ie
.oci
, ie
.oci_len
, &ci
,
1538 channel_width_to_int(ci
.chanwidth
),
1539 ci
.seg1_idx
) != 0) {
1540 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
, "%s",
1545 #endif /* CONFIG_OCV */
1547 if (wpa_supplicant_send_4_of_4(sm
, sm
->bssid
, key
, ver
, key_info
,
1552 /* SNonce was successfully used in msg 3/4, so mark it to be renewed
1553 * for the next 4-Way Handshake. If msg 3 is received again, the old
1554 * SNonce will still be used to avoid changing PTK. */
1555 sm
->renew_snonce
= 1;
1557 if (key_info
& WPA_KEY_INFO_INSTALL
) {
1558 if (wpa_supplicant_install_ptk(sm
, key
, KEY_FLAG_RX_TX
))
1562 if (key_info
& WPA_KEY_INFO_SECURE
) {
1563 wpa_sm_mlme_setprotection(
1564 sm
, sm
->bssid
, MLME_SETPROTECTION_PROTECT_TYPE_RX
,
1565 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
1566 eapol_sm_notify_portValid(sm
->eapol
, TRUE
);
1568 wpa_sm_set_state(sm
, WPA_GROUP_HANDSHAKE
);
1570 if (sm
->group_cipher
== WPA_CIPHER_GTK_NOT_USED
) {
1571 /* No GTK to be set to the driver */
1572 } else if (!ie
.gtk
&& sm
->proto
== WPA_PROTO_RSN
) {
1573 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1574 "RSN: No GTK KDE included in EAPOL-Key msg 3/4");
1576 } else if (ie
.gtk
&&
1577 wpa_supplicant_pairwise_gtk(sm
, key
,
1578 ie
.gtk
, ie
.gtk_len
, key_info
) < 0) {
1579 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1580 "RSN: Failed to configure GTK");
1584 if (ieee80211w_set_keys(sm
, &ie
) < 0) {
1585 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1586 "RSN: Failed to configure IGTK");
1590 if (sm
->group_cipher
== WPA_CIPHER_GTK_NOT_USED
|| ie
.gtk
)
1591 wpa_supplicant_key_neg_complete(sm
, sm
->bssid
,
1592 key_info
& WPA_KEY_INFO_SECURE
);
1595 wpa_sm_set_rekey_offload(sm
);
1597 /* Add PMKSA cache entry for Suite B AKMs here since PMKID can be
1598 * calculated only after KCK has been derived. Though, do not replace an
1599 * existing PMKSA entry after each 4-way handshake (i.e., new KCK/PMKID)
1600 * to avoid unnecessary changes of PMKID while continuing to use the
1602 if (sm
->proto
== WPA_PROTO_RSN
&& wpa_key_mgmt_suite_b(sm
->key_mgmt
) &&
1604 struct rsn_pmksa_cache_entry
*sa
;
1606 sa
= pmksa_cache_add(sm
->pmksa
, sm
->pmk
, sm
->pmk_len
, NULL
,
1607 sm
->ptk
.kck
, sm
->ptk
.kck_len
,
1608 sm
->bssid
, sm
->own_addr
,
1609 sm
->network_ctx
, sm
->key_mgmt
, NULL
);
1614 sm
->msg_3_of_4_ok
= 1;
1618 wpa_sm_deauthenticate(sm
, WLAN_REASON_UNSPECIFIED
);
1622 static int wpa_supplicant_process_1_of_2_rsn(struct wpa_sm
*sm
,
1626 struct wpa_gtk_data
*gd
)
1629 struct wpa_eapol_ie_parse ie
;
1631 wpa_hexdump_key(MSG_DEBUG
, "RSN: msg 1/2 key data",
1632 keydata
, keydatalen
);
1633 if (wpa_supplicant_parse_ies(keydata
, keydatalen
, &ie
) < 0)
1635 if (ie
.gtk
&& !(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
1636 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1637 "WPA: GTK IE in unencrypted key data");
1640 if (ie
.gtk
== NULL
) {
1641 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1642 "WPA: No GTK IE in Group Key msg 1/2");
1645 maxkeylen
= gd
->gtk_len
= ie
.gtk_len
- 2;
1648 if (wpa_sm_ocv_enabled(sm
)) {
1649 struct wpa_channel_info ci
;
1651 if (wpa_sm_channel_info(sm
, &ci
) != 0) {
1652 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1653 "Failed to get channel info to validate received OCI in EAPOL-Key group msg 1/2");
1657 if (ocv_verify_tx_params(ie
.oci
, ie
.oci_len
, &ci
,
1658 channel_width_to_int(ci
.chanwidth
),
1659 ci
.seg1_idx
) != 0) {
1660 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
, "%s",
1665 #endif /* CONFIG_OCV */
1667 if (wpa_supplicant_check_group_cipher(sm
, sm
->group_cipher
,
1668 gd
->gtk_len
, maxkeylen
,
1669 &gd
->key_rsc_len
, &gd
->alg
))
1672 wpa_hexdump_key(MSG_DEBUG
, "RSN: received GTK in group key handshake",
1673 ie
.gtk
, ie
.gtk_len
);
1674 gd
->keyidx
= ie
.gtk
[0] & 0x3;
1675 gd
->tx
= wpa_supplicant_gtk_tx_bit_workaround(sm
,
1676 !!(ie
.gtk
[0] & BIT(2)));
1677 if (ie
.gtk_len
- 2 > sizeof(gd
->gtk
)) {
1678 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1679 "RSN: Too long GTK in GTK IE (len=%lu)",
1680 (unsigned long) ie
.gtk_len
- 2);
1683 os_memcpy(gd
->gtk
, ie
.gtk
+ 2, ie
.gtk_len
- 2);
1685 if (ieee80211w_set_keys(sm
, &ie
) < 0)
1686 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1687 "RSN: Failed to configure IGTK");
1693 static int wpa_supplicant_process_1_of_2_wpa(struct wpa_sm
*sm
,
1694 const struct wpa_eapol_key
*key
,
1696 size_t key_data_len
, u16 key_info
,
1697 u16 ver
, struct wpa_gtk_data
*gd
)
1702 gtk_len
= WPA_GET_BE16(key
->key_length
);
1703 maxkeylen
= key_data_len
;
1704 if (ver
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
1705 if (maxkeylen
< 8) {
1706 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1707 "WPA: Too short maxkeylen (%lu)",
1708 (unsigned long) maxkeylen
);
1714 if (gtk_len
> maxkeylen
||
1715 wpa_supplicant_check_group_cipher(sm
, sm
->group_cipher
,
1717 &gd
->key_rsc_len
, &gd
->alg
))
1720 gd
->gtk_len
= gtk_len
;
1721 gd
->keyidx
= (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
) >>
1722 WPA_KEY_INFO_KEY_INDEX_SHIFT
;
1723 if (ver
== WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
&& sm
->ptk
.kek_len
== 16) {
1724 #ifdef CONFIG_NO_RC4
1725 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1726 "WPA: RC4 not supported in the build");
1728 #else /* CONFIG_NO_RC4 */
1730 if (key_data_len
> sizeof(gd
->gtk
)) {
1731 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1732 "WPA: RC4 key data too long (%lu)",
1733 (unsigned long) key_data_len
);
1736 os_memcpy(ek
, key
->key_iv
, 16);
1737 os_memcpy(ek
+ 16, sm
->ptk
.kek
, sm
->ptk
.kek_len
);
1738 os_memcpy(gd
->gtk
, key_data
, key_data_len
);
1739 if (rc4_skip(ek
, 32, 256, gd
->gtk
, key_data_len
)) {
1740 forced_memzero(ek
, sizeof(ek
));
1741 wpa_msg(sm
->ctx
->msg_ctx
, MSG_ERROR
,
1745 forced_memzero(ek
, sizeof(ek
));
1746 #endif /* CONFIG_NO_RC4 */
1747 } else if (ver
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
1748 if (maxkeylen
% 8) {
1749 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1750 "WPA: Unsupported AES-WRAP len %lu",
1751 (unsigned long) maxkeylen
);
1754 if (maxkeylen
> sizeof(gd
->gtk
)) {
1755 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1756 "WPA: AES-WRAP key data "
1757 "too long (keydatalen=%lu maxkeylen=%lu)",
1758 (unsigned long) key_data_len
,
1759 (unsigned long) maxkeylen
);
1762 if (aes_unwrap(sm
->ptk
.kek
, sm
->ptk
.kek_len
, maxkeylen
/ 8,
1763 key_data
, gd
->gtk
)) {
1764 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1765 "WPA: AES unwrap failed - could not decrypt "
1770 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1771 "WPA: Unsupported key_info type %d", ver
);
1774 gd
->tx
= wpa_supplicant_gtk_tx_bit_workaround(
1775 sm
, !!(key_info
& WPA_KEY_INFO_TXRX
));
1780 static int wpa_supplicant_send_2_of_2(struct wpa_sm
*sm
,
1781 const struct wpa_eapol_key
*key
,
1782 int ver
, u16 key_info
)
1784 size_t mic_len
, hdrlen
, rlen
;
1785 struct wpa_eapol_key
*reply
;
1790 if (wpa_sm_ocv_enabled(sm
))
1791 kde_len
= OCV_OCI_KDE_LEN
;
1792 #endif /* CONFIG_OCV */
1794 mic_len
= wpa_mic_len(sm
->key_mgmt
, sm
->pmk_len
);
1795 hdrlen
= sizeof(*reply
) + mic_len
+ 2;
1796 rbuf
= wpa_sm_alloc_eapol(sm
, IEEE802_1X_TYPE_EAPOL_KEY
, NULL
,
1797 hdrlen
+ kde_len
, &rlen
, (void *) &reply
);
1801 reply
->type
= (sm
->proto
== WPA_PROTO_RSN
||
1802 sm
->proto
== WPA_PROTO_OSEN
) ?
1803 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
1804 key_info
&= WPA_KEY_INFO_KEY_INDEX_MASK
;
1805 key_info
|= ver
| WPA_KEY_INFO_SECURE
;
1807 key_info
|= WPA_KEY_INFO_MIC
;
1809 key_info
|= WPA_KEY_INFO_ENCR_KEY_DATA
;
1810 WPA_PUT_BE16(reply
->key_info
, key_info
);
1811 if (sm
->proto
== WPA_PROTO_RSN
|| sm
->proto
== WPA_PROTO_OSEN
)
1812 WPA_PUT_BE16(reply
->key_length
, 0);
1814 os_memcpy(reply
->key_length
, key
->key_length
, 2);
1815 os_memcpy(reply
->replay_counter
, key
->replay_counter
,
1816 WPA_REPLAY_COUNTER_LEN
);
1818 key_mic
= (u8
*) (reply
+ 1);
1819 WPA_PUT_BE16(key_mic
+ mic_len
, kde_len
); /* Key Data Length */
1822 if (wpa_sm_ocv_enabled(sm
)) {
1823 struct wpa_channel_info ci
;
1826 if (wpa_sm_channel_info(sm
, &ci
) != 0) {
1827 wpa_printf(MSG_WARNING
,
1828 "Failed to get channel info for OCI element in EAPOL-Key 2/2");
1833 pos
= key_mic
+ mic_len
+ 2; /* Key Data */
1834 if (ocv_insert_oci_kde(&ci
, &pos
) < 0) {
1839 #endif /* CONFIG_OCV */
1841 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: Sending EAPOL-Key 2/2");
1842 return wpa_eapol_key_send(sm
, &sm
->ptk
, ver
, sm
->bssid
, ETH_P_EAPOL
,
1843 rbuf
, rlen
, key_mic
);
1847 static void wpa_supplicant_process_1_of_2(struct wpa_sm
*sm
,
1848 const unsigned char *src_addr
,
1849 const struct wpa_eapol_key
*key
,
1851 size_t key_data_len
, u16 ver
)
1855 struct wpa_gtk_data gd
;
1858 if (!sm
->msg_3_of_4_ok
&& !wpa_fils_is_completed(sm
)) {
1859 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
1860 "WPA: Group Key Handshake started prior to completion of 4-way handshake");
1864 os_memset(&gd
, 0, sizeof(gd
));
1866 rekey
= wpa_sm_get_state(sm
) == WPA_COMPLETED
;
1867 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: RX message 1 of Group Key "
1868 "Handshake from " MACSTR
" (ver=%d)", MAC2STR(src_addr
), ver
);
1870 key_info
= WPA_GET_BE16(key
->key_info
);
1872 if (sm
->proto
== WPA_PROTO_RSN
|| sm
->proto
== WPA_PROTO_OSEN
) {
1873 ret
= wpa_supplicant_process_1_of_2_rsn(sm
, key_data
,
1874 key_data_len
, key_info
,
1877 ret
= wpa_supplicant_process_1_of_2_wpa(sm
, key
, key_data
,
1879 key_info
, ver
, &gd
);
1882 wpa_sm_set_state(sm
, WPA_GROUP_HANDSHAKE
);
1887 key_rsc
= key
->key_rsc
;
1888 if (wpa_supplicant_rsc_relaxation(sm
, key
->key_rsc
))
1891 if (wpa_supplicant_install_gtk(sm
, &gd
, key_rsc
, 0) ||
1892 wpa_supplicant_send_2_of_2(sm
, key
, ver
, key_info
) < 0)
1894 forced_memzero(&gd
, sizeof(gd
));
1897 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
, "WPA: Group rekeying "
1898 "completed with " MACSTR
" [GTK=%s]",
1899 MAC2STR(sm
->bssid
), wpa_cipher_txt(sm
->group_cipher
));
1900 wpa_sm_cancel_auth_timeout(sm
);
1901 wpa_sm_set_state(sm
, WPA_COMPLETED
);
1903 wpa_supplicant_key_neg_complete(sm
, sm
->bssid
,
1905 WPA_KEY_INFO_SECURE
);
1908 wpa_sm_set_rekey_offload(sm
);
1913 forced_memzero(&gd
, sizeof(gd
));
1914 wpa_sm_deauthenticate(sm
, WLAN_REASON_UNSPECIFIED
);
1918 static int wpa_supplicant_verify_eapol_key_mic(struct wpa_sm
*sm
,
1919 struct wpa_eapol_key
*key
,
1921 const u8
*buf
, size_t len
)
1923 u8 mic
[WPA_EAPOL_KEY_MIC_MAX_LEN
];
1925 size_t mic_len
= wpa_mic_len(sm
->key_mgmt
, sm
->pmk_len
);
1927 os_memcpy(mic
, key
+ 1, mic_len
);
1929 os_memset(key
+ 1, 0, mic_len
);
1930 if (wpa_eapol_key_mic(sm
->tptk
.kck
, sm
->tptk
.kck_len
,
1932 ver
, buf
, len
, (u8
*) (key
+ 1)) < 0 ||
1933 os_memcmp_const(mic
, key
+ 1, mic_len
) != 0) {
1934 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1935 "WPA: Invalid EAPOL-Key MIC "
1936 "when using TPTK - ignoring TPTK");
1938 wpa_printf(MSG_INFO
,
1939 "TEST: Ignore Key MIC failure for fuzz testing");
1941 #endif /* TEST_FUZZ */
1945 #endif /* TEST_FUZZ */
1949 os_memcpy(&sm
->ptk
, &sm
->tptk
, sizeof(sm
->ptk
));
1950 os_memset(&sm
->tptk
, 0, sizeof(sm
->tptk
));
1952 * This assures the same TPTK in sm->tptk can never be
1953 * copied twice to sm->ptk as the new PTK. In
1954 * combination with the installed flag in the wpa_ptk
1955 * struct, this assures the same PTK is only installed
1958 sm
->renew_snonce
= 1;
1962 if (!ok
&& sm
->ptk_set
) {
1963 os_memset(key
+ 1, 0, mic_len
);
1964 if (wpa_eapol_key_mic(sm
->ptk
.kck
, sm
->ptk
.kck_len
,
1966 ver
, buf
, len
, (u8
*) (key
+ 1)) < 0 ||
1967 os_memcmp_const(mic
, key
+ 1, mic_len
) != 0) {
1968 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1969 "WPA: Invalid EAPOL-Key MIC - "
1972 wpa_printf(MSG_INFO
,
1973 "TEST: Ignore Key MIC failure for fuzz testing");
1974 goto continue_fuzz2
;
1975 #endif /* TEST_FUZZ */
1980 #endif /* TEST_FUZZ */
1985 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
1986 "WPA: Could not verify EAPOL-Key MIC - "
1991 os_memcpy(sm
->rx_replay_counter
, key
->replay_counter
,
1992 WPA_REPLAY_COUNTER_LEN
);
1993 sm
->rx_replay_counter_set
= 1;
1998 /* Decrypt RSN EAPOL-Key key data (RC4 or AES-WRAP) */
1999 static int wpa_supplicant_decrypt_key_data(struct wpa_sm
*sm
,
2000 struct wpa_eapol_key
*key
,
2001 size_t mic_len
, u16 ver
,
2002 u8
*key_data
, size_t *key_data_len
)
2004 wpa_hexdump(MSG_DEBUG
, "RSN: encrypted key data",
2005 key_data
, *key_data_len
);
2007 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2008 "WPA: PTK not available, cannot decrypt EAPOL-Key Key "
2013 /* Decrypt key data here so that this operation does not need
2014 * to be implemented separately for each message type. */
2015 if (ver
== WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
&& sm
->ptk
.kek_len
== 16) {
2016 #ifdef CONFIG_NO_RC4
2017 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2018 "WPA: RC4 not supported in the build");
2020 #else /* CONFIG_NO_RC4 */
2023 wpa_printf(MSG_DEBUG
, "WPA: Decrypt Key Data using RC4");
2024 os_memcpy(ek
, key
->key_iv
, 16);
2025 os_memcpy(ek
+ 16, sm
->ptk
.kek
, sm
->ptk
.kek_len
);
2026 if (rc4_skip(ek
, 32, 256, key_data
, *key_data_len
)) {
2027 forced_memzero(ek
, sizeof(ek
));
2028 wpa_msg(sm
->ctx
->msg_ctx
, MSG_ERROR
,
2032 forced_memzero(ek
, sizeof(ek
));
2033 #endif /* CONFIG_NO_RC4 */
2034 } else if (ver
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
||
2035 ver
== WPA_KEY_INFO_TYPE_AES_128_CMAC
||
2036 wpa_use_aes_key_wrap(sm
->key_mgmt
)) {
2039 wpa_printf(MSG_DEBUG
,
2040 "WPA: Decrypt Key Data using AES-UNWRAP (KEK length %u)",
2041 (unsigned int) sm
->ptk
.kek_len
);
2042 if (*key_data_len
< 8 || *key_data_len
% 8) {
2043 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2044 "WPA: Unsupported AES-WRAP len %u",
2045 (unsigned int) *key_data_len
);
2048 *key_data_len
-= 8; /* AES-WRAP adds 8 bytes */
2049 buf
= os_malloc(*key_data_len
);
2051 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2052 "WPA: No memory for AES-UNWRAP buffer");
2056 os_memset(buf
, 0x11, *key_data_len
);
2057 #endif /* TEST_FUZZ */
2058 if (aes_unwrap(sm
->ptk
.kek
, sm
->ptk
.kek_len
, *key_data_len
/ 8,
2061 wpa_printf(MSG_INFO
,
2062 "TEST: Ignore AES unwrap failure for fuzz testing");
2064 #endif /* TEST_FUZZ */
2065 bin_clear_free(buf
, *key_data_len
);
2066 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2067 "WPA: AES unwrap failed - "
2068 "could not decrypt EAPOL-Key key data");
2073 #endif /* TEST_FUZZ */
2074 os_memcpy(key_data
, buf
, *key_data_len
);
2075 bin_clear_free(buf
, *key_data_len
);
2076 WPA_PUT_BE16(((u8
*) (key
+ 1)) + mic_len
, *key_data_len
);
2078 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2079 "WPA: Unsupported key_info type %d", ver
);
2082 wpa_hexdump_key(MSG_DEBUG
, "WPA: decrypted EAPOL-Key key data",
2083 key_data
, *key_data_len
);
2089 * wpa_sm_aborted_cached - Notify WPA that PMKSA caching was aborted
2090 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2092 void wpa_sm_aborted_cached(struct wpa_sm
*sm
)
2094 if (sm
&& sm
->cur_pmksa
) {
2095 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2096 "RSN: Cancelling PMKSA caching attempt");
2097 sm
->cur_pmksa
= NULL
;
2102 static void wpa_eapol_key_dump(struct wpa_sm
*sm
,
2103 const struct wpa_eapol_key
*key
,
2104 unsigned int key_data_len
,
2105 const u8
*mic
, unsigned int mic_len
)
2107 #ifndef CONFIG_NO_STDOUT_DEBUG
2108 u16 key_info
= WPA_GET_BE16(key
->key_info
);
2110 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, " EAPOL-Key type=%d", key
->type
);
2111 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2112 " key_info 0x%x (ver=%d keyidx=%d rsvd=%d %s%s%s%s%s%s%s%s)",
2113 key_info
, key_info
& WPA_KEY_INFO_TYPE_MASK
,
2114 (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
) >>
2115 WPA_KEY_INFO_KEY_INDEX_SHIFT
,
2116 (key_info
& (BIT(13) | BIT(14) | BIT(15))) >> 13,
2117 key_info
& WPA_KEY_INFO_KEY_TYPE
? "Pairwise" : "Group",
2118 key_info
& WPA_KEY_INFO_INSTALL
? " Install" : "",
2119 key_info
& WPA_KEY_INFO_ACK
? " Ack" : "",
2120 key_info
& WPA_KEY_INFO_MIC
? " MIC" : "",
2121 key_info
& WPA_KEY_INFO_SECURE
? " Secure" : "",
2122 key_info
& WPA_KEY_INFO_ERROR
? " Error" : "",
2123 key_info
& WPA_KEY_INFO_REQUEST
? " Request" : "",
2124 key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
? " Encr" : "");
2125 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2126 " key_length=%u key_data_length=%u",
2127 WPA_GET_BE16(key
->key_length
), key_data_len
);
2128 wpa_hexdump(MSG_DEBUG
, " replay_counter",
2129 key
->replay_counter
, WPA_REPLAY_COUNTER_LEN
);
2130 wpa_hexdump(MSG_DEBUG
, " key_nonce", key
->key_nonce
, WPA_NONCE_LEN
);
2131 wpa_hexdump(MSG_DEBUG
, " key_iv", key
->key_iv
, 16);
2132 wpa_hexdump(MSG_DEBUG
, " key_rsc", key
->key_rsc
, 8);
2133 wpa_hexdump(MSG_DEBUG
, " key_id (reserved)", key
->key_id
, 8);
2134 wpa_hexdump(MSG_DEBUG
, " key_mic", mic
, mic_len
);
2135 #endif /* CONFIG_NO_STDOUT_DEBUG */
2140 static int wpa_supp_aead_decrypt(struct wpa_sm
*sm
, u8
*buf
, size_t buf_len
,
2141 size_t *key_data_len
)
2143 struct wpa_ptk
*ptk
;
2144 struct ieee802_1x_hdr
*hdr
;
2145 struct wpa_eapol_key
*key
;
2150 if (*key_data_len
< AES_BLOCK_SIZE
) {
2151 wpa_printf(MSG_INFO
, "No room for AES-SIV data in the frame");
2157 else if (sm
->ptk_set
)
2162 hdr
= (struct ieee802_1x_hdr
*) buf
;
2163 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
2164 pos
= (u8
*) (key
+ 1);
2165 pos
+= 2; /* Pointing at the Encrypted Key Data field */
2167 tmp
= os_malloc(*key_data_len
);
2171 /* AES-SIV AAD from EAPOL protocol version field (inclusive) to
2172 * to Key Data (exclusive). */
2174 aad_len
[0] = pos
- buf
;
2175 if (aes_siv_decrypt(ptk
->kek
, ptk
->kek_len
, pos
, *key_data_len
,
2176 1, aad
, aad_len
, tmp
) < 0) {
2177 wpa_printf(MSG_INFO
, "Invalid AES-SIV data in the frame");
2178 bin_clear_free(tmp
, *key_data_len
);
2182 /* AEAD decryption and validation completed successfully */
2183 (*key_data_len
) -= AES_BLOCK_SIZE
;
2184 wpa_hexdump_key(MSG_DEBUG
, "WPA: Decrypted Key Data",
2185 tmp
, *key_data_len
);
2187 /* Replace Key Data field with the decrypted version */
2188 os_memcpy(pos
, tmp
, *key_data_len
);
2189 pos
-= 2; /* Key Data Length field */
2190 WPA_PUT_BE16(pos
, *key_data_len
);
2191 bin_clear_free(tmp
, *key_data_len
);
2196 os_memcpy(&sm
->ptk
, &sm
->tptk
, sizeof(sm
->ptk
));
2197 os_memset(&sm
->tptk
, 0, sizeof(sm
->tptk
));
2200 os_memcpy(sm
->rx_replay_counter
, key
->replay_counter
,
2201 WPA_REPLAY_COUNTER_LEN
);
2202 sm
->rx_replay_counter_set
= 1;
2206 #endif /* CONFIG_FILS */
2210 * wpa_sm_rx_eapol - Process received WPA EAPOL frames
2211 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2212 * @src_addr: Source MAC address of the EAPOL packet
2213 * @buf: Pointer to the beginning of the EAPOL data (EAPOL header)
2214 * @len: Length of the EAPOL frame
2215 * Returns: 1 = WPA EAPOL-Key processed, 0 = not a WPA EAPOL-Key, -1 failure
2217 * This function is called for each received EAPOL frame. Other than EAPOL-Key
2218 * frames can be skipped if filtering is done elsewhere. wpa_sm_rx_eapol() is
2219 * only processing WPA and WPA2 EAPOL-Key frames.
2221 * The received EAPOL-Key packets are validated and valid packets are replied
2222 * to. In addition, key material (PTK, GTK) is configured at the end of a
2223 * successful key handshake.
2225 int wpa_sm_rx_eapol(struct wpa_sm
*sm
, const u8
*src_addr
,
2226 const u8
*buf
, size_t len
)
2228 size_t plen
, data_len
, key_data_len
;
2229 const struct ieee802_1x_hdr
*hdr
;
2230 struct wpa_eapol_key
*key
;
2235 size_t mic_len
, keyhdrlen
;
2237 #ifdef CONFIG_IEEE80211R
2238 sm
->ft_completed
= 0;
2239 #endif /* CONFIG_IEEE80211R */
2241 mic_len
= wpa_mic_len(sm
->key_mgmt
, sm
->pmk_len
);
2242 keyhdrlen
= sizeof(*key
) + mic_len
+ 2;
2244 if (len
< sizeof(*hdr
) + keyhdrlen
) {
2245 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2246 "WPA: EAPOL frame too short to be a WPA "
2247 "EAPOL-Key (len %lu, expecting at least %lu)",
2248 (unsigned long) len
,
2249 (unsigned long) sizeof(*hdr
) + keyhdrlen
);
2253 hdr
= (const struct ieee802_1x_hdr
*) buf
;
2254 plen
= be_to_host16(hdr
->length
);
2255 data_len
= plen
+ sizeof(*hdr
);
2256 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2257 "IEEE 802.1X RX: version=%d type=%d length=%lu",
2258 hdr
->version
, hdr
->type
, (unsigned long) plen
);
2260 if (hdr
->version
< EAPOL_VERSION
) {
2261 /* TODO: backwards compatibility */
2263 if (hdr
->type
!= IEEE802_1X_TYPE_EAPOL_KEY
) {
2264 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2265 "WPA: EAPOL frame (type %u) discarded, "
2266 "not a Key frame", hdr
->type
);
2270 wpa_hexdump(MSG_MSGDUMP
, "WPA: RX EAPOL-Key", buf
, len
);
2271 if (plen
> len
- sizeof(*hdr
) || plen
< keyhdrlen
) {
2272 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2273 "WPA: EAPOL frame payload size %lu "
2274 "invalid (frame size %lu)",
2275 (unsigned long) plen
, (unsigned long) len
);
2279 if (data_len
< len
) {
2280 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2281 "WPA: ignoring %lu bytes after the IEEE 802.1X data",
2282 (unsigned long) len
- data_len
);
2286 * Make a copy of the frame since we need to modify the buffer during
2287 * MAC validation and Key Data decryption.
2289 tmp
= os_memdup(buf
, data_len
);
2292 key
= (struct wpa_eapol_key
*) (tmp
+ sizeof(struct ieee802_1x_hdr
));
2293 mic
= (u8
*) (key
+ 1);
2294 key_data
= mic
+ mic_len
+ 2;
2296 if (key
->type
!= EAPOL_KEY_TYPE_WPA
&& key
->type
!= EAPOL_KEY_TYPE_RSN
)
2298 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2299 "WPA: EAPOL-Key type (%d) unknown, discarded",
2305 key_data_len
= WPA_GET_BE16(mic
+ mic_len
);
2306 wpa_eapol_key_dump(sm
, key
, key_data_len
, mic
, mic_len
);
2308 if (key_data_len
> plen
- keyhdrlen
) {
2309 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
, "WPA: Invalid EAPOL-Key "
2310 "frame - key_data overflow (%u > %u)",
2311 (unsigned int) key_data_len
,
2312 (unsigned int) (plen
- keyhdrlen
));
2316 eapol_sm_notify_lower_layer_success(sm
->eapol
, 0);
2317 key_info
= WPA_GET_BE16(key
->key_info
);
2318 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
2319 if (ver
!= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
&&
2320 ver
!= WPA_KEY_INFO_TYPE_AES_128_CMAC
&&
2321 ver
!= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
&&
2322 !wpa_use_akm_defined(sm
->key_mgmt
)) {
2323 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2324 "WPA: Unsupported EAPOL-Key descriptor version %d",
2329 if (wpa_use_akm_defined(sm
->key_mgmt
) &&
2330 ver
!= WPA_KEY_INFO_TYPE_AKM_DEFINED
) {
2331 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2332 "RSN: Unsupported EAPOL-Key descriptor version %d (expected AKM defined = 0)",
2337 #ifdef CONFIG_IEEE80211R
2338 if (wpa_key_mgmt_ft(sm
->key_mgmt
)) {
2339 /* IEEE 802.11r uses a new key_info type (AES-128-CMAC). */
2340 if (ver
!= WPA_KEY_INFO_TYPE_AES_128_CMAC
&&
2341 !wpa_use_akm_defined(sm
->key_mgmt
)) {
2342 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2343 "FT: AP did not use AES-128-CMAC");
2347 #endif /* CONFIG_IEEE80211R */
2348 if (wpa_key_mgmt_sha256(sm
->key_mgmt
)) {
2349 if (ver
!= WPA_KEY_INFO_TYPE_AES_128_CMAC
&&
2350 !wpa_use_akm_defined(sm
->key_mgmt
)) {
2351 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2352 "WPA: AP did not use the "
2353 "negotiated AES-128-CMAC");
2356 } else if (sm
->pairwise_cipher
== WPA_CIPHER_CCMP
&&
2357 !wpa_use_akm_defined(sm
->key_mgmt
) &&
2358 ver
!= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
2359 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2360 "WPA: CCMP is used, but EAPOL-Key "
2361 "descriptor version (%d) is not 2", ver
);
2362 if (sm
->group_cipher
!= WPA_CIPHER_CCMP
&&
2363 !(key_info
& WPA_KEY_INFO_KEY_TYPE
)) {
2364 /* Earlier versions of IEEE 802.11i did not explicitly
2365 * require version 2 descriptor for all EAPOL-Key
2366 * packets, so allow group keys to use version 1 if
2367 * CCMP is not used for them. */
2368 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2369 "WPA: Backwards compatibility: allow invalid "
2370 "version for non-CCMP group keys");
2371 } else if (ver
== WPA_KEY_INFO_TYPE_AES_128_CMAC
) {
2372 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2373 "WPA: Interoperability workaround: allow incorrect (should have been HMAC-SHA1), but stronger (is AES-128-CMAC), descriptor version to be used");
2376 } else if (sm
->pairwise_cipher
== WPA_CIPHER_GCMP
&&
2377 !wpa_use_akm_defined(sm
->key_mgmt
) &&
2378 ver
!= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
2379 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2380 "WPA: GCMP is used, but EAPOL-Key "
2381 "descriptor version (%d) is not 2", ver
);
2385 if (sm
->rx_replay_counter_set
&&
2386 os_memcmp(key
->replay_counter
, sm
->rx_replay_counter
,
2387 WPA_REPLAY_COUNTER_LEN
) <= 0) {
2388 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2389 "WPA: EAPOL-Key Replay Counter did not increase - "
2394 if (key_info
& WPA_KEY_INFO_SMK_MESSAGE
) {
2395 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2396 "WPA: Unsupported SMK bit in key_info");
2400 if (!(key_info
& WPA_KEY_INFO_ACK
)) {
2401 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2402 "WPA: No Ack bit in key_info");
2406 if (key_info
& WPA_KEY_INFO_REQUEST
) {
2407 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
2408 "WPA: EAPOL-Key with Request bit - dropped");
2412 if ((key_info
& WPA_KEY_INFO_MIC
) &&
2413 wpa_supplicant_verify_eapol_key_mic(sm
, key
, ver
, tmp
, data_len
))
2417 if (!mic_len
&& (key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
2418 if (wpa_supp_aead_decrypt(sm
, tmp
, data_len
, &key_data_len
))
2421 #endif /* CONFIG_FILS */
2423 if ((sm
->proto
== WPA_PROTO_RSN
|| sm
->proto
== WPA_PROTO_OSEN
) &&
2424 (key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
) && mic_len
) {
2426 * Only decrypt the Key Data field if the frame's authenticity
2427 * was verified. When using AES-SIV (FILS), the MIC flag is not
2428 * set, so this check should only be performed if mic_len != 0
2429 * which is the case in this code branch.
2431 if (!(key_info
& WPA_KEY_INFO_MIC
)) {
2432 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2433 "WPA: Ignore EAPOL-Key with encrypted but unauthenticated data");
2436 if (wpa_supplicant_decrypt_key_data(sm
, key
, mic_len
,
2442 if (key_info
& WPA_KEY_INFO_KEY_TYPE
) {
2443 if (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
) {
2444 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2445 "WPA: Ignored EAPOL-Key (Pairwise) with "
2446 "non-zero key index");
2449 if (key_info
& (WPA_KEY_INFO_MIC
|
2450 WPA_KEY_INFO_ENCR_KEY_DATA
)) {
2451 /* 3/4 4-Way Handshake */
2452 wpa_supplicant_process_3_of_4(sm
, key
, ver
, key_data
,
2455 /* 1/4 4-Way Handshake */
2456 wpa_supplicant_process_1_of_4(sm
, src_addr
, key
,
2461 if ((mic_len
&& (key_info
& WPA_KEY_INFO_MIC
)) ||
2462 (!mic_len
&& (key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
))) {
2463 /* 1/2 Group Key Handshake */
2464 wpa_supplicant_process_1_of_2(sm
, src_addr
, key
,
2465 key_data
, key_data_len
,
2468 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
2469 "WPA: EAPOL-Key (Group) without Mic/Encr bit - "
2477 bin_clear_free(tmp
, data_len
);
2482 #ifdef CONFIG_CTRL_IFACE
2483 static u32
wpa_key_mgmt_suite(struct wpa_sm
*sm
)
2485 switch (sm
->key_mgmt
) {
2486 case WPA_KEY_MGMT_IEEE8021X
:
2487 return ((sm
->proto
== WPA_PROTO_RSN
||
2488 sm
->proto
== WPA_PROTO_OSEN
) ?
2489 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
:
2490 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X
);
2491 case WPA_KEY_MGMT_PSK
:
2492 return (sm
->proto
== WPA_PROTO_RSN
?
2493 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
:
2494 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X
);
2495 #ifdef CONFIG_IEEE80211R
2496 case WPA_KEY_MGMT_FT_IEEE8021X
:
2497 return RSN_AUTH_KEY_MGMT_FT_802_1X
;
2498 case WPA_KEY_MGMT_FT_PSK
:
2499 return RSN_AUTH_KEY_MGMT_FT_PSK
;
2500 #endif /* CONFIG_IEEE80211R */
2501 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
2502 return RSN_AUTH_KEY_MGMT_802_1X_SHA256
;
2503 case WPA_KEY_MGMT_PSK_SHA256
:
2504 return RSN_AUTH_KEY_MGMT_PSK_SHA256
;
2505 case WPA_KEY_MGMT_CCKM
:
2506 return (sm
->proto
== WPA_PROTO_RSN
?
2507 RSN_AUTH_KEY_MGMT_CCKM
:
2508 WPA_AUTH_KEY_MGMT_CCKM
);
2509 case WPA_KEY_MGMT_WPA_NONE
:
2510 return WPA_AUTH_KEY_MGMT_NONE
;
2511 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
2512 return RSN_AUTH_KEY_MGMT_802_1X_SUITE_B
;
2513 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
2514 return RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192
;
2521 #define RSN_SUITE "%02x-%02x-%02x-%d"
2522 #define RSN_SUITE_ARG(s) \
2523 ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
2526 * wpa_sm_get_mib - Dump text list of MIB entries
2527 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2528 * @buf: Buffer for the list
2529 * @buflen: Length of the buffer
2530 * Returns: Number of bytes written to buffer
2532 * This function is used fetch dot11 MIB variables.
2534 int wpa_sm_get_mib(struct wpa_sm
*sm
, char *buf
, size_t buflen
)
2536 char pmkid_txt
[PMKID_LEN
* 2 + 1];
2540 if (sm
->cur_pmksa
) {
2541 wpa_snprintf_hex(pmkid_txt
, sizeof(pmkid_txt
),
2542 sm
->cur_pmksa
->pmkid
, PMKID_LEN
);
2544 pmkid_txt
[0] = '\0';
2546 if ((wpa_key_mgmt_wpa_psk(sm
->key_mgmt
) ||
2547 wpa_key_mgmt_wpa_ieee8021x(sm
->key_mgmt
)) &&
2548 sm
->proto
== WPA_PROTO_RSN
)
2553 ret
= os_snprintf(buf
, buflen
,
2554 "dot11RSNAOptionImplemented=TRUE\n"
2555 "dot11RSNAPreauthenticationImplemented=TRUE\n"
2556 "dot11RSNAEnabled=%s\n"
2557 "dot11RSNAPreauthenticationEnabled=%s\n"
2558 "dot11RSNAConfigVersion=%d\n"
2559 "dot11RSNAConfigPairwiseKeysSupported=5\n"
2560 "dot11RSNAConfigGroupCipherSize=%d\n"
2561 "dot11RSNAConfigPMKLifetime=%d\n"
2562 "dot11RSNAConfigPMKReauthThreshold=%d\n"
2563 "dot11RSNAConfigNumberOfPTKSAReplayCounters=1\n"
2564 "dot11RSNAConfigSATimeout=%d\n",
2565 rsna
? "TRUE" : "FALSE",
2566 rsna
? "TRUE" : "FALSE",
2568 wpa_cipher_key_len(sm
->group_cipher
) * 8,
2569 sm
->dot11RSNAConfigPMKLifetime
,
2570 sm
->dot11RSNAConfigPMKReauthThreshold
,
2571 sm
->dot11RSNAConfigSATimeout
);
2572 if (os_snprintf_error(buflen
, ret
))
2577 buf
+ len
, buflen
- len
,
2578 "dot11RSNAAuthenticationSuiteSelected=" RSN_SUITE
"\n"
2579 "dot11RSNAPairwiseCipherSelected=" RSN_SUITE
"\n"
2580 "dot11RSNAGroupCipherSelected=" RSN_SUITE
"\n"
2581 "dot11RSNAPMKIDUsed=%s\n"
2582 "dot11RSNAAuthenticationSuiteRequested=" RSN_SUITE
"\n"
2583 "dot11RSNAPairwiseCipherRequested=" RSN_SUITE
"\n"
2584 "dot11RSNAGroupCipherRequested=" RSN_SUITE
"\n"
2585 "dot11RSNAConfigNumberOfGTKSAReplayCounters=0\n"
2586 "dot11RSNA4WayHandshakeFailures=%u\n",
2587 RSN_SUITE_ARG(wpa_key_mgmt_suite(sm
)),
2588 RSN_SUITE_ARG(wpa_cipher_to_suite(sm
->proto
,
2589 sm
->pairwise_cipher
)),
2590 RSN_SUITE_ARG(wpa_cipher_to_suite(sm
->proto
,
2593 RSN_SUITE_ARG(wpa_key_mgmt_suite(sm
)),
2594 RSN_SUITE_ARG(wpa_cipher_to_suite(sm
->proto
,
2595 sm
->pairwise_cipher
)),
2596 RSN_SUITE_ARG(wpa_cipher_to_suite(sm
->proto
,
2598 sm
->dot11RSNA4WayHandshakeFailures
);
2599 if (!os_snprintf_error(buflen
- len
, ret
))
2604 #endif /* CONFIG_CTRL_IFACE */
2607 static void wpa_sm_pmksa_free_cb(struct rsn_pmksa_cache_entry
*entry
,
2608 void *ctx
, enum pmksa_free_reason reason
)
2610 struct wpa_sm
*sm
= ctx
;
2613 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "RSN: PMKSA cache entry free_cb: "
2614 MACSTR
" reason=%d", MAC2STR(entry
->aa
), reason
);
2616 if (sm
->cur_pmksa
== entry
) {
2617 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2618 "RSN: %s current PMKSA entry",
2619 reason
== PMKSA_REPLACE
? "replaced" : "removed");
2620 pmksa_cache_clear_current(sm
);
2623 * If an entry is simply being replaced, there's no need to
2624 * deauthenticate because it will be immediately re-added.
2625 * This happens when EAP authentication is completed again
2626 * (reauth or failed PMKSA caching attempt).
2628 if (reason
!= PMKSA_REPLACE
)
2632 if (reason
== PMKSA_EXPIRE
&&
2633 (sm
->pmk_len
== entry
->pmk_len
&&
2634 os_memcmp(sm
->pmk
, entry
->pmk
, sm
->pmk_len
) == 0)) {
2635 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2636 "RSN: deauthenticating due to expired PMK");
2637 pmksa_cache_clear_current(sm
);
2643 os_memset(sm
->pmk
, 0, sizeof(sm
->pmk
));
2644 wpa_sm_deauthenticate(sm
, WLAN_REASON_UNSPECIFIED
);
2650 * wpa_sm_init - Initialize WPA state machine
2651 * @ctx: Context pointer for callbacks; this needs to be an allocated buffer
2652 * Returns: Pointer to the allocated WPA state machine data
2654 * This function is used to allocate a new WPA state machine and the returned
2655 * value is passed to all WPA state machine calls.
2657 struct wpa_sm
* wpa_sm_init(struct wpa_sm_ctx
*ctx
)
2661 sm
= os_zalloc(sizeof(*sm
));
2664 dl_list_init(&sm
->pmksa_candidates
);
2665 sm
->renew_snonce
= 1;
2668 sm
->dot11RSNAConfigPMKLifetime
= 43200;
2669 sm
->dot11RSNAConfigPMKReauthThreshold
= 70;
2670 sm
->dot11RSNAConfigSATimeout
= 60;
2672 sm
->pmksa
= pmksa_cache_init(wpa_sm_pmksa_free_cb
, sm
, sm
);
2673 if (sm
->pmksa
== NULL
) {
2674 wpa_msg(sm
->ctx
->msg_ctx
, MSG_ERROR
,
2675 "RSN: PMKSA cache initialization failed");
2685 * wpa_sm_deinit - Deinitialize WPA state machine
2686 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2688 void wpa_sm_deinit(struct wpa_sm
*sm
)
2692 pmksa_cache_deinit(sm
->pmksa
);
2693 eloop_cancel_timeout(wpa_sm_start_preauth
, sm
, NULL
);
2694 eloop_cancel_timeout(wpa_sm_rekey_ptk
, sm
, NULL
);
2695 os_free(sm
->assoc_wpa_ie
);
2696 os_free(sm
->assoc_rsnxe
);
2697 os_free(sm
->ap_wpa_ie
);
2698 os_free(sm
->ap_rsn_ie
);
2699 os_free(sm
->ap_rsnxe
);
2702 #ifdef CONFIG_IEEE80211R
2703 os_free(sm
->assoc_resp_ies
);
2704 #endif /* CONFIG_IEEE80211R */
2705 #ifdef CONFIG_TESTING_OPTIONS
2706 wpabuf_free(sm
->test_assoc_ie
);
2707 #endif /* CONFIG_TESTING_OPTIONS */
2708 #ifdef CONFIG_FILS_SK_PFS
2709 crypto_ecdh_deinit(sm
->fils_ecdh
);
2710 #endif /* CONFIG_FILS_SK_PFS */
2712 wpabuf_free(sm
->fils_ft_ies
);
2713 #endif /* CONFIG_FILS */
2715 crypto_ecdh_deinit(sm
->owe_ecdh
);
2716 #endif /* CONFIG_OWE */
2718 wpabuf_clear_free(sm
->dpp_z
);
2719 #endif /* CONFIG_DPP2 */
2725 * wpa_sm_notify_assoc - Notify WPA state machine about association
2726 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2727 * @bssid: The BSSID of the new association
2729 * This function is called to let WPA state machine know that the connection
2732 void wpa_sm_notify_assoc(struct wpa_sm
*sm
, const u8
*bssid
)
2739 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
2740 "WPA: Association event - clear replay counter");
2741 os_memcpy(sm
->bssid
, bssid
, ETH_ALEN
);
2742 os_memset(sm
->rx_replay_counter
, 0, WPA_REPLAY_COUNTER_LEN
);
2743 sm
->rx_replay_counter_set
= 0;
2744 sm
->renew_snonce
= 1;
2745 if (os_memcmp(sm
->preauth_bssid
, bssid
, ETH_ALEN
) == 0)
2746 rsn_preauth_deinit(sm
);
2748 #ifdef CONFIG_IEEE80211R
2749 if (wpa_ft_is_completed(sm
)) {
2751 * Clear portValid to kick EAPOL state machine to re-enter
2752 * AUTHENTICATED state to get the EAPOL port Authorized.
2754 eapol_sm_notify_portValid(sm
->eapol
, FALSE
);
2755 wpa_supplicant_key_neg_complete(sm
, sm
->bssid
, 1);
2757 /* Prepare for the next transition */
2758 wpa_ft_prepare_auth_request(sm
, NULL
);
2761 sm
->ft_protocol
= 1;
2763 sm
->ft_protocol
= 0;
2765 #endif /* CONFIG_IEEE80211R */
2767 if (sm
->fils_completed
) {
2769 * Clear portValid to kick EAPOL state machine to re-enter
2770 * AUTHENTICATED state to get the EAPOL port Authorized.
2772 wpa_supplicant_key_neg_complete(sm
, sm
->bssid
, 1);
2775 #endif /* CONFIG_FILS */
2779 * IEEE 802.11, 8.4.10: Delete PTK SA on (re)association if
2780 * this is not part of a Fast BSS Transition.
2782 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: Clear old PTK");
2784 os_memset(&sm
->ptk
, 0, sizeof(sm
->ptk
));
2786 os_memset(&sm
->tptk
, 0, sizeof(sm
->tptk
));
2787 os_memset(&sm
->gtk
, 0, sizeof(sm
->gtk
));
2788 os_memset(&sm
->gtk_wnm_sleep
, 0, sizeof(sm
->gtk_wnm_sleep
));
2789 os_memset(&sm
->igtk
, 0, sizeof(sm
->igtk
));
2790 os_memset(&sm
->igtk_wnm_sleep
, 0, sizeof(sm
->igtk_wnm_sleep
));
2795 #endif /* CONFIG_TDLS */
2798 os_memset(sm
->p2p_ip_addr
, 0, sizeof(sm
->p2p_ip_addr
));
2799 #endif /* CONFIG_P2P */
2804 * wpa_sm_notify_disassoc - Notify WPA state machine about disassociation
2805 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2807 * This function is called to let WPA state machine know that the connection
2808 * was lost. This will abort any existing pre-authentication session.
2810 void wpa_sm_notify_disassoc(struct wpa_sm
*sm
)
2812 eloop_cancel_timeout(wpa_sm_start_preauth
, sm
, NULL
);
2813 eloop_cancel_timeout(wpa_sm_rekey_ptk
, sm
, NULL
);
2814 rsn_preauth_deinit(sm
);
2815 pmksa_cache_clear_current(sm
);
2816 if (wpa_sm_get_state(sm
) == WPA_4WAY_HANDSHAKE
)
2817 sm
->dot11RSNA4WayHandshakeFailures
++;
2819 wpa_tdls_disassoc(sm
);
2820 #endif /* CONFIG_TDLS */
2822 sm
->fils_completed
= 0;
2823 #endif /* CONFIG_FILS */
2824 #ifdef CONFIG_IEEE80211R
2825 sm
->ft_reassoc_completed
= 0;
2826 sm
->ft_protocol
= 0;
2827 #endif /* CONFIG_IEEE80211R */
2829 /* Keys are not needed in the WPA state machine anymore */
2832 sm
->msg_3_of_4_ok
= 0;
2833 os_memset(sm
->bssid
, 0, ETH_ALEN
);
2838 * wpa_sm_set_pmk - Set PMK
2839 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2841 * @pmk_len: The length of the new PMK in bytes
2842 * @pmkid: Calculated PMKID
2843 * @bssid: AA to add into PMKSA cache or %NULL to not cache the PMK
2845 * Configure the PMK for WPA state machine.
2847 void wpa_sm_set_pmk(struct wpa_sm
*sm
, const u8
*pmk
, size_t pmk_len
,
2848 const u8
*pmkid
, const u8
*bssid
)
2853 wpa_hexdump_key(MSG_DEBUG
, "WPA: Set PMK based on external data",
2855 sm
->pmk_len
= pmk_len
;
2856 os_memcpy(sm
->pmk
, pmk
, pmk_len
);
2858 #ifdef CONFIG_IEEE80211R
2859 /* Set XXKey to be PSK for FT key derivation */
2860 sm
->xxkey_len
= pmk_len
;
2861 os_memcpy(sm
->xxkey
, pmk
, pmk_len
);
2862 #endif /* CONFIG_IEEE80211R */
2865 pmksa_cache_add(sm
->pmksa
, pmk
, pmk_len
, pmkid
, NULL
, 0,
2866 bssid
, sm
->own_addr
,
2867 sm
->network_ctx
, sm
->key_mgmt
, NULL
);
2873 * wpa_sm_set_pmk_from_pmksa - Set PMK based on the current PMKSA
2874 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2876 * Take the PMK from the current PMKSA into use. If no PMKSA is active, the PMK
2879 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm
*sm
)
2884 if (sm
->cur_pmksa
) {
2885 wpa_hexdump_key(MSG_DEBUG
,
2886 "WPA: Set PMK based on current PMKSA",
2887 sm
->cur_pmksa
->pmk
, sm
->cur_pmksa
->pmk_len
);
2888 sm
->pmk_len
= sm
->cur_pmksa
->pmk_len
;
2889 os_memcpy(sm
->pmk
, sm
->cur_pmksa
->pmk
, sm
->pmk_len
);
2891 wpa_printf(MSG_DEBUG
, "WPA: No current PMKSA - clear PMK");
2893 os_memset(sm
->pmk
, 0, PMK_LEN_MAX
);
2899 * wpa_sm_set_fast_reauth - Set fast reauthentication (EAP) enabled/disabled
2900 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2901 * @fast_reauth: Whether fast reauthentication (EAP) is allowed
2903 void wpa_sm_set_fast_reauth(struct wpa_sm
*sm
, int fast_reauth
)
2906 sm
->fast_reauth
= fast_reauth
;
2911 * wpa_sm_set_scard_ctx - Set context pointer for smartcard callbacks
2912 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2913 * @scard_ctx: Context pointer for smartcard related callback functions
2915 void wpa_sm_set_scard_ctx(struct wpa_sm
*sm
, void *scard_ctx
)
2919 sm
->scard_ctx
= scard_ctx
;
2920 if (sm
->preauth_eapol
)
2921 eapol_sm_register_scard_ctx(sm
->preauth_eapol
, scard_ctx
);
2926 * wpa_sm_set_config - Notification of current configuration change
2927 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2928 * @config: Pointer to current network configuration
2930 * Notify WPA state machine that configuration has changed. config will be
2931 * stored as a backpointer to network configuration. This can be %NULL to clear
2932 * the stored pointed.
2934 void wpa_sm_set_config(struct wpa_sm
*sm
, struct rsn_supp_config
*config
)
2940 sm
->network_ctx
= config
->network_ctx
;
2941 sm
->allowed_pairwise_cipher
= config
->allowed_pairwise_cipher
;
2942 sm
->proactive_key_caching
= config
->proactive_key_caching
;
2943 sm
->eap_workaround
= config
->eap_workaround
;
2944 sm
->eap_conf_ctx
= config
->eap_conf_ctx
;
2946 os_memcpy(sm
->ssid
, config
->ssid
, config
->ssid_len
);
2947 sm
->ssid_len
= config
->ssid_len
;
2950 sm
->wpa_ptk_rekey
= config
->wpa_ptk_rekey
;
2951 sm
->p2p
= config
->p2p
;
2952 sm
->wpa_rsc_relaxation
= config
->wpa_rsc_relaxation
;
2953 sm
->owe_ptk_workaround
= config
->owe_ptk_workaround
;
2955 if (config
->fils_cache_id
) {
2956 sm
->fils_cache_id_set
= 1;
2957 os_memcpy(sm
->fils_cache_id
, config
->fils_cache_id
,
2960 sm
->fils_cache_id_set
= 0;
2962 sm
->beacon_prot
= config
->beacon_prot
;
2963 #endif /* CONFIG_FILS */
2965 sm
->network_ctx
= NULL
;
2966 sm
->allowed_pairwise_cipher
= 0;
2967 sm
->proactive_key_caching
= 0;
2968 sm
->eap_workaround
= 0;
2969 sm
->eap_conf_ctx
= NULL
;
2971 sm
->wpa_ptk_rekey
= 0;
2973 sm
->wpa_rsc_relaxation
= 0;
2974 sm
->owe_ptk_workaround
= 0;
2975 sm
->beacon_prot
= 0;
2981 * wpa_sm_set_own_addr - Set own MAC address
2982 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2983 * @addr: Own MAC address
2985 void wpa_sm_set_own_addr(struct wpa_sm
*sm
, const u8
*addr
)
2988 os_memcpy(sm
->own_addr
, addr
, ETH_ALEN
);
2993 * wpa_sm_set_ifname - Set network interface name
2994 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2995 * @ifname: Interface name
2996 * @bridge_ifname: Optional bridge interface name (for pre-auth)
2998 void wpa_sm_set_ifname(struct wpa_sm
*sm
, const char *ifname
,
2999 const char *bridge_ifname
)
3002 sm
->ifname
= ifname
;
3003 sm
->bridge_ifname
= bridge_ifname
;
3009 * wpa_sm_set_eapol - Set EAPOL state machine pointer
3010 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3011 * @eapol: Pointer to EAPOL state machine allocated with eapol_sm_init()
3013 void wpa_sm_set_eapol(struct wpa_sm
*sm
, struct eapol_sm
*eapol
)
3021 * wpa_sm_set_param - Set WPA state machine parameters
3022 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3023 * @param: Parameter field
3024 * @value: Parameter value
3025 * Returns: 0 on success, -1 on failure
3027 int wpa_sm_set_param(struct wpa_sm
*sm
, enum wpa_sm_conf_params param
,
3036 case RSNA_PMK_LIFETIME
:
3038 sm
->dot11RSNAConfigPMKLifetime
= value
;
3042 case RSNA_PMK_REAUTH_THRESHOLD
:
3043 if (value
> 0 && value
<= 100)
3044 sm
->dot11RSNAConfigPMKReauthThreshold
= value
;
3048 case RSNA_SA_TIMEOUT
:
3050 sm
->dot11RSNAConfigSATimeout
= value
;
3054 case WPA_PARAM_PROTO
:
3057 case WPA_PARAM_PAIRWISE
:
3058 sm
->pairwise_cipher
= value
;
3060 case WPA_PARAM_GROUP
:
3061 sm
->group_cipher
= value
;
3063 case WPA_PARAM_KEY_MGMT
:
3064 sm
->key_mgmt
= value
;
3066 case WPA_PARAM_MGMT_GROUP
:
3067 sm
->mgmt_group_cipher
= value
;
3069 case WPA_PARAM_RSN_ENABLED
:
3070 sm
->rsn_enabled
= value
;
3078 case WPA_PARAM_SAE_PWE
:
3079 sm
->sae_pwe
= value
;
3090 * wpa_sm_get_status - Get WPA state machine
3091 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3092 * @buf: Buffer for status information
3093 * @buflen: Maximum buffer length
3094 * @verbose: Whether to include verbose status information
3095 * Returns: Number of bytes written to buf.
3097 * Query WPA state machine for status information. This function fills in
3098 * a text area with current status information. If the buffer (buf) is not
3099 * large enough, status information will be truncated to fit the buffer.
3101 int wpa_sm_get_status(struct wpa_sm
*sm
, char *buf
, size_t buflen
,
3104 char *pos
= buf
, *end
= buf
+ buflen
;
3107 ret
= os_snprintf(pos
, end
- pos
,
3108 "pairwise_cipher=%s\n"
3111 wpa_cipher_txt(sm
->pairwise_cipher
),
3112 wpa_cipher_txt(sm
->group_cipher
),
3113 wpa_key_mgmt_txt(sm
->key_mgmt
, sm
->proto
));
3114 if (os_snprintf_error(end
- pos
, ret
))
3118 if (sm
->mfp
!= NO_MGMT_FRAME_PROTECTION
&& sm
->ap_rsn_ie
) {
3119 struct wpa_ie_data rsn
;
3120 if (wpa_parse_wpa_ie_rsn(sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
, &rsn
)
3122 rsn
.capabilities
& (WPA_CAPABILITY_MFPR
|
3123 WPA_CAPABILITY_MFPC
)) {
3124 ret
= os_snprintf(pos
, end
- pos
, "pmf=%d\n"
3125 "mgmt_group_cipher=%s\n",
3127 WPA_CAPABILITY_MFPR
) ? 2 : 1,
3129 sm
->mgmt_group_cipher
));
3130 if (os_snprintf_error(end
- pos
, ret
))
3140 int wpa_sm_pmf_enabled(struct wpa_sm
*sm
)
3142 struct wpa_ie_data rsn
;
3144 if (sm
->mfp
== NO_MGMT_FRAME_PROTECTION
|| !sm
->ap_rsn_ie
)
3147 if (wpa_parse_wpa_ie_rsn(sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
, &rsn
) >= 0 &&
3148 rsn
.capabilities
& (WPA_CAPABILITY_MFPR
| WPA_CAPABILITY_MFPC
))
3155 int wpa_sm_ocv_enabled(struct wpa_sm
*sm
)
3157 struct wpa_ie_data rsn
;
3159 if (!sm
->ocv
|| !sm
->ap_rsn_ie
)
3162 return wpa_parse_wpa_ie_rsn(sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
,
3164 (rsn
.capabilities
& WPA_CAPABILITY_OCVC
);
3169 * wpa_sm_set_assoc_wpa_ie_default - Generate own WPA/RSN IE from configuration
3170 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3171 * @wpa_ie: Pointer to buffer for WPA/RSN IE
3172 * @wpa_ie_len: Pointer to the length of the wpa_ie buffer
3173 * Returns: 0 on success, -1 on failure
3175 int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm
*sm
, u8
*wpa_ie
,
3183 #ifdef CONFIG_TESTING_OPTIONS
3184 if (sm
->test_assoc_ie
) {
3185 wpa_printf(MSG_DEBUG
,
3186 "TESTING: Replace association WPA/RSN IE");
3187 if (*wpa_ie_len
< wpabuf_len(sm
->test_assoc_ie
))
3189 os_memcpy(wpa_ie
, wpabuf_head(sm
->test_assoc_ie
),
3190 wpabuf_len(sm
->test_assoc_ie
));
3191 res
= wpabuf_len(sm
->test_assoc_ie
);
3193 #endif /* CONFIG_TESTING_OPTIONS */
3194 res
= wpa_gen_wpa_ie(sm
, wpa_ie
, *wpa_ie_len
);
3199 wpa_hexdump(MSG_DEBUG
, "WPA: Set own WPA IE default",
3200 wpa_ie
, *wpa_ie_len
);
3202 if (sm
->assoc_wpa_ie
== NULL
) {
3204 * Make a copy of the WPA/RSN IE so that 4-Way Handshake gets
3205 * the correct version of the IE even if PMKSA caching is
3206 * aborted (which would remove PMKID from IE generation).
3208 sm
->assoc_wpa_ie
= os_memdup(wpa_ie
, *wpa_ie_len
);
3209 if (sm
->assoc_wpa_ie
== NULL
)
3212 sm
->assoc_wpa_ie_len
= *wpa_ie_len
;
3214 wpa_hexdump(MSG_DEBUG
,
3215 "WPA: Leave previously set WPA IE default",
3216 sm
->assoc_wpa_ie
, sm
->assoc_wpa_ie_len
);
3224 * wpa_sm_set_assoc_wpa_ie - Set own WPA/RSN IE from (Re)AssocReq
3225 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3226 * @ie: Pointer to IE data (starting from id)
3228 * Returns: 0 on success, -1 on failure
3230 * Inform WPA state machine about the WPA/RSN IE used in (Re)Association
3231 * Request frame. The IE will be used to override the default value generated
3232 * with wpa_sm_set_assoc_wpa_ie_default().
3234 int wpa_sm_set_assoc_wpa_ie(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3239 os_free(sm
->assoc_wpa_ie
);
3240 if (ie
== NULL
|| len
== 0) {
3241 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3242 "WPA: clearing own WPA/RSN IE");
3243 sm
->assoc_wpa_ie
= NULL
;
3244 sm
->assoc_wpa_ie_len
= 0;
3246 wpa_hexdump(MSG_DEBUG
, "WPA: set own WPA/RSN IE", ie
, len
);
3247 sm
->assoc_wpa_ie
= os_memdup(ie
, len
);
3248 if (sm
->assoc_wpa_ie
== NULL
)
3251 sm
->assoc_wpa_ie_len
= len
;
3259 * wpa_sm_set_assoc_rsnxe_default - Generate own RSNXE from configuration
3260 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3261 * @rsnxe: Pointer to buffer for RSNXE
3262 * @rsnxe_len: Pointer to the length of the rsne buffer
3263 * Returns: 0 on success, -1 on failure
3265 int wpa_sm_set_assoc_rsnxe_default(struct wpa_sm
*sm
, u8
*rsnxe
,
3273 res
= wpa_gen_rsnxe(sm
, rsnxe
, *rsnxe_len
);
3278 wpa_hexdump(MSG_DEBUG
, "RSN: Set own RSNXE default", rsnxe
, *rsnxe_len
);
3280 if (sm
->assoc_rsnxe
) {
3281 wpa_hexdump(MSG_DEBUG
,
3282 "RSN: Leave previously set RSNXE default",
3283 sm
->assoc_rsnxe
, sm
->assoc_rsnxe_len
);
3284 } else if (*rsnxe_len
> 0) {
3286 * Make a copy of the RSNXE so that 4-Way Handshake gets the
3287 * correct version of the IE even if it gets changed.
3289 sm
->assoc_rsnxe
= os_memdup(rsnxe
, *rsnxe_len
);
3290 if (!sm
->assoc_rsnxe
)
3293 sm
->assoc_rsnxe_len
= *rsnxe_len
;
3301 * wpa_sm_set_assoc_rsnxe - Set own RSNXE from (Re)AssocReq
3302 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3303 * @ie: Pointer to IE data (starting from id)
3305 * Returns: 0 on success, -1 on failure
3307 * Inform WPA state machine about the RSNXE used in (Re)Association Request
3308 * frame. The IE will be used to override the default value generated
3309 * with wpa_sm_set_assoc_rsnxe_default().
3311 int wpa_sm_set_assoc_rsnxe(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3316 os_free(sm
->assoc_rsnxe
);
3317 if (!ie
|| len
== 0) {
3318 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3319 "RSN: clearing own RSNXE");
3320 sm
->assoc_rsnxe
= NULL
;
3321 sm
->assoc_rsnxe_len
= 0;
3323 wpa_hexdump(MSG_DEBUG
, "RSN: set own RSNXE", ie
, len
);
3324 sm
->assoc_rsnxe
= os_memdup(ie
, len
);
3325 if (!sm
->assoc_rsnxe
)
3328 sm
->assoc_rsnxe_len
= len
;
3336 * wpa_sm_set_ap_wpa_ie - Set AP WPA IE from Beacon/ProbeResp
3337 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3338 * @ie: Pointer to IE data (starting from id)
3340 * Returns: 0 on success, -1 on failure
3342 * Inform WPA state machine about the WPA IE used in Beacon / Probe Response
3345 int wpa_sm_set_ap_wpa_ie(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3350 os_free(sm
->ap_wpa_ie
);
3351 if (ie
== NULL
|| len
== 0) {
3352 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3353 "WPA: clearing AP WPA IE");
3354 sm
->ap_wpa_ie
= NULL
;
3355 sm
->ap_wpa_ie_len
= 0;
3357 wpa_hexdump(MSG_DEBUG
, "WPA: set AP WPA IE", ie
, len
);
3358 sm
->ap_wpa_ie
= os_memdup(ie
, len
);
3359 if (sm
->ap_wpa_ie
== NULL
)
3362 sm
->ap_wpa_ie_len
= len
;
3370 * wpa_sm_set_ap_rsn_ie - Set AP RSN IE from Beacon/ProbeResp
3371 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3372 * @ie: Pointer to IE data (starting from id)
3374 * Returns: 0 on success, -1 on failure
3376 * Inform WPA state machine about the RSN IE used in Beacon / Probe Response
3379 int wpa_sm_set_ap_rsn_ie(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3384 os_free(sm
->ap_rsn_ie
);
3385 if (ie
== NULL
|| len
== 0) {
3386 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3387 "WPA: clearing AP RSN IE");
3388 sm
->ap_rsn_ie
= NULL
;
3389 sm
->ap_rsn_ie_len
= 0;
3391 wpa_hexdump(MSG_DEBUG
, "WPA: set AP RSN IE", ie
, len
);
3392 sm
->ap_rsn_ie
= os_memdup(ie
, len
);
3393 if (sm
->ap_rsn_ie
== NULL
)
3396 sm
->ap_rsn_ie_len
= len
;
3404 * wpa_sm_set_ap_rsnxe - Set AP RSNXE from Beacon/ProbeResp
3405 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3406 * @ie: Pointer to IE data (starting from id)
3408 * Returns: 0 on success, -1 on failure
3410 * Inform WPA state machine about the RSNXE used in Beacon / Probe Response
3413 int wpa_sm_set_ap_rsnxe(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3418 os_free(sm
->ap_rsnxe
);
3419 if (!ie
|| len
== 0) {
3420 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: clearing AP RSNXE");
3421 sm
->ap_rsnxe
= NULL
;
3422 sm
->ap_rsnxe_len
= 0;
3424 wpa_hexdump(MSG_DEBUG
, "WPA: set AP RSNXE", ie
, len
);
3425 sm
->ap_rsnxe
= os_memdup(ie
, len
);
3429 sm
->ap_rsnxe_len
= len
;
3437 * wpa_sm_parse_own_wpa_ie - Parse own WPA/RSN IE
3438 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3439 * @data: Pointer to data area for parsing results
3440 * Returns: 0 on success, -1 if IE is not known, or -2 on parsing failure
3442 * Parse the contents of the own WPA or RSN IE from (Re)AssocReq and write the
3443 * parsed data into data.
3445 int wpa_sm_parse_own_wpa_ie(struct wpa_sm
*sm
, struct wpa_ie_data
*data
)
3450 if (sm
->assoc_wpa_ie
== NULL
) {
3451 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3452 "WPA: No WPA/RSN IE available from association info");
3455 if (wpa_parse_wpa_ie(sm
->assoc_wpa_ie
, sm
->assoc_wpa_ie_len
, data
))
3461 int wpa_sm_pmksa_cache_list(struct wpa_sm
*sm
, char *buf
, size_t len
)
3463 return pmksa_cache_list(sm
->pmksa
, buf
, len
);
3467 struct rsn_pmksa_cache_entry
* wpa_sm_pmksa_cache_head(struct wpa_sm
*sm
)
3469 return pmksa_cache_head(sm
->pmksa
);
3473 struct rsn_pmksa_cache_entry
*
3474 wpa_sm_pmksa_cache_add_entry(struct wpa_sm
*sm
,
3475 struct rsn_pmksa_cache_entry
* entry
)
3477 return pmksa_cache_add_entry(sm
->pmksa
, entry
);
3481 void wpa_sm_pmksa_cache_add(struct wpa_sm
*sm
, const u8
*pmk
, size_t pmk_len
,
3482 const u8
*pmkid
, const u8
*bssid
,
3483 const u8
*fils_cache_id
)
3485 sm
->cur_pmksa
= pmksa_cache_add(sm
->pmksa
, pmk
, pmk_len
, pmkid
, NULL
, 0,
3486 bssid
, sm
->own_addr
, sm
->network_ctx
,
3487 sm
->key_mgmt
, fils_cache_id
);
3491 int wpa_sm_pmksa_exists(struct wpa_sm
*sm
, const u8
*bssid
,
3492 const void *network_ctx
)
3494 return pmksa_cache_get(sm
->pmksa
, bssid
, NULL
, network_ctx
, 0) != NULL
;
3498 void wpa_sm_drop_sa(struct wpa_sm
*sm
)
3500 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: Clear old PMK and PTK");
3504 os_memset(sm
->pmk
, 0, sizeof(sm
->pmk
));
3505 os_memset(&sm
->ptk
, 0, sizeof(sm
->ptk
));
3506 os_memset(&sm
->tptk
, 0, sizeof(sm
->tptk
));
3507 os_memset(&sm
->gtk
, 0, sizeof(sm
->gtk
));
3508 os_memset(&sm
->gtk_wnm_sleep
, 0, sizeof(sm
->gtk_wnm_sleep
));
3509 os_memset(&sm
->igtk
, 0, sizeof(sm
->igtk
));
3510 os_memset(&sm
->igtk_wnm_sleep
, 0, sizeof(sm
->igtk_wnm_sleep
));
3511 #ifdef CONFIG_IEEE80211R
3512 os_memset(sm
->xxkey
, 0, sizeof(sm
->xxkey
));
3514 os_memset(sm
->pmk_r0
, 0, sizeof(sm
->pmk_r0
));
3516 os_memset(sm
->pmk_r1
, 0, sizeof(sm
->pmk_r1
));
3518 #endif /* CONFIG_IEEE80211R */
3522 int wpa_sm_has_ptk(struct wpa_sm
*sm
)
3530 int wpa_sm_has_ptk_installed(struct wpa_sm
*sm
)
3534 return sm
->ptk
.installed
;
3538 void wpa_sm_update_replay_ctr(struct wpa_sm
*sm
, const u8
*replay_ctr
)
3540 os_memcpy(sm
->rx_replay_counter
, replay_ctr
, WPA_REPLAY_COUNTER_LEN
);
3544 void wpa_sm_pmksa_cache_flush(struct wpa_sm
*sm
, void *network_ctx
)
3546 pmksa_cache_flush(sm
->pmksa
, network_ctx
, NULL
, 0);
3551 int wpa_wnmsleep_install_key(struct wpa_sm
*sm
, u8 subelem_id
, u8
*buf
)
3554 u8 keylen
; /* plaintext key len */
3557 if (subelem_id
== WNM_SLEEP_SUBELEM_GTK
) {
3558 struct wpa_gtk_data gd
;
3560 os_memset(&gd
, 0, sizeof(gd
));
3561 keylen
= wpa_cipher_key_len(sm
->group_cipher
);
3562 gd
.key_rsc_len
= wpa_cipher_rsc_len(sm
->group_cipher
);
3563 gd
.alg
= wpa_cipher_to_alg(sm
->group_cipher
);
3564 if (gd
.alg
== WPA_ALG_NONE
) {
3565 wpa_printf(MSG_DEBUG
, "Unsupported group cipher suite");
3570 keyinfo
= WPA_GET_LE16(buf
+ 2);
3571 gd
.gtk_len
= keylen
;
3572 if (gd
.gtk_len
!= buf
[4]) {
3573 wpa_printf(MSG_DEBUG
, "GTK len mismatch len %d vs %d",
3574 gd
.gtk_len
, buf
[4]);
3577 gd
.keyidx
= keyinfo
& 0x03; /* B0 - B1 */
3578 gd
.tx
= wpa_supplicant_gtk_tx_bit_workaround(
3579 sm
, !!(keyinfo
& WPA_KEY_INFO_TXRX
));
3581 os_memcpy(gd
.gtk
, buf
+ 13, gd
.gtk_len
);
3583 wpa_hexdump_key(MSG_DEBUG
, "Install GTK (WNM SLEEP)",
3584 gd
.gtk
, gd
.gtk_len
);
3585 if (wpa_supplicant_install_gtk(sm
, &gd
, key_rsc
, 1)) {
3586 forced_memzero(&gd
, sizeof(gd
));
3587 wpa_printf(MSG_DEBUG
, "Failed to install the GTK in "
3591 forced_memzero(&gd
, sizeof(gd
));
3592 } else if (subelem_id
== WNM_SLEEP_SUBELEM_IGTK
) {
3593 const struct wpa_igtk_kde
*igtk
;
3595 igtk
= (const struct wpa_igtk_kde
*) (buf
+ 2);
3596 if (wpa_supplicant_install_igtk(sm
, igtk
, 1) < 0)
3599 wpa_printf(MSG_DEBUG
, "Unknown element id");
3605 #endif /* CONFIG_WNM */
3610 int wpa_sm_get_p2p_ip_addr(struct wpa_sm
*sm
, u8
*buf
)
3612 if (sm
== NULL
|| WPA_GET_BE32(sm
->p2p_ip_addr
) == 0)
3614 os_memcpy(buf
, sm
->p2p_ip_addr
, 3 * 4);
3618 #endif /* CONFIG_P2P */
3621 void wpa_sm_set_rx_replay_ctr(struct wpa_sm
*sm
, const u8
*rx_replay_counter
)
3623 if (rx_replay_counter
== NULL
)
3626 os_memcpy(sm
->rx_replay_counter
, rx_replay_counter
,
3627 WPA_REPLAY_COUNTER_LEN
);
3628 sm
->rx_replay_counter_set
= 1;
3629 wpa_printf(MSG_DEBUG
, "Updated key replay counter");
3633 void wpa_sm_set_ptk_kck_kek(struct wpa_sm
*sm
,
3634 const u8
*ptk_kck
, size_t ptk_kck_len
,
3635 const u8
*ptk_kek
, size_t ptk_kek_len
)
3637 if (ptk_kck
&& ptk_kck_len
<= WPA_KCK_MAX_LEN
) {
3638 os_memcpy(sm
->ptk
.kck
, ptk_kck
, ptk_kck_len
);
3639 sm
->ptk
.kck_len
= ptk_kck_len
;
3640 wpa_printf(MSG_DEBUG
, "Updated PTK KCK");
3642 if (ptk_kek
&& ptk_kek_len
<= WPA_KEK_MAX_LEN
) {
3643 os_memcpy(sm
->ptk
.kek
, ptk_kek
, ptk_kek_len
);
3644 sm
->ptk
.kek_len
= ptk_kek_len
;
3645 wpa_printf(MSG_DEBUG
, "Updated PTK KEK");
3651 #ifdef CONFIG_TESTING_OPTIONS
3653 void wpa_sm_set_test_assoc_ie(struct wpa_sm
*sm
, struct wpabuf
*buf
)
3655 wpabuf_free(sm
->test_assoc_ie
);
3656 sm
->test_assoc_ie
= buf
;
3660 const u8
* wpa_sm_get_anonce(struct wpa_sm
*sm
)
3665 #endif /* CONFIG_TESTING_OPTIONS */
3668 unsigned int wpa_sm_get_key_mgmt(struct wpa_sm
*sm
)
3670 return sm
->key_mgmt
;
3676 struct wpabuf
* fils_build_auth(struct wpa_sm
*sm
, int dh_group
, const u8
*md
)
3678 struct wpabuf
*buf
= NULL
;
3679 struct wpabuf
*erp_msg
;
3680 struct wpabuf
*pub
= NULL
;
3682 erp_msg
= eapol_sm_build_erp_reauth_start(sm
->eapol
);
3683 if (!erp_msg
&& !sm
->cur_pmksa
) {
3684 wpa_printf(MSG_DEBUG
,
3685 "FILS: Neither ERP EAP-Initiate/Re-auth nor PMKSA cache entry is available - skip FILS");
3689 wpa_printf(MSG_DEBUG
, "FILS: Try to use FILS (erp=%d pmksa_cache=%d)",
3690 erp_msg
!= NULL
, sm
->cur_pmksa
!= NULL
);
3692 sm
->fils_completed
= 0;
3694 if (!sm
->assoc_wpa_ie
) {
3695 wpa_printf(MSG_INFO
, "FILS: No own RSN IE set for FILS");
3699 if (random_get_bytes(sm
->fils_nonce
, FILS_NONCE_LEN
) < 0 ||
3700 random_get_bytes(sm
->fils_session
, FILS_SESSION_LEN
) < 0)
3703 wpa_hexdump(MSG_DEBUG
, "FILS: Generated FILS Nonce",
3704 sm
->fils_nonce
, FILS_NONCE_LEN
);
3705 wpa_hexdump(MSG_DEBUG
, "FILS: Generated FILS Session",
3706 sm
->fils_session
, FILS_SESSION_LEN
);
3708 #ifdef CONFIG_FILS_SK_PFS
3709 sm
->fils_dh_group
= dh_group
;
3711 crypto_ecdh_deinit(sm
->fils_ecdh
);
3712 sm
->fils_ecdh
= crypto_ecdh_init(dh_group
);
3713 if (!sm
->fils_ecdh
) {
3714 wpa_printf(MSG_INFO
,
3715 "FILS: Could not initialize ECDH with group %d",
3719 pub
= crypto_ecdh_get_pubkey(sm
->fils_ecdh
, 1);
3722 wpa_hexdump_buf(MSG_DEBUG
, "FILS: Element (DH public key)",
3724 sm
->fils_dh_elem_len
= wpabuf_len(pub
);
3726 #endif /* CONFIG_FILS_SK_PFS */
3728 buf
= wpabuf_alloc(1000 + sm
->assoc_wpa_ie_len
+
3729 (pub
? wpabuf_len(pub
) : 0));
3733 /* Fields following the Authentication algorithm number field */
3735 /* Authentication Transaction seq# */
3736 wpabuf_put_le16(buf
, 1);
3739 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
3742 #ifdef CONFIG_FILS_SK_PFS
3744 /* Finite Cyclic Group */
3745 wpabuf_put_le16(buf
, dh_group
);
3747 wpabuf_put_buf(buf
, pub
);
3749 #endif /* CONFIG_FILS_SK_PFS */
3752 wpa_hexdump(MSG_DEBUG
, "FILS: RSNE in FILS Authentication frame",
3753 sm
->assoc_wpa_ie
, sm
->assoc_wpa_ie_len
);
3754 wpabuf_put_data(buf
, sm
->assoc_wpa_ie
, sm
->assoc_wpa_ie_len
);
3757 /* MDE when using FILS for FT initial association */
3758 struct rsn_mdie
*mdie
;
3760 wpabuf_put_u8(buf
, WLAN_EID_MOBILITY_DOMAIN
);
3761 wpabuf_put_u8(buf
, sizeof(*mdie
));
3762 mdie
= wpabuf_put(buf
, sizeof(*mdie
));
3763 os_memcpy(mdie
->mobility_domain
, md
, MOBILITY_DOMAIN_ID_LEN
);
3768 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
3769 wpabuf_put_u8(buf
, 1 + FILS_NONCE_LEN
); /* Length */
3770 /* Element ID Extension */
3771 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_NONCE
);
3772 wpabuf_put_data(buf
, sm
->fils_nonce
, FILS_NONCE_LEN
);
3775 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
3776 wpabuf_put_u8(buf
, 1 + FILS_SESSION_LEN
); /* Length */
3777 /* Element ID Extension */
3778 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_SESSION
);
3779 wpabuf_put_data(buf
, sm
->fils_session
, FILS_SESSION_LEN
);
3781 /* FILS Wrapped Data */
3782 sm
->fils_erp_pmkid_set
= 0;
3784 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
3785 wpabuf_put_u8(buf
, 1 + wpabuf_len(erp_msg
)); /* Length */
3786 /* Element ID Extension */
3787 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_WRAPPED_DATA
);
3788 wpabuf_put_buf(buf
, erp_msg
);
3789 /* Calculate pending PMKID here so that we do not need to
3790 * maintain a copy of the EAP-Initiate/Reauth message. */
3791 if (fils_pmkid_erp(sm
->key_mgmt
, wpabuf_head(erp_msg
),
3792 wpabuf_len(erp_msg
),
3793 sm
->fils_erp_pmkid
) == 0)
3794 sm
->fils_erp_pmkid_set
= 1;
3797 wpa_hexdump_buf(MSG_DEBUG
, "RSN: FILS fields for Authentication frame",
3801 wpabuf_free(erp_msg
);
3807 int fils_process_auth(struct wpa_sm
*sm
, const u8
*bssid
, const u8
*data
,
3810 const u8
*pos
, *end
;
3811 struct ieee802_11_elems elems
;
3812 struct wpa_ie_data rsn
;
3813 int pmkid_match
= 0;
3814 u8 ick
[FILS_ICK_MAX_LEN
];
3817 struct wpabuf
*dh_ss
= NULL
;
3818 const u8
*g_sta
= NULL
;
3819 size_t g_sta_len
= 0;
3820 const u8
*g_ap
= NULL
;
3821 size_t g_ap_len
= 0;
3822 struct wpabuf
*pub
= NULL
;
3824 os_memcpy(sm
->bssid
, bssid
, ETH_ALEN
);
3826 wpa_hexdump(MSG_DEBUG
, "FILS: Authentication frame fields",
3832 #ifdef CONFIG_FILS_SK_PFS
3833 if (sm
->fils_dh_group
) {
3836 /* Using FILS PFS */
3838 /* Finite Cyclic Group */
3839 if (end
- pos
< 2) {
3840 wpa_printf(MSG_DEBUG
,
3841 "FILS: No room for Finite Cyclic Group");
3844 group
= WPA_GET_LE16(pos
);
3846 if (group
!= sm
->fils_dh_group
) {
3847 wpa_printf(MSG_DEBUG
,
3848 "FILS: Unexpected change in Finite Cyclic Group: %u (expected %u)",
3849 group
, sm
->fils_dh_group
);
3854 if ((size_t) (end
- pos
) < sm
->fils_dh_elem_len
) {
3855 wpa_printf(MSG_DEBUG
, "FILS: No room for Element");
3859 if (!sm
->fils_ecdh
) {
3860 wpa_printf(MSG_DEBUG
, "FILS: No ECDH state available");
3863 dh_ss
= crypto_ecdh_set_peerkey(sm
->fils_ecdh
, 1, pos
,
3864 sm
->fils_dh_elem_len
);
3866 wpa_printf(MSG_DEBUG
, "FILS: ECDH operation failed");
3869 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: DH_SS", dh_ss
);
3871 g_ap_len
= sm
->fils_dh_elem_len
;
3872 pos
+= sm
->fils_dh_elem_len
;
3874 #endif /* CONFIG_FILS_SK_PFS */
3876 wpa_hexdump(MSG_DEBUG
, "FILS: Remaining IEs", pos
, end
- pos
);
3877 if (ieee802_11_parse_elems(pos
, end
- pos
, &elems
, 1) == ParseFailed
) {
3878 wpa_printf(MSG_DEBUG
, "FILS: Could not parse elements");
3883 wpa_hexdump(MSG_DEBUG
, "FILS: RSN element", elems
.rsn_ie
,
3885 if (!elems
.rsn_ie
||
3886 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
3888 wpa_printf(MSG_DEBUG
, "FILS: No RSN element");
3892 if (!elems
.fils_nonce
) {
3893 wpa_printf(MSG_DEBUG
, "FILS: No FILS Nonce field");
3896 os_memcpy(sm
->fils_anonce
, elems
.fils_nonce
, FILS_NONCE_LEN
);
3897 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce", sm
->fils_anonce
, FILS_NONCE_LEN
);
3899 #ifdef CONFIG_IEEE80211R
3900 if (wpa_key_mgmt_ft(sm
->key_mgmt
)) {
3901 struct wpa_ft_ies parse
;
3903 if (!elems
.mdie
|| !elems
.ftie
) {
3904 wpa_printf(MSG_DEBUG
, "FILS+FT: No MDE or FTE");
3908 if (wpa_ft_parse_ies(pos
, end
- pos
, &parse
,
3909 wpa_key_mgmt_sha384(sm
->key_mgmt
)) < 0) {
3910 wpa_printf(MSG_DEBUG
, "FILS+FT: Failed to parse IEs");
3914 if (!parse
.r0kh_id
) {
3915 wpa_printf(MSG_DEBUG
,
3916 "FILS+FT: No R0KH-ID subelem in FTE");
3919 os_memcpy(sm
->r0kh_id
, parse
.r0kh_id
, parse
.r0kh_id_len
);
3920 sm
->r0kh_id_len
= parse
.r0kh_id_len
;
3921 wpa_hexdump_ascii(MSG_DEBUG
, "FILS+FT: R0KH-ID",
3922 sm
->r0kh_id
, sm
->r0kh_id_len
);
3924 if (!parse
.r1kh_id
) {
3925 wpa_printf(MSG_DEBUG
,
3926 "FILS+FT: No R1KH-ID subelem in FTE");
3929 os_memcpy(sm
->r1kh_id
, parse
.r1kh_id
, FT_R1KH_ID_LEN
);
3930 wpa_hexdump(MSG_DEBUG
, "FILS+FT: R1KH-ID",
3931 sm
->r1kh_id
, FT_R1KH_ID_LEN
);
3933 /* TODO: Check MDE and FTE payload */
3935 wpabuf_free(sm
->fils_ft_ies
);
3936 sm
->fils_ft_ies
= wpabuf_alloc(2 + elems
.mdie_len
+
3937 2 + elems
.ftie_len
);
3938 if (!sm
->fils_ft_ies
)
3940 wpabuf_put_data(sm
->fils_ft_ies
, elems
.mdie
- 2,
3941 2 + elems
.mdie_len
);
3942 wpabuf_put_data(sm
->fils_ft_ies
, elems
.ftie
- 2,
3943 2 + elems
.ftie_len
);
3945 wpabuf_free(sm
->fils_ft_ies
);
3946 sm
->fils_ft_ies
= NULL
;
3948 #endif /* CONFIG_IEEE80211R */
3951 if (rsn
.pmkid
&& rsn
.num_pmkid
> 0) {
3952 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID List",
3953 rsn
.pmkid
, rsn
.num_pmkid
* PMKID_LEN
);
3955 if (rsn
.num_pmkid
!= 1) {
3956 wpa_printf(MSG_DEBUG
, "FILS: Invalid PMKID selection");
3959 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", rsn
.pmkid
, PMKID_LEN
);
3960 if (os_memcmp(sm
->cur_pmksa
->pmkid
, rsn
.pmkid
, PMKID_LEN
) != 0)
3962 wpa_printf(MSG_DEBUG
, "FILS: PMKID mismatch");
3963 wpa_hexdump(MSG_DEBUG
, "FILS: Expected PMKID",
3964 sm
->cur_pmksa
->pmkid
, PMKID_LEN
);
3967 wpa_printf(MSG_DEBUG
,
3968 "FILS: Matching PMKID - continue using PMKSA caching");
3971 if (!pmkid_match
&& sm
->cur_pmksa
) {
3972 wpa_printf(MSG_DEBUG
,
3973 "FILS: No PMKID match - cannot use cached PMKSA entry");
3974 sm
->cur_pmksa
= NULL
;
3978 if (!elems
.fils_session
) {
3979 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
3982 wpa_hexdump(MSG_DEBUG
, "FILS: FILS Session", elems
.fils_session
,
3984 if (os_memcmp(sm
->fils_session
, elems
.fils_session
, FILS_SESSION_LEN
)
3986 wpa_printf(MSG_DEBUG
, "FILS: Session mismatch");
3987 wpa_hexdump(MSG_DEBUG
, "FILS: Expected FILS Session",
3988 sm
->fils_session
, FILS_SESSION_LEN
);
3992 /* FILS Wrapped Data */
3993 if (!sm
->cur_pmksa
&& elems
.fils_wrapped_data
) {
3994 u8 rmsk
[ERP_MAX_KEY_LEN
];
3997 wpa_hexdump(MSG_DEBUG
, "FILS: Wrapped Data",
3998 elems
.fils_wrapped_data
,
3999 elems
.fils_wrapped_data_len
);
4000 eapol_sm_process_erp_finish(sm
->eapol
, elems
.fils_wrapped_data
,
4001 elems
.fils_wrapped_data_len
);
4002 if (eapol_sm_failed(sm
->eapol
))
4005 rmsk_len
= ERP_MAX_KEY_LEN
;
4006 res
= eapol_sm_get_key(sm
->eapol
, rmsk
, rmsk_len
);
4007 if (res
== PMK_LEN
) {
4009 res
= eapol_sm_get_key(sm
->eapol
, rmsk
, rmsk_len
);
4014 res
= fils_rmsk_to_pmk(sm
->key_mgmt
, rmsk
, rmsk_len
,
4015 sm
->fils_nonce
, sm
->fils_anonce
,
4016 dh_ss
? wpabuf_head(dh_ss
) : NULL
,
4017 dh_ss
? wpabuf_len(dh_ss
) : 0,
4018 sm
->pmk
, &sm
->pmk_len
);
4019 forced_memzero(rmsk
, sizeof(rmsk
));
4021 /* Don't use DHss in PTK derivation if PMKSA caching is not
4023 wpabuf_clear_free(dh_ss
);
4029 if (!sm
->fils_erp_pmkid_set
) {
4030 wpa_printf(MSG_DEBUG
, "FILS: PMKID not available");
4033 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", sm
->fils_erp_pmkid
,
4035 wpa_printf(MSG_DEBUG
, "FILS: ERP processing succeeded - add PMKSA cache entry for the result");
4036 sm
->cur_pmksa
= pmksa_cache_add(sm
->pmksa
, sm
->pmk
, sm
->pmk_len
,
4037 sm
->fils_erp_pmkid
, NULL
, 0,
4038 sm
->bssid
, sm
->own_addr
,
4039 sm
->network_ctx
, sm
->key_mgmt
,
4043 if (!sm
->cur_pmksa
) {
4044 wpa_printf(MSG_DEBUG
,
4045 "FILS: No remaining options to continue FILS authentication");
4049 if (fils_pmk_to_ptk(sm
->pmk
, sm
->pmk_len
, sm
->own_addr
, sm
->bssid
,
4050 sm
->fils_nonce
, sm
->fils_anonce
,
4051 dh_ss
? wpabuf_head(dh_ss
) : NULL
,
4052 dh_ss
? wpabuf_len(dh_ss
) : 0,
4053 &sm
->ptk
, ick
, &ick_len
,
4054 sm
->key_mgmt
, sm
->pairwise_cipher
,
4055 sm
->fils_ft
, &sm
->fils_ft_len
) < 0) {
4056 wpa_printf(MSG_DEBUG
, "FILS: Failed to derive PTK");
4060 wpabuf_clear_free(dh_ss
);
4065 os_memset(&sm
->tptk
, 0, sizeof(sm
->tptk
));
4067 #ifdef CONFIG_FILS_SK_PFS
4068 if (sm
->fils_dh_group
) {
4069 if (!sm
->fils_ecdh
) {
4070 wpa_printf(MSG_INFO
, "FILS: ECDH not initialized");
4073 pub
= crypto_ecdh_get_pubkey(sm
->fils_ecdh
, 1);
4076 wpa_hexdump_buf(MSG_DEBUG
, "FILS: gSTA", pub
);
4077 g_sta
= wpabuf_head(pub
);
4078 g_sta_len
= wpabuf_len(pub
);
4080 wpa_printf(MSG_INFO
, "FILS: gAP not available");
4083 wpa_hexdump(MSG_DEBUG
, "FILS: gAP", g_ap
, g_ap_len
);
4085 #endif /* CONFIG_FILS_SK_PFS */
4087 res
= fils_key_auth_sk(ick
, ick_len
, sm
->fils_nonce
,
4088 sm
->fils_anonce
, sm
->own_addr
, sm
->bssid
,
4089 g_sta
, g_sta_len
, g_ap
, g_ap_len
,
4090 sm
->key_mgmt
, sm
->fils_key_auth_sta
,
4091 sm
->fils_key_auth_ap
,
4092 &sm
->fils_key_auth_len
);
4094 forced_memzero(ick
, sizeof(ick
));
4098 wpabuf_clear_free(dh_ss
);
4103 #ifdef CONFIG_IEEE80211R
4104 static int fils_ft_build_assoc_req_rsne(struct wpa_sm
*sm
, struct wpabuf
*buf
)
4106 struct rsn_ie_hdr
*rsnie
;
4109 int use_sha384
= wpa_key_mgmt_sha384(sm
->key_mgmt
);
4111 /* RSNIE[PMKR0Name/PMKR1Name] */
4112 rsnie
= wpabuf_put(buf
, sizeof(*rsnie
));
4113 rsnie
->elem_id
= WLAN_EID_RSN
;
4114 WPA_PUT_LE16(rsnie
->version
, RSN_VERSION
);
4116 /* Group Suite Selector */
4117 if (!wpa_cipher_valid_group(sm
->group_cipher
)) {
4118 wpa_printf(MSG_WARNING
, "FT: Invalid group cipher (%d)",
4122 pos
= wpabuf_put(buf
, RSN_SELECTOR_LEN
);
4123 RSN_SELECTOR_PUT(pos
, wpa_cipher_to_suite(WPA_PROTO_RSN
,
4126 /* Pairwise Suite Count */
4127 wpabuf_put_le16(buf
, 1);
4129 /* Pairwise Suite List */
4130 if (!wpa_cipher_valid_pairwise(sm
->pairwise_cipher
)) {
4131 wpa_printf(MSG_WARNING
, "FT: Invalid pairwise cipher (%d)",
4132 sm
->pairwise_cipher
);
4135 pos
= wpabuf_put(buf
, RSN_SELECTOR_LEN
);
4136 RSN_SELECTOR_PUT(pos
, wpa_cipher_to_suite(WPA_PROTO_RSN
,
4137 sm
->pairwise_cipher
));
4139 /* Authenticated Key Management Suite Count */
4140 wpabuf_put_le16(buf
, 1);
4142 /* Authenticated Key Management Suite List */
4143 pos
= wpabuf_put(buf
, RSN_SELECTOR_LEN
);
4144 if (sm
->key_mgmt
== WPA_KEY_MGMT_FT_FILS_SHA256
)
4145 RSN_SELECTOR_PUT(pos
, RSN_AUTH_KEY_MGMT_FT_FILS_SHA256
);
4146 else if (sm
->key_mgmt
== WPA_KEY_MGMT_FT_FILS_SHA384
)
4147 RSN_SELECTOR_PUT(pos
, RSN_AUTH_KEY_MGMT_FT_FILS_SHA384
);
4149 wpa_printf(MSG_WARNING
,
4150 "FILS+FT: Invalid key management type (%d)",
4155 /* RSN Capabilities */
4158 capab
|= WPA_CAPABILITY_MFPC
;
4160 capab
|= WPA_CAPABILITY_MFPR
;
4162 capab
|= WPA_CAPABILITY_OCVC
;
4163 wpabuf_put_le16(buf
, capab
);
4166 wpabuf_put_le16(buf
, 1);
4168 /* PMKID List [PMKR1Name] */
4169 wpa_hexdump_key(MSG_DEBUG
, "FILS+FT: XXKey (FILS-FT)",
4170 sm
->fils_ft
, sm
->fils_ft_len
);
4171 wpa_hexdump_ascii(MSG_DEBUG
, "FILS+FT: SSID", sm
->ssid
, sm
->ssid_len
);
4172 wpa_hexdump(MSG_DEBUG
, "FILS+FT: MDID",
4173 sm
->mobility_domain
, MOBILITY_DOMAIN_ID_LEN
);
4174 wpa_hexdump_ascii(MSG_DEBUG
, "FILS+FT: R0KH-ID",
4175 sm
->r0kh_id
, sm
->r0kh_id_len
);
4176 if (wpa_derive_pmk_r0(sm
->fils_ft
, sm
->fils_ft_len
, sm
->ssid
,
4177 sm
->ssid_len
, sm
->mobility_domain
,
4178 sm
->r0kh_id
, sm
->r0kh_id_len
, sm
->own_addr
,
4179 sm
->pmk_r0
, sm
->pmk_r0_name
, use_sha384
) < 0) {
4180 wpa_printf(MSG_WARNING
, "FILS+FT: Could not derive PMK-R0");
4183 sm
->pmk_r0_len
= use_sha384
? SHA384_MAC_LEN
: PMK_LEN
;
4184 wpa_hexdump_key(MSG_DEBUG
, "FILS+FT: PMK-R0",
4185 sm
->pmk_r0
, sm
->pmk_r0_len
);
4186 wpa_hexdump(MSG_DEBUG
, "FILS+FT: PMKR0Name",
4187 sm
->pmk_r0_name
, WPA_PMK_NAME_LEN
);
4188 wpa_printf(MSG_DEBUG
, "FILS+FT: R1KH-ID: " MACSTR
,
4189 MAC2STR(sm
->r1kh_id
));
4190 pos
= wpabuf_put(buf
, WPA_PMK_NAME_LEN
);
4191 if (wpa_derive_pmk_r1_name(sm
->pmk_r0_name
, sm
->r1kh_id
, sm
->own_addr
,
4192 sm
->pmk_r1_name
, use_sha384
) < 0) {
4193 wpa_printf(MSG_WARNING
, "FILS+FT: Could not derive PMKR1Name");
4196 wpa_hexdump(MSG_DEBUG
, "FILS+FT: PMKR1Name", sm
->pmk_r1_name
,
4198 os_memcpy(pos
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
);
4200 if (sm
->mgmt_group_cipher
== WPA_CIPHER_AES_128_CMAC
) {
4201 /* Management Group Cipher Suite */
4202 pos
= wpabuf_put(buf
, RSN_SELECTOR_LEN
);
4203 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_AES_128_CMAC
);
4206 rsnie
->len
= ((u8
*) wpabuf_put(buf
, 0) - (u8
*) rsnie
) - 2;
4209 #endif /* CONFIG_IEEE80211R */
4212 struct wpabuf
* fils_build_assoc_req(struct wpa_sm
*sm
, const u8
**kek
,
4213 size_t *kek_len
, const u8
**snonce
,
4215 const struct wpabuf
**hlp
,
4216 unsigned int num_hlp
)
4223 #ifdef CONFIG_IEEE80211R
4224 if (sm
->fils_ft_ies
)
4225 len
+= wpabuf_len(sm
->fils_ft_ies
);
4226 if (wpa_key_mgmt_ft(sm
->key_mgmt
))
4228 #endif /* CONFIG_IEEE80211R */
4229 for (i
= 0; hlp
&& i
< num_hlp
; i
++)
4230 len
+= 10 + wpabuf_len(hlp
[i
]);
4231 buf
= wpabuf_alloc(len
);
4235 #ifdef CONFIG_IEEE80211R
4236 if (wpa_key_mgmt_ft(sm
->key_mgmt
) && sm
->fils_ft_ies
) {
4237 /* MDE and FTE when using FILS+FT */
4238 wpabuf_put_buf(buf
, sm
->fils_ft_ies
);
4239 /* RSNE with PMKR1Name in PMKID field */
4240 if (fils_ft_build_assoc_req_rsne(sm
, buf
) < 0) {
4245 #endif /* CONFIG_IEEE80211R */
4248 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
4249 wpabuf_put_u8(buf
, 1 + FILS_SESSION_LEN
); /* Length */
4250 /* Element ID Extension */
4251 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_SESSION
);
4252 wpabuf_put_data(buf
, sm
->fils_session
, FILS_SESSION_LEN
);
4254 /* Everything after FILS Session element gets encrypted in the driver
4255 * with KEK. The buffer returned from here is the plaintext version. */
4257 /* TODO: FILS Public Key */
4259 /* FILS Key Confirm */
4260 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
4261 wpabuf_put_u8(buf
, 1 + sm
->fils_key_auth_len
); /* Length */
4262 /* Element ID Extension */
4263 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_KEY_CONFIRM
);
4264 wpabuf_put_data(buf
, sm
->fils_key_auth_sta
, sm
->fils_key_auth_len
);
4266 /* FILS HLP Container */
4267 for (i
= 0; hlp
&& i
< num_hlp
; i
++) {
4268 const u8
*pos
= wpabuf_head(hlp
[i
]);
4269 size_t left
= wpabuf_len(hlp
[i
]);
4271 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
4276 wpabuf_put_u8(buf
, len
); /* Length */
4277 /* Element ID Extension */
4278 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_HLP_CONTAINER
);
4279 /* Destination MAC Address, Source MAC Address, HLP Packet.
4280 * HLP Packet is in MSDU format (i.e., included the LLC/SNAP
4281 * header when LPD is used). */
4282 wpabuf_put_data(buf
, pos
, len
- 1);
4286 wpabuf_put_u8(buf
, WLAN_EID_FRAGMENT
);
4287 len
= left
> 255 ? 255 : left
;
4288 wpabuf_put_u8(buf
, len
);
4289 wpabuf_put_data(buf
, pos
, len
);
4295 /* TODO: FILS IP Address Assignment */
4298 if (wpa_sm_ocv_enabled(sm
)) {
4299 struct wpa_channel_info ci
;
4302 if (wpa_sm_channel_info(sm
, &ci
) != 0) {
4303 wpa_printf(MSG_WARNING
,
4304 "FILS: Failed to get channel info for OCI element");
4309 pos
= wpabuf_put(buf
, OCV_OCI_EXTENDED_LEN
);
4310 if (ocv_insert_extended_oci(&ci
, pos
) < 0) {
4315 #endif /* CONFIG_OCV */
4317 wpa_hexdump_buf(MSG_DEBUG
, "FILS: Association Request plaintext", buf
);
4320 *kek_len
= sm
->ptk
.kek_len
;
4321 wpa_hexdump_key(MSG_DEBUG
, "FILS: KEK for AEAD", *kek
, *kek_len
);
4322 *snonce
= sm
->fils_nonce
;
4323 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce for AEAD AAD",
4324 *snonce
, FILS_NONCE_LEN
);
4325 *anonce
= sm
->fils_anonce
;
4326 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce for AEAD AAD",
4327 *anonce
, FILS_NONCE_LEN
);
4333 static void fils_process_hlp_resp(struct wpa_sm
*sm
, const u8
*resp
, size_t len
)
4335 const u8
*pos
, *end
;
4337 wpa_hexdump(MSG_MSGDUMP
, "FILS: HLP response", resp
, len
);
4338 if (len
< 2 * ETH_ALEN
)
4340 pos
= resp
+ 2 * ETH_ALEN
;
4342 if (end
- pos
>= 6 &&
4343 os_memcmp(pos
, "\xaa\xaa\x03\x00\x00\x00", 6) == 0)
4344 pos
+= 6; /* Remove SNAP/LLC header */
4345 wpa_sm_fils_hlp_rx(sm
, resp
, resp
+ ETH_ALEN
, pos
, end
- pos
);
4349 static void fils_process_hlp_container(struct wpa_sm
*sm
, const u8
*pos
,
4352 const u8
*end
= pos
+ len
;
4355 /* Check if there are any FILS HLP Container elements */
4356 while (end
- pos
>= 2) {
4357 if (2 + pos
[1] > end
- pos
)
4359 if (pos
[0] == WLAN_EID_EXTENSION
&&
4360 pos
[1] >= 1 + 2 * ETH_ALEN
&&
4361 pos
[2] == WLAN_EID_EXT_FILS_HLP_CONTAINER
)
4366 return; /* No FILS HLP Container elements */
4368 tmp
= os_malloc(end
- pos
);
4372 while (end
- pos
>= 2) {
4373 if (2 + pos
[1] > end
- pos
||
4374 pos
[0] != WLAN_EID_EXTENSION
||
4375 pos
[1] < 1 + 2 * ETH_ALEN
||
4376 pos
[2] != WLAN_EID_EXT_FILS_HLP_CONTAINER
)
4379 os_memcpy(tmp_pos
, pos
+ 3, pos
[1] - 1);
4380 tmp_pos
+= pos
[1] - 1;
4383 /* Add possible fragments */
4384 while (end
- pos
>= 2 && pos
[0] == WLAN_EID_FRAGMENT
&&
4385 2 + pos
[1] <= end
- pos
) {
4386 os_memcpy(tmp_pos
, pos
+ 2, pos
[1]);
4391 fils_process_hlp_resp(sm
, tmp
, tmp_pos
- tmp
);
4398 int fils_process_assoc_resp(struct wpa_sm
*sm
, const u8
*resp
, size_t len
)
4400 const struct ieee80211_mgmt
*mgmt
;
4401 const u8
*end
, *ie_start
;
4402 struct ieee802_11_elems elems
;
4405 struct wpa_gtk_data gd
;
4407 struct wpa_eapol_ie_parse kde
;
4409 if (!sm
|| !sm
->ptk_set
) {
4410 wpa_printf(MSG_DEBUG
, "FILS: No KEK available");
4414 if (!wpa_key_mgmt_fils(sm
->key_mgmt
)) {
4415 wpa_printf(MSG_DEBUG
, "FILS: Not a FILS AKM");
4419 if (sm
->fils_completed
) {
4420 wpa_printf(MSG_DEBUG
,
4421 "FILS: Association has already been completed for this FILS authentication - ignore unexpected retransmission");
4425 wpa_hexdump(MSG_DEBUG
, "FILS: (Re)Association Response frame",
4428 mgmt
= (const struct ieee80211_mgmt
*) resp
;
4429 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.assoc_resp
))
4433 /* Same offset for Association Response and Reassociation Response */
4434 ie_start
= mgmt
->u
.assoc_resp
.variable
;
4436 if (ieee802_11_parse_elems(ie_start
, end
- ie_start
, &elems
, 1) ==
4438 wpa_printf(MSG_DEBUG
,
4439 "FILS: Failed to parse decrypted elements");
4443 if (!elems
.fils_session
) {
4444 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
4447 if (os_memcmp(elems
.fils_session
, sm
->fils_session
,
4448 FILS_SESSION_LEN
) != 0) {
4449 wpa_printf(MSG_DEBUG
, "FILS: FILS Session mismatch");
4450 wpa_hexdump(MSG_DEBUG
, "FILS: Received FILS Session",
4451 elems
.fils_session
, FILS_SESSION_LEN
);
4452 wpa_hexdump(MSG_DEBUG
, "FILS: Expected FILS Session",
4453 sm
->fils_session
, FILS_SESSION_LEN
);
4456 if (!elems
.rsn_ie
) {
4457 wpa_printf(MSG_DEBUG
,
4458 "FILS: No RSNE in (Re)Association Response");
4459 /* As an interop workaround, allow this for now since IEEE Std
4460 * 802.11ai-2016 did not include all the needed changes to make
4461 * a FILS AP include RSNE in the frame. This workaround might
4462 * eventually be removed and replaced with rejection (goto fail)
4463 * to follow a strict interpretation of the standard. */
4464 } else if (wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm
->key_mgmt
),
4465 sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
,
4466 elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2)) {
4467 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
4468 "FILS: RSNE mismatch between Beacon/Probe Response and (Re)Association Response");
4469 wpa_hexdump(MSG_DEBUG
, "FILS: RSNE in Beacon/Probe Response",
4470 sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
);
4471 wpa_hexdump(MSG_DEBUG
, "FILS: RSNE in (Re)Association Response",
4472 elems
.rsn_ie
, elems
.rsn_ie_len
);
4476 /* TODO: FILS Public Key */
4478 if (!elems
.fils_key_confirm
) {
4479 wpa_printf(MSG_DEBUG
, "FILS: No FILS Key Confirm element");
4482 if (elems
.fils_key_confirm_len
!= sm
->fils_key_auth_len
) {
4483 wpa_printf(MSG_DEBUG
,
4484 "FILS: Unexpected Key-Auth length %d (expected %d)",
4485 elems
.fils_key_confirm_len
,
4486 (int) sm
->fils_key_auth_len
);
4489 if (os_memcmp(elems
.fils_key_confirm
, sm
->fils_key_auth_ap
,
4490 sm
->fils_key_auth_len
) != 0) {
4491 wpa_printf(MSG_DEBUG
, "FILS: Key-Auth mismatch");
4492 wpa_hexdump(MSG_DEBUG
, "FILS: Received Key-Auth",
4493 elems
.fils_key_confirm
,
4494 elems
.fils_key_confirm_len
);
4495 wpa_hexdump(MSG_DEBUG
, "FILS: Expected Key-Auth",
4496 sm
->fils_key_auth_ap
, sm
->fils_key_auth_len
);
4501 if (wpa_sm_ocv_enabled(sm
)) {
4502 struct wpa_channel_info ci
;
4504 if (wpa_sm_channel_info(sm
, &ci
) != 0) {
4505 wpa_printf(MSG_WARNING
,
4506 "Failed to get channel info to validate received OCI in FILS (Re)Association Response frame");
4510 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
4511 channel_width_to_int(ci
.chanwidth
),
4512 ci
.seg1_idx
) != 0) {
4513 wpa_printf(MSG_WARNING
, "FILS: %s", ocv_errorstr
);
4517 #endif /* CONFIG_OCV */
4519 #ifdef CONFIG_IEEE80211R
4520 if (wpa_key_mgmt_ft(sm
->key_mgmt
) && sm
->fils_ft_ies
) {
4521 struct wpa_ie_data rsn
;
4523 /* Check that PMKR1Name derived by the AP matches */
4524 if (!elems
.rsn_ie
||
4525 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
4527 !rsn
.pmkid
|| rsn
.num_pmkid
!= 1 ||
4528 os_memcmp(rsn
.pmkid
, sm
->pmk_r1_name
,
4529 WPA_PMK_NAME_LEN
) != 0) {
4530 wpa_printf(MSG_DEBUG
,
4531 "FILS+FT: No RSNE[PMKR1Name] match in AssocResp");
4535 #endif /* CONFIG_IEEE80211R */
4538 if (!elems
.key_delivery
) {
4539 wpa_printf(MSG_DEBUG
, "FILS: No Key Delivery element");
4543 /* Parse GTK and set the key to the driver */
4544 os_memset(&gd
, 0, sizeof(gd
));
4545 if (wpa_supplicant_parse_ies(elems
.key_delivery
+ WPA_KEY_RSC_LEN
,
4546 elems
.key_delivery_len
- WPA_KEY_RSC_LEN
,
4548 wpa_printf(MSG_DEBUG
, "FILS: Failed to parse KDEs");
4552 wpa_printf(MSG_DEBUG
, "FILS: No GTK KDE");
4555 maxkeylen
= gd
.gtk_len
= kde
.gtk_len
- 2;
4556 if (wpa_supplicant_check_group_cipher(sm
, sm
->group_cipher
,
4557 gd
.gtk_len
, maxkeylen
,
4558 &gd
.key_rsc_len
, &gd
.alg
))
4561 wpa_hexdump_key(MSG_DEBUG
, "FILS: Received GTK", kde
.gtk
, kde
.gtk_len
);
4562 gd
.keyidx
= kde
.gtk
[0] & 0x3;
4563 gd
.tx
= wpa_supplicant_gtk_tx_bit_workaround(sm
,
4564 !!(kde
.gtk
[0] & BIT(2)));
4565 if (kde
.gtk_len
- 2 > sizeof(gd
.gtk
)) {
4566 wpa_printf(MSG_DEBUG
, "FILS: Too long GTK in GTK KDE (len=%lu)",
4567 (unsigned long) kde
.gtk_len
- 2);
4570 os_memcpy(gd
.gtk
, kde
.gtk
+ 2, kde
.gtk_len
- 2);
4572 wpa_printf(MSG_DEBUG
, "FILS: Set GTK to driver");
4573 if (wpa_supplicant_install_gtk(sm
, &gd
, elems
.key_delivery
, 0) < 0) {
4574 wpa_printf(MSG_DEBUG
, "FILS: Failed to set GTK");
4578 if (ieee80211w_set_keys(sm
, &kde
) < 0) {
4579 wpa_printf(MSG_DEBUG
, "FILS: Failed to set IGTK");
4583 alg
= wpa_cipher_to_alg(sm
->pairwise_cipher
);
4584 keylen
= wpa_cipher_key_len(sm
->pairwise_cipher
);
4585 if (keylen
<= 0 || (unsigned int) keylen
!= sm
->ptk
.tk_len
) {
4586 wpa_printf(MSG_DEBUG
, "FILS: TK length mismatch: %u != %lu",
4587 keylen
, (long unsigned int) sm
->ptk
.tk_len
);
4590 rsclen
= wpa_cipher_rsc_len(sm
->pairwise_cipher
);
4591 wpa_hexdump_key(MSG_DEBUG
, "FILS: Set TK to driver",
4592 sm
->ptk
.tk
, keylen
);
4593 if (wpa_sm_set_key(sm
, alg
, sm
->bssid
, 0, 1, null_rsc
, rsclen
,
4594 sm
->ptk
.tk
, keylen
, KEY_FLAG_PAIRWISE_RX_TX
) < 0) {
4595 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
4596 "FILS: Failed to set PTK to the driver (alg=%d keylen=%d bssid="
4598 alg
, keylen
, MAC2STR(sm
->bssid
));
4602 /* TODO: TK could be cleared after auth frame exchange now that driver
4603 * takes care of association frame encryption/decryption. */
4604 /* TK is not needed anymore in supplicant */
4605 os_memset(sm
->ptk
.tk
, 0, WPA_TK_MAX_LEN
);
4607 sm
->ptk
.installed
= 1;
4609 /* FILS HLP Container */
4610 fils_process_hlp_container(sm
, ie_start
, end
- ie_start
);
4612 /* TODO: FILS IP Address Assignment */
4614 wpa_printf(MSG_DEBUG
, "FILS: Auth+Assoc completed successfully");
4615 sm
->fils_completed
= 1;
4616 forced_memzero(&gd
, sizeof(gd
));
4620 forced_memzero(&gd
, sizeof(gd
));
4625 void wpa_sm_set_reset_fils_completed(struct wpa_sm
*sm
, int set
)
4628 sm
->fils_completed
= !!set
;
4631 #endif /* CONFIG_FILS */
4634 int wpa_fils_is_completed(struct wpa_sm
*sm
)
4637 return sm
&& sm
->fils_completed
;
4638 #else /* CONFIG_FILS */
4640 #endif /* CONFIG_FILS */
4646 struct wpabuf
* owe_build_assoc_req(struct wpa_sm
*sm
, u16 group
)
4648 struct wpabuf
*ie
= NULL
, *pub
= NULL
;
4653 else if (group
== 20)
4655 else if (group
== 21)
4660 crypto_ecdh_deinit(sm
->owe_ecdh
);
4661 sm
->owe_ecdh
= crypto_ecdh_init(group
);
4664 sm
->owe_group
= group
;
4665 pub
= crypto_ecdh_get_pubkey(sm
->owe_ecdh
, 0);
4666 pub
= wpabuf_zeropad(pub
, prime_len
);
4670 ie
= wpabuf_alloc(5 + wpabuf_len(pub
));
4673 wpabuf_put_u8(ie
, WLAN_EID_EXTENSION
);
4674 wpabuf_put_u8(ie
, 1 + 2 + wpabuf_len(pub
));
4675 wpabuf_put_u8(ie
, WLAN_EID_EXT_OWE_DH_PARAM
);
4676 wpabuf_put_le16(ie
, group
);
4677 wpabuf_put_buf(ie
, pub
);
4679 wpa_hexdump_buf(MSG_DEBUG
, "OWE: Diffie-Hellman Parameter element",
4685 crypto_ecdh_deinit(sm
->owe_ecdh
);
4686 sm
->owe_ecdh
= NULL
;
4691 int owe_process_assoc_resp(struct wpa_sm
*sm
, const u8
*bssid
,
4692 const u8
*resp_ies
, size_t resp_ies_len
)
4694 struct ieee802_11_elems elems
;
4696 struct wpabuf
*secret
, *pub
, *hkey
;
4698 u8 prk
[SHA512_MAC_LEN
], pmkid
[SHA512_MAC_LEN
];
4699 const char *info
= "OWE Key Generation";
4702 size_t hash_len
, prime_len
;
4703 struct wpa_ie_data data
;
4706 ieee802_11_parse_elems(resp_ies
, resp_ies_len
, &elems
, 1) ==
4708 wpa_printf(MSG_INFO
,
4709 "OWE: Could not parse Association Response frame elements");
4713 if (sm
->cur_pmksa
&& elems
.rsn_ie
&&
4714 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, 2 + elems
.rsn_ie_len
,
4716 data
.num_pmkid
== 1 && data
.pmkid
&&
4717 os_memcmp(sm
->cur_pmksa
->pmkid
, data
.pmkid
, PMKID_LEN
) == 0) {
4718 wpa_printf(MSG_DEBUG
, "OWE: Use PMKSA caching");
4719 wpa_sm_set_pmk_from_pmksa(sm
);
4723 if (!elems
.owe_dh
) {
4724 wpa_printf(MSG_INFO
,
4725 "OWE: No Diffie-Hellman Parameter element found in Association Response frame");
4729 group
= WPA_GET_LE16(elems
.owe_dh
);
4730 if (group
!= sm
->owe_group
) {
4731 wpa_printf(MSG_INFO
,
4732 "OWE: Unexpected Diffie-Hellman group in response: %u",
4737 if (!sm
->owe_ecdh
) {
4738 wpa_printf(MSG_INFO
, "OWE: No ECDH state available");
4744 else if (group
== 20)
4746 else if (group
== 21)
4751 secret
= crypto_ecdh_set_peerkey(sm
->owe_ecdh
, 0,
4753 elems
.owe_dh_len
- 2);
4754 secret
= wpabuf_zeropad(secret
, prime_len
);
4756 wpa_printf(MSG_DEBUG
, "OWE: Invalid peer DH public key");
4759 wpa_hexdump_buf_key(MSG_DEBUG
, "OWE: DH shared secret", secret
);
4761 /* prk = HKDF-extract(C | A | group, z) */
4763 pub
= crypto_ecdh_get_pubkey(sm
->owe_ecdh
, 0);
4765 wpabuf_clear_free(secret
);
4769 /* PMKID = Truncate-128(Hash(C | A)) */
4770 addr
[0] = wpabuf_head(pub
);
4771 len
[0] = wpabuf_len(pub
);
4772 addr
[1] = elems
.owe_dh
+ 2;
4773 len
[1] = elems
.owe_dh_len
- 2;
4775 res
= sha256_vector(2, addr
, len
, pmkid
);
4776 hash_len
= SHA256_MAC_LEN
;
4777 } else if (group
== 20) {
4778 res
= sha384_vector(2, addr
, len
, pmkid
);
4779 hash_len
= SHA384_MAC_LEN
;
4780 } else if (group
== 21) {
4781 res
= sha512_vector(2, addr
, len
, pmkid
);
4782 hash_len
= SHA512_MAC_LEN
;
4787 pub
= wpabuf_zeropad(pub
, prime_len
);
4788 if (res
< 0 || !pub
) {
4790 wpabuf_clear_free(secret
);
4794 hkey
= wpabuf_alloc(wpabuf_len(pub
) + elems
.owe_dh_len
- 2 + 2);
4797 wpabuf_clear_free(secret
);
4801 wpabuf_put_buf(hkey
, pub
); /* C */
4803 wpabuf_put_data(hkey
, elems
.owe_dh
+ 2, elems
.owe_dh_len
- 2); /* A */
4804 wpabuf_put_le16(hkey
, sm
->owe_group
); /* group */
4806 res
= hmac_sha256(wpabuf_head(hkey
), wpabuf_len(hkey
),
4807 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
4808 else if (group
== 20)
4809 res
= hmac_sha384(wpabuf_head(hkey
), wpabuf_len(hkey
),
4810 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
4811 else if (group
== 21)
4812 res
= hmac_sha512(wpabuf_head(hkey
), wpabuf_len(hkey
),
4813 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
4814 wpabuf_clear_free(hkey
);
4815 wpabuf_clear_free(secret
);
4819 wpa_hexdump_key(MSG_DEBUG
, "OWE: prk", prk
, hash_len
);
4821 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
4824 res
= hmac_sha256_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
4825 os_strlen(info
), sm
->pmk
, hash_len
);
4826 else if (group
== 20)
4827 res
= hmac_sha384_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
4828 os_strlen(info
), sm
->pmk
, hash_len
);
4829 else if (group
== 21)
4830 res
= hmac_sha512_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
4831 os_strlen(info
), sm
->pmk
, hash_len
);
4832 forced_memzero(prk
, SHA512_MAC_LEN
);
4837 sm
->pmk_len
= hash_len
;
4839 wpa_hexdump_key(MSG_DEBUG
, "OWE: PMK", sm
->pmk
, sm
->pmk_len
);
4840 wpa_hexdump(MSG_DEBUG
, "OWE: PMKID", pmkid
, PMKID_LEN
);
4841 pmksa_cache_add(sm
->pmksa
, sm
->pmk
, sm
->pmk_len
, pmkid
, NULL
, 0,
4842 bssid
, sm
->own_addr
, sm
->network_ctx
, sm
->key_mgmt
,
4848 #endif /* CONFIG_OWE */
4851 void wpa_sm_set_fils_cache_id(struct wpa_sm
*sm
, const u8
*fils_cache_id
)
4854 if (sm
&& fils_cache_id
) {
4855 sm
->fils_cache_id_set
= 1;
4856 os_memcpy(sm
->fils_cache_id
, fils_cache_id
, FILS_CACHE_ID_LEN
);
4858 #endif /* CONFIG_FILS */
4863 void wpa_sm_set_dpp_z(struct wpa_sm
*sm
, const struct wpabuf
*z
)
4866 wpabuf_clear_free(sm
->dpp_z
);
4867 sm
->dpp_z
= z
? wpabuf_dup(z
) : NULL
;
4870 #endif /* CONFIG_DPP2 */