2020-12-16 12:00:28 +01:00
|
|
|
/*
|
|
|
|
* wpa_supplicant - PASN processing
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Intel Corporation
|
|
|
|
*
|
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
|
|
|
|
#include "common/ieee802_11_defs.h"
|
|
|
|
#include "common/ieee802_11_common.h"
|
|
|
|
#include "common/dragonfly.h"
|
|
|
|
#include "common/ptksa_cache.h"
|
|
|
|
#include "utils/eloop.h"
|
|
|
|
#include "drivers/driver.h"
|
|
|
|
#include "crypto/crypto.h"
|
2020-12-16 12:00:55 +01:00
|
|
|
#include "crypto/random.h"
|
|
|
|
#include "eap_common/eap_defs.h"
|
2020-12-16 12:00:28 +01:00
|
|
|
#include "rsn_supp/wpa.h"
|
|
|
|
#include "rsn_supp/pmksa_cache.h"
|
|
|
|
#include "wpa_supplicant_i.h"
|
|
|
|
#include "driver_i.h"
|
|
|
|
#include "bss.h"
|
2022-07-26 09:50:48 +02:00
|
|
|
#include "scan.h"
|
2020-12-16 12:00:52 +01:00
|
|
|
#include "config.h"
|
2020-12-16 12:00:28 +01:00
|
|
|
|
|
|
|
static const int dot11RSNAConfigPMKLifetime = 43200;
|
|
|
|
|
|
|
|
struct wpa_pasn_auth_work {
|
2022-03-20 10:59:49 +01:00
|
|
|
u8 own_addr[ETH_ALEN];
|
2022-10-30 17:17:28 +01:00
|
|
|
u8 peer_addr[ETH_ALEN];
|
2020-12-16 12:00:28 +01:00
|
|
|
int akmp;
|
|
|
|
int cipher;
|
|
|
|
u16 group;
|
2020-12-16 12:00:52 +01:00
|
|
|
int network_id;
|
2021-03-21 12:55:09 +01:00
|
|
|
struct wpabuf *comeback;
|
2020-12-16 12:00:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-10-29 15:01:29 +02:00
|
|
|
static int wpas_pasn_send_mlme(void *ctx, const u8 *data, size_t data_len,
|
|
|
|
int noack, unsigned int freq, unsigned int wait)
|
|
|
|
{
|
|
|
|
struct wpa_supplicant *wpa_s = ctx;
|
|
|
|
|
|
|
|
return wpa_drv_send_mlme(wpa_s, data, data_len, noack, freq, wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-21 17:33:17 +01:00
|
|
|
static void wpas_pasn_free_auth_work(struct wpa_pasn_auth_work *awork)
|
|
|
|
{
|
|
|
|
wpabuf_free(awork->comeback);
|
|
|
|
awork->comeback = NULL;
|
|
|
|
os_free(awork);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-16 12:00:28 +01:00
|
|
|
static void wpas_pasn_auth_work_timeout(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_supplicant *wpa_s = eloop_ctx;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Auth work timeout - stopping auth");
|
|
|
|
|
|
|
|
wpas_pasn_auth_stop(wpa_s);
|
2022-07-26 09:50:48 +02:00
|
|
|
|
|
|
|
wpas_pasn_auth_work_done(wpa_s, PASN_STATUS_FAILURE);
|
2020-12-16 12:00:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpas_pasn_cancel_auth_work(struct wpa_supplicant *wpa_s)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Cancel pasn-start-auth work");
|
|
|
|
|
|
|
|
/* Remove pending/started work */
|
|
|
|
radio_remove_works(wpa_s, "pasn-start-auth", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
static void wpas_pasn_auth_status(struct wpa_supplicant *wpa_s,
|
|
|
|
const u8 *peer_addr,
|
2021-03-21 12:55:09 +01:00
|
|
|
int akmp, int cipher, u8 status,
|
|
|
|
struct wpabuf *comeback,
|
|
|
|
u16 comeback_after)
|
2020-12-16 12:00:28 +01:00
|
|
|
{
|
2021-03-21 12:55:09 +01:00
|
|
|
if (comeback) {
|
|
|
|
size_t comeback_len = wpabuf_len(comeback);
|
|
|
|
size_t buflen = comeback_len * 2 + 1;
|
|
|
|
char *comeback_txt = os_malloc(buflen);
|
|
|
|
|
|
|
|
if (comeback_txt) {
|
|
|
|
wpa_snprintf_hex(comeback_txt, buflen,
|
|
|
|
wpabuf_head(comeback), comeback_len);
|
|
|
|
|
|
|
|
wpa_msg(wpa_s, MSG_INFO, PASN_AUTH_STATUS MACSTR
|
|
|
|
" akmp=%s, status=%u comeback_after=%u comeback=%s",
|
2022-10-30 17:17:28 +01:00
|
|
|
MAC2STR(peer_addr),
|
2021-03-21 12:55:09 +01:00
|
|
|
wpa_key_mgmt_txt(akmp, WPA_PROTO_RSN),
|
|
|
|
status, comeback_after, comeback_txt);
|
|
|
|
|
|
|
|
os_free(comeback_txt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 12:00:28 +01:00
|
|
|
wpa_msg(wpa_s, MSG_INFO,
|
|
|
|
PASN_AUTH_STATUS MACSTR " akmp=%s, status=%u",
|
2022-10-30 17:17:28 +01:00
|
|
|
MAC2STR(peer_addr), wpa_key_mgmt_txt(akmp, WPA_PROTO_RSN),
|
2020-12-16 12:00:28 +01:00
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-16 12:00:52 +01:00
|
|
|
#ifdef CONFIG_SAE
|
|
|
|
|
2022-10-07 11:04:48 +02:00
|
|
|
static struct sae_pt *
|
|
|
|
wpas_pasn_sae_derive_pt(struct wpa_ssid *ssid, int group)
|
2021-04-08 11:06:24 +02:00
|
|
|
{
|
|
|
|
const char *password = ssid->sae_password;
|
|
|
|
int groups[2] = { group, 0 };
|
|
|
|
|
|
|
|
if (!password)
|
|
|
|
password = ssid->passphrase;
|
|
|
|
|
|
|
|
if (!password) {
|
2022-10-07 11:04:48 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "PASN: SAE without a password");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sae_derive_pt(groups, ssid->ssid, ssid->ssid_len,
|
|
|
|
(const u8 *) password, os_strlen(password),
|
|
|
|
ssid->sae_password_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wpas_pasn_sae_setup_pt(struct wpa_ssid *ssid, int group)
|
|
|
|
{
|
|
|
|
if (!ssid->sae_password && !ssid->passphrase) {
|
2021-04-08 11:06:24 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "PASN: SAE without a password");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ssid->pt)
|
|
|
|
return 0; /* PT already derived */
|
|
|
|
|
2022-10-07 11:04:48 +02:00
|
|
|
ssid->pt = wpas_pasn_sae_derive_pt(ssid, group);
|
2021-04-08 11:06:24 +02:00
|
|
|
|
|
|
|
return ssid->pt ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2020-12-16 12:00:52 +01:00
|
|
|
#endif /* CONFIG_SAE */
|
|
|
|
|
|
|
|
|
2022-07-26 09:50:48 +02:00
|
|
|
static int wpas_pasn_get_params_from_bss(struct wpa_supplicant *wpa_s,
|
|
|
|
struct pasn_peer *peer)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
const u8 *rsne, *rsnxe;
|
|
|
|
struct wpa_bss *bss;
|
|
|
|
struct wpa_ie_data rsne_data;
|
|
|
|
int sel, key_mgmt, pairwise_cipher;
|
|
|
|
int network_id = 0, group = 19;
|
|
|
|
struct wpa_ssid *ssid = NULL;
|
|
|
|
size_t ssid_str_len = 0;
|
|
|
|
const u8 *ssid_str = NULL;
|
2022-10-30 17:17:28 +01:00
|
|
|
const u8 *peer_addr = peer->peer_addr;
|
2022-07-26 09:50:48 +02:00
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
bss = wpa_bss_get_bssid(wpa_s, peer_addr);
|
2022-07-26 09:50:48 +02:00
|
|
|
if (!bss) {
|
|
|
|
wpa_supplicant_update_scan_results(wpa_s);
|
2022-10-30 17:17:28 +01:00
|
|
|
bss = wpa_bss_get_bssid(wpa_s, peer_addr);
|
2022-07-26 09:50:48 +02:00
|
|
|
if (!bss) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: BSS not found");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rsne = wpa_bss_get_ie(bss, WLAN_EID_RSN);
|
|
|
|
if (!rsne) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: BSS without RSNE");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = wpa_parse_wpa_ie(rsne, *(rsne + 1) + 2, &rsne_data);
|
|
|
|
if (ret) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Failed parsing RSNE data");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
|
|
|
|
|
|
|
|
ssid_str_len = bss->ssid_len;
|
|
|
|
ssid_str = bss->ssid;
|
|
|
|
|
|
|
|
/* Get the network configuration based on the obtained SSID */
|
|
|
|
for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
|
|
|
|
if (!wpas_network_disabled(wpa_s, ssid) &&
|
|
|
|
ssid_str_len == ssid->ssid_len &&
|
|
|
|
os_memcmp(ssid_str, ssid->ssid, ssid_str_len) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ssid)
|
|
|
|
network_id = ssid->id;
|
|
|
|
|
|
|
|
sel = rsne_data.pairwise_cipher;
|
|
|
|
if (ssid && ssid->pairwise_cipher)
|
|
|
|
sel &= ssid->pairwise_cipher;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: peer pairwise 0x%x, select 0x%x",
|
|
|
|
rsne_data.pairwise_cipher, sel);
|
|
|
|
|
|
|
|
pairwise_cipher = wpa_pick_pairwise_cipher(sel, 1);
|
|
|
|
if (pairwise_cipher < 0) {
|
|
|
|
wpa_msg(wpa_s, MSG_WARNING,
|
|
|
|
"PASN: Failed to select pairwise cipher");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sel = rsne_data.key_mgmt;
|
|
|
|
if (ssid && ssid->key_mgmt)
|
|
|
|
sel &= ssid->key_mgmt;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: peer AKMP 0x%x, select 0x%x",
|
|
|
|
rsne_data.key_mgmt, sel);
|
|
|
|
#ifdef CONFIG_SAE
|
|
|
|
if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) || !ssid)
|
|
|
|
sel &= ~(WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_SAE_EXT_KEY |
|
|
|
|
WPA_KEY_MGMT_FT_SAE | WPA_KEY_MGMT_FT_SAE_EXT_KEY);
|
|
|
|
#endif /* CONFIG_SAE */
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
if (!(wpa_s->drv_flags & (WPA_DRIVER_FLAGS_SME |
|
|
|
|
WPA_DRIVER_FLAGS_UPDATE_FT_IES)))
|
|
|
|
sel &= ~WPA_KEY_MGMT_FT;
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
if (0) {
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
#ifdef CONFIG_SHA384
|
|
|
|
} else if ((sel & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) &&
|
|
|
|
os_strcmp(wpa_supplicant_get_eap_mode(wpa_s), "LEAP") != 0) {
|
|
|
|
key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: using KEY_MGMT FT/802.1X-SHA384");
|
|
|
|
if (ssid && !ssid->ft_eap_pmksa_caching &&
|
|
|
|
pmksa_cache_get_current(wpa_s->wpa)) {
|
|
|
|
/* PMKSA caching with FT may have interoperability
|
|
|
|
* issues, so disable that case by default for now.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: Disable PMKSA caching for FT/802.1X connection");
|
|
|
|
pmksa_cache_clear_current(wpa_s->wpa);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SHA384 */
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
#ifdef CONFIG_SAE
|
|
|
|
} else if ((sel & WPA_KEY_MGMT_SAE_EXT_KEY) &&
|
|
|
|
(ieee802_11_rsnx_capab(rsnxe,
|
|
|
|
WLAN_RSNX_CAPAB_SAE_H2E)) &&
|
2022-09-28 21:18:18 +02:00
|
|
|
(wpas_pasn_sae_setup_pt(ssid, group) == 0)) {
|
2022-07-26 09:50:48 +02:00
|
|
|
key_mgmt = WPA_KEY_MGMT_SAE_EXT_KEY;
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: using KEY_MGMT SAE (ext key)");
|
|
|
|
} else if ((sel & WPA_KEY_MGMT_SAE) &&
|
|
|
|
(ieee802_11_rsnx_capab(rsnxe,
|
|
|
|
WLAN_RSNX_CAPAB_SAE_H2E)) &&
|
2022-09-28 21:18:18 +02:00
|
|
|
(wpas_pasn_sae_setup_pt(ssid, group) == 0)) {
|
2022-07-26 09:50:48 +02:00
|
|
|
key_mgmt = WPA_KEY_MGMT_SAE;
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: using KEY_MGMT SAE");
|
|
|
|
#endif /* CONFIG_SAE */
|
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
} else if (sel & WPA_KEY_MGMT_FILS_SHA384) {
|
|
|
|
key_mgmt = WPA_KEY_MGMT_FILS_SHA384;
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: using KEY_MGMT FILS-SHA384");
|
|
|
|
} else if (sel & WPA_KEY_MGMT_FILS_SHA256) {
|
|
|
|
key_mgmt = WPA_KEY_MGMT_FILS_SHA256;
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: using KEY_MGMT FILS-SHA256");
|
|
|
|
#endif /* CONFIG_FILS */
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
} else if ((sel & WPA_KEY_MGMT_FT_IEEE8021X) &&
|
|
|
|
os_strcmp(wpa_supplicant_get_eap_mode(wpa_s), "LEAP") != 0) {
|
|
|
|
key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X;
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: using KEY_MGMT FT/802.1X");
|
|
|
|
if (ssid && !ssid->ft_eap_pmksa_caching &&
|
|
|
|
pmksa_cache_get_current(wpa_s->wpa)) {
|
|
|
|
/* PMKSA caching with FT may have interoperability
|
|
|
|
* issues, so disable that case by default for now.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: Disable PMKSA caching for FT/802.1X connection");
|
|
|
|
pmksa_cache_clear_current(wpa_s->wpa);
|
|
|
|
}
|
|
|
|
} else if (sel & WPA_KEY_MGMT_FT_PSK) {
|
|
|
|
key_mgmt = WPA_KEY_MGMT_FT_PSK;
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: using KEY_MGMT FT/PSK");
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
} else if (sel & WPA_KEY_MGMT_PASN) {
|
|
|
|
key_mgmt = WPA_KEY_MGMT_PASN;
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: using KEY_MGMT PASN");
|
|
|
|
} else {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: invalid AKMP");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
peer->akmp = key_mgmt;
|
|
|
|
peer->cipher = pairwise_cipher;
|
|
|
|
peer->network_id = network_id;
|
|
|
|
peer->group = group;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-26 10:26:03 +02:00
|
|
|
static int wpas_pasn_set_keys_from_cache(struct wpa_supplicant *wpa_s,
|
2022-10-30 17:17:28 +01:00
|
|
|
const u8 *own_addr,
|
|
|
|
const u8 *peer_addr,
|
2022-07-26 10:26:03 +02:00
|
|
|
int cipher, int akmp)
|
|
|
|
{
|
|
|
|
struct ptksa_cache_entry *entry;
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
entry = ptksa_cache_get(wpa_s->ptksa, peer_addr, cipher);
|
2022-07-26 10:26:03 +02:00
|
|
|
if (!entry) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: peer " MACSTR
|
2022-10-30 17:17:28 +01:00
|
|
|
" not present in PTKSA cache", MAC2STR(peer_addr));
|
2022-07-26 10:26:03 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os_memcmp(entry->own_addr, own_addr, ETH_ALEN) != 0) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: own addr " MACSTR " and PTKSA entry own addr "
|
|
|
|
MACSTR " differ",
|
|
|
|
MAC2STR(own_addr), MAC2STR(entry->own_addr));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: " MACSTR " present in PTKSA cache",
|
2022-10-30 17:17:28 +01:00
|
|
|
MAC2STR(peer_addr));
|
|
|
|
wpa_drv_set_secure_ranging_ctx(wpa_s, own_addr, peer_addr, cipher,
|
2022-07-26 10:26:03 +02:00
|
|
|
entry->ptk.tk_len,
|
|
|
|
entry->ptk.tk,
|
|
|
|
entry->ptk.ltf_keyseed_len,
|
|
|
|
entry->ptk.ltf_keyseed, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-26 09:50:48 +02:00
|
|
|
static void wpas_pasn_configure_next_peer(struct wpa_supplicant *wpa_s,
|
|
|
|
struct pasn_auth *pasn_params)
|
|
|
|
{
|
|
|
|
struct pasn_peer *peer;
|
|
|
|
u8 comeback_len = 0;
|
|
|
|
const u8 *comeback = NULL;
|
|
|
|
|
|
|
|
if (!pasn_params)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (wpa_s->pasn_count < pasn_params->num_peers) {
|
|
|
|
peer = &pasn_params->peer[wpa_s->pasn_count];
|
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
if (os_memcmp(wpa_s->bssid, peer->peer_addr, ETH_ALEN) == 0) {
|
2020-12-16 12:00:52 +01:00
|
|
|
wpa_printf(MSG_DEBUG,
|
2022-10-30 13:48:16 +01:00
|
|
|
"PASN: Associated peer is not expected");
|
|
|
|
peer->status = PASN_STATUS_FAILURE;
|
|
|
|
wpa_s->pasn_count++;
|
|
|
|
continue;
|
2020-12-16 12:00:52 +01:00
|
|
|
}
|
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
if (wpas_pasn_set_keys_from_cache(wpa_s, peer->own_addr,
|
|
|
|
peer->peer_addr,
|
|
|
|
peer->cipher,
|
|
|
|
peer->akmp) == 0) {
|
|
|
|
peer->status = PASN_STATUS_SUCCESS;
|
|
|
|
wpa_s->pasn_count++;
|
|
|
|
continue;
|
|
|
|
}
|
2020-12-16 12:00:55 +01:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
if (wpas_pasn_get_params_from_bss(wpa_s, peer)) {
|
|
|
|
peer->status = PASN_STATUS_FAILURE;
|
|
|
|
wpa_s->pasn_count++;
|
|
|
|
continue;
|
2020-12-16 12:00:55 +01:00
|
|
|
}
|
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
if (wpas_pasn_auth_start(wpa_s, peer->own_addr,
|
|
|
|
peer->peer_addr, peer->akmp,
|
|
|
|
peer->cipher, peer->group,
|
|
|
|
peer->network_id,
|
|
|
|
comeback, comeback_len)) {
|
|
|
|
peer->status = PASN_STATUS_FAILURE;
|
|
|
|
wpa_s->pasn_count++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Sent PASN auth start for " MACSTR,
|
|
|
|
MAC2STR(peer->peer_addr));
|
|
|
|
return;
|
2020-12-16 12:00:55 +01:00
|
|
|
}
|
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
if (wpa_s->pasn_count == pasn_params->num_peers) {
|
|
|
|
wpa_drv_send_pasn_resp(wpa_s, pasn_params);
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Response sent");
|
|
|
|
os_free(wpa_s->pasn_params);
|
|
|
|
wpa_s->pasn_params = NULL;
|
|
|
|
}
|
2020-12-16 12:00:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
void wpas_pasn_auth_work_done(struct wpa_supplicant *wpa_s, int status)
|
2020-12-16 12:00:28 +01:00
|
|
|
{
|
2022-10-30 13:48:16 +01:00
|
|
|
if (!wpa_s->pasn_params)
|
|
|
|
return;
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
wpa_s->pasn_params->peer[wpa_s->pasn_count].status = status;
|
|
|
|
wpa_s->pasn_count++;
|
|
|
|
wpas_pasn_configure_next_peer(wpa_s, wpa_s->pasn_params);
|
|
|
|
}
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2021-04-08 11:06:24 +02:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
static void wpas_pasn_delete_peers(struct wpa_supplicant *wpa_s,
|
|
|
|
struct pasn_auth *pasn_params)
|
|
|
|
{
|
|
|
|
struct pasn_peer *peer;
|
|
|
|
unsigned int i;
|
2021-04-08 11:06:24 +02:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
if (!pasn_params)
|
|
|
|
return;
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
for (i = 0; i < pasn_params->num_peers; i++) {
|
|
|
|
peer = &pasn_params->peer[i];
|
2022-11-30 20:40:33 +01:00
|
|
|
ptksa_cache_flush(wpa_s->ptksa, peer->peer_addr,
|
|
|
|
WPA_CIPHER_NONE);
|
2020-12-16 12:00:28 +01:00
|
|
|
}
|
2022-10-30 13:48:16 +01:00
|
|
|
}
|
2020-12-16 12:00:28 +01:00
|
|
|
|
|
|
|
|
2022-11-03 09:02:06 +01:00
|
|
|
static void wpas_pasn_initiate_eapol(struct pasn_data *pasn,
|
2022-10-30 13:48:16 +01:00
|
|
|
struct wpa_ssid *ssid)
|
|
|
|
{
|
|
|
|
struct eapol_config eapol_conf;
|
2020-12-16 12:01:38 +01:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "PASN: FILS: Initiating EAPOL");
|
2021-04-08 11:06:20 +02:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
eapol_sm_notify_eap_success(pasn->eapol, false);
|
|
|
|
eapol_sm_notify_eap_fail(pasn->eapol, false);
|
|
|
|
eapol_sm_notify_portControl(pasn->eapol, Auto);
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
os_memset(&eapol_conf, 0, sizeof(eapol_conf));
|
|
|
|
eapol_conf.fast_reauth = pasn->fast_reauth;
|
|
|
|
eapol_conf.workaround = ssid->eap_workaround;
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
eapol_sm_notify_config(pasn->eapol, &ssid->eap, &eapol_conf);
|
|
|
|
}
|
2020-12-16 12:00:28 +01:00
|
|
|
|
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
static void wpas_pasn_reset(struct wpa_supplicant *wpa_s)
|
|
|
|
{
|
2022-11-03 09:02:06 +01:00
|
|
|
struct pasn_data *pasn = &wpa_s->pasn;
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
wpas_pasn_cancel_auth_work(wpa_s);
|
|
|
|
wpa_s->pasn_auth_work = NULL;
|
|
|
|
eloop_cancel_timeout(wpas_pasn_auth_work_timeout, wpa_s, NULL);
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2022-10-30 13:48:16 +01:00
|
|
|
wpa_pasn_reset(pasn);
|
2020-12-16 12:00:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wpa_bss * wpas_pasn_allowed(struct wpa_supplicant *wpa_s,
|
2022-10-30 17:17:28 +01:00
|
|
|
const u8 *peer_addr, int akmp,
|
|
|
|
int cipher)
|
2020-12-16 12:00:28 +01:00
|
|
|
{
|
|
|
|
struct wpa_bss *bss;
|
|
|
|
const u8 *rsne;
|
|
|
|
struct wpa_ie_data rsne_data;
|
|
|
|
int ret;
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
if (os_memcmp(wpa_s->bssid, peer_addr, ETH_ALEN) == 0) {
|
2020-12-16 12:00:28 +01:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: Not doing authentication with current BSS");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
bss = wpa_bss_get_bssid(wpa_s, peer_addr);
|
2020-12-16 12:00:28 +01:00
|
|
|
if (!bss) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: BSS not found");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rsne = wpa_bss_get_ie(bss, WLAN_EID_RSN);
|
|
|
|
if (!rsne) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: BSS without RSNE");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = wpa_parse_wpa_ie(rsne, *(rsne + 1) + 2, &rsne_data);
|
|
|
|
if (ret) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Failed parsing RSNE data");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(rsne_data.key_mgmt & akmp) ||
|
|
|
|
!(rsne_data.pairwise_cipher & cipher)) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: AP does not support requested AKMP or cipher");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bss;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpas_pasn_auth_start_cb(struct wpa_radio_work *work, int deinit)
|
|
|
|
{
|
|
|
|
struct wpa_supplicant *wpa_s = work->wpa_s;
|
|
|
|
struct wpa_pasn_auth_work *awork = work->ctx;
|
2022-11-03 09:02:06 +01:00
|
|
|
struct pasn_data *pasn = &wpa_s->pasn;
|
2022-10-07 11:04:48 +02:00
|
|
|
struct wpa_ssid *ssid;
|
2020-12-16 12:00:28 +01:00
|
|
|
struct wpa_bss *bss;
|
2020-12-16 12:01:38 +01:00
|
|
|
const u8 *rsne, *rsnxe;
|
2022-09-18 15:34:54 +02:00
|
|
|
const u8 *indic;
|
|
|
|
u16 fils_info;
|
2022-09-18 19:43:54 +02:00
|
|
|
u16 capab = 0;
|
2022-09-18 20:29:36 +02:00
|
|
|
bool derive_kdk;
|
2020-12-16 12:00:28 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: auth_start_cb: deinit=%d", deinit);
|
|
|
|
|
|
|
|
if (deinit) {
|
|
|
|
if (work->started) {
|
|
|
|
eloop_cancel_timeout(wpas_pasn_auth_work_timeout,
|
|
|
|
wpa_s, NULL);
|
|
|
|
wpa_s->pasn_auth_work = NULL;
|
|
|
|
}
|
2021-03-21 12:55:09 +01:00
|
|
|
|
2021-03-21 17:33:17 +01:00
|
|
|
wpas_pasn_free_auth_work(awork);
|
2020-12-16 12:00:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is possible that by the time the callback is called, the PASN
|
|
|
|
* authentication is not allowed, e.g., a connection with the AP was
|
|
|
|
* established.
|
|
|
|
*/
|
2022-10-30 17:17:28 +01:00
|
|
|
bss = wpas_pasn_allowed(wpa_s, awork->peer_addr, awork->akmp,
|
2020-12-16 12:00:28 +01:00
|
|
|
awork->cipher);
|
|
|
|
if (!bss) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: auth_start_cb: Not allowed");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
rsne = wpa_bss_get_ie(bss, WLAN_EID_RSN);
|
|
|
|
if (!rsne) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: BSS without RSNE");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-12-16 12:01:38 +01:00
|
|
|
rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
|
|
|
|
|
2022-09-18 20:29:36 +02:00
|
|
|
derive_kdk = (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SEC_LTF_STA) &&
|
|
|
|
ieee802_11_rsnx_capab(rsnxe,
|
|
|
|
WLAN_RSNX_CAPAB_SECURE_LTF);
|
|
|
|
#ifdef CONFIG_TESTING_OPTIONS
|
|
|
|
if (!derive_kdk)
|
|
|
|
derive_kdk = wpa_s->conf->force_kdk_derivation;
|
|
|
|
#endif /* CONFIG_TESTING_OPTIONS */
|
|
|
|
if (derive_kdk)
|
|
|
|
pasn->kdk_len = WPA_KDK_MAX_LEN;
|
|
|
|
else
|
|
|
|
pasn->kdk_len = 0;
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: kdk_len=%zu", pasn->kdk_len);
|
|
|
|
|
|
|
|
if ((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SEC_LTF_STA) &&
|
|
|
|
ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF))
|
|
|
|
pasn->secure_ltf = true;
|
|
|
|
else
|
|
|
|
pasn->secure_ltf = false;
|
|
|
|
|
2022-09-18 15:34:54 +02:00
|
|
|
#ifdef CONFIG_TESTING_OPTIONS
|
|
|
|
pasn->corrupt_mic = wpa_s->conf->pasn_corrupt_mic;
|
|
|
|
#endif /* CONFIG_TESTING_OPTIONS */
|
|
|
|
|
2022-09-18 19:43:54 +02:00
|
|
|
capab |= BIT(WLAN_RSNX_CAPAB_SAE_H2E);
|
|
|
|
if (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SEC_LTF_STA)
|
|
|
|
capab |= BIT(WLAN_RSNX_CAPAB_SECURE_LTF);
|
|
|
|
if (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SEC_RTT_STA)
|
|
|
|
capab |= BIT(WLAN_RSNX_CAPAB_SECURE_RTT);
|
|
|
|
if (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_STA)
|
2022-12-04 13:46:15 +01:00
|
|
|
capab |= BIT(WLAN_RSNX_CAPAB_URNM_MFPR);
|
2022-09-18 19:43:54 +02:00
|
|
|
pasn->rsnxe_capab = capab;
|
2022-10-29 15:01:29 +02:00
|
|
|
pasn->send_mgmt = wpas_pasn_send_mlme;
|
2022-09-18 19:43:54 +02:00
|
|
|
|
2022-10-07 11:04:48 +02:00
|
|
|
ssid = wpa_config_get_network(wpa_s->conf, awork->network_id);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SAE
|
|
|
|
if (awork->akmp == WPA_KEY_MGMT_SAE) {
|
|
|
|
if (!ssid) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: No network profile found for SAE");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
pasn->pt = wpas_pasn_sae_derive_pt(ssid, awork->group);
|
|
|
|
if (!pasn->pt) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Failed to derive PT");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
pasn->network_id = ssid->id;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SAE */
|
|
|
|
|
2022-09-18 15:34:54 +02:00
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
/* Prepare needed information for wpas_pasn_wd_fils_auth(). */
|
|
|
|
if (awork->akmp == WPA_KEY_MGMT_FILS_SHA256 ||
|
|
|
|
awork->akmp == WPA_KEY_MGMT_FILS_SHA384) {
|
|
|
|
indic = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
|
2022-10-07 11:04:48 +02:00
|
|
|
if (!ssid) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: FILS: No network block");
|
|
|
|
} else if (!indic || indic[1] < 2) {
|
2022-09-18 15:34:54 +02:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: Missing FILS Indication IE");
|
|
|
|
} else {
|
|
|
|
fils_info = WPA_GET_LE16(indic + 2);
|
2022-10-07 11:04:48 +02:00
|
|
|
if ((fils_info & BIT(9)) && ssid) {
|
2022-09-18 15:34:54 +02:00
|
|
|
pasn->eapol = wpa_s->eapol;
|
2022-10-07 11:04:48 +02:00
|
|
|
pasn->network_id = ssid->id;
|
|
|
|
wpas_pasn_initiate_eapol(pasn, ssid);
|
2022-09-18 15:34:54 +02:00
|
|
|
pasn->fils_eapol = true;
|
|
|
|
} else {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: FILS auth without PFS not supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pasn->fast_reauth = wpa_s->conf->fast_reauth;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FILS */
|
|
|
|
|
2022-09-18 20:29:36 +02:00
|
|
|
pasn->cb_ctx = wpa_s;
|
2022-09-18 15:34:54 +02:00
|
|
|
pasn->pmksa = wpa_sm_get_pmksa_cache(wpa_s->wpa);
|
2022-09-18 19:57:13 +02:00
|
|
|
|
2022-09-18 19:43:54 +02:00
|
|
|
if (wpa_key_mgmt_ft(awork->akmp)) {
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
ret = wpa_pasn_ft_derive_pmk_r1(wpa_s->wpa, awork->akmp,
|
2022-10-30 17:17:28 +01:00
|
|
|
awork->peer_addr,
|
2022-09-18 19:43:54 +02:00
|
|
|
pasn->pmk_r1,
|
|
|
|
&pasn->pmk_r1_len,
|
|
|
|
pasn->pmk_r1_name);
|
|
|
|
if (ret) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: FT: Failed to derive keys");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
#else /* CONFIG_IEEE80211R */
|
|
|
|
goto fail;
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
}
|
|
|
|
|
2022-09-18 20:29:36 +02:00
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
ret = wpas_pasn_start(pasn, awork->own_addr, awork->peer_addr,
|
2022-11-04 11:45:31 +01:00
|
|
|
awork->peer_addr, awork->akmp, awork->cipher,
|
|
|
|
awork->group, bss->freq, rsne, *(rsne + 1) + 2,
|
2020-12-16 12:01:38 +01:00
|
|
|
rsnxe, rsnxe ? *(rsnxe + 1) + 2 : 0,
|
2022-10-07 11:04:48 +02:00
|
|
|
awork->comeback);
|
2020-12-16 12:00:28 +01:00
|
|
|
if (ret) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: Failed to start PASN authentication");
|
|
|
|
goto fail;
|
|
|
|
}
|
2022-09-18 20:29:36 +02:00
|
|
|
eloop_register_timeout(2, 0, wpas_pasn_auth_work_timeout, wpa_s, NULL);
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2021-03-21 12:55:09 +01:00
|
|
|
/* comeback token is no longer needed at this stage */
|
|
|
|
wpabuf_free(awork->comeback);
|
|
|
|
awork->comeback = NULL;
|
|
|
|
|
2020-12-16 12:00:28 +01:00
|
|
|
wpa_s->pasn_auth_work = work;
|
|
|
|
return;
|
|
|
|
fail:
|
2021-03-21 17:33:17 +01:00
|
|
|
wpas_pasn_free_auth_work(awork);
|
2020-12-16 12:00:28 +01:00
|
|
|
work->ctx = NULL;
|
|
|
|
radio_work_done(work);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-20 10:59:49 +01:00
|
|
|
int wpas_pasn_auth_start(struct wpa_supplicant *wpa_s,
|
2022-10-30 17:17:28 +01:00
|
|
|
const u8 *own_addr, const u8 *peer_addr,
|
2021-03-21 12:55:09 +01:00
|
|
|
int akmp, int cipher, u16 group, int network_id,
|
|
|
|
const u8 *comeback, size_t comeback_len)
|
2020-12-16 12:00:28 +01:00
|
|
|
{
|
|
|
|
struct wpa_pasn_auth_work *awork;
|
|
|
|
struct wpa_bss *bss;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Start: " MACSTR " akmp=0x%x, cipher=0x%x",
|
2022-10-30 17:17:28 +01:00
|
|
|
MAC2STR(peer_addr), akmp, cipher);
|
2020-12-16 12:00:28 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: Consider modifying the offchannel logic to handle additional
|
|
|
|
* Management frames other then Action frames. For now allow PASN only
|
|
|
|
* with drivers that support off-channel TX.
|
|
|
|
*/
|
|
|
|
if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX)) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: Driver does not support offchannel TX");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radio_work_pending(wpa_s, "pasn-start-auth")) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: send_auth: Work is already pending");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wpa_s->pasn_auth_work) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: send_auth: Already in progress");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
bss = wpas_pasn_allowed(wpa_s, peer_addr, akmp, cipher);
|
2020-12-16 12:00:28 +01:00
|
|
|
if (!bss)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
wpas_pasn_reset(wpa_s);
|
|
|
|
|
|
|
|
awork = os_zalloc(sizeof(*awork));
|
|
|
|
if (!awork)
|
|
|
|
return -1;
|
|
|
|
|
2022-03-20 10:59:49 +01:00
|
|
|
os_memcpy(awork->own_addr, own_addr, ETH_ALEN);
|
2022-10-30 17:17:28 +01:00
|
|
|
os_memcpy(awork->peer_addr, peer_addr, ETH_ALEN);
|
2020-12-16 12:00:28 +01:00
|
|
|
awork->akmp = akmp;
|
|
|
|
awork->cipher = cipher;
|
|
|
|
awork->group = group;
|
2020-12-16 12:00:52 +01:00
|
|
|
awork->network_id = network_id;
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2021-03-21 12:55:09 +01:00
|
|
|
if (comeback && comeback_len) {
|
|
|
|
awork->comeback = wpabuf_alloc_copy(comeback, comeback_len);
|
|
|
|
if (!awork->comeback) {
|
2021-03-21 17:33:17 +01:00
|
|
|
wpas_pasn_free_auth_work(awork);
|
2021-03-21 12:55:09 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 12:00:28 +01:00
|
|
|
if (radio_add_work(wpa_s, bss->freq, "pasn-start-auth", 1,
|
|
|
|
wpas_pasn_auth_start_cb, awork) < 0) {
|
2021-03-21 17:33:17 +01:00
|
|
|
wpas_pasn_free_auth_work(awork);
|
2020-12-16 12:00:28 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Auth work successfully added");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpas_pasn_auth_stop(struct wpa_supplicant *wpa_s)
|
|
|
|
{
|
2022-11-03 09:02:06 +01:00
|
|
|
struct pasn_data *pasn = &wpa_s->pasn;
|
2020-12-16 12:00:28 +01:00
|
|
|
|
|
|
|
if (!wpa_s->pasn.ecdh)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Stopping authentication");
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
wpas_pasn_auth_status(wpa_s, pasn->peer_addr, pasn->akmp, pasn->cipher,
|
2021-03-21 12:55:09 +01:00
|
|
|
pasn->status, pasn->comeback,
|
|
|
|
pasn->comeback_after);
|
|
|
|
|
|
|
|
wpas_pasn_reset(wpa_s);
|
|
|
|
}
|
|
|
|
|
2020-12-16 12:00:28 +01:00
|
|
|
|
2021-03-21 12:55:09 +01:00
|
|
|
static int wpas_pasn_immediate_retry(struct wpa_supplicant *wpa_s,
|
2022-11-03 09:02:06 +01:00
|
|
|
struct pasn_data *pasn,
|
2021-03-21 12:55:09 +01:00
|
|
|
struct wpa_pasn_params_data *params)
|
|
|
|
{
|
|
|
|
int akmp = pasn->akmp;
|
|
|
|
int cipher = pasn->cipher;
|
|
|
|
u16 group = pasn->group;
|
2022-03-20 10:59:49 +01:00
|
|
|
u8 own_addr[ETH_ALEN];
|
2022-10-30 17:17:28 +01:00
|
|
|
u8 peer_addr[ETH_ALEN];
|
2021-03-21 12:55:09 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Immediate retry");
|
2022-03-20 10:59:49 +01:00
|
|
|
os_memcpy(own_addr, pasn->own_addr, ETH_ALEN);
|
2022-10-30 17:17:28 +01:00
|
|
|
os_memcpy(peer_addr, pasn->peer_addr, ETH_ALEN);
|
2020-12-16 12:00:28 +01:00
|
|
|
wpas_pasn_reset(wpa_s);
|
2021-03-21 12:55:09 +01:00
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
return wpas_pasn_auth_start(wpa_s, own_addr, peer_addr, akmp, cipher,
|
|
|
|
group, pasn->network_id,
|
2021-03-21 12:55:09 +01:00
|
|
|
params->comeback, params->comeback_len);
|
2020-12-16 12:00:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-08 08:11:01 +02:00
|
|
|
static void wpas_pasn_deauth_cb(struct ptksa_cache_entry *entry)
|
|
|
|
{
|
|
|
|
struct wpa_supplicant *wpa_s = entry->ctx;
|
2022-11-11 19:45:36 +01:00
|
|
|
u8 own_addr[ETH_ALEN];
|
|
|
|
u8 peer_addr[ETH_ALEN];
|
2022-07-08 08:11:01 +02:00
|
|
|
|
2022-11-11 19:45:36 +01:00
|
|
|
/* Use a copy of the addresses from the entry to avoid issues with the
|
|
|
|
* entry getting freed during deauthentication processing. */
|
|
|
|
os_memcpy(own_addr, entry->own_addr, ETH_ALEN);
|
|
|
|
os_memcpy(peer_addr, entry->addr, ETH_ALEN);
|
|
|
|
wpas_pasn_deauthenticate(wpa_s, own_addr, peer_addr);
|
2022-07-08 08:11:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-18 15:43:45 +02:00
|
|
|
int wpas_pasn_auth_rx(struct wpa_supplicant *wpa_s,
|
|
|
|
const struct ieee80211_mgmt *mgmt, size_t len)
|
|
|
|
{
|
2022-11-03 09:02:06 +01:00
|
|
|
struct pasn_data *pasn = &wpa_s->pasn;
|
2022-09-18 15:43:45 +02:00
|
|
|
struct wpa_pasn_params_data pasn_data;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!wpa_s->pasn_auth_work)
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
pasn->cb_ctx = wpa_s;
|
|
|
|
ret = wpa_pasn_auth_rx(pasn, (const u8 *) mgmt, len, &pasn_data);
|
|
|
|
if (ret == 0) {
|
2022-10-30 17:17:28 +01:00
|
|
|
ptksa_cache_add(wpa_s->ptksa, pasn->own_addr, pasn->peer_addr,
|
2022-09-18 15:43:45 +02:00
|
|
|
pasn->cipher, dot11RSNAConfigPMKLifetime,
|
|
|
|
&pasn->ptk,
|
|
|
|
wpa_s->pasn_params ? wpas_pasn_deauth_cb : NULL,
|
2022-09-21 06:44:55 +02:00
|
|
|
wpa_s->pasn_params ? wpa_s : NULL, pasn->akmp);
|
2022-09-18 15:43:45 +02:00
|
|
|
|
|
|
|
if (pasn->pmksa_entry)
|
|
|
|
wpa_sm_set_cur_pmksa(wpa_s->wpa, pasn->pmksa_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
forced_memzero(&pasn->ptk, sizeof(pasn->ptk));
|
|
|
|
|
|
|
|
if (ret == -1) {
|
|
|
|
wpas_pasn_auth_stop(wpa_s);
|
|
|
|
wpas_pasn_auth_work_done(wpa_s, PASN_STATUS_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 1)
|
|
|
|
ret = wpas_pasn_immediate_retry(wpa_s, pasn, &pasn_data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-26 09:50:48 +02:00
|
|
|
void wpas_pasn_auth_trigger(struct wpa_supplicant *wpa_s,
|
|
|
|
struct pasn_auth *pasn_auth)
|
|
|
|
{
|
|
|
|
struct pasn_peer *src, *dst;
|
|
|
|
unsigned int i, num_peers = pasn_auth->num_peers;
|
|
|
|
|
|
|
|
if (wpa_s->pasn_params) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: auth_trigger: Already in progress");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!num_peers || num_peers > WPAS_MAX_PASN_PEERS) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: auth trigger: Invalid number of peers");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_s->pasn_params = os_zalloc(sizeof(struct pasn_auth));
|
|
|
|
if (!wpa_s->pasn_params) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: auth trigger: Failed to allocate a buffer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_s->pasn_count = 0;
|
|
|
|
wpa_s->pasn_params->num_peers = num_peers;
|
|
|
|
|
|
|
|
for (i = 0; i < num_peers; i++) {
|
|
|
|
dst = &wpa_s->pasn_params->peer[i];
|
|
|
|
src = &pasn_auth->peer[i];
|
|
|
|
os_memcpy(dst->own_addr, wpa_s->own_addr, ETH_ALEN);
|
|
|
|
os_memcpy(dst->peer_addr, src->peer_addr, ETH_ALEN);
|
|
|
|
dst->ltf_keyseed_required = src->ltf_keyseed_required;
|
|
|
|
dst->status = PASN_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
if (!is_zero_ether_addr(src->own_addr)) {
|
|
|
|
os_memcpy(dst->own_addr, src->own_addr, ETH_ALEN);
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: Own (source) MAC addr: "
|
|
|
|
MACSTR, MAC2STR(dst->own_addr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pasn_auth->action == PASN_ACTION_DELETE_SECURE_RANGING_CONTEXT) {
|
|
|
|
wpas_pasn_delete_peers(wpa_s, wpa_s->pasn_params);
|
|
|
|
os_free(wpa_s->pasn_params);
|
|
|
|
wpa_s->pasn_params = NULL;
|
|
|
|
} else if (pasn_auth->action == PASN_ACTION_AUTH) {
|
|
|
|
wpas_pasn_configure_next_peer(wpa_s, wpa_s->pasn_params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-18 15:46:04 +02:00
|
|
|
int wpas_pasn_auth_tx_status(struct wpa_supplicant *wpa_s,
|
|
|
|
const u8 *data, size_t data_len, u8 acked)
|
|
|
|
|
|
|
|
{
|
2022-11-03 09:02:06 +01:00
|
|
|
struct pasn_data *pasn = &wpa_s->pasn;
|
2022-09-18 15:46:04 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!wpa_s->pasn_auth_work) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: auth_tx_status: no work in progress");
|
|
|
|
return -1;
|
2020-12-16 12:00:28 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:04 +02:00
|
|
|
ret = wpa_pasn_auth_tx_status(pasn, data, data_len, acked);
|
|
|
|
if (ret != 1)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!wpa_s->pasn_params) {
|
|
|
|
wpas_pasn_auth_stop(wpa_s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
wpas_pasn_set_keys_from_cache(wpa_s, pasn->own_addr, pasn->peer_addr,
|
2022-09-18 15:46:04 +02:00
|
|
|
pasn->cipher, pasn->akmp);
|
|
|
|
wpas_pasn_auth_stop(wpa_s);
|
|
|
|
wpas_pasn_auth_work_done(wpa_s, PASN_STATUS_SUCCESS);
|
|
|
|
|
2020-12-16 12:00:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2021-03-15 13:57:12 +01:00
|
|
|
|
|
|
|
|
2022-03-20 10:59:49 +01:00
|
|
|
int wpas_pasn_deauthenticate(struct wpa_supplicant *wpa_s, const u8 *own_addr,
|
2022-10-30 17:17:28 +01:00
|
|
|
const u8 *peer_addr)
|
2021-03-15 13:57:12 +01:00
|
|
|
{
|
|
|
|
struct wpa_bss *bss;
|
|
|
|
struct wpabuf *buf;
|
|
|
|
struct ieee80211_mgmt *deauth;
|
|
|
|
int ret;
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
if (os_memcmp(wpa_s->bssid, peer_addr, ETH_ALEN) == 0) {
|
2021-03-15 13:57:12 +01:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"PASN: Cannot deauthenticate from current BSS");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
wpa_drv_set_secure_ranging_ctx(wpa_s, own_addr, peer_addr, 0, 0, NULL,
|
|
|
|
0, NULL, 1);
|
2022-07-26 09:50:48 +02:00
|
|
|
|
2021-03-15 13:57:12 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "PASN: deauth: Flushing all PTKSA entries for "
|
2022-10-30 17:17:28 +01:00
|
|
|
MACSTR, MAC2STR(peer_addr));
|
|
|
|
ptksa_cache_flush(wpa_s->ptksa, peer_addr, WPA_CIPHER_NONE);
|
2021-03-15 13:57:12 +01:00
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
bss = wpa_bss_get_bssid(wpa_s, peer_addr);
|
2021-03-15 13:57:12 +01:00
|
|
|
if (!bss) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: deauth: BSS not found");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = wpabuf_alloc(64);
|
|
|
|
if (!buf) {
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: deauth: Failed wpabuf allocate");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
deauth = wpabuf_put(buf, offsetof(struct ieee80211_mgmt,
|
|
|
|
u.deauth.variable));
|
|
|
|
|
|
|
|
deauth->frame_control = host_to_le16((WLAN_FC_TYPE_MGMT << 2) |
|
|
|
|
(WLAN_FC_STYPE_DEAUTH << 4));
|
|
|
|
|
2022-10-30 17:17:28 +01:00
|
|
|
os_memcpy(deauth->da, peer_addr, ETH_ALEN);
|
2022-03-20 10:59:49 +01:00
|
|
|
os_memcpy(deauth->sa, own_addr, ETH_ALEN);
|
2022-10-30 17:17:28 +01:00
|
|
|
os_memcpy(deauth->bssid, peer_addr, ETH_ALEN);
|
2021-03-15 13:57:12 +01:00
|
|
|
deauth->u.deauth.reason_code =
|
|
|
|
host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we do not expect any response from the AP, implement the
|
|
|
|
* Deauthentication frame transmission using direct call to the driver
|
|
|
|
* without a radio work.
|
|
|
|
*/
|
|
|
|
ret = wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf), 1,
|
|
|
|
bss->freq, 0);
|
|
|
|
|
|
|
|
wpabuf_free(buf);
|
|
|
|
wpa_printf(MSG_DEBUG, "PASN: deauth: send_mlme ret=%d", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|