From: Jouni Malinen Date: Thu, 26 Dec 2024 18:30:23 +0000 (+0200) Subject: tests: Make ap_cipher_tkip_countermeasures_sta2 more robust X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58767e7ef5d570b1babd867814696237a6c00bd7;p=thirdparty%2Fhostap.git tests: Make ap_cipher_tkip_countermeasures_sta2 more robust 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 --- diff --git a/tests/hwsim/test_ap_ciphers.py b/tests/hwsim/test_ap_ciphers.py index 5ad3e0289..a3d8aa0f3 100644 --- a/tests/hwsim/test_ap_ciphers.py +++ b/tests/hwsim/test_ap_ciphers.py @@ -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")