3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-10-05 19:08:52 +02:00

handshake: simplify IE setters

The handshake object had 4 setters for authenticator/supplicant IE.
Since the IE ultimately gets put into the same buffer, there really
only needs to be a single setter for authenticator/supplicant. The
handshake object can deal with parsing to decide what kind of IE it
is (WPA or RSN).
This commit is contained in:
James Prestwood 2019-06-07 12:17:00 -07:00 committed by Denis Kenzior
parent f6df93d358
commit 75e6ee98f3
6 changed files with 24 additions and 52 deletions

View File

@ -228,8 +228,8 @@ static struct eapol_sm *adhoc_new_sm(struct sta_state *sta, bool authenticator,
handshake_state_set_event_func(hs, adhoc_handshake_event, sta); handshake_state_set_event_func(hs, adhoc_handshake_event, sta);
handshake_state_set_ssid(hs, (void *)adhoc->ssid, strlen(adhoc->ssid)); handshake_state_set_ssid(hs, (void *)adhoc->ssid, strlen(adhoc->ssid));
/* we dont have the connecting peer rsn info, so just set ap == own */ /* we dont have the connecting peer rsn info, so just set ap == own */
handshake_state_set_authenticator_rsn(hs, bss_rsne); handshake_state_set_authenticator_ie(hs, bss_rsne);
handshake_state_set_supplicant_rsn(hs, bss_rsne); handshake_state_set_supplicant_ie(hs, bss_rsne);
handshake_state_set_pmk(hs, adhoc->pmk, 32); handshake_state_set_pmk(hs, adhoc->pmk, 32);
if (authenticator) { if (authenticator) {

View File

@ -425,8 +425,8 @@ static void ap_start_rsna(struct sta_state *sta, const uint8_t *gtk_rsc)
handshake_state_set_event_func(sta->hs, ap_handshake_event, sta); handshake_state_set_event_func(sta->hs, ap_handshake_event, sta);
handshake_state_set_ssid(sta->hs, (void *)ap->ssid, strlen(ap->ssid)); handshake_state_set_ssid(sta->hs, (void *)ap->ssid, strlen(ap->ssid));
handshake_state_set_authenticator(sta->hs, true); handshake_state_set_authenticator(sta->hs, true);
handshake_state_set_authenticator_rsn(sta->hs, bss_rsne); handshake_state_set_authenticator_ie(sta->hs, bss_rsne);
handshake_state_set_supplicant_rsn(sta->hs, sta->assoc_rsne); handshake_state_set_supplicant_ie(sta->hs, sta->assoc_rsne);
handshake_state_set_pmk(sta->hs, ap->pmk, 32); handshake_state_set_pmk(sta->hs, ap->pmk, 32);
handshake_state_set_authenticator_address(sta->hs, own_addr); handshake_state_set_authenticator_address(sta->hs, own_addr);
handshake_state_set_supplicant_address(sta->hs, sta->addr); handshake_state_set_supplicant_address(sta->hs, sta->addr);

View File

@ -148,19 +148,19 @@ static bool handshake_state_setup_own_ciphers(struct handshake_state *s,
return true; return true;
} }
static bool handshake_state_set_authenticator_ie(struct handshake_state *s, bool handshake_state_set_authenticator_ie(struct handshake_state *s,
const uint8_t *ie, bool is_wpa) const uint8_t *ie)
{ {
struct ie_rsn_info info; struct ie_rsn_info info;
l_free(s->authenticator_ie); l_free(s->authenticator_ie);
s->authenticator_ie = l_memdup(ie, ie[1] + 2u); s->authenticator_ie = l_memdup(ie, ie[1] + 2u);
s->wpa_ie = is_wpa; s->wpa_ie = is_ie_wpa_ie(ie + 2, ie[1]);
if (!s->authenticator) if (!s->authenticator)
return true; return true;
if (is_wpa) { if (s->wpa_ie) {
if (ie_parse_wpa_from_data(ie, ie[1] + 2, &info) < 0) if (ie_parse_wpa_from_data(ie, ie[1] + 2, &info) < 0)
return false; return false;
} else { } else {
@ -171,19 +171,19 @@ static bool handshake_state_set_authenticator_ie(struct handshake_state *s,
return handshake_state_setup_own_ciphers(s, &info); return handshake_state_setup_own_ciphers(s, &info);
} }
static bool handshake_state_set_supplicant_ie(struct handshake_state *s, bool handshake_state_set_supplicant_ie(struct handshake_state *s,
const uint8_t *ie, bool is_wpa) const uint8_t *ie)
{ {
struct ie_rsn_info info; struct ie_rsn_info info;
l_free(s->supplicant_ie); l_free(s->supplicant_ie);
s->supplicant_ie = l_memdup(ie, ie[1] + 2u); s->supplicant_ie = l_memdup(ie, ie[1] + 2u);
s->wpa_ie = is_wpa; s->wpa_ie = is_ie_wpa_ie(ie + 2, ie[1]);
if (s->authenticator) if (s->authenticator)
return true; return true;
if (is_wpa) { if (s->wpa_ie) {
if (ie_parse_wpa_from_data(ie, ie[1] + 2, &info) < 0) if (ie_parse_wpa_from_data(ie, ie[1] + 2, &info) < 0)
return false; return false;
} else { } else {
@ -194,30 +194,6 @@ static bool handshake_state_set_supplicant_ie(struct handshake_state *s,
return handshake_state_setup_own_ciphers(s, &info); return handshake_state_setup_own_ciphers(s, &info);
} }
bool handshake_state_set_authenticator_rsn(struct handshake_state *s,
const uint8_t *rsn_ie)
{
return handshake_state_set_authenticator_ie(s, rsn_ie, false);
}
bool handshake_state_set_supplicant_rsn(struct handshake_state *s,
const uint8_t *rsn_ie)
{
return handshake_state_set_supplicant_ie(s, rsn_ie, false);
}
bool handshake_state_set_authenticator_wpa(struct handshake_state *s,
const uint8_t *wpa_ie)
{
return handshake_state_set_authenticator_ie(s, wpa_ie, true);
}
bool handshake_state_set_supplicant_wpa(struct handshake_state *s,
const uint8_t *wpa_ie)
{
return handshake_state_set_supplicant_ie(s, wpa_ie, true);
}
void handshake_state_set_ssid(struct handshake_state *s, const uint8_t *ssid, void handshake_state_set_ssid(struct handshake_state *s, const uint8_t *ssid,
size_t ssid_len) size_t ssid_len)
{ {

View File

@ -141,14 +141,10 @@ void handshake_state_set_ptk(struct handshake_state *s, const uint8_t *ptk,
size_t ptk_len); size_t ptk_len);
void handshake_state_set_8021x_config(struct handshake_state *s, void handshake_state_set_8021x_config(struct handshake_state *s,
struct l_settings *settings); struct l_settings *settings);
bool handshake_state_set_supplicant_rsn(struct handshake_state *s, bool handshake_state_set_authenticator_ie(struct handshake_state *s,
const uint8_t *rsn_ie); const uint8_t *ie);
bool handshake_state_set_authenticator_rsn(struct handshake_state *s, bool handshake_state_set_supplicant_ie(struct handshake_state *s,
const uint8_t *rsn_ie); const uint8_t *ie);
bool handshake_state_set_supplicant_wpa(struct handshake_state *s,
const uint8_t *wpa_ie);
bool handshake_state_set_authenticator_wpa(struct handshake_state *s,
const uint8_t *wpa_ie);
void handshake_state_set_ssid(struct handshake_state *s, void handshake_state_set_ssid(struct handshake_state *s,
const uint8_t *ssid, size_t ssid_len); const uint8_t *ssid, size_t ssid_len);
void handshake_state_set_mde(struct handshake_state *s, void handshake_state_set_mde(struct handshake_state *s,

View File

@ -1616,14 +1616,14 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev)
switch (ie_tlv_iter_get_tag(&iter)) { switch (ie_tlv_iter_get_tag(&iter)) {
case IE_TYPE_RSN: case IE_TYPE_RSN:
handshake_state_set_supplicant_rsn(netdev->handshake, handshake_state_set_supplicant_ie(netdev->handshake,
data - 2); data - 2);
break; break;
case IE_TYPE_VENDOR_SPECIFIC: case IE_TYPE_VENDOR_SPECIFIC:
if (!is_ie_wpa_ie(data, ie_tlv_iter_get_length(&iter))) if (!is_ie_wpa_ie(data, ie_tlv_iter_get_length(&iter)))
break; break;
handshake_state_set_supplicant_wpa(netdev->handshake, handshake_state_set_supplicant_ie(netdev->handshake,
data - 2); data - 2);
break; break;
case IE_TYPE_MOBILITY_DOMAIN: case IE_TYPE_MOBILITY_DOMAIN:
@ -2876,7 +2876,7 @@ static int fast_transition(struct netdev *netdev, struct scan_bss *target_bss,
handshake_state_set_authenticator_address(netdev->handshake, handshake_state_set_authenticator_address(netdev->handshake,
target_bss->addr); target_bss->addr);
handshake_state_set_authenticator_rsn(netdev->handshake, handshake_state_set_authenticator_ie(netdev->handshake,
target_bss->rsne); target_bss->rsne);
memcpy(netdev->handshake->mde + 2, target_bss->mde, 3); memcpy(netdev->handshake->mde + 2, target_bss->mde, 3);

View File

@ -623,12 +623,12 @@ static int station_build_handshake_rsn(struct handshake_state *hs,
/* RSN takes priority */ /* RSN takes priority */
if (bss->rsne) { if (bss->rsne) {
ie_build_rsne(&info, rsne_buf); ie_build_rsne(&info, rsne_buf);
handshake_state_set_authenticator_rsn(hs, bss->rsne); handshake_state_set_authenticator_ie(hs, bss->rsne);
handshake_state_set_supplicant_rsn(hs, rsne_buf); handshake_state_set_supplicant_ie(hs, rsne_buf);
} else { } else {
ie_build_wpa(&info, rsne_buf); ie_build_wpa(&info, rsne_buf);
handshake_state_set_authenticator_wpa(hs, bss->wpa); handshake_state_set_authenticator_ie(hs, bss->wpa);
handshake_state_set_supplicant_wpa(hs, rsne_buf); handshake_state_set_supplicant_ie(hs, rsne_buf);
} }
if (info.akm_suites & (IE_RSN_AKM_SUITE_FT_OVER_8021X | if (info.akm_suites & (IE_RSN_AKM_SUITE_FT_OVER_8021X |
@ -1199,7 +1199,7 @@ static void station_preauthenticate_cb(struct netdev *netdev,
rsn_info.pmkids = pmkid; rsn_info.pmkids = pmkid;
ie_build_rsne(&rsn_info, rsne_buf); ie_build_rsne(&rsn_info, rsne_buf);
handshake_state_set_supplicant_rsn(new_hs, rsne_buf); handshake_state_set_supplicant_ie(new_hs, rsne_buf);
} }
station_transition_reassociate(station, bss, new_hs); station_transition_reassociate(station, bss, new_hs);