[PATCH 36/55] tests: FT-EAP with PMKR0Name privacy and MAC address randomization

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


Verify that with PMKSA caching privacy the STA can use a new random MAC
address for every fast BSS transition, both when the target AP has the
PMK-R1 and when it needs to pull it from the R0KH, and that every FT
Authentication frame uses a new MAC address and a new PMKR0Name.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 tests/hwsim/test_ap_ft.py | 112 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 109 insertions(+), 3 deletions(-)

diff --git a/tests/hwsim/test_ap_ft.py b/tests/hwsim/test_ap_ft.py
index 90af8d6a9a8f..3e5a89a9061b 100644
--- a/tests/hwsim/test_ap_ft.py
+++ b/tests/hwsim/test_ap_ft.py
@@ -142,7 +142,7 @@ def run_roams(dev, apdev, hapd0, hapd1, ssid, passphrase, over_ds=False,
               wait_before_roam=0, return_after_initial=False, ieee80211w="1",
               sae_transition=False, beacon_prot=False, sae_ext_key=False,
               check_ssid=False, gtk_rekey=False, eap_over_auth=False,
-              pmksa_privacy=False):
+              pmksa_privacy=False, mac_addr=None):
     logger.info("Connect to first AP")
 
     copts = {}
@@ -150,6 +150,8 @@ def run_roams(dev, apdev, hapd0, hapd1, ssid, passphrase, over_ds=False,
         copts["eap_over_auth_frame"] = "1"
     if pmksa_privacy:
         copts["pmksa_privacy"] = "1"
+    if mac_addr:
+        copts["mac_addr"] = mac_addr
     copts["proto"] = "WPA2"
     copts["ieee80211w"] = ieee80211w
     copts["scan_freq"] = "2412"
@@ -4024,7 +4026,7 @@ def ft_pmk_r0_names(capfile, sta):
 
 def run_ap_ft_enc_assoc(dev, apdev, params, sha384=False, roams=1,
                         ap_privacy=False, sta_privacy=False,
-                        r1_push=True, eap_over_auth=False):
+                        r1_push=True, eap_over_auth=False, mac_addr=None):
     capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
     ssid = "test-ft"
     passphrase = "12345678"
@@ -4054,7 +4056,8 @@ def run_ap_ft_enc_assoc(dev, apdev, params, sha384=False, roams=1,
     run_roams(dev[0], apdev, hapds[0], hapds[1], ssid, passphrase, eap=True,
               sha384=sha384, ieee80211w="2", roams=roams,
               force_initial_conn_to_first_ap=eap_over_auth,
-              eap_over_auth=eap_over_auth, pmksa_privacy=sta_privacy)
+              eap_over_auth=eap_over_auth, pmksa_privacy=sta_privacy,
+              mac_addr=mac_addr)
 
     sta = dev[0].own_addr()
     ft_enc_assoc_check_capture(capfile, sta,
@@ -4142,6 +4145,109 @@ def test_ap_ft_eap_enc_assoc_pmksa_privacy_pull(dev, apdev, params):
     """FT-EAP with encrypted reassociation and PMKR0Name privacy, no push"""
     run_ap_ft_enc_assoc_pmksa_privacy(dev, apdev, params, r1_push=False)
 
+def run_ap_ft_enc_assoc_pmksa_privacy_mac_addr(dev, apdev, params,
+                                               r1_push=True):
+    capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
+    roams = 2
+    try:
+        dev[0].set("rand_addr_lifetime", "0")
+        run_ap_ft_enc_assoc(dev, apdev, params, roams=roams,
+                            ap_privacy=True, sta_privacy=True,
+                            r1_push=r1_push, mac_addr="1")
+    finally:
+        dev[0].set("rand_addr_lifetime", "60")
+
+    ft_check_new_mac_addrs(capfile, 2 * roams)
+
+def ft_check_new_mac_addrs(capfile, count):
+    # The first FT Authentication frame of every roam uses a new MAC address
+    # and a new PMKR0Name.
+    filt = "wlan.fc.type_subtype == 0x000b && wlan.fixed.auth.alg == 2 && " + \
+           "wlan.fixed.auth_seq == 1"
+    res = run_tshark(capfile, filt, ["wlan.sa", "wlan.pmkid.akms"])
+    frames = [line.split('\t') for line in res.splitlines() if line]
+    logger.info("FT Authentication frames: " + str(frames))
+    if len(frames) != count:
+        raise Exception("Unexpected number of FT Authentication frames: " +
+                        str(frames))
+
+    addrs = [f[0] for f in frames]
+    names = [f[1] for f in frames]
+    if len(set(addrs)) != len(addrs):
+        raise Exception("MAC address was reused: " + str(addrs))
+
+    if len(set(names)) != len(names):
+        raise Exception("PMKR0Name was reused: " + str(names))
+
+    # The MAC address of the initial association is not reused either
+    res = run_tshark(capfile, "wlan.fc.type_subtype == 0x0000", ["wlan.sa"])
+    initial = [a for a in res.splitlines() if a]
+    if not initial:
+        raise Exception("No Association Request frame in capture")
+
+    if initial[0] in addrs:
+        raise Exception("MAC address of the initial association was reused: " +
+                        initial[0])
+
+def test_ap_ft_eap_enc_assoc_pmksa_privacy_mac_addr_target(dev, apdev, params):
+    """FT-EAP with PMKR0Name privacy: no FT with a new MAC address to an AP without it"""
+    capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
+    ssid = "test-ft"
+    radius = hostapd.radius_params()
+    hapds = []
+    for i, ft_p in enumerate([ft_params1, ft_params2]):
+        p = ft_p(ssid=ssid, passphrase="12345678")
+        p['wpa_key_mgmt'] = "FT-EAP"
+        p["ieee8021x"] = "1"
+        p["ieee80211w"] = "2"
+        p["assoc_frame_encryption"] = "1"
+
+        if i == 0:
+            p["pmksa_caching_privacy"] = "1"
+
+        p = dict(list(radius.items()) + list(p.items()))
+        hapds.append(hostapd.add_ap(apdev[i], p))
+
+    try:
+        dev[0].set("rand_addr_lifetime", "0")
+        dev[0].flush_scan_cache()
+        dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
+        dev[0].connect(ssid, key_mgmt="FT-EAP", ieee80211w="2", eap="GPSK",
+                       identity="gpsk user",
+                       password="abcdefghijklmnop0123456789abcdef",
+                       pmksa_privacy="1", mac_addr="1", scan_freq="2412",
+                       bssid_hint=apdev[0]['bssid'])
+        hapds[0].wait_sta()
+
+        # The MAC address changes, but the target AP does not support
+        # PMKSA caching privacy, so a full authentication has to be used.
+        dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
+        if "OK" not in dev[0].request("ROAM " + apdev[1]['bssid']):
+            raise Exception("ROAM failed")
+
+        dev[0].wait_connected(timeout=15)
+        hapds[1].wait_sta()
+        addr = dev[0].get_status_field("address")
+        if hapds[1].get_sta(addr).get('auth_alg') == '2':
+            raise Exception("FT was used with a new MAC address")
+
+    finally:
+        dev[0].set("rand_addr_lifetime", "60")
+
+    res = run_tshark(capfile, "wlan.fc.type_subtype == 0x000b && " +
+                     "wlan.fixed.auth.alg == 2", ["wlan.sa"])
+    if res.strip():
+        raise Exception("FT Authentication frames sent: " + res)
+
+def test_ap_ft_eap_enc_assoc_pmksa_privacy_mac_addr(dev, apdev, params):
+    """FT-EAP with PMKR0Name privacy and a new MAC address for each roam"""
+    run_ap_ft_enc_assoc_pmksa_privacy_mac_addr(dev, apdev, params)
+
+def test_ap_ft_eap_enc_assoc_pmksa_privacy_mac_addr_pull(dev, apdev, params):
+    """FT-EAP with PMKR0Name privacy and a new MAC address, no push"""
+    run_ap_ft_enc_assoc_pmksa_privacy_mac_addr(dev, apdev, params,
+                                               r1_push=False)
+
 def test_ap_ft_eap_enc_assoc_pmksa_privacy_ap_only(dev, apdev, params):
     """FT-EAP with encrypted reassociation and PMKR0Name privacy only on AP"""
     names = run_ap_ft_enc_assoc(dev, apdev, params, roams=2,
-- 
2.55.0




More information about the Hostap mailing list