From 986f66a3c606273f2eeab09b1b0d589f0c2d7971 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Wed, 15 Aug 2018 10:36:19 -0700 Subject: [PATCH] eapol: removed authenticator bit and auth register This removes the authenticator bit in eapol_sm as well as unifies eapol_register_authenticator and eapol_register. Taking advantage of the handshake state authenticator bit we no longer have a need for 2 separate register functions. ap, and adhoc were also updated to set the authenticator bit in the handshake and only use eapol_register to register their sm's. netdev was updated to use the authenticator bit when choosing the correct key address for adhoc. --- src/adhoc.c | 3 ++- src/ap.c | 3 ++- src/eapol.c | 26 ++++++++++---------------- src/eapol.h | 1 - src/netdev.c | 2 +- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/adhoc.c b/src/adhoc.c index cabd507a..a3ae9fca 100644 --- a/src/adhoc.c +++ b/src/adhoc.c @@ -224,6 +224,7 @@ static struct eapol_sm *adhoc_new_sm(struct sta_state *sta, bool authenticator) if (authenticator) { handshake_state_set_authenticator_address(hs, own_addr); handshake_state_set_supplicant_address(hs, sta->addr); + handshake_state_set_authenticator(hs, true); } else { handshake_state_set_authenticator_address(hs, sta->addr); handshake_state_set_supplicant_address(hs, own_addr); @@ -299,7 +300,7 @@ static void adhoc_new_station(struct adhoc_state *adhoc, const uint8_t *mac) } eapol_register(sta->sm); - eapol_register_authenticator(sta->sm_a); + eapol_register(sta->sm_a); eapol_start(sta->sm); diff --git a/src/ap.c b/src/ap.c index a75492fa..7b946439 100644 --- a/src/ap.c +++ b/src/ap.c @@ -424,6 +424,7 @@ static void ap_associate_sta_cb(struct l_genl_msg *msg, void *user_data) 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); + handshake_state_set_authenticator(sta->hs, true); sta->sm = eapol_sm_new(sta->hs); if (!sta->sm) { @@ -435,7 +436,7 @@ static void ap_associate_sta_cb(struct l_genl_msg *msg, void *user_data) eapol_sm_set_listen_interval(sta->sm, sta->listen_interval); eapol_sm_set_protocol_version(sta->sm, EAPOL_PROTOCOL_VERSION_2004); - eapol_register_authenticator(sta->sm); + eapol_register(sta->sm); return; diff --git a/src/eapol.c b/src/eapol.c index 2e07a0ce..86da2cd5 100644 --- a/src/eapol.c +++ b/src/eapol.c @@ -687,7 +687,6 @@ struct eapol_sm { bool use_eapol_start:1; bool require_handshake:1; bool eap_exchanged:1; - bool authenticator:1; struct eap_state *eap; struct eapol_frame *early_frame; uint32_t watch_id; @@ -2040,24 +2039,19 @@ void eapol_register(struct eapol_sm *sm) { l_queue_push_head(state_machines, sm); - sm->watch_id = eapol_frame_watch_add(sm->handshake->ifindex, + if (sm->handshake->authenticator) { + sm->watch_id = eapol_frame_watch_add(sm->handshake->ifindex, + eapol_rx_auth_packet, sm); + + sm->started = true; + + /* kick off handshake */ + eapol_ptk_1_of_4_retry(NULL, sm); + } else + sm->watch_id = eapol_frame_watch_add(sm->handshake->ifindex, eapol_rx_packet, sm); } -void eapol_register_authenticator(struct eapol_sm *sm) -{ - l_queue_push_head(state_machines, sm); - - sm->watch_id = eapol_frame_watch_add(sm->handshake->ifindex, - eapol_rx_auth_packet, sm); - - sm->started = true; - sm->authenticator = true; - - /* kick off handshake */ - eapol_ptk_1_of_4_retry(NULL, sm); -} - bool eapol_start(struct eapol_sm *sm) { if (sm->handshake->settings_8021x) { diff --git a/src/eapol.h b/src/eapol.h index dbf48c25..f284ad11 100644 --- a/src/eapol.h +++ b/src/eapol.h @@ -200,7 +200,6 @@ void eapol_sm_set_user_data(struct eapol_sm *sm, void *user_data); void eapol_sm_set_event_func(struct eapol_sm *sm, eapol_sm_event_func_t func); void eapol_register(struct eapol_sm *sm); -void eapol_register_authenticator(struct eapol_sm *sm); bool eapol_start(struct eapol_sm *sm); uint32_t eapol_frame_watch_add(uint32_t ifindex, diff --git a/src/netdev.c b/src/netdev.c index 366c73ad..16bc713a 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -1279,7 +1279,7 @@ static const uint8_t *netdev_choose_key_address( case NL80211_IFTYPE_AP: return nhs->super.spa; case NL80211_IFTYPE_ADHOC: - if (!memcmp(nhs->netdev->addr, nhs->super.aa, 6)) + if (nhs->super.authenticator) return nhs->super.spa; else return nhs->super.aa;