[v2,4/4] tests: Add basic Extended Key ID test
diff mbox series

Message ID 20190424161109.3046-4-alexander@wetzel-home.de
State New
Headers show
Series
  • [v2,1/4] Update API and drivers for Extended Key ID support
Related show

Commit Message

Alexander Wetzel April 24, 2019, 4:11 p.m. UTC
To verify interoperability of Extended Key ID test_ap_wpa2_ptk_rekey has
been modified and supplemented by test_ap_wpa2_ptk_rekey_extended.

Extended Key ID support affects all wpa2 tests. When supported it will
be used as default for all tests using wpa2 (RSN).

This also adds a new GET call for tests, allowing access to the driver
flags and verify driver capabilities.

Signed-off-by: Alexander Wetzel <alexander@wetzel-home.de>
---

Differences compared to v1:
- Fixed one too long line.

 hostapd/ctrl_iface.c         |  6 ++++++
 tests/hwsim/hostapd.py       |  6 ++++--
 tests/hwsim/test_ap_psk.py   | 41 ++++++++++++++++++++++++++++++++++--
 tests/hwsim/wpasupplicant.py |  3 ++-
 4 files changed, 51 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 3d7265b65..732dc9279 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -1452,6 +1452,12 @@  static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
 		if (os_snprintf_error(buflen, res))
 			return -1;
 		return res;
+	} else if (os_strcmp(cmd, "drv_flags") == 0) {
+		res = os_snprintf(buf, buflen, "%016lx",
+				  hapd->iface->drv_flags);
+		if (os_snprintf_error(buflen, res))
+			return -1;
+		return res;
 	}
 
 	return -1;
diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py
index 13f8df62f..3033ce69a 100644
--- a/tests/hwsim/hostapd.py
+++ b/tests/hwsim/hostapd.py
@@ -527,7 +527,7 @@  def add_ap(apdev, params, wait_enabled=True, no_enable=False, timeout=30,
             raise Exception("Could not ping hostapd")
         hapd.set_defaults()
         fields = ["ssid", "wpa_passphrase", "nas_identifier", "wpa_key_mgmt",
-                  "wpa",
+                  "wpa", "wpa_extended_key_id",
                   "wpa_pairwise", "rsn_pairwise", "auth_server_addr",
                   "acct_server_addr", "osu_server_uri"]
         for field in fields:
@@ -610,7 +610,7 @@  def terminate(apdev):
     hapd_global = HostapdGlobal(apdev)
     hapd_global.terminate()
 
-def wpa2_params(ssid=None, passphrase=None):
+def wpa2_params(ssid=None, passphrase=None, wpa_extended_key_id=None):
     params = {"wpa": "2",
               "wpa_key_mgmt": "WPA-PSK",
               "rsn_pairwise": "CCMP"}
@@ -618,6 +618,8 @@  def wpa2_params(ssid=None, passphrase=None):
         params["ssid"] = ssid
     if passphrase:
         params["wpa_passphrase"] = passphrase
+    if wpa_extended_key_id:
+        params["wpa_extended_key_id"] = wpa_extended_key_id
     return params
 
 def wpa_params(ssid=None, passphrase=None):
diff --git a/tests/hwsim/test_ap_psk.py b/tests/hwsim/test_ap_psk.py
index 3be68e830..e5b33dc71 100644
--- a/tests/hwsim/test_ap_psk.py
+++ b/tests/hwsim/test_ap_psk.py
@@ -203,15 +203,52 @@  def _test_ap_wpa2_psk_mem(dev, apdev):
 
 @remote_compatible
 def test_ap_wpa2_ptk_rekey(dev, apdev):
-    """WPA2-PSK AP and PTK rekey enforced by station"""
+    """WPA2-PSK AP and PTK rekey enforced by station without Extended Key ID"""
+    ssid = "test-wpa2-psk"
+    passphrase = 'qwertyuiop'
+    params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase,
+                                 wpa_extended_key_id="0")
+    hapd = hostapd.add_ap(apdev[0], params)
+    dev[0].connect(ssid, psk=passphrase, wpa_ptk_rekey="1", scan_freq="2412",
+                   wpa_extended_key_id="0")
+    ev = dev[0].wait_event(["WPA: Key negotiation completed"])
+    if ev is None:
+        raise Exception("PTK rekey timed out")
+    hwsim_utils.test_connectivity(dev[0], hapd)
+
+def test_ap_wpa2_ptk_rekey_extended(dev, apdev):
+    """WPA2-PSK AP and PTK rekey enforced by station with Extended Key ID"""
     ssid = "test-wpa2-psk"
     passphrase = 'qwertyuiop'
     params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
     hapd = hostapd.add_ap(apdev[0], params)
+    if not int(hapd.request("GET drv_flags"), 16) & 0x0400000000000000:
+        raise HwsimSkip("No Extended Key ID support in kernel")
+
+    dev[0].connect(ssid, psk=passphrase, wpa_ptk_rekey="1", scan_freq="2412",
+                   wpa_extended_key_id="0")
+    ev = dev[0].wait_event(["WPA: Key negotiation completed"])
+    if ev is None:
+        raise Exception("PTK rekey timed out (STA without Extended Key ID)")
+    hwsim_utils.test_connectivity(dev[0], hapd)
+
     dev[0].connect(ssid, psk=passphrase, wpa_ptk_rekey="1", scan_freq="2412")
     ev = dev[0].wait_event(["WPA: Key negotiation completed"])
     if ev is None:
-        raise Exception("PTK rekey timed out")
+        raise Exception("PTK rekey timed out (STA with Extended Key ID)")
+    hwsim_utils.test_connectivity(dev[0], hapd)
+    ev = dev[0].wait_event(["WPA: Key negotiation completed"])
+    if ev is None:
+        raise Exception("PTK rekey timed out 2 (STA with Extended Key ID)")
+    hwsim_utils.test_connectivity(dev[0], hapd)
+
+    params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase,
+                                 wpa_extended_key_id="0")
+    hapd = hostapd.add_ap(apdev[0], params)
+    dev[0].connect(ssid, psk=passphrase, wpa_ptk_rekey="1", scan_freq="2412")
+    ev = dev[0].wait_event(["WPA: Key negotiation completed"])
+    if ev is None:
+        raise Exception("PTK rekey timed out (AP without Extended Key ID")
     hwsim_utils.test_connectivity(dev[0], hapd)
 
 def test_ap_wpa2_ptk_rekey_anonce(dev, apdev):
diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py
index 3b9fd2964..e4c93d382 100644
--- a/tests/hwsim/wpasupplicant.py
+++ b/tests/hwsim/wpasupplicant.py
@@ -1084,7 +1084,8 @@  class WpaSupplicant:
                       "dpp_netaccesskey", "dpp_netaccesskey_expiry",
                       "group_mgmt", "owe_group",
                       "roaming_consortium_selection", "ocv",
-                      "multi_ap_backhaul_sta", "rx_stbc", "tx_stbc"]
+                      "multi_ap_backhaul_sta", "rx_stbc", "tx_stbc",
+                      "wpa_extended_key_id"]
         for field in not_quoted:
             if field in kwargs and kwargs[field]:
                 self.set_network(id, field, kwargs[field])