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