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