From 7381c60db8f0ed926d88394de8cfbee4ba5159bc Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 25 Aug 2023 11:28:44 +0300 Subject: [PATCH] FT: Make FTE MIC calculation more flexible Generate the "extra" data buffer outside wpa_ft_mic() to make this function easier to share for MLO FT Reassociation Response frame. This replaces the earlier design in commit e6f64a8e1daf ("FT: FTE MIC calculation for MLO Reassociation Request frame"). Signed-off-by: Jouni Malinen --- src/common/wpa_common.c | 18 +++++++----------- src/common/wpa_common.h | 5 +++-- wlantest/rx_mgmt.c | 20 +++++++++++++++++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/common/wpa_common.c b/src/common/wpa_common.c index 4456e6a16..c11b461eb 100644 --- a/src/common/wpa_common.c +++ b/src/common/wpa_common.c @@ -890,11 +890,11 @@ int wpa_ft_mic(int key_mgmt, const u8 *kck, size_t kck_len, const u8 *sta_addr, const u8 *rsnie, size_t rsnie_len, const u8 *ric, size_t ric_len, const u8 *rsnxe, size_t rsnxe_len, - const u8 link_addr[MAX_NUM_MLO_LINKS][ETH_ALEN], + const struct wpabuf *extra, u8 *mic) { - const u8 *addr[10 + MAX_NUM_MLO_LINKS]; - size_t len[10 + MAX_NUM_MLO_LINKS]; + const u8 *addr[11]; + size_t len[11]; size_t i, num_elem = 0; u8 zero_mic[32]; size_t mic_len, fte_fixed_len; @@ -972,14 +972,10 @@ int wpa_ft_mic(int key_mgmt, const u8 *kck, size_t kck_len, const u8 *sta_addr, num_elem++; } - if (link_addr) { - for (i = 0; i < MAX_NUM_MLO_LINKS; i++) { - if (is_zero_ether_addr(link_addr[i])) - continue; - addr[num_elem] = link_addr[i]; - len[num_elem] = ETH_ALEN; - num_elem++; - } + if (extra) { + addr[num_elem] = wpabuf_head(extra); + len[num_elem] = wpabuf_len(extra); + num_elem++; } for (i = 0; i < num_elem; i++) diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h index 2a7c75224..bfcd71781 100644 --- a/src/common/wpa_common.h +++ b/src/common/wpa_common.h @@ -452,7 +452,6 @@ struct rsn_rdie { #pragma pack(pop) #endif /* _MSC_VER */ -#define MAX_NUM_MLO_LINKS 15 int wpa_eapol_key_mic(const u8 *key, size_t key_len, int akmp, int ver, const u8 *buf, size_t len, u8 *mic); @@ -486,7 +485,7 @@ int wpa_ft_mic(int key_mgmt, const u8 *kck, size_t kck_len, const u8 *sta_addr, const u8 *rsnie, size_t rsnie_len, const u8 *ric, size_t ric_len, const u8 *rsnxe, size_t rsnxe_len, - const u8 link_addr[MAX_NUM_MLO_LINKS][ETH_ALEN], + const struct wpabuf *extra, u8 *mic); int wpa_derive_pmk_r0(const u8 *xxkey, size_t xxkey_len, const u8 *ssid, size_t ssid_len, @@ -558,6 +557,8 @@ int wpa_compare_rsn_ie(int ft_initial_assoc, const u8 *ie2, size_t ie2len); int wpa_insert_pmkid(u8 *ies, size_t *ies_len, const u8 *pmkid); +#define MAX_NUM_MLO_LINKS 15 + struct wpa_ft_ies { const u8 *mdie; size_t mdie_len; diff --git a/wlantest/rx_mgmt.c b/wlantest/rx_mgmt.c index 82a2255c2..461679e5e 100644 --- a/wlantest/rx_mgmt.c +++ b/wlantest/rx_mgmt.c @@ -1290,6 +1290,7 @@ static void rx_mgmt_reassoc_req(struct wlantest *wt, const u8 *data, const u8 *kck; size_t kck_len; const u8 *aa, *spa; + struct wpabuf *extra = NULL; if (elems.basic_mle) { aa = bss->mld_mac_addr; @@ -1425,6 +1426,21 @@ static void rx_mgmt_reassoc_req(struct wlantest *wt, const u8 *data, kck = sta->ptk.kck; kck_len = sta->ptk.kck_len; } + + if (elems.basic_mle) { + int i; + + extra = wpabuf_alloc(MAX_NUM_MLO_LINKS * ETH_ALEN); + if (!extra) + return; + for (i = 0; i < MAX_NUM_MLO_LINKS; i++) { + if (!is_zero_ether_addr(sta->link_addr[i])) + wpabuf_put_data(extra, + sta->link_addr[i], + ETH_ALEN); + } + } + if (wpa_ft_mic(sta->key_mgmt, kck, kck_len, spa, aa, 5, parse.mdie - 2, parse.mdie_len + 2, @@ -1433,11 +1449,13 @@ static void rx_mgmt_reassoc_req(struct wlantest *wt, const u8 *data, parse.ric, parse.ric_len, parse.rsnxe ? parse.rsnxe - 2 : NULL, parse.rsnxe ? parse.rsnxe_len + 2 : 0, - elems.basic_mle ? sta->link_addr : NULL, + extra, mic) < 0) { + wpabuf_free(extra); add_note(wt, MSG_INFO, "FT: Failed to calculate MIC"); return; } + wpabuf_free(extra); if (os_memcmp_const(mic, fte_mic, mic_len) != 0) { int link_id;