From 865fa1e9ea87db7434d8b42686311cfe94e49352 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 20 Mar 2016 18:06:03 +0200 Subject: [PATCH] tests: PMKSA cache control interface operations Signed-off-by: Jouni Malinen --- tests/hwsim/hostapd.py | 15 ++++++++++++++ tests/hwsim/test_pmksa_cache.py | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index 0a4ad72..1282e71 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -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) diff --git a/tests/hwsim/test_pmksa_cache.py b/tests/hwsim/test_pmksa_cache.py index c837c79..f044c4e 100644 --- a/tests/hwsim/test_pmksa_cache.py +++ b/tests/hwsim/test_pmksa_cache.py @@ -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") -- 2.1.4