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