]>
Commit | Line | Data |
---|---|---|
f6f33f8f JM |
1 | # Test cases for sigma_dut |
2 | # Copyright (c) 2017, Qualcomm Atheros, Inc. | |
3 | # | |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
7 | import logging | |
8 | logger = logging.getLogger() | |
9 | import os | |
10 | import socket | |
11 | import subprocess | |
d84c0cf4 | 12 | import threading |
f6f33f8f JM |
13 | import time |
14 | ||
15 | import hostapd | |
16 | from utils import HwsimSkip | |
17 | from hwsim import HWSimRadio | |
d84c0cf4 | 18 | from test_dpp import check_dpp_capab |
002b49ed | 19 | from test_suite_b import check_suite_b_192_capa, suite_b_as_params, suite_b_192_rsa_ap_params |
f6f33f8f JM |
20 | |
21 | def check_sigma_dut(): | |
22 | if not os.path.exists("./sigma_dut"): | |
23 | raise HwsimSkip("sigma_dut not available") | |
24 | ||
d84c0cf4 | 25 | def sigma_dut_cmd(cmd, port=9000, timeout=2): |
f6f33f8f JM |
26 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, |
27 | socket.IPPROTO_TCP) | |
d84c0cf4 | 28 | sock.settimeout(timeout) |
f6f33f8f JM |
29 | addr = ('127.0.0.1', port) |
30 | sock.connect(addr) | |
31 | sock.send(cmd + "\r\n") | |
32 | try: | |
33 | res = sock.recv(1000) | |
34 | running = False | |
35 | done = False | |
36 | for line in res.splitlines(): | |
37 | if line.startswith("status,RUNNING"): | |
38 | running = True | |
39 | elif line.startswith("status,INVALID"): | |
40 | done = True | |
41 | elif line.startswith("status,ERROR"): | |
42 | done = True | |
43 | elif line.startswith("status,COMPLETE"): | |
44 | done = True | |
45 | if running and not done: | |
46 | # Read the actual response | |
47 | res = sock.recv(1000) | |
48 | except: | |
49 | res = '' | |
50 | pass | |
51 | sock.close() | |
52 | res = res.rstrip() | |
53 | logger.debug("sigma_dut: '%s' --> '%s'" % (cmd, res)) | |
54 | return res | |
55 | ||
d84c0cf4 JM |
56 | def sigma_dut_cmd_check(cmd, port=9000, timeout=2): |
57 | res = sigma_dut_cmd(cmd, port=port, timeout=timeout) | |
f6f33f8f JM |
58 | if "COMPLETE" not in res: |
59 | raise Exception("sigma_dut command failed: " + cmd) | |
60 | return res | |
61 | ||
2ef00a36 | 62 | def start_sigma_dut(ifname, debug=False, hostapd_logdir=None, cert_path=None): |
f6f33f8f JM |
63 | check_sigma_dut() |
64 | cmd = [ './sigma_dut', | |
65 | '-M', ifname, | |
66 | '-S', ifname, | |
67 | '-F', '../../hostapd/hostapd', | |
68 | '-G', | |
d84c0cf4 | 69 | '-w', '/var/run/wpa_supplicant/', |
f6f33f8f JM |
70 | '-j', ifname ] |
71 | if debug: | |
72 | cmd += [ '-d' ] | |
2ef00a36 JM |
73 | if hostapd_logdir: |
74 | cmd += [ '-H', hostapd_logdir ] | |
75 | if cert_path: | |
76 | cmd += [ '-C', cert_path ] | |
f6f33f8f JM |
77 | sigma = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
78 | stderr=subprocess.PIPE) | |
79 | for i in range(20): | |
80 | try: | |
81 | res = sigma_dut_cmd("HELLO") | |
82 | break | |
83 | except: | |
84 | time.sleep(0.05) | |
85 | return sigma | |
86 | ||
87 | def stop_sigma_dut(sigma): | |
88 | sigma.terminate() | |
89 | sigma.wait() | |
90 | out, err = sigma.communicate() | |
91 | logger.debug("sigma_dut stdout: " + str(out)) | |
92 | logger.debug("sigma_dut stderr: " + str(err)) | |
93 | ||
94 | def sigma_dut_wait_connected(ifname): | |
95 | for i in range(50): | |
96 | res = sigma_dut_cmd("sta_is_connected,interface," + ifname) | |
97 | if "connected,1" in res: | |
98 | break | |
99 | time.sleep(0.2) | |
100 | if i == 49: | |
101 | raise Exception("Connection did not complete") | |
102 | ||
103 | def test_sigma_dut_basic(dev, apdev): | |
104 | """sigma_dut basic functionality""" | |
105 | sigma = start_sigma_dut(dev[0].ifname) | |
106 | ||
107 | res = sigma_dut_cmd("UNKNOWN") | |
108 | if "status,INVALID,errorCode,Unknown command" not in res: | |
109 | raise Exception("Unexpected sigma_dut response to unknown command") | |
110 | ||
111 | tests = [ ("ca_get_version", "status,COMPLETE,version,1.0"), | |
112 | ("device_get_info", "status,COMPLETE,vendor"), | |
113 | ("device_list_interfaces,interfaceType,foo", "status,ERROR"), | |
114 | ("device_list_interfaces,interfaceType,802.11", | |
115 | "status,COMPLETE,interfaceType,802.11,interfaceID," + dev[0].ifname) ] | |
116 | for cmd, response in tests: | |
117 | res = sigma_dut_cmd(cmd) | |
118 | if response not in res: | |
119 | raise Exception("Unexpected %s response: %s" % (cmd, res)) | |
120 | ||
121 | stop_sigma_dut(sigma) | |
122 | ||
123 | def test_sigma_dut_open(dev, apdev): | |
124 | """sigma_dut controlled open network association""" | |
65fa9d96 JM |
125 | try: |
126 | run_sigma_dut_open(dev, apdev) | |
127 | finally: | |
128 | dev[0].set("ignore_old_scan_res", "0") | |
129 | ||
130 | def run_sigma_dut_open(dev, apdev): | |
f6f33f8f JM |
131 | ifname = dev[0].ifname |
132 | sigma = start_sigma_dut(ifname) | |
133 | ||
134 | hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) | |
135 | ||
136 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
137 | sigma_dut_cmd_check("sta_set_encryption,interface,%s,ssid,%s,encpType,none" % (ifname, "open")) | |
138 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "open")) | |
139 | sigma_dut_wait_connected(ifname) | |
140 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
141 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
142 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
143 | ||
144 | stop_sigma_dut(sigma) | |
145 | ||
146 | def test_sigma_dut_psk_pmf(dev, apdev): | |
147 | """sigma_dut controlled PSK+PMF association""" | |
65fa9d96 JM |
148 | try: |
149 | run_sigma_dut_psk_pmf(dev, apdev) | |
150 | finally: | |
151 | dev[0].set("ignore_old_scan_res", "0") | |
152 | ||
153 | def run_sigma_dut_psk_pmf(dev, apdev): | |
f6f33f8f JM |
154 | ifname = dev[0].ifname |
155 | sigma = start_sigma_dut(ifname) | |
156 | ||
157 | ssid = "test-pmf-required" | |
158 | params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") | |
159 | params["wpa_key_mgmt"] = "WPA-PSK-SHA256" | |
160 | params["ieee80211w"] = "2" | |
161 | hapd = hostapd.add_ap(apdev[0], params) | |
162 | ||
163 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname) | |
164 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
165 | sigma_dut_cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required" % (ifname, "test-pmf-required", "12345678")) | |
166 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required")) | |
167 | sigma_dut_wait_connected(ifname) | |
168 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
169 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
170 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
171 | ||
172 | stop_sigma_dut(sigma) | |
173 | ||
8cfdca12 JM |
174 | def test_sigma_dut_psk_pmf_bip_cmac_128(dev, apdev): |
175 | """sigma_dut controlled PSK+PMF association with BIP-CMAC-128""" | |
176 | try: | |
177 | run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-CMAC-128", "AES-128-CMAC") | |
178 | finally: | |
179 | dev[0].set("ignore_old_scan_res", "0") | |
180 | ||
181 | def test_sigma_dut_psk_pmf_bip_cmac_256(dev, apdev): | |
182 | """sigma_dut controlled PSK+PMF association with BIP-CMAC-256""" | |
183 | try: | |
184 | run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-CMAC-256", "BIP-CMAC-256") | |
185 | finally: | |
186 | dev[0].set("ignore_old_scan_res", "0") | |
187 | ||
188 | def test_sigma_dut_psk_pmf_bip_gmac_128(dev, apdev): | |
189 | """sigma_dut controlled PSK+PMF association with BIP-GMAC-128""" | |
190 | try: | |
191 | run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-GMAC-128", "BIP-GMAC-128") | |
192 | finally: | |
193 | dev[0].set("ignore_old_scan_res", "0") | |
194 | ||
195 | def test_sigma_dut_psk_pmf_bip_gmac_256(dev, apdev): | |
196 | """sigma_dut controlled PSK+PMF association with BIP-GMAC-256""" | |
197 | try: | |
198 | run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-GMAC-256", "BIP-GMAC-256") | |
199 | finally: | |
200 | dev[0].set("ignore_old_scan_res", "0") | |
201 | ||
202 | def test_sigma_dut_psk_pmf_bip_gmac_256_mismatch(dev, apdev): | |
203 | """sigma_dut controlled PSK+PMF association with BIP-GMAC-256 mismatch""" | |
204 | try: | |
205 | run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-GMAC-256", "AES-128-CMAC", | |
206 | failure=True) | |
207 | finally: | |
208 | dev[0].set("ignore_old_scan_res", "0") | |
209 | ||
210 | def run_sigma_dut_psk_pmf_cipher(dev, apdev, sigma_cipher, hostapd_cipher, | |
211 | failure=False): | |
212 | ifname = dev[0].ifname | |
213 | sigma = start_sigma_dut(ifname) | |
214 | ||
215 | ssid = "test-pmf-required" | |
216 | params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") | |
217 | params["wpa_key_mgmt"] = "WPA-PSK-SHA256" | |
218 | params["ieee80211w"] = "2" | |
219 | params["group_mgmt_cipher"] = hostapd_cipher | |
220 | hapd = hostapd.add_ap(apdev[0], params) | |
221 | ||
222 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname) | |
223 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
224 | sigma_dut_cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required,GroupMgntCipher,%s" % (ifname, "test-pmf-required", "12345678", sigma_cipher)) | |
225 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required")) | |
226 | if failure: | |
227 | ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND", | |
228 | "CTRL-EVENT-CONNECTED"], timeout=10) | |
229 | if ev is None: | |
230 | raise Exception("Network selection result not indicated") | |
231 | if "CTRL-EVENT-CONNECTED" in ev: | |
232 | raise Exception("Unexpected connection") | |
233 | res = sigma_dut_cmd("sta_is_connected,interface," + ifname) | |
234 | if "connected,1" in res: | |
235 | raise Exception("Connection reported") | |
236 | else: | |
237 | sigma_dut_wait_connected(ifname) | |
238 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
239 | ||
240 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
241 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
242 | ||
243 | stop_sigma_dut(sigma) | |
244 | ||
1ed508d9 JM |
245 | def test_sigma_dut_sae(dev, apdev): |
246 | """sigma_dut controlled SAE association""" | |
247 | if "SAE" not in dev[0].get_capability("auth_alg"): | |
248 | raise HwsimSkip("SAE not supported") | |
249 | ||
250 | ifname = dev[0].ifname | |
251 | sigma = start_sigma_dut(ifname) | |
252 | ||
253 | ssid = "test-sae" | |
254 | params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") | |
255 | params['wpa_key_mgmt'] = 'SAE' | |
256 | hapd = hostapd.add_ap(apdev[0], params) | |
257 | ||
258 | sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname) | |
259 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
260 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678")) | |
261 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae")) | |
262 | sigma_dut_wait_connected(ifname) | |
263 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
264 | if dev[0].get_status_field('sae_group') != '19': | |
265 | raise Exception("Expected default SAE group not used") | |
266 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
267 | ||
268 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
269 | ||
270 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
271 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,ECGroupID,20" % (ifname, "test-sae", "12345678")) | |
272 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae")) | |
273 | sigma_dut_wait_connected(ifname) | |
274 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
275 | if dev[0].get_status_field('sae_group') != '20': | |
276 | raise Exception("Expected SAE group not used") | |
277 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
278 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
279 | ||
280 | stop_sigma_dut(sigma) | |
281 | ||
6644069c JM |
282 | def test_sigma_dut_sae_password(dev, apdev): |
283 | """sigma_dut controlled SAE association and long password""" | |
284 | if "SAE" not in dev[0].get_capability("auth_alg"): | |
285 | raise HwsimSkip("SAE not supported") | |
286 | ||
287 | ifname = dev[0].ifname | |
288 | sigma = start_sigma_dut(ifname) | |
289 | ||
290 | try: | |
291 | ssid = "test-sae" | |
292 | params = hostapd.wpa2_params(ssid=ssid) | |
293 | params['sae_password'] = 100*'B' | |
294 | params['wpa_key_mgmt'] = 'SAE' | |
295 | hapd = hostapd.add_ap(apdev[0], params) | |
296 | ||
297 | sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname) | |
298 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
299 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", 100*'B')) | |
300 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae")) | |
301 | sigma_dut_wait_connected(ifname) | |
302 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
303 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
304 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
305 | finally: | |
306 | stop_sigma_dut(sigma) | |
307 | ||
f6f33f8f JM |
308 | def test_sigma_dut_sta_override_rsne(dev, apdev): |
309 | """sigma_dut and RSNE override on STA""" | |
65fa9d96 JM |
310 | try: |
311 | run_sigma_dut_sta_override_rsne(dev, apdev) | |
312 | finally: | |
313 | dev[0].set("ignore_old_scan_res", "0") | |
314 | ||
315 | def run_sigma_dut_sta_override_rsne(dev, apdev): | |
f6f33f8f JM |
316 | ifname = dev[0].ifname |
317 | sigma = start_sigma_dut(ifname) | |
318 | ||
319 | ssid = "test-psk" | |
320 | params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") | |
321 | hapd = hostapd.add_ap(apdev[0], params) | |
322 | ||
323 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
324 | ||
325 | tests = [ "30120100000fac040100000fac040100000fac02", | |
326 | "30140100000fac040100000fac040100000fac02ffff" ] | |
327 | for test in tests: | |
328 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678")) | |
329 | sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,%s" % (ifname, test)) | |
330 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk")) | |
331 | sigma_dut_wait_connected(ifname) | |
332 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
333 | dev[0].dump_monitor() | |
334 | ||
335 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678")) | |
336 | sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,300101" % ifname) | |
337 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk")) | |
338 | ||
339 | ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"]) | |
340 | if ev is None: | |
341 | raise Exception("Association rejection not reported") | |
342 | if "status_code=40" not in ev: | |
343 | raise Exception("Unexpected status code: " + ev) | |
344 | ||
345 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
346 | ||
347 | stop_sigma_dut(sigma) | |
348 | ||
349 | def test_sigma_dut_ap_psk(dev, apdev): | |
350 | """sigma_dut controlled AP""" | |
351 | with HWSimRadio() as (radio, iface): | |
352 | sigma = start_sigma_dut(iface) | |
353 | try: | |
354 | sigma_dut_cmd_check("ap_reset_default") | |
355 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng") | |
356 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678") | |
357 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
358 | ||
359 | dev[0].connect("test-psk", psk="12345678", scan_freq="2412") | |
360 | ||
361 | sigma_dut_cmd_check("ap_reset_default") | |
362 | finally: | |
363 | stop_sigma_dut(sigma) | |
364 | ||
2ef00a36 JM |
365 | def test_sigma_dut_suite_b(dev, apdev, params): |
366 | """sigma_dut controlled STA Suite B""" | |
367 | check_suite_b_192_capa(dev) | |
368 | logdir = params['logdir'] | |
369 | ||
370 | with open("auth_serv/ec2-ca.pem", "r") as f: | |
371 | with open(os.path.join(logdir, "suite_b_ca.pem"), "w") as f2: | |
372 | f2.write(f.read()) | |
373 | ||
374 | with open("auth_serv/ec2-user.pem", "r") as f: | |
375 | with open("auth_serv/ec2-user.key", "r") as f2: | |
376 | with open(os.path.join(logdir, "suite_b.pem"), "w") as f3: | |
377 | f3.write(f.read()) | |
378 | f3.write(f2.read()) | |
379 | ||
380 | dev[0].flush_scan_cache() | |
381 | params = suite_b_as_params() | |
382 | params['ca_cert'] = 'auth_serv/ec2-ca.pem' | |
383 | params['server_cert'] = 'auth_serv/ec2-server.pem' | |
384 | params['private_key'] = 'auth_serv/ec2-server.key' | |
385 | params['openssl_ciphers'] = 'SUITEB192' | |
386 | hostapd.add_ap(apdev[1], params) | |
387 | ||
388 | params = { "ssid": "test-suite-b", | |
389 | "wpa": "2", | |
390 | "wpa_key_mgmt": "WPA-EAP-SUITE-B-192", | |
391 | "rsn_pairwise": "GCMP-256", | |
392 | "group_mgmt_cipher": "BIP-GMAC-256", | |
393 | "ieee80211w": "2", | |
394 | "ieee8021x": "1", | |
395 | 'auth_server_addr': "127.0.0.1", | |
396 | 'auth_server_port': "18129", | |
397 | 'auth_server_shared_secret': "radius", | |
398 | 'nas_identifier': "nas.w1.fi" } | |
399 | hapd = hostapd.add_ap(apdev[0], params) | |
400 | ||
401 | ifname = dev[0].ifname | |
402 | sigma = start_sigma_dut(ifname, cert_path=logdir) | |
403 | ||
404 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname) | |
405 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
002b49ed | 406 | sigma_dut_cmd_check("sta_set_security,type,eaptls,interface,%s,ssid,%s,PairwiseCipher,AES-GCMP-256,GroupCipher,AES-GCMP-256,GroupMgntCipher,BIP-GMAC-256,keymgmttype,SuiteB,PMF,Required,clientCertificate,suite_b.pem,trustedRootCA,suite_b_ca.pem,CertType,ECC" % (ifname, "test-suite-b")) |
2ef00a36 JM |
407 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b")) |
408 | sigma_dut_wait_connected(ifname) | |
409 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
410 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
411 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
412 | ||
413 | stop_sigma_dut(sigma) | |
414 | ||
002b49ed JM |
415 | def test_sigma_dut_suite_b_rsa(dev, apdev, params): |
416 | """sigma_dut controlled STA Suite B (RSA)""" | |
417 | check_suite_b_192_capa(dev) | |
418 | logdir = params['logdir'] | |
419 | ||
420 | with open("auth_serv/rsa3072-ca.pem", "r") as f: | |
421 | with open(os.path.join(logdir, "suite_b_ca_rsa.pem"), "w") as f2: | |
422 | f2.write(f.read()) | |
423 | ||
424 | with open("auth_serv/rsa3072-user.pem", "r") as f: | |
425 | with open("auth_serv/rsa3072-user.key", "r") as f2: | |
426 | with open(os.path.join(logdir, "suite_b_rsa.pem"), "w") as f3: | |
427 | f3.write(f.read()) | |
428 | f3.write(f2.read()) | |
429 | ||
430 | dev[0].flush_scan_cache() | |
431 | params = suite_b_192_rsa_ap_params() | |
432 | hapd = hostapd.add_ap(apdev[0], params) | |
433 | ||
434 | ifname = dev[0].ifname | |
435 | sigma = start_sigma_dut(ifname, cert_path=logdir) | |
436 | ||
437 | cmd = "sta_set_security,type,eaptls,interface,%s,ssid,%s,PairwiseCipher,AES-GCMP-256,GroupCipher,AES-GCMP-256,GroupMgntCipher,BIP-GMAC-256,keymgmttype,SuiteB,PMF,Required,clientCertificate,suite_b_rsa.pem,trustedRootCA,suite_b_ca_rsa.pem,CertType,RSA" % (ifname, "test-suite-b") | |
438 | ||
439 | tests = [ "", | |
440 | ",TLSCipher,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", | |
441 | ",TLSCipher,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" ] | |
442 | for extra in tests: | |
443 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname) | |
444 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
445 | sigma_dut_cmd_check(cmd + extra) | |
446 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b")) | |
447 | sigma_dut_wait_connected(ifname) | |
448 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
449 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
450 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
451 | ||
452 | stop_sigma_dut(sigma) | |
453 | ||
2ef00a36 JM |
454 | def test_sigma_dut_ap_suite_b(dev, apdev, params): |
455 | """sigma_dut controlled AP Suite B""" | |
456 | check_suite_b_192_capa(dev) | |
457 | logdir = os.path.join(params['logdir'], | |
458 | "sigma_dut_ap_suite_b.sigma-hostapd") | |
459 | params = suite_b_as_params() | |
460 | params['ca_cert'] = 'auth_serv/ec2-ca.pem' | |
461 | params['server_cert'] = 'auth_serv/ec2-server.pem' | |
462 | params['private_key'] = 'auth_serv/ec2-server.key' | |
463 | params['openssl_ciphers'] = 'SUITEB192' | |
464 | hostapd.add_ap(apdev[1], params) | |
465 | with HWSimRadio() as (radio, iface): | |
466 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
467 | try: | |
468 | sigma_dut_cmd_check("ap_reset_default") | |
469 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng") | |
470 | sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius") | |
471 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required") | |
472 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
473 | ||
474 | dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192", | |
475 | ieee80211w="2", | |
476 | openssl_ciphers="SUITEB192", | |
477 | eap="TLS", identity="tls user", | |
478 | ca_cert="auth_serv/ec2-ca.pem", | |
479 | client_cert="auth_serv/ec2-user.pem", | |
480 | private_key="auth_serv/ec2-user.key", | |
481 | pairwise="GCMP-256", group="GCMP-256", | |
482 | scan_freq="2412") | |
483 | ||
484 | sigma_dut_cmd_check("ap_reset_default") | |
485 | finally: | |
486 | stop_sigma_dut(sigma) | |
487 | ||
488 | def test_sigma_dut_ap_cipher_gcmp_128(dev, apdev, params): | |
489 | """sigma_dut controlled AP with GCMP-128/BIP-GMAC-128 cipher""" | |
490 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-128", "BIP-GMAC-128", | |
491 | "GCMP") | |
492 | ||
493 | def test_sigma_dut_ap_cipher_gcmp_256(dev, apdev, params): | |
494 | """sigma_dut controlled AP with GCMP-256/BIP-GMAC-256 cipher""" | |
495 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-256", "BIP-GMAC-256", | |
496 | "GCMP-256") | |
497 | ||
498 | def test_sigma_dut_ap_cipher_ccmp_128(dev, apdev, params): | |
499 | """sigma_dut controlled AP with CCMP-128/BIP-CMAC-128 cipher""" | |
500 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128", "BIP-CMAC-128", | |
501 | "CCMP") | |
502 | ||
503 | def test_sigma_dut_ap_cipher_ccmp_256(dev, apdev, params): | |
504 | """sigma_dut controlled AP with CCMP-256/BIP-CMAC-256 cipher""" | |
505 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-256", "BIP-CMAC-256", | |
506 | "CCMP-256") | |
507 | ||
508 | def run_sigma_dut_ap_cipher(dev, apdev, params, ap_pairwise, ap_group_mgmt, | |
509 | sta_cipher): | |
510 | check_suite_b_192_capa(dev) | |
511 | logdir = os.path.join(params['logdir'], | |
512 | "sigma_dut_ap_cipher.sigma-hostapd") | |
513 | params = suite_b_as_params() | |
514 | params['ca_cert'] = 'auth_serv/ec2-ca.pem' | |
515 | params['server_cert'] = 'auth_serv/ec2-server.pem' | |
516 | params['private_key'] = 'auth_serv/ec2-server.key' | |
517 | params['openssl_ciphers'] = 'SUITEB192' | |
518 | hostapd.add_ap(apdev[1], params) | |
519 | with HWSimRadio() as (radio, iface): | |
520 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
521 | try: | |
522 | sigma_dut_cmd_check("ap_reset_default") | |
523 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng") | |
524 | sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius") | |
525 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required,PairwiseCipher,%s,GroupMgntCipher,%s" % (ap_pairwise, ap_group_mgmt)) | |
526 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
527 | ||
528 | dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192", | |
529 | ieee80211w="2", | |
530 | openssl_ciphers="SUITEB192", | |
531 | eap="TLS", identity="tls user", | |
532 | ca_cert="auth_serv/ec2-ca.pem", | |
533 | client_cert="auth_serv/ec2-user.pem", | |
534 | private_key="auth_serv/ec2-user.key", | |
535 | pairwise=sta_cipher, group=sta_cipher, | |
536 | scan_freq="2412") | |
537 | ||
538 | sigma_dut_cmd_check("ap_reset_default") | |
539 | finally: | |
540 | stop_sigma_dut(sigma) | |
541 | ||
f6f33f8f JM |
542 | def test_sigma_dut_ap_override_rsne(dev, apdev): |
543 | """sigma_dut controlled AP overriding RSNE""" | |
544 | with HWSimRadio() as (radio, iface): | |
545 | sigma = start_sigma_dut(iface) | |
546 | try: | |
547 | sigma_dut_cmd_check("ap_reset_default") | |
548 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng") | |
549 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678") | |
550 | sigma_dut_cmd_check("dev_configure_ie,NAME,AP,interface,%s,IE_Name,RSNE,Contents,30180100000fac040200ffffffff000fac040100000fac020c00" % iface) | |
551 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
552 | ||
553 | dev[0].connect("test-psk", psk="12345678", scan_freq="2412") | |
554 | ||
555 | sigma_dut_cmd_check("ap_reset_default") | |
556 | finally: | |
557 | stop_sigma_dut(sigma) | |
1ed508d9 JM |
558 | |
559 | def test_sigma_dut_ap_sae(dev, apdev): | |
560 | """sigma_dut controlled AP with SAE""" | |
561 | with HWSimRadio() as (radio, iface): | |
562 | sigma = start_sigma_dut(iface) | |
563 | try: | |
564 | sigma_dut_cmd_check("ap_reset_default") | |
565 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") | |
566 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678") | |
567 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
568 | ||
569 | dev[0].request("SET sae_groups ") | |
570 | dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678", | |
571 | scan_freq="2412") | |
572 | if dev[0].get_status_field('sae_group') != '19': | |
573 | raise Exception("Expected default SAE group not used") | |
574 | ||
575 | sigma_dut_cmd_check("ap_reset_default") | |
6644069c JM |
576 | finally: |
577 | stop_sigma_dut(sigma) | |
578 | ||
579 | def test_sigma_dut_ap_sae_password(dev, apdev): | |
580 | """sigma_dut controlled AP with SAE and long password""" | |
581 | with HWSimRadio() as (radio, iface): | |
582 | sigma = start_sigma_dut(iface) | |
583 | try: | |
584 | sigma_dut_cmd_check("ap_reset_default") | |
585 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") | |
586 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK," + 100*'C') | |
587 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
588 | ||
589 | dev[0].request("SET sae_groups ") | |
590 | dev[0].connect("test-sae", key_mgmt="SAE", sae_password=100*'C', | |
591 | scan_freq="2412") | |
592 | if dev[0].get_status_field('sae_group') != '19': | |
593 | raise Exception("Expected default SAE group not used") | |
594 | ||
595 | sigma_dut_cmd_check("ap_reset_default") | |
1ed508d9 JM |
596 | finally: |
597 | stop_sigma_dut(sigma) | |
598 | ||
599 | def test_sigma_dut_ap_sae_group(dev, apdev): | |
600 | """sigma_dut controlled AP with SAE and specific group""" | |
601 | with HWSimRadio() as (radio, iface): | |
602 | sigma = start_sigma_dut(iface) | |
603 | try: | |
604 | sigma_dut_cmd_check("ap_reset_default") | |
605 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") | |
606 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20") | |
607 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
608 | ||
609 | dev[0].request("SET sae_groups ") | |
610 | dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678", | |
611 | scan_freq="2412") | |
612 | if dev[0].get_status_field('sae_group') != '20': | |
613 | raise Exception("Expected SAE group not used") | |
614 | ||
615 | sigma_dut_cmd_check("ap_reset_default") | |
616 | finally: | |
617 | stop_sigma_dut(sigma) | |
618 | ||
619 | def test_sigma_dut_ap_psk_sae(dev, apdev): | |
620 | """sigma_dut controlled AP with PSK+SAE""" | |
621 | with HWSimRadio() as (radio, iface): | |
622 | sigma = start_sigma_dut(iface) | |
623 | try: | |
624 | sigma_dut_cmd_check("ap_reset_default") | |
625 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") | |
626 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678") | |
627 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
628 | ||
629 | dev[0].request("SET sae_groups ") | |
630 | dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678", | |
631 | scan_freq="2412") | |
632 | dev[1].connect("test-sae", psk="12345678", scan_freq="2412") | |
633 | ||
634 | sigma_dut_cmd_check("ap_reset_default") | |
635 | finally: | |
636 | stop_sigma_dut(sigma) | |
b9c0e1fa JM |
637 | |
638 | def test_sigma_dut_owe(dev, apdev): | |
639 | """sigma_dut controlled OWE station""" | |
640 | try: | |
641 | run_sigma_dut_owe(dev, apdev) | |
642 | finally: | |
643 | dev[0].set("ignore_old_scan_res", "0") | |
644 | ||
645 | def run_sigma_dut_owe(dev, apdev): | |
646 | if "OWE" not in dev[0].get_capability("key_mgmt"): | |
647 | raise HwsimSkip("OWE not supported") | |
648 | ||
649 | ifname = dev[0].ifname | |
650 | sigma = start_sigma_dut(ifname) | |
651 | ||
652 | try: | |
653 | params = { "ssid": "owe", | |
654 | "wpa": "2", | |
655 | "wpa_key_mgmt": "OWE", | |
656 | "rsn_pairwise": "CCMP" } | |
657 | hapd = hostapd.add_ap(apdev[0], params) | |
658 | bssid = hapd.own_addr() | |
659 | ||
660 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname) | |
661 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
662 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname) | |
663 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname) | |
664 | sigma_dut_wait_connected(ifname) | |
665 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
666 | ||
667 | dev[0].dump_monitor() | |
668 | sigma_dut_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid)) | |
669 | dev[0].wait_connected() | |
670 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
671 | dev[0].wait_disconnected() | |
672 | dev[0].dump_monitor() | |
673 | ||
674 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname) | |
675 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
676 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname) | |
677 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname) | |
678 | sigma_dut_wait_connected(ifname) | |
679 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
e30de6c2 JM |
680 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) |
681 | dev[0].wait_disconnected() | |
682 | dev[0].dump_monitor() | |
683 | ||
684 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname) | |
685 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
686 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname) | |
687 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname) | |
688 | ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10) | |
689 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
690 | if ev is None: | |
691 | raise Exception("Association not rejected") | |
692 | if "status_code=77" not in ev: | |
693 | raise Exception("Unexpected rejection reason: " + ev) | |
b9c0e1fa JM |
694 | |
695 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
696 | finally: | |
697 | stop_sigma_dut(sigma) | |
698 | ||
699 | def test_sigma_dut_ap_owe(dev, apdev): | |
700 | """sigma_dut controlled AP with OWE""" | |
701 | if "OWE" not in dev[0].get_capability("key_mgmt"): | |
702 | raise HwsimSkip("OWE not supported") | |
703 | with HWSimRadio() as (radio, iface): | |
704 | sigma = start_sigma_dut(iface) | |
705 | try: | |
706 | sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3") | |
707 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng") | |
708 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE") | |
709 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
710 | ||
b9c0e1fa JM |
711 | dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412") |
712 | ||
713 | sigma_dut_cmd_check("ap_reset_default") | |
714 | finally: | |
715 | stop_sigma_dut(sigma) | |
7f811be5 JM |
716 | |
717 | def test_sigma_dut_ap_owe_ecgroupid(dev, apdev): | |
718 | """sigma_dut controlled AP with OWE and ECGroupID""" | |
719 | if "OWE" not in dev[0].get_capability("key_mgmt"): | |
720 | raise HwsimSkip("OWE not supported") | |
721 | with HWSimRadio() as (radio, iface): | |
722 | sigma = start_sigma_dut(iface) | |
723 | try: | |
724 | sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3") | |
725 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng") | |
726 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required") | |
727 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
728 | ||
729 | dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2", | |
730 | owe_group="20", scan_freq="2412") | |
731 | dev[0].request("REMOVE_NETWORK all") | |
732 | dev[0].wait_disconnected() | |
733 | ||
734 | dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2", | |
735 | owe_group="21", scan_freq="2412") | |
736 | dev[0].request("REMOVE_NETWORK all") | |
737 | dev[0].wait_disconnected() | |
738 | ||
739 | dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2", | |
740 | owe_group="19", scan_freq="2412", wait_connect=False) | |
741 | ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10) | |
742 | dev[0].request("DISCONNECT") | |
743 | if ev is None: | |
744 | raise Exception("Association not rejected") | |
745 | if "status_code=77" not in ev: | |
746 | raise Exception("Unexpected rejection reason: " + ev) | |
747 | dev[0].dump_monitor() | |
748 | ||
749 | sigma_dut_cmd_check("ap_reset_default") | |
750 | finally: | |
751 | stop_sigma_dut(sigma) | |
86fd7d70 JM |
752 | |
753 | def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params): | |
754 | """sigma_dut controlled AP with OWE and transition mode""" | |
755 | if "OWE" not in dev[0].get_capability("key_mgmt"): | |
756 | raise HwsimSkip("OWE not supported") | |
757 | logdir = os.path.join(params['logdir'], | |
758 | "sigma_dut_ap_owe_transition_mode.sigma-hostapd") | |
759 | with HWSimRadio() as (radio, iface): | |
760 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
761 | try: | |
762 | sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3") | |
763 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng") | |
764 | sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE") | |
765 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng") | |
766 | sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE") | |
767 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
768 | ||
89c343e8 JM |
769 | res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G") |
770 | res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G") | |
771 | ||
86fd7d70 JM |
772 | dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412") |
773 | dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412") | |
89c343e8 JM |
774 | if dev[0].get_status_field('bssid') not in res1: |
775 | raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res1) | |
776 | if dev[1].get_status_field('bssid') not in res2: | |
777 | raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res2) | |
86fd7d70 JM |
778 | |
779 | sigma_dut_cmd_check("ap_reset_default") | |
780 | finally: | |
781 | stop_sigma_dut(sigma) | |
d84c0cf4 JM |
782 | |
783 | def dpp_init_enrollee(dev, id1): | |
784 | logger.info("Starting DPP initiator/enrollee in a thread") | |
785 | time.sleep(1) | |
786 | cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1 | |
787 | if "OK" not in dev.request(cmd): | |
788 | raise Exception("Failed to initiate DPP Authentication") | |
789 | ev = dev.wait_event(["DPP-CONF-RECEIVED"], timeout=5) | |
790 | if ev is None: | |
791 | raise Exception("DPP configuration not completed (Enrollee)") | |
792 | logger.info("DPP initiator/enrollee done") | |
793 | ||
794 | def test_sigma_dut_dpp_qr_resp_1(dev, apdev): | |
795 | """sigma_dut DPP/QR responder (conf index 1)""" | |
796 | run_sigma_dut_dpp_qr_resp(dev, apdev, 1) | |
797 | ||
798 | def test_sigma_dut_dpp_qr_resp_2(dev, apdev): | |
799 | """sigma_dut DPP/QR responder (conf index 2)""" | |
800 | run_sigma_dut_dpp_qr_resp(dev, apdev, 2) | |
801 | ||
802 | def test_sigma_dut_dpp_qr_resp_3(dev, apdev): | |
803 | """sigma_dut DPP/QR responder (conf index 3)""" | |
804 | run_sigma_dut_dpp_qr_resp(dev, apdev, 3) | |
805 | ||
806 | def test_sigma_dut_dpp_qr_resp_4(dev, apdev): | |
807 | """sigma_dut DPP/QR responder (conf index 4)""" | |
808 | run_sigma_dut_dpp_qr_resp(dev, apdev, 4) | |
809 | ||
810 | def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx): | |
811 | check_dpp_capab(dev[0]) | |
812 | check_dpp_capab(dev[1]) | |
813 | sigma = start_sigma_dut(dev[0].ifname) | |
814 | try: | |
815 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") | |
816 | if "status,COMPLETE" not in res: | |
817 | raise Exception("dev_exec_action did not succeed: " + res) | |
818 | hex = res.split(',')[3] | |
819 | uri = hex.decode('hex') | |
820 | logger.info("URI from sigma_dut: " + uri) | |
821 | ||
822 | res = dev[1].request("DPP_QR_CODE " + uri) | |
823 | if "FAIL" in res: | |
824 | raise Exception("Failed to parse QR Code URI") | |
825 | id1 = int(res) | |
826 | ||
827 | t = threading.Thread(target=dpp_init_enrollee, args=(dev[1], id1)) | |
828 | t.start() | |
829 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPConfIndex,%d,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfigEnrolleeRole,STA,DPPSigningKeyECC,P-256,DPPConfigEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6" % conf_idx, timeout=10) | |
830 | t.join() | |
831 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: | |
832 | raise Exception("Unexpected result: " + res) | |
833 | finally: | |
834 | stop_sigma_dut(sigma) | |
835 | ||
836 | def test_sigma_dut_dpp_qr_init_enrollee(dev, apdev): | |
837 | """sigma_dut DPP/QR initiator as Enrollee""" | |
838 | check_dpp_capab(dev[0]) | |
839 | check_dpp_capab(dev[1]) | |
840 | ||
841 | csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
842 | csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
843 | ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg" | |
844 | ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b" | |
845 | ||
846 | params = { "ssid": "DPPNET01", | |
847 | "wpa": "2", | |
848 | "wpa_key_mgmt": "DPP", | |
849 | "rsn_pairwise": "CCMP", | |
850 | "dpp_connector": ap_connector, | |
851 | "dpp_csign": csign_pub, | |
852 | "dpp_netaccesskey": ap_netaccesskey } | |
853 | try: | |
854 | hapd = hostapd.add_ap(apdev[0], params) | |
855 | except: | |
856 | raise HwsimSkip("DPP not supported") | |
857 | ||
858 | sigma = start_sigma_dut(dev[0].ifname) | |
859 | try: | |
860 | dev[0].set("dpp_config_processing", "2") | |
861 | ||
862 | cmd = "DPP_CONFIGURATOR_ADD key=" + csign | |
863 | res = dev[1].request(cmd); | |
864 | if "FAIL" in res: | |
865 | raise Exception("Failed to add configurator") | |
866 | conf_id = int(res) | |
867 | ||
868 | addr = dev[1].own_addr().replace(':', '') | |
869 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
870 | res = dev[1].request(cmd) | |
871 | if "FAIL" in res: | |
872 | raise Exception("Failed to generate bootstrapping info") | |
873 | id0 = int(res) | |
874 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
875 | ||
876 | dev[1].set("dpp_configurator_params", | |
877 | " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id)); | |
878 | cmd = "DPP_LISTEN 2437 role=configurator" | |
879 | if "OK" not in dev[1].request(cmd): | |
880 | raise Exception("Failed to start listen operation") | |
881 | ||
882 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
883 | if "status,COMPLETE" not in res: | |
884 | raise Exception("dev_exec_action did not succeed: " + res) | |
885 | ||
886 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10) | |
887 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res: | |
888 | raise Exception("Unexpected result: " + res) | |
889 | finally: | |
890 | dev[0].set("dpp_config_processing", "0") | |
891 | stop_sigma_dut(sigma) | |
892 | ||
893 | def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev): | |
894 | """sigma_dut DPP/QR (mutual) initiator as Enrollee""" | |
895 | check_dpp_capab(dev[0]) | |
896 | check_dpp_capab(dev[1]) | |
897 | ||
898 | csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
899 | csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
900 | ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg" | |
901 | ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b" | |
902 | ||
903 | params = { "ssid": "DPPNET01", | |
904 | "wpa": "2", | |
905 | "wpa_key_mgmt": "DPP", | |
906 | "rsn_pairwise": "CCMP", | |
907 | "dpp_connector": ap_connector, | |
908 | "dpp_csign": csign_pub, | |
909 | "dpp_netaccesskey": ap_netaccesskey } | |
910 | try: | |
911 | hapd = hostapd.add_ap(apdev[0], params) | |
912 | except: | |
913 | raise HwsimSkip("DPP not supported") | |
914 | ||
915 | sigma = start_sigma_dut(dev[0].ifname) | |
916 | try: | |
917 | dev[0].set("dpp_config_processing", "2") | |
918 | ||
919 | cmd = "DPP_CONFIGURATOR_ADD key=" + csign | |
920 | res = dev[1].request(cmd); | |
921 | if "FAIL" in res: | |
922 | raise Exception("Failed to add configurator") | |
923 | conf_id = int(res) | |
924 | ||
925 | addr = dev[1].own_addr().replace(':', '') | |
926 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
927 | res = dev[1].request(cmd) | |
928 | if "FAIL" in res: | |
929 | raise Exception("Failed to generate bootstrapping info") | |
930 | id0 = int(res) | |
931 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
932 | ||
933 | dev[1].set("dpp_configurator_params", | |
934 | " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id)); | |
935 | cmd = "DPP_LISTEN 2437 role=configurator qr=mutual" | |
936 | if "OK" not in dev[1].request(cmd): | |
937 | raise Exception("Failed to start listen operation") | |
938 | ||
939 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") | |
940 | if "status,COMPLETE" not in res: | |
941 | raise Exception("dev_exec_action did not succeed: " + res) | |
942 | hex = res.split(',')[3] | |
943 | uri = hex.decode('hex') | |
944 | logger.info("URI from sigma_dut: " + uri) | |
945 | ||
946 | res = dev[1].request("DPP_QR_CODE " + uri) | |
947 | if "FAIL" in res: | |
948 | raise Exception("Failed to parse QR Code URI") | |
949 | id1 = int(res) | |
950 | ||
951 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
952 | if "status,COMPLETE" not in res: | |
953 | raise Exception("dev_exec_action did not succeed: " + res) | |
954 | ||
955 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10) | |
956 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res: | |
957 | raise Exception("Unexpected result: " + res) | |
958 | finally: | |
959 | dev[0].set("dpp_config_processing", "0") | |
960 | stop_sigma_dut(sigma) | |
961 | ||
962 | def dpp_init_conf_mutual(dev, id1, conf_id, own_id=None): | |
963 | time.sleep(1) | |
964 | logger.info("Starting DPP initiator/configurator in a thread") | |
965 | cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp ssid=%s configurator=%d" % (id1, "DPPNET01".encode("hex"), conf_id) | |
966 | if own_id is not None: | |
967 | cmd += " own=%d" % own_id | |
968 | if "OK" not in dev.request(cmd): | |
969 | raise Exception("Failed to initiate DPP Authentication") | |
970 | ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10) | |
971 | if ev is None: | |
972 | raise Exception("DPP configuration not completed (Configurator)") | |
973 | logger.info("DPP initiator/configurator done") | |
974 | ||
975 | def test_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev): | |
976 | """sigma_dut DPP/QR (mutual) responder as Enrollee""" | |
977 | check_dpp_capab(dev[0]) | |
978 | check_dpp_capab(dev[1]) | |
979 | ||
980 | csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
981 | csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
982 | ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg" | |
983 | ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b" | |
984 | ||
985 | params = { "ssid": "DPPNET01", | |
986 | "wpa": "2", | |
987 | "wpa_key_mgmt": "DPP", | |
988 | "rsn_pairwise": "CCMP", | |
989 | "dpp_connector": ap_connector, | |
990 | "dpp_csign": csign_pub, | |
991 | "dpp_netaccesskey": ap_netaccesskey } | |
992 | try: | |
993 | hapd = hostapd.add_ap(apdev[0], params) | |
994 | except: | |
995 | raise HwsimSkip("DPP not supported") | |
996 | ||
997 | sigma = start_sigma_dut(dev[0].ifname) | |
998 | try: | |
999 | dev[0].set("dpp_config_processing", "2") | |
1000 | ||
1001 | cmd = "DPP_CONFIGURATOR_ADD key=" + csign | |
1002 | res = dev[1].request(cmd); | |
1003 | if "FAIL" in res: | |
1004 | raise Exception("Failed to add configurator") | |
1005 | conf_id = int(res) | |
1006 | ||
1007 | addr = dev[1].own_addr().replace(':', '') | |
1008 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1009 | res = dev[1].request(cmd) | |
1010 | if "FAIL" in res: | |
1011 | raise Exception("Failed to generate bootstrapping info") | |
1012 | id0 = int(res) | |
1013 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1014 | ||
1015 | dev[1].set("dpp_configurator_params", | |
1016 | " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id)); | |
1017 | cmd = "DPP_LISTEN 2437 role=configurator qr=mutual" | |
1018 | if "OK" not in dev[1].request(cmd): | |
1019 | raise Exception("Failed to start listen operation") | |
1020 | ||
1021 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") | |
1022 | if "status,COMPLETE" not in res: | |
1023 | raise Exception("dev_exec_action did not succeed: " + res) | |
1024 | hex = res.split(',')[3] | |
1025 | uri = hex.decode('hex') | |
1026 | logger.info("URI from sigma_dut: " + uri) | |
1027 | ||
1028 | res = dev[1].request("DPP_QR_CODE " + uri) | |
1029 | if "FAIL" in res: | |
1030 | raise Exception("Failed to parse QR Code URI") | |
1031 | id1 = int(res) | |
1032 | ||
1033 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1034 | if "status,COMPLETE" not in res: | |
1035 | raise Exception("dev_exec_action did not succeed: " + res) | |
1036 | ||
1037 | t = threading.Thread(target=dpp_init_conf_mutual, | |
1038 | args=(dev[1], id1, conf_id, id0)) | |
1039 | t.start() | |
1040 | ||
1041 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,20,DPPWaitForConnect,Yes", timeout=25) | |
1042 | t.join() | |
1043 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res: | |
1044 | raise Exception("Unexpected result: " + res) | |
1045 | finally: | |
1046 | dev[0].set("dpp_config_processing", "0") | |
1047 | stop_sigma_dut(sigma) | |
1048 | ||
1049 | def test_sigma_dut_dpp_qr_init_enrollee_psk(dev, apdev): | |
1050 | """sigma_dut DPP/QR initiator as Enrollee (PSK)""" | |
1051 | check_dpp_capab(dev[0]) | |
1052 | check_dpp_capab(dev[1]) | |
1053 | ||
1054 | params = hostapd.wpa2_params(ssid="DPPNET01", | |
1055 | passphrase="ThisIsDppPassphrase") | |
1056 | hapd = hostapd.add_ap(apdev[0], params) | |
1057 | ||
1058 | sigma = start_sigma_dut(dev[0].ifname) | |
1059 | try: | |
1060 | dev[0].set("dpp_config_processing", "2") | |
1061 | ||
1062 | cmd = "DPP_CONFIGURATOR_ADD" | |
1063 | res = dev[1].request(cmd); | |
1064 | if "FAIL" in res: | |
1065 | raise Exception("Failed to add configurator") | |
1066 | conf_id = int(res) | |
1067 | ||
1068 | addr = dev[1].own_addr().replace(':', '') | |
1069 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1070 | res = dev[1].request(cmd) | |
1071 | if "FAIL" in res: | |
1072 | raise Exception("Failed to generate bootstrapping info") | |
1073 | id0 = int(res) | |
1074 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1075 | ||
1076 | dev[1].set("dpp_configurator_params", | |
1077 | " conf=sta-psk ssid=%s pass=%s configurator=%d" % ("DPPNET01".encode("hex"), "ThisIsDppPassphrase".encode("hex"), conf_id)); | |
1078 | cmd = "DPP_LISTEN 2437 role=configurator" | |
1079 | if "OK" not in dev[1].request(cmd): | |
1080 | raise Exception("Failed to start listen operation") | |
1081 | ||
1082 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1083 | if "status,COMPLETE" not in res: | |
1084 | raise Exception("dev_exec_action did not succeed: " + res) | |
1085 | ||
1086 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10) | |
1087 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res: | |
1088 | raise Exception("Unexpected result: " + res) | |
1089 | finally: | |
1090 | dev[0].set("dpp_config_processing", "0") | |
1091 | stop_sigma_dut(sigma) | |
1092 | ||
1093 | def test_sigma_dut_dpp_qr_init_configurator_1(dev, apdev): | |
1094 | """sigma_dut DPP/QR initiator as Configurator (conf index 1)""" | |
1095 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1) | |
1096 | ||
1097 | def test_sigma_dut_dpp_qr_init_configurator_2(dev, apdev): | |
1098 | """sigma_dut DPP/QR initiator as Configurator (conf index 2)""" | |
1099 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 2) | |
1100 | ||
1101 | def test_sigma_dut_dpp_qr_init_configurator_3(dev, apdev): | |
1102 | """sigma_dut DPP/QR initiator as Configurator (conf index 3)""" | |
1103 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 3) | |
1104 | ||
1105 | def test_sigma_dut_dpp_qr_init_configurator_4(dev, apdev): | |
1106 | """sigma_dut DPP/QR initiator as Configurator (conf index 4)""" | |
1107 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 4) | |
1108 | ||
1109 | def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx): | |
1110 | check_dpp_capab(dev[0]) | |
1111 | check_dpp_capab(dev[1]) | |
1112 | sigma = start_sigma_dut(dev[0].ifname) | |
1113 | try: | |
1114 | addr = dev[1].own_addr().replace(':', '') | |
1115 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1116 | res = dev[1].request(cmd) | |
1117 | if "FAIL" in res: | |
1118 | raise Exception("Failed to generate bootstrapping info") | |
1119 | id0 = int(res) | |
1120 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1121 | ||
1122 | cmd = "DPP_LISTEN 2437 role=enrollee" | |
1123 | if "OK" not in dev[1].request(cmd): | |
1124 | raise Exception("Failed to start listen operation") | |
1125 | ||
1126 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1127 | if "status,COMPLETE" not in res: | |
1128 | raise Exception("dev_exec_action did not succeed: " + res) | |
1129 | ||
1130 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,%d,DPPSigningKeyECC,P-256,DPPConfigEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6" % conf_idx) | |
1131 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: | |
1132 | raise Exception("Unexpected result: " + res) | |
1133 | finally: | |
1134 | stop_sigma_dut(sigma) | |
1135 | ||
1136 | def test_sigma_dut_dpp_pkex_init_configurator(dev, apdev): | |
1137 | """sigma_dut DPP/PKEX initiator as Configurator""" | |
1138 | check_dpp_capab(dev[0]) | |
1139 | check_dpp_capab(dev[1]) | |
1140 | sigma = start_sigma_dut(dev[0].ifname) | |
1141 | try: | |
1142 | cmd = "DPP_BOOTSTRAP_GEN type=pkex" | |
1143 | res = dev[1].request(cmd) | |
1144 | if "FAIL" in res: | |
1145 | raise Exception("Failed to generate bootstrapping info") | |
1146 | id1 = int(res) | |
1147 | cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1) | |
1148 | res = dev[1].request(cmd) | |
1149 | if "FAIL" in res: | |
1150 | raise Exception("Failed to set PKEX data (responder)") | |
1151 | cmd = "DPP_LISTEN 2437 role=enrollee" | |
1152 | if "OK" not in dev[1].request(cmd): | |
1153 | raise Exception("Failed to start listen operation") | |
1154 | ||
1155 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfigEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6") | |
1156 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: | |
1157 | raise Exception("Unexpected result: " + res) | |
1158 | finally: | |
1159 | stop_sigma_dut(sigma) | |
1160 | ||
1161 | def dpp_init_conf(dev, id1, conf, conf_id, extra): | |
1162 | logger.info("Starting DPP initiator/configurator in a thread") | |
1163 | cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id1, conf, extra, conf_id) | |
1164 | if "OK" not in dev.request(cmd): | |
1165 | raise Exception("Failed to initiate DPP Authentication") | |
1166 | ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5) | |
1167 | if ev is None: | |
1168 | raise Exception("DPP configuration not completed (Configurator)") | |
1169 | logger.info("DPP initiator/configurator done") | |
1170 | ||
1171 | def test_sigma_dut_ap_dpp_qr(dev, apdev, params): | |
1172 | """sigma_dut controlled AP (DPP)""" | |
1173 | run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-dpp", "sta-dpp") | |
1174 | ||
1175 | def test_sigma_dut_ap_dpp_qr_legacy(dev, apdev, params): | |
1176 | """sigma_dut controlled AP (legacy)""" | |
1177 | run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk", | |
1178 | extra="pass=%s" % "qwertyuiop".encode("hex")) | |
1179 | ||
1180 | def test_sigma_dut_ap_dpp_qr_legacy_psk(dev, apdev, params): | |
1181 | """sigma_dut controlled AP (legacy)""" | |
1182 | run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk", | |
1183 | extra="psk=%s" % (32*"12")) | |
1184 | ||
1185 | def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra=""): | |
1186 | logdir = os.path.join(params['logdir'], "sigma_dut_ap_dpp_qr.sigma-hostapd") | |
1187 | with HWSimRadio() as (radio, iface): | |
1188 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
1189 | try: | |
1190 | sigma_dut_cmd_check("ap_reset_default,program,DPP") | |
1191 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") | |
1192 | if "status,COMPLETE" not in res: | |
1193 | raise Exception("dev_exec_action did not succeed: " + res) | |
1194 | hex = res.split(',')[3] | |
1195 | uri = hex.decode('hex') | |
1196 | logger.info("URI from sigma_dut: " + uri) | |
1197 | ||
1198 | cmd = "DPP_CONFIGURATOR_ADD" | |
1199 | res = dev[0].request(cmd); | |
1200 | if "FAIL" in res: | |
1201 | raise Exception("Failed to add configurator") | |
1202 | conf_id = int(res) | |
1203 | ||
1204 | res = dev[0].request("DPP_QR_CODE " + uri) | |
1205 | if "FAIL" in res: | |
1206 | raise Exception("Failed to parse QR Code URI") | |
1207 | id1 = int(res) | |
1208 | ||
1209 | t = threading.Thread(target=dpp_init_conf, | |
1210 | args=(dev[0], id1, ap_conf, conf_id, extra)) | |
1211 | t.start() | |
1212 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6") | |
1213 | t.join() | |
1214 | if "ConfResult,OK" not in res: | |
1215 | raise Exception("Unexpected result: " + res) | |
1216 | ||
1217 | addr = dev[1].own_addr().replace(':', '') | |
1218 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr | |
1219 | res = dev[1].request(cmd) | |
1220 | if "FAIL" in res: | |
1221 | raise Exception("Failed to generate bootstrapping info") | |
1222 | id1 = int(res) | |
1223 | uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1) | |
1224 | ||
1225 | res = dev[0].request("DPP_QR_CODE " + uri1) | |
1226 | if "FAIL" in res: | |
1227 | raise Exception("Failed to parse QR Code URI") | |
1228 | id0b = int(res) | |
1229 | ||
1230 | dev[1].set("dpp_config_processing", "2") | |
1231 | cmd = "DPP_LISTEN 2412" | |
1232 | if "OK" not in dev[1].request(cmd): | |
1233 | raise Exception("Failed to start listen operation") | |
1234 | cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id0b, sta_conf, extra, conf_id) | |
1235 | if "OK" not in dev[0].request(cmd): | |
1236 | raise Exception("Failed to initiate DPP Authentication") | |
1237 | dev[1].wait_connected() | |
1238 | ||
1239 | sigma_dut_cmd_check("ap_reset_default") | |
1240 | finally: | |
1241 | dev[1].set("dpp_config_processing", "0") | |
1242 | stop_sigma_dut(sigma) |