]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Make ap_cipher_tkip_countermeasures_sta2 more robust
authorJouni Malinen <j@w1.fi>
Thu, 26 Dec 2024 18:30:23 +0000 (20:30 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 26 Dec 2024 18:30:23 +0000 (20:30 +0200)
Work around a race condition between Michael MIC error report processing
on the AP from two STAs and the 4-way handshake that might get started,
but not necessarily completed, during that window.

Signed-off-by: Jouni Malinen <j@w1.fi>
tests/hwsim/test_ap_ciphers.py

index 5ad3e0289a9150adb33cbd582f92d4a83996bac4..a3d8aa0f3a234e4c3195789bc6d899bbda039355 100644 (file)
@@ -226,20 +226,34 @@ def test_ap_cipher_tkip_countermeasures_sta2(dev, apdev):
     dev[0].connect("tkip-countermeasures", psk="12345678",
                    pairwise="TKIP", group="TKIP", scan_freq="2412")
     dev[0].dump_monitor()
+    hapd.wait_sta()
     id = dev[1].connect("tkip-countermeasures", psk="12345678",
                         pairwise="TKIP", group="TKIP", scan_freq="2412")
     dev[1].dump_monitor()
+    hapd.wait_sta()
 
     hapd.cmd_execute(["echo", "-n", "ff:ff:ff:ff:ff:ff", ">", testfile],
                      shell=True)
-    ev = dev[0].wait_disconnected(timeout=10,
-                                  error="No disconnection after two Michael MIC failure")
-    if "reason=14" not in ev:
-        raise Exception("Unexpected disconnection reason: " + ev)
-    ev = dev[1].wait_disconnected(timeout=5,
-                                  error="No disconnection after two Michael MIC failure")
-    if "reason=14" not in ev:
-        raise Exception("Unexpected disconnection reason: " + ev)
+    ev0 = dev[0].wait_disconnected(timeout=10,
+                                   error="No disconnection after two Michael MIC failure")
+    ev1 = dev[1].wait_disconnected(timeout=5,
+                                   error="No disconnection after two Michael MIC failure")
+    # There is a race condition here between EAPOL-Key Request frame initiated
+    # 4-way handshake from one of the STAs being able to start before the AP
+    # has received the Michael MIC error report from the other STA. If the new
+    # 4-way handshake has been started, it is possible for the that 4-way
+    # handshake to fail due to being unable to send an EAPOL-Key frame if the
+    # AP deauthenticates the STA in the middle of that exchange. That ends up
+    # showing a different disconnection reason, so we need to accept both the
+    # normal reason code 14 for Michael MIC failures and the locally generated
+    # disconnection.
+    if "reason=14" not in ev0:
+        if "reason=1 locally_generated=1" not in ev0:
+            raise Exception("Unexpected disconnection reason (dev0): " + ev0)
+    if "reason=14" not in ev1:
+        if "reason=1 locally_generated=1" not in ev1:
+            raise Exception("Unexpected disconnection reason (dev1): " + ev1)
+
     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
     if ev is not None:
         raise Exception("Unexpected connection during TKIP countermeasures")