]>
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 |
9626962d JM |
15 | |
16 | import hwsim_utils | |
17 | import hostapd | |
ee9533eb | 18 | from utils import HwsimSkip, alloc_fail |
5b3c40a6 | 19 | from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations |
9626962d | 20 | |
81e787b7 JM |
21 | def check_hlr_auc_gw_support(): |
22 | if not os.path.exists("/tmp/hlr_auc_gw.sock"): | |
23 | raise HwsimSkip("No hlr_auc_gw available") | |
24 | ||
3b51cc63 JM |
25 | def check_eap_capa(dev, method): |
26 | res = dev.get_capability("eap") | |
27 | if method not in res: | |
28 | raise HwsimSkip("EAP method %s not supported in the build" % method) | |
29 | ||
506b2f05 JM |
30 | def check_subject_match_support(dev): |
31 | tls = dev.request("GET tls_library") | |
32 | if not tls.startswith("OpenSSL"): | |
33 | raise HwsimSkip("subject_match not supported with this TLS library: " + tls) | |
34 | ||
35 | def check_altsubject_match_support(dev): | |
36 | tls = dev.request("GET tls_library") | |
37 | if not tls.startswith("OpenSSL"): | |
38 | raise HwsimSkip("altsubject_match not supported with this TLS library: " + tls) | |
39 | ||
24579e70 JM |
40 | def check_domain_match_full(dev): |
41 | tls = dev.request("GET tls_library") | |
42 | if not tls.startswith("OpenSSL"): | |
43 | raise HwsimSkip("domain_suffix_match requires full match with this TLS library: " + tls) | |
44 | ||
4bf4e9db JM |
45 | def check_cert_probe_support(dev): |
46 | tls = dev.request("GET tls_library") | |
47 | if not tls.startswith("OpenSSL"): | |
48 | raise HwsimSkip("Certificate probing not supported with this TLS library: " + tls) | |
49 | ||
6ea231e6 JM |
50 | def read_pem(fname): |
51 | with open(fname, "r") as f: | |
52 | lines = f.readlines() | |
53 | copy = False | |
54 | cert = "" | |
55 | for l in lines: | |
56 | if "-----END" in l: | |
57 | break | |
58 | if copy: | |
59 | cert = cert + l | |
60 | if "-----BEGIN" in l: | |
61 | copy = True | |
62 | return base64.b64decode(cert) | |
63 | ||
6f939e59 JM |
64 | def eap_connect(dev, ap, method, identity, |
65 | sha256=False, expect_failure=False, local_error_report=False, | |
66 | **kwargs): | |
cb33ee14 | 67 | hapd = hostapd.Hostapd(ap['ifname']) |
2bb9e283 JM |
68 | id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", |
69 | eap=method, identity=identity, | |
6f939e59 JM |
70 | wait_connect=False, scan_freq="2412", ieee80211w="1", |
71 | **kwargs) | |
f10ba3b2 JM |
72 | eap_check_auth(dev, method, True, sha256=sha256, |
73 | expect_failure=expect_failure, | |
74 | local_error_report=local_error_report) | |
75 | if expect_failure: | |
76 | return id | |
cb33ee14 JM |
77 | ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) |
78 | if ev is None: | |
79 | raise Exception("No connection event received from hostapd") | |
2bb9e283 | 80 | return id |
75b2b9cf | 81 | |
f10ba3b2 JM |
82 | def eap_check_auth(dev, method, initial, rsn=True, sha256=False, |
83 | expect_failure=False, local_error_report=False): | |
9626962d JM |
84 | ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) |
85 | if ev is None: | |
86 | raise Exception("Association and EAP start timed out") | |
87 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
88 | if ev is None: | |
89 | raise Exception("EAP method selection timed out") | |
90 | if method not in ev: | |
91 | raise Exception("Unexpected EAP method") | |
f10ba3b2 JM |
92 | if expect_failure: |
93 | ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
94 | if ev is None: | |
95 | raise Exception("EAP failure timed out") | |
5f35a5e2 | 96 | ev = dev.wait_disconnected(timeout=10) |
f10ba3b2 JM |
97 | if not local_error_report: |
98 | if "reason=23" not in ev: | |
99 | raise Exception("Proper reason code for disconnection not reported") | |
100 | return | |
9626962d JM |
101 | ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) |
102 | if ev is None: | |
103 | raise Exception("EAP success timed out") | |
9626962d | 104 | |
75b2b9cf JM |
105 | if initial: |
106 | ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
75b2b9cf | 107 | else: |
bce774ad JM |
108 | ev = dev.wait_event(["WPA: Key negotiation completed"], timeout=10) |
109 | if ev is None: | |
110 | raise Exception("Association with the AP timed out") | |
111 | status = dev.get_status() | |
112 | if status["wpa_state"] != "COMPLETED": | |
113 | raise Exception("Connection not completed") | |
75b2b9cf | 114 | |
9626962d JM |
115 | if status["suppPortStatus"] != "Authorized": |
116 | raise Exception("Port not authorized") | |
117 | if method not in status["selectedMethod"]: | |
118 | raise Exception("Incorrect EAP method status") | |
2b005194 JM |
119 | if sha256: |
120 | e = "WPA2-EAP-SHA256" | |
121 | elif rsn: | |
71390dc8 JM |
122 | e = "WPA2/IEEE 802.1X/EAP" |
123 | else: | |
124 | e = "WPA/IEEE 802.1X/EAP" | |
125 | if status["key_mgmt"] != e: | |
126 | raise Exception("Unexpected key_mgmt status: " + status["key_mgmt"]) | |
2fc4749c | 127 | return status |
9626962d | 128 | |
5b1aaf6c | 129 | def eap_reauth(dev, method, rsn=True, sha256=False, expect_failure=False): |
75b2b9cf | 130 | dev.request("REAUTHENTICATE") |
2fc4749c JM |
131 | return eap_check_auth(dev, method, False, rsn=rsn, sha256=sha256, |
132 | expect_failure=expect_failure) | |
75b2b9cf | 133 | |
9626962d JM |
134 | def test_ap_wpa2_eap_sim(dev, apdev): |
135 | """WPA2-Enterprise connection using EAP-SIM""" | |
81e787b7 | 136 | check_hlr_auc_gw_support() |
9626962d | 137 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 138 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 139 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", |
9626962d | 140 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") |
a8375c94 | 141 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 142 | eap_reauth(dev[0], "SIM") |
9626962d | 143 | |
a0f350fd JM |
144 | eap_connect(dev[1], apdev[0], "SIM", "1232010000000001", |
145 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
146 | eap_connect(dev[2], apdev[0], "SIM", "1232010000000002", | |
147 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
148 | expect_failure=True) | |
149 | ||
f10ba3b2 JM |
150 | logger.info("Negative test with incorrect key") |
151 | dev[0].request("REMOVE_NETWORK all") | |
152 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
153 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
154 | expect_failure=True) | |
155 | ||
32747a3e JM |
156 | logger.info("Invalid GSM-Milenage key") |
157 | dev[0].request("REMOVE_NETWORK all") | |
158 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
159 | password="ffdca4eda45b53cf0f12d7c9c3bc6a", | |
160 | expect_failure=True) | |
161 | ||
162 | logger.info("Invalid GSM-Milenage key(2)") | |
163 | dev[0].request("REMOVE_NETWORK all") | |
164 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
165 | password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581", | |
166 | expect_failure=True) | |
167 | ||
168 | logger.info("Invalid GSM-Milenage key(3)") | |
169 | dev[0].request("REMOVE_NETWORK all") | |
170 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
171 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q", | |
172 | expect_failure=True) | |
173 | ||
174 | logger.info("Invalid GSM-Milenage key(4)") | |
175 | dev[0].request("REMOVE_NETWORK all") | |
176 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
177 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581", | |
178 | expect_failure=True) | |
179 | ||
180 | logger.info("Missing key configuration") | |
181 | dev[0].request("REMOVE_NETWORK all") | |
182 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
183 | expect_failure=True) | |
184 | ||
5b1aaf6c JM |
185 | def test_ap_wpa2_eap_sim_sql(dev, apdev, params): |
186 | """WPA2-Enterprise connection using EAP-SIM (SQL)""" | |
81e787b7 | 187 | check_hlr_auc_gw_support() |
5b1aaf6c JM |
188 | try: |
189 | import sqlite3 | |
190 | except ImportError: | |
81e787b7 | 191 | raise HwsimSkip("No sqlite3 module available") |
5b1aaf6c JM |
192 | con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) |
193 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
194 | params['auth_server_port'] = "1814" | |
195 | hostapd.add_ap(apdev[0]['ifname'], params) | |
196 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
197 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
198 | ||
199 | logger.info("SIM fast re-authentication") | |
200 | eap_reauth(dev[0], "SIM") | |
201 | ||
202 | logger.info("SIM full auth with pseudonym") | |
203 | with con: | |
204 | cur = con.cursor() | |
205 | cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'") | |
206 | eap_reauth(dev[0], "SIM") | |
207 | ||
208 | logger.info("SIM full auth with permanent identity") | |
209 | with con: | |
210 | cur = con.cursor() | |
211 | cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'") | |
212 | cur.execute("DELETE FROM pseudonyms WHERE permanent='1232010000000000'") | |
213 | eap_reauth(dev[0], "SIM") | |
214 | ||
215 | logger.info("SIM reauth with mismatching MK") | |
216 | with con: | |
217 | cur = con.cursor() | |
218 | cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='1232010000000000'") | |
219 | eap_reauth(dev[0], "SIM", expect_failure=True) | |
220 | dev[0].request("REMOVE_NETWORK all") | |
221 | ||
222 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
223 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
224 | with con: | |
225 | cur = con.cursor() | |
226 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'") | |
227 | eap_reauth(dev[0], "SIM") | |
228 | with con: | |
229 | cur = con.cursor() | |
230 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'") | |
231 | logger.info("SIM reauth with mismatching counter") | |
232 | eap_reauth(dev[0], "SIM") | |
233 | dev[0].request("REMOVE_NETWORK all") | |
234 | ||
235 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
236 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
237 | with con: | |
238 | cur = con.cursor() | |
239 | cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='1232010000000000'") | |
240 | logger.info("SIM reauth with max reauth count reached") | |
241 | eap_reauth(dev[0], "SIM") | |
242 | ||
e2a90a4c JM |
243 | def test_ap_wpa2_eap_sim_config(dev, apdev): |
244 | """EAP-SIM configuration options""" | |
245 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
246 | hostapd.add_ap(apdev[0]['ifname'], params) | |
247 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM", | |
248 | identity="1232010000000000", | |
249 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
250 | phase1="sim_min_num_chal=1", | |
251 | wait_connect=False, scan_freq="2412") | |
252 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10) | |
253 | if ev is None: | |
254 | raise Exception("No EAP error message seen") | |
255 | dev[0].request("REMOVE_NETWORK all") | |
256 | ||
257 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM", | |
258 | identity="1232010000000000", | |
259 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
260 | phase1="sim_min_num_chal=4", | |
261 | wait_connect=False, scan_freq="2412") | |
262 | ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10) | |
263 | if ev is None: | |
264 | raise Exception("No EAP error message seen (2)") | |
265 | dev[0].request("REMOVE_NETWORK all") | |
266 | ||
267 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
268 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
269 | phase1="sim_min_num_chal=2") | |
270 | eap_connect(dev[1], apdev[0], "SIM", "1232010000000000", | |
271 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
272 | anonymous_identity="345678") | |
273 | ||
72cbc684 JM |
274 | def test_ap_wpa2_eap_sim_ext(dev, apdev): |
275 | """WPA2-Enterprise connection using EAP-SIM and external GSM auth""" | |
47dcb118 | 276 | try: |
81e787b7 | 277 | _test_ap_wpa2_eap_sim_ext(dev, apdev) |
47dcb118 JM |
278 | finally: |
279 | dev[0].request("SET external_sim 0") | |
280 | ||
281 | def _test_ap_wpa2_eap_sim_ext(dev, apdev): | |
81e787b7 | 282 | check_hlr_auc_gw_support() |
72cbc684 JM |
283 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
284 | hostapd.add_ap(apdev[0]['ifname'], params) | |
285 | dev[0].request("SET external_sim 1") | |
286 | id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP", | |
287 | identity="1232010000000000", | |
288 | wait_connect=False, scan_freq="2412") | |
289 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) | |
290 | if ev is None: | |
291 | raise Exception("Network connected timed out") | |
292 | ||
293 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
294 | if ev is None: | |
295 | raise Exception("Wait for external SIM processing request timed out") | |
296 | p = ev.split(':', 2) | |
297 | if p[1] != "GSM-AUTH": | |
298 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
299 | rid = p[0].split('-')[3] | |
300 | ||
301 | # IK:CK:RES | |
302 | resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344" | |
303 | # This will fail during processing, but the ctrl_iface command succeeds | |
304 | dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:" + resp) | |
305 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
306 | if ev is None: | |
307 | raise Exception("EAP failure not reported") | |
308 | dev[0].request("DISCONNECT") | |
309 | ||
310 | dev[0].select_network(id, freq="2412") | |
311 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
312 | if ev is None: | |
313 | raise Exception("Wait for external SIM processing request timed out") | |
314 | p = ev.split(':', 2) | |
315 | if p[1] != "GSM-AUTH": | |
316 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
317 | rid = p[0].split('-')[3] | |
318 | # This will fail during GSM auth validation | |
319 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:q"): | |
320 | raise Exception("CTRL-RSP-SIM failed") | |
321 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
322 | if ev is None: | |
323 | raise Exception("EAP failure not reported") | |
324 | dev[0].request("DISCONNECT") | |
325 | ||
326 | dev[0].select_network(id, freq="2412") | |
327 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
328 | if ev is None: | |
329 | raise Exception("Wait for external SIM processing request timed out") | |
330 | p = ev.split(':', 2) | |
331 | if p[1] != "GSM-AUTH": | |
332 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
333 | rid = p[0].split('-')[3] | |
334 | # This will fail during GSM auth validation | |
335 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:34"): | |
336 | raise Exception("CTRL-RSP-SIM failed") | |
337 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
338 | if ev is None: | |
339 | raise Exception("EAP failure not reported") | |
340 | dev[0].request("DISCONNECT") | |
341 | ||
342 | dev[0].select_network(id, freq="2412") | |
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 | # This will fail during GSM auth validation | |
351 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677"): | |
352 | raise Exception("CTRL-RSP-SIM failed") | |
353 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
354 | if ev is None: | |
355 | raise Exception("EAP failure not reported") | |
356 | dev[0].request("DISCONNECT") | |
357 | ||
358 | dev[0].select_network(id, freq="2412") | |
359 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
360 | if ev is None: | |
361 | raise Exception("Wait for external SIM processing request timed out") | |
362 | p = ev.split(':', 2) | |
363 | if p[1] != "GSM-AUTH": | |
364 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
365 | rid = p[0].split('-')[3] | |
366 | # This will fail during GSM auth validation | |
367 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:q"): | |
368 | raise Exception("CTRL-RSP-SIM failed") | |
369 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
370 | if ev is None: | |
371 | raise Exception("EAP failure not reported") | |
372 | dev[0].request("DISCONNECT") | |
373 | ||
374 | dev[0].select_network(id, freq="2412") | |
375 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
376 | if ev is None: | |
377 | raise Exception("Wait for external SIM processing request timed out") | |
378 | p = ev.split(':', 2) | |
379 | if p[1] != "GSM-AUTH": | |
380 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
381 | rid = p[0].split('-')[3] | |
382 | # This will fail during GSM auth validation | |
383 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:00112233"): | |
384 | raise Exception("CTRL-RSP-SIM failed") | |
385 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
386 | if ev is None: | |
387 | raise Exception("EAP failure not reported") | |
388 | dev[0].request("DISCONNECT") | |
389 | ||
390 | dev[0].select_network(id, freq="2412") | |
391 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
392 | if ev is None: | |
393 | raise Exception("Wait for external SIM processing request timed out") | |
394 | p = ev.split(':', 2) | |
395 | if p[1] != "GSM-AUTH": | |
396 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
397 | rid = p[0].split('-')[3] | |
398 | # This will fail during GSM auth validation | |
399 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:00112233:q"): | |
400 | raise Exception("CTRL-RSP-SIM failed") | |
401 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
402 | if ev is None: | |
403 | raise Exception("EAP failure not reported") | |
404 | ||
9626962d JM |
405 | def test_ap_wpa2_eap_aka(dev, apdev): |
406 | """WPA2-Enterprise connection using EAP-AKA""" | |
81e787b7 | 407 | check_hlr_auc_gw_support() |
9626962d | 408 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 409 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 410 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", |
9626962d | 411 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") |
a8375c94 | 412 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 413 | eap_reauth(dev[0], "AKA") |
9626962d | 414 | |
f10ba3b2 JM |
415 | logger.info("Negative test with incorrect key") |
416 | dev[0].request("REMOVE_NETWORK all") | |
417 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
418 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
419 | expect_failure=True) | |
420 | ||
32747a3e JM |
421 | logger.info("Invalid Milenage key") |
422 | dev[0].request("REMOVE_NETWORK all") | |
423 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
424 | password="ffdca4eda45b53cf0f12d7c9c3bc6a", | |
425 | expect_failure=True) | |
426 | ||
427 | logger.info("Invalid Milenage key(2)") | |
428 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
429 | password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
430 | expect_failure=True) | |
431 | ||
432 | logger.info("Invalid Milenage key(3)") | |
433 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
434 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q:000000000123", | |
435 | expect_failure=True) | |
436 | ||
437 | logger.info("Invalid Milenage key(4)") | |
438 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
439 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:00000000012q", | |
440 | expect_failure=True) | |
441 | ||
442 | logger.info("Invalid Milenage key(5)") | |
443 | dev[0].request("REMOVE_NETWORK all") | |
444 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
445 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581q000000000123", | |
446 | expect_failure=True) | |
447 | ||
448 | logger.info("Invalid Milenage key(6)") | |
449 | dev[0].request("REMOVE_NETWORK all") | |
450 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
451 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581q000000000123", | |
452 | expect_failure=True) | |
453 | ||
454 | logger.info("Missing key configuration") | |
455 | dev[0].request("REMOVE_NETWORK all") | |
456 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
457 | expect_failure=True) | |
458 | ||
5b1aaf6c JM |
459 | def test_ap_wpa2_eap_aka_sql(dev, apdev, params): |
460 | """WPA2-Enterprise connection using EAP-AKA (SQL)""" | |
81e787b7 | 461 | check_hlr_auc_gw_support() |
5b1aaf6c JM |
462 | try: |
463 | import sqlite3 | |
464 | except ImportError: | |
81e787b7 | 465 | raise HwsimSkip("No sqlite3 module available") |
5b1aaf6c JM |
466 | con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) |
467 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
468 | params['auth_server_port'] = "1814" | |
469 | hostapd.add_ap(apdev[0]['ifname'], params) | |
470 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
471 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") | |
472 | ||
473 | logger.info("AKA fast re-authentication") | |
474 | eap_reauth(dev[0], "AKA") | |
475 | ||
476 | logger.info("AKA full auth with pseudonym") | |
477 | with con: | |
478 | cur = con.cursor() | |
479 | cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'") | |
480 | eap_reauth(dev[0], "AKA") | |
481 | ||
482 | logger.info("AKA full auth with permanent identity") | |
483 | with con: | |
484 | cur = con.cursor() | |
485 | cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'") | |
486 | cur.execute("DELETE FROM pseudonyms WHERE permanent='0232010000000000'") | |
487 | eap_reauth(dev[0], "AKA") | |
488 | ||
489 | logger.info("AKA reauth with mismatching MK") | |
490 | with con: | |
491 | cur = con.cursor() | |
492 | cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='0232010000000000'") | |
493 | eap_reauth(dev[0], "AKA", expect_failure=True) | |
494 | dev[0].request("REMOVE_NETWORK all") | |
495 | ||
496 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
497 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") | |
498 | with con: | |
499 | cur = con.cursor() | |
500 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'") | |
501 | eap_reauth(dev[0], "AKA") | |
502 | with con: | |
503 | cur = con.cursor() | |
504 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'") | |
505 | logger.info("AKA reauth with mismatching counter") | |
506 | eap_reauth(dev[0], "AKA") | |
507 | dev[0].request("REMOVE_NETWORK all") | |
508 | ||
509 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
510 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") | |
511 | with con: | |
512 | cur = con.cursor() | |
513 | cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='0232010000000000'") | |
514 | logger.info("AKA reauth with max reauth count reached") | |
515 | eap_reauth(dev[0], "AKA") | |
516 | ||
e2a90a4c JM |
517 | def test_ap_wpa2_eap_aka_config(dev, apdev): |
518 | """EAP-AKA configuration options""" | |
519 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
520 | hostapd.add_ap(apdev[0]['ifname'], params) | |
521 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
522 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
523 | anonymous_identity="2345678") | |
524 | ||
d314bedf JM |
525 | def test_ap_wpa2_eap_aka_ext(dev, apdev): |
526 | """WPA2-Enterprise connection using EAP-AKA and external UMTS auth""" | |
47dcb118 | 527 | try: |
81e787b7 | 528 | _test_ap_wpa2_eap_aka_ext(dev, apdev) |
47dcb118 JM |
529 | finally: |
530 | dev[0].request("SET external_sim 0") | |
531 | ||
532 | def _test_ap_wpa2_eap_aka_ext(dev, apdev): | |
81e787b7 | 533 | check_hlr_auc_gw_support() |
d314bedf JM |
534 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
535 | hostapd.add_ap(apdev[0]['ifname'], params) | |
536 | dev[0].request("SET external_sim 1") | |
537 | id = dev[0].connect("test-wpa2-eap", eap="AKA", key_mgmt="WPA-EAP", | |
538 | identity="0232010000000000", | |
539 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
540 | wait_connect=False, scan_freq="2412") | |
541 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) | |
542 | if ev is None: | |
543 | raise Exception("Network connected timed out") | |
544 | ||
545 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
546 | if ev is None: | |
547 | raise Exception("Wait for external SIM processing request timed out") | |
548 | p = ev.split(':', 2) | |
549 | if p[1] != "UMTS-AUTH": | |
550 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
551 | rid = p[0].split('-')[3] | |
552 | ||
553 | # IK:CK:RES | |
554 | resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344" | |
555 | # This will fail during processing, but the ctrl_iface command succeeds | |
556 | dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp) | |
557 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
558 | if ev is None: | |
559 | raise Exception("EAP failure not reported") | |
560 | dev[0].request("DISCONNECT") | |
584e4197 | 561 | dev[0].wait_disconnected() |
d314bedf | 562 | |
584e4197 | 563 | dev[0].select_network(id, freq="2412") |
d314bedf JM |
564 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) |
565 | if ev is None: | |
566 | raise Exception("Wait for external SIM processing request timed out") | |
567 | p = ev.split(':', 2) | |
568 | if p[1] != "UMTS-AUTH": | |
569 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
570 | rid = p[0].split('-')[3] | |
571 | # This will fail during UMTS auth validation | |
572 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:" + resp): | |
573 | raise Exception("CTRL-RSP-SIM failed") | |
574 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
575 | if ev is None: | |
576 | raise Exception("EAP failure not reported") | |
d8e02214 | 577 | dev[0].request("DISCONNECT") |
584e4197 | 578 | dev[0].wait_disconnected() |
d8e02214 JM |
579 | |
580 | dev[0].select_network(id, freq="2412") | |
581 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
582 | if ev is None: | |
583 | raise Exception("Wait for external SIM processing request timed out") | |
584 | p = ev.split(':', 2) | |
585 | if p[1] != "UMTS-AUTH": | |
586 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
587 | rid = p[0].split('-')[3] | |
588 | # This will fail during UMTS auth validation | |
589 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:112233445566778899aabbccddee"): | |
590 | raise Exception("CTRL-RSP-SIM failed") | |
591 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
592 | if ev is None: | |
593 | raise Exception("Wait for external SIM processing request timed out") | |
594 | p = ev.split(':', 2) | |
595 | if p[1] != "UMTS-AUTH": | |
596 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
597 | rid = p[0].split('-')[3] | |
598 | # This will fail during UMTS auth validation | |
599 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:12"): | |
600 | raise Exception("CTRL-RSP-SIM failed") | |
601 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
602 | if ev is None: | |
603 | raise Exception("EAP failure not reported") | |
604 | dev[0].request("DISCONNECT") | |
584e4197 | 605 | dev[0].wait_disconnected() |
d8e02214 JM |
606 | |
607 | dev[0].select_network(id, freq="2412") | |
608 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
609 | if ev is None: | |
610 | raise Exception("Wait for external SIM processing request timed out") | |
611 | p = ev.split(':', 2) | |
612 | if p[1] != "UMTS-AUTH": | |
613 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
614 | rid = p[0].split('-')[3] | |
615 | # This will fail during UMTS auth validation | |
616 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:34"): | |
617 | raise Exception("CTRL-RSP-SIM failed") | |
618 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
619 | if ev is None: | |
620 | raise Exception("EAP failure not reported") | |
621 | dev[0].request("DISCONNECT") | |
584e4197 | 622 | dev[0].wait_disconnected() |
d8e02214 JM |
623 | |
624 | dev[0].select_network(id, freq="2412") | |
625 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
626 | if ev is None: | |
627 | raise Exception("Wait for external SIM processing request timed out") | |
628 | p = ev.split(':', 2) | |
629 | if p[1] != "UMTS-AUTH": | |
630 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
631 | rid = p[0].split('-')[3] | |
632 | # This will fail during UMTS auth validation | |
633 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:00112233445566778899aabbccddeeff.00112233445566778899aabbccddeeff:0011223344"): | |
634 | raise Exception("CTRL-RSP-SIM failed") | |
635 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
636 | if ev is None: | |
637 | raise Exception("EAP failure not reported") | |
638 | dev[0].request("DISCONNECT") | |
584e4197 | 639 | dev[0].wait_disconnected() |
d8e02214 JM |
640 | |
641 | dev[0].select_network(id, freq="2412") | |
642 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
643 | if ev is None: | |
644 | raise Exception("Wait for external SIM processing request timed out") | |
645 | p = ev.split(':', 2) | |
646 | if p[1] != "UMTS-AUTH": | |
647 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
648 | rid = p[0].split('-')[3] | |
649 | # This will fail during UMTS auth validation | |
650 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddee:0011223344"): | |
651 | raise Exception("CTRL-RSP-SIM failed") | |
652 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
653 | if ev is None: | |
654 | raise Exception("EAP failure not reported") | |
655 | dev[0].request("DISCONNECT") | |
584e4197 | 656 | dev[0].wait_disconnected() |
d8e02214 JM |
657 | |
658 | dev[0].select_network(id, freq="2412") | |
659 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
660 | if ev is None: | |
661 | raise Exception("Wait for external SIM processing request timed out") | |
662 | p = ev.split(':', 2) | |
663 | if p[1] != "UMTS-AUTH": | |
664 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
665 | rid = p[0].split('-')[3] | |
666 | # This will fail during UMTS auth validation | |
667 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff.0011223344"): | |
668 | raise Exception("CTRL-RSP-SIM failed") | |
669 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
670 | if ev is None: | |
671 | raise Exception("EAP failure not reported") | |
672 | dev[0].request("DISCONNECT") | |
584e4197 | 673 | dev[0].wait_disconnected() |
d8e02214 JM |
674 | |
675 | dev[0].select_network(id, freq="2412") | |
676 | ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15) | |
677 | if ev is None: | |
678 | raise Exception("Wait for external SIM processing request timed out") | |
679 | p = ev.split(':', 2) | |
680 | if p[1] != "UMTS-AUTH": | |
681 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
682 | rid = p[0].split('-')[3] | |
683 | # This will fail during UMTS auth validation | |
684 | if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff0011223344"): | |
685 | raise Exception("CTRL-RSP-SIM failed") | |
686 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15) | |
687 | if ev is None: | |
688 | raise Exception("EAP failure not reported") | |
689 | dev[0].request("DISCONNECT") | |
584e4197 | 690 | dev[0].wait_disconnected() |
d8e02214 JM |
691 | |
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 + ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:001122334q"): | |
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") | |
584e4197 JM |
706 | dev[0].request("DISCONNECT") |
707 | dev[0].wait_disconnected() | |
d314bedf | 708 | |
9626962d JM |
709 | def test_ap_wpa2_eap_aka_prime(dev, apdev): |
710 | """WPA2-Enterprise connection using EAP-AKA'""" | |
81e787b7 | 711 | check_hlr_auc_gw_support() |
9626962d | 712 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 713 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 714 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", |
9626962d | 715 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") |
a8375c94 | 716 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 717 | eap_reauth(dev[0], "AKA'") |
9626962d | 718 | |
8583d664 JM |
719 | logger.info("EAP-AKA' bidding protection when EAP-AKA enabled as well") |
720 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="AKA' AKA", | |
721 | identity="6555444333222111@both", | |
722 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
723 | wait_connect=False, scan_freq="2412") | |
5f35a5e2 | 724 | dev[1].wait_connected(timeout=15) |
8583d664 | 725 | |
f10ba3b2 JM |
726 | logger.info("Negative test with incorrect key") |
727 | dev[0].request("REMOVE_NETWORK all") | |
728 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
729 | password="ff22250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
730 | expect_failure=True) | |
731 | ||
5b1aaf6c JM |
732 | def test_ap_wpa2_eap_aka_prime_sql(dev, apdev, params): |
733 | """WPA2-Enterprise connection using EAP-AKA' (SQL)""" | |
81e787b7 | 734 | check_hlr_auc_gw_support() |
5b1aaf6c JM |
735 | try: |
736 | import sqlite3 | |
737 | except ImportError: | |
81e787b7 | 738 | raise HwsimSkip("No sqlite3 module available") |
5b1aaf6c JM |
739 | con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) |
740 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
741 | params['auth_server_port'] = "1814" | |
742 | hostapd.add_ap(apdev[0]['ifname'], params) | |
743 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
744 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") | |
745 | ||
746 | logger.info("AKA' fast re-authentication") | |
747 | eap_reauth(dev[0], "AKA'") | |
748 | ||
749 | logger.info("AKA' full auth with pseudonym") | |
750 | with con: | |
751 | cur = con.cursor() | |
752 | cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'") | |
753 | eap_reauth(dev[0], "AKA'") | |
754 | ||
755 | logger.info("AKA' full auth with permanent identity") | |
756 | with con: | |
757 | cur = con.cursor() | |
758 | cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'") | |
759 | cur.execute("DELETE FROM pseudonyms WHERE permanent='6555444333222111'") | |
760 | eap_reauth(dev[0], "AKA'") | |
761 | ||
762 | logger.info("AKA' reauth with mismatching k_aut") | |
763 | with con: | |
764 | cur = con.cursor() | |
765 | cur.execute("UPDATE reauth SET k_aut='0000000000000000000000000000000000000000000000000000000000000000' WHERE permanent='6555444333222111'") | |
766 | eap_reauth(dev[0], "AKA'", expect_failure=True) | |
767 | dev[0].request("REMOVE_NETWORK all") | |
768 | ||
769 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
770 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") | |
771 | with con: | |
772 | cur = con.cursor() | |
773 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'") | |
774 | eap_reauth(dev[0], "AKA'") | |
775 | with con: | |
776 | cur = con.cursor() | |
777 | cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'") | |
778 | logger.info("AKA' reauth with mismatching counter") | |
779 | eap_reauth(dev[0], "AKA'") | |
780 | dev[0].request("REMOVE_NETWORK all") | |
781 | ||
782 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
783 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") | |
784 | with con: | |
785 | cur = con.cursor() | |
786 | cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='6555444333222111'") | |
787 | logger.info("AKA' reauth with max reauth count reached") | |
788 | eap_reauth(dev[0], "AKA'") | |
789 | ||
9626962d JM |
790 | def test_ap_wpa2_eap_ttls_pap(dev, apdev): |
791 | """WPA2-Enterprise connection using EAP-TTLS/PAP""" | |
792 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
65038313 JM |
793 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
794 | key_mgmt = hapd.get_config()['key_mgmt'] | |
795 | if key_mgmt.split(' ')[0] != "WPA-EAP": | |
796 | raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt) | |
cb33ee14 | 797 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
9626962d | 798 | anonymous_identity="ttls", password="password", |
506b2f05 | 799 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") |
a8375c94 | 800 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 801 | eap_reauth(dev[0], "TTLS") |
eaf3f9b1 JM |
802 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-1"), |
803 | ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-1") ]) | |
9626962d | 804 | |
506b2f05 JM |
805 | def test_ap_wpa2_eap_ttls_pap_subject_match(dev, apdev): |
806 | """WPA2-Enterprise connection using EAP-TTLS/PAP and (alt)subject_match""" | |
807 | check_subject_match_support(dev[0]) | |
808 | check_altsubject_match_support(dev[0]) | |
809 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
810 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
811 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
812 | anonymous_identity="ttls", password="password", | |
813 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
814 | subject_match="/C=FI/O=w1.fi/CN=server.w1.fi", | |
815 | altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/") | |
816 | eap_reauth(dev[0], "TTLS") | |
817 | ||
82a8f5b5 JM |
818 | def test_ap_wpa2_eap_ttls_pap_incorrect_password(dev, apdev): |
819 | """WPA2-Enterprise connection using EAP-TTLS/PAP - incorrect password""" | |
820 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
821 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
822 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
823 | anonymous_identity="ttls", password="wrong", | |
824 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
825 | expect_failure=True) | |
826 | eap_connect(dev[1], apdev[0], "TTLS", "user", | |
827 | anonymous_identity="ttls", password="password", | |
828 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
829 | expect_failure=True) | |
830 | ||
9626962d JM |
831 | def test_ap_wpa2_eap_ttls_chap(dev, apdev): |
832 | """WPA2-Enterprise connection using EAP-TTLS/CHAP""" | |
833 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
a8375c94 | 834 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
506b2f05 JM |
835 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", |
836 | anonymous_identity="ttls", password="password", | |
837 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP") | |
838 | hwsim_utils.test_connectivity(dev[0], hapd) | |
839 | eap_reauth(dev[0], "TTLS") | |
840 | ||
841 | def test_ap_wpa2_eap_ttls_chap_altsubject_match(dev, apdev): | |
842 | """WPA2-Enterprise connection using EAP-TTLS/CHAP""" | |
843 | check_altsubject_match_support(dev[0]) | |
844 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
845 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 846 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", |
9626962d | 847 | anonymous_identity="ttls", password="password", |
5c65e277 JM |
848 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP", |
849 | altsubject_match="EMAIL:noone@example.com;URI:http://example.com/;DNS:server.w1.fi") | |
75b2b9cf | 850 | eap_reauth(dev[0], "TTLS") |
9626962d | 851 | |
82a8f5b5 JM |
852 | def test_ap_wpa2_eap_ttls_chap_incorrect_password(dev, apdev): |
853 | """WPA2-Enterprise connection using EAP-TTLS/CHAP - incorrect password""" | |
854 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
855 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
856 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", | |
857 | anonymous_identity="ttls", password="wrong", | |
858 | ca_cert="auth_serv/ca.pem", phase2="auth=CHAP", | |
859 | expect_failure=True) | |
860 | eap_connect(dev[1], apdev[0], "TTLS", "user", | |
861 | anonymous_identity="ttls", password="password", | |
862 | ca_cert="auth_serv/ca.pem", phase2="auth=CHAP", | |
863 | expect_failure=True) | |
864 | ||
9626962d JM |
865 | def test_ap_wpa2_eap_ttls_mschap(dev, apdev): |
866 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAP""" | |
867 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
a8375c94 | 868 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 869 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", |
9626962d | 870 | anonymous_identity="ttls", password="password", |
72c052d5 JM |
871 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", |
872 | domain_suffix_match="server.w1.fi") | |
a8375c94 | 873 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 874 | eap_reauth(dev[0], "TTLS") |
6daf5b9c JM |
875 | dev[0].request("REMOVE_NETWORK all") |
876 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", | |
877 | anonymous_identity="ttls", password="password", | |
878 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
879 | fragment_size="200") | |
9626962d | 880 | |
82a8f5b5 JM |
881 | def test_ap_wpa2_eap_ttls_mschap_incorrect_password(dev, apdev): |
882 | """WPA2-Enterprise connection using EAP-TTLS/CHAP - incorrect password""" | |
883 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
884 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
885 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", | |
886 | anonymous_identity="ttls", password="wrong", | |
887 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
888 | expect_failure=True) | |
889 | eap_connect(dev[1], apdev[0], "TTLS", "user", | |
890 | anonymous_identity="ttls", password="password", | |
891 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
892 | expect_failure=True) | |
893 | eap_connect(dev[2], apdev[0], "TTLS", "no such user", | |
894 | anonymous_identity="ttls", password="password", | |
895 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
896 | expect_failure=True) | |
897 | ||
9626962d JM |
898 | def test_ap_wpa2_eap_ttls_mschapv2(dev, apdev): |
899 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2""" | |
900 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
901 | hostapd.add_ap(apdev[0]['ifname'], params) | |
5dec879d | 902 | hapd = hostapd.Hostapd(apdev[0]['ifname']) |
cb33ee14 | 903 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", |
9626962d | 904 | anonymous_identity="ttls", password="password", |
72c052d5 | 905 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", |
24579e70 | 906 | domain_suffix_match="server.w1.fi") |
a8375c94 | 907 | hwsim_utils.test_connectivity(dev[0], hapd) |
5dec879d JM |
908 | sta1 = hapd.get_sta(dev[0].p2p_interface_addr()) |
909 | eapol1 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol") | |
75b2b9cf | 910 | eap_reauth(dev[0], "TTLS") |
5dec879d JM |
911 | sta2 = hapd.get_sta(dev[0].p2p_interface_addr()) |
912 | eapol2 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol") | |
913 | if int(sta2['dot1xAuthEapolFramesRx']) <= int(sta1['dot1xAuthEapolFramesRx']): | |
914 | raise Exception("dot1xAuthEapolFramesRx did not increase") | |
915 | if int(eapol2['authAuthEapStartsWhileAuthenticated']) < 1: | |
916 | raise Exception("authAuthEapStartsWhileAuthenticated did not increase") | |
917 | if int(eapol2['backendAuthSuccesses']) <= int(eapol1['backendAuthSuccesses']): | |
918 | raise Exception("backendAuthSuccesses did not increase") | |
9626962d | 919 | |
fa0ddb14 JM |
920 | logger.info("Password as hash value") |
921 | dev[0].request("REMOVE_NETWORK all") | |
922 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
923 | anonymous_identity="ttls", | |
924 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
925 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
926 | ||
24579e70 JM |
927 | def test_ap_wpa2_eap_ttls_mschapv2_suffix_match(dev, apdev): |
928 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2""" | |
929 | check_domain_match_full(dev[0]) | |
930 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
931 | hostapd.add_ap(apdev[0]['ifname'], params) | |
932 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
933 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
934 | anonymous_identity="ttls", password="password", | |
935 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
936 | domain_suffix_match="w1.fi") | |
937 | hwsim_utils.test_connectivity(dev[0], hapd) | |
938 | eap_reauth(dev[0], "TTLS") | |
939 | ||
061cbb25 JM |
940 | def test_ap_wpa2_eap_ttls_mschapv2_domain_match(dev, apdev): |
941 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 (domain_match)""" | |
942 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
943 | hostapd.add_ap(apdev[0]['ifname'], params) | |
944 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
945 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
946 | anonymous_identity="ttls", password="password", | |
947 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
948 | domain_match="Server.w1.fi") | |
949 | hwsim_utils.test_connectivity(dev[0], hapd) | |
950 | eap_reauth(dev[0], "TTLS") | |
951 | ||
82a8f5b5 JM |
952 | def test_ap_wpa2_eap_ttls_mschapv2_incorrect_password(dev, apdev): |
953 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 - incorrect password""" | |
954 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
955 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
f10ba3b2 JM |
956 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", |
957 | anonymous_identity="ttls", password="password1", | |
958 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
959 | expect_failure=True) | |
82a8f5b5 JM |
960 | eap_connect(dev[1], apdev[0], "TTLS", "user", |
961 | anonymous_identity="ttls", password="password", | |
962 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
963 | expect_failure=True) | |
f10ba3b2 | 964 | |
eac67440 JM |
965 | def test_ap_wpa2_eap_ttls_mschapv2_utf8(dev, apdev): |
966 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 and UTF-8 password""" | |
967 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
968 | hostapd.add_ap(apdev[0]['ifname'], params) | |
969 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
970 | eap_connect(dev[0], apdev[0], "TTLS", "utf8-user-hash", | |
971 | anonymous_identity="ttls", password="secret-åäö-€-password", | |
972 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
973 | eap_connect(dev[1], apdev[0], "TTLS", "utf8-user", | |
974 | anonymous_identity="ttls", | |
975 | password_hex="hash:bd5844fad2489992da7fe8c5a01559cf", | |
976 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
977 | ||
9626962d JM |
978 | def test_ap_wpa2_eap_ttls_eap_gtc(dev, apdev): |
979 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC""" | |
980 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
a8375c94 | 981 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 982 | eap_connect(dev[0], apdev[0], "TTLS", "user", |
9626962d JM |
983 | anonymous_identity="ttls", password="password", |
984 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC") | |
a8375c94 | 985 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 986 | eap_reauth(dev[0], "TTLS") |
9626962d JM |
987 | |
988 | def test_ap_wpa2_eap_ttls_eap_md5(dev, apdev): | |
989 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5""" | |
990 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
a8375c94 | 991 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 992 | eap_connect(dev[0], apdev[0], "TTLS", "user", |
9626962d JM |
993 | anonymous_identity="ttls", password="password", |
994 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5") | |
a8375c94 | 995 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 996 | eap_reauth(dev[0], "TTLS") |
9626962d | 997 | |
ee9533eb JM |
998 | def test_ap_wpa2_eap_ttls_eap_md5_incorrect_password(dev, apdev): |
999 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - incorrect password""" | |
1000 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1001 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1002 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
1003 | anonymous_identity="ttls", password="wrong", | |
1004 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1005 | expect_failure=True) | |
1006 | ||
1007 | def test_ap_wpa2_eap_ttls_eap_md5_server_oom(dev, apdev): | |
1008 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - server OOM""" | |
1009 | params = int_eap_server_params() | |
1010 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1011 | with alloc_fail(hapd, 1, "eap_md5_init"): | |
1012 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
1013 | anonymous_identity="ttls", password="password", | |
1014 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1015 | expect_failure=True) | |
1016 | dev[0].request("REMOVE_NETWORK all") | |
1017 | ||
1018 | with alloc_fail(hapd, 1, "eap_md5_buildReq"): | |
1019 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1020 | eap="TTLS", identity="user", | |
1021 | anonymous_identity="ttls", password="password", | |
1022 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5", | |
1023 | wait_connect=False, scan_freq="2412") | |
1024 | # This would eventually time out, but we can stop after having reached | |
1025 | # the allocation failure. | |
1026 | for i in range(20): | |
1027 | time.sleep(0.1) | |
1028 | if hapd.request("GET_ALLOC_FAIL").startswith('0'): | |
1029 | break | |
1030 | ||
9626962d JM |
1031 | def test_ap_wpa2_eap_ttls_eap_mschapv2(dev, apdev): |
1032 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2""" | |
1033 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
a8375c94 | 1034 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 1035 | eap_connect(dev[0], apdev[0], "TTLS", "user", |
9626962d JM |
1036 | anonymous_identity="ttls", password="password", |
1037 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2") | |
a8375c94 | 1038 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1039 | eap_reauth(dev[0], "TTLS") |
9626962d | 1040 | |
f10ba3b2 JM |
1041 | logger.info("Negative test with incorrect password") |
1042 | dev[0].request("REMOVE_NETWORK all") | |
1043 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
1044 | anonymous_identity="ttls", password="password1", | |
1045 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
1046 | expect_failure=True) | |
1047 | ||
95fb531c JM |
1048 | def test_ap_wpa2_eap_ttls_eap_aka(dev, apdev): |
1049 | """WPA2-Enterprise connection using EAP-TTLS/EAP-AKA""" | |
1050 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1051 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1052 | eap_connect(dev[0], apdev[0], "TTLS", "0232010000000000", | |
1053 | anonymous_identity="0232010000000000@ttls", | |
1054 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1055 | ca_cert="auth_serv/ca.pem", phase2="autheap=AKA") | |
1056 | ||
1057 | def test_ap_wpa2_eap_peap_eap_aka(dev, apdev): | |
1058 | """WPA2-Enterprise connection using EAP-PEAP/EAP-AKA""" | |
1059 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1060 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1061 | eap_connect(dev[0], apdev[0], "PEAP", "0232010000000000", | |
1062 | anonymous_identity="0232010000000000@peap", | |
1063 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1064 | ca_cert="auth_serv/ca.pem", phase2="auth=AKA") | |
1065 | ||
1066 | def test_ap_wpa2_eap_fast_eap_aka(dev, apdev): | |
1067 | """WPA2-Enterprise connection using EAP-FAST/EAP-AKA""" | |
3b51cc63 | 1068 | check_eap_capa(dev[0], "FAST") |
95fb531c JM |
1069 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1070 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1071 | eap_connect(dev[0], apdev[0], "FAST", "0232010000000000", | |
1072 | anonymous_identity="0232010000000000@fast", | |
1073 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1074 | phase1="fast_provisioning=2", | |
1075 | pac_file="blob://fast_pac_auth_aka", | |
1076 | ca_cert="auth_serv/ca.pem", phase2="auth=AKA") | |
1077 | ||
9626962d JM |
1078 | def test_ap_wpa2_eap_peap_eap_mschapv2(dev, apdev): |
1079 | """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2""" | |
1080 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
a8375c94 | 1081 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 1082 | eap_connect(dev[0], apdev[0], "PEAP", "user", |
698f8324 | 1083 | anonymous_identity="peap", password="password", |
9626962d | 1084 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") |
a8375c94 | 1085 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1086 | eap_reauth(dev[0], "PEAP") |
6daf5b9c JM |
1087 | dev[0].request("REMOVE_NETWORK all") |
1088 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
1089 | anonymous_identity="peap", password="password", | |
1090 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1091 | fragment_size="200") | |
c7afc078 | 1092 | |
fa0ddb14 JM |
1093 | logger.info("Password as hash value") |
1094 | dev[0].request("REMOVE_NETWORK all") | |
1095 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
1096 | anonymous_identity="peap", | |
1097 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
1098 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
1099 | ||
f10ba3b2 JM |
1100 | logger.info("Negative test with incorrect password") |
1101 | dev[0].request("REMOVE_NETWORK all") | |
1102 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
1103 | anonymous_identity="peap", password="password1", | |
1104 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1105 | expect_failure=True) | |
1106 | ||
698f8324 JM |
1107 | def test_ap_wpa2_eap_peap_crypto_binding(dev, apdev): |
1108 | """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding""" | |
1109 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
a8375c94 | 1110 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 1111 | eap_connect(dev[0], apdev[0], "PEAP", "user", password="password", |
698f8324 JM |
1112 | ca_cert="auth_serv/ca.pem", |
1113 | phase1="peapver=0 crypto_binding=2", | |
1114 | phase2="auth=MSCHAPV2") | |
a8375c94 | 1115 | hwsim_utils.test_connectivity(dev[0], hapd) |
75b2b9cf | 1116 | eap_reauth(dev[0], "PEAP") |
698f8324 | 1117 | |
ea6464b0 JM |
1118 | eap_connect(dev[1], apdev[0], "PEAP", "user", password="password", |
1119 | ca_cert="auth_serv/ca.pem", | |
1120 | phase1="peapver=0 crypto_binding=1", | |
1121 | phase2="auth=MSCHAPV2") | |
1122 | eap_connect(dev[2], apdev[0], "PEAP", "user", password="password", | |
1123 | ca_cert="auth_serv/ca.pem", | |
1124 | phase1="peapver=0 crypto_binding=0", | |
1125 | phase2="auth=MSCHAPV2") | |
1126 | ||
c4d37011 JM |
1127 | def test_ap_wpa2_eap_peap_params(dev, apdev): |
1128 | """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and various parameters""" | |
1129 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1130 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1131 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
1132 | anonymous_identity="peap", password="password", | |
1133 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1134 | phase1="peapver=0 peaplabel=1", | |
1135 | expect_failure=True) | |
1136 | dev[0].request("REMOVE_NETWORK all") | |
1137 | eap_connect(dev[1], apdev[0], "PEAP", "user", password="password", | |
1138 | ca_cert="auth_serv/ca.pem", | |
1139 | phase1="peap_outer_success=1", | |
1140 | phase2="auth=MSCHAPV2") | |
1141 | eap_connect(dev[2], apdev[0], "PEAP", "user", password="password", | |
1142 | ca_cert="auth_serv/ca.pem", | |
1143 | phase1="peap_outer_success=2", | |
1144 | phase2="auth=MSCHAPV2") | |
1145 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
1146 | identity="user", | |
1147 | anonymous_identity="peap", password="password", | |
1148 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1149 | phase1="peapver=1 peaplabel=1", | |
1150 | wait_connect=False, scan_freq="2412") | |
1151 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) | |
1152 | if ev is None: | |
1153 | raise Exception("No EAP success seen") | |
1154 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1) | |
1155 | if ev is not None: | |
1156 | raise Exception("Unexpected connection") | |
1157 | ||
d0ce1050 JM |
1158 | def test_ap_wpa2_eap_peap_eap_tls(dev, apdev): |
1159 | """WPA2-Enterprise connection using EAP-PEAP/EAP-TLS""" | |
1160 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1161 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1162 | eap_connect(dev[0], apdev[0], "PEAP", "cert user", | |
1163 | ca_cert="auth_serv/ca.pem", phase2="auth=TLS", | |
1164 | ca_cert2="auth_serv/ca.pem", | |
1165 | client_cert2="auth_serv/user.pem", | |
1166 | private_key2="auth_serv/user.key") | |
1167 | eap_reauth(dev[0], "PEAP") | |
1168 | ||
e114c49c JM |
1169 | def test_ap_wpa2_eap_tls(dev, apdev): |
1170 | """WPA2-Enterprise connection using EAP-TLS""" | |
1171 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1172 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 1173 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
e114c49c JM |
1174 | client_cert="auth_serv/user.pem", |
1175 | private_key="auth_serv/user.key") | |
75b2b9cf | 1176 | eap_reauth(dev[0], "TLS") |
e114c49c | 1177 | |
6ea231e6 JM |
1178 | def test_ap_wpa2_eap_tls_blob(dev, apdev): |
1179 | """WPA2-Enterprise connection using EAP-TLS and config blobs""" | |
1180 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1181 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1182 | cert = read_pem("auth_serv/ca.pem") | |
1183 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
1184 | raise Exception("Could not set cacert blob") | |
1185 | cert = read_pem("auth_serv/user.pem") | |
1186 | if "OK" not in dev[0].request("SET blob usercert " + cert.encode("hex")): | |
1187 | raise Exception("Could not set usercert blob") | |
62750c3e | 1188 | key = read_pem("auth_serv/user.rsa-key") |
6ea231e6 JM |
1189 | if "OK" not in dev[0].request("SET blob userkey " + key.encode("hex")): |
1190 | raise Exception("Could not set cacert blob") | |
1191 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="blob://cacert", | |
1192 | client_cert="blob://usercert", | |
1193 | private_key="blob://userkey") | |
1194 | ||
2d10eb0e JM |
1195 | def test_ap_wpa2_eap_tls_pkcs12(dev, apdev): |
1196 | """WPA2-Enterprise connection using EAP-TLS and PKCS#12""" | |
1197 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1198 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1199 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
1200 | private_key="auth_serv/user.pkcs12", | |
1201 | private_key_passwd="whatever") | |
1202 | dev[0].request("REMOVE_NETWORK all") | |
1203 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
1204 | identity="tls user", | |
1205 | ca_cert="auth_serv/ca.pem", | |
1206 | private_key="auth_serv/user.pkcs12", | |
1207 | wait_connect=False, scan_freq="2412") | |
1208 | ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"]) | |
1209 | if ev is None: | |
1210 | raise Exception("Request for private key passphrase timed out") | |
1211 | id = ev.split(':')[0].split('-')[-1] | |
1212 | dev[0].request("CTRL-RSP-PASSPHRASE-" + id + ":whatever") | |
5f35a5e2 | 1213 | dev[0].wait_connected(timeout=10) |
2d10eb0e | 1214 | |
6ea231e6 JM |
1215 | def test_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev): |
1216 | """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob""" | |
1217 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1218 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1219 | cert = read_pem("auth_serv/ca.pem") | |
1220 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
1221 | raise Exception("Could not set cacert blob") | |
1222 | with open("auth_serv/user.pkcs12", "rb") as f: | |
1223 | if "OK" not in dev[0].request("SET blob pkcs12 " + f.read().encode("hex")): | |
1224 | raise Exception("Could not set pkcs12 blob") | |
1225 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="blob://cacert", | |
1226 | private_key="blob://pkcs12", | |
1227 | private_key_passwd="whatever") | |
1228 | ||
c7afc078 JM |
1229 | def test_ap_wpa2_eap_tls_neg_incorrect_trust_root(dev, apdev): |
1230 | """WPA2-Enterprise negative test - incorrect trust root""" | |
1231 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1232 | hostapd.add_ap(apdev[0]['ifname'], params) | |
6ea231e6 JM |
1233 | cert = read_pem("auth_serv/ca-incorrect.pem") |
1234 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
1235 | raise Exception("Could not set cacert blob") | |
c7afc078 | 1236 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
6ea231e6 JM |
1237 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", |
1238 | password="password", phase2="auth=MSCHAPV2", | |
1239 | ca_cert="blob://cacert", | |
1240 | wait_connect=False, scan_freq="2412") | |
1241 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
c7afc078 JM |
1242 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", |
1243 | password="password", phase2="auth=MSCHAPV2", | |
1244 | ca_cert="auth_serv/ca-incorrect.pem", | |
c65f23ab | 1245 | wait_connect=False, scan_freq="2412") |
c7afc078 | 1246 | |
6ea231e6 JM |
1247 | for dev in (dev[0], dev[1]): |
1248 | ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1249 | if ev is None: | |
1250 | raise Exception("Association and EAP start timed out") | |
c7afc078 | 1251 | |
6ea231e6 JM |
1252 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) |
1253 | if ev is None: | |
1254 | raise Exception("EAP method selection timed out") | |
1255 | if "TTLS" not in ev: | |
1256 | raise Exception("Unexpected EAP method") | |
1257 | ||
1258 | ev = dev.wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1259 | "CTRL-EVENT-EAP-SUCCESS", | |
1260 | "CTRL-EVENT-EAP-FAILURE", | |
1261 | "CTRL-EVENT-CONNECTED", | |
1262 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1263 | if ev is None: | |
1264 | raise Exception("EAP result timed out") | |
1265 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1266 | raise Exception("TLS certificate error not reported") | |
1267 | ||
1268 | ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1269 | "CTRL-EVENT-EAP-FAILURE", | |
1270 | "CTRL-EVENT-CONNECTED", | |
1271 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1272 | if ev is None: | |
1273 | raise Exception("EAP result(2) timed out") | |
1274 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1275 | raise Exception("EAP failure not reported") | |
c7afc078 | 1276 | |
6ea231e6 JM |
1277 | ev = dev.wait_event(["CTRL-EVENT-CONNECTED", |
1278 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1279 | if ev is None: | |
1280 | raise Exception("EAP result(3) timed out") | |
1281 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1282 | raise Exception("Disconnection not reported") | |
c7afc078 | 1283 | |
6ea231e6 JM |
1284 | ev = dev.wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) |
1285 | if ev is None: | |
1286 | raise Exception("Network block disabling not reported") | |
72c052d5 | 1287 | |
9a5cfd70 JM |
1288 | def test_ap_wpa2_eap_tls_diff_ca_trust(dev, apdev): |
1289 | """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust""" | |
1290 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1291 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1292 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1293 | identity="pap user", anonymous_identity="ttls", | |
1294 | password="password", phase2="auth=PAP", | |
1295 | ca_cert="auth_serv/ca.pem", | |
1296 | wait_connect=True, scan_freq="2412") | |
1297 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1298 | identity="pap user", anonymous_identity="ttls", | |
1299 | password="password", phase2="auth=PAP", | |
1300 | ca_cert="auth_serv/ca-incorrect.pem", | |
1301 | only_add_network=True, scan_freq="2412") | |
1302 | ||
1303 | dev[0].request("DISCONNECT") | |
1304 | dev[0].dump_monitor() | |
1305 | dev[0].select_network(id, freq="2412") | |
1306 | ||
1307 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15) | |
1308 | if ev is None: | |
1309 | raise Exception("EAP-TTLS not re-started") | |
1310 | ||
5f35a5e2 | 1311 | ev = dev[0].wait_disconnected(timeout=15) |
9a5cfd70 JM |
1312 | if "reason=23" not in ev: |
1313 | raise Exception("Proper reason code for disconnection not reported") | |
1314 | ||
1315 | def test_ap_wpa2_eap_tls_diff_ca_trust2(dev, apdev): | |
1316 | """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust""" | |
1317 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1318 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1319 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1320 | identity="pap user", anonymous_identity="ttls", | |
1321 | password="password", phase2="auth=PAP", | |
1322 | wait_connect=True, scan_freq="2412") | |
1323 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1324 | identity="pap user", anonymous_identity="ttls", | |
1325 | password="password", phase2="auth=PAP", | |
1326 | ca_cert="auth_serv/ca-incorrect.pem", | |
1327 | only_add_network=True, scan_freq="2412") | |
1328 | ||
1329 | dev[0].request("DISCONNECT") | |
1330 | dev[0].dump_monitor() | |
1331 | dev[0].select_network(id, freq="2412") | |
1332 | ||
1333 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15) | |
1334 | if ev is None: | |
1335 | raise Exception("EAP-TTLS not re-started") | |
1336 | ||
5f35a5e2 | 1337 | ev = dev[0].wait_disconnected(timeout=15) |
9a5cfd70 JM |
1338 | if "reason=23" not in ev: |
1339 | raise Exception("Proper reason code for disconnection not reported") | |
1340 | ||
1341 | def test_ap_wpa2_eap_tls_diff_ca_trust3(dev, apdev): | |
1342 | """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust""" | |
1343 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1344 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1345 | id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1346 | identity="pap user", anonymous_identity="ttls", | |
1347 | password="password", phase2="auth=PAP", | |
1348 | ca_cert="auth_serv/ca.pem", | |
1349 | wait_connect=True, scan_freq="2412") | |
1350 | dev[0].request("DISCONNECT") | |
1351 | dev[0].dump_monitor() | |
1352 | dev[0].set_network_quoted(id, "ca_cert", "auth_serv/ca-incorrect.pem") | |
1353 | dev[0].select_network(id, freq="2412") | |
1354 | ||
1355 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15) | |
1356 | if ev is None: | |
1357 | raise Exception("EAP-TTLS not re-started") | |
1358 | ||
5f35a5e2 | 1359 | ev = dev[0].wait_disconnected(timeout=15) |
9a5cfd70 JM |
1360 | if "reason=23" not in ev: |
1361 | raise Exception("Proper reason code for disconnection not reported") | |
1362 | ||
72c052d5 JM |
1363 | def test_ap_wpa2_eap_tls_neg_suffix_match(dev, apdev): |
1364 | """WPA2-Enterprise negative test - domain suffix mismatch""" | |
1365 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1366 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1367 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1368 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1369 | password="password", phase2="auth=MSCHAPV2", | |
1370 | ca_cert="auth_serv/ca.pem", | |
1371 | domain_suffix_match="incorrect.example.com", | |
c65f23ab | 1372 | wait_connect=False, scan_freq="2412") |
72c052d5 JM |
1373 | |
1374 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1375 | if ev is None: | |
1376 | raise Exception("Association and EAP start timed out") | |
1377 | ||
1378 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
1379 | if ev is None: | |
1380 | raise Exception("EAP method selection timed out") | |
1381 | if "TTLS" not in ev: | |
1382 | raise Exception("Unexpected EAP method") | |
1383 | ||
1384 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1385 | "CTRL-EVENT-EAP-SUCCESS", | |
1386 | "CTRL-EVENT-EAP-FAILURE", | |
1387 | "CTRL-EVENT-CONNECTED", | |
1388 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1389 | if ev is None: | |
1390 | raise Exception("EAP result timed out") | |
1391 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1392 | raise Exception("TLS certificate error not reported") | |
1393 | if "Domain suffix mismatch" not in ev: | |
1394 | raise Exception("Domain suffix mismatch not reported") | |
1395 | ||
1396 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1397 | "CTRL-EVENT-EAP-FAILURE", | |
1398 | "CTRL-EVENT-CONNECTED", | |
1399 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1400 | if ev is None: | |
1401 | raise Exception("EAP result(2) timed out") | |
1402 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1403 | raise Exception("EAP failure not reported") | |
1404 | ||
1405 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
1406 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1407 | if ev is None: | |
1408 | raise Exception("EAP result(3) timed out") | |
1409 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1410 | raise Exception("Disconnection not reported") | |
1411 | ||
1412 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
1413 | if ev is None: | |
1414 | raise Exception("Network block disabling not reported") | |
22b99086 | 1415 | |
061cbb25 JM |
1416 | def test_ap_wpa2_eap_tls_neg_domain_match(dev, apdev): |
1417 | """WPA2-Enterprise negative test - domain mismatch""" | |
1418 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1419 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1420 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1421 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1422 | password="password", phase2="auth=MSCHAPV2", | |
1423 | ca_cert="auth_serv/ca.pem", | |
1424 | domain_match="w1.fi", | |
1425 | wait_connect=False, scan_freq="2412") | |
1426 | ||
1427 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1428 | if ev is None: | |
1429 | raise Exception("Association and EAP start timed out") | |
1430 | ||
1431 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
1432 | if ev is None: | |
1433 | raise Exception("EAP method selection timed out") | |
1434 | if "TTLS" not in ev: | |
1435 | raise Exception("Unexpected EAP method") | |
1436 | ||
1437 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1438 | "CTRL-EVENT-EAP-SUCCESS", | |
1439 | "CTRL-EVENT-EAP-FAILURE", | |
1440 | "CTRL-EVENT-CONNECTED", | |
1441 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1442 | if ev is None: | |
1443 | raise Exception("EAP result timed out") | |
1444 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1445 | raise Exception("TLS certificate error not reported") | |
1446 | if "Domain mismatch" not in ev: | |
1447 | raise Exception("Domain mismatch not reported") | |
1448 | ||
1449 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1450 | "CTRL-EVENT-EAP-FAILURE", | |
1451 | "CTRL-EVENT-CONNECTED", | |
1452 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1453 | if ev is None: | |
1454 | raise Exception("EAP result(2) timed out") | |
1455 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1456 | raise Exception("EAP failure not reported") | |
1457 | ||
1458 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
1459 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1460 | if ev is None: | |
1461 | raise Exception("EAP result(3) timed out") | |
1462 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1463 | raise Exception("Disconnection not reported") | |
1464 | ||
1465 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
1466 | if ev is None: | |
1467 | raise Exception("Network block disabling not reported") | |
1468 | ||
3b74982f JM |
1469 | def test_ap_wpa2_eap_tls_neg_subject_match(dev, apdev): |
1470 | """WPA2-Enterprise negative test - subject mismatch""" | |
1471 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1472 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1473 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1474 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1475 | password="password", phase2="auth=MSCHAPV2", | |
1476 | ca_cert="auth_serv/ca.pem", | |
1477 | subject_match="/C=FI/O=w1.fi/CN=example.com", | |
1478 | wait_connect=False, scan_freq="2412") | |
1479 | ||
1480 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1481 | if ev is None: | |
1482 | raise Exception("Association and EAP start timed out") | |
1483 | ||
506b2f05 JM |
1484 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD", |
1485 | "EAP: Failed to initialize EAP method"], timeout=10) | |
3b74982f JM |
1486 | if ev is None: |
1487 | raise Exception("EAP method selection timed out") | |
506b2f05 JM |
1488 | if "EAP: Failed to initialize EAP method" in ev: |
1489 | tls = dev[0].request("GET tls_library") | |
1490 | if tls.startswith("OpenSSL"): | |
1491 | raise Exception("Failed to select EAP method") | |
1492 | logger.info("subject_match not supported - connection failed, so test succeeded") | |
1493 | return | |
3b74982f JM |
1494 | if "TTLS" not in ev: |
1495 | raise Exception("Unexpected EAP method") | |
1496 | ||
1497 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1498 | "CTRL-EVENT-EAP-SUCCESS", | |
1499 | "CTRL-EVENT-EAP-FAILURE", | |
1500 | "CTRL-EVENT-CONNECTED", | |
1501 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1502 | if ev is None: | |
1503 | raise Exception("EAP result timed out") | |
1504 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1505 | raise Exception("TLS certificate error not reported") | |
1506 | if "Subject mismatch" not in ev: | |
1507 | raise Exception("Subject mismatch not reported") | |
1508 | ||
1509 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1510 | "CTRL-EVENT-EAP-FAILURE", | |
1511 | "CTRL-EVENT-CONNECTED", | |
1512 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1513 | if ev is None: | |
1514 | raise Exception("EAP result(2) timed out") | |
1515 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1516 | raise Exception("EAP failure not reported") | |
1517 | ||
1518 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
1519 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1520 | if ev is None: | |
1521 | raise Exception("EAP result(3) timed out") | |
1522 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1523 | raise Exception("Disconnection not reported") | |
1524 | ||
1525 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
1526 | if ev is None: | |
1527 | raise Exception("Network block disabling not reported") | |
1528 | ||
1529 | def test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev): | |
1530 | """WPA2-Enterprise negative test - altsubject mismatch""" | |
1531 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1532 | hostapd.add_ap(apdev[0]['ifname'], params) | |
37d61355 JM |
1533 | |
1534 | tests = [ "incorrect.example.com", | |
1535 | "DNS:incorrect.example.com", | |
1536 | "DNS:w1.fi", | |
1537 | "DNS:erver.w1.fi" ] | |
1538 | for match in tests: | |
1539 | _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match) | |
1540 | ||
1541 | def _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match): | |
3b74982f JM |
1542 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
1543 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1544 | password="password", phase2="auth=MSCHAPV2", | |
1545 | ca_cert="auth_serv/ca.pem", | |
37d61355 | 1546 | altsubject_match=match, |
3b74982f JM |
1547 | wait_connect=False, scan_freq="2412") |
1548 | ||
1549 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1550 | if ev is None: | |
1551 | raise Exception("Association and EAP start timed out") | |
1552 | ||
506b2f05 JM |
1553 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD", |
1554 | "EAP: Failed to initialize EAP method"], timeout=10) | |
3b74982f JM |
1555 | if ev is None: |
1556 | raise Exception("EAP method selection timed out") | |
506b2f05 JM |
1557 | if "EAP: Failed to initialize EAP method" in ev: |
1558 | tls = dev[0].request("GET tls_library") | |
1559 | if tls.startswith("OpenSSL"): | |
1560 | raise Exception("Failed to select EAP method") | |
1561 | logger.info("altsubject_match not supported - connection failed, so test succeeded") | |
1562 | return | |
3b74982f JM |
1563 | if "TTLS" not in ev: |
1564 | raise Exception("Unexpected EAP method") | |
1565 | ||
1566 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
1567 | "CTRL-EVENT-EAP-SUCCESS", | |
1568 | "CTRL-EVENT-EAP-FAILURE", | |
1569 | "CTRL-EVENT-CONNECTED", | |
1570 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1571 | if ev is None: | |
1572 | raise Exception("EAP result timed out") | |
1573 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
1574 | raise Exception("TLS certificate error not reported") | |
1575 | if "AltSubject mismatch" not in ev: | |
1576 | raise Exception("altsubject mismatch not reported") | |
1577 | ||
1578 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
1579 | "CTRL-EVENT-EAP-FAILURE", | |
1580 | "CTRL-EVENT-CONNECTED", | |
1581 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1582 | if ev is None: | |
1583 | raise Exception("EAP result(2) timed out") | |
1584 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
1585 | raise Exception("EAP failure not reported") | |
1586 | ||
1587 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
1588 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1589 | if ev is None: | |
1590 | raise Exception("EAP result(3) timed out") | |
1591 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
1592 | raise Exception("Disconnection not reported") | |
1593 | ||
1594 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
1595 | if ev is None: | |
1596 | raise Exception("Network block disabling not reported") | |
1597 | ||
37d61355 JM |
1598 | dev[0].request("REMOVE_NETWORK all") |
1599 | ||
5a0c1517 JM |
1600 | def test_ap_wpa2_eap_unauth_tls(dev, apdev): |
1601 | """WPA2-Enterprise connection using UNAUTH-TLS""" | |
1602 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1603 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1604 | eap_connect(dev[0], apdev[0], "UNAUTH-TLS", "unauth-tls", | |
1605 | ca_cert="auth_serv/ca.pem") | |
1606 | eap_reauth(dev[0], "UNAUTH-TLS") | |
1607 | ||
57be05e1 JM |
1608 | def test_ap_wpa2_eap_ttls_server_cert_hash(dev, apdev): |
1609 | """WPA2-Enterprise connection using EAP-TTLS and server certificate hash""" | |
4bf4e9db | 1610 | check_cert_probe_support(dev[0]) |
c1d1b699 | 1611 | srv_cert_hash = "1477c9cd88391609444b83eca45c4f9f324e3051c5c31fc233ac6aede30ce7cd" |
57be05e1 JM |
1612 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1613 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1614 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1615 | identity="probe", ca_cert="probe://", | |
1616 | wait_connect=False, scan_freq="2412") | |
1617 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1618 | if ev is None: | |
1619 | raise Exception("Association and EAP start timed out") | |
1620 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT depth=0"], timeout=10) | |
1621 | if ev is None: | |
1622 | raise Exception("No peer server certificate event seen") | |
1623 | if "hash=" + srv_cert_hash not in ev: | |
1624 | raise Exception("Expected server certificate hash not reported") | |
1625 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10) | |
1626 | if ev is None: | |
1627 | raise Exception("EAP result timed out") | |
1628 | if "Server certificate chain probe" not in ev: | |
1629 | raise Exception("Server certificate probe not reported") | |
5f35a5e2 | 1630 | dev[0].wait_disconnected(timeout=10) |
57be05e1 JM |
1631 | dev[0].request("REMOVE_NETWORK all") |
1632 | ||
1633 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1634 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1635 | password="password", phase2="auth=MSCHAPV2", | |
1636 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a", | |
1637 | wait_connect=False, scan_freq="2412") | |
1638 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1639 | if ev is None: | |
1640 | raise Exception("Association and EAP start timed out") | |
1641 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10) | |
1642 | if ev is None: | |
1643 | raise Exception("EAP result timed out") | |
1644 | if "Server certificate mismatch" not in ev: | |
1645 | raise Exception("Server certificate mismatch not reported") | |
5f35a5e2 | 1646 | dev[0].wait_disconnected(timeout=10) |
57be05e1 JM |
1647 | dev[0].request("REMOVE_NETWORK all") |
1648 | ||
1649 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
1650 | anonymous_identity="ttls", password="password", | |
1651 | ca_cert="hash://server/sha256/" + srv_cert_hash, | |
1652 | phase2="auth=MSCHAPV2") | |
1653 | ||
2a6a2192 JM |
1654 | def test_ap_wpa2_eap_ttls_server_cert_hash_invalid(dev, apdev): |
1655 | """WPA2-Enterprise connection using EAP-TTLS and server certificate hash (invalid config)""" | |
1656 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1657 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1658 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1659 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1660 | password="password", phase2="auth=MSCHAPV2", | |
1661 | ca_cert="hash://server/md5/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a", | |
1662 | wait_connect=False, scan_freq="2412") | |
1663 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1664 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1665 | password="password", phase2="auth=MSCHAPV2", | |
1666 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca", | |
1667 | wait_connect=False, scan_freq="2412") | |
1668 | dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1669 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
1670 | password="password", phase2="auth=MSCHAPV2", | |
1671 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6Q", | |
1672 | wait_connect=False, scan_freq="2412") | |
1673 | for i in range(0, 3): | |
1674 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1675 | if ev is None: | |
1676 | raise Exception("Association and EAP start timed out") | |
cbb85a03 JM |
1677 | ev = dev[i].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 21 (TTLS)"], timeout=5) |
1678 | if ev is None: | |
1679 | raise Exception("Did not report EAP method initialization failure") | |
2a6a2192 | 1680 | |
22b99086 JM |
1681 | def test_ap_wpa2_eap_pwd(dev, apdev): |
1682 | """WPA2-Enterprise connection using EAP-pwd""" | |
3b51cc63 | 1683 | check_eap_capa(dev[0], "PWD") |
22b99086 JM |
1684 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1685 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 1686 | eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password") |
75b2b9cf | 1687 | eap_reauth(dev[0], "PWD") |
6daf5b9c | 1688 | dev[0].request("REMOVE_NETWORK all") |
0403fa0a JM |
1689 | |
1690 | eap_connect(dev[1], apdev[0], "PWD", | |
1691 | "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com", | |
1692 | password="secret password", | |
6daf5b9c JM |
1693 | fragment_size="90") |
1694 | ||
f10ba3b2 | 1695 | logger.info("Negative test with incorrect password") |
0403fa0a | 1696 | eap_connect(dev[2], apdev[0], "PWD", "pwd user", password="secret-password", |
f10ba3b2 JM |
1697 | expect_failure=True, local_error_report=True) |
1698 | ||
0403fa0a JM |
1699 | eap_connect(dev[0], apdev[0], "PWD", |
1700 | "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com", | |
1701 | password="secret password", | |
1702 | fragment_size="31") | |
1703 | ||
c075f040 JM |
1704 | def test_ap_wpa2_eap_pwd_groups(dev, apdev): |
1705 | """WPA2-Enterprise connection using various EAP-pwd groups""" | |
3b51cc63 | 1706 | check_eap_capa(dev[0], "PWD") |
c075f040 JM |
1707 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
1708 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
1709 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" } | |
1710 | for i in [ 19, 20, 21, 25, 26 ]: | |
1711 | params['pwd_group'] = str(i) | |
1712 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1713 | dev[0].request("REMOVE_NETWORK all") | |
1714 | eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password") | |
1715 | ||
4b2d2098 JM |
1716 | def test_ap_wpa2_eap_pwd_invalid_group(dev, apdev): |
1717 | """WPA2-Enterprise connection using invalid EAP-pwd group""" | |
3b51cc63 | 1718 | check_eap_capa(dev[0], "PWD") |
4b2d2098 JM |
1719 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
1720 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
1721 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" } | |
1722 | params['pwd_group'] = "0" | |
1723 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1724 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD", | |
1725 | identity="pwd user", password="secret password", | |
1726 | scan_freq="2412", wait_connect=False) | |
1727 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
1728 | if ev is None: | |
1729 | raise Exception("Timeout on EAP failure report") | |
1730 | ||
8ba89e0a JM |
1731 | def test_ap_wpa2_eap_pwd_as_frag(dev, apdev): |
1732 | """WPA2-Enterprise connection using EAP-pwd with server fragmentation""" | |
3b51cc63 | 1733 | check_eap_capa(dev[0], "PWD") |
8ba89e0a JM |
1734 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1735 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", | |
1736 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
1737 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
1738 | "pwd_group": "19", "fragment_size": "40" } | |
1739 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1740 | eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password") | |
1741 | ||
22b99086 JM |
1742 | def test_ap_wpa2_eap_gpsk(dev, apdev): |
1743 | """WPA2-Enterprise connection using EAP-GPSK""" | |
1744 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1745 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 1746 | id = eap_connect(dev[0], apdev[0], "GPSK", "gpsk user", |
369f9c20 | 1747 | password="abcdefghijklmnop0123456789abcdef") |
75b2b9cf | 1748 | eap_reauth(dev[0], "GPSK") |
22b99086 | 1749 | |
369f9c20 JM |
1750 | logger.info("Test forced algorithm selection") |
1751 | for phase1 in [ "cipher=1", "cipher=2" ]: | |
1752 | dev[0].set_network_quoted(id, "phase1", phase1) | |
1753 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
1754 | if ev is None: | |
1755 | raise Exception("EAP success timed out") | |
5f35a5e2 | 1756 | dev[0].wait_connected(timeout=10) |
369f9c20 JM |
1757 | |
1758 | logger.info("Test failed algorithm negotiation") | |
1759 | dev[0].set_network_quoted(id, "phase1", "cipher=9") | |
1760 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
1761 | if ev is None: | |
1762 | raise Exception("EAP failure timed out") | |
1763 | ||
f10ba3b2 JM |
1764 | logger.info("Negative test with incorrect password") |
1765 | dev[0].request("REMOVE_NETWORK all") | |
1766 | eap_connect(dev[0], apdev[0], "GPSK", "gpsk user", | |
1767 | password="ffcdefghijklmnop0123456789abcdef", | |
1768 | expect_failure=True) | |
1769 | ||
22b99086 JM |
1770 | def test_ap_wpa2_eap_sake(dev, apdev): |
1771 | """WPA2-Enterprise connection using EAP-SAKE""" | |
1772 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1773 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 1774 | eap_connect(dev[0], apdev[0], "SAKE", "sake user", |
22b99086 | 1775 | password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") |
75b2b9cf | 1776 | eap_reauth(dev[0], "SAKE") |
22b99086 | 1777 | |
f10ba3b2 JM |
1778 | logger.info("Negative test with incorrect password") |
1779 | dev[0].request("REMOVE_NETWORK all") | |
1780 | eap_connect(dev[0], apdev[0], "SAKE", "sake user", | |
1781 | password_hex="ff23456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", | |
1782 | expect_failure=True) | |
1783 | ||
22b99086 JM |
1784 | def test_ap_wpa2_eap_eke(dev, apdev): |
1785 | """WPA2-Enterprise connection using EAP-EKE""" | |
1786 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1787 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 1788 | id = eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello") |
75b2b9cf | 1789 | eap_reauth(dev[0], "EKE") |
22b99086 | 1790 | |
2bb9e283 JM |
1791 | logger.info("Test forced algorithm selection") |
1792 | for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2", | |
1793 | "dhgroup=4 encr=1 prf=2 mac=2", | |
1794 | "dhgroup=3 encr=1 prf=2 mac=2", | |
1795 | "dhgroup=3 encr=1 prf=1 mac=1" ]: | |
1796 | dev[0].set_network_quoted(id, "phase1", phase1) | |
1797 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
1798 | if ev is None: | |
1799 | raise Exception("EAP success timed out") | |
5f35a5e2 | 1800 | dev[0].wait_connected(timeout=10) |
2bb9e283 JM |
1801 | |
1802 | logger.info("Test failed algorithm negotiation") | |
1803 | dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9") | |
1804 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
1805 | if ev is None: | |
1806 | raise Exception("EAP failure timed out") | |
1807 | ||
f10ba3b2 JM |
1808 | logger.info("Negative test with incorrect password") |
1809 | dev[0].request("REMOVE_NETWORK all") | |
1810 | eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello1", | |
1811 | expect_failure=True) | |
1812 | ||
22b99086 JM |
1813 | def test_ap_wpa2_eap_ikev2(dev, apdev): |
1814 | """WPA2-Enterprise connection using EAP-IKEv2""" | |
1815 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1816 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 JM |
1817 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", |
1818 | password="ike password") | |
75b2b9cf | 1819 | eap_reauth(dev[0], "IKEV2") |
6daf5b9c JM |
1820 | dev[0].request("REMOVE_NETWORK all") |
1821 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", | |
47a74ad8 | 1822 | password="ike password", fragment_size="50") |
22b99086 | 1823 | |
f10ba3b2 JM |
1824 | logger.info("Negative test with incorrect password") |
1825 | dev[0].request("REMOVE_NETWORK all") | |
1826 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", | |
1827 | password="ike-password", expect_failure=True) | |
1828 | ||
47a74ad8 JM |
1829 | def test_ap_wpa2_eap_ikev2_as_frag(dev, apdev): |
1830 | """WPA2-Enterprise connection using EAP-IKEv2 with server fragmentation""" | |
1831 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1832 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", | |
1833 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
1834 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
1835 | "fragment_size": "50" } | |
1836 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1837 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", | |
1838 | password="ike password") | |
1839 | eap_reauth(dev[0], "IKEV2") | |
1840 | ||
22b99086 JM |
1841 | def test_ap_wpa2_eap_pax(dev, apdev): |
1842 | """WPA2-Enterprise connection using EAP-PAX""" | |
1843 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1844 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 1845 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", |
22b99086 | 1846 | password_hex="0123456789abcdef0123456789abcdef") |
75b2b9cf | 1847 | eap_reauth(dev[0], "PAX") |
22b99086 | 1848 | |
f10ba3b2 JM |
1849 | logger.info("Negative test with incorrect password") |
1850 | dev[0].request("REMOVE_NETWORK all") | |
1851 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", | |
1852 | password_hex="ff23456789abcdef0123456789abcdef", | |
1853 | expect_failure=True) | |
1854 | ||
22b99086 JM |
1855 | def test_ap_wpa2_eap_psk(dev, apdev): |
1856 | """WPA2-Enterprise connection using EAP-PSK""" | |
1857 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2b005194 JM |
1858 | params["wpa_key_mgmt"] = "WPA-EAP-SHA256" |
1859 | params["ieee80211w"] = "2" | |
22b99086 | 1860 | hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 1861 | eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com", |
2b005194 JM |
1862 | password_hex="0123456789abcdef0123456789abcdef", sha256=True) |
1863 | eap_reauth(dev[0], "PSK", sha256=True) | |
eaf3f9b1 JM |
1864 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"), |
1865 | ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ]) | |
71390dc8 | 1866 | |
d463c556 JM |
1867 | bss = dev[0].get_bss(apdev[0]['bssid']) |
1868 | if 'flags' not in bss: | |
1869 | raise Exception("Could not get BSS flags from BSS table") | |
1870 | if "[WPA2-EAP-SHA256-CCMP]" not in bss['flags']: | |
1871 | raise Exception("Unexpected BSS flags: " + bss['flags']) | |
1872 | ||
f10ba3b2 JM |
1873 | logger.info("Negative test with incorrect password") |
1874 | dev[0].request("REMOVE_NETWORK all") | |
1875 | eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com", | |
1876 | password_hex="ff23456789abcdef0123456789abcdef", sha256=True, | |
1877 | expect_failure=True) | |
1878 | ||
71390dc8 JM |
1879 | def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev): |
1880 | """WPA-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2""" | |
1881 | params = hostapd.wpa_eap_params(ssid="test-wpa-eap") | |
a8375c94 | 1882 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
71390dc8 JM |
1883 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="PEAP", |
1884 | identity="user", password="password", phase2="auth=MSCHAPV2", | |
1885 | ca_cert="auth_serv/ca.pem", wait_connect=False, | |
1886 | scan_freq="2412") | |
1887 | eap_check_auth(dev[0], "PEAP", True, rsn=False) | |
a8375c94 | 1888 | hwsim_utils.test_connectivity(dev[0], hapd) |
71390dc8 | 1889 | eap_reauth(dev[0], "PEAP", rsn=False) |
eaf3f9b1 JM |
1890 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"), |
1891 | ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ]) | |
40759604 JM |
1892 | |
1893 | def test_ap_wpa2_eap_interactive(dev, apdev): | |
1894 | """WPA2-Enterprise connection using interactive identity/password entry""" | |
1895 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1896 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1897 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1898 | ||
1899 | tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry", | |
1900 | "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2", | |
1901 | None, "password"), | |
1902 | ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry", | |
1903 | "TTLS", "ttls", None, "auth=MSCHAPV2", | |
1904 | "DOMAIN\mschapv2 user", "password"), | |
1905 | ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry", | |
1906 | "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"), | |
1907 | ("Connection with dynamic TTLS/EAP-MD5 password entry", | |
1908 | "TTLS", "ttls", "user", "autheap=MD5", None, "password"), | |
1909 | ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry", | |
1910 | "PEAP", None, "user", "auth=MSCHAPV2", None, "password"), | |
1911 | ("Connection with dynamic PEAP/EAP-GTC password entry", | |
1912 | "PEAP", None, "user", "auth=GTC", None, "password") ] | |
1913 | for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests: | |
1914 | logger.info(desc) | |
1915 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap, | |
1916 | anonymous_identity=anon, identity=identity, | |
1917 | ca_cert="auth_serv/ca.pem", phase2=phase2, | |
1918 | wait_connect=False, scan_freq="2412") | |
1919 | if req_id: | |
1920 | ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"]) | |
1921 | if ev is None: | |
1922 | raise Exception("Request for identity timed out") | |
1923 | id = ev.split(':')[0].split('-')[-1] | |
1924 | dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id) | |
1925 | ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"]) | |
1926 | if ev is None: | |
1927 | raise Exception("Request for password timed out") | |
1928 | id = ev.split(':')[0].split('-')[-1] | |
1929 | type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD" | |
1930 | dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw) | |
5f35a5e2 | 1931 | dev[0].wait_connected(timeout=10) |
40759604 | 1932 | dev[0].request("REMOVE_NETWORK all") |
e745c811 JM |
1933 | |
1934 | def test_ap_wpa2_eap_vendor_test(dev, apdev): | |
1935 | """WPA2-Enterprise connection using EAP vendor test""" | |
1936 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1937 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1938 | eap_connect(dev[0], apdev[0], "VENDOR-TEST", "vendor-test") | |
1939 | eap_reauth(dev[0], "VENDOR-TEST") | |
53a6f06a JM |
1940 | |
1941 | def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev): | |
1942 | """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning""" | |
3b51cc63 | 1943 | check_eap_capa(dev[0], "FAST") |
53a6f06a | 1944 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 1945 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
53a6f06a JM |
1946 | eap_connect(dev[0], apdev[0], "FAST", "user", |
1947 | anonymous_identity="FAST", password="password", | |
1948 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1949 | phase1="fast_provisioning=1", pac_file="blob://fast_pac") | |
a8375c94 | 1950 | hwsim_utils.test_connectivity(dev[0], hapd) |
2fc4749c JM |
1951 | res = eap_reauth(dev[0], "FAST") |
1952 | if res['tls_session_reused'] != '1': | |
1953 | raise Exception("EAP-FAST could not use PAC session ticket") | |
53a6f06a | 1954 | |
873e7c29 JM |
1955 | def test_ap_wpa2_eap_fast_pac_file(dev, apdev, params): |
1956 | """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and PAC file""" | |
3b51cc63 | 1957 | check_eap_capa(dev[0], "FAST") |
873e7c29 JM |
1958 | pac_file = os.path.join(params['logdir'], "fast.pac") |
1959 | pac_file2 = os.path.join(params['logdir'], "fast-bin.pac") | |
1960 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1961 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1962 | ||
1963 | try: | |
1964 | eap_connect(dev[0], apdev[0], "FAST", "user", | |
1965 | anonymous_identity="FAST", password="password", | |
1966 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1967 | phase1="fast_provisioning=1", pac_file=pac_file) | |
1968 | with open(pac_file, "r") as f: | |
1969 | data = f.read() | |
1970 | if "wpa_supplicant EAP-FAST PAC file - version 1" not in data: | |
1971 | raise Exception("PAC file header missing") | |
1972 | if "PAC-Key=" not in data: | |
1973 | raise Exception("PAC-Key missing from PAC file") | |
1974 | dev[0].request("REMOVE_NETWORK all") | |
1975 | eap_connect(dev[0], apdev[0], "FAST", "user", | |
1976 | anonymous_identity="FAST", password="password", | |
1977 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1978 | pac_file=pac_file) | |
1979 | ||
1980 | eap_connect(dev[1], apdev[0], "FAST", "user", | |
1981 | anonymous_identity="FAST", password="password", | |
1982 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1983 | phase1="fast_provisioning=1 fast_pac_format=binary", | |
1984 | pac_file=pac_file2) | |
1985 | dev[1].request("REMOVE_NETWORK all") | |
1986 | eap_connect(dev[1], apdev[0], "FAST", "user", | |
1987 | anonymous_identity="FAST", password="password", | |
1988 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
1989 | phase1="fast_pac_format=binary", | |
1990 | pac_file=pac_file2) | |
1991 | finally: | |
1992 | subprocess.call(['sudo', 'rm', pac_file]) | |
1993 | subprocess.call(['sudo', 'rm', pac_file2]) | |
1994 | ||
c6ab1cdb JM |
1995 | def test_ap_wpa2_eap_fast_binary_pac(dev, apdev): |
1996 | """WPA2-Enterprise connection using EAP-FAST and binary PAC format""" | |
3b51cc63 | 1997 | check_eap_capa(dev[0], "FAST") |
c6ab1cdb JM |
1998 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
1999 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2000 | eap_connect(dev[0], apdev[0], "FAST", "user", | |
2001 | anonymous_identity="FAST", password="password", | |
2002 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2003 | phase1="fast_provisioning=1 fast_max_pac_list_len=1 fast_pac_format=binary", | |
2004 | pac_file="blob://fast_pac_bin") | |
2fc4749c JM |
2005 | res = eap_reauth(dev[0], "FAST") |
2006 | if res['tls_session_reused'] != '1': | |
2007 | raise Exception("EAP-FAST could not use PAC session ticket") | |
c6ab1cdb | 2008 | |
46e094bd JM |
2009 | def test_ap_wpa2_eap_fast_missing_pac_config(dev, apdev): |
2010 | """WPA2-Enterprise connection using EAP-FAST and missing PAC config""" | |
3b51cc63 | 2011 | check_eap_capa(dev[0], "FAST") |
46e094bd JM |
2012 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2013 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2014 | ||
2015 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
2016 | identity="user", anonymous_identity="FAST", | |
2017 | password="password", | |
2018 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2019 | pac_file="blob://fast_pac_not_in_use", | |
2020 | wait_connect=False, scan_freq="2412") | |
2021 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2022 | if ev is None: | |
2023 | raise Exception("Timeout on EAP failure report") | |
2024 | dev[0].request("REMOVE_NETWORK all") | |
2025 | ||
2026 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", | |
2027 | identity="user", anonymous_identity="FAST", | |
2028 | password="password", | |
2029 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2030 | wait_connect=False, scan_freq="2412") | |
2031 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2032 | if ev is None: | |
2033 | raise Exception("Timeout on EAP failure report") | |
2034 | ||
53a6f06a JM |
2035 | def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev): |
2036 | """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning""" | |
3b51cc63 | 2037 | check_eap_capa(dev[0], "FAST") |
53a6f06a | 2038 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
a8375c94 | 2039 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
53a6f06a JM |
2040 | eap_connect(dev[0], apdev[0], "FAST", "user", |
2041 | anonymous_identity="FAST", password="password", | |
2042 | ca_cert="auth_serv/ca.pem", phase2="auth=GTC", | |
2043 | phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth") | |
a8375c94 | 2044 | hwsim_utils.test_connectivity(dev[0], hapd) |
2fc4749c JM |
2045 | res = eap_reauth(dev[0], "FAST") |
2046 | if res['tls_session_reused'] != '1': | |
2047 | raise Exception("EAP-FAST could not use PAC session ticket") | |
d4c7a2b9 JM |
2048 | |
2049 | def test_ap_wpa2_eap_tls_ocsp(dev, apdev): | |
2050 | """WPA2-Enterprise connection using EAP-TLS and verifying OCSP""" | |
2051 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2052 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2053 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
2054 | private_key="auth_serv/user.pkcs12", | |
2055 | private_key_passwd="whatever", ocsp=2) | |
2056 | ||
64e05f96 | 2057 | def int_eap_server_params(): |
d4c7a2b9 JM |
2058 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
2059 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
2060 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
2061 | "ca_cert": "auth_serv/ca.pem", | |
2062 | "server_cert": "auth_serv/server.pem", | |
64e05f96 JM |
2063 | "private_key": "auth_serv/server.key" } |
2064 | return params | |
2065 | ||
2066 | def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev): | |
2067 | """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response""" | |
2068 | params = int_eap_server_params() | |
2069 | params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid" | |
d4c7a2b9 JM |
2070 | hostapd.add_ap(apdev[0]['ifname'], params) |
2071 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2072 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2073 | private_key="auth_serv/user.pkcs12", | |
2074 | private_key_passwd="whatever", ocsp=2, | |
2075 | wait_connect=False, scan_freq="2412") | |
2076 | count = 0 | |
2077 | while True: | |
2078 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2079 | if ev is None: | |
2080 | raise Exception("Timeout on EAP status") | |
2081 | if 'bad certificate status response' in ev: | |
2082 | break | |
2083 | count = count + 1 | |
2084 | if count > 10: | |
2085 | raise Exception("Unexpected number of EAP status messages") | |
2086 | ||
2087 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2088 | if ev is None: | |
2089 | raise Exception("Timeout on EAP failure report") | |
64e05f96 | 2090 | |
37b4a66c JM |
2091 | def test_ap_wpa2_eap_ttls_ocsp_revoked(dev, apdev, params): |
2092 | """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked""" | |
2093 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-revoked.der") | |
2094 | if not os.path.exists(ocsp): | |
2095 | raise HwsimSkip("No OCSP response available") | |
2096 | params = int_eap_server_params() | |
2097 | params["ocsp_stapling_response"] = ocsp | |
2098 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2099 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2100 | identity="pap user", ca_cert="auth_serv/ca.pem", | |
2101 | anonymous_identity="ttls", password="password", | |
2102 | phase2="auth=PAP", ocsp=2, | |
2103 | wait_connect=False, scan_freq="2412") | |
2104 | count = 0 | |
2105 | while True: | |
2106 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2107 | if ev is None: | |
2108 | raise Exception("Timeout on EAP status") | |
2109 | if 'bad certificate status response' in ev: | |
2110 | break | |
2111 | if 'certificate revoked' in ev: | |
2112 | break | |
2113 | count = count + 1 | |
2114 | if count > 10: | |
2115 | raise Exception("Unexpected number of EAP status messages") | |
2116 | ||
2117 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2118 | if ev is None: | |
2119 | raise Exception("Timeout on EAP failure report") | |
2120 | ||
2121 | def test_ap_wpa2_eap_ttls_ocsp_unknown(dev, apdev, params): | |
2122 | """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked""" | |
2123 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der") | |
2124 | if not os.path.exists(ocsp): | |
2125 | raise HwsimSkip("No OCSP response available") | |
2126 | params = int_eap_server_params() | |
2127 | params["ocsp_stapling_response"] = ocsp | |
2128 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2129 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2130 | identity="pap user", ca_cert="auth_serv/ca.pem", | |
2131 | anonymous_identity="ttls", password="password", | |
2132 | phase2="auth=PAP", ocsp=2, | |
2133 | wait_connect=False, scan_freq="2412") | |
2134 | count = 0 | |
2135 | while True: | |
2136 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
2137 | if ev is None: | |
2138 | raise Exception("Timeout on EAP status") | |
2139 | if 'bad certificate status response' in ev: | |
2140 | break | |
2141 | count = count + 1 | |
2142 | if count > 10: | |
2143 | raise Exception("Unexpected number of EAP status messages") | |
2144 | ||
2145 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2146 | if ev is None: | |
2147 | raise Exception("Timeout on EAP failure report") | |
2148 | ||
2149 | def test_ap_wpa2_eap_ttls_optional_ocsp_unknown(dev, apdev, params): | |
2150 | """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked""" | |
2151 | ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der") | |
2152 | if not os.path.exists(ocsp): | |
2153 | raise HwsimSkip("No OCSP response available") | |
2154 | params = int_eap_server_params() | |
2155 | params["ocsp_stapling_response"] = ocsp | |
2156 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2157 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2158 | identity="pap user", ca_cert="auth_serv/ca.pem", | |
2159 | anonymous_identity="ttls", password="password", | |
2160 | phase2="auth=PAP", ocsp=1, scan_freq="2412") | |
2161 | ||
24579e70 | 2162 | def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev): |
64e05f96 JM |
2163 | """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)""" |
2164 | params = int_eap_server_params() | |
2165 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
2166 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
2167 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2168 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2169 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2170 | private_key="auth_serv/user.pkcs12", | |
2171 | private_key_passwd="whatever", | |
2172 | domain_suffix_match="server3.w1.fi", | |
2173 | scan_freq="2412") | |
24579e70 | 2174 | |
061cbb25 JM |
2175 | def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev): |
2176 | """WPA2-Enterprise using EAP-TLS and domainmatch (CN)""" | |
2177 | params = int_eap_server_params() | |
2178 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
2179 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
2180 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2181 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2182 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2183 | private_key="auth_serv/user.pkcs12", | |
2184 | private_key_passwd="whatever", | |
2185 | domain_match="server3.w1.fi", | |
2186 | scan_freq="2412") | |
2187 | ||
24579e70 JM |
2188 | def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev): |
2189 | """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)""" | |
2190 | check_domain_match_full(dev[0]) | |
2191 | params = int_eap_server_params() | |
2192 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
2193 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
2194 | hostapd.add_ap(apdev[0]['ifname'], params) | |
64e05f96 JM |
2195 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
2196 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2197 | private_key="auth_serv/user.pkcs12", | |
2198 | private_key_passwd="whatever", | |
2199 | domain_suffix_match="w1.fi", | |
2200 | scan_freq="2412") | |
2201 | ||
2202 | def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev): | |
2203 | """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)""" | |
2204 | params = int_eap_server_params() | |
2205 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
2206 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
2207 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2208 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2209 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2210 | private_key="auth_serv/user.pkcs12", | |
2211 | private_key_passwd="whatever", | |
2212 | domain_suffix_match="example.com", | |
2213 | wait_connect=False, | |
2214 | scan_freq="2412") | |
c61dca40 JM |
2215 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
2216 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2217 | private_key="auth_serv/user.pkcs12", | |
2218 | private_key_passwd="whatever", | |
2219 | domain_suffix_match="erver3.w1.fi", | |
2220 | wait_connect=False, | |
2221 | scan_freq="2412") | |
64e05f96 JM |
2222 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) |
2223 | if ev is None: | |
2224 | raise Exception("Timeout on EAP failure report") | |
c61dca40 JM |
2225 | ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"]) |
2226 | if ev is None: | |
2227 | raise Exception("Timeout on EAP failure report (2)") | |
6a4d0dbe | 2228 | |
061cbb25 JM |
2229 | def test_ap_wpa2_eap_tls_domain_mismatch_cn(dev, apdev): |
2230 | """WPA2-Enterprise using EAP-TLS and domain mismatch (CN)""" | |
2231 | params = int_eap_server_params() | |
2232 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
2233 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
2234 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2235 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2236 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2237 | private_key="auth_serv/user.pkcs12", | |
2238 | private_key_passwd="whatever", | |
2239 | domain_match="example.com", | |
2240 | wait_connect=False, | |
2241 | scan_freq="2412") | |
2242 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
2243 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
2244 | private_key="auth_serv/user.pkcs12", | |
2245 | private_key_passwd="whatever", | |
2246 | domain_match="w1.fi", | |
2247 | wait_connect=False, | |
2248 | scan_freq="2412") | |
2249 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2250 | if ev is None: | |
2251 | raise Exception("Timeout on EAP failure report") | |
2252 | ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2253 | if ev is None: | |
2254 | raise Exception("Timeout on EAP failure report (2)") | |
2255 | ||
6a4d0dbe JM |
2256 | def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev): |
2257 | """WPA2-Enterprise using EAP-TTLS and expired certificate""" | |
2258 | params = int_eap_server_params() | |
2259 | params["server_cert"] = "auth_serv/server-expired.pem" | |
2260 | params["private_key"] = "auth_serv/server-expired.key" | |
2261 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2262 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2263 | identity="mschap user", password="password", | |
2264 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
2265 | wait_connect=False, | |
2266 | scan_freq="2412") | |
2267 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"]) | |
2268 | if ev is None: | |
2269 | raise Exception("Timeout on EAP certificate error report") | |
2270 | if "reason=4" not in ev or "certificate has expired" not in ev: | |
2271 | raise Exception("Unexpected failure reason: " + ev) | |
2272 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2273 | if ev is None: | |
2274 | raise Exception("Timeout on EAP failure report") | |
2275 | ||
2276 | def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev): | |
2277 | """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration""" | |
2278 | params = int_eap_server_params() | |
2279 | params["server_cert"] = "auth_serv/server-expired.pem" | |
2280 | params["private_key"] = "auth_serv/server-expired.key" | |
2281 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2282 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2283 | identity="mschap user", password="password", | |
2284 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
2285 | phase1="tls_disable_time_checks=1", | |
2286 | scan_freq="2412") | |
6ab4a7aa JM |
2287 | |
2288 | def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev): | |
2289 | """WPA2-Enterprise using EAP-TTLS and server cert with client EKU""" | |
2290 | params = int_eap_server_params() | |
2291 | params["server_cert"] = "auth_serv/server-eku-client.pem" | |
2292 | params["private_key"] = "auth_serv/server-eku-client.key" | |
2293 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2294 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2295 | identity="mschap user", password="password", | |
2296 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
2297 | wait_connect=False, | |
2298 | scan_freq="2412") | |
2299 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2300 | if ev is None: | |
2301 | raise Exception("Timeout on EAP failure report") | |
242219c5 | 2302 | |
14bef66d JM |
2303 | def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev): |
2304 | """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU""" | |
2305 | params = int_eap_server_params() | |
2306 | params["server_cert"] = "auth_serv/server-eku-client-server.pem" | |
2307 | params["private_key"] = "auth_serv/server-eku-client-server.key" | |
2308 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2309 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2310 | identity="mschap user", password="password", | |
2311 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
2312 | scan_freq="2412") | |
2313 | ||
c37b02fc JM |
2314 | def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev): |
2315 | """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file""" | |
2316 | params = int_eap_server_params() | |
2317 | del params["server_cert"] | |
2318 | params["private_key"] = "auth_serv/server.pkcs12" | |
2319 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2320 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2321 | identity="mschap user", password="password", | |
2322 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
2323 | scan_freq="2412") | |
2324 | ||
242219c5 JM |
2325 | def test_ap_wpa2_eap_ttls_dh_params(dev, apdev): |
2326 | """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params""" | |
2327 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2328 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2329 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", | |
2330 | anonymous_identity="ttls", password="password", | |
2331 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP", | |
2332 | dh_file="auth_serv/dh.conf") | |
7c50093f | 2333 | |
6ea231e6 JM |
2334 | def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev): |
2335 | """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob""" | |
2336 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2337 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2338 | dh = read_pem("auth_serv/dh.conf") | |
2339 | if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")): | |
2340 | raise Exception("Could not set dhparams blob") | |
2341 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", | |
2342 | anonymous_identity="ttls", password="password", | |
2343 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP", | |
2344 | dh_file="blob://dhparams") | |
2345 | ||
7c50093f JM |
2346 | def test_ap_wpa2_eap_reauth(dev, apdev): |
2347 | """WPA2-Enterprise and Authenticator forcing reauthentication""" | |
2348 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2349 | params['eap_reauth_period'] = '2' | |
2350 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2351 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", | |
2352 | password_hex="0123456789abcdef0123456789abcdef") | |
2353 | logger.info("Wait for reauthentication") | |
2354 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
2355 | if ev is None: | |
2356 | raise Exception("Timeout on reauthentication") | |
2357 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
2358 | if ev is None: | |
2359 | raise Exception("Timeout on reauthentication") | |
2360 | for i in range(0, 20): | |
2361 | state = dev[0].get_status_field("wpa_state") | |
2362 | if state == "COMPLETED": | |
2363 | break | |
2364 | time.sleep(0.1) | |
2365 | if state != "COMPLETED": | |
2366 | raise Exception("Reauthentication did not complete") | |
8b56743e JM |
2367 | |
2368 | def test_ap_wpa2_eap_request_identity_message(dev, apdev): | |
2369 | """Optional displayable message in EAP Request-Identity""" | |
2370 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2371 | params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com' | |
2372 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2373 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", | |
2374 | password_hex="0123456789abcdef0123456789abcdef") | |
910f16ca JM |
2375 | |
2376 | def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev): | |
2377 | """WPA2-Enterprise using EAP-SIM/AKA and protected result indication""" | |
81e787b7 | 2378 | check_hlr_auc_gw_support() |
910f16ca JM |
2379 | params = int_eap_server_params() |
2380 | params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock" | |
2381 | params['eap_sim_aka_result_ind'] = "1" | |
2382 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2383 | ||
2384 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
2385 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
2386 | phase1="result_ind=1") | |
2387 | eap_reauth(dev[0], "SIM") | |
2388 | eap_connect(dev[1], apdev[0], "SIM", "1232010000000000", | |
2389 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
2390 | ||
2391 | dev[0].request("REMOVE_NETWORK all") | |
2392 | dev[1].request("REMOVE_NETWORK all") | |
2393 | ||
2394 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
2395 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
2396 | phase1="result_ind=1") | |
2397 | eap_reauth(dev[0], "AKA") | |
2398 | eap_connect(dev[1], apdev[0], "AKA", "0232010000000000", | |
2399 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") | |
2400 | ||
2401 | dev[0].request("REMOVE_NETWORK all") | |
2402 | dev[1].request("REMOVE_NETWORK all") | |
2403 | ||
2404 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
2405 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
2406 | phase1="result_ind=1") | |
2407 | eap_reauth(dev[0], "AKA'") | |
2408 | eap_connect(dev[1], apdev[0], "AKA'", "6555444333222111", | |
2409 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") | |
633e364b JM |
2410 | |
2411 | def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev): | |
2412 | """WPA2-Enterprise connection resulting in too many EAP roundtrips""" | |
2413 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2414 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2415 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
2416 | eap="TTLS", identity="mschap user", | |
2417 | wait_connect=False, scan_freq="2412", ieee80211w="1", | |
2418 | anonymous_identity="ttls", password="password", | |
2419 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
2420 | fragment_size="10") | |
2421 | ev = dev[0].wait_event(["EAP: more than"], timeout=20) | |
2422 | if ev is None: | |
2423 | raise Exception("EAP roundtrip limit not reached") | |
32dca985 JM |
2424 | |
2425 | def test_ap_wpa2_eap_expanded_nak(dev, apdev): | |
2426 | """WPA2-Enterprise connection with EAP resulting in expanded NAK""" | |
2427 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2428 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2429 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
2430 | eap="PSK", identity="vendor-test", | |
2431 | password_hex="ff23456789abcdef0123456789abcdef", | |
2432 | wait_connect=False) | |
2433 | ||
2434 | found = False | |
2435 | for i in range(0, 5): | |
2436 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=10) | |
2437 | if ev is None: | |
2438 | raise Exception("Association and EAP start timed out") | |
2439 | if "refuse proposed method" in ev: | |
2440 | found = True | |
2441 | break | |
2442 | if not found: | |
2443 | raise Exception("Unexpected EAP status: " + ev) | |
2444 | ||
2445 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
2446 | if ev is None: | |
2447 | raise Exception("EAP failure timed out") | |
745f8771 JM |
2448 | |
2449 | def test_ap_wpa2_eap_sql(dev, apdev, params): | |
2450 | """WPA2-Enterprise connection using SQLite for user DB""" | |
2451 | try: | |
2452 | import sqlite3 | |
2453 | except ImportError: | |
81e787b7 | 2454 | raise HwsimSkip("No sqlite3 module available") |
745f8771 JM |
2455 | dbfile = os.path.join(params['logdir'], "eap-user.db") |
2456 | try: | |
2457 | os.remove(dbfile) | |
2458 | except: | |
2459 | pass | |
2460 | con = sqlite3.connect(dbfile) | |
2461 | with con: | |
2462 | cur = con.cursor() | |
2463 | cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)") | |
2464 | cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)") | |
2465 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-pap','TTLS-PAP','password',1)") | |
2466 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-chap','TTLS-CHAP','password',1)") | |
2467 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschap','TTLS-MSCHAP','password',1)") | |
2468 | cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1)") | |
2469 | cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')") | |
2470 | cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)") | |
2471 | ||
2472 | try: | |
2473 | params = int_eap_server_params() | |
2474 | params["eap_user_file"] = "sqlite:" + dbfile | |
2475 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2476 | eap_connect(dev[0], apdev[0], "TTLS", "user-mschapv2", | |
2477 | anonymous_identity="ttls", password="password", | |
2478 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
2479 | dev[0].request("REMOVE_NETWORK all") | |
2480 | eap_connect(dev[1], apdev[0], "TTLS", "user-mschap", | |
2481 | anonymous_identity="ttls", password="password", | |
2482 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP") | |
2483 | dev[1].request("REMOVE_NETWORK all") | |
2484 | eap_connect(dev[0], apdev[0], "TTLS", "user-chap", | |
2485 | anonymous_identity="ttls", password="password", | |
2486 | ca_cert="auth_serv/ca.pem", phase2="auth=CHAP") | |
2487 | eap_connect(dev[1], apdev[0], "TTLS", "user-pap", | |
2488 | anonymous_identity="ttls", password="password", | |
2489 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
2490 | finally: | |
2491 | os.remove(dbfile) | |
b246e2af JM |
2492 | |
2493 | def test_ap_wpa2_eap_non_ascii_identity(dev, apdev): | |
2494 | """WPA2-Enterprise connection attempt using non-ASCII identity""" | |
2495 | params = int_eap_server_params() | |
2496 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2497 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2498 | identity="\x80", password="password", wait_connect=False) | |
2499 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2500 | identity="a\x80", password="password", wait_connect=False) | |
2501 | for i in range(0, 2): | |
2502 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
2503 | if ev is None: | |
2504 | raise Exception("Association and EAP start timed out") | |
2505 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
2506 | if ev is None: | |
2507 | raise Exception("EAP method selection timed out") | |
2508 | ||
2509 | def test_ap_wpa2_eap_non_ascii_identity2(dev, apdev): | |
2510 | """WPA2-Enterprise connection attempt using non-ASCII identity""" | |
2511 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2512 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2513 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2514 | identity="\x80", password="password", wait_connect=False) | |
2515 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
2516 | identity="a\x80", password="password", wait_connect=False) | |
2517 | for i in range(0, 2): | |
2518 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
2519 | if ev is None: | |
2520 | raise Exception("Association and EAP start timed out") | |
2521 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
2522 | if ev is None: | |
2523 | raise Exception("EAP method selection timed out") | |
89f20842 JM |
2524 | |
2525 | def test_openssl_cipher_suite_config_wpas(dev, apdev): | |
2526 | """OpenSSL cipher suite configuration on wpa_supplicant""" | |
a783340d JM |
2527 | tls = dev[0].request("GET tls_library") |
2528 | if not tls.startswith("OpenSSL"): | |
2529 | raise HwsimSkip("TLS library is not OpenSSL: " + tls) | |
89f20842 JM |
2530 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
2531 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
2532 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", | |
2533 | anonymous_identity="ttls", password="password", | |
2534 | openssl_ciphers="AES128", | |
2535 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
2536 | eap_connect(dev[1], apdev[0], "TTLS", "pap user", | |
2537 | anonymous_identity="ttls", password="password", | |
2538 | openssl_ciphers="EXPORT", | |
2539 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
2540 | expect_failure=True) | |
2541 | ||
2542 | def test_openssl_cipher_suite_config_hapd(dev, apdev): | |
2543 | """OpenSSL cipher suite configuration on hostapd""" | |
a783340d JM |
2544 | tls = dev[0].request("GET tls_library") |
2545 | if not tls.startswith("OpenSSL"): | |
2546 | raise HwsimSkip("wpa_supplicant TLS library is not OpenSSL: " + tls) | |
89f20842 JM |
2547 | params = int_eap_server_params() |
2548 | params['openssl_ciphers'] = "AES256" | |
2549 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
a783340d JM |
2550 | tls = hapd.request("GET tls_library") |
2551 | if not tls.startswith("OpenSSL"): | |
2552 | raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls) | |
89f20842 JM |
2553 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
2554 | anonymous_identity="ttls", password="password", | |
2555 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
2556 | eap_connect(dev[1], apdev[0], "TTLS", "pap user", | |
2557 | anonymous_identity="ttls", password="password", | |
2558 | openssl_ciphers="AES128", | |
2559 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", | |
2560 | expect_failure=True) | |
2561 | eap_connect(dev[2], apdev[0], "TTLS", "pap user", | |
2562 | anonymous_identity="ttls", password="password", | |
2563 | openssl_ciphers="HIGH:!ADH", | |
2564 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
5b3c40a6 JM |
2565 | |
2566 | def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params): | |
2567 | """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP""" | |
2568 | p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2569 | hapd = hostapd.add_ap(apdev[0]['ifname'], p) | |
2570 | password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25" | |
2571 | pid = find_wpas_process(dev[0]) | |
2572 | id = eap_connect(dev[0], apdev[0], "TTLS", "pap-secret", | |
2573 | anonymous_identity="ttls", password=password, | |
2574 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP") | |
2575 | time.sleep(0.1) | |
2576 | buf = read_process_memory(pid, password) | |
2577 | ||
2578 | dev[0].request("DISCONNECT") | |
2579 | dev[0].wait_disconnected() | |
2580 | ||
2581 | dev[0].relog() | |
750904dd JM |
2582 | msk = None |
2583 | emsk = None | |
5b3c40a6 JM |
2584 | pmk = None |
2585 | ptk = None | |
2586 | gtk = None | |
2587 | with open(os.path.join(params['logdir'], 'log0'), 'r') as f: | |
2588 | for l in f.readlines(): | |
750904dd JM |
2589 | if "EAP-TTLS: Derived key - hexdump" in l: |
2590 | val = l.strip().split(':')[3].replace(' ', '') | |
2591 | msk = binascii.unhexlify(val) | |
2592 | if "EAP-TTLS: Derived EMSK - hexdump" in l: | |
2593 | val = l.strip().split(':')[3].replace(' ', '') | |
2594 | emsk = binascii.unhexlify(val) | |
5b3c40a6 JM |
2595 | if "WPA: PMK - hexdump" in l: |
2596 | val = l.strip().split(':')[3].replace(' ', '') | |
2597 | pmk = binascii.unhexlify(val) | |
2598 | if "WPA: PTK - hexdump" in l: | |
2599 | val = l.strip().split(':')[3].replace(' ', '') | |
2600 | ptk = binascii.unhexlify(val) | |
2601 | if "WPA: Group Key - hexdump" in l: | |
2602 | val = l.strip().split(':')[3].replace(' ', '') | |
2603 | gtk = binascii.unhexlify(val) | |
750904dd | 2604 | if not msk or not emsk or not pmk or not ptk or not gtk: |
5b3c40a6 JM |
2605 | raise Exception("Could not find keys from debug log") |
2606 | if len(gtk) != 16: | |
2607 | raise Exception("Unexpected GTK length") | |
2608 | ||
2609 | kck = ptk[0:16] | |
2610 | kek = ptk[16:32] | |
2611 | tk = ptk[32:48] | |
2612 | ||
2613 | fname = os.path.join(params['logdir'], | |
2614 | 'wpa2_eap_ttls_pap_key_lifetime_in_memory.memctx-') | |
2615 | ||
2616 | logger.info("Checking keys in memory while associated") | |
2617 | get_key_locations(buf, password, "Password") | |
2618 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
2619 | get_key_locations(buf, msk, "MSK") |
2620 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 | 2621 | if password not in buf: |
81e787b7 | 2622 | raise HwsimSkip("Password not found while associated") |
5b3c40a6 | 2623 | if pmk not in buf: |
81e787b7 | 2624 | raise HwsimSkip("PMK not found while associated") |
5b3c40a6 JM |
2625 | if kck not in buf: |
2626 | raise Exception("KCK not found while associated") | |
2627 | if kek not in buf: | |
2628 | raise Exception("KEK not found while associated") | |
2629 | if tk in buf: | |
2630 | raise Exception("TK found from memory") | |
2631 | if gtk in buf: | |
2632 | raise Exception("GTK found from memory") | |
2633 | ||
2634 | logger.info("Checking keys in memory after disassociation") | |
2635 | buf = read_process_memory(pid, password) | |
2636 | ||
2637 | # Note: Password is still present in network configuration | |
2638 | # Note: PMK is in PMKSA cache and EAP fast re-auth data | |
2639 | ||
2640 | get_key_locations(buf, password, "Password") | |
2641 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
2642 | get_key_locations(buf, msk, "MSK") |
2643 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 JM |
2644 | verify_not_present(buf, kck, fname, "KCK") |
2645 | verify_not_present(buf, kek, fname, "KEK") | |
2646 | verify_not_present(buf, tk, fname, "TK") | |
2647 | verify_not_present(buf, gtk, fname, "GTK") | |
2648 | ||
2649 | dev[0].request("PMKSA_FLUSH") | |
2650 | dev[0].set_network_quoted(id, "identity", "foo") | |
2651 | logger.info("Checking keys in memory after PMKSA cache and EAP fast reauth flush") | |
2652 | buf = read_process_memory(pid, password) | |
2653 | get_key_locations(buf, password, "Password") | |
2654 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
2655 | get_key_locations(buf, msk, "MSK") |
2656 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 JM |
2657 | verify_not_present(buf, pmk, fname, "PMK") |
2658 | ||
2659 | dev[0].request("REMOVE_NETWORK all") | |
2660 | ||
2661 | logger.info("Checking keys in memory after network profile removal") | |
2662 | buf = read_process_memory(pid, password) | |
2663 | ||
2664 | get_key_locations(buf, password, "Password") | |
2665 | get_key_locations(buf, pmk, "PMK") | |
750904dd JM |
2666 | get_key_locations(buf, msk, "MSK") |
2667 | get_key_locations(buf, emsk, "EMSK") | |
5b3c40a6 JM |
2668 | verify_not_present(buf, password, fname, "password") |
2669 | verify_not_present(buf, pmk, fname, "PMK") | |
2670 | verify_not_present(buf, kck, fname, "KCK") | |
2671 | verify_not_present(buf, kek, fname, "KEK") | |
2672 | verify_not_present(buf, tk, fname, "TK") | |
2673 | verify_not_present(buf, gtk, fname, "GTK") | |
750904dd JM |
2674 | verify_not_present(buf, msk, fname, "MSK") |
2675 | verify_not_present(buf, emsk, fname, "EMSK") |