]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - tests/hwsim/test_ap_eap.py
tests: private_key_passwd2 in hostapd configuration
[thirdparty/hostap.git] / tests / hwsim / test_ap_eap.py
index 0acb39a36b1b89f071f922840d117a45d4afe633..4fcb1e1dfdf2237d8507552e7d4026512d24e401 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # WPA2-Enterprise tests
-# Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
+# Copyright (c) 2013-2019, Jouni Malinen <j@w1.fi>
 #
 # This software may be distributed under the terms of the BSD license.
 # See README for more details.
@@ -12,14 +12,19 @@ import subprocess
 import logging
 logger = logging.getLogger()
 import os
+import signal
 import socket
-import SocketServer
+try:
+    import SocketServer
+except ImportError:
+    import socketserver as SocketServer
 import struct
 import tempfile
 
 import hwsim_utils
+from hwsim import HWSimRadio
 import hostapd
-from utils import HwsimSkip, alloc_fail, fail_test, skip_with_fips, wait_fail_trigger
+from utils import HwsimSkip, alloc_fail, fail_test, skip_with_fips, wait_fail_trigger, require_under_vm
 from wpasupplicant import WpaSupplicant
 from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations, set_test_assoc_ie
 
@@ -40,12 +45,17 @@ def check_eap_capa(dev, method):
 
 def check_subject_match_support(dev):
     tls = dev.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
+    if not tls.startswith("OpenSSL") and not tls.startswith("wolfSSL"):
         raise HwsimSkip("subject_match not supported with this TLS library: " + tls)
 
-def check_altsubject_match_support(dev):
+def check_check_cert_subject_support(dev):
     tls = dev.request("GET tls_library")
     if not tls.startswith("OpenSSL"):
+        raise HwsimSkip("check_cert_subject not supported with this TLS library: " + tls)
+
+def check_altsubject_match_support(dev):
+    tls = dev.request("GET tls_library")
+    if not tls.startswith("OpenSSL") and not tls.startswith("wolfSSL"):
         raise HwsimSkip("altsubject_match not supported with this TLS library: " + tls)
 
 def check_domain_match(dev):
@@ -60,7 +70,7 @@ def check_domain_suffix_match(dev):
 
 def check_domain_match_full(dev):
     tls = dev.request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
+    if not tls.startswith("OpenSSL") and not tls.startswith("wolfSSL"):
         raise HwsimSkip("domain_suffix_match requires full match with this TLS library: " + tls)
 
 def check_cert_probe_support(dev):
@@ -79,10 +89,12 @@ def check_ocsp_support(dev):
     #    raise HwsimSkip("OCSP not supported with this TLS library: " + tls)
     #if "BoringSSL" in tls:
     #    raise HwsimSkip("OCSP not supported with this TLS library: " + tls)
+    if tls.startswith("wolfSSL"):
+        raise HwsimSkip("OCSP not supported with this TLS library: " + tls)
 
 def check_pkcs5_v15_support(dev):
     tls = dev.request("GET tls_library")
-    if "BoringSSL" in tls:
+    if "BoringSSL" in tls or "GnuTLS" in tls:
         raise HwsimSkip("PKCS#5 v1.5 not supported with this TLS library: " + tls)
 
 def check_ocsp_multi_support(dev):
@@ -99,6 +111,8 @@ def check_pkcs12_support(dev):
     tls = dev.request("GET tls_library")
     #if tls.startswith("internal"):
     #    raise HwsimSkip("PKCS#12 not supported with this TLS library: " + tls)
+    if tls.startswith("wolfSSL"):
+        raise HwsimSkip("PKCS#12 not supported with this TLS library: " + tls)
 
 def check_dh_dsa_support(dev):
     tls = dev.request("GET tls_library")
@@ -121,7 +135,8 @@ def read_pem(fname):
 
 def eap_connect(dev, hapd, method, identity,
                 sha256=False, expect_failure=False, local_error_report=False,
-                maybe_local_error=False, **kwargs):
+                maybe_local_error=False, report_failure=False,
+                expect_cert_error=None, **kwargs):
     id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
                      eap=method, identity=identity,
                      wait_connect=False, scan_freq="2412", ieee80211w="1",
@@ -129,17 +144,21 @@ def eap_connect(dev, hapd, method, identity,
     eap_check_auth(dev, method, True, sha256=sha256,
                    expect_failure=expect_failure,
                    local_error_report=local_error_report,
-                   maybe_local_error=maybe_local_error)
+                   maybe_local_error=maybe_local_error,
+                   report_failure=report_failure,
+                   expect_cert_error=expect_cert_error)
     if expect_failure:
         return id
-    ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
-    if ev is None:
-        raise Exception("No connection event received from hostapd")
+    if hapd:
+        ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=5)
+        if ev is None:
+            raise Exception("No connection event received from hostapd")
     return id
 
 def eap_check_auth(dev, method, initial, rsn=True, sha256=False,
                    expect_failure=False, local_error_report=False,
-                   maybe_local_error=False):
+                   maybe_local_error=False, report_failure=False,
+                   expect_cert_error=None):
     ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
     if ev is None:
         raise Exception("Association and EAP start timed out")
@@ -153,10 +172,19 @@ def eap_check_auth(dev, method, initial, rsn=True, sha256=False,
         raise Exception("Could not select EAP method")
     if method not in ev:
         raise Exception("Unexpected EAP method")
+    if expect_cert_error is not None:
+        ev = dev.wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
+                             "CTRL-EVENT-EAP-FAILURE",
+                             "CTRL-EVENT-EAP-SUCCESS"], timeout=5)
+        if ev is None or "reason=%d " % expect_cert_error not in ev:
+            raise Exception("Expected certificate error not reported")
     if expect_failure:
-        ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE"])
+        ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE",
+                             "CTRL-EVENT-EAP-SUCCESS"], timeout=5)
         if ev is None:
             raise Exception("EAP failure timed out")
+        if "CTRL-EVENT-EAP-SUCCESS" in ev:
+            raise Exception("Unexpected EAP success")
         ev = dev.wait_disconnected(timeout=10)
         if maybe_local_error and "locally_generated=1" in ev:
             return
@@ -164,9 +192,17 @@ def eap_check_auth(dev, method, initial, rsn=True, sha256=False,
             if "reason=23" not in ev:
                 raise Exception("Proper reason code for disconnection not reported")
         return
-    ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
-    if ev is None:
-        raise Exception("EAP success timed out")
+    if report_failure:
+        ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS",
+                             "CTRL-EVENT-EAP-FAILURE"], timeout=10)
+        if ev is None:
+            raise Exception("EAP success timed out")
+        if "CTRL-EVENT-EAP-SUCCESS" not in ev:
+            raise Exception("EAP failed")
+    else:
+        ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
+        if ev is None:
+            raise Exception("EAP success timed out")
 
     if initial:
         ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
@@ -340,6 +376,32 @@ def test_ap_wpa2_eap_sim_config(dev, apdev):
                 password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
                 anonymous_identity="345678")
 
+def test_ap_wpa2_eap_sim_id_0(dev, apdev):
+    """WPA2-Enterprise connection using EAP-SIM (no pseudonym or reauth)"""
+    run_ap_wpa2_eap_sim_id(dev, apdev, 0)
+
+def test_ap_wpa2_eap_sim_id_1(dev, apdev):
+    """WPA2-Enterprise connection using EAP-SIM (pseudonym, no reauth)"""
+    run_ap_wpa2_eap_sim_id(dev, apdev, 1)
+
+def test_ap_wpa2_eap_sim_id_2(dev, apdev):
+    """WPA2-Enterprise connection using EAP-SIM (no pseudonym, reauth)"""
+    run_ap_wpa2_eap_sim_id(dev, apdev, 2)
+
+def test_ap_wpa2_eap_sim_id_3(dev, apdev):
+    """WPA2-Enterprise connection using EAP-SIM (pseudonym and reauth)"""
+    run_ap_wpa2_eap_sim_id(dev, apdev, 3)
+
+def run_ap_wpa2_eap_sim_id(dev, apdev, eap_sim_id):
+    check_hlr_auc_gw_support()
+    params = int_eap_server_params()
+    params['eap_sim_id'] = str(eap_sim_id)
+    params['eap_sim_db'] = 'unix:/tmp/hlr_auc_gw.sock'
+    hapd = hostapd.add_ap(apdev[0], params)
+    eap_connect(dev[0], hapd, "SIM", "1232010000000000",
+                password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
+    eap_reauth(dev[0], "SIM")
+
 def test_ap_wpa2_eap_sim_ext(dev, apdev):
     """WPA2-Enterprise connection using EAP-SIM and external GSM auth"""
     try:
@@ -511,7 +573,7 @@ def _test_ap_wpa2_eap_sim_ext_replace_sim(dev, apdev):
     res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
                                    "-m",
                                    "auth_serv/hlr_auc_gw.milenage_db",
-                                   "GSM-AUTH-REQ 232010000000000 " + rand])
+                                   "GSM-AUTH-REQ 232010000000000 " + rand]).decode()
     if "GSM-AUTH-RESP" not in res:
         raise Exception("Unexpected hlr_auc_gw response")
     resp = res.split(' ')[2].rstrip()
@@ -537,7 +599,7 @@ def _test_ap_wpa2_eap_sim_ext_replace_sim(dev, apdev):
     res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
                                    "-m",
                                    "auth_serv/hlr_auc_gw.milenage_db",
-                                   "GSM-AUTH-REQ 232010000000009 " + rand])
+                                   "GSM-AUTH-REQ 232010000000009 " + rand]).decode()
     if "GSM-AUTH-RESP" not in res:
         raise Exception("Unexpected hlr_auc_gw response")
     resp = res.split(' ')[2].rstrip()
@@ -577,7 +639,7 @@ def _test_ap_wpa2_eap_sim_ext_replace_sim2(dev, apdev):
     res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
                                    "-m",
                                    "auth_serv/hlr_auc_gw.milenage_db",
-                                   "GSM-AUTH-REQ 232010000000000 " + rand])
+                                   "GSM-AUTH-REQ 232010000000000 " + rand]).decode()
     if "GSM-AUTH-RESP" not in res:
         raise Exception("Unexpected hlr_auc_gw response")
     resp = res.split(' ')[2].rstrip()
@@ -604,7 +666,7 @@ def _test_ap_wpa2_eap_sim_ext_replace_sim2(dev, apdev):
     res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
                                    "-m",
                                    "auth_serv/hlr_auc_gw.milenage_db",
-                                   "GSM-AUTH-REQ 232010000000009 " + rand])
+                                   "GSM-AUTH-REQ 232010000000009 " + rand]).decode()
     if "GSM-AUTH-RESP" not in res:
         raise Exception("Unexpected hlr_auc_gw response")
     resp = res.split(' ')[2].rstrip()
@@ -647,7 +709,7 @@ def _test_ap_wpa2_eap_sim_ext_replace_sim3(dev, apdev):
     res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
                                    "-m",
                                    "auth_serv/hlr_auc_gw.milenage_db",
-                                   "GSM-AUTH-REQ 232010000000000 " + rand])
+                                   "GSM-AUTH-REQ 232010000000000 " + rand]).decode()
     if "GSM-AUTH-RESP" not in res:
         raise Exception("Unexpected hlr_auc_gw response")
     resp = res.split(' ')[2].rstrip()
@@ -680,7 +742,7 @@ def _test_ap_wpa2_eap_sim_ext_replace_sim3(dev, apdev):
     res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
                                    "-m",
                                    "auth_serv/hlr_auc_gw.milenage_db",
-                                   "GSM-AUTH-REQ 232010000000009 " + rand])
+                                   "GSM-AUTH-REQ 232010000000009 " + rand]).decode()
     if "GSM-AUTH-RESP" not in res:
         raise Exception("Unexpected hlr_auc_gw response")
     resp = res.split(' ')[2].rstrip()
@@ -728,7 +790,7 @@ def test_ap_wpa2_eap_sim_change_bssid(dev, apdev):
 def _test_ap_wpa2_eap_sim_change_bssid(dev, apdev):
     check_hlr_auc_gw_support()
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
-    hostapd.add_ap(apdev[0], params)
+    hapd = hostapd.add_ap(apdev[0], params)
     dev[0].request("SET external_sim 1")
     id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
                         identity="1232010000000000",
@@ -746,13 +808,14 @@ def _test_ap_wpa2_eap_sim_change_bssid(dev, apdev):
     res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
                                    "-m",
                                    "auth_serv/hlr_auc_gw.milenage_db",
-                                   "GSM-AUTH-REQ 232010000000000 " + rand])
+                                   "GSM-AUTH-REQ 232010000000000 " + rand]).decode()
     if "GSM-AUTH-RESP" not in res:
         raise Exception("Unexpected hlr_auc_gw response")
     resp = res.split(' ')[2].rstrip()
 
     dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
     dev[0].wait_connected(timeout=15)
+    hapd.wait_sta()
 
     # Verify that EAP-SIM Reauthentication can be used after a profile change
     # that does not affect EAP parameters.
@@ -769,7 +832,7 @@ def test_ap_wpa2_eap_sim_no_change_set(dev, apdev):
 def _test_ap_wpa2_eap_sim_no_change_set(dev, apdev):
     check_hlr_auc_gw_support()
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
-    hostapd.add_ap(apdev[0], params)
+    hapd = hostapd.add_ap(apdev[0], params)
     dev[0].request("SET external_sim 1")
     id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
                         identity="1232010000000000",
@@ -787,13 +850,14 @@ def _test_ap_wpa2_eap_sim_no_change_set(dev, apdev):
     res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
                                    "-m",
                                    "auth_serv/hlr_auc_gw.milenage_db",
-                                   "GSM-AUTH-REQ 232010000000000 " + rand])
+                                   "GSM-AUTH-REQ 232010000000000 " + rand]).decode()
     if "GSM-AUTH-RESP" not in res:
         raise Exception("Unexpected hlr_auc_gw response")
     resp = res.split(' ')[2].rstrip()
 
     dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
     dev[0].wait_connected(timeout=15)
+    hapd.wait_sta()
 
     # Verify that EAP-SIM Reauthentication can be used after network profile
     # SET_NETWORK commands that do not actually change previously set
@@ -804,22 +868,83 @@ def _test_ap_wpa2_eap_sim_no_change_set(dev, apdev):
     dev[0].set_network_quoted(id, "ssid", "test-wpa2-eap")
     eap_reauth(dev[0], "SIM")
 
+def test_ap_wpa2_eap_sim_ext_anonymous(dev, apdev):
+    """EAP-SIM with external GSM auth and anonymous identity"""
+    check_hlr_auc_gw_support()
+    params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hostapd.add_ap(apdev[0], params)
+    try:
+        run_ap_wpa2_eap_sim_ext_anonymous(dev, "anonymous@example.org")
+        run_ap_wpa2_eap_sim_ext_anonymous(dev, "@example.org")
+    finally:
+        dev[0].request("SET external_sim 0")
+
+def test_ap_wpa2_eap_sim_ext_anonymous_no_pseudonym(dev, apdev):
+    """EAP-SIM with external GSM auth and anonymous identity without pseudonym update"""
+    check_hlr_auc_gw_support()
+    params = int_eap_server_params()
+    params['eap_sim_id'] = '0'
+    params['eap_sim_db'] = 'unix:/tmp/hlr_auc_gw.sock'
+    hostapd.add_ap(apdev[0], params)
+    try:
+        run_ap_wpa2_eap_sim_ext_anonymous(dev, "anonymous@example.org",
+                                          anon_id_change=False)
+        run_ap_wpa2_eap_sim_ext_anonymous(dev, "@example.org",
+                                          anon_id_change=False)
+    finally:
+        dev[0].request("SET external_sim 0")
+
+def run_ap_wpa2_eap_sim_ext_anonymous(dev, anon, anon_id_change=True):
+    dev[0].request("SET external_sim 1")
+    id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
+                        identity="1232010000000000",
+                        anonymous_identity=anon,
+                        wait_connect=False, scan_freq="2412")
+
+    ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
+    if ev is None:
+        raise Exception("Wait for external SIM processing request timed out")
+    p = ev.split(':', 2)
+    if p[1] != "GSM-AUTH":
+        raise Exception("Unexpected CTRL-REQ-SIM type")
+    rid = p[0].split('-')[3]
+    rand = p[2].split(' ')[0]
+
+    res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
+                                   "-m",
+                                   "auth_serv/hlr_auc_gw.milenage_db",
+                                   "GSM-AUTH-REQ 232010000000000 " + rand]).decode()
+    if "GSM-AUTH-RESP" not in res:
+        raise Exception("Unexpected hlr_auc_gw response")
+    resp = res.split(' ')[2].rstrip()
+
+    dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
+    dev[0].wait_connected(timeout=5)
+    anon_id = dev[0].get_network(id, "anonymous_identity").strip('"')
+    if anon_id_change and anon == anon_id:
+        raise Exception("anonymous_identity did not change")
+    if not anon_id_change and anon != anon_id:
+        raise Exception("anonymous_identity changed")
+    dev[0].request("REMOVE_NETWORK all")
+    dev[0].wait_disconnected()
+    dev[0].dump_monitor()
+
 def test_ap_wpa2_eap_sim_oom(dev, apdev):
     """EAP-SIM and OOM"""
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hostapd.add_ap(apdev[0], params)
-    tests = [ (1, "milenage_f2345"),
-              (2, "milenage_f2345"),
-              (3, "milenage_f2345"),
-              (4, "milenage_f2345"),
-              (5, "milenage_f2345"),
-              (6, "milenage_f2345"),
-              (7, "milenage_f2345"),
-              (8, "milenage_f2345"),
-              (9, "milenage_f2345"),
-              (10, "milenage_f2345"),
-              (11, "milenage_f2345"),
-              (12, "milenage_f2345") ]
+    tests = [(1, "milenage_f2345"),
+             (2, "milenage_f2345"),
+             (3, "milenage_f2345"),
+             (4, "milenage_f2345"),
+             (5, "milenage_f2345"),
+             (6, "milenage_f2345"),
+             (7, "milenage_f2345"),
+             (8, "milenage_f2345"),
+             (9, "milenage_f2345"),
+             (10, "milenage_f2345"),
+             (11, "milenage_f2345"),
+             (12, "milenage_f2345")]
     for count, func in tests:
         with fail_test(dev[0], count, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM",
@@ -1021,13 +1146,13 @@ def _test_ap_wpa2_eap_aka_ext(dev, apdev):
     time.sleep(0.1)
     dev[0].dump_monitor()
 
-    tests = [ ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344",
-              ":UMTS-AUTH:34",
-              ":UMTS-AUTH:00112233445566778899aabbccddeeff.00112233445566778899aabbccddeeff:0011223344",
-              ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddee:0011223344",
-              ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff.0011223344",
-              ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff0011223344",
-              ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:001122334q" ]
+    tests = [":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344",
+             ":UMTS-AUTH:34",
+             ":UMTS-AUTH:00112233445566778899aabbccddeeff.00112233445566778899aabbccddeeff:0011223344",
+             ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddee:0011223344",
+             ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff.0011223344",
+             ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff0011223344",
+             ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:001122334q"]
     for t in tests:
         dev[0].select_network(id, freq="2412")
         ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
@@ -1231,8 +1356,8 @@ def test_ap_wpa2_eap_ttls_pap(dev, apdev):
                 ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
     hwsim_utils.test_connectivity(dev[0], hapd)
     eap_reauth(dev[0], "TTLS")
-    check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-1"),
-                        ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-1") ])
+    check_mib(dev[0], [("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-1"),
+                       ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-1")])
 
 def test_ap_wpa2_eap_ttls_pap_subject_match(dev, apdev):
     """WPA2-Enterprise connection using EAP-TTLS/PAP and (alt)subject_match"""
@@ -1247,6 +1372,51 @@ def test_ap_wpa2_eap_ttls_pap_subject_match(dev, apdev):
                 altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/")
     eap_reauth(dev[0], "TTLS")
 
+def test_ap_wpa2_eap_ttls_pap_check_cert_subject(dev, apdev):
+    """EAP-TTLS/PAP and check_cert_subject"""
+    check_check_cert_subject_support(dev[0])
+    params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], params)
+    tests = ["C=FI/O=w1.fi/CN=server.w1.fi",
+             "C=FI/O=w1.fi",
+             "C=FI/CN=server.w1.fi",
+             "O=w1.fi/CN=server.w1.fi",
+             "C=FI",
+             "O=w1.fi",
+             "O=w1.*",
+             "CN=server.w1.fi",
+             "*"]
+    for test in tests:
+        eap_connect(dev[0], hapd, "TTLS", "pap user",
+                    anonymous_identity="ttls", password="password",
+                    ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
+                    check_cert_subject=test)
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].wait_disconnected()
+        dev[0].dump_monitor()
+
+def test_ap_wpa2_eap_ttls_pap_check_cert_subject_neg(dev, apdev):
+    """EAP-TTLS/PAP and check_cert_subject (negative)"""
+    check_check_cert_subject_support(dev[0])
+    params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], params)
+    tests = ["C=US",
+             "C",
+             "C=FI1*",
+             "O=w1.f",
+             "O=w1.fi1",
+             "O=w1.fi/O=foo",
+             "O=foo/O=w1.fi",
+             "O=w1.fi/O=w1.fi"]
+    for test in tests:
+        eap_connect(dev[0], hapd, "TTLS", "pap user",
+                    anonymous_identity="ttls", password="password",
+                    ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
+                    expect_failure=True, expect_cert_error=12,
+                    check_cert_subject=test)
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].dump_monitor()
+
 def test_ap_wpa2_eap_ttls_pap_incorrect_password(dev, apdev):
     """WPA2-Enterprise connection using EAP-TTLS/PAP - incorrect password"""
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
@@ -1373,9 +1543,9 @@ def test_ap_wpa2_eap_ttls_invalid_phase2(dev, apdev):
     """EAP-TTLS with invalid phase2 parameter values"""
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hostapd.add_ap(apdev[0], params)
-    tests = [ "auth=MSCHAPv2", "auth=MSCHAPV2 autheap=MD5",
-              "autheap=MD5 auth=MSCHAPV2", "auth=PAP auth=CHAP",
-              "autheap=MD5 autheap=FOO autheap=MSCHAPV2" ]
+    tests = ["auth=MSCHAPv2", "auth=MSCHAPV2 autheap=MD5",
+             "autheap=MD5 auth=MSCHAPV2", "auth=PAP auth=CHAP",
+             "autheap=MD5 autheap=FOO autheap=MSCHAPV2"]
     for t in tests:
         dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
                        identity="DOMAIN\mschapv2 user",
@@ -1445,7 +1615,7 @@ def test_ap_wpa2_eap_ttls_mschapv2_utf8(dev, apdev):
                 anonymous_identity="ttls",
                 password_hex="hash:bd5844fad2489992da7fe8c5a01559cf",
                 ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
-    for p in [ "80", "41c041e04141e041", 257*"41" ]:
+    for p in ["80", "41c041e04141e041", 257*"41"]:
         dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
                        eap="TTLS", identity="utf8-user-hash",
                        anonymous_identity="ttls", password_hex=p,
@@ -1514,8 +1684,8 @@ def test_ap_wpa2_eap_ttls_eap_gtc_oom(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
 
-    tests = [ "eap_gtc_init",
-              "eap_msg_alloc;eap_gtc_process" ]
+    tests = ["eap_gtc_init",
+             "eap_msg_alloc;eap_gtc_process"]
     for func in tests:
         with alloc_fail(dev[0], 1, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
@@ -1676,7 +1846,7 @@ def test_ap_wpa2_eap_ttls_eap_sim(dev, apdev):
                 ca_cert="auth_serv/ca.pem", phase2="autheap=SIM")
     eap_reauth(dev[0], "TTLS")
 
-def run_ext_sim_auth(dev):
+def run_ext_sim_auth(hapd, dev):
     ev = dev.wait_event(["CTRL-REQ-SIM"], timeout=15)
     if ev is None:
         raise Exception("Wait for external SIM processing request timed out")
@@ -1689,13 +1859,14 @@ def run_ext_sim_auth(dev):
     res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
                                    "-m",
                                    "auth_serv/hlr_auc_gw.milenage_db",
-                                   "GSM-AUTH-REQ 232010000000000 " + rand])
+                                   "GSM-AUTH-REQ 232010000000000 " + rand]).decode()
     if "GSM-AUTH-RESP" not in res:
         raise Exception("Unexpected hlr_auc_gw response")
     resp = res.split(' ')[2].rstrip()
 
     dev.request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
     dev.wait_connected(timeout=15)
+    hapd.wait_sta()
 
     dev.dump_monitor()
     dev.request("REAUTHENTICATE")
@@ -1725,7 +1896,7 @@ def run_ap_wpa2_eap_ttls_eap_sim_ext(dev, apdev):
                    password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
                    ca_cert="auth_serv/ca.pem", phase2="autheap=SIM",
                    wait_connect=False, scan_freq="2412")
-    run_ext_sim_auth(dev[0])
+    run_ext_sim_auth(hapd, dev[0])
 
 def test_ap_wpa2_eap_peap_eap_sim(dev, apdev):
     """WPA2-Enterprise connection using EAP-PEAP/EAP-SIM"""
@@ -1755,10 +1926,11 @@ def run_ap_wpa2_eap_peap_eap_sim_ext(dev, apdev):
                    password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
                    ca_cert="auth_serv/ca.pem", phase2="auth=SIM",
                    wait_connect=False, scan_freq="2412")
-    run_ext_sim_auth(dev[0])
+    run_ext_sim_auth(hapd, dev[0])
 
 def test_ap_wpa2_eap_fast_eap_sim(dev, apdev):
     """WPA2-Enterprise connection using EAP-FAST/EAP-SIM"""
+    check_eap_capa(dev[0], "FAST")
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
     eap_connect(dev[0], hapd, "FAST", "1232010000000000",
@@ -1789,7 +1961,7 @@ def run_ap_wpa2_eap_fast_eap_sim_ext(dev, apdev):
                    pac_file="blob://fast_pac_auth_sim",
                    ca_cert="auth_serv/ca.pem", phase2="auth=SIM",
                    wait_connect=False, scan_freq="2412")
-    run_ext_sim_auth(dev[0])
+    run_ext_sim_auth(hapd, dev[0])
 
 def test_ap_wpa2_eap_ttls_eap_aka(dev, apdev):
     """WPA2-Enterprise connection using EAP-TTLS/EAP-AKA"""
@@ -1859,7 +2031,7 @@ def test_ap_wpa2_eap_peap_eap_mschapv2_domain(dev, apdev):
     check_eap_capa(dev[0], "MSCHAPV2")
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    eap_connect(dev[0], hapd, "PEAP", "DOMAIN\user3",
+    eap_connect(dev[0], hapd, "PEAP", r"DOMAIN\user3",
                 anonymous_identity="peap", password="password",
                 ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
     hwsim_utils.test_connectivity(dev[0], hapd)
@@ -1948,15 +2120,18 @@ def test_ap_wpa2_eap_peap_params(dev, apdev):
     ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
     if ev is None:
         raise Exception("No EAP success seen")
-    ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
-    if ev is not None:
+    ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
+                            "CTRL-EVENT-DISCONNECTED"], timeout=1)
+    if ev and "CTRL-EVENT-CONNECTED" in ev:
         raise Exception("Unexpected connection")
+    dev[0].request("REMOVE_NETWORK all")
+    dev[0].disconnect_and_stop_scan()
 
-    tests = [ ("peap-ver0", ""),
-              ("peap-ver1", ""),
-              ("peap-ver0", "peapver=0"),
-              ("peap-ver1", "peapver=1") ]
-    for anon,phase1 in tests:
+    tests = [("peap-ver0", ""),
+             ("peap-ver1", ""),
+             ("peap-ver0", "peapver=0"),
+             ("peap-ver1", "peapver=1")]
+    for anon, phase1 in tests:
         dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
                        identity="user", anonymous_identity=anon,
                        password="password", phase1=phase1,
@@ -1965,9 +2140,9 @@ def test_ap_wpa2_eap_peap_params(dev, apdev):
         dev[0].request("REMOVE_NETWORK all")
         dev[0].wait_disconnected()
 
-    tests = [ ("peap-ver0", "peapver=1"),
-              ("peap-ver1", "peapver=0") ]
-    for anon,phase1 in tests:
+    tests = [("peap-ver0", "peapver=1"),
+             ("peap-ver1", "peapver=0")]
+    for anon, phase1 in tests:
         dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
                        identity="user", anonymous_identity=anon,
                        password="password", phase1=phase1,
@@ -1984,6 +2159,14 @@ def test_ap_wpa2_eap_peap_params(dev, apdev):
                 phase1="tls_allow_md5=1 tls_disable_session_ticket=1 tls_disable_tlsv1_0=0 tls_disable_tlsv1_1=0 tls_disable_tlsv1_2=0 tls_ext_cert_check=0",
                 phase2="auth=MSCHAPV2")
 
+def test_ap_wpa2_eap_peap_eap_gtc(dev, apdev, params):
+    """WPA2-Enterprise connection using EAP-PEAP/EAP-GTC"""
+    p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], p)
+    eap_connect(dev[0], hapd, "PEAP", "user", phase1="peapver=1",
+                anonymous_identity="peap", password="password",
+                ca_cert="auth_serv/ca.pem", phase2="auth=GTC")
+
 def test_ap_wpa2_eap_peap_eap_tls(dev, apdev):
     """WPA2-Enterprise connection using EAP-PEAP/EAP-TLS"""
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
@@ -2028,13 +2211,13 @@ def test_ap_wpa2_eap_tls_blob(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
     cert = read_pem("auth_serv/ca.pem")
-    if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
+    if "OK" not in dev[0].request("SET blob cacert " +  binascii.hexlify(cert).decode()):
         raise Exception("Could not set cacert blob")
     cert = read_pem("auth_serv/user.pem")
-    if "OK" not in dev[0].request("SET blob usercert " + cert.encode("hex")):
+    if "OK" not in dev[0].request("SET blob usercert " + binascii.hexlify(cert).decode()):
         raise Exception("Could not set usercert blob")
     key = read_pem("auth_serv/user.rsa-key")
-    if "OK" not in dev[0].request("SET blob userkey " + key.encode("hex")):
+    if "OK" not in dev[0].request("SET blob userkey " + binascii.hexlify(key).decode()):
         raise Exception("Could not set cacert blob")
     eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="blob://cacert",
                 client_cert="blob://usercert",
@@ -2105,14 +2288,35 @@ def test_ap_wpa2_eap_tls_pkcs12(dev, apdev):
 
 def test_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev):
     """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob"""
+    cert = read_pem("auth_serv/ca.pem")
+    cacert = binascii.hexlify(cert).decode()
+    run_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev, cacert)
+
+def test_ap_wpa2_eap_tls_pkcs12_blob_pem(dev, apdev):
+    """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob and PEM ca_cert blob"""
+    with open("auth_serv/ca.pem", "r") as f:
+        lines = f.readlines()
+        copy = False
+        cert = ""
+        for l in lines:
+            if "-----BEGIN" in l:
+                copy = True
+            if copy:
+                cert += l
+            if "-----END" in l:
+                copy = False
+                break
+    cacert = binascii.hexlify(cert.encode()).decode()
+    run_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev, cacert)
+
+def run_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev, cacert):
     check_pkcs12_support(dev[0])
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
-    cert = read_pem("auth_serv/ca.pem")
-    if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
+    if "OK" not in dev[0].request("SET blob cacert " + cacert):
         raise Exception("Could not set cacert blob")
     with open("auth_serv/user.pkcs12", "rb") as f:
-        if "OK" not in dev[0].request("SET blob pkcs12 " + f.read().encode("hex")):
+        if "OK" not in dev[0].request("SET blob pkcs12 " + binascii.hexlify(f.read()).decode()):
             raise Exception("Could not set pkcs12 blob")
     eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="blob://cacert",
                 private_key="blob://pkcs12",
@@ -2124,7 +2328,7 @@ def test_ap_wpa2_eap_tls_neg_incorrect_trust_root(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hostapd.add_ap(apdev[0], params)
     cert = read_pem("auth_serv/ca-incorrect.pem")
-    if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
+    if "OK" not in dev[0].request("SET blob cacert " + binascii.hexlify(cert).decode()):
         raise Exception("Could not set cacert blob")
     dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
                    identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
@@ -2429,10 +2633,10 @@ def test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hostapd.add_ap(apdev[0], params)
 
-    tests = [ "incorrect.example.com",
-              "DNS:incorrect.example.com",
-              "DNS:w1.fi",
-              "DNS:erver.w1.fi" ]
+    tests = ["incorrect.example.com",
+             "DNS:incorrect.example.com",
+             "DNS:w1.fi",
+             "DNS:erver.w1.fi"]
     for match in tests:
         _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match)
 
@@ -2507,7 +2711,7 @@ def test_ap_wpa2_eap_ttls_server_cert_hash(dev, apdev):
     """WPA2-Enterprise connection using EAP-TTLS and server certificate hash"""
     check_cert_probe_support(dev[0])
     skip_with_fips(dev[0])
-    srv_cert_hash = "53728dde442d4adc27cb10a847234a4315590f0b36786353023c3b0f2e9fdf49"
+    srv_cert_hash = "4704e62784f36cc5fd964c6410402f4938773bb471dce9d42939bf22fdbdb2dd"
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
     dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
@@ -2613,60 +2817,109 @@ def test_ap_wpa2_eap_pwd_nthash(dev, apdev):
                 password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a",
                 expect_failure=True, local_error_report=True)
 
+def test_ap_wpa2_eap_pwd_salt_sha1(dev, apdev):
+    """WPA2-Enterprise connection using EAP-pwd and salted password SHA-1"""
+    check_eap_capa(dev[0], "PWD")
+    params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], params)
+    eap_connect(dev[0], hapd, "PWD", "pwd-hash-sha1",
+                password="secret password")
+
+def test_ap_wpa2_eap_pwd_salt_sha256(dev, apdev):
+    """WPA2-Enterprise connection using EAP-pwd and salted password SHA256"""
+    check_eap_capa(dev[0], "PWD")
+    params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], params)
+    eap_connect(dev[0], hapd, "PWD", "pwd-hash-sha256",
+                password="secret password")
+
+def test_ap_wpa2_eap_pwd_salt_sha512(dev, apdev):
+    """WPA2-Enterprise connection using EAP-pwd and salted password SHA512"""
+    check_eap_capa(dev[0], "PWD")
+    params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], params)
+    eap_connect(dev[0], hapd, "PWD", "pwd-hash-sha512",
+                password="secret password")
+
 def test_ap_wpa2_eap_pwd_groups(dev, apdev):
     """WPA2-Enterprise connection using various EAP-pwd groups"""
     check_eap_capa(dev[0], "PWD")
     tls = dev[0].request("GET tls_library")
-    params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
-               "rsn_pairwise": "CCMP", "ieee8021x": "1",
-               "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
-    groups = [ 19, 20, 21, 25, 26 ]
-    if tls.startswith("OpenSSL") and "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
-        logger.info("Add Brainpool EC groups since OpenSSL is new enough")
-        groups += [ 27, 28, 29, 30 ]
+    params = {"ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP", "ieee8021x": "1",
+              "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf"}
+    groups = [19, 20, 21]
     for i in groups:
         logger.info("Group %d" % i)
         params['pwd_group'] = str(i)
         hapd = hostapd.add_ap(apdev[0], params)
-        try:
-            eap_connect(dev[0], hapd, "PWD", "pwd user",
-                        password="secret password")
-            dev[0].request("REMOVE_NETWORK all")
-            dev[0].wait_disconnected()
-            dev[0].dump_monitor()
-        except:
-            if "BoringSSL" in tls and i in [ 25 ]:
-                logger.info("Ignore connection failure with group %d with BoringSSL" % i)
-                dev[0].request("DISCONNECT")
-                time.sleep(0.1)
-                dev[0].request("REMOVE_NETWORK all")
-                dev[0].dump_monitor()
-                continue
-            raise
+        eap_connect(dev[0], hapd, "PWD", "pwd user",
+                    password="secret password",
+                    phase1="eap_pwd_groups=0-65535")
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].wait_disconnected()
+        dev[0].dump_monitor()
+        hapd.disable()
 
 def test_ap_wpa2_eap_pwd_invalid_group(dev, apdev):
     """WPA2-Enterprise connection using invalid EAP-pwd group"""
     check_eap_capa(dev[0], "PWD")
-    params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
-               "rsn_pairwise": "CCMP", "ieee8021x": "1",
-               "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
-    params['pwd_group'] = "0"
-    hostapd.add_ap(apdev[0], params)
+    params = {"ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP", "ieee8021x": "1",
+              "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf"}
+    for i in [0, 25, 26, 27]:
+        logger.info("Group %d" % i)
+        params['pwd_group'] = str(i)
+        hapd = hostapd.add_ap(apdev[0], params)
+        dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD",
+                       identity="pwd user", password="secret password",
+                       phase1="eap_pwd_groups=0-65535",
+                       scan_freq="2412", wait_connect=False)
+        ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
+        if ev is None:
+            raise Exception("Timeout on EAP failure report (group %d)" % i)
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].wait_disconnected()
+        dev[0].dump_monitor()
+        hapd.disable()
+
+def test_ap_wpa2_eap_pwd_disabled_group(dev, apdev):
+    """WPA2-Enterprise connection using disabled EAP-pwd group"""
+    check_eap_capa(dev[0], "PWD")
+    params = {"ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP", "ieee8021x": "1",
+              "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf"}
+    for i in [19, 21]:
+        logger.info("Group %d" % i)
+        params['pwd_group'] = str(i)
+        hapd = hostapd.add_ap(apdev[0], params)
+        dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD",
+                       identity="pwd user", password="secret password",
+                       phase1="eap_pwd_groups=20",
+                       scan_freq="2412", wait_connect=False)
+        ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
+        if ev is None:
+            raise Exception("Timeout on EAP failure report (group %d)" % i)
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].wait_disconnected()
+        dev[0].dump_monitor()
+        hapd.disable()
+
+    params['pwd_group'] = "20"
+    hapd = hostapd.add_ap(apdev[0], params)
     dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD",
                    identity="pwd user", password="secret password",
-                   scan_freq="2412", wait_connect=False)
-    ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
-    if ev is None:
-        raise Exception("Timeout on EAP failure report")
+                   phase1="eap_pwd_groups=20",
+                   scan_freq="2412")
 
 def test_ap_wpa2_eap_pwd_as_frag(dev, apdev):
     """WPA2-Enterprise connection using EAP-pwd with server fragmentation"""
     check_eap_capa(dev[0], "PWD")
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
-    params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
-               "rsn_pairwise": "CCMP", "ieee8021x": "1",
-               "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
-               "pwd_group": "19", "fragment_size": "40" }
+    params = {"ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP", "ieee8021x": "1",
+              "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
+              "pwd_group": "19", "fragment_size": "40"}
     hapd = hostapd.add_ap(apdev[0], params)
     eap_connect(dev[0], hapd, "PWD", "pwd user", password="secret password")
 
@@ -2679,7 +2932,7 @@ def test_ap_wpa2_eap_gpsk(dev, apdev):
     eap_reauth(dev[0], "GPSK")
 
     logger.info("Test forced algorithm selection")
-    for phase1 in [ "cipher=1", "cipher=2" ]:
+    for phase1 in ["cipher=1", "cipher=2"]:
         dev[0].set_network_quoted(id, "phase1", phase1)
         ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
         if ev is None:
@@ -2720,21 +2973,33 @@ def test_ap_wpa2_eap_eke(dev, apdev):
     eap_reauth(dev[0], "EKE")
 
     logger.info("Test forced algorithm selection")
-    for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2",
-                    "dhgroup=4 encr=1 prf=2 mac=2",
-                    "dhgroup=3 encr=1 prf=2 mac=2",
-                    "dhgroup=3 encr=1 prf=1 mac=1" ]:
+    for phase1 in ["dhgroup=5 encr=1 prf=2 mac=2",
+                   "dhgroup=4 encr=1 prf=2 mac=2",
+                   "dhgroup=3 encr=1 prf=2 mac=2",
+                   "dhgroup=3 encr=1 prf=1 mac=1"]:
         dev[0].set_network_quoted(id, "phase1", phase1)
         ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
         if ev is None:
             raise Exception("EAP success timed out")
         dev[0].wait_connected(timeout=10)
+    dev[0].dump_monitor()
 
     logger.info("Test failed algorithm negotiation")
     dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9")
     ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
     if ev is None:
         raise Exception("EAP failure timed out")
+    dev[0].dump_monitor()
+
+    logger.info("Test unsupported algorithm proposals")
+    dev[0].request("REMOVE_NETWORK all")
+    dev[0].dump_monitor()
+    eap_connect(dev[0], hapd, "EKE", "eke user", password="hello",
+                phase1="dhgroup=2 encr=1 prf=1 mac=1", expect_failure=True)
+    dev[0].request("REMOVE_NETWORK all")
+    dev[0].dump_monitor()
+    eap_connect(dev[0], hapd, "EKE", "eke user", password="hello",
+                phase1="dhgroup=1 encr=1 prf=1 mac=1", expect_failure=True)
 
     logger.info("Negative test with incorrect password")
     dev[0].request("REMOVE_NETWORK all")
@@ -2788,7 +3053,7 @@ def test_ap_wpa2_eap_eke_server_oom(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], params)
     dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
 
-    for count,func in [ (1, "eap_eke_build_commit"),
+    for count, func in [(1, "eap_eke_build_commit"),
                         (2, "eap_eke_build_commit"),
                         (3, "eap_eke_build_commit"),
                         (1, "eap_eke_build_confirm"),
@@ -2799,19 +3064,19 @@ def test_ap_wpa2_eap_eke_server_oom(dev, apdev):
                         (1, "eap_eke_process_identity"),
                         (2, "eap_eke_process_identity"),
                         (3, "eap_eke_process_identity"),
-                        (4, "eap_eke_process_identity") ]:
+                        (4, "eap_eke_process_identity")]:
         with alloc_fail(hapd, count, func):
             eap_connect(dev[0], hapd, "EKE", "eke user", password="hello",
                         expect_failure=True)
             dev[0].request("REMOVE_NETWORK all")
 
-    for count,func,pw in [ (1, "eap_eke_init", "hello"),
-                           (1, "eap_eke_get_session_id", "hello"),
-                           (1, "eap_eke_getKey", "hello"),
-                           (1, "eap_eke_build_msg", "hello"),
-                           (1, "eap_eke_build_failure", "wrong"),
-                           (1, "eap_eke_build_identity", "hello"),
-                           (2, "eap_eke_build_identity", "hello") ]:
+    for count, func, pw in [(1, "eap_eke_init", "hello"),
+                            (1, "eap_eke_get_session_id", "hello"),
+                            (1, "eap_eke_getKey", "hello"),
+                            (1, "eap_eke_build_msg", "hello"),
+                            (1, "eap_eke_build_failure", "wrong"),
+                            (1, "eap_eke_build_identity", "hello"),
+                            (2, "eap_eke_build_identity", "hello")]:
         with alloc_fail(hapd, count, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
                            eap="EKE", identity="eke user", password=pw,
@@ -2838,7 +3103,7 @@ def test_ap_wpa2_eap_eke_server_oom(dev, apdev):
                     if hapd.request("GET_ALLOC_FAIL").startswith('0'):
                         break
                 dev[0].request("REMOVE_NETWORK all")
-        except Exception, e:
+        except Exception as e:
             if str(e) == "Allocation failure did not trigger":
                 if count < 30:
                     raise Exception("Too few allocation failures")
@@ -2873,10 +3138,10 @@ def test_ap_wpa2_eap_ikev2_as_frag(dev, apdev):
     """WPA2-Enterprise connection using EAP-IKEv2 with server fragmentation"""
     check_eap_capa(dev[0], "IKEV2")
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
-    params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
-               "rsn_pairwise": "CCMP", "ieee8021x": "1",
-               "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
-               "fragment_size": "50" }
+    params = {"ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP", "ieee8021x": "1",
+              "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
+              "fragment_size": "50"}
     hapd = hostapd.add_ap(apdev[0], params)
     eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
                 password="ike password")
@@ -2888,9 +3153,9 @@ def test_ap_wpa2_eap_ikev2_oom(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hostapd.add_ap(apdev[0], params)
 
-    tests = [ (1, "dh_init"),
-              (2, "dh_init"),
-              (1, "dh_derive_shared") ]
+    tests = [(1, "dh_init"),
+             (2, "dh_init"),
+             (1, "dh_derive_shared")]
     for count, func in tests:
         with alloc_fail(dev[0], count, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
@@ -2905,7 +3170,11 @@ def test_ap_wpa2_eap_ikev2_oom(dev, apdev):
                 time.sleep(0.02)
             dev[0].request("REMOVE_NETWORK all")
 
-    tests = [ (1, "os_get_random;dh_init") ]
+    tls = dev[0].request("GET tls_library")
+    if not tls.startswith("wolfSSL"):
+        tests = [(1, "os_get_random;dh_init")]
+    else:
+        tests = [(1, "crypto_dh_init;dh_init")]
     for count, func in tests:
         with fail_test(dev[0], count, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
@@ -2943,8 +3212,8 @@ def test_ap_wpa2_eap_psk(dev, apdev):
     eap_connect(dev[0], hapd, "PSK", "psk.user@example.com",
                 password_hex="0123456789abcdef0123456789abcdef", sha256=True)
     eap_reauth(dev[0], "PSK", sha256=True)
-    check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"),
-                        ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ])
+    check_mib(dev[0], [("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"),
+                       ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5")])
 
     bss = dev[0].get_bss(apdev[0]['bssid'])
     if 'flags' not in bss:
@@ -2963,8 +3232,8 @@ def test_ap_wpa2_eap_psk_oom(dev, apdev):
     skip_with_fips(dev[0])
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hostapd.add_ap(apdev[0], params)
-    tests = [ (1, "=aes_128_eax_encrypt"),
-              (1, "=aes_128_eax_decrypt") ]
+    tests = [(1, "=aes_128_eax_encrypt"),
+             (1, "=aes_128_eax_decrypt")]
     for count, func in tests:
         with alloc_fail(dev[0], count, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
@@ -2979,15 +3248,15 @@ def test_ap_wpa2_eap_psk_oom(dev, apdev):
             dev[0].request("REMOVE_NETWORK all")
             dev[0].wait_disconnected()
 
-    tests = [ (1, "aes_ctr_encrypt;aes_128_eax_encrypt"),
-              (1, "omac1_aes_128;aes_128_eax_encrypt"),
-              (2, "omac1_aes_128;aes_128_eax_encrypt"),
-              (3, "omac1_aes_128;aes_128_eax_encrypt"),
-              (1, "omac1_aes_vector"),
-              (1, "omac1_aes_128;aes_128_eax_decrypt"),
-              (2, "omac1_aes_128;aes_128_eax_decrypt"),
-              (3, "omac1_aes_128;aes_128_eax_decrypt"),
-              (1, "aes_ctr_encrypt;aes_128_eax_decrypt") ]
+    tests = [(1, "aes_ctr_encrypt;aes_128_eax_encrypt"),
+             (1, "omac1_aes_128;aes_128_eax_encrypt"),
+             (2, "omac1_aes_128;aes_128_eax_encrypt"),
+             (3, "omac1_aes_128;aes_128_eax_encrypt"),
+             (1, "omac1_aes_vector"),
+             (1, "omac1_aes_128;aes_128_eax_decrypt"),
+             (2, "omac1_aes_128;aes_128_eax_decrypt"),
+             (3, "omac1_aes_128;aes_128_eax_decrypt"),
+             (1, "aes_ctr_encrypt;aes_128_eax_decrypt")]
     for count, func in tests:
         with fail_test(dev[0], count, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
@@ -3023,10 +3292,11 @@ def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev):
                    ca_cert="auth_serv/ca.pem", wait_connect=False,
                    scan_freq="2412")
     eap_check_auth(dev[0], "PEAP", True, rsn=False)
+    hapd.wait_sta()
     hwsim_utils.test_connectivity(dev[0], hapd)
     eap_reauth(dev[0], "PEAP", rsn=False)
-    check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"),
-                        ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ])
+    check_mib(dev[0], [("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"),
+                       ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1")])
     status = dev[0].get_status(extra="VERBOSE")
     if 'portControl' not in status:
         raise Exception("portControl missing from STATUS-VERBOSE")
@@ -3043,21 +3313,21 @@ def test_ap_wpa2_eap_interactive(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
 
-    tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry",
-               "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2",
-               None, "password"),
-              ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry",
-               "TTLS", "ttls", None, "auth=MSCHAPV2",
-               "DOMAIN\mschapv2 user", "password"),
-              ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry",
-               "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"),
-              ("Connection with dynamic TTLS/EAP-MD5 password entry",
-               "TTLS", "ttls", "user", "autheap=MD5", None, "password"),
-              ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry",
-               "PEAP", None, "user", "auth=MSCHAPV2", None, "password"),
-              ("Connection with dynamic PEAP/EAP-GTC password entry",
-               "PEAP", None, "user", "auth=GTC", None, "password") ]
-    for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests:
+    tests = [("Connection with dynamic TTLS/MSCHAPv2 password entry",
+              "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2",
+              None, "password"),
+             ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry",
+              "TTLS", "ttls", None, "auth=MSCHAPV2",
+              "DOMAIN\mschapv2 user", "password"),
+             ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry",
+              "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"),
+             ("Connection with dynamic TTLS/EAP-MD5 password entry",
+              "TTLS", "ttls", "user", "autheap=MD5", None, "password"),
+             ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry",
+              "PEAP", None, "user", "auth=MSCHAPV2", None, "password"),
+             ("Connection with dynamic PEAP/EAP-GTC password entry",
+              "PEAP", None, "user", "auth=GTC", None, "password")]
+    for [desc, eap, anon, identity, phase2, req_id, req_pw] in tests:
         logger.info(desc)
         dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap,
                        anonymous_identity=anon, identity=identity,
@@ -3069,7 +3339,7 @@ def test_ap_wpa2_eap_interactive(dev, apdev):
                 raise Exception("Request for identity timed out")
             id = ev.split(':')[0].split('-')[-1]
             dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
-        ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"])
+        ev = dev[0].wait_event(["CTRL-REQ-PASSWORD", "CTRL-REQ-OTP"])
         if ev is None:
             raise Exception("Request for password timed out")
         id = ev.split(':')[0].split('-')[-1]
@@ -3121,9 +3391,9 @@ def test_ap_wpa2_eap_vendor_test_oom(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hostapd.add_ap(apdev[0], params)
 
-    tests = [ "eap_vendor_test_init",
-              "eap_msg_alloc;eap_vendor_test_process",
-              "eap_vendor_test_getKey" ]
+    tests = ["eap_vendor_test_init",
+             "eap_msg_alloc;eap_vendor_test_process",
+             "eap_vendor_test_getKey"]
     for func in tests:
         with alloc_fail(dev[0], 1, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
@@ -3249,9 +3519,9 @@ def test_ap_wpa2_eap_fast_binary_pac_errors(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
 
-    tests = [ (1, "=eap_fast_save_pac_bin"),
-              (1, "eap_fast_write_pac"),
-              (2, "eap_fast_write_pac"), ]
+    tests = [(1, "=eap_fast_save_pac_bin"),
+             (1, "eap_fast_write_pac"),
+             (2, "eap_fast_write_pac"),]
     for count, func in tests:
         if "OK" not in dev[0].request("SET blob fast_pac_bin_errors "):
             raise Exception("Could not set blob")
@@ -3265,12 +3535,12 @@ def test_ap_wpa2_eap_fast_binary_pac_errors(dev, apdev):
             dev[0].request("REMOVE_NETWORK all")
             dev[0].wait_disconnected()
 
-    tests = [ "00", "000000000000", "6ae4920c0001",
-              "6ae4920c000000",
-              "6ae4920c0000" + "0000" + 32*"00" + "ffff" + "0000",
-              "6ae4920c0000" + "0000" + 32*"00" + "0001" + "0000",
-              "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0001",
-              "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0008" + "00040000" + "0007000100"]
+    tests = ["00", "000000000000", "6ae4920c0001",
+             "6ae4920c000000",
+             "6ae4920c0000" + "0000" + 32*"00" + "ffff" + "0000",
+             "6ae4920c0000" + "0000" + 32*"00" + "0001" + "0000",
+             "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0001",
+             "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0008" + "00040000" + "0007000100"]
     for t in tests:
         if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + t):
             raise Exception("Could not set blob")
@@ -3290,9 +3560,9 @@ def test_ap_wpa2_eap_fast_binary_pac_errors(dev, apdev):
         dev[0].wait_disconnected()
 
     pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0000"
-    tests = [ (1, "eap_fast_load_pac_bin"),
-              (2, "eap_fast_load_pac_bin"),
-              (3, "eap_fast_load_pac_bin") ]
+    tests = [(1, "eap_fast_load_pac_bin"),
+             (2, "eap_fast_load_pac_bin"),
+             (3, "eap_fast_load_pac_bin")]
     for count, func in tests:
         if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
             raise Exception("Could not set blob")
@@ -3325,8 +3595,8 @@ def test_ap_wpa2_eap_fast_binary_pac_errors(dev, apdev):
     dev[0].wait_disconnected()
 
     pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0009" + "00040000" + "0007000100"
-    tests = [ (1, "eap_fast_pac_get_a_id"),
-              (2, "eap_fast_pac_get_a_id") ]
+    tests = [(1, "eap_fast_pac_get_a_id"),
+             (2, "eap_fast_pac_get_a_id")]
     for count, func in tests:
         if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
             raise Exception("Could not set blob")
@@ -3345,11 +3615,11 @@ def test_ap_wpa2_eap_fast_text_pac_errors(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hostapd.add_ap(apdev[0], params)
 
-    tests = [ (1, "eap_fast_parse_hex;eap_fast_parse_pac_key"),
-              (1, "eap_fast_parse_hex;eap_fast_parse_pac_opaque"),
-              (1, "eap_fast_parse_hex;eap_fast_parse_a_id"),
-              (1, "eap_fast_parse_start"),
-              (1, "eap_fast_save_pac") ]
+    tests = [(1, "eap_fast_parse_hex;eap_fast_parse_pac_key"),
+             (1, "eap_fast_parse_hex;eap_fast_parse_pac_opaque"),
+             (1, "eap_fast_parse_hex;eap_fast_parse_a_id"),
+             (1, "eap_fast_parse_start"),
+             (1, "eap_fast_save_pac")]
     for count, func in tests:
         dev[0].request("FLUSH")
         if "OK" not in dev[0].request("SET blob fast_pac_text_errors "):
@@ -3371,7 +3641,7 @@ def test_ap_wpa2_eap_fast_text_pac_errors(dev, apdev):
     pac += "START\n"
     pac += "PAC-Type\n"
     pac += "END\n"
-    if "OK" not in dev[0].request("SET blob fast_pac_text_errors " + pac.encode("hex")):
+    if "OK" not in dev[0].request("SET blob fast_pac_text_errors " + binascii.hexlify(pac.encode()).decode()):
         raise Exception("Could not set blob")
 
     dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
@@ -3619,8 +3889,8 @@ def test_ap_wpa2_eap_fast_cipher_suites(dev, apdev):
     """EAP-FAST and different TLS cipher suites"""
     check_eap_capa(dev[0], "FAST")
     tls = dev[0].request("GET tls_library")
-    if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("TLS library is not OpenSSL: " + tls)
+    if not tls.startswith("OpenSSL") and not tls.startswith("wolfSSL"):
+        raise HwsimSkip("TLS library is not OpenSSL or wolfSSL: " + tls)
 
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
@@ -3637,11 +3907,11 @@ def test_ap_wpa2_eap_fast_cipher_suites(dev, apdev):
     if res != "DHE-RSA-AES256-SHA":
         raise Exception("Unexpected cipher suite for provisioning: " + res)
 
-    tests = [ "DHE-RSA-AES128-SHA",
-              "RC4-SHA",
-              "AES128-SHA",
-              "AES256-SHA",
-              "DHE-RSA-AES256-SHA" ]
+    tests = ["DHE-RSA-AES128-SHA",
+             "RC4-SHA",
+             "AES128-SHA",
+             "AES256-SHA",
+             "DHE-RSA-AES256-SHA"]
     for cipher in tests:
         dev[0].dump_monitor()
         logger.info("Testing " + cipher)
@@ -3650,10 +3920,12 @@ def test_ap_wpa2_eap_fast_cipher_suites(dev, apdev):
                         openssl_ciphers=cipher,
                         anonymous_identity="FAST", password="password",
                         ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
-                        pac_file="blob://fast_pac_ciphers")
-        except Exception, e:
-            if "Could not select EAP method" in str(e) and cipher == "RC4-SHA":
-                tls = dev[0].request("GET tls_library")
+                        pac_file="blob://fast_pac_ciphers",
+                        report_failure=True)
+        except Exception as e:
+            if cipher == "RC4-SHA" and \
+               ("Could not select EAP method" in str(e) or \
+                "EAP failed" in str(e)):
                 if "run=OpenSSL 1.1" in tls:
                     logger.info("Allow failure due to missing TLS library support")
                     dev[0].request("REMOVE_NETWORK all")
@@ -3813,18 +4085,19 @@ def test_ap_wpa2_eap_tls_ocsp_multi(dev, apdev):
                 private_key_passwd="whatever", ocsp=2)
 
 def int_eap_server_params():
-    params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
-               "rsn_pairwise": "CCMP", "ieee8021x": "1",
-               "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
-               "ca_cert": "auth_serv/ca.pem",
-               "server_cert": "auth_serv/server.pem",
-               "private_key": "auth_serv/server.key",
-               "dh_file": "auth_serv/dh.conf" }
+    params = {"ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP", "ieee8021x": "1",
+              "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
+              "ca_cert": "auth_serv/ca.pem",
+              "server_cert": "auth_serv/server.pem",
+              "private_key": "auth_serv/server.key",
+              "dh_file": "auth_serv/dh.conf"}
     return params
 
 def test_ap_wpa2_eap_tls_ocsp_key_id(dev, apdev, params):
     """EAP-TLS and OCSP certificate signed OCSP response using key ID"""
     check_ocsp_support(dev[0])
+    check_pkcs12_support(dev[0])
     ocsp = os.path.join(params['logdir'], "ocsp-server-cache-key-id.der")
     if not os.path.exists(ocsp):
         raise HwsimSkip("No OCSP response available")
@@ -3840,6 +4113,7 @@ def test_ap_wpa2_eap_tls_ocsp_key_id(dev, apdev, params):
 def test_ap_wpa2_eap_tls_ocsp_ca_signed_good(dev, apdev, params):
     """EAP-TLS and CA signed OCSP response (good)"""
     check_ocsp_support(dev[0])
+    check_pkcs12_support(dev[0])
     ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed.der")
     if not os.path.exists(ocsp):
         raise HwsimSkip("No OCSP response available")
@@ -3855,6 +4129,7 @@ def test_ap_wpa2_eap_tls_ocsp_ca_signed_good(dev, apdev, params):
 def test_ap_wpa2_eap_tls_ocsp_ca_signed_revoked(dev, apdev, params):
     """EAP-TLS and CA signed OCSP response (revoked)"""
     check_ocsp_support(dev[0])
+    check_pkcs12_support(dev[0])
     ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-revoked.der")
     if not os.path.exists(ocsp):
         raise HwsimSkip("No OCSP response available")
@@ -3886,6 +4161,7 @@ def test_ap_wpa2_eap_tls_ocsp_ca_signed_revoked(dev, apdev, params):
 def test_ap_wpa2_eap_tls_ocsp_ca_signed_unknown(dev, apdev, params):
     """EAP-TLS and CA signed OCSP response (unknown)"""
     check_ocsp_support(dev[0])
+    check_pkcs12_support(dev[0])
     ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-unknown.der")
     if not os.path.exists(ocsp):
         raise HwsimSkip("No OCSP response available")
@@ -3915,6 +4191,7 @@ def test_ap_wpa2_eap_tls_ocsp_ca_signed_unknown(dev, apdev, params):
 def test_ap_wpa2_eap_tls_ocsp_server_signed(dev, apdev, params):
     """EAP-TLS and server signed OCSP response"""
     check_ocsp_support(dev[0])
+    check_pkcs12_support(dev[0])
     ocsp = os.path.join(params['logdir'], "ocsp-resp-server-signed.der")
     if not os.path.exists(ocsp):
         raise HwsimSkip("No OCSP response available")
@@ -3944,6 +4221,7 @@ def test_ap_wpa2_eap_tls_ocsp_server_signed(dev, apdev, params):
 def test_ap_wpa2_eap_tls_ocsp_invalid_data(dev, apdev):
     """WPA2-Enterprise connection using EAP-TLS and invalid OCSP data"""
     check_ocsp_support(dev[0])
+    check_pkcs12_support(dev[0])
     params = int_eap_server_params()
     params["ocsp_stapling_response"] = "auth_serv/ocsp-req.der"
     hostapd.add_ap(apdev[0], params)
@@ -3970,6 +4248,7 @@ def test_ap_wpa2_eap_tls_ocsp_invalid_data(dev, apdev):
 def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev):
     """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response"""
     check_ocsp_support(dev[0])
+    check_pkcs12_support(dev[0])
     params = int_eap_server_params()
     params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid"
     hostapd.add_ap(apdev[0], params)
@@ -3996,6 +4275,7 @@ def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev):
 def test_ap_wpa2_eap_tls_ocsp_unknown_sign(dev, apdev):
     """WPA2-Enterprise connection using EAP-TLS and unknown OCSP signer"""
     check_ocsp_support(dev[0])
+    check_pkcs12_support(dev[0])
     params = int_eap_server_params()
     params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-unknown-sign"
     hostapd.add_ap(apdev[0], params)
@@ -4081,6 +4361,7 @@ def test_ap_wpa2_eap_ttls_ocsp_unknown(dev, apdev, params):
 
 def test_ap_wpa2_eap_ttls_optional_ocsp_unknown(dev, apdev, params):
     """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
+    check_ocsp_support(dev[0])
     ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
     if not os.path.exists(ocsp):
         raise HwsimSkip("No OCSP response available")
@@ -4099,10 +4380,17 @@ def test_ap_wpa2_eap_tls_intermediate_ca(dev, apdev, params):
     params["server_cert"] = "auth_serv/iCA-server/server.pem"
     params["private_key"] = "auth_serv/iCA-server/server.key"
     hostapd.add_ap(apdev[0], params)
+    tls = dev[0].request("GET tls_library")
+    if "GnuTLS" in tls or "wolfSSL" in tls:
+        ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+        client_cert = "auth_serv/iCA-user/user_and_ica.pem"
+    else:
+        ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+        client_cert = "auth_serv/iCA-user/user.pem"
     dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
                    identity="tls user",
-                   ca_cert="auth_serv/iCA-user/ca-and-root.pem",
-                   client_cert="auth_serv/iCA-user/user.pem",
+                   ca_cert=ca_cert,
+                   client_cert=client_cert,
                    private_key="auth_serv/iCA-user/user.key",
                    scan_freq="2412")
 
@@ -4112,12 +4400,12 @@ def root_ocsp(cert):
     fd2, fn2 = tempfile.mkstemp()
     os.close(fd2)
 
-    arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, "-sha256",
-            "-cert", cert, "-no_nonce", "-text" ]
+    arg = ["openssl", "ocsp", "-reqout", fn2, "-issuer", ca, "-sha256",
+           "-cert", cert, "-no_nonce", "-text"]
     logger.info(' '.join(arg))
     cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
-    res = cmd.stdout.read() + "\n" + cmd.stderr.read()
+    res = cmd.stdout.read().decode() + "\n" + cmd.stderr.read().decode()
     cmd.stdout.close()
     cmd.stderr.close()
     cmd.wait()
@@ -4127,14 +4415,14 @@ def root_ocsp(cert):
 
     fd, fn = tempfile.mkstemp()
     os.close(fd)
-    arg = [ "openssl", "ocsp", "-index", "auth_serv/rootCA/index.txt",
-            "-rsigner", ca, "-rkey", "auth_serv/ca-key.pem",
-            "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
-            "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
-            "-text" ]
+    arg = ["openssl", "ocsp", "-index", "auth_serv/rootCA/index.txt",
+           "-rsigner", ca, "-rkey", "auth_serv/ca-key.pem",
+           "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
+           "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
+           "-text"]
     cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
-    res = cmd.stdout.read() + "\n" + cmd.stderr.read()
+    res = cmd.stdout.read().decode() + "\n" + cmd.stderr.read().decode()
     cmd.stdout.close()
     cmd.stderr.close()
     cmd.wait()
@@ -4152,11 +4440,11 @@ def ica_ocsp(cert, md="-sha256"):
     fd2, fn2 = tempfile.mkstemp()
     os.close(fd2)
 
-    arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, md,
-            "-cert", cert, "-no_nonce", "-text" ]
+    arg = ["openssl", "ocsp", "-reqout", fn2, "-issuer", ca, md,
+           "-cert", cert, "-no_nonce", "-text"]
     cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
-    res = cmd.stdout.read() + "\n" + cmd.stderr.read()
+    res = cmd.stdout.read().decode() + "\n" + cmd.stderr.read().decode()
     cmd.stdout.close()
     cmd.stderr.close()
     cmd.wait()
@@ -4166,14 +4454,14 @@ def ica_ocsp(cert, md="-sha256"):
 
     fd, fn = tempfile.mkstemp()
     os.close(fd)
-    arg = [ "openssl", "ocsp", "-index", prefix + "index.txt",
-            "-rsigner", ca, "-rkey", prefix + "private/cakey.pem",
-            "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
-            "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
-            "-text" ]
+    arg = ["openssl", "ocsp", "-index", prefix + "index.txt",
+           "-rsigner", ca, "-rkey", prefix + "private/cakey.pem",
+           "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
+           "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
+           "-text"]
     cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
-    res = cmd.stdout.read() + "\n" + cmd.stderr.read()
+    res = cmd.stdout.read().decode() + "\n" + cmd.stderr.read().decode()
     cmd.stdout.close()
     cmd.stderr.close()
     cmd.wait()
@@ -4200,10 +4488,17 @@ def run_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params, md):
     params["ocsp_stapling_response"] = fn
     try:
         hostapd.add_ap(apdev[0], params)
+        tls = dev[0].request("GET tls_library")
+        if "GnuTLS" in tls or "wolfSSL" in tls:
+            ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+            client_cert = "auth_serv/iCA-user/user_and_ica.pem"
+        else:
+            ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+            client_cert = "auth_serv/iCA-user/user.pem"
         dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
                        identity="tls user",
-                       ca_cert="auth_serv/iCA-user/ca-and-root.pem",
-                       client_cert="auth_serv/iCA-user/user.pem",
+                       ca_cert=ca_cert,
+                       client_cert=client_cert,
                        private_key="auth_serv/iCA-user/user.key",
                        scan_freq="2412", ocsp=2)
     finally:
@@ -4220,6 +4515,7 @@ def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked_sha1(dev, apdev, params):
                                                      "-sha1")
 
 def run_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params, md):
+    check_ocsp_support(dev[0])
     params = int_eap_server_params()
     params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
     params["server_cert"] = "auth_serv/iCA-server/server-revoked.pem"
@@ -4228,10 +4524,17 @@ def run_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params, md):
     params["ocsp_stapling_response"] = fn
     try:
         hostapd.add_ap(apdev[0], params)
+        tls = dev[0].request("GET tls_library")
+        if "GnuTLS" in tls or "wolfSSL" in tls:
+            ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+            client_cert = "auth_serv/iCA-user/user_and_ica.pem"
+        else:
+            ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+            client_cert = "auth_serv/iCA-user/user.pem"
         dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
                        identity="tls user",
-                       ca_cert="auth_serv/iCA-user/ca-and-root.pem",
-                       client_cert="auth_serv/iCA-user/user.pem",
+                       ca_cert=ca_cert,
+                       client_cert=client_cert,
                        private_key="auth_serv/iCA-user/user.key",
                        scan_freq="2412", ocsp=1, wait_connect=False)
         count = 0
@@ -4271,10 +4574,17 @@ def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi_missing_resp(dev, apdev, par
     params["ocsp_stapling_response"] = fn
     try:
         hostapd.add_ap(apdev[0], params)
+        tls = dev[0].request("GET tls_library")
+        if "GnuTLS" in tls or "wolfSSL" in tls:
+            ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+            client_cert = "auth_serv/iCA-user/user_and_ica.pem"
+        else:
+            ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+            client_cert = "auth_serv/iCA-user/user.pem"
         dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
                        identity="tls user",
-                       ca_cert="auth_serv/iCA-user/ca-and-root.pem",
-                       client_cert="auth_serv/iCA-user/user.pem",
+                       ca_cert=ca_cert,
+                       client_cert=client_cert,
                        private_key="auth_serv/iCA-user/user.key",
                        scan_freq="2412", ocsp=3, wait_connect=False)
         count = 0
@@ -4314,14 +4624,14 @@ def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi(dev, apdev, params):
     fn2 = root_ocsp("auth_serv/iCA-server/cacert.pem")
     params["ocsp_stapling_response"] = fn
 
-    with open(fn, "r") as f:
+    with open(fn, "rb") as f:
         resp_server = f.read()
-    with open(fn2, "r") as f:
+    with open(fn2, "rb") as f:
         resp_ica = f.read()
 
     fd3, fn3 = tempfile.mkstemp()
     try:
-        f = os.fdopen(fd3, 'w')
+        f = os.fdopen(fd3, 'wb')
         f.write(struct.pack(">L", len(resp_server))[1:4])
         f.write(resp_server)
         f.write(struct.pack(">L", len(resp_ica))[1:4])
@@ -4331,10 +4641,17 @@ def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi(dev, apdev, params):
         params["ocsp_stapling_response_multi"] = fn3
 
         hostapd.add_ap(apdev[0], params)
+        tls = dev[0].request("GET tls_library")
+        if "GnuTLS" in tls or "wolfSSL" in tls:
+            ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+            client_cert = "auth_serv/iCA-user/user_and_ica.pem"
+        else:
+            ca_cert = "auth_serv/iCA-user/ca-and-root.pem"
+            client_cert = "auth_serv/iCA-user/user.pem"
         dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
                        identity="tls user",
-                       ca_cert="auth_serv/iCA-user/ca-and-root.pem",
-                       client_cert="auth_serv/iCA-user/user.pem",
+                       ca_cert=ca_cert,
+                       client_cert=client_cert,
                        private_key="auth_serv/iCA-user/user.key",
                        scan_freq="2412", ocsp=3)
         dev[0].request("REMOVE_NETWORK all")
@@ -4348,6 +4665,7 @@ def test_ap_wpa2_eap_tls_ocsp_multi_revoked(dev, apdev, params):
     """EAP-TLS and CA signed OCSP multi response (revoked)"""
     check_ocsp_support(dev[0])
     check_ocsp_multi_support(dev[0])
+    check_pkcs12_support(dev[0])
 
     ocsp_revoked = os.path.join(params['logdir'],
                                 "ocsp-resp-ca-signed-revoked.der")
@@ -4358,9 +4676,9 @@ def test_ap_wpa2_eap_tls_ocsp_multi_revoked(dev, apdev, params):
     if not os.path.exists(ocsp_unknown):
         raise HwsimSkip("No OCSP response(unknown) available")
 
-    with open(ocsp_revoked, "r") as f:
+    with open(ocsp_revoked, "rb") as f:
         resp_revoked = f.read()
-    with open(ocsp_unknown, "r") as f:
+    with open(ocsp_unknown, "rb") as f:
         resp_unknown = f.read()
 
     fd, fn = tempfile.mkstemp()
@@ -4368,7 +4686,7 @@ def test_ap_wpa2_eap_tls_ocsp_multi_revoked(dev, apdev, params):
         # This is not really a valid order of the OCSPResponse items in the
         # list, but this works for now to verify parsing and processing of
         # multiple responses.
-        f = os.fdopen(fd, 'w')
+        f = os.fdopen(fd, 'wb')
         f.write(struct.pack(">L", len(resp_unknown))[1:4])
         f.write(resp_unknown)
         f.write(struct.pack(">L", len(resp_revoked))[1:4])
@@ -4407,6 +4725,7 @@ def test_ap_wpa2_eap_tls_ocsp_multi_revoked(dev, apdev, params):
 def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev):
     """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
     check_domain_match_full(dev[0])
+    check_pkcs12_support(dev[0])
     params = int_eap_server_params()
     params["server_cert"] = "auth_serv/server-no-dnsname.pem"
     params["private_key"] = "auth_serv/server-no-dnsname.key"
@@ -4421,6 +4740,7 @@ def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev):
 def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev):
     """WPA2-Enterprise using EAP-TLS and domainmatch (CN)"""
     check_domain_match(dev[0])
+    check_pkcs12_support(dev[0])
     params = int_eap_server_params()
     params["server_cert"] = "auth_serv/server-no-dnsname.pem"
     params["private_key"] = "auth_serv/server-no-dnsname.key"
@@ -4435,6 +4755,7 @@ def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev):
 def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev):
     """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
     check_domain_match_full(dev[0])
+    check_pkcs12_support(dev[0])
     params = int_eap_server_params()
     params["server_cert"] = "auth_serv/server-no-dnsname.pem"
     params["private_key"] = "auth_serv/server-no-dnsname.key"
@@ -4449,6 +4770,7 @@ def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev):
 def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev):
     """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)"""
     check_domain_suffix_match(dev[0])
+    check_pkcs12_support(dev[0])
     params = int_eap_server_params()
     params["server_cert"] = "auth_serv/server-no-dnsname.pem"
     params["private_key"] = "auth_serv/server-no-dnsname.key"
@@ -4477,6 +4799,7 @@ def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev):
 def test_ap_wpa2_eap_tls_domain_mismatch_cn(dev, apdev):
     """WPA2-Enterprise using EAP-TLS and domain mismatch (CN)"""
     check_domain_match(dev[0])
+    check_pkcs12_support(dev[0])
     params = int_eap_server_params()
     params["server_cert"] = "auth_serv/server-no-dnsname.pem"
     params["private_key"] = "auth_serv/server-no-dnsname.key"
@@ -4657,7 +4980,7 @@ def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
     dh = read_pem("auth_serv/dh2.conf")
-    if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")):
+    if "OK" not in dev[0].request("SET blob dhparams " + binascii.hexlify(dh).decode()):
         raise Exception("Could not set dhparams blob")
     eap_connect(dev[0], hapd, "TTLS", "pap user",
                 anonymous_identity="ttls", password="password",
@@ -4779,8 +5102,8 @@ def test_ap_wpa2_eap_sim_zero_db_timeout(dev, apdev):
                        identity="1232010000000000",
                        password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
                        wait_connect=False, scan_freq="2412")
-        ev = dev[0].wait_event([ "CTRL-EVENT-CONNECTED",
-                                 "CTRL-EVENT-DISCONNECTED" ],
+        ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
+                                "CTRL-EVENT-DISCONNECTED"],
                                timeout=15)
         if ev is None:
             raise Exception("No connection result")
@@ -4961,22 +5284,40 @@ def test_openssl_cipher_suite_config_hapd(dev, apdev):
     params['openssl_ciphers'] = "FOO"
     hapd2 = hostapd.add_ap(apdev[1], params, no_enable=True)
     if "FAIL" not in hapd2.request("ENABLE"):
-        raise Exception("Invalid openssl_ciphers value accepted")
+        if "run=OpenSSL 1.1.1" in tls:
+            logger.info("Ignore acceptance of an invalid openssl_ciphers value with OpenSSL 1.1.1")
+        else:
+            raise Exception("Invalid openssl_ciphers value accepted")
 
 def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params):
     """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP"""
     p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], p)
     password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25"
-    pid = find_wpas_process(dev[0])
     id = eap_connect(dev[0], hapd, "TTLS", "pap-secret",
                      anonymous_identity="ttls", password=password,
                      ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
+    run_eap_key_lifetime_in_memory(dev, params, id, password)
+
+def test_wpa2_eap_peap_gtc_key_lifetime_in_memory(dev, apdev, params):
+    """Key lifetime in memory with WPA2-Enterprise using PEAP/GTC"""
+    p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], p)
+    password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25"
+    id = eap_connect(dev[0], hapd, "PEAP", "user-secret",
+                     anonymous_identity="peap", password=password,
+                     ca_cert="auth_serv/ca.pem", phase2="auth=GTC")
+    run_eap_key_lifetime_in_memory(dev, params, id, password)
+
+def run_eap_key_lifetime_in_memory(dev, params, id, password):
+    pid = find_wpas_process(dev[0])
+
     # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
     # event has been delivered, so verify that wpa_supplicant has returned to
     # eloop before reading process memory.
     time.sleep(1)
     dev[0].ping()
+    password = password.encode()
     buf = read_process_memory(pid, password)
 
     dev[0].request("DISCONNECT")
@@ -4990,10 +5331,12 @@ def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params):
     gtk = None
     with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
         for l in f.readlines():
-            if "EAP-TTLS: Derived key - hexdump" in l:
+            if "EAP-TTLS: Derived key - hexdump" in l or \
+               "EAP-PEAP: Derived key - hexdump" in l:
                 val = l.strip().split(':')[3].replace(' ', '')
                 msk = binascii.unhexlify(val)
-            if "EAP-TTLS: Derived EMSK - hexdump" in l:
+            if "EAP-TTLS: Derived EMSK - hexdump" in l or \
+               "EAP-PEAP: Derived EMSK - hexdump" in l:
                 val = l.strip().split(':')[3].replace(' ', '')
                 emsk = binascii.unhexlify(val)
             if "WPA: PMK - hexdump" in l:
@@ -5030,8 +5373,8 @@ def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params):
         raise Exception("KCK not found while associated")
     if kek not in buf:
         raise Exception("KEK not found while associated")
-    if tk in buf:
-        raise Exception("TK found from memory")
+    #if tk in buf:
+    #    raise Exception("TK found from memory")
 
     logger.info("Checking keys in memory after disassociation")
     buf = read_process_memory(pid, password)
@@ -5094,8 +5437,8 @@ def test_ap_wpa2_eap_unexpected_wep_eapol_key(dev, apdev):
 
 def test_ap_wpa2_eap_in_bridge(dev, apdev):
     """WPA2-EAP and wpas interface in a bridge"""
-    br_ifname='sta-br0'
-    ifname='wlan5'
+    br_ifname = 'sta-br0'
+    ifname = 'wlan5'
     try:
         _test_ap_wpa2_eap_in_bridge(dev, apdev)
     finally:
@@ -5108,8 +5451,8 @@ def _test_ap_wpa2_eap_in_bridge(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
 
-    br_ifname='sta-br0'
-    ifname='wlan5'
+    br_ifname = 'sta-br0'
+    ifname = 'wlan5'
     wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
     subprocess.call(['brctl', 'addbr', br_ifname])
     subprocess.call(['brctl', 'setfd', br_ifname, '0'])
@@ -5192,6 +5535,62 @@ def test_ap_wpa2_eap_tls_check_crl(dev, apdev):
                 private_key="auth_serv/user.key")
     dev[0].request("REMOVE_NETWORK all")
 
+def test_ap_wpa2_eap_tls_crl_reload(dev, apdev, params):
+    """EAP-TLS and server reloading CRL from ca_cert"""
+    ca_cert = os.path.join(params['logdir'],
+                           "ap_wpa2_eap_tls_crl_reload.ca_cert")
+    with open('auth_serv/ca.pem', 'r') as f:
+        only_cert = f.read()
+    with open('auth_serv/ca-and-crl.pem', 'r') as f:
+        cert_and_crl = f.read()
+    with open(ca_cert, 'w') as f:
+        f.write(only_cert)
+    params = int_eap_server_params()
+    params['ca_cert'] = ca_cert
+    params['check_crl'] = '1'
+    params['crl_reload_interval'] = '1'
+    hapd = hostapd.add_ap(apdev[0], params)
+
+    # check_crl=1 and no CRL available --> reject connection
+    eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
+                client_cert="auth_serv/user.pem",
+                private_key="auth_serv/user.key", expect_failure=True)
+    dev[0].request("REMOVE_NETWORK all")
+    dev[0].dump_monitor()
+
+    with open(ca_cert, 'w') as f:
+        f.write(cert_and_crl)
+    time.sleep(1)
+
+    # check_crl=1 and valid CRL --> accept
+    eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
+                client_cert="auth_serv/user.pem",
+                private_key="auth_serv/user.key")
+    dev[0].request("REMOVE_NETWORK all")
+    dev[0].wait_disconnected()
+
+def test_ap_wpa2_eap_tls_check_cert_subject(dev, apdev):
+    """EAP-TLS and server checking client subject name"""
+    params = int_eap_server_params()
+    params['check_cert_subject'] = 'C=FI/O=w1.fi/CN=Test User'
+    hapd = hostapd.add_ap(apdev[0], params)
+    check_check_cert_subject_support(hapd)
+
+    eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
+                client_cert="auth_serv/user.pem",
+                private_key="auth_serv/user.key")
+
+def test_ap_wpa2_eap_tls_check_cert_subject_neg(dev, apdev):
+    """EAP-TLS and server checking client subject name (negative)"""
+    params = int_eap_server_params()
+    params['check_cert_subject'] = 'C=FI/O=example'
+    hapd = hostapd.add_ap(apdev[0], params)
+    check_check_cert_subject_support(hapd)
+
+    eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
+                client_cert="auth_serv/user.pem",
+                private_key="auth_serv/user.key", expect_failure=True)
+
 def test_ap_wpa2_eap_tls_oom(dev, apdev):
     """EAP-TLS and OOM"""
     check_subject_match_support(dev[0])
@@ -5202,10 +5601,10 @@ def test_ap_wpa2_eap_tls_oom(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hostapd.add_ap(apdev[0], params)
 
-    tests = [ (1, "tls_connection_set_subject_match"),
-              (2, "tls_connection_set_subject_match"),
-              (3, "tls_connection_set_subject_match"),
-              (4, "tls_connection_set_subject_match") ]
+    tests = [(1, "tls_connection_set_subject_match"),
+             (2, "tls_connection_set_subject_match"),
+             (3, "tls_connection_set_subject_match"),
+             (4, "tls_connection_set_subject_match")]
     for count, func in tests:
         with alloc_fail(dev[0], count, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
@@ -5256,6 +5655,9 @@ def check_tls_ver(dev, hapd, phase1, expected):
     ver = dev.get_status_field("eap_tls_version")
     if ver != expected:
         raise Exception("Unexpected TLS version (expected %s): %s" % (expected, ver))
+    dev.request("REMOVE_NETWORK all")
+    dev.wait_disconnected()
+    dev.dump_monitor()
 
 def test_ap_wpa2_eap_tls_versions(dev, apdev):
     """EAP-TLS and TLS version configuration"""
@@ -5264,7 +5666,13 @@ def test_ap_wpa2_eap_tls_versions(dev, apdev):
 
     tls = dev[0].request("GET tls_library")
     if tls.startswith("OpenSSL"):
-        if "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
+        if "build=OpenSSL 1.0.1" not in tls and "run=OpenSSL 1.0.1" not in tls:
+            check_tls_ver(dev[0], hapd,
+                          "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1",
+                          "TLSv1.2")
+    if tls.startswith("wolfSSL"):
+        if ("build=3.10.0" in tls and "run=3.10.0" in tls) or \
+           ("build=3.13.0" in tls and "run=3.13.0" in tls):
             check_tls_ver(dev[0], hapd,
                           "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1",
                           "TLSv1.2")
@@ -5275,6 +5683,172 @@ def test_ap_wpa2_eap_tls_versions(dev, apdev):
                   "tls_disable_tlsv1_0=1 tls_disable_tlsv1_2=1", "TLSv1.1")
     check_tls_ver(dev[2], hapd,
                   "tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1", "TLSv1")
+    if "run=OpenSSL 1.1.1" in tls:
+        check_tls_ver(dev[0], hapd,
+                      "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1 tls_disable_tlsv1_3=0", "TLSv1.3")
+
+def test_ap_wpa2_eap_tls_versions_server(dev, apdev):
+    """EAP-TLS and TLS version configuration on server side"""
+    params = {"ssid": "test-wpa2-eap",
+              "wpa": "2",
+              "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP",
+              "ieee8021x": "1",
+              "eap_server": "1",
+              "eap_user_file": "auth_serv/eap_user.conf",
+              "ca_cert": "auth_serv/ca.pem",
+              "server_cert": "auth_serv/server.pem",
+              "private_key": "auth_serv/server.key"}
+    hapd = hostapd.add_ap(apdev[0], params)
+
+    tests = [("TLSv1", "[ENABLE-TLSv1.0][DISABLE-TLSv1.1][DISABLE-TLSv1.2][DISABLE-TLSv1.3]"),
+             ("TLSv1.1", "[ENABLE-TLSv1.0][ENABLE-TLSv1.1][DISABLE-TLSv1.2][DISABLE-TLSv1.3]"),
+             ("TLSv1.2", "[ENABLE-TLSv1.0][ENABLE-TLSv1.1][ENABLE-TLSv1.2][DISABLE-TLSv1.3]")]
+    for exp, flags in tests:
+        hapd.disable()
+        hapd.set("tls_flags", flags)
+        hapd.enable()
+        check_tls_ver(dev[0], hapd, "", exp)
+
+def test_ap_wpa2_eap_tls_13(dev, apdev):
+    """EAP-TLS and TLS 1.3"""
+    params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], params)
+
+    tls = dev[0].request("GET tls_library")
+    if "run=OpenSSL 1.1.1" not in tls:
+        raise HwsimSkip("TLS v1.3 not supported")
+    id = eap_connect(dev[0], hapd, "TLS", "tls user",
+                     ca_cert="auth_serv/ca.pem",
+                     client_cert="auth_serv/user.pem",
+                     private_key="auth_serv/user.key",
+                     phase1="tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1 tls_disable_tlsv1_3=0")
+    ver = dev[0].get_status_field("eap_tls_version")
+    if ver != "TLSv1.3":
+        raise Exception("Unexpected TLS version")
+
+    eap_reauth(dev[0], "TLS")
+    dev[0].request("DISCONNECT")
+    dev[0].wait_disconnected()
+    dev[0].request("PMKSA_FLUSH")
+    dev[0].request("RECONNECT")
+    dev[0].wait_connected()
+
+def test_ap_wpa2_eap_tls_13_ec(dev, apdev):
+    """EAP-TLS and TLS 1.3 (EC certificates)"""
+    params = {"ssid": "test-wpa2-eap",
+              "wpa": "2",
+              "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP",
+              "ieee8021x": "1",
+              "eap_server": "1",
+              "eap_user_file": "auth_serv/eap_user.conf",
+              "ca_cert": "auth_serv/ec-ca.pem",
+              "server_cert": "auth_serv/ec-server.pem",
+              "private_key": "auth_serv/ec-server.key",
+              "tls_flags": "[ENABLE-TLSv1.3]"}
+    hapd = hostapd.add_ap(apdev[0], params)
+    tls = hapd.request("GET tls_library")
+    if "run=OpenSSL 1.1.1" not in tls:
+        raise HwsimSkip("TLS v1.3 not supported")
+
+    tls = dev[0].request("GET tls_library")
+    if "run=OpenSSL 1.1.1" not in tls:
+        raise HwsimSkip("TLS v1.3 not supported")
+    id = eap_connect(dev[0], hapd, "TLS", "tls user",
+                     ca_cert="auth_serv/ec-ca.pem",
+                     client_cert="auth_serv/ec-user.pem",
+                     private_key="auth_serv/ec-user.key",
+                     phase1="tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1 tls_disable_tlsv1_3=0")
+    ver = dev[0].get_status_field("eap_tls_version")
+    if ver != "TLSv1.3":
+        raise Exception("Unexpected TLS version")
+
+def test_ap_wpa2_eap_tls_rsa_and_ec(dev, apdev, params):
+    """EAP-TLS and both RSA and EC sertificates certificates"""
+    ca = os.path.join(params['logdir'], "ap_wpa2_eap_tls_rsa_and_ec.ca.pem")
+    with open(ca, "w") as f:
+        with open("auth_serv/ca.pem", "r") as f2:
+            f.write(f2.read())
+        with open("auth_serv/ec-ca.pem", "r") as f2:
+            f.write(f2.read())
+    params = {"ssid": "test-wpa2-eap",
+              "wpa": "2",
+              "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP",
+              "ieee8021x": "1",
+              "eap_server": "1",
+              "eap_user_file": "auth_serv/eap_user.conf",
+              "ca_cert": ca,
+              "server_cert": "auth_serv/server.pem",
+              "private_key": "auth_serv/server.key",
+              "server_cert2": "auth_serv/ec-server.pem",
+              "private_key2": "auth_serv/ec-server.key"}
+    hapd = hostapd.add_ap(apdev[0], params)
+
+    eap_connect(dev[0], hapd, "TLS", "tls user",
+                ca_cert="auth_serv/ec-ca.pem",
+                client_cert="auth_serv/ec-user.pem",
+                private_key="auth_serv/ec-user.key")
+    dev[0].request("REMOVE_NETWORK all")
+    dev[0].wait_disconnected()
+
+    # TODO: Make wpa_supplicant automatically filter out cipher suites that
+    # would require ECDH/ECDSA keys when those are not configured in the
+    # selected client certificate. And for no-client-cert case, deprioritize
+    # those cipher suites based on configured ca_cert value so that the most
+    # likely to work cipher suites are selected by the server. Only do these
+    # when an explicit openssl_ciphers parameter is not set.
+    eap_connect(dev[1], hapd, "TLS", "tls user",
+                openssl_ciphers="DEFAULT:-aECDH:-aECDSA",
+                ca_cert="auth_serv/ca.pem",
+                client_cert="auth_serv/user.pem",
+                private_key="auth_serv/user.key")
+    dev[1].request("REMOVE_NETWORK all")
+    dev[1].wait_disconnected()
+
+def test_ap_wpa2_eap_tls_ec_and_rsa(dev, apdev, params):
+    """EAP-TLS and both EC and RSA sertificates certificates"""
+    ca = os.path.join(params['logdir'], "ap_wpa2_eap_tls_ec_and_rsa.ca.pem")
+    with open(ca, "w") as f:
+        with open("auth_serv/ca.pem", "r") as f2:
+            f.write(f2.read())
+        with open("auth_serv/ec-ca.pem", "r") as f2:
+            f.write(f2.read())
+    params = {"ssid": "test-wpa2-eap",
+              "wpa": "2",
+              "wpa_key_mgmt": "WPA-EAP",
+              "rsn_pairwise": "CCMP",
+              "ieee8021x": "1",
+              "eap_server": "1",
+              "eap_user_file": "auth_serv/eap_user.conf",
+              "ca_cert": ca,
+              "private_key2": "auth_serv/server-extra.pkcs12",
+              "private_key_passwd2": "whatever",
+              "server_cert": "auth_serv/ec-server.pem",
+              "private_key": "auth_serv/ec-server.key"}
+    hapd = hostapd.add_ap(apdev[0], params)
+
+    eap_connect(dev[0], hapd, "TLS", "tls user",
+                ca_cert="auth_serv/ec-ca.pem",
+                client_cert="auth_serv/ec-user.pem",
+                private_key="auth_serv/ec-user.key")
+    dev[0].request("REMOVE_NETWORK all")
+    dev[0].wait_disconnected()
+
+    # TODO: Make wpa_supplicant automatically filter out cipher suites that
+    # would require ECDH/ECDSA keys when those are not configured in the
+    # selected client certificate. And for no-client-cert case, deprioritize
+    # those cipher suites based on configured ca_cert value so that the most
+    # likely to work cipher suites are selected by the server. Only do these
+    # when an explicit openssl_ciphers parameter is not set.
+    eap_connect(dev[1], hapd, "TLS", "tls user",
+                openssl_ciphers="DEFAULT:-aECDH:-aECDSA",
+                ca_cert="auth_serv/ca.pem",
+                client_cert="auth_serv/user.pem",
+                private_key="auth_serv/user.key")
+    dev[1].request("REMOVE_NETWORK all")
+    dev[1].wait_disconnected()
 
 def test_rsn_ie_proto_eap_sta(dev, apdev):
     """RSN element protocol testing for EAP cases on STA side"""
@@ -5288,15 +5862,15 @@ def test_rsn_ie_proto_eap_sta(dev, apdev):
                         password="abcdefghijklmnop0123456789abcdef",
                         scan_freq="2412")
 
-    tests = [ ('No RSN Capabilities field',
-               '30120100000fac040100000fac040100000fac01'),
-              ('No AKM Suite fields',
-               '300c0100000fac040100000fac04'),
-              ('No Pairwise Cipher Suite fields',
-               '30060100000fac04'),
-              ('No Group Data Cipher Suite field',
-               '30020100') ]
-    for txt,ie in tests:
+    tests = [('No RSN Capabilities field',
+              '30120100000fac040100000fac040100000fac01'),
+             ('No AKM Suite fields',
+              '300c0100000fac040100000fac04'),
+             ('No Pairwise Cipher Suite fields',
+              '30060100000fac04'),
+             ('No Group Data Cipher Suite field',
+              '30020100')]
+    for txt, ie in tests:
         dev[0].request("DISCONNECT")
         dev[0].wait_disconnected()
         logger.info(txt)
@@ -5315,7 +5889,7 @@ def test_rsn_ie_proto_eap_sta(dev, apdev):
 def check_tls_session_resumption_capa(dev, hapd):
     tls = hapd.request("GET tls_library")
     if not tls.startswith("OpenSSL"):
-        raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
+        raise HwsimSkip("hostapd TLS library is not OpenSSL or wolfSSL: " + tls)
 
     tls = dev.request("GET tls_library")
     if not tls.startswith("OpenSSL"):
@@ -5343,6 +5917,7 @@ def test_eap_ttls_pap_session_resumption(dev, apdev):
         raise Exception("Key handshake with the AP timed out")
     if dev[0].get_status_field("tls_session_reused") != '1':
         raise Exception("Session resumption not used on the second connection")
+    hwsim_utils.test_connectivity(dev[0], hapd)
 
 def test_eap_ttls_chap_session_resumption(dev, apdev):
     """EAP-TTLS/CHAP session resumption"""
@@ -5461,6 +6036,7 @@ def test_eap_ttls_no_session_resumption(dev, apdev):
 
 def test_eap_peap_session_resumption(dev, apdev):
     """EAP-PEAP session resumption"""
+    check_eap_capa(dev[0], "MSCHAPV2")
     params = int_eap_server_params()
     params['tls_session_lifetime'] = '60'
     hapd = hostapd.add_ap(apdev[0], params)
@@ -5607,15 +6183,15 @@ def test_eap_tls_no_session_resumption(dev, apdev):
 
 def test_eap_tls_session_resumption_radius(dev, apdev):
     """EAP-TLS session resumption (RADIUS)"""
-    params = { "ssid": "as", "beacon_int": "2000",
-               "radius_server_clients": "auth_serv/radius_clients.conf",
-               "radius_server_auth_port": '18128',
-               "eap_server": "1",
-               "eap_user_file": "auth_serv/eap_user.conf",
-               "ca_cert": "auth_serv/ca.pem",
-               "server_cert": "auth_serv/server.pem",
-               "private_key": "auth_serv/server.key",
-               "tls_session_lifetime": "60" }
+    params = {"ssid": "as", "beacon_int": "2000",
+              "radius_server_clients": "auth_serv/radius_clients.conf",
+              "radius_server_auth_port": '18128',
+              "eap_server": "1",
+              "eap_user_file": "auth_serv/eap_user.conf",
+              "ca_cert": "auth_serv/ca.pem",
+              "server_cert": "auth_serv/server.pem",
+              "private_key": "auth_serv/server.key",
+              "tls_session_lifetime": "60"}
     authsrv = hostapd.add_ap(apdev[1], params)
     check_tls_session_resumption_capa(dev[0], authsrv)
 
@@ -5640,15 +6216,15 @@ def test_eap_tls_session_resumption_radius(dev, apdev):
 
 def test_eap_tls_no_session_resumption_radius(dev, apdev):
     """EAP-TLS session resumption disabled (RADIUS)"""
-    params = { "ssid": "as", "beacon_int": "2000",
-               "radius_server_clients": "auth_serv/radius_clients.conf",
-               "radius_server_auth_port": '18128',
-               "eap_server": "1",
-               "eap_user_file": "auth_serv/eap_user.conf",
-               "ca_cert": "auth_serv/ca.pem",
-               "server_cert": "auth_serv/server.pem",
-               "private_key": "auth_serv/server.key",
-               "tls_session_lifetime": "0" }
+    params = {"ssid": "as", "beacon_int": "2000",
+              "radius_server_clients": "auth_serv/radius_clients.conf",
+              "radius_server_auth_port": '18128',
+              "eap_server": "1",
+              "eap_user_file": "auth_serv/eap_user.conf",
+              "ca_cert": "auth_serv/ca.pem",
+              "server_cert": "auth_serv/server.pem",
+              "private_key": "auth_serv/server.key",
+              "tls_session_lifetime": "0"}
     hostapd.add_ap(apdev[1], params)
 
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
@@ -5683,14 +6259,14 @@ def test_eap_mschapv2_errors(dev, apdev):
     dev[0].request("REMOVE_NETWORK all")
     dev[0].wait_disconnected()
 
-    tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
-              (1, "nt_password_hash;mschapv2_derive_response"),
-              (1, "nt_password_hash;=mschapv2_derive_response"),
-              (1, "generate_nt_response;mschapv2_derive_response"),
-              (1, "generate_authenticator_response;mschapv2_derive_response"),
-              (1, "nt_password_hash;=mschapv2_derive_response"),
-              (1, "get_master_key;mschapv2_derive_response"),
-              (1, "os_get_random;eap_mschapv2_challenge_reply") ]
+    tests = [(1, "hash_nt_password_hash;mschapv2_derive_response"),
+             (1, "nt_password_hash;mschapv2_derive_response"),
+             (1, "nt_password_hash;=mschapv2_derive_response"),
+             (1, "generate_nt_response;mschapv2_derive_response"),
+             (1, "generate_authenticator_response;mschapv2_derive_response"),
+             (1, "nt_password_hash;=mschapv2_derive_response"),
+             (1, "get_master_key;mschapv2_derive_response"),
+             (1, "os_get_random;eap_mschapv2_challenge_reply")]
     for count, func in tests:
         with fail_test(dev[0], count, func):
             dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
@@ -5700,10 +6276,10 @@ def test_eap_mschapv2_errors(dev, apdev):
             dev[0].request("REMOVE_NETWORK all")
             dev[0].wait_disconnected()
 
-    tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
-              (1, "hash_nt_password_hash;=mschapv2_derive_response"),
-              (1, "generate_nt_response_pwhash;mschapv2_derive_response"),
-              (1, "generate_authenticator_response_pwhash;mschapv2_derive_response") ]
+    tests = [(1, "hash_nt_password_hash;mschapv2_derive_response"),
+             (1, "hash_nt_password_hash;=mschapv2_derive_response"),
+             (1, "generate_nt_response_pwhash;mschapv2_derive_response"),
+             (1, "generate_authenticator_response_pwhash;mschapv2_derive_response")]
     for count, func in tests:
         with fail_test(dev[0], count, func):
             dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
@@ -5714,10 +6290,10 @@ def test_eap_mschapv2_errors(dev, apdev):
             dev[0].request("REMOVE_NETWORK all")
             dev[0].wait_disconnected()
 
-    tests = [ (1, "eap_mschapv2_init"),
-              (1, "eap_msg_alloc;eap_mschapv2_challenge_reply"),
-              (1, "eap_msg_alloc;eap_mschapv2_success"),
-              (1, "eap_mschapv2_getKey") ]
+    tests = [(1, "eap_mschapv2_init"),
+             (1, "eap_msg_alloc;eap_mschapv2_challenge_reply"),
+             (1, "eap_msg_alloc;eap_mschapv2_success"),
+             (1, "eap_mschapv2_getKey")]
     for count, func in tests:
         with alloc_fail(dev[0], count, func):
             dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
@@ -5727,7 +6303,7 @@ def test_eap_mschapv2_errors(dev, apdev):
             dev[0].request("REMOVE_NETWORK all")
             dev[0].wait_disconnected()
 
-    tests = [ (1, "eap_msg_alloc;eap_mschapv2_failure") ]
+    tests = [(1, "eap_msg_alloc;eap_mschapv2_failure")]
     for count, func in tests:
         with alloc_fail(dev[0], count, func):
             dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
@@ -5737,8 +6313,8 @@ def test_eap_mschapv2_errors(dev, apdev):
             dev[0].request("REMOVE_NETWORK all")
             dev[0].wait_disconnected()
 
-    tests = [ (2, "eap_mschapv2_init"),
-              (3, "eap_mschapv2_init") ]
+    tests = [(2, "eap_mschapv2_init"),
+             (3, "eap_mschapv2_init")]
     for count, func in tests:
         with alloc_fail(dev[0], count, func):
             dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="FAST",
@@ -5763,20 +6339,21 @@ def test_eap_gpsk_errors(dev, apdev):
     dev[0].request("REMOVE_NETWORK all")
     dev[0].wait_disconnected()
 
-    tests = [ (1, "os_get_random;eap_gpsk_send_gpsk_2", None),
-              (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
-               "cipher=1"),
-              (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
-               "cipher=2"),
-              (1, "eap_gpsk_derive_keys_helper", None),
-              (2, "eap_gpsk_derive_keys_helper", None),
-              (1, "eap_gpsk_compute_mic_aes;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
-               "cipher=1"),
-              (1, "hmac_sha256;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
-               "cipher=2"),
-              (1, "eap_gpsk_compute_mic;eap_gpsk_validate_gpsk_3_mic", None),
-              (1, "eap_gpsk_compute_mic;eap_gpsk_send_gpsk_4", None),
-              (1, "eap_gpsk_derive_mid_helper", None) ]
+    tests = [(1, "os_get_random;eap_gpsk_send_gpsk_2", None),
+             (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
+              "cipher=1"),
+             (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
+              "cipher=2"),
+             (1, "eap_gpsk_derive_keys_helper", None),
+             (2, "eap_gpsk_derive_keys_helper", None),
+             (3, "eap_gpsk_derive_keys_helper", None),
+             (1, "eap_gpsk_compute_mic_aes;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
+              "cipher=1"),
+             (1, "hmac_sha256;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
+              "cipher=2"),
+             (1, "eap_gpsk_compute_mic;eap_gpsk_validate_gpsk_3_mic", None),
+             (1, "eap_gpsk_compute_mic;eap_gpsk_send_gpsk_4", None),
+             (1, "eap_gpsk_derive_mid_helper", None)]
     for count, func, phase1 in tests:
         with fail_test(dev[0], count, func):
             dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
@@ -5788,19 +6365,19 @@ def test_eap_gpsk_errors(dev, apdev):
             dev[0].request("REMOVE_NETWORK all")
             dev[0].wait_disconnected()
 
-    tests = [ (1, "eap_gpsk_init"),
-              (2, "eap_gpsk_init"),
-              (3, "eap_gpsk_init"),
-              (1, "eap_gpsk_process_id_server"),
-              (1, "eap_msg_alloc;eap_gpsk_send_gpsk_2"),
-              (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
-              (1, "eap_gpsk_derive_mid_helper;eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
-              (1, "eap_gpsk_derive_keys"),
-              (1, "eap_gpsk_derive_keys_helper"),
-              (1, "eap_msg_alloc;eap_gpsk_send_gpsk_4"),
-              (1, "eap_gpsk_getKey"),
-              (1, "eap_gpsk_get_emsk"),
-              (1, "eap_gpsk_get_session_id") ]
+    tests = [(1, "eap_gpsk_init"),
+             (2, "eap_gpsk_init"),
+             (3, "eap_gpsk_init"),
+             (1, "eap_gpsk_process_id_server"),
+             (1, "eap_msg_alloc;eap_gpsk_send_gpsk_2"),
+             (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
+             (1, "eap_gpsk_derive_mid_helper;eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
+             (1, "eap_gpsk_derive_keys"),
+             (1, "eap_gpsk_derive_keys_helper"),
+             (1, "eap_msg_alloc;eap_gpsk_send_gpsk_4"),
+             (1, "eap_gpsk_getKey"),
+             (1, "eap_gpsk_get_emsk"),
+             (1, "eap_gpsk_get_session_id")]
     for count, func in tests:
         with alloc_fail(dev[0], count, func):
             dev[0].request("ERP_FLUSH")
@@ -5828,6 +6405,11 @@ def test_ap_wpa2_eap_sim_db(dev, apdev, params):
                         eap="SIM", identity="1232010000000000",
                         password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
                         scan_freq="2412", wait_connect=False)
+    ev = dev[0].wait_event(["EAP-ERROR-CODE"], timeout=10)
+    if ev is None:
+        raise Exception("EAP method specific error code not reported")
+    if int(ev.split()[1]) != 16384:
+        raise Exception("Unexpected EAP method specific error code: " + ev)
     ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
     if ev is None:
         raise Exception("EAP-Failure not reported")
@@ -5838,15 +6420,15 @@ def test_ap_wpa2_eap_sim_db(dev, apdev, params):
 
     class test_handler(SocketServer.DatagramRequestHandler):
         def handle(self):
-            data = self.request[0].strip()
+            data = self.request[0].decode().strip()
             socket = self.request[1]
             logger.debug("Received hlr_auc_gw request: " + data)
             # EAP-SIM DB: Failed to parse response string
-            socket.sendto("FOO", self.client_address)
+            socket.sendto(b"FOO", self.client_address)
             # EAP-SIM DB: Failed to parse response string
-            socket.sendto("FOO 1", self.client_address)
+            socket.sendto(b"FOO 1", self.client_address)
             # EAP-SIM DB: Unknown external response
-            socket.sendto("FOO 1 2", self.client_address)
+            socket.sendto(b"FOO 1 2", self.client_address)
             logger.info("No proper response - wait for pending eap_sim_db request timeout")
 
     server = SocketServer.UnixDatagramServer(sockpath, test_handler)
@@ -5864,7 +6446,7 @@ def test_ap_wpa2_eap_sim_db(dev, apdev, params):
 
     class test_handler2(SocketServer.DatagramRequestHandler):
         def handle(self):
-            data = self.request[0].strip()
+            data = self.request[0].decode().strip()
             socket = self.request[1]
             logger.debug("Received hlr_auc_gw request: " + data)
             fname = os.path.join(params['logdir'],
@@ -5872,10 +6454,10 @@ def test_ap_wpa2_eap_sim_db(dev, apdev, params):
             cmd = subprocess.Popen(['../../hostapd/hlr_auc_gw',
                                     '-m', fname, data],
                                    stdout=subprocess.PIPE)
-            res = cmd.stdout.read().strip()
+            res = cmd.stdout.read().decode().strip()
             cmd.stdout.close()
             logger.debug("hlr_auc_gw response: " + res)
-            socket.sendto(res, self.client_address)
+            socket.sendto(res.encode(), self.client_address)
 
     server.RequestHandlerClass = test_handler2
 
@@ -5937,19 +6519,19 @@ def test_ap_wpa2_eap_assoc_rsn(dev, apdev):
     hostapd.add_ap(apdev[1], params)
 
     # Success cases with optional RSN IE fields removed one by one
-    tests = [ ("Normal wpa_supplicant assoc req RSN IE",
-               "30140100000fac040100000fac040100000fac010000"),
-              ("Extra PMKIDCount field in RSN IE",
-               "30160100000fac040100000fac040100000fac0100000000"),
-              ("Extra Group Management Cipher Suite in RSN IE",
-               "301a0100000fac040100000fac040100000fac0100000000000fac06"),
-              ("Extra undefined extension field in RSN IE",
-               "301c0100000fac040100000fac040100000fac0100000000000fac061122"),
-              ("RSN IE without RSN Capabilities",
-               "30120100000fac040100000fac040100000fac01"),
-              ("RSN IE without AKM", "300c0100000fac040100000fac04"),
-              ("RSN IE without pairwise", "30060100000fac04"),
-              ("RSN IE without group", "30020100") ]
+    tests = [("Normal wpa_supplicant assoc req RSN IE",
+              "30140100000fac040100000fac040100000fac010000"),
+             ("Extra PMKIDCount field in RSN IE",
+              "30160100000fac040100000fac040100000fac0100000000"),
+             ("Extra Group Management Cipher Suite in RSN IE",
+              "301a0100000fac040100000fac040100000fac0100000000000fac06"),
+             ("Extra undefined extension field in RSN IE",
+              "301c0100000fac040100000fac040100000fac0100000000000fac061122"),
+             ("RSN IE without RSN Capabilities",
+              "30120100000fac040100000fac040100000fac01"),
+             ("RSN IE without AKM", "300c0100000fac040100000fac04"),
+             ("RSN IE without pairwise", "30060100000fac04"),
+             ("RSN IE without group", "30020100")]
     for title, ie in tests:
         logger.info(title)
         set_test_assoc_ie(dev[0], ie)
@@ -5960,10 +6542,10 @@ def test_ap_wpa2_eap_assoc_rsn(dev, apdev):
         dev[0].request("REMOVE_NETWORK all")
         dev[0].wait_disconnected()
 
-    tests = [ ("Normal wpa_supplicant assoc req RSN IE",
-               "30140100000fac040100000fac040100000fac01cc00"),
-              ("Group management cipher included in assoc req RSN IE",
-               "301a0100000fac040100000fac040100000fac01cc000000000fac06") ]
+    tests = [("Normal wpa_supplicant assoc req RSN IE",
+              "30140100000fac040100000fac040100000fac01cc00"),
+             ("Group management cipher included in assoc req RSN IE",
+              "301a0100000fac040100000fac040100000fac01cc000000000fac06")]
     for title, ie in tests:
         logger.info(title)
         set_test_assoc_ie(dev[0], ie)
@@ -5974,8 +6556,8 @@ def test_ap_wpa2_eap_assoc_rsn(dev, apdev):
         dev[0].request("REMOVE_NETWORK all")
         dev[0].wait_disconnected()
 
-    tests = [ ("Invalid group cipher", "30060100000fac02", 41),
-              ("Invalid pairwise cipher", "300c0100000fac040100000fac02", 42) ]
+    tests = [("Invalid group cipher", "30060100000fac02", 41),
+             ("Invalid pairwise cipher", "300c0100000fac040100000fac02", 42)]
     for title, ie, status in tests:
         logger.info(title)
         set_test_assoc_ie(dev[0], ie)
@@ -5991,10 +6573,10 @@ def test_ap_wpa2_eap_assoc_rsn(dev, apdev):
         dev[0].request("REMOVE_NETWORK all")
         dev[0].dump_monitor()
 
-    tests = [ ("Management frame protection not enabled",
-               "30140100000fac040100000fac040100000fac010000", 31),
-              ("Unsupported management group cipher",
-               "301a0100000fac040100000fac040100000fac01cc000000000fac0b", 31) ]
+    tests = [("Management frame protection not enabled",
+              "30140100000fac040100000fac040100000fac010000", 31),
+             ("Unsupported management group cipher",
+              "301a0100000fac040100000fac040100000fac01cc000000000fac0b", 46)]
     for title, ie, status in tests:
         logger.info(title)
         set_test_assoc_ie(dev[0], ie)
@@ -6175,11 +6757,11 @@ def test_eap_tls_errors(dev, apdev):
         dev[0].request("REMOVE_NETWORK all")
         dev[0].wait_disconnected()
 
-    tests = [ "eap_peer_tls_derive_key;eap_tls_success",
-              "eap_peer_tls_derive_session_id;eap_tls_success",
-              "eap_tls_getKey",
-              "eap_tls_get_emsk",
-              "eap_tls_get_session_id" ]
+    tests = ["eap_peer_tls_derive_key;eap_tls_success",
+             "eap_peer_tls_derive_session_id;eap_tls_success",
+             "eap_tls_getKey",
+             "eap_tls_get_emsk",
+             "eap_tls_get_session_id"]
     for func in tests:
         with alloc_fail(dev[0], 1, func):
             dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
@@ -6244,7 +6826,12 @@ def test_ap_wpa2_eap_status(dev, apdev):
     decisions = []
     req_methods = []
     selected_methods = []
+    connected = False
     for i in range(100000):
+        if not connected and i % 10 == 9:
+            ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.0001)
+            if ev:
+                connected = True
         s = dev[0].get_status(extra="VERBOSE")
         if 'EAP state' in s:
             state = s['EAP state']
@@ -6278,7 +6865,8 @@ def test_ap_wpa2_eap_status(dev, apdev):
     logger.info("selectedMethods: " + str(selected_methods))
     if not success:
         raise Exception("EAP did not succeed")
-    dev[0].wait_connected()
+    if not connected:
+        dev[0].wait_connected()
     dev[0].request("REMOVE_NETWORK all")
     dev[0].wait_disconnected()
 
@@ -6292,6 +6880,7 @@ def test_ap_wpa2_eap_gpsk_ptk_rekey_ap(dev, apdev):
     ev = dev[0].wait_event(["WPA: Key negotiation completed"])
     if ev is None:
         raise Exception("PTK rekey timed out")
+    time.sleep(0.1)
     hwsim_utils.test_connectivity(dev[0], hapd)
 
 def test_ap_wpa2_eap_wildcard_ssid(dev, apdev):
@@ -6302,3 +6891,200 @@ def test_ap_wpa2_eap_wildcard_ssid(dev, apdev):
                    identity="gpsk user",
                    password="abcdefghijklmnop0123456789abcdef",
                    scan_freq="2412")
+
+def test_ap_wpa2_eap_psk_mac_addr_change(dev, apdev):
+    """WPA2-Enterprise connection using EAP-PSK after MAC address change"""
+    params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], params)
+
+    cmd = subprocess.Popen(['ps', '-eo', 'pid,command'], stdout=subprocess.PIPE)
+    res = cmd.stdout.read().decode()
+    cmd.stdout.close()
+    pid = 0
+    for p in res.splitlines():
+        if "wpa_supplicant" not in p:
+            continue
+        if dev[0].ifname not in p:
+            continue
+        pid = int(p.strip().split(' ')[0])
+    if pid == 0:
+        logger.info("Could not find wpa_supplicant PID")
+    else:
+        logger.info("wpa_supplicant PID %d" % pid)
+
+    addr = dev[0].get_status_field("address")
+    subprocess.call(['ip', 'link', 'set', 'dev', dev[0].ifname, 'down'])
+    subprocess.call(['ip', 'link', 'set', 'dev', dev[0].ifname, 'address',
+                     '02:11:22:33:44:55'])
+    subprocess.call(['ip', 'link', 'set', 'dev', dev[0].ifname, 'up'])
+    addr1 = dev[0].get_status_field("address")
+    if addr1 != '02:11:22:33:44:55':
+        raise Exception("Failed to change MAC address")
+
+    # Scan using the externally set MAC address, stop the wpa_supplicant
+    # process to avoid it from processing the ifdown event before the interface
+    # is already UP, change the MAC address back, allow the wpa_supplicant
+    # process to continue. This will result in the ifdown + ifup sequence of
+    # RTM_NEWLINK events to be processed while the interface is already UP.
+    try:
+        dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
+        os.kill(pid, signal.SIGSTOP)
+        time.sleep(0.1)
+    finally:
+        subprocess.call(['ip', 'link', 'set', 'dev', dev[0].ifname, 'down'])
+        subprocess.call(['ip', 'link', 'set', 'dev', dev[0].ifname, 'address',
+                         addr])
+        subprocess.call(['ip', 'link', 'set', 'dev', dev[0].ifname, 'up'])
+        time.sleep(0.1)
+        os.kill(pid, signal.SIGCONT)
+
+    eap_connect(dev[0], hapd, "PSK", "psk.user@example.com",
+                password_hex="0123456789abcdef0123456789abcdef")
+
+    addr2 = dev[0].get_status_field("address")
+    if addr != addr2:
+        raise Exception("Failed to restore MAC address")
+
+def test_ap_wpa2_eap_server_get_id(dev, apdev):
+    """Internal EAP server and dot1xAuthSessionUserName"""
+    params = int_eap_server_params()
+    hapd = hostapd.add_ap(apdev[0], params)
+    eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
+                client_cert="auth_serv/user.pem",
+                private_key="auth_serv/user.key")
+    sta = hapd.get_sta(dev[0].own_addr())
+    if 'dot1xAuthSessionUserName' not in sta:
+        raise Exception("No dot1xAuthSessionUserName included")
+    user = sta['dot1xAuthSessionUserName']
+    if user != "tls user":
+        raise Exception("Unexpected dot1xAuthSessionUserName value: " + user)
+
+def test_ap_wpa2_radius_server_get_id(dev, apdev):
+    """External RADIUS server and dot1xAuthSessionUserName"""
+    params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
+    hapd = hostapd.add_ap(apdev[0], params)
+    eap_connect(dev[0], hapd, "TTLS", "test-user",
+                anonymous_identity="ttls", password="password",
+                ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
+    sta = hapd.get_sta(dev[0].own_addr())
+    if 'dot1xAuthSessionUserName' not in sta:
+        raise Exception("No dot1xAuthSessionUserName included")
+    user = sta['dot1xAuthSessionUserName']
+    if user != "real-user":
+        raise Exception("Unexpected dot1xAuthSessionUserName value: " + user)
+
+def test_openssl_systemwide_policy(dev, apdev, test_params):
+    """OpenSSL systemwide policy and overrides"""
+    prefix = "openssl_systemwide_policy"
+    pidfile = os.path.join(test_params['logdir'], prefix + '.pid-wpas')
+    try:
+        with HWSimRadio() as (radio, iface):
+            run_openssl_systemwide_policy(iface, apdev, test_params)
+    finally:
+        if os.path.exists(pidfile):
+            with open(pidfile, 'r') as f:
+                pid = int(f.read().strip())
+                os.kill(pid, signal.SIGTERM)
+
+def write_openssl_cnf(cnf, MinProtocol=None, CipherString=None):
+    with open(cnf, "w") as f:
+        f.write("""openssl_conf = default_conf
+[default_conf]
+ssl_conf = ssl_sect
+[ssl_sect]
+system_default = system_default_sect
+[system_default_sect]
+""")
+        if MinProtocol:
+            f.write("MinProtocol = %s\n" % MinProtocol)
+        if CipherString:
+            f.write("CipherString = %s\n" % CipherString)
+
+def run_openssl_systemwide_policy(iface, apdev, test_params):
+    prefix = "openssl_systemwide_policy"
+    logfile = os.path.join(test_params['logdir'], prefix + '.log-wpas')
+    pidfile = os.path.join(test_params['logdir'], prefix + '.pid-wpas')
+    conffile = os.path.join(test_params['logdir'], prefix + '.conf')
+    openssl_cnf = os.path.join(test_params['logdir'], prefix + '.openssl.cnf')
+
+    write_openssl_cnf(openssl_cnf, "TLSv1.2", "DEFAULT@SECLEVEL=2")
+
+    with open(conffile, 'w') as f:
+        f.write("ctrl_interface=DIR=/var/run/wpa_supplicant\n")
+
+    params = int_eap_server_params()
+    params['tls_flags'] = "[DISABLE-TLSv1.1][DISABLE-TLSv1.2][DISABLE-TLSv1.3]"
+
+    hapd = hostapd.add_ap(apdev[0], params)
+
+    prg = os.path.join(test_params['logdir'],
+                       'alt-wpa_supplicant/wpa_supplicant/wpa_supplicant')
+    if not os.path.exists(prg):
+        prg = '../../wpa_supplicant/wpa_supplicant'
+    arg = [prg, '-BddtK', '-P', pidfile, '-f', logfile,
+           '-Dnl80211', '-c', conffile, '-i', iface]
+    logger.info("Start wpa_supplicant: " + str(arg))
+    subprocess.call(arg, env={'OPENSSL_CONF': openssl_cnf})
+    wpas = WpaSupplicant(ifname=iface)
+    if "PONG" not in wpas.request("PING"):
+        raise Exception("Could not PING wpa_supplicant")
+    tls = wpas.request("GET tls_library")
+    if not tls.startswith("OpenSSL"):
+        raise HwsimSkip("Not using OpenSSL")
+
+    # Use default configuration without any TLS version overrides. This should
+    # end up using OpenSSL systemwide policy and result in failure to find a
+    # compatible protocol version.
+    ca_file = os.path.join(os.getcwd(), "auth_serv/ca.pem")
+    id = wpas.connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
+                      identity="pap user", anonymous_identity="ttls",
+                      password="password", phase2="auth=PAP",
+                      ca_cert=ca_file,
+                      scan_freq="2412", wait_connect=False)
+    ev = wpas.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
+    if ev is None:
+        raise Exception("EAP not started")
+    ev = wpas.wait_event(["CTRL-EVENT-EAP-STATUS status='local TLS alert'"],
+                         timeout=1)
+    if ev is None:
+        raise HwsimSkip("OpenSSL systemwide policy not supported")
+    wpas.request("DISCONNECT")
+    wpas.wait_disconnected()
+    wpas.dump_monitor()
+
+    # Explicitly allow TLSv1.0 to be used to override OpenSSL systemwide policy
+    wpas.set_network_quoted(id, "openssl_ciphers", "DEFAULT@SECLEVEL=1")
+    wpas.set_network_quoted(id, "phase1", "tls_disable_tlsv1_0=0")
+    wpas.select_network(id, freq="2412")
+    wpas.wait_connected()
+
+    wpas.request("TERMINATE")
+
+def test_ap_wpa2_eap_tls_tod(dev, apdev):
+    """EAP-TLS server certificate validation and TOD"""
+    params = int_eap_server_params()
+    params["server_cert"] = "auth_serv/server-certpol.pem"
+    params["private_key"] = "auth_serv/server-certpol.key"
+    hapd = hostapd.add_ap(apdev[0], params)
+
+    dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
+                   eap="TLS", identity="tls user",
+                   wait_connect=False, scan_freq="2412",
+                   ca_cert="auth_serv/ca.pem",
+                   client_cert="auth_serv/user.pem",
+                   private_key="auth_serv/user.key")
+    tod0 = None
+    tod1 = None
+    while tod0 is None or tod1 is None:
+        ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT"], timeout=10)
+        if ev is None:
+            raise Exception("Peer certificate not reported")
+        if "depth=1 " in ev and "hash=" in ev:
+            tod1 = " tod=1" in ev
+        if "depth=0 " in ev and "hash=" in ev:
+            tod0 = " tod=1" in ev
+    dev[0].wait_connected()
+    if not tod0:
+        raise Exception("TOD policy not reported for server certificate")
+    if tod1:
+        raise Exception("TOD policy unexpectedly reported for CA certificate")