]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Make PMKSA caching tests more robust
authorJouni Malinen <j@w1.fi>
Sun, 18 Jan 2015 13:47:56 +0000 (15:47 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 18 Jan 2015 13:47:56 +0000 (15:47 +0200)
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 <j@w1.fi>
tests/hwsim/test_pmksa_cache.py
tests/hwsim/test_sae.py

index e0e23ee19d978b9e260e000b9ccee7f9b2d87ac2..5944f98c37d50c9cadc4edce41423dfcef99d908 100644 (file)
@@ -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()
index 473473a44df222421d64864bef726d8f181f9b37..93194d30ec46dfeb8bfcb0e51c53a6a26ef9179b 100644 (file)
@@ -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':