From b9029aaf65d87c04d06f4ab87ff49e5dd9f59fd4 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Fri, 26 Oct 2018 09:44:59 -0700 Subject: [PATCH] adhoc: wait for both handshakes before adding peer Adhoc was not waiting for BOTH handshakes to complete before adding the new peer to the ConnectedPeers property. Actually waiting for the gtk/igtk (in a previous commit) helps with this, but adhoc also needed to keep track of which handshakes had completed, and only add the peer once BOTH were done. This required a small change in netdev, where we memcmp the addresses from both handshakes and only set the PTK on one. --- src/adhoc.c | 11 +++++++++-- src/netdev.c | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/adhoc.c b/src/adhoc.c index 69de257a..ec89bc34 100644 --- a/src/adhoc.c +++ b/src/adhoc.c @@ -67,7 +67,8 @@ struct sta_state { struct eapol_sm *sm_a; struct handshake_state *hs_auth; uint32_t gtk_query_cmd_id; - + bool hs_sta_done : 1; + bool hs_auth_done : 1; bool authenticated : 1; }; @@ -183,7 +184,13 @@ static void adhoc_handshake_event(struct handshake_state *hs, return; case HANDSHAKE_EVENT_COMPLETE: - if ((sta->hs_auth == hs || sta->hs_sta == hs) && + if (sta->hs_auth == hs) + sta->hs_auth_done = true; + + if (sta->hs_sta == hs) + sta->hs_sta_done = true; + + if ((sta->hs_auth_done && sta->hs_sta_done) && !sta->authenticated) { sta->authenticated = true; l_dbus_property_changed(dbus_get_bus(), diff --git a/src/netdev.c b/src/netdev.c index b1c04f3e..07845b0c 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -1425,8 +1425,11 @@ static void netdev_set_tk(struct handshake_state *hs, * by the STA Authenticator with the higher MAC address... */ if (netdev->type == NL80211_IFTYPE_ADHOC && - memcmp(nhs->super.aa, nhs->super.spa, 6) < 0) + memcmp(nhs->super.aa, nhs->super.spa, 6) < 0) { + nhs->ptk_installed = true; + try_handshake_complete(nhs); return; + } l_debug("%d", netdev->index);