[PATCH 55/55] tests: PTK rekeying with the PQC AKMs

Ilan Peer ilan.peer at intel.com
Thu Dec 3 02:44:54 PST 2026


Add PTK rekey tests for the PQC and FT PQC AKMs, including after FT
roaming, and for FT-EAP over IEEE 802.1X Authentication frames.

Use bssid_hint in the FT PQC tests, since a network limited to the
first AP does not match after the roam, causing the rekey to fail.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 tests/hwsim/test_ap_ft.py          |  53 +++++++++++++--
 tests/hwsim/test_ieee8021x_auth.py | 105 +++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+), 4 deletions(-)

diff --git a/tests/hwsim/test_ap_ft.py b/tests/hwsim/test_ap_ft.py
index 01f6256e4038..43a8cc4da2e2 100644
--- a/tests/hwsim/test_ap_ft.py
+++ b/tests/hwsim/test_ap_ft.py
@@ -3984,7 +3984,7 @@ def test_ap_ft_eap_1x_auth_fte_mismatch(dev, apdev):
     if "CTRL-EVENT-CONNECTED" in ev:
         raise Exception("FTE mismatch in Association Response not detected")
 
-def ft_pqc_ap(apdev, i, ssid, profile, privacy=False):
+def ft_pqc_ap(apdev, i, ssid, profile, privacy=False, ptk_rekey=None):
     p = (ft_params1 if i == 0 else ft_params2)(ssid=ssid)
     p = dict(list(hostapd.radius_params().items()) + list(p.items()))
 
@@ -4002,6 +4002,9 @@ def ft_pqc_ap(apdev, i, ssid, profile, privacy=False):
     if privacy:
         p["pmksa_caching_privacy"] = "1"
 
+    if ptk_rekey:
+        p["wpa_ptk_rekey"] = ptk_rekey
+
     return hostapd.add_ap(apdev[i], p)
 
 def ft_pqc_check_capture(capfile):
@@ -4029,17 +4032,21 @@ def ft_pqc_check_capture(capfile):
         if not vals or any(v not in ["1", "True"] for v in vals):
             raise Exception("Unprotected Reassociation frame (subtype %s): %s" % (subtype, str(vals)))
 
-def run_ap_ft_pqc(dev, apdev, params, profile, privacy=False, mac_addr=False):
+def run_ap_ft_pqc(dev, apdev, params, profile, privacy=False, ptk_rekey=False,
+                  mac_addr=False):
     check_pqc_capab(dev[0])
     capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
     ssid = "test-ft-pqc"
-    hapds = [ft_pqc_ap(apdev, i, ssid, profile, privacy) for i in range(2)]
+    rekey = "2" if ptk_rekey else None
+    hapds = [ft_pqc_ap(apdev, i, ssid, profile, privacy, rekey)
+             for i in range(2)]
 
     copts = {}
     if mac_addr:
         copts["mac_addr"] = "1"
 
     dev[0].flush_scan_cache()
+    dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
     dev[0].set("security_profiles", "1")
     dev[0].connect(ssid, key_mgmt="WPA-EAP", ieee80211w="2",
                    pairwise="GCMP-256", group="GCMP-256", scan_freq="2412",
@@ -4047,7 +4054,7 @@ def run_ap_ft_pqc(dev, apdev, params, profile, privacy=False, mac_addr=False):
                    eap="GPSK", identity="gpsk user",
                    password="abcdefghijklmnop0123456789abcdef",
                    pmksa_privacy="1" if privacy else "0",
-                   bssid=apdev[0]['bssid'], **copts)
+                   bssid_hint=apdev[0]['bssid'], **copts)
 
     hapds[0].wait_sta()
     sta = hapds[0].get_sta(dev[0].get_addr())
@@ -4055,6 +4062,8 @@ def run_ap_ft_pqc(dev, apdev, params, profile, privacy=False, mac_addr=False):
         raise Exception("Unexpected AKM: " + sta["AKMSuiteSelector"])
 
     hwsim_utils.test_connectivity(dev[0], hapds[0])
+    if ptk_rekey:
+        check_ptk_rekey(dev[0], hapds[0], hapds[1])
 
     dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
     for i in [1, 0, 1]:
@@ -4067,6 +4076,8 @@ def run_ap_ft_pqc(dev, apdev, params, profile, privacy=False, mac_addr=False):
             raise Exception("FT was not used")
 
         hwsim_utils.test_connectivity(dev[0], hapds[i])
+        if ptk_rekey:
+            check_ptk_rekey(dev[0], hapds[0], hapds[1])
 
     ft_pqc_check_capture(capfile)
 
@@ -4140,6 +4151,40 @@ def test_ap_ft_unexpected_pqc_param(dev, apdev):
     dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
     dev[0].roam(apdev[1]['bssid'], fail_test=True)
 
+def test_ap_ft_pqc_ptk_rekey_profile_20(dev, apdev, params):
+    """FT-PQC with PTK rekeying, security profile 20"""
+    run_ap_ft_pqc(dev, apdev, params, 20, ptk_rekey=True)
+
+def test_ap_ft_pqc_ptk_rekey_profile_21(dev, apdev, params):
+    """FT-PQC with PTK rekeying, security profile 21"""
+    run_ap_ft_pqc(dev, apdev, params, 21, ptk_rekey=True)
+
+def test_ap_ft_pqc_ptk_rekey_profile_22(dev, apdev, params):
+    """FT-PQC with PTK rekeying, security profile 22"""
+    run_ap_ft_pqc(dev, apdev, params, 22, ptk_rekey=True)
+
+def test_ap_ft_pqc_ptk_rekey_profile_23(dev, apdev, params):
+    """FT-PQC with PTK rekeying, security profile 23"""
+    run_ap_ft_pqc(dev, apdev, params, 23, ptk_rekey=True)
+
+def test_ap_ft_eap_1x_auth_ptk_rekey(dev, apdev):
+    """FT-EAP initial MDA over IEEE 802.1X Authentication frames and PTK rekeying"""
+    p = ft_params1(ssid="test-ft", passphrase="12345678")
+    p = dict(list(hostapd.radius_params().items()) + list(p.items()))
+    p["wpa_key_mgmt"] = "FT-EAP"
+    p["ieee8021x"] = "1"
+    p["ieee80211w"] = "2"
+    p["assoc_frame_encryption"] = "1"
+    p["eap_using_authentication_frames"] = "1"
+    p["wpa_ptk_rekey"] = "2"
+    hapd = hostapd.add_ap(apdev[0], p)
+    dev[0].connect("test-ft", key_mgmt="FT-EAP", ieee80211w="2",
+                   eap="GPSK", identity="gpsk user",
+                   password="abcdefghijklmnop0123456789abcdef",
+                   eap_over_auth_frame="1", scan_freq="2412")
+    hapd.wait_sta()
+    check_ptk_rekey(dev[0], hapd, hapd)
+
 def ft_enc_assoc_check_capture(capfile, sta, aps):
     # All FT Authentication frames carry the Diffie-Hellman Parameter element
     filt = "wlan.fc.type_subtype == 0x000b && wlan.fixed.auth.alg == 2 && " + \
diff --git a/tests/hwsim/test_ieee8021x_auth.py b/tests/hwsim/test_ieee8021x_auth.py
index 8bde6e44de8d..d4f625743481 100644
--- a/tests/hwsim/test_ieee8021x_auth.py
+++ b/tests/hwsim/test_ieee8021x_auth.py
@@ -5,6 +5,7 @@
 # See README for more details.
 
 import binascii
+import hashlib
 import logging
 import os
 import struct
@@ -2946,3 +2947,107 @@ def test_ieee8021x_auth_pqc_sta_invalid_elements(dev, apdev):
 
     hapd.set("ext_mgmt_frame_handling", "0")
     pqc_connect(dev[0], ssid)
+
+def pqc_wait_ptk_rekey(dev, hapd):
+    """Wait for a PTK rekey and verify the connection is still usable"""
+    ev = dev.wait_event(["WPA: Key negotiation completed",
+                         "CTRL-EVENT-DISCONNECTED"], timeout=10)
+    if ev is None:
+        raise Exception("PTK rekey timed out")
+
+    if "CTRL-EVENT-DISCONNECTED" in ev:
+        raise Exception("Disconnected during PTK rekey")
+
+    hwsim_utils.test_connectivity(dev, hapd)
+
+def run_ieee8021x_auth_pqc_ptk_rekey(dev, apdev, profile):
+    check_pqc_capab(dev[0])
+    ssid = "test-pqc-rekey"
+    params = pqc_ap_params(ssid, str(profile))
+    params["wpa_ptk_rekey"] = "2"
+    hapd = hostapd.add_ap(apdev[0], params)
+    pqc_connect(dev[0], ssid, str(profile), eap_params=EAP_PSK_PARAMS)
+    hapd.wait_sta()
+    hwsim_utils.test_connectivity(dev[0], hapd)
+    for i in range(2):
+        pqc_wait_ptk_rekey(dev[0], hapd)
+
+def log_hexdump(line):
+    return binascii.unhexlify(line.strip().split('): ', 1)[1].replace(' ', ''))
+
+def test_ieee8021x_auth_pqc_ptk_rekey_transcript(dev, apdev, params):
+    """PTK rekeying with the PQC AKM: transcript covers the full EAPOL-Key PDUs"""
+    run_ieee8021x_auth_pqc_ptk_rekey(dev, apdev, SECURITY_PROFILE_8021X_PQC_2)
+    dev[0].request("DISCONNECT")
+    dev[0].wait_disconnected()
+    dev[0].relog()
+
+    # IEEE P802.11bt/D1.1, 12.17.4: the EAPOL-Key PDU starts at Protocol
+    # Version; Key MIC of msg 2/4 set to 0. Profile 18 uses SHA-384.
+    mic_offset = 4 + 1 + 2 + 2 + 8 + 32 + 16 + 8 + 8
+    mic_len = 24
+    msg1 = None
+    checked = 0
+    with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
+        for l in f.readlines():
+            if "WPA: RX EAPOL-Key - hexdump" in l:
+                msg1 = log_hexdump(l)
+                key_info = struct.unpack('>H', msg1[5:7])[0]
+
+                if key_info & 0x0100:
+                    msg1 = None
+            elif "RSN: PQC: T - hexdump" in l and msg1:
+                t = log_hexdump(l)
+            elif "WPA: TX EAPOL-Key - hexdump" in l and msg1:
+                msg2 = bytearray(log_hexdump(l))
+                msg2[mic_offset:mic_offset + mic_len] = mic_len * b'\x00'
+                data = struct.pack('<I', len(msg1)) + msg1 + \
+                    struct.pack('<I', len(msg2)) + bytes(msg2)
+
+                if hashlib.sha384(data).digest() != t:
+                    raise Exception("Transcript does not cover the full EAPOL-Key PDUs")
+
+                checked += 1
+                msg1 = None
+    if checked < 2:
+        raise Exception("Only %d rekey transcripts found" % checked)
+
+def test_ieee8021x_auth_pqc_ptk_rekey_profile_16(dev, apdev):
+    """PTK rekeying with the PQC AKM and security profile 16"""
+    run_ieee8021x_auth_pqc_ptk_rekey(dev, apdev, 16)
+
+def test_ieee8021x_auth_pqc_ptk_rekey_profile_17(dev, apdev):
+    """PTK rekeying with the PQC AKM and security profile 17"""
+    run_ieee8021x_auth_pqc_ptk_rekey(dev, apdev, 17)
+
+def test_ieee8021x_auth_pqc_ptk_rekey_profile_18(dev, apdev):
+    """PTK rekeying with the PQC AKM and security profile 18"""
+    run_ieee8021x_auth_pqc_ptk_rekey(dev, apdev, 18)
+
+def test_ieee8021x_auth_pqc_ptk_rekey_profile_19(dev, apdev):
+    """PTK rekeying with the PQC AKM and security profile 19"""
+    run_ieee8021x_auth_pqc_ptk_rekey(dev, apdev, 19)
+
+def test_ieee8021x_auth_pqc_ptk_rekey_extra_pqc_param(dev, apdev):
+    """PTK rekeying with the PQC AKM and two PQC Parameters in msg 1/4"""
+    check_pqc_capab(dev[0])
+    ssid = "test-pqc-rekey"
+    params = pqc_ap_params(ssid)
+    params["wpa_ptk_rekey"] = "2"
+    params["eapol_m1_elements"] = binascii.hexlify(
+        pqc_parameter_elem(SECURITY_PROFILE_8021X_PQC_2, 0)).decode()
+
+    hapd = hostapd.add_ap(apdev[0], params)
+    pqc_connect(dev[0], ssid, eap_params=EAP_PSK_PARAMS)
+
+    hapd.wait_sta()
+    ev = dev[0].wait_event(["WPA: Key negotiation completed",
+                            "CTRL-EVENT-DISCONNECTED"], timeout=10)
+    if ev is None:
+        raise Exception("No disconnection on invalid msg 1/4")
+
+    if "CTRL-EVENT-DISCONNECTED" not in ev:
+        raise Exception("PTK rekey accepted two PQC Parameters")
+
+    if "reason=1 locally_generated=1" not in ev:
+        raise Exception("Unexpected disconnection reason: " + ev)
-- 
2.55.0




More information about the Hostap mailing list