]>
Commit | Line | Data |
---|---|---|
eac67440 | 1 | # -*- coding: utf-8 -*- |
9626962d | 2 | # WPA2-Enterprise tests |
bce774ad | 3 | # Copyright (c) 2013-2014, 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 | 8 | import base64 |
9626962d JM |
9 | import time |
10 | import subprocess | |
11 | import logging | |
c9aa4308 | 12 | logger = logging.getLogger() |
0d4c5494 | 13 | import os.path |
9626962d JM |
14 | |
15 | import hwsim_utils | |
16 | import hostapd | |
eaf3f9b1 | 17 | from test_ap_psk import check_mib |
9626962d | 18 | |
6ea231e6 JM |
19 | def read_pem(fname): |
20 | with open(fname, "r") as f: | |
21 | lines = f.readlines() | |
22 | copy = False | |
23 | cert = "" | |
24 | for l in lines: | |
25 | if "-----END" in l: | |
26 | break | |
27 | if copy: | |
28 | cert = cert + l | |
29 | if "-----BEGIN" in l: | |
30 | copy = True | |
31 | return base64.b64decode(cert) | |
32 | ||
6f939e59 JM |
33 | def eap_connect(dev, ap, method, identity, |
34 | sha256=False, expect_failure=False, local_error_report=False, | |
35 | **kwargs): | |
cb33ee14 | 36 | hapd = hostapd.Hostapd(ap['ifname']) |
2bb9e283 JM |
37 | id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", |
38 | eap=method, identity=identity, | |
6f939e59 JM |
39 | wait_connect=False, scan_freq="2412", ieee80211w="1", |
40 | **kwargs) | |
f10ba3b2 JM |
41 | eap_check_auth(dev, method, True, sha256=sha256, |
42 | expect_failure=expect_failure, | |
43 | local_error_report=local_error_report) | |
44 | if expect_failure: | |
45 | return id | |
cb33ee14 JM |
46 | ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) |
47 | if ev is None: | |
48 | raise Exception("No connection event received from hostapd") | |
2bb9e283 | 49 | return id |
75b2b9cf | 50 | |
f10ba3b2 JM |
51 | def eap_check_auth(dev, method, initial, rsn=True, sha256=False, |
52 | expect_failure=False, local_error_report=False): | |
9626962d JM |
53 | ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) |
54 | if ev is None: | |
55 | raise Exception("Association and EAP start timed out") | |
56 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
57 | if ev is None: | |
58 | raise Exception("EAP method selection timed out") | |
59 | if method not in ev: | |
60 | raise Exception("Unexpected EAP method") | |
f10ba3b2 JM |
61 | if expect_failure: |
62 | ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
63 | if ev is None: | |
64 | raise Exception("EAP failure timed out") | |
65 | ev = dev.wait_event(["CTRL-EVENT-DISCONNECTED"]) | |
66 | if ev is None: | |
67 | raise Exception("Disconnection timed out") | |
68 | if not local_error_report: | |
69 | if "reason=23" not in ev: | |
70 | raise Exception("Proper reason code for disconnection not reported") | |
71 | return | |
9626962d JM |
72 | ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) |
73 | if ev is None: | |
74 | raise Exception("EAP success timed out") | |
9626962d | 75 | |
75b2b9cf JM |
76 | if initial: |
77 | ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
75b2b9cf | 78 | else: |
bce774ad JM |
79 | ev = dev.wait_event(["WPA: Key negotiation completed"], timeout=10) |
80 | if ev is None: | |
81 | raise Exception("Association with the AP timed out") | |
82 | status = dev.get_status() | |
83 | if status["wpa_state"] != "COMPLETED": | |
84 | raise Exception("Connection not completed") | |
75b2b9cf | 85 | |
9626962d JM |
86 | if status["suppPortStatus"] != "Authorized": |
87 | raise Exception("Port not authorized") | |
88 | if method not in status["selectedMethod"]: | |
89 | raise Exception("Incorrect EAP method status") | |
2b005194 JM |
90 | if sha256: |
91 | e = "WPA2-EAP-SHA256" | |
92 | elif rsn: | |
71390dc8 JM |
93 | e = "WPA2/IEEE 802.1X/EAP" |
94 | else: | |
95 | e = "WPA/IEEE 802.1X/EAP" | |
96 | if status["key_mgmt"] != e: | |
97 | raise Exception("Unexpected key_mgmt status: " + status["key_mgmt"]) | |
9626962d | 98 | |
2b005194 | 99 | def eap_reauth(dev, method, rsn=True, sha256=False): |
75b2b9cf | 100 | dev.request("REAUTHENTICATE") |
2b005194 | 101 | eap_check_auth(dev, method, False, rsn=rsn, sha256=sha256) |
75b2b9cf | 102 | |
9626962d JM |
103 | def test_ap_wpa2_eap_sim(dev, apdev): |
104 | """WPA2-Enterprise connection using EAP-SIM""" | |
0d4c5494 JM |
105 | if not os.path.exists("/tmp/hlr_auc_gw.sock"): |
106 | logger.info("No hlr_auc_gw available"); | |
107 | return "skip" | |
9626962d JM |
108 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
109 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 110 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", |
9626962d JM |
111 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") |
112 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
75b2b9cf | 113 | eap_reauth(dev[0], "SIM") |
9626962d | 114 | |
a0f350fd JM |
115 | eap_connect(dev[1], apdev[0], "SIM", "1232010000000001", |
116 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
117 | eap_connect(dev[2], apdev[0], "SIM", "1232010000000002", | |
118 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
119 | expect_failure=True) | |
120 | ||
f10ba3b2 JM |
121 | logger.info("Negative test with incorrect key") |
122 | dev[0].request("REMOVE_NETWORK all") | |
123 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
124 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
125 | expect_failure=True) | |
126 | ||
9626962d JM |
127 | def test_ap_wpa2_eap_aka(dev, apdev): |
128 | """WPA2-Enterprise connection using EAP-AKA""" | |
0d4c5494 JM |
129 | if not os.path.exists("/tmp/hlr_auc_gw.sock"): |
130 | logger.info("No hlr_auc_gw available"); | |
131 | return "skip" | |
9626962d JM |
132 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
133 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 134 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", |
9626962d JM |
135 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") |
136 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
75b2b9cf | 137 | eap_reauth(dev[0], "AKA") |
9626962d | 138 | |
f10ba3b2 JM |
139 | logger.info("Negative test with incorrect key") |
140 | dev[0].request("REMOVE_NETWORK all") | |
141 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
142 | password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
143 | expect_failure=True) | |
144 | ||
9626962d JM |
145 | def test_ap_wpa2_eap_aka_prime(dev, apdev): |
146 | """WPA2-Enterprise connection using EAP-AKA'""" | |
0d4c5494 JM |
147 | if not os.path.exists("/tmp/hlr_auc_gw.sock"): |
148 | logger.info("No hlr_auc_gw available"); | |
149 | return "skip" | |
9626962d JM |
150 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") |
151 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 152 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", |
9626962d JM |
153 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") |
154 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
75b2b9cf | 155 | eap_reauth(dev[0], "AKA'") |
9626962d | 156 | |
f10ba3b2 JM |
157 | logger.info("Negative test with incorrect key") |
158 | dev[0].request("REMOVE_NETWORK all") | |
159 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
160 | password="ff22250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
161 | expect_failure=True) | |
162 | ||
9626962d JM |
163 | def test_ap_wpa2_eap_ttls_pap(dev, apdev): |
164 | """WPA2-Enterprise connection using EAP-TTLS/PAP""" | |
165 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
65038313 JM |
166 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
167 | key_mgmt = hapd.get_config()['key_mgmt'] | |
168 | if key_mgmt.split(' ')[0] != "WPA-EAP": | |
169 | raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt) | |
cb33ee14 | 170 | eap_connect(dev[0], apdev[0], "TTLS", "pap user", |
9626962d | 171 | anonymous_identity="ttls", password="password", |
3b74982f JM |
172 | ca_cert="auth_serv/ca.pem", phase2="auth=PAP", |
173 | subject_match="/C=FI/O=w1.fi/CN=server.w1.fi", | |
174 | altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/") | |
9626962d | 175 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) |
75b2b9cf | 176 | eap_reauth(dev[0], "TTLS") |
eaf3f9b1 JM |
177 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-1"), |
178 | ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-1") ]) | |
9626962d JM |
179 | |
180 | def test_ap_wpa2_eap_ttls_chap(dev, apdev): | |
181 | """WPA2-Enterprise connection using EAP-TTLS/CHAP""" | |
182 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
183 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 184 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", |
9626962d | 185 | anonymous_identity="ttls", password="password", |
5c65e277 JM |
186 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP", |
187 | altsubject_match="EMAIL:noone@example.com;URI:http://example.com/;DNS:server.w1.fi") | |
9626962d | 188 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) |
75b2b9cf | 189 | eap_reauth(dev[0], "TTLS") |
9626962d JM |
190 | |
191 | def test_ap_wpa2_eap_ttls_mschap(dev, apdev): | |
192 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAP""" | |
193 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
194 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 195 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", |
9626962d | 196 | anonymous_identity="ttls", password="password", |
72c052d5 JM |
197 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", |
198 | domain_suffix_match="server.w1.fi") | |
9626962d | 199 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) |
75b2b9cf | 200 | eap_reauth(dev[0], "TTLS") |
6daf5b9c JM |
201 | dev[0].request("REMOVE_NETWORK all") |
202 | eap_connect(dev[0], apdev[0], "TTLS", "mschap user", | |
203 | anonymous_identity="ttls", password="password", | |
204 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
205 | fragment_size="200") | |
9626962d JM |
206 | |
207 | def test_ap_wpa2_eap_ttls_mschapv2(dev, apdev): | |
208 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2""" | |
209 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
210 | hostapd.add_ap(apdev[0]['ifname'], params) | |
5dec879d | 211 | hapd = hostapd.Hostapd(apdev[0]['ifname']) |
cb33ee14 | 212 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", |
9626962d | 213 | anonymous_identity="ttls", password="password", |
72c052d5 JM |
214 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", |
215 | domain_suffix_match="w1.fi") | |
9626962d | 216 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) |
5dec879d JM |
217 | sta1 = hapd.get_sta(dev[0].p2p_interface_addr()) |
218 | eapol1 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol") | |
75b2b9cf | 219 | eap_reauth(dev[0], "TTLS") |
5dec879d JM |
220 | sta2 = hapd.get_sta(dev[0].p2p_interface_addr()) |
221 | eapol2 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol") | |
222 | if int(sta2['dot1xAuthEapolFramesRx']) <= int(sta1['dot1xAuthEapolFramesRx']): | |
223 | raise Exception("dot1xAuthEapolFramesRx did not increase") | |
224 | if int(eapol2['authAuthEapStartsWhileAuthenticated']) < 1: | |
225 | raise Exception("authAuthEapStartsWhileAuthenticated did not increase") | |
226 | if int(eapol2['backendAuthSuccesses']) <= int(eapol1['backendAuthSuccesses']): | |
227 | raise Exception("backendAuthSuccesses did not increase") | |
9626962d | 228 | |
fa0ddb14 JM |
229 | logger.info("Password as hash value") |
230 | dev[0].request("REMOVE_NETWORK all") | |
231 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
232 | anonymous_identity="ttls", | |
233 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
234 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
235 | ||
f10ba3b2 JM |
236 | logger.info("Negative test with incorrect password") |
237 | dev[0].request("REMOVE_NETWORK all") | |
238 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
239 | anonymous_identity="ttls", password="password1", | |
240 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
241 | expect_failure=True) | |
242 | ||
eac67440 JM |
243 | def test_ap_wpa2_eap_ttls_mschapv2_utf8(dev, apdev): |
244 | """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 and UTF-8 password""" | |
245 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
246 | hostapd.add_ap(apdev[0]['ifname'], params) | |
247 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
248 | eap_connect(dev[0], apdev[0], "TTLS", "utf8-user-hash", | |
249 | anonymous_identity="ttls", password="secret-åäö-€-password", | |
250 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
251 | eap_connect(dev[1], apdev[0], "TTLS", "utf8-user", | |
252 | anonymous_identity="ttls", | |
253 | password_hex="hash:bd5844fad2489992da7fe8c5a01559cf", | |
254 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
255 | ||
9626962d JM |
256 | def test_ap_wpa2_eap_ttls_eap_gtc(dev, apdev): |
257 | """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC""" | |
258 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
259 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 260 | eap_connect(dev[0], apdev[0], "TTLS", "user", |
9626962d JM |
261 | anonymous_identity="ttls", password="password", |
262 | ca_cert="auth_serv/ca.pem", phase2="autheap=GTC") | |
263 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
75b2b9cf | 264 | eap_reauth(dev[0], "TTLS") |
9626962d JM |
265 | |
266 | def test_ap_wpa2_eap_ttls_eap_md5(dev, apdev): | |
267 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5""" | |
268 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
269 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 270 | eap_connect(dev[0], apdev[0], "TTLS", "user", |
9626962d JM |
271 | anonymous_identity="ttls", password="password", |
272 | ca_cert="auth_serv/ca.pem", phase2="autheap=MD5") | |
273 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
75b2b9cf | 274 | eap_reauth(dev[0], "TTLS") |
9626962d JM |
275 | |
276 | def test_ap_wpa2_eap_ttls_eap_mschapv2(dev, apdev): | |
277 | """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2""" | |
278 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
279 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 280 | eap_connect(dev[0], apdev[0], "TTLS", "user", |
9626962d JM |
281 | anonymous_identity="ttls", password="password", |
282 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2") | |
283 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
75b2b9cf | 284 | eap_reauth(dev[0], "TTLS") |
9626962d | 285 | |
f10ba3b2 JM |
286 | logger.info("Negative test with incorrect password") |
287 | dev[0].request("REMOVE_NETWORK all") | |
288 | eap_connect(dev[0], apdev[0], "TTLS", "user", | |
289 | anonymous_identity="ttls", password="password1", | |
290 | ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2", | |
291 | expect_failure=True) | |
292 | ||
9626962d JM |
293 | def test_ap_wpa2_eap_peap_eap_mschapv2(dev, apdev): |
294 | """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2""" | |
295 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
296 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 297 | eap_connect(dev[0], apdev[0], "PEAP", "user", |
698f8324 | 298 | anonymous_identity="peap", password="password", |
9626962d JM |
299 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") |
300 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
75b2b9cf | 301 | eap_reauth(dev[0], "PEAP") |
6daf5b9c JM |
302 | dev[0].request("REMOVE_NETWORK all") |
303 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
304 | anonymous_identity="peap", password="password", | |
305 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
306 | fragment_size="200") | |
c7afc078 | 307 | |
fa0ddb14 JM |
308 | logger.info("Password as hash value") |
309 | dev[0].request("REMOVE_NETWORK all") | |
310 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
311 | anonymous_identity="peap", | |
312 | password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c", | |
313 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2") | |
314 | ||
f10ba3b2 JM |
315 | logger.info("Negative test with incorrect password") |
316 | dev[0].request("REMOVE_NETWORK all") | |
317 | eap_connect(dev[0], apdev[0], "PEAP", "user", | |
318 | anonymous_identity="peap", password="password1", | |
319 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
320 | expect_failure=True) | |
321 | ||
698f8324 JM |
322 | def test_ap_wpa2_eap_peap_crypto_binding(dev, apdev): |
323 | """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding""" | |
324 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
325 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 326 | eap_connect(dev[0], apdev[0], "PEAP", "user", password="password", |
698f8324 JM |
327 | ca_cert="auth_serv/ca.pem", |
328 | phase1="peapver=0 crypto_binding=2", | |
329 | phase2="auth=MSCHAPV2") | |
330 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
75b2b9cf | 331 | eap_reauth(dev[0], "PEAP") |
698f8324 | 332 | |
d0ce1050 JM |
333 | def test_ap_wpa2_eap_peap_eap_tls(dev, apdev): |
334 | """WPA2-Enterprise connection using EAP-PEAP/EAP-TLS""" | |
335 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
336 | hostapd.add_ap(apdev[0]['ifname'], params) | |
337 | eap_connect(dev[0], apdev[0], "PEAP", "cert user", | |
338 | ca_cert="auth_serv/ca.pem", phase2="auth=TLS", | |
339 | ca_cert2="auth_serv/ca.pem", | |
340 | client_cert2="auth_serv/user.pem", | |
341 | private_key2="auth_serv/user.key") | |
342 | eap_reauth(dev[0], "PEAP") | |
343 | ||
e114c49c JM |
344 | def test_ap_wpa2_eap_tls(dev, apdev): |
345 | """WPA2-Enterprise connection using EAP-TLS""" | |
346 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
347 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 348 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", |
e114c49c JM |
349 | client_cert="auth_serv/user.pem", |
350 | private_key="auth_serv/user.key") | |
75b2b9cf | 351 | eap_reauth(dev[0], "TLS") |
e114c49c | 352 | |
6ea231e6 JM |
353 | def test_ap_wpa2_eap_tls_blob(dev, apdev): |
354 | """WPA2-Enterprise connection using EAP-TLS and config blobs""" | |
355 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
356 | hostapd.add_ap(apdev[0]['ifname'], params) | |
357 | cert = read_pem("auth_serv/ca.pem") | |
358 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
359 | raise Exception("Could not set cacert blob") | |
360 | cert = read_pem("auth_serv/user.pem") | |
361 | if "OK" not in dev[0].request("SET blob usercert " + cert.encode("hex")): | |
362 | raise Exception("Could not set usercert blob") | |
363 | key = read_pem("auth_serv/user.key") | |
364 | if "OK" not in dev[0].request("SET blob userkey " + key.encode("hex")): | |
365 | raise Exception("Could not set cacert blob") | |
366 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="blob://cacert", | |
367 | client_cert="blob://usercert", | |
368 | private_key="blob://userkey") | |
369 | ||
2d10eb0e JM |
370 | def test_ap_wpa2_eap_tls_pkcs12(dev, apdev): |
371 | """WPA2-Enterprise connection using EAP-TLS and PKCS#12""" | |
372 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
373 | hostapd.add_ap(apdev[0]['ifname'], params) | |
374 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
375 | private_key="auth_serv/user.pkcs12", | |
376 | private_key_passwd="whatever") | |
377 | dev[0].request("REMOVE_NETWORK all") | |
378 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
379 | identity="tls user", | |
380 | ca_cert="auth_serv/ca.pem", | |
381 | private_key="auth_serv/user.pkcs12", | |
382 | wait_connect=False, scan_freq="2412") | |
383 | ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"]) | |
384 | if ev is None: | |
385 | raise Exception("Request for private key passphrase timed out") | |
386 | id = ev.split(':')[0].split('-')[-1] | |
387 | dev[0].request("CTRL-RSP-PASSPHRASE-" + id + ":whatever") | |
388 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
389 | if ev is None: | |
390 | raise Exception("Connection timed out") | |
391 | ||
6ea231e6 JM |
392 | def test_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev): |
393 | """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob""" | |
394 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
395 | hostapd.add_ap(apdev[0]['ifname'], params) | |
396 | cert = read_pem("auth_serv/ca.pem") | |
397 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
398 | raise Exception("Could not set cacert blob") | |
399 | with open("auth_serv/user.pkcs12", "rb") as f: | |
400 | if "OK" not in dev[0].request("SET blob pkcs12 " + f.read().encode("hex")): | |
401 | raise Exception("Could not set pkcs12 blob") | |
402 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="blob://cacert", | |
403 | private_key="blob://pkcs12", | |
404 | private_key_passwd="whatever") | |
405 | ||
c7afc078 JM |
406 | def test_ap_wpa2_eap_tls_neg_incorrect_trust_root(dev, apdev): |
407 | """WPA2-Enterprise negative test - incorrect trust root""" | |
408 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
409 | hostapd.add_ap(apdev[0]['ifname'], params) | |
6ea231e6 JM |
410 | cert = read_pem("auth_serv/ca-incorrect.pem") |
411 | if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")): | |
412 | raise Exception("Could not set cacert blob") | |
c7afc078 | 413 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", |
6ea231e6 JM |
414 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", |
415 | password="password", phase2="auth=MSCHAPV2", | |
416 | ca_cert="blob://cacert", | |
417 | wait_connect=False, scan_freq="2412") | |
418 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
c7afc078 JM |
419 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", |
420 | password="password", phase2="auth=MSCHAPV2", | |
421 | ca_cert="auth_serv/ca-incorrect.pem", | |
c65f23ab | 422 | wait_connect=False, scan_freq="2412") |
c7afc078 | 423 | |
6ea231e6 JM |
424 | for dev in (dev[0], dev[1]): |
425 | ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
426 | if ev is None: | |
427 | raise Exception("Association and EAP start timed out") | |
c7afc078 | 428 | |
6ea231e6 JM |
429 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) |
430 | if ev is None: | |
431 | raise Exception("EAP method selection timed out") | |
432 | if "TTLS" not in ev: | |
433 | raise Exception("Unexpected EAP method") | |
434 | ||
435 | ev = dev.wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
436 | "CTRL-EVENT-EAP-SUCCESS", | |
437 | "CTRL-EVENT-EAP-FAILURE", | |
438 | "CTRL-EVENT-CONNECTED", | |
439 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
440 | if ev is None: | |
441 | raise Exception("EAP result timed out") | |
442 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
443 | raise Exception("TLS certificate error not reported") | |
444 | ||
445 | ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
446 | "CTRL-EVENT-EAP-FAILURE", | |
447 | "CTRL-EVENT-CONNECTED", | |
448 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
449 | if ev is None: | |
450 | raise Exception("EAP result(2) timed out") | |
451 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
452 | raise Exception("EAP failure not reported") | |
c7afc078 | 453 | |
6ea231e6 JM |
454 | ev = dev.wait_event(["CTRL-EVENT-CONNECTED", |
455 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
456 | if ev is None: | |
457 | raise Exception("EAP result(3) timed out") | |
458 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
459 | raise Exception("Disconnection not reported") | |
c7afc078 | 460 | |
6ea231e6 JM |
461 | ev = dev.wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) |
462 | if ev is None: | |
463 | raise Exception("Network block disabling not reported") | |
72c052d5 JM |
464 | |
465 | def test_ap_wpa2_eap_tls_neg_suffix_match(dev, apdev): | |
466 | """WPA2-Enterprise negative test - domain suffix mismatch""" | |
467 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
468 | hostapd.add_ap(apdev[0]['ifname'], params) | |
469 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
470 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
471 | password="password", phase2="auth=MSCHAPV2", | |
472 | ca_cert="auth_serv/ca.pem", | |
473 | domain_suffix_match="incorrect.example.com", | |
c65f23ab | 474 | wait_connect=False, scan_freq="2412") |
72c052d5 JM |
475 | |
476 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
477 | if ev is None: | |
478 | raise Exception("Association and EAP start timed out") | |
479 | ||
480 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
481 | if ev is None: | |
482 | raise Exception("EAP method selection timed out") | |
483 | if "TTLS" not in ev: | |
484 | raise Exception("Unexpected EAP method") | |
485 | ||
486 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
487 | "CTRL-EVENT-EAP-SUCCESS", | |
488 | "CTRL-EVENT-EAP-FAILURE", | |
489 | "CTRL-EVENT-CONNECTED", | |
490 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
491 | if ev is None: | |
492 | raise Exception("EAP result timed out") | |
493 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
494 | raise Exception("TLS certificate error not reported") | |
495 | if "Domain suffix mismatch" not in ev: | |
496 | raise Exception("Domain suffix mismatch not reported") | |
497 | ||
498 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
499 | "CTRL-EVENT-EAP-FAILURE", | |
500 | "CTRL-EVENT-CONNECTED", | |
501 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
502 | if ev is None: | |
503 | raise Exception("EAP result(2) timed out") | |
504 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
505 | raise Exception("EAP failure not reported") | |
506 | ||
507 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
508 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
509 | if ev is None: | |
510 | raise Exception("EAP result(3) timed out") | |
511 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
512 | raise Exception("Disconnection not reported") | |
513 | ||
514 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
515 | if ev is None: | |
516 | raise Exception("Network block disabling not reported") | |
22b99086 | 517 | |
3b74982f JM |
518 | def test_ap_wpa2_eap_tls_neg_subject_match(dev, apdev): |
519 | """WPA2-Enterprise negative test - subject mismatch""" | |
520 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
521 | hostapd.add_ap(apdev[0]['ifname'], params) | |
522 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
523 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
524 | password="password", phase2="auth=MSCHAPV2", | |
525 | ca_cert="auth_serv/ca.pem", | |
526 | subject_match="/C=FI/O=w1.fi/CN=example.com", | |
527 | wait_connect=False, scan_freq="2412") | |
528 | ||
529 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
530 | if ev is None: | |
531 | raise Exception("Association and EAP start timed out") | |
532 | ||
533 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
534 | if ev is None: | |
535 | raise Exception("EAP method selection timed out") | |
536 | if "TTLS" not in ev: | |
537 | raise Exception("Unexpected EAP method") | |
538 | ||
539 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
540 | "CTRL-EVENT-EAP-SUCCESS", | |
541 | "CTRL-EVENT-EAP-FAILURE", | |
542 | "CTRL-EVENT-CONNECTED", | |
543 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
544 | if ev is None: | |
545 | raise Exception("EAP result timed out") | |
546 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
547 | raise Exception("TLS certificate error not reported") | |
548 | if "Subject mismatch" not in ev: | |
549 | raise Exception("Subject mismatch not reported") | |
550 | ||
551 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
552 | "CTRL-EVENT-EAP-FAILURE", | |
553 | "CTRL-EVENT-CONNECTED", | |
554 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
555 | if ev is None: | |
556 | raise Exception("EAP result(2) timed out") | |
557 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
558 | raise Exception("EAP failure not reported") | |
559 | ||
560 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
561 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
562 | if ev is None: | |
563 | raise Exception("EAP result(3) timed out") | |
564 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
565 | raise Exception("Disconnection not reported") | |
566 | ||
567 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
568 | if ev is None: | |
569 | raise Exception("Network block disabling not reported") | |
570 | ||
571 | def test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev): | |
572 | """WPA2-Enterprise negative test - altsubject mismatch""" | |
573 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
574 | hostapd.add_ap(apdev[0]['ifname'], params) | |
575 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
576 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
577 | password="password", phase2="auth=MSCHAPV2", | |
578 | ca_cert="auth_serv/ca.pem", | |
579 | altsubject_match="incorrect.example.com", | |
580 | wait_connect=False, scan_freq="2412") | |
581 | ||
582 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
583 | if ev is None: | |
584 | raise Exception("Association and EAP start timed out") | |
585 | ||
586 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10) | |
587 | if ev is None: | |
588 | raise Exception("EAP method selection timed out") | |
589 | if "TTLS" not in ev: | |
590 | raise Exception("Unexpected EAP method") | |
591 | ||
592 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR", | |
593 | "CTRL-EVENT-EAP-SUCCESS", | |
594 | "CTRL-EVENT-EAP-FAILURE", | |
595 | "CTRL-EVENT-CONNECTED", | |
596 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
597 | if ev is None: | |
598 | raise Exception("EAP result timed out") | |
599 | if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev: | |
600 | raise Exception("TLS certificate error not reported") | |
601 | if "AltSubject mismatch" not in ev: | |
602 | raise Exception("altsubject mismatch not reported") | |
603 | ||
604 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS", | |
605 | "CTRL-EVENT-EAP-FAILURE", | |
606 | "CTRL-EVENT-CONNECTED", | |
607 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
608 | if ev is None: | |
609 | raise Exception("EAP result(2) timed out") | |
610 | if "CTRL-EVENT-EAP-FAILURE" not in ev: | |
611 | raise Exception("EAP failure not reported") | |
612 | ||
613 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
614 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
615 | if ev is None: | |
616 | raise Exception("EAP result(3) timed out") | |
617 | if "CTRL-EVENT-DISCONNECTED" not in ev: | |
618 | raise Exception("Disconnection not reported") | |
619 | ||
620 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10) | |
621 | if ev is None: | |
622 | raise Exception("Network block disabling not reported") | |
623 | ||
57be05e1 JM |
624 | def test_ap_wpa2_eap_ttls_server_cert_hash(dev, apdev): |
625 | """WPA2-Enterprise connection using EAP-TTLS and server certificate hash""" | |
626 | srv_cert_hash = "0a3f81f63569226657a069855bb13f3b922670437a2b87585a4734f70ac7315b" | |
627 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
628 | hostapd.add_ap(apdev[0]['ifname'], params) | |
629 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
630 | identity="probe", ca_cert="probe://", | |
631 | wait_connect=False, scan_freq="2412") | |
632 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
633 | if ev is None: | |
634 | raise Exception("Association and EAP start timed out") | |
635 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT depth=0"], timeout=10) | |
636 | if ev is None: | |
637 | raise Exception("No peer server certificate event seen") | |
638 | if "hash=" + srv_cert_hash not in ev: | |
639 | raise Exception("Expected server certificate hash not reported") | |
640 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10) | |
641 | if ev is None: | |
642 | raise Exception("EAP result timed out") | |
643 | if "Server certificate chain probe" not in ev: | |
644 | raise Exception("Server certificate probe not reported") | |
645 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=10) | |
646 | if ev is None: | |
647 | raise Exception("Disconnection event not seen") | |
648 | dev[0].request("REMOVE_NETWORK all") | |
649 | ||
650 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
651 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
652 | password="password", phase2="auth=MSCHAPV2", | |
653 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a", | |
654 | wait_connect=False, scan_freq="2412") | |
655 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
656 | if ev is None: | |
657 | raise Exception("Association and EAP start timed out") | |
658 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10) | |
659 | if ev is None: | |
660 | raise Exception("EAP result timed out") | |
661 | if "Server certificate mismatch" not in ev: | |
662 | raise Exception("Server certificate mismatch not reported") | |
663 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=10) | |
664 | if ev is None: | |
665 | raise Exception("Disconnection event not seen") | |
666 | dev[0].request("REMOVE_NETWORK all") | |
667 | ||
668 | eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user", | |
669 | anonymous_identity="ttls", password="password", | |
670 | ca_cert="hash://server/sha256/" + srv_cert_hash, | |
671 | phase2="auth=MSCHAPV2") | |
672 | ||
2a6a2192 JM |
673 | def test_ap_wpa2_eap_ttls_server_cert_hash_invalid(dev, apdev): |
674 | """WPA2-Enterprise connection using EAP-TTLS and server certificate hash (invalid config)""" | |
675 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
676 | hostapd.add_ap(apdev[0]['ifname'], params) | |
677 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
678 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
679 | password="password", phase2="auth=MSCHAPV2", | |
680 | ca_cert="hash://server/md5/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a", | |
681 | wait_connect=False, scan_freq="2412") | |
682 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
683 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
684 | password="password", phase2="auth=MSCHAPV2", | |
685 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca", | |
686 | wait_connect=False, scan_freq="2412") | |
687 | dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
688 | identity="DOMAIN\mschapv2 user", anonymous_identity="ttls", | |
689 | password="password", phase2="auth=MSCHAPV2", | |
690 | ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6Q", | |
691 | wait_connect=False, scan_freq="2412") | |
692 | for i in range(0, 3): | |
693 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
694 | if ev is None: | |
695 | raise Exception("Association and EAP start timed out") | |
696 | timeout = 1 if i == 0 else 0.1 | |
697 | ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=timeout) | |
698 | if ev is not None: | |
699 | raise Exception("Unexpected EAP start") | |
700 | ||
22b99086 JM |
701 | def test_ap_wpa2_eap_pwd(dev, apdev): |
702 | """WPA2-Enterprise connection using EAP-pwd""" | |
703 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
704 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 705 | eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password") |
75b2b9cf | 706 | eap_reauth(dev[0], "PWD") |
6daf5b9c | 707 | dev[0].request("REMOVE_NETWORK all") |
0403fa0a JM |
708 | |
709 | eap_connect(dev[1], apdev[0], "PWD", | |
710 | "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com", | |
711 | password="secret password", | |
6daf5b9c JM |
712 | fragment_size="90") |
713 | ||
f10ba3b2 | 714 | logger.info("Negative test with incorrect password") |
0403fa0a | 715 | eap_connect(dev[2], apdev[0], "PWD", "pwd user", password="secret-password", |
f10ba3b2 JM |
716 | expect_failure=True, local_error_report=True) |
717 | ||
0403fa0a JM |
718 | eap_connect(dev[0], apdev[0], "PWD", |
719 | "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com", | |
720 | password="secret password", | |
721 | fragment_size="31") | |
722 | ||
c075f040 JM |
723 | def test_ap_wpa2_eap_pwd_groups(dev, apdev): |
724 | """WPA2-Enterprise connection using various EAP-pwd groups""" | |
725 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", | |
726 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
727 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" } | |
728 | for i in [ 19, 20, 21, 25, 26 ]: | |
729 | params['pwd_group'] = str(i) | |
730 | hostapd.add_ap(apdev[0]['ifname'], params) | |
731 | dev[0].request("REMOVE_NETWORK all") | |
732 | eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password") | |
733 | ||
22b99086 JM |
734 | def test_ap_wpa2_eap_gpsk(dev, apdev): |
735 | """WPA2-Enterprise connection using EAP-GPSK""" | |
736 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
737 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 738 | id = eap_connect(dev[0], apdev[0], "GPSK", "gpsk user", |
369f9c20 | 739 | password="abcdefghijklmnop0123456789abcdef") |
75b2b9cf | 740 | eap_reauth(dev[0], "GPSK") |
22b99086 | 741 | |
369f9c20 JM |
742 | logger.info("Test forced algorithm selection") |
743 | for phase1 in [ "cipher=1", "cipher=2" ]: | |
744 | dev[0].set_network_quoted(id, "phase1", phase1) | |
745 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
746 | if ev is None: | |
747 | raise Exception("EAP success timed out") | |
748 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
749 | if ev is None: | |
750 | raise Exception("Association with the AP timed out") | |
751 | ||
752 | logger.info("Test failed algorithm negotiation") | |
753 | dev[0].set_network_quoted(id, "phase1", "cipher=9") | |
754 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
755 | if ev is None: | |
756 | raise Exception("EAP failure timed out") | |
757 | ||
f10ba3b2 JM |
758 | logger.info("Negative test with incorrect password") |
759 | dev[0].request("REMOVE_NETWORK all") | |
760 | eap_connect(dev[0], apdev[0], "GPSK", "gpsk user", | |
761 | password="ffcdefghijklmnop0123456789abcdef", | |
762 | expect_failure=True) | |
763 | ||
22b99086 JM |
764 | def test_ap_wpa2_eap_sake(dev, apdev): |
765 | """WPA2-Enterprise connection using EAP-SAKE""" | |
766 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
767 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 768 | eap_connect(dev[0], apdev[0], "SAKE", "sake user", |
22b99086 | 769 | password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") |
75b2b9cf | 770 | eap_reauth(dev[0], "SAKE") |
22b99086 | 771 | |
f10ba3b2 JM |
772 | logger.info("Negative test with incorrect password") |
773 | dev[0].request("REMOVE_NETWORK all") | |
774 | eap_connect(dev[0], apdev[0], "SAKE", "sake user", | |
775 | password_hex="ff23456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", | |
776 | expect_failure=True) | |
777 | ||
22b99086 JM |
778 | def test_ap_wpa2_eap_eke(dev, apdev): |
779 | """WPA2-Enterprise connection using EAP-EKE""" | |
780 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
781 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 782 | id = eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello") |
75b2b9cf | 783 | eap_reauth(dev[0], "EKE") |
22b99086 | 784 | |
2bb9e283 JM |
785 | logger.info("Test forced algorithm selection") |
786 | for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2", | |
787 | "dhgroup=4 encr=1 prf=2 mac=2", | |
788 | "dhgroup=3 encr=1 prf=2 mac=2", | |
789 | "dhgroup=3 encr=1 prf=1 mac=1" ]: | |
790 | dev[0].set_network_quoted(id, "phase1", phase1) | |
791 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
792 | if ev is None: | |
793 | raise Exception("EAP success timed out") | |
794 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
795 | if ev is None: | |
796 | raise Exception("Association with the AP timed out") | |
797 | ||
798 | logger.info("Test failed algorithm negotiation") | |
799 | dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9") | |
800 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
801 | if ev is None: | |
802 | raise Exception("EAP failure timed out") | |
803 | ||
f10ba3b2 JM |
804 | logger.info("Negative test with incorrect password") |
805 | dev[0].request("REMOVE_NETWORK all") | |
806 | eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello1", | |
807 | expect_failure=True) | |
808 | ||
22b99086 JM |
809 | def test_ap_wpa2_eap_ikev2(dev, apdev): |
810 | """WPA2-Enterprise connection using EAP-IKEv2""" | |
811 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
812 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 JM |
813 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", |
814 | password="ike password") | |
75b2b9cf | 815 | eap_reauth(dev[0], "IKEV2") |
6daf5b9c JM |
816 | dev[0].request("REMOVE_NETWORK all") |
817 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", | |
818 | password="ike password", fragment_size="250") | |
22b99086 | 819 | |
f10ba3b2 JM |
820 | logger.info("Negative test with incorrect password") |
821 | dev[0].request("REMOVE_NETWORK all") | |
822 | eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user", | |
823 | password="ike-password", expect_failure=True) | |
824 | ||
22b99086 JM |
825 | def test_ap_wpa2_eap_pax(dev, apdev): |
826 | """WPA2-Enterprise connection using EAP-PAX""" | |
827 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
828 | hostapd.add_ap(apdev[0]['ifname'], params) | |
cb33ee14 | 829 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", |
22b99086 | 830 | password_hex="0123456789abcdef0123456789abcdef") |
75b2b9cf | 831 | eap_reauth(dev[0], "PAX") |
22b99086 | 832 | |
f10ba3b2 JM |
833 | logger.info("Negative test with incorrect password") |
834 | dev[0].request("REMOVE_NETWORK all") | |
835 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", | |
836 | password_hex="ff23456789abcdef0123456789abcdef", | |
837 | expect_failure=True) | |
838 | ||
22b99086 JM |
839 | def test_ap_wpa2_eap_psk(dev, apdev): |
840 | """WPA2-Enterprise connection using EAP-PSK""" | |
841 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
2b005194 JM |
842 | params["wpa_key_mgmt"] = "WPA-EAP-SHA256" |
843 | params["ieee80211w"] = "2" | |
22b99086 | 844 | hostapd.add_ap(apdev[0]['ifname'], params) |
cb33ee14 | 845 | eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com", |
2b005194 JM |
846 | password_hex="0123456789abcdef0123456789abcdef", sha256=True) |
847 | eap_reauth(dev[0], "PSK", sha256=True) | |
eaf3f9b1 JM |
848 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"), |
849 | ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ]) | |
71390dc8 | 850 | |
f10ba3b2 JM |
851 | logger.info("Negative test with incorrect password") |
852 | dev[0].request("REMOVE_NETWORK all") | |
853 | eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com", | |
854 | password_hex="ff23456789abcdef0123456789abcdef", sha256=True, | |
855 | expect_failure=True) | |
856 | ||
71390dc8 JM |
857 | def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev): |
858 | """WPA-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2""" | |
859 | params = hostapd.wpa_eap_params(ssid="test-wpa-eap") | |
860 | hostapd.add_ap(apdev[0]['ifname'], params) | |
861 | dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="PEAP", | |
862 | identity="user", password="password", phase2="auth=MSCHAPV2", | |
863 | ca_cert="auth_serv/ca.pem", wait_connect=False, | |
864 | scan_freq="2412") | |
865 | eap_check_auth(dev[0], "PEAP", True, rsn=False) | |
866 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
867 | eap_reauth(dev[0], "PEAP", rsn=False) | |
eaf3f9b1 JM |
868 | check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"), |
869 | ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ]) | |
40759604 JM |
870 | |
871 | def test_ap_wpa2_eap_interactive(dev, apdev): | |
872 | """WPA2-Enterprise connection using interactive identity/password entry""" | |
873 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
874 | hostapd.add_ap(apdev[0]['ifname'], params) | |
875 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
876 | ||
877 | tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry", | |
878 | "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2", | |
879 | None, "password"), | |
880 | ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry", | |
881 | "TTLS", "ttls", None, "auth=MSCHAPV2", | |
882 | "DOMAIN\mschapv2 user", "password"), | |
883 | ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry", | |
884 | "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"), | |
885 | ("Connection with dynamic TTLS/EAP-MD5 password entry", | |
886 | "TTLS", "ttls", "user", "autheap=MD5", None, "password"), | |
887 | ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry", | |
888 | "PEAP", None, "user", "auth=MSCHAPV2", None, "password"), | |
889 | ("Connection with dynamic PEAP/EAP-GTC password entry", | |
890 | "PEAP", None, "user", "auth=GTC", None, "password") ] | |
891 | for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests: | |
892 | logger.info(desc) | |
893 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap, | |
894 | anonymous_identity=anon, identity=identity, | |
895 | ca_cert="auth_serv/ca.pem", phase2=phase2, | |
896 | wait_connect=False, scan_freq="2412") | |
897 | if req_id: | |
898 | ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"]) | |
899 | if ev is None: | |
900 | raise Exception("Request for identity timed out") | |
901 | id = ev.split(':')[0].split('-')[-1] | |
902 | dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id) | |
903 | ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"]) | |
904 | if ev is None: | |
905 | raise Exception("Request for password timed out") | |
906 | id = ev.split(':')[0].split('-')[-1] | |
907 | type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD" | |
908 | dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw) | |
909 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
910 | if ev is None: | |
911 | raise Exception("Connection timed out") | |
912 | dev[0].request("REMOVE_NETWORK all") | |
e745c811 JM |
913 | |
914 | def test_ap_wpa2_eap_vendor_test(dev, apdev): | |
915 | """WPA2-Enterprise connection using EAP vendor test""" | |
916 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
917 | hostapd.add_ap(apdev[0]['ifname'], params) | |
918 | eap_connect(dev[0], apdev[0], "VENDOR-TEST", "vendor-test") | |
919 | eap_reauth(dev[0], "VENDOR-TEST") | |
53a6f06a JM |
920 | |
921 | def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev): | |
922 | """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning""" | |
923 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
924 | hostapd.add_ap(apdev[0]['ifname'], params) | |
925 | eap_connect(dev[0], apdev[0], "FAST", "user", | |
926 | anonymous_identity="FAST", password="password", | |
927 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
928 | phase1="fast_provisioning=1", pac_file="blob://fast_pac") | |
929 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
930 | eap_reauth(dev[0], "FAST") | |
931 | ||
932 | def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev): | |
933 | """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning""" | |
934 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
935 | hostapd.add_ap(apdev[0]['ifname'], params) | |
936 | eap_connect(dev[0], apdev[0], "FAST", "user", | |
937 | anonymous_identity="FAST", password="password", | |
938 | ca_cert="auth_serv/ca.pem", phase2="auth=GTC", | |
939 | phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth") | |
940 | hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) | |
941 | eap_reauth(dev[0], "FAST") | |
d4c7a2b9 JM |
942 | |
943 | def test_ap_wpa2_eap_tls_ocsp(dev, apdev): | |
944 | """WPA2-Enterprise connection using EAP-TLS and verifying OCSP""" | |
945 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
946 | hostapd.add_ap(apdev[0]['ifname'], params) | |
947 | eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem", | |
948 | private_key="auth_serv/user.pkcs12", | |
949 | private_key_passwd="whatever", ocsp=2) | |
950 | ||
64e05f96 | 951 | def int_eap_server_params(): |
d4c7a2b9 JM |
952 | params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP", |
953 | "rsn_pairwise": "CCMP", "ieee8021x": "1", | |
954 | "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf", | |
955 | "ca_cert": "auth_serv/ca.pem", | |
956 | "server_cert": "auth_serv/server.pem", | |
64e05f96 JM |
957 | "private_key": "auth_serv/server.key" } |
958 | return params | |
959 | ||
960 | def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev): | |
961 | """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response""" | |
962 | params = int_eap_server_params() | |
963 | params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid" | |
d4c7a2b9 JM |
964 | hostapd.add_ap(apdev[0]['ifname'], params) |
965 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
966 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
967 | private_key="auth_serv/user.pkcs12", | |
968 | private_key_passwd="whatever", ocsp=2, | |
969 | wait_connect=False, scan_freq="2412") | |
970 | count = 0 | |
971 | while True: | |
972 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"]) | |
973 | if ev is None: | |
974 | raise Exception("Timeout on EAP status") | |
975 | if 'bad certificate status response' in ev: | |
976 | break | |
977 | count = count + 1 | |
978 | if count > 10: | |
979 | raise Exception("Unexpected number of EAP status messages") | |
980 | ||
981 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
982 | if ev is None: | |
983 | raise Exception("Timeout on EAP failure report") | |
64e05f96 JM |
984 | |
985 | def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev): | |
986 | """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)""" | |
987 | params = int_eap_server_params() | |
988 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
989 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
990 | hostapd.add_ap(apdev[0]['ifname'], params) | |
991 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
992 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
993 | private_key="auth_serv/user.pkcs12", | |
994 | private_key_passwd="whatever", | |
995 | domain_suffix_match="server3.w1.fi", | |
996 | scan_freq="2412") | |
997 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
998 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
999 | private_key="auth_serv/user.pkcs12", | |
1000 | private_key_passwd="whatever", | |
1001 | domain_suffix_match="w1.fi", | |
1002 | scan_freq="2412") | |
1003 | ||
1004 | def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev): | |
1005 | """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)""" | |
1006 | params = int_eap_server_params() | |
1007 | params["server_cert"] = "auth_serv/server-no-dnsname.pem" | |
1008 | params["private_key"] = "auth_serv/server-no-dnsname.key" | |
1009 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1010 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", | |
1011 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
1012 | private_key="auth_serv/user.pkcs12", | |
1013 | private_key_passwd="whatever", | |
1014 | domain_suffix_match="example.com", | |
1015 | wait_connect=False, | |
1016 | scan_freq="2412") | |
c61dca40 JM |
1017 | dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS", |
1018 | identity="tls user", ca_cert="auth_serv/ca.pem", | |
1019 | private_key="auth_serv/user.pkcs12", | |
1020 | private_key_passwd="whatever", | |
1021 | domain_suffix_match="erver3.w1.fi", | |
1022 | wait_connect=False, | |
1023 | scan_freq="2412") | |
64e05f96 JM |
1024 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) |
1025 | if ev is None: | |
1026 | raise Exception("Timeout on EAP failure report") | |
c61dca40 JM |
1027 | ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"]) |
1028 | if ev is None: | |
1029 | raise Exception("Timeout on EAP failure report (2)") | |
6a4d0dbe JM |
1030 | |
1031 | def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev): | |
1032 | """WPA2-Enterprise using EAP-TTLS and expired certificate""" | |
1033 | params = int_eap_server_params() | |
1034 | params["server_cert"] = "auth_serv/server-expired.pem" | |
1035 | params["private_key"] = "auth_serv/server-expired.key" | |
1036 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1037 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1038 | identity="mschap user", password="password", | |
1039 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1040 | wait_connect=False, | |
1041 | scan_freq="2412") | |
1042 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"]) | |
1043 | if ev is None: | |
1044 | raise Exception("Timeout on EAP certificate error report") | |
1045 | if "reason=4" not in ev or "certificate has expired" not in ev: | |
1046 | raise Exception("Unexpected failure reason: " + ev) | |
1047 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
1048 | if ev is None: | |
1049 | raise Exception("Timeout on EAP failure report") | |
1050 | ||
1051 | def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev): | |
1052 | """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration""" | |
1053 | params = int_eap_server_params() | |
1054 | params["server_cert"] = "auth_serv/server-expired.pem" | |
1055 | params["private_key"] = "auth_serv/server-expired.key" | |
1056 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1057 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1058 | identity="mschap user", password="password", | |
1059 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1060 | phase1="tls_disable_time_checks=1", | |
1061 | scan_freq="2412") | |
6ab4a7aa JM |
1062 | |
1063 | def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev): | |
1064 | """WPA2-Enterprise using EAP-TTLS and server cert with client EKU""" | |
1065 | params = int_eap_server_params() | |
1066 | params["server_cert"] = "auth_serv/server-eku-client.pem" | |
1067 | params["private_key"] = "auth_serv/server-eku-client.key" | |
1068 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1069 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1070 | identity="mschap user", password="password", | |
1071 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1072 | wait_connect=False, | |
1073 | scan_freq="2412") | |
1074 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
1075 | if ev is None: | |
1076 | raise Exception("Timeout on EAP failure report") | |
242219c5 | 1077 | |
14bef66d JM |
1078 | def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev): |
1079 | """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU""" | |
1080 | params = int_eap_server_params() | |
1081 | params["server_cert"] = "auth_serv/server-eku-client-server.pem" | |
1082 | params["private_key"] = "auth_serv/server-eku-client-server.key" | |
1083 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1084 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1085 | identity="mschap user", password="password", | |
1086 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1087 | scan_freq="2412") | |
1088 | ||
c37b02fc JM |
1089 | def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev): |
1090 | """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file""" | |
1091 | params = int_eap_server_params() | |
1092 | del params["server_cert"] | |
1093 | params["private_key"] = "auth_serv/server.pkcs12" | |
1094 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1095 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", | |
1096 | identity="mschap user", password="password", | |
1097 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1098 | scan_freq="2412") | |
1099 | ||
242219c5 JM |
1100 | def test_ap_wpa2_eap_ttls_dh_params(dev, apdev): |
1101 | """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params""" | |
1102 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1103 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1104 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", | |
1105 | anonymous_identity="ttls", password="password", | |
1106 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP", | |
1107 | dh_file="auth_serv/dh.conf") | |
7c50093f | 1108 | |
6ea231e6 JM |
1109 | def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev): |
1110 | """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob""" | |
1111 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1112 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1113 | dh = read_pem("auth_serv/dh.conf") | |
1114 | if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")): | |
1115 | raise Exception("Could not set dhparams blob") | |
1116 | eap_connect(dev[0], apdev[0], "TTLS", "chap user", | |
1117 | anonymous_identity="ttls", password="password", | |
1118 | ca_cert="auth_serv/ca.der", phase2="auth=CHAP", | |
1119 | dh_file="blob://dhparams") | |
1120 | ||
7c50093f JM |
1121 | def test_ap_wpa2_eap_reauth(dev, apdev): |
1122 | """WPA2-Enterprise and Authenticator forcing reauthentication""" | |
1123 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1124 | params['eap_reauth_period'] = '2' | |
1125 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1126 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", | |
1127 | password_hex="0123456789abcdef0123456789abcdef") | |
1128 | logger.info("Wait for reauthentication") | |
1129 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10) | |
1130 | if ev is None: | |
1131 | raise Exception("Timeout on reauthentication") | |
1132 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) | |
1133 | if ev is None: | |
1134 | raise Exception("Timeout on reauthentication") | |
1135 | for i in range(0, 20): | |
1136 | state = dev[0].get_status_field("wpa_state") | |
1137 | if state == "COMPLETED": | |
1138 | break | |
1139 | time.sleep(0.1) | |
1140 | if state != "COMPLETED": | |
1141 | raise Exception("Reauthentication did not complete") | |
8b56743e JM |
1142 | |
1143 | def test_ap_wpa2_eap_request_identity_message(dev, apdev): | |
1144 | """Optional displayable message in EAP Request-Identity""" | |
1145 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1146 | params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com' | |
1147 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1148 | eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com", | |
1149 | password_hex="0123456789abcdef0123456789abcdef") | |
910f16ca JM |
1150 | |
1151 | def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev): | |
1152 | """WPA2-Enterprise using EAP-SIM/AKA and protected result indication""" | |
1153 | if not os.path.exists("/tmp/hlr_auc_gw.sock"): | |
1154 | logger.info("No hlr_auc_gw available"); | |
1155 | return "skip" | |
1156 | params = int_eap_server_params() | |
1157 | params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock" | |
1158 | params['eap_sim_aka_result_ind'] = "1" | |
1159 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1160 | ||
1161 | eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", | |
1162 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", | |
1163 | phase1="result_ind=1") | |
1164 | eap_reauth(dev[0], "SIM") | |
1165 | eap_connect(dev[1], apdev[0], "SIM", "1232010000000000", | |
1166 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581") | |
1167 | ||
1168 | dev[0].request("REMOVE_NETWORK all") | |
1169 | dev[1].request("REMOVE_NETWORK all") | |
1170 | ||
1171 | eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", | |
1172 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123", | |
1173 | phase1="result_ind=1") | |
1174 | eap_reauth(dev[0], "AKA") | |
1175 | eap_connect(dev[1], apdev[0], "AKA", "0232010000000000", | |
1176 | password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123") | |
1177 | ||
1178 | dev[0].request("REMOVE_NETWORK all") | |
1179 | dev[1].request("REMOVE_NETWORK all") | |
1180 | ||
1181 | eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", | |
1182 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
1183 | phase1="result_ind=1") | |
1184 | eap_reauth(dev[0], "AKA'") | |
1185 | eap_connect(dev[1], apdev[0], "AKA'", "6555444333222111", | |
1186 | password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123") | |
633e364b JM |
1187 | |
1188 | def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev): | |
1189 | """WPA2-Enterprise connection resulting in too many EAP roundtrips""" | |
1190 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1191 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1192 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1193 | eap="TTLS", identity="mschap user", | |
1194 | wait_connect=False, scan_freq="2412", ieee80211w="1", | |
1195 | anonymous_identity="ttls", password="password", | |
1196 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP", | |
1197 | fragment_size="10") | |
1198 | ev = dev[0].wait_event(["EAP: more than"], timeout=20) | |
1199 | if ev is None: | |
1200 | raise Exception("EAP roundtrip limit not reached") | |
32dca985 JM |
1201 | |
1202 | def test_ap_wpa2_eap_expanded_nak(dev, apdev): | |
1203 | """WPA2-Enterprise connection with EAP resulting in expanded NAK""" | |
1204 | params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") | |
1205 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1206 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256", | |
1207 | eap="PSK", identity="vendor-test", | |
1208 | password_hex="ff23456789abcdef0123456789abcdef", | |
1209 | wait_connect=False) | |
1210 | ||
1211 | found = False | |
1212 | for i in range(0, 5): | |
1213 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=10) | |
1214 | if ev is None: | |
1215 | raise Exception("Association and EAP start timed out") | |
1216 | if "refuse proposed method" in ev: | |
1217 | found = True | |
1218 | break | |
1219 | if not found: | |
1220 | raise Exception("Unexpected EAP status: " + ev) | |
1221 | ||
1222 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"]) | |
1223 | if ev is None: | |
1224 | raise Exception("EAP failure timed out") |