]>
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 | |
9626962d JM |
17 | |
18 | import hwsim_utils | |
19 | import hostapd | |
7c0d66cf | 20 | from utils import HwsimSkip, alloc_fail, fail_test, skip_with_fips, wait_fail_trigger |
52352802 | 21 | from wpasupplicant import WpaSupplicant |
0ceff76e | 22 | from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations, set_test_assoc_ie |
9626962d | 23 | |
ca27ee09 JM |
24 | try: |
25 | import OpenSSL | |
26 | openssl_imported = True | |
27 | except ImportError: | |
28 | openssl_imported = False | |
29 | ||
81e787b7 JM |
30 | def check_hlr_auc_gw_support(): |
31 | if not os.path.exists("/tmp/hlr_auc_gw.sock"): | |
32 | raise HwsimSkip("No hlr_auc_gw available") | |
33 | ||
3b51cc63 JM |
34 | def check_eap_capa(dev, method): |
35 | res = dev.get_capability("eap") | |
36 | if method not in res: | |
37 | raise HwsimSkip("EAP method %s not supported in the build" % method) | |
38 | ||
506b2f05 JM |
39 | def check_subject_match_support(dev): |
40 | tls = dev.request("GET tls_library") | |
41 | if not tls.startswith("OpenSSL"): | |
42 | raise HwsimSkip("subject_match not supported with this TLS library: " + tls) | |
43 | ||
44 | def check_altsubject_match_support(dev): | |
45 | tls = dev.request("GET tls_library") | |
46 | if not tls.startswith("OpenSSL"): | |
47 | raise HwsimSkip("altsubject_match not supported with this TLS library: " + tls) | |
48 | ||
e78eb404 JM |
49 | def check_domain_match(dev): |
50 | tls = dev.request("GET tls_library") | |
51 | if tls.startswith("internal"): | |
52 | raise HwsimSkip("domain_match not supported with this TLS library: " + tls) | |
53 | ||
54 | def check_domain_suffix_match(dev): | |
55 | tls = dev.request("GET tls_library") | |
56 | if tls.startswith("internal"): | |
57 | raise HwsimSkip("domain_suffix_match not supported with this TLS library: " + tls) | |
58 | ||
24579e70 JM |
59 | def check_domain_match_full(dev): |
60 | tls = dev.request("GET tls_library") | |
61 | if not tls.startswith("OpenSSL"): | |
62 | raise HwsimSkip("domain_suffix_match requires full match with this TLS library: " + tls) | |
63 | ||
4bf4e9db JM |
64 | def check_cert_probe_support(dev): |
65 | tls = dev.request("GET tls_library") | |
0fc1b583 | 66 | if not tls.startswith("OpenSSL") and not tls.startswith("internal"): |
4bf4e9db JM |
67 | raise HwsimSkip("Certificate probing not supported with this TLS library: " + tls) |
68 | ||
ca27ee09 JM |
69 | def check_ext_cert_check_support(dev): |
70 | tls = dev.request("GET tls_library") | |
71 | if not tls.startswith("OpenSSL"): | |
72 | raise HwsimSkip("ext_cert_check not supported with this TLS library: " + tls) | |
73 | ||
0dae8c99 JM |
74 | def check_ocsp_support(dev): |
75 | tls = dev.request("GET tls_library") | |
138903f9 JM |
76 | #if tls.startswith("internal"): |
77 | # raise HwsimSkip("OCSP not supported with this TLS library: " + tls) | |
0c6185fc JM |
78 | #if "BoringSSL" in tls: |
79 | # raise HwsimSkip("OCSP not supported with this TLS library: " + tls) | |
0dae8c99 | 80 | |
686eee77 JM |
81 | def check_pkcs12_support(dev): |
82 | tls = dev.request("GET tls_library") | |
16c43d2a JM |
83 | #if tls.startswith("internal"): |
84 | # raise HwsimSkip("PKCS#12 not supported with this TLS library: " + tls) | |
686eee77 | 85 | |
404597e6 JM |
86 | def check_dh_dsa_support(dev): |
87 | tls = dev.request("GET tls_library") | |
88 | if tls.startswith("internal"): | |
89 | raise HwsimSkip("DH DSA not supported with this TLS library: " + tls) | |
90 | ||
6ea231e6 JM |
91 | def read_pem(fname): |
92 | with open(fname, "r") as f: | |
93 | lines = f.readlines() | |
94 | copy = False | |
95 | cert = "" | |
96 | for l in lines: | |
97 | if "-----END" in l: | |
98 | break | |
99 | if copy: | |
100 | cert = cert + l | |
101 | if "-----BEGIN" in l: | |
102 | copy = True | |
103 | return base64.b64decode(cert) | |
104 | ||
6f939e59 JM |
105 | def eap_connect(dev, ap, method, identity, |
106 | sha256=False, expect_failure=False, local_error_report=False, | |
9dd21d51 | 107 | maybe_local_error=False, **kwargs): |
cb33ee14 | 108 | hapd = hostapd.Hostapd(ap['ifname']) |
2bb9e283 JM |
109 | id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", |
110 | eap=method, identity=identity, | |
6f939e59 JM |
111 | wait_connect=False, scan_freq="2412", ieee80211w="1", |
112 | **kwargs) | |
f10ba3b2 JM |
113 | eap_check_auth(dev, method, True, sha256=sha256, |
114 | expect_failure=expect_failure, | |
9dd21d51 JM |
115 | local_error_report=local_error_report, |
116 | maybe_local_error=maybe_local_error) | |
f10ba3b2 JM |
117 | if expect_failure: |
118 | return id | |
cb33ee14 JM |
119 | ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) |
120 | if ev is None: | |
121 | raise Exception("No connection event received from hostapd") | |
2bb9e283 | 122 | return id |
75b2b9cf | 123 | |
f10ba3b2 | 124 | def eap_check_auth(dev, method, initial, rsn=True, sha256=False, |
9dd21d51 JM |
125 | expect_failure=False, local_error_report=False, |
126 | maybe_local_error=False): | |
9626962d JM |
127 | ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) |
128 | if ev is None: | |
129 | raise Exception("Association and EAP start timed out") | |
06cdd1cd JM |
130 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD", |
131 | "CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
9626962d JM |
132 | if ev is None: |
133 | raise Exception("EAP method selection timed out") | |
06cdd1cd JM |
134 | if "CTRL-EVENT-EAP-FAILURE" in ev: |
135 | if maybe_local_error: | |
136 | return | |
137 | raise Exception("Could not select EAP method") | |
9626962d JM |
138 | if method not in ev: |
139 | raise Exception("Unexpected EAP method") | |
f10ba3b2 JM |
140 | if expect_failure: |
141 | ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
142 | if ev is None: | |
143 | raise Exception("EAP failure timed out") | |
5f35a5e2 | 144 | ev = dev.wait_disconnected(timeout=10) |
9dd21d51 JM |
145 | if maybe_local_error and "locally_generated=1" in ev: |
146 | return | |
f10ba3b2 JM |
147 | if not local_error_report: |
148 | if "reason=23" not in ev: | |
149 | raise Exception("Proper reason code for disconnection not reported") | |
150 | return | |
9626962d JM |
151 | ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) |
152 | if ev is None: | |
153 | raise Exception("EAP success timed out") | |
9626962d | 154 | |
75b2b9cf JM |
155 | if initial: |
156 | ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
75b2b9cf | 157 | else: |
bce774ad JM |
158 | ev = dev.wait_event(["WPA: Key negotiation completed"], timeout=10) |
159 | if ev is None: | |
160 | raise Exception("Association with the AP timed out") | |
161 | status = dev.get_status() | |
162 | if status["wpa_state"] != "COMPLETED": | |
163 | raise Exception("Connection not completed") | |
75b2b9cf | 164 | |
9626962d JM |
165 | if status["suppPortStatus"] != "Authorized": |
166 | raise Exception("Port not authorized") | |
167 | if method not in status["selectedMethod"]: | |
168 | raise Exception("Incorrect EAP method status") | |
2b005194 JM |
169 | if sha256: |
170 | e = "WPA2-EAP-SHA256" | |
171 | elif rsn: | |
71390dc8 JM |
172 | e = "WPA2/IEEE 802.1X/EAP" |
173 | else: | |
174 | e = "WPA/IEEE 802.1X/EAP" | |
175 | if status["key_mgmt"] != e: | |
176 | raise Exception("Unexpected key_mgmt status: " + status["key_mgmt"]) | |
2fc4749c | 177 | return status |
9626962d | 178 | |
5b1aaf6c | 179 | def eap_reauth(dev, method, rsn=True, sha256=False, expect_failure=False): |
75b2b9cf | 180 | dev.request("REAUTHENTICATE") |
2fc4749c JM |
181 | return eap_check_auth(dev, method, False, rsn=rsn, sha256=sha256, |
182 | expect_failure=expect_failure) | |
75b2b9cf | 183 | |
9626962d JM |
184 | def test_ap_wpa2_eap_sim(dev, apdev): |
185 | """WPA2-Enterprise connection using EAP-SIM""" | |
81e787b7 | 186 | check_hlr_auc_gw_support() |
9626962d | 187 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 188 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 189 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", |
9626962d | 190 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") |
a8375c94 | 191 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 192 | eap_reauth(dev[0], "SIM") |
9626962d | 193 | |
a0f350fd JM |
194 | eap_connect(dev[1], apdev[0], "SIM", "1232010000000001", |
195 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
196 | eap_connect(dev[2], apdev[0], "SIM", "1232010000000002", | |
197 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
198 | expect_failure=True) | |
199 | ||
f10ba3b2 JM |
200 | logger.info("Negative test with incorrect key") |
201 | dev[0].request("REMOVE_NETWORK all") | |
202 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
203 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
204 | expect_failure=True) | |
205 | ||
32747a3e JM |
206 | logger.info("Invalid GSM-Milenage key") |
207 | dev[0].request("REMOVE_NETWORK all") | |
208 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
209 | password="ffdca4eda45b53cf0f12d7c9c3bc6a", | |
210 | expect_failure=True) | |
211 | ||
212 | logger.info("Invalid GSM-Milenage key(2)") | |
213 | dev[0].request("REMOVE_NETWORK all") | |
214 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
215 | password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581", | |
216 | expect_failure=True) | |
217 | ||
218 | logger.info("Invalid GSM-Milenage key(3)") | |
219 | dev[0].request("REMOVE_NETWORK all") | |
220 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
221 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q", | |
222 | expect_failure=True) | |
223 | ||
224 | logger.info("Invalid GSM-Milenage key(4)") | |
225 | dev[0].request("REMOVE_NETWORK all") | |
226 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
227 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581", | |
228 | expect_failure=True) | |
229 | ||
230 | logger.info("Missing key configuration") | |
231 | dev[0].request("REMOVE_NETWORK all") | |
232 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
233 | expect_failure=True) | |
234 | ||
5b1aaf6c JM |
235 | def test_ap_wpa2_eap_sim_sql(dev, apdev, params): |
236 | """WPA2-Enterprise connection using EAP-SIM (SQL)""" | |
81e787b7 | 237 | check_hlr_auc_gw_support() |
5b1aaf6c JM |
238 | try: |
239 | import sqlite3 | |
240 | except ImportError: | |
81e787b7 | 241 | raise HwsimSkip("No sqlite3 module available") |
5b1aaf6c JM |
242 | con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) |
243 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
244 | params['auth_server_port'] = "1814" | |
245 | hostapd.add_ap(apdev[0]['ifname'], params) | |
246 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
247 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
248 | ||
249 | logger.info("SIM fast re-authentication") | |
250 | eap_reauth(dev[0], "SIM") | |
251 | ||
252 | logger.info("SIM full auth with pseudonym") | |
253 | with con: | |
254 | cur = con.cursor() | |
255 | cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'") | |
256 | eap_reauth(dev[0], "SIM") | |
257 | ||
258 | logger.info("SIM full auth with permanent identity") | |
259 | with con: | |
260 | cur = con.cursor() | |
261 | cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'") | |
262 | cur.execute("DELETE FROM pseudonyms WHERE permanent='1232010000000000'") | |
263 | eap_reauth(dev[0], "SIM") | |
264 | ||
265 | logger.info("SIM reauth with mismatching MK") | |
266 | with con: | |
267 | cur = con.cursor() | |
268 | cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='1232010000000000'") | |
269 | eap_reauth(dev[0], "SIM", expect_failure=True) | |
270 | dev[0].request("REMOVE_NETWORK all") | |
271 | ||
272 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
273 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
274 | with con: | |
275 | cur = con.cursor() | |
276 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'") | |
277 | eap_reauth(dev[0], "SIM") | |
278 | with con: | |
279 | cur = con.cursor() | |
280 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'") | |
281 | logger.info("SIM reauth with mismatching counter") | |
282 | eap_reauth(dev[0], "SIM") | |
283 | dev[0].request("REMOVE_NETWORK all") | |
284 | ||
285 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
286 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
287 | with con: | |
288 | cur = con.cursor() | |
289 | cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='1232010000000000'") | |
290 | logger.info("SIM reauth with max reauth count reached") | |
291 | eap_reauth(dev[0], "SIM") | |
292 | ||
e2a90a4c JM |
293 | def test_ap_wpa2_eap_sim_config(dev, apdev): |
294 | """EAP-SIM configuration options""" | |
295 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
296 | hostapd.add_ap(apdev[0]['ifname'], params) | |
297 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM", | |
298 | identity="1232010000000000", | |
299 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
300 | phase1="sim_min_num_chal=1", | |
301 | wait_connect=False, scan_freq="2412") | |
302 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10) | |
303 | if ev is None: | |
304 | raise Exception("No EAP error message seen") | |
305 | dev[0].request("REMOVE_NETWORK all") | |
306 | ||
307 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM", | |
308 | identity="1232010000000000", | |
309 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
310 | phase1="sim_min_num_chal=4", | |
311 | wait_connect=False, scan_freq="2412") | |
312 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10) | |
313 | if ev is None: | |
314 | raise Exception("No EAP error message seen (2)") | |
315 | dev[0].request("REMOVE_NETWORK all") | |
316 | ||
317 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
318 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
319 | phase1="sim_min_num_chal=2") | |
320 | eap_connect(dev[1], apdev[0], "SIM", "1232010000000000", | |
321 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
322 | anonymous_identity="345678") | |
323 | ||
72cbc684 JM |
324 | def test_ap_wpa2_eap_sim_ext(dev, apdev): |
325 | """WPA2-Enterprise connection using EAP-SIM and external GSM auth""" | |
47dcb118 | 326 | try: |
81e787b7 | 327 | _test_ap_wpa2_eap_sim_ext(dev, apdev) |
47dcb118 JM |
328 | finally: |
329 | dev[0].request("SET external_sim 0") | |
330 | ||
331 | def _test_ap_wpa2_eap_sim_ext(dev, apdev): | |
81e787b7 | 332 | check_hlr_auc_gw_support() |
72cbc684 JM |
333 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
334 | hostapd.add_ap(apdev[0]['ifname'], params) | |
335 | dev[0].request("SET external_sim 1") | |
336 | id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP", | |
337 | identity="1232010000000000", | |
338 | wait_connect=False, scan_freq="2412") | |
339 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) | |
340 | if ev is None: | |
341 | raise Exception("Network connected timed out") | |
342 | ||
343 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
344 | if ev is None: | |
345 | raise Exception("Wait for external SIM processing request timed out") | |
346 | p = ev.split(':', 2) | |
347 | if p[1] != "GSM-AUTH": | |
348 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
349 | rid = p[0].split('-')[3] | |
350 | ||
351 | # IK:CK:RES | |
352 | resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344" | |
353 | # This will fail during processing, but the ctrl_iface command succeeds | |
354 | dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:" + resp) | |
355 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
356 | if ev is None: | |
357 | raise Exception("EAP failure not reported") | |
358 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
359 | dev[0].wait_disconnected() |
360 | time.sleep(0.1) | |
72cbc684 JM |
361 | |
362 | dev[0].select_network(id, freq="2412") | |
363 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
364 | if ev is None: | |
365 | raise Exception("Wait for external SIM processing request timed out") | |
366 | p = ev.split(':', 2) | |
367 | if p[1] != "GSM-AUTH": | |
368 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
369 | rid = p[0].split('-')[3] | |
370 | # This will fail during GSM auth validation | |
371 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:q"): | |
372 | raise Exception("CTRL-RSP-SIM failed") | |
373 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
374 | if ev is None: | |
375 | raise Exception("EAP failure not reported") | |
376 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
377 | dev[0].wait_disconnected() |
378 | time.sleep(0.1) | |
72cbc684 JM |
379 | |
380 | dev[0].select_network(id, freq="2412") | |
381 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
382 | if ev is None: | |
383 | raise Exception("Wait for external SIM processing request timed out") | |
384 | p = ev.split(':', 2) | |
385 | if p[1] != "GSM-AUTH": | |
386 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
387 | rid = p[0].split('-')[3] | |
388 | # This will fail during GSM auth validation | |
389 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:34"): | |
390 | raise Exception("CTRL-RSP-SIM failed") | |
391 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
392 | if ev is None: | |
393 | raise Exception("EAP failure not reported") | |
394 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
395 | dev[0].wait_disconnected() |
396 | time.sleep(0.1) | |
72cbc684 JM |
397 | |
398 | dev[0].select_network(id, freq="2412") | |
399 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
400 | if ev is None: | |
401 | raise Exception("Wait for external SIM processing request timed out") | |
402 | p = ev.split(':', 2) | |
403 | if p[1] != "GSM-AUTH": | |
404 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
405 | rid = p[0].split('-')[3] | |
406 | # This will fail during GSM auth validation | |
407 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677"): | |
408 | raise Exception("CTRL-RSP-SIM failed") | |
409 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
410 | if ev is None: | |
411 | raise Exception("EAP failure not reported") | |
412 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
413 | dev[0].wait_disconnected() |
414 | time.sleep(0.1) | |
72cbc684 JM |
415 | |
416 | dev[0].select_network(id, freq="2412") | |
417 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
418 | if ev is None: | |
419 | raise Exception("Wait for external SIM processing request timed out") | |
420 | p = ev.split(':', 2) | |
421 | if p[1] != "GSM-AUTH": | |
422 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
423 | rid = p[0].split('-')[3] | |
424 | # This will fail during GSM auth validation | |
425 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:q"): | |
426 | raise Exception("CTRL-RSP-SIM failed") | |
427 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
428 | if ev is None: | |
429 | raise Exception("EAP failure not reported") | |
430 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
431 | dev[0].wait_disconnected() |
432 | time.sleep(0.1) | |
72cbc684 JM |
433 | |
434 | dev[0].select_network(id, freq="2412") | |
435 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
436 | if ev is None: | |
437 | raise Exception("Wait for external SIM processing request timed out") | |
438 | p = ev.split(':', 2) | |
439 | if p[1] != "GSM-AUTH": | |
440 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
441 | rid = p[0].split('-')[3] | |
442 | # This will fail during GSM auth validation | |
443 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:00112233"): | |
444 | raise Exception("CTRL-RSP-SIM failed") | |
445 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
446 | if ev is None: | |
447 | raise Exception("EAP failure not reported") | |
448 | dev[0].request("DISCONNECT") | |
90ad11e6 JM |
449 | dev[0].wait_disconnected() |
450 | time.sleep(0.1) | |
72cbc684 JM |
451 | |
452 | dev[0].select_network(id, freq="2412") | |
453 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
454 | if ev is None: | |
455 | raise Exception("Wait for external SIM processing request timed out") | |
456 | p = ev.split(':', 2) | |
457 | if p[1] != "GSM-AUTH": | |
458 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
459 | rid = p[0].split('-')[3] | |
460 | # This will fail during GSM auth validation | |
461 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:00112233:q"): | |
462 | raise Exception("CTRL-RSP-SIM failed") | |
463 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
464 | if ev is None: | |
465 | raise Exception("EAP failure not reported") | |
466 | ||
486f4e3c JM |
467 | def test_ap_wpa2_eap_sim_oom(dev, apdev): |
468 | """EAP-SIM and OOM""" | |
469 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
470 | hostapd.add_ap(apdev[0]['ifname'], params) | |
471 | tests = [ (1, "milenage_f2345"), | |
472 | (2, "milenage_f2345"), | |
473 | (3, "milenage_f2345"), | |
474 | (4, "milenage_f2345"), | |
475 | (5, "milenage_f2345"), | |
476 | (6, "milenage_f2345"), | |
477 | (7, "milenage_f2345"), | |
478 | (8, "milenage_f2345"), | |
479 | (9, "milenage_f2345"), | |
480 | (10, "milenage_f2345"), | |
481 | (11, "milenage_f2345"), | |
482 | (12, "milenage_f2345") ] | |
483 | for count, func in tests: | |
484 | with alloc_fail(dev[0], count, func): | |
485 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM", | |
486 | identity="1232010000000000", | |
487 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
488 | wait_connect=False, scan_freq="2412") | |
489 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5) | |
490 | if ev is None: | |
491 | raise Exception("EAP method not selected") | |
492 | dev[0].wait_disconnected() | |
493 | dev[0].request("REMOVE_NETWORK all") | |
494 | ||
9626962d JM |
495 | def test_ap_wpa2_eap_aka(dev, apdev): |
496 | """WPA2-Enterprise connection using EAP-AKA""" | |
81e787b7 | 497 | check_hlr_auc_gw_support() |
9626962d | 498 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 499 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 500 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", |
9626962d | 501 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") |
a8375c94 | 502 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 503 | eap_reauth(dev[0], "AKA") |
9626962d | 504 | |
f10ba3b2 JM |
505 | logger.info("Negative test with incorrect key") |
506 | dev[0].request("REMOVE_NETWORK all") | |
507 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
508 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
509 | expect_failure=True) | |
510 | ||
32747a3e JM |
511 | logger.info("Invalid Milenage key") |
512 | dev[0].request("REMOVE_NETWORK all") | |
513 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
514 | password="ffdca4eda45b53cf0f12d7c9c3bc6a", | |
515 | expect_failure=True) | |
516 | ||
517 | logger.info("Invalid Milenage key(2)") | |
518 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
519 | password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
520 | expect_failure=True) | |
521 | ||
522 | logger.info("Invalid Milenage key(3)") | |
523 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
524 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q:000000000123", | |
525 | expect_failure=True) | |
526 | ||
527 | logger.info("Invalid Milenage key(4)") | |
528 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
529 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:00000000012q", | |
530 | expect_failure=True) | |
531 | ||
532 | logger.info("Invalid Milenage key(5)") | |
533 | dev[0].request("REMOVE_NETWORK all") | |
534 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
535 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581q000000000123", | |
536 | expect_failure=True) | |
537 | ||
538 | logger.info("Invalid Milenage key(6)") | |
539 | dev[0].request("REMOVE_NETWORK all") | |
540 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
541 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581q000000000123", | |
542 | expect_failure=True) | |
543 | ||
544 | logger.info("Missing key configuration") | |
545 | dev[0].request("REMOVE_NETWORK all") | |
546 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
547 | expect_failure=True) | |
548 | ||
5b1aaf6c JM |
549 | def test_ap_wpa2_eap_aka_sql(dev, apdev, params): |
550 | """WPA2-Enterprise connection using EAP-AKA (SQL)""" | |
81e787b7 | 551 | check_hlr_auc_gw_support() |
5b1aaf6c JM |
552 | try: |
553 | import sqlite3 | |
554 | except ImportError: | |
81e787b7 | 555 | raise HwsimSkip("No sqlite3 module available") |
5b1aaf6c JM |
556 | con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) |
557 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
558 | params['auth_server_port'] = "1814" | |
559 | hostapd.add_ap(apdev[0]['ifname'], params) | |
560 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
561 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") | |
562 | ||
563 | logger.info("AKA fast re-authentication") | |
564 | eap_reauth(dev[0], "AKA") | |
565 | ||
566 | logger.info("AKA full auth with pseudonym") | |
567 | with con: | |
568 | cur = con.cursor() | |
569 | cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'") | |
570 | eap_reauth(dev[0], "AKA") | |
571 | ||
572 | logger.info("AKA full auth with permanent identity") | |
573 | with con: | |
574 | cur = con.cursor() | |
575 | cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'") | |
576 | cur.execute("DELETE FROM pseudonyms WHERE permanent='0232010000000000'") | |
577 | eap_reauth(dev[0], "AKA") | |
578 | ||
579 | logger.info("AKA reauth with mismatching MK") | |
580 | with con: | |
581 | cur = con.cursor() | |
582 | cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='0232010000000000'") | |
583 | eap_reauth(dev[0], "AKA", expect_failure=True) | |
584 | dev[0].request("REMOVE_NETWORK all") | |
585 | ||
586 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
587 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") | |
588 | with con: | |
589 | cur = con.cursor() | |
590 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'") | |
591 | eap_reauth(dev[0], "AKA") | |
592 | with con: | |
593 | cur = con.cursor() | |
594 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'") | |
595 | logger.info("AKA reauth with mismatching counter") | |
596 | eap_reauth(dev[0], "AKA") | |
597 | dev[0].request("REMOVE_NETWORK all") | |
598 | ||
599 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
600 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") | |
601 | with con: | |
602 | cur = con.cursor() | |
603 | cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='0232010000000000'") | |
604 | logger.info("AKA reauth with max reauth count reached") | |
605 | eap_reauth(dev[0], "AKA") | |
606 | ||
e2a90a4c JM |
607 | def test_ap_wpa2_eap_aka_config(dev, apdev): |
608 | """EAP-AKA configuration options""" | |
609 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
610 | hostapd.add_ap(apdev[0]['ifname'], params) | |
611 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
612 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
613 | anonymous_identity="2345678") | |
614 | ||
d314bedf JM |
615 | def test_ap_wpa2_eap_aka_ext(dev, apdev): |
616 | """WPA2-Enterprise connection using EAP-AKA and external UMTS auth""" | |
47dcb118 | 617 | try: |
81e787b7 | 618 | _test_ap_wpa2_eap_aka_ext(dev, apdev) |
47dcb118 JM |
619 | finally: |
620 | dev[0].request("SET external_sim 0") | |
621 | ||
622 | def _test_ap_wpa2_eap_aka_ext(dev, apdev): | |
81e787b7 | 623 | check_hlr_auc_gw_support() |
d314bedf JM |
624 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
625 | hostapd.add_ap(apdev[0]['ifname'], params) | |
626 | dev[0].request("SET external_sim 1") | |
627 | id = dev[0].connect("test-wpa2-eap", eap="AKA", key_mgmt="WPA-EAP", | |
628 | identity="0232010000000000", | |
629 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
630 | wait_connect=False, scan_freq="2412") | |
631 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) | |
632 | if ev is None: | |
633 | raise Exception("Network connected timed out") | |
634 | ||
635 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
636 | if ev is None: | |
637 | raise Exception("Wait for external SIM processing request timed out") | |
638 | p = ev.split(':', 2) | |
639 | if p[1] != "UMTS-AUTH": | |
640 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
641 | rid = p[0].split('-')[3] | |
642 | ||
643 | # IK:CK:RES | |
644 | resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344" | |
645 | # This will fail during processing, but the ctrl_iface command succeeds | |
646 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
647 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
648 | if ev is None: | |
649 | raise Exception("EAP failure not reported") | |
650 | dev[0].request("DISCONNECT") | |
584e4197 | 651 | dev[0].wait_disconnected() |
90ad11e6 | 652 | time.sleep(0.1) |
a359c7bb | 653 | dev[0].dump_monitor() |
d314bedf | 654 | |
d8e02214 JM |
655 | dev[0].select_network(id, freq="2412") |
656 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
657 | if ev is None: | |
658 | raise Exception("Wait for external SIM processing request timed out") | |
659 | p = ev.split(':', 2) | |
660 | if p[1] != "UMTS-AUTH": | |
661 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
662 | rid = p[0].split('-')[3] | |
663 | # This will fail during UMTS auth validation | |
664 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:112233445566778899aabbccddee"): | |
665 | raise Exception("CTRL-RSP-SIM failed") | |
666 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
667 | if ev is None: | |
668 | raise Exception("Wait for external SIM processing request timed out") | |
669 | p = ev.split(':', 2) | |
670 | if p[1] != "UMTS-AUTH": | |
671 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
672 | rid = p[0].split('-')[3] | |
673 | # This will fail during UMTS auth validation | |
674 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:12"): | |
675 | raise Exception("CTRL-RSP-SIM failed") | |
676 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
677 | if ev is None: | |
678 | raise Exception("EAP failure not reported") | |
679 | dev[0].request("DISCONNECT") | |
584e4197 | 680 | dev[0].wait_disconnected() |
90ad11e6 | 681 | time.sleep(0.1) |
a359c7bb | 682 | dev[0].dump_monitor() |
d8e02214 | 683 | |
0258cf10 JM |
684 | tests = [ ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344", |
685 | ":UMTS-AUTH:34", | |
686 | ":UMTS-AUTH:00112233445566778899aabbccddeeff.00112233445566778899aabbccddeeff:0011223344", | |
687 | ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddee:0011223344", | |
688 | ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff.0011223344", | |
689 | ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff0011223344", | |
690 | ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:001122334q" ] | |
691 | for t in tests: | |
692 | dev[0].select_network(id, freq="2412") | |
693 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
694 | if ev is None: | |
695 | raise Exception("Wait for external SIM processing request timed out") | |
696 | p = ev.split(':', 2) | |
697 | if p[1] != "UMTS-AUTH": | |
698 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
699 | rid = p[0].split('-')[3] | |
700 | # This will fail during UMTS auth validation | |
701 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + t): | |
702 | raise Exception("CTRL-RSP-SIM failed") | |
703 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
704 | if ev is None: | |
705 | raise Exception("EAP failure not reported") | |
706 | dev[0].request("DISCONNECT") | |
707 | dev[0].wait_disconnected() | |
90ad11e6 | 708 | time.sleep(0.1) |
a359c7bb | 709 | dev[0].dump_monitor() |
d314bedf | 710 | |
9626962d JM |
711 | def test_ap_wpa2_eap_aka_prime(dev, apdev): |
712 | """WPA2-Enterprise connection using EAP-AKA'""" | |
81e787b7 | 713 | check_hlr_auc_gw_support() |
9626962d | 714 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 715 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 716 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", |
9626962d | 717 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") |
a8375c94 | 718 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 719 | eap_reauth(dev[0], "AKA'") |
9626962d | 720 | |
8583d664 JM |
721 | logger.info("EAP-AKA' bidding protection when EAP-AKA enabled as well") |
722 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="AKA' AKA", | |
723 | identity="6555444333222111@both", | |
724 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
725 | wait_connect=False, scan_freq="2412") | |
5f35a5e2 | 726 | dev[1].wait_connected(timeout=15) |
8583d664 | 727 | |
f10ba3b2 JM |
728 | logger.info("Negative test with incorrect key") |
729 | dev[0].request("REMOVE_NETWORK all") | |
730 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
731 | password="ff22250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
732 | expect_failure=True) | |
733 | ||
5b1aaf6c JM |
734 | def test_ap_wpa2_eap_aka_prime_sql(dev, apdev, params): |
735 | """WPA2-Enterprise connection using EAP-AKA' (SQL)""" | |
81e787b7 | 736 | check_hlr_auc_gw_support() |
5b1aaf6c JM |
737 | try: |
738 | import sqlite3 | |
739 | except ImportError: | |
81e787b7 | 740 | raise HwsimSkip("No sqlite3 module available") |
5b1aaf6c JM |
741 | con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) |
742 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
743 | params['auth_server_port'] = "1814" | |
744 | hostapd.add_ap(apdev[0]['ifname'], params) | |
745 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
746 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") | |
747 | ||
748 | logger.info("AKA' fast re-authentication") | |
749 | eap_reauth(dev[0], "AKA'") | |
750 | ||
751 | logger.info("AKA' full auth with pseudonym") | |
752 | with con: | |
753 | cur = con.cursor() | |
754 | cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'") | |
755 | eap_reauth(dev[0], "AKA'") | |
756 | ||
757 | logger.info("AKA' full auth with permanent identity") | |
758 | with con: | |
759 | cur = con.cursor() | |
760 | cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'") | |
761 | cur.execute("DELETE FROM pseudonyms WHERE permanent='6555444333222111'") | |
762 | eap_reauth(dev[0], "AKA'") | |
763 | ||
764 | logger.info("AKA' reauth with mismatching k_aut") | |
765 | with con: | |
766 | cur = con.cursor() | |
767 | cur.execute("UPDATE reauth SET k_aut='0000000000000000000000000000000000000000000000000000000000000000' WHERE permanent='6555444333222111'") | |
768 | eap_reauth(dev[0], "AKA'", expect_failure=True) | |
769 | dev[0].request("REMOVE_NETWORK all") | |
770 | ||
771 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
772 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") | |
773 | with con: | |
774 | cur = con.cursor() | |
775 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'") | |
776 | eap_reauth(dev[0], "AKA'") | |
777 | with con: | |
778 | cur = con.cursor() | |
779 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'") | |
780 | logger.info("AKA' reauth with mismatching counter") | |
781 | eap_reauth(dev[0], "AKA'") | |
782 | dev[0].request("REMOVE_NETWORK all") | |
783 | ||
784 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
785 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") | |
786 | with con: | |
787 | cur = con.cursor() | |
788 | cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='6555444333222111'") | |
789 | logger.info("AKA' reauth with max reauth count reached") | |
790 | eap_reauth(dev[0], "AKA'") | |
791 | ||
9626962d JM |
792 | def test_ap_wpa2_eap_ttls_pap(dev, apdev): |
793 | """WPA2-Enterprise connection using EAP-TTLS/PAP""" | |
794 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
65038313 JM |
795 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
796 | key_mgmt = hapd.get_config()['key_mgmt'] | |
797 | if key_mgmt.split(' ')[0] != "WPA-EAP": | |
798 | raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt) | |
cb33ee14 | 799 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
9626962d | 800 | anonymous_identity="ttls", password="password", |
506b2f05 | 801 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") |
a8375c94 | 802 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 803 | eap_reauth(dev[0], "TTLS") |
eaf3f9b1 JM |
804 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-1"), |
805 | ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-1") ]) | |
9626962d | 806 | |
506b2f05 JM |
807 | def test_ap_wpa2_eap_ttls_pap_subject_match(dev, apdev): |
808 | """WPA2-Enterprise connection using EAP-TTLS/PAP and (alt)subject_match""" | |
809 | check_subject_match_support(dev[0]) | |
810 | check_altsubject_match_support(dev[0]) | |
811 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
812 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
813 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
814 | anonymous_identity="ttls", password="password", | |
815 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
816 | subject_match="/C=FI/O=w1.fi/CN=server.w1.fi", | |
817 | altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/") | |
818 | eap_reauth(dev[0], "TTLS") | |
819 | ||
82a8f5b5 JM |
820 | def test_ap_wpa2_eap_ttls_pap_incorrect_password(dev, apdev): |
821 | """WPA2-Enterprise connection using EAP-TTLS/PAP - incorrect password""" | |
822 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
823 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
824 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
825 | anonymous_identity="ttls", password="wrong", | |
826 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
827 | expect_failure=True) | |
828 | eap_connect(dev[1], apdev[0], "TTLS", "user", | |
829 | anonymous_identity="ttls", password="password", | |
830 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
831 | expect_failure=True) | |
832 | ||
9626962d JM |
833 | def test_ap_wpa2_eap_ttls_chap(dev, apdev): |
834 | """WPA2-Enterprise connection using EAP-TTLS/CHAP""" | |
ca158ea6 | 835 | skip_with_fips(dev[0]) |
9626962d | 836 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 837 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
506b2f05 JM |
838 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", |
839 | anonymous_identity="ttls", password="password", | |
840 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP") | |
841 | hwsim_utils.test_connectivity(dev[0], hapd) | |
842 | eap_reauth(dev[0], "TTLS") | |
843 | ||
844 | def test_ap_wpa2_eap_ttls_chap_altsubject_match(dev, apdev): | |
845 | """WPA2-Enterprise connection using EAP-TTLS/CHAP""" | |
ca158ea6 | 846 | skip_with_fips(dev[0]) |
506b2f05 JM |
847 | check_altsubject_match_support(dev[0]) |
848 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
849 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 850 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", |
9626962d | 851 | anonymous_identity="ttls", password="password", |
5c65e277 JM |
852 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP", |
853 | altsubject_match="EMAIL:noone@example.com;URI:http://example.com/;DNS:server.w1.fi") | |
75b2b9cf | 854 | eap_reauth(dev[0], "TTLS") |
9626962d | 855 | |
82a8f5b5 JM |
856 | def test_ap_wpa2_eap_ttls_chap_incorrect_password(dev, apdev): |
857 | """WPA2-Enterprise connection using EAP-TTLS/CHAP - incorrect password""" | |
ca158ea6 | 858 | skip_with_fips(dev[0]) |
82a8f5b5 JM |
859 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
860 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
861 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", | |
862 | anonymous_identity="ttls", password="wrong", | |
863 | ca_cert="auth_serv/ca.pem", phase2="auth=CHAP", | |
864 | expect_failure=True) | |
865 | eap_connect(dev[1], apdev[0], "TTLS", "user", | |
866 | anonymous_identity="ttls", password="password", | |
867 | ca_cert="auth_serv/ca.pem", phase2="auth=CHAP", | |
868 | expect_failure=True) | |
869 | ||
9626962d JM |
870 | def test_ap_wpa2_eap_ttls_mschap(dev, apdev): |
871 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAP""" | |
ca158ea6 | 872 | skip_with_fips(dev[0]) |
e78eb404 | 873 | check_domain_suffix_match(dev[0]) |
9626962d | 874 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 875 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 876 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", |
9626962d | 877 | anonymous_identity="ttls", password="password", |
72c052d5 JM |
878 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", |
879 | domain_suffix_match="server.w1.fi") | |
a8375c94 | 880 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 881 | eap_reauth(dev[0], "TTLS") |
6daf5b9c JM |
882 | dev[0].request("REMOVE_NETWORK all") |
883 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", | |
884 | anonymous_identity="ttls", password="password", | |
885 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
886 | fragment_size="200") | |
bfdb90d4 JM |
887 | dev[0].request("REMOVE_NETWORK all") |
888 | dev[0].wait_disconnected() | |
889 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", | |
890 | anonymous_identity="ttls", | |
891 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
892 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP") | |
9626962d | 893 | |
82a8f5b5 | 894 | def test_ap_wpa2_eap_ttls_mschap_incorrect_password(dev, apdev): |
ca158ea6 JM |
895 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAP - incorrect password""" |
896 | skip_with_fips(dev[0]) | |
82a8f5b5 JM |
897 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
898 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
899 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", | |
900 | anonymous_identity="ttls", password="wrong", | |
901 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
902 | expect_failure=True) | |
903 | eap_connect(dev[1], apdev[0], "TTLS", "user", | |
904 | anonymous_identity="ttls", password="password", | |
905 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
906 | expect_failure=True) | |
907 | eap_connect(dev[2], apdev[0], "TTLS", "no such user", | |
908 | anonymous_identity="ttls", password="password", | |
909 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
910 | expect_failure=True) | |
911 | ||
9626962d JM |
912 | def test_ap_wpa2_eap_ttls_mschapv2(dev, apdev): |
913 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2""" | |
e78eb404 | 914 | check_domain_suffix_match(dev[0]) |
ca158ea6 | 915 | check_eap_capa(dev[0], "MSCHAPV2") |
9626962d JM |
916 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
917 | hostapd.add_ap(apdev[0]['ifname'], params) | |
5dec879d | 918 | hapd = hostapd.Hostapd(apdev[0]['ifname']) |
cb33ee14 | 919 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", |
9626962d | 920 | anonymous_identity="ttls", password="password", |
72c052d5 | 921 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", |
24579e70 | 922 | domain_suffix_match="server.w1.fi") |
a8375c94 | 923 | hwsim_utils.test_connectivity(dev[0], hapd) |
5dec879d JM |
924 | sta1 = hapd.get_sta(dev[0].p2p_interface_addr()) |
925 | eapol1 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol") | |
75b2b9cf | 926 | eap_reauth(dev[0], "TTLS") |
5dec879d JM |
927 | sta2 = hapd.get_sta(dev[0].p2p_interface_addr()) |
928 | eapol2 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol") | |
929 | if int(sta2['dot1xAuthEapolFramesRx']) <= int(sta1['dot1xAuthEapolFramesRx']): | |
930 | raise Exception("dot1xAuthEapolFramesRx did not increase") | |
931 | if int(eapol2['authAuthEapStartsWhileAuthenticated']) < 1: | |
932 | raise Exception("authAuthEapStartsWhileAuthenticated did not increase") | |
933 | if int(eapol2['backendAuthSuccesses']) <= int(eapol1['backendAuthSuccesses']): | |
934 | raise Exception("backendAuthSuccesses did not increase") | |
9626962d | 935 | |
fa0ddb14 JM |
936 | logger.info("Password as hash value") |
937 | dev[0].request("REMOVE_NETWORK all") | |
938 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
939 | anonymous_identity="ttls", | |
940 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
941 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
942 | ||
c4e06b9b JM |
943 | def test_ap_wpa2_eap_ttls_invalid_phase2(dev, apdev): |
944 | """EAP-TTLS with invalid phase2 parameter values""" | |
945 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
946 | hostapd.add_ap(apdev[0]['ifname'], params) | |
947 | tests = [ "auth=MSCHAPv2", "auth=MSCHAPV2 autheap=MD5", | |
948 | "autheap=MD5 auth=MSCHAPV2", "auth=PAP auth=CHAP" ] | |
949 | for t in tests: | |
950 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
951 | identity="DOMAIN\mschapv2 user", | |
952 | anonymous_identity="ttls", password="password", | |
953 | ca_cert="auth_serv/ca.pem", phase2=t, | |
954 | wait_connect=False, scan_freq="2412") | |
955 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=10) | |
956 | if ev is None or "method=21" not in ev: | |
957 | raise Exception("EAP-TTLS not started") | |
958 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method", | |
959 | "CTRL-EVENT-CONNECTED"], timeout=5) | |
960 | if ev is None or "CTRL-EVENT-CONNECTED" in ev: | |
961 | raise Exception("No EAP-TTLS failure reported for phase2=" + t) | |
962 | dev[0].request("REMOVE_NETWORK all") | |
963 | dev[0].wait_disconnected() | |
964 | dev[0].dump_monitor() | |
965 | ||
24579e70 JM |
966 | def test_ap_wpa2_eap_ttls_mschapv2_suffix_match(dev, apdev): |
967 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2""" | |
968 | check_domain_match_full(dev[0]) | |
ca158ea6 | 969 | skip_with_fips(dev[0]) |
24579e70 JM |
970 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
971 | hostapd.add_ap(apdev[0]['ifname'], params) | |
972 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
973 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
974 | anonymous_identity="ttls", password="password", | |
975 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
976 | domain_suffix_match="w1.fi") | |
977 | hwsim_utils.test_connectivity(dev[0], hapd) | |
978 | eap_reauth(dev[0], "TTLS") | |
979 | ||
061cbb25 JM |
980 | def test_ap_wpa2_eap_ttls_mschapv2_domain_match(dev, apdev): |
981 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 (domain_match)""" | |
e78eb404 | 982 | check_domain_match(dev[0]) |
ca158ea6 | 983 | skip_with_fips(dev[0]) |
061cbb25 JM |
984 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
985 | hostapd.add_ap(apdev[0]['ifname'], params) | |
986 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
987 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
988 | anonymous_identity="ttls", password="password", | |
989 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
990 | domain_match="Server.w1.fi") | |
991 | hwsim_utils.test_connectivity(dev[0], hapd) | |
992 | eap_reauth(dev[0], "TTLS") | |
993 | ||
82a8f5b5 JM |
994 | def test_ap_wpa2_eap_ttls_mschapv2_incorrect_password(dev, apdev): |
995 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 - incorrect password""" | |
ca158ea6 | 996 | skip_with_fips(dev[0]) |
82a8f5b5 JM |
997 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
998 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
f10ba3b2 JM |
999 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", |
1000 | anonymous_identity="ttls", password="password1", | |
1001 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1002 | expect_failure=True) | |
82a8f5b5 JM |
1003 | eap_connect(dev[1], apdev[0], "TTLS", "user", |
1004 | anonymous_identity="ttls", password="password", | |
1005 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1006 | expect_failure=True) | |
f10ba3b2 | 1007 | |
eac67440 JM |
1008 | def test_ap_wpa2_eap_ttls_mschapv2_utf8(dev, apdev): |
1009 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 and UTF-8 password""" | |
ca158ea6 | 1010 | skip_with_fips(dev[0]) |
eac67440 JM |
1011 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1012 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1013 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1014 | eap_connect(dev[0], apdev[0], "TTLS", "utf8-user-hash", | |
1015 | anonymous_identity="ttls", password="secret-åäö-€-password", | |
1016 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
1017 | eap_connect(dev[1], apdev[0], "TTLS", "utf8-user", | |
1018 | anonymous_identity="ttls", | |
1019 | password_hex="hash:bd5844fad2489992da7fe8c5a01559cf", | |
1020 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
0d2a7bad JM |
1021 | for p in [ "80", "41c041e04141e041", 257*"41" ]: |
1022 | dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", | |
1023 | eap="TTLS", identity="utf8-user-hash", | |
1024 | anonymous_identity="ttls", password_hex=p, | |
1025 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1026 | wait_connect=False, scan_freq="2412") | |
1027 | ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=1) | |
1028 | if ev is None: | |
1029 | raise Exception("No failure reported") | |
1030 | dev[2].request("REMOVE_NETWORK all") | |
1031 | dev[2].wait_disconnected() | |
eac67440 | 1032 | |
9626962d JM |
1033 | def test_ap_wpa2_eap_ttls_eap_gtc(dev, apdev): |
1034 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC""" | |
1035 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
a8375c94 | 1036 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 1037 | eap_connect(dev[0], apdev[0], "TTLS", "user", |
9626962d JM |
1038 | anonymous_identity="ttls", password="password", |
1039 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC") | |
a8375c94 | 1040 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1041 | eap_reauth(dev[0], "TTLS") |
9626962d | 1042 | |
95a15d79 JM |
1043 | def test_ap_wpa2_eap_ttls_eap_gtc_incorrect_password(dev, apdev): |
1044 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC - incorrect password""" | |
1045 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1046 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1047 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
1048 | anonymous_identity="ttls", password="wrong", | |
1049 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC", | |
1050 | expect_failure=True) | |
1051 | ||
1052 | def test_ap_wpa2_eap_ttls_eap_gtc_no_password(dev, apdev): | |
1053 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC - no password""" | |
1054 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1055 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1056 | eap_connect(dev[0], apdev[0], "TTLS", "user-no-passwd", | |
1057 | anonymous_identity="ttls", password="password", | |
1058 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC", | |
1059 | expect_failure=True) | |
1060 | ||
1061 | def test_ap_wpa2_eap_ttls_eap_gtc_server_oom(dev, apdev): | |
1062 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC - server OOM""" | |
1063 | params = int_eap_server_params() | |
1064 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1065 | with alloc_fail(hapd, 1, "eap_gtc_init"): | |
1066 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
1067 | anonymous_identity="ttls", password="password", | |
1068 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC", | |
1069 | expect_failure=True) | |
1070 | dev[0].request("REMOVE_NETWORK all") | |
1071 | ||
1072 | with alloc_fail(hapd, 1, "eap_gtc_buildReq"): | |
1073 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1074 | eap="TTLS", identity="user", | |
1075 | anonymous_identity="ttls", password="password", | |
1076 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC", | |
1077 | wait_connect=False, scan_freq="2412") | |
1078 | # This would eventually time out, but we can stop after having reached | |
1079 | # the allocation failure. | |
1080 | for i in range(20): | |
1081 | time.sleep(0.1) | |
1082 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1083 | break | |
1084 | ||
9626962d JM |
1085 | def test_ap_wpa2_eap_ttls_eap_md5(dev, apdev): |
1086 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5""" | |
e7ac04ce | 1087 | check_eap_capa(dev[0], "MD5") |
9626962d | 1088 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 1089 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 1090 | eap_connect(dev[0], apdev[0], "TTLS", "user", |
9626962d JM |
1091 | anonymous_identity="ttls", password="password", |
1092 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5") | |
a8375c94 | 1093 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1094 | eap_reauth(dev[0], "TTLS") |
9626962d | 1095 | |
ee9533eb JM |
1096 | def test_ap_wpa2_eap_ttls_eap_md5_incorrect_password(dev, apdev): |
1097 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - incorrect password""" | |
e7ac04ce | 1098 | check_eap_capa(dev[0], "MD5") |
ee9533eb JM |
1099 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1100 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1101 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
1102 | anonymous_identity="ttls", password="wrong", | |
1103 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1104 | expect_failure=True) | |
1105 | ||
95a15d79 JM |
1106 | def test_ap_wpa2_eap_ttls_eap_md5_no_password(dev, apdev): |
1107 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - no password""" | |
e7ac04ce | 1108 | check_eap_capa(dev[0], "MD5") |
95a15d79 JM |
1109 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1110 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1111 | eap_connect(dev[0], apdev[0], "TTLS", "user-no-passwd", | |
1112 | anonymous_identity="ttls", password="password", | |
1113 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1114 | expect_failure=True) | |
1115 | ||
ee9533eb JM |
1116 | def test_ap_wpa2_eap_ttls_eap_md5_server_oom(dev, apdev): |
1117 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - server OOM""" | |
e7ac04ce | 1118 | check_eap_capa(dev[0], "MD5") |
ee9533eb JM |
1119 | params = int_eap_server_params() |
1120 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1121 | with alloc_fail(hapd, 1, "eap_md5_init"): | |
1122 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
1123 | anonymous_identity="ttls", password="password", | |
1124 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1125 | expect_failure=True) | |
1126 | dev[0].request("REMOVE_NETWORK all") | |
1127 | ||
1128 | with alloc_fail(hapd, 1, "eap_md5_buildReq"): | |
1129 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1130 | eap="TTLS", identity="user", | |
1131 | anonymous_identity="ttls", password="password", | |
1132 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1133 | wait_connect=False, scan_freq="2412") | |
1134 | # This would eventually time out, but we can stop after having reached | |
1135 | # the allocation failure. | |
1136 | for i in range(20): | |
1137 | time.sleep(0.1) | |
1138 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1139 | break | |
1140 | ||
9626962d JM |
1141 | def test_ap_wpa2_eap_ttls_eap_mschapv2(dev, apdev): |
1142 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2""" | |
e7ac04ce | 1143 | check_eap_capa(dev[0], "MSCHAPV2") |
9626962d | 1144 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 1145 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 1146 | eap_connect(dev[0], apdev[0], "TTLS", "user", |
9626962d JM |
1147 | anonymous_identity="ttls", password="password", |
1148 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2") | |
a8375c94 | 1149 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1150 | eap_reauth(dev[0], "TTLS") |
9626962d | 1151 | |
f10ba3b2 JM |
1152 | logger.info("Negative test with incorrect password") |
1153 | dev[0].request("REMOVE_NETWORK all") | |
1154 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
1155 | anonymous_identity="ttls", password="password1", | |
1156 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1157 | expect_failure=True) | |
1158 | ||
95a15d79 JM |
1159 | def test_ap_wpa2_eap_ttls_eap_mschapv2_no_password(dev, apdev): |
1160 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2 - no password""" | |
e7ac04ce | 1161 | check_eap_capa(dev[0], "MSCHAPV2") |
95a15d79 JM |
1162 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1163 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1164 | eap_connect(dev[0], apdev[0], "TTLS", "user-no-passwd", | |
1165 | anonymous_identity="ttls", password="password", | |
1166 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1167 | expect_failure=True) | |
1168 | ||
ef318402 JM |
1169 | def test_ap_wpa2_eap_ttls_eap_mschapv2_server_oom(dev, apdev): |
1170 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2 - server OOM""" | |
e7ac04ce | 1171 | check_eap_capa(dev[0], "MSCHAPV2") |
ef318402 JM |
1172 | params = int_eap_server_params() |
1173 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1174 | with alloc_fail(hapd, 1, "eap_mschapv2_init"): | |
1175 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
1176 | anonymous_identity="ttls", password="password", | |
1177 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1178 | expect_failure=True) | |
1179 | dev[0].request("REMOVE_NETWORK all") | |
1180 | ||
1181 | with alloc_fail(hapd, 1, "eap_mschapv2_build_challenge"): | |
1182 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1183 | eap="TTLS", identity="user", | |
1184 | anonymous_identity="ttls", password="password", | |
1185 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1186 | wait_connect=False, scan_freq="2412") | |
1187 | # This would eventually time out, but we can stop after having reached | |
1188 | # the allocation failure. | |
1189 | for i in range(20): | |
1190 | time.sleep(0.1) | |
1191 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1192 | break | |
1193 | dev[0].request("REMOVE_NETWORK all") | |
1194 | ||
1195 | with alloc_fail(hapd, 1, "eap_mschapv2_build_success_req"): | |
1196 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1197 | eap="TTLS", identity="user", | |
1198 | anonymous_identity="ttls", password="password", | |
1199 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1200 | wait_connect=False, scan_freq="2412") | |
1201 | # This would eventually time out, but we can stop after having reached | |
1202 | # the allocation failure. | |
1203 | for i in range(20): | |
1204 | time.sleep(0.1) | |
1205 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1206 | break | |
1207 | dev[0].request("REMOVE_NETWORK all") | |
1208 | ||
1209 | with alloc_fail(hapd, 1, "eap_mschapv2_build_failure_req"): | |
1210 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1211 | eap="TTLS", identity="user", | |
1212 | anonymous_identity="ttls", password="wrong", | |
1213 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1214 | wait_connect=False, scan_freq="2412") | |
1215 | # This would eventually time out, but we can stop after having reached | |
1216 | # the allocation failure. | |
1217 | for i in range(20): | |
1218 | time.sleep(0.1) | |
1219 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1220 | break | |
1221 | dev[0].request("REMOVE_NETWORK all") | |
1222 | ||
95fb531c JM |
1223 | def test_ap_wpa2_eap_ttls_eap_aka(dev, apdev): |
1224 | """WPA2-Enterprise connection using EAP-TTLS/EAP-AKA""" | |
1225 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1226 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1227 | eap_connect(dev[0], apdev[0], "TTLS", "0232010000000000", | |
1228 | anonymous_identity="0232010000000000@ttls", | |
1229 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1230 | ca_cert="auth_serv/ca.pem", phase2="autheap=AKA") | |
1231 | ||
1232 | def test_ap_wpa2_eap_peap_eap_aka(dev, apdev): | |
1233 | """WPA2-Enterprise connection using EAP-PEAP/EAP-AKA""" | |
1234 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1235 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1236 | eap_connect(dev[0], apdev[0], "PEAP", "0232010000000000", | |
1237 | anonymous_identity="0232010000000000@peap", | |
1238 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1239 | ca_cert="auth_serv/ca.pem", phase2="auth=AKA") | |
1240 | ||
1241 | def test_ap_wpa2_eap_fast_eap_aka(dev, apdev): | |
1242 | """WPA2-Enterprise connection using EAP-FAST/EAP-AKA""" | |
3b51cc63 | 1243 | check_eap_capa(dev[0], "FAST") |
95fb531c JM |
1244 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1245 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1246 | eap_connect(dev[0], apdev[0], "FAST", "0232010000000000", | |
1247 | anonymous_identity="0232010000000000@fast", | |
1248 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1249 | phase1="fast_provisioning=2", | |
1250 | pac_file="blob://fast_pac_auth_aka", | |
1251 | ca_cert="auth_serv/ca.pem", phase2="auth=AKA") | |
1252 | ||
9626962d JM |
1253 | def test_ap_wpa2_eap_peap_eap_mschapv2(dev, apdev): |
1254 | """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2""" | |
e7ac04ce | 1255 | check_eap_capa(dev[0], "MSCHAPV2") |
9626962d | 1256 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 1257 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 1258 | eap_connect(dev[0], apdev[0], "PEAP", "user", |
698f8324 | 1259 | anonymous_identity="peap", password="password", |
9626962d | 1260 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") |
a8375c94 | 1261 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1262 | eap_reauth(dev[0], "PEAP") |
6daf5b9c JM |
1263 | dev[0].request("REMOVE_NETWORK all") |
1264 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
1265 | anonymous_identity="peap", password="password", | |
1266 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1267 | fragment_size="200") | |
c7afc078 | 1268 | |
fa0ddb14 JM |
1269 | logger.info("Password as hash value") |
1270 | dev[0].request("REMOVE_NETWORK all") | |
1271 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
1272 | anonymous_identity="peap", | |
1273 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
1274 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
1275 | ||
f10ba3b2 JM |
1276 | logger.info("Negative test with incorrect password") |
1277 | dev[0].request("REMOVE_NETWORK all") | |
1278 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
1279 | anonymous_identity="peap", password="password1", | |
1280 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1281 | expect_failure=True) | |
1282 | ||
0d33f504 JM |
1283 | def test_ap_wpa2_eap_peap_eap_mschapv2_domain(dev, apdev): |
1284 | """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2 with domain""" | |
e7ac04ce | 1285 | check_eap_capa(dev[0], "MSCHAPV2") |
0d33f504 JM |
1286 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1287 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1288 | eap_connect(dev[0], apdev[0], "PEAP", "DOMAIN\user3", | |
1289 | anonymous_identity="peap", password="password", | |
1290 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
1291 | hwsim_utils.test_connectivity(dev[0], hapd) | |
1292 | eap_reauth(dev[0], "PEAP") | |
1293 | ||
f4cd0f64 JM |
1294 | def test_ap_wpa2_eap_peap_eap_mschapv2_incorrect_password(dev, apdev): |
1295 | """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2 - incorrect password""" | |
e7ac04ce | 1296 | check_eap_capa(dev[0], "MSCHAPV2") |
f4cd0f64 JM |
1297 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1298 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1299 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
1300 | anonymous_identity="peap", password="wrong", | |
1301 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1302 | expect_failure=True) | |
1303 | ||
698f8324 JM |
1304 | def test_ap_wpa2_eap_peap_crypto_binding(dev, apdev): |
1305 | """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding""" | |
e7ac04ce | 1306 | check_eap_capa(dev[0], "MSCHAPV2") |
698f8324 | 1307 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 1308 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 1309 | eap_connect(dev[0], apdev[0], "PEAP", "user", password="password", |
698f8324 JM |
1310 | ca_cert="auth_serv/ca.pem", |
1311 | phase1="peapver=0 crypto_binding=2", | |
1312 | phase2="auth=MSCHAPV2") | |
a8375c94 | 1313 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1314 | eap_reauth(dev[0], "PEAP") |
698f8324 | 1315 | |
ea6464b0 JM |
1316 | eap_connect(dev[1], apdev[0], "PEAP", "user", password="password", |
1317 | ca_cert="auth_serv/ca.pem", | |
1318 | phase1="peapver=0 crypto_binding=1", | |
1319 | phase2="auth=MSCHAPV2") | |
1320 | eap_connect(dev[2], apdev[0], "PEAP", "user", password="password", | |
1321 | ca_cert="auth_serv/ca.pem", | |
1322 | phase1="peapver=0 crypto_binding=0", | |
1323 | phase2="auth=MSCHAPV2") | |
1324 | ||
ef318402 JM |
1325 | def test_ap_wpa2_eap_peap_crypto_binding_server_oom(dev, apdev): |
1326 | """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding with server OOM""" | |
e7ac04ce | 1327 | check_eap_capa(dev[0], "MSCHAPV2") |
ef318402 JM |
1328 | params = int_eap_server_params() |
1329 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1330 | with alloc_fail(hapd, 1, "eap_mschapv2_getKey"): | |
1331 | eap_connect(dev[0], apdev[0], "PEAP", "user", password="password", | |
1332 | ca_cert="auth_serv/ca.pem", | |
1333 | phase1="peapver=0 crypto_binding=2", | |
1334 | phase2="auth=MSCHAPV2", | |
1335 | expect_failure=True, local_error_report=True) | |
1336 | ||
c4d37011 JM |
1337 | def test_ap_wpa2_eap_peap_params(dev, apdev): |
1338 | """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and various parameters""" | |
e7ac04ce | 1339 | check_eap_capa(dev[0], "MSCHAPV2") |
c4d37011 JM |
1340 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1341 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1342 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
1343 | anonymous_identity="peap", password="password", | |
1344 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1345 | phase1="peapver=0 peaplabel=1", | |
1346 | expect_failure=True) | |
1347 | dev[0].request("REMOVE_NETWORK all") | |
09ad98c5 JM |
1348 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", |
1349 | identity="user", | |
1350 | anonymous_identity="peap", password="password", | |
1351 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1352 | phase1="peap_outer_success=0", | |
1353 | wait_connect=False, scan_freq="2412") | |
1354 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) | |
1355 | if ev is None: | |
1356 | raise Exception("No EAP success seen") | |
1357 | # This won't succeed to connect with peap_outer_success=0, so stop here. | |
1358 | dev[0].request("REMOVE_NETWORK all") | |
1359 | dev[0].wait_disconnected() | |
c4d37011 JM |
1360 | eap_connect(dev[1], apdev[0], "PEAP", "user", password="password", |
1361 | ca_cert="auth_serv/ca.pem", | |
1362 | phase1="peap_outer_success=1", | |
1363 | phase2="auth=MSCHAPV2") | |
1364 | eap_connect(dev[2], apdev[0], "PEAP", "user", password="password", | |
1365 | ca_cert="auth_serv/ca.pem", | |
1366 | phase1="peap_outer_success=2", | |
1367 | phase2="auth=MSCHAPV2") | |
1368 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
1369 | identity="user", | |
1370 | anonymous_identity="peap", password="password", | |
1371 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1372 | phase1="peapver=1 peaplabel=1", | |
1373 | wait_connect=False, scan_freq="2412") | |
1374 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) | |
1375 | if ev is None: | |
1376 | raise Exception("No EAP success seen") | |
1377 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1) | |
1378 | if ev is not None: | |
1379 | raise Exception("Unexpected connection") | |
1380 | ||
09a4404a JM |
1381 | tests = [ ("peap-ver0", ""), |
1382 | ("peap-ver1", ""), | |
1383 | ("peap-ver0", "peapver=0"), | |
1384 | ("peap-ver1", "peapver=1") ] | |
1385 | for anon,phase1 in tests: | |
1386 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
1387 | identity="user", anonymous_identity=anon, | |
1388 | password="password", phase1=phase1, | |
1389 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1390 | scan_freq="2412") | |
1391 | dev[0].request("REMOVE_NETWORK all") | |
1392 | dev[0].wait_disconnected() | |
1393 | ||
1394 | tests = [ ("peap-ver0", "peapver=1"), | |
1395 | ("peap-ver1", "peapver=0") ] | |
1396 | for anon,phase1 in tests: | |
1397 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
1398 | identity="user", anonymous_identity=anon, | |
1399 | password="password", phase1=phase1, | |
1400 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1401 | wait_connect=False, scan_freq="2412") | |
1402 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
1403 | if ev is None: | |
1404 | raise Exception("No EAP-Failure seen") | |
1405 | dev[0].request("REMOVE_NETWORK all") | |
1406 | dev[0].wait_disconnected() | |
1407 | ||
d0ce1050 JM |
1408 | def test_ap_wpa2_eap_peap_eap_tls(dev, apdev): |
1409 | """WPA2-Enterprise connection using EAP-PEAP/EAP-TLS""" | |
1410 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1411 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1412 | eap_connect(dev[0], apdev[0], "PEAP", "cert user", | |
1413 | ca_cert="auth_serv/ca.pem", phase2="auth=TLS", | |
1414 | ca_cert2="auth_serv/ca.pem", | |
1415 | client_cert2="auth_serv/user.pem", | |
1416 | private_key2="auth_serv/user.key") | |
1417 | eap_reauth(dev[0], "PEAP") | |
1418 | ||
e114c49c JM |
1419 | def test_ap_wpa2_eap_tls(dev, apdev): |
1420 | """WPA2-Enterprise connection using EAP-TLS""" | |
1421 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1422 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 1423 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
e114c49c JM |
1424 | client_cert="auth_serv/user.pem", |
1425 | private_key="auth_serv/user.key") | |
75b2b9cf | 1426 | eap_reauth(dev[0], "TLS") |
e114c49c | 1427 | |
96bf8fe1 JM |
1428 | def test_eap_tls_pkcs8_pkcs5_v2_des3(dev, apdev): |
1429 | """WPA2-Enterprise connection using EAP-TLS and PKCS #8, PKCS #5 v2 DES3 key""" | |
1430 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1431 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1432 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
1433 | client_cert="auth_serv/user.pem", | |
1434 | private_key="auth_serv/user.key.pkcs8", | |
1435 | private_key_passwd="whatever") | |
1436 | ||
1437 | def test_eap_tls_pkcs8_pkcs5_v15(dev, apdev): | |
1438 | """WPA2-Enterprise connection using EAP-TLS and PKCS #8, PKCS #5 v1.5 key""" | |
1439 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1440 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1441 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
1442 | client_cert="auth_serv/user.pem", | |
1443 | private_key="auth_serv/user.key.pkcs8.pkcs5v15", | |
1444 | private_key_passwd="whatever") | |
1445 | ||
6ea231e6 JM |
1446 | def test_ap_wpa2_eap_tls_blob(dev, apdev): |
1447 | """WPA2-Enterprise connection using EAP-TLS and config blobs""" | |
1448 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1449 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1450 | cert = read_pem("auth_serv/ca.pem") | |
1451 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
1452 | raise Exception("Could not set cacert blob") | |
1453 | cert = read_pem("auth_serv/user.pem") | |
1454 | if "OK" not in dev[0].request("SET blob usercert " + cert.encode("hex")): | |
1455 | raise Exception("Could not set usercert blob") | |
62750c3e | 1456 | key = read_pem("auth_serv/user.rsa-key") |
6ea231e6 JM |
1457 | if "OK" not in dev[0].request("SET blob userkey " + key.encode("hex")): |
1458 | raise Exception("Could not set cacert blob") | |
1459 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="blob://cacert", | |
1460 | client_cert="blob://usercert", | |
1461 | private_key="blob://userkey") | |
1462 | ||
cef42a44 JM |
1463 | def test_ap_wpa2_eap_tls_blob_missing(dev, apdev): |
1464 | """EAP-TLS and config blob missing""" | |
1465 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1466 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1467 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
1468 | identity="tls user", | |
1469 | ca_cert="blob://testing-blob-does-not-exist", | |
1470 | client_cert="blob://testing-blob-does-not-exist", | |
1471 | private_key="blob://testing-blob-does-not-exist", | |
1472 | wait_connect=False, scan_freq="2412") | |
1473 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], timeout=10) | |
1474 | if ev is None: | |
1475 | raise Exception("EAP failure not reported") | |
1476 | dev[0].request("REMOVE_NETWORK all") | |
1477 | dev[0].wait_disconnected() | |
1478 | ||
2d10eb0e JM |
1479 | def test_ap_wpa2_eap_tls_pkcs12(dev, apdev): |
1480 | """WPA2-Enterprise connection using EAP-TLS and PKCS#12""" | |
686eee77 | 1481 | check_pkcs12_support(dev[0]) |
2d10eb0e JM |
1482 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1483 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1484 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
1485 | private_key="auth_serv/user.pkcs12", | |
1486 | private_key_passwd="whatever") | |
1487 | dev[0].request("REMOVE_NETWORK all") | |
0c83ae04 JM |
1488 | dev[0].wait_disconnected() |
1489 | ||
2d10eb0e JM |
1490 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
1491 | identity="tls user", | |
1492 | ca_cert="auth_serv/ca.pem", | |
1493 | private_key="auth_serv/user.pkcs12", | |
1494 | wait_connect=False, scan_freq="2412") | |
1495 | ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"]) | |
1496 | if ev is None: | |
1497 | raise Exception("Request for private key passphrase timed out") | |
1498 | id = ev.split(':')[0].split('-')[-1] | |
1499 | dev[0].request("CTRL-RSP-PASSPHRASE-" + id + ":whatever") | |
5f35a5e2 | 1500 | dev[0].wait_connected(timeout=10) |
0c83ae04 JM |
1501 | dev[0].request("REMOVE_NETWORK all") |
1502 | dev[0].wait_disconnected() | |
1503 | ||
6da3b745 JM |
1504 | # Run this twice to verify certificate chain handling with OpenSSL. Use two |
1505 | # different files to cover both cases of the extra certificate being the | |
1506 | # one that signed the client certificate and it being unrelated to the | |
1507 | # client certificate. | |
1508 | for pkcs12 in "auth_serv/user2.pkcs12", "auth_serv/user3.pkcs12": | |
1509 | for i in range(2): | |
1510 | eap_connect(dev[0], apdev[0], "TLS", "tls user", | |
1511 | ca_cert="auth_serv/ca.pem", | |
1512 | private_key=pkcs12, | |
1513 | private_key_passwd="whatever") | |
1514 | dev[0].request("REMOVE_NETWORK all") | |
1515 | dev[0].wait_disconnected() | |
2d10eb0e | 1516 | |
6ea231e6 JM |
1517 | def test_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev): |
1518 | """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob""" | |
686eee77 | 1519 | check_pkcs12_support(dev[0]) |
6ea231e6 JM |
1520 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1521 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1522 | cert = read_pem("auth_serv/ca.pem") | |
1523 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
1524 | raise Exception("Could not set cacert blob") | |
1525 | with open("auth_serv/user.pkcs12", "rb") as f: | |
1526 | if "OK" not in dev[0].request("SET blob pkcs12 " + f.read().encode("hex")): | |
1527 | raise Exception("Could not set pkcs12 blob") | |
1528 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="blob://cacert", | |
1529 | private_key="blob://pkcs12", | |
1530 | private_key_passwd="whatever") | |
1531 | ||
c7afc078 JM |
1532 | def test_ap_wpa2_eap_tls_neg_incorrect_trust_root(dev, apdev): |
1533 | """WPA2-Enterprise negative test - incorrect trust root""" | |
e7ac04ce | 1534 | check_eap_capa(dev[0], "MSCHAPV2") |
c7afc078 JM |
1535 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1536 | hostapd.add_ap(apdev[0]['ifname'], params) | |
6ea231e6 JM |
1537 | cert = read_pem("auth_serv/ca-incorrect.pem") |
1538 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
1539 | raise Exception("Could not set cacert blob") | |
c7afc078 | 1540 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
6ea231e6 JM |
1541 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", |
1542 | password="password", phase2="auth=MSCHAPV2", | |
1543 | ca_cert="blob://cacert", | |
1544 | wait_connect=False, scan_freq="2412") | |
1545 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
c7afc078 JM |
1546 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", |
1547 | password="password", phase2="auth=MSCHAPV2", | |
1548 | ca_cert="auth_serv/ca-incorrect.pem", | |
c65f23ab | 1549 | wait_connect=False, scan_freq="2412") |
c7afc078 | 1550 | |
6ea231e6 JM |
1551 | for dev in (dev[0], dev[1]): |
1552 | ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1553 | if ev is None: | |
1554 | raise Exception("Association and EAP start timed out") | |
c7afc078 | 1555 | |
6ea231e6 JM |
1556 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) |
1557 | if ev is None: | |
1558 | raise Exception("EAP method selection timed out") | |
1559 | if "TTLS" not in ev: | |
1560 | raise Exception("Unexpected EAP method") | |
1561 | ||
1562 | ev = dev.wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1563 | "CTRL-EVENT-EAP-SUCCESS", | |
1564 | "CTRL-EVENT-EAP-FAILURE", | |
1565 | "CTRL-EVENT-CONNECTED", | |
1566 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1567 | if ev is None: | |
1568 | raise Exception("EAP result timed out") | |
1569 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1570 | raise Exception("TLS certificate error not reported") | |
1571 | ||
1572 | ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1573 | "CTRL-EVENT-EAP-FAILURE", | |
1574 | "CTRL-EVENT-CONNECTED", | |
1575 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1576 | if ev is None: | |
1577 | raise Exception("EAP result(2) timed out") | |
1578 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1579 | raise Exception("EAP failure not reported") | |
c7afc078 | 1580 | |
6ea231e6 JM |
1581 | ev = dev.wait_event(["CTRL-EVENT-CONNECTED", |
1582 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1583 | if ev is None: | |
1584 | raise Exception("EAP result(3) timed out") | |
1585 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1586 | raise Exception("Disconnection not reported") | |
c7afc078 | 1587 | |
6ea231e6 JM |
1588 | ev = dev.wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) |
1589 | if ev is None: | |
1590 | raise Exception("Network block disabling not reported") | |
72c052d5 | 1591 | |
9a5cfd70 JM |
1592 | def test_ap_wpa2_eap_tls_diff_ca_trust(dev, apdev): |
1593 | """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust""" | |
1594 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1595 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1596 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1597 | identity="pap user", anonymous_identity="ttls", | |
1598 | password="password", phase2="auth=PAP", | |
1599 | ca_cert="auth_serv/ca.pem", | |
1600 | wait_connect=True, scan_freq="2412") | |
1601 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1602 | identity="pap user", anonymous_identity="ttls", | |
1603 | password="password", phase2="auth=PAP", | |
1604 | ca_cert="auth_serv/ca-incorrect.pem", | |
1605 | only_add_network=True, scan_freq="2412") | |
1606 | ||
1607 | dev[0].request("DISCONNECT") | |
90ad11e6 | 1608 | dev[0].wait_disconnected() |
9a5cfd70 JM |
1609 | dev[0].dump_monitor() |
1610 | dev[0].select_network(id, freq="2412") | |
1611 | ||
1612 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15) | |
1613 | if ev is None: | |
1614 | raise Exception("EAP-TTLS not re-started") | |
1615 | ||
5f35a5e2 | 1616 | ev = dev[0].wait_disconnected(timeout=15) |
9a5cfd70 JM |
1617 | if "reason=23" not in ev: |
1618 | raise Exception("Proper reason code for disconnection not reported") | |
1619 | ||
1620 | def test_ap_wpa2_eap_tls_diff_ca_trust2(dev, apdev): | |
1621 | """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust""" | |
1622 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1623 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1624 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1625 | identity="pap user", anonymous_identity="ttls", | |
1626 | password="password", phase2="auth=PAP", | |
1627 | wait_connect=True, scan_freq="2412") | |
1628 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1629 | identity="pap user", anonymous_identity="ttls", | |
1630 | password="password", phase2="auth=PAP", | |
1631 | ca_cert="auth_serv/ca-incorrect.pem", | |
1632 | only_add_network=True, scan_freq="2412") | |
1633 | ||
1634 | dev[0].request("DISCONNECT") | |
90ad11e6 | 1635 | dev[0].wait_disconnected() |
9a5cfd70 JM |
1636 | dev[0].dump_monitor() |
1637 | dev[0].select_network(id, freq="2412") | |
1638 | ||
1639 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15) | |
1640 | if ev is None: | |
1641 | raise Exception("EAP-TTLS not re-started") | |
1642 | ||
5f35a5e2 | 1643 | ev = dev[0].wait_disconnected(timeout=15) |
9a5cfd70 JM |
1644 | if "reason=23" not in ev: |
1645 | raise Exception("Proper reason code for disconnection not reported") | |
1646 | ||
1647 | def test_ap_wpa2_eap_tls_diff_ca_trust3(dev, apdev): | |
1648 | """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust""" | |
1649 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1650 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1651 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1652 | identity="pap user", anonymous_identity="ttls", | |
1653 | password="password", phase2="auth=PAP", | |
1654 | ca_cert="auth_serv/ca.pem", | |
1655 | wait_connect=True, scan_freq="2412") | |
1656 | dev[0].request("DISCONNECT") | |
90ad11e6 | 1657 | dev[0].wait_disconnected() |
9a5cfd70 JM |
1658 | dev[0].dump_monitor() |
1659 | dev[0].set_network_quoted(id, "ca_cert", "auth_serv/ca-incorrect.pem") | |
1660 | dev[0].select_network(id, freq="2412") | |
1661 | ||
1662 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15) | |
1663 | if ev is None: | |
1664 | raise Exception("EAP-TTLS not re-started") | |
1665 | ||
5f35a5e2 | 1666 | ev = dev[0].wait_disconnected(timeout=15) |
9a5cfd70 JM |
1667 | if "reason=23" not in ev: |
1668 | raise Exception("Proper reason code for disconnection not reported") | |
1669 | ||
72c052d5 JM |
1670 | def test_ap_wpa2_eap_tls_neg_suffix_match(dev, apdev): |
1671 | """WPA2-Enterprise negative test - domain suffix mismatch""" | |
e78eb404 | 1672 | check_domain_suffix_match(dev[0]) |
72c052d5 JM |
1673 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1674 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1675 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1676 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1677 | password="password", phase2="auth=MSCHAPV2", | |
1678 | ca_cert="auth_serv/ca.pem", | |
1679 | domain_suffix_match="incorrect.example.com", | |
c65f23ab | 1680 | wait_connect=False, scan_freq="2412") |
72c052d5 JM |
1681 | |
1682 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1683 | if ev is None: | |
1684 | raise Exception("Association and EAP start timed out") | |
1685 | ||
1686 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
1687 | if ev is None: | |
1688 | raise Exception("EAP method selection timed out") | |
1689 | if "TTLS" not in ev: | |
1690 | raise Exception("Unexpected EAP method") | |
1691 | ||
1692 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1693 | "CTRL-EVENT-EAP-SUCCESS", | |
1694 | "CTRL-EVENT-EAP-FAILURE", | |
1695 | "CTRL-EVENT-CONNECTED", | |
1696 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1697 | if ev is None: | |
1698 | raise Exception("EAP result timed out") | |
1699 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1700 | raise Exception("TLS certificate error not reported") | |
1701 | if "Domain suffix mismatch" not in ev: | |
1702 | raise Exception("Domain suffix mismatch not reported") | |
1703 | ||
1704 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1705 | "CTRL-EVENT-EAP-FAILURE", | |
1706 | "CTRL-EVENT-CONNECTED", | |
1707 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1708 | if ev is None: | |
1709 | raise Exception("EAP result(2) timed out") | |
1710 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1711 | raise Exception("EAP failure not reported") | |
1712 | ||
1713 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
1714 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1715 | if ev is None: | |
1716 | raise Exception("EAP result(3) timed out") | |
1717 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1718 | raise Exception("Disconnection not reported") | |
1719 | ||
1720 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
1721 | if ev is None: | |
1722 | raise Exception("Network block disabling not reported") | |
22b99086 | 1723 | |
061cbb25 JM |
1724 | def test_ap_wpa2_eap_tls_neg_domain_match(dev, apdev): |
1725 | """WPA2-Enterprise negative test - domain mismatch""" | |
e78eb404 | 1726 | check_domain_match(dev[0]) |
061cbb25 JM |
1727 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1728 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1729 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1730 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1731 | password="password", phase2="auth=MSCHAPV2", | |
1732 | ca_cert="auth_serv/ca.pem", | |
1733 | domain_match="w1.fi", | |
1734 | wait_connect=False, scan_freq="2412") | |
1735 | ||
1736 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1737 | if ev is None: | |
1738 | raise Exception("Association and EAP start timed out") | |
1739 | ||
1740 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
1741 | if ev is None: | |
1742 | raise Exception("EAP method selection timed out") | |
1743 | if "TTLS" not in ev: | |
1744 | raise Exception("Unexpected EAP method") | |
1745 | ||
1746 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1747 | "CTRL-EVENT-EAP-SUCCESS", | |
1748 | "CTRL-EVENT-EAP-FAILURE", | |
1749 | "CTRL-EVENT-CONNECTED", | |
1750 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1751 | if ev is None: | |
1752 | raise Exception("EAP result timed out") | |
1753 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1754 | raise Exception("TLS certificate error not reported") | |
1755 | if "Domain mismatch" not in ev: | |
1756 | raise Exception("Domain mismatch not reported") | |
1757 | ||
1758 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1759 | "CTRL-EVENT-EAP-FAILURE", | |
1760 | "CTRL-EVENT-CONNECTED", | |
1761 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1762 | if ev is None: | |
1763 | raise Exception("EAP result(2) timed out") | |
1764 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1765 | raise Exception("EAP failure not reported") | |
1766 | ||
1767 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
1768 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1769 | if ev is None: | |
1770 | raise Exception("EAP result(3) timed out") | |
1771 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1772 | raise Exception("Disconnection not reported") | |
1773 | ||
1774 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
1775 | if ev is None: | |
1776 | raise Exception("Network block disabling not reported") | |
1777 | ||
3b74982f JM |
1778 | def test_ap_wpa2_eap_tls_neg_subject_match(dev, apdev): |
1779 | """WPA2-Enterprise negative test - subject mismatch""" | |
1780 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1781 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1782 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1783 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1784 | password="password", phase2="auth=MSCHAPV2", | |
1785 | ca_cert="auth_serv/ca.pem", | |
1786 | subject_match="/C=FI/O=w1.fi/CN=example.com", | |
1787 | wait_connect=False, scan_freq="2412") | |
1788 | ||
1789 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1790 | if ev is None: | |
1791 | raise Exception("Association and EAP start timed out") | |
1792 | ||
506b2f05 JM |
1793 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD", |
1794 | "EAP: Failed to initialize EAP method"], timeout=10) | |
3b74982f JM |
1795 | if ev is None: |
1796 | raise Exception("EAP method selection timed out") | |
506b2f05 JM |
1797 | if "EAP: Failed to initialize EAP method" in ev: |
1798 | tls = dev[0].request("GET tls_library") | |
1799 | if tls.startswith("OpenSSL"): | |
1800 | raise Exception("Failed to select EAP method") | |
1801 | logger.info("subject_match not supported - connection failed, so test succeeded") | |
1802 | return | |
3b74982f JM |
1803 | if "TTLS" not in ev: |
1804 | raise Exception("Unexpected EAP method") | |
1805 | ||
1806 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1807 | "CTRL-EVENT-EAP-SUCCESS", | |
1808 | "CTRL-EVENT-EAP-FAILURE", | |
1809 | "CTRL-EVENT-CONNECTED", | |
1810 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1811 | if ev is None: | |
1812 | raise Exception("EAP result timed out") | |
1813 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1814 | raise Exception("TLS certificate error not reported") | |
1815 | if "Subject mismatch" not in ev: | |
1816 | raise Exception("Subject mismatch not reported") | |
1817 | ||
1818 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1819 | "CTRL-EVENT-EAP-FAILURE", | |
1820 | "CTRL-EVENT-CONNECTED", | |
1821 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1822 | if ev is None: | |
1823 | raise Exception("EAP result(2) timed out") | |
1824 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1825 | raise Exception("EAP failure not reported") | |
1826 | ||
1827 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
1828 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1829 | if ev is None: | |
1830 | raise Exception("EAP result(3) timed out") | |
1831 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1832 | raise Exception("Disconnection not reported") | |
1833 | ||
1834 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
1835 | if ev is None: | |
1836 | raise Exception("Network block disabling not reported") | |
1837 | ||
1838 | def test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev): | |
1839 | """WPA2-Enterprise negative test - altsubject mismatch""" | |
1840 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1841 | hostapd.add_ap(apdev[0]['ifname'], params) | |
37d61355 JM |
1842 | |
1843 | tests = [ "incorrect.example.com", | |
1844 | "DNS:incorrect.example.com", | |
1845 | "DNS:w1.fi", | |
1846 | "DNS:erver.w1.fi" ] | |
1847 | for match in tests: | |
1848 | _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match) | |
1849 | ||
1850 | def _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match): | |
3b74982f JM |
1851 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
1852 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1853 | password="password", phase2="auth=MSCHAPV2", | |
1854 | ca_cert="auth_serv/ca.pem", | |
37d61355 | 1855 | altsubject_match=match, |
3b74982f JM |
1856 | wait_connect=False, scan_freq="2412") |
1857 | ||
1858 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1859 | if ev is None: | |
1860 | raise Exception("Association and EAP start timed out") | |
1861 | ||
506b2f05 JM |
1862 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD", |
1863 | "EAP: Failed to initialize EAP method"], timeout=10) | |
3b74982f JM |
1864 | if ev is None: |
1865 | raise Exception("EAP method selection timed out") | |
506b2f05 JM |
1866 | if "EAP: Failed to initialize EAP method" in ev: |
1867 | tls = dev[0].request("GET tls_library") | |
1868 | if tls.startswith("OpenSSL"): | |
1869 | raise Exception("Failed to select EAP method") | |
1870 | logger.info("altsubject_match not supported - connection failed, so test succeeded") | |
1871 | return | |
3b74982f JM |
1872 | if "TTLS" not in ev: |
1873 | raise Exception("Unexpected EAP method") | |
1874 | ||
1875 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1876 | "CTRL-EVENT-EAP-SUCCESS", | |
1877 | "CTRL-EVENT-EAP-FAILURE", | |
1878 | "CTRL-EVENT-CONNECTED", | |
1879 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1880 | if ev is None: | |
1881 | raise Exception("EAP result timed out") | |
1882 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1883 | raise Exception("TLS certificate error not reported") | |
1884 | if "AltSubject mismatch" not in ev: | |
1885 | raise Exception("altsubject mismatch not reported") | |
1886 | ||
1887 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1888 | "CTRL-EVENT-EAP-FAILURE", | |
1889 | "CTRL-EVENT-CONNECTED", | |
1890 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1891 | if ev is None: | |
1892 | raise Exception("EAP result(2) timed out") | |
1893 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1894 | raise Exception("EAP failure not reported") | |
1895 | ||
1896 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
1897 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1898 | if ev is None: | |
1899 | raise Exception("EAP result(3) timed out") | |
1900 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1901 | raise Exception("Disconnection not reported") | |
1902 | ||
1903 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
1904 | if ev is None: | |
1905 | raise Exception("Network block disabling not reported") | |
1906 | ||
37d61355 JM |
1907 | dev[0].request("REMOVE_NETWORK all") |
1908 | ||
5a0c1517 JM |
1909 | def test_ap_wpa2_eap_unauth_tls(dev, apdev): |
1910 | """WPA2-Enterprise connection using UNAUTH-TLS""" | |
1911 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1912 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1913 | eap_connect(dev[0], apdev[0], "UNAUTH-TLS", "unauth-tls", | |
1914 | ca_cert="auth_serv/ca.pem") | |
1915 | eap_reauth(dev[0], "UNAUTH-TLS") | |
1916 | ||
57be05e1 JM |
1917 | def test_ap_wpa2_eap_ttls_server_cert_hash(dev, apdev): |
1918 | """WPA2-Enterprise connection using EAP-TTLS and server certificate hash""" | |
4bf4e9db | 1919 | check_cert_probe_support(dev[0]) |
ca158ea6 | 1920 | skip_with_fips(dev[0]) |
403610d3 | 1921 | srv_cert_hash = "e75bd454c7b02d312e5006d75067c28ffa5baea422effeb2bbd572179cd000ca" |
57be05e1 JM |
1922 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1923 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1924 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1925 | identity="probe", ca_cert="probe://", | |
1926 | wait_connect=False, scan_freq="2412") | |
1927 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1928 | if ev is None: | |
1929 | raise Exception("Association and EAP start timed out") | |
1930 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT depth=0"], timeout=10) | |
1931 | if ev is None: | |
1932 | raise Exception("No peer server certificate event seen") | |
1933 | if "hash=" + srv_cert_hash not in ev: | |
1934 | raise Exception("Expected server certificate hash not reported") | |
1935 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10) | |
1936 | if ev is None: | |
1937 | raise Exception("EAP result timed out") | |
1938 | if "Server certificate chain probe" not in ev: | |
1939 | raise Exception("Server certificate probe not reported") | |
5f35a5e2 | 1940 | dev[0].wait_disconnected(timeout=10) |
57be05e1 JM |
1941 | dev[0].request("REMOVE_NETWORK all") |
1942 | ||
1943 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1944 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1945 | password="password", phase2="auth=MSCHAPV2", | |
1946 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a", | |
1947 | wait_connect=False, scan_freq="2412") | |
1948 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1949 | if ev is None: | |
1950 | raise Exception("Association and EAP start timed out") | |
1951 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10) | |
1952 | if ev is None: | |
1953 | raise Exception("EAP result timed out") | |
1954 | if "Server certificate mismatch" not in ev: | |
1955 | raise Exception("Server certificate mismatch not reported") | |
5f35a5e2 | 1956 | dev[0].wait_disconnected(timeout=10) |
57be05e1 JM |
1957 | dev[0].request("REMOVE_NETWORK all") |
1958 | ||
1959 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
1960 | anonymous_identity="ttls", password="password", | |
1961 | ca_cert="hash://server/sha256/" + srv_cert_hash, | |
1962 | phase2="auth=MSCHAPV2") | |
1963 | ||
2a6a2192 JM |
1964 | def test_ap_wpa2_eap_ttls_server_cert_hash_invalid(dev, apdev): |
1965 | """WPA2-Enterprise connection using EAP-TTLS and server certificate hash (invalid config)""" | |
1966 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1967 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1968 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1969 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1970 | password="password", phase2="auth=MSCHAPV2", | |
1971 | ca_cert="hash://server/md5/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a", | |
1972 | wait_connect=False, scan_freq="2412") | |
1973 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1974 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1975 | password="password", phase2="auth=MSCHAPV2", | |
1976 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca", | |
1977 | wait_connect=False, scan_freq="2412") | |
1978 | dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1979 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1980 | password="password", phase2="auth=MSCHAPV2", | |
1981 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6Q", | |
1982 | wait_connect=False, scan_freq="2412") | |
1983 | for i in range(0, 3): | |
1984 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1985 | if ev is None: | |
1986 | raise Exception("Association and EAP start timed out") | |
cbb85a03 JM |
1987 | ev = dev[i].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 21 (TTLS)"], timeout=5) |
1988 | if ev is None: | |
1989 | raise Exception("Did not report EAP method initialization failure") | |
2a6a2192 | 1990 | |
22b99086 JM |
1991 | def test_ap_wpa2_eap_pwd(dev, apdev): |
1992 | """WPA2-Enterprise connection using EAP-pwd""" | |
3b51cc63 | 1993 | check_eap_capa(dev[0], "PWD") |
22b99086 JM |
1994 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1995 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 1996 | eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password") |
75b2b9cf | 1997 | eap_reauth(dev[0], "PWD") |
6daf5b9c | 1998 | dev[0].request("REMOVE_NETWORK all") |
0403fa0a JM |
1999 | |
2000 | eap_connect(dev[1], apdev[0], "PWD", | |
2001 | "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com", | |
2002 | password="secret password", | |
6daf5b9c JM |
2003 | fragment_size="90") |
2004 | ||
f10ba3b2 | 2005 | logger.info("Negative test with incorrect password") |
0403fa0a | 2006 | eap_connect(dev[2], apdev[0], "PWD", "pwd user", password="secret-password", |
f10ba3b2 JM |
2007 | expect_failure=True, local_error_report=True) |
2008 | ||
0403fa0a JM |
2009 | eap_connect(dev[0], apdev[0], "PWD", |
2010 | "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com", | |
2011 | password="secret password", | |
2012 | fragment_size="31") | |
2013 | ||
b898a6ee JM |
2014 | def test_ap_wpa2_eap_pwd_nthash(dev, apdev): |
2015 | """WPA2-Enterprise connection using EAP-pwd and NTHash""" | |
2016 | check_eap_capa(dev[0], "PWD") | |
0392867b | 2017 | skip_with_fips(dev[0]) |
b898a6ee JM |
2018 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2019 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2020 | eap_connect(dev[0], apdev[0], "PWD", "pwd-hash", password="secret password") | |
2021 | eap_connect(dev[1], apdev[0], "PWD", "pwd-hash", | |
2022 | password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a") | |
2023 | eap_connect(dev[2], apdev[0], "PWD", "pwd user", | |
2024 | password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a", | |
2025 | expect_failure=True, local_error_report=True) | |
2026 | ||
c075f040 JM |
2027 | def test_ap_wpa2_eap_pwd_groups(dev, apdev): |
2028 | """WPA2-Enterprise connection using various EAP-pwd groups""" | |
3b51cc63 | 2029 | check_eap_capa(dev[0], "PWD") |
5f2e4547 | 2030 | tls = dev[0].request("GET tls_library") |
c075f040 JM |
2031 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
2032 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2033 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" } | |
f2d789f2 JM |
2034 | groups = [ 19, 20, 21, 25, 26 ] |
2035 | if tls.startswith("OpenSSL") and "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls: | |
2036 | logger.info("Add Brainpool EC groups since OpenSSL is new enough") | |
2037 | groups += [ 27, 28, 29, 30 ] | |
2038 | for i in groups: | |
2039 | logger.info("Group %d" % i) | |
c075f040 JM |
2040 | params['pwd_group'] = str(i) |
2041 | hostapd.add_ap(apdev[0]['ifname'], params) | |
5f2e4547 JM |
2042 | try: |
2043 | eap_connect(dev[0], apdev[0], "PWD", "pwd user", | |
2044 | password="secret password") | |
f2d789f2 JM |
2045 | dev[0].request("REMOVE_NETWORK all") |
2046 | dev[0].wait_disconnected() | |
2047 | dev[0].dump_monitor() | |
5f2e4547 JM |
2048 | except: |
2049 | if "BoringSSL" in tls and i in [ 25 ]: | |
2050 | logger.info("Ignore connection failure with group %d with BoringSSL" % i) | |
2051 | dev[0].request("DISCONNECT") | |
2052 | time.sleep(0.1) | |
f2d789f2 JM |
2053 | dev[0].request("REMOVE_NETWORK all") |
2054 | dev[0].dump_monitor() | |
5f2e4547 JM |
2055 | continue |
2056 | raise | |
c075f040 | 2057 | |
4b2d2098 JM |
2058 | def test_ap_wpa2_eap_pwd_invalid_group(dev, apdev): |
2059 | """WPA2-Enterprise connection using invalid EAP-pwd group""" | |
3b51cc63 | 2060 | check_eap_capa(dev[0], "PWD") |
4b2d2098 JM |
2061 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
2062 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2063 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" } | |
2064 | params['pwd_group'] = "0" | |
2065 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2066 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD", | |
2067 | identity="pwd user", password="secret password", | |
2068 | scan_freq="2412", wait_connect=False) | |
2069 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2070 | if ev is None: | |
2071 | raise Exception("Timeout on EAP failure report") | |
2072 | ||
8ba89e0a JM |
2073 | def test_ap_wpa2_eap_pwd_as_frag(dev, apdev): |
2074 | """WPA2-Enterprise connection using EAP-pwd with server fragmentation""" | |
3b51cc63 | 2075 | check_eap_capa(dev[0], "PWD") |
8ba89e0a JM |
2076 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2077 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", | |
2078 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2079 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
2080 | "pwd_group": "19", "fragment_size": "40" } | |
2081 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2082 | eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password") | |
2083 | ||
22b99086 JM |
2084 | def test_ap_wpa2_eap_gpsk(dev, apdev): |
2085 | """WPA2-Enterprise connection using EAP-GPSK""" | |
2086 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2087 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 2088 | id = eap_connect(dev[0], apdev[0], "GPSK", "gpsk user", |
369f9c20 | 2089 | password="abcdefghijklmnop0123456789abcdef") |
75b2b9cf | 2090 | eap_reauth(dev[0], "GPSK") |
22b99086 | 2091 | |
369f9c20 JM |
2092 | logger.info("Test forced algorithm selection") |
2093 | for phase1 in [ "cipher=1", "cipher=2" ]: | |
2094 | dev[0].set_network_quoted(id, "phase1", phase1) | |
2095 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
2096 | if ev is None: | |
2097 | raise Exception("EAP success timed out") | |
5f35a5e2 | 2098 | dev[0].wait_connected(timeout=10) |
369f9c20 JM |
2099 | |
2100 | logger.info("Test failed algorithm negotiation") | |
2101 | dev[0].set_network_quoted(id, "phase1", "cipher=9") | |
2102 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
2103 | if ev is None: | |
2104 | raise Exception("EAP failure timed out") | |
2105 | ||
f10ba3b2 JM |
2106 | logger.info("Negative test with incorrect password") |
2107 | dev[0].request("REMOVE_NETWORK all") | |
2108 | eap_connect(dev[0], apdev[0], "GPSK", "gpsk user", | |
2109 | password="ffcdefghijklmnop0123456789abcdef", | |
2110 | expect_failure=True) | |
2111 | ||
22b99086 JM |
2112 | def test_ap_wpa2_eap_sake(dev, apdev): |
2113 | """WPA2-Enterprise connection using EAP-SAKE""" | |
2114 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2115 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 2116 | eap_connect(dev[0], apdev[0], "SAKE", "sake user", |
22b99086 | 2117 | password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") |
75b2b9cf | 2118 | eap_reauth(dev[0], "SAKE") |
22b99086 | 2119 | |
f10ba3b2 JM |
2120 | logger.info("Negative test with incorrect password") |
2121 | dev[0].request("REMOVE_NETWORK all") | |
2122 | eap_connect(dev[0], apdev[0], "SAKE", "sake user", | |
2123 | password_hex="ff23456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", | |
2124 | expect_failure=True) | |
2125 | ||
22b99086 JM |
2126 | def test_ap_wpa2_eap_eke(dev, apdev): |
2127 | """WPA2-Enterprise connection using EAP-EKE""" | |
2128 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2129 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 2130 | id = eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello") |
75b2b9cf | 2131 | eap_reauth(dev[0], "EKE") |
22b99086 | 2132 | |
2bb9e283 JM |
2133 | logger.info("Test forced algorithm selection") |
2134 | for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2", | |
2135 | "dhgroup=4 encr=1 prf=2 mac=2", | |
2136 | "dhgroup=3 encr=1 prf=2 mac=2", | |
2137 | "dhgroup=3 encr=1 prf=1 mac=1" ]: | |
2138 | dev[0].set_network_quoted(id, "phase1", phase1) | |
2139 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
2140 | if ev is None: | |
2141 | raise Exception("EAP success timed out") | |
5f35a5e2 | 2142 | dev[0].wait_connected(timeout=10) |
2bb9e283 JM |
2143 | |
2144 | logger.info("Test failed algorithm negotiation") | |
2145 | dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9") | |
2146 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
2147 | if ev is None: | |
2148 | raise Exception("EAP failure timed out") | |
2149 | ||
f10ba3b2 JM |
2150 | logger.info("Negative test with incorrect password") |
2151 | dev[0].request("REMOVE_NETWORK all") | |
2152 | eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello1", | |
2153 | expect_failure=True) | |
2154 | ||
f7e3c17b JM |
2155 | def test_ap_wpa2_eap_eke_serverid_nai(dev, apdev): |
2156 | """WPA2-Enterprise connection using EAP-EKE with serverid NAI""" | |
2157 | params = int_eap_server_params() | |
2158 | params['server_id'] = 'example.server@w1.fi' | |
2159 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2160 | eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello") | |
2161 | ||
5e0bedc6 JM |
2162 | def test_ap_wpa2_eap_eke_server_oom(dev, apdev): |
2163 | """WPA2-Enterprise connection using EAP-EKE with server OOM""" | |
2164 | params = int_eap_server_params() | |
2165 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
2166 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
2167 | ||
2168 | for count,func in [ (1, "eap_eke_build_commit"), | |
2169 | (2, "eap_eke_build_commit"), | |
2170 | (3, "eap_eke_build_commit"), | |
2171 | (1, "eap_eke_build_confirm"), | |
2172 | (2, "eap_eke_build_confirm"), | |
2173 | (1, "eap_eke_process_commit"), | |
2174 | (2, "eap_eke_process_commit"), | |
2175 | (1, "eap_eke_process_confirm"), | |
2176 | (1, "eap_eke_process_identity"), | |
2177 | (2, "eap_eke_process_identity"), | |
2178 | (3, "eap_eke_process_identity"), | |
2179 | (4, "eap_eke_process_identity") ]: | |
2180 | with alloc_fail(hapd, count, func): | |
2181 | eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello", | |
2182 | expect_failure=True) | |
2183 | dev[0].request("REMOVE_NETWORK all") | |
2184 | ||
2185 | for count,func,pw in [ (1, "eap_eke_init", "hello"), | |
2186 | (1, "eap_eke_get_session_id", "hello"), | |
2187 | (1, "eap_eke_getKey", "hello"), | |
2188 | (1, "eap_eke_build_msg", "hello"), | |
2189 | (1, "eap_eke_build_failure", "wrong"), | |
2190 | (1, "eap_eke_build_identity", "hello"), | |
2191 | (2, "eap_eke_build_identity", "hello") ]: | |
2192 | with alloc_fail(hapd, count, func): | |
2193 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
2194 | eap="EKE", identity="eke user", password=pw, | |
2195 | wait_connect=False, scan_freq="2412") | |
2196 | # This would eventually time out, but we can stop after having | |
2197 | # reached the allocation failure. | |
2198 | for i in range(20): | |
2199 | time.sleep(0.1) | |
2200 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
2201 | break | |
2202 | dev[0].request("REMOVE_NETWORK all") | |
2203 | ||
2204 | for count in range(1, 1000): | |
2205 | try: | |
2206 | with alloc_fail(hapd, count, "eap_server_sm_step"): | |
2207 | dev[0].connect("test-wpa2-eap", | |
2208 | key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
2209 | eap="EKE", identity="eke user", password=pw, | |
2210 | wait_connect=False, scan_freq="2412") | |
2211 | # This would eventually time out, but we can stop after having | |
2212 | # reached the allocation failure. | |
2213 | for i in range(10): | |
2214 | time.sleep(0.1) | |
2215 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
2216 | break | |
2217 | dev[0].request("REMOVE_NETWORK all") | |
2218 | except Exception, e: | |
2219 | if str(e) == "Allocation failure did not trigger": | |
2220 | if count < 30: | |
2221 | raise Exception("Too few allocation failures") | |
2222 | logger.info("%d allocation failures tested" % (count - 1)) | |
2223 | break | |
2224 | raise e | |
2225 | ||
22b99086 JM |
2226 | def test_ap_wpa2_eap_ikev2(dev, apdev): |
2227 | """WPA2-Enterprise connection using EAP-IKEv2""" | |
c8e82c94 | 2228 | check_eap_capa(dev[0], "IKEV2") |
22b99086 JM |
2229 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2230 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 JM |
2231 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", |
2232 | password="ike password") | |
75b2b9cf | 2233 | eap_reauth(dev[0], "IKEV2") |
6daf5b9c JM |
2234 | dev[0].request("REMOVE_NETWORK all") |
2235 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", | |
47a74ad8 | 2236 | password="ike password", fragment_size="50") |
22b99086 | 2237 | |
f10ba3b2 JM |
2238 | logger.info("Negative test with incorrect password") |
2239 | dev[0].request("REMOVE_NETWORK all") | |
2240 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", | |
2241 | password="ike-password", expect_failure=True) | |
2242 | ||
47a74ad8 JM |
2243 | def test_ap_wpa2_eap_ikev2_as_frag(dev, apdev): |
2244 | """WPA2-Enterprise connection using EAP-IKEv2 with server fragmentation""" | |
c8e82c94 | 2245 | check_eap_capa(dev[0], "IKEV2") |
47a74ad8 JM |
2246 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2247 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", | |
2248 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2249 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
2250 | "fragment_size": "50" } | |
2251 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2252 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", | |
2253 | password="ike password") | |
2254 | eap_reauth(dev[0], "IKEV2") | |
2255 | ||
f1ab79c3 JM |
2256 | def test_ap_wpa2_eap_ikev2_oom(dev, apdev): |
2257 | """WPA2-Enterprise connection using EAP-IKEv2 and OOM""" | |
c8e82c94 | 2258 | check_eap_capa(dev[0], "IKEV2") |
f1ab79c3 JM |
2259 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2260 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2261 | ||
2262 | tests = [ (1, "dh_init"), | |
2263 | (2, "dh_init"), | |
2264 | (1, "dh_derive_shared") ] | |
2265 | for count, func in tests: | |
2266 | with alloc_fail(dev[0], count, func): | |
2267 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2", | |
2268 | identity="ikev2 user", password="ike password", | |
2269 | wait_connect=False, scan_freq="2412") | |
2270 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5) | |
2271 | if ev is None: | |
2272 | raise Exception("EAP method not selected") | |
2273 | for i in range(10): | |
2274 | if "0:" in dev[0].request("GET_ALLOC_FAIL"): | |
2275 | break | |
2276 | time.sleep(0.02) | |
2277 | dev[0].request("REMOVE_NETWORK all") | |
2278 | ||
2279 | tests = [ (1, "os_get_random;dh_init") ] | |
2280 | for count, func in tests: | |
2281 | with fail_test(dev[0], count, func): | |
2282 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2", | |
2283 | identity="ikev2 user", password="ike password", | |
2284 | wait_connect=False, scan_freq="2412") | |
2285 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5) | |
2286 | if ev is None: | |
2287 | raise Exception("EAP method not selected") | |
2288 | for i in range(10): | |
2289 | if "0:" in dev[0].request("GET_FAIL"): | |
2290 | break | |
2291 | time.sleep(0.02) | |
2292 | dev[0].request("REMOVE_NETWORK all") | |
2293 | ||
22b99086 JM |
2294 | def test_ap_wpa2_eap_pax(dev, apdev): |
2295 | """WPA2-Enterprise connection using EAP-PAX""" | |
2296 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2297 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 2298 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", |
22b99086 | 2299 | password_hex="0123456789abcdef0123456789abcdef") |
75b2b9cf | 2300 | eap_reauth(dev[0], "PAX") |
22b99086 | 2301 | |
f10ba3b2 JM |
2302 | logger.info("Negative test with incorrect password") |
2303 | dev[0].request("REMOVE_NETWORK all") | |
2304 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", | |
2305 | password_hex="ff23456789abcdef0123456789abcdef", | |
2306 | expect_failure=True) | |
2307 | ||
22b99086 JM |
2308 | def test_ap_wpa2_eap_psk(dev, apdev): |
2309 | """WPA2-Enterprise connection using EAP-PSK""" | |
2310 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2b005194 JM |
2311 | params["wpa_key_mgmt"] = "WPA-EAP-SHA256" |
2312 | params["ieee80211w"] = "2" | |
22b99086 | 2313 | hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 2314 | eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com", |
2b005194 JM |
2315 | password_hex="0123456789abcdef0123456789abcdef", sha256=True) |
2316 | eap_reauth(dev[0], "PSK", sha256=True) | |
eaf3f9b1 JM |
2317 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"), |
2318 | ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ]) | |
71390dc8 | 2319 | |
d463c556 JM |
2320 | bss = dev[0].get_bss(apdev[0]['bssid']) |
2321 | if 'flags' not in bss: | |
2322 | raise Exception("Could not get BSS flags from BSS table") | |
2323 | if "[WPA2-EAP-SHA256-CCMP]" not in bss['flags']: | |
2324 | raise Exception("Unexpected BSS flags: " + bss['flags']) | |
2325 | ||
f10ba3b2 JM |
2326 | logger.info("Negative test with incorrect password") |
2327 | dev[0].request("REMOVE_NETWORK all") | |
2328 | eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com", | |
2329 | password_hex="ff23456789abcdef0123456789abcdef", sha256=True, | |
2330 | expect_failure=True) | |
2331 | ||
8c4e4c01 JM |
2332 | def test_ap_wpa2_eap_psk_oom(dev, apdev): |
2333 | """WPA2-Enterprise connection using EAP-PSK and OOM""" | |
38934ed1 | 2334 | skip_with_fips(dev[0]) |
8c4e4c01 JM |
2335 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2336 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2337 | tests = [ (1, "aes_128_ctr_encrypt;aes_128_eax_encrypt"), | |
2338 | (1, "omac1_aes_128;aes_128_eax_encrypt"), | |
2339 | (2, "omac1_aes_128;aes_128_eax_encrypt"), | |
2340 | (3, "omac1_aes_128;aes_128_eax_encrypt"), | |
2341 | (1, "=aes_128_eax_encrypt"), | |
2342 | (1, "omac1_aes_vector"), | |
2343 | (1, "aes_128_ctr_encrypt;aes_128_eax_decrypt"), | |
2344 | (1, "omac1_aes_128;aes_128_eax_decrypt"), | |
2345 | (2, "omac1_aes_128;aes_128_eax_decrypt"), | |
2346 | (3, "omac1_aes_128;aes_128_eax_decrypt"), | |
2347 | (1, "=aes_128_eax_decrypt") ] | |
2348 | for count, func in tests: | |
2349 | with alloc_fail(dev[0], count, func): | |
2350 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK", | |
2351 | identity="psk.user@example.com", | |
2352 | password_hex="0123456789abcdef0123456789abcdef", | |
2353 | wait_connect=False, scan_freq="2412") | |
2354 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5) | |
2355 | if ev is None: | |
2356 | raise Exception("EAP method not selected") | |
2357 | for i in range(10): | |
2358 | if "0:" in dev[0].request("GET_ALLOC_FAIL"): | |
2359 | break | |
2360 | time.sleep(0.02) | |
2361 | dev[0].request("REMOVE_NETWORK all") | |
2362 | ||
2363 | with alloc_fail(dev[0], 1, "aes_128_encrypt_block"): | |
2364 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK", | |
2365 | identity="psk.user@example.com", | |
2366 | password_hex="0123456789abcdef0123456789abcdef", | |
2367 | wait_connect=False, scan_freq="2412") | |
2368 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
2369 | if ev is None: | |
2370 | raise Exception("EAP method failure not reported") | |
2371 | dev[0].request("REMOVE_NETWORK all") | |
2372 | ||
71390dc8 JM |
2373 | def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev): |
2374 | """WPA-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2""" | |
e7ac04ce | 2375 | check_eap_capa(dev[0], "MSCHAPV2") |
71390dc8 | 2376 | params = hostapd.wpa_eap_params(ssid="test-wpa-eap") |
a8375c94 | 2377 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
71390dc8 JM |
2378 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="PEAP", |
2379 | identity="user", password="password", phase2="auth=MSCHAPV2", | |
2380 | ca_cert="auth_serv/ca.pem", wait_connect=False, | |
2381 | scan_freq="2412") | |
2382 | eap_check_auth(dev[0], "PEAP", True, rsn=False) | |
a8375c94 | 2383 | hwsim_utils.test_connectivity(dev[0], hapd) |
71390dc8 | 2384 | eap_reauth(dev[0], "PEAP", rsn=False) |
eaf3f9b1 JM |
2385 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"), |
2386 | ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ]) | |
48bb2e68 JM |
2387 | status = dev[0].get_status(extra="VERBOSE") |
2388 | if 'portControl' not in status: | |
2389 | raise Exception("portControl missing from STATUS-VERBOSE") | |
2390 | if status['portControl'] != 'Auto': | |
2391 | raise Exception("Unexpected portControl value: " + status['portControl']) | |
2392 | if 'eap_session_id' not in status: | |
2393 | raise Exception("eap_session_id missing from STATUS-VERBOSE") | |
2394 | if not status['eap_session_id'].startswith("19"): | |
2395 | raise Exception("Unexpected eap_session_id value: " + status['eap_session_id']) | |
40759604 JM |
2396 | |
2397 | def test_ap_wpa2_eap_interactive(dev, apdev): | |
2398 | """WPA2-Enterprise connection using interactive identity/password entry""" | |
e7ac04ce | 2399 | check_eap_capa(dev[0], "MSCHAPV2") |
40759604 JM |
2400 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2401 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2402 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
2403 | ||
2404 | tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry", | |
2405 | "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2", | |
2406 | None, "password"), | |
2407 | ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry", | |
2408 | "TTLS", "ttls", None, "auth=MSCHAPV2", | |
2409 | "DOMAIN\mschapv2 user", "password"), | |
2410 | ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry", | |
2411 | "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"), | |
2412 | ("Connection with dynamic TTLS/EAP-MD5 password entry", | |
2413 | "TTLS", "ttls", "user", "autheap=MD5", None, "password"), | |
2414 | ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry", | |
2415 | "PEAP", None, "user", "auth=MSCHAPV2", None, "password"), | |
2416 | ("Connection with dynamic PEAP/EAP-GTC password entry", | |
2417 | "PEAP", None, "user", "auth=GTC", None, "password") ] | |
2418 | for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests: | |
2419 | logger.info(desc) | |
2420 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap, | |
2421 | anonymous_identity=anon, identity=identity, | |
2422 | ca_cert="auth_serv/ca.pem", phase2=phase2, | |
2423 | wait_connect=False, scan_freq="2412") | |
2424 | if req_id: | |
2425 | ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"]) | |
2426 | if ev is None: | |
2427 | raise Exception("Request for identity timed out") | |
2428 | id = ev.split(':')[0].split('-')[-1] | |
2429 | dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id) | |
2430 | ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"]) | |
2431 | if ev is None: | |
2432 | raise Exception("Request for password timed out") | |
2433 | id = ev.split(':')[0].split('-')[-1] | |
2434 | type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD" | |
2435 | dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw) | |
5f35a5e2 | 2436 | dev[0].wait_connected(timeout=10) |
40759604 | 2437 | dev[0].request("REMOVE_NETWORK all") |
e745c811 | 2438 | |
f455998a JM |
2439 | def test_ap_wpa2_eap_ext_enable_network_while_connected(dev, apdev): |
2440 | """WPA2-Enterprise interactive identity entry and ENABLE_NETWORK""" | |
2441 | check_eap_capa(dev[0], "MSCHAPV2") | |
2442 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2443 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2444 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
2445 | ||
2446 | id_other = dev[0].connect("other", key_mgmt="NONE", scan_freq="2412", | |
2447 | only_add_network=True) | |
2448 | ||
2449 | req_id = "DOMAIN\mschapv2 user" | |
2450 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2451 | anonymous_identity="ttls", identity=None, | |
2452 | password="password", | |
2453 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2454 | wait_connect=False, scan_freq="2412") | |
2455 | ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"]) | |
2456 | if ev is None: | |
2457 | raise Exception("Request for identity timed out") | |
2458 | id = ev.split(':')[0].split('-')[-1] | |
2459 | dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id) | |
2460 | dev[0].wait_connected(timeout=10) | |
2461 | ||
2462 | if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id_other)): | |
2463 | raise Exception("Failed to enable network") | |
2464 | ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=1) | |
2465 | if ev is not None: | |
2466 | raise Exception("Unexpected reconnection attempt on ENABLE_NETWORK") | |
2467 | dev[0].request("REMOVE_NETWORK all") | |
2468 | ||
e745c811 JM |
2469 | def test_ap_wpa2_eap_vendor_test(dev, apdev): |
2470 | """WPA2-Enterprise connection using EAP vendor test""" | |
2471 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2472 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2473 | eap_connect(dev[0], apdev[0], "VENDOR-TEST", "vendor-test") | |
2474 | eap_reauth(dev[0], "VENDOR-TEST") | |
467775c5 JM |
2475 | eap_connect(dev[1], apdev[0], "VENDOR-TEST", "vendor-test", |
2476 | password="pending") | |
53a6f06a JM |
2477 | |
2478 | def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev): | |
2479 | """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning""" | |
3b51cc63 | 2480 | check_eap_capa(dev[0], "FAST") |
53a6f06a | 2481 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 2482 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
53a6f06a JM |
2483 | eap_connect(dev[0], apdev[0], "FAST", "user", |
2484 | anonymous_identity="FAST", password="password", | |
2485 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2486 | phase1="fast_provisioning=1", pac_file="blob://fast_pac") | |
a8375c94 | 2487 | hwsim_utils.test_connectivity(dev[0], hapd) |
2fc4749c JM |
2488 | res = eap_reauth(dev[0], "FAST") |
2489 | if res['tls_session_reused'] != '1': | |
2490 | raise Exception("EAP-FAST could not use PAC session ticket") | |
53a6f06a | 2491 | |
873e7c29 JM |
2492 | def test_ap_wpa2_eap_fast_pac_file(dev, apdev, params): |
2493 | """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and PAC file""" | |
3b51cc63 | 2494 | check_eap_capa(dev[0], "FAST") |
873e7c29 JM |
2495 | pac_file = os.path.join(params['logdir'], "fast.pac") |
2496 | pac_file2 = os.path.join(params['logdir'], "fast-bin.pac") | |
2497 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2498 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2499 | ||
2500 | try: | |
2501 | eap_connect(dev[0], apdev[0], "FAST", "user", | |
2502 | anonymous_identity="FAST", password="password", | |
2503 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2504 | phase1="fast_provisioning=1", pac_file=pac_file) | |
2505 | with open(pac_file, "r") as f: | |
2506 | data = f.read() | |
2507 | if "wpa_supplicant EAP-FAST PAC file - version 1" not in data: | |
2508 | raise Exception("PAC file header missing") | |
2509 | if "PAC-Key=" not in data: | |
2510 | raise Exception("PAC-Key missing from PAC file") | |
2511 | dev[0].request("REMOVE_NETWORK all") | |
2512 | eap_connect(dev[0], apdev[0], "FAST", "user", | |
2513 | anonymous_identity="FAST", password="password", | |
2514 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2515 | pac_file=pac_file) | |
2516 | ||
2517 | eap_connect(dev[1], apdev[0], "FAST", "user", | |
2518 | anonymous_identity="FAST", password="password", | |
2519 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2520 | phase1="fast_provisioning=1 fast_pac_format=binary", | |
2521 | pac_file=pac_file2) | |
2522 | dev[1].request("REMOVE_NETWORK all") | |
2523 | eap_connect(dev[1], apdev[0], "FAST", "user", | |
2524 | anonymous_identity="FAST", password="password", | |
2525 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2526 | phase1="fast_pac_format=binary", | |
2527 | pac_file=pac_file2) | |
2528 | finally: | |
b638f703 JM |
2529 | try: |
2530 | os.remove(pac_file) | |
2531 | except: | |
2532 | pass | |
2533 | try: | |
2534 | os.remove(pac_file2) | |
2535 | except: | |
2536 | pass | |
873e7c29 | 2537 | |
c6ab1cdb JM |
2538 | def test_ap_wpa2_eap_fast_binary_pac(dev, apdev): |
2539 | """WPA2-Enterprise connection using EAP-FAST and binary PAC format""" | |
3b51cc63 | 2540 | check_eap_capa(dev[0], "FAST") |
c6ab1cdb JM |
2541 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2542 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2543 | eap_connect(dev[0], apdev[0], "FAST", "user", | |
2544 | anonymous_identity="FAST", password="password", | |
2545 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2546 | phase1="fast_provisioning=1 fast_max_pac_list_len=1 fast_pac_format=binary", | |
2547 | pac_file="blob://fast_pac_bin") | |
2fc4749c JM |
2548 | res = eap_reauth(dev[0], "FAST") |
2549 | if res['tls_session_reused'] != '1': | |
2550 | raise Exception("EAP-FAST could not use PAC session ticket") | |
c6ab1cdb | 2551 | |
46e094bd JM |
2552 | def test_ap_wpa2_eap_fast_missing_pac_config(dev, apdev): |
2553 | """WPA2-Enterprise connection using EAP-FAST and missing PAC config""" | |
3b51cc63 | 2554 | check_eap_capa(dev[0], "FAST") |
46e094bd JM |
2555 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2556 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2557 | ||
2558 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
2559 | identity="user", anonymous_identity="FAST", | |
2560 | password="password", | |
2561 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2562 | pac_file="blob://fast_pac_not_in_use", | |
2563 | wait_connect=False, scan_freq="2412") | |
2564 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2565 | if ev is None: | |
2566 | raise Exception("Timeout on EAP failure report") | |
2567 | dev[0].request("REMOVE_NETWORK all") | |
2568 | ||
2569 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
2570 | identity="user", anonymous_identity="FAST", | |
2571 | password="password", | |
2572 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2573 | wait_connect=False, scan_freq="2412") | |
2574 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2575 | if ev is None: | |
2576 | raise Exception("Timeout on EAP failure report") | |
2577 | ||
53a6f06a JM |
2578 | def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev): |
2579 | """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning""" | |
3b51cc63 | 2580 | check_eap_capa(dev[0], "FAST") |
53a6f06a | 2581 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 2582 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
53a6f06a JM |
2583 | eap_connect(dev[0], apdev[0], "FAST", "user", |
2584 | anonymous_identity="FAST", password="password", | |
2585 | ca_cert="auth_serv/ca.pem", phase2="auth=GTC", | |
2586 | phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth") | |
a8375c94 | 2587 | hwsim_utils.test_connectivity(dev[0], hapd) |
2fc4749c JM |
2588 | res = eap_reauth(dev[0], "FAST") |
2589 | if res['tls_session_reused'] != '1': | |
2590 | raise Exception("EAP-FAST could not use PAC session ticket") | |
d4c7a2b9 | 2591 | |
95a15d79 JM |
2592 | def test_ap_wpa2_eap_fast_gtc_identity_change(dev, apdev): |
2593 | """WPA2-Enterprise connection using EAP-FAST/GTC and identity changing""" | |
2594 | check_eap_capa(dev[0], "FAST") | |
2595 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2596 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
2597 | id = eap_connect(dev[0], apdev[0], "FAST", "user", | |
2598 | anonymous_identity="FAST", password="password", | |
2599 | ca_cert="auth_serv/ca.pem", phase2="auth=GTC", | |
2600 | phase1="fast_provisioning=2", | |
2601 | pac_file="blob://fast_pac_auth") | |
2602 | dev[0].set_network_quoted(id, "identity", "user2") | |
2603 | dev[0].wait_disconnected() | |
2604 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) | |
2605 | if ev is None: | |
2606 | raise Exception("EAP-FAST not started") | |
2607 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
2608 | if ev is None: | |
2609 | raise Exception("EAP failure not reported") | |
2610 | dev[0].wait_disconnected() | |
2611 | ||
27f2fab0 JM |
2612 | def test_ap_wpa2_eap_fast_prf_oom(dev, apdev): |
2613 | """WPA2-Enterprise connection using EAP-FAST and OOM in PRF""" | |
2614 | check_eap_capa(dev[0], "FAST") | |
cc71035f JM |
2615 | tls = dev[0].request("GET tls_library") |
2616 | if tls.startswith("OpenSSL"): | |
2617 | func = "openssl_tls_prf" | |
2618 | count = 2 | |
2619 | elif tls.startswith("internal"): | |
2620 | func = "tls_connection_prf" | |
2621 | count = 1 | |
2622 | else: | |
2623 | raise HwsimSkip("Unsupported TLS library") | |
27f2fab0 JM |
2624 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2625 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
cc71035f | 2626 | with alloc_fail(dev[0], count, func): |
27f2fab0 JM |
2627 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", |
2628 | identity="user", anonymous_identity="FAST", | |
2629 | password="password", ca_cert="auth_serv/ca.pem", | |
2630 | phase2="auth=GTC", | |
2631 | phase1="fast_provisioning=2", | |
2632 | pac_file="blob://fast_pac_auth", | |
2633 | wait_connect=False, scan_freq="2412") | |
2634 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
2635 | if ev is None: | |
2636 | raise Exception("EAP failure not reported") | |
2637 | dev[0].request("DISCONNECT") | |
2638 | ||
6eddd530 JM |
2639 | def test_ap_wpa2_eap_fast_server_oom(dev, apdev): |
2640 | """EAP-FAST/MSCHAPv2 and server OOM""" | |
2641 | check_eap_capa(dev[0], "FAST") | |
2642 | ||
2643 | params = int_eap_server_params() | |
2644 | params['dh_file'] = 'auth_serv/dh.conf' | |
2645 | params['pac_opaque_encr_key'] = '000102030405060708090a0b0c0d0e0f' | |
2646 | params['eap_fast_a_id'] = '1011' | |
2647 | params['eap_fast_a_id_info'] = 'another test server' | |
2648 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
2649 | ||
2650 | with alloc_fail(hapd, 1, "tls_session_ticket_ext_cb"): | |
2651 | id = eap_connect(dev[0], apdev[0], "FAST", "user", | |
2652 | anonymous_identity="FAST", password="password", | |
2653 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2654 | phase1="fast_provisioning=1", | |
2655 | pac_file="blob://fast_pac", | |
2656 | expect_failure=True) | |
2657 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
2658 | if ev is None: | |
2659 | raise Exception("No EAP failure reported") | |
2660 | dev[0].wait_disconnected() | |
2661 | dev[0].request("DISCONNECT") | |
2662 | ||
2663 | dev[0].select_network(id, freq="2412") | |
2664 | ||
d4c7a2b9 JM |
2665 | def test_ap_wpa2_eap_tls_ocsp(dev, apdev): |
2666 | """WPA2-Enterprise connection using EAP-TLS and verifying OCSP""" | |
0dae8c99 | 2667 | check_ocsp_support(dev[0]) |
16c43d2a | 2668 | check_pkcs12_support(dev[0]) |
d4c7a2b9 JM |
2669 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2670 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2671 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
2672 | private_key="auth_serv/user.pkcs12", | |
2673 | private_key_passwd="whatever", ocsp=2) | |
2674 | ||
64e05f96 | 2675 | def int_eap_server_params(): |
d4c7a2b9 JM |
2676 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
2677 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2678 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
2679 | "ca_cert": "auth_serv/ca.pem", | |
2680 | "server_cert": "auth_serv/server.pem", | |
64e05f96 JM |
2681 | "private_key": "auth_serv/server.key" } |
2682 | return params | |
d2a1047e | 2683 | |
58a40620 JM |
2684 | def test_ap_wpa2_eap_tls_ocsp_key_id(dev, apdev, params): |
2685 | """EAP-TLS and OCSP certificate signed OCSP response using key ID""" | |
2686 | check_ocsp_support(dev[0]) | |
2687 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-key-id.der") | |
2688 | if not os.path.exists(ocsp): | |
2689 | raise HwsimSkip("No OCSP response available") | |
2690 | params = int_eap_server_params() | |
2691 | params["ocsp_stapling_response"] = ocsp | |
2692 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2693 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2694 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2695 | private_key="auth_serv/user.pkcs12", | |
2696 | private_key_passwd="whatever", ocsp=2, | |
2697 | scan_freq="2412") | |
2698 | ||
d79ce4a6 JM |
2699 | def test_ap_wpa2_eap_tls_ocsp_ca_signed_good(dev, apdev, params): |
2700 | """EAP-TLS and CA signed OCSP response (good)""" | |
2701 | check_ocsp_support(dev[0]) | |
2702 | ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed.der") | |
2703 | if not os.path.exists(ocsp): | |
2704 | raise HwsimSkip("No OCSP response available") | |
2705 | params = int_eap_server_params() | |
2706 | params["ocsp_stapling_response"] = ocsp | |
2707 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2708 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2709 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2710 | private_key="auth_serv/user.pkcs12", | |
2711 | private_key_passwd="whatever", ocsp=2, | |
2712 | scan_freq="2412") | |
2713 | ||
2714 | def test_ap_wpa2_eap_tls_ocsp_ca_signed_revoked(dev, apdev, params): | |
2715 | """EAP-TLS and CA signed OCSP response (revoked)""" | |
2716 | check_ocsp_support(dev[0]) | |
2717 | ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-revoked.der") | |
2718 | if not os.path.exists(ocsp): | |
2719 | raise HwsimSkip("No OCSP response available") | |
2720 | params = int_eap_server_params() | |
2721 | params["ocsp_stapling_response"] = ocsp | |
2722 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2723 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2724 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2725 | private_key="auth_serv/user.pkcs12", | |
2726 | private_key_passwd="whatever", ocsp=2, | |
2727 | wait_connect=False, scan_freq="2412") | |
2728 | count = 0 | |
2729 | while True: | |
2730 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2731 | if ev is None: | |
2732 | raise Exception("Timeout on EAP status") | |
2733 | if 'bad certificate status response' in ev: | |
2734 | break | |
2735 | if 'certificate revoked' in ev: | |
2736 | break | |
2737 | count = count + 1 | |
2738 | if count > 10: | |
2739 | raise Exception("Unexpected number of EAP status messages") | |
2740 | ||
2741 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2742 | if ev is None: | |
2743 | raise Exception("Timeout on EAP failure report") | |
2744 | ||
2745 | def test_ap_wpa2_eap_tls_ocsp_ca_signed_unknown(dev, apdev, params): | |
2746 | """EAP-TLS and CA signed OCSP response (unknown)""" | |
2747 | check_ocsp_support(dev[0]) | |
2748 | ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-unknown.der") | |
2749 | if not os.path.exists(ocsp): | |
2750 | raise HwsimSkip("No OCSP response available") | |
2751 | params = int_eap_server_params() | |
2752 | params["ocsp_stapling_response"] = ocsp | |
2753 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2754 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2755 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2756 | private_key="auth_serv/user.pkcs12", | |
2757 | private_key_passwd="whatever", ocsp=2, | |
2758 | wait_connect=False, scan_freq="2412") | |
2759 | count = 0 | |
2760 | while True: | |
2761 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2762 | if ev is None: | |
2763 | raise Exception("Timeout on EAP status") | |
2764 | if 'bad certificate status response' in ev: | |
2765 | break | |
2766 | count = count + 1 | |
2767 | if count > 10: | |
2768 | raise Exception("Unexpected number of EAP status messages") | |
2769 | ||
2770 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2771 | if ev is None: | |
2772 | raise Exception("Timeout on EAP failure report") | |
2773 | ||
2774 | def test_ap_wpa2_eap_tls_ocsp_server_signed(dev, apdev, params): | |
2775 | """EAP-TLS and server signed OCSP response""" | |
2776 | check_ocsp_support(dev[0]) | |
2777 | ocsp = os.path.join(params['logdir'], "ocsp-resp-server-signed.der") | |
2778 | if not os.path.exists(ocsp): | |
2779 | raise HwsimSkip("No OCSP response available") | |
2780 | params = int_eap_server_params() | |
2781 | params["ocsp_stapling_response"] = ocsp | |
2782 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2783 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2784 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2785 | private_key="auth_serv/user.pkcs12", | |
2786 | private_key_passwd="whatever", ocsp=2, | |
2787 | wait_connect=False, scan_freq="2412") | |
2788 | count = 0 | |
2789 | while True: | |
2790 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2791 | if ev is None: | |
2792 | raise Exception("Timeout on EAP status") | |
2793 | if 'bad certificate status response' in ev: | |
2794 | break | |
2795 | count = count + 1 | |
2796 | if count > 10: | |
2797 | raise Exception("Unexpected number of EAP status messages") | |
2798 | ||
2799 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2800 | if ev is None: | |
2801 | raise Exception("Timeout on EAP failure report") | |
2802 | ||
d2a1047e JM |
2803 | def test_ap_wpa2_eap_tls_ocsp_invalid_data(dev, apdev): |
2804 | """WPA2-Enterprise connection using EAP-TLS and invalid OCSP data""" | |
0dae8c99 | 2805 | check_ocsp_support(dev[0]) |
d2a1047e JM |
2806 | params = int_eap_server_params() |
2807 | params["ocsp_stapling_response"] = "auth_serv/ocsp-req.der" | |
2808 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2809 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2810 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2811 | private_key="auth_serv/user.pkcs12", | |
2812 | private_key_passwd="whatever", ocsp=2, | |
2813 | wait_connect=False, scan_freq="2412") | |
2814 | count = 0 | |
2815 | while True: | |
2816 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2817 | if ev is None: | |
2818 | raise Exception("Timeout on EAP status") | |
2819 | if 'bad certificate status response' in ev: | |
2820 | break | |
2821 | count = count + 1 | |
2822 | if count > 10: | |
2823 | raise Exception("Unexpected number of EAP status messages") | |
2824 | ||
2825 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2826 | if ev is None: | |
2827 | raise Exception("Timeout on EAP failure report") | |
2828 | ||
64e05f96 JM |
2829 | def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev): |
2830 | """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response""" | |
0dae8c99 | 2831 | check_ocsp_support(dev[0]) |
64e05f96 JM |
2832 | params = int_eap_server_params() |
2833 | params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid" | |
d4c7a2b9 | 2834 | hostapd.add_ap(apdev[0]['ifname'], params) |
df7ad0fa JM |
2835 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
2836 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2837 | private_key="auth_serv/user.pkcs12", | |
2838 | private_key_passwd="whatever", ocsp=2, | |
2839 | wait_connect=False, scan_freq="2412") | |
2840 | count = 0 | |
2841 | while True: | |
2842 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2843 | if ev is None: | |
2844 | raise Exception("Timeout on EAP status") | |
2845 | if 'bad certificate status response' in ev: | |
2846 | break | |
2847 | count = count + 1 | |
2848 | if count > 10: | |
2849 | raise Exception("Unexpected number of EAP status messages") | |
2850 | ||
2851 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2852 | if ev is None: | |
2853 | raise Exception("Timeout on EAP failure report") | |
2854 | ||
2855 | def test_ap_wpa2_eap_tls_ocsp_unknown_sign(dev, apdev): | |
2856 | """WPA2-Enterprise connection using EAP-TLS and unknown OCSP signer""" | |
0dae8c99 | 2857 | check_ocsp_support(dev[0]) |
df7ad0fa JM |
2858 | params = int_eap_server_params() |
2859 | params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-unknown-sign" | |
2860 | hostapd.add_ap(apdev[0]['ifname'], params) | |
d4c7a2b9 JM |
2861 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
2862 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2863 | private_key="auth_serv/user.pkcs12", | |
2864 | private_key_passwd="whatever", ocsp=2, | |
2865 | wait_connect=False, scan_freq="2412") | |
2866 | count = 0 | |
2867 | while True: | |
2868 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2869 | if ev is None: | |
2870 | raise Exception("Timeout on EAP status") | |
2871 | if 'bad certificate status response' in ev: | |
2872 | break | |
2873 | count = count + 1 | |
2874 | if count > 10: | |
2875 | raise Exception("Unexpected number of EAP status messages") | |
2876 | ||
2877 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2878 | if ev is None: | |
2879 | raise Exception("Timeout on EAP failure report") | |
64e05f96 | 2880 | |
37b4a66c JM |
2881 | def test_ap_wpa2_eap_ttls_ocsp_revoked(dev, apdev, params): |
2882 | """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked""" | |
0dae8c99 | 2883 | check_ocsp_support(dev[0]) |
37b4a66c JM |
2884 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-revoked.der") |
2885 | if not os.path.exists(ocsp): | |
2886 | raise HwsimSkip("No OCSP response available") | |
2887 | params = int_eap_server_params() | |
2888 | params["ocsp_stapling_response"] = ocsp | |
2889 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2890 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2891 | identity="pap user", ca_cert="auth_serv/ca.pem", | |
2892 | anonymous_identity="ttls", password="password", | |
2893 | phase2="auth=PAP", ocsp=2, | |
2894 | wait_connect=False, scan_freq="2412") | |
2895 | count = 0 | |
2896 | while True: | |
2897 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2898 | if ev is None: | |
2899 | raise Exception("Timeout on EAP status") | |
2900 | if 'bad certificate status response' in ev: | |
2901 | break | |
2902 | if 'certificate revoked' in ev: | |
2903 | break | |
2904 | count = count + 1 | |
2905 | if count > 10: | |
2906 | raise Exception("Unexpected number of EAP status messages") | |
2907 | ||
2908 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2909 | if ev is None: | |
2910 | raise Exception("Timeout on EAP failure report") | |
2911 | ||
2912 | def test_ap_wpa2_eap_ttls_ocsp_unknown(dev, apdev, params): | |
2913 | """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked""" | |
0dae8c99 | 2914 | check_ocsp_support(dev[0]) |
37b4a66c JM |
2915 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der") |
2916 | if not os.path.exists(ocsp): | |
2917 | raise HwsimSkip("No OCSP response available") | |
2918 | params = int_eap_server_params() | |
2919 | params["ocsp_stapling_response"] = ocsp | |
2920 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2921 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2922 | identity="pap user", ca_cert="auth_serv/ca.pem", | |
2923 | anonymous_identity="ttls", password="password", | |
2924 | phase2="auth=PAP", ocsp=2, | |
2925 | wait_connect=False, scan_freq="2412") | |
2926 | count = 0 | |
2927 | while True: | |
2928 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2929 | if ev is None: | |
2930 | raise Exception("Timeout on EAP status") | |
2931 | if 'bad certificate status response' in ev: | |
2932 | break | |
2933 | count = count + 1 | |
2934 | if count > 10: | |
2935 | raise Exception("Unexpected number of EAP status messages") | |
2936 | ||
2937 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2938 | if ev is None: | |
2939 | raise Exception("Timeout on EAP failure report") | |
2940 | ||
2941 | def test_ap_wpa2_eap_ttls_optional_ocsp_unknown(dev, apdev, params): | |
2942 | """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked""" | |
2943 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der") | |
2944 | if not os.path.exists(ocsp): | |
2945 | raise HwsimSkip("No OCSP response available") | |
2946 | params = int_eap_server_params() | |
2947 | params["ocsp_stapling_response"] = ocsp | |
2948 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2949 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2950 | identity="pap user", ca_cert="auth_serv/ca.pem", | |
2951 | anonymous_identity="ttls", password="password", | |
2952 | phase2="auth=PAP", ocsp=1, scan_freq="2412") | |
2953 | ||
24579e70 | 2954 | def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev): |
64e05f96 | 2955 | """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)""" |
e78eb404 | 2956 | check_domain_match_full(dev[0]) |
64e05f96 JM |
2957 | params = int_eap_server_params() |
2958 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
2959 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
2960 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2961 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2962 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2963 | private_key="auth_serv/user.pkcs12", | |
2964 | private_key_passwd="whatever", | |
2965 | domain_suffix_match="server3.w1.fi", | |
2966 | scan_freq="2412") | |
24579e70 | 2967 | |
061cbb25 JM |
2968 | def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev): |
2969 | """WPA2-Enterprise using EAP-TLS and domainmatch (CN)""" | |
e78eb404 | 2970 | check_domain_match(dev[0]) |
061cbb25 JM |
2971 | params = int_eap_server_params() |
2972 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
2973 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
2974 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2975 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2976 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2977 | private_key="auth_serv/user.pkcs12", | |
2978 | private_key_passwd="whatever", | |
2979 | domain_match="server3.w1.fi", | |
2980 | scan_freq="2412") | |
2981 | ||
24579e70 JM |
2982 | def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev): |
2983 | """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)""" | |
2984 | check_domain_match_full(dev[0]) | |
2985 | params = int_eap_server_params() | |
2986 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
2987 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
2988 | hostapd.add_ap(apdev[0]['ifname'], params) | |
64e05f96 JM |
2989 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
2990 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2991 | private_key="auth_serv/user.pkcs12", | |
2992 | private_key_passwd="whatever", | |
2993 | domain_suffix_match="w1.fi", | |
2994 | scan_freq="2412") | |
2995 | ||
2996 | def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev): | |
2997 | """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)""" | |
e78eb404 | 2998 | check_domain_suffix_match(dev[0]) |
64e05f96 JM |
2999 | params = int_eap_server_params() |
3000 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
3001 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
3002 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3003 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
3004 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3005 | private_key="auth_serv/user.pkcs12", | |
3006 | private_key_passwd="whatever", | |
3007 | domain_suffix_match="example.com", | |
3008 | wait_connect=False, | |
3009 | scan_freq="2412") | |
c61dca40 JM |
3010 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
3011 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3012 | private_key="auth_serv/user.pkcs12", | |
3013 | private_key_passwd="whatever", | |
3014 | domain_suffix_match="erver3.w1.fi", | |
3015 | wait_connect=False, | |
3016 | scan_freq="2412") | |
64e05f96 JM |
3017 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) |
3018 | if ev is None: | |
3019 | raise Exception("Timeout on EAP failure report") | |
c61dca40 JM |
3020 | ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"]) |
3021 | if ev is None: | |
3022 | raise Exception("Timeout on EAP failure report (2)") | |
6a4d0dbe | 3023 | |
061cbb25 JM |
3024 | def test_ap_wpa2_eap_tls_domain_mismatch_cn(dev, apdev): |
3025 | """WPA2-Enterprise using EAP-TLS and domain mismatch (CN)""" | |
e78eb404 | 3026 | check_domain_match(dev[0]) |
061cbb25 JM |
3027 | params = int_eap_server_params() |
3028 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
3029 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
3030 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3031 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
3032 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3033 | private_key="auth_serv/user.pkcs12", | |
3034 | private_key_passwd="whatever", | |
3035 | domain_match="example.com", | |
3036 | wait_connect=False, | |
3037 | scan_freq="2412") | |
3038 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
3039 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3040 | private_key="auth_serv/user.pkcs12", | |
3041 | private_key_passwd="whatever", | |
3042 | domain_match="w1.fi", | |
3043 | wait_connect=False, | |
3044 | scan_freq="2412") | |
3045 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3046 | if ev is None: | |
3047 | raise Exception("Timeout on EAP failure report") | |
3048 | ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3049 | if ev is None: | |
3050 | raise Exception("Timeout on EAP failure report (2)") | |
3051 | ||
6a4d0dbe JM |
3052 | def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev): |
3053 | """WPA2-Enterprise using EAP-TTLS and expired certificate""" | |
ca158ea6 | 3054 | skip_with_fips(dev[0]) |
6a4d0dbe JM |
3055 | params = int_eap_server_params() |
3056 | params["server_cert"] = "auth_serv/server-expired.pem" | |
3057 | params["private_key"] = "auth_serv/server-expired.key" | |
3058 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3059 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3060 | identity="mschap user", password="password", | |
3061 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3062 | wait_connect=False, | |
3063 | scan_freq="2412") | |
3064 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"]) | |
3065 | if ev is None: | |
3066 | raise Exception("Timeout on EAP certificate error report") | |
3067 | if "reason=4" not in ev or "certificate has expired" not in ev: | |
3068 | raise Exception("Unexpected failure reason: " + ev) | |
3069 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3070 | if ev is None: | |
3071 | raise Exception("Timeout on EAP failure report") | |
3072 | ||
3073 | def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev): | |
3074 | """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration""" | |
ca158ea6 | 3075 | skip_with_fips(dev[0]) |
6a4d0dbe JM |
3076 | params = int_eap_server_params() |
3077 | params["server_cert"] = "auth_serv/server-expired.pem" | |
3078 | params["private_key"] = "auth_serv/server-expired.key" | |
3079 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3080 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3081 | identity="mschap user", password="password", | |
3082 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3083 | phase1="tls_disable_time_checks=1", | |
3084 | scan_freq="2412") | |
6ab4a7aa | 3085 | |
5748d1e5 JM |
3086 | def test_ap_wpa2_eap_ttls_long_duration(dev, apdev): |
3087 | """WPA2-Enterprise using EAP-TTLS and long certificate duration""" | |
ca158ea6 | 3088 | skip_with_fips(dev[0]) |
5748d1e5 JM |
3089 | params = int_eap_server_params() |
3090 | params["server_cert"] = "auth_serv/server-long-duration.pem" | |
3091 | params["private_key"] = "auth_serv/server-long-duration.key" | |
3092 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3093 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3094 | identity="mschap user", password="password", | |
3095 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3096 | scan_freq="2412") | |
3097 | ||
6ab4a7aa JM |
3098 | def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev): |
3099 | """WPA2-Enterprise using EAP-TTLS and server cert with client EKU""" | |
ca158ea6 | 3100 | skip_with_fips(dev[0]) |
6ab4a7aa JM |
3101 | params = int_eap_server_params() |
3102 | params["server_cert"] = "auth_serv/server-eku-client.pem" | |
3103 | params["private_key"] = "auth_serv/server-eku-client.key" | |
3104 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3105 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3106 | identity="mschap user", password="password", | |
3107 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3108 | wait_connect=False, | |
3109 | scan_freq="2412") | |
3110 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3111 | if ev is None: | |
3112 | raise Exception("Timeout on EAP failure report") | |
242219c5 | 3113 | |
14bef66d JM |
3114 | def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev): |
3115 | """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU""" | |
ca158ea6 | 3116 | skip_with_fips(dev[0]) |
14bef66d JM |
3117 | params = int_eap_server_params() |
3118 | params["server_cert"] = "auth_serv/server-eku-client-server.pem" | |
3119 | params["private_key"] = "auth_serv/server-eku-client-server.key" | |
3120 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3121 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3122 | identity="mschap user", password="password", | |
3123 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3124 | scan_freq="2412") | |
3125 | ||
c37b02fc JM |
3126 | def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev): |
3127 | """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file""" | |
ca158ea6 | 3128 | skip_with_fips(dev[0]) |
c37b02fc JM |
3129 | params = int_eap_server_params() |
3130 | del params["server_cert"] | |
3131 | params["private_key"] = "auth_serv/server.pkcs12" | |
3132 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3133 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3134 | identity="mschap user", password="password", | |
3135 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3136 | scan_freq="2412") | |
3137 | ||
242219c5 JM |
3138 | def test_ap_wpa2_eap_ttls_dh_params(dev, apdev): |
3139 | """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params""" | |
3140 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3141 | hostapd.add_ap(apdev[0]['ifname'], params) | |
ca158ea6 | 3142 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
242219c5 | 3143 | anonymous_identity="ttls", password="password", |
ca158ea6 | 3144 | ca_cert="auth_serv/ca.der", phase2="auth=PAP", |
242219c5 | 3145 | dh_file="auth_serv/dh.conf") |
7c50093f | 3146 | |
b3ff3dec JM |
3147 | def test_ap_wpa2_eap_ttls_dh_params_dsa(dev, apdev): |
3148 | """WPA2-Enterprise connection using EAP-TTLS and setting DH params (DSA)""" | |
404597e6 | 3149 | check_dh_dsa_support(dev[0]) |
b3ff3dec JM |
3150 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3151 | hostapd.add_ap(apdev[0]['ifname'], params) | |
ca158ea6 | 3152 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
b3ff3dec | 3153 | anonymous_identity="ttls", password="password", |
ca158ea6 | 3154 | ca_cert="auth_serv/ca.der", phase2="auth=PAP", |
b3ff3dec JM |
3155 | dh_file="auth_serv/dsaparam.pem") |
3156 | ||
3157 | def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev): | |
3158 | """EAP-TTLS and DH params file not found""" | |
ca158ea6 | 3159 | skip_with_fips(dev[0]) |
b3ff3dec JM |
3160 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3161 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3162 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3163 | identity="mschap user", password="password", | |
3164 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3165 | dh_file="auth_serv/dh-no-such-file.conf", | |
3166 | scan_freq="2412", wait_connect=False) | |
3167 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3168 | if ev is None: | |
3169 | raise Exception("EAP failure timed out") | |
3170 | dev[0].request("REMOVE_NETWORK all") | |
3171 | dev[0].wait_disconnected() | |
3172 | ||
3173 | def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev): | |
3174 | """EAP-TTLS and invalid DH params file""" | |
ca158ea6 | 3175 | skip_with_fips(dev[0]) |
b3ff3dec JM |
3176 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3177 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3178 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3179 | identity="mschap user", password="password", | |
3180 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3181 | dh_file="auth_serv/ca.pem", | |
3182 | scan_freq="2412", wait_connect=False) | |
3183 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3184 | if ev is None: | |
3185 | raise Exception("EAP failure timed out") | |
3186 | dev[0].request("REMOVE_NETWORK all") | |
3187 | dev[0].wait_disconnected() | |
3188 | ||
6ea231e6 JM |
3189 | def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev): |
3190 | """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob""" | |
3191 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3192 | hostapd.add_ap(apdev[0]['ifname'], params) | |
768ea0bc | 3193 | dh = read_pem("auth_serv/dh2.conf") |
6ea231e6 JM |
3194 | if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")): |
3195 | raise Exception("Could not set dhparams blob") | |
ca158ea6 | 3196 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
6ea231e6 | 3197 | anonymous_identity="ttls", password="password", |
ca158ea6 | 3198 | ca_cert="auth_serv/ca.der", phase2="auth=PAP", |
6ea231e6 JM |
3199 | dh_file="blob://dhparams") |
3200 | ||
768ea0bc JM |
3201 | def test_ap_wpa2_eap_ttls_dh_params_server(dev, apdev): |
3202 | """WPA2-Enterprise using EAP-TTLS and alternative server dhparams""" | |
3203 | params = int_eap_server_params() | |
3204 | params["dh_file"] = "auth_serv/dh2.conf" | |
3205 | hostapd.add_ap(apdev[0]['ifname'], params) | |
ca158ea6 | 3206 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
768ea0bc | 3207 | anonymous_identity="ttls", password="password", |
ca158ea6 | 3208 | ca_cert="auth_serv/ca.der", phase2="auth=PAP") |
768ea0bc | 3209 | |
b3ff3dec JM |
3210 | def test_ap_wpa2_eap_ttls_dh_params_dsa_server(dev, apdev): |
3211 | """WPA2-Enterprise using EAP-TTLS and alternative server dhparams (DSA)""" | |
3212 | params = int_eap_server_params() | |
3213 | params["dh_file"] = "auth_serv/dsaparam.pem" | |
3214 | hostapd.add_ap(apdev[0]['ifname'], params) | |
ca158ea6 | 3215 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
b3ff3dec | 3216 | anonymous_identity="ttls", password="password", |
ca158ea6 | 3217 | ca_cert="auth_serv/ca.der", phase2="auth=PAP") |
b3ff3dec JM |
3218 | |
3219 | def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev): | |
3220 | """EAP-TLS server and dhparams file not found""" | |
3221 | params = int_eap_server_params() | |
3222 | params["dh_file"] = "auth_serv/dh-no-such-file.conf" | |
3223 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True) | |
3224 | if "FAIL" not in hapd.request("ENABLE"): | |
3225 | raise Exception("Invalid configuration accepted") | |
3226 | ||
3227 | def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev): | |
3228 | """EAP-TLS server and invalid dhparams file""" | |
3229 | params = int_eap_server_params() | |
3230 | params["dh_file"] = "auth_serv/ca.pem" | |
3231 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True) | |
3232 | if "FAIL" not in hapd.request("ENABLE"): | |
3233 | raise Exception("Invalid configuration accepted") | |
3234 | ||
7c50093f JM |
3235 | def test_ap_wpa2_eap_reauth(dev, apdev): |
3236 | """WPA2-Enterprise and Authenticator forcing reauthentication""" | |
3237 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3238 | params['eap_reauth_period'] = '2' | |
3239 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3240 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", | |
3241 | password_hex="0123456789abcdef0123456789abcdef") | |
3242 | logger.info("Wait for reauthentication") | |
3243 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
3244 | if ev is None: | |
3245 | raise Exception("Timeout on reauthentication") | |
3246 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
3247 | if ev is None: | |
3248 | raise Exception("Timeout on reauthentication") | |
3249 | for i in range(0, 20): | |
3250 | state = dev[0].get_status_field("wpa_state") | |
3251 | if state == "COMPLETED": | |
3252 | break | |
3253 | time.sleep(0.1) | |
3254 | if state != "COMPLETED": | |
3255 | raise Exception("Reauthentication did not complete") | |
8b56743e JM |
3256 | |
3257 | def test_ap_wpa2_eap_request_identity_message(dev, apdev): | |
3258 | """Optional displayable message in EAP Request-Identity""" | |
3259 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3260 | params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com' | |
3261 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3262 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", | |
3263 | password_hex="0123456789abcdef0123456789abcdef") | |
910f16ca JM |
3264 | |
3265 | def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev): | |
3266 | """WPA2-Enterprise using EAP-SIM/AKA and protected result indication""" | |
81e787b7 | 3267 | check_hlr_auc_gw_support() |
910f16ca JM |
3268 | params = int_eap_server_params() |
3269 | params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock" | |
3270 | params['eap_sim_aka_result_ind'] = "1" | |
3271 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3272 | ||
3273 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
3274 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
3275 | phase1="result_ind=1") | |
3276 | eap_reauth(dev[0], "SIM") | |
3277 | eap_connect(dev[1], apdev[0], "SIM", "1232010000000000", | |
3278 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
3279 | ||
3280 | dev[0].request("REMOVE_NETWORK all") | |
3281 | dev[1].request("REMOVE_NETWORK all") | |
3282 | ||
3283 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
3284 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
3285 | phase1="result_ind=1") | |
3286 | eap_reauth(dev[0], "AKA") | |
3287 | eap_connect(dev[1], apdev[0], "AKA", "0232010000000000", | |
3288 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") | |
3289 | ||
3290 | dev[0].request("REMOVE_NETWORK all") | |
3291 | dev[1].request("REMOVE_NETWORK all") | |
3292 | ||
3293 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
3294 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
3295 | phase1="result_ind=1") | |
3296 | eap_reauth(dev[0], "AKA'") | |
3297 | eap_connect(dev[1], apdev[0], "AKA'", "6555444333222111", | |
3298 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") | |
633e364b JM |
3299 | |
3300 | def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev): | |
3301 | """WPA2-Enterprise connection resulting in too many EAP roundtrips""" | |
ca158ea6 | 3302 | skip_with_fips(dev[0]) |
633e364b JM |
3303 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3304 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3305 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
3306 | eap="TTLS", identity="mschap user", | |
3307 | wait_connect=False, scan_freq="2412", ieee80211w="1", | |
3308 | anonymous_identity="ttls", password="password", | |
3309 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3310 | fragment_size="10") | |
3311 | ev = dev[0].wait_event(["EAP: more than"], timeout=20) | |
3312 | if ev is None: | |
3313 | raise Exception("EAP roundtrip limit not reached") | |
32dca985 JM |
3314 | |
3315 | def test_ap_wpa2_eap_expanded_nak(dev, apdev): | |
3316 | """WPA2-Enterprise connection with EAP resulting in expanded NAK""" | |
3317 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3318 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3319 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
3320 | eap="PSK", identity="vendor-test", | |
3321 | password_hex="ff23456789abcdef0123456789abcdef", | |
3322 | wait_connect=False) | |
3323 | ||
3324 | found = False | |
3325 | for i in range(0, 5): | |
3326 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=10) | |
3327 | if ev is None: | |
3328 | raise Exception("Association and EAP start timed out") | |
3329 | if "refuse proposed method" in ev: | |
3330 | found = True | |
3331 | break | |
3332 | if not found: | |
3333 | raise Exception("Unexpected EAP status: " + ev) | |
3334 | ||
3335 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
3336 | if ev is None: | |
3337 | raise Exception("EAP failure timed out") | |
745f8771 JM |
3338 | |
3339 | def test_ap_wpa2_eap_sql(dev, apdev, params): | |
3340 | """WPA2-Enterprise connection using SQLite for user DB""" | |
ca158ea6 | 3341 | skip_with_fips(dev[0]) |
745f8771 JM |
3342 | try: |
3343 | import sqlite3 | |
3344 | except ImportError: | |
81e787b7 | 3345 | raise HwsimSkip("No sqlite3 module available") |
745f8771 JM |
3346 | dbfile = os.path.join(params['logdir'], "eap-user.db") |
3347 | try: | |
3348 | os.remove(dbfile) | |
3349 | except: | |
3350 | pass | |
3351 | con = sqlite3.connect(dbfile) | |
3352 | with con: | |
3353 | cur = con.cursor() | |
3354 | cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)") | |
3355 | cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)") | |
3356 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-pap','TTLS-PAP','password',1)") | |
3357 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-chap','TTLS-CHAP','password',1)") | |
3358 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschap','TTLS-MSCHAP','password',1)") | |
3359 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1)") | |
3360 | cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')") | |
3361 | cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)") | |
3362 | ||
3363 | try: | |
3364 | params = int_eap_server_params() | |
3365 | params["eap_user_file"] = "sqlite:" + dbfile | |
3366 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3367 | eap_connect(dev[0], apdev[0], "TTLS", "user-mschapv2", | |
3368 | anonymous_identity="ttls", password="password", | |
3369 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
3370 | dev[0].request("REMOVE_NETWORK all") | |
3371 | eap_connect(dev[1], apdev[0], "TTLS", "user-mschap", | |
3372 | anonymous_identity="ttls", password="password", | |
3373 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP") | |
3374 | dev[1].request("REMOVE_NETWORK all") | |
3375 | eap_connect(dev[0], apdev[0], "TTLS", "user-chap", | |
3376 | anonymous_identity="ttls", password="password", | |
3377 | ca_cert="auth_serv/ca.pem", phase2="auth=CHAP") | |
3378 | eap_connect(dev[1], apdev[0], "TTLS", "user-pap", | |
3379 | anonymous_identity="ttls", password="password", | |
3380 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
3381 | finally: | |
3382 | os.remove(dbfile) | |
b246e2af JM |
3383 | |
3384 | def test_ap_wpa2_eap_non_ascii_identity(dev, apdev): | |
3385 | """WPA2-Enterprise connection attempt using non-ASCII identity""" | |
3386 | params = int_eap_server_params() | |
3387 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3388 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3389 | identity="\x80", password="password", wait_connect=False) | |
3390 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3391 | identity="a\x80", password="password", wait_connect=False) | |
3392 | for i in range(0, 2): | |
3393 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
3394 | if ev is None: | |
3395 | raise Exception("Association and EAP start timed out") | |
3396 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
3397 | if ev is None: | |
3398 | raise Exception("EAP method selection timed out") | |
3399 | ||
3400 | def test_ap_wpa2_eap_non_ascii_identity2(dev, apdev): | |
3401 | """WPA2-Enterprise connection attempt using non-ASCII identity""" | |
3402 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3403 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3404 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3405 | identity="\x80", password="password", wait_connect=False) | |
3406 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
3407 | identity="a\x80", password="password", wait_connect=False) | |
3408 | for i in range(0, 2): | |
3409 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
3410 | if ev is None: | |
3411 | raise Exception("Association and EAP start timed out") | |
3412 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
3413 | if ev is None: | |
3414 | raise Exception("EAP method selection timed out") | |
89f20842 JM |
3415 | |
3416 | def test_openssl_cipher_suite_config_wpas(dev, apdev): | |
3417 | """OpenSSL cipher suite configuration on wpa_supplicant""" | |
a783340d JM |
3418 | tls = dev[0].request("GET tls_library") |
3419 | if not tls.startswith("OpenSSL"): | |
3420 | raise HwsimSkip("TLS library is not OpenSSL: " + tls) | |
89f20842 JM |
3421 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
3422 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3423 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
3424 | anonymous_identity="ttls", password="password", | |
3425 | openssl_ciphers="AES128", | |
3426 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
3427 | eap_connect(dev[1], apdev[0], "TTLS", "pap user", | |
3428 | anonymous_identity="ttls", password="password", | |
3429 | openssl_ciphers="EXPORT", | |
3430 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
9dd21d51 | 3431 | expect_failure=True, maybe_local_error=True) |
7be5ec99 JM |
3432 | dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
3433 | identity="pap user", anonymous_identity="ttls", | |
3434 | password="password", | |
3435 | openssl_ciphers="FOO", | |
3436 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
3437 | wait_connect=False) | |
3438 | ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
3439 | if ev is None: | |
3440 | raise Exception("EAP failure after invalid openssl_ciphers not reported") | |
3441 | dev[2].request("DISCONNECT") | |
89f20842 JM |
3442 | |
3443 | def test_openssl_cipher_suite_config_hapd(dev, apdev): | |
3444 | """OpenSSL cipher suite configuration on hostapd""" | |
a783340d JM |
3445 | tls = dev[0].request("GET tls_library") |
3446 | if not tls.startswith("OpenSSL"): | |
3447 | raise HwsimSkip("wpa_supplicant TLS library is not OpenSSL: " + tls) | |
89f20842 JM |
3448 | params = int_eap_server_params() |
3449 | params['openssl_ciphers'] = "AES256" | |
3450 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
a783340d JM |
3451 | tls = hapd.request("GET tls_library") |
3452 | if not tls.startswith("OpenSSL"): | |
3453 | raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls) | |
89f20842 JM |
3454 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
3455 | anonymous_identity="ttls", password="password", | |
3456 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
3457 | eap_connect(dev[1], apdev[0], "TTLS", "pap user", | |
3458 | anonymous_identity="ttls", password="password", | |
3459 | openssl_ciphers="AES128", | |
3460 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
3461 | expect_failure=True) | |
3462 | eap_connect(dev[2], apdev[0], "TTLS", "pap user", | |
3463 | anonymous_identity="ttls", password="password", | |
3464 | openssl_ciphers="HIGH:!ADH", | |
3465 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
5b3c40a6 | 3466 | |
7be5ec99 JM |
3467 | params['openssl_ciphers'] = "FOO" |
3468 | hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, no_enable=True) | |
3469 | if "FAIL" not in hapd2.request("ENABLE"): | |
3470 | raise Exception("Invalid openssl_ciphers value accepted") | |
3471 | ||
5b3c40a6 JM |
3472 | def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params): |
3473 | """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP""" | |
3474 | p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3475 | hapd = hostapd.add_ap(apdev[0]['ifname'], p) | |
3476 | password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25" | |
3477 | pid = find_wpas_process(dev[0]) | |
3478 | id = eap_connect(dev[0], apdev[0], "TTLS", "pap-secret", | |
3479 | anonymous_identity="ttls", password=password, | |
3480 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
8e416cec JM |
3481 | # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED |
3482 | # event has been delivered, so verify that wpa_supplicant has returned to | |
3483 | # eloop before reading process memory. | |
54f2cae2 | 3484 | time.sleep(1) |
8e416cec | 3485 | dev[0].ping() |
5b3c40a6 JM |
3486 | buf = read_process_memory(pid, password) |
3487 | ||
3488 | dev[0].request("DISCONNECT") | |
3489 | dev[0].wait_disconnected() | |
3490 | ||
3491 | dev[0].relog() | |
750904dd JM |
3492 | msk = None |
3493 | emsk = None | |
5b3c40a6 JM |
3494 | pmk = None |
3495 | ptk = None | |
3496 | gtk = None | |
3497 | with open(os.path.join(params['logdir'], 'log0'), 'r') as f: | |
3498 | for l in f.readlines(): | |
750904dd JM |
3499 | if "EAP-TTLS: Derived key - hexdump" in l: |
3500 | val = l.strip().split(':')[3].replace(' ', '') | |
3501 | msk = binascii.unhexlify(val) | |
3502 | if "EAP-TTLS: Derived EMSK - hexdump" in l: | |
3503 | val = l.strip().split(':')[3].replace(' ', '') | |
3504 | emsk = binascii.unhexlify(val) | |
5b3c40a6 JM |
3505 | if "WPA: PMK - hexdump" in l: |
3506 | val = l.strip().split(':')[3].replace(' ', '') | |
3507 | pmk = binascii.unhexlify(val) | |
3508 | if "WPA: PTK - hexdump" in l: | |
3509 | val = l.strip().split(':')[3].replace(' ', '') | |
3510 | ptk = binascii.unhexlify(val) | |
3511 | if "WPA: Group Key - hexdump" in l: | |
3512 | val = l.strip().split(':')[3].replace(' ', '') | |
3513 | gtk = binascii.unhexlify(val) | |
750904dd | 3514 | if not msk or not emsk or not pmk or not ptk or not gtk: |
5b3c40a6 JM |
3515 | raise Exception("Could not find keys from debug log") |
3516 | if len(gtk) != 16: | |
3517 | raise Exception("Unexpected GTK length") | |
3518 | ||
3519 | kck = ptk[0:16] | |
3520 | kek = ptk[16:32] | |
3521 | tk = ptk[32:48] | |
3522 | ||
3523 | fname = os.path.join(params['logdir'], | |
3524 | 'wpa2_eap_ttls_pap_key_lifetime_in_memory.memctx-') | |
3525 | ||
3526 | logger.info("Checking keys in memory while associated") | |
3527 | get_key_locations(buf, password, "Password") | |
3528 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
3529 | get_key_locations(buf, msk, "MSK") |
3530 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 | 3531 | if password not in buf: |
81e787b7 | 3532 | raise HwsimSkip("Password not found while associated") |
5b3c40a6 | 3533 | if pmk not in buf: |
81e787b7 | 3534 | raise HwsimSkip("PMK not found while associated") |
5b3c40a6 JM |
3535 | if kck not in buf: |
3536 | raise Exception("KCK not found while associated") | |
3537 | if kek not in buf: | |
3538 | raise Exception("KEK not found while associated") | |
3539 | if tk in buf: | |
3540 | raise Exception("TK found from memory") | |
3541 | if gtk in buf: | |
8eb45bde | 3542 | get_key_locations(buf, gtk, "GTK") |
5b3c40a6 JM |
3543 | raise Exception("GTK found from memory") |
3544 | ||
3545 | logger.info("Checking keys in memory after disassociation") | |
3546 | buf = read_process_memory(pid, password) | |
3547 | ||
3548 | # Note: Password is still present in network configuration | |
3549 | # Note: PMK is in PMKSA cache and EAP fast re-auth data | |
3550 | ||
3551 | get_key_locations(buf, password, "Password") | |
3552 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
3553 | get_key_locations(buf, msk, "MSK") |
3554 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 JM |
3555 | verify_not_present(buf, kck, fname, "KCK") |
3556 | verify_not_present(buf, kek, fname, "KEK") | |
3557 | verify_not_present(buf, tk, fname, "TK") | |
3558 | verify_not_present(buf, gtk, fname, "GTK") | |
3559 | ||
3560 | dev[0].request("PMKSA_FLUSH") | |
3561 | dev[0].set_network_quoted(id, "identity", "foo") | |
3562 | logger.info("Checking keys in memory after PMKSA cache and EAP fast reauth flush") | |
3563 | buf = read_process_memory(pid, password) | |
3564 | get_key_locations(buf, password, "Password") | |
3565 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
3566 | get_key_locations(buf, msk, "MSK") |
3567 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 JM |
3568 | verify_not_present(buf, pmk, fname, "PMK") |
3569 | ||
3570 | dev[0].request("REMOVE_NETWORK all") | |
3571 | ||
3572 | logger.info("Checking keys in memory after network profile removal") | |
3573 | buf = read_process_memory(pid, password) | |
3574 | ||
3575 | get_key_locations(buf, password, "Password") | |
3576 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
3577 | get_key_locations(buf, msk, "MSK") |
3578 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 JM |
3579 | verify_not_present(buf, password, fname, "password") |
3580 | verify_not_present(buf, pmk, fname, "PMK") | |
3581 | verify_not_present(buf, kck, fname, "KCK") | |
3582 | verify_not_present(buf, kek, fname, "KEK") | |
3583 | verify_not_present(buf, tk, fname, "TK") | |
3584 | verify_not_present(buf, gtk, fname, "GTK") | |
750904dd JM |
3585 | verify_not_present(buf, msk, fname, "MSK") |
3586 | verify_not_present(buf, emsk, fname, "EMSK") | |
a08fdb17 JM |
3587 | |
3588 | def test_ap_wpa2_eap_unexpected_wep_eapol_key(dev, apdev): | |
3589 | """WPA2-Enterprise connection and unexpected WEP EAPOL-Key""" | |
3590 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3591 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3592 | bssid = apdev[0]['bssid'] | |
3593 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
3594 | anonymous_identity="ttls", password="password", | |
3595 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
3596 | ||
3597 | # Send unexpected WEP EAPOL-Key; this gets dropped | |
3598 | res = dev[0].request("EAPOL_RX " + bssid + " 0203002c0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000") | |
3599 | if "OK" not in res: | |
3600 | raise Exception("EAPOL_RX to wpa_supplicant failed") | |
52352802 JM |
3601 | |
3602 | def test_ap_wpa2_eap_in_bridge(dev, apdev): | |
3603 | """WPA2-EAP and wpas interface in a bridge""" | |
3604 | br_ifname='sta-br0' | |
3605 | ifname='wlan5' | |
3606 | try: | |
3607 | _test_ap_wpa2_eap_in_bridge(dev, apdev) | |
3608 | finally: | |
3609 | subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down']) | |
3610 | subprocess.call(['brctl', 'delif', br_ifname, ifname]) | |
3611 | subprocess.call(['brctl', 'delbr', br_ifname]) | |
3612 | subprocess.call(['iw', ifname, 'set', '4addr', 'off']) | |
3613 | ||
3614 | def _test_ap_wpa2_eap_in_bridge(dev, apdev): | |
3615 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3616 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3617 | ||
3618 | br_ifname='sta-br0' | |
3619 | ifname='wlan5' | |
3620 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
3621 | subprocess.call(['brctl', 'addbr', br_ifname]) | |
3622 | subprocess.call(['brctl', 'setfd', br_ifname, '0']) | |
3623 | subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) | |
3624 | subprocess.call(['iw', ifname, 'set', '4addr', 'on']) | |
3625 | subprocess.check_call(['brctl', 'addif', br_ifname, ifname]) | |
3626 | wpas.interface_add(ifname, br_ifname=br_ifname) | |
4b9d79b6 | 3627 | wpas.dump_monitor() |
52352802 JM |
3628 | |
3629 | id = eap_connect(wpas, apdev[0], "PAX", "pax.user@example.com", | |
3630 | password_hex="0123456789abcdef0123456789abcdef") | |
4b9d79b6 | 3631 | wpas.dump_monitor() |
52352802 | 3632 | eap_reauth(wpas, "PAX") |
4b9d79b6 | 3633 | wpas.dump_monitor() |
52352802 JM |
3634 | # Try again as a regression test for packet socket workaround |
3635 | eap_reauth(wpas, "PAX") | |
4b9d79b6 | 3636 | wpas.dump_monitor() |
52352802 JM |
3637 | wpas.request("DISCONNECT") |
3638 | wpas.wait_disconnected() | |
4b9d79b6 | 3639 | wpas.dump_monitor() |
52352802 JM |
3640 | wpas.request("RECONNECT") |
3641 | wpas.wait_connected() | |
4b9d79b6 | 3642 | wpas.dump_monitor() |
febf5752 JM |
3643 | |
3644 | def test_ap_wpa2_eap_session_ticket(dev, apdev): | |
3645 | """WPA2-Enterprise connection using EAP-TTLS and TLS session ticket enabled""" | |
3646 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3647 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3648 | key_mgmt = hapd.get_config()['key_mgmt'] | |
3649 | if key_mgmt.split(' ')[0] != "WPA-EAP": | |
3650 | raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt) | |
3651 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
3652 | anonymous_identity="ttls", password="password", | |
3653 | ca_cert="auth_serv/ca.pem", | |
3654 | phase1="tls_disable_session_ticket=0", phase2="auth=PAP") | |
3655 | eap_reauth(dev[0], "TTLS") | |
3656 | ||
3657 | def test_ap_wpa2_eap_no_workaround(dev, apdev): | |
3658 | """WPA2-Enterprise connection using EAP-TTLS and eap_workaround=0""" | |
3659 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3660 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3661 | key_mgmt = hapd.get_config()['key_mgmt'] | |
3662 | if key_mgmt.split(' ')[0] != "WPA-EAP": | |
3663 | raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt) | |
3664 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
3665 | anonymous_identity="ttls", password="password", | |
3666 | ca_cert="auth_serv/ca.pem", eap_workaround='0', | |
3667 | phase2="auth=PAP") | |
3668 | eap_reauth(dev[0], "TTLS") | |
b197a819 JM |
3669 | |
3670 | def test_ap_wpa2_eap_tls_check_crl(dev, apdev): | |
3671 | """EAP-TLS and server checking CRL""" | |
3672 | params = int_eap_server_params() | |
3673 | params['check_crl'] = '1' | |
3674 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3675 | ||
3676 | # check_crl=1 and no CRL available --> reject connection | |
3677 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
3678 | client_cert="auth_serv/user.pem", | |
3679 | private_key="auth_serv/user.key", expect_failure=True) | |
3680 | dev[0].request("REMOVE_NETWORK all") | |
3681 | ||
3682 | hapd.disable() | |
3683 | hapd.set("ca_cert", "auth_serv/ca-and-crl.pem") | |
3684 | hapd.enable() | |
3685 | ||
3686 | # check_crl=1 and valid CRL --> accept | |
3687 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
3688 | client_cert="auth_serv/user.pem", | |
3689 | private_key="auth_serv/user.key") | |
3690 | dev[0].request("REMOVE_NETWORK all") | |
3691 | ||
3692 | hapd.disable() | |
3693 | hapd.set("check_crl", "2") | |
3694 | hapd.enable() | |
3695 | ||
3696 | # check_crl=2 and valid CRL --> accept | |
3697 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
3698 | client_cert="auth_serv/user.pem", | |
3699 | private_key="auth_serv/user.key") | |
3700 | dev[0].request("REMOVE_NETWORK all") | |
b1fb4275 JM |
3701 | |
3702 | def test_ap_wpa2_eap_tls_oom(dev, apdev): | |
3703 | """EAP-TLS and OOM""" | |
3704 | check_subject_match_support(dev[0]) | |
3705 | check_altsubject_match_support(dev[0]) | |
e78eb404 | 3706 | check_domain_match(dev[0]) |
b1fb4275 JM |
3707 | check_domain_match_full(dev[0]) |
3708 | ||
3709 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3710 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3711 | ||
3712 | tests = [ (1, "tls_connection_set_subject_match"), | |
3713 | (2, "tls_connection_set_subject_match"), | |
3714 | (3, "tls_connection_set_subject_match"), | |
3715 | (4, "tls_connection_set_subject_match") ] | |
3716 | for count, func in tests: | |
3717 | with alloc_fail(dev[0], count, func): | |
3718 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
3719 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3720 | client_cert="auth_serv/user.pem", | |
3721 | private_key="auth_serv/user.key", | |
3722 | subject_match="/C=FI/O=w1.fi/CN=server.w1.fi", | |
3723 | altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/", | |
3724 | domain_suffix_match="server.w1.fi", | |
3725 | domain_match="server.w1.fi", | |
3726 | wait_connect=False, scan_freq="2412") | |
3727 | # TLS parameter configuration error results in CTRL-REQ-PASSPHRASE | |
3728 | ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"], timeout=5) | |
3729 | if ev is None: | |
3730 | raise Exception("No passphrase request") | |
3731 | dev[0].request("REMOVE_NETWORK all") | |
3732 | dev[0].wait_disconnected() | |
405c621c JM |
3733 | |
3734 | def test_ap_wpa2_eap_tls_macacl(dev, apdev): | |
3735 | """WPA2-Enterprise connection using MAC ACL""" | |
3736 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3737 | params["macaddr_acl"] = "2" | |
3738 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3739 | eap_connect(dev[1], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
3740 | client_cert="auth_serv/user.pem", | |
3741 | private_key="auth_serv/user.key") | |
85774b70 JM |
3742 | |
3743 | def test_ap_wpa2_eap_oom(dev, apdev): | |
3744 | """EAP server and OOM""" | |
3745 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3746 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3747 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3748 | ||
3749 | with alloc_fail(hapd, 1, "eapol_auth_alloc"): | |
3750 | # The first attempt fails, but STA will send EAPOL-Start to retry and | |
3751 | # that succeeds. | |
3752 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
3753 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
3754 | client_cert="auth_serv/user.pem", | |
3755 | private_key="auth_serv/user.key", | |
3756 | scan_freq="2412") | |
6c4b5da4 JM |
3757 | |
3758 | def check_tls_ver(dev, ap, phase1, expected): | |
3759 | eap_connect(dev, ap, "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
3760 | client_cert="auth_serv/user.pem", | |
3761 | private_key="auth_serv/user.key", | |
3762 | phase1=phase1) | |
3763 | ver = dev.get_status_field("eap_tls_version") | |
3764 | if ver != expected: | |
3765 | raise Exception("Unexpected TLS version (expected %s): %s" % (expected, ver)) | |
3766 | ||
3767 | def test_ap_wpa2_eap_tls_versions(dev, apdev): | |
3768 | """EAP-TLS and TLS version configuration""" | |
3769 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3770 | hostapd.add_ap(apdev[0]['ifname'], params) | |
3771 | ||
3772 | tls = dev[0].request("GET tls_library") | |
3773 | if tls.startswith("OpenSSL"): | |
3774 | if "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls: | |
3775 | check_tls_ver(dev[0], apdev[0], | |
3776 | "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1", | |
3777 | "TLSv1.2") | |
2286578f JM |
3778 | elif tls.startswith("internal"): |
3779 | check_tls_ver(dev[0], apdev[0], | |
3780 | "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1", "TLSv1.2") | |
6c4b5da4 JM |
3781 | check_tls_ver(dev[1], apdev[0], |
3782 | "tls_disable_tlsv1_0=1 tls_disable_tlsv1_2=1", "TLSv1.1") | |
3783 | check_tls_ver(dev[2], apdev[0], | |
3784 | "tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1", "TLSv1") | |
ecafa0cf JM |
3785 | |
3786 | def test_rsn_ie_proto_eap_sta(dev, apdev): | |
3787 | """RSN element protocol testing for EAP cases on STA side""" | |
3788 | bssid = apdev[0]['bssid'] | |
3789 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
3790 | # This is the RSN element used normally by hostapd | |
3791 | params['own_ie_override'] = '30140100000fac040100000fac040100000fac010c00' | |
3792 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3793 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
3794 | identity="gpsk user", | |
3795 | password="abcdefghijklmnop0123456789abcdef", | |
3796 | scan_freq="2412") | |
3797 | ||
3798 | tests = [ ('No RSN Capabilities field', | |
3799 | '30120100000fac040100000fac040100000fac01'), | |
3800 | ('No AKM Suite fields', | |
3801 | '300c0100000fac040100000fac04'), | |
3802 | ('No Pairwise Cipher Suite fields', | |
3803 | '30060100000fac04'), | |
3804 | ('No Group Data Cipher Suite field', | |
3805 | '30020100') ] | |
3806 | for txt,ie in tests: | |
3807 | dev[0].request("DISCONNECT") | |
3808 | dev[0].wait_disconnected() | |
3809 | logger.info(txt) | |
3810 | hapd.disable() | |
3811 | hapd.set('own_ie_override', ie) | |
3812 | hapd.enable() | |
3813 | dev[0].request("BSS_FLUSH 0") | |
3814 | dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True) | |
3815 | dev[0].select_network(id, freq=2412) | |
3816 | dev[0].wait_connected() | |
f9dd43ea JM |
3817 | |
3818 | def check_tls_session_resumption_capa(dev, hapd): | |
3819 | tls = hapd.request("GET tls_library") | |
3820 | if not tls.startswith("OpenSSL"): | |
3821 | raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls) | |
3822 | ||
3823 | tls = dev.request("GET tls_library") | |
3824 | if not tls.startswith("OpenSSL"): | |
3825 | raise HwsimSkip("Session resumption not supported with this TLS library: " + tls) | |
3826 | ||
3827 | def test_eap_ttls_pap_session_resumption(dev, apdev): | |
3828 | """EAP-TTLS/PAP session resumption""" | |
3829 | params = int_eap_server_params() | |
3830 | params['tls_session_lifetime'] = '60' | |
3831 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3832 | check_tls_session_resumption_capa(dev[0], hapd) | |
3833 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
3834 | anonymous_identity="ttls", password="password", | |
3835 | ca_cert="auth_serv/ca.pem", eap_workaround='0', | |
3836 | phase2="auth=PAP") | |
3837 | if dev[0].get_status_field("tls_session_reused") != '0': | |
3838 | raise Exception("Unexpected session resumption on the first connection") | |
3839 | ||
3840 | dev[0].request("REAUTHENTICATE") | |
3841 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
3842 | if ev is None: | |
3843 | raise Exception("EAP success timed out") | |
3844 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
3845 | if ev is None: | |
3846 | raise Exception("Key handshake with the AP timed out") | |
3847 | if dev[0].get_status_field("tls_session_reused") != '1': | |
3848 | raise Exception("Session resumption not used on the second connection") | |
3849 | ||
3850 | def test_eap_ttls_chap_session_resumption(dev, apdev): | |
3851 | """EAP-TTLS/CHAP session resumption""" | |
3852 | params = int_eap_server_params() | |
3853 | params['tls_session_lifetime'] = '60' | |
3854 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3855 | check_tls_session_resumption_capa(dev[0], hapd) | |
3856 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", | |
3857 | anonymous_identity="ttls", password="password", | |
3858 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP") | |
3859 | if dev[0].get_status_field("tls_session_reused") != '0': | |
3860 | raise Exception("Unexpected session resumption on the first connection") | |
3861 | ||
3862 | dev[0].request("REAUTHENTICATE") | |
3863 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
3864 | if ev is None: | |
3865 | raise Exception("EAP success timed out") | |
3866 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
3867 | if ev is None: | |
3868 | raise Exception("Key handshake with the AP timed out") | |
3869 | if dev[0].get_status_field("tls_session_reused") != '1': | |
3870 | raise Exception("Session resumption not used on the second connection") | |
3871 | ||
3872 | def test_eap_ttls_mschap_session_resumption(dev, apdev): | |
3873 | """EAP-TTLS/MSCHAP session resumption""" | |
e78eb404 | 3874 | check_domain_suffix_match(dev[0]) |
f9dd43ea JM |
3875 | params = int_eap_server_params() |
3876 | params['tls_session_lifetime'] = '60' | |
3877 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3878 | check_tls_session_resumption_capa(dev[0], hapd) | |
3879 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", | |
3880 | anonymous_identity="ttls", password="password", | |
3881 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
3882 | domain_suffix_match="server.w1.fi") | |
3883 | if dev[0].get_status_field("tls_session_reused") != '0': | |
3884 | raise Exception("Unexpected session resumption on the first connection") | |
3885 | ||
3886 | dev[0].request("REAUTHENTICATE") | |
3887 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
3888 | if ev is None: | |
3889 | raise Exception("EAP success timed out") | |
3890 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
3891 | if ev is None: | |
3892 | raise Exception("Key handshake with the AP timed out") | |
3893 | if dev[0].get_status_field("tls_session_reused") != '1': | |
3894 | raise Exception("Session resumption not used on the second connection") | |
3895 | ||
3896 | def test_eap_ttls_mschapv2_session_resumption(dev, apdev): | |
3897 | """EAP-TTLS/MSCHAPv2 session resumption""" | |
e78eb404 | 3898 | check_domain_suffix_match(dev[0]) |
f9dd43ea JM |
3899 | check_eap_capa(dev[0], "MSCHAPV2") |
3900 | params = int_eap_server_params() | |
3901 | params['tls_session_lifetime'] = '60' | |
3902 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3903 | check_tls_session_resumption_capa(dev[0], hapd) | |
3904 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
3905 | anonymous_identity="ttls", password="password", | |
3906 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
3907 | domain_suffix_match="server.w1.fi") | |
3908 | if dev[0].get_status_field("tls_session_reused") != '0': | |
3909 | raise Exception("Unexpected session resumption on the first connection") | |
3910 | ||
3911 | dev[0].request("REAUTHENTICATE") | |
3912 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
3913 | if ev is None: | |
3914 | raise Exception("EAP success timed out") | |
3915 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
3916 | if ev is None: | |
3917 | raise Exception("Key handshake with the AP timed out") | |
3918 | if dev[0].get_status_field("tls_session_reused") != '1': | |
3919 | raise Exception("Session resumption not used on the second connection") | |
3920 | ||
3921 | def test_eap_ttls_eap_gtc_session_resumption(dev, apdev): | |
3922 | """EAP-TTLS/EAP-GTC session resumption""" | |
3923 | params = int_eap_server_params() | |
3924 | params['tls_session_lifetime'] = '60' | |
3925 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3926 | check_tls_session_resumption_capa(dev[0], hapd) | |
3927 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
3928 | anonymous_identity="ttls", password="password", | |
3929 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC") | |
3930 | if dev[0].get_status_field("tls_session_reused") != '0': | |
3931 | raise Exception("Unexpected session resumption on the first connection") | |
3932 | ||
3933 | dev[0].request("REAUTHENTICATE") | |
3934 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
3935 | if ev is None: | |
3936 | raise Exception("EAP success timed out") | |
3937 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
3938 | if ev is None: | |
3939 | raise Exception("Key handshake with the AP timed out") | |
3940 | if dev[0].get_status_field("tls_session_reused") != '1': | |
3941 | raise Exception("Session resumption not used on the second connection") | |
3942 | ||
3943 | def test_eap_ttls_no_session_resumption(dev, apdev): | |
3944 | """EAP-TTLS session resumption disabled on server""" | |
3945 | params = int_eap_server_params() | |
3946 | params['tls_session_lifetime'] = '0' | |
3947 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3948 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
3949 | anonymous_identity="ttls", password="password", | |
3950 | ca_cert="auth_serv/ca.pem", eap_workaround='0', | |
3951 | phase2="auth=PAP") | |
3952 | if dev[0].get_status_field("tls_session_reused") != '0': | |
3953 | raise Exception("Unexpected session resumption on the first connection") | |
3954 | ||
3955 | dev[0].request("REAUTHENTICATE") | |
3956 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
3957 | if ev is None: | |
3958 | raise Exception("EAP success timed out") | |
3959 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
3960 | if ev is None: | |
3961 | raise Exception("Key handshake with the AP timed out") | |
3962 | if dev[0].get_status_field("tls_session_reused") != '0': | |
3963 | raise Exception("Unexpected session resumption on the second connection") | |
3964 | ||
3965 | def test_eap_peap_session_resumption(dev, apdev): | |
3966 | """EAP-PEAP session resumption""" | |
3967 | params = int_eap_server_params() | |
3968 | params['tls_session_lifetime'] = '60' | |
3969 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3970 | check_tls_session_resumption_capa(dev[0], hapd) | |
3971 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
3972 | anonymous_identity="peap", password="password", | |
3973 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
3974 | if dev[0].get_status_field("tls_session_reused") != '0': | |
3975 | raise Exception("Unexpected session resumption on the first connection") | |
3976 | ||
3977 | dev[0].request("REAUTHENTICATE") | |
3978 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
3979 | if ev is None: | |
3980 | raise Exception("EAP success timed out") | |
3981 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
3982 | if ev is None: | |
3983 | raise Exception("Key handshake with the AP timed out") | |
3984 | if dev[0].get_status_field("tls_session_reused") != '1': | |
3985 | raise Exception("Session resumption not used on the second connection") | |
3986 | ||
81e1ab85 JM |
3987 | def test_eap_peap_session_resumption_crypto_binding(dev, apdev): |
3988 | """EAP-PEAP session resumption with crypto binding""" | |
3989 | params = int_eap_server_params() | |
3990 | params['tls_session_lifetime'] = '60' | |
3991 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3992 | check_tls_session_resumption_capa(dev[0], hapd) | |
3993 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
3994 | anonymous_identity="peap", password="password", | |
3995 | phase1="peapver=0 crypto_binding=2", | |
3996 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
3997 | if dev[0].get_status_field("tls_session_reused") != '0': | |
3998 | raise Exception("Unexpected session resumption on the first connection") | |
3999 | ||
4000 | dev[0].request("REAUTHENTICATE") | |
4001 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4002 | if ev is None: | |
4003 | raise Exception("EAP success timed out") | |
4004 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
4005 | if ev is None: | |
4006 | raise Exception("Key handshake with the AP timed out") | |
4007 | if dev[0].get_status_field("tls_session_reused") != '1': | |
4008 | raise Exception("Session resumption not used on the second connection") | |
4009 | ||
f9dd43ea JM |
4010 | def test_eap_peap_no_session_resumption(dev, apdev): |
4011 | """EAP-PEAP session resumption disabled on server""" | |
4012 | params = int_eap_server_params() | |
4013 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
4014 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
4015 | anonymous_identity="peap", password="password", | |
4016 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
4017 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4018 | raise Exception("Unexpected session resumption on the first connection") | |
4019 | ||
4020 | dev[0].request("REAUTHENTICATE") | |
4021 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4022 | if ev is None: | |
4023 | raise Exception("EAP success timed out") | |
4024 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
4025 | if ev is None: | |
4026 | raise Exception("Key handshake with the AP timed out") | |
4027 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4028 | raise Exception("Unexpected session resumption on the second connection") | |
4029 | ||
4030 | def test_eap_tls_session_resumption(dev, apdev): | |
4031 | """EAP-TLS session resumption""" | |
4032 | params = int_eap_server_params() | |
4033 | params['tls_session_lifetime'] = '60' | |
4034 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
4035 | check_tls_session_resumption_capa(dev[0], hapd) | |
4036 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
4037 | client_cert="auth_serv/user.pem", | |
4038 | private_key="auth_serv/user.key") | |
4039 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4040 | raise Exception("Unexpected session resumption on the first connection") | |
4041 | ||
4042 | dev[0].request("REAUTHENTICATE") | |
4043 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4044 | if ev is None: | |
4045 | raise Exception("EAP success timed out") | |
4046 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
4047 | if ev is None: | |
4048 | raise Exception("Key handshake with the AP timed out") | |
4049 | if dev[0].get_status_field("tls_session_reused") != '1': | |
4050 | raise Exception("Session resumption not used on the second connection") | |
4051 | ||
4052 | dev[0].request("REAUTHENTICATE") | |
4053 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4054 | if ev is None: | |
4055 | raise Exception("EAP success timed out") | |
4056 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
4057 | if ev is None: | |
4058 | raise Exception("Key handshake with the AP timed out") | |
4059 | if dev[0].get_status_field("tls_session_reused") != '1': | |
4060 | raise Exception("Session resumption not used on the third connection") | |
4061 | ||
4062 | def test_eap_tls_session_resumption_expiration(dev, apdev): | |
4063 | """EAP-TLS session resumption""" | |
4064 | params = int_eap_server_params() | |
4065 | params['tls_session_lifetime'] = '1' | |
4066 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
4067 | check_tls_session_resumption_capa(dev[0], hapd) | |
4068 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
4069 | client_cert="auth_serv/user.pem", | |
4070 | private_key="auth_serv/user.key") | |
4071 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4072 | raise Exception("Unexpected session resumption on the first connection") | |
4073 | ||
4074 | # Allow multiple attempts since OpenSSL may not expire the cached entry | |
4075 | # immediately. | |
4076 | for i in range(10): | |
4077 | time.sleep(1.2) | |
4078 | ||
4079 | dev[0].request("REAUTHENTICATE") | |
4080 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4081 | if ev is None: | |
4082 | raise Exception("EAP success timed out") | |
4083 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
4084 | if ev is None: | |
4085 | raise Exception("Key handshake with the AP timed out") | |
4086 | if dev[0].get_status_field("tls_session_reused") == '0': | |
4087 | break | |
4088 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4089 | raise Exception("Session resumption used after lifetime expiration") | |
4090 | ||
4091 | def test_eap_tls_no_session_resumption(dev, apdev): | |
4092 | """EAP-TLS session resumption disabled on server""" | |
4093 | params = int_eap_server_params() | |
4094 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
4095 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
4096 | client_cert="auth_serv/user.pem", | |
4097 | private_key="auth_serv/user.key") | |
4098 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4099 | raise Exception("Unexpected session resumption on the first connection") | |
4100 | ||
4101 | dev[0].request("REAUTHENTICATE") | |
4102 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4103 | if ev is None: | |
4104 | raise Exception("EAP success timed out") | |
4105 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
4106 | if ev is None: | |
4107 | raise Exception("Key handshake with the AP timed out") | |
4108 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4109 | raise Exception("Unexpected session resumption on the second connection") | |
4110 | ||
4111 | def test_eap_tls_session_resumption_radius(dev, apdev): | |
4112 | """EAP-TLS session resumption (RADIUS)""" | |
4113 | params = { "ssid": "as", "beacon_int": "2000", | |
4114 | "radius_server_clients": "auth_serv/radius_clients.conf", | |
4115 | "radius_server_auth_port": '18128', | |
4116 | "eap_server": "1", | |
4117 | "eap_user_file": "auth_serv/eap_user.conf", | |
4118 | "ca_cert": "auth_serv/ca.pem", | |
4119 | "server_cert": "auth_serv/server.pem", | |
4120 | "private_key": "auth_serv/server.key", | |
4121 | "tls_session_lifetime": "60" } | |
4122 | authsrv = hostapd.add_ap(apdev[1]['ifname'], params) | |
4123 | check_tls_session_resumption_capa(dev[0], authsrv) | |
4124 | ||
4125 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
4126 | params['auth_server_port'] = "18128" | |
4127 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
4128 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
4129 | client_cert="auth_serv/user.pem", | |
4130 | private_key="auth_serv/user.key") | |
4131 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4132 | raise Exception("Unexpected session resumption on the first connection") | |
4133 | ||
4134 | dev[0].request("REAUTHENTICATE") | |
4135 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4136 | if ev is None: | |
4137 | raise Exception("EAP success timed out") | |
4138 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
4139 | if ev is None: | |
4140 | raise Exception("Key handshake with the AP timed out") | |
4141 | if dev[0].get_status_field("tls_session_reused") != '1': | |
4142 | raise Exception("Session resumption not used on the second connection") | |
4143 | ||
4144 | def test_eap_tls_no_session_resumption_radius(dev, apdev): | |
4145 | """EAP-TLS session resumption disabled (RADIUS)""" | |
4146 | params = { "ssid": "as", "beacon_int": "2000", | |
4147 | "radius_server_clients": "auth_serv/radius_clients.conf", | |
4148 | "radius_server_auth_port": '18128', | |
4149 | "eap_server": "1", | |
4150 | "eap_user_file": "auth_serv/eap_user.conf", | |
4151 | "ca_cert": "auth_serv/ca.pem", | |
4152 | "server_cert": "auth_serv/server.pem", | |
4153 | "private_key": "auth_serv/server.key", | |
4154 | "tls_session_lifetime": "0" } | |
4155 | hostapd.add_ap(apdev[1]['ifname'], params) | |
4156 | ||
4157 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
4158 | params['auth_server_port'] = "18128" | |
4159 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
4160 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
4161 | client_cert="auth_serv/user.pem", | |
4162 | private_key="auth_serv/user.key") | |
4163 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4164 | raise Exception("Unexpected session resumption on the first connection") | |
4165 | ||
4166 | dev[0].request("REAUTHENTICATE") | |
4167 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4168 | if ev is None: | |
4169 | raise Exception("EAP success timed out") | |
4170 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10) | |
4171 | if ev is None: | |
4172 | raise Exception("Key handshake with the AP timed out") | |
4173 | if dev[0].get_status_field("tls_session_reused") != '0': | |
4174 | raise Exception("Unexpected session resumption on the second connection") | |
7c0d66cf JM |
4175 | |
4176 | def test_eap_mschapv2_errors(dev, apdev): | |
4177 | """EAP-MSCHAPv2 error cases""" | |
4178 | check_eap_capa(dev[0], "MSCHAPV2") | |
4179 | check_eap_capa(dev[0], "FAST") | |
4180 | ||
4181 | params = hostapd.wpa2_eap_params(ssid="test-wpa-eap") | |
4182 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
4183 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", | |
4184 | identity="phase1-user", password="password", | |
4185 | scan_freq="2412") | |
4186 | dev[0].request("REMOVE_NETWORK all") | |
4187 | dev[0].wait_disconnected() | |
4188 | ||
4189 | tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"), | |
4190 | (1, "nt_password_hash;mschapv2_derive_response"), | |
4191 | (1, "nt_password_hash;=mschapv2_derive_response"), | |
4192 | (1, "generate_nt_response;mschapv2_derive_response"), | |
4193 | (1, "generate_authenticator_response;mschapv2_derive_response"), | |
4194 | (1, "nt_password_hash;=mschapv2_derive_response"), | |
4195 | (1, "get_master_key;mschapv2_derive_response"), | |
4196 | (1, "os_get_random;eap_mschapv2_challenge_reply") ] | |
4197 | for count, func in tests: | |
4198 | with fail_test(dev[0], count, func): | |
4199 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", | |
4200 | identity="phase1-user", password="password", | |
4201 | wait_connect=False, scan_freq="2412") | |
4202 | wait_fail_trigger(dev[0], "GET_FAIL") | |
4203 | dev[0].request("REMOVE_NETWORK all") | |
4204 | dev[0].wait_disconnected() | |
4205 | ||
4206 | tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"), | |
4207 | (1, "hash_nt_password_hash;=mschapv2_derive_response"), | |
4208 | (1, "generate_nt_response_pwhash;mschapv2_derive_response"), | |
4209 | (1, "generate_authenticator_response_pwhash;mschapv2_derive_response") ] | |
4210 | for count, func in tests: | |
4211 | with fail_test(dev[0], count, func): | |
4212 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", | |
4213 | identity="phase1-user", | |
4214 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
4215 | wait_connect=False, scan_freq="2412") | |
4216 | wait_fail_trigger(dev[0], "GET_FAIL") | |
4217 | dev[0].request("REMOVE_NETWORK all") | |
4218 | dev[0].wait_disconnected() | |
4219 | ||
4220 | tests = [ (1, "eap_mschapv2_init"), | |
4221 | (1, "eap_msg_alloc;eap_mschapv2_challenge_reply"), | |
4222 | (1, "eap_msg_alloc;eap_mschapv2_success"), | |
4223 | (1, "eap_mschapv2_getKey") ] | |
4224 | for count, func in tests: | |
4225 | with alloc_fail(dev[0], count, func): | |
4226 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", | |
4227 | identity="phase1-user", password="password", | |
4228 | wait_connect=False, scan_freq="2412") | |
4229 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
4230 | dev[0].request("REMOVE_NETWORK all") | |
4231 | dev[0].wait_disconnected() | |
4232 | ||
4233 | tests = [ (1, "eap_msg_alloc;eap_mschapv2_failure") ] | |
4234 | for count, func in tests: | |
4235 | with alloc_fail(dev[0], count, func): | |
4236 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2", | |
4237 | identity="phase1-user", password="wrong password", | |
4238 | wait_connect=False, scan_freq="2412") | |
4239 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
4240 | dev[0].request("REMOVE_NETWORK all") | |
4241 | dev[0].wait_disconnected() | |
4242 | ||
4243 | tests = [ (2, "eap_mschapv2_init"), | |
4244 | (3, "eap_mschapv2_init") ] | |
4245 | for count, func in tests: | |
4246 | with alloc_fail(dev[0], count, func): | |
4247 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="FAST", | |
4248 | anonymous_identity="FAST", identity="user", | |
4249 | password="password", | |
4250 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
4251 | phase1="fast_provisioning=1", | |
4252 | pac_file="blob://fast_pac", | |
4253 | wait_connect=False, scan_freq="2412") | |
4254 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
4255 | dev[0].request("REMOVE_NETWORK all") | |
4256 | dev[0].wait_disconnected() | |
bf0ec17a JM |
4257 | |
4258 | def test_eap_gpsk_errors(dev, apdev): | |
4259 | """EAP-GPSK error cases""" | |
4260 | params = hostapd.wpa2_eap_params(ssid="test-wpa-eap") | |
4261 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
4262 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
4263 | identity="gpsk user", | |
4264 | password="abcdefghijklmnop0123456789abcdef", | |
4265 | scan_freq="2412") | |
4266 | dev[0].request("REMOVE_NETWORK all") | |
4267 | dev[0].wait_disconnected() | |
4268 | ||
4269 | tests = [ (1, "os_get_random;eap_gpsk_send_gpsk_2", None), | |
4270 | (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2", | |
4271 | "cipher=1"), | |
4272 | (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2", | |
4273 | "cipher=2"), | |
4274 | (1, "eap_gpsk_derive_keys_helper", None), | |
4275 | (2, "eap_gpsk_derive_keys_helper", None), | |
4276 | (1, "eap_gpsk_compute_mic_aes;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2", | |
4277 | "cipher=1"), | |
4278 | (1, "hmac_sha256;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2", | |
4279 | "cipher=2"), | |
4280 | (1, "eap_gpsk_compute_mic;eap_gpsk_validate_gpsk_3_mic", None), | |
4281 | (1, "eap_gpsk_compute_mic;eap_gpsk_send_gpsk_4", None), | |
4282 | (1, "eap_gpsk_derive_mid_helper", None) ] | |
4283 | for count, func, phase1 in tests: | |
4284 | with fail_test(dev[0], count, func): | |
4285 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
4286 | identity="gpsk user", | |
4287 | password="abcdefghijklmnop0123456789abcdef", | |
4288 | phase1=phase1, | |
4289 | wait_connect=False, scan_freq="2412") | |
4290 | wait_fail_trigger(dev[0], "GET_FAIL") | |
4291 | dev[0].request("REMOVE_NETWORK all") | |
4292 | dev[0].wait_disconnected() | |
4293 | ||
4294 | tests = [ (1, "eap_gpsk_init"), | |
4295 | (2, "eap_gpsk_init"), | |
4296 | (3, "eap_gpsk_init"), | |
4297 | (1, "eap_gpsk_process_id_server"), | |
4298 | (1, "eap_msg_alloc;eap_gpsk_send_gpsk_2"), | |
4299 | (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"), | |
4300 | (1, "eap_gpsk_derive_mid_helper;eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"), | |
4301 | (1, "eap_gpsk_derive_keys"), | |
4302 | (1, "eap_gpsk_derive_keys_helper"), | |
4303 | (1, "eap_msg_alloc;eap_gpsk_send_gpsk_4"), | |
4304 | (1, "eap_gpsk_getKey"), | |
4305 | (1, "eap_gpsk_get_emsk"), | |
4306 | (1, "eap_gpsk_get_session_id") ] | |
4307 | for count, func in tests: | |
4308 | with alloc_fail(dev[0], count, func): | |
4309 | dev[0].request("ERP_FLUSH") | |
4310 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
4311 | identity="gpsk user", erp="1", | |
4312 | password="abcdefghijklmnop0123456789abcdef", | |
4313 | wait_connect=False, scan_freq="2412") | |
4314 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
4315 | dev[0].request("REMOVE_NETWORK all") | |
4316 | dev[0].wait_disconnected() | |
d4c3c055 JM |
4317 | |
4318 | def test_ap_wpa2_eap_sim_db(dev, apdev, params): | |
4319 | """EAP-SIM DB error cases""" | |
4320 | sockpath = '/tmp/hlr_auc_gw.sock-test' | |
4321 | try: | |
4322 | os.remove(sockpath) | |
4323 | except: | |
4324 | pass | |
4325 | hparams = int_eap_server_params() | |
4326 | hparams['eap_sim_db'] = 'unix:' + sockpath | |
4327 | hapd = hostapd.add_ap(apdev[0]['ifname'], hparams) | |
4328 | ||
4329 | # Initial test with hlr_auc_gw socket not available | |
4330 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
4331 | eap="SIM", identity="1232010000000000", | |
4332 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
4333 | scan_freq="2412", wait_connect=False) | |
4334 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4335 | if ev is None: | |
4336 | raise Exception("EAP-Failure not reported") | |
4337 | dev[0].wait_disconnected() | |
4338 | dev[0].request("DISCONNECT") | |
4339 | ||
4340 | # Test with invalid responses and response timeout | |
4341 | ||
4342 | class test_handler(SocketServer.DatagramRequestHandler): | |
4343 | def handle(self): | |
4344 | data = self.request[0].strip() | |
4345 | socket = self.request[1] | |
4346 | logger.debug("Received hlr_auc_gw request: " + data) | |
4347 | # EAP-SIM DB: Failed to parse response string | |
4348 | socket.sendto("FOO", self.client_address) | |
4349 | # EAP-SIM DB: Failed to parse response string | |
4350 | socket.sendto("FOO 1", self.client_address) | |
4351 | # EAP-SIM DB: Unknown external response | |
4352 | socket.sendto("FOO 1 2", self.client_address) | |
4353 | logger.info("No proper response - wait for pending eap_sim_db request timeout") | |
4354 | ||
4355 | server = SocketServer.UnixDatagramServer(sockpath, test_handler) | |
4356 | server.timeout = 1 | |
4357 | ||
4358 | dev[0].select_network(id) | |
4359 | server.handle_request() | |
4360 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4361 | if ev is None: | |
4362 | raise Exception("EAP-Failure not reported") | |
4363 | dev[0].wait_disconnected() | |
4364 | dev[0].request("DISCONNECT") | |
4365 | ||
4366 | # Test with a valid response | |
4367 | ||
4368 | class test_handler2(SocketServer.DatagramRequestHandler): | |
4369 | def handle(self): | |
4370 | data = self.request[0].strip() | |
4371 | socket = self.request[1] | |
4372 | logger.debug("Received hlr_auc_gw request: " + data) | |
4373 | fname = os.path.join(params['logdir'], | |
4374 | 'hlr_auc_gw.milenage_db') | |
4375 | cmd = subprocess.Popen(['../../hostapd/hlr_auc_gw', | |
4376 | '-m', fname, data], | |
4377 | stdout=subprocess.PIPE) | |
4378 | res = cmd.stdout.read().strip() | |
4379 | cmd.stdout.close() | |
4380 | logger.debug("hlr_auc_gw response: " + res) | |
4381 | socket.sendto(res, self.client_address) | |
4382 | ||
4383 | server.RequestHandlerClass = test_handler2 | |
4384 | ||
4385 | dev[0].select_network(id) | |
4386 | server.handle_request() | |
4387 | dev[0].wait_connected() | |
4388 | dev[0].request("DISCONNECT") | |
4389 | dev[0].wait_disconnected() | |
d6ba709a JM |
4390 | |
4391 | def test_eap_tls_sha512(dev, apdev, params): | |
4392 | """EAP-TLS with SHA512 signature""" | |
4393 | params = int_eap_server_params() | |
4394 | params["ca_cert"] = "auth_serv/sha512-ca.pem" | |
4395 | params["server_cert"] = "auth_serv/sha512-server.pem" | |
4396 | params["private_key"] = "auth_serv/sha512-server.key" | |
4397 | hostapd.add_ap(apdev[0]['ifname'], params) | |
4398 | ||
4399 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
4400 | identity="tls user sha512", | |
4401 | ca_cert="auth_serv/sha512-ca.pem", | |
4402 | client_cert="auth_serv/sha512-user.pem", | |
4403 | private_key="auth_serv/sha512-user.key", | |
4404 | scan_freq="2412") | |
4405 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
4406 | identity="tls user sha512", | |
4407 | ca_cert="auth_serv/sha512-ca.pem", | |
4408 | client_cert="auth_serv/sha384-user.pem", | |
4409 | private_key="auth_serv/sha384-user.key", | |
4410 | scan_freq="2412") | |
4411 | ||
4412 | def test_eap_tls_sha384(dev, apdev, params): | |
4413 | """EAP-TLS with SHA384 signature""" | |
4414 | params = int_eap_server_params() | |
4415 | params["ca_cert"] = "auth_serv/sha512-ca.pem" | |
4416 | params["server_cert"] = "auth_serv/sha384-server.pem" | |
4417 | params["private_key"] = "auth_serv/sha384-server.key" | |
4418 | hostapd.add_ap(apdev[0]['ifname'], params) | |
4419 | ||
4420 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
4421 | identity="tls user sha512", | |
4422 | ca_cert="auth_serv/sha512-ca.pem", | |
4423 | client_cert="auth_serv/sha512-user.pem", | |
4424 | private_key="auth_serv/sha512-user.key", | |
4425 | scan_freq="2412") | |
4426 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
4427 | identity="tls user sha512", | |
4428 | ca_cert="auth_serv/sha512-ca.pem", | |
4429 | client_cert="auth_serv/sha384-user.pem", | |
4430 | private_key="auth_serv/sha384-user.key", | |
4431 | scan_freq="2412") | |
0ceff76e JM |
4432 | |
4433 | def test_ap_wpa2_eap_assoc_rsn(dev, apdev): | |
4434 | """WPA2-Enterprise AP and association request RSN IE differences""" | |
4435 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
4436 | hostapd.add_ap(apdev[0]['ifname'], params) | |
4437 | ||
4438 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap-11w") | |
4439 | params["ieee80211w"] = "2" | |
4440 | hostapd.add_ap(apdev[1]['ifname'], params) | |
4441 | ||
4442 | # Success cases with optional RSN IE fields removed one by one | |
4443 | tests = [ ("Normal wpa_supplicant assoc req RSN IE", | |
4444 | "30140100000fac040100000fac040100000fac010000"), | |
4445 | ("Extra PMKIDCount field in RSN IE", | |
4446 | "30160100000fac040100000fac040100000fac0100000000"), | |
4447 | ("Extra Group Management Cipher Suite in RSN IE", | |
4448 | "301a0100000fac040100000fac040100000fac0100000000000fac06"), | |
4449 | ("Extra undefined extension field in RSN IE", | |
4450 | "301c0100000fac040100000fac040100000fac0100000000000fac061122"), | |
4451 | ("RSN IE without RSN Capabilities", | |
4452 | "30120100000fac040100000fac040100000fac01"), | |
4453 | ("RSN IE without AKM", "300c0100000fac040100000fac04"), | |
4454 | ("RSN IE without pairwise", "30060100000fac04"), | |
4455 | ("RSN IE without group", "30020100") ] | |
4456 | for title, ie in tests: | |
4457 | logger.info(title) | |
4458 | set_test_assoc_ie(dev[0], ie) | |
4459 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
4460 | identity="gpsk user", | |
4461 | password="abcdefghijklmnop0123456789abcdef", | |
4462 | scan_freq="2412") | |
4463 | dev[0].request("REMOVE_NETWORK all") | |
4464 | dev[0].wait_disconnected() | |
4465 | ||
4466 | tests = [ ("Normal wpa_supplicant assoc req RSN IE", | |
4467 | "30140100000fac040100000fac040100000fac01cc00"), | |
4468 | ("Group management cipher included in assoc req RSN IE", | |
4469 | "301a0100000fac040100000fac040100000fac01cc000000000fac06") ] | |
4470 | for title, ie in tests: | |
4471 | logger.info(title) | |
4472 | set_test_assoc_ie(dev[0], ie) | |
4473 | dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1", | |
4474 | eap="GPSK", identity="gpsk user", | |
4475 | password="abcdefghijklmnop0123456789abcdef", | |
4476 | scan_freq="2412") | |
4477 | dev[0].request("REMOVE_NETWORK all") | |
4478 | dev[0].wait_disconnected() | |
4479 | ||
4480 | tests = [ ("Invalid group cipher", "30060100000fac02", 41), | |
4481 | ("Invalid pairwise cipher", "300c0100000fac040100000fac02", 42) ] | |
4482 | for title, ie, status in tests: | |
4483 | logger.info(title) | |
4484 | set_test_assoc_ie(dev[0], ie) | |
4485 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK", | |
4486 | identity="gpsk user", | |
4487 | password="abcdefghijklmnop0123456789abcdef", | |
4488 | scan_freq="2412", wait_connect=False) | |
4489 | ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"]) | |
4490 | if ev is None: | |
4491 | raise Exception("Association rejection not reported") | |
4492 | if "status_code=" + str(status) not in ev: | |
4493 | raise Exception("Unexpected status code: " + ev) | |
4494 | dev[0].request("REMOVE_NETWORK all") | |
4495 | dev[0].dump_monitor() | |
4496 | ||
4497 | tests = [ ("Management frame protection not enabled", | |
4498 | "30140100000fac040100000fac040100000fac010000", 31), | |
4499 | ("Unsupported management group cipher", | |
4500 | "301a0100000fac040100000fac040100000fac01cc000000000fac0b", 31) ] | |
4501 | for title, ie, status in tests: | |
4502 | logger.info(title) | |
4503 | set_test_assoc_ie(dev[0], ie) | |
4504 | dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1", | |
4505 | eap="GPSK", identity="gpsk user", | |
4506 | password="abcdefghijklmnop0123456789abcdef", | |
4507 | scan_freq="2412", wait_connect=False) | |
4508 | ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"]) | |
4509 | if ev is None: | |
4510 | raise Exception("Association rejection not reported") | |
4511 | if "status_code=" + str(status) not in ev: | |
4512 | raise Exception("Unexpected status code: " + ev) | |
4513 | dev[0].request("REMOVE_NETWORK all") | |
4514 | dev[0].dump_monitor() | |
ca27ee09 JM |
4515 | |
4516 | def test_eap_tls_ext_cert_check(dev, apdev): | |
4517 | """EAP-TLS and external server certification validation""" | |
4518 | # With internal server certificate chain validation | |
4519 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
4520 | identity="tls user", | |
4521 | ca_cert="auth_serv/ca.pem", | |
4522 | client_cert="auth_serv/user.pem", | |
4523 | private_key="auth_serv/user.key", | |
4524 | phase1="tls_ext_cert_check=1", scan_freq="2412", | |
4525 | only_add_network=True) | |
4526 | run_ext_cert_check(dev, apdev, id) | |
4527 | ||
4528 | def test_eap_ttls_ext_cert_check(dev, apdev): | |
4529 | """EAP-TTLS and external server certification validation""" | |
4530 | # Without internal server certificate chain validation | |
4531 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
4532 | identity="pap user", anonymous_identity="ttls", | |
4533 | password="password", phase2="auth=PAP", | |
4534 | phase1="tls_ext_cert_check=1", scan_freq="2412", | |
4535 | only_add_network=True) | |
4536 | run_ext_cert_check(dev, apdev, id) | |
4537 | ||
4538 | def test_eap_peap_ext_cert_check(dev, apdev): | |
4539 | """EAP-PEAP and external server certification validation""" | |
4540 | # With internal server certificate chain validation | |
4541 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
4542 | identity="user", anonymous_identity="peap", | |
4543 | ca_cert="auth_serv/ca.pem", | |
4544 | password="password", phase2="auth=MSCHAPV2", | |
4545 | phase1="tls_ext_cert_check=1", scan_freq="2412", | |
4546 | only_add_network=True) | |
4547 | run_ext_cert_check(dev, apdev, id) | |
4548 | ||
4549 | def test_eap_fast_ext_cert_check(dev, apdev): | |
4550 | """EAP-FAST and external server certification validation""" | |
4551 | check_eap_capa(dev[0], "FAST") | |
4552 | # With internal server certificate chain validation | |
4553 | dev[0].request("SET blob fast_pac_auth_ext ") | |
4554 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
4555 | identity="user", anonymous_identity="FAST", | |
4556 | ca_cert="auth_serv/ca.pem", | |
4557 | password="password", phase2="auth=GTC", | |
4558 | phase1="tls_ext_cert_check=1 fast_provisioning=2", | |
4559 | pac_file="blob://fast_pac_auth_ext", | |
4560 | scan_freq="2412", | |
4561 | only_add_network=True) | |
4562 | run_ext_cert_check(dev, apdev, id) | |
4563 | ||
4564 | def run_ext_cert_check(dev, apdev, net_id): | |
4565 | check_ext_cert_check_support(dev[0]) | |
4566 | if not openssl_imported: | |
4567 | raise HwsimSkip("OpenSSL python method not available") | |
4568 | ||
4569 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
4570 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
4571 | ||
4572 | dev[0].select_network(net_id) | |
4573 | certs = {} | |
4574 | while True: | |
4575 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT", | |
4576 | "CTRL-REQ-EXT_CERT_CHECK", | |
4577 | "CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
4578 | if ev is None: | |
4579 | raise Exception("No peer server certificate event seen") | |
4580 | if "CTRL-EVENT-EAP-PEER-CERT" in ev: | |
4581 | depth = None | |
4582 | cert = None | |
4583 | vals = ev.split(' ') | |
4584 | for v in vals: | |
4585 | if v.startswith("depth="): | |
4586 | depth = int(v.split('=')[1]) | |
4587 | elif v.startswith("cert="): | |
4588 | cert = v.split('=')[1] | |
4589 | if depth is not None and cert: | |
4590 | certs[depth] = binascii.unhexlify(cert) | |
4591 | elif "CTRL-EVENT-EAP-SUCCESS" in ev: | |
4592 | raise Exception("Unexpected EAP-Success") | |
4593 | elif "CTRL-REQ-EXT_CERT_CHECK" in ev: | |
4594 | id = ev.split(':')[0].split('-')[-1] | |
4595 | break | |
4596 | if 0 not in certs: | |
4597 | raise Exception("Server certificate not received") | |
4598 | if 1 not in certs: | |
4599 | raise Exception("Server certificate issuer not received") | |
4600 | ||
4601 | cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, | |
4602 | certs[0]) | |
4603 | cn = cert.get_subject().commonName | |
4604 | logger.info("Server certificate CN=" + cn) | |
4605 | ||
4606 | issuer = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, | |
4607 | certs[1]) | |
4608 | icn = issuer.get_subject().commonName | |
4609 | logger.info("Issuer certificate CN=" + icn) | |
4610 | ||
4611 | if cn != "server.w1.fi": | |
4612 | raise Exception("Unexpected server certificate CN: " + cn) | |
4613 | if icn != "Root CA": | |
4614 | raise Exception("Unexpected server certificate issuer CN: " + icn) | |
4615 | ||
4616 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=0.1) | |
4617 | if ev: | |
4618 | raise Exception("Unexpected EAP-Success before external check result indication") | |
4619 | ||
4620 | dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":good") | |
4621 | dev[0].wait_connected() | |
4622 | ||
4623 | dev[0].request("DISCONNECT") | |
4624 | dev[0].wait_disconnected() | |
4625 | if "FAIL" in dev[0].request("PMKSA_FLUSH"): | |
4626 | raise Exception("PMKSA_FLUSH failed") | |
4627 | dev[0].request("SET blob fast_pac_auth_ext ") | |
4628 | dev[0].request("RECONNECT") | |
4629 | ||
4630 | ev = dev[0].wait_event(["CTRL-REQ-EXT_CERT_CHECK"], timeout=10) | |
4631 | if ev is None: | |
4632 | raise Exception("No peer server certificate event seen (2)") | |
4633 | id = ev.split(':')[0].split('-')[-1] | |
4634 | dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":bad") | |
4635 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
4636 | if ev is None: | |
4637 | raise Exception("EAP-Failure not reported") | |
4638 | dev[0].request("REMOVE_NETWORK all") | |
4639 | dev[0].wait_disconnected() |