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