]>
Commit | Line | Data |
---|---|---|
eac67440 | 1 | # -*- coding: utf-8 -*- |
9626962d | 2 | # WPA2-Enterprise tests |
3b51cc63 | 3 | # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi> |
9626962d JM |
4 | # |
5 | # This software may be distributed under the terms of the BSD license. | |
6 | # See README for more details. | |
7 | ||
6ea231e6 | 8 | import base64 |
5b3c40a6 | 9 | import binascii |
9626962d JM |
10 | import time |
11 | import subprocess | |
12 | import logging | |
c9aa4308 | 13 | logger = logging.getLogger() |
873e7c29 | 14 | import os |
d4c3c055 JM |
15 | import socket |
16 | import SocketServer | |
98d125ca JM |
17 | import struct |
18 | import tempfile | |
9626962d JM |
19 | |
20 | import hwsim_utils | |
21 | import hostapd | |
7c0d66cf | 22 | from utils import HwsimSkip, alloc_fail, fail_test, skip_with_fips, wait_fail_trigger |
52352802 | 23 | from wpasupplicant import WpaSupplicant |
0ceff76e | 24 | from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations, set_test_assoc_ie |
9626962d | 25 | |
ca27ee09 JM |
26 | try: |
27 | import OpenSSL | |
28 | openssl_imported = True | |
29 | except ImportError: | |
30 | openssl_imported = False | |
31 | ||
81e787b7 JM |
32 | def check_hlr_auc_gw_support(): |
33 | if not os.path.exists("/tmp/hlr_auc_gw.sock"): | |
34 | raise HwsimSkip("No hlr_auc_gw available") | |
35 | ||
3b51cc63 JM |
36 | def check_eap_capa(dev, method): |
37 | res = dev.get_capability("eap") | |
38 | if method not in res: | |
39 | raise HwsimSkip("EAP method %s not supported in the build" % method) | |
40 | ||
506b2f05 JM |
41 | def check_subject_match_support(dev): |
42 | tls = dev.request("GET tls_library") | |
43 | if not tls.startswith("OpenSSL"): | |
44 | raise HwsimSkip("subject_match not supported with this TLS library: " + tls) | |
45 | ||
46 | def check_altsubject_match_support(dev): | |
47 | tls = dev.request("GET tls_library") | |
48 | if not tls.startswith("OpenSSL"): | |
49 | raise HwsimSkip("altsubject_match not supported with this TLS library: " + tls) | |
50 | ||
e78eb404 JM |
51 | def check_domain_match(dev): |
52 | tls = dev.request("GET tls_library") | |
53 | if tls.startswith("internal"): | |
54 | raise HwsimSkip("domain_match not supported with this TLS library: " + tls) | |
55 | ||
56 | def check_domain_suffix_match(dev): | |
57 | tls = dev.request("GET tls_library") | |
58 | if tls.startswith("internal"): | |
59 | raise HwsimSkip("domain_suffix_match not supported with this TLS library: " + tls) | |
60 | ||
24579e70 JM |
61 | def check_domain_match_full(dev): |
62 | tls = dev.request("GET tls_library") | |
63 | if not tls.startswith("OpenSSL"): | |
64 | raise HwsimSkip("domain_suffix_match requires full match with this TLS library: " + tls) | |
65 | ||
4bf4e9db JM |
66 | def check_cert_probe_support(dev): |
67 | tls = dev.request("GET tls_library") | |
0fc1b583 | 68 | if not tls.startswith("OpenSSL") and not tls.startswith("internal"): |
4bf4e9db JM |
69 | raise HwsimSkip("Certificate probing not supported with this TLS library: " + tls) |
70 | ||
ca27ee09 JM |
71 | def check_ext_cert_check_support(dev): |
72 | tls = dev.request("GET tls_library") | |
73 | if not tls.startswith("OpenSSL"): | |
74 | raise HwsimSkip("ext_cert_check not supported with this TLS library: " + tls) | |
75 | ||
0dae8c99 JM |
76 | def check_ocsp_support(dev): |
77 | tls = dev.request("GET tls_library") | |
138903f9 JM |
78 | #if tls.startswith("internal"): |
79 | # raise HwsimSkip("OCSP not supported with this TLS library: " + tls) | |
0c6185fc JM |
80 | #if "BoringSSL" in tls: |
81 | # raise HwsimSkip("OCSP not supported with this TLS library: " + tls) | |
0dae8c99 | 82 | |
969e5250 JM |
83 | def check_pkcs5_v15_support(dev): |
84 | tls = dev.request("GET tls_library") | |
85 | if "BoringSSL" in tls: | |
86 | raise HwsimSkip("PKCS#5 v1.5 not supported with this TLS library: " + tls) | |
87 | ||
98d125ca JM |
88 | def check_ocsp_multi_support(dev): |
89 | tls = dev.request("GET tls_library") | |
90 | if not tls.startswith("internal"): | |
91 | raise HwsimSkip("OCSP-multi not supported with this TLS library: " + tls) | |
92 | as_hapd = hostapd.Hostapd("as") | |
93 | res = as_hapd.request("GET tls_library") | |
94 | del as_hapd | |
95 | if not res.startswith("internal"): | |
96 | raise HwsimSkip("Authentication server does not support ocsp_multi") | |
97 | ||
686eee77 JM |
98 | def check_pkcs12_support(dev): |
99 | tls = dev.request("GET tls_library") | |
16c43d2a JM |
100 | #if tls.startswith("internal"): |
101 | # raise HwsimSkip("PKCS#12 not supported with this TLS library: " + tls) | |
686eee77 | 102 | |
404597e6 JM |
103 | def check_dh_dsa_support(dev): |
104 | tls = dev.request("GET tls_library") | |
105 | if tls.startswith("internal"): | |
106 | raise HwsimSkip("DH DSA not supported with this TLS library: " + tls) | |
107 | ||
6ea231e6 JM |
108 | def read_pem(fname): |
109 | with open(fname, "r") as f: | |
110 | lines = f.readlines() | |
111 | copy = False | |
112 | cert = "" | |
113 | for l in lines: | |
114 | if "-----END" in l: | |
115 | break | |
116 | if copy: | |
117 | cert = cert + l | |
118 | if "-----BEGIN" in l: | |
119 | copy = True | |
120 | return base64.b64decode(cert) | |
121 | ||
3b3e2687 | 122 | def eap_connect(dev, hapd, method, identity, |
6f939e59 | 123 | sha256=False, expect_failure=False, local_error_report=False, |
9dd21d51 | 124 | maybe_local_error=False, **kwargs): |
2bb9e283 JM |
125 | id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", |
126 | eap=method, identity=identity, | |
6f939e59 JM |
127 | wait_connect=False, scan_freq="2412", ieee80211w="1", |
128 | **kwargs) | |
f10ba3b2 JM |
129 | eap_check_auth(dev, method, True, sha256=sha256, |
130 | expect_failure=expect_failure, | |
9dd21d51 JM |
131 | local_error_report=local_error_report, |
132 | maybe_local_error=maybe_local_error) | |
f10ba3b2 JM |
133 | if expect_failure: |
134 | return id | |
cb33ee14 JM |
135 | ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) |
136 | if ev is None: | |
137 | raise Exception("No connection event received from hostapd") | |
2bb9e283 | 138 | return id |
75b2b9cf | 139 | |
f10ba3b2 | 140 | def eap_check_auth(dev, method, initial, rsn=True, sha256=False, |
9dd21d51 JM |
141 | expect_failure=False, local_error_report=False, |
142 | maybe_local_error=False): | |
412c6030 | 143 | ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
9626962d JM |
144 | if ev is None: |
145 | raise Exception("Association and EAP start timed out") | |
06cdd1cd JM |
146 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD", |
147 | "CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
9626962d JM |
148 | if ev is None: |
149 | raise Exception("EAP method selection timed out") | |
06cdd1cd JM |
150 | if "CTRL-EVENT-EAP-FAILURE" in ev: |
151 | if maybe_local_error: | |
152 | return | |
153 | raise Exception("Could not select EAP method") | |
9626962d JM |
154 | if method not in ev: |
155 | raise Exception("Unexpected EAP method") | |
f10ba3b2 JM |
156 | if expect_failure: |
157 | ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
158 | if ev is None: | |
159 | raise Exception("EAP failure timed out") | |
5f35a5e2 | 160 | ev = dev.wait_disconnected(timeout=10) |
9dd21d51 JM |
161 | if maybe_local_error and "locally_generated=1" in ev: |
162 | return | |
f10ba3b2 JM |
163 | if not local_error_report: |
164 | if "reason=23" not in ev: | |
165 | raise Exception("Proper reason code for disconnection not reported") | |
166 | return | |
9626962d JM |
167 | ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) |
168 | if ev is None: | |
169 | raise Exception("EAP success timed out") | |
9626962d | 170 | |
75b2b9cf JM |
171 | if initial: |
172 | ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
75b2b9cf | 173 | else: |
bce774ad JM |
174 | ev = dev.wait_event(["WPA: Key negotiation completed"], timeout=10) |
175 | if ev is None: | |
176 | raise Exception("Association with the AP timed out") | |
177 | status = dev.get_status() | |
178 | if status["wpa_state"] != "COMPLETED": | |
179 | raise Exception("Connection not completed") | |
75b2b9cf | 180 | |
9626962d JM |
181 | if status["suppPortStatus"] != "Authorized": |
182 | raise Exception("Port not authorized") | |
447fb0b0 JM |
183 | if "selectedMethod" not in status: |
184 | logger.info("Status: " + str(status)) | |
185 | raise Exception("No selectedMethod in status") | |
9626962d JM |
186 | if method not in status["selectedMethod"]: |
187 | raise Exception("Incorrect EAP method status") | |
2b005194 JM |
188 | if sha256: |
189 | e = "WPA2-EAP-SHA256" | |
190 | elif rsn: | |
71390dc8 JM |
191 | e = "WPA2/IEEE 802.1X/EAP" |
192 | else: | |
193 | e = "WPA/IEEE 802.1X/EAP" | |
194 | if status["key_mgmt"] != e: | |
195 | raise Exception("Unexpected key_mgmt status: " + status["key_mgmt"]) | |
2fc4749c | 196 | return status |
9626962d | 197 | |
5b1aaf6c | 198 | def eap_reauth(dev, method, rsn=True, sha256=False, expect_failure=False): |
75b2b9cf | 199 | dev.request("REAUTHENTICATE") |
2fc4749c JM |
200 | return eap_check_auth(dev, method, False, rsn=rsn, sha256=sha256, |
201 | expect_failure=expect_failure) | |
75b2b9cf | 202 | |
9626962d JM |
203 | def test_ap_wpa2_eap_sim(dev, apdev): |
204 | """WPA2-Enterprise connection using EAP-SIM""" | |
81e787b7 | 205 | check_hlr_auc_gw_support() |
9626962d | 206 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 207 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 208 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
9626962d | 209 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") |
a8375c94 | 210 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 211 | eap_reauth(dev[0], "SIM") |
9626962d | 212 | |
3b3e2687 | 213 | eap_connect(dev[1], hapd, "SIM", "1232010000000001", |
a0f350fd | 214 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") |
3b3e2687 | 215 | eap_connect(dev[2], hapd, "SIM", "1232010000000002", |
a0f350fd JM |
216 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", |
217 | expect_failure=True) | |
218 | ||
f10ba3b2 JM |
219 | logger.info("Negative test with incorrect key") |
220 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 221 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
f10ba3b2 JM |
222 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", |
223 | expect_failure=True) | |
224 | ||
32747a3e JM |
225 | logger.info("Invalid GSM-Milenage key") |
226 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 227 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
32747a3e JM |
228 | password="ffdca4eda45b53cf0f12d7c9c3bc6a", |
229 | expect_failure=True) | |
230 | ||
231 | logger.info("Invalid GSM-Milenage key(2)") | |
232 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 233 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
32747a3e JM |
234 | password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581", |
235 | expect_failure=True) | |
236 | ||
237 | logger.info("Invalid GSM-Milenage key(3)") | |
238 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 239 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
32747a3e JM |
240 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q", |
241 | expect_failure=True) | |
242 | ||
243 | logger.info("Invalid GSM-Milenage key(4)") | |
244 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 245 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
32747a3e JM |
246 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581", |
247 | expect_failure=True) | |
248 | ||
249 | logger.info("Missing key configuration") | |
250 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 251 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
32747a3e JM |
252 | expect_failure=True) |
253 | ||
5b1aaf6c JM |
254 | def test_ap_wpa2_eap_sim_sql(dev, apdev, params): |
255 | """WPA2-Enterprise connection using EAP-SIM (SQL)""" | |
81e787b7 | 256 | check_hlr_auc_gw_support() |
5b1aaf6c JM |
257 | try: |
258 | import sqlite3 | |
259 | except ImportError: | |
81e787b7 | 260 | raise HwsimSkip("No sqlite3 module available") |
5b1aaf6c JM |
261 | con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) |
262 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
263 | params['auth_server_port'] = "1814" | |
3b3e2687 JD |
264 | hapd = hostapd.add_ap(apdev[0], params) |
265 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", | |
5b1aaf6c JM |
266 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") |
267 | ||
268 | logger.info("SIM fast re-authentication") | |
269 | eap_reauth(dev[0], "SIM") | |
270 | ||
271 | logger.info("SIM full auth with pseudonym") | |
272 | with con: | |
273 | cur = con.cursor() | |
274 | cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'") | |
275 | eap_reauth(dev[0], "SIM") | |
276 | ||
277 | logger.info("SIM full auth with permanent identity") | |
278 | with con: | |
279 | cur = con.cursor() | |
280 | cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'") | |
281 | cur.execute("DELETE FROM pseudonyms WHERE permanent='1232010000000000'") | |
282 | eap_reauth(dev[0], "SIM") | |
283 | ||
284 | logger.info("SIM reauth with mismatching MK") | |
285 | with con: | |
286 | cur = con.cursor() | |
287 | cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='1232010000000000'") | |
288 | eap_reauth(dev[0], "SIM", expect_failure=True) | |
289 | dev[0].request("REMOVE_NETWORK all") | |
290 | ||
3b3e2687 | 291 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
5b1aaf6c JM |
292 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") |
293 | with con: | |
294 | cur = con.cursor() | |
295 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'") | |
296 | eap_reauth(dev[0], "SIM") | |
297 | with con: | |
298 | cur = con.cursor() | |
299 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'") | |
300 | logger.info("SIM reauth with mismatching counter") | |
301 | eap_reauth(dev[0], "SIM") | |
302 | dev[0].request("REMOVE_NETWORK all") | |
303 | ||
3b3e2687 | 304 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
5b1aaf6c JM |
305 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") |
306 | with con: | |
307 | cur = con.cursor() | |
308 | cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='1232010000000000'") | |
309 | logger.info("SIM reauth with max reauth count reached") | |
310 | eap_reauth(dev[0], "SIM") | |
311 | ||
e2a90a4c JM |
312 | def test_ap_wpa2_eap_sim_config(dev, apdev): |
313 | """EAP-SIM configuration options""" | |
314 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 | 315 | hapd = hostapd.add_ap(apdev[0], params) |
e2a90a4c JM |
316 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM", |
317 | identity="1232010000000000", | |
318 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
319 | phase1="sim_min_num_chal=1", | |
320 | wait_connect=False, scan_freq="2412") | |
321 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10) | |
322 | if ev is None: | |
323 | raise Exception("No EAP error message seen") | |
324 | dev[0].request("REMOVE_NETWORK all") | |
325 | ||
326 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM", | |
327 | identity="1232010000000000", | |
328 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
329 | phase1="sim_min_num_chal=4", | |
330 | wait_connect=False, scan_freq="2412") | |
331 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10) | |
332 | if ev is None: | |
333 | raise Exception("No EAP error message seen (2)") | |
334 | dev[0].request("REMOVE_NETWORK all") | |
335 | ||
3b3e2687 | 336 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
e2a90a4c JM |
337 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", |
338 | phase1="sim_min_num_chal=2") | |
3b3e2687 | 339 | eap_connect(dev[1], hapd, "SIM", "1232010000000000", |
e2a90a4c JM |
340 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", |
341 | anonymous_identity="345678") | |
342 | ||
72cbc684 JM |
343 | def test_ap_wpa2_eap_sim_ext(dev, apdev): |
344 | """WPA2-Enterprise connection using EAP-SIM and external GSM auth""" | |
47dcb118 | 345 | try: |
81e787b7 | 346 | _test_ap_wpa2_eap_sim_ext(dev, apdev) |
47dcb118 JM |
347 | finally: |
348 | dev[0].request("SET external_sim 0") | |
349 | ||
350 | def _test_ap_wpa2_eap_sim_ext(dev, apdev): | |
81e787b7 | 351 | check_hlr_auc_gw_support() |
72cbc684 | 352 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 353 | hostapd.add_ap(apdev[0], params) |
72cbc684 JM |
354 | dev[0].request("SET external_sim 1") |
355 | id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP", | |
356 | identity="1232010000000000", | |
357 | wait_connect=False, scan_freq="2412") | |
358 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) | |
359 | if ev is None: | |
360 | raise Exception("Network connected timed out") | |
361 | ||
362 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
363 | if ev is None: | |
364 | raise Exception("Wait for external SIM processing request timed out") | |
365 | p = ev.split(':', 2) | |
366 | if p[1] != "GSM-AUTH": | |
367 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
368 | rid = p[0].split('-')[3] | |
369 | ||
370 | # IK:CK:RES | |
371 | resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344" | |
372 | # This will fail during processing, but the ctrl_iface command succeeds | |
373 | dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:" + resp) | |
374 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
375 | if ev is None: | |
376 | raise Exception("EAP failure not reported") | |
377 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
378 | dev[0].wait_disconnected() |
379 | time.sleep(0.1) | |
72cbc684 JM |
380 | |
381 | dev[0].select_network(id, freq="2412") | |
382 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
383 | if ev is None: | |
384 | raise Exception("Wait for external SIM processing request timed out") | |
385 | p = ev.split(':', 2) | |
386 | if p[1] != "GSM-AUTH": | |
387 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
388 | rid = p[0].split('-')[3] | |
389 | # This will fail during GSM auth validation | |
390 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:q"): | |
391 | raise Exception("CTRL-RSP-SIM failed") | |
392 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
393 | if ev is None: | |
394 | raise Exception("EAP failure not reported") | |
395 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
396 | dev[0].wait_disconnected() |
397 | time.sleep(0.1) | |
72cbc684 JM |
398 | |
399 | dev[0].select_network(id, freq="2412") | |
400 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
401 | if ev is None: | |
402 | raise Exception("Wait for external SIM processing request timed out") | |
403 | p = ev.split(':', 2) | |
404 | if p[1] != "GSM-AUTH": | |
405 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
406 | rid = p[0].split('-')[3] | |
407 | # This will fail during GSM auth validation | |
408 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:34"): | |
409 | raise Exception("CTRL-RSP-SIM failed") | |
410 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
411 | if ev is None: | |
412 | raise Exception("EAP failure not reported") | |
413 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
414 | dev[0].wait_disconnected() |
415 | time.sleep(0.1) | |
72cbc684 JM |
416 | |
417 | dev[0].select_network(id, freq="2412") | |
418 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
419 | if ev is None: | |
420 | raise Exception("Wait for external SIM processing request timed out") | |
421 | p = ev.split(':', 2) | |
422 | if p[1] != "GSM-AUTH": | |
423 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
424 | rid = p[0].split('-')[3] | |
425 | # This will fail during GSM auth validation | |
426 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677"): | |
427 | raise Exception("CTRL-RSP-SIM failed") | |
428 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
429 | if ev is None: | |
430 | raise Exception("EAP failure not reported") | |
431 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
432 | dev[0].wait_disconnected() |
433 | time.sleep(0.1) | |
72cbc684 JM |
434 | |
435 | dev[0].select_network(id, freq="2412") | |
436 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
437 | if ev is None: | |
438 | raise Exception("Wait for external SIM processing request timed out") | |
439 | p = ev.split(':', 2) | |
440 | if p[1] != "GSM-AUTH": | |
441 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
442 | rid = p[0].split('-')[3] | |
443 | # This will fail during GSM auth validation | |
444 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:q"): | |
445 | raise Exception("CTRL-RSP-SIM failed") | |
446 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
447 | if ev is None: | |
448 | raise Exception("EAP failure not reported") | |
449 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
450 | dev[0].wait_disconnected() |
451 | time.sleep(0.1) | |
72cbc684 JM |
452 | |
453 | dev[0].select_network(id, freq="2412") | |
454 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
455 | if ev is None: | |
456 | raise Exception("Wait for external SIM processing request timed out") | |
457 | p = ev.split(':', 2) | |
458 | if p[1] != "GSM-AUTH": | |
459 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
460 | rid = p[0].split('-')[3] | |
461 | # This will fail during GSM auth validation | |
462 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:00112233"): | |
463 | raise Exception("CTRL-RSP-SIM failed") | |
464 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
465 | if ev is None: | |
466 | raise Exception("EAP failure not reported") | |
467 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
468 | dev[0].wait_disconnected() |
469 | time.sleep(0.1) | |
72cbc684 JM |
470 | |
471 | dev[0].select_network(id, freq="2412") | |
472 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
473 | if ev is None: | |
474 | raise Exception("Wait for external SIM processing request timed out") | |
475 | p = ev.split(':', 2) | |
476 | if p[1] != "GSM-AUTH": | |
477 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
478 | rid = p[0].split('-')[3] | |
479 | # This will fail during GSM auth validation | |
480 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:00112233:q"): | |
481 | raise Exception("CTRL-RSP-SIM failed") | |
482 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
483 | if ev is None: | |
484 | raise Exception("EAP failure not reported") | |
485 | ||
40c654cc JM |
486 | def test_ap_wpa2_eap_sim_ext_replace_sim(dev, apdev): |
487 | """EAP-SIM with external GSM auth and replacing SIM without clearing pseudonym id""" | |
488 | try: | |
489 | _test_ap_wpa2_eap_sim_ext_replace_sim(dev, apdev) | |
490 | finally: | |
491 | dev[0].request("SET external_sim 0") | |
492 | ||
493 | def _test_ap_wpa2_eap_sim_ext_replace_sim(dev, apdev): | |
494 | check_hlr_auc_gw_support() | |
495 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 496 | hostapd.add_ap(apdev[0], params) |
40c654cc JM |
497 | dev[0].request("SET external_sim 1") |
498 | id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP", | |
499 | identity="1232010000000000", | |
500 | wait_connect=False, scan_freq="2412") | |
501 | ||
502 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
503 | if ev is None: | |
504 | raise Exception("Wait for external SIM processing request timed out") | |
505 | p = ev.split(':', 2) | |
506 | if p[1] != "GSM-AUTH": | |
507 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
508 | rid = p[0].split('-')[3] | |
509 | rand = p[2].split(' ')[0] | |
510 | ||
511 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
512 | "-m", | |
513 | "auth_serv/hlr_auc_gw.milenage_db", | |
514 | "GSM-AUTH-REQ 232010000000000 " + rand]) | |
515 | if "GSM-AUTH-RESP" not in res: | |
516 | raise Exception("Unexpected hlr_auc_gw response") | |
517 | resp = res.split(' ')[2].rstrip() | |
518 | ||
519 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
520 | dev[0].wait_connected(timeout=15) | |
521 | dev[0].request("DISCONNECT") | |
522 | dev[0].wait_disconnected() | |
523 | ||
524 | # Replace SIM, but forget to drop the previous pseudonym identity | |
525 | dev[0].set_network_quoted(id, "identity", "1232010000000009") | |
526 | dev[0].select_network(id, freq="2412") | |
527 | ||
528 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
529 | if ev is None: | |
530 | raise Exception("Wait for external SIM processing request timed out") | |
531 | p = ev.split(':', 2) | |
532 | if p[1] != "GSM-AUTH": | |
533 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
534 | rid = p[0].split('-')[3] | |
535 | rand = p[2].split(' ')[0] | |
536 | ||
537 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
538 | "-m", | |
539 | "auth_serv/hlr_auc_gw.milenage_db", | |
540 | "GSM-AUTH-REQ 232010000000009 " + rand]) | |
541 | if "GSM-AUTH-RESP" not in res: | |
542 | raise Exception("Unexpected hlr_auc_gw response") | |
543 | resp = res.split(' ')[2].rstrip() | |
544 | ||
545 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
546 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
547 | if ev is None: | |
548 | raise Exception("EAP-Failure not reported") | |
549 | dev[0].request("DISCONNECT") | |
550 | dev[0].wait_disconnected() | |
551 | ||
552 | def test_ap_wpa2_eap_sim_ext_replace_sim2(dev, apdev): | |
553 | """EAP-SIM with external GSM auth and replacing SIM and clearing pseudonym identity""" | |
554 | try: | |
555 | _test_ap_wpa2_eap_sim_ext_replace_sim2(dev, apdev) | |
556 | finally: | |
557 | dev[0].request("SET external_sim 0") | |
558 | ||
559 | def _test_ap_wpa2_eap_sim_ext_replace_sim2(dev, apdev): | |
560 | check_hlr_auc_gw_support() | |
561 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 562 | hostapd.add_ap(apdev[0], params) |
40c654cc JM |
563 | dev[0].request("SET external_sim 1") |
564 | id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP", | |
565 | identity="1232010000000000", | |
566 | wait_connect=False, scan_freq="2412") | |
567 | ||
568 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
569 | if ev is None: | |
570 | raise Exception("Wait for external SIM processing request timed out") | |
571 | p = ev.split(':', 2) | |
572 | if p[1] != "GSM-AUTH": | |
573 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
574 | rid = p[0].split('-')[3] | |
575 | rand = p[2].split(' ')[0] | |
576 | ||
577 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
578 | "-m", | |
579 | "auth_serv/hlr_auc_gw.milenage_db", | |
580 | "GSM-AUTH-REQ 232010000000000 " + rand]) | |
581 | if "GSM-AUTH-RESP" not in res: | |
582 | raise Exception("Unexpected hlr_auc_gw response") | |
583 | resp = res.split(' ')[2].rstrip() | |
584 | ||
585 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
586 | dev[0].wait_connected(timeout=15) | |
587 | dev[0].request("DISCONNECT") | |
588 | dev[0].wait_disconnected() | |
589 | ||
590 | # Replace SIM and drop the previous pseudonym identity | |
591 | dev[0].set_network_quoted(id, "identity", "1232010000000009") | |
592 | dev[0].set_network(id, "anonymous_identity", "NULL") | |
593 | dev[0].select_network(id, freq="2412") | |
594 | ||
595 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
596 | if ev is None: | |
597 | raise Exception("Wait for external SIM processing request timed out") | |
598 | p = ev.split(':', 2) | |
599 | if p[1] != "GSM-AUTH": | |
600 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
601 | rid = p[0].split('-')[3] | |
602 | rand = p[2].split(' ')[0] | |
603 | ||
604 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
605 | "-m", | |
606 | "auth_serv/hlr_auc_gw.milenage_db", | |
607 | "GSM-AUTH-REQ 232010000000009 " + rand]) | |
608 | if "GSM-AUTH-RESP" not in res: | |
609 | raise Exception("Unexpected hlr_auc_gw response") | |
610 | resp = res.split(' ')[2].rstrip() | |
611 | ||
612 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
613 | dev[0].wait_connected() | |
614 | dev[0].request("DISCONNECT") | |
615 | dev[0].wait_disconnected() | |
616 | ||
617 | def test_ap_wpa2_eap_sim_ext_replace_sim3(dev, apdev): | |
618 | """EAP-SIM with external GSM auth, replacing SIM, and no identity in config""" | |
619 | try: | |
620 | _test_ap_wpa2_eap_sim_ext_replace_sim3(dev, apdev) | |
621 | finally: | |
622 | dev[0].request("SET external_sim 0") | |
623 | ||
624 | def _test_ap_wpa2_eap_sim_ext_replace_sim3(dev, apdev): | |
625 | check_hlr_auc_gw_support() | |
626 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 627 | hostapd.add_ap(apdev[0], params) |
40c654cc JM |
628 | dev[0].request("SET external_sim 1") |
629 | id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP", | |
630 | wait_connect=False, scan_freq="2412") | |
631 | ||
632 | ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"]) | |
633 | if ev is None: | |
634 | raise Exception("Request for identity timed out") | |
635 | rid = ev.split(':')[0].split('-')[-1] | |
636 | dev[0].request("CTRL-RSP-IDENTITY-" + rid + ":1232010000000000") | |
637 | ||
638 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
639 | if ev is None: | |
640 | raise Exception("Wait for external SIM processing request timed out") | |
641 | p = ev.split(':', 2) | |
642 | if p[1] != "GSM-AUTH": | |
643 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
644 | rid = p[0].split('-')[3] | |
645 | rand = p[2].split(' ')[0] | |
646 | ||
647 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
648 | "-m", | |
649 | "auth_serv/hlr_auc_gw.milenage_db", | |
650 | "GSM-AUTH-REQ 232010000000000 " + rand]) | |
651 | if "GSM-AUTH-RESP" not in res: | |
652 | raise Exception("Unexpected hlr_auc_gw response") | |
653 | resp = res.split(' ')[2].rstrip() | |
654 | ||
655 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
656 | dev[0].wait_connected(timeout=15) | |
657 | dev[0].request("DISCONNECT") | |
658 | dev[0].wait_disconnected() | |
659 | ||
660 | # Replace SIM and drop the previous permanent and pseudonym identities | |
661 | dev[0].set_network(id, "identity", "NULL") | |
662 | dev[0].set_network(id, "anonymous_identity", "NULL") | |
663 | dev[0].select_network(id, freq="2412") | |
664 | ||
665 | ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"]) | |
666 | if ev is None: | |
667 | raise Exception("Request for identity timed out") | |
668 | rid = ev.split(':')[0].split('-')[-1] | |
669 | dev[0].request("CTRL-RSP-IDENTITY-" + rid + ":1232010000000009") | |
670 | ||
671 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
672 | if ev is None: | |
673 | raise Exception("Wait for external SIM processing request timed out") | |
674 | p = ev.split(':', 2) | |
675 | if p[1] != "GSM-AUTH": | |
676 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
677 | rid = p[0].split('-')[3] | |
678 | rand = p[2].split(' ')[0] | |
679 | ||
680 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
681 | "-m", | |
682 | "auth_serv/hlr_auc_gw.milenage_db", | |
683 | "GSM-AUTH-REQ 232010000000009 " + rand]) | |
684 | if "GSM-AUTH-RESP" not in res: | |
685 | raise Exception("Unexpected hlr_auc_gw response") | |
686 | resp = res.split(' ')[2].rstrip() | |
687 | ||
688 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
689 | dev[0].wait_connected() | |
690 | dev[0].request("DISCONNECT") | |
691 | dev[0].wait_disconnected() | |
692 | ||
c397edf2 JM |
693 | def test_ap_wpa2_eap_sim_ext_auth_fail(dev, apdev): |
694 | """EAP-SIM with external GSM auth and auth failing""" | |
695 | try: | |
696 | _test_ap_wpa2_eap_sim_ext_auth_fail(dev, apdev) | |
697 | finally: | |
698 | dev[0].request("SET external_sim 0") | |
699 | ||
700 | def _test_ap_wpa2_eap_sim_ext_auth_fail(dev, apdev): | |
701 | check_hlr_auc_gw_support() | |
702 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 703 | hostapd.add_ap(apdev[0], params) |
c397edf2 JM |
704 | dev[0].request("SET external_sim 1") |
705 | id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP", | |
706 | identity="1232010000000000", | |
707 | wait_connect=False, scan_freq="2412") | |
708 | ||
709 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
710 | if ev is None: | |
711 | raise Exception("Wait for external SIM processing request timed out") | |
712 | p = ev.split(':', 2) | |
713 | rid = p[0].split('-')[3] | |
714 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-FAIL") | |
715 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
716 | if ev is None: | |
717 | raise Exception("EAP failure not reported") | |
718 | dev[0].request("REMOVE_NETWORK all") | |
719 | dev[0].wait_disconnected() | |
720 | ||
6c7fed46 JM |
721 | def test_ap_wpa2_eap_sim_change_bssid(dev, apdev): |
722 | """EAP-SIM and external GSM auth to check fast reauth with bssid change""" | |
723 | try: | |
724 | _test_ap_wpa2_eap_sim_change_bssid(dev, apdev) | |
725 | finally: | |
726 | dev[0].request("SET external_sim 0") | |
727 | ||
728 | def _test_ap_wpa2_eap_sim_change_bssid(dev, apdev): | |
729 | check_hlr_auc_gw_support() | |
730 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 731 | hostapd.add_ap(apdev[0], params) |
6c7fed46 JM |
732 | dev[0].request("SET external_sim 1") |
733 | id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP", | |
734 | identity="1232010000000000", | |
735 | wait_connect=False, scan_freq="2412") | |
736 | ||
737 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
738 | if ev is None: | |
739 | raise Exception("Wait for external SIM processing request timed out") | |
740 | p = ev.split(':', 2) | |
741 | if p[1] != "GSM-AUTH": | |
742 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
743 | rid = p[0].split('-')[3] | |
744 | rand = p[2].split(' ')[0] | |
745 | ||
746 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
747 | "-m", | |
748 | "auth_serv/hlr_auc_gw.milenage_db", | |
749 | "GSM-AUTH-REQ 232010000000000 " + rand]) | |
750 | if "GSM-AUTH-RESP" not in res: | |
751 | raise Exception("Unexpected hlr_auc_gw response") | |
752 | resp = res.split(' ')[2].rstrip() | |
753 | ||
754 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
755 | dev[0].wait_connected(timeout=15) | |
756 | ||
757 | # Verify that EAP-SIM Reauthentication can be used after a profile change | |
758 | # that does not affect EAP parameters. | |
759 | dev[0].set_network(id, "bssid", "any") | |
760 | eap_reauth(dev[0], "SIM") | |
761 | ||
07f0da30 JM |
762 | def test_ap_wpa2_eap_sim_no_change_set(dev, apdev): |
763 | """EAP-SIM and external GSM auth to check fast reauth with no-change SET_NETWORK""" | |
764 | try: | |
765 | _test_ap_wpa2_eap_sim_no_change_set(dev, apdev) | |
766 | finally: | |
767 | dev[0].request("SET external_sim 0") | |
768 | ||
769 | def _test_ap_wpa2_eap_sim_no_change_set(dev, apdev): | |
770 | check_hlr_auc_gw_support() | |
771 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 772 | hostapd.add_ap(apdev[0], params) |
07f0da30 JM |
773 | dev[0].request("SET external_sim 1") |
774 | id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP", | |
775 | identity="1232010000000000", | |
776 | wait_connect=False, scan_freq="2412") | |
777 | ||
778 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
779 | if ev is None: | |
780 | raise Exception("Wait for external SIM processing request timed out") | |
781 | p = ev.split(':', 2) | |
782 | if p[1] != "GSM-AUTH": | |
783 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
784 | rid = p[0].split('-')[3] | |
785 | rand = p[2].split(' ')[0] | |
786 | ||
787 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
788 | "-m", | |
789 | "auth_serv/hlr_auc_gw.milenage_db", | |
790 | "GSM-AUTH-REQ 232010000000000 " + rand]) | |
791 | if "GSM-AUTH-RESP" not in res: | |
792 | raise Exception("Unexpected hlr_auc_gw response") | |
793 | resp = res.split(' ')[2].rstrip() | |
794 | ||
795 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
796 | dev[0].wait_connected(timeout=15) | |
797 | ||
798 | # Verify that EAP-SIM Reauthentication can be used after network profile | |
799 | # SET_NETWORK commands that do not actually change previously set | |
800 | # parameter values. | |
801 | dev[0].set_network(id, "key_mgmt", "WPA-EAP") | |
802 | dev[0].set_network(id, "eap", "SIM") | |
803 | dev[0].set_network_quoted(id, "identity", "1232010000000000") | |
804 | dev[0].set_network_quoted(id, "ssid", "test-wpa2-eap") | |
805 | eap_reauth(dev[0], "SIM") | |
806 | ||
486f4e3c JM |
807 | def test_ap_wpa2_eap_sim_oom(dev, apdev): |
808 | """EAP-SIM and OOM""" | |
809 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 810 | hostapd.add_ap(apdev[0], params) |
486f4e3c JM |
811 | tests = [ (1, "milenage_f2345"), |
812 | (2, "milenage_f2345"), | |
813 | (3, "milenage_f2345"), | |
814 | (4, "milenage_f2345"), | |
815 | (5, "milenage_f2345"), | |
816 | (6, "milenage_f2345"), | |
817 | (7, "milenage_f2345"), | |
818 | (8, "milenage_f2345"), | |
819 | (9, "milenage_f2345"), | |
820 | (10, "milenage_f2345"), | |
821 | (11, "milenage_f2345"), | |
822 | (12, "milenage_f2345") ] | |
823 | for count, func in tests: | |
7cbc8e67 | 824 | with fail_test(dev[0], count, func): |
486f4e3c JM |
825 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM", |
826 | identity="1232010000000000", | |
827 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
828 | wait_connect=False, scan_freq="2412") | |
829 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5) | |
830 | if ev is None: | |
831 | raise Exception("EAP method not selected") | |
832 | dev[0].wait_disconnected() | |
833 | dev[0].request("REMOVE_NETWORK all") | |
834 | ||
9626962d JM |
835 | def test_ap_wpa2_eap_aka(dev, apdev): |
836 | """WPA2-Enterprise connection using EAP-AKA""" | |
81e787b7 | 837 | check_hlr_auc_gw_support() |
9626962d | 838 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 839 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 840 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
9626962d | 841 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") |
a8375c94 | 842 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 843 | eap_reauth(dev[0], "AKA") |
9626962d | 844 | |
f10ba3b2 JM |
845 | logger.info("Negative test with incorrect key") |
846 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 847 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
f10ba3b2 JM |
848 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", |
849 | expect_failure=True) | |
850 | ||
32747a3e JM |
851 | logger.info("Invalid Milenage key") |
852 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 853 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
32747a3e JM |
854 | password="ffdca4eda45b53cf0f12d7c9c3bc6a", |
855 | expect_failure=True) | |
856 | ||
857 | logger.info("Invalid Milenage key(2)") | |
3b3e2687 | 858 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
32747a3e JM |
859 | password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581:000000000123", |
860 | expect_failure=True) | |
861 | ||
862 | logger.info("Invalid Milenage key(3)") | |
3b3e2687 | 863 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
32747a3e JM |
864 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q:000000000123", |
865 | expect_failure=True) | |
866 | ||
867 | logger.info("Invalid Milenage key(4)") | |
3b3e2687 | 868 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
32747a3e JM |
869 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:00000000012q", |
870 | expect_failure=True) | |
871 | ||
872 | logger.info("Invalid Milenage key(5)") | |
873 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 874 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
32747a3e JM |
875 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581q000000000123", |
876 | expect_failure=True) | |
877 | ||
878 | logger.info("Invalid Milenage key(6)") | |
879 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 880 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
32747a3e JM |
881 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581q000000000123", |
882 | expect_failure=True) | |
883 | ||
884 | logger.info("Missing key configuration") | |
885 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 886 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
32747a3e JM |
887 | expect_failure=True) |
888 | ||
5b1aaf6c JM |
889 | def test_ap_wpa2_eap_aka_sql(dev, apdev, params): |
890 | """WPA2-Enterprise connection using EAP-AKA (SQL)""" | |
81e787b7 | 891 | check_hlr_auc_gw_support() |
5b1aaf6c JM |
892 | try: |
893 | import sqlite3 | |
894 | except ImportError: | |
81e787b7 | 895 | raise HwsimSkip("No sqlite3 module available") |
5b1aaf6c JM |
896 | con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) |
897 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
898 | params['auth_server_port'] = "1814" | |
3b3e2687 JD |
899 | hapd = hostapd.add_ap(apdev[0], params) |
900 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", | |
5b1aaf6c JM |
901 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") |
902 | ||
903 | logger.info("AKA fast re-authentication") | |
904 | eap_reauth(dev[0], "AKA") | |
905 | ||
906 | logger.info("AKA full auth with pseudonym") | |
907 | with con: | |
908 | cur = con.cursor() | |
909 | cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'") | |
910 | eap_reauth(dev[0], "AKA") | |
911 | ||
912 | logger.info("AKA full auth with permanent identity") | |
913 | with con: | |
914 | cur = con.cursor() | |
915 | cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'") | |
916 | cur.execute("DELETE FROM pseudonyms WHERE permanent='0232010000000000'") | |
917 | eap_reauth(dev[0], "AKA") | |
918 | ||
919 | logger.info("AKA reauth with mismatching MK") | |
920 | with con: | |
921 | cur = con.cursor() | |
922 | cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='0232010000000000'") | |
923 | eap_reauth(dev[0], "AKA", expect_failure=True) | |
924 | dev[0].request("REMOVE_NETWORK all") | |
925 | ||
3b3e2687 | 926 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
5b1aaf6c JM |
927 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") |
928 | with con: | |
929 | cur = con.cursor() | |
930 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'") | |
931 | eap_reauth(dev[0], "AKA") | |
932 | with con: | |
933 | cur = con.cursor() | |
934 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'") | |
935 | logger.info("AKA reauth with mismatching counter") | |
936 | eap_reauth(dev[0], "AKA") | |
937 | dev[0].request("REMOVE_NETWORK all") | |
938 | ||
3b3e2687 | 939 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
5b1aaf6c JM |
940 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") |
941 | with con: | |
942 | cur = con.cursor() | |
943 | cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='0232010000000000'") | |
944 | logger.info("AKA reauth with max reauth count reached") | |
945 | eap_reauth(dev[0], "AKA") | |
946 | ||
e2a90a4c JM |
947 | def test_ap_wpa2_eap_aka_config(dev, apdev): |
948 | """EAP-AKA configuration options""" | |
949 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
950 | hapd = hostapd.add_ap(apdev[0], params) |
951 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", | |
e2a90a4c JM |
952 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", |
953 | anonymous_identity="2345678") | |
954 | ||
d314bedf JM |
955 | def test_ap_wpa2_eap_aka_ext(dev, apdev): |
956 | """WPA2-Enterprise connection using EAP-AKA and external UMTS auth""" | |
47dcb118 | 957 | try: |
81e787b7 | 958 | _test_ap_wpa2_eap_aka_ext(dev, apdev) |
47dcb118 JM |
959 | finally: |
960 | dev[0].request("SET external_sim 0") | |
961 | ||
962 | def _test_ap_wpa2_eap_aka_ext(dev, apdev): | |
81e787b7 | 963 | check_hlr_auc_gw_support() |
d314bedf | 964 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 965 | hostapd.add_ap(apdev[0], params) |
d314bedf JM |
966 | dev[0].request("SET external_sim 1") |
967 | id = dev[0].connect("test-wpa2-eap", eap="AKA", key_mgmt="WPA-EAP", | |
968 | identity="0232010000000000", | |
969 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
970 | wait_connect=False, scan_freq="2412") | |
971 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) | |
972 | if ev is None: | |
973 | raise Exception("Network connected timed out") | |
974 | ||
975 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
976 | if ev is None: | |
977 | raise Exception("Wait for external SIM processing request timed out") | |
978 | p = ev.split(':', 2) | |
979 | if p[1] != "UMTS-AUTH": | |
980 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
981 | rid = p[0].split('-')[3] | |
982 | ||
983 | # IK:CK:RES | |
984 | resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344" | |
985 | # This will fail during processing, but the ctrl_iface command succeeds | |
986 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
987 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
988 | if ev is None: | |
989 | raise Exception("EAP failure not reported") | |
990 | dev[0].request("DISCONNECT") | |
584e4197 | 991 | dev[0].wait_disconnected() |
90ad11e6 | 992 | time.sleep(0.1) |
a359c7bb | 993 | dev[0].dump_monitor() |
d314bedf | 994 | |
d8e02214 JM |
995 | dev[0].select_network(id, freq="2412") |
996 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
997 | if ev is None: | |
998 | raise Exception("Wait for external SIM processing request timed out") | |
999 | p = ev.split(':', 2) | |
1000 | if p[1] != "UMTS-AUTH": | |
1001 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
1002 | rid = p[0].split('-')[3] | |
1003 | # This will fail during UMTS auth validation | |
1004 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:112233445566778899aabbccddee"): | |
1005 | raise Exception("CTRL-RSP-SIM failed") | |
1006 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
1007 | if ev is None: | |
1008 | raise Exception("Wait for external SIM processing request timed out") | |
1009 | p = ev.split(':', 2) | |
1010 | if p[1] != "UMTS-AUTH": | |
1011 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
1012 | rid = p[0].split('-')[3] | |
1013 | # This will fail during UMTS auth validation | |
1014 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:12"): | |
1015 | raise Exception("CTRL-RSP-SIM failed") | |
1016 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
1017 | if ev is None: | |
1018 | raise Exception("EAP failure not reported") | |
1019 | dev[0].request("DISCONNECT") | |
584e4197 | 1020 | dev[0].wait_disconnected() |
90ad11e6 | 1021 | time.sleep(0.1) |
a359c7bb | 1022 | dev[0].dump_monitor() |
d8e02214 | 1023 | |
0258cf10 JM |
1024 | tests = [ ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344", |
1025 | ":UMTS-AUTH:34", | |
1026 | ":UMTS-AUTH:00112233445566778899aabbccddeeff.00112233445566778899aabbccddeeff:0011223344", | |
1027 | ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddee:0011223344", | |
1028 | ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff.0011223344", | |
1029 | ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff0011223344", | |
1030 | ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:001122334q" ] | |
1031 | for t in tests: | |
1032 | dev[0].select_network(id, freq="2412") | |
1033 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
1034 | if ev is None: | |
1035 | raise Exception("Wait for external SIM processing request timed out") | |
1036 | p = ev.split(':', 2) | |
1037 | if p[1] != "UMTS-AUTH": | |
1038 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
1039 | rid = p[0].split('-')[3] | |
1040 | # This will fail during UMTS auth validation | |
1041 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + t): | |
1042 | raise Exception("CTRL-RSP-SIM failed") | |
1043 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
1044 | if ev is None: | |
1045 | raise Exception("EAP failure not reported") | |
1046 | dev[0].request("DISCONNECT") | |
1047 | dev[0].wait_disconnected() | |
90ad11e6 | 1048 | time.sleep(0.1) |
a359c7bb | 1049 | dev[0].dump_monitor() |
d314bedf | 1050 | |
c397edf2 JM |
1051 | def test_ap_wpa2_eap_aka_ext_auth_fail(dev, apdev): |
1052 | """EAP-AKA with external UMTS auth and auth failing""" | |
1053 | try: | |
1054 | _test_ap_wpa2_eap_aka_ext_auth_fail(dev, apdev) | |
1055 | finally: | |
1056 | dev[0].request("SET external_sim 0") | |
1057 | ||
1058 | def _test_ap_wpa2_eap_aka_ext_auth_fail(dev, apdev): | |
1059 | check_hlr_auc_gw_support() | |
1060 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1061 | hostapd.add_ap(apdev[0], params) |
c397edf2 JM |
1062 | dev[0].request("SET external_sim 1") |
1063 | id = dev[0].connect("test-wpa2-eap", eap="AKA", key_mgmt="WPA-EAP", | |
1064 | identity="0232010000000000", | |
1065 | wait_connect=False, scan_freq="2412") | |
1066 | ||
1067 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
1068 | if ev is None: | |
1069 | raise Exception("Wait for external SIM processing request timed out") | |
1070 | p = ev.split(':', 2) | |
1071 | rid = p[0].split('-')[3] | |
1072 | dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-FAIL") | |
1073 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
1074 | if ev is None: | |
1075 | raise Exception("EAP failure not reported") | |
1076 | dev[0].request("REMOVE_NETWORK all") | |
1077 | dev[0].wait_disconnected() | |
1078 | ||
9626962d JM |
1079 | def test_ap_wpa2_eap_aka_prime(dev, apdev): |
1080 | """WPA2-Enterprise connection using EAP-AKA'""" | |
81e787b7 | 1081 | check_hlr_auc_gw_support() |
9626962d | 1082 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1083 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1084 | eap_connect(dev[0], hapd, "AKA'", "6555444333222111", |
9626962d | 1085 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") |
a8375c94 | 1086 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1087 | eap_reauth(dev[0], "AKA'") |
9626962d | 1088 | |
8583d664 JM |
1089 | logger.info("EAP-AKA' bidding protection when EAP-AKA enabled as well") |
1090 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="AKA' AKA", | |
1091 | identity="6555444333222111@both", | |
1092 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
1093 | wait_connect=False, scan_freq="2412") | |
5f35a5e2 | 1094 | dev[1].wait_connected(timeout=15) |
8583d664 | 1095 | |
f10ba3b2 JM |
1096 | logger.info("Negative test with incorrect key") |
1097 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 1098 | eap_connect(dev[0], hapd, "AKA'", "6555444333222111", |
f10ba3b2 JM |
1099 | password="ff22250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", |
1100 | expect_failure=True) | |
1101 | ||
5b1aaf6c JM |
1102 | def test_ap_wpa2_eap_aka_prime_sql(dev, apdev, params): |
1103 | """WPA2-Enterprise connection using EAP-AKA' (SQL)""" | |
81e787b7 | 1104 | check_hlr_auc_gw_support() |
5b1aaf6c JM |
1105 | try: |
1106 | import sqlite3 | |
1107 | except ImportError: | |
81e787b7 | 1108 | raise HwsimSkip("No sqlite3 module available") |
5b1aaf6c JM |
1109 | con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) |
1110 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1111 | params['auth_server_port'] = "1814" | |
3b3e2687 JD |
1112 | hapd = hostapd.add_ap(apdev[0], params) |
1113 | eap_connect(dev[0], hapd, "AKA'", "6555444333222111", | |
5b1aaf6c JM |
1114 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") |
1115 | ||
1116 | logger.info("AKA' fast re-authentication") | |
1117 | eap_reauth(dev[0], "AKA'") | |
1118 | ||
1119 | logger.info("AKA' full auth with pseudonym") | |
1120 | with con: | |
1121 | cur = con.cursor() | |
1122 | cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'") | |
1123 | eap_reauth(dev[0], "AKA'") | |
1124 | ||
1125 | logger.info("AKA' full auth with permanent identity") | |
1126 | with con: | |
1127 | cur = con.cursor() | |
1128 | cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'") | |
1129 | cur.execute("DELETE FROM pseudonyms WHERE permanent='6555444333222111'") | |
1130 | eap_reauth(dev[0], "AKA'") | |
1131 | ||
1132 | logger.info("AKA' reauth with mismatching k_aut") | |
1133 | with con: | |
1134 | cur = con.cursor() | |
1135 | cur.execute("UPDATE reauth SET k_aut='0000000000000000000000000000000000000000000000000000000000000000' WHERE permanent='6555444333222111'") | |
1136 | eap_reauth(dev[0], "AKA'", expect_failure=True) | |
1137 | dev[0].request("REMOVE_NETWORK all") | |
1138 | ||
3b3e2687 | 1139 | eap_connect(dev[0], hapd, "AKA'", "6555444333222111", |
5b1aaf6c JM |
1140 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") |
1141 | with con: | |
1142 | cur = con.cursor() | |
1143 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'") | |
1144 | eap_reauth(dev[0], "AKA'") | |
1145 | with con: | |
1146 | cur = con.cursor() | |
1147 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'") | |
1148 | logger.info("AKA' reauth with mismatching counter") | |
1149 | eap_reauth(dev[0], "AKA'") | |
1150 | dev[0].request("REMOVE_NETWORK all") | |
1151 | ||
3b3e2687 | 1152 | eap_connect(dev[0], hapd, "AKA'", "6555444333222111", |
5b1aaf6c JM |
1153 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") |
1154 | with con: | |
1155 | cur = con.cursor() | |
1156 | cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='6555444333222111'") | |
1157 | logger.info("AKA' reauth with max reauth count reached") | |
1158 | eap_reauth(dev[0], "AKA'") | |
1159 | ||
c397edf2 JM |
1160 | def test_ap_wpa2_eap_aka_prime_ext_auth_fail(dev, apdev): |
1161 | """EAP-AKA' with external UMTS auth and auth failing""" | |
1162 | try: | |
1163 | _test_ap_wpa2_eap_aka_prime_ext_auth_fail(dev, apdev) | |
1164 | finally: | |
1165 | dev[0].request("SET external_sim 0") | |
1166 | ||
1167 | def _test_ap_wpa2_eap_aka_prime_ext_auth_fail(dev, apdev): | |
1168 | check_hlr_auc_gw_support() | |
1169 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1170 | hostapd.add_ap(apdev[0], params) |
c397edf2 JM |
1171 | dev[0].request("SET external_sim 1") |
1172 | id = dev[0].connect("test-wpa2-eap", eap="AKA'", key_mgmt="WPA-EAP", | |
1173 | identity="6555444333222111", | |
1174 | wait_connect=False, scan_freq="2412") | |
1175 | ||
1176 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
1177 | if ev is None: | |
1178 | raise Exception("Wait for external SIM processing request timed out") | |
1179 | p = ev.split(':', 2) | |
1180 | rid = p[0].split('-')[3] | |
1181 | dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-FAIL") | |
1182 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
1183 | if ev is None: | |
1184 | raise Exception("EAP failure not reported") | |
1185 | dev[0].request("REMOVE_NETWORK all") | |
1186 | dev[0].wait_disconnected() | |
1187 | ||
c25aada9 JM |
1188 | def test_ap_wpa2_eap_aka_prime_ext(dev, apdev): |
1189 | """EAP-AKA' with external UMTS auth to hit Synchronization-Failure""" | |
1190 | try: | |
1191 | _test_ap_wpa2_eap_aka_prime_ext(dev, apdev) | |
1192 | finally: | |
1193 | dev[0].request("SET external_sim 0") | |
1194 | ||
1195 | def _test_ap_wpa2_eap_aka_prime_ext(dev, apdev): | |
1196 | check_hlr_auc_gw_support() | |
1197 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1198 | hostapd.add_ap(apdev[0], params) | |
1199 | dev[0].request("SET external_sim 1") | |
1200 | id = dev[0].connect("test-wpa2-eap", eap="AKA'", key_mgmt="WPA-EAP", | |
1201 | identity="6555444333222111", | |
1202 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1203 | wait_connect=False, scan_freq="2412") | |
1204 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) | |
1205 | if ev is None: | |
1206 | raise Exception("Network connected timed out") | |
1207 | ||
1208 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
1209 | if ev is None: | |
1210 | raise Exception("Wait for external SIM processing request timed out") | |
1211 | p = ev.split(':', 2) | |
1212 | if p[1] != "UMTS-AUTH": | |
1213 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
1214 | rid = p[0].split('-')[3] | |
1215 | # This will fail during UMTS auth validation | |
1216 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:112233445566778899aabbccddee"): | |
1217 | raise Exception("CTRL-RSP-SIM failed") | |
1218 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
1219 | if ev is None: | |
1220 | raise Exception("Wait for external SIM processing request timed out") | |
1221 | ||
9626962d JM |
1222 | def test_ap_wpa2_eap_ttls_pap(dev, apdev): |
1223 | """WPA2-Enterprise connection using EAP-TTLS/PAP""" | |
1224 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1225 | hapd = hostapd.add_ap(apdev[0], params) |
65038313 JM |
1226 | key_mgmt = hapd.get_config()['key_mgmt'] |
1227 | if key_mgmt.split(' ')[0] != "WPA-EAP": | |
1228 | raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt) | |
3b3e2687 | 1229 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
9626962d | 1230 | anonymous_identity="ttls", password="password", |
506b2f05 | 1231 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") |
a8375c94 | 1232 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1233 | eap_reauth(dev[0], "TTLS") |
eaf3f9b1 JM |
1234 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-1"), |
1235 | ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-1") ]) | |
9626962d | 1236 | |
506b2f05 JM |
1237 | def test_ap_wpa2_eap_ttls_pap_subject_match(dev, apdev): |
1238 | """WPA2-Enterprise connection using EAP-TTLS/PAP and (alt)subject_match""" | |
1239 | check_subject_match_support(dev[0]) | |
1240 | check_altsubject_match_support(dev[0]) | |
1241 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1242 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1243 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
506b2f05 JM |
1244 | anonymous_identity="ttls", password="password", |
1245 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
1246 | subject_match="/C=FI/O=w1.fi/CN=server.w1.fi", | |
1247 | altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/") | |
1248 | eap_reauth(dev[0], "TTLS") | |
1249 | ||
82a8f5b5 JM |
1250 | def test_ap_wpa2_eap_ttls_pap_incorrect_password(dev, apdev): |
1251 | """WPA2-Enterprise connection using EAP-TTLS/PAP - incorrect password""" | |
1252 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1253 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1254 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
82a8f5b5 JM |
1255 | anonymous_identity="ttls", password="wrong", |
1256 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
1257 | expect_failure=True) | |
3b3e2687 | 1258 | eap_connect(dev[1], hapd, "TTLS", "user", |
82a8f5b5 JM |
1259 | anonymous_identity="ttls", password="password", |
1260 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
1261 | expect_failure=True) | |
1262 | ||
9626962d JM |
1263 | def test_ap_wpa2_eap_ttls_chap(dev, apdev): |
1264 | """WPA2-Enterprise connection using EAP-TTLS/CHAP""" | |
ca158ea6 | 1265 | skip_with_fips(dev[0]) |
9626962d | 1266 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1267 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1268 | eap_connect(dev[0], hapd, "TTLS", "chap user", |
506b2f05 JM |
1269 | anonymous_identity="ttls", password="password", |
1270 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP") | |
1271 | hwsim_utils.test_connectivity(dev[0], hapd) | |
1272 | eap_reauth(dev[0], "TTLS") | |
1273 | ||
1274 | def test_ap_wpa2_eap_ttls_chap_altsubject_match(dev, apdev): | |
1275 | """WPA2-Enterprise connection using EAP-TTLS/CHAP""" | |
ca158ea6 | 1276 | skip_with_fips(dev[0]) |
506b2f05 JM |
1277 | check_altsubject_match_support(dev[0]) |
1278 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1279 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1280 | eap_connect(dev[0], hapd, "TTLS", "chap user", |
9626962d | 1281 | anonymous_identity="ttls", password="password", |
5c65e277 JM |
1282 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP", |
1283 | altsubject_match="EMAIL:noone@example.com;URI:http://example.com/;DNS:server.w1.fi") | |
75b2b9cf | 1284 | eap_reauth(dev[0], "TTLS") |
9626962d | 1285 | |
82a8f5b5 JM |
1286 | def test_ap_wpa2_eap_ttls_chap_incorrect_password(dev, apdev): |
1287 | """WPA2-Enterprise connection using EAP-TTLS/CHAP - incorrect password""" | |
ca158ea6 | 1288 | skip_with_fips(dev[0]) |
82a8f5b5 | 1289 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1290 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1291 | eap_connect(dev[0], hapd, "TTLS", "chap user", |
82a8f5b5 JM |
1292 | anonymous_identity="ttls", password="wrong", |
1293 | ca_cert="auth_serv/ca.pem", phase2="auth=CHAP", | |
1294 | expect_failure=True) | |
3b3e2687 | 1295 | eap_connect(dev[1], hapd, "TTLS", "user", |
82a8f5b5 JM |
1296 | anonymous_identity="ttls", password="password", |
1297 | ca_cert="auth_serv/ca.pem", phase2="auth=CHAP", | |
1298 | expect_failure=True) | |
1299 | ||
9626962d JM |
1300 | def test_ap_wpa2_eap_ttls_mschap(dev, apdev): |
1301 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAP""" | |
ca158ea6 | 1302 | skip_with_fips(dev[0]) |
e78eb404 | 1303 | check_domain_suffix_match(dev[0]) |
9626962d | 1304 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1305 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1306 | eap_connect(dev[0], hapd, "TTLS", "mschap user", |
9626962d | 1307 | anonymous_identity="ttls", password="password", |
72c052d5 JM |
1308 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", |
1309 | domain_suffix_match="server.w1.fi") | |
a8375c94 | 1310 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1311 | eap_reauth(dev[0], "TTLS") |
6daf5b9c | 1312 | dev[0].request("REMOVE_NETWORK all") |
3b3e2687 | 1313 | eap_connect(dev[0], hapd, "TTLS", "mschap user", |
6daf5b9c JM |
1314 | anonymous_identity="ttls", password="password", |
1315 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1316 | fragment_size="200") | |
bfdb90d4 JM |
1317 | dev[0].request("REMOVE_NETWORK all") |
1318 | dev[0].wait_disconnected() | |
3b3e2687 | 1319 | eap_connect(dev[0], hapd, "TTLS", "mschap user", |
bfdb90d4 JM |
1320 | anonymous_identity="ttls", |
1321 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
1322 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP") | |
9626962d | 1323 | |
82a8f5b5 | 1324 | def test_ap_wpa2_eap_ttls_mschap_incorrect_password(dev, apdev): |
ca158ea6 JM |
1325 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAP - incorrect password""" |
1326 | skip_with_fips(dev[0]) | |
82a8f5b5 | 1327 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1328 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1329 | eap_connect(dev[0], hapd, "TTLS", "mschap user", |
82a8f5b5 JM |
1330 | anonymous_identity="ttls", password="wrong", |
1331 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1332 | expect_failure=True) | |
3b3e2687 | 1333 | eap_connect(dev[1], hapd, "TTLS", "user", |
82a8f5b5 JM |
1334 | anonymous_identity="ttls", password="password", |
1335 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1336 | expect_failure=True) | |
3b3e2687 | 1337 | eap_connect(dev[2], hapd, "TTLS", "no such user", |
82a8f5b5 JM |
1338 | anonymous_identity="ttls", password="password", |
1339 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1340 | expect_failure=True) | |
1341 | ||
9626962d JM |
1342 | def test_ap_wpa2_eap_ttls_mschapv2(dev, apdev): |
1343 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2""" | |
e78eb404 | 1344 | check_domain_suffix_match(dev[0]) |
ca158ea6 | 1345 | check_eap_capa(dev[0], "MSCHAPV2") |
9626962d | 1346 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
1347 | hapd = hostapd.add_ap(apdev[0], params) |
1348 | eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user", | |
9626962d | 1349 | anonymous_identity="ttls", password="password", |
72c052d5 | 1350 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", |
24579e70 | 1351 | domain_suffix_match="server.w1.fi") |
a8375c94 | 1352 | hwsim_utils.test_connectivity(dev[0], hapd) |
5dec879d JM |
1353 | sta1 = hapd.get_sta(dev[0].p2p_interface_addr()) |
1354 | eapol1 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol") | |
75b2b9cf | 1355 | eap_reauth(dev[0], "TTLS") |
5dec879d JM |
1356 | sta2 = hapd.get_sta(dev[0].p2p_interface_addr()) |
1357 | eapol2 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol") | |
1358 | if int(sta2['dot1xAuthEapolFramesRx']) <= int(sta1['dot1xAuthEapolFramesRx']): | |
1359 | raise Exception("dot1xAuthEapolFramesRx did not increase") | |
1360 | if int(eapol2['authAuthEapStartsWhileAuthenticated']) < 1: | |
1361 | raise Exception("authAuthEapStartsWhileAuthenticated did not increase") | |
1362 | if int(eapol2['backendAuthSuccesses']) <= int(eapol1['backendAuthSuccesses']): | |
1363 | raise Exception("backendAuthSuccesses did not increase") | |
9626962d | 1364 | |
fa0ddb14 JM |
1365 | logger.info("Password as hash value") |
1366 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 1367 | eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user", |
fa0ddb14 JM |
1368 | anonymous_identity="ttls", |
1369 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
1370 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
1371 | ||
c4e06b9b JM |
1372 | def test_ap_wpa2_eap_ttls_invalid_phase2(dev, apdev): |
1373 | """EAP-TTLS with invalid phase2 parameter values""" | |
1374 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1375 | hostapd.add_ap(apdev[0], params) |
c4e06b9b | 1376 | tests = [ "auth=MSCHAPv2", "auth=MSCHAPV2 autheap=MD5", |
53827125 JM |
1377 | "autheap=MD5 auth=MSCHAPV2", "auth=PAP auth=CHAP", |
1378 | "autheap=MD5 autheap=FOO autheap=MSCHAPV2" ] | |
c4e06b9b JM |
1379 | for t in tests: |
1380 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1381 | identity="DOMAIN\mschapv2 user", | |
1382 | anonymous_identity="ttls", password="password", | |
1383 | ca_cert="auth_serv/ca.pem", phase2=t, | |
1384 | wait_connect=False, scan_freq="2412") | |
1385 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=10) | |
1386 | if ev is None or "method=21" not in ev: | |
1387 | raise Exception("EAP-TTLS not started") | |
1388 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method", | |
1389 | "CTRL-EVENT-CONNECTED"], timeout=5) | |
1390 | if ev is None or "CTRL-EVENT-CONNECTED" in ev: | |
1391 | raise Exception("No EAP-TTLS failure reported for phase2=" + t) | |
1392 | dev[0].request("REMOVE_NETWORK all") | |
1393 | dev[0].wait_disconnected() | |
1394 | dev[0].dump_monitor() | |
1395 | ||
24579e70 JM |
1396 | def test_ap_wpa2_eap_ttls_mschapv2_suffix_match(dev, apdev): |
1397 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2""" | |
1398 | check_domain_match_full(dev[0]) | |
ca158ea6 | 1399 | skip_with_fips(dev[0]) |
24579e70 | 1400 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
1401 | hapd = hostapd.add_ap(apdev[0], params) |
1402 | eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user", | |
24579e70 JM |
1403 | anonymous_identity="ttls", password="password", |
1404 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1405 | domain_suffix_match="w1.fi") | |
1406 | hwsim_utils.test_connectivity(dev[0], hapd) | |
1407 | eap_reauth(dev[0], "TTLS") | |
1408 | ||
061cbb25 JM |
1409 | def test_ap_wpa2_eap_ttls_mschapv2_domain_match(dev, apdev): |
1410 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 (domain_match)""" | |
e78eb404 | 1411 | check_domain_match(dev[0]) |
ca158ea6 | 1412 | skip_with_fips(dev[0]) |
061cbb25 | 1413 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
1414 | hapd = hostapd.add_ap(apdev[0], params) |
1415 | eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user", | |
061cbb25 JM |
1416 | anonymous_identity="ttls", password="password", |
1417 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1418 | domain_match="Server.w1.fi") | |
1419 | hwsim_utils.test_connectivity(dev[0], hapd) | |
1420 | eap_reauth(dev[0], "TTLS") | |
1421 | ||
82a8f5b5 JM |
1422 | def test_ap_wpa2_eap_ttls_mschapv2_incorrect_password(dev, apdev): |
1423 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 - incorrect password""" | |
ca158ea6 | 1424 | skip_with_fips(dev[0]) |
82a8f5b5 | 1425 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1426 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1427 | eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user", |
f10ba3b2 JM |
1428 | anonymous_identity="ttls", password="password1", |
1429 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1430 | expect_failure=True) | |
3b3e2687 | 1431 | eap_connect(dev[1], hapd, "TTLS", "user", |
82a8f5b5 JM |
1432 | anonymous_identity="ttls", password="password", |
1433 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1434 | expect_failure=True) | |
f10ba3b2 | 1435 | |
eac67440 JM |
1436 | def test_ap_wpa2_eap_ttls_mschapv2_utf8(dev, apdev): |
1437 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 and UTF-8 password""" | |
ca158ea6 | 1438 | skip_with_fips(dev[0]) |
eac67440 | 1439 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
1440 | hapd = hostapd.add_ap(apdev[0], params) |
1441 | eap_connect(dev[0], hapd, "TTLS", "utf8-user-hash", | |
eac67440 JM |
1442 | anonymous_identity="ttls", password="secret-åäö-€-password", |
1443 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
3b3e2687 | 1444 | eap_connect(dev[1], hapd, "TTLS", "utf8-user", |
eac67440 JM |
1445 | anonymous_identity="ttls", |
1446 | password_hex="hash:bd5844fad2489992da7fe8c5a01559cf", | |
1447 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
0d2a7bad JM |
1448 | for p in [ "80", "41c041e04141e041", 257*"41" ]: |
1449 | dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", | |
1450 | eap="TTLS", identity="utf8-user-hash", | |
1451 | anonymous_identity="ttls", password_hex=p, | |
1452 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1453 | wait_connect=False, scan_freq="2412") | |
1454 | ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=1) | |
1455 | if ev is None: | |
1456 | raise Exception("No failure reported") | |
1457 | dev[2].request("REMOVE_NETWORK all") | |
1458 | dev[2].wait_disconnected() | |
eac67440 | 1459 | |
9626962d JM |
1460 | def test_ap_wpa2_eap_ttls_eap_gtc(dev, apdev): |
1461 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC""" | |
1462 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1463 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1464 | eap_connect(dev[0], hapd, "TTLS", "user", |
9626962d JM |
1465 | anonymous_identity="ttls", password="password", |
1466 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC") | |
a8375c94 | 1467 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1468 | eap_reauth(dev[0], "TTLS") |
9626962d | 1469 | |
95a15d79 JM |
1470 | def test_ap_wpa2_eap_ttls_eap_gtc_incorrect_password(dev, apdev): |
1471 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC - incorrect password""" | |
1472 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1473 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1474 | eap_connect(dev[0], hapd, "TTLS", "user", |
95a15d79 JM |
1475 | anonymous_identity="ttls", password="wrong", |
1476 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC", | |
1477 | expect_failure=True) | |
1478 | ||
1479 | def test_ap_wpa2_eap_ttls_eap_gtc_no_password(dev, apdev): | |
1480 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC - no password""" | |
1481 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1482 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1483 | eap_connect(dev[0], hapd, "TTLS", "user-no-passwd", |
95a15d79 JM |
1484 | anonymous_identity="ttls", password="password", |
1485 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC", | |
1486 | expect_failure=True) | |
1487 | ||
1488 | def test_ap_wpa2_eap_ttls_eap_gtc_server_oom(dev, apdev): | |
1489 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC - server OOM""" | |
1490 | params = int_eap_server_params() | |
8b8a1864 | 1491 | hapd = hostapd.add_ap(apdev[0], params) |
95a15d79 | 1492 | with alloc_fail(hapd, 1, "eap_gtc_init"): |
3b3e2687 | 1493 | eap_connect(dev[0], hapd, "TTLS", "user", |
95a15d79 JM |
1494 | anonymous_identity="ttls", password="password", |
1495 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC", | |
1496 | expect_failure=True) | |
1497 | dev[0].request("REMOVE_NETWORK all") | |
1498 | ||
1499 | with alloc_fail(hapd, 1, "eap_gtc_buildReq"): | |
1500 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1501 | eap="TTLS", identity="user", | |
1502 | anonymous_identity="ttls", password="password", | |
1503 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC", | |
1504 | wait_connect=False, scan_freq="2412") | |
1505 | # This would eventually time out, but we can stop after having reached | |
1506 | # the allocation failure. | |
1507 | for i in range(20): | |
1508 | time.sleep(0.1) | |
1509 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1510 | break | |
1511 | ||
ac713c09 JM |
1512 | def test_ap_wpa2_eap_ttls_eap_gtc_oom(dev, apdev): |
1513 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC (OOM)""" | |
1514 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 1515 | hapd = hostapd.add_ap(apdev[0], params) |
ac713c09 JM |
1516 | |
1517 | tests = [ "eap_gtc_init", | |
1518 | "eap_msg_alloc;eap_gtc_process" ] | |
1519 | for func in tests: | |
1520 | with alloc_fail(dev[0], 1, func): | |
1521 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", | |
1522 | scan_freq="2412", | |
1523 | eap="TTLS", identity="user", | |
1524 | anonymous_identity="ttls", password="password", | |
1525 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC", | |
1526 | wait_connect=False) | |
1527 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
1528 | dev[0].request("REMOVE_NETWORK all") | |
1529 | dev[0].wait_disconnected() | |
1530 | ||
9626962d JM |
1531 | def test_ap_wpa2_eap_ttls_eap_md5(dev, apdev): |
1532 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5""" | |
e7ac04ce | 1533 | check_eap_capa(dev[0], "MD5") |
9626962d | 1534 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1535 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1536 | eap_connect(dev[0], hapd, "TTLS", "user", |
9626962d JM |
1537 | anonymous_identity="ttls", password="password", |
1538 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5") | |
a8375c94 | 1539 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1540 | eap_reauth(dev[0], "TTLS") |
9626962d | 1541 | |
ee9533eb JM |
1542 | def test_ap_wpa2_eap_ttls_eap_md5_incorrect_password(dev, apdev): |
1543 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - incorrect password""" | |
e7ac04ce | 1544 | check_eap_capa(dev[0], "MD5") |
ee9533eb | 1545 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1546 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1547 | eap_connect(dev[0], hapd, "TTLS", "user", |
ee9533eb JM |
1548 | anonymous_identity="ttls", password="wrong", |
1549 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1550 | expect_failure=True) | |
1551 | ||
95a15d79 JM |
1552 | def test_ap_wpa2_eap_ttls_eap_md5_no_password(dev, apdev): |
1553 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - no password""" | |
e7ac04ce | 1554 | check_eap_capa(dev[0], "MD5") |
95a15d79 | 1555 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1556 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1557 | eap_connect(dev[0], hapd, "TTLS", "user-no-passwd", |
95a15d79 JM |
1558 | anonymous_identity="ttls", password="password", |
1559 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1560 | expect_failure=True) | |
1561 | ||
ee9533eb JM |
1562 | def test_ap_wpa2_eap_ttls_eap_md5_server_oom(dev, apdev): |
1563 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - server OOM""" | |
e7ac04ce | 1564 | check_eap_capa(dev[0], "MD5") |
ee9533eb | 1565 | params = int_eap_server_params() |
8b8a1864 | 1566 | hapd = hostapd.add_ap(apdev[0], params) |
ee9533eb | 1567 | with alloc_fail(hapd, 1, "eap_md5_init"): |
3b3e2687 | 1568 | eap_connect(dev[0], hapd, "TTLS", "user", |
ee9533eb JM |
1569 | anonymous_identity="ttls", password="password", |
1570 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1571 | expect_failure=True) | |
1572 | dev[0].request("REMOVE_NETWORK all") | |
1573 | ||
1574 | with alloc_fail(hapd, 1, "eap_md5_buildReq"): | |
1575 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1576 | eap="TTLS", identity="user", | |
1577 | anonymous_identity="ttls", password="password", | |
1578 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1579 | wait_connect=False, scan_freq="2412") | |
1580 | # This would eventually time out, but we can stop after having reached | |
1581 | # the allocation failure. | |
1582 | for i in range(20): | |
1583 | time.sleep(0.1) | |
1584 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1585 | break | |
1586 | ||
9626962d JM |
1587 | def test_ap_wpa2_eap_ttls_eap_mschapv2(dev, apdev): |
1588 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2""" | |
e7ac04ce | 1589 | check_eap_capa(dev[0], "MSCHAPV2") |
9626962d | 1590 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1591 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1592 | eap_connect(dev[0], hapd, "TTLS", "user", |
9626962d JM |
1593 | anonymous_identity="ttls", password="password", |
1594 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2") | |
a8375c94 | 1595 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1596 | eap_reauth(dev[0], "TTLS") |
9626962d | 1597 | |
f10ba3b2 JM |
1598 | logger.info("Negative test with incorrect password") |
1599 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 1600 | eap_connect(dev[0], hapd, "TTLS", "user", |
f10ba3b2 JM |
1601 | anonymous_identity="ttls", password="password1", |
1602 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1603 | expect_failure=True) | |
1604 | ||
95a15d79 JM |
1605 | def test_ap_wpa2_eap_ttls_eap_mschapv2_no_password(dev, apdev): |
1606 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2 - no password""" | |
e7ac04ce | 1607 | check_eap_capa(dev[0], "MSCHAPV2") |
95a15d79 | 1608 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1609 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1610 | eap_connect(dev[0], hapd, "TTLS", "user-no-passwd", |
95a15d79 JM |
1611 | anonymous_identity="ttls", password="password", |
1612 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1613 | expect_failure=True) | |
1614 | ||
ef318402 JM |
1615 | def test_ap_wpa2_eap_ttls_eap_mschapv2_server_oom(dev, apdev): |
1616 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2 - server OOM""" | |
e7ac04ce | 1617 | check_eap_capa(dev[0], "MSCHAPV2") |
ef318402 | 1618 | params = int_eap_server_params() |
8b8a1864 | 1619 | hapd = hostapd.add_ap(apdev[0], params) |
ef318402 | 1620 | with alloc_fail(hapd, 1, "eap_mschapv2_init"): |
3b3e2687 | 1621 | eap_connect(dev[0], hapd, "TTLS", "user", |
ef318402 JM |
1622 | anonymous_identity="ttls", password="password", |
1623 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1624 | expect_failure=True) | |
1625 | dev[0].request("REMOVE_NETWORK all") | |
1626 | ||
1627 | with alloc_fail(hapd, 1, "eap_mschapv2_build_challenge"): | |
1628 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1629 | eap="TTLS", identity="user", | |
1630 | anonymous_identity="ttls", password="password", | |
1631 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1632 | wait_connect=False, scan_freq="2412") | |
1633 | # This would eventually time out, but we can stop after having reached | |
1634 | # the allocation failure. | |
1635 | for i in range(20): | |
1636 | time.sleep(0.1) | |
1637 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1638 | break | |
1639 | dev[0].request("REMOVE_NETWORK all") | |
1640 | ||
1641 | with alloc_fail(hapd, 1, "eap_mschapv2_build_success_req"): | |
1642 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1643 | eap="TTLS", identity="user", | |
1644 | anonymous_identity="ttls", password="password", | |
1645 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1646 | wait_connect=False, scan_freq="2412") | |
1647 | # This would eventually time out, but we can stop after having reached | |
1648 | # the allocation failure. | |
1649 | for i in range(20): | |
1650 | time.sleep(0.1) | |
1651 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1652 | break | |
1653 | dev[0].request("REMOVE_NETWORK all") | |
1654 | ||
1655 | with alloc_fail(hapd, 1, "eap_mschapv2_build_failure_req"): | |
1656 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1657 | eap="TTLS", identity="user", | |
1658 | anonymous_identity="ttls", password="wrong", | |
1659 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1660 | wait_connect=False, scan_freq="2412") | |
1661 | # This would eventually time out, but we can stop after having reached | |
1662 | # the allocation failure. | |
1663 | for i in range(20): | |
1664 | time.sleep(0.1) | |
1665 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1666 | break | |
1667 | dev[0].request("REMOVE_NETWORK all") | |
1668 | ||
f22bc118 JM |
1669 | def test_ap_wpa2_eap_ttls_eap_sim(dev, apdev): |
1670 | """WPA2-Enterprise connection using EAP-TTLS/EAP-SIM""" | |
1671 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1672 | hapd = hostapd.add_ap(apdev[0], params) | |
1673 | eap_connect(dev[0], hapd, "TTLS", "1232010000000000", | |
1674 | anonymous_identity="1232010000000000@ttls", | |
1675 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
1676 | ca_cert="auth_serv/ca.pem", phase2="autheap=SIM") | |
1677 | eap_reauth(dev[0], "TTLS") | |
1678 | ||
1679 | def run_ext_sim_auth(dev): | |
1680 | ev = dev.wait_event(["CTRL-REQ-SIM"], timeout=15) | |
1681 | if ev is None: | |
1682 | raise Exception("Wait for external SIM processing request timed out") | |
1683 | p = ev.split(':', 2) | |
1684 | if p[1] != "GSM-AUTH": | |
1685 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
1686 | rid = p[0].split('-')[3] | |
1687 | rand = p[2].split(' ')[0] | |
1688 | ||
1689 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
1690 | "-m", | |
1691 | "auth_serv/hlr_auc_gw.milenage_db", | |
1692 | "GSM-AUTH-REQ 232010000000000 " + rand]) | |
1693 | if "GSM-AUTH-RESP" not in res: | |
1694 | raise Exception("Unexpected hlr_auc_gw response") | |
1695 | resp = res.split(' ')[2].rstrip() | |
1696 | ||
1697 | dev.request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
1698 | dev.wait_connected(timeout=15) | |
1699 | ||
1700 | dev.dump_monitor() | |
1701 | dev.request("REAUTHENTICATE") | |
1702 | ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5) | |
1703 | if ev is None: | |
1704 | raise Exception("EAP reauthentication did not succeed") | |
1705 | ev = dev.wait_event(["WPA: Key negotiation completed"], timeout=5) | |
1706 | if ev is None: | |
1707 | raise Exception("Key negotiation did not complete") | |
1708 | dev.dump_monitor() | |
1709 | ||
1710 | def test_ap_wpa2_eap_ttls_eap_sim_ext(dev, apdev): | |
1711 | """WPA2-Enterprise connection using EAP-TTLS/EAP-SIM and external GSM auth""" | |
1712 | check_hlr_auc_gw_support() | |
1713 | try: | |
1714 | run_ap_wpa2_eap_ttls_eap_sim_ext(dev, apdev) | |
1715 | finally: | |
1716 | dev[0].request("SET external_sim 0") | |
1717 | ||
1718 | def run_ap_wpa2_eap_ttls_eap_sim_ext(dev, apdev): | |
1719 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1720 | hapd = hostapd.add_ap(apdev[0], params) | |
1721 | dev[0].request("SET external_sim 1") | |
1722 | dev[0].connect("test-wpa2-eap", eap="TTLS", key_mgmt="WPA-EAP", | |
1723 | identity="1232010000000000", | |
1724 | anonymous_identity="1232010000000000@ttls", | |
1725 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
1726 | ca_cert="auth_serv/ca.pem", phase2="autheap=SIM", | |
1727 | wait_connect=False, scan_freq="2412") | |
1728 | run_ext_sim_auth(dev[0]) | |
1729 | ||
1730 | def test_ap_wpa2_eap_peap_eap_sim(dev, apdev): | |
1731 | """WPA2-Enterprise connection using EAP-PEAP/EAP-SIM""" | |
1732 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1733 | hapd = hostapd.add_ap(apdev[0], params) | |
1734 | eap_connect(dev[0], hapd, "PEAP", "1232010000000000", | |
1735 | anonymous_identity="1232010000000000@peap", | |
1736 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
1737 | ca_cert="auth_serv/ca.pem", phase2="auth=SIM") | |
1738 | eap_reauth(dev[0], "PEAP") | |
1739 | ||
1740 | def test_ap_wpa2_eap_peap_eap_sim_ext(dev, apdev): | |
1741 | """WPA2-Enterprise connection using EAP-PEAP/EAP-SIM and external GSM auth""" | |
1742 | check_hlr_auc_gw_support() | |
1743 | try: | |
1744 | run_ap_wpa2_eap_peap_eap_sim_ext(dev, apdev) | |
1745 | finally: | |
1746 | dev[0].request("SET external_sim 0") | |
1747 | ||
1748 | def run_ap_wpa2_eap_peap_eap_sim_ext(dev, apdev): | |
1749 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1750 | hapd = hostapd.add_ap(apdev[0], params) | |
1751 | dev[0].request("SET external_sim 1") | |
1752 | dev[0].connect("test-wpa2-eap", eap="PEAP", key_mgmt="WPA-EAP", | |
1753 | identity="1232010000000000", | |
1754 | anonymous_identity="1232010000000000@peap", | |
1755 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
1756 | ca_cert="auth_serv/ca.pem", phase2="auth=SIM", | |
1757 | wait_connect=False, scan_freq="2412") | |
1758 | run_ext_sim_auth(dev[0]) | |
1759 | ||
1760 | def test_ap_wpa2_eap_fast_eap_sim(dev, apdev): | |
1761 | """WPA2-Enterprise connection using EAP-FAST/EAP-SIM""" | |
1762 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1763 | hapd = hostapd.add_ap(apdev[0], params) | |
1764 | eap_connect(dev[0], hapd, "FAST", "1232010000000000", | |
1765 | anonymous_identity="1232010000000000@fast", | |
1766 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
1767 | phase1="fast_provisioning=2", | |
1768 | pac_file="blob://fast_pac_auth_sim", | |
1769 | ca_cert="auth_serv/ca.pem", phase2="auth=SIM") | |
1770 | eap_reauth(dev[0], "FAST") | |
1771 | ||
1772 | def test_ap_wpa2_eap_fast_eap_sim_ext(dev, apdev): | |
1773 | """WPA2-Enterprise connection using EAP-FAST/EAP-SIM and external GSM auth""" | |
1774 | check_hlr_auc_gw_support() | |
1775 | try: | |
1776 | run_ap_wpa2_eap_fast_eap_sim_ext(dev, apdev) | |
1777 | finally: | |
1778 | dev[0].request("SET external_sim 0") | |
1779 | ||
1780 | def run_ap_wpa2_eap_fast_eap_sim_ext(dev, apdev): | |
1781 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1782 | hapd = hostapd.add_ap(apdev[0], params) | |
1783 | dev[0].request("SET external_sim 1") | |
1784 | dev[0].connect("test-wpa2-eap", eap="PEAP", key_mgmt="WPA-EAP", | |
1785 | identity="1232010000000000", | |
1786 | anonymous_identity="1232010000000000@peap", | |
1787 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
1788 | phase1="fast_provisioning=2", | |
1789 | pac_file="blob://fast_pac_auth_sim", | |
1790 | ca_cert="auth_serv/ca.pem", phase2="auth=SIM", | |
1791 | wait_connect=False, scan_freq="2412") | |
1792 | run_ext_sim_auth(dev[0]) | |
1793 | ||
95fb531c JM |
1794 | def test_ap_wpa2_eap_ttls_eap_aka(dev, apdev): |
1795 | """WPA2-Enterprise connection using EAP-TTLS/EAP-AKA""" | |
1796 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
1797 | hapd = hostapd.add_ap(apdev[0], params) |
1798 | eap_connect(dev[0], hapd, "TTLS", "0232010000000000", | |
95fb531c JM |
1799 | anonymous_identity="0232010000000000@ttls", |
1800 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1801 | ca_cert="auth_serv/ca.pem", phase2="autheap=AKA") | |
8a303f09 | 1802 | eap_reauth(dev[0], "TTLS") |
95fb531c JM |
1803 | |
1804 | def test_ap_wpa2_eap_peap_eap_aka(dev, apdev): | |
1805 | """WPA2-Enterprise connection using EAP-PEAP/EAP-AKA""" | |
1806 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
1807 | hapd = hostapd.add_ap(apdev[0], params) |
1808 | eap_connect(dev[0], hapd, "PEAP", "0232010000000000", | |
95fb531c JM |
1809 | anonymous_identity="0232010000000000@peap", |
1810 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1811 | ca_cert="auth_serv/ca.pem", phase2="auth=AKA") | |
8a303f09 | 1812 | eap_reauth(dev[0], "PEAP") |
95fb531c JM |
1813 | |
1814 | def test_ap_wpa2_eap_fast_eap_aka(dev, apdev): | |
1815 | """WPA2-Enterprise connection using EAP-FAST/EAP-AKA""" | |
3b51cc63 | 1816 | check_eap_capa(dev[0], "FAST") |
95fb531c | 1817 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
1818 | hapd = hostapd.add_ap(apdev[0], params) |
1819 | eap_connect(dev[0], hapd, "FAST", "0232010000000000", | |
95fb531c JM |
1820 | anonymous_identity="0232010000000000@fast", |
1821 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1822 | phase1="fast_provisioning=2", | |
1823 | pac_file="blob://fast_pac_auth_aka", | |
1824 | ca_cert="auth_serv/ca.pem", phase2="auth=AKA") | |
8a303f09 | 1825 | eap_reauth(dev[0], "FAST") |
95fb531c | 1826 | |
9626962d JM |
1827 | def test_ap_wpa2_eap_peap_eap_mschapv2(dev, apdev): |
1828 | """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2""" | |
e7ac04ce | 1829 | check_eap_capa(dev[0], "MSCHAPV2") |
9626962d | 1830 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1831 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1832 | eap_connect(dev[0], hapd, "PEAP", "user", |
698f8324 | 1833 | anonymous_identity="peap", password="password", |
9626962d | 1834 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") |
a8375c94 | 1835 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1836 | eap_reauth(dev[0], "PEAP") |
6daf5b9c | 1837 | dev[0].request("REMOVE_NETWORK all") |
3b3e2687 | 1838 | eap_connect(dev[0], hapd, "PEAP", "user", |
6daf5b9c JM |
1839 | anonymous_identity="peap", password="password", |
1840 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1841 | fragment_size="200") | |
c7afc078 | 1842 | |
fa0ddb14 JM |
1843 | logger.info("Password as hash value") |
1844 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 1845 | eap_connect(dev[0], hapd, "PEAP", "user", |
fa0ddb14 JM |
1846 | anonymous_identity="peap", |
1847 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
1848 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
1849 | ||
f10ba3b2 JM |
1850 | logger.info("Negative test with incorrect password") |
1851 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 1852 | eap_connect(dev[0], hapd, "PEAP", "user", |
f10ba3b2 JM |
1853 | anonymous_identity="peap", password="password1", |
1854 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1855 | expect_failure=True) | |
1856 | ||
0d33f504 JM |
1857 | def test_ap_wpa2_eap_peap_eap_mschapv2_domain(dev, apdev): |
1858 | """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2 with domain""" | |
e7ac04ce | 1859 | check_eap_capa(dev[0], "MSCHAPV2") |
0d33f504 | 1860 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1861 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1862 | eap_connect(dev[0], hapd, "PEAP", "DOMAIN\user3", |
0d33f504 JM |
1863 | anonymous_identity="peap", password="password", |
1864 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
1865 | hwsim_utils.test_connectivity(dev[0], hapd) | |
1866 | eap_reauth(dev[0], "PEAP") | |
1867 | ||
f4cd0f64 JM |
1868 | def test_ap_wpa2_eap_peap_eap_mschapv2_incorrect_password(dev, apdev): |
1869 | """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2 - incorrect password""" | |
e7ac04ce | 1870 | check_eap_capa(dev[0], "MSCHAPV2") |
f4cd0f64 | 1871 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1872 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1873 | eap_connect(dev[0], hapd, "PEAP", "user", |
f4cd0f64 JM |
1874 | anonymous_identity="peap", password="wrong", |
1875 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1876 | expect_failure=True) | |
1877 | ||
698f8324 JM |
1878 | def test_ap_wpa2_eap_peap_crypto_binding(dev, apdev): |
1879 | """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding""" | |
e7ac04ce | 1880 | check_eap_capa(dev[0], "MSCHAPV2") |
698f8324 | 1881 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 1882 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 1883 | eap_connect(dev[0], hapd, "PEAP", "user", password="password", |
698f8324 JM |
1884 | ca_cert="auth_serv/ca.pem", |
1885 | phase1="peapver=0 crypto_binding=2", | |
1886 | phase2="auth=MSCHAPV2") | |
a8375c94 | 1887 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1888 | eap_reauth(dev[0], "PEAP") |
698f8324 | 1889 | |
3b3e2687 | 1890 | eap_connect(dev[1], hapd, "PEAP", "user", password="password", |
ea6464b0 JM |
1891 | ca_cert="auth_serv/ca.pem", |
1892 | phase1="peapver=0 crypto_binding=1", | |
1893 | phase2="auth=MSCHAPV2") | |
3b3e2687 | 1894 | eap_connect(dev[2], hapd, "PEAP", "user", password="password", |
ea6464b0 JM |
1895 | ca_cert="auth_serv/ca.pem", |
1896 | phase1="peapver=0 crypto_binding=0", | |
1897 | phase2="auth=MSCHAPV2") | |
1898 | ||
ef318402 JM |
1899 | def test_ap_wpa2_eap_peap_crypto_binding_server_oom(dev, apdev): |
1900 | """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding with server OOM""" | |
e7ac04ce | 1901 | check_eap_capa(dev[0], "MSCHAPV2") |
ef318402 | 1902 | params = int_eap_server_params() |
8b8a1864 | 1903 | hapd = hostapd.add_ap(apdev[0], params) |
ef318402 | 1904 | with alloc_fail(hapd, 1, "eap_mschapv2_getKey"): |
3b3e2687 | 1905 | eap_connect(dev[0], hapd, "PEAP", "user", password="password", |
ef318402 JM |
1906 | ca_cert="auth_serv/ca.pem", |
1907 | phase1="peapver=0 crypto_binding=2", | |
1908 | phase2="auth=MSCHAPV2", | |
1909 | expect_failure=True, local_error_report=True) | |
1910 | ||
c4d37011 JM |
1911 | def test_ap_wpa2_eap_peap_params(dev, apdev): |
1912 | """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and various parameters""" | |
e7ac04ce | 1913 | check_eap_capa(dev[0], "MSCHAPV2") |
c4d37011 | 1914 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
1915 | hapd = hostapd.add_ap(apdev[0], params) |
1916 | eap_connect(dev[0], hapd, "PEAP", "user", | |
c4d37011 JM |
1917 | anonymous_identity="peap", password="password", |
1918 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1919 | phase1="peapver=0 peaplabel=1", | |
1920 | expect_failure=True) | |
1921 | dev[0].request("REMOVE_NETWORK all") | |
09ad98c5 JM |
1922 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", |
1923 | identity="user", | |
1924 | anonymous_identity="peap", password="password", | |
1925 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1926 | phase1="peap_outer_success=0", | |
1927 | wait_connect=False, scan_freq="2412") | |
1928 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) | |
1929 | if ev is None: | |
1930 | raise Exception("No EAP success seen") | |
1931 | # This won't succeed to connect with peap_outer_success=0, so stop here. | |
1932 | dev[0].request("REMOVE_NETWORK all") | |
1933 | dev[0].wait_disconnected() | |
3b3e2687 | 1934 | eap_connect(dev[1], hapd, "PEAP", "user", password="password", |
c4d37011 JM |
1935 | ca_cert="auth_serv/ca.pem", |
1936 | phase1="peap_outer_success=1", | |
1937 | phase2="auth=MSCHAPV2") | |
3b3e2687 | 1938 | eap_connect(dev[2], hapd, "PEAP", "user", password="password", |
c4d37011 JM |
1939 | ca_cert="auth_serv/ca.pem", |
1940 | phase1="peap_outer_success=2", | |
1941 | phase2="auth=MSCHAPV2") | |
1942 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
1943 | identity="user", | |
1944 | anonymous_identity="peap", password="password", | |
1945 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1946 | phase1="peapver=1 peaplabel=1", | |
1947 | wait_connect=False, scan_freq="2412") | |
1948 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) | |
1949 | if ev is None: | |
1950 | raise Exception("No EAP success seen") | |
1951 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1) | |
1952 | if ev is not None: | |
1953 | raise Exception("Unexpected connection") | |
1954 | ||
09a4404a JM |
1955 | tests = [ ("peap-ver0", ""), |
1956 | ("peap-ver1", ""), | |
1957 | ("peap-ver0", "peapver=0"), | |
1958 | ("peap-ver1", "peapver=1") ] | |
1959 | for anon,phase1 in tests: | |
1960 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
1961 | identity="user", anonymous_identity=anon, | |
1962 | password="password", phase1=phase1, | |
1963 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1964 | scan_freq="2412") | |
1965 | dev[0].request("REMOVE_NETWORK all") | |
1966 | dev[0].wait_disconnected() | |
1967 | ||
1968 | tests = [ ("peap-ver0", "peapver=1"), | |
1969 | ("peap-ver1", "peapver=0") ] | |
1970 | for anon,phase1 in tests: | |
1971 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
1972 | identity="user", anonymous_identity=anon, | |
1973 | password="password", phase1=phase1, | |
1974 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1975 | wait_connect=False, scan_freq="2412") | |
1976 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
1977 | if ev is None: | |
1978 | raise Exception("No EAP-Failure seen") | |
1979 | dev[0].request("REMOVE_NETWORK all") | |
1980 | dev[0].wait_disconnected() | |
1981 | ||
3b3e2687 | 1982 | eap_connect(dev[0], hapd, "PEAP", "user", password="password", |
d5f5d260 JM |
1983 | ca_cert="auth_serv/ca.pem", |
1984 | 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", | |
1985 | phase2="auth=MSCHAPV2") | |
1986 | ||
d0ce1050 JM |
1987 | def test_ap_wpa2_eap_peap_eap_tls(dev, apdev): |
1988 | """WPA2-Enterprise connection using EAP-PEAP/EAP-TLS""" | |
1989 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
1990 | hapd = hostapd.add_ap(apdev[0], params) |
1991 | eap_connect(dev[0], hapd, "PEAP", "cert user", | |
d0ce1050 JM |
1992 | ca_cert="auth_serv/ca.pem", phase2="auth=TLS", |
1993 | ca_cert2="auth_serv/ca.pem", | |
1994 | client_cert2="auth_serv/user.pem", | |
1995 | private_key2="auth_serv/user.key") | |
1996 | eap_reauth(dev[0], "PEAP") | |
1997 | ||
e114c49c JM |
1998 | def test_ap_wpa2_eap_tls(dev, apdev): |
1999 | """WPA2-Enterprise connection using EAP-TLS""" | |
2000 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
2001 | hapd = hostapd.add_ap(apdev[0], params) |
2002 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
e114c49c JM |
2003 | client_cert="auth_serv/user.pem", |
2004 | private_key="auth_serv/user.key") | |
75b2b9cf | 2005 | eap_reauth(dev[0], "TLS") |
e114c49c | 2006 | |
96bf8fe1 JM |
2007 | def test_eap_tls_pkcs8_pkcs5_v2_des3(dev, apdev): |
2008 | """WPA2-Enterprise connection using EAP-TLS and PKCS #8, PKCS #5 v2 DES3 key""" | |
2009 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
2010 | hapd = hostapd.add_ap(apdev[0], params) |
2011 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
96bf8fe1 JM |
2012 | client_cert="auth_serv/user.pem", |
2013 | private_key="auth_serv/user.key.pkcs8", | |
2014 | private_key_passwd="whatever") | |
2015 | ||
2016 | def test_eap_tls_pkcs8_pkcs5_v15(dev, apdev): | |
2017 | """WPA2-Enterprise connection using EAP-TLS and PKCS #8, PKCS #5 v1.5 key""" | |
969e5250 | 2018 | check_pkcs5_v15_support(dev[0]) |
96bf8fe1 | 2019 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
2020 | hapd = hostapd.add_ap(apdev[0], params) |
2021 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
96bf8fe1 JM |
2022 | client_cert="auth_serv/user.pem", |
2023 | private_key="auth_serv/user.key.pkcs8.pkcs5v15", | |
2024 | private_key_passwd="whatever") | |
2025 | ||
6ea231e6 JM |
2026 | def test_ap_wpa2_eap_tls_blob(dev, apdev): |
2027 | """WPA2-Enterprise connection using EAP-TLS and config blobs""" | |
2028 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 | 2029 | hapd = hostapd.add_ap(apdev[0], params) |
6ea231e6 JM |
2030 | cert = read_pem("auth_serv/ca.pem") |
2031 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
2032 | raise Exception("Could not set cacert blob") | |
2033 | cert = read_pem("auth_serv/user.pem") | |
2034 | if "OK" not in dev[0].request("SET blob usercert " + cert.encode("hex")): | |
2035 | raise Exception("Could not set usercert blob") | |
62750c3e | 2036 | key = read_pem("auth_serv/user.rsa-key") |
6ea231e6 JM |
2037 | if "OK" not in dev[0].request("SET blob userkey " + key.encode("hex")): |
2038 | raise Exception("Could not set cacert blob") | |
3b3e2687 | 2039 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="blob://cacert", |
6ea231e6 JM |
2040 | client_cert="blob://usercert", |
2041 | private_key="blob://userkey") | |
2042 | ||
cef42a44 JM |
2043 | def test_ap_wpa2_eap_tls_blob_missing(dev, apdev): |
2044 | """EAP-TLS and config blob missing""" | |
2045 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 2046 | hostapd.add_ap(apdev[0], params) |
cef42a44 JM |
2047 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
2048 | identity="tls user", | |
2049 | ca_cert="blob://testing-blob-does-not-exist", | |
2050 | client_cert="blob://testing-blob-does-not-exist", | |
2051 | private_key="blob://testing-blob-does-not-exist", | |
2052 | wait_connect=False, scan_freq="2412") | |
2053 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], timeout=10) | |
2054 | if ev is None: | |
2055 | raise Exception("EAP failure not reported") | |
2056 | dev[0].request("REMOVE_NETWORK all") | |
2057 | dev[0].wait_disconnected() | |
2058 | ||
7cb27f89 JM |
2059 | def test_ap_wpa2_eap_tls_with_tls_len(dev, apdev): |
2060 | """EAP-TLS and TLS Message Length in unfragmented packets""" | |
2061 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
2062 | hapd = hostapd.add_ap(apdev[0], params) |
2063 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
7cb27f89 JM |
2064 | phase1="include_tls_length=1", |
2065 | client_cert="auth_serv/user.pem", | |
2066 | private_key="auth_serv/user.key") | |
2067 | ||
2d10eb0e JM |
2068 | def test_ap_wpa2_eap_tls_pkcs12(dev, apdev): |
2069 | """WPA2-Enterprise connection using EAP-TLS and PKCS#12""" | |
686eee77 | 2070 | check_pkcs12_support(dev[0]) |
2d10eb0e | 2071 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
2072 | hapd = hostapd.add_ap(apdev[0], params) |
2073 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
2d10eb0e JM |
2074 | private_key="auth_serv/user.pkcs12", |
2075 | private_key_passwd="whatever") | |
2076 | dev[0].request("REMOVE_NETWORK all") | |
0c83ae04 JM |
2077 | dev[0].wait_disconnected() |
2078 | ||
2d10eb0e JM |
2079 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
2080 | identity="tls user", | |
2081 | ca_cert="auth_serv/ca.pem", | |
2082 | private_key="auth_serv/user.pkcs12", | |
2083 | wait_connect=False, scan_freq="2412") | |
2084 | ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"]) | |
2085 | if ev is None: | |
2086 | raise Exception("Request for private key passphrase timed out") | |
2087 | id = ev.split(':')[0].split('-')[-1] | |
2088 | dev[0].request("CTRL-RSP-PASSPHRASE-" + id + ":whatever") | |
5f35a5e2 | 2089 | dev[0].wait_connected(timeout=10) |
0c83ae04 JM |
2090 | dev[0].request("REMOVE_NETWORK all") |
2091 | dev[0].wait_disconnected() | |
2092 | ||
6da3b745 JM |
2093 | # Run this twice to verify certificate chain handling with OpenSSL. Use two |
2094 | # different files to cover both cases of the extra certificate being the | |
2095 | # one that signed the client certificate and it being unrelated to the | |
2096 | # client certificate. | |
2097 | for pkcs12 in "auth_serv/user2.pkcs12", "auth_serv/user3.pkcs12": | |
2098 | for i in range(2): | |
3b3e2687 | 2099 | eap_connect(dev[0], hapd, "TLS", "tls user", |
6da3b745 JM |
2100 | ca_cert="auth_serv/ca.pem", |
2101 | private_key=pkcs12, | |
2102 | private_key_passwd="whatever") | |
2103 | dev[0].request("REMOVE_NETWORK all") | |
2104 | dev[0].wait_disconnected() | |
2d10eb0e | 2105 | |
6ea231e6 JM |
2106 | def test_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev): |
2107 | """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob""" | |
686eee77 | 2108 | check_pkcs12_support(dev[0]) |
6ea231e6 | 2109 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 | 2110 | hapd = hostapd.add_ap(apdev[0], params) |
6ea231e6 JM |
2111 | cert = read_pem("auth_serv/ca.pem") |
2112 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
2113 | raise Exception("Could not set cacert blob") | |
2114 | with open("auth_serv/user.pkcs12", "rb") as f: | |
2115 | if "OK" not in dev[0].request("SET blob pkcs12 " + f.read().encode("hex")): | |
2116 | raise Exception("Could not set pkcs12 blob") | |
3b3e2687 | 2117 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="blob://cacert", |
6ea231e6 JM |
2118 | private_key="blob://pkcs12", |
2119 | private_key_passwd="whatever") | |
2120 | ||
c7afc078 JM |
2121 | def test_ap_wpa2_eap_tls_neg_incorrect_trust_root(dev, apdev): |
2122 | """WPA2-Enterprise negative test - incorrect trust root""" | |
e7ac04ce | 2123 | check_eap_capa(dev[0], "MSCHAPV2") |
c7afc078 | 2124 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 2125 | hostapd.add_ap(apdev[0], params) |
6ea231e6 JM |
2126 | cert = read_pem("auth_serv/ca-incorrect.pem") |
2127 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
2128 | raise Exception("Could not set cacert blob") | |
c7afc078 | 2129 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
6ea231e6 JM |
2130 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", |
2131 | password="password", phase2="auth=MSCHAPV2", | |
2132 | ca_cert="blob://cacert", | |
2133 | wait_connect=False, scan_freq="2412") | |
2134 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
c7afc078 JM |
2135 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", |
2136 | password="password", phase2="auth=MSCHAPV2", | |
2137 | ca_cert="auth_serv/ca-incorrect.pem", | |
c65f23ab | 2138 | wait_connect=False, scan_freq="2412") |
c7afc078 | 2139 | |
6ea231e6 | 2140 | for dev in (dev[0], dev[1]): |
412c6030 | 2141 | ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
6ea231e6 JM |
2142 | if ev is None: |
2143 | raise Exception("Association and EAP start timed out") | |
c7afc078 | 2144 | |
6ea231e6 JM |
2145 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) |
2146 | if ev is None: | |
2147 | raise Exception("EAP method selection timed out") | |
2148 | if "TTLS" not in ev: | |
2149 | raise Exception("Unexpected EAP method") | |
2150 | ||
2151 | ev = dev.wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
2152 | "CTRL-EVENT-EAP-SUCCESS", | |
2153 | "CTRL-EVENT-EAP-FAILURE", | |
2154 | "CTRL-EVENT-CONNECTED", | |
2155 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2156 | if ev is None: | |
2157 | raise Exception("EAP result timed out") | |
2158 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
2159 | raise Exception("TLS certificate error not reported") | |
2160 | ||
2161 | ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
2162 | "CTRL-EVENT-EAP-FAILURE", | |
2163 | "CTRL-EVENT-CONNECTED", | |
2164 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2165 | if ev is None: | |
2166 | raise Exception("EAP result(2) timed out") | |
2167 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
2168 | raise Exception("EAP failure not reported") | |
c7afc078 | 2169 | |
6ea231e6 JM |
2170 | ev = dev.wait_event(["CTRL-EVENT-CONNECTED", |
2171 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2172 | if ev is None: | |
2173 | raise Exception("EAP result(3) timed out") | |
2174 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
2175 | raise Exception("Disconnection not reported") | |
c7afc078 | 2176 | |
6ea231e6 JM |
2177 | ev = dev.wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) |
2178 | if ev is None: | |
2179 | raise Exception("Network block disabling not reported") | |
72c052d5 | 2180 | |
9a5cfd70 JM |
2181 | def test_ap_wpa2_eap_tls_diff_ca_trust(dev, apdev): |
2182 | """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust""" | |
2183 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 2184 | hapd = hostapd.add_ap(apdev[0], params) |
9a5cfd70 JM |
2185 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
2186 | identity="pap user", anonymous_identity="ttls", | |
2187 | password="password", phase2="auth=PAP", | |
2188 | ca_cert="auth_serv/ca.pem", | |
2189 | wait_connect=True, scan_freq="2412") | |
2190 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2191 | identity="pap user", anonymous_identity="ttls", | |
2192 | password="password", phase2="auth=PAP", | |
2193 | ca_cert="auth_serv/ca-incorrect.pem", | |
2194 | only_add_network=True, scan_freq="2412") | |
2195 | ||
2196 | dev[0].request("DISCONNECT") | |
90ad11e6 | 2197 | dev[0].wait_disconnected() |
9a5cfd70 JM |
2198 | dev[0].dump_monitor() |
2199 | dev[0].select_network(id, freq="2412") | |
2200 | ||
2201 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15) | |
2202 | if ev is None: | |
2203 | raise Exception("EAP-TTLS not re-started") | |
db98b587 | 2204 | |
5f35a5e2 | 2205 | ev = dev[0].wait_disconnected(timeout=15) |
9a5cfd70 JM |
2206 | if "reason=23" not in ev: |
2207 | raise Exception("Proper reason code for disconnection not reported") | |
2208 | ||
2209 | def test_ap_wpa2_eap_tls_diff_ca_trust2(dev, apdev): | |
2210 | """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust""" | |
2211 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 2212 | hapd = hostapd.add_ap(apdev[0], params) |
9a5cfd70 JM |
2213 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
2214 | identity="pap user", anonymous_identity="ttls", | |
2215 | password="password", phase2="auth=PAP", | |
2216 | wait_connect=True, scan_freq="2412") | |
2217 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2218 | identity="pap user", anonymous_identity="ttls", | |
2219 | password="password", phase2="auth=PAP", | |
2220 | ca_cert="auth_serv/ca-incorrect.pem", | |
2221 | only_add_network=True, scan_freq="2412") | |
2222 | ||
2223 | dev[0].request("DISCONNECT") | |
90ad11e6 | 2224 | dev[0].wait_disconnected() |
9a5cfd70 JM |
2225 | dev[0].dump_monitor() |
2226 | dev[0].select_network(id, freq="2412") | |
2227 | ||
2228 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15) | |
2229 | if ev is None: | |
2230 | raise Exception("EAP-TTLS not re-started") | |
db98b587 | 2231 | |
5f35a5e2 | 2232 | ev = dev[0].wait_disconnected(timeout=15) |
9a5cfd70 JM |
2233 | if "reason=23" not in ev: |
2234 | raise Exception("Proper reason code for disconnection not reported") | |
2235 | ||
2236 | def test_ap_wpa2_eap_tls_diff_ca_trust3(dev, apdev): | |
2237 | """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust""" | |
2238 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 2239 | hapd = hostapd.add_ap(apdev[0], params) |
9a5cfd70 JM |
2240 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
2241 | identity="pap user", anonymous_identity="ttls", | |
2242 | password="password", phase2="auth=PAP", | |
2243 | ca_cert="auth_serv/ca.pem", | |
2244 | wait_connect=True, scan_freq="2412") | |
2245 | dev[0].request("DISCONNECT") | |
90ad11e6 | 2246 | dev[0].wait_disconnected() |
9a5cfd70 JM |
2247 | dev[0].dump_monitor() |
2248 | dev[0].set_network_quoted(id, "ca_cert", "auth_serv/ca-incorrect.pem") | |
2249 | dev[0].select_network(id, freq="2412") | |
2250 | ||
2251 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15) | |
2252 | if ev is None: | |
2253 | raise Exception("EAP-TTLS not re-started") | |
db98b587 | 2254 | |
5f35a5e2 | 2255 | ev = dev[0].wait_disconnected(timeout=15) |
9a5cfd70 JM |
2256 | if "reason=23" not in ev: |
2257 | raise Exception("Proper reason code for disconnection not reported") | |
2258 | ||
72c052d5 JM |
2259 | def test_ap_wpa2_eap_tls_neg_suffix_match(dev, apdev): |
2260 | """WPA2-Enterprise negative test - domain suffix mismatch""" | |
e78eb404 | 2261 | check_domain_suffix_match(dev[0]) |
72c052d5 | 2262 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 2263 | hostapd.add_ap(apdev[0], params) |
72c052d5 JM |
2264 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
2265 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
2266 | password="password", phase2="auth=MSCHAPV2", | |
2267 | ca_cert="auth_serv/ca.pem", | |
2268 | domain_suffix_match="incorrect.example.com", | |
c65f23ab | 2269 | wait_connect=False, scan_freq="2412") |
72c052d5 | 2270 | |
412c6030 | 2271 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
72c052d5 JM |
2272 | if ev is None: |
2273 | raise Exception("Association and EAP start timed out") | |
2274 | ||
2275 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
2276 | if ev is None: | |
2277 | raise Exception("EAP method selection timed out") | |
2278 | if "TTLS" not in ev: | |
2279 | raise Exception("Unexpected EAP method") | |
2280 | ||
2281 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
2282 | "CTRL-EVENT-EAP-SUCCESS", | |
2283 | "CTRL-EVENT-EAP-FAILURE", | |
2284 | "CTRL-EVENT-CONNECTED", | |
2285 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2286 | if ev is None: | |
2287 | raise Exception("EAP result timed out") | |
2288 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
2289 | raise Exception("TLS certificate error not reported") | |
2290 | if "Domain suffix mismatch" not in ev: | |
2291 | raise Exception("Domain suffix mismatch not reported") | |
2292 | ||
2293 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
2294 | "CTRL-EVENT-EAP-FAILURE", | |
2295 | "CTRL-EVENT-CONNECTED", | |
2296 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2297 | if ev is None: | |
2298 | raise Exception("EAP result(2) timed out") | |
2299 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
2300 | raise Exception("EAP failure not reported") | |
2301 | ||
2302 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
2303 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2304 | if ev is None: | |
2305 | raise Exception("EAP result(3) timed out") | |
2306 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
2307 | raise Exception("Disconnection not reported") | |
2308 | ||
2309 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
2310 | if ev is None: | |
2311 | raise Exception("Network block disabling not reported") | |
22b99086 | 2312 | |
061cbb25 JM |
2313 | def test_ap_wpa2_eap_tls_neg_domain_match(dev, apdev): |
2314 | """WPA2-Enterprise negative test - domain mismatch""" | |
e78eb404 | 2315 | check_domain_match(dev[0]) |
061cbb25 | 2316 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 2317 | hostapd.add_ap(apdev[0], params) |
061cbb25 JM |
2318 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
2319 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
2320 | password="password", phase2="auth=MSCHAPV2", | |
2321 | ca_cert="auth_serv/ca.pem", | |
2322 | domain_match="w1.fi", | |
2323 | wait_connect=False, scan_freq="2412") | |
2324 | ||
412c6030 | 2325 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
061cbb25 JM |
2326 | if ev is None: |
2327 | raise Exception("Association and EAP start timed out") | |
2328 | ||
2329 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
2330 | if ev is None: | |
2331 | raise Exception("EAP method selection timed out") | |
2332 | if "TTLS" not in ev: | |
2333 | raise Exception("Unexpected EAP method") | |
2334 | ||
2335 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
2336 | "CTRL-EVENT-EAP-SUCCESS", | |
2337 | "CTRL-EVENT-EAP-FAILURE", | |
2338 | "CTRL-EVENT-CONNECTED", | |
2339 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2340 | if ev is None: | |
2341 | raise Exception("EAP result timed out") | |
2342 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
2343 | raise Exception("TLS certificate error not reported") | |
2344 | if "Domain mismatch" not in ev: | |
2345 | raise Exception("Domain mismatch not reported") | |
2346 | ||
2347 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
2348 | "CTRL-EVENT-EAP-FAILURE", | |
2349 | "CTRL-EVENT-CONNECTED", | |
2350 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2351 | if ev is None: | |
2352 | raise Exception("EAP result(2) timed out") | |
2353 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
2354 | raise Exception("EAP failure not reported") | |
2355 | ||
2356 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
2357 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2358 | if ev is None: | |
2359 | raise Exception("EAP result(3) timed out") | |
2360 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
2361 | raise Exception("Disconnection not reported") | |
2362 | ||
2363 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
2364 | if ev is None: | |
2365 | raise Exception("Network block disabling not reported") | |
2366 | ||
3b74982f JM |
2367 | def test_ap_wpa2_eap_tls_neg_subject_match(dev, apdev): |
2368 | """WPA2-Enterprise negative test - subject mismatch""" | |
2369 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 2370 | hostapd.add_ap(apdev[0], params) |
3b74982f JM |
2371 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
2372 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
2373 | password="password", phase2="auth=MSCHAPV2", | |
2374 | ca_cert="auth_serv/ca.pem", | |
2375 | subject_match="/C=FI/O=w1.fi/CN=example.com", | |
2376 | wait_connect=False, scan_freq="2412") | |
2377 | ||
412c6030 | 2378 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
3b74982f JM |
2379 | if ev is None: |
2380 | raise Exception("Association and EAP start timed out") | |
2381 | ||
506b2f05 JM |
2382 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD", |
2383 | "EAP: Failed to initialize EAP method"], timeout=10) | |
3b74982f JM |
2384 | if ev is None: |
2385 | raise Exception("EAP method selection timed out") | |
506b2f05 JM |
2386 | if "EAP: Failed to initialize EAP method" in ev: |
2387 | tls = dev[0].request("GET tls_library") | |
2388 | if tls.startswith("OpenSSL"): | |
2389 | raise Exception("Failed to select EAP method") | |
2390 | logger.info("subject_match not supported - connection failed, so test succeeded") | |
2391 | return | |
3b74982f JM |
2392 | if "TTLS" not in ev: |
2393 | raise Exception("Unexpected EAP method") | |
2394 | ||
2395 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
2396 | "CTRL-EVENT-EAP-SUCCESS", | |
2397 | "CTRL-EVENT-EAP-FAILURE", | |
2398 | "CTRL-EVENT-CONNECTED", | |
2399 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2400 | if ev is None: | |
2401 | raise Exception("EAP result timed out") | |
2402 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
2403 | raise Exception("TLS certificate error not reported") | |
2404 | if "Subject mismatch" not in ev: | |
2405 | raise Exception("Subject mismatch not reported") | |
2406 | ||
2407 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
2408 | "CTRL-EVENT-EAP-FAILURE", | |
2409 | "CTRL-EVENT-CONNECTED", | |
2410 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2411 | if ev is None: | |
2412 | raise Exception("EAP result(2) timed out") | |
2413 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
2414 | raise Exception("EAP failure not reported") | |
2415 | ||
2416 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
2417 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2418 | if ev is None: | |
2419 | raise Exception("EAP result(3) timed out") | |
2420 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
2421 | raise Exception("Disconnection not reported") | |
2422 | ||
2423 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
2424 | if ev is None: | |
2425 | raise Exception("Network block disabling not reported") | |
2426 | ||
2427 | def test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev): | |
2428 | """WPA2-Enterprise negative test - altsubject mismatch""" | |
2429 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 2430 | hostapd.add_ap(apdev[0], params) |
37d61355 JM |
2431 | |
2432 | tests = [ "incorrect.example.com", | |
2433 | "DNS:incorrect.example.com", | |
2434 | "DNS:w1.fi", | |
2435 | "DNS:erver.w1.fi" ] | |
2436 | for match in tests: | |
2437 | _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match) | |
2438 | ||
2439 | def _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match): | |
3b74982f JM |
2440 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
2441 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
2442 | password="password", phase2="auth=MSCHAPV2", | |
2443 | ca_cert="auth_serv/ca.pem", | |
37d61355 | 2444 | altsubject_match=match, |
3b74982f JM |
2445 | wait_connect=False, scan_freq="2412") |
2446 | ||
412c6030 | 2447 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
3b74982f JM |
2448 | if ev is None: |
2449 | raise Exception("Association and EAP start timed out") | |
2450 | ||
506b2f05 JM |
2451 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD", |
2452 | "EAP: Failed to initialize EAP method"], timeout=10) | |
3b74982f JM |
2453 | if ev is None: |
2454 | raise Exception("EAP method selection timed out") | |
506b2f05 JM |
2455 | if "EAP: Failed to initialize EAP method" in ev: |
2456 | tls = dev[0].request("GET tls_library") | |
2457 | if tls.startswith("OpenSSL"): | |
2458 | raise Exception("Failed to select EAP method") | |
2459 | logger.info("altsubject_match not supported - connection failed, so test succeeded") | |
2460 | return | |
3b74982f JM |
2461 | if "TTLS" not in ev: |
2462 | raise Exception("Unexpected EAP method") | |
2463 | ||
2464 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
2465 | "CTRL-EVENT-EAP-SUCCESS", | |
2466 | "CTRL-EVENT-EAP-FAILURE", | |
2467 | "CTRL-EVENT-CONNECTED", | |
2468 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2469 | if ev is None: | |
2470 | raise Exception("EAP result timed out") | |
2471 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
2472 | raise Exception("TLS certificate error not reported") | |
2473 | if "AltSubject mismatch" not in ev: | |
2474 | raise Exception("altsubject mismatch not reported") | |
2475 | ||
2476 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
2477 | "CTRL-EVENT-EAP-FAILURE", | |
2478 | "CTRL-EVENT-CONNECTED", | |
2479 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2480 | if ev is None: | |
2481 | raise Exception("EAP result(2) timed out") | |
2482 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
2483 | raise Exception("EAP failure not reported") | |
2484 | ||
2485 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
2486 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
2487 | if ev is None: | |
2488 | raise Exception("EAP result(3) timed out") | |
2489 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
2490 | raise Exception("Disconnection not reported") | |
2491 | ||
2492 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
2493 | if ev is None: | |
2494 | raise Exception("Network block disabling not reported") | |
2495 | ||
37d61355 JM |
2496 | dev[0].request("REMOVE_NETWORK all") |
2497 | ||
5a0c1517 JM |
2498 | def test_ap_wpa2_eap_unauth_tls(dev, apdev): |
2499 | """WPA2-Enterprise connection using UNAUTH-TLS""" | |
2500 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
2501 | hapd = hostapd.add_ap(apdev[0], params) |
2502 | eap_connect(dev[0], hapd, "UNAUTH-TLS", "unauth-tls", | |
5a0c1517 JM |
2503 | ca_cert="auth_serv/ca.pem") |
2504 | eap_reauth(dev[0], "UNAUTH-TLS") | |
2505 | ||
57be05e1 JM |
2506 | def test_ap_wpa2_eap_ttls_server_cert_hash(dev, apdev): |
2507 | """WPA2-Enterprise connection using EAP-TTLS and server certificate hash""" | |
4bf4e9db | 2508 | check_cert_probe_support(dev[0]) |
ca158ea6 | 2509 | skip_with_fips(dev[0]) |
0ba13e86 | 2510 | srv_cert_hash = "53728dde442d4adc27cb10a847234a4315590f0b36786353023c3b0f2e9fdf49" |
57be05e1 | 2511 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 | 2512 | hapd = hostapd.add_ap(apdev[0], params) |
57be05e1 JM |
2513 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
2514 | identity="probe", ca_cert="probe://", | |
2515 | wait_connect=False, scan_freq="2412") | |
412c6030 | 2516 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
57be05e1 JM |
2517 | if ev is None: |
2518 | raise Exception("Association and EAP start timed out") | |
2519 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT depth=0"], timeout=10) | |
2520 | if ev is None: | |
2521 | raise Exception("No peer server certificate event seen") | |
2522 | if "hash=" + srv_cert_hash not in ev: | |
2523 | raise Exception("Expected server certificate hash not reported") | |
2524 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10) | |
2525 | if ev is None: | |
2526 | raise Exception("EAP result timed out") | |
2527 | if "Server certificate chain probe" not in ev: | |
2528 | raise Exception("Server certificate probe not reported") | |
5f35a5e2 | 2529 | dev[0].wait_disconnected(timeout=10) |
57be05e1 JM |
2530 | dev[0].request("REMOVE_NETWORK all") |
2531 | ||
2532 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2533 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
2534 | password="password", phase2="auth=MSCHAPV2", | |
2535 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a", | |
2536 | wait_connect=False, scan_freq="2412") | |
412c6030 | 2537 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
57be05e1 JM |
2538 | if ev is None: |
2539 | raise Exception("Association and EAP start timed out") | |
2540 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10) | |
2541 | if ev is None: | |
2542 | raise Exception("EAP result timed out") | |
2543 | if "Server certificate mismatch" not in ev: | |
2544 | raise Exception("Server certificate mismatch not reported") | |
5f35a5e2 | 2545 | dev[0].wait_disconnected(timeout=10) |
57be05e1 JM |
2546 | dev[0].request("REMOVE_NETWORK all") |
2547 | ||
3b3e2687 | 2548 | eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user", |
57be05e1 JM |
2549 | anonymous_identity="ttls", password="password", |
2550 | ca_cert="hash://server/sha256/" + srv_cert_hash, | |
2551 | phase2="auth=MSCHAPV2") | |
2552 | ||
2a6a2192 JM |
2553 | def test_ap_wpa2_eap_ttls_server_cert_hash_invalid(dev, apdev): |
2554 | """WPA2-Enterprise connection using EAP-TTLS and server certificate hash (invalid config)""" | |
2555 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 2556 | hostapd.add_ap(apdev[0], params) |
2a6a2192 JM |
2557 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
2558 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
2559 | password="password", phase2="auth=MSCHAPV2", | |
2560 | ca_cert="hash://server/md5/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a", | |
2561 | wait_connect=False, scan_freq="2412") | |
2562 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2563 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
2564 | password="password", phase2="auth=MSCHAPV2", | |
2565 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca", | |
2566 | wait_connect=False, scan_freq="2412") | |
2567 | dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2568 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
2569 | password="password", phase2="auth=MSCHAPV2", | |
2570 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6Q", | |
2571 | wait_connect=False, scan_freq="2412") | |
2572 | for i in range(0, 3): | |
412c6030 | 2573 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
2a6a2192 JM |
2574 | if ev is None: |
2575 | raise Exception("Association and EAP start timed out") | |
cbb85a03 JM |
2576 | ev = dev[i].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 21 (TTLS)"], timeout=5) |
2577 | if ev is None: | |
2578 | raise Exception("Did not report EAP method initialization failure") | |
2a6a2192 | 2579 | |
22b99086 JM |
2580 | def test_ap_wpa2_eap_pwd(dev, apdev): |
2581 | """WPA2-Enterprise connection using EAP-pwd""" | |
3b51cc63 | 2582 | check_eap_capa(dev[0], "PWD") |
22b99086 | 2583 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
2584 | hapd = hostapd.add_ap(apdev[0], params) |
2585 | eap_connect(dev[0], hapd, "PWD", "pwd user", password="secret password") | |
75b2b9cf | 2586 | eap_reauth(dev[0], "PWD") |
6daf5b9c | 2587 | dev[0].request("REMOVE_NETWORK all") |
0403fa0a | 2588 | |
3b3e2687 | 2589 | eap_connect(dev[1], hapd, "PWD", |
0403fa0a JM |
2590 | "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com", |
2591 | password="secret password", | |
6daf5b9c JM |
2592 | fragment_size="90") |
2593 | ||
f10ba3b2 | 2594 | logger.info("Negative test with incorrect password") |
3b3e2687 | 2595 | eap_connect(dev[2], hapd, "PWD", "pwd user", password="secret-password", |
f10ba3b2 JM |
2596 | expect_failure=True, local_error_report=True) |
2597 | ||
3b3e2687 | 2598 | eap_connect(dev[0], hapd, "PWD", |
0403fa0a JM |
2599 | "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com", |
2600 | password="secret password", | |
2601 | fragment_size="31") | |
2602 | ||
b898a6ee JM |
2603 | def test_ap_wpa2_eap_pwd_nthash(dev, apdev): |
2604 | """WPA2-Enterprise connection using EAP-pwd and NTHash""" | |
2605 | check_eap_capa(dev[0], "PWD") | |
0392867b | 2606 | skip_with_fips(dev[0]) |
b898a6ee | 2607 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
2608 | hapd = hostapd.add_ap(apdev[0], params) |
2609 | eap_connect(dev[0], hapd, "PWD", "pwd-hash", password="secret password") | |
2610 | eap_connect(dev[1], hapd, "PWD", "pwd-hash", | |
b898a6ee | 2611 | password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a") |
3b3e2687 | 2612 | eap_connect(dev[2], hapd, "PWD", "pwd user", |
b898a6ee JM |
2613 | password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a", |
2614 | expect_failure=True, local_error_report=True) | |
2615 | ||
c075f040 JM |
2616 | def test_ap_wpa2_eap_pwd_groups(dev, apdev): |
2617 | """WPA2-Enterprise connection using various EAP-pwd groups""" | |
3b51cc63 | 2618 | check_eap_capa(dev[0], "PWD") |
5f2e4547 | 2619 | tls = dev[0].request("GET tls_library") |
c075f040 JM |
2620 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
2621 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2622 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" } | |
f2d789f2 JM |
2623 | groups = [ 19, 20, 21, 25, 26 ] |
2624 | if tls.startswith("OpenSSL") and "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls: | |
2625 | logger.info("Add Brainpool EC groups since OpenSSL is new enough") | |
2626 | groups += [ 27, 28, 29, 30 ] | |
2627 | for i in groups: | |
2628 | logger.info("Group %d" % i) | |
c075f040 | 2629 | params['pwd_group'] = str(i) |
3b3e2687 | 2630 | hapd = hostapd.add_ap(apdev[0], params) |
5f2e4547 | 2631 | try: |
3b3e2687 | 2632 | eap_connect(dev[0], hapd, "PWD", "pwd user", |
5f2e4547 | 2633 | password="secret password") |
f2d789f2 JM |
2634 | dev[0].request("REMOVE_NETWORK all") |
2635 | dev[0].wait_disconnected() | |
2636 | dev[0].dump_monitor() | |
5f2e4547 JM |
2637 | except: |
2638 | if "BoringSSL" in tls and i in [ 25 ]: | |
2639 | logger.info("Ignore connection failure with group %d with BoringSSL" % i) | |
2640 | dev[0].request("DISCONNECT") | |
2641 | time.sleep(0.1) | |
f2d789f2 JM |
2642 | dev[0].request("REMOVE_NETWORK all") |
2643 | dev[0].dump_monitor() | |
5f2e4547 JM |
2644 | continue |
2645 | raise | |
c075f040 | 2646 | |
4b2d2098 JM |
2647 | def test_ap_wpa2_eap_pwd_invalid_group(dev, apdev): |
2648 | """WPA2-Enterprise connection using invalid EAP-pwd group""" | |
3b51cc63 | 2649 | check_eap_capa(dev[0], "PWD") |
4b2d2098 JM |
2650 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
2651 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2652 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" } | |
2653 | params['pwd_group'] = "0" | |
8b8a1864 | 2654 | hostapd.add_ap(apdev[0], params) |
4b2d2098 JM |
2655 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD", |
2656 | identity="pwd user", password="secret password", | |
2657 | scan_freq="2412", wait_connect=False) | |
2658 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2659 | if ev is None: | |
2660 | raise Exception("Timeout on EAP failure report") | |
2661 | ||
8ba89e0a JM |
2662 | def test_ap_wpa2_eap_pwd_as_frag(dev, apdev): |
2663 | """WPA2-Enterprise connection using EAP-pwd with server fragmentation""" | |
3b51cc63 | 2664 | check_eap_capa(dev[0], "PWD") |
8ba89e0a JM |
2665 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2666 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", | |
2667 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2668 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
2669 | "pwd_group": "19", "fragment_size": "40" } | |
3b3e2687 JD |
2670 | hapd = hostapd.add_ap(apdev[0], params) |
2671 | eap_connect(dev[0], hapd, "PWD", "pwd user", password="secret password") | |
8ba89e0a | 2672 | |
22b99086 JM |
2673 | def test_ap_wpa2_eap_gpsk(dev, apdev): |
2674 | """WPA2-Enterprise connection using EAP-GPSK""" | |
2675 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
2676 | hapd = hostapd.add_ap(apdev[0], params) |
2677 | id = eap_connect(dev[0], hapd, "GPSK", "gpsk user", | |
369f9c20 | 2678 | password="abcdefghijklmnop0123456789abcdef") |
75b2b9cf | 2679 | eap_reauth(dev[0], "GPSK") |
22b99086 | 2680 | |
369f9c20 JM |
2681 | logger.info("Test forced algorithm selection") |
2682 | for phase1 in [ "cipher=1", "cipher=2" ]: | |
2683 | dev[0].set_network_quoted(id, "phase1", phase1) | |
2684 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
2685 | if ev is None: | |
2686 | raise Exception("EAP success timed out") | |
5f35a5e2 | 2687 | dev[0].wait_connected(timeout=10) |
369f9c20 JM |
2688 | |
2689 | logger.info("Test failed algorithm negotiation") | |
2690 | dev[0].set_network_quoted(id, "phase1", "cipher=9") | |
2691 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
2692 | if ev is None: | |
2693 | raise Exception("EAP failure timed out") | |
2694 | ||
f10ba3b2 JM |
2695 | logger.info("Negative test with incorrect password") |
2696 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 2697 | eap_connect(dev[0], hapd, "GPSK", "gpsk user", |
f10ba3b2 JM |
2698 | password="ffcdefghijklmnop0123456789abcdef", |
2699 | expect_failure=True) | |
2700 | ||
22b99086 JM |
2701 | def test_ap_wpa2_eap_sake(dev, apdev): |
2702 | """WPA2-Enterprise connection using EAP-SAKE""" | |
2703 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
2704 | hapd = hostapd.add_ap(apdev[0], params) |
2705 | eap_connect(dev[0], hapd, "SAKE", "sake user", | |
22b99086 | 2706 | password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") |
75b2b9cf | 2707 | eap_reauth(dev[0], "SAKE") |
22b99086 | 2708 | |
f10ba3b2 JM |
2709 | logger.info("Negative test with incorrect password") |
2710 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 2711 | eap_connect(dev[0], hapd, "SAKE", "sake user", |
f10ba3b2 JM |
2712 | password_hex="ff23456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", |
2713 | expect_failure=True) | |
2714 | ||
22b99086 JM |
2715 | def test_ap_wpa2_eap_eke(dev, apdev): |
2716 | """WPA2-Enterprise connection using EAP-EKE""" | |
2717 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
2718 | hapd = hostapd.add_ap(apdev[0], params) |
2719 | id = eap_connect(dev[0], hapd, "EKE", "eke user", password="hello") | |
75b2b9cf | 2720 | eap_reauth(dev[0], "EKE") |
22b99086 | 2721 | |
2bb9e283 JM |
2722 | logger.info("Test forced algorithm selection") |
2723 | for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2", | |
2724 | "dhgroup=4 encr=1 prf=2 mac=2", | |
2725 | "dhgroup=3 encr=1 prf=2 mac=2", | |
2726 | "dhgroup=3 encr=1 prf=1 mac=1" ]: | |
2727 | dev[0].set_network_quoted(id, "phase1", phase1) | |
2728 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
2729 | if ev is None: | |
2730 | raise Exception("EAP success timed out") | |
5f35a5e2 | 2731 | dev[0].wait_connected(timeout=10) |
2bb9e283 JM |
2732 | |
2733 | logger.info("Test failed algorithm negotiation") | |
2734 | dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9") | |
2735 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
2736 | if ev is None: | |
2737 | raise Exception("EAP failure timed out") | |
2738 | ||
f10ba3b2 JM |
2739 | logger.info("Negative test with incorrect password") |
2740 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 2741 | eap_connect(dev[0], hapd, "EKE", "eke user", password="hello1", |
f10ba3b2 JM |
2742 | expect_failure=True) |
2743 | ||
3b6f3b37 JM |
2744 | def test_ap_wpa2_eap_eke_many(dev, apdev, params): |
2745 | """WPA2-Enterprise connection using EAP-EKE (many connections) [long]""" | |
2746 | if not params['long']: | |
2747 | raise HwsimSkip("Skip test case with long duration due to --long not specified") | |
2748 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 2749 | hostapd.add_ap(apdev[0], params) |
3b6f3b37 JM |
2750 | success = 0 |
2751 | fail = 0 | |
2752 | for i in range(100): | |
2753 | for j in range(3): | |
2754 | dev[j].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="EKE", | |
2755 | identity="eke user", password="hello", | |
2756 | phase1="dhgroup=3 encr=1 prf=1 mac=1", | |
2757 | scan_freq="2412", wait_connect=False) | |
2758 | for j in range(3): | |
2759 | ev = dev[j].wait_event(["CTRL-EVENT-CONNECTED", | |
2760 | "CTRL-EVENT-DISCONNECTED"], timeout=15) | |
2761 | if ev is None: | |
2762 | raise Exception("No connected/disconnected event") | |
2763 | if "CTRL-EVENT-DISCONNECTED" in ev: | |
2764 | fail += 1 | |
2765 | # The RADIUS server limits on active sessions can be hit when | |
2766 | # going through this test case, so try to give some more time | |
2767 | # for the server to remove sessions. | |
2768 | logger.info("Failed to connect i=%d j=%d" % (i, j)) | |
2769 | dev[j].request("REMOVE_NETWORK all") | |
2770 | time.sleep(1) | |
2771 | else: | |
2772 | success += 1 | |
2773 | dev[j].request("REMOVE_NETWORK all") | |
2774 | dev[j].wait_disconnected() | |
2775 | dev[j].dump_monitor() | |
2776 | logger.info("Total success=%d failure=%d" % (success, fail)) | |
2777 | ||
f7e3c17b JM |
2778 | def test_ap_wpa2_eap_eke_serverid_nai(dev, apdev): |
2779 | """WPA2-Enterprise connection using EAP-EKE with serverid NAI""" | |
2780 | params = int_eap_server_params() | |
2781 | params['server_id'] = 'example.server@w1.fi' | |
3b3e2687 JD |
2782 | hapd = hostapd.add_ap(apdev[0], params) |
2783 | eap_connect(dev[0], hapd, "EKE", "eke user", password="hello") | |
f7e3c17b | 2784 | |
5e0bedc6 JM |
2785 | def test_ap_wpa2_eap_eke_server_oom(dev, apdev): |
2786 | """WPA2-Enterprise connection using EAP-EKE with server OOM""" | |
2787 | params = int_eap_server_params() | |
8b8a1864 | 2788 | hapd = hostapd.add_ap(apdev[0], params) |
5e0bedc6 JM |
2789 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2790 | ||
2791 | for count,func in [ (1, "eap_eke_build_commit"), | |
2792 | (2, "eap_eke_build_commit"), | |
2793 | (3, "eap_eke_build_commit"), | |
2794 | (1, "eap_eke_build_confirm"), | |
2795 | (2, "eap_eke_build_confirm"), | |
2796 | (1, "eap_eke_process_commit"), | |
2797 | (2, "eap_eke_process_commit"), | |
2798 | (1, "eap_eke_process_confirm"), | |
2799 | (1, "eap_eke_process_identity"), | |
2800 | (2, "eap_eke_process_identity"), | |
2801 | (3, "eap_eke_process_identity"), | |
2802 | (4, "eap_eke_process_identity") ]: | |
2803 | with alloc_fail(hapd, count, func): | |
3b3e2687 | 2804 | eap_connect(dev[0], hapd, "EKE", "eke user", password="hello", |
5e0bedc6 JM |
2805 | expect_failure=True) |
2806 | dev[0].request("REMOVE_NETWORK all") | |
2807 | ||
2808 | for count,func,pw in [ (1, "eap_eke_init", "hello"), | |
2809 | (1, "eap_eke_get_session_id", "hello"), | |
2810 | (1, "eap_eke_getKey", "hello"), | |
2811 | (1, "eap_eke_build_msg", "hello"), | |
2812 | (1, "eap_eke_build_failure", "wrong"), | |
2813 | (1, "eap_eke_build_identity", "hello"), | |
2814 | (2, "eap_eke_build_identity", "hello") ]: | |
2815 | with alloc_fail(hapd, count, func): | |
2816 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
2817 | eap="EKE", identity="eke user", password=pw, | |
2818 | wait_connect=False, scan_freq="2412") | |
2819 | # This would eventually time out, but we can stop after having | |
2820 | # reached the allocation failure. | |
2821 | for i in range(20): | |
2822 | time.sleep(0.1) | |
2823 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
2824 | break | |
2825 | dev[0].request("REMOVE_NETWORK all") | |
2826 | ||
2827 | for count in range(1, 1000): | |
2828 | try: | |
2829 | with alloc_fail(hapd, count, "eap_server_sm_step"): | |
2830 | dev[0].connect("test-wpa2-eap", | |
2831 | key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
2832 | eap="EKE", identity="eke user", password=pw, | |
2833 | wait_connect=False, scan_freq="2412") | |
2834 | # This would eventually time out, but we can stop after having | |
2835 | # reached the allocation failure. | |
2836 | for i in range(10): | |
2837 | time.sleep(0.1) | |
2838 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
2839 | break | |
2840 | dev[0].request("REMOVE_NETWORK all") | |
2841 | except Exception, e: | |
2842 | if str(e) == "Allocation failure did not trigger": | |
2843 | if count < 30: | |
2844 | raise Exception("Too few allocation failures") | |
2845 | logger.info("%d allocation failures tested" % (count - 1)) | |
2846 | break | |
2847 | raise e | |
2848 | ||
22b99086 JM |
2849 | def test_ap_wpa2_eap_ikev2(dev, apdev): |
2850 | """WPA2-Enterprise connection using EAP-IKEv2""" | |
c8e82c94 | 2851 | check_eap_capa(dev[0], "IKEV2") |
22b99086 | 2852 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
2853 | hapd = hostapd.add_ap(apdev[0], params) |
2854 | eap_connect(dev[0], hapd, "IKEV2", "ikev2 user", | |
cb33ee14 | 2855 | password="ike password") |
75b2b9cf | 2856 | eap_reauth(dev[0], "IKEV2") |
6daf5b9c | 2857 | dev[0].request("REMOVE_NETWORK all") |
3b3e2687 | 2858 | eap_connect(dev[0], hapd, "IKEV2", "ikev2 user", |
47a74ad8 | 2859 | password="ike password", fragment_size="50") |
22b99086 | 2860 | |
f10ba3b2 JM |
2861 | logger.info("Negative test with incorrect password") |
2862 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 2863 | eap_connect(dev[0], hapd, "IKEV2", "ikev2 user", |
f10ba3b2 | 2864 | password="ike-password", expect_failure=True) |
35372f6c JM |
2865 | dev[0].request("REMOVE_NETWORK all") |
2866 | ||
3b3e2687 | 2867 | eap_connect(dev[0], hapd, "IKEV2", "ikev2 user", |
35372f6c JM |
2868 | password="ike password", fragment_size="0") |
2869 | dev[0].request("REMOVE_NETWORK all") | |
2870 | dev[0].wait_disconnected() | |
f10ba3b2 | 2871 | |
47a74ad8 JM |
2872 | def test_ap_wpa2_eap_ikev2_as_frag(dev, apdev): |
2873 | """WPA2-Enterprise connection using EAP-IKEv2 with server fragmentation""" | |
c8e82c94 | 2874 | check_eap_capa(dev[0], "IKEV2") |
47a74ad8 JM |
2875 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2876 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", | |
2877 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2878 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
2879 | "fragment_size": "50" } | |
3b3e2687 JD |
2880 | hapd = hostapd.add_ap(apdev[0], params) |
2881 | eap_connect(dev[0], hapd, "IKEV2", "ikev2 user", | |
47a74ad8 JM |
2882 | password="ike password") |
2883 | eap_reauth(dev[0], "IKEV2") | |
2884 | ||
f1ab79c3 JM |
2885 | def test_ap_wpa2_eap_ikev2_oom(dev, apdev): |
2886 | """WPA2-Enterprise connection using EAP-IKEv2 and OOM""" | |
c8e82c94 | 2887 | check_eap_capa(dev[0], "IKEV2") |
f1ab79c3 | 2888 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 2889 | hostapd.add_ap(apdev[0], params) |
f1ab79c3 JM |
2890 | |
2891 | tests = [ (1, "dh_init"), | |
2892 | (2, "dh_init"), | |
2893 | (1, "dh_derive_shared") ] | |
2894 | for count, func in tests: | |
2895 | with alloc_fail(dev[0], count, func): | |
2896 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2", | |
2897 | identity="ikev2 user", password="ike password", | |
2898 | wait_connect=False, scan_freq="2412") | |
2899 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5) | |
2900 | if ev is None: | |
2901 | raise Exception("EAP method not selected") | |
2902 | for i in range(10): | |
2903 | if "0:" in dev[0].request("GET_ALLOC_FAIL"): | |
2904 | break | |
2905 | time.sleep(0.02) | |
2906 | dev[0].request("REMOVE_NETWORK all") | |
2907 | ||
2908 | tests = [ (1, "os_get_random;dh_init") ] | |
2909 | for count, func in tests: | |
2910 | with fail_test(dev[0], count, func): | |
2911 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2", | |
2912 | identity="ikev2 user", password="ike password", | |
2913 | wait_connect=False, scan_freq="2412") | |
2914 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5) | |
2915 | if ev is None: | |
2916 | raise Exception("EAP method not selected") | |
2917 | for i in range(10): | |
2918 | if "0:" in dev[0].request("GET_FAIL"): | |
2919 | break | |
2920 | time.sleep(0.02) | |
2921 | dev[0].request("REMOVE_NETWORK all") | |
2922 | ||
22b99086 JM |
2923 | def test_ap_wpa2_eap_pax(dev, apdev): |
2924 | """WPA2-Enterprise connection using EAP-PAX""" | |
2925 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
2926 | hapd = hostapd.add_ap(apdev[0], params) |
2927 | eap_connect(dev[0], hapd, "PAX", "pax.user@example.com", | |
22b99086 | 2928 | password_hex="0123456789abcdef0123456789abcdef") |
75b2b9cf | 2929 | eap_reauth(dev[0], "PAX") |
22b99086 | 2930 | |
f10ba3b2 JM |
2931 | logger.info("Negative test with incorrect password") |
2932 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 2933 | eap_connect(dev[0], hapd, "PAX", "pax.user@example.com", |
f10ba3b2 JM |
2934 | password_hex="ff23456789abcdef0123456789abcdef", |
2935 | expect_failure=True) | |
2936 | ||
22b99086 JM |
2937 | def test_ap_wpa2_eap_psk(dev, apdev): |
2938 | """WPA2-Enterprise connection using EAP-PSK""" | |
2939 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2b005194 JM |
2940 | params["wpa_key_mgmt"] = "WPA-EAP-SHA256" |
2941 | params["ieee80211w"] = "2" | |
3b3e2687 JD |
2942 | hapd = hostapd.add_ap(apdev[0], params) |
2943 | eap_connect(dev[0], hapd, "PSK", "psk.user@example.com", | |
2b005194 JM |
2944 | password_hex="0123456789abcdef0123456789abcdef", sha256=True) |
2945 | eap_reauth(dev[0], "PSK", sha256=True) | |
eaf3f9b1 JM |
2946 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"), |
2947 | ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ]) | |
71390dc8 | 2948 | |
d463c556 JM |
2949 | bss = dev[0].get_bss(apdev[0]['bssid']) |
2950 | if 'flags' not in bss: | |
2951 | raise Exception("Could not get BSS flags from BSS table") | |
2952 | if "[WPA2-EAP-SHA256-CCMP]" not in bss['flags']: | |
2953 | raise Exception("Unexpected BSS flags: " + bss['flags']) | |
2954 | ||
f10ba3b2 JM |
2955 | logger.info("Negative test with incorrect password") |
2956 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 2957 | eap_connect(dev[0], hapd, "PSK", "psk.user@example.com", |
f10ba3b2 JM |
2958 | password_hex="ff23456789abcdef0123456789abcdef", sha256=True, |
2959 | expect_failure=True) | |
2960 | ||
8c4e4c01 JM |
2961 | def test_ap_wpa2_eap_psk_oom(dev, apdev): |
2962 | """WPA2-Enterprise connection using EAP-PSK and OOM""" | |
38934ed1 | 2963 | skip_with_fips(dev[0]) |
8c4e4c01 | 2964 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 2965 | hostapd.add_ap(apdev[0], params) |
7cbc8e67 JM |
2966 | tests = [ (1, "=aes_128_eax_encrypt"), |
2967 | (1, "=aes_128_eax_decrypt") ] | |
2968 | for count, func in tests: | |
2969 | with alloc_fail(dev[0], count, func): | |
2970 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK", | |
2971 | identity="psk.user@example.com", | |
2972 | password_hex="0123456789abcdef0123456789abcdef", | |
2973 | wait_connect=False, scan_freq="2412") | |
2974 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5) | |
2975 | if ev is None: | |
2976 | raise Exception("EAP method not selected") | |
2977 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL", | |
2978 | note="Failure not triggered: %d:%s" % (count, func)) | |
2979 | dev[0].request("REMOVE_NETWORK all") | |
2980 | dev[0].wait_disconnected() | |
2981 | ||
677c2283 | 2982 | tests = [ (1, "aes_ctr_encrypt;aes_128_eax_encrypt"), |
8c4e4c01 JM |
2983 | (1, "omac1_aes_128;aes_128_eax_encrypt"), |
2984 | (2, "omac1_aes_128;aes_128_eax_encrypt"), | |
2985 | (3, "omac1_aes_128;aes_128_eax_encrypt"), | |
8c4e4c01 | 2986 | (1, "omac1_aes_vector"), |
8c4e4c01 JM |
2987 | (1, "omac1_aes_128;aes_128_eax_decrypt"), |
2988 | (2, "omac1_aes_128;aes_128_eax_decrypt"), | |
2989 | (3, "omac1_aes_128;aes_128_eax_decrypt"), | |
677c2283 | 2990 | (1, "aes_ctr_encrypt;aes_128_eax_decrypt") ] |
8c4e4c01 | 2991 | for count, func in tests: |
7cbc8e67 | 2992 | with fail_test(dev[0], count, func): |
8c4e4c01 JM |
2993 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK", |
2994 | identity="psk.user@example.com", | |
2995 | password_hex="0123456789abcdef0123456789abcdef", | |
2996 | wait_connect=False, scan_freq="2412") | |
2997 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5) | |
2998 | if ev is None: | |
2999 | raise Exception("EAP method not selected") | |
7cbc8e67 JM |
3000 | wait_fail_trigger(dev[0], "GET_FAIL", |
3001 | note="Failure not triggered: %d:%s" % (count, func)) | |
8c4e4c01 | 3002 | dev[0].request("REMOVE_NETWORK all") |
7cbc8e67 | 3003 | dev[0].wait_disconnected() |
8c4e4c01 | 3004 | |
7cbc8e67 | 3005 | with fail_test(dev[0], 1, "aes_128_encrypt_block"): |
8c4e4c01 JM |
3006 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK", |
3007 | identity="psk.user@example.com", | |
3008 | password_hex="0123456789abcdef0123456789abcdef", | |
3009 | wait_connect=False, scan_freq="2412") | |
3010 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
3011 | if ev is None: | |
3012 | raise Exception("EAP method failure not reported") | |
3013 | dev[0].request("REMOVE_NETWORK all") | |
7cbc8e67 | 3014 | dev[0].wait_disconnected() |
8c4e4c01 | 3015 | |
71390dc8 JM |
3016 | def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev): |
3017 | """WPA-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2""" | |
e7ac04ce | 3018 | check_eap_capa(dev[0], "MSCHAPV2") |
71390dc8 | 3019 | params = hostapd.wpa_eap_params(ssid="test-wpa-eap") |
8b8a1864 | 3020 | hapd = hostapd.add_ap(apdev[0], params) |
71390dc8 JM |
3021 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="PEAP", |
3022 | identity="user", password="password", phase2="auth=MSCHAPV2", | |
3023 | ca_cert="auth_serv/ca.pem", wait_connect=False, | |
3024 | scan_freq="2412") | |
3025 | eap_check_auth(dev[0], "PEAP", True, rsn=False) | |
a8375c94 | 3026 | hwsim_utils.test_connectivity(dev[0], hapd) |
71390dc8 | 3027 | eap_reauth(dev[0], "PEAP", rsn=False) |
eaf3f9b1 JM |
3028 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"), |
3029 | ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ]) | |
48bb2e68 JM |
3030 | status = dev[0].get_status(extra="VERBOSE") |
3031 | if 'portControl' not in status: | |
3032 | raise Exception("portControl missing from STATUS-VERBOSE") | |
3033 | if status['portControl'] != 'Auto': | |
3034 | raise Exception("Unexpected portControl value: " + status['portControl']) | |
3035 | if 'eap_session_id' not in status: | |
3036 | raise Exception("eap_session_id missing from STATUS-VERBOSE") | |
3037 | if not status['eap_session_id'].startswith("19"): | |
3038 | raise Exception("Unexpected eap_session_id value: " + status['eap_session_id']) | |
40759604 JM |
3039 | |
3040 | def test_ap_wpa2_eap_interactive(dev, apdev): | |
3041 | """WPA2-Enterprise connection using interactive identity/password entry""" | |
e7ac04ce | 3042 | check_eap_capa(dev[0], "MSCHAPV2") |
40759604 | 3043 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
6f334bf7 | 3044 | hapd = hostapd.add_ap(apdev[0], params) |
40759604 JM |
3045 | |
3046 | tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry", | |
3047 | "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2", | |
3048 | None, "password"), | |
3049 | ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry", | |
3050 | "TTLS", "ttls", None, "auth=MSCHAPV2", | |
3051 | "DOMAIN\mschapv2 user", "password"), | |
3052 | ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry", | |
3053 | "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"), | |
3054 | ("Connection with dynamic TTLS/EAP-MD5 password entry", | |
3055 | "TTLS", "ttls", "user", "autheap=MD5", None, "password"), | |
3056 | ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry", | |
3057 | "PEAP", None, "user", "auth=MSCHAPV2", None, "password"), | |
3058 | ("Connection with dynamic PEAP/EAP-GTC password entry", | |
3059 | "PEAP", None, "user", "auth=GTC", None, "password") ] | |
3060 | for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests: | |
3061 | logger.info(desc) | |
3062 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap, | |
3063 | anonymous_identity=anon, identity=identity, | |
3064 | ca_cert="auth_serv/ca.pem", phase2=phase2, | |
3065 | wait_connect=False, scan_freq="2412") | |
3066 | if req_id: | |
3067 | ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"]) | |
3068 | if ev is None: | |
3069 | raise Exception("Request for identity timed out") | |
3070 | id = ev.split(':')[0].split('-')[-1] | |
3071 | dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id) | |
3072 | ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"]) | |
3073 | if ev is None: | |
3074 | raise Exception("Request for password timed out") | |
3075 | id = ev.split(':')[0].split('-')[-1] | |
3076 | type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD" | |
3077 | dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw) | |
5f35a5e2 | 3078 | dev[0].wait_connected(timeout=10) |
40759604 | 3079 | dev[0].request("REMOVE_NETWORK all") |
e745c811 | 3080 | |
f455998a JM |
3081 | def test_ap_wpa2_eap_ext_enable_network_while_connected(dev, apdev): |
3082 | """WPA2-Enterprise interactive identity entry and ENABLE_NETWORK""" | |
3083 | check_eap_capa(dev[0], "MSCHAPV2") | |
3084 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
6f334bf7 | 3085 | hapd = hostapd.add_ap(apdev[0], params) |
f455998a JM |
3086 | |
3087 | id_other = dev[0].connect("other", key_mgmt="NONE", scan_freq="2412", | |
3088 | only_add_network=True) | |
3089 | ||
3090 | req_id = "DOMAIN\mschapv2 user" | |
3091 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3092 | anonymous_identity="ttls", identity=None, | |
3093 | password="password", | |
3094 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3095 | wait_connect=False, scan_freq="2412") | |
3096 | ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"]) | |
3097 | if ev is None: | |
3098 | raise Exception("Request for identity timed out") | |
3099 | id = ev.split(':')[0].split('-')[-1] | |
3100 | dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id) | |
3101 | dev[0].wait_connected(timeout=10) | |
3102 | ||
3103 | if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id_other)): | |
3104 | raise Exception("Failed to enable network") | |
3105 | ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=1) | |
3106 | if ev is not None: | |
3107 | raise Exception("Unexpected reconnection attempt on ENABLE_NETWORK") | |
3108 | dev[0].request("REMOVE_NETWORK all") | |
3109 | ||
e745c811 JM |
3110 | def test_ap_wpa2_eap_vendor_test(dev, apdev): |
3111 | """WPA2-Enterprise connection using EAP vendor test""" | |
3112 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
3113 | hapd = hostapd.add_ap(apdev[0], params) |
3114 | eap_connect(dev[0], hapd, "VENDOR-TEST", "vendor-test") | |
e745c811 | 3115 | eap_reauth(dev[0], "VENDOR-TEST") |
3b3e2687 | 3116 | eap_connect(dev[1], hapd, "VENDOR-TEST", "vendor-test", |
467775c5 | 3117 | password="pending") |
53a6f06a | 3118 | |
79a3973c JM |
3119 | def test_ap_wpa2_eap_vendor_test_oom(dev, apdev): |
3120 | """WPA2-Enterprise connection using EAP vendor test (OOM)""" | |
3121 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 3122 | hostapd.add_ap(apdev[0], params) |
79a3973c JM |
3123 | |
3124 | tests = [ "eap_vendor_test_init", | |
3125 | "eap_msg_alloc;eap_vendor_test_process", | |
3126 | "eap_vendor_test_getKey" ] | |
3127 | for func in tests: | |
3128 | with alloc_fail(dev[0], 1, func): | |
3129 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", | |
3130 | scan_freq="2412", | |
3131 | eap="VENDOR-TEST", identity="vendor-test", | |
3132 | wait_connect=False) | |
3133 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
3134 | dev[0].request("REMOVE_NETWORK all") | |
3135 | dev[0].wait_disconnected() | |
3136 | ||
53a6f06a JM |
3137 | def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev): |
3138 | """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning""" | |
3b51cc63 | 3139 | check_eap_capa(dev[0], "FAST") |
53a6f06a | 3140 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 3141 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 3142 | eap_connect(dev[0], hapd, "FAST", "user", |
53a6f06a JM |
3143 | anonymous_identity="FAST", password="password", |
3144 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3145 | phase1="fast_provisioning=1", pac_file="blob://fast_pac") | |
a8375c94 | 3146 | hwsim_utils.test_connectivity(dev[0], hapd) |
2fc4749c JM |
3147 | res = eap_reauth(dev[0], "FAST") |
3148 | if res['tls_session_reused'] != '1': | |
3149 | raise Exception("EAP-FAST could not use PAC session ticket") | |
53a6f06a | 3150 | |
873e7c29 JM |
3151 | def test_ap_wpa2_eap_fast_pac_file(dev, apdev, params): |
3152 | """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and PAC file""" | |
3b51cc63 | 3153 | check_eap_capa(dev[0], "FAST") |
873e7c29 JM |
3154 | pac_file = os.path.join(params['logdir'], "fast.pac") |
3155 | pac_file2 = os.path.join(params['logdir'], "fast-bin.pac") | |
3156 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 | 3157 | hapd = hostapd.add_ap(apdev[0], params) |
873e7c29 JM |
3158 | |
3159 | try: | |
3b3e2687 | 3160 | eap_connect(dev[0], hapd, "FAST", "user", |
873e7c29 JM |
3161 | anonymous_identity="FAST", password="password", |
3162 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3163 | phase1="fast_provisioning=1", pac_file=pac_file) | |
3164 | with open(pac_file, "r") as f: | |
3165 | data = f.read() | |
3166 | if "wpa_supplicant EAP-FAST PAC file - version 1" not in data: | |
3167 | raise Exception("PAC file header missing") | |
3168 | if "PAC-Key=" not in data: | |
3169 | raise Exception("PAC-Key missing from PAC file") | |
3170 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 3171 | eap_connect(dev[0], hapd, "FAST", "user", |
873e7c29 JM |
3172 | anonymous_identity="FAST", password="password", |
3173 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3174 | pac_file=pac_file) | |
3175 | ||
3b3e2687 | 3176 | eap_connect(dev[1], hapd, "FAST", "user", |
873e7c29 JM |
3177 | anonymous_identity="FAST", password="password", |
3178 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3179 | phase1="fast_provisioning=1 fast_pac_format=binary", | |
3180 | pac_file=pac_file2) | |
3181 | dev[1].request("REMOVE_NETWORK all") | |
3b3e2687 | 3182 | eap_connect(dev[1], hapd, "FAST", "user", |
873e7c29 JM |
3183 | anonymous_identity="FAST", password="password", |
3184 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3185 | phase1="fast_pac_format=binary", | |
3186 | pac_file=pac_file2) | |
3187 | finally: | |
b638f703 JM |
3188 | try: |
3189 | os.remove(pac_file) | |
3190 | except: | |
3191 | pass | |
3192 | try: | |
3193 | os.remove(pac_file2) | |
3194 | except: | |
3195 | pass | |
873e7c29 | 3196 | |
c6ab1cdb JM |
3197 | def test_ap_wpa2_eap_fast_binary_pac(dev, apdev): |
3198 | """WPA2-Enterprise connection using EAP-FAST and binary PAC format""" | |
3b51cc63 | 3199 | check_eap_capa(dev[0], "FAST") |
c6ab1cdb | 3200 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
3201 | hapd = hostapd.add_ap(apdev[0], params) |
3202 | eap_connect(dev[0], hapd, "FAST", "user", | |
c6ab1cdb JM |
3203 | anonymous_identity="FAST", password="password", |
3204 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3205 | phase1="fast_provisioning=1 fast_max_pac_list_len=1 fast_pac_format=binary", | |
3206 | pac_file="blob://fast_pac_bin") | |
2fc4749c JM |
3207 | res = eap_reauth(dev[0], "FAST") |
3208 | if res['tls_session_reused'] != '1': | |
3209 | raise Exception("EAP-FAST could not use PAC session ticket") | |
c6ab1cdb | 3210 | |
d7ef6e63 JM |
3211 | # Verify fast_max_pac_list_len=0 special case |
3212 | dev[0].request("REMOVE_NETWORK all") | |
3213 | dev[0].wait_disconnected() | |
3b3e2687 | 3214 | eap_connect(dev[0], hapd, "FAST", "user", |
d7ef6e63 JM |
3215 | anonymous_identity="FAST", password="password", |
3216 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3217 | phase1="fast_provisioning=1 fast_max_pac_list_len=0 fast_pac_format=binary", | |
3218 | pac_file="blob://fast_pac_bin") | |
3219 | ||
46e094bd JM |
3220 | def test_ap_wpa2_eap_fast_missing_pac_config(dev, apdev): |
3221 | """WPA2-Enterprise connection using EAP-FAST and missing PAC config""" | |
3b51cc63 | 3222 | check_eap_capa(dev[0], "FAST") |
46e094bd | 3223 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 3224 | hostapd.add_ap(apdev[0], params) |
46e094bd JM |
3225 | |
3226 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3227 | identity="user", anonymous_identity="FAST", | |
3228 | password="password", | |
3229 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3230 | pac_file="blob://fast_pac_not_in_use", | |
3231 | wait_connect=False, scan_freq="2412") | |
3232 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3233 | if ev is None: | |
3234 | raise Exception("Timeout on EAP failure report") | |
3235 | dev[0].request("REMOVE_NETWORK all") | |
3236 | ||
3237 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3238 | identity="user", anonymous_identity="FAST", | |
3239 | password="password", | |
3240 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3241 | wait_connect=False, scan_freq="2412") | |
3242 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3243 | if ev is None: | |
3244 | raise Exception("Timeout on EAP failure report") | |
3245 | ||
93aa1e16 JM |
3246 | def test_ap_wpa2_eap_fast_binary_pac_errors(dev, apdev): |
3247 | """EAP-FAST and binary PAC errors""" | |
3248 | check_eap_capa(dev[0], "FAST") | |
3249 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 | 3250 | hapd = hostapd.add_ap(apdev[0], params) |
93aa1e16 JM |
3251 | |
3252 | tests = [ (1, "=eap_fast_save_pac_bin"), | |
3253 | (1, "eap_fast_write_pac"), | |
3254 | (2, "eap_fast_write_pac"), ] | |
3255 | for count, func in tests: | |
3256 | if "OK" not in dev[0].request("SET blob fast_pac_bin_errors "): | |
3257 | raise Exception("Could not set blob") | |
3258 | ||
3259 | with alloc_fail(dev[0], count, func): | |
3b3e2687 | 3260 | eap_connect(dev[0], hapd, "FAST", "user", |
93aa1e16 JM |
3261 | anonymous_identity="FAST", password="password", |
3262 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3263 | phase1="fast_provisioning=1 fast_pac_format=binary", | |
3264 | pac_file="blob://fast_pac_bin_errors") | |
3265 | dev[0].request("REMOVE_NETWORK all") | |
3266 | dev[0].wait_disconnected() | |
3267 | ||
3268 | tests = [ "00", "000000000000", "6ae4920c0001", | |
3269 | "6ae4920c000000", | |
3270 | "6ae4920c0000" + "0000" + 32*"00" + "ffff" + "0000", | |
3271 | "6ae4920c0000" + "0000" + 32*"00" + "0001" + "0000", | |
3272 | "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0001", | |
3273 | "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0008" + "00040000" + "0007000100"] | |
3274 | for t in tests: | |
3275 | if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + t): | |
3276 | raise Exception("Could not set blob") | |
3277 | ||
3278 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3279 | identity="user", anonymous_identity="FAST", | |
3280 | password="password", | |
3281 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3282 | phase1="fast_provisioning=1 fast_pac_format=binary", | |
3283 | pac_file="blob://fast_pac_bin_errors", | |
3284 | scan_freq="2412", wait_connect=False) | |
3285 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], | |
3286 | timeout=5) | |
3287 | if ev is None: | |
3288 | raise Exception("Failure not reported") | |
3289 | dev[0].request("REMOVE_NETWORK all") | |
3290 | dev[0].wait_disconnected() | |
3291 | ||
3292 | pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0000" | |
3293 | tests = [ (1, "eap_fast_load_pac_bin"), | |
3294 | (2, "eap_fast_load_pac_bin"), | |
3295 | (3, "eap_fast_load_pac_bin") ] | |
3296 | for count, func in tests: | |
3297 | if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac): | |
3298 | raise Exception("Could not set blob") | |
3299 | ||
3300 | with alloc_fail(dev[0], count, func): | |
3301 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3302 | identity="user", anonymous_identity="FAST", | |
3303 | password="password", | |
3304 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3305 | phase1="fast_provisioning=1 fast_pac_format=binary", | |
3306 | pac_file="blob://fast_pac_bin_errors", | |
3307 | scan_freq="2412", wait_connect=False) | |
3308 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], | |
3309 | timeout=5) | |
3310 | if ev is None: | |
3311 | raise Exception("Failure not reported") | |
3312 | dev[0].request("REMOVE_NETWORK all") | |
3313 | dev[0].wait_disconnected() | |
3314 | ||
3315 | pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0005" + "0011223344" | |
3316 | if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac): | |
3317 | raise Exception("Could not set blob") | |
3318 | ||
3b3e2687 | 3319 | eap_connect(dev[0], hapd, "FAST", "user", |
93aa1e16 JM |
3320 | anonymous_identity="FAST", password="password", |
3321 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3322 | phase1="fast_provisioning=1 fast_pac_format=binary", | |
3323 | pac_file="blob://fast_pac_bin_errors") | |
3324 | dev[0].request("REMOVE_NETWORK all") | |
3325 | dev[0].wait_disconnected() | |
3326 | ||
3327 | pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0009" + "00040000" + "0007000100" | |
3328 | tests = [ (1, "eap_fast_pac_get_a_id"), | |
3329 | (2, "eap_fast_pac_get_a_id") ] | |
3330 | for count, func in tests: | |
3331 | if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac): | |
3332 | raise Exception("Could not set blob") | |
3333 | with alloc_fail(dev[0], count, func): | |
3b3e2687 | 3334 | eap_connect(dev[0], hapd, "FAST", "user", |
93aa1e16 JM |
3335 | anonymous_identity="FAST", password="password", |
3336 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3337 | phase1="fast_provisioning=1 fast_pac_format=binary", | |
3338 | pac_file="blob://fast_pac_bin_errors") | |
3339 | dev[0].request("REMOVE_NETWORK all") | |
3340 | dev[0].wait_disconnected() | |
3341 | ||
592790bf JM |
3342 | def test_ap_wpa2_eap_fast_text_pac_errors(dev, apdev): |
3343 | """EAP-FAST and text PAC errors""" | |
3344 | check_eap_capa(dev[0], "FAST") | |
3345 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 3346 | hostapd.add_ap(apdev[0], params) |
592790bf JM |
3347 | |
3348 | tests = [ (1, "eap_fast_parse_hex;eap_fast_parse_pac_key"), | |
3349 | (1, "eap_fast_parse_hex;eap_fast_parse_pac_opaque"), | |
3350 | (1, "eap_fast_parse_hex;eap_fast_parse_a_id"), | |
3351 | (1, "eap_fast_parse_start"), | |
3352 | (1, "eap_fast_save_pac") ] | |
3353 | for count, func in tests: | |
3354 | dev[0].request("FLUSH") | |
3355 | if "OK" not in dev[0].request("SET blob fast_pac_text_errors "): | |
3356 | raise Exception("Could not set blob") | |
3357 | ||
3358 | with alloc_fail(dev[0], count, func): | |
3359 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3360 | identity="user", anonymous_identity="FAST", | |
3361 | password="password", | |
3362 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3363 | phase1="fast_provisioning=1", | |
3364 | pac_file="blob://fast_pac_text_errors", | |
3365 | scan_freq="2412", wait_connect=False) | |
3366 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
3367 | dev[0].request("REMOVE_NETWORK all") | |
3368 | dev[0].wait_disconnected() | |
3369 | ||
3370 | pac = "wpa_supplicant EAP-FAST PAC file - version 1\n" | |
3371 | pac += "START\n" | |
3372 | pac += "PAC-Type\n" | |
3373 | pac += "END\n" | |
3374 | if "OK" not in dev[0].request("SET blob fast_pac_text_errors " + pac.encode("hex")): | |
3375 | raise Exception("Could not set blob") | |
3376 | ||
3377 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3378 | identity="user", anonymous_identity="FAST", | |
3379 | password="password", | |
3380 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3381 | phase1="fast_provisioning=1", | |
3382 | pac_file="blob://fast_pac_text_errors", | |
3383 | scan_freq="2412", wait_connect=False) | |
3384 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], timeout=5) | |
3385 | if ev is None: | |
3386 | raise Exception("Failure not reported") | |
3387 | dev[0].request("REMOVE_NETWORK all") | |
3388 | dev[0].wait_disconnected() | |
3389 | ||
3390 | dev[0].request("FLUSH") | |
3391 | if "OK" not in dev[0].request("SET blob fast_pac_text_errors "): | |
3392 | raise Exception("Could not set blob") | |
3393 | ||
3394 | with alloc_fail(dev[0], 1, "eap_fast_add_pac_data"): | |
3395 | for i in range(3): | |
3396 | params = int_eap_server_params() | |
3397 | params['ssid'] = "test-wpa2-eap-2" | |
3398 | params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i | |
3399 | params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i | |
3400 | params['eap_fast_a_id_info'] = "test server %d" % i | |
3401 | ||
8b8a1864 | 3402 | hapd2 = hostapd.add_ap(apdev[1], params) |
592790bf JM |
3403 | |
3404 | dev[0].connect("test-wpa2-eap-2", key_mgmt="WPA-EAP", eap="FAST", | |
3405 | identity="user", anonymous_identity="FAST", | |
3406 | password="password", | |
3407 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3408 | phase1="fast_provisioning=1", | |
3409 | pac_file="blob://fast_pac_text_errors", | |
3410 | scan_freq="2412", wait_connect=False) | |
3411 | dev[0].wait_connected() | |
3412 | dev[0].request("REMOVE_NETWORK all") | |
3413 | dev[0].wait_disconnected() | |
3414 | ||
3415 | hapd2.disable() | |
3416 | ||
3417 | def test_ap_wpa2_eap_fast_pac_truncate(dev, apdev): | |
3418 | """EAP-FAST and PAC list truncation""" | |
3419 | check_eap_capa(dev[0], "FAST") | |
3420 | if "OK" not in dev[0].request("SET blob fast_pac_truncate "): | |
3421 | raise Exception("Could not set blob") | |
3422 | for i in range(5): | |
3423 | params = int_eap_server_params() | |
3424 | params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i | |
3425 | params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i | |
3426 | params['eap_fast_a_id_info'] = "test server %d" % i | |
8b8a1864 | 3427 | hapd = hostapd.add_ap(apdev[0], params) |
592790bf JM |
3428 | |
3429 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3430 | identity="user", anonymous_identity="FAST", | |
3431 | password="password", | |
3432 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3433 | phase1="fast_provisioning=1 fast_max_pac_list_len=2", | |
3434 | pac_file="blob://fast_pac_truncate", | |
3435 | scan_freq="2412", wait_connect=False) | |
3436 | dev[0].wait_connected() | |
3437 | dev[0].request("REMOVE_NETWORK all") | |
3438 | dev[0].wait_disconnected() | |
3439 | ||
3440 | hapd.disable() | |
3441 | ||
3442 | def test_ap_wpa2_eap_fast_pac_refresh(dev, apdev): | |
3443 | """EAP-FAST and PAC refresh""" | |
3444 | check_eap_capa(dev[0], "FAST") | |
3445 | if "OK" not in dev[0].request("SET blob fast_pac_refresh "): | |
3446 | raise Exception("Could not set blob") | |
3447 | for i in range(2): | |
3448 | params = int_eap_server_params() | |
3449 | params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i | |
3450 | params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i | |
3451 | params['eap_fast_a_id_info'] = "test server %d" % i | |
3452 | params['pac_key_refresh_time'] = "1" | |
3453 | params['pac_key_lifetime'] = "10" | |
8b8a1864 | 3454 | hapd = hostapd.add_ap(apdev[0], params) |
592790bf JM |
3455 | |
3456 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3457 | identity="user", anonymous_identity="FAST", | |
3458 | password="password", | |
3459 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3460 | phase1="fast_provisioning=1", | |
3461 | pac_file="blob://fast_pac_refresh", | |
3462 | scan_freq="2412", wait_connect=False) | |
3463 | dev[0].wait_connected() | |
3464 | dev[0].request("REMOVE_NETWORK all") | |
3465 | dev[0].wait_disconnected() | |
3466 | ||
3467 | hapd.disable() | |
3468 | ||
3469 | for i in range(2): | |
3470 | params = int_eap_server_params() | |
3471 | params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i | |
3472 | params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i | |
3473 | params['eap_fast_a_id_info'] = "test server %d" % i | |
3474 | params['pac_key_refresh_time'] = "10" | |
3475 | params['pac_key_lifetime'] = "10" | |
8b8a1864 | 3476 | hapd = hostapd.add_ap(apdev[0], params) |
592790bf JM |
3477 | |
3478 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3479 | identity="user", anonymous_identity="FAST", | |
3480 | password="password", | |
3481 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3482 | phase1="fast_provisioning=1", | |
3483 | pac_file="blob://fast_pac_refresh", | |
3484 | scan_freq="2412", wait_connect=False) | |
3485 | dev[0].wait_connected() | |
3486 | dev[0].request("REMOVE_NETWORK all") | |
3487 | dev[0].wait_disconnected() | |
3488 | ||
3489 | hapd.disable() | |
3490 | ||
3491 | def test_ap_wpa2_eap_fast_pac_lifetime(dev, apdev): | |
3492 | """EAP-FAST and PAC lifetime""" | |
3493 | check_eap_capa(dev[0], "FAST") | |
3494 | if "OK" not in dev[0].request("SET blob fast_pac_refresh "): | |
3495 | raise Exception("Could not set blob") | |
3496 | ||
3497 | i = 0 | |
3498 | params = int_eap_server_params() | |
3499 | params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i | |
3500 | params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i | |
3501 | params['eap_fast_a_id_info'] = "test server %d" % i | |
3502 | params['pac_key_refresh_time'] = "0" | |
3503 | params['pac_key_lifetime'] = "2" | |
8b8a1864 | 3504 | hapd = hostapd.add_ap(apdev[0], params) |
592790bf JM |
3505 | |
3506 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3507 | identity="user", anonymous_identity="FAST", | |
3508 | password="password", | |
3509 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3510 | phase1="fast_provisioning=2", | |
3511 | pac_file="blob://fast_pac_refresh", | |
3512 | scan_freq="2412", wait_connect=False) | |
3513 | dev[0].wait_connected() | |
3514 | dev[0].request("DISCONNECT") | |
3515 | dev[0].wait_disconnected() | |
3516 | ||
3517 | time.sleep(3) | |
3518 | dev[0].request("PMKSA_FLUSH") | |
3519 | dev[0].request("RECONNECT") | |
3520 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
3521 | if ev is None: | |
3522 | raise Exception("No EAP-Failure seen after expired PAC") | |
3523 | dev[0].request("DISCONNECT") | |
3524 | dev[0].wait_disconnected() | |
3525 | ||
3526 | dev[0].select_network(id) | |
3527 | dev[0].wait_connected() | |
3528 | dev[0].request("REMOVE_NETWORK all") | |
3529 | dev[0].wait_disconnected() | |
3530 | ||
53a6f06a JM |
3531 | def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev): |
3532 | """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning""" | |
3b51cc63 | 3533 | check_eap_capa(dev[0], "FAST") |
53a6f06a | 3534 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 3535 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 3536 | eap_connect(dev[0], hapd, "FAST", "user", |
53a6f06a JM |
3537 | anonymous_identity="FAST", password="password", |
3538 | ca_cert="auth_serv/ca.pem", phase2="auth=GTC", | |
3539 | phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth") | |
a8375c94 | 3540 | hwsim_utils.test_connectivity(dev[0], hapd) |
2fc4749c JM |
3541 | res = eap_reauth(dev[0], "FAST") |
3542 | if res['tls_session_reused'] != '1': | |
3543 | raise Exception("EAP-FAST could not use PAC session ticket") | |
d4c7a2b9 | 3544 | |
95a15d79 JM |
3545 | def test_ap_wpa2_eap_fast_gtc_identity_change(dev, apdev): |
3546 | """WPA2-Enterprise connection using EAP-FAST/GTC and identity changing""" | |
3547 | check_eap_capa(dev[0], "FAST") | |
3548 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 3549 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 3550 | id = eap_connect(dev[0], hapd, "FAST", "user", |
95a15d79 JM |
3551 | anonymous_identity="FAST", password="password", |
3552 | ca_cert="auth_serv/ca.pem", phase2="auth=GTC", | |
3553 | phase1="fast_provisioning=2", | |
3554 | pac_file="blob://fast_pac_auth") | |
3555 | dev[0].set_network_quoted(id, "identity", "user2") | |
3556 | dev[0].wait_disconnected() | |
3557 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) | |
3558 | if ev is None: | |
3559 | raise Exception("EAP-FAST not started") | |
3560 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
3561 | if ev is None: | |
3562 | raise Exception("EAP failure not reported") | |
3563 | dev[0].wait_disconnected() | |
3564 | ||
27f2fab0 JM |
3565 | def test_ap_wpa2_eap_fast_prf_oom(dev, apdev): |
3566 | """WPA2-Enterprise connection using EAP-FAST and OOM in PRF""" | |
3567 | check_eap_capa(dev[0], "FAST") | |
cc71035f JM |
3568 | tls = dev[0].request("GET tls_library") |
3569 | if tls.startswith("OpenSSL"): | |
90b4c73f | 3570 | func = "tls_connection_get_eap_fast_key" |
cc71035f JM |
3571 | count = 2 |
3572 | elif tls.startswith("internal"): | |
3573 | func = "tls_connection_prf" | |
3574 | count = 1 | |
3575 | else: | |
3576 | raise HwsimSkip("Unsupported TLS library") | |
27f2fab0 | 3577 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 3578 | hapd = hostapd.add_ap(apdev[0], params) |
cc71035f | 3579 | with alloc_fail(dev[0], count, func): |
27f2fab0 JM |
3580 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", |
3581 | identity="user", anonymous_identity="FAST", | |
3582 | password="password", ca_cert="auth_serv/ca.pem", | |
3583 | phase2="auth=GTC", | |
3584 | phase1="fast_provisioning=2", | |
3585 | pac_file="blob://fast_pac_auth", | |
3586 | wait_connect=False, scan_freq="2412") | |
3587 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
3588 | if ev is None: | |
3589 | raise Exception("EAP failure not reported") | |
3590 | dev[0].request("DISCONNECT") | |
3591 | ||
6eddd530 JM |
3592 | def test_ap_wpa2_eap_fast_server_oom(dev, apdev): |
3593 | """EAP-FAST/MSCHAPv2 and server OOM""" | |
3594 | check_eap_capa(dev[0], "FAST") | |
3595 | ||
3596 | params = int_eap_server_params() | |
3597 | params['dh_file'] = 'auth_serv/dh.conf' | |
3598 | params['pac_opaque_encr_key'] = '000102030405060708090a0b0c0d0e0f' | |
3599 | params['eap_fast_a_id'] = '1011' | |
3600 | params['eap_fast_a_id_info'] = 'another test server' | |
8b8a1864 | 3601 | hapd = hostapd.add_ap(apdev[0], params) |
6eddd530 JM |
3602 | |
3603 | with alloc_fail(hapd, 1, "tls_session_ticket_ext_cb"): | |
3b3e2687 | 3604 | id = eap_connect(dev[0], hapd, "FAST", "user", |
6eddd530 JM |
3605 | anonymous_identity="FAST", password="password", |
3606 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3607 | phase1="fast_provisioning=1", | |
3608 | pac_file="blob://fast_pac", | |
3609 | expect_failure=True) | |
3610 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
3611 | if ev is None: | |
3612 | raise Exception("No EAP failure reported") | |
3613 | dev[0].wait_disconnected() | |
3614 | dev[0].request("DISCONNECT") | |
3615 | ||
3616 | dev[0].select_network(id, freq="2412") | |
3617 | ||
ecd07de4 JM |
3618 | def test_ap_wpa2_eap_fast_cipher_suites(dev, apdev): |
3619 | """EAP-FAST and different TLS cipher suites""" | |
3620 | check_eap_capa(dev[0], "FAST") | |
3621 | tls = dev[0].request("GET tls_library") | |
3622 | if not tls.startswith("OpenSSL"): | |
3623 | raise HwsimSkip("TLS library is not OpenSSL: " + tls) | |
3624 | ||
3625 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 3626 | hapd = hostapd.add_ap(apdev[0], params) |
ecd07de4 JM |
3627 | |
3628 | dev[0].request("SET blob fast_pac_ciphers ") | |
3b3e2687 | 3629 | eap_connect(dev[0], hapd, "FAST", "user", |
ecd07de4 JM |
3630 | anonymous_identity="FAST", password="password", |
3631 | ca_cert="auth_serv/ca.pem", phase2="auth=GTC", | |
3632 | phase1="fast_provisioning=2", | |
3633 | pac_file="blob://fast_pac_ciphers") | |
3634 | res = dev[0].get_status_field('EAP TLS cipher') | |
3635 | dev[0].request("REMOVE_NETWORK all") | |
3636 | dev[0].wait_disconnected() | |
3637 | if res != "DHE-RSA-AES256-SHA": | |
3638 | raise Exception("Unexpected cipher suite for provisioning: " + res) | |
3639 | ||
3640 | tests = [ "DHE-RSA-AES128-SHA", | |
3641 | "RC4-SHA", | |
3642 | "AES128-SHA", | |
3643 | "AES256-SHA", | |
3644 | "DHE-RSA-AES256-SHA" ] | |
3645 | for cipher in tests: | |
71666dc3 JM |
3646 | dev[0].dump_monitor() |
3647 | logger.info("Testing " + cipher) | |
3648 | try: | |
3b3e2687 | 3649 | eap_connect(dev[0], hapd, "FAST", "user", |
71666dc3 JM |
3650 | openssl_ciphers=cipher, |
3651 | anonymous_identity="FAST", password="password", | |
3652 | ca_cert="auth_serv/ca.pem", phase2="auth=GTC", | |
3653 | pac_file="blob://fast_pac_ciphers") | |
3654 | except Exception, e: | |
3655 | if "Could not select EAP method" in str(e) and cipher == "RC4-SHA": | |
3656 | tls = dev[0].request("GET tls_library") | |
3657 | if "run=OpenSSL 1.1" in tls: | |
3658 | logger.info("Allow failure due to missing TLS library support") | |
3659 | dev[0].request("REMOVE_NETWORK all") | |
3660 | dev[0].wait_disconnected() | |
3661 | continue | |
3662 | raise | |
ecd07de4 JM |
3663 | res = dev[0].get_status_field('EAP TLS cipher') |
3664 | dev[0].request("REMOVE_NETWORK all") | |
3665 | dev[0].wait_disconnected() | |
3666 | if res != cipher: | |
3667 | raise Exception("Unexpected TLS cipher info (configured %s): %s" % (cipher, res)) | |
3668 | ||
4c626382 JM |
3669 | def test_ap_wpa2_eap_fast_prov(dev, apdev): |
3670 | """EAP-FAST and provisioning options""" | |
3671 | check_eap_capa(dev[0], "FAST") | |
3672 | if "OK" not in dev[0].request("SET blob fast_pac_prov "): | |
3673 | raise Exception("Could not set blob") | |
3674 | ||
3675 | i = 100 | |
3676 | params = int_eap_server_params() | |
3677 | params['disable_pmksa_caching'] = '1' | |
3678 | params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i | |
3679 | params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i | |
3680 | params['eap_fast_a_id_info'] = "test server %d" % i | |
3681 | params['eap_fast_prov'] = "0" | |
3682 | hapd = hostapd.add_ap(apdev[0], params) | |
3683 | ||
3684 | logger.info("Provisioning attempt while server has provisioning disabled") | |
3685 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
3686 | identity="user", anonymous_identity="FAST", | |
3687 | password="password", | |
3688 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3689 | phase1="fast_provisioning=2", | |
3690 | pac_file="blob://fast_pac_prov", | |
3691 | scan_freq="2412", wait_connect=False) | |
3692 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"], | |
3693 | timeout=15) | |
3694 | if ev is None: | |
3695 | raise Exception("EAP result not reported") | |
3696 | if "parameter='failure'" not in ev: | |
3697 | raise Exception("Unexpected EAP result: " + ev) | |
3698 | dev[0].wait_disconnected() | |
3699 | dev[0].request("DISCONNECT") | |
3700 | dev[0].dump_monitor() | |
3701 | ||
3702 | hapd.disable() | |
3703 | logger.info("Authenticated provisioning") | |
3704 | hapd.set("eap_fast_prov", "2") | |
3705 | hapd.enable() | |
3706 | ||
3707 | dev[0].select_network(id, freq="2412") | |
3708 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"], | |
3709 | timeout=15) | |
3710 | if ev is None: | |
3711 | raise Exception("EAP result not reported") | |
3712 | if "parameter='success'" not in ev: | |
3713 | raise Exception("Unexpected EAP result: " + ev) | |
3714 | dev[0].wait_connected() | |
3715 | dev[0].request("DISCONNECT") | |
3716 | dev[0].wait_disconnected() | |
3717 | dev[0].dump_monitor() | |
3718 | ||
3719 | hapd.disable() | |
3720 | logger.info("Provisioning disabled - using previously provisioned PAC") | |
3721 | hapd.set("eap_fast_prov", "0") | |
3722 | hapd.enable() | |
3723 | ||
3724 | dev[0].select_network(id, freq="2412") | |
3725 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"], | |
3726 | timeout=15) | |
3727 | if ev is None: | |
3728 | raise Exception("EAP result not reported") | |
3729 | if "parameter='success'" not in ev: | |
3730 | raise Exception("Unexpected EAP result: " + ev) | |
3731 | dev[0].wait_connected() | |
3732 | dev[0].request("DISCONNECT") | |
3733 | dev[0].wait_disconnected() | |
3734 | dev[0].dump_monitor() | |
3735 | ||
3736 | logger.info("Drop PAC and verify connection failure") | |
3737 | if "OK" not in dev[0].request("SET blob fast_pac_prov "): | |
3738 | raise Exception("Could not set blob") | |
3739 | ||
3740 | dev[0].select_network(id, freq="2412") | |
3741 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"], | |
3742 | timeout=15) | |
3743 | if ev is None: | |
3744 | raise Exception("EAP result not reported") | |
3745 | if "parameter='failure'" not in ev: | |
3746 | raise Exception("Unexpected EAP result: " + ev) | |
3747 | dev[0].wait_disconnected() | |
3748 | dev[0].request("DISCONNECT") | |
3749 | dev[0].dump_monitor() | |
3750 | ||
3751 | hapd.disable() | |
3752 | logger.info("Anonymous provisioning") | |
3753 | hapd.set("eap_fast_prov", "1") | |
3754 | hapd.enable() | |
3755 | dev[0].set_network_quoted(id, "phase1", "fast_provisioning=1") | |
3756 | dev[0].select_network(id, freq="2412") | |
3757 | # Anonymous provisioning results in EAP-Failure first | |
3758 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"], | |
3759 | timeout=15) | |
3760 | if ev is None: | |
3761 | raise Exception("EAP result not reported") | |
3762 | if "parameter='failure'" not in ev: | |
3763 | raise Exception("Unexpected EAP result: " + ev) | |
3764 | dev[0].wait_disconnected() | |
3765 | # And then the actual data connection | |
3766 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"], | |
3767 | timeout=15) | |
3768 | if ev is None: | |
3769 | raise Exception("EAP result not reported") | |
3770 | if "parameter='success'" not in ev: | |
3771 | raise Exception("Unexpected EAP result: " + ev) | |
3772 | dev[0].wait_connected() | |
3773 | dev[0].request("DISCONNECT") | |
3774 | dev[0].wait_disconnected() | |
3775 | dev[0].dump_monitor() | |
3776 | ||
3777 | hapd.disable() | |
3778 | logger.info("Provisioning disabled - using previously provisioned PAC") | |
3779 | hapd.set("eap_fast_prov", "0") | |
3780 | hapd.enable() | |
3781 | ||
3782 | dev[0].select_network(id, freq="2412") | |
3783 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"], | |
3784 | timeout=15) | |
3785 | if ev is None: | |
3786 | raise Exception("EAP result not reported") | |
3787 | if "parameter='success'" not in ev: | |
3788 | raise Exception("Unexpected EAP result: " + ev) | |
3789 | dev[0].wait_connected() | |
3790 | dev[0].request("DISCONNECT") | |
3791 | dev[0].wait_disconnected() | |
3792 | dev[0].dump_monitor() | |
3793 | ||
d4c7a2b9 JM |
3794 | def test_ap_wpa2_eap_tls_ocsp(dev, apdev): |
3795 | """WPA2-Enterprise connection using EAP-TLS and verifying OCSP""" | |
0dae8c99 | 3796 | check_ocsp_support(dev[0]) |
16c43d2a | 3797 | check_pkcs12_support(dev[0]) |
d4c7a2b9 | 3798 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
3799 | hapd = hostapd.add_ap(apdev[0], params) |
3800 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
d4c7a2b9 JM |
3801 | private_key="auth_serv/user.pkcs12", |
3802 | private_key_passwd="whatever", ocsp=2) | |
3803 | ||
98d125ca JM |
3804 | def test_ap_wpa2_eap_tls_ocsp_multi(dev, apdev): |
3805 | """WPA2-Enterprise connection using EAP-TLS and verifying OCSP-multi""" | |
3806 | check_ocsp_multi_support(dev[0]) | |
3807 | check_pkcs12_support(dev[0]) | |
3808 | ||
3809 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
3810 | hapd = hostapd.add_ap(apdev[0], params) |
3811 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
98d125ca JM |
3812 | private_key="auth_serv/user.pkcs12", |
3813 | private_key_passwd="whatever", ocsp=2) | |
3814 | ||
64e05f96 | 3815 | def int_eap_server_params(): |
d4c7a2b9 JM |
3816 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
3817 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
3818 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
3819 | "ca_cert": "auth_serv/ca.pem", | |
3820 | "server_cert": "auth_serv/server.pem", | |
8adce07a JM |
3821 | "private_key": "auth_serv/server.key", |
3822 | "dh_file": "auth_serv/dh.conf" } | |
64e05f96 | 3823 | return params |
d2a1047e | 3824 | |
58a40620 JM |
3825 | def test_ap_wpa2_eap_tls_ocsp_key_id(dev, apdev, params): |
3826 | """EAP-TLS and OCSP certificate signed OCSP response using key ID""" | |
3827 | check_ocsp_support(dev[0]) | |
3828 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-key-id.der") | |
3829 | if not os.path.exists(ocsp): | |
3830 | raise HwsimSkip("No OCSP response available") | |
3831 | params = int_eap_server_params() | |
3832 | params["ocsp_stapling_response"] = ocsp | |
8b8a1864 | 3833 | hostapd.add_ap(apdev[0], params) |
58a40620 JM |
3834 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
3835 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3836 | private_key="auth_serv/user.pkcs12", | |
3837 | private_key_passwd="whatever", ocsp=2, | |
3838 | scan_freq="2412") | |
3839 | ||
d79ce4a6 JM |
3840 | def test_ap_wpa2_eap_tls_ocsp_ca_signed_good(dev, apdev, params): |
3841 | """EAP-TLS and CA signed OCSP response (good)""" | |
3842 | check_ocsp_support(dev[0]) | |
3843 | ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed.der") | |
3844 | if not os.path.exists(ocsp): | |
3845 | raise HwsimSkip("No OCSP response available") | |
3846 | params = int_eap_server_params() | |
3847 | params["ocsp_stapling_response"] = ocsp | |
8b8a1864 | 3848 | hostapd.add_ap(apdev[0], params) |
d79ce4a6 JM |
3849 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
3850 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3851 | private_key="auth_serv/user.pkcs12", | |
3852 | private_key_passwd="whatever", ocsp=2, | |
3853 | scan_freq="2412") | |
3854 | ||
3855 | def test_ap_wpa2_eap_tls_ocsp_ca_signed_revoked(dev, apdev, params): | |
3856 | """EAP-TLS and CA signed OCSP response (revoked)""" | |
3857 | check_ocsp_support(dev[0]) | |
3858 | ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-revoked.der") | |
3859 | if not os.path.exists(ocsp): | |
3860 | raise HwsimSkip("No OCSP response available") | |
3861 | params = int_eap_server_params() | |
3862 | params["ocsp_stapling_response"] = ocsp | |
8b8a1864 | 3863 | hostapd.add_ap(apdev[0], params) |
d79ce4a6 JM |
3864 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
3865 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3866 | private_key="auth_serv/user.pkcs12", | |
3867 | private_key_passwd="whatever", ocsp=2, | |
3868 | wait_connect=False, scan_freq="2412") | |
3869 | count = 0 | |
3870 | while True: | |
3871 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
3872 | if ev is None: | |
3873 | raise Exception("Timeout on EAP status") | |
3874 | if 'bad certificate status response' in ev: | |
3875 | break | |
3876 | if 'certificate revoked' in ev: | |
3877 | break | |
3878 | count = count + 1 | |
3879 | if count > 10: | |
3880 | raise Exception("Unexpected number of EAP status messages") | |
3881 | ||
3882 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3883 | if ev is None: | |
3884 | raise Exception("Timeout on EAP failure report") | |
3885 | ||
3886 | def test_ap_wpa2_eap_tls_ocsp_ca_signed_unknown(dev, apdev, params): | |
3887 | """EAP-TLS and CA signed OCSP response (unknown)""" | |
3888 | check_ocsp_support(dev[0]) | |
3889 | ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-unknown.der") | |
3890 | if not os.path.exists(ocsp): | |
3891 | raise HwsimSkip("No OCSP response available") | |
3892 | params = int_eap_server_params() | |
3893 | params["ocsp_stapling_response"] = ocsp | |
8b8a1864 | 3894 | hostapd.add_ap(apdev[0], params) |
d79ce4a6 JM |
3895 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
3896 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3897 | private_key="auth_serv/user.pkcs12", | |
3898 | private_key_passwd="whatever", ocsp=2, | |
3899 | wait_connect=False, scan_freq="2412") | |
3900 | count = 0 | |
3901 | while True: | |
3902 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
3903 | if ev is None: | |
3904 | raise Exception("Timeout on EAP status") | |
3905 | if 'bad certificate status response' in ev: | |
3906 | break | |
3907 | count = count + 1 | |
3908 | if count > 10: | |
3909 | raise Exception("Unexpected number of EAP status messages") | |
3910 | ||
3911 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3912 | if ev is None: | |
3913 | raise Exception("Timeout on EAP failure report") | |
3914 | ||
3915 | def test_ap_wpa2_eap_tls_ocsp_server_signed(dev, apdev, params): | |
3916 | """EAP-TLS and server signed OCSP response""" | |
3917 | check_ocsp_support(dev[0]) | |
3918 | ocsp = os.path.join(params['logdir'], "ocsp-resp-server-signed.der") | |
3919 | if not os.path.exists(ocsp): | |
3920 | raise HwsimSkip("No OCSP response available") | |
3921 | params = int_eap_server_params() | |
3922 | params["ocsp_stapling_response"] = ocsp | |
8b8a1864 | 3923 | hostapd.add_ap(apdev[0], params) |
d79ce4a6 JM |
3924 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
3925 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3926 | private_key="auth_serv/user.pkcs12", | |
3927 | private_key_passwd="whatever", ocsp=2, | |
3928 | wait_connect=False, scan_freq="2412") | |
3929 | count = 0 | |
3930 | while True: | |
3931 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
3932 | if ev is None: | |
3933 | raise Exception("Timeout on EAP status") | |
3934 | if 'bad certificate status response' in ev: | |
3935 | break | |
3936 | count = count + 1 | |
3937 | if count > 10: | |
3938 | raise Exception("Unexpected number of EAP status messages") | |
3939 | ||
3940 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3941 | if ev is None: | |
3942 | raise Exception("Timeout on EAP failure report") | |
3943 | ||
d2a1047e JM |
3944 | def test_ap_wpa2_eap_tls_ocsp_invalid_data(dev, apdev): |
3945 | """WPA2-Enterprise connection using EAP-TLS and invalid OCSP data""" | |
0dae8c99 | 3946 | check_ocsp_support(dev[0]) |
d2a1047e JM |
3947 | params = int_eap_server_params() |
3948 | params["ocsp_stapling_response"] = "auth_serv/ocsp-req.der" | |
8b8a1864 | 3949 | hostapd.add_ap(apdev[0], params) |
d2a1047e JM |
3950 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
3951 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3952 | private_key="auth_serv/user.pkcs12", | |
3953 | private_key_passwd="whatever", ocsp=2, | |
3954 | wait_connect=False, scan_freq="2412") | |
3955 | count = 0 | |
3956 | while True: | |
3957 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
3958 | if ev is None: | |
3959 | raise Exception("Timeout on EAP status") | |
3960 | if 'bad certificate status response' in ev: | |
3961 | break | |
3962 | count = count + 1 | |
3963 | if count > 10: | |
3964 | raise Exception("Unexpected number of EAP status messages") | |
3965 | ||
3966 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3967 | if ev is None: | |
3968 | raise Exception("Timeout on EAP failure report") | |
3969 | ||
64e05f96 JM |
3970 | def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev): |
3971 | """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response""" | |
0dae8c99 | 3972 | check_ocsp_support(dev[0]) |
64e05f96 JM |
3973 | params = int_eap_server_params() |
3974 | params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid" | |
8b8a1864 | 3975 | hostapd.add_ap(apdev[0], params) |
df7ad0fa JM |
3976 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
3977 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3978 | private_key="auth_serv/user.pkcs12", | |
3979 | private_key_passwd="whatever", ocsp=2, | |
3980 | wait_connect=False, scan_freq="2412") | |
3981 | count = 0 | |
3982 | while True: | |
3983 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
3984 | if ev is None: | |
3985 | raise Exception("Timeout on EAP status") | |
3986 | if 'bad certificate status response' in ev: | |
3987 | break | |
3988 | count = count + 1 | |
3989 | if count > 10: | |
3990 | raise Exception("Unexpected number of EAP status messages") | |
3991 | ||
3992 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3993 | if ev is None: | |
3994 | raise Exception("Timeout on EAP failure report") | |
3995 | ||
3996 | def test_ap_wpa2_eap_tls_ocsp_unknown_sign(dev, apdev): | |
3997 | """WPA2-Enterprise connection using EAP-TLS and unknown OCSP signer""" | |
0dae8c99 | 3998 | check_ocsp_support(dev[0]) |
df7ad0fa JM |
3999 | params = int_eap_server_params() |
4000 | params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-unknown-sign" | |
8b8a1864 | 4001 | hostapd.add_ap(apdev[0], params) |
d4c7a2b9 JM |
4002 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4003 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
4004 | private_key="auth_serv/user.pkcs12", | |
4005 | private_key_passwd="whatever", ocsp=2, | |
4006 | wait_connect=False, scan_freq="2412") | |
4007 | count = 0 | |
4008 | while True: | |
4009 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
4010 | if ev is None: | |
4011 | raise Exception("Timeout on EAP status") | |
4012 | if 'bad certificate status response' in ev: | |
4013 | break | |
4014 | count = count + 1 | |
4015 | if count > 10: | |
4016 | raise Exception("Unexpected number of EAP status messages") | |
4017 | ||
4018 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4019 | if ev is None: | |
4020 | raise Exception("Timeout on EAP failure report") | |
64e05f96 | 4021 | |
37b4a66c JM |
4022 | def test_ap_wpa2_eap_ttls_ocsp_revoked(dev, apdev, params): |
4023 | """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked""" | |
0dae8c99 | 4024 | check_ocsp_support(dev[0]) |
37b4a66c JM |
4025 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-revoked.der") |
4026 | if not os.path.exists(ocsp): | |
4027 | raise HwsimSkip("No OCSP response available") | |
4028 | params = int_eap_server_params() | |
4029 | params["ocsp_stapling_response"] = ocsp | |
8b8a1864 | 4030 | hostapd.add_ap(apdev[0], params) |
37b4a66c JM |
4031 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4032 | identity="pap user", ca_cert="auth_serv/ca.pem", | |
4033 | anonymous_identity="ttls", password="password", | |
4034 | phase2="auth=PAP", ocsp=2, | |
4035 | wait_connect=False, scan_freq="2412") | |
4036 | count = 0 | |
4037 | while True: | |
4038 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
4039 | if ev is None: | |
4040 | raise Exception("Timeout on EAP status") | |
4041 | if 'bad certificate status response' in ev: | |
4042 | break | |
4043 | if 'certificate revoked' in ev: | |
4044 | break | |
4045 | count = count + 1 | |
4046 | if count > 10: | |
4047 | raise Exception("Unexpected number of EAP status messages") | |
4048 | ||
4049 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4050 | if ev is None: | |
4051 | raise Exception("Timeout on EAP failure report") | |
4052 | ||
4053 | def test_ap_wpa2_eap_ttls_ocsp_unknown(dev, apdev, params): | |
4054 | """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked""" | |
0dae8c99 | 4055 | check_ocsp_support(dev[0]) |
37b4a66c JM |
4056 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der") |
4057 | if not os.path.exists(ocsp): | |
4058 | raise HwsimSkip("No OCSP response available") | |
4059 | params = int_eap_server_params() | |
4060 | params["ocsp_stapling_response"] = ocsp | |
8b8a1864 | 4061 | hostapd.add_ap(apdev[0], params) |
37b4a66c JM |
4062 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4063 | identity="pap user", ca_cert="auth_serv/ca.pem", | |
4064 | anonymous_identity="ttls", password="password", | |
4065 | phase2="auth=PAP", ocsp=2, | |
4066 | wait_connect=False, scan_freq="2412") | |
4067 | count = 0 | |
4068 | while True: | |
4069 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
4070 | if ev is None: | |
4071 | raise Exception("Timeout on EAP status") | |
4072 | if 'bad certificate status response' in ev: | |
4073 | break | |
4074 | count = count + 1 | |
4075 | if count > 10: | |
4076 | raise Exception("Unexpected number of EAP status messages") | |
4077 | ||
4078 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4079 | if ev is None: | |
4080 | raise Exception("Timeout on EAP failure report") | |
4081 | ||
4082 | def test_ap_wpa2_eap_ttls_optional_ocsp_unknown(dev, apdev, params): | |
4083 | """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked""" | |
4084 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der") | |
4085 | if not os.path.exists(ocsp): | |
4086 | raise HwsimSkip("No OCSP response available") | |
4087 | params = int_eap_server_params() | |
4088 | params["ocsp_stapling_response"] = ocsp | |
8b8a1864 | 4089 | hostapd.add_ap(apdev[0], params) |
37b4a66c JM |
4090 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4091 | identity="pap user", ca_cert="auth_serv/ca.pem", | |
4092 | anonymous_identity="ttls", password="password", | |
4093 | phase2="auth=PAP", ocsp=1, scan_freq="2412") | |
4094 | ||
52811b8c JM |
4095 | def test_ap_wpa2_eap_tls_intermediate_ca(dev, apdev, params): |
4096 | """EAP-TLS with intermediate server/user CA""" | |
4097 | params = int_eap_server_params() | |
4098 | params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem" | |
4099 | params["server_cert"] = "auth_serv/iCA-server/server.pem" | |
4100 | params["private_key"] = "auth_serv/iCA-server/server.key" | |
8b8a1864 | 4101 | hostapd.add_ap(apdev[0], params) |
52811b8c JM |
4102 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4103 | identity="tls user", | |
4104 | ca_cert="auth_serv/iCA-user/ca-and-root.pem", | |
4105 | client_cert="auth_serv/iCA-user/user.pem", | |
4106 | private_key="auth_serv/iCA-user/user.key", | |
4107 | scan_freq="2412") | |
4108 | ||
4109 | def root_ocsp(cert): | |
4110 | ca = "auth_serv/ca.pem" | |
4111 | ||
4112 | fd2, fn2 = tempfile.mkstemp() | |
4113 | os.close(fd2) | |
4114 | ||
d40d959e JB |
4115 | arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, "-sha256", |
4116 | "-cert", cert, "-no_nonce", "-text" ] | |
4117 | logger.info(' '.join(arg)) | |
52811b8c JM |
4118 | cmd = subprocess.Popen(arg, stdout=subprocess.PIPE, |
4119 | stderr=subprocess.PIPE) | |
4120 | res = cmd.stdout.read() + "\n" + cmd.stderr.read() | |
4121 | cmd.stdout.close() | |
4122 | cmd.stderr.close() | |
d40d959e JB |
4123 | cmd.wait() |
4124 | if cmd.returncode != 0: | |
4125 | raise Exception("bad return code from openssl ocsp\n\n" + res) | |
52811b8c JM |
4126 | logger.info("OCSP request:\n" + res) |
4127 | ||
4128 | fd, fn = tempfile.mkstemp() | |
4129 | os.close(fd) | |
40ae4a2f JM |
4130 | arg = [ "openssl", "ocsp", "-index", "auth_serv/rootCA/index.txt", |
4131 | "-rsigner", ca, "-rkey", "auth_serv/ca-key.pem", | |
52811b8c JM |
4132 | "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other", |
4133 | "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn, | |
4134 | "-text" ] | |
4135 | cmd = subprocess.Popen(arg, stdout=subprocess.PIPE, | |
4136 | stderr=subprocess.PIPE) | |
4137 | res = cmd.stdout.read() + "\n" + cmd.stderr.read() | |
4138 | cmd.stdout.close() | |
4139 | cmd.stderr.close() | |
d40d959e JB |
4140 | cmd.wait() |
4141 | if cmd.returncode != 0: | |
4142 | raise Exception("bad return code from openssl ocsp\n\n" + res) | |
52811b8c JM |
4143 | logger.info("OCSP response:\n" + res) |
4144 | os.unlink(fn2) | |
4145 | return fn | |
4146 | ||
b7288e5d | 4147 | def ica_ocsp(cert, md="-sha256"): |
52811b8c JM |
4148 | prefix = "auth_serv/iCA-server/" |
4149 | ca = prefix + "cacert.pem" | |
4150 | cert = prefix + cert | |
4151 | ||
4152 | fd2, fn2 = tempfile.mkstemp() | |
4153 | os.close(fd2) | |
4154 | ||
b7288e5d | 4155 | arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, md, |
d40d959e | 4156 | "-cert", cert, "-no_nonce", "-text" ] |
52811b8c JM |
4157 | cmd = subprocess.Popen(arg, stdout=subprocess.PIPE, |
4158 | stderr=subprocess.PIPE) | |
4159 | res = cmd.stdout.read() + "\n" + cmd.stderr.read() | |
4160 | cmd.stdout.close() | |
4161 | cmd.stderr.close() | |
d40d959e JB |
4162 | cmd.wait() |
4163 | if cmd.returncode != 0: | |
4164 | raise Exception("bad return code from openssl ocsp\n\n" + res) | |
52811b8c JM |
4165 | logger.info("OCSP request:\n" + res) |
4166 | ||
4167 | fd, fn = tempfile.mkstemp() | |
4168 | os.close(fd) | |
4169 | arg = [ "openssl", "ocsp", "-index", prefix + "index.txt", | |
4170 | "-rsigner", ca, "-rkey", prefix + "private/cakey.pem", | |
4171 | "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other", | |
4172 | "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn, | |
4173 | "-text" ] | |
4174 | cmd = subprocess.Popen(arg, stdout=subprocess.PIPE, | |
4175 | stderr=subprocess.PIPE) | |
4176 | res = cmd.stdout.read() + "\n" + cmd.stderr.read() | |
4177 | cmd.stdout.close() | |
4178 | cmd.stderr.close() | |
d40d959e JB |
4179 | cmd.wait() |
4180 | if cmd.returncode != 0: | |
4181 | raise Exception("bad return code from openssl ocsp\n\n" + res) | |
52811b8c JM |
4182 | logger.info("OCSP response:\n" + res) |
4183 | os.unlink(fn2) | |
4184 | return fn | |
4185 | ||
4186 | def test_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params): | |
4187 | """EAP-TLS with intermediate server/user CA and OCSP on server certificate""" | |
b7288e5d JM |
4188 | run_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params, "-sha256") |
4189 | ||
4190 | def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_sha1(dev, apdev, params): | |
4191 | """EAP-TLS with intermediate server/user CA and OCSP on server certificate )SHA1)""" | |
4192 | run_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params, "-sha1") | |
4193 | ||
4194 | def run_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params, md): | |
52811b8c JM |
4195 | params = int_eap_server_params() |
4196 | params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem" | |
4197 | params["server_cert"] = "auth_serv/iCA-server/server.pem" | |
4198 | params["private_key"] = "auth_serv/iCA-server/server.key" | |
b7288e5d | 4199 | fn = ica_ocsp("server.pem", md) |
52811b8c JM |
4200 | params["ocsp_stapling_response"] = fn |
4201 | try: | |
8b8a1864 | 4202 | hostapd.add_ap(apdev[0], params) |
52811b8c JM |
4203 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4204 | identity="tls user", | |
4205 | ca_cert="auth_serv/iCA-user/ca-and-root.pem", | |
4206 | client_cert="auth_serv/iCA-user/user.pem", | |
4207 | private_key="auth_serv/iCA-user/user.key", | |
4208 | scan_freq="2412", ocsp=2) | |
4209 | finally: | |
4210 | os.unlink(fn) | |
4211 | ||
4212 | def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params): | |
4213 | """EAP-TLS with intermediate server/user CA and OCSP on revoked server certificate""" | |
b7288e5d JM |
4214 | run_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params, |
4215 | "-sha256") | |
4216 | ||
4217 | def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked_sha1(dev, apdev, params): | |
4218 | """EAP-TLS with intermediate server/user CA and OCSP on revoked server certificate (SHA1)""" | |
4219 | run_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params, | |
4220 | "-sha1") | |
4221 | ||
4222 | def run_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params, md): | |
52811b8c JM |
4223 | params = int_eap_server_params() |
4224 | params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem" | |
4225 | params["server_cert"] = "auth_serv/iCA-server/server-revoked.pem" | |
4226 | params["private_key"] = "auth_serv/iCA-server/server-revoked.key" | |
b7288e5d | 4227 | fn = ica_ocsp("server-revoked.pem", md) |
52811b8c JM |
4228 | params["ocsp_stapling_response"] = fn |
4229 | try: | |
8b8a1864 | 4230 | hostapd.add_ap(apdev[0], params) |
52811b8c JM |
4231 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4232 | identity="tls user", | |
4233 | ca_cert="auth_serv/iCA-user/ca-and-root.pem", | |
4234 | client_cert="auth_serv/iCA-user/user.pem", | |
4235 | private_key="auth_serv/iCA-user/user.key", | |
4236 | scan_freq="2412", ocsp=1, wait_connect=False) | |
4237 | count = 0 | |
4238 | while True: | |
4239 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS", | |
4240 | "CTRL-EVENT-EAP-SUCCESS"]) | |
4241 | if ev is None: | |
4242 | raise Exception("Timeout on EAP status") | |
4243 | if "CTRL-EVENT-EAP-SUCCESS" in ev: | |
4244 | raise Exception("Unexpected EAP-Success") | |
4245 | if 'bad certificate status response' in ev: | |
4246 | break | |
4247 | if 'certificate revoked' in ev: | |
4248 | break | |
4249 | count = count + 1 | |
4250 | if count > 10: | |
4251 | raise Exception("Unexpected number of EAP status messages") | |
4252 | ||
4253 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4254 | if ev is None: | |
4255 | raise Exception("Timeout on EAP failure report") | |
4256 | dev[0].request("REMOVE_NETWORK all") | |
4257 | dev[0].wait_disconnected() | |
4258 | finally: | |
4259 | os.unlink(fn) | |
4260 | ||
4261 | def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi_missing_resp(dev, apdev, params): | |
4262 | """EAP-TLS with intermediate server/user CA and OCSP multi missing response""" | |
4263 | check_ocsp_support(dev[0]) | |
4264 | check_ocsp_multi_support(dev[0]) | |
4265 | ||
4266 | params = int_eap_server_params() | |
4267 | params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem" | |
4268 | params["server_cert"] = "auth_serv/iCA-server/server.pem" | |
4269 | params["private_key"] = "auth_serv/iCA-server/server.key" | |
4270 | fn = ica_ocsp("server.pem") | |
4271 | params["ocsp_stapling_response"] = fn | |
4272 | try: | |
8b8a1864 | 4273 | hostapd.add_ap(apdev[0], params) |
52811b8c JM |
4274 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4275 | identity="tls user", | |
4276 | ca_cert="auth_serv/iCA-user/ca-and-root.pem", | |
4277 | client_cert="auth_serv/iCA-user/user.pem", | |
4278 | private_key="auth_serv/iCA-user/user.key", | |
4279 | scan_freq="2412", ocsp=3, wait_connect=False) | |
4280 | count = 0 | |
4281 | while True: | |
4282 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS", | |
4283 | "CTRL-EVENT-EAP-SUCCESS"]) | |
4284 | if ev is None: | |
4285 | raise Exception("Timeout on EAP status") | |
4286 | if "CTRL-EVENT-EAP-SUCCESS" in ev: | |
4287 | raise Exception("Unexpected EAP-Success") | |
4288 | if 'bad certificate status response' in ev: | |
4289 | break | |
4290 | if 'certificate revoked' in ev: | |
4291 | break | |
4292 | count = count + 1 | |
4293 | if count > 10: | |
4294 | raise Exception("Unexpected number of EAP status messages") | |
4295 | ||
4296 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4297 | if ev is None: | |
4298 | raise Exception("Timeout on EAP failure report") | |
4299 | dev[0].request("REMOVE_NETWORK all") | |
4300 | dev[0].wait_disconnected() | |
4301 | finally: | |
4302 | os.unlink(fn) | |
4303 | ||
4304 | def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi(dev, apdev, params): | |
4305 | """EAP-TLS with intermediate server/user CA and OCSP multi OK""" | |
4306 | check_ocsp_support(dev[0]) | |
4307 | check_ocsp_multi_support(dev[0]) | |
4308 | ||
4309 | params = int_eap_server_params() | |
4310 | params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem" | |
4311 | params["server_cert"] = "auth_serv/iCA-server/server.pem" | |
4312 | params["private_key"] = "auth_serv/iCA-server/server.key" | |
4313 | fn = ica_ocsp("server.pem") | |
4314 | fn2 = root_ocsp("auth_serv/iCA-server/cacert.pem") | |
4315 | params["ocsp_stapling_response"] = fn | |
4316 | ||
4317 | with open(fn, "r") as f: | |
4318 | resp_server = f.read() | |
4319 | with open(fn2, "r") as f: | |
4320 | resp_ica = f.read() | |
4321 | ||
4322 | fd3, fn3 = tempfile.mkstemp() | |
4323 | try: | |
4324 | f = os.fdopen(fd3, 'w') | |
4325 | f.write(struct.pack(">L", len(resp_server))[1:4]) | |
4326 | f.write(resp_server) | |
4327 | f.write(struct.pack(">L", len(resp_ica))[1:4]) | |
4328 | f.write(resp_ica) | |
4329 | f.close() | |
4330 | ||
4331 | params["ocsp_stapling_response_multi"] = fn3 | |
4332 | ||
8b8a1864 | 4333 | hostapd.add_ap(apdev[0], params) |
52811b8c JM |
4334 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4335 | identity="tls user", | |
4336 | ca_cert="auth_serv/iCA-user/ca-and-root.pem", | |
4337 | client_cert="auth_serv/iCA-user/user.pem", | |
4338 | private_key="auth_serv/iCA-user/user.key", | |
40ae4a2f | 4339 | scan_freq="2412", ocsp=3) |
52811b8c JM |
4340 | dev[0].request("REMOVE_NETWORK all") |
4341 | dev[0].wait_disconnected() | |
4342 | finally: | |
4343 | os.unlink(fn) | |
4344 | os.unlink(fn2) | |
4345 | os.unlink(fn3) | |
4346 | ||
98d125ca JM |
4347 | def test_ap_wpa2_eap_tls_ocsp_multi_revoked(dev, apdev, params): |
4348 | """EAP-TLS and CA signed OCSP multi response (revoked)""" | |
4349 | check_ocsp_support(dev[0]) | |
4350 | check_ocsp_multi_support(dev[0]) | |
4351 | ||
4352 | ocsp_revoked = os.path.join(params['logdir'], | |
4353 | "ocsp-resp-ca-signed-revoked.der") | |
4354 | if not os.path.exists(ocsp_revoked): | |
4355 | raise HwsimSkip("No OCSP response (revoked) available") | |
4356 | ocsp_unknown = os.path.join(params['logdir'], | |
4357 | "ocsp-resp-ca-signed-unknown.der") | |
4358 | if not os.path.exists(ocsp_unknown): | |
4359 | raise HwsimSkip("No OCSP response(unknown) available") | |
4360 | ||
4361 | with open(ocsp_revoked, "r") as f: | |
4362 | resp_revoked = f.read() | |
4363 | with open(ocsp_unknown, "r") as f: | |
4364 | resp_unknown = f.read() | |
4365 | ||
4366 | fd, fn = tempfile.mkstemp() | |
4367 | try: | |
4368 | # This is not really a valid order of the OCSPResponse items in the | |
4369 | # list, but this works for now to verify parsing and processing of | |
4370 | # multiple responses. | |
4371 | f = os.fdopen(fd, 'w') | |
4372 | f.write(struct.pack(">L", len(resp_unknown))[1:4]) | |
4373 | f.write(resp_unknown) | |
4374 | f.write(struct.pack(">L", len(resp_revoked))[1:4]) | |
4375 | f.write(resp_revoked) | |
4376 | f.write(struct.pack(">L", 0)[1:4]) | |
4377 | f.write(struct.pack(">L", len(resp_unknown))[1:4]) | |
4378 | f.write(resp_unknown) | |
4379 | f.close() | |
4380 | ||
4381 | params = int_eap_server_params() | |
4382 | params["ocsp_stapling_response_multi"] = fn | |
8b8a1864 | 4383 | hostapd.add_ap(apdev[0], params) |
98d125ca JM |
4384 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4385 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
4386 | private_key="auth_serv/user.pkcs12", | |
4387 | private_key_passwd="whatever", ocsp=1, | |
4388 | wait_connect=False, scan_freq="2412") | |
4389 | count = 0 | |
4390 | while True: | |
4391 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS", | |
4392 | "CTRL-EVENT-EAP-SUCCESS"]) | |
4393 | if ev is None: | |
4394 | raise Exception("Timeout on EAP status") | |
4395 | if "CTRL-EVENT-EAP-SUCCESS" in ev: | |
4396 | raise Exception("Unexpected EAP-Success") | |
4397 | if 'bad certificate status response' in ev: | |
4398 | break | |
4399 | if 'certificate revoked' in ev: | |
4400 | break | |
4401 | count = count + 1 | |
4402 | if count > 10: | |
4403 | raise Exception("Unexpected number of EAP status messages") | |
4404 | finally: | |
4405 | os.unlink(fn) | |
4406 | ||
24579e70 | 4407 | def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev): |
64e05f96 | 4408 | """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)""" |
e78eb404 | 4409 | check_domain_match_full(dev[0]) |
64e05f96 JM |
4410 | params = int_eap_server_params() |
4411 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
4412 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
8b8a1864 | 4413 | hostapd.add_ap(apdev[0], params) |
64e05f96 JM |
4414 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4415 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
4416 | private_key="auth_serv/user.pkcs12", | |
4417 | private_key_passwd="whatever", | |
4418 | domain_suffix_match="server3.w1.fi", | |
4419 | scan_freq="2412") | |
24579e70 | 4420 | |
061cbb25 JM |
4421 | def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev): |
4422 | """WPA2-Enterprise using EAP-TLS and domainmatch (CN)""" | |
e78eb404 | 4423 | check_domain_match(dev[0]) |
061cbb25 JM |
4424 | params = int_eap_server_params() |
4425 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
4426 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
8b8a1864 | 4427 | hostapd.add_ap(apdev[0], params) |
061cbb25 JM |
4428 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4429 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
4430 | private_key="auth_serv/user.pkcs12", | |
4431 | private_key_passwd="whatever", | |
4432 | domain_match="server3.w1.fi", | |
4433 | scan_freq="2412") | |
4434 | ||
24579e70 JM |
4435 | def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev): |
4436 | """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)""" | |
4437 | check_domain_match_full(dev[0]) | |
4438 | params = int_eap_server_params() | |
4439 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
4440 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
8b8a1864 | 4441 | hostapd.add_ap(apdev[0], params) |
64e05f96 JM |
4442 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4443 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
4444 | private_key="auth_serv/user.pkcs12", | |
4445 | private_key_passwd="whatever", | |
4446 | domain_suffix_match="w1.fi", | |
4447 | scan_freq="2412") | |
4448 | ||
4449 | def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev): | |
4450 | """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)""" | |
e78eb404 | 4451 | check_domain_suffix_match(dev[0]) |
64e05f96 JM |
4452 | params = int_eap_server_params() |
4453 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
4454 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
8b8a1864 | 4455 | hostapd.add_ap(apdev[0], params) |
64e05f96 JM |
4456 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4457 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
4458 | private_key="auth_serv/user.pkcs12", | |
4459 | private_key_passwd="whatever", | |
4460 | domain_suffix_match="example.com", | |
4461 | wait_connect=False, | |
4462 | scan_freq="2412") | |
c61dca40 JM |
4463 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4464 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
4465 | private_key="auth_serv/user.pkcs12", | |
4466 | private_key_passwd="whatever", | |
4467 | domain_suffix_match="erver3.w1.fi", | |
4468 | wait_connect=False, | |
4469 | scan_freq="2412") | |
64e05f96 JM |
4470 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) |
4471 | if ev is None: | |
4472 | raise Exception("Timeout on EAP failure report") | |
c61dca40 JM |
4473 | ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"]) |
4474 | if ev is None: | |
4475 | raise Exception("Timeout on EAP failure report (2)") | |
6a4d0dbe | 4476 | |
061cbb25 JM |
4477 | def test_ap_wpa2_eap_tls_domain_mismatch_cn(dev, apdev): |
4478 | """WPA2-Enterprise using EAP-TLS and domain mismatch (CN)""" | |
e78eb404 | 4479 | check_domain_match(dev[0]) |
061cbb25 JM |
4480 | params = int_eap_server_params() |
4481 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
4482 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
8b8a1864 | 4483 | hostapd.add_ap(apdev[0], params) |
061cbb25 JM |
4484 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
4485 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
4486 | private_key="auth_serv/user.pkcs12", | |
4487 | private_key_passwd="whatever", | |
4488 | domain_match="example.com", | |
4489 | wait_connect=False, | |
4490 | scan_freq="2412") | |
4491 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
4492 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
4493 | private_key="auth_serv/user.pkcs12", | |
4494 | private_key_passwd="whatever", | |
4495 | domain_match="w1.fi", | |
4496 | wait_connect=False, | |
4497 | scan_freq="2412") | |
4498 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4499 | if ev is None: | |
4500 | raise Exception("Timeout on EAP failure report") | |
4501 | ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4502 | if ev is None: | |
4503 | raise Exception("Timeout on EAP failure report (2)") | |
4504 | ||
6a4d0dbe JM |
4505 | def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev): |
4506 | """WPA2-Enterprise using EAP-TTLS and expired certificate""" | |
ca158ea6 | 4507 | skip_with_fips(dev[0]) |
6a4d0dbe JM |
4508 | params = int_eap_server_params() |
4509 | params["server_cert"] = "auth_serv/server-expired.pem" | |
4510 | params["private_key"] = "auth_serv/server-expired.key" | |
8b8a1864 | 4511 | hostapd.add_ap(apdev[0], params) |
6a4d0dbe JM |
4512 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4513 | identity="mschap user", password="password", | |
4514 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
4515 | wait_connect=False, | |
4516 | scan_freq="2412") | |
4517 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"]) | |
4518 | if ev is None: | |
4519 | raise Exception("Timeout on EAP certificate error report") | |
4520 | if "reason=4" not in ev or "certificate has expired" not in ev: | |
4521 | raise Exception("Unexpected failure reason: " + ev) | |
4522 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4523 | if ev is None: | |
4524 | raise Exception("Timeout on EAP failure report") | |
4525 | ||
4526 | def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev): | |
4527 | """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration""" | |
ca158ea6 | 4528 | skip_with_fips(dev[0]) |
6a4d0dbe JM |
4529 | params = int_eap_server_params() |
4530 | params["server_cert"] = "auth_serv/server-expired.pem" | |
4531 | params["private_key"] = "auth_serv/server-expired.key" | |
8b8a1864 | 4532 | hostapd.add_ap(apdev[0], params) |
6a4d0dbe JM |
4533 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4534 | identity="mschap user", password="password", | |
4535 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
4536 | phase1="tls_disable_time_checks=1", | |
4537 | scan_freq="2412") | |
6ab4a7aa | 4538 | |
5748d1e5 JM |
4539 | def test_ap_wpa2_eap_ttls_long_duration(dev, apdev): |
4540 | """WPA2-Enterprise using EAP-TTLS and long certificate duration""" | |
ca158ea6 | 4541 | skip_with_fips(dev[0]) |
5748d1e5 JM |
4542 | params = int_eap_server_params() |
4543 | params["server_cert"] = "auth_serv/server-long-duration.pem" | |
4544 | params["private_key"] = "auth_serv/server-long-duration.key" | |
8b8a1864 | 4545 | hostapd.add_ap(apdev[0], params) |
5748d1e5 JM |
4546 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4547 | identity="mschap user", password="password", | |
4548 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
4549 | scan_freq="2412") | |
4550 | ||
6ab4a7aa JM |
4551 | def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev): |
4552 | """WPA2-Enterprise using EAP-TTLS and server cert with client EKU""" | |
ca158ea6 | 4553 | skip_with_fips(dev[0]) |
6ab4a7aa JM |
4554 | params = int_eap_server_params() |
4555 | params["server_cert"] = "auth_serv/server-eku-client.pem" | |
4556 | params["private_key"] = "auth_serv/server-eku-client.key" | |
8b8a1864 | 4557 | hostapd.add_ap(apdev[0], params) |
6ab4a7aa JM |
4558 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4559 | identity="mschap user", password="password", | |
4560 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
4561 | wait_connect=False, | |
4562 | scan_freq="2412") | |
4563 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4564 | if ev is None: | |
4565 | raise Exception("Timeout on EAP failure report") | |
242219c5 | 4566 | |
14bef66d JM |
4567 | def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev): |
4568 | """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU""" | |
ca158ea6 | 4569 | skip_with_fips(dev[0]) |
14bef66d JM |
4570 | params = int_eap_server_params() |
4571 | params["server_cert"] = "auth_serv/server-eku-client-server.pem" | |
4572 | params["private_key"] = "auth_serv/server-eku-client-server.key" | |
8b8a1864 | 4573 | hostapd.add_ap(apdev[0], params) |
14bef66d JM |
4574 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4575 | identity="mschap user", password="password", | |
4576 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
4577 | scan_freq="2412") | |
4578 | ||
c37b02fc JM |
4579 | def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev): |
4580 | """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file""" | |
ca158ea6 | 4581 | skip_with_fips(dev[0]) |
c37b02fc JM |
4582 | params = int_eap_server_params() |
4583 | del params["server_cert"] | |
4584 | params["private_key"] = "auth_serv/server.pkcs12" | |
8b8a1864 | 4585 | hostapd.add_ap(apdev[0], params) |
c37b02fc JM |
4586 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4587 | identity="mschap user", password="password", | |
4588 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
4589 | scan_freq="2412") | |
4590 | ||
31dd3153 JM |
4591 | def test_ap_wpa2_eap_ttls_server_pkcs12_extra(dev, apdev): |
4592 | """EAP-TTLS and server PKCS#12 file with extra certs""" | |
4593 | skip_with_fips(dev[0]) | |
4594 | params = int_eap_server_params() | |
4595 | del params["server_cert"] | |
4596 | params["private_key"] = "auth_serv/server-extra.pkcs12" | |
4597 | params["private_key_passwd"] = "whatever" | |
8b8a1864 | 4598 | hostapd.add_ap(apdev[0], params) |
31dd3153 JM |
4599 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4600 | identity="mschap user", password="password", | |
4601 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
4602 | scan_freq="2412") | |
4603 | ||
242219c5 JM |
4604 | def test_ap_wpa2_eap_ttls_dh_params(dev, apdev): |
4605 | """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params""" | |
4606 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 JD |
4607 | hapd = hostapd.add_ap(apdev[0], params) |
4608 | eap_connect(dev[0], hapd, "TTLS", "pap user", | |
242219c5 | 4609 | anonymous_identity="ttls", password="password", |
ca158ea6 | 4610 | ca_cert="auth_serv/ca.der", phase2="auth=PAP", |
242219c5 | 4611 | dh_file="auth_serv/dh.conf") |
7c50093f | 4612 | |
b3ff3dec JM |
4613 | def test_ap_wpa2_eap_ttls_dh_params_dsa(dev, apdev): |
4614 | """WPA2-Enterprise connection using EAP-TTLS and setting DH params (DSA)""" | |
404597e6 | 4615 | check_dh_dsa_support(dev[0]) |
b3ff3dec | 4616 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3b3e2687 JD |
4617 | hapd = hostapd.add_ap(apdev[0], params) |
4618 | eap_connect(dev[0], hapd, "TTLS", "pap user", | |
b3ff3dec | 4619 | anonymous_identity="ttls", password="password", |
ca158ea6 | 4620 | ca_cert="auth_serv/ca.der", phase2="auth=PAP", |
b3ff3dec JM |
4621 | dh_file="auth_serv/dsaparam.pem") |
4622 | ||
4623 | def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev): | |
4624 | """EAP-TTLS and DH params file not found""" | |
ca158ea6 | 4625 | skip_with_fips(dev[0]) |
b3ff3dec | 4626 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 4627 | hostapd.add_ap(apdev[0], params) |
b3ff3dec JM |
4628 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4629 | identity="mschap user", password="password", | |
4630 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
4631 | dh_file="auth_serv/dh-no-such-file.conf", | |
4632 | scan_freq="2412", wait_connect=False) | |
4633 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4634 | if ev is None: | |
4635 | raise Exception("EAP failure timed out") | |
4636 | dev[0].request("REMOVE_NETWORK all") | |
4637 | dev[0].wait_disconnected() | |
4638 | ||
4639 | def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev): | |
4640 | """EAP-TTLS and invalid DH params file""" | |
ca158ea6 | 4641 | skip_with_fips(dev[0]) |
b3ff3dec | 4642 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 4643 | hostapd.add_ap(apdev[0], params) |
b3ff3dec JM |
4644 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4645 | identity="mschap user", password="password", | |
4646 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
4647 | dh_file="auth_serv/ca.pem", | |
4648 | scan_freq="2412", wait_connect=False) | |
4649 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4650 | if ev is None: | |
4651 | raise Exception("EAP failure timed out") | |
4652 | dev[0].request("REMOVE_NETWORK all") | |
4653 | dev[0].wait_disconnected() | |
4654 | ||
6ea231e6 JM |
4655 | def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev): |
4656 | """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob""" | |
4657 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 | 4658 | hapd = hostapd.add_ap(apdev[0], params) |
768ea0bc | 4659 | dh = read_pem("auth_serv/dh2.conf") |
6ea231e6 JM |
4660 | if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")): |
4661 | raise Exception("Could not set dhparams blob") | |
3b3e2687 | 4662 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
6ea231e6 | 4663 | anonymous_identity="ttls", password="password", |
ca158ea6 | 4664 | ca_cert="auth_serv/ca.der", phase2="auth=PAP", |
6ea231e6 JM |
4665 | dh_file="blob://dhparams") |
4666 | ||
768ea0bc JM |
4667 | def test_ap_wpa2_eap_ttls_dh_params_server(dev, apdev): |
4668 | """WPA2-Enterprise using EAP-TTLS and alternative server dhparams""" | |
4669 | params = int_eap_server_params() | |
4670 | params["dh_file"] = "auth_serv/dh2.conf" | |
3b3e2687 JD |
4671 | hapd = hostapd.add_ap(apdev[0], params) |
4672 | eap_connect(dev[0], hapd, "TTLS", "pap user", | |
768ea0bc | 4673 | anonymous_identity="ttls", password="password", |
ca158ea6 | 4674 | ca_cert="auth_serv/ca.der", phase2="auth=PAP") |
768ea0bc | 4675 | |
b3ff3dec JM |
4676 | def test_ap_wpa2_eap_ttls_dh_params_dsa_server(dev, apdev): |
4677 | """WPA2-Enterprise using EAP-TTLS and alternative server dhparams (DSA)""" | |
4678 | params = int_eap_server_params() | |
4679 | params["dh_file"] = "auth_serv/dsaparam.pem" | |
3b3e2687 JD |
4680 | hapd = hostapd.add_ap(apdev[0], params) |
4681 | eap_connect(dev[0], hapd, "TTLS", "pap user", | |
b3ff3dec | 4682 | anonymous_identity="ttls", password="password", |
ca158ea6 | 4683 | ca_cert="auth_serv/ca.der", phase2="auth=PAP") |
b3ff3dec JM |
4684 | |
4685 | def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev): | |
4686 | """EAP-TLS server and dhparams file not found""" | |
4687 | params = int_eap_server_params() | |
4688 | params["dh_file"] = "auth_serv/dh-no-such-file.conf" | |
8b8a1864 | 4689 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
b3ff3dec JM |
4690 | if "FAIL" not in hapd.request("ENABLE"): |
4691 | raise Exception("Invalid configuration accepted") | |
4692 | ||
4693 | def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev): | |
4694 | """EAP-TLS server and invalid dhparams file""" | |
4695 | params = int_eap_server_params() | |
4696 | params["dh_file"] = "auth_serv/ca.pem" | |
8b8a1864 | 4697 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
b3ff3dec JM |
4698 | if "FAIL" not in hapd.request("ENABLE"): |
4699 | raise Exception("Invalid configuration accepted") | |
4700 | ||
7c50093f JM |
4701 | def test_ap_wpa2_eap_reauth(dev, apdev): |
4702 | """WPA2-Enterprise and Authenticator forcing reauthentication""" | |
4703 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
4704 | params['eap_reauth_period'] = '2' | |
3b3e2687 JD |
4705 | hapd = hostapd.add_ap(apdev[0], params) |
4706 | eap_connect(dev[0], hapd, "PAX", "pax.user@example.com", | |
7c50093f JM |
4707 | password_hex="0123456789abcdef0123456789abcdef") |
4708 | logger.info("Wait for reauthentication") | |
4709 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
4710 | if ev is None: | |
4711 | raise Exception("Timeout on reauthentication") | |
4712 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4713 | if ev is None: | |
4714 | raise Exception("Timeout on reauthentication") | |
4715 | for i in range(0, 20): | |
4716 | state = dev[0].get_status_field("wpa_state") | |
4717 | if state == "COMPLETED": | |
4718 | break | |
4719 | time.sleep(0.1) | |
4720 | if state != "COMPLETED": | |
4721 | raise Exception("Reauthentication did not complete") | |
8b56743e JM |
4722 | |
4723 | def test_ap_wpa2_eap_request_identity_message(dev, apdev): | |
4724 | """Optional displayable message in EAP Request-Identity""" | |
4725 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
4726 | params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com' | |
3b3e2687 JD |
4727 | hapd = hostapd.add_ap(apdev[0], params) |
4728 | eap_connect(dev[0], hapd, "PAX", "pax.user@example.com", | |
8b56743e | 4729 | password_hex="0123456789abcdef0123456789abcdef") |
910f16ca JM |
4730 | |
4731 | def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev): | |
4732 | """WPA2-Enterprise using EAP-SIM/AKA and protected result indication""" | |
81e787b7 | 4733 | check_hlr_auc_gw_support() |
910f16ca JM |
4734 | params = int_eap_server_params() |
4735 | params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock" | |
4736 | params['eap_sim_aka_result_ind'] = "1" | |
3b3e2687 | 4737 | hapd = hostapd.add_ap(apdev[0], params) |
910f16ca | 4738 | |
3b3e2687 | 4739 | eap_connect(dev[0], hapd, "SIM", "1232010000000000", |
910f16ca JM |
4740 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", |
4741 | phase1="result_ind=1") | |
4742 | eap_reauth(dev[0], "SIM") | |
3b3e2687 | 4743 | eap_connect(dev[1], hapd, "SIM", "1232010000000000", |
910f16ca JM |
4744 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") |
4745 | ||
4746 | dev[0].request("REMOVE_NETWORK all") | |
4747 | dev[1].request("REMOVE_NETWORK all") | |
4748 | ||
3b3e2687 | 4749 | eap_connect(dev[0], hapd, "AKA", "0232010000000000", |
910f16ca JM |
4750 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", |
4751 | phase1="result_ind=1") | |
4752 | eap_reauth(dev[0], "AKA") | |
3b3e2687 | 4753 | eap_connect(dev[1], hapd, "AKA", "0232010000000000", |
910f16ca JM |
4754 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") |
4755 | ||
4756 | dev[0].request("REMOVE_NETWORK all") | |
4757 | dev[1].request("REMOVE_NETWORK all") | |
4758 | ||
3b3e2687 | 4759 | eap_connect(dev[0], hapd, "AKA'", "6555444333222111", |
910f16ca JM |
4760 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", |
4761 | phase1="result_ind=1") | |
4762 | eap_reauth(dev[0], "AKA'") | |
3b3e2687 | 4763 | eap_connect(dev[1], hapd, "AKA'", "6555444333222111", |
910f16ca | 4764 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") |
633e364b | 4765 | |
a8217972 JM |
4766 | def test_ap_wpa2_eap_sim_zero_db_timeout(dev, apdev): |
4767 | """WPA2-Enterprise using EAP-SIM with zero database timeout""" | |
4768 | check_hlr_auc_gw_support() | |
4769 | params = int_eap_server_params() | |
4770 | params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock" | |
4771 | params['eap_sim_db_timeout'] = "0" | |
4772 | params['disable_pmksa_caching'] = '1' | |
4773 | hapd = hostapd.add_ap(apdev[0], params) | |
4774 | ||
4775 | # Run multiple iterations to make it more likely to hit the case where the | |
4776 | # DB request times out and response is lost. | |
4777 | for i in range(20): | |
a8217972 JM |
4778 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM", |
4779 | identity="1232010000000000", | |
4780 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
4781 | wait_connect=False, scan_freq="2412") | |
4782 | ev = dev[0].wait_event([ "CTRL-EVENT-CONNECTED", | |
4783 | "CTRL-EVENT-DISCONNECTED" ], | |
4784 | timeout=15) | |
4785 | if ev is None: | |
4786 | raise Exception("No connection result") | |
4787 | dev[0].request("REMOVE_NETWORK all") | |
4788 | if "CTRL-EVENT-DISCONNECTED" in ev: | |
4789 | break | |
4790 | dev[0].wait_disconnected() | |
4791 | hapd.ping() | |
4792 | ||
633e364b JM |
4793 | def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev): |
4794 | """WPA2-Enterprise connection resulting in too many EAP roundtrips""" | |
ca158ea6 | 4795 | skip_with_fips(dev[0]) |
633e364b | 4796 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 4797 | hostapd.add_ap(apdev[0], params) |
633e364b JM |
4798 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", |
4799 | eap="TTLS", identity="mschap user", | |
4800 | wait_connect=False, scan_freq="2412", ieee80211w="1", | |
4801 | anonymous_identity="ttls", password="password", | |
4802 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
78d2233f JM |
4803 | fragment_size="8") |
4804 | ev = dev[0].wait_event(["EAP: more than", | |
4805 | "CTRL-EVENT-EAP-SUCCESS"], timeout=20) | |
4806 | if ev is None or "EAP: more than" not in ev: | |
633e364b | 4807 | raise Exception("EAP roundtrip limit not reached") |
32dca985 JM |
4808 | |
4809 | def test_ap_wpa2_eap_expanded_nak(dev, apdev): | |
4810 | """WPA2-Enterprise connection with EAP resulting in expanded NAK""" | |
4811 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 4812 | hostapd.add_ap(apdev[0], params) |
32dca985 JM |
4813 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", |
4814 | eap="PSK", identity="vendor-test", | |
4815 | password_hex="ff23456789abcdef0123456789abcdef", | |
4816 | wait_connect=False) | |
4817 | ||
4818 | found = False | |
4819 | for i in range(0, 5): | |
412c6030 | 4820 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=16) |
32dca985 JM |
4821 | if ev is None: |
4822 | raise Exception("Association and EAP start timed out") | |
4823 | if "refuse proposed method" in ev: | |
4824 | found = True | |
4825 | break | |
4826 | if not found: | |
4827 | raise Exception("Unexpected EAP status: " + ev) | |
4828 | ||
4829 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
4830 | if ev is None: | |
4831 | raise Exception("EAP failure timed out") | |
745f8771 JM |
4832 | |
4833 | def test_ap_wpa2_eap_sql(dev, apdev, params): | |
4834 | """WPA2-Enterprise connection using SQLite for user DB""" | |
ca158ea6 | 4835 | skip_with_fips(dev[0]) |
745f8771 JM |
4836 | try: |
4837 | import sqlite3 | |
4838 | except ImportError: | |
81e787b7 | 4839 | raise HwsimSkip("No sqlite3 module available") |
745f8771 JM |
4840 | dbfile = os.path.join(params['logdir'], "eap-user.db") |
4841 | try: | |
4842 | os.remove(dbfile) | |
4843 | except: | |
4844 | pass | |
4845 | con = sqlite3.connect(dbfile) | |
4846 | with con: | |
4847 | cur = con.cursor() | |
4848 | cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)") | |
4849 | cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)") | |
4850 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-pap','TTLS-PAP','password',1)") | |
4851 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-chap','TTLS-CHAP','password',1)") | |
4852 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschap','TTLS-MSCHAP','password',1)") | |
4853 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1)") | |
4854 | cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')") | |
4855 | cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)") | |
4856 | ||
4857 | try: | |
4858 | params = int_eap_server_params() | |
4859 | params["eap_user_file"] = "sqlite:" + dbfile | |
3b3e2687 JD |
4860 | hapd = hostapd.add_ap(apdev[0], params) |
4861 | eap_connect(dev[0], hapd, "TTLS", "user-mschapv2", | |
745f8771 JM |
4862 | anonymous_identity="ttls", password="password", |
4863 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
4864 | dev[0].request("REMOVE_NETWORK all") | |
3b3e2687 | 4865 | eap_connect(dev[1], hapd, "TTLS", "user-mschap", |
745f8771 JM |
4866 | anonymous_identity="ttls", password="password", |
4867 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP") | |
4868 | dev[1].request("REMOVE_NETWORK all") | |
3b3e2687 | 4869 | eap_connect(dev[0], hapd, "TTLS", "user-chap", |
745f8771 JM |
4870 | anonymous_identity="ttls", password="password", |
4871 | ca_cert="auth_serv/ca.pem", phase2="auth=CHAP") | |
3b3e2687 | 4872 | eap_connect(dev[1], hapd, "TTLS", "user-pap", |
745f8771 JM |
4873 | anonymous_identity="ttls", password="password", |
4874 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
4875 | finally: | |
4876 | os.remove(dbfile) | |
b246e2af JM |
4877 | |
4878 | def test_ap_wpa2_eap_non_ascii_identity(dev, apdev): | |
4879 | """WPA2-Enterprise connection attempt using non-ASCII identity""" | |
4880 | params = int_eap_server_params() | |
8b8a1864 | 4881 | hostapd.add_ap(apdev[0], params) |
b246e2af JM |
4882 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4883 | identity="\x80", password="password", wait_connect=False) | |
4884 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
4885 | identity="a\x80", password="password", wait_connect=False) | |
4886 | for i in range(0, 2): | |
412c6030 | 4887 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
b246e2af JM |
4888 | if ev is None: |
4889 | raise Exception("Association and EAP start timed out") | |
4890 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
4891 | if ev is None: | |
4892 | raise Exception("EAP method selection timed out") | |
4893 | ||
4894 | def test_ap_wpa2_eap_non_ascii_identity2(dev, apdev): | |
4895 | """WPA2-Enterprise connection attempt using non-ASCII identity""" | |
4896 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 4897 | hostapd.add_ap(apdev[0], params) |
b246e2af JM |
4898 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4899 | identity="\x80", password="password", wait_connect=False) | |
4900 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
4901 | identity="a\x80", password="password", wait_connect=False) | |
4902 | for i in range(0, 2): | |
412c6030 | 4903 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16) |
b246e2af JM |
4904 | if ev is None: |
4905 | raise Exception("Association and EAP start timed out") | |
4906 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
4907 | if ev is None: | |
4908 | raise Exception("EAP method selection timed out") | |
89f20842 JM |
4909 | |
4910 | def test_openssl_cipher_suite_config_wpas(dev, apdev): | |
4911 | """OpenSSL cipher suite configuration on wpa_supplicant""" | |
a783340d JM |
4912 | tls = dev[0].request("GET tls_library") |
4913 | if not tls.startswith("OpenSSL"): | |
4914 | raise HwsimSkip("TLS library is not OpenSSL: " + tls) | |
89f20842 | 4915 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
8b8a1864 | 4916 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 4917 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
89f20842 JM |
4918 | anonymous_identity="ttls", password="password", |
4919 | openssl_ciphers="AES128", | |
4920 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
3b3e2687 | 4921 | eap_connect(dev[1], hapd, "TTLS", "pap user", |
89f20842 JM |
4922 | anonymous_identity="ttls", password="password", |
4923 | openssl_ciphers="EXPORT", | |
4924 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
9dd21d51 | 4925 | expect_failure=True, maybe_local_error=True) |
7be5ec99 JM |
4926 | dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
4927 | identity="pap user", anonymous_identity="ttls", | |
4928 | password="password", | |
4929 | openssl_ciphers="FOO", | |
4930 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
4931 | wait_connect=False) | |
4932 | ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4933 | if ev is None: | |
4934 | raise Exception("EAP failure after invalid openssl_ciphers not reported") | |
4935 | dev[2].request("DISCONNECT") | |
89f20842 JM |
4936 | |
4937 | def test_openssl_cipher_suite_config_hapd(dev, apdev): | |
4938 | """OpenSSL cipher suite configuration on hostapd""" | |
a783340d JM |
4939 | tls = dev[0].request("GET tls_library") |
4940 | if not tls.startswith("OpenSSL"): | |
4941 | raise HwsimSkip("wpa_supplicant TLS library is not OpenSSL: " + tls) | |
89f20842 JM |
4942 | params = int_eap_server_params() |
4943 | params['openssl_ciphers'] = "AES256" | |
8b8a1864 | 4944 | hapd = hostapd.add_ap(apdev[0], params) |
a783340d JM |
4945 | tls = hapd.request("GET tls_library") |
4946 | if not tls.startswith("OpenSSL"): | |
4947 | raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls) | |
3b3e2687 | 4948 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
89f20842 JM |
4949 | anonymous_identity="ttls", password="password", |
4950 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
3b3e2687 | 4951 | eap_connect(dev[1], hapd, "TTLS", "pap user", |
89f20842 JM |
4952 | anonymous_identity="ttls", password="password", |
4953 | openssl_ciphers="AES128", | |
4954 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
4955 | expect_failure=True) | |
3b3e2687 | 4956 | eap_connect(dev[2], hapd, "TTLS", "pap user", |
89f20842 JM |
4957 | anonymous_identity="ttls", password="password", |
4958 | openssl_ciphers="HIGH:!ADH", | |
4959 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
5b3c40a6 | 4960 | |
7be5ec99 | 4961 | params['openssl_ciphers'] = "FOO" |
8b8a1864 | 4962 | hapd2 = hostapd.add_ap(apdev[1], params, no_enable=True) |
7be5ec99 JM |
4963 | if "FAIL" not in hapd2.request("ENABLE"): |
4964 | raise Exception("Invalid openssl_ciphers value accepted") | |
4965 | ||
5b3c40a6 JM |
4966 | def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params): |
4967 | """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP""" | |
4968 | p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 4969 | hapd = hostapd.add_ap(apdev[0], p) |
5b3c40a6 JM |
4970 | password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25" |
4971 | pid = find_wpas_process(dev[0]) | |
3b3e2687 | 4972 | id = eap_connect(dev[0], hapd, "TTLS", "pap-secret", |
5b3c40a6 JM |
4973 | anonymous_identity="ttls", password=password, |
4974 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
8e416cec JM |
4975 | # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED |
4976 | # event has been delivered, so verify that wpa_supplicant has returned to | |
4977 | # eloop before reading process memory. | |
54f2cae2 | 4978 | time.sleep(1) |
8e416cec | 4979 | dev[0].ping() |
5b3c40a6 JM |
4980 | buf = read_process_memory(pid, password) |
4981 | ||
4982 | dev[0].request("DISCONNECT") | |
4983 | dev[0].wait_disconnected() | |
4984 | ||
4985 | dev[0].relog() | |
750904dd JM |
4986 | msk = None |
4987 | emsk = None | |
5b3c40a6 JM |
4988 | pmk = None |
4989 | ptk = None | |
4990 | gtk = None | |
4991 | with open(os.path.join(params['logdir'], 'log0'), 'r') as f: | |
4992 | for l in f.readlines(): | |
750904dd JM |
4993 | if "EAP-TTLS: Derived key - hexdump" in l: |
4994 | val = l.strip().split(':')[3].replace(' ', '') | |
4995 | msk = binascii.unhexlify(val) | |
4996 | if "EAP-TTLS: Derived EMSK - hexdump" in l: | |
4997 | val = l.strip().split(':')[3].replace(' ', '') | |
4998 | emsk = binascii.unhexlify(val) | |
5b3c40a6 JM |
4999 | if "WPA: PMK - hexdump" in l: |
5000 | val = l.strip().split(':')[3].replace(' ', '') | |
5001 | pmk = binascii.unhexlify(val) | |
5002 | if "WPA: PTK - hexdump" in l: | |
5003 | val = l.strip().split(':')[3].replace(' ', '') | |
5004 | ptk = binascii.unhexlify(val) | |
5005 | if "WPA: Group Key - hexdump" in l: | |
5006 | val = l.strip().split(':')[3].replace(' ', '') | |
5007 | gtk = binascii.unhexlify(val) | |
750904dd | 5008 | if not msk or not emsk or not pmk or not ptk or not gtk: |
5b3c40a6 JM |
5009 | raise Exception("Could not find keys from debug log") |
5010 | if len(gtk) != 16: | |
5011 | raise Exception("Unexpected GTK length") | |
5012 | ||
5013 | kck = ptk[0:16] | |
5014 | kek = ptk[16:32] | |
5015 | tk = ptk[32:48] | |
5016 | ||
5017 | fname = os.path.join(params['logdir'], | |
5018 | 'wpa2_eap_ttls_pap_key_lifetime_in_memory.memctx-') | |
5019 | ||
5020 | logger.info("Checking keys in memory while associated") | |
5021 | get_key_locations(buf, password, "Password") | |
5022 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
5023 | get_key_locations(buf, msk, "MSK") |
5024 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 | 5025 | if password not in buf: |
81e787b7 | 5026 | raise HwsimSkip("Password not found while associated") |
5b3c40a6 | 5027 | if pmk not in buf: |
81e787b7 | 5028 | raise HwsimSkip("PMK not found while associated") |
5b3c40a6 JM |
5029 | if kck not in buf: |
5030 | raise Exception("KCK not found while associated") | |
5031 | if kek not in buf: | |
5032 | raise Exception("KEK not found while associated") | |
5033 | if tk in buf: | |
5034 | raise Exception("TK found from memory") | |
5035 | if gtk in buf: | |
8eb45bde | 5036 | get_key_locations(buf, gtk, "GTK") |
5b3c40a6 JM |
5037 | raise Exception("GTK found from memory") |
5038 | ||
5039 | logger.info("Checking keys in memory after disassociation") | |
5040 | buf = read_process_memory(pid, password) | |
5041 | ||
5042 | # Note: Password is still present in network configuration | |
5043 | # Note: PMK is in PMKSA cache and EAP fast re-auth data | |
5044 | ||
5045 | get_key_locations(buf, password, "Password") | |
5046 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
5047 | get_key_locations(buf, msk, "MSK") |
5048 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 JM |
5049 | verify_not_present(buf, kck, fname, "KCK") |
5050 | verify_not_present(buf, kek, fname, "KEK") | |
5051 | verify_not_present(buf, tk, fname, "TK") | |
5052 | verify_not_present(buf, gtk, fname, "GTK") | |
5053 | ||
5054 | dev[0].request("PMKSA_FLUSH") | |
5055 | dev[0].set_network_quoted(id, "identity", "foo") | |
5056 | logger.info("Checking keys in memory after PMKSA cache and EAP fast reauth flush") | |
5057 | buf = read_process_memory(pid, password) | |
5058 | get_key_locations(buf, password, "Password") | |
5059 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
5060 | get_key_locations(buf, msk, "MSK") |
5061 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 JM |
5062 | verify_not_present(buf, pmk, fname, "PMK") |
5063 | ||
5064 | dev[0].request("REMOVE_NETWORK all") | |
5065 | ||
5066 | logger.info("Checking keys in memory after network profile removal") | |
5067 | buf = read_process_memory(pid, password) | |
5068 | ||
5069 | get_key_locations(buf, password, "Password") | |
5070 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
5071 | get_key_locations(buf, msk, "MSK") |
5072 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 JM |
5073 | verify_not_present(buf, password, fname, "password") |
5074 | verify_not_present(buf, pmk, fname, "PMK") | |
5075 | verify_not_present(buf, kck, fname, "KCK") | |
5076 | verify_not_present(buf, kek, fname, "KEK") | |
5077 | verify_not_present(buf, tk, fname, "TK") | |
5078 | verify_not_present(buf, gtk, fname, "GTK") | |
750904dd JM |
5079 | verify_not_present(buf, msk, fname, "MSK") |
5080 | verify_not_present(buf, emsk, fname, "EMSK") | |
a08fdb17 JM |
5081 | |
5082 | def test_ap_wpa2_eap_unexpected_wep_eapol_key(dev, apdev): | |
5083 | """WPA2-Enterprise connection and unexpected WEP EAPOL-Key""" | |
5084 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 5085 | hapd = hostapd.add_ap(apdev[0], params) |
a08fdb17 | 5086 | bssid = apdev[0]['bssid'] |
3b3e2687 | 5087 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
a08fdb17 JM |
5088 | anonymous_identity="ttls", password="password", |
5089 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
5090 | ||
5091 | # Send unexpected WEP EAPOL-Key; this gets dropped | |
5092 | res = dev[0].request("EAPOL_RX " + bssid + " 0203002c0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000") | |
5093 | if "OK" not in res: | |
5094 | raise Exception("EAPOL_RX to wpa_supplicant failed") | |
52352802 JM |
5095 | |
5096 | def test_ap_wpa2_eap_in_bridge(dev, apdev): | |
5097 | """WPA2-EAP and wpas interface in a bridge""" | |
5098 | br_ifname='sta-br0' | |
5099 | ifname='wlan5' | |
5100 | try: | |
5101 | _test_ap_wpa2_eap_in_bridge(dev, apdev) | |
5102 | finally: | |
5103 | subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down']) | |
5104 | subprocess.call(['brctl', 'delif', br_ifname, ifname]) | |
5105 | subprocess.call(['brctl', 'delbr', br_ifname]) | |
5106 | subprocess.call(['iw', ifname, 'set', '4addr', 'off']) | |
5107 | ||
5108 | def _test_ap_wpa2_eap_in_bridge(dev, apdev): | |
5109 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 5110 | hapd = hostapd.add_ap(apdev[0], params) |
52352802 JM |
5111 | |
5112 | br_ifname='sta-br0' | |
5113 | ifname='wlan5' | |
5114 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
5115 | subprocess.call(['brctl', 'addbr', br_ifname]) | |
5116 | subprocess.call(['brctl', 'setfd', br_ifname, '0']) | |
5117 | subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) | |
5118 | subprocess.call(['iw', ifname, 'set', '4addr', 'on']) | |
5119 | subprocess.check_call(['brctl', 'addif', br_ifname, ifname]) | |
5120 | wpas.interface_add(ifname, br_ifname=br_ifname) | |
4b9d79b6 | 5121 | wpas.dump_monitor() |
52352802 | 5122 | |
3b3e2687 | 5123 | id = eap_connect(wpas, hapd, "PAX", "pax.user@example.com", |
52352802 | 5124 | password_hex="0123456789abcdef0123456789abcdef") |
4b9d79b6 | 5125 | wpas.dump_monitor() |
52352802 | 5126 | eap_reauth(wpas, "PAX") |
4b9d79b6 | 5127 | wpas.dump_monitor() |
52352802 JM |
5128 | # Try again as a regression test for packet socket workaround |
5129 | eap_reauth(wpas, "PAX") | |
4b9d79b6 | 5130 | wpas.dump_monitor() |
52352802 JM |
5131 | wpas.request("DISCONNECT") |
5132 | wpas.wait_disconnected() | |
4b9d79b6 | 5133 | wpas.dump_monitor() |
52352802 JM |
5134 | wpas.request("RECONNECT") |
5135 | wpas.wait_connected() | |
4b9d79b6 | 5136 | wpas.dump_monitor() |
febf5752 JM |
5137 | |
5138 | def test_ap_wpa2_eap_session_ticket(dev, apdev): | |
5139 | """WPA2-Enterprise connection using EAP-TTLS and TLS session ticket enabled""" | |
5140 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 5141 | hapd = hostapd.add_ap(apdev[0], params) |
febf5752 JM |
5142 | key_mgmt = hapd.get_config()['key_mgmt'] |
5143 | if key_mgmt.split(' ')[0] != "WPA-EAP": | |
5144 | raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt) | |
3b3e2687 | 5145 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
febf5752 JM |
5146 | anonymous_identity="ttls", password="password", |
5147 | ca_cert="auth_serv/ca.pem", | |
5148 | phase1="tls_disable_session_ticket=0", phase2="auth=PAP") | |
5149 | eap_reauth(dev[0], "TTLS") | |
5150 | ||
5151 | def test_ap_wpa2_eap_no_workaround(dev, apdev): | |
5152 | """WPA2-Enterprise connection using EAP-TTLS and eap_workaround=0""" | |
5153 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 5154 | hapd = hostapd.add_ap(apdev[0], params) |
febf5752 JM |
5155 | key_mgmt = hapd.get_config()['key_mgmt'] |
5156 | if key_mgmt.split(' ')[0] != "WPA-EAP": | |
5157 | raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt) | |
3b3e2687 | 5158 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
febf5752 JM |
5159 | anonymous_identity="ttls", password="password", |
5160 | ca_cert="auth_serv/ca.pem", eap_workaround='0', | |
5161 | phase2="auth=PAP") | |
5162 | eap_reauth(dev[0], "TTLS") | |
b197a819 JM |
5163 | |
5164 | def test_ap_wpa2_eap_tls_check_crl(dev, apdev): | |
5165 | """EAP-TLS and server checking CRL""" | |
5166 | params = int_eap_server_params() | |
5167 | params['check_crl'] = '1' | |
8b8a1864 | 5168 | hapd = hostapd.add_ap(apdev[0], params) |
b197a819 JM |
5169 | |
5170 | # check_crl=1 and no CRL available --> reject connection | |
3b3e2687 | 5171 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
b197a819 JM |
5172 | client_cert="auth_serv/user.pem", |
5173 | private_key="auth_serv/user.key", expect_failure=True) | |
5174 | dev[0].request("REMOVE_NETWORK all") | |
5175 | ||
5176 | hapd.disable() | |
5177 | hapd.set("ca_cert", "auth_serv/ca-and-crl.pem") | |
5178 | hapd.enable() | |
5179 | ||
5180 | # check_crl=1 and valid CRL --> accept | |
3b3e2687 | 5181 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
b197a819 JM |
5182 | client_cert="auth_serv/user.pem", |
5183 | private_key="auth_serv/user.key") | |
5184 | dev[0].request("REMOVE_NETWORK all") | |
5185 | ||
5186 | hapd.disable() | |
5187 | hapd.set("check_crl", "2") | |
5188 | hapd.enable() | |
5189 | ||
5190 | # check_crl=2 and valid CRL --> accept | |
3b3e2687 | 5191 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
b197a819 JM |
5192 | client_cert="auth_serv/user.pem", |
5193 | private_key="auth_serv/user.key") | |
5194 | dev[0].request("REMOVE_NETWORK all") | |
b1fb4275 JM |
5195 | |
5196 | def test_ap_wpa2_eap_tls_oom(dev, apdev): | |
5197 | """EAP-TLS and OOM""" | |
5198 | check_subject_match_support(dev[0]) | |
5199 | check_altsubject_match_support(dev[0]) | |
e78eb404 | 5200 | check_domain_match(dev[0]) |
b1fb4275 JM |
5201 | check_domain_match_full(dev[0]) |
5202 | ||
5203 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 5204 | hostapd.add_ap(apdev[0], params) |
b1fb4275 JM |
5205 | |
5206 | tests = [ (1, "tls_connection_set_subject_match"), | |
5207 | (2, "tls_connection_set_subject_match"), | |
5208 | (3, "tls_connection_set_subject_match"), | |
5209 | (4, "tls_connection_set_subject_match") ] | |
5210 | for count, func in tests: | |
5211 | with alloc_fail(dev[0], count, func): | |
5212 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
5213 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
5214 | client_cert="auth_serv/user.pem", | |
5215 | private_key="auth_serv/user.key", | |
5216 | subject_match="/C=FI/O=w1.fi/CN=server.w1.fi", | |
5217 | altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/", | |
5218 | domain_suffix_match="server.w1.fi", | |
5219 | domain_match="server.w1.fi", | |
5220 | wait_connect=False, scan_freq="2412") | |
5221 | # TLS parameter configuration error results in CTRL-REQ-PASSPHRASE | |
5222 | ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"], timeout=5) | |
5223 | if ev is None: | |
5224 | raise Exception("No passphrase request") | |
5225 | dev[0].request("REMOVE_NETWORK all") | |
5226 | dev[0].wait_disconnected() | |
405c621c JM |
5227 | |
5228 | def test_ap_wpa2_eap_tls_macacl(dev, apdev): | |
5229 | """WPA2-Enterprise connection using MAC ACL""" | |
5230 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
5231 | params["macaddr_acl"] = "2" | |
3b3e2687 JD |
5232 | hapd = hostapd.add_ap(apdev[0], params) |
5233 | eap_connect(dev[1], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
405c621c JM |
5234 | client_cert="auth_serv/user.pem", |
5235 | private_key="auth_serv/user.key") | |
85774b70 JM |
5236 | |
5237 | def test_ap_wpa2_eap_oom(dev, apdev): | |
5238 | """EAP server and OOM""" | |
5239 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 5240 | hapd = hostapd.add_ap(apdev[0], params) |
85774b70 JM |
5241 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
5242 | ||
5243 | with alloc_fail(hapd, 1, "eapol_auth_alloc"): | |
5244 | # The first attempt fails, but STA will send EAPOL-Start to retry and | |
5245 | # that succeeds. | |
5246 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
5247 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
5248 | client_cert="auth_serv/user.pem", | |
5249 | private_key="auth_serv/user.key", | |
5250 | scan_freq="2412") | |
6c4b5da4 | 5251 | |
3b3e2687 JD |
5252 | def check_tls_ver(dev, hapd, phase1, expected): |
5253 | eap_connect(dev, hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
6c4b5da4 JM |
5254 | client_cert="auth_serv/user.pem", |
5255 | private_key="auth_serv/user.key", | |
5256 | phase1=phase1) | |
5257 | ver = dev.get_status_field("eap_tls_version") | |
5258 | if ver != expected: | |
5259 | raise Exception("Unexpected TLS version (expected %s): %s" % (expected, ver)) | |
5260 | ||
5261 | def test_ap_wpa2_eap_tls_versions(dev, apdev): | |
5262 | """EAP-TLS and TLS version configuration""" | |
5263 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3b3e2687 | 5264 | hapd = hostapd.add_ap(apdev[0], params) |
6c4b5da4 JM |
5265 | |
5266 | tls = dev[0].request("GET tls_library") | |
5267 | if tls.startswith("OpenSSL"): | |
5268 | if "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls: | |
3b3e2687 | 5269 | check_tls_ver(dev[0], hapd, |
6c4b5da4 JM |
5270 | "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1", |
5271 | "TLSv1.2") | |
2286578f | 5272 | elif tls.startswith("internal"): |
3b3e2687 | 5273 | check_tls_ver(dev[0], hapd, |
2286578f | 5274 | "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1", "TLSv1.2") |
3b3e2687 | 5275 | check_tls_ver(dev[1], hapd, |
6c4b5da4 | 5276 | "tls_disable_tlsv1_0=1 tls_disable_tlsv1_2=1", "TLSv1.1") |
3b3e2687 | 5277 | check_tls_ver(dev[2], hapd, |
6c4b5da4 | 5278 | "tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1", "TLSv1") |
ecafa0cf JM |
5279 | |
5280 | def test_rsn_ie_proto_eap_sta(dev, apdev): | |
5281 | """RSN element protocol testing for EAP cases on STA side""" | |
5282 | bssid = apdev[0]['bssid'] | |
5283 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
5284 | # This is the RSN element used normally by hostapd | |
5285 | params['own_ie_override'] = '30140100000fac040100000fac040100000fac010c00' | |
8b8a1864 | 5286 | hapd = hostapd.add_ap(apdev[0], params) |
ecafa0cf JM |
5287 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK", |
5288 | identity="gpsk user", | |
5289 | password="abcdefghijklmnop0123456789abcdef", | |
5290 | scan_freq="2412") | |
5291 | ||
5292 | tests = [ ('No RSN Capabilities field', | |
5293 | '30120100000fac040100000fac040100000fac01'), | |
5294 | ('No AKM Suite fields', | |
5295 | '300c0100000fac040100000fac04'), | |
5296 | ('No Pairwise Cipher Suite fields', | |
5297 | '30060100000fac04'), | |
5298 | ('No Group Data Cipher Suite field', | |
5299 | '30020100') ] | |
5300 | for txt,ie in tests: | |
5301 | dev[0].request("DISCONNECT") | |
5302 | dev[0].wait_disconnected() | |
5303 | logger.info(txt) | |
5304 | hapd.disable() | |
5305 | hapd.set('own_ie_override', ie) | |
5306 | hapd.enable() | |
5307 | dev[0].request("BSS_FLUSH 0") | |
5308 | dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True) | |
5309 | dev[0].select_network(id, freq=2412) | |
5310 | dev[0].wait_connected() | |
f9dd43ea | 5311 | |
9353f07f JM |
5312 | dev[0].request("DISCONNECT") |
5313 | dev[0].wait_disconnected() | |
5314 | dev[0].flush_scan_cache() | |
5315 | ||
f9dd43ea JM |
5316 | def check_tls_session_resumption_capa(dev, hapd): |
5317 | tls = hapd.request("GET tls_library") | |
5318 | if not tls.startswith("OpenSSL"): | |
5319 | raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls) | |
5320 | ||
5321 | tls = dev.request("GET tls_library") | |
5322 | if not tls.startswith("OpenSSL"): | |
5323 | raise HwsimSkip("Session resumption not supported with this TLS library: " + tls) | |
5324 | ||
5325 | def test_eap_ttls_pap_session_resumption(dev, apdev): | |
5326 | """EAP-TTLS/PAP session resumption""" | |
5327 | params = int_eap_server_params() | |
5328 | params['tls_session_lifetime'] = '60' | |
8b8a1864 | 5329 | hapd = hostapd.add_ap(apdev[0], params) |
f9dd43ea | 5330 | check_tls_session_resumption_capa(dev[0], hapd) |
3b3e2687 | 5331 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
f9dd43ea JM |
5332 | anonymous_identity="ttls", password="password", |
5333 | ca_cert="auth_serv/ca.pem", eap_workaround='0', | |
5334 | phase2="auth=PAP") | |
5335 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5336 | raise Exception("Unexpected session resumption on the first connection") | |
5337 | ||
5338 | dev[0].request("REAUTHENTICATE") | |
5339 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5340 | if ev is None: | |
5341 | raise Exception("EAP success timed out") | |
5342 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5343 | if ev is None: | |
5344 | raise Exception("Key handshake with the AP timed out") | |
5345 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5346 | raise Exception("Session resumption not used on the second connection") | |
5347 | ||
5348 | def test_eap_ttls_chap_session_resumption(dev, apdev): | |
5349 | """EAP-TTLS/CHAP session resumption""" | |
5350 | params = int_eap_server_params() | |
5351 | params['tls_session_lifetime'] = '60' | |
8b8a1864 | 5352 | hapd = hostapd.add_ap(apdev[0], params) |
f9dd43ea | 5353 | check_tls_session_resumption_capa(dev[0], hapd) |
3b3e2687 | 5354 | eap_connect(dev[0], hapd, "TTLS", "chap user", |
f9dd43ea JM |
5355 | anonymous_identity="ttls", password="password", |
5356 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP") | |
5357 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5358 | raise Exception("Unexpected session resumption on the first connection") | |
5359 | ||
5360 | dev[0].request("REAUTHENTICATE") | |
5361 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5362 | if ev is None: | |
5363 | raise Exception("EAP success timed out") | |
5364 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5365 | if ev is None: | |
5366 | raise Exception("Key handshake with the AP timed out") | |
5367 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5368 | raise Exception("Session resumption not used on the second connection") | |
5369 | ||
5370 | def test_eap_ttls_mschap_session_resumption(dev, apdev): | |
5371 | """EAP-TTLS/MSCHAP session resumption""" | |
e78eb404 | 5372 | check_domain_suffix_match(dev[0]) |
f9dd43ea JM |
5373 | params = int_eap_server_params() |
5374 | params['tls_session_lifetime'] = '60' | |
8b8a1864 | 5375 | hapd = hostapd.add_ap(apdev[0], params) |
f9dd43ea | 5376 | check_tls_session_resumption_capa(dev[0], hapd) |
3b3e2687 | 5377 | eap_connect(dev[0], hapd, "TTLS", "mschap user", |
f9dd43ea JM |
5378 | anonymous_identity="ttls", password="password", |
5379 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
5380 | domain_suffix_match="server.w1.fi") | |
5381 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5382 | raise Exception("Unexpected session resumption on the first connection") | |
5383 | ||
5384 | dev[0].request("REAUTHENTICATE") | |
5385 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5386 | if ev is None: | |
5387 | raise Exception("EAP success timed out") | |
5388 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5389 | if ev is None: | |
5390 | raise Exception("Key handshake with the AP timed out") | |
5391 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5392 | raise Exception("Session resumption not used on the second connection") | |
5393 | ||
5394 | def test_eap_ttls_mschapv2_session_resumption(dev, apdev): | |
5395 | """EAP-TTLS/MSCHAPv2 session resumption""" | |
e78eb404 | 5396 | check_domain_suffix_match(dev[0]) |
f9dd43ea JM |
5397 | check_eap_capa(dev[0], "MSCHAPV2") |
5398 | params = int_eap_server_params() | |
5399 | params['tls_session_lifetime'] = '60' | |
8b8a1864 | 5400 | hapd = hostapd.add_ap(apdev[0], params) |
f9dd43ea | 5401 | check_tls_session_resumption_capa(dev[0], hapd) |
3b3e2687 | 5402 | eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user", |
f9dd43ea JM |
5403 | anonymous_identity="ttls", password="password", |
5404 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
5405 | domain_suffix_match="server.w1.fi") | |
5406 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5407 | raise Exception("Unexpected session resumption on the first connection") | |
5408 | ||
5409 | dev[0].request("REAUTHENTICATE") | |
5410 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5411 | if ev is None: | |
5412 | raise Exception("EAP success timed out") | |
5413 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5414 | if ev is None: | |
5415 | raise Exception("Key handshake with the AP timed out") | |
5416 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5417 | raise Exception("Session resumption not used on the second connection") | |
5418 | ||
5419 | def test_eap_ttls_eap_gtc_session_resumption(dev, apdev): | |
5420 | """EAP-TTLS/EAP-GTC session resumption""" | |
5421 | params = int_eap_server_params() | |
5422 | params['tls_session_lifetime'] = '60' | |
8b8a1864 | 5423 | hapd = hostapd.add_ap(apdev[0], params) |
f9dd43ea | 5424 | check_tls_session_resumption_capa(dev[0], hapd) |
3b3e2687 | 5425 | eap_connect(dev[0], hapd, "TTLS", "user", |
f9dd43ea JM |
5426 | anonymous_identity="ttls", password="password", |
5427 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC") | |
5428 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5429 | raise Exception("Unexpected session resumption on the first connection") | |
5430 | ||
5431 | dev[0].request("REAUTHENTICATE") | |
5432 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5433 | if ev is None: | |
5434 | raise Exception("EAP success timed out") | |
5435 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5436 | if ev is None: | |
5437 | raise Exception("Key handshake with the AP timed out") | |
5438 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5439 | raise Exception("Session resumption not used on the second connection") | |
5440 | ||
5441 | def test_eap_ttls_no_session_resumption(dev, apdev): | |
5442 | """EAP-TTLS session resumption disabled on server""" | |
5443 | params = int_eap_server_params() | |
5444 | params['tls_session_lifetime'] = '0' | |
8b8a1864 | 5445 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 5446 | eap_connect(dev[0], hapd, "TTLS", "pap user", |
f9dd43ea JM |
5447 | anonymous_identity="ttls", password="password", |
5448 | ca_cert="auth_serv/ca.pem", eap_workaround='0', | |
5449 | phase2="auth=PAP") | |
5450 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5451 | raise Exception("Unexpected session resumption on the first connection") | |
5452 | ||
5453 | dev[0].request("REAUTHENTICATE") | |
5454 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5455 | if ev is None: | |
5456 | raise Exception("EAP success timed out") | |
5457 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5458 | if ev is None: | |
5459 | raise Exception("Key handshake with the AP timed out") | |
5460 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5461 | raise Exception("Unexpected session resumption on the second connection") | |
5462 | ||
5463 | def test_eap_peap_session_resumption(dev, apdev): | |
5464 | """EAP-PEAP session resumption""" | |
5465 | params = int_eap_server_params() | |
5466 | params['tls_session_lifetime'] = '60' | |
8b8a1864 | 5467 | hapd = hostapd.add_ap(apdev[0], params) |
f9dd43ea | 5468 | check_tls_session_resumption_capa(dev[0], hapd) |
3b3e2687 | 5469 | eap_connect(dev[0], hapd, "PEAP", "user", |
f9dd43ea JM |
5470 | anonymous_identity="peap", password="password", |
5471 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
5472 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5473 | raise Exception("Unexpected session resumption on the first connection") | |
5474 | ||
5475 | dev[0].request("REAUTHENTICATE") | |
5476 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5477 | if ev is None: | |
5478 | raise Exception("EAP success timed out") | |
5479 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5480 | if ev is None: | |
5481 | raise Exception("Key handshake with the AP timed out") | |
5482 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5483 | raise Exception("Session resumption not used on the second connection") | |
5484 | ||
81e1ab85 JM |
5485 | def test_eap_peap_session_resumption_crypto_binding(dev, apdev): |
5486 | """EAP-PEAP session resumption with crypto binding""" | |
5487 | params = int_eap_server_params() | |
5488 | params['tls_session_lifetime'] = '60' | |
8b8a1864 | 5489 | hapd = hostapd.add_ap(apdev[0], params) |
81e1ab85 | 5490 | check_tls_session_resumption_capa(dev[0], hapd) |
3b3e2687 | 5491 | eap_connect(dev[0], hapd, "PEAP", "user", |
81e1ab85 JM |
5492 | anonymous_identity="peap", password="password", |
5493 | phase1="peapver=0 crypto_binding=2", | |
5494 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
5495 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5496 | raise Exception("Unexpected session resumption on the first connection") | |
5497 | ||
5498 | dev[0].request("REAUTHENTICATE") | |
5499 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5500 | if ev is None: | |
5501 | raise Exception("EAP success timed out") | |
5502 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5503 | if ev is None: | |
5504 | raise Exception("Key handshake with the AP timed out") | |
5505 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5506 | raise Exception("Session resumption not used on the second connection") | |
5507 | ||
f9dd43ea JM |
5508 | def test_eap_peap_no_session_resumption(dev, apdev): |
5509 | """EAP-PEAP session resumption disabled on server""" | |
5510 | params = int_eap_server_params() | |
8b8a1864 | 5511 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 5512 | eap_connect(dev[0], hapd, "PEAP", "user", |
f9dd43ea JM |
5513 | anonymous_identity="peap", password="password", |
5514 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
5515 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5516 | raise Exception("Unexpected session resumption on the first connection") | |
5517 | ||
5518 | dev[0].request("REAUTHENTICATE") | |
5519 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5520 | if ev is None: | |
5521 | raise Exception("EAP success timed out") | |
5522 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5523 | if ev is None: | |
5524 | raise Exception("Key handshake with the AP timed out") | |
5525 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5526 | raise Exception("Unexpected session resumption on the second connection") | |
5527 | ||
5528 | def test_eap_tls_session_resumption(dev, apdev): | |
5529 | """EAP-TLS session resumption""" | |
5530 | params = int_eap_server_params() | |
5531 | params['tls_session_lifetime'] = '60' | |
8b8a1864 | 5532 | hapd = hostapd.add_ap(apdev[0], params) |
f9dd43ea | 5533 | check_tls_session_resumption_capa(dev[0], hapd) |
3b3e2687 | 5534 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
f9dd43ea JM |
5535 | client_cert="auth_serv/user.pem", |
5536 | private_key="auth_serv/user.key") | |
5537 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5538 | raise Exception("Unexpected session resumption on the first connection") | |
5539 | ||
5540 | dev[0].request("REAUTHENTICATE") | |
5541 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5542 | if ev is None: | |
5543 | raise Exception("EAP success timed out") | |
5544 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5545 | if ev is None: | |
5546 | raise Exception("Key handshake with the AP timed out") | |
5547 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5548 | raise Exception("Session resumption not used on the second connection") | |
5549 | ||
5550 | dev[0].request("REAUTHENTICATE") | |
5551 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5552 | if ev is None: | |
5553 | raise Exception("EAP success timed out") | |
5554 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5555 | if ev is None: | |
5556 | raise Exception("Key handshake with the AP timed out") | |
5557 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5558 | raise Exception("Session resumption not used on the third connection") | |
5559 | ||
5560 | def test_eap_tls_session_resumption_expiration(dev, apdev): | |
5561 | """EAP-TLS session resumption""" | |
5562 | params = int_eap_server_params() | |
5563 | params['tls_session_lifetime'] = '1' | |
8b8a1864 | 5564 | hapd = hostapd.add_ap(apdev[0], params) |
f9dd43ea | 5565 | check_tls_session_resumption_capa(dev[0], hapd) |
3b3e2687 | 5566 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
f9dd43ea JM |
5567 | client_cert="auth_serv/user.pem", |
5568 | private_key="auth_serv/user.key") | |
5569 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5570 | raise Exception("Unexpected session resumption on the first connection") | |
5571 | ||
5572 | # Allow multiple attempts since OpenSSL may not expire the cached entry | |
5573 | # immediately. | |
5574 | for i in range(10): | |
5575 | time.sleep(1.2) | |
5576 | ||
5577 | dev[0].request("REAUTHENTICATE") | |
5578 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5579 | if ev is None: | |
5580 | raise Exception("EAP success timed out") | |
5581 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5582 | if ev is None: | |
5583 | raise Exception("Key handshake with the AP timed out") | |
5584 | if dev[0].get_status_field("tls_session_reused") == '0': | |
5585 | break | |
5586 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5587 | raise Exception("Session resumption used after lifetime expiration") | |
5588 | ||
5589 | def test_eap_tls_no_session_resumption(dev, apdev): | |
5590 | """EAP-TLS session resumption disabled on server""" | |
5591 | params = int_eap_server_params() | |
8b8a1864 | 5592 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 5593 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
f9dd43ea JM |
5594 | client_cert="auth_serv/user.pem", |
5595 | private_key="auth_serv/user.key") | |
5596 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5597 | raise Exception("Unexpected session resumption on the first connection") | |
5598 | ||
5599 | dev[0].request("REAUTHENTICATE") | |
5600 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5601 | if ev is None: | |
5602 | raise Exception("EAP success timed out") | |
5603 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5604 | if ev is None: | |
5605 | raise Exception("Key handshake with the AP timed out") | |
5606 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5607 | raise Exception("Unexpected session resumption on the second connection") | |
5608 | ||
5609 | def test_eap_tls_session_resumption_radius(dev, apdev): | |
5610 | """EAP-TLS session resumption (RADIUS)""" | |
5611 | params = { "ssid": "as", "beacon_int": "2000", | |
5612 | "radius_server_clients": "auth_serv/radius_clients.conf", | |
5613 | "radius_server_auth_port": '18128', | |
5614 | "eap_server": "1", | |
5615 | "eap_user_file": "auth_serv/eap_user.conf", | |
5616 | "ca_cert": "auth_serv/ca.pem", | |
5617 | "server_cert": "auth_serv/server.pem", | |
5618 | "private_key": "auth_serv/server.key", | |
5619 | "tls_session_lifetime": "60" } | |
8b8a1864 | 5620 | authsrv = hostapd.add_ap(apdev[1], params) |
f9dd43ea JM |
5621 | check_tls_session_resumption_capa(dev[0], authsrv) |
5622 | ||
5623 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
5624 | params['auth_server_port'] = "18128" | |
8b8a1864 | 5625 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 5626 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
f9dd43ea JM |
5627 | client_cert="auth_serv/user.pem", |
5628 | private_key="auth_serv/user.key") | |
5629 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5630 | raise Exception("Unexpected session resumption on the first connection") | |
5631 | ||
5632 | dev[0].request("REAUTHENTICATE") | |
5633 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5634 | if ev is None: | |
5635 | raise Exception("EAP success timed out") | |
5636 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5637 | if ev is None: | |
5638 | raise Exception("Key handshake with the AP timed out") | |
5639 | if dev[0].get_status_field("tls_session_reused") != '1': | |
5640 | raise Exception("Session resumption not used on the second connection") | |
5641 | ||
5642 | def test_eap_tls_no_session_resumption_radius(dev, apdev): | |
5643 | """EAP-TLS session resumption disabled (RADIUS)""" | |
5644 | params = { "ssid": "as", "beacon_int": "2000", | |
5645 | "radius_server_clients": "auth_serv/radius_clients.conf", | |
5646 | "radius_server_auth_port": '18128', | |
5647 | "eap_server": "1", | |
5648 | "eap_user_file": "auth_serv/eap_user.conf", | |
5649 | "ca_cert": "auth_serv/ca.pem", | |
5650 | "server_cert": "auth_serv/server.pem", | |
5651 | "private_key": "auth_serv/server.key", | |
5652 | "tls_session_lifetime": "0" } | |
8b8a1864 | 5653 | hostapd.add_ap(apdev[1], params) |
f9dd43ea JM |
5654 | |
5655 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
5656 | params['auth_server_port'] = "18128" | |
8b8a1864 | 5657 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 5658 | eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
f9dd43ea JM |
5659 | client_cert="auth_serv/user.pem", |
5660 | private_key="auth_serv/user.key") | |
5661 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5662 | raise Exception("Unexpected session resumption on the first connection") | |
5663 | ||
5664 | dev[0].request("REAUTHENTICATE") | |
5665 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
5666 | if ev is None: | |
5667 | raise Exception("EAP success timed out") | |
5668 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
5669 | if ev is None: | |
5670 | raise Exception("Key handshake with the AP timed out") | |
5671 | if dev[0].get_status_field("tls_session_reused") != '0': | |
5672 | raise Exception("Unexpected session resumption on the second connection") | |
7c0d66cf JM |
5673 | |
5674 | def test_eap_mschapv2_errors(dev, apdev): | |
5675 | """EAP-MSCHAPv2 error cases""" | |
5676 | check_eap_capa(dev[0], "MSCHAPV2") | |
5677 | check_eap_capa(dev[0], "FAST") | |
5678 | ||
5679 | params = hostapd.wpa2_eap_params(ssid="test-wpa-eap") | |
8b8a1864 | 5680 | hapd = hostapd.add_ap(apdev[0], params) |
7c0d66cf JM |
5681 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", |
5682 | identity="phase1-user", password="password", | |
5683 | scan_freq="2412") | |
5684 | dev[0].request("REMOVE_NETWORK all") | |
5685 | dev[0].wait_disconnected() | |
5686 | ||
5687 | tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"), | |
5688 | (1, "nt_password_hash;mschapv2_derive_response"), | |
5689 | (1, "nt_password_hash;=mschapv2_derive_response"), | |
5690 | (1, "generate_nt_response;mschapv2_derive_response"), | |
5691 | (1, "generate_authenticator_response;mschapv2_derive_response"), | |
5692 | (1, "nt_password_hash;=mschapv2_derive_response"), | |
5693 | (1, "get_master_key;mschapv2_derive_response"), | |
5694 | (1, "os_get_random;eap_mschapv2_challenge_reply") ] | |
5695 | for count, func in tests: | |
5696 | with fail_test(dev[0], count, func): | |
5697 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", | |
5698 | identity="phase1-user", password="password", | |
5699 | wait_connect=False, scan_freq="2412") | |
5700 | wait_fail_trigger(dev[0], "GET_FAIL") | |
5701 | dev[0].request("REMOVE_NETWORK all") | |
5702 | dev[0].wait_disconnected() | |
5703 | ||
5704 | tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"), | |
5705 | (1, "hash_nt_password_hash;=mschapv2_derive_response"), | |
5706 | (1, "generate_nt_response_pwhash;mschapv2_derive_response"), | |
5707 | (1, "generate_authenticator_response_pwhash;mschapv2_derive_response") ] | |
5708 | for count, func in tests: | |
5709 | with fail_test(dev[0], count, func): | |
5710 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", | |
5711 | identity="phase1-user", | |
5712 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
5713 | wait_connect=False, scan_freq="2412") | |
5714 | wait_fail_trigger(dev[0], "GET_FAIL") | |
5715 | dev[0].request("REMOVE_NETWORK all") | |
5716 | dev[0].wait_disconnected() | |
5717 | ||
5718 | tests = [ (1, "eap_mschapv2_init"), | |
5719 | (1, "eap_msg_alloc;eap_mschapv2_challenge_reply"), | |
5720 | (1, "eap_msg_alloc;eap_mschapv2_success"), | |
5721 | (1, "eap_mschapv2_getKey") ] | |
5722 | for count, func in tests: | |
5723 | with alloc_fail(dev[0], count, func): | |
5724 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", | |
5725 | identity="phase1-user", password="password", | |
5726 | wait_connect=False, scan_freq="2412") | |
5727 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
5728 | dev[0].request("REMOVE_NETWORK all") | |
5729 | dev[0].wait_disconnected() | |
5730 | ||
5731 | tests = [ (1, "eap_msg_alloc;eap_mschapv2_failure") ] | |
5732 | for count, func in tests: | |
5733 | with alloc_fail(dev[0], count, func): | |
5734 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", | |
5735 | identity="phase1-user", password="wrong password", | |
5736 | wait_connect=False, scan_freq="2412") | |
5737 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
5738 | dev[0].request("REMOVE_NETWORK all") | |
5739 | dev[0].wait_disconnected() | |
5740 | ||
5741 | tests = [ (2, "eap_mschapv2_init"), | |
5742 | (3, "eap_mschapv2_init") ] | |
5743 | for count, func in tests: | |
5744 | with alloc_fail(dev[0], count, func): | |
5745 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="FAST", | |
5746 | anonymous_identity="FAST", identity="user", | |
5747 | password="password", | |
5748 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
5749 | phase1="fast_provisioning=1", | |
5750 | pac_file="blob://fast_pac", | |
5751 | wait_connect=False, scan_freq="2412") | |
5752 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
5753 | dev[0].request("REMOVE_NETWORK all") | |
5754 | dev[0].wait_disconnected() | |
bf0ec17a JM |
5755 | |
5756 | def test_eap_gpsk_errors(dev, apdev): | |
5757 | """EAP-GPSK error cases""" | |
5758 | params = hostapd.wpa2_eap_params(ssid="test-wpa-eap") | |
8b8a1864 | 5759 | hapd = hostapd.add_ap(apdev[0], params) |
bf0ec17a JM |
5760 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK", |
5761 | identity="gpsk user", | |
5762 | password="abcdefghijklmnop0123456789abcdef", | |
5763 | scan_freq="2412") | |
5764 | dev[0].request("REMOVE_NETWORK all") | |
5765 | dev[0].wait_disconnected() | |
5766 | ||
5767 | tests = [ (1, "os_get_random;eap_gpsk_send_gpsk_2", None), | |
5768 | (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2", | |
5769 | "cipher=1"), | |
5770 | (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2", | |
5771 | "cipher=2"), | |
5772 | (1, "eap_gpsk_derive_keys_helper", None), | |
5773 | (2, "eap_gpsk_derive_keys_helper", None), | |
5774 | (1, "eap_gpsk_compute_mic_aes;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2", | |
5775 | "cipher=1"), | |
5776 | (1, "hmac_sha256;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2", | |
5777 | "cipher=2"), | |
5778 | (1, "eap_gpsk_compute_mic;eap_gpsk_validate_gpsk_3_mic", None), | |
5779 | (1, "eap_gpsk_compute_mic;eap_gpsk_send_gpsk_4", None), | |
5780 | (1, "eap_gpsk_derive_mid_helper", None) ] | |
5781 | for count, func, phase1 in tests: | |
5782 | with fail_test(dev[0], count, func): | |
5783 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
5784 | identity="gpsk user", | |
5785 | password="abcdefghijklmnop0123456789abcdef", | |
5786 | phase1=phase1, | |
5787 | wait_connect=False, scan_freq="2412") | |
5788 | wait_fail_trigger(dev[0], "GET_FAIL") | |
5789 | dev[0].request("REMOVE_NETWORK all") | |
5790 | dev[0].wait_disconnected() | |
5791 | ||
5792 | tests = [ (1, "eap_gpsk_init"), | |
5793 | (2, "eap_gpsk_init"), | |
5794 | (3, "eap_gpsk_init"), | |
5795 | (1, "eap_gpsk_process_id_server"), | |
5796 | (1, "eap_msg_alloc;eap_gpsk_send_gpsk_2"), | |
5797 | (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"), | |
5798 | (1, "eap_gpsk_derive_mid_helper;eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"), | |
5799 | (1, "eap_gpsk_derive_keys"), | |
5800 | (1, "eap_gpsk_derive_keys_helper"), | |
5801 | (1, "eap_msg_alloc;eap_gpsk_send_gpsk_4"), | |
5802 | (1, "eap_gpsk_getKey"), | |
5803 | (1, "eap_gpsk_get_emsk"), | |
5804 | (1, "eap_gpsk_get_session_id") ] | |
5805 | for count, func in tests: | |
5806 | with alloc_fail(dev[0], count, func): | |
5807 | dev[0].request("ERP_FLUSH") | |
5808 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
0a0c4dc1 | 5809 | identity="gpsk user@domain", erp="1", |
bf0ec17a JM |
5810 | password="abcdefghijklmnop0123456789abcdef", |
5811 | wait_connect=False, scan_freq="2412") | |
5812 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
5813 | dev[0].request("REMOVE_NETWORK all") | |
5814 | dev[0].wait_disconnected() | |
d4c3c055 JM |
5815 | |
5816 | def test_ap_wpa2_eap_sim_db(dev, apdev, params): | |
5817 | """EAP-SIM DB error cases""" | |
5818 | sockpath = '/tmp/hlr_auc_gw.sock-test' | |
5819 | try: | |
5820 | os.remove(sockpath) | |
5821 | except: | |
5822 | pass | |
5823 | hparams = int_eap_server_params() | |
5824 | hparams['eap_sim_db'] = 'unix:' + sockpath | |
8b8a1864 | 5825 | hapd = hostapd.add_ap(apdev[0], hparams) |
d4c3c055 JM |
5826 | |
5827 | # Initial test with hlr_auc_gw socket not available | |
5828 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
5829 | eap="SIM", identity="1232010000000000", | |
5830 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
5831 | scan_freq="2412", wait_connect=False) | |
5832 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5833 | if ev is None: | |
5834 | raise Exception("EAP-Failure not reported") | |
5835 | dev[0].wait_disconnected() | |
5836 | dev[0].request("DISCONNECT") | |
5837 | ||
5838 | # Test with invalid responses and response timeout | |
5839 | ||
5840 | class test_handler(SocketServer.DatagramRequestHandler): | |
5841 | def handle(self): | |
5842 | data = self.request[0].strip() | |
5843 | socket = self.request[1] | |
5844 | logger.debug("Received hlr_auc_gw request: " + data) | |
5845 | # EAP-SIM DB: Failed to parse response string | |
5846 | socket.sendto("FOO", self.client_address) | |
5847 | # EAP-SIM DB: Failed to parse response string | |
5848 | socket.sendto("FOO 1", self.client_address) | |
5849 | # EAP-SIM DB: Unknown external response | |
5850 | socket.sendto("FOO 1 2", self.client_address) | |
5851 | logger.info("No proper response - wait for pending eap_sim_db request timeout") | |
5852 | ||
5853 | server = SocketServer.UnixDatagramServer(sockpath, test_handler) | |
5854 | server.timeout = 1 | |
5855 | ||
5856 | dev[0].select_network(id) | |
5857 | server.handle_request() | |
5858 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5859 | if ev is None: | |
5860 | raise Exception("EAP-Failure not reported") | |
5861 | dev[0].wait_disconnected() | |
5862 | dev[0].request("DISCONNECT") | |
5863 | ||
5864 | # Test with a valid response | |
5865 | ||
5866 | class test_handler2(SocketServer.DatagramRequestHandler): | |
5867 | def handle(self): | |
5868 | data = self.request[0].strip() | |
5869 | socket = self.request[1] | |
5870 | logger.debug("Received hlr_auc_gw request: " + data) | |
5871 | fname = os.path.join(params['logdir'], | |
5872 | 'hlr_auc_gw.milenage_db') | |
5873 | cmd = subprocess.Popen(['../../hostapd/hlr_auc_gw', | |
5874 | '-m', fname, data], | |
5875 | stdout=subprocess.PIPE) | |
5876 | res = cmd.stdout.read().strip() | |
5877 | cmd.stdout.close() | |
5878 | logger.debug("hlr_auc_gw response: " + res) | |
5879 | socket.sendto(res, self.client_address) | |
5880 | ||
5881 | server.RequestHandlerClass = test_handler2 | |
5882 | ||
5883 | dev[0].select_network(id) | |
5884 | server.handle_request() | |
5885 | dev[0].wait_connected() | |
5886 | dev[0].request("DISCONNECT") | |
5887 | dev[0].wait_disconnected() | |
d6ba709a JM |
5888 | |
5889 | def test_eap_tls_sha512(dev, apdev, params): | |
5890 | """EAP-TLS with SHA512 signature""" | |
5891 | params = int_eap_server_params() | |
5892 | params["ca_cert"] = "auth_serv/sha512-ca.pem" | |
5893 | params["server_cert"] = "auth_serv/sha512-server.pem" | |
5894 | params["private_key"] = "auth_serv/sha512-server.key" | |
8b8a1864 | 5895 | hostapd.add_ap(apdev[0], params) |
d6ba709a JM |
5896 | |
5897 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
5898 | identity="tls user sha512", | |
5899 | ca_cert="auth_serv/sha512-ca.pem", | |
5900 | client_cert="auth_serv/sha512-user.pem", | |
5901 | private_key="auth_serv/sha512-user.key", | |
5902 | scan_freq="2412") | |
5903 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
5904 | identity="tls user sha512", | |
5905 | ca_cert="auth_serv/sha512-ca.pem", | |
5906 | client_cert="auth_serv/sha384-user.pem", | |
5907 | private_key="auth_serv/sha384-user.key", | |
5908 | scan_freq="2412") | |
5909 | ||
5910 | def test_eap_tls_sha384(dev, apdev, params): | |
5911 | """EAP-TLS with SHA384 signature""" | |
5912 | params = int_eap_server_params() | |
5913 | params["ca_cert"] = "auth_serv/sha512-ca.pem" | |
5914 | params["server_cert"] = "auth_serv/sha384-server.pem" | |
5915 | params["private_key"] = "auth_serv/sha384-server.key" | |
8b8a1864 | 5916 | hostapd.add_ap(apdev[0], params) |
d6ba709a JM |
5917 | |
5918 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
5919 | identity="tls user sha512", | |
5920 | ca_cert="auth_serv/sha512-ca.pem", | |
5921 | client_cert="auth_serv/sha512-user.pem", | |
5922 | private_key="auth_serv/sha512-user.key", | |
5923 | scan_freq="2412") | |
5924 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
5925 | identity="tls user sha512", | |
5926 | ca_cert="auth_serv/sha512-ca.pem", | |
5927 | client_cert="auth_serv/sha384-user.pem", | |
5928 | private_key="auth_serv/sha384-user.key", | |
5929 | scan_freq="2412") | |
0ceff76e JM |
5930 | |
5931 | def test_ap_wpa2_eap_assoc_rsn(dev, apdev): | |
5932 | """WPA2-Enterprise AP and association request RSN IE differences""" | |
5933 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 5934 | hostapd.add_ap(apdev[0], params) |
0ceff76e JM |
5935 | |
5936 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap-11w") | |
5937 | params["ieee80211w"] = "2" | |
8b8a1864 | 5938 | hostapd.add_ap(apdev[1], params) |
0ceff76e JM |
5939 | |
5940 | # Success cases with optional RSN IE fields removed one by one | |
5941 | tests = [ ("Normal wpa_supplicant assoc req RSN IE", | |
5942 | "30140100000fac040100000fac040100000fac010000"), | |
5943 | ("Extra PMKIDCount field in RSN IE", | |
5944 | "30160100000fac040100000fac040100000fac0100000000"), | |
5945 | ("Extra Group Management Cipher Suite in RSN IE", | |
5946 | "301a0100000fac040100000fac040100000fac0100000000000fac06"), | |
5947 | ("Extra undefined extension field in RSN IE", | |
5948 | "301c0100000fac040100000fac040100000fac0100000000000fac061122"), | |
5949 | ("RSN IE without RSN Capabilities", | |
5950 | "30120100000fac040100000fac040100000fac01"), | |
5951 | ("RSN IE without AKM", "300c0100000fac040100000fac04"), | |
5952 | ("RSN IE without pairwise", "30060100000fac04"), | |
5953 | ("RSN IE without group", "30020100") ] | |
5954 | for title, ie in tests: | |
5955 | logger.info(title) | |
5956 | set_test_assoc_ie(dev[0], ie) | |
5957 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
5958 | identity="gpsk user", | |
5959 | password="abcdefghijklmnop0123456789abcdef", | |
5960 | scan_freq="2412") | |
5961 | dev[0].request("REMOVE_NETWORK all") | |
5962 | dev[0].wait_disconnected() | |
5963 | ||
5964 | tests = [ ("Normal wpa_supplicant assoc req RSN IE", | |
5965 | "30140100000fac040100000fac040100000fac01cc00"), | |
5966 | ("Group management cipher included in assoc req RSN IE", | |
5967 | "301a0100000fac040100000fac040100000fac01cc000000000fac06") ] | |
5968 | for title, ie in tests: | |
5969 | logger.info(title) | |
5970 | set_test_assoc_ie(dev[0], ie) | |
5971 | dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1", | |
5972 | eap="GPSK", identity="gpsk user", | |
5973 | password="abcdefghijklmnop0123456789abcdef", | |
5974 | scan_freq="2412") | |
5975 | dev[0].request("REMOVE_NETWORK all") | |
5976 | dev[0].wait_disconnected() | |
5977 | ||
5978 | tests = [ ("Invalid group cipher", "30060100000fac02", 41), | |
5979 | ("Invalid pairwise cipher", "300c0100000fac040100000fac02", 42) ] | |
5980 | for title, ie, status in tests: | |
5981 | logger.info(title) | |
5982 | set_test_assoc_ie(dev[0], ie) | |
5983 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
5984 | identity="gpsk user", | |
5985 | password="abcdefghijklmnop0123456789abcdef", | |
5986 | scan_freq="2412", wait_connect=False) | |
5987 | ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"]) | |
5988 | if ev is None: | |
5989 | raise Exception("Association rejection not reported") | |
5990 | if "status_code=" + str(status) not in ev: | |
5991 | raise Exception("Unexpected status code: " + ev) | |
5992 | dev[0].request("REMOVE_NETWORK all") | |
5993 | dev[0].dump_monitor() | |
5994 | ||
5995 | tests = [ ("Management frame protection not enabled", | |
5996 | "30140100000fac040100000fac040100000fac010000", 31), | |
5997 | ("Unsupported management group cipher", | |
5998 | "301a0100000fac040100000fac040100000fac01cc000000000fac0b", 31) ] | |
5999 | for title, ie, status in tests: | |
6000 | logger.info(title) | |
6001 | set_test_assoc_ie(dev[0], ie) | |
6002 | dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1", | |
6003 | eap="GPSK", identity="gpsk user", | |
6004 | password="abcdefghijklmnop0123456789abcdef", | |
6005 | scan_freq="2412", wait_connect=False) | |
6006 | ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"]) | |
6007 | if ev is None: | |
6008 | raise Exception("Association rejection not reported") | |
6009 | if "status_code=" + str(status) not in ev: | |
6010 | raise Exception("Unexpected status code: " + ev) | |
6011 | dev[0].request("REMOVE_NETWORK all") | |
6012 | dev[0].dump_monitor() | |
ca27ee09 JM |
6013 | |
6014 | def test_eap_tls_ext_cert_check(dev, apdev): | |
6015 | """EAP-TLS and external server certification validation""" | |
6016 | # With internal server certificate chain validation | |
6017 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
6018 | identity="tls user", | |
6019 | ca_cert="auth_serv/ca.pem", | |
6020 | client_cert="auth_serv/user.pem", | |
6021 | private_key="auth_serv/user.key", | |
6022 | phase1="tls_ext_cert_check=1", scan_freq="2412", | |
6023 | only_add_network=True) | |
6024 | run_ext_cert_check(dev, apdev, id) | |
6025 | ||
6026 | def test_eap_ttls_ext_cert_check(dev, apdev): | |
6027 | """EAP-TTLS and external server certification validation""" | |
6028 | # Without internal server certificate chain validation | |
6029 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
6030 | identity="pap user", anonymous_identity="ttls", | |
6031 | password="password", phase2="auth=PAP", | |
6032 | phase1="tls_ext_cert_check=1", scan_freq="2412", | |
6033 | only_add_network=True) | |
6034 | run_ext_cert_check(dev, apdev, id) | |
6035 | ||
6036 | def test_eap_peap_ext_cert_check(dev, apdev): | |
6037 | """EAP-PEAP and external server certification validation""" | |
6038 | # With internal server certificate chain validation | |
6039 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
6040 | identity="user", anonymous_identity="peap", | |
6041 | ca_cert="auth_serv/ca.pem", | |
6042 | password="password", phase2="auth=MSCHAPV2", | |
6043 | phase1="tls_ext_cert_check=1", scan_freq="2412", | |
6044 | only_add_network=True) | |
6045 | run_ext_cert_check(dev, apdev, id) | |
6046 | ||
6047 | def test_eap_fast_ext_cert_check(dev, apdev): | |
6048 | """EAP-FAST and external server certification validation""" | |
6049 | check_eap_capa(dev[0], "FAST") | |
6050 | # With internal server certificate chain validation | |
6051 | dev[0].request("SET blob fast_pac_auth_ext ") | |
6052 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
6053 | identity="user", anonymous_identity="FAST", | |
6054 | ca_cert="auth_serv/ca.pem", | |
6055 | password="password", phase2="auth=GTC", | |
6056 | phase1="tls_ext_cert_check=1 fast_provisioning=2", | |
6057 | pac_file="blob://fast_pac_auth_ext", | |
6058 | scan_freq="2412", | |
6059 | only_add_network=True) | |
6060 | run_ext_cert_check(dev, apdev, id) | |
6061 | ||
6062 | def run_ext_cert_check(dev, apdev, net_id): | |
6063 | check_ext_cert_check_support(dev[0]) | |
6064 | if not openssl_imported: | |
6065 | raise HwsimSkip("OpenSSL python method not available") | |
6066 | ||
6067 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 6068 | hapd = hostapd.add_ap(apdev[0], params) |
ca27ee09 JM |
6069 | |
6070 | dev[0].select_network(net_id) | |
6071 | certs = {} | |
6072 | while True: | |
6073 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT", | |
6074 | "CTRL-REQ-EXT_CERT_CHECK", | |
6075 | "CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
6076 | if ev is None: | |
6077 | raise Exception("No peer server certificate event seen") | |
6078 | if "CTRL-EVENT-EAP-PEER-CERT" in ev: | |
6079 | depth = None | |
6080 | cert = None | |
6081 | vals = ev.split(' ') | |
6082 | for v in vals: | |
6083 | if v.startswith("depth="): | |
6084 | depth = int(v.split('=')[1]) | |
6085 | elif v.startswith("cert="): | |
6086 | cert = v.split('=')[1] | |
6087 | if depth is not None and cert: | |
6088 | certs[depth] = binascii.unhexlify(cert) | |
6089 | elif "CTRL-EVENT-EAP-SUCCESS" in ev: | |
6090 | raise Exception("Unexpected EAP-Success") | |
6091 | elif "CTRL-REQ-EXT_CERT_CHECK" in ev: | |
6092 | id = ev.split(':')[0].split('-')[-1] | |
6093 | break | |
6094 | if 0 not in certs: | |
6095 | raise Exception("Server certificate not received") | |
6096 | if 1 not in certs: | |
6097 | raise Exception("Server certificate issuer not received") | |
6098 | ||
6099 | cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, | |
6100 | certs[0]) | |
6101 | cn = cert.get_subject().commonName | |
6102 | logger.info("Server certificate CN=" + cn) | |
6103 | ||
6104 | issuer = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, | |
6105 | certs[1]) | |
6106 | icn = issuer.get_subject().commonName | |
6107 | logger.info("Issuer certificate CN=" + icn) | |
6108 | ||
6109 | if cn != "server.w1.fi": | |
6110 | raise Exception("Unexpected server certificate CN: " + cn) | |
6111 | if icn != "Root CA": | |
6112 | raise Exception("Unexpected server certificate issuer CN: " + icn) | |
6113 | ||
6114 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=0.1) | |
6115 | if ev: | |
6116 | raise Exception("Unexpected EAP-Success before external check result indication") | |
6117 | ||
6118 | dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":good") | |
6119 | dev[0].wait_connected() | |
6120 | ||
6121 | dev[0].request("DISCONNECT") | |
6122 | dev[0].wait_disconnected() | |
6123 | if "FAIL" in dev[0].request("PMKSA_FLUSH"): | |
6124 | raise Exception("PMKSA_FLUSH failed") | |
6125 | dev[0].request("SET blob fast_pac_auth_ext ") | |
6126 | dev[0].request("RECONNECT") | |
6127 | ||
6128 | ev = dev[0].wait_event(["CTRL-REQ-EXT_CERT_CHECK"], timeout=10) | |
6129 | if ev is None: | |
6130 | raise Exception("No peer server certificate event seen (2)") | |
6131 | id = ev.split(':')[0].split('-')[-1] | |
6132 | dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":bad") | |
6133 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
6134 | if ev is None: | |
6135 | raise Exception("EAP-Failure not reported") | |
6136 | dev[0].request("REMOVE_NETWORK all") | |
6137 | dev[0].wait_disconnected() | |
a89faedc JM |
6138 | |
6139 | def test_eap_tls_errors(dev, apdev): | |
6140 | """EAP-TLS error cases""" | |
6141 | params = int_eap_server_params() | |
6142 | params['fragment_size'] = '100' | |
8b8a1864 | 6143 | hostapd.add_ap(apdev[0], params) |
a89faedc JM |
6144 | with alloc_fail(dev[0], 1, |
6145 | "eap_peer_tls_reassemble_fragment"): | |
6146 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
6147 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
6148 | client_cert="auth_serv/user.pem", | |
6149 | private_key="auth_serv/user.key", | |
6150 | wait_connect=False, scan_freq="2412") | |
6151 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
6152 | dev[0].request("REMOVE_NETWORK all") | |
6153 | dev[0].wait_disconnected() | |
6154 | ||
6155 | with alloc_fail(dev[0], 1, "eap_tls_init"): | |
6156 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
6157 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
6158 | client_cert="auth_serv/user.pem", | |
6159 | private_key="auth_serv/user.key", | |
6160 | wait_connect=False, scan_freq="2412") | |
6161 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
6162 | dev[0].request("REMOVE_NETWORK all") | |
6163 | dev[0].wait_disconnected() | |
6164 | ||
6165 | with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init"): | |
6166 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
6167 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
6168 | client_cert="auth_serv/user.pem", | |
6169 | private_key="auth_serv/user.key", | |
6170 | engine="1", | |
6171 | wait_connect=False, scan_freq="2412") | |
6172 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
6173 | ev = dev[0].wait_event(["CTRL-REQ-PIN"], timeout=5) | |
6174 | if ev is None: | |
6175 | raise Exception("No CTRL-REQ-PIN seen") | |
6176 | dev[0].request("REMOVE_NETWORK all") | |
6177 | dev[0].wait_disconnected() | |
6178 | ||
6179 | tests = [ "eap_peer_tls_derive_key;eap_tls_success", | |
6180 | "eap_peer_tls_derive_session_id;eap_tls_success", | |
6181 | "eap_tls_getKey", | |
6182 | "eap_tls_get_emsk", | |
6183 | "eap_tls_get_session_id" ] | |
6184 | for func in tests: | |
6185 | with alloc_fail(dev[0], 1, func): | |
6186 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
0a0c4dc1 JM |
6187 | identity="tls user@domain", |
6188 | ca_cert="auth_serv/ca.pem", | |
a89faedc JM |
6189 | client_cert="auth_serv/user.pem", |
6190 | private_key="auth_serv/user.key", | |
6191 | erp="1", | |
6192 | wait_connect=False, scan_freq="2412") | |
6193 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
6194 | dev[0].request("REMOVE_NETWORK all") | |
6195 | dev[0].wait_disconnected() | |
6196 | ||
6197 | with alloc_fail(dev[0], 1, "eap_unauth_tls_init"): | |
6198 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="UNAUTH-TLS", | |
6199 | identity="unauth-tls", ca_cert="auth_serv/ca.pem", | |
6200 | wait_connect=False, scan_freq="2412") | |
6201 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
6202 | dev[0].request("REMOVE_NETWORK all") | |
6203 | dev[0].wait_disconnected() | |
6204 | ||
6205 | with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init;eap_unauth_tls_init"): | |
6206 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="UNAUTH-TLS", | |
6207 | identity="unauth-tls", ca_cert="auth_serv/ca.pem", | |
6208 | wait_connect=False, scan_freq="2412") | |
6209 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
6210 | dev[0].request("REMOVE_NETWORK all") | |
6211 | dev[0].wait_disconnected() | |
6212 | ||
6213 | with alloc_fail(dev[0], 1, "eap_wfa_unauth_tls_init"): | |
6214 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", | |
6215 | eap="WFA-UNAUTH-TLS", | |
6216 | identity="osen@example.com", ca_cert="auth_serv/ca.pem", | |
6217 | wait_connect=False, scan_freq="2412") | |
6218 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
6219 | dev[0].request("REMOVE_NETWORK all") | |
6220 | dev[0].wait_disconnected() | |
6221 | ||
6222 | with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init;eap_wfa_unauth_tls_init"): | |
6223 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", | |
6224 | eap="WFA-UNAUTH-TLS", | |
6225 | identity="osen@example.com", ca_cert="auth_serv/ca.pem", | |
6226 | wait_connect=False, scan_freq="2412") | |
6227 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
6228 | dev[0].request("REMOVE_NETWORK all") | |
6229 | dev[0].wait_disconnected() | |
0918fe4d JM |
6230 | |
6231 | def test_ap_wpa2_eap_status(dev, apdev): | |
6232 | """EAP state machine status information""" | |
6233 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
8b8a1864 | 6234 | hostapd.add_ap(apdev[0], params) |
0918fe4d JM |
6235 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", |
6236 | identity="cert user", | |
6237 | ca_cert="auth_serv/ca.pem", phase2="auth=TLS", | |
6238 | ca_cert2="auth_serv/ca.pem", | |
6239 | client_cert2="auth_serv/user.pem", | |
6240 | private_key2="auth_serv/user.key", | |
6241 | scan_freq="2412", wait_connect=False) | |
6242 | success = False | |
6243 | states = [] | |
6244 | method_states = [] | |
6245 | decisions = [] | |
6246 | req_methods = [] | |
6247 | selected_methods = [] | |
6248 | for i in range(100000): | |
6249 | s = dev[0].get_status(extra="VERBOSE") | |
6250 | if 'EAP state' in s: | |
6251 | state = s['EAP state'] | |
6252 | if state: | |
6253 | if state not in states: | |
6254 | states.append(state) | |
6255 | if state == "SUCCESS": | |
6256 | success = True | |
6257 | break | |
6258 | if 'methodState' in s: | |
6259 | val = s['methodState'] | |
6260 | if val not in method_states: | |
6261 | method_states.append(val) | |
6262 | if 'decision' in s: | |
6263 | val = s['decision'] | |
6264 | if val not in decisions: | |
6265 | decisions.append(val) | |
6266 | if 'reqMethod' in s: | |
6267 | val = s['reqMethod'] | |
6268 | if val not in req_methods: | |
6269 | req_methods.append(val) | |
6270 | if 'selectedMethod' in s: | |
6271 | val = s['selectedMethod'] | |
6272 | if val not in selected_methods: | |
6273 | selected_methods.append(val) | |
6274 | logger.info("Iterations: %d" % i) | |
6275 | logger.info("EAP states: " + str(states)) | |
6276 | logger.info("methodStates: " + str(method_states)) | |
6277 | logger.info("decisions: " + str(decisions)) | |
6278 | logger.info("reqMethods: " + str(req_methods)) | |
6279 | logger.info("selectedMethods: " + str(selected_methods)) | |
6280 | if not success: | |
6281 | raise Exception("EAP did not succeed") | |
6282 | dev[0].wait_connected() | |
6283 | dev[0].request("REMOVE_NETWORK all") | |
6284 | dev[0].wait_disconnected() | |
29b508e7 JM |
6285 | |
6286 | def test_ap_wpa2_eap_gpsk_ptk_rekey_ap(dev, apdev): | |
6287 | """WPA2-Enterprise with EAP-GPSK and PTK rekey enforced by AP""" | |
6288 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
6289 | params['wpa_ptk_rekey'] = '2' | |
8b8a1864 | 6290 | hapd = hostapd.add_ap(apdev[0], params) |
3b3e2687 | 6291 | id = eap_connect(dev[0], hapd, "GPSK", "gpsk user", |
29b508e7 JM |
6292 | password="abcdefghijklmnop0123456789abcdef") |
6293 | ev = dev[0].wait_event(["WPA: Key negotiation completed"]) | |
6294 | if ev is None: | |
6295 | raise Exception("PTK rekey timed out") | |
6296 | hwsim_utils.test_connectivity(dev[0], hapd) | |
2833743d JM |
6297 | |
6298 | def test_ap_wpa2_eap_wildcard_ssid(dev, apdev): | |
6299 | """WPA2-Enterprise connection using EAP-GPSK and wildcard SSID""" | |
6300 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
6301 | hapd = hostapd.add_ap(apdev[0], params) | |
6302 | dev[0].connect(bssid=apdev[0]['bssid'], key_mgmt="WPA-EAP", eap="GPSK", | |
6303 | identity="gpsk user", | |
6304 | password="abcdefghijklmnop0123456789abcdef", | |
6305 | scan_freq="2412") |