]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: PMKSA cache control interface operations
authorJouni Malinen <j@w1.fi>
Sun, 20 Mar 2016 16:06:03 +0000 (18:06 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 20 Mar 2016 16:06:03 +0000 (18:06 +0200)
Signed-off-by: Jouni Malinen <j@w1.fi>
tests/hwsim/hostapd.py
tests/hwsim/test_pmksa_cache.py

index 0a4ad72acabaa0d5536514b5f0d71fbc1db6be50..1282e712f4f7474b1296a89da908228f2d3017f7 100644 (file)
@@ -319,6 +319,21 @@ class Hostapd:
                 vals[name_val[0]] = name_val[1]
         return vals
 
+    def get_pmksa(self, addr):
+        res = self.request("PMKSA")
+        lines = res.splitlines()
+        for l in lines:
+            if addr not in l:
+                continue
+            vals = dict()
+            [index,aa,pmkid,expiration,opportunistic] = l.split(' ')
+            vals['index'] = index
+            vals['pmkid'] = pmkid
+            vals['expiration'] = expiration
+            vals['opportunistic'] = opportunistic
+            return vals
+        return None
+
 def add_ap(ifname, params, wait_enabled=True, no_enable=False, timeout=30,
            hostname=None, port=8878):
         logger.info("Starting AP " + ifname)
index c837c79bcd6922b736e9c1a15d263e0820406466..f044c4e943ce5ff338d1c755b4ab63e2aa3c2693 100644 (file)
@@ -833,3 +833,46 @@ def test_pmksa_cache_preauth_wpas_oom(dev, apdev):
                 if state.startswith('0:'):
                     break
                 time.sleep(0.05)
+
+def test_pmksa_cache_ctrl(dev, apdev):
+    """PMKSA cache control interface operations"""
+    params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
+    hapd = hostapd.add_ap(apdev[0]['ifname'], params)
+    bssid = apdev[0]['bssid']
+    addr = dev[0].own_addr()
+
+    dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
+                   eap="GPSK", identity="gpsk user",
+                   password="abcdefghijklmnop0123456789abcdef",
+                   scan_freq="2412")
+
+    pmksa_sta = dev[0].get_pmksa(bssid)
+    if pmksa_sta is None:
+        raise Exception("No PMKSA cache entry created on STA")
+    pmksa_ap = hapd.get_pmksa(addr)
+    if pmksa_ap is None:
+        raise Exception("No PMKSA cache entry created on AP")
+    if pmksa_sta['pmkid'] != pmksa_ap['pmkid']:
+        raise Exception("PMKID mismatch in PMKSA cache entries")
+
+    if "OK" not in hapd.request("PMKSA_FLUSH"):
+        raise Exception("PMKSA_FLUSH failed")
+    pmksa_ap = hapd.get_pmksa(addr)
+    if pmksa_ap is not None:
+        raise Exception("PMKSA cache entry was not removed on AP")
+
+    dev[0].request("DISCONNECT")
+    dev[0].wait_disconnected()
+    dev[0].request("RECONNECT")
+    dev[0].wait_connected()
+
+    pmksa_sta2 = dev[0].get_pmksa(bssid)
+    if pmksa_sta2 is None:
+        raise Exception("No PMKSA cache entry created on STA after reconnect")
+    pmksa_ap2 = hapd.get_pmksa(addr)
+    if pmksa_ap2 is None:
+        raise Exception("No PMKSA cache entry created on AP after reconnect")
+    if pmksa_sta2['pmkid'] != pmksa_ap2['pmkid']:
+        raise Exception("PMKID mismatch in PMKSA cache entries after reconnect")
+    if pmksa_sta2['pmkid'] == pmksa_sta['pmkid']:
+        raise Exception("PMKID did not change after reconnect")