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