[PATCH 1/6] tests/hwsim: check_imsi_support helper func

Glenn Strauss gstrauss at gluelogic.com
Mon Nov 7 21:05:49 PST 2022


Signed-off-by: Glenn Strauss <gstrauss at gluelogic.com>
---
 tests/hwsim/test_ap_eap.py  | 67 ++++++++++++-------------------------
 tests/hwsim/test_ap_hs20.py |  6 ++--
 2 files changed, 24 insertions(+), 49 deletions(-)

diff --git a/tests/hwsim/test_ap_eap.py b/tests/hwsim/test_ap_eap.py
index dacd41041..89c8329c7 100644
--- a/tests/hwsim/test_ap_eap.py
+++ b/tests/hwsim/test_ap_eap.py
@@ -47,6 +47,13 @@ def check_eap_capa(dev, method):
         if tls.startswith("mbed TLS"):
             raise HwsimSkip("EAP-%s not supported with this TLS library: " % method + tls)
 
+def check_imsi_support(dev):
+    tls = dev.request("GET tls_library")
+    if tls.startswith("OpenSSL"):
+        return
+    else:
+        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+
 def check_subject_match_support(dev):
     tls = dev.request("GET tls_library")
     if tls.startswith("OpenSSL"):
@@ -352,9 +359,7 @@ def test_ap_wpa2_eap_sim_imsi_identity(dev, apdev, params):
     prefix = params['prefix']
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    tls = hapd.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(hapd)
 
     imsi = "232010000000000"
     realm = "wlan.mnc232.mcc02.3gppnetwork.org"
@@ -390,15 +395,11 @@ def test_ap_wpa2_eap_sim_imsi_identity(dev, apdev, params):
 
 def test_ap_wpa2_eap_sim_imsi_privacy_key(dev, apdev):
     """WPA2-Enterprise connection using EAP-SIM and imsi_privacy_cert"""
-    tls = dev[0].request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(dev[0])
     check_hlr_auc_gw_support()
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    tls = hapd.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(hapd)
 
     eap_connect(dev[0], hapd, "SIM",
                 "1232010000000000 at wlan.mnc232.mcc02.3gppnetwork.org",
@@ -408,15 +409,11 @@ def test_ap_wpa2_eap_sim_imsi_privacy_key(dev, apdev):
 
 def test_ap_wpa2_eap_sim_imsi_privacy_attr(dev, apdev):
     """WPA2-Enterprise connection using EAP-SIM and imsi_privacy_cert/attr"""
-    tls = dev[0].request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(dev[0])
     check_hlr_auc_gw_support()
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    tls = hapd.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(hapd)
 
     eap_connect(dev[0], hapd, "SIM",
                 "1232010000000000 at wlan.mnc232.mcc02.3gppnetwork.org",
@@ -1155,9 +1152,7 @@ def test_ap_wpa2_eap_aka_imsi_identity(dev, apdev, params):
     prefix = params['prefix']
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    tls = hapd.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(hapd)
 
     imsi = "232010000000000"
     realm = "wlan.mnc232.mcc02.3gppnetwork.org"
@@ -1193,15 +1188,11 @@ def test_ap_wpa2_eap_aka_imsi_identity(dev, apdev, params):
 
 def test_ap_wpa2_eap_aka_imsi_privacy_key(dev, apdev):
     """WPA2-Enterprise connection using EAP-AKA and imsi_privacy_cert"""
-    tls = dev[0].request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(dev[0])
     check_hlr_auc_gw_support()
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    tls = hapd.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(hapd)
 
     eap_connect(dev[0], hapd, "AKA",
                 "0232010000000000 at wlan.mnc232.mcc02.3gppnetwork.org",
@@ -1211,15 +1202,11 @@ def test_ap_wpa2_eap_aka_imsi_privacy_key(dev, apdev):
 
 def test_ap_wpa2_eap_aka_imsi_privacy_attr(dev, apdev):
     """WPA2-Enterprise connection using EAP-AKA and imsi_privacy_cert/attr"""
-    tls = dev[0].request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(dev[0])
     check_hlr_auc_gw_support()
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    tls = hapd.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(hapd)
 
     eap_connect(dev[0], hapd, "AKA",
                 "0232010000000000 at wlan.mnc232.mcc02.3gppnetwork.org",
@@ -1229,17 +1216,13 @@ def test_ap_wpa2_eap_aka_imsi_privacy_attr(dev, apdev):
 
 def test_ap_wpa2_eap_aka_imsi_privacy_key_expired(dev, apdev):
     """WPA2-Enterprise connection using EAP-AKA and expired imsi_privacy_cert"""
-    tls = dev[0].request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(dev[0])
     check_hlr_auc_gw_support()
     params = int_eap_server_params()
     params['eap_sim_db'] = 'unix:/tmp/hlr_auc_gw.sock'
     params['imsi_privacy_key'] = 'auth_serv/imsi-privacy-key-2.pem'
     hapd = hostapd.add_ap(apdev[0], params)
-    tls = hapd.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(hapd)
 
     dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
                    eap="AKA",
@@ -1470,9 +1453,7 @@ def test_ap_wpa2_eap_aka_prime_imsi_identity(dev, apdev, params):
     prefix = params['prefix']
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    tls = hapd.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(hapd)
 
     imsi = "555444333222111"
     realm = "wlan.mnc555.mcc44.3gppnetwork.org"
@@ -1508,15 +1489,11 @@ def test_ap_wpa2_eap_aka_prime_imsi_identity(dev, apdev, params):
 
 def test_ap_wpa2_eap_aka_prime_imsi_privacy_key(dev, apdev):
     """WPA2-Enterprise connection using EAP-AKA' and imsi_privacy_cert"""
-    tls = dev[0].request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(dev[0])
     check_hlr_auc_gw_support()
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    tls = hapd.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+    check_imsi_support(hapd)
 
     eap_connect(dev[0], hapd, "AKA'",
                 "6555444333222111 at wlan.mnc555.mcc44.3gppnetwork.org",
diff --git a/tests/hwsim/test_ap_hs20.py b/tests/hwsim/test_ap_hs20.py
index c981b3547..428cd1ab0 100644
--- a/tests/hwsim/test_ap_hs20.py
+++ b/tests/hwsim/test_ap_hs20.py
@@ -23,7 +23,7 @@ from tshark import run_tshark
 from wlantest import Wlantest
 from wpasupplicant import WpaSupplicant
 from wlantest import WlantestCapture
-from test_ap_eap import check_eap_capa, check_domain_match_full
+from test_ap_eap import check_eap_capa, check_domain_match_full, check_imsi_support
 from test_gas import gas_rx, parse_gas, action_response, anqp_initial_resp, send_gas_resp, ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE
 
 def hs20_ap_params(ssid="test-hs20"):
@@ -543,9 +543,7 @@ def hs20_simulated_sim(dev, ap, method, imsi_privacy=False,
     params = {'imsi': "555444-333222111", 'eap': method,
               'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123"}
     if imsi_privacy:
-        tls = dev.request("GET tls_library")
-        if not tls.startswith("OpenSSL"):
-            raise HwsimSkip("IMSI privacy not supported with this TLS library: " + tls)
+        check_imsi_support(dev)
         params['imsi_privacy_cert'] = "auth_serv/imsi-privacy-cert.pem"
         if imsi_privacy_attr:
             params['imsi_privacy_attr'] = "Identifier=1234567"
-- 
2.38.1



More information about the Hostap mailing list