OWE: Reduce code duplication in OWE element parsing

Reduce the code-duplication for methods handling the OWE transition
mode.

Signed-off-by: David Bauer <mail@david-bauer.net>
This commit is contained in:
David Bauer 2024-04-28 15:13:40 +02:00 committed by Jouni Malinen
parent 1e54160515
commit ddfed3f084
4 changed files with 49 additions and 45 deletions

View file

@ -1139,30 +1139,20 @@ static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
const u8 **ret_ssid, size_t *ret_ssid_len) const u8 **ret_ssid, size_t *ret_ssid_len)
{ {
#ifdef CONFIG_OWE #ifdef CONFIG_OWE
const u8 *owe, *pos, *end, *bssid; const u8 *owe, *bssid;
u8 ssid_len;
owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
if (!owe || !wpa_bss_get_rsne(wpa_s, bss, NULL, false)) if (!owe || !wpa_bss_get_rsne(wpa_s, bss, NULL, false))
return; return;
pos = owe + 6; if (wpas_get_owe_trans_network(owe, &bssid, ret_ssid, ret_ssid_len))
end = owe + 2 + owe[1];
if (end - pos < ETH_ALEN + 1)
return;
bssid = pos;
pos += ETH_ALEN;
ssid_len = *pos++;
if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
return; return;
/* Match the profile SSID against the OWE transition mode SSID on the /* Match the profile SSID against the OWE transition mode SSID on the
* open network. */ * open network. */
wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
" SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len)); " SSID: %s", MAC2STR(bssid),
*ret_ssid = pos; wpa_ssid_txt(*ret_ssid, *ret_ssid_len));
*ret_ssid_len = ssid_len;
if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) { if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
struct wpa_ssid *ssid; struct wpa_ssid *ssid;
@ -1170,8 +1160,8 @@ static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
if (wpas_network_disabled(wpa_s, ssid)) if (wpas_network_disabled(wpa_s, ssid))
continue; continue;
if (ssid->ssid_len == ssid_len && if (ssid->ssid_len == *ret_ssid_len &&
os_memcmp(ssid->ssid, pos, ssid_len) == 0) { os_memcmp(ssid->ssid, ret_ssid, *ret_ssid_len) == 0) {
/* OWE BSS in transition mode for a currently /* OWE BSS in transition mode for a currently
* enabled OWE network. */ * enabled OWE network. */
wpa_dbg(wpa_s, MSG_DEBUG, wpa_dbg(wpa_s, MSG_DEBUG,

View file

@ -954,8 +954,7 @@ static void wpa_add_owe_scan_ssid(struct wpa_supplicant *wpa_s,
wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
const u8 *owe, *pos, *end; const u8 *owe, *owe_bssid, *owe_ssid;
const u8 *owe_ssid;
size_t owe_ssid_len; size_t owe_ssid_len;
if (bss->ssid_len != ssid->ssid_len || if (bss->ssid_len != ssid->ssid_len ||
@ -966,21 +965,9 @@ static void wpa_add_owe_scan_ssid(struct wpa_supplicant *wpa_s,
if (!owe || owe[1] < 4) if (!owe || owe[1] < 4)
continue; continue;
pos = owe + 6; if (wpas_get_owe_trans_network(owe, &owe_bssid, &owe_ssid,
end = owe + 2 + owe[1]; &owe_ssid_len))
continue;
/* Must include BSSID and ssid_len */
if (end - pos < ETH_ALEN + 1)
return;
/* Skip BSSID */
pos += ETH_ALEN;
owe_ssid_len = *pos++;
owe_ssid = pos;
if ((size_t) (end - pos) < owe_ssid_len ||
owe_ssid_len > SSID_MAX_LEN)
return;
wpa_printf(MSG_DEBUG, wpa_printf(MSG_DEBUG,
"OWE: scan_ssids: transition mode OWE ssid=%s", "OWE: scan_ssids: transition mode OWE ssid=%s",

View file

@ -5504,8 +5504,8 @@ int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level,
static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid, static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid,
const u8 *entry_ssid, size_t entry_ssid_len) const u8 *entry_ssid, size_t entry_ssid_len)
{ {
const u8 *owe, *pos, *end; const u8 *owe, *owe_bssid, *owe_ssid;
u8 ssid_len; size_t owe_ssid_len;
struct wpa_bss *bss; struct wpa_bss *bss;
/* Check network profile SSID aganst the SSID in the /* Check network profile SSID aganst the SSID in the
@ -5519,18 +5519,12 @@ static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid,
if (!owe) if (!owe)
return 0; return 0;
pos = owe + 6; if (wpas_get_owe_trans_network(owe, &owe_bssid, &owe_ssid,
end = owe + 2 + owe[1]; &owe_ssid_len))
if (end - pos < ETH_ALEN + 1)
return 0;
pos += ETH_ALEN;
ssid_len = *pos++;
if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
return 0; return 0;
return entry_ssid_len == ssid_len && return entry_ssid_len == owe_ssid_len &&
os_memcmp(pos, entry_ssid, ssid_len) == 0; os_memcmp(owe_ssid, entry_ssid, owe_ssid_len) == 0;
} }
#endif /* CONFIG_OWE */ #endif /* CONFIG_OWE */
@ -9714,3 +9708,34 @@ bool wpas_ap_supports_rsn_overriding_2(struct wpa_supplicant *wpa_s,
return false; return false;
} }
int wpas_get_owe_trans_network(const u8 *owe_ie, const u8 **bssid,
const u8 **ssid, size_t *ssid_len)
{
#ifdef CONFIG_OWE
const u8 *pos, *end;
u8 ssid_len_tmp;
if (!owe_ie)
return -1;
pos = owe_ie + 6;
end = owe_ie + 2 + owe_ie[1];
if (end - pos < ETH_ALEN + 1)
return -1;
*bssid = pos;
pos += ETH_ALEN;
ssid_len_tmp = *pos++;
if (end - pos < ssid_len_tmp || ssid_len_tmp > SSID_MAX_LEN)
return -1;
*ssid = pos;
*ssid_len = ssid_len_tmp;
return 0;
#else /* CONFIG_OWE */
return -1;
#endif /* CONFIG_OWE */
}

View file

@ -2017,5 +2017,7 @@ bool wpas_ap_supports_rsn_overriding(struct wpa_supplicant *wpa_s,
struct wpa_bss *bss); struct wpa_bss *bss);
bool wpas_ap_supports_rsn_overriding_2(struct wpa_supplicant *wpa_s, bool wpas_ap_supports_rsn_overriding_2(struct wpa_supplicant *wpa_s,
struct wpa_bss *bss); struct wpa_bss *bss);
int wpas_get_owe_trans_network(const u8 *owe_ie, const u8 **bssid,
const u8 **ssid, size_t *ssid_len);
#endif /* WPA_SUPPLICANT_I_H */ #endif /* WPA_SUPPLICANT_I_H */