Skip to content

Commit 73b838d

Browse files
committed
Merge branch 'bugfix/sae_auth_and_pmk_issues' into 'master'
Fix SAE open auth and PMK issues Closes WIFI-5059 See merge request espressif/esp-idf!21910
2 parents cdcb493 + 9603d1d commit 73b838d

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static struct wpabuf *g_sae_commit = NULL;
1818
static struct wpabuf *g_sae_confirm = NULL;
1919
int g_allowed_groups[] = { IANA_SECP256R1, 0 };
2020

21-
static esp_err_t wpa3_build_sae_commit(u8 *bssid)
21+
static esp_err_t wpa3_build_sae_commit(u8 *bssid, size_t *sae_msg_len)
2222
{
2323
int default_group = IANA_SECP256R1;
2424
u32 len = 0;
@@ -33,6 +33,7 @@ static esp_err_t wpa3_build_sae_commit(u8 *bssid)
3333

3434
if (wpa_sta_cur_pmksa_matches_akm()) {
3535
wpa_printf(MSG_INFO, "wpa3: Skip SAE and use cached PMK instead");
36+
*sae_msg_len = 0;
3637
return ESP_FAIL;
3738
}
3839

@@ -151,7 +152,7 @@ static u8 *wpa3_build_sae_msg(u8 *bssid, u32 sae_msg_type, size_t *sae_msg_len)
151152
if (esp_wifi_get_wps_status_internal() != WPS_STATUS_DISABLE) {
152153
return NULL;
153154
}
154-
if (ESP_OK != wpa3_build_sae_commit(bssid))
155+
if (ESP_OK != wpa3_build_sae_commit(bssid, sae_msg_len))
155156
return NULL;
156157
*sae_msg_len = wpabuf_len(g_sae_commit);
157158
buf = wpabuf_mhead_u8(g_sae_commit);

components/wpa_supplicant/src/common/defs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ static inline int wpa_key_mgmt_cckm(int akm)
126126
return akm == WPA_KEY_MGMT_CCKM;
127127
}
128128

129+
#ifdef ESP_SUPPLICANT
130+
static inline int wpa_key_mgmt_supports_caching(int akm)
131+
{
132+
return wpa_key_mgmt_wpa_ieee8021x(akm) ||
133+
wpa_key_mgmt_sae(akm) ||
134+
wpa_key_mgmt_owe(akm);
135+
}
136+
#endif
129137

130138
#define WPA_PROTO_WPA BIT(0)
131139
#define WPA_PROTO_RSN BIT(1)

components/wpa_supplicant/src/rsn_supp/wpa.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,7 +2425,7 @@ int wpa_set_bss(char *macddr, char * bssid, u8 pairwise_cipher, u8 group_cipher,
24252425
{
24262426
int res = 0;
24272427
struct wpa_sm *sm = &gWpaSm;
2428-
bool use_pmk_cache = true;
2428+
bool use_pmk_cache = !esp_wifi_skip_supp_pmkcaching();
24292429
u8 assoc_rsnxe[20];
24302430
size_t assoc_rsnxe_len = sizeof(assoc_rsnxe);
24312431

@@ -2450,28 +2450,19 @@ int wpa_set_bss(char *macddr, char * bssid, u8 pairwise_cipher, u8 group_cipher,
24502450
sm->use_ext_key_id = (sm->proto == WPA_PROTO_WPA);
24512451
pmksa_cache_clear_current(sm);
24522452

2453-
if (sm->key_mgmt == WPA_KEY_MGMT_SAE ||
2454-
sm->key_mgmt == WPA_KEY_MGMT_OWE ||
2455-
is_wpa2_enterprise_connection()) {
2456-
if (!esp_wifi_skip_supp_pmkcaching() && use_pmk_cache) {
2457-
if (pmksa_cache_set_current(sm, NULL, (const u8*) bssid, 0, 0) == 0) {
2458-
struct rsn_pmksa_cache_entry *pmksa = pmksa_cache_get_current(sm);
2459-
if (pmksa && (pmksa->akmp != sm->key_mgmt)) {
2460-
pmksa_cache_clear_current(sm);
2461-
pmksa_cache_flush(sm->pmksa, NULL, pmksa->pmk, pmksa->pmk_len);
2462-
}
2463-
} else {
2464-
wpa_sm_set_pmk_from_pmksa(sm);
2465-
}
2466-
} else {
2467-
struct rsn_pmksa_cache_entry *entry = NULL;
2468-
2469-
if (sm->pmksa) {
2470-
entry = pmksa_cache_get(sm->pmksa, (const u8 *)bssid, NULL, NULL);
2471-
}
2472-
if (entry) {
2473-
pmksa_cache_flush(sm->pmksa, NULL, entry->pmk, entry->pmk_len);
2474-
}
2453+
struct rsn_pmksa_cache_entry *pmksa = NULL;
2454+
if (use_pmk_cache) {
2455+
pmksa = pmksa_cache_get(sm->pmksa, (const u8 *)bssid, NULL, NULL);
2456+
if (pmksa && (pmksa->akmp != sm->key_mgmt)) {
2457+
use_pmk_cache = false;
2458+
}
2459+
}
2460+
if (wpa_key_mgmt_supports_caching(sm->key_mgmt) && use_pmk_cache) {
2461+
pmksa_cache_set_current(sm, NULL, (const u8*) bssid, 0, 0);
2462+
wpa_sm_set_pmk_from_pmksa(sm);
2463+
} else {
2464+
if (pmksa) {
2465+
pmksa_cache_flush(sm->pmksa, NULL, pmksa->pmk, pmksa->pmk_len);
24752466
}
24762467
}
24772468

0 commit comments

Comments
 (0)