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