From 7cc9a81f1eac927da50f86315e756839b87954be Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 18 Jan 2015 15:47:56 +0200 Subject: [PATCH] tests: Make PMKSA caching tests more robust When the STA is forced to disconnect immediately after completion of 4-way handshake, there is a race condition on the AP side between the reception of EAPOL-Key msg 4/4 and the following Deauthentication frame. It is possible for the deauthentication notification to be processed first since that message uses different path from kernel to user space. If hostapd does not receive EAPOL-Key msg 4/4 prior to deauthentication, no PMKSA cache entry is added. This race condition was making the test cases expecting PMKSA caching to work to fail every now and then. Avoid this issue by waiting for AP-STA-CONNECTED event from hostapd. This makes sure the PMKSA cache entry gets added on the AP side. Signed-off-by: Jouni Malinen --- tests/hwsim/test_pmksa_cache.py | 11 +++++++++-- tests/hwsim/test_sae.py | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/hwsim/test_pmksa_cache.py b/tests/hwsim/test_pmksa_cache.py index e0e23ee19..5944f98c3 100644 --- a/tests/hwsim/test_pmksa_cache.py +++ b/tests/hwsim/test_pmksa_cache.py @@ -288,7 +288,7 @@ def test_pmksa_cache_and_cui(dev, apdev): params['acct_server_addr'] = "127.0.0.1" params['acct_server_port'] = "1813" params['acct_server_shared_secret'] = "radius" - hostapd.add_ap(apdev[0]['ifname'], params) + hapd = hostapd.add_ap(apdev[0]['ifname'], params) bssid = apdev[0]['bssid'] dev[0].connect("cui", proto="RSN", key_mgmt="WPA-EAP", eap="GPSK", identity="gpsk-cui", @@ -297,10 +297,14 @@ def test_pmksa_cache_and_cui(dev, apdev): pmksa = dev[0].get_pmksa(bssid) if pmksa is None: raise Exception("No PMKSA cache entry created") + ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) + if ev is None: + raise Exception("No connection event received from hostapd") dev[0].dump_monitor() logger.info("Disconnect and reconnect to the same AP") dev[0].request("DISCONNECT") + dev[0].wait_disconnected() dev[0].request("RECONNECT") ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED", "CTRL-EVENT-CONNECTED"], timeout=10) @@ -421,12 +425,15 @@ def test_pmksa_cache_disabled(dev, apdev): def test_pmksa_cache_ap_expiration(dev, apdev): """PMKSA cache entry expiring on AP""" params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache") - hostapd.add_ap(apdev[0]['ifname'], params) + hapd = hostapd.add_ap(apdev[0]['ifname'], params) bssid = apdev[0]['bssid'] dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP", eap="GPSK", identity="gpsk-user-session-timeout", password="abcdefghijklmnop0123456789abcdef", scan_freq="2412") + ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) + if ev is None: + raise Exception("No connection event received from hostapd") dev[0].request("DISCONNECT") time.sleep(5) dev[0].dump_monitor() diff --git a/tests/hwsim/test_sae.py b/tests/hwsim/test_sae.py index 473473a44..93194d30e 100644 --- a/tests/hwsim/test_sae.py +++ b/tests/hwsim/test_sae.py @@ -51,7 +51,11 @@ def test_sae_pmksa_caching(dev, apdev): dev[0].request("SET sae_groups ") dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE", scan_freq="2412") + ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) + if ev is None: + raise Exception("No connection event received from hostapd") dev[0].request("DISCONNECT") + dev[0].wait_disconnected() dev[0].request("RECONNECT") dev[0].wait_connected(timeout=15, error="Reconnect timed out") if dev[0].get_status_field('sae_group') is not None: @@ -70,7 +74,11 @@ def test_sae_pmksa_caching_disabled(dev, apdev): dev[0].request("SET sae_groups ") dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE", scan_freq="2412") + ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) + if ev is None: + raise Exception("No connection event received from hostapd") dev[0].request("DISCONNECT") + dev[0].wait_disconnected() dev[0].request("RECONNECT") dev[0].wait_connected(timeout=15, error="Reconnect timed out") if dev[0].get_status_field('sae_group') != '19':