From 75e6ee98f357b110ff38f777363ed88c0f812bcc Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Fri, 7 Jun 2019 12:17:00 -0700 Subject: [PATCH] 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). --- src/adhoc.c | 4 ++-- src/ap.c | 4 ++-- src/handshake.c | 40 ++++++++-------------------------------- src/handshake.h | 12 ++++-------- src/netdev.c | 6 +++--- src/station.c | 10 +++++----- 6 files changed, 24 insertions(+), 52 deletions(-) diff --git a/src/adhoc.c b/src/adhoc.c index 7a93b86c..f29c4dfe 100644 --- a/src/adhoc.c +++ b/src/adhoc.c @@ -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_ssid(hs, (void *)adhoc->ssid, strlen(adhoc->ssid)); /* we dont have the connecting peer rsn info, so just set ap == own */ - handshake_state_set_authenticator_rsn(hs, bss_rsne); - handshake_state_set_supplicant_rsn(hs, bss_rsne); + handshake_state_set_authenticator_ie(hs, bss_rsne); + handshake_state_set_supplicant_ie(hs, bss_rsne); handshake_state_set_pmk(hs, adhoc->pmk, 32); if (authenticator) { diff --git a/src/ap.c b/src/ap.c index d8b3eb99..fdaf9834 100644 --- a/src/ap.c +++ b/src/ap.c @@ -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_ssid(sta->hs, (void *)ap->ssid, strlen(ap->ssid)); handshake_state_set_authenticator(sta->hs, true); - handshake_state_set_authenticator_rsn(sta->hs, bss_rsne); - handshake_state_set_supplicant_rsn(sta->hs, sta->assoc_rsne); + handshake_state_set_authenticator_ie(sta->hs, bss_rsne); + handshake_state_set_supplicant_ie(sta->hs, sta->assoc_rsne); handshake_state_set_pmk(sta->hs, ap->pmk, 32); handshake_state_set_authenticator_address(sta->hs, own_addr); handshake_state_set_supplicant_address(sta->hs, sta->addr); diff --git a/src/handshake.c b/src/handshake.c index aee8d924..6cf05add 100644 --- a/src/handshake.c +++ b/src/handshake.c @@ -148,19 +148,19 @@ static bool handshake_state_setup_own_ciphers(struct handshake_state *s, return true; } -static bool handshake_state_set_authenticator_ie(struct handshake_state *s, - const uint8_t *ie, bool is_wpa) +bool handshake_state_set_authenticator_ie(struct handshake_state *s, + const uint8_t *ie) { struct ie_rsn_info info; l_free(s->authenticator_ie); 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) return true; - if (is_wpa) { + if (s->wpa_ie) { if (ie_parse_wpa_from_data(ie, ie[1] + 2, &info) < 0) return false; } else { @@ -171,19 +171,19 @@ static bool handshake_state_set_authenticator_ie(struct handshake_state *s, return handshake_state_setup_own_ciphers(s, &info); } -static bool handshake_state_set_supplicant_ie(struct handshake_state *s, - const uint8_t *ie, bool is_wpa) +bool handshake_state_set_supplicant_ie(struct handshake_state *s, + const uint8_t *ie) { struct ie_rsn_info info; l_free(s->supplicant_ie); 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) return true; - if (is_wpa) { + if (s->wpa_ie) { if (ie_parse_wpa_from_data(ie, ie[1] + 2, &info) < 0) return false; } else { @@ -194,30 +194,6 @@ static bool handshake_state_set_supplicant_ie(struct handshake_state *s, 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, size_t ssid_len) { diff --git a/src/handshake.h b/src/handshake.h index 669e6ff9..6d16ca46 100644 --- a/src/handshake.h +++ b/src/handshake.h @@ -141,14 +141,10 @@ void handshake_state_set_ptk(struct handshake_state *s, const uint8_t *ptk, size_t ptk_len); void handshake_state_set_8021x_config(struct handshake_state *s, struct l_settings *settings); -bool handshake_state_set_supplicant_rsn(struct handshake_state *s, - const uint8_t *rsn_ie); -bool handshake_state_set_authenticator_rsn(struct handshake_state *s, - const uint8_t *rsn_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); +bool handshake_state_set_authenticator_ie(struct handshake_state *s, + const uint8_t *ie); +bool handshake_state_set_supplicant_ie(struct handshake_state *s, + const uint8_t *ie); void handshake_state_set_ssid(struct handshake_state *s, const uint8_t *ssid, size_t ssid_len); void handshake_state_set_mde(struct handshake_state *s, diff --git a/src/netdev.c b/src/netdev.c index bf667742..c71493e4 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -1616,14 +1616,14 @@ static void netdev_connect_event(struct l_genl_msg *msg, struct netdev *netdev) switch (ie_tlv_iter_get_tag(&iter)) { case IE_TYPE_RSN: - handshake_state_set_supplicant_rsn(netdev->handshake, + handshake_state_set_supplicant_ie(netdev->handshake, data - 2); break; case IE_TYPE_VENDOR_SPECIFIC: if (!is_ie_wpa_ie(data, ie_tlv_iter_get_length(&iter))) break; - handshake_state_set_supplicant_wpa(netdev->handshake, + handshake_state_set_supplicant_ie(netdev->handshake, data - 2); break; 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, target_bss->addr); - handshake_state_set_authenticator_rsn(netdev->handshake, + handshake_state_set_authenticator_ie(netdev->handshake, target_bss->rsne); memcpy(netdev->handshake->mde + 2, target_bss->mde, 3); diff --git a/src/station.c b/src/station.c index e4dee053..089fe162 100644 --- a/src/station.c +++ b/src/station.c @@ -623,12 +623,12 @@ static int station_build_handshake_rsn(struct handshake_state *hs, /* RSN takes priority */ if (bss->rsne) { ie_build_rsne(&info, rsne_buf); - handshake_state_set_authenticator_rsn(hs, bss->rsne); - handshake_state_set_supplicant_rsn(hs, rsne_buf); + handshake_state_set_authenticator_ie(hs, bss->rsne); + handshake_state_set_supplicant_ie(hs, rsne_buf); } else { ie_build_wpa(&info, rsne_buf); - handshake_state_set_authenticator_wpa(hs, bss->wpa); - handshake_state_set_supplicant_wpa(hs, rsne_buf); + handshake_state_set_authenticator_ie(hs, bss->wpa); + handshake_state_set_supplicant_ie(hs, rsne_buf); } 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; 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);