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