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 #endif /* CONFIG_FILS */
2964 sm
->network_ctx
= NULL
;
2965 sm
->allowed_pairwise_cipher
= 0;
2966 sm
->proactive_key_caching
= 0;
2967 sm
->eap_workaround
= 0;
2968 sm
->eap_conf_ctx
= NULL
;
2970 sm
->wpa_ptk_rekey
= 0;
2972 sm
->wpa_rsc_relaxation
= 0;
2973 sm
->owe_ptk_workaround
= 0;
2979 * wpa_sm_set_own_addr - Set own MAC address
2980 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2981 * @addr: Own MAC address
2983 void wpa_sm_set_own_addr(struct wpa_sm
*sm
, const u8
*addr
)
2986 os_memcpy(sm
->own_addr
, addr
, ETH_ALEN
);
2991 * wpa_sm_set_ifname - Set network interface name
2992 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2993 * @ifname: Interface name
2994 * @bridge_ifname: Optional bridge interface name (for pre-auth)
2996 void wpa_sm_set_ifname(struct wpa_sm
*sm
, const char *ifname
,
2997 const char *bridge_ifname
)
3000 sm
->ifname
= ifname
;
3001 sm
->bridge_ifname
= bridge_ifname
;
3007 * wpa_sm_set_eapol - Set EAPOL state machine pointer
3008 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3009 * @eapol: Pointer to EAPOL state machine allocated with eapol_sm_init()
3011 void wpa_sm_set_eapol(struct wpa_sm
*sm
, struct eapol_sm
*eapol
)
3019 * wpa_sm_set_param - Set WPA state machine parameters
3020 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3021 * @param: Parameter field
3022 * @value: Parameter value
3023 * Returns: 0 on success, -1 on failure
3025 int wpa_sm_set_param(struct wpa_sm
*sm
, enum wpa_sm_conf_params param
,
3034 case RSNA_PMK_LIFETIME
:
3036 sm
->dot11RSNAConfigPMKLifetime
= value
;
3040 case RSNA_PMK_REAUTH_THRESHOLD
:
3041 if (value
> 0 && value
<= 100)
3042 sm
->dot11RSNAConfigPMKReauthThreshold
= value
;
3046 case RSNA_SA_TIMEOUT
:
3048 sm
->dot11RSNAConfigSATimeout
= value
;
3052 case WPA_PARAM_PROTO
:
3055 case WPA_PARAM_PAIRWISE
:
3056 sm
->pairwise_cipher
= value
;
3058 case WPA_PARAM_GROUP
:
3059 sm
->group_cipher
= value
;
3061 case WPA_PARAM_KEY_MGMT
:
3062 sm
->key_mgmt
= value
;
3064 case WPA_PARAM_MGMT_GROUP
:
3065 sm
->mgmt_group_cipher
= value
;
3067 case WPA_PARAM_RSN_ENABLED
:
3068 sm
->rsn_enabled
= value
;
3076 case WPA_PARAM_SAE_PWE
:
3077 sm
->sae_pwe
= value
;
3088 * wpa_sm_get_status - Get WPA state machine
3089 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3090 * @buf: Buffer for status information
3091 * @buflen: Maximum buffer length
3092 * @verbose: Whether to include verbose status information
3093 * Returns: Number of bytes written to buf.
3095 * Query WPA state machine for status information. This function fills in
3096 * a text area with current status information. If the buffer (buf) is not
3097 * large enough, status information will be truncated to fit the buffer.
3099 int wpa_sm_get_status(struct wpa_sm
*sm
, char *buf
, size_t buflen
,
3102 char *pos
= buf
, *end
= buf
+ buflen
;
3105 ret
= os_snprintf(pos
, end
- pos
,
3106 "pairwise_cipher=%s\n"
3109 wpa_cipher_txt(sm
->pairwise_cipher
),
3110 wpa_cipher_txt(sm
->group_cipher
),
3111 wpa_key_mgmt_txt(sm
->key_mgmt
, sm
->proto
));
3112 if (os_snprintf_error(end
- pos
, ret
))
3116 if (sm
->mfp
!= NO_MGMT_FRAME_PROTECTION
&& sm
->ap_rsn_ie
) {
3117 struct wpa_ie_data rsn
;
3118 if (wpa_parse_wpa_ie_rsn(sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
, &rsn
)
3120 rsn
.capabilities
& (WPA_CAPABILITY_MFPR
|
3121 WPA_CAPABILITY_MFPC
)) {
3122 ret
= os_snprintf(pos
, end
- pos
, "pmf=%d\n"
3123 "mgmt_group_cipher=%s\n",
3125 WPA_CAPABILITY_MFPR
) ? 2 : 1,
3127 sm
->mgmt_group_cipher
));
3128 if (os_snprintf_error(end
- pos
, ret
))
3138 int wpa_sm_pmf_enabled(struct wpa_sm
*sm
)
3140 struct wpa_ie_data rsn
;
3142 if (sm
->mfp
== NO_MGMT_FRAME_PROTECTION
|| !sm
->ap_rsn_ie
)
3145 if (wpa_parse_wpa_ie_rsn(sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
, &rsn
) >= 0 &&
3146 rsn
.capabilities
& (WPA_CAPABILITY_MFPR
| WPA_CAPABILITY_MFPC
))
3153 int wpa_sm_ocv_enabled(struct wpa_sm
*sm
)
3155 struct wpa_ie_data rsn
;
3157 if (!sm
->ocv
|| !sm
->ap_rsn_ie
)
3160 return wpa_parse_wpa_ie_rsn(sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
,
3162 (rsn
.capabilities
& WPA_CAPABILITY_OCVC
);
3167 * wpa_sm_set_assoc_wpa_ie_default - Generate own WPA/RSN IE from configuration
3168 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3169 * @wpa_ie: Pointer to buffer for WPA/RSN IE
3170 * @wpa_ie_len: Pointer to the length of the wpa_ie buffer
3171 * Returns: 0 on success, -1 on failure
3173 int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm
*sm
, u8
*wpa_ie
,
3181 #ifdef CONFIG_TESTING_OPTIONS
3182 if (sm
->test_assoc_ie
) {
3183 wpa_printf(MSG_DEBUG
,
3184 "TESTING: Replace association WPA/RSN IE");
3185 if (*wpa_ie_len
< wpabuf_len(sm
->test_assoc_ie
))
3187 os_memcpy(wpa_ie
, wpabuf_head(sm
->test_assoc_ie
),
3188 wpabuf_len(sm
->test_assoc_ie
));
3189 res
= wpabuf_len(sm
->test_assoc_ie
);
3191 #endif /* CONFIG_TESTING_OPTIONS */
3192 res
= wpa_gen_wpa_ie(sm
, wpa_ie
, *wpa_ie_len
);
3197 wpa_hexdump(MSG_DEBUG
, "WPA: Set own WPA IE default",
3198 wpa_ie
, *wpa_ie_len
);
3200 if (sm
->assoc_wpa_ie
== NULL
) {
3202 * Make a copy of the WPA/RSN IE so that 4-Way Handshake gets
3203 * the correct version of the IE even if PMKSA caching is
3204 * aborted (which would remove PMKID from IE generation).
3206 sm
->assoc_wpa_ie
= os_memdup(wpa_ie
, *wpa_ie_len
);
3207 if (sm
->assoc_wpa_ie
== NULL
)
3210 sm
->assoc_wpa_ie_len
= *wpa_ie_len
;
3212 wpa_hexdump(MSG_DEBUG
,
3213 "WPA: Leave previously set WPA IE default",
3214 sm
->assoc_wpa_ie
, sm
->assoc_wpa_ie_len
);
3222 * wpa_sm_set_assoc_wpa_ie - Set own WPA/RSN IE from (Re)AssocReq
3223 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3224 * @ie: Pointer to IE data (starting from id)
3226 * Returns: 0 on success, -1 on failure
3228 * Inform WPA state machine about the WPA/RSN IE used in (Re)Association
3229 * Request frame. The IE will be used to override the default value generated
3230 * with wpa_sm_set_assoc_wpa_ie_default().
3232 int wpa_sm_set_assoc_wpa_ie(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3237 os_free(sm
->assoc_wpa_ie
);
3238 if (ie
== NULL
|| len
== 0) {
3239 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3240 "WPA: clearing own WPA/RSN IE");
3241 sm
->assoc_wpa_ie
= NULL
;
3242 sm
->assoc_wpa_ie_len
= 0;
3244 wpa_hexdump(MSG_DEBUG
, "WPA: set own WPA/RSN IE", ie
, len
);
3245 sm
->assoc_wpa_ie
= os_memdup(ie
, len
);
3246 if (sm
->assoc_wpa_ie
== NULL
)
3249 sm
->assoc_wpa_ie_len
= len
;
3257 * wpa_sm_set_assoc_rsnxe_default - Generate own RSNXE from configuration
3258 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3259 * @rsnxe: Pointer to buffer for RSNXE
3260 * @rsnxe_len: Pointer to the length of the rsne buffer
3261 * Returns: 0 on success, -1 on failure
3263 int wpa_sm_set_assoc_rsnxe_default(struct wpa_sm
*sm
, u8
*rsnxe
,
3271 res
= wpa_gen_rsnxe(sm
, rsnxe
, *rsnxe_len
);
3276 wpa_hexdump(MSG_DEBUG
, "RSN: Set own RSNXE default", rsnxe
, *rsnxe_len
);
3278 if (sm
->assoc_rsnxe
) {
3279 wpa_hexdump(MSG_DEBUG
,
3280 "RSN: Leave previously set RSNXE default",
3281 sm
->assoc_rsnxe
, sm
->assoc_rsnxe_len
);
3282 } else if (*rsnxe_len
> 0) {
3284 * Make a copy of the RSNXE so that 4-Way Handshake gets the
3285 * correct version of the IE even if it gets changed.
3287 sm
->assoc_rsnxe
= os_memdup(rsnxe
, *rsnxe_len
);
3288 if (!sm
->assoc_rsnxe
)
3291 sm
->assoc_rsnxe_len
= *rsnxe_len
;
3299 * wpa_sm_set_assoc_rsnxe - Set own RSNXE from (Re)AssocReq
3300 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3301 * @ie: Pointer to IE data (starting from id)
3303 * Returns: 0 on success, -1 on failure
3305 * Inform WPA state machine about the RSNXE used in (Re)Association Request
3306 * frame. The IE will be used to override the default value generated
3307 * with wpa_sm_set_assoc_rsnxe_default().
3309 int wpa_sm_set_assoc_rsnxe(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3314 os_free(sm
->assoc_rsnxe
);
3315 if (!ie
|| len
== 0) {
3316 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3317 "RSN: clearing own RSNXE");
3318 sm
->assoc_rsnxe
= NULL
;
3319 sm
->assoc_rsnxe_len
= 0;
3321 wpa_hexdump(MSG_DEBUG
, "RSN: set own RSNXE", ie
, len
);
3322 sm
->assoc_rsnxe
= os_memdup(ie
, len
);
3323 if (!sm
->assoc_rsnxe
)
3326 sm
->assoc_rsnxe_len
= len
;
3334 * wpa_sm_set_ap_wpa_ie - Set AP WPA IE from Beacon/ProbeResp
3335 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3336 * @ie: Pointer to IE data (starting from id)
3338 * Returns: 0 on success, -1 on failure
3340 * Inform WPA state machine about the WPA IE used in Beacon / Probe Response
3343 int wpa_sm_set_ap_wpa_ie(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3348 os_free(sm
->ap_wpa_ie
);
3349 if (ie
== NULL
|| len
== 0) {
3350 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3351 "WPA: clearing AP WPA IE");
3352 sm
->ap_wpa_ie
= NULL
;
3353 sm
->ap_wpa_ie_len
= 0;
3355 wpa_hexdump(MSG_DEBUG
, "WPA: set AP WPA IE", ie
, len
);
3356 sm
->ap_wpa_ie
= os_memdup(ie
, len
);
3357 if (sm
->ap_wpa_ie
== NULL
)
3360 sm
->ap_wpa_ie_len
= len
;
3368 * wpa_sm_set_ap_rsn_ie - Set AP RSN IE from Beacon/ProbeResp
3369 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3370 * @ie: Pointer to IE data (starting from id)
3372 * Returns: 0 on success, -1 on failure
3374 * Inform WPA state machine about the RSN IE used in Beacon / Probe Response
3377 int wpa_sm_set_ap_rsn_ie(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3382 os_free(sm
->ap_rsn_ie
);
3383 if (ie
== NULL
|| len
== 0) {
3384 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3385 "WPA: clearing AP RSN IE");
3386 sm
->ap_rsn_ie
= NULL
;
3387 sm
->ap_rsn_ie_len
= 0;
3389 wpa_hexdump(MSG_DEBUG
, "WPA: set AP RSN IE", ie
, len
);
3390 sm
->ap_rsn_ie
= os_memdup(ie
, len
);
3391 if (sm
->ap_rsn_ie
== NULL
)
3394 sm
->ap_rsn_ie_len
= len
;
3402 * wpa_sm_set_ap_rsnxe - Set AP RSNXE from Beacon/ProbeResp
3403 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3404 * @ie: Pointer to IE data (starting from id)
3406 * Returns: 0 on success, -1 on failure
3408 * Inform WPA state machine about the RSNXE used in Beacon / Probe Response
3411 int wpa_sm_set_ap_rsnxe(struct wpa_sm
*sm
, const u8
*ie
, size_t len
)
3416 os_free(sm
->ap_rsnxe
);
3417 if (!ie
|| len
== 0) {
3418 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: clearing AP RSNXE");
3419 sm
->ap_rsnxe
= NULL
;
3420 sm
->ap_rsnxe_len
= 0;
3422 wpa_hexdump(MSG_DEBUG
, "WPA: set AP RSNXE", ie
, len
);
3423 sm
->ap_rsnxe
= os_memdup(ie
, len
);
3427 sm
->ap_rsnxe_len
= len
;
3435 * wpa_sm_parse_own_wpa_ie - Parse own WPA/RSN IE
3436 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3437 * @data: Pointer to data area for parsing results
3438 * Returns: 0 on success, -1 if IE is not known, or -2 on parsing failure
3440 * Parse the contents of the own WPA or RSN IE from (Re)AssocReq and write the
3441 * parsed data into data.
3443 int wpa_sm_parse_own_wpa_ie(struct wpa_sm
*sm
, struct wpa_ie_data
*data
)
3448 if (sm
->assoc_wpa_ie
== NULL
) {
3449 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
,
3450 "WPA: No WPA/RSN IE available from association info");
3453 if (wpa_parse_wpa_ie(sm
->assoc_wpa_ie
, sm
->assoc_wpa_ie_len
, data
))
3459 int wpa_sm_pmksa_cache_list(struct wpa_sm
*sm
, char *buf
, size_t len
)
3461 return pmksa_cache_list(sm
->pmksa
, buf
, len
);
3465 struct rsn_pmksa_cache_entry
* wpa_sm_pmksa_cache_head(struct wpa_sm
*sm
)
3467 return pmksa_cache_head(sm
->pmksa
);
3471 struct rsn_pmksa_cache_entry
*
3472 wpa_sm_pmksa_cache_add_entry(struct wpa_sm
*sm
,
3473 struct rsn_pmksa_cache_entry
* entry
)
3475 return pmksa_cache_add_entry(sm
->pmksa
, entry
);
3479 void wpa_sm_pmksa_cache_add(struct wpa_sm
*sm
, const u8
*pmk
, size_t pmk_len
,
3480 const u8
*pmkid
, const u8
*bssid
,
3481 const u8
*fils_cache_id
)
3483 sm
->cur_pmksa
= pmksa_cache_add(sm
->pmksa
, pmk
, pmk_len
, pmkid
, NULL
, 0,
3484 bssid
, sm
->own_addr
, sm
->network_ctx
,
3485 sm
->key_mgmt
, fils_cache_id
);
3489 int wpa_sm_pmksa_exists(struct wpa_sm
*sm
, const u8
*bssid
,
3490 const void *network_ctx
)
3492 return pmksa_cache_get(sm
->pmksa
, bssid
, NULL
, network_ctx
, 0) != NULL
;
3496 void wpa_sm_drop_sa(struct wpa_sm
*sm
)
3498 wpa_dbg(sm
->ctx
->msg_ctx
, MSG_DEBUG
, "WPA: Clear old PMK and PTK");
3502 os_memset(sm
->pmk
, 0, sizeof(sm
->pmk
));
3503 os_memset(&sm
->ptk
, 0, sizeof(sm
->ptk
));
3504 os_memset(&sm
->tptk
, 0, sizeof(sm
->tptk
));
3505 os_memset(&sm
->gtk
, 0, sizeof(sm
->gtk
));
3506 os_memset(&sm
->gtk_wnm_sleep
, 0, sizeof(sm
->gtk_wnm_sleep
));
3507 os_memset(&sm
->igtk
, 0, sizeof(sm
->igtk
));
3508 os_memset(&sm
->igtk_wnm_sleep
, 0, sizeof(sm
->igtk_wnm_sleep
));
3509 #ifdef CONFIG_IEEE80211R
3510 os_memset(sm
->xxkey
, 0, sizeof(sm
->xxkey
));
3512 os_memset(sm
->pmk_r0
, 0, sizeof(sm
->pmk_r0
));
3514 os_memset(sm
->pmk_r1
, 0, sizeof(sm
->pmk_r1
));
3516 #endif /* CONFIG_IEEE80211R */
3520 int wpa_sm_has_ptk(struct wpa_sm
*sm
)
3528 int wpa_sm_has_ptk_installed(struct wpa_sm
*sm
)
3532 return sm
->ptk
.installed
;
3536 void wpa_sm_update_replay_ctr(struct wpa_sm
*sm
, const u8
*replay_ctr
)
3538 os_memcpy(sm
->rx_replay_counter
, replay_ctr
, WPA_REPLAY_COUNTER_LEN
);
3542 void wpa_sm_pmksa_cache_flush(struct wpa_sm
*sm
, void *network_ctx
)
3544 pmksa_cache_flush(sm
->pmksa
, network_ctx
, NULL
, 0);
3549 int wpa_wnmsleep_install_key(struct wpa_sm
*sm
, u8 subelem_id
, u8
*buf
)
3552 u8 keylen
; /* plaintext key len */
3555 if (subelem_id
== WNM_SLEEP_SUBELEM_GTK
) {
3556 struct wpa_gtk_data gd
;
3558 os_memset(&gd
, 0, sizeof(gd
));
3559 keylen
= wpa_cipher_key_len(sm
->group_cipher
);
3560 gd
.key_rsc_len
= wpa_cipher_rsc_len(sm
->group_cipher
);
3561 gd
.alg
= wpa_cipher_to_alg(sm
->group_cipher
);
3562 if (gd
.alg
== WPA_ALG_NONE
) {
3563 wpa_printf(MSG_DEBUG
, "Unsupported group cipher suite");
3568 keyinfo
= WPA_GET_LE16(buf
+ 2);
3569 gd
.gtk_len
= keylen
;
3570 if (gd
.gtk_len
!= buf
[4]) {
3571 wpa_printf(MSG_DEBUG
, "GTK len mismatch len %d vs %d",
3572 gd
.gtk_len
, buf
[4]);
3575 gd
.keyidx
= keyinfo
& 0x03; /* B0 - B1 */
3576 gd
.tx
= wpa_supplicant_gtk_tx_bit_workaround(
3577 sm
, !!(keyinfo
& WPA_KEY_INFO_TXRX
));
3579 os_memcpy(gd
.gtk
, buf
+ 13, gd
.gtk_len
);
3581 wpa_hexdump_key(MSG_DEBUG
, "Install GTK (WNM SLEEP)",
3582 gd
.gtk
, gd
.gtk_len
);
3583 if (wpa_supplicant_install_gtk(sm
, &gd
, key_rsc
, 1)) {
3584 forced_memzero(&gd
, sizeof(gd
));
3585 wpa_printf(MSG_DEBUG
, "Failed to install the GTK in "
3589 forced_memzero(&gd
, sizeof(gd
));
3590 } else if (subelem_id
== WNM_SLEEP_SUBELEM_IGTK
) {
3591 const struct wpa_igtk_kde
*igtk
;
3593 igtk
= (const struct wpa_igtk_kde
*) (buf
+ 2);
3594 if (wpa_supplicant_install_igtk(sm
, igtk
, 1) < 0)
3597 wpa_printf(MSG_DEBUG
, "Unknown element id");
3603 #endif /* CONFIG_WNM */
3608 int wpa_sm_get_p2p_ip_addr(struct wpa_sm
*sm
, u8
*buf
)
3610 if (sm
== NULL
|| WPA_GET_BE32(sm
->p2p_ip_addr
) == 0)
3612 os_memcpy(buf
, sm
->p2p_ip_addr
, 3 * 4);
3616 #endif /* CONFIG_P2P */
3619 void wpa_sm_set_rx_replay_ctr(struct wpa_sm
*sm
, const u8
*rx_replay_counter
)
3621 if (rx_replay_counter
== NULL
)
3624 os_memcpy(sm
->rx_replay_counter
, rx_replay_counter
,
3625 WPA_REPLAY_COUNTER_LEN
);
3626 sm
->rx_replay_counter_set
= 1;
3627 wpa_printf(MSG_DEBUG
, "Updated key replay counter");
3631 void wpa_sm_set_ptk_kck_kek(struct wpa_sm
*sm
,
3632 const u8
*ptk_kck
, size_t ptk_kck_len
,
3633 const u8
*ptk_kek
, size_t ptk_kek_len
)
3635 if (ptk_kck
&& ptk_kck_len
<= WPA_KCK_MAX_LEN
) {
3636 os_memcpy(sm
->ptk
.kck
, ptk_kck
, ptk_kck_len
);
3637 sm
->ptk
.kck_len
= ptk_kck_len
;
3638 wpa_printf(MSG_DEBUG
, "Updated PTK KCK");
3640 if (ptk_kek
&& ptk_kek_len
<= WPA_KEK_MAX_LEN
) {
3641 os_memcpy(sm
->ptk
.kek
, ptk_kek
, ptk_kek_len
);
3642 sm
->ptk
.kek_len
= ptk_kek_len
;
3643 wpa_printf(MSG_DEBUG
, "Updated PTK KEK");
3649 #ifdef CONFIG_TESTING_OPTIONS
3651 void wpa_sm_set_test_assoc_ie(struct wpa_sm
*sm
, struct wpabuf
*buf
)
3653 wpabuf_free(sm
->test_assoc_ie
);
3654 sm
->test_assoc_ie
= buf
;
3658 const u8
* wpa_sm_get_anonce(struct wpa_sm
*sm
)
3663 #endif /* CONFIG_TESTING_OPTIONS */
3666 unsigned int wpa_sm_get_key_mgmt(struct wpa_sm
*sm
)
3668 return sm
->key_mgmt
;
3674 struct wpabuf
* fils_build_auth(struct wpa_sm
*sm
, int dh_group
, const u8
*md
)
3676 struct wpabuf
*buf
= NULL
;
3677 struct wpabuf
*erp_msg
;
3678 struct wpabuf
*pub
= NULL
;
3680 erp_msg
= eapol_sm_build_erp_reauth_start(sm
->eapol
);
3681 if (!erp_msg
&& !sm
->cur_pmksa
) {
3682 wpa_printf(MSG_DEBUG
,
3683 "FILS: Neither ERP EAP-Initiate/Re-auth nor PMKSA cache entry is available - skip FILS");
3687 wpa_printf(MSG_DEBUG
, "FILS: Try to use FILS (erp=%d pmksa_cache=%d)",
3688 erp_msg
!= NULL
, sm
->cur_pmksa
!= NULL
);
3690 sm
->fils_completed
= 0;
3692 if (!sm
->assoc_wpa_ie
) {
3693 wpa_printf(MSG_INFO
, "FILS: No own RSN IE set for FILS");
3697 if (random_get_bytes(sm
->fils_nonce
, FILS_NONCE_LEN
) < 0 ||
3698 random_get_bytes(sm
->fils_session
, FILS_SESSION_LEN
) < 0)
3701 wpa_hexdump(MSG_DEBUG
, "FILS: Generated FILS Nonce",
3702 sm
->fils_nonce
, FILS_NONCE_LEN
);
3703 wpa_hexdump(MSG_DEBUG
, "FILS: Generated FILS Session",
3704 sm
->fils_session
, FILS_SESSION_LEN
);
3706 #ifdef CONFIG_FILS_SK_PFS
3707 sm
->fils_dh_group
= dh_group
;
3709 crypto_ecdh_deinit(sm
->fils_ecdh
);
3710 sm
->fils_ecdh
= crypto_ecdh_init(dh_group
);
3711 if (!sm
->fils_ecdh
) {
3712 wpa_printf(MSG_INFO
,
3713 "FILS: Could not initialize ECDH with group %d",
3717 pub
= crypto_ecdh_get_pubkey(sm
->fils_ecdh
, 1);
3720 wpa_hexdump_buf(MSG_DEBUG
, "FILS: Element (DH public key)",
3722 sm
->fils_dh_elem_len
= wpabuf_len(pub
);
3724 #endif /* CONFIG_FILS_SK_PFS */
3726 buf
= wpabuf_alloc(1000 + sm
->assoc_wpa_ie_len
+
3727 (pub
? wpabuf_len(pub
) : 0));
3731 /* Fields following the Authentication algorithm number field */
3733 /* Authentication Transaction seq# */
3734 wpabuf_put_le16(buf
, 1);
3737 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
3740 #ifdef CONFIG_FILS_SK_PFS
3742 /* Finite Cyclic Group */
3743 wpabuf_put_le16(buf
, dh_group
);
3745 wpabuf_put_buf(buf
, pub
);
3747 #endif /* CONFIG_FILS_SK_PFS */
3750 wpa_hexdump(MSG_DEBUG
, "FILS: RSNE in FILS Authentication frame",
3751 sm
->assoc_wpa_ie
, sm
->assoc_wpa_ie_len
);
3752 wpabuf_put_data(buf
, sm
->assoc_wpa_ie
, sm
->assoc_wpa_ie_len
);
3755 /* MDE when using FILS for FT initial association */
3756 struct rsn_mdie
*mdie
;
3758 wpabuf_put_u8(buf
, WLAN_EID_MOBILITY_DOMAIN
);
3759 wpabuf_put_u8(buf
, sizeof(*mdie
));
3760 mdie
= wpabuf_put(buf
, sizeof(*mdie
));
3761 os_memcpy(mdie
->mobility_domain
, md
, MOBILITY_DOMAIN_ID_LEN
);
3766 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
3767 wpabuf_put_u8(buf
, 1 + FILS_NONCE_LEN
); /* Length */
3768 /* Element ID Extension */
3769 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_NONCE
);
3770 wpabuf_put_data(buf
, sm
->fils_nonce
, FILS_NONCE_LEN
);
3773 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
3774 wpabuf_put_u8(buf
, 1 + FILS_SESSION_LEN
); /* Length */
3775 /* Element ID Extension */
3776 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_SESSION
);
3777 wpabuf_put_data(buf
, sm
->fils_session
, FILS_SESSION_LEN
);
3779 /* FILS Wrapped Data */
3780 sm
->fils_erp_pmkid_set
= 0;
3782 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
3783 wpabuf_put_u8(buf
, 1 + wpabuf_len(erp_msg
)); /* Length */
3784 /* Element ID Extension */
3785 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_WRAPPED_DATA
);
3786 wpabuf_put_buf(buf
, erp_msg
);
3787 /* Calculate pending PMKID here so that we do not need to
3788 * maintain a copy of the EAP-Initiate/Reauth message. */
3789 if (fils_pmkid_erp(sm
->key_mgmt
, wpabuf_head(erp_msg
),
3790 wpabuf_len(erp_msg
),
3791 sm
->fils_erp_pmkid
) == 0)
3792 sm
->fils_erp_pmkid_set
= 1;
3795 wpa_hexdump_buf(MSG_DEBUG
, "RSN: FILS fields for Authentication frame",
3799 wpabuf_free(erp_msg
);
3805 int fils_process_auth(struct wpa_sm
*sm
, const u8
*bssid
, const u8
*data
,
3808 const u8
*pos
, *end
;
3809 struct ieee802_11_elems elems
;
3810 struct wpa_ie_data rsn
;
3811 int pmkid_match
= 0;
3812 u8 ick
[FILS_ICK_MAX_LEN
];
3815 struct wpabuf
*dh_ss
= NULL
;
3816 const u8
*g_sta
= NULL
;
3817 size_t g_sta_len
= 0;
3818 const u8
*g_ap
= NULL
;
3819 size_t g_ap_len
= 0;
3820 struct wpabuf
*pub
= NULL
;
3822 os_memcpy(sm
->bssid
, bssid
, ETH_ALEN
);
3824 wpa_hexdump(MSG_DEBUG
, "FILS: Authentication frame fields",
3830 #ifdef CONFIG_FILS_SK_PFS
3831 if (sm
->fils_dh_group
) {
3834 /* Using FILS PFS */
3836 /* Finite Cyclic Group */
3837 if (end
- pos
< 2) {
3838 wpa_printf(MSG_DEBUG
,
3839 "FILS: No room for Finite Cyclic Group");
3842 group
= WPA_GET_LE16(pos
);
3844 if (group
!= sm
->fils_dh_group
) {
3845 wpa_printf(MSG_DEBUG
,
3846 "FILS: Unexpected change in Finite Cyclic Group: %u (expected %u)",
3847 group
, sm
->fils_dh_group
);
3852 if ((size_t) (end
- pos
) < sm
->fils_dh_elem_len
) {
3853 wpa_printf(MSG_DEBUG
, "FILS: No room for Element");
3857 if (!sm
->fils_ecdh
) {
3858 wpa_printf(MSG_DEBUG
, "FILS: No ECDH state available");
3861 dh_ss
= crypto_ecdh_set_peerkey(sm
->fils_ecdh
, 1, pos
,
3862 sm
->fils_dh_elem_len
);
3864 wpa_printf(MSG_DEBUG
, "FILS: ECDH operation failed");
3867 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: DH_SS", dh_ss
);
3869 g_ap_len
= sm
->fils_dh_elem_len
;
3870 pos
+= sm
->fils_dh_elem_len
;
3872 #endif /* CONFIG_FILS_SK_PFS */
3874 wpa_hexdump(MSG_DEBUG
, "FILS: Remaining IEs", pos
, end
- pos
);
3875 if (ieee802_11_parse_elems(pos
, end
- pos
, &elems
, 1) == ParseFailed
) {
3876 wpa_printf(MSG_DEBUG
, "FILS: Could not parse elements");
3881 wpa_hexdump(MSG_DEBUG
, "FILS: RSN element", elems
.rsn_ie
,
3883 if (!elems
.rsn_ie
||
3884 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
3886 wpa_printf(MSG_DEBUG
, "FILS: No RSN element");
3890 if (!elems
.fils_nonce
) {
3891 wpa_printf(MSG_DEBUG
, "FILS: No FILS Nonce field");
3894 os_memcpy(sm
->fils_anonce
, elems
.fils_nonce
, FILS_NONCE_LEN
);
3895 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce", sm
->fils_anonce
, FILS_NONCE_LEN
);
3897 #ifdef CONFIG_IEEE80211R
3898 if (wpa_key_mgmt_ft(sm
->key_mgmt
)) {
3899 struct wpa_ft_ies parse
;
3901 if (!elems
.mdie
|| !elems
.ftie
) {
3902 wpa_printf(MSG_DEBUG
, "FILS+FT: No MDE or FTE");
3906 if (wpa_ft_parse_ies(pos
, end
- pos
, &parse
,
3907 wpa_key_mgmt_sha384(sm
->key_mgmt
)) < 0) {
3908 wpa_printf(MSG_DEBUG
, "FILS+FT: Failed to parse IEs");
3912 if (!parse
.r0kh_id
) {
3913 wpa_printf(MSG_DEBUG
,
3914 "FILS+FT: No R0KH-ID subelem in FTE");
3917 os_memcpy(sm
->r0kh_id
, parse
.r0kh_id
, parse
.r0kh_id_len
);
3918 sm
->r0kh_id_len
= parse
.r0kh_id_len
;
3919 wpa_hexdump_ascii(MSG_DEBUG
, "FILS+FT: R0KH-ID",
3920 sm
->r0kh_id
, sm
->r0kh_id_len
);
3922 if (!parse
.r1kh_id
) {
3923 wpa_printf(MSG_DEBUG
,
3924 "FILS+FT: No R1KH-ID subelem in FTE");
3927 os_memcpy(sm
->r1kh_id
, parse
.r1kh_id
, FT_R1KH_ID_LEN
);
3928 wpa_hexdump(MSG_DEBUG
, "FILS+FT: R1KH-ID",
3929 sm
->r1kh_id
, FT_R1KH_ID_LEN
);
3931 /* TODO: Check MDE and FTE payload */
3933 wpabuf_free(sm
->fils_ft_ies
);
3934 sm
->fils_ft_ies
= wpabuf_alloc(2 + elems
.mdie_len
+
3935 2 + elems
.ftie_len
);
3936 if (!sm
->fils_ft_ies
)
3938 wpabuf_put_data(sm
->fils_ft_ies
, elems
.mdie
- 2,
3939 2 + elems
.mdie_len
);
3940 wpabuf_put_data(sm
->fils_ft_ies
, elems
.ftie
- 2,
3941 2 + elems
.ftie_len
);
3943 wpabuf_free(sm
->fils_ft_ies
);
3944 sm
->fils_ft_ies
= NULL
;
3946 #endif /* CONFIG_IEEE80211R */
3949 if (rsn
.pmkid
&& rsn
.num_pmkid
> 0) {
3950 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID List",
3951 rsn
.pmkid
, rsn
.num_pmkid
* PMKID_LEN
);
3953 if (rsn
.num_pmkid
!= 1) {
3954 wpa_printf(MSG_DEBUG
, "FILS: Invalid PMKID selection");
3957 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", rsn
.pmkid
, PMKID_LEN
);
3958 if (os_memcmp(sm
->cur_pmksa
->pmkid
, rsn
.pmkid
, PMKID_LEN
) != 0)
3960 wpa_printf(MSG_DEBUG
, "FILS: PMKID mismatch");
3961 wpa_hexdump(MSG_DEBUG
, "FILS: Expected PMKID",
3962 sm
->cur_pmksa
->pmkid
, PMKID_LEN
);
3965 wpa_printf(MSG_DEBUG
,
3966 "FILS: Matching PMKID - continue using PMKSA caching");
3969 if (!pmkid_match
&& sm
->cur_pmksa
) {
3970 wpa_printf(MSG_DEBUG
,
3971 "FILS: No PMKID match - cannot use cached PMKSA entry");
3972 sm
->cur_pmksa
= NULL
;
3976 if (!elems
.fils_session
) {
3977 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
3980 wpa_hexdump(MSG_DEBUG
, "FILS: FILS Session", elems
.fils_session
,
3982 if (os_memcmp(sm
->fils_session
, elems
.fils_session
, FILS_SESSION_LEN
)
3984 wpa_printf(MSG_DEBUG
, "FILS: Session mismatch");
3985 wpa_hexdump(MSG_DEBUG
, "FILS: Expected FILS Session",
3986 sm
->fils_session
, FILS_SESSION_LEN
);
3990 /* FILS Wrapped Data */
3991 if (!sm
->cur_pmksa
&& elems
.fils_wrapped_data
) {
3992 u8 rmsk
[ERP_MAX_KEY_LEN
];
3995 wpa_hexdump(MSG_DEBUG
, "FILS: Wrapped Data",
3996 elems
.fils_wrapped_data
,
3997 elems
.fils_wrapped_data_len
);
3998 eapol_sm_process_erp_finish(sm
->eapol
, elems
.fils_wrapped_data
,
3999 elems
.fils_wrapped_data_len
);
4000 if (eapol_sm_failed(sm
->eapol
))
4003 rmsk_len
= ERP_MAX_KEY_LEN
;
4004 res
= eapol_sm_get_key(sm
->eapol
, rmsk
, rmsk_len
);
4005 if (res
== PMK_LEN
) {
4007 res
= eapol_sm_get_key(sm
->eapol
, rmsk
, rmsk_len
);
4012 res
= fils_rmsk_to_pmk(sm
->key_mgmt
, rmsk
, rmsk_len
,
4013 sm
->fils_nonce
, sm
->fils_anonce
,
4014 dh_ss
? wpabuf_head(dh_ss
) : NULL
,
4015 dh_ss
? wpabuf_len(dh_ss
) : 0,
4016 sm
->pmk
, &sm
->pmk_len
);
4017 forced_memzero(rmsk
, sizeof(rmsk
));
4019 /* Don't use DHss in PTK derivation if PMKSA caching is not
4021 wpabuf_clear_free(dh_ss
);
4027 if (!sm
->fils_erp_pmkid_set
) {
4028 wpa_printf(MSG_DEBUG
, "FILS: PMKID not available");
4031 wpa_hexdump(MSG_DEBUG
, "FILS: PMKID", sm
->fils_erp_pmkid
,
4033 wpa_printf(MSG_DEBUG
, "FILS: ERP processing succeeded - add PMKSA cache entry for the result");
4034 sm
->cur_pmksa
= pmksa_cache_add(sm
->pmksa
, sm
->pmk
, sm
->pmk_len
,
4035 sm
->fils_erp_pmkid
, NULL
, 0,
4036 sm
->bssid
, sm
->own_addr
,
4037 sm
->network_ctx
, sm
->key_mgmt
,
4041 if (!sm
->cur_pmksa
) {
4042 wpa_printf(MSG_DEBUG
,
4043 "FILS: No remaining options to continue FILS authentication");
4047 if (fils_pmk_to_ptk(sm
->pmk
, sm
->pmk_len
, sm
->own_addr
, sm
->bssid
,
4048 sm
->fils_nonce
, sm
->fils_anonce
,
4049 dh_ss
? wpabuf_head(dh_ss
) : NULL
,
4050 dh_ss
? wpabuf_len(dh_ss
) : 0,
4051 &sm
->ptk
, ick
, &ick_len
,
4052 sm
->key_mgmt
, sm
->pairwise_cipher
,
4053 sm
->fils_ft
, &sm
->fils_ft_len
) < 0) {
4054 wpa_printf(MSG_DEBUG
, "FILS: Failed to derive PTK");
4058 wpabuf_clear_free(dh_ss
);
4063 os_memset(&sm
->tptk
, 0, sizeof(sm
->tptk
));
4065 #ifdef CONFIG_FILS_SK_PFS
4066 if (sm
->fils_dh_group
) {
4067 if (!sm
->fils_ecdh
) {
4068 wpa_printf(MSG_INFO
, "FILS: ECDH not initialized");
4071 pub
= crypto_ecdh_get_pubkey(sm
->fils_ecdh
, 1);
4074 wpa_hexdump_buf(MSG_DEBUG
, "FILS: gSTA", pub
);
4075 g_sta
= wpabuf_head(pub
);
4076 g_sta_len
= wpabuf_len(pub
);
4078 wpa_printf(MSG_INFO
, "FILS: gAP not available");
4081 wpa_hexdump(MSG_DEBUG
, "FILS: gAP", g_ap
, g_ap_len
);
4083 #endif /* CONFIG_FILS_SK_PFS */
4085 res
= fils_key_auth_sk(ick
, ick_len
, sm
->fils_nonce
,
4086 sm
->fils_anonce
, sm
->own_addr
, sm
->bssid
,
4087 g_sta
, g_sta_len
, g_ap
, g_ap_len
,
4088 sm
->key_mgmt
, sm
->fils_key_auth_sta
,
4089 sm
->fils_key_auth_ap
,
4090 &sm
->fils_key_auth_len
);
4092 forced_memzero(ick
, sizeof(ick
));
4096 wpabuf_clear_free(dh_ss
);
4101 #ifdef CONFIG_IEEE80211R
4102 static int fils_ft_build_assoc_req_rsne(struct wpa_sm
*sm
, struct wpabuf
*buf
)
4104 struct rsn_ie_hdr
*rsnie
;
4107 int use_sha384
= wpa_key_mgmt_sha384(sm
->key_mgmt
);
4109 /* RSNIE[PMKR0Name/PMKR1Name] */
4110 rsnie
= wpabuf_put(buf
, sizeof(*rsnie
));
4111 rsnie
->elem_id
= WLAN_EID_RSN
;
4112 WPA_PUT_LE16(rsnie
->version
, RSN_VERSION
);
4114 /* Group Suite Selector */
4115 if (!wpa_cipher_valid_group(sm
->group_cipher
)) {
4116 wpa_printf(MSG_WARNING
, "FT: Invalid group cipher (%d)",
4120 pos
= wpabuf_put(buf
, RSN_SELECTOR_LEN
);
4121 RSN_SELECTOR_PUT(pos
, wpa_cipher_to_suite(WPA_PROTO_RSN
,
4124 /* Pairwise Suite Count */
4125 wpabuf_put_le16(buf
, 1);
4127 /* Pairwise Suite List */
4128 if (!wpa_cipher_valid_pairwise(sm
->pairwise_cipher
)) {
4129 wpa_printf(MSG_WARNING
, "FT: Invalid pairwise cipher (%d)",
4130 sm
->pairwise_cipher
);
4133 pos
= wpabuf_put(buf
, RSN_SELECTOR_LEN
);
4134 RSN_SELECTOR_PUT(pos
, wpa_cipher_to_suite(WPA_PROTO_RSN
,
4135 sm
->pairwise_cipher
));
4137 /* Authenticated Key Management Suite Count */
4138 wpabuf_put_le16(buf
, 1);
4140 /* Authenticated Key Management Suite List */
4141 pos
= wpabuf_put(buf
, RSN_SELECTOR_LEN
);
4142 if (sm
->key_mgmt
== WPA_KEY_MGMT_FT_FILS_SHA256
)
4143 RSN_SELECTOR_PUT(pos
, RSN_AUTH_KEY_MGMT_FT_FILS_SHA256
);
4144 else if (sm
->key_mgmt
== WPA_KEY_MGMT_FT_FILS_SHA384
)
4145 RSN_SELECTOR_PUT(pos
, RSN_AUTH_KEY_MGMT_FT_FILS_SHA384
);
4147 wpa_printf(MSG_WARNING
,
4148 "FILS+FT: Invalid key management type (%d)",
4153 /* RSN Capabilities */
4156 capab
|= WPA_CAPABILITY_MFPC
;
4158 capab
|= WPA_CAPABILITY_MFPR
;
4160 capab
|= WPA_CAPABILITY_OCVC
;
4161 wpabuf_put_le16(buf
, capab
);
4164 wpabuf_put_le16(buf
, 1);
4166 /* PMKID List [PMKR1Name] */
4167 wpa_hexdump_key(MSG_DEBUG
, "FILS+FT: XXKey (FILS-FT)",
4168 sm
->fils_ft
, sm
->fils_ft_len
);
4169 wpa_hexdump_ascii(MSG_DEBUG
, "FILS+FT: SSID", sm
->ssid
, sm
->ssid_len
);
4170 wpa_hexdump(MSG_DEBUG
, "FILS+FT: MDID",
4171 sm
->mobility_domain
, MOBILITY_DOMAIN_ID_LEN
);
4172 wpa_hexdump_ascii(MSG_DEBUG
, "FILS+FT: R0KH-ID",
4173 sm
->r0kh_id
, sm
->r0kh_id_len
);
4174 if (wpa_derive_pmk_r0(sm
->fils_ft
, sm
->fils_ft_len
, sm
->ssid
,
4175 sm
->ssid_len
, sm
->mobility_domain
,
4176 sm
->r0kh_id
, sm
->r0kh_id_len
, sm
->own_addr
,
4177 sm
->pmk_r0
, sm
->pmk_r0_name
, use_sha384
) < 0) {
4178 wpa_printf(MSG_WARNING
, "FILS+FT: Could not derive PMK-R0");
4181 sm
->pmk_r0_len
= use_sha384
? SHA384_MAC_LEN
: PMK_LEN
;
4182 wpa_hexdump_key(MSG_DEBUG
, "FILS+FT: PMK-R0",
4183 sm
->pmk_r0
, sm
->pmk_r0_len
);
4184 wpa_hexdump(MSG_DEBUG
, "FILS+FT: PMKR0Name",
4185 sm
->pmk_r0_name
, WPA_PMK_NAME_LEN
);
4186 wpa_printf(MSG_DEBUG
, "FILS+FT: R1KH-ID: " MACSTR
,
4187 MAC2STR(sm
->r1kh_id
));
4188 pos
= wpabuf_put(buf
, WPA_PMK_NAME_LEN
);
4189 if (wpa_derive_pmk_r1_name(sm
->pmk_r0_name
, sm
->r1kh_id
, sm
->own_addr
,
4190 sm
->pmk_r1_name
, use_sha384
) < 0) {
4191 wpa_printf(MSG_WARNING
, "FILS+FT: Could not derive PMKR1Name");
4194 wpa_hexdump(MSG_DEBUG
, "FILS+FT: PMKR1Name", sm
->pmk_r1_name
,
4196 os_memcpy(pos
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
);
4198 if (sm
->mgmt_group_cipher
== WPA_CIPHER_AES_128_CMAC
) {
4199 /* Management Group Cipher Suite */
4200 pos
= wpabuf_put(buf
, RSN_SELECTOR_LEN
);
4201 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_AES_128_CMAC
);
4204 rsnie
->len
= ((u8
*) wpabuf_put(buf
, 0) - (u8
*) rsnie
) - 2;
4207 #endif /* CONFIG_IEEE80211R */
4210 struct wpabuf
* fils_build_assoc_req(struct wpa_sm
*sm
, const u8
**kek
,
4211 size_t *kek_len
, const u8
**snonce
,
4213 const struct wpabuf
**hlp
,
4214 unsigned int num_hlp
)
4221 #ifdef CONFIG_IEEE80211R
4222 if (sm
->fils_ft_ies
)
4223 len
+= wpabuf_len(sm
->fils_ft_ies
);
4224 if (wpa_key_mgmt_ft(sm
->key_mgmt
))
4226 #endif /* CONFIG_IEEE80211R */
4227 for (i
= 0; hlp
&& i
< num_hlp
; i
++)
4228 len
+= 10 + wpabuf_len(hlp
[i
]);
4229 buf
= wpabuf_alloc(len
);
4233 #ifdef CONFIG_IEEE80211R
4234 if (wpa_key_mgmt_ft(sm
->key_mgmt
) && sm
->fils_ft_ies
) {
4235 /* MDE and FTE when using FILS+FT */
4236 wpabuf_put_buf(buf
, sm
->fils_ft_ies
);
4237 /* RSNE with PMKR1Name in PMKID field */
4238 if (fils_ft_build_assoc_req_rsne(sm
, buf
) < 0) {
4243 #endif /* CONFIG_IEEE80211R */
4246 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
4247 wpabuf_put_u8(buf
, 1 + FILS_SESSION_LEN
); /* Length */
4248 /* Element ID Extension */
4249 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_SESSION
);
4250 wpabuf_put_data(buf
, sm
->fils_session
, FILS_SESSION_LEN
);
4252 /* Everything after FILS Session element gets encrypted in the driver
4253 * with KEK. The buffer returned from here is the plaintext version. */
4255 /* TODO: FILS Public Key */
4257 /* FILS Key Confirm */
4258 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
4259 wpabuf_put_u8(buf
, 1 + sm
->fils_key_auth_len
); /* Length */
4260 /* Element ID Extension */
4261 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_KEY_CONFIRM
);
4262 wpabuf_put_data(buf
, sm
->fils_key_auth_sta
, sm
->fils_key_auth_len
);
4264 /* FILS HLP Container */
4265 for (i
= 0; hlp
&& i
< num_hlp
; i
++) {
4266 const u8
*pos
= wpabuf_head(hlp
[i
]);
4267 size_t left
= wpabuf_len(hlp
[i
]);
4269 wpabuf_put_u8(buf
, WLAN_EID_EXTENSION
); /* Element ID */
4274 wpabuf_put_u8(buf
, len
); /* Length */
4275 /* Element ID Extension */
4276 wpabuf_put_u8(buf
, WLAN_EID_EXT_FILS_HLP_CONTAINER
);
4277 /* Destination MAC Address, Source MAC Address, HLP Packet.
4278 * HLP Packet is in MSDU format (i.e., included the LLC/SNAP
4279 * header when LPD is used). */
4280 wpabuf_put_data(buf
, pos
, len
- 1);
4284 wpabuf_put_u8(buf
, WLAN_EID_FRAGMENT
);
4285 len
= left
> 255 ? 255 : left
;
4286 wpabuf_put_u8(buf
, len
);
4287 wpabuf_put_data(buf
, pos
, len
);
4293 /* TODO: FILS IP Address Assignment */
4296 if (wpa_sm_ocv_enabled(sm
)) {
4297 struct wpa_channel_info ci
;
4300 if (wpa_sm_channel_info(sm
, &ci
) != 0) {
4301 wpa_printf(MSG_WARNING
,
4302 "FILS: Failed to get channel info for OCI element");
4307 pos
= wpabuf_put(buf
, OCV_OCI_EXTENDED_LEN
);
4308 if (ocv_insert_extended_oci(&ci
, pos
) < 0) {
4313 #endif /* CONFIG_OCV */
4315 wpa_hexdump_buf(MSG_DEBUG
, "FILS: Association Request plaintext", buf
);
4318 *kek_len
= sm
->ptk
.kek_len
;
4319 wpa_hexdump_key(MSG_DEBUG
, "FILS: KEK for AEAD", *kek
, *kek_len
);
4320 *snonce
= sm
->fils_nonce
;
4321 wpa_hexdump(MSG_DEBUG
, "FILS: SNonce for AEAD AAD",
4322 *snonce
, FILS_NONCE_LEN
);
4323 *anonce
= sm
->fils_anonce
;
4324 wpa_hexdump(MSG_DEBUG
, "FILS: ANonce for AEAD AAD",
4325 *anonce
, FILS_NONCE_LEN
);
4331 static void fils_process_hlp_resp(struct wpa_sm
*sm
, const u8
*resp
, size_t len
)
4333 const u8
*pos
, *end
;
4335 wpa_hexdump(MSG_MSGDUMP
, "FILS: HLP response", resp
, len
);
4336 if (len
< 2 * ETH_ALEN
)
4338 pos
= resp
+ 2 * ETH_ALEN
;
4340 if (end
- pos
>= 6 &&
4341 os_memcmp(pos
, "\xaa\xaa\x03\x00\x00\x00", 6) == 0)
4342 pos
+= 6; /* Remove SNAP/LLC header */
4343 wpa_sm_fils_hlp_rx(sm
, resp
, resp
+ ETH_ALEN
, pos
, end
- pos
);
4347 static void fils_process_hlp_container(struct wpa_sm
*sm
, const u8
*pos
,
4350 const u8
*end
= pos
+ len
;
4353 /* Check if there are any FILS HLP Container elements */
4354 while (end
- pos
>= 2) {
4355 if (2 + pos
[1] > end
- pos
)
4357 if (pos
[0] == WLAN_EID_EXTENSION
&&
4358 pos
[1] >= 1 + 2 * ETH_ALEN
&&
4359 pos
[2] == WLAN_EID_EXT_FILS_HLP_CONTAINER
)
4364 return; /* No FILS HLP Container elements */
4366 tmp
= os_malloc(end
- pos
);
4370 while (end
- pos
>= 2) {
4371 if (2 + pos
[1] > end
- pos
||
4372 pos
[0] != WLAN_EID_EXTENSION
||
4373 pos
[1] < 1 + 2 * ETH_ALEN
||
4374 pos
[2] != WLAN_EID_EXT_FILS_HLP_CONTAINER
)
4377 os_memcpy(tmp_pos
, pos
+ 3, pos
[1] - 1);
4378 tmp_pos
+= pos
[1] - 1;
4381 /* Add possible fragments */
4382 while (end
- pos
>= 2 && pos
[0] == WLAN_EID_FRAGMENT
&&
4383 2 + pos
[1] <= end
- pos
) {
4384 os_memcpy(tmp_pos
, pos
+ 2, pos
[1]);
4389 fils_process_hlp_resp(sm
, tmp
, tmp_pos
- tmp
);
4396 int fils_process_assoc_resp(struct wpa_sm
*sm
, const u8
*resp
, size_t len
)
4398 const struct ieee80211_mgmt
*mgmt
;
4399 const u8
*end
, *ie_start
;
4400 struct ieee802_11_elems elems
;
4403 struct wpa_gtk_data gd
;
4405 struct wpa_eapol_ie_parse kde
;
4407 if (!sm
|| !sm
->ptk_set
) {
4408 wpa_printf(MSG_DEBUG
, "FILS: No KEK available");
4412 if (!wpa_key_mgmt_fils(sm
->key_mgmt
)) {
4413 wpa_printf(MSG_DEBUG
, "FILS: Not a FILS AKM");
4417 if (sm
->fils_completed
) {
4418 wpa_printf(MSG_DEBUG
,
4419 "FILS: Association has already been completed for this FILS authentication - ignore unexpected retransmission");
4423 wpa_hexdump(MSG_DEBUG
, "FILS: (Re)Association Response frame",
4426 mgmt
= (const struct ieee80211_mgmt
*) resp
;
4427 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.assoc_resp
))
4431 /* Same offset for Association Response and Reassociation Response */
4432 ie_start
= mgmt
->u
.assoc_resp
.variable
;
4434 if (ieee802_11_parse_elems(ie_start
, end
- ie_start
, &elems
, 1) ==
4436 wpa_printf(MSG_DEBUG
,
4437 "FILS: Failed to parse decrypted elements");
4441 if (!elems
.fils_session
) {
4442 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
4445 if (os_memcmp(elems
.fils_session
, sm
->fils_session
,
4446 FILS_SESSION_LEN
) != 0) {
4447 wpa_printf(MSG_DEBUG
, "FILS: FILS Session mismatch");
4448 wpa_hexdump(MSG_DEBUG
, "FILS: Received FILS Session",
4449 elems
.fils_session
, FILS_SESSION_LEN
);
4450 wpa_hexdump(MSG_DEBUG
, "FILS: Expected FILS Session",
4451 sm
->fils_session
, FILS_SESSION_LEN
);
4454 if (!elems
.rsn_ie
) {
4455 wpa_printf(MSG_DEBUG
,
4456 "FILS: No RSNE in (Re)Association Response");
4457 /* As an interop workaround, allow this for now since IEEE Std
4458 * 802.11ai-2016 did not include all the needed changes to make
4459 * a FILS AP include RSNE in the frame. This workaround might
4460 * eventually be removed and replaced with rejection (goto fail)
4461 * to follow a strict interpretation of the standard. */
4462 } else if (wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm
->key_mgmt
),
4463 sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
,
4464 elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2)) {
4465 wpa_msg(sm
->ctx
->msg_ctx
, MSG_INFO
,
4466 "FILS: RSNE mismatch between Beacon/Probe Response and (Re)Association Response");
4467 wpa_hexdump(MSG_DEBUG
, "FILS: RSNE in Beacon/Probe Response",
4468 sm
->ap_rsn_ie
, sm
->ap_rsn_ie_len
);
4469 wpa_hexdump(MSG_DEBUG
, "FILS: RSNE in (Re)Association Response",
4470 elems
.rsn_ie
, elems
.rsn_ie_len
);
4474 /* TODO: FILS Public Key */
4476 if (!elems
.fils_key_confirm
) {
4477 wpa_printf(MSG_DEBUG
, "FILS: No FILS Key Confirm element");
4480 if (elems
.fils_key_confirm_len
!= sm
->fils_key_auth_len
) {
4481 wpa_printf(MSG_DEBUG
,
4482 "FILS: Unexpected Key-Auth length %d (expected %d)",
4483 elems
.fils_key_confirm_len
,
4484 (int) sm
->fils_key_auth_len
);
4487 if (os_memcmp(elems
.fils_key_confirm
, sm
->fils_key_auth_ap
,
4488 sm
->fils_key_auth_len
) != 0) {
4489 wpa_printf(MSG_DEBUG
, "FILS: Key-Auth mismatch");
4490 wpa_hexdump(MSG_DEBUG
, "FILS: Received Key-Auth",
4491 elems
.fils_key_confirm
,
4492 elems
.fils_key_confirm_len
);
4493 wpa_hexdump(MSG_DEBUG
, "FILS: Expected Key-Auth",
4494 sm
->fils_key_auth_ap
, sm
->fils_key_auth_len
);
4499 if (wpa_sm_ocv_enabled(sm
)) {
4500 struct wpa_channel_info ci
;
4502 if (wpa_sm_channel_info(sm
, &ci
) != 0) {
4503 wpa_printf(MSG_WARNING
,
4504 "Failed to get channel info to validate received OCI in FILS (Re)Association Response frame");
4508 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
4509 channel_width_to_int(ci
.chanwidth
),
4510 ci
.seg1_idx
) != 0) {
4511 wpa_printf(MSG_WARNING
, "FILS: %s", ocv_errorstr
);
4515 #endif /* CONFIG_OCV */
4517 #ifdef CONFIG_IEEE80211R
4518 if (wpa_key_mgmt_ft(sm
->key_mgmt
) && sm
->fils_ft_ies
) {
4519 struct wpa_ie_data rsn
;
4521 /* Check that PMKR1Name derived by the AP matches */
4522 if (!elems
.rsn_ie
||
4523 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, elems
.rsn_ie_len
+ 2,
4525 !rsn
.pmkid
|| rsn
.num_pmkid
!= 1 ||
4526 os_memcmp(rsn
.pmkid
, sm
->pmk_r1_name
,
4527 WPA_PMK_NAME_LEN
) != 0) {
4528 wpa_printf(MSG_DEBUG
,
4529 "FILS+FT: No RSNE[PMKR1Name] match in AssocResp");
4533 #endif /* CONFIG_IEEE80211R */
4536 if (!elems
.key_delivery
) {
4537 wpa_printf(MSG_DEBUG
, "FILS: No Key Delivery element");
4541 /* Parse GTK and set the key to the driver */
4542 os_memset(&gd
, 0, sizeof(gd
));
4543 if (wpa_supplicant_parse_ies(elems
.key_delivery
+ WPA_KEY_RSC_LEN
,
4544 elems
.key_delivery_len
- WPA_KEY_RSC_LEN
,
4546 wpa_printf(MSG_DEBUG
, "FILS: Failed to parse KDEs");
4550 wpa_printf(MSG_DEBUG
, "FILS: No GTK KDE");
4553 maxkeylen
= gd
.gtk_len
= kde
.gtk_len
- 2;
4554 if (wpa_supplicant_check_group_cipher(sm
, sm
->group_cipher
,
4555 gd
.gtk_len
, maxkeylen
,
4556 &gd
.key_rsc_len
, &gd
.alg
))
4559 wpa_hexdump_key(MSG_DEBUG
, "FILS: Received GTK", kde
.gtk
, kde
.gtk_len
);
4560 gd
.keyidx
= kde
.gtk
[0] & 0x3;
4561 gd
.tx
= wpa_supplicant_gtk_tx_bit_workaround(sm
,
4562 !!(kde
.gtk
[0] & BIT(2)));
4563 if (kde
.gtk_len
- 2 > sizeof(gd
.gtk
)) {
4564 wpa_printf(MSG_DEBUG
, "FILS: Too long GTK in GTK KDE (len=%lu)",
4565 (unsigned long) kde
.gtk_len
- 2);
4568 os_memcpy(gd
.gtk
, kde
.gtk
+ 2, kde
.gtk_len
- 2);
4570 wpa_printf(MSG_DEBUG
, "FILS: Set GTK to driver");
4571 if (wpa_supplicant_install_gtk(sm
, &gd
, elems
.key_delivery
, 0) < 0) {
4572 wpa_printf(MSG_DEBUG
, "FILS: Failed to set GTK");
4576 if (ieee80211w_set_keys(sm
, &kde
) < 0) {
4577 wpa_printf(MSG_DEBUG
, "FILS: Failed to set IGTK");
4581 alg
= wpa_cipher_to_alg(sm
->pairwise_cipher
);
4582 keylen
= wpa_cipher_key_len(sm
->pairwise_cipher
);
4583 if (keylen
<= 0 || (unsigned int) keylen
!= sm
->ptk
.tk_len
) {
4584 wpa_printf(MSG_DEBUG
, "FILS: TK length mismatch: %u != %lu",
4585 keylen
, (long unsigned int) sm
->ptk
.tk_len
);
4588 rsclen
= wpa_cipher_rsc_len(sm
->pairwise_cipher
);
4589 wpa_hexdump_key(MSG_DEBUG
, "FILS: Set TK to driver",
4590 sm
->ptk
.tk
, keylen
);
4591 if (wpa_sm_set_key(sm
, alg
, sm
->bssid
, 0, 1, null_rsc
, rsclen
,
4592 sm
->ptk
.tk
, keylen
, KEY_FLAG_PAIRWISE_RX_TX
) < 0) {
4593 wpa_msg(sm
->ctx
->msg_ctx
, MSG_WARNING
,
4594 "FILS: Failed to set PTK to the driver (alg=%d keylen=%d bssid="
4596 alg
, keylen
, MAC2STR(sm
->bssid
));
4600 /* TODO: TK could be cleared after auth frame exchange now that driver
4601 * takes care of association frame encryption/decryption. */
4602 /* TK is not needed anymore in supplicant */
4603 os_memset(sm
->ptk
.tk
, 0, WPA_TK_MAX_LEN
);
4605 sm
->ptk
.installed
= 1;
4607 /* FILS HLP Container */
4608 fils_process_hlp_container(sm
, ie_start
, end
- ie_start
);
4610 /* TODO: FILS IP Address Assignment */
4612 wpa_printf(MSG_DEBUG
, "FILS: Auth+Assoc completed successfully");
4613 sm
->fils_completed
= 1;
4614 forced_memzero(&gd
, sizeof(gd
));
4618 forced_memzero(&gd
, sizeof(gd
));
4623 void wpa_sm_set_reset_fils_completed(struct wpa_sm
*sm
, int set
)
4626 sm
->fils_completed
= !!set
;
4629 #endif /* CONFIG_FILS */
4632 int wpa_fils_is_completed(struct wpa_sm
*sm
)
4635 return sm
&& sm
->fils_completed
;
4636 #else /* CONFIG_FILS */
4638 #endif /* CONFIG_FILS */
4644 struct wpabuf
* owe_build_assoc_req(struct wpa_sm
*sm
, u16 group
)
4646 struct wpabuf
*ie
= NULL
, *pub
= NULL
;
4651 else if (group
== 20)
4653 else if (group
== 21)
4658 crypto_ecdh_deinit(sm
->owe_ecdh
);
4659 sm
->owe_ecdh
= crypto_ecdh_init(group
);
4662 sm
->owe_group
= group
;
4663 pub
= crypto_ecdh_get_pubkey(sm
->owe_ecdh
, 0);
4664 pub
= wpabuf_zeropad(pub
, prime_len
);
4668 ie
= wpabuf_alloc(5 + wpabuf_len(pub
));
4671 wpabuf_put_u8(ie
, WLAN_EID_EXTENSION
);
4672 wpabuf_put_u8(ie
, 1 + 2 + wpabuf_len(pub
));
4673 wpabuf_put_u8(ie
, WLAN_EID_EXT_OWE_DH_PARAM
);
4674 wpabuf_put_le16(ie
, group
);
4675 wpabuf_put_buf(ie
, pub
);
4677 wpa_hexdump_buf(MSG_DEBUG
, "OWE: Diffie-Hellman Parameter element",
4683 crypto_ecdh_deinit(sm
->owe_ecdh
);
4684 sm
->owe_ecdh
= NULL
;
4689 int owe_process_assoc_resp(struct wpa_sm
*sm
, const u8
*bssid
,
4690 const u8
*resp_ies
, size_t resp_ies_len
)
4692 struct ieee802_11_elems elems
;
4694 struct wpabuf
*secret
, *pub
, *hkey
;
4696 u8 prk
[SHA512_MAC_LEN
], pmkid
[SHA512_MAC_LEN
];
4697 const char *info
= "OWE Key Generation";
4700 size_t hash_len
, prime_len
;
4701 struct wpa_ie_data data
;
4704 ieee802_11_parse_elems(resp_ies
, resp_ies_len
, &elems
, 1) ==
4706 wpa_printf(MSG_INFO
,
4707 "OWE: Could not parse Association Response frame elements");
4711 if (sm
->cur_pmksa
&& elems
.rsn_ie
&&
4712 wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2, 2 + elems
.rsn_ie_len
,
4714 data
.num_pmkid
== 1 && data
.pmkid
&&
4715 os_memcmp(sm
->cur_pmksa
->pmkid
, data
.pmkid
, PMKID_LEN
) == 0) {
4716 wpa_printf(MSG_DEBUG
, "OWE: Use PMKSA caching");
4717 wpa_sm_set_pmk_from_pmksa(sm
);
4721 if (!elems
.owe_dh
) {
4722 wpa_printf(MSG_INFO
,
4723 "OWE: No Diffie-Hellman Parameter element found in Association Response frame");
4727 group
= WPA_GET_LE16(elems
.owe_dh
);
4728 if (group
!= sm
->owe_group
) {
4729 wpa_printf(MSG_INFO
,
4730 "OWE: Unexpected Diffie-Hellman group in response: %u",
4735 if (!sm
->owe_ecdh
) {
4736 wpa_printf(MSG_INFO
, "OWE: No ECDH state available");
4742 else if (group
== 20)
4744 else if (group
== 21)
4749 secret
= crypto_ecdh_set_peerkey(sm
->owe_ecdh
, 0,
4751 elems
.owe_dh_len
- 2);
4752 secret
= wpabuf_zeropad(secret
, prime_len
);
4754 wpa_printf(MSG_DEBUG
, "OWE: Invalid peer DH public key");
4757 wpa_hexdump_buf_key(MSG_DEBUG
, "OWE: DH shared secret", secret
);
4759 /* prk = HKDF-extract(C | A | group, z) */
4761 pub
= crypto_ecdh_get_pubkey(sm
->owe_ecdh
, 0);
4763 wpabuf_clear_free(secret
);
4767 /* PMKID = Truncate-128(Hash(C | A)) */
4768 addr
[0] = wpabuf_head(pub
);
4769 len
[0] = wpabuf_len(pub
);
4770 addr
[1] = elems
.owe_dh
+ 2;
4771 len
[1] = elems
.owe_dh_len
- 2;
4773 res
= sha256_vector(2, addr
, len
, pmkid
);
4774 hash_len
= SHA256_MAC_LEN
;
4775 } else if (group
== 20) {
4776 res
= sha384_vector(2, addr
, len
, pmkid
);
4777 hash_len
= SHA384_MAC_LEN
;
4778 } else if (group
== 21) {
4779 res
= sha512_vector(2, addr
, len
, pmkid
);
4780 hash_len
= SHA512_MAC_LEN
;
4785 pub
= wpabuf_zeropad(pub
, prime_len
);
4786 if (res
< 0 || !pub
) {
4788 wpabuf_clear_free(secret
);
4792 hkey
= wpabuf_alloc(wpabuf_len(pub
) + elems
.owe_dh_len
- 2 + 2);
4795 wpabuf_clear_free(secret
);
4799 wpabuf_put_buf(hkey
, pub
); /* C */
4801 wpabuf_put_data(hkey
, elems
.owe_dh
+ 2, elems
.owe_dh_len
- 2); /* A */
4802 wpabuf_put_le16(hkey
, sm
->owe_group
); /* group */
4804 res
= hmac_sha256(wpabuf_head(hkey
), wpabuf_len(hkey
),
4805 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
4806 else if (group
== 20)
4807 res
= hmac_sha384(wpabuf_head(hkey
), wpabuf_len(hkey
),
4808 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
4809 else if (group
== 21)
4810 res
= hmac_sha512(wpabuf_head(hkey
), wpabuf_len(hkey
),
4811 wpabuf_head(secret
), wpabuf_len(secret
), prk
);
4812 wpabuf_clear_free(hkey
);
4813 wpabuf_clear_free(secret
);
4817 wpa_hexdump_key(MSG_DEBUG
, "OWE: prk", prk
, hash_len
);
4819 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
4822 res
= hmac_sha256_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
4823 os_strlen(info
), sm
->pmk
, hash_len
);
4824 else if (group
== 20)
4825 res
= hmac_sha384_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
4826 os_strlen(info
), sm
->pmk
, hash_len
);
4827 else if (group
== 21)
4828 res
= hmac_sha512_kdf(prk
, hash_len
, NULL
, (const u8
*) info
,
4829 os_strlen(info
), sm
->pmk
, hash_len
);
4830 forced_memzero(prk
, SHA512_MAC_LEN
);
4835 sm
->pmk_len
= hash_len
;
4837 wpa_hexdump_key(MSG_DEBUG
, "OWE: PMK", sm
->pmk
, sm
->pmk_len
);
4838 wpa_hexdump(MSG_DEBUG
, "OWE: PMKID", pmkid
, PMKID_LEN
);
4839 pmksa_cache_add(sm
->pmksa
, sm
->pmk
, sm
->pmk_len
, pmkid
, NULL
, 0,
4840 bssid
, sm
->own_addr
, sm
->network_ctx
, sm
->key_mgmt
,
4846 #endif /* CONFIG_OWE */
4849 void wpa_sm_set_fils_cache_id(struct wpa_sm
*sm
, const u8
*fils_cache_id
)
4852 if (sm
&& fils_cache_id
) {
4853 sm
->fils_cache_id_set
= 1;
4854 os_memcpy(sm
->fils_cache_id
, fils_cache_id
, FILS_CACHE_ID_LEN
);
4856 #endif /* CONFIG_FILS */
4861 void wpa_sm_set_dpp_z(struct wpa_sm
*sm
, const struct wpabuf
*z
)
4864 wpabuf_clear_free(sm
->dpp_z
);
4865 sm
->dpp_z
= z
? wpabuf_dup(z
) : NULL
;
4868 #endif /* CONFIG_DPP2 */