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