]>
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 | |
211b5d1b | 18 | from test_dpp import check_dpp_capab, update_hapd_config |
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 | ||
20c18348 JM |
365 | def test_sigma_dut_ap_pskhex(dev, apdev, params): |
366 | """sigma_dut controlled AP and PSKHEX""" | |
367 | logdir = os.path.join(params['logdir'], | |
368 | "sigma_dut_ap_pskhex.sigma-hostapd") | |
369 | with HWSimRadio() as (radio, iface): | |
370 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
371 | try: | |
372 | psk = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" | |
373 | sigma_dut_cmd_check("ap_reset_default") | |
374 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng") | |
375 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSKHEX," + psk) | |
376 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
377 | ||
378 | dev[0].connect("test-psk", raw_psk=psk, scan_freq="2412") | |
379 | ||
380 | sigma_dut_cmd_check("ap_reset_default") | |
381 | finally: | |
382 | stop_sigma_dut(sigma) | |
383 | ||
2ef00a36 JM |
384 | def test_sigma_dut_suite_b(dev, apdev, params): |
385 | """sigma_dut controlled STA Suite B""" | |
386 | check_suite_b_192_capa(dev) | |
387 | logdir = params['logdir'] | |
388 | ||
389 | with open("auth_serv/ec2-ca.pem", "r") as f: | |
390 | with open(os.path.join(logdir, "suite_b_ca.pem"), "w") as f2: | |
391 | f2.write(f.read()) | |
392 | ||
393 | with open("auth_serv/ec2-user.pem", "r") as f: | |
394 | with open("auth_serv/ec2-user.key", "r") as f2: | |
395 | with open(os.path.join(logdir, "suite_b.pem"), "w") as f3: | |
396 | f3.write(f.read()) | |
397 | f3.write(f2.read()) | |
398 | ||
399 | dev[0].flush_scan_cache() | |
400 | params = suite_b_as_params() | |
401 | params['ca_cert'] = 'auth_serv/ec2-ca.pem' | |
402 | params['server_cert'] = 'auth_serv/ec2-server.pem' | |
403 | params['private_key'] = 'auth_serv/ec2-server.key' | |
404 | params['openssl_ciphers'] = 'SUITEB192' | |
405 | hostapd.add_ap(apdev[1], params) | |
406 | ||
407 | params = { "ssid": "test-suite-b", | |
408 | "wpa": "2", | |
409 | "wpa_key_mgmt": "WPA-EAP-SUITE-B-192", | |
410 | "rsn_pairwise": "GCMP-256", | |
411 | "group_mgmt_cipher": "BIP-GMAC-256", | |
412 | "ieee80211w": "2", | |
413 | "ieee8021x": "1", | |
414 | 'auth_server_addr': "127.0.0.1", | |
415 | 'auth_server_port': "18129", | |
416 | 'auth_server_shared_secret': "radius", | |
417 | 'nas_identifier': "nas.w1.fi" } | |
418 | hapd = hostapd.add_ap(apdev[0], params) | |
419 | ||
420 | ifname = dev[0].ifname | |
421 | sigma = start_sigma_dut(ifname, cert_path=logdir) | |
422 | ||
423 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname) | |
424 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
002b49ed | 425 | 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 |
426 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b")) |
427 | sigma_dut_wait_connected(ifname) | |
428 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
429 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
430 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
431 | ||
432 | stop_sigma_dut(sigma) | |
433 | ||
002b49ed JM |
434 | def test_sigma_dut_suite_b_rsa(dev, apdev, params): |
435 | """sigma_dut controlled STA Suite B (RSA)""" | |
436 | check_suite_b_192_capa(dev) | |
437 | logdir = params['logdir'] | |
438 | ||
439 | with open("auth_serv/rsa3072-ca.pem", "r") as f: | |
440 | with open(os.path.join(logdir, "suite_b_ca_rsa.pem"), "w") as f2: | |
441 | f2.write(f.read()) | |
442 | ||
443 | with open("auth_serv/rsa3072-user.pem", "r") as f: | |
444 | with open("auth_serv/rsa3072-user.key", "r") as f2: | |
445 | with open(os.path.join(logdir, "suite_b_rsa.pem"), "w") as f3: | |
446 | f3.write(f.read()) | |
447 | f3.write(f2.read()) | |
448 | ||
449 | dev[0].flush_scan_cache() | |
450 | params = suite_b_192_rsa_ap_params() | |
451 | hapd = hostapd.add_ap(apdev[0], params) | |
452 | ||
453 | ifname = dev[0].ifname | |
454 | sigma = start_sigma_dut(ifname, cert_path=logdir) | |
455 | ||
456 | 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") | |
457 | ||
458 | tests = [ "", | |
459 | ",TLSCipher,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", | |
460 | ",TLSCipher,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" ] | |
461 | for extra in tests: | |
462 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname) | |
463 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
464 | sigma_dut_cmd_check(cmd + extra) | |
465 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b")) | |
466 | sigma_dut_wait_connected(ifname) | |
467 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
468 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
469 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
470 | ||
471 | stop_sigma_dut(sigma) | |
472 | ||
2ef00a36 JM |
473 | def test_sigma_dut_ap_suite_b(dev, apdev, params): |
474 | """sigma_dut controlled AP Suite B""" | |
475 | check_suite_b_192_capa(dev) | |
476 | logdir = os.path.join(params['logdir'], | |
477 | "sigma_dut_ap_suite_b.sigma-hostapd") | |
478 | params = suite_b_as_params() | |
479 | params['ca_cert'] = 'auth_serv/ec2-ca.pem' | |
480 | params['server_cert'] = 'auth_serv/ec2-server.pem' | |
481 | params['private_key'] = 'auth_serv/ec2-server.key' | |
482 | params['openssl_ciphers'] = 'SUITEB192' | |
483 | hostapd.add_ap(apdev[1], params) | |
484 | with HWSimRadio() as (radio, iface): | |
485 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
486 | try: | |
487 | sigma_dut_cmd_check("ap_reset_default") | |
488 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng") | |
489 | sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius") | |
490 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required") | |
491 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
492 | ||
493 | dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192", | |
494 | ieee80211w="2", | |
495 | openssl_ciphers="SUITEB192", | |
496 | eap="TLS", identity="tls user", | |
497 | ca_cert="auth_serv/ec2-ca.pem", | |
498 | client_cert="auth_serv/ec2-user.pem", | |
499 | private_key="auth_serv/ec2-user.key", | |
500 | pairwise="GCMP-256", group="GCMP-256", | |
501 | scan_freq="2412") | |
502 | ||
503 | sigma_dut_cmd_check("ap_reset_default") | |
504 | finally: | |
505 | stop_sigma_dut(sigma) | |
506 | ||
507 | def test_sigma_dut_ap_cipher_gcmp_128(dev, apdev, params): | |
508 | """sigma_dut controlled AP with GCMP-128/BIP-GMAC-128 cipher""" | |
509 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-128", "BIP-GMAC-128", | |
510 | "GCMP") | |
511 | ||
512 | def test_sigma_dut_ap_cipher_gcmp_256(dev, apdev, params): | |
513 | """sigma_dut controlled AP with GCMP-256/BIP-GMAC-256 cipher""" | |
514 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-256", "BIP-GMAC-256", | |
515 | "GCMP-256") | |
516 | ||
517 | def test_sigma_dut_ap_cipher_ccmp_128(dev, apdev, params): | |
518 | """sigma_dut controlled AP with CCMP-128/BIP-CMAC-128 cipher""" | |
519 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128", "BIP-CMAC-128", | |
520 | "CCMP") | |
521 | ||
522 | def test_sigma_dut_ap_cipher_ccmp_256(dev, apdev, params): | |
523 | """sigma_dut controlled AP with CCMP-256/BIP-CMAC-256 cipher""" | |
524 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-256", "BIP-CMAC-256", | |
525 | "CCMP-256") | |
526 | ||
6af3b593 JM |
527 | def test_sigma_dut_ap_cipher_ccmp_gcmp_1(dev, apdev, params): |
528 | """sigma_dut controlled AP with CCMP-128+GCMP-256 ciphers (1)""" | |
529 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128 AES-GCMP-256", | |
530 | "BIP-GMAC-256", "CCMP") | |
531 | ||
532 | def test_sigma_dut_ap_cipher_ccmp_gcmp_2(dev, apdev, params): | |
533 | """sigma_dut controlled AP with CCMP-128+GCMP-256 ciphers (2)""" | |
534 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128 AES-GCMP-256", | |
535 | "BIP-GMAC-256", "GCMP-256", "CCMP") | |
536 | ||
21fd5576 JM |
537 | def test_sigma_dut_ap_cipher_gcmp_256_group_ccmp(dev, apdev, params): |
538 | """sigma_dut controlled AP with GCMP-256/CCMP/BIP-GMAC-256 cipher""" | |
539 | run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-256", "BIP-GMAC-256", | |
540 | "GCMP-256", "CCMP", "AES-CCMP-128") | |
541 | ||
2ef00a36 | 542 | def run_sigma_dut_ap_cipher(dev, apdev, params, ap_pairwise, ap_group_mgmt, |
21fd5576 | 543 | sta_cipher, sta_cipher_group=None, ap_group=None): |
2ef00a36 JM |
544 | check_suite_b_192_capa(dev) |
545 | logdir = os.path.join(params['logdir'], | |
546 | "sigma_dut_ap_cipher.sigma-hostapd") | |
547 | params = suite_b_as_params() | |
548 | params['ca_cert'] = 'auth_serv/ec2-ca.pem' | |
549 | params['server_cert'] = 'auth_serv/ec2-server.pem' | |
550 | params['private_key'] = 'auth_serv/ec2-server.key' | |
551 | params['openssl_ciphers'] = 'SUITEB192' | |
552 | hostapd.add_ap(apdev[1], params) | |
553 | with HWSimRadio() as (radio, iface): | |
554 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
555 | try: | |
556 | sigma_dut_cmd_check("ap_reset_default") | |
557 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng") | |
558 | sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius") | |
21fd5576 JM |
559 | cmd = "ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required,PairwiseCipher,%s,GroupMgntCipher,%s" % (ap_pairwise, ap_group_mgmt) |
560 | if ap_group: | |
561 | cmd += ",GroupCipher,%s" % ap_group | |
562 | sigma_dut_cmd_check(cmd) | |
2ef00a36 JM |
563 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") |
564 | ||
6af3b593 JM |
565 | if sta_cipher_group is None: |
566 | sta_cipher_group = sta_cipher | |
2ef00a36 JM |
567 | dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192", |
568 | ieee80211w="2", | |
569 | openssl_ciphers="SUITEB192", | |
570 | eap="TLS", identity="tls user", | |
571 | ca_cert="auth_serv/ec2-ca.pem", | |
572 | client_cert="auth_serv/ec2-user.pem", | |
573 | private_key="auth_serv/ec2-user.key", | |
6af3b593 | 574 | pairwise=sta_cipher, group=sta_cipher_group, |
2ef00a36 JM |
575 | scan_freq="2412") |
576 | ||
577 | sigma_dut_cmd_check("ap_reset_default") | |
578 | finally: | |
579 | stop_sigma_dut(sigma) | |
580 | ||
f6f33f8f JM |
581 | def test_sigma_dut_ap_override_rsne(dev, apdev): |
582 | """sigma_dut controlled AP overriding RSNE""" | |
583 | with HWSimRadio() as (radio, iface): | |
584 | sigma = start_sigma_dut(iface) | |
585 | try: | |
586 | sigma_dut_cmd_check("ap_reset_default") | |
587 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng") | |
588 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678") | |
589 | sigma_dut_cmd_check("dev_configure_ie,NAME,AP,interface,%s,IE_Name,RSNE,Contents,30180100000fac040200ffffffff000fac040100000fac020c00" % iface) | |
590 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
591 | ||
592 | dev[0].connect("test-psk", psk="12345678", scan_freq="2412") | |
593 | ||
594 | sigma_dut_cmd_check("ap_reset_default") | |
595 | finally: | |
596 | stop_sigma_dut(sigma) | |
1ed508d9 JM |
597 | |
598 | def test_sigma_dut_ap_sae(dev, apdev): | |
599 | """sigma_dut controlled AP with SAE""" | |
6e6651d0 JM |
600 | if "SAE" not in dev[0].get_capability("auth_alg"): |
601 | raise HwsimSkip("SAE not supported") | |
1ed508d9 JM |
602 | with HWSimRadio() as (radio, iface): |
603 | sigma = start_sigma_dut(iface) | |
604 | try: | |
605 | sigma_dut_cmd_check("ap_reset_default") | |
606 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") | |
607 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678") | |
608 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
609 | ||
610 | dev[0].request("SET sae_groups ") | |
611 | dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678", | |
612 | scan_freq="2412") | |
613 | if dev[0].get_status_field('sae_group') != '19': | |
614 | raise Exception("Expected default SAE group not used") | |
615 | ||
616 | sigma_dut_cmd_check("ap_reset_default") | |
6644069c JM |
617 | finally: |
618 | stop_sigma_dut(sigma) | |
619 | ||
620 | def test_sigma_dut_ap_sae_password(dev, apdev): | |
621 | """sigma_dut controlled AP with SAE and long password""" | |
6e6651d0 JM |
622 | if "SAE" not in dev[0].get_capability("auth_alg"): |
623 | raise HwsimSkip("SAE not supported") | |
6644069c JM |
624 | with HWSimRadio() as (radio, iface): |
625 | sigma = start_sigma_dut(iface) | |
626 | try: | |
627 | sigma_dut_cmd_check("ap_reset_default") | |
628 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") | |
629 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK," + 100*'C') | |
630 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
631 | ||
632 | dev[0].request("SET sae_groups ") | |
633 | dev[0].connect("test-sae", key_mgmt="SAE", sae_password=100*'C', | |
634 | scan_freq="2412") | |
635 | if dev[0].get_status_field('sae_group') != '19': | |
636 | raise Exception("Expected default SAE group not used") | |
637 | ||
638 | sigma_dut_cmd_check("ap_reset_default") | |
1ed508d9 JM |
639 | finally: |
640 | stop_sigma_dut(sigma) | |
641 | ||
642 | def test_sigma_dut_ap_sae_group(dev, apdev): | |
643 | """sigma_dut controlled AP with SAE and specific group""" | |
6e6651d0 JM |
644 | if "SAE" not in dev[0].get_capability("auth_alg"): |
645 | raise HwsimSkip("SAE not supported") | |
1ed508d9 JM |
646 | with HWSimRadio() as (radio, iface): |
647 | sigma = start_sigma_dut(iface) | |
648 | try: | |
649 | sigma_dut_cmd_check("ap_reset_default") | |
650 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") | |
651 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20") | |
652 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
653 | ||
654 | dev[0].request("SET sae_groups ") | |
655 | dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678", | |
656 | scan_freq="2412") | |
657 | if dev[0].get_status_field('sae_group') != '20': | |
658 | raise Exception("Expected SAE group not used") | |
659 | ||
660 | sigma_dut_cmd_check("ap_reset_default") | |
661 | finally: | |
662 | stop_sigma_dut(sigma) | |
663 | ||
664 | def test_sigma_dut_ap_psk_sae(dev, apdev): | |
665 | """sigma_dut controlled AP with PSK+SAE""" | |
6e6651d0 JM |
666 | if "SAE" not in dev[0].get_capability("auth_alg"): |
667 | raise HwsimSkip("SAE not supported") | |
1ed508d9 JM |
668 | with HWSimRadio() as (radio, iface): |
669 | sigma = start_sigma_dut(iface) | |
670 | try: | |
671 | sigma_dut_cmd_check("ap_reset_default") | |
672 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") | |
673 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678") | |
674 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
675 | ||
676 | dev[0].request("SET sae_groups ") | |
677 | dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678", | |
678 | scan_freq="2412") | |
679 | dev[1].connect("test-sae", psk="12345678", scan_freq="2412") | |
680 | ||
681 | sigma_dut_cmd_check("ap_reset_default") | |
682 | finally: | |
683 | stop_sigma_dut(sigma) | |
b9c0e1fa JM |
684 | |
685 | def test_sigma_dut_owe(dev, apdev): | |
686 | """sigma_dut controlled OWE station""" | |
687 | try: | |
688 | run_sigma_dut_owe(dev, apdev) | |
689 | finally: | |
690 | dev[0].set("ignore_old_scan_res", "0") | |
691 | ||
692 | def run_sigma_dut_owe(dev, apdev): | |
693 | if "OWE" not in dev[0].get_capability("key_mgmt"): | |
694 | raise HwsimSkip("OWE not supported") | |
695 | ||
696 | ifname = dev[0].ifname | |
697 | sigma = start_sigma_dut(ifname) | |
698 | ||
699 | try: | |
700 | params = { "ssid": "owe", | |
701 | "wpa": "2", | |
702 | "wpa_key_mgmt": "OWE", | |
703 | "rsn_pairwise": "CCMP" } | |
704 | hapd = hostapd.add_ap(apdev[0], params) | |
705 | bssid = hapd.own_addr() | |
706 | ||
707 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname) | |
708 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
709 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname) | |
710 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname) | |
711 | sigma_dut_wait_connected(ifname) | |
712 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
713 | ||
714 | dev[0].dump_monitor() | |
715 | sigma_dut_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid)) | |
716 | dev[0].wait_connected() | |
717 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
718 | dev[0].wait_disconnected() | |
719 | dev[0].dump_monitor() | |
720 | ||
721 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname) | |
722 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
723 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname) | |
724 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname) | |
725 | sigma_dut_wait_connected(ifname) | |
726 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
e30de6c2 JM |
727 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) |
728 | dev[0].wait_disconnected() | |
729 | dev[0].dump_monitor() | |
730 | ||
731 | sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname) | |
732 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
733 | sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname) | |
734 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname) | |
735 | ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10) | |
736 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
737 | if ev is None: | |
738 | raise Exception("Association not rejected") | |
739 | if "status_code=77" not in ev: | |
740 | raise Exception("Unexpected rejection reason: " + ev) | |
b9c0e1fa JM |
741 | |
742 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
743 | finally: | |
744 | stop_sigma_dut(sigma) | |
745 | ||
746 | def test_sigma_dut_ap_owe(dev, apdev): | |
747 | """sigma_dut controlled AP with OWE""" | |
748 | if "OWE" not in dev[0].get_capability("key_mgmt"): | |
749 | raise HwsimSkip("OWE not supported") | |
750 | with HWSimRadio() as (radio, iface): | |
751 | sigma = start_sigma_dut(iface) | |
752 | try: | |
753 | sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3") | |
754 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng") | |
755 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE") | |
756 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
757 | ||
b9c0e1fa JM |
758 | dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412") |
759 | ||
760 | sigma_dut_cmd_check("ap_reset_default") | |
761 | finally: | |
762 | stop_sigma_dut(sigma) | |
7f811be5 JM |
763 | |
764 | def test_sigma_dut_ap_owe_ecgroupid(dev, apdev): | |
765 | """sigma_dut controlled AP with OWE and ECGroupID""" | |
766 | if "OWE" not in dev[0].get_capability("key_mgmt"): | |
767 | raise HwsimSkip("OWE not supported") | |
768 | with HWSimRadio() as (radio, iface): | |
769 | sigma = start_sigma_dut(iface) | |
770 | try: | |
771 | sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3") | |
772 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng") | |
773 | sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required") | |
774 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
775 | ||
776 | dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2", | |
777 | owe_group="20", scan_freq="2412") | |
778 | dev[0].request("REMOVE_NETWORK all") | |
779 | dev[0].wait_disconnected() | |
780 | ||
781 | dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2", | |
782 | owe_group="21", scan_freq="2412") | |
783 | dev[0].request("REMOVE_NETWORK all") | |
784 | dev[0].wait_disconnected() | |
785 | ||
786 | dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2", | |
787 | owe_group="19", scan_freq="2412", wait_connect=False) | |
788 | ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10) | |
789 | dev[0].request("DISCONNECT") | |
790 | if ev is None: | |
791 | raise Exception("Association not rejected") | |
792 | if "status_code=77" not in ev: | |
793 | raise Exception("Unexpected rejection reason: " + ev) | |
794 | dev[0].dump_monitor() | |
795 | ||
796 | sigma_dut_cmd_check("ap_reset_default") | |
797 | finally: | |
798 | stop_sigma_dut(sigma) | |
86fd7d70 JM |
799 | |
800 | def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params): | |
801 | """sigma_dut controlled AP with OWE and transition mode""" | |
802 | if "OWE" not in dev[0].get_capability("key_mgmt"): | |
803 | raise HwsimSkip("OWE not supported") | |
804 | logdir = os.path.join(params['logdir'], | |
805 | "sigma_dut_ap_owe_transition_mode.sigma-hostapd") | |
806 | with HWSimRadio() as (radio, iface): | |
807 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
808 | try: | |
809 | sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3") | |
810 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng") | |
811 | sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE") | |
812 | sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng") | |
813 | sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE") | |
814 | sigma_dut_cmd_check("ap_config_commit,NAME,AP") | |
815 | ||
89c343e8 JM |
816 | res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G") |
817 | res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G") | |
818 | ||
86fd7d70 JM |
819 | dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412") |
820 | dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412") | |
89c343e8 JM |
821 | if dev[0].get_status_field('bssid') not in res1: |
822 | raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res1) | |
823 | if dev[1].get_status_field('bssid') not in res2: | |
824 | raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res2) | |
86fd7d70 JM |
825 | |
826 | sigma_dut_cmd_check("ap_reset_default") | |
827 | finally: | |
828 | stop_sigma_dut(sigma) | |
d84c0cf4 JM |
829 | |
830 | def dpp_init_enrollee(dev, id1): | |
831 | logger.info("Starting DPP initiator/enrollee in a thread") | |
832 | time.sleep(1) | |
833 | cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1 | |
834 | if "OK" not in dev.request(cmd): | |
835 | raise Exception("Failed to initiate DPP Authentication") | |
836 | ev = dev.wait_event(["DPP-CONF-RECEIVED"], timeout=5) | |
837 | if ev is None: | |
838 | raise Exception("DPP configuration not completed (Enrollee)") | |
839 | logger.info("DPP initiator/enrollee done") | |
840 | ||
841 | def test_sigma_dut_dpp_qr_resp_1(dev, apdev): | |
842 | """sigma_dut DPP/QR responder (conf index 1)""" | |
843 | run_sigma_dut_dpp_qr_resp(dev, apdev, 1) | |
844 | ||
845 | def test_sigma_dut_dpp_qr_resp_2(dev, apdev): | |
846 | """sigma_dut DPP/QR responder (conf index 2)""" | |
847 | run_sigma_dut_dpp_qr_resp(dev, apdev, 2) | |
848 | ||
849 | def test_sigma_dut_dpp_qr_resp_3(dev, apdev): | |
850 | """sigma_dut DPP/QR responder (conf index 3)""" | |
851 | run_sigma_dut_dpp_qr_resp(dev, apdev, 3) | |
852 | ||
853 | def test_sigma_dut_dpp_qr_resp_4(dev, apdev): | |
854 | """sigma_dut DPP/QR responder (conf index 4)""" | |
855 | run_sigma_dut_dpp_qr_resp(dev, apdev, 4) | |
856 | ||
b014624b JM |
857 | def test_sigma_dut_dpp_qr_resp_chan_list(dev, apdev): |
858 | """sigma_dut DPP/QR responder (channel list override)""" | |
859 | run_sigma_dut_dpp_qr_resp(dev, apdev, 1, chan_list='81/2 81/6 81/1', | |
860 | listen_chan=2) | |
861 | ||
862 | def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None, | |
863 | listen_chan=None): | |
d84c0cf4 JM |
864 | check_dpp_capab(dev[0]) |
865 | check_dpp_capab(dev[1]) | |
866 | sigma = start_sigma_dut(dev[0].ifname) | |
867 | try: | |
b014624b JM |
868 | cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR" |
869 | if chan_list: | |
870 | cmd += ",DPPChannelList," + chan_list | |
871 | res = sigma_dut_cmd(cmd) | |
d84c0cf4 JM |
872 | if "status,COMPLETE" not in res: |
873 | raise Exception("dev_exec_action did not succeed: " + res) | |
874 | hex = res.split(',')[3] | |
875 | uri = hex.decode('hex') | |
876 | logger.info("URI from sigma_dut: " + uri) | |
877 | ||
878 | res = dev[1].request("DPP_QR_CODE " + uri) | |
879 | if "FAIL" in res: | |
880 | raise Exception("Failed to parse QR Code URI") | |
881 | id1 = int(res) | |
882 | ||
883 | t = threading.Thread(target=dpp_init_enrollee, args=(dev[1], id1)) | |
884 | t.start() | |
14f8e081 | 885 | cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPConfIndex,%d,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,STA,DPPSigningKeyECC,P-256,DPPBS,QR,DPPTimeout,6" % conf_idx |
b014624b JM |
886 | if listen_chan: |
887 | cmd += ",DPPListenChannel," + str(listen_chan) | |
888 | res = sigma_dut_cmd(cmd, timeout=10) | |
d84c0cf4 JM |
889 | t.join() |
890 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: | |
891 | raise Exception("Unexpected result: " + res) | |
892 | finally: | |
893 | stop_sigma_dut(sigma) | |
894 | ||
895 | def test_sigma_dut_dpp_qr_init_enrollee(dev, apdev): | |
896 | """sigma_dut DPP/QR initiator as Enrollee""" | |
897 | check_dpp_capab(dev[0]) | |
898 | check_dpp_capab(dev[1]) | |
899 | ||
900 | csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
901 | csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
902 | ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg" | |
903 | ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b" | |
904 | ||
905 | params = { "ssid": "DPPNET01", | |
906 | "wpa": "2", | |
907 | "wpa_key_mgmt": "DPP", | |
908 | "rsn_pairwise": "CCMP", | |
909 | "dpp_connector": ap_connector, | |
910 | "dpp_csign": csign_pub, | |
911 | "dpp_netaccesskey": ap_netaccesskey } | |
912 | try: | |
913 | hapd = hostapd.add_ap(apdev[0], params) | |
914 | except: | |
915 | raise HwsimSkip("DPP not supported") | |
916 | ||
917 | sigma = start_sigma_dut(dev[0].ifname) | |
918 | try: | |
919 | dev[0].set("dpp_config_processing", "2") | |
920 | ||
921 | cmd = "DPP_CONFIGURATOR_ADD key=" + csign | |
922 | res = dev[1].request(cmd); | |
923 | if "FAIL" in res: | |
924 | raise Exception("Failed to add configurator") | |
925 | conf_id = int(res) | |
926 | ||
927 | addr = dev[1].own_addr().replace(':', '') | |
928 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
929 | res = dev[1].request(cmd) | |
930 | if "FAIL" in res: | |
931 | raise Exception("Failed to generate bootstrapping info") | |
932 | id0 = int(res) | |
933 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
934 | ||
935 | dev[1].set("dpp_configurator_params", | |
936 | " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id)); | |
937 | cmd = "DPP_LISTEN 2437 role=configurator" | |
938 | if "OK" not in dev[1].request(cmd): | |
939 | raise Exception("Failed to start listen operation") | |
940 | ||
941 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
942 | if "status,COMPLETE" not in res: | |
943 | raise Exception("dev_exec_action did not succeed: " + res) | |
944 | ||
945 | 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) | |
946 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res: | |
947 | raise Exception("Unexpected result: " + res) | |
948 | finally: | |
949 | dev[0].set("dpp_config_processing", "0") | |
950 | stop_sigma_dut(sigma) | |
951 | ||
952 | def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev): | |
953 | """sigma_dut DPP/QR (mutual) initiator as Enrollee""" | |
33cddd7f JM |
954 | run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev) |
955 | ||
956 | def test_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev): | |
957 | """sigma_dut DPP/QR (mutual) initiator as Enrollee (extra check)""" | |
958 | run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev, | |
959 | extra="DPPAuthDirection,Mutual,") | |
960 | ||
961 | def run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev, extra=''): | |
d84c0cf4 JM |
962 | check_dpp_capab(dev[0]) |
963 | check_dpp_capab(dev[1]) | |
964 | ||
965 | csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
966 | csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
967 | ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg" | |
968 | ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b" | |
969 | ||
970 | params = { "ssid": "DPPNET01", | |
971 | "wpa": "2", | |
972 | "wpa_key_mgmt": "DPP", | |
973 | "rsn_pairwise": "CCMP", | |
974 | "dpp_connector": ap_connector, | |
975 | "dpp_csign": csign_pub, | |
976 | "dpp_netaccesskey": ap_netaccesskey } | |
977 | try: | |
978 | hapd = hostapd.add_ap(apdev[0], params) | |
979 | except: | |
980 | raise HwsimSkip("DPP not supported") | |
981 | ||
982 | sigma = start_sigma_dut(dev[0].ifname) | |
983 | try: | |
984 | dev[0].set("dpp_config_processing", "2") | |
985 | ||
986 | cmd = "DPP_CONFIGURATOR_ADD key=" + csign | |
987 | res = dev[1].request(cmd); | |
988 | if "FAIL" in res: | |
989 | raise Exception("Failed to add configurator") | |
990 | conf_id = int(res) | |
991 | ||
992 | addr = dev[1].own_addr().replace(':', '') | |
993 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
994 | res = dev[1].request(cmd) | |
995 | if "FAIL" in res: | |
996 | raise Exception("Failed to generate bootstrapping info") | |
997 | id0 = int(res) | |
998 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
999 | ||
1000 | dev[1].set("dpp_configurator_params", | |
1001 | " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id)); | |
1002 | cmd = "DPP_LISTEN 2437 role=configurator qr=mutual" | |
1003 | if "OK" not in dev[1].request(cmd): | |
1004 | raise Exception("Failed to start listen operation") | |
1005 | ||
1006 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") | |
1007 | if "status,COMPLETE" not in res: | |
1008 | raise Exception("dev_exec_action did not succeed: " + res) | |
1009 | hex = res.split(',')[3] | |
1010 | uri = hex.decode('hex') | |
1011 | logger.info("URI from sigma_dut: " + uri) | |
1012 | ||
1013 | res = dev[1].request("DPP_QR_CODE " + uri) | |
1014 | if "FAIL" in res: | |
1015 | raise Exception("Failed to parse QR Code URI") | |
1016 | id1 = int(res) | |
1017 | ||
1018 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1019 | if "status,COMPLETE" not in res: | |
1020 | raise Exception("dev_exec_action did not succeed: " + res) | |
1021 | ||
33cddd7f | 1022 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,%sDPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes" % extra, timeout=10) |
d84c0cf4 JM |
1023 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res: |
1024 | raise Exception("Unexpected result: " + res) | |
1025 | finally: | |
1026 | dev[0].set("dpp_config_processing", "0") | |
1027 | stop_sigma_dut(sigma) | |
1028 | ||
1029 | def dpp_init_conf_mutual(dev, id1, conf_id, own_id=None): | |
1030 | time.sleep(1) | |
1031 | logger.info("Starting DPP initiator/configurator in a thread") | |
1032 | cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp ssid=%s configurator=%d" % (id1, "DPPNET01".encode("hex"), conf_id) | |
1033 | if own_id is not None: | |
1034 | cmd += " own=%d" % own_id | |
1035 | if "OK" not in dev.request(cmd): | |
1036 | raise Exception("Failed to initiate DPP Authentication") | |
1037 | ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10) | |
1038 | if ev is None: | |
1039 | raise Exception("DPP configuration not completed (Configurator)") | |
1040 | logger.info("DPP initiator/configurator done") | |
1041 | ||
1042 | def test_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev): | |
1043 | """sigma_dut DPP/QR (mutual) responder as Enrollee""" | |
71db91db JM |
1044 | run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev) |
1045 | ||
1046 | def test_sigma_dut_dpp_qr_mutual_resp_enrollee_pending(dev, apdev): | |
1047 | """sigma_dut DPP/QR (mutual) responder as Enrollee (response pending)""" | |
1048 | run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, ',DPPDelayQRResponse,1') | |
1049 | ||
1050 | def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None): | |
d84c0cf4 JM |
1051 | check_dpp_capab(dev[0]) |
1052 | check_dpp_capab(dev[1]) | |
1053 | ||
1054 | csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
1055 | csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
1056 | ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg" | |
1057 | ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b" | |
1058 | ||
1059 | params = { "ssid": "DPPNET01", | |
1060 | "wpa": "2", | |
1061 | "wpa_key_mgmt": "DPP", | |
1062 | "rsn_pairwise": "CCMP", | |
1063 | "dpp_connector": ap_connector, | |
1064 | "dpp_csign": csign_pub, | |
1065 | "dpp_netaccesskey": ap_netaccesskey } | |
1066 | try: | |
1067 | hapd = hostapd.add_ap(apdev[0], params) | |
1068 | except: | |
1069 | raise HwsimSkip("DPP not supported") | |
1070 | ||
1071 | sigma = start_sigma_dut(dev[0].ifname) | |
1072 | try: | |
1073 | dev[0].set("dpp_config_processing", "2") | |
1074 | ||
1075 | cmd = "DPP_CONFIGURATOR_ADD key=" + csign | |
1076 | res = dev[1].request(cmd); | |
1077 | if "FAIL" in res: | |
1078 | raise Exception("Failed to add configurator") | |
1079 | conf_id = int(res) | |
1080 | ||
1081 | addr = dev[1].own_addr().replace(':', '') | |
1082 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1083 | res = dev[1].request(cmd) | |
1084 | if "FAIL" in res: | |
1085 | raise Exception("Failed to generate bootstrapping info") | |
1086 | id0 = int(res) | |
1087 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1088 | ||
d84c0cf4 JM |
1089 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") |
1090 | if "status,COMPLETE" not in res: | |
1091 | raise Exception("dev_exec_action did not succeed: " + res) | |
1092 | hex = res.split(',')[3] | |
1093 | uri = hex.decode('hex') | |
1094 | logger.info("URI from sigma_dut: " + uri) | |
1095 | ||
1096 | res = dev[1].request("DPP_QR_CODE " + uri) | |
1097 | if "FAIL" in res: | |
1098 | raise Exception("Failed to parse QR Code URI") | |
1099 | id1 = int(res) | |
1100 | ||
1101 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1102 | if "status,COMPLETE" not in res: | |
1103 | raise Exception("dev_exec_action did not succeed: " + res) | |
1104 | ||
1105 | t = threading.Thread(target=dpp_init_conf_mutual, | |
1106 | args=(dev[1], id1, conf_id, id0)) | |
1107 | t.start() | |
1108 | ||
71db91db JM |
1109 | cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,20,DPPWaitForConnect,Yes" |
1110 | if extra: | |
1111 | cmd += extra | |
1112 | res = sigma_dut_cmd(cmd, timeout=25) | |
d84c0cf4 JM |
1113 | t.join() |
1114 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res: | |
1115 | raise Exception("Unexpected result: " + res) | |
1116 | finally: | |
1117 | dev[0].set("dpp_config_processing", "0") | |
1118 | stop_sigma_dut(sigma) | |
1119 | ||
e486e5fd JM |
1120 | def dpp_resp_conf_mutual(dev, conf_id, uri): |
1121 | logger.info("Starting DPP responder/configurator in a thread") | |
1122 | dev.set("dpp_configurator_params", | |
1123 | " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id)); | |
1124 | cmd = "DPP_LISTEN 2437 role=configurator qr=mutual" | |
1125 | if "OK" not in dev.request(cmd): | |
1126 | raise Exception("Failed to initiate DPP listen") | |
1127 | if uri: | |
1128 | ev = dev.wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=10) | |
1129 | if ev is None: | |
1130 | raise Exception("QR Code scan for mutual authentication not requested") | |
1131 | res = dev.request("DPP_QR_CODE " + uri) | |
1132 | if "FAIL" in res: | |
1133 | raise Exception("Failed to parse QR Code URI") | |
1134 | ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10) | |
1135 | if ev is None: | |
1136 | raise Exception("DPP configuration not completed (Configurator)") | |
1137 | logger.info("DPP responder/configurator done") | |
1138 | ||
1139 | def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev): | |
1140 | """sigma_dut DPP/QR (mutual) initiator as Enrollee""" | |
1141 | run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, False) | |
1142 | ||
1143 | def test_sigma_dut_dpp_qr_mutual_init_enrollee_pending(dev, apdev): | |
1144 | """sigma_dut DPP/QR (mutual) initiator as Enrollee (response pending)""" | |
1145 | run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, True) | |
1146 | ||
1147 | def run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, resp_pending): | |
1148 | check_dpp_capab(dev[0]) | |
1149 | check_dpp_capab(dev[1]) | |
1150 | ||
1151 | csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
1152 | csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
1153 | ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg" | |
1154 | ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b" | |
1155 | ||
1156 | params = { "ssid": "DPPNET01", | |
1157 | "wpa": "2", | |
1158 | "wpa_key_mgmt": "DPP", | |
1159 | "rsn_pairwise": "CCMP", | |
1160 | "dpp_connector": ap_connector, | |
1161 | "dpp_csign": csign_pub, | |
1162 | "dpp_netaccesskey": ap_netaccesskey } | |
1163 | try: | |
1164 | hapd = hostapd.add_ap(apdev[0], params) | |
1165 | except: | |
1166 | raise HwsimSkip("DPP not supported") | |
1167 | ||
1168 | sigma = start_sigma_dut(dev[0].ifname) | |
1169 | try: | |
1170 | dev[0].set("dpp_config_processing", "2") | |
1171 | ||
1172 | cmd = "DPP_CONFIGURATOR_ADD key=" + csign | |
1173 | res = dev[1].request(cmd); | |
1174 | if "FAIL" in res: | |
1175 | raise Exception("Failed to add configurator") | |
1176 | conf_id = int(res) | |
1177 | ||
1178 | addr = dev[1].own_addr().replace(':', '') | |
1179 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1180 | res = dev[1].request(cmd) | |
1181 | if "FAIL" in res: | |
1182 | raise Exception("Failed to generate bootstrapping info") | |
1183 | id0 = int(res) | |
1184 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1185 | ||
1186 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") | |
1187 | if "status,COMPLETE" not in res: | |
1188 | raise Exception("dev_exec_action did not succeed: " + res) | |
1189 | hex = res.split(',')[3] | |
1190 | uri = hex.decode('hex') | |
1191 | logger.info("URI from sigma_dut: " + uri) | |
1192 | ||
1193 | if not resp_pending: | |
1194 | res = dev[1].request("DPP_QR_CODE " + uri) | |
1195 | if "FAIL" in res: | |
1196 | raise Exception("Failed to parse QR Code URI") | |
1197 | uri = None | |
1198 | ||
1199 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1200 | if "status,COMPLETE" not in res: | |
1201 | raise Exception("dev_exec_action did not succeed: " + res) | |
1202 | ||
1203 | t = threading.Thread(target=dpp_resp_conf_mutual, | |
1204 | args=(dev[1], conf_id, uri)) | |
1205 | t.start() | |
1206 | ||
1207 | time.sleep(1) | |
33cddd7f | 1208 | cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,10,DPPWaitForConnect,Yes" |
e486e5fd JM |
1209 | res = sigma_dut_cmd(cmd, timeout=15) |
1210 | t.join() | |
1211 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res: | |
1212 | raise Exception("Unexpected result: " + res) | |
1213 | finally: | |
1214 | dev[0].set("dpp_config_processing", "0") | |
1215 | stop_sigma_dut(sigma) | |
1216 | ||
d84c0cf4 JM |
1217 | def test_sigma_dut_dpp_qr_init_enrollee_psk(dev, apdev): |
1218 | """sigma_dut DPP/QR initiator as Enrollee (PSK)""" | |
1219 | check_dpp_capab(dev[0]) | |
1220 | check_dpp_capab(dev[1]) | |
1221 | ||
1222 | params = hostapd.wpa2_params(ssid="DPPNET01", | |
1223 | passphrase="ThisIsDppPassphrase") | |
1224 | hapd = hostapd.add_ap(apdev[0], params) | |
1225 | ||
1226 | sigma = start_sigma_dut(dev[0].ifname) | |
1227 | try: | |
1228 | dev[0].set("dpp_config_processing", "2") | |
1229 | ||
1230 | cmd = "DPP_CONFIGURATOR_ADD" | |
1231 | res = dev[1].request(cmd); | |
1232 | if "FAIL" in res: | |
1233 | raise Exception("Failed to add configurator") | |
1234 | conf_id = int(res) | |
1235 | ||
1236 | addr = dev[1].own_addr().replace(':', '') | |
1237 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1238 | res = dev[1].request(cmd) | |
1239 | if "FAIL" in res: | |
1240 | raise Exception("Failed to generate bootstrapping info") | |
1241 | id0 = int(res) | |
1242 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1243 | ||
1244 | dev[1].set("dpp_configurator_params", | |
1245 | " conf=sta-psk ssid=%s pass=%s configurator=%d" % ("DPPNET01".encode("hex"), "ThisIsDppPassphrase".encode("hex"), conf_id)); | |
1246 | cmd = "DPP_LISTEN 2437 role=configurator" | |
1247 | if "OK" not in dev[1].request(cmd): | |
1248 | raise Exception("Failed to start listen operation") | |
1249 | ||
1250 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1251 | if "status,COMPLETE" not in res: | |
1252 | raise Exception("dev_exec_action did not succeed: " + res) | |
1253 | ||
1254 | 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) | |
1255 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res: | |
1256 | raise Exception("Unexpected result: " + res) | |
1257 | finally: | |
1258 | dev[0].set("dpp_config_processing", "0") | |
1259 | stop_sigma_dut(sigma) | |
1260 | ||
1261 | def test_sigma_dut_dpp_qr_init_configurator_1(dev, apdev): | |
1262 | """sigma_dut DPP/QR initiator as Configurator (conf index 1)""" | |
1263 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1) | |
1264 | ||
1265 | def test_sigma_dut_dpp_qr_init_configurator_2(dev, apdev): | |
1266 | """sigma_dut DPP/QR initiator as Configurator (conf index 2)""" | |
1267 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 2) | |
1268 | ||
1269 | def test_sigma_dut_dpp_qr_init_configurator_3(dev, apdev): | |
1270 | """sigma_dut DPP/QR initiator as Configurator (conf index 3)""" | |
1271 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 3) | |
1272 | ||
1273 | def test_sigma_dut_dpp_qr_init_configurator_4(dev, apdev): | |
1274 | """sigma_dut DPP/QR initiator as Configurator (conf index 4)""" | |
1275 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 4) | |
1276 | ||
0e664e0c JM |
1277 | def test_sigma_dut_dpp_qr_init_configurator_both(dev, apdev): |
1278 | """sigma_dut DPP/QR initiator as Configurator or Enrollee (conf index 1)""" | |
1279 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1, "Both") | |
1280 | ||
cb6b2232 JM |
1281 | def test_sigma_dut_dpp_qr_init_configurator_neg_freq(dev, apdev): |
1282 | """sigma_dut DPP/QR initiator as Configurator (neg_freq)""" | |
1283 | run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1, extra='DPPSubsequentChannel,81/11') | |
1284 | ||
0e664e0c | 1285 | def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx, |
cb6b2232 JM |
1286 | prov_role="Configurator", |
1287 | extra=None): | |
d84c0cf4 JM |
1288 | check_dpp_capab(dev[0]) |
1289 | check_dpp_capab(dev[1]) | |
1290 | sigma = start_sigma_dut(dev[0].ifname) | |
1291 | try: | |
1292 | addr = dev[1].own_addr().replace(':', '') | |
1293 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1294 | res = dev[1].request(cmd) | |
1295 | if "FAIL" in res: | |
1296 | raise Exception("Failed to generate bootstrapping info") | |
1297 | id0 = int(res) | |
1298 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1299 | ||
1300 | cmd = "DPP_LISTEN 2437 role=enrollee" | |
1301 | if "OK" not in dev[1].request(cmd): | |
1302 | raise Exception("Failed to start listen operation") | |
1303 | ||
1304 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1305 | if "status,COMPLETE" not in res: | |
1306 | raise Exception("dev_exec_action did not succeed: " + res) | |
1307 | ||
cb6b2232 JM |
1308 | cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,%s,DPPConfIndex,%d,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6" % (prov_role, conf_idx) |
1309 | if extra: | |
1310 | cmd += "," + extra | |
1311 | res = sigma_dut_cmd(cmd) | |
d84c0cf4 JM |
1312 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: |
1313 | raise Exception("Unexpected result: " + res) | |
1314 | finally: | |
1315 | stop_sigma_dut(sigma) | |
1316 | ||
1317 | def test_sigma_dut_dpp_pkex_init_configurator(dev, apdev): | |
1318 | """sigma_dut DPP/PKEX initiator as Configurator""" | |
1319 | check_dpp_capab(dev[0]) | |
1320 | check_dpp_capab(dev[1]) | |
1321 | sigma = start_sigma_dut(dev[0].ifname) | |
1322 | try: | |
1323 | cmd = "DPP_BOOTSTRAP_GEN type=pkex" | |
1324 | res = dev[1].request(cmd) | |
1325 | if "FAIL" in res: | |
1326 | raise Exception("Failed to generate bootstrapping info") | |
1327 | id1 = int(res) | |
1328 | cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1) | |
1329 | res = dev[1].request(cmd) | |
1330 | if "FAIL" in res: | |
1331 | raise Exception("Failed to set PKEX data (responder)") | |
1332 | cmd = "DPP_LISTEN 2437 role=enrollee" | |
1333 | if "OK" not in dev[1].request(cmd): | |
1334 | raise Exception("Failed to start listen operation") | |
1335 | ||
33cddd7f | 1336 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6") |
d84c0cf4 JM |
1337 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: |
1338 | raise Exception("Unexpected result: " + res) | |
1339 | finally: | |
1340 | stop_sigma_dut(sigma) | |
1341 | ||
1342 | def dpp_init_conf(dev, id1, conf, conf_id, extra): | |
1343 | logger.info("Starting DPP initiator/configurator in a thread") | |
1344 | cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id1, conf, extra, conf_id) | |
1345 | if "OK" not in dev.request(cmd): | |
1346 | raise Exception("Failed to initiate DPP Authentication") | |
1347 | ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5) | |
1348 | if ev is None: | |
1349 | raise Exception("DPP configuration not completed (Configurator)") | |
1350 | logger.info("DPP initiator/configurator done") | |
1351 | ||
1352 | def test_sigma_dut_ap_dpp_qr(dev, apdev, params): | |
1353 | """sigma_dut controlled AP (DPP)""" | |
1354 | run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-dpp", "sta-dpp") | |
1355 | ||
1356 | def test_sigma_dut_ap_dpp_qr_legacy(dev, apdev, params): | |
1357 | """sigma_dut controlled AP (legacy)""" | |
1358 | run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk", | |
1359 | extra="pass=%s" % "qwertyuiop".encode("hex")) | |
1360 | ||
1361 | def test_sigma_dut_ap_dpp_qr_legacy_psk(dev, apdev, params): | |
1362 | """sigma_dut controlled AP (legacy)""" | |
1363 | run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk", | |
1364 | extra="psk=%s" % (32*"12")) | |
1365 | ||
1366 | def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra=""): | |
6e6651d0 | 1367 | check_dpp_capab(dev[0]) |
d84c0cf4 JM |
1368 | logdir = os.path.join(params['logdir'], "sigma_dut_ap_dpp_qr.sigma-hostapd") |
1369 | with HWSimRadio() as (radio, iface): | |
1370 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
1371 | try: | |
1372 | sigma_dut_cmd_check("ap_reset_default,program,DPP") | |
1373 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") | |
1374 | if "status,COMPLETE" not in res: | |
1375 | raise Exception("dev_exec_action did not succeed: " + res) | |
1376 | hex = res.split(',')[3] | |
1377 | uri = hex.decode('hex') | |
1378 | logger.info("URI from sigma_dut: " + uri) | |
1379 | ||
1380 | cmd = "DPP_CONFIGURATOR_ADD" | |
1381 | res = dev[0].request(cmd); | |
1382 | if "FAIL" in res: | |
1383 | raise Exception("Failed to add configurator") | |
1384 | conf_id = int(res) | |
1385 | ||
1386 | res = dev[0].request("DPP_QR_CODE " + uri) | |
1387 | if "FAIL" in res: | |
1388 | raise Exception("Failed to parse QR Code URI") | |
1389 | id1 = int(res) | |
1390 | ||
1391 | t = threading.Thread(target=dpp_init_conf, | |
1392 | args=(dev[0], id1, ap_conf, conf_id, extra)) | |
1393 | t.start() | |
1394 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6") | |
1395 | t.join() | |
1396 | if "ConfResult,OK" not in res: | |
1397 | raise Exception("Unexpected result: " + res) | |
1398 | ||
1399 | addr = dev[1].own_addr().replace(':', '') | |
1400 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr | |
1401 | res = dev[1].request(cmd) | |
1402 | if "FAIL" in res: | |
1403 | raise Exception("Failed to generate bootstrapping info") | |
1404 | id1 = int(res) | |
1405 | uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1) | |
1406 | ||
1407 | res = dev[0].request("DPP_QR_CODE " + uri1) | |
1408 | if "FAIL" in res: | |
1409 | raise Exception("Failed to parse QR Code URI") | |
1410 | id0b = int(res) | |
1411 | ||
1412 | dev[1].set("dpp_config_processing", "2") | |
1413 | cmd = "DPP_LISTEN 2412" | |
1414 | if "OK" not in dev[1].request(cmd): | |
1415 | raise Exception("Failed to start listen operation") | |
1416 | cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id0b, sta_conf, extra, conf_id) | |
1417 | if "OK" not in dev[0].request(cmd): | |
1418 | raise Exception("Failed to initiate DPP Authentication") | |
1419 | dev[1].wait_connected() | |
1420 | ||
1421 | sigma_dut_cmd_check("ap_reset_default") | |
1422 | finally: | |
1423 | dev[1].set("dpp_config_processing", "0") | |
1424 | stop_sigma_dut(sigma) | |
b900fb1a JM |
1425 | |
1426 | def test_sigma_dut_ap_dpp_pkex_responder(dev, apdev, params): | |
1427 | """sigma_dut controlled AP as DPP PKEX responder""" | |
6e6651d0 | 1428 | check_dpp_capab(dev[0]) |
b900fb1a JM |
1429 | logdir = os.path.join(params['logdir'], |
1430 | "sigma_dut_ap_dpp_pkex_responder.sigma-hostapd") | |
1431 | with HWSimRadio() as (radio, iface): | |
1432 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
1433 | try: | |
1434 | run_sigma_dut_ap_dpp_pkex_responder(dev, apdev) | |
1435 | finally: | |
1436 | stop_sigma_dut(sigma) | |
1437 | ||
1438 | def dpp_init_conf_pkex(dev, conf_id): | |
1439 | logger.info("Starting DPP PKEX initiator/configurator in a thread") | |
1440 | time.sleep(1.5) | |
1441 | cmd = "DPP_BOOTSTRAP_GEN type=pkex" | |
1442 | res = dev.request(cmd) | |
1443 | if "FAIL" in res: | |
1444 | raise Exception("Failed to generate bootstrapping info") | |
1445 | id = int(res) | |
1446 | cmd = "DPP_PKEX_ADD own=%d init=1 conf=ap-dpp configurator=%d code=password" % (id, conf_id) | |
1447 | res = dev.request(cmd) | |
1448 | if "FAIL" in res: | |
1449 | raise Exception("Failed to initiate DPP PKEX") | |
1450 | ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5) | |
1451 | if ev is None: | |
1452 | raise Exception("DPP configuration not completed (Configurator)") | |
1453 | logger.info("DPP initiator/configurator done") | |
1454 | ||
1455 | def run_sigma_dut_ap_dpp_pkex_responder(dev, apdev): | |
1456 | sigma_dut_cmd_check("ap_reset_default,program,DPP") | |
1457 | ||
1458 | cmd = "DPP_CONFIGURATOR_ADD" | |
1459 | res = dev[0].request(cmd); | |
1460 | if "FAIL" in res: | |
1461 | raise Exception("Failed to add configurator") | |
1462 | conf_id = int(res) | |
1463 | ||
1464 | t = threading.Thread(target=dpp_init_conf_pkex, args=(dev[0], conf_id)) | |
1465 | t.start() | |
1466 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,PKEX,DPPPKEXCode,password,DPPTimeout,6", timeout=10) | |
1467 | t.join() | |
1468 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: | |
1469 | raise Exception("Unexpected result: " + res) | |
1470 | ||
1471 | sigma_dut_cmd_check("ap_reset_default") | |
8c735316 JM |
1472 | |
1473 | def dpp_proto_init(dev, id1): | |
1474 | time.sleep(1) | |
1475 | logger.info("Starting DPP initiator/configurator in a thread") | |
1476 | cmd = "DPP_CONFIGURATOR_ADD" | |
1477 | res = dev.request(cmd); | |
1478 | if "FAIL" in res: | |
1479 | raise Exception("Failed to add configurator") | |
1480 | conf_id = int(res) | |
1481 | ||
1482 | cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id) | |
1483 | if "OK" not in dev.request(cmd): | |
1484 | raise Exception("Failed to initiate DPP Authentication") | |
1485 | ||
1486 | def test_sigma_dut_dpp_proto_initiator(dev, apdev): | |
1487 | """sigma_dut DPP protocol testing - Initiator""" | |
1488 | check_dpp_capab(dev[0]) | |
1489 | check_dpp_capab(dev[1]) | |
1490 | tests = [ ("InvalidValue", "AuthenticationRequest", "WrappedData", | |
1491 | "BootstrapResult,OK,AuthResult,Errorsent", | |
1492 | None), | |
1493 | ("InvalidValue", "AuthenticationConfirm", "WrappedData", | |
1494 | "BootstrapResult,OK,AuthResult,Errorsent", | |
1495 | None), | |
1496 | ("MissingAttribute", "AuthenticationRequest", "InitCapabilities", | |
1497 | "BootstrapResult,OK,AuthResult,Errorsent", | |
1498 | "Missing or invalid I-capabilities"), | |
1499 | ("InvalidValue", "AuthenticationConfirm", "InitAuthTag", | |
1500 | "BootstrapResult,OK,AuthResult,Errorsent", | |
1501 | "Mismatching Initiator Authenticating Tag"), | |
1502 | ("MissingAttribute", "ConfigurationResponse", "EnrolleeNonce", | |
1503 | "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent", | |
1504 | "Missing or invalid Enrollee Nonce attribute") ] | |
1505 | for step, frame, attr, result, fail in tests: | |
1506 | dev[0].request("FLUSH") | |
1507 | dev[1].request("FLUSH") | |
1508 | sigma = start_sigma_dut(dev[0].ifname) | |
1509 | try: | |
1510 | run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result, | |
1511 | fail) | |
1512 | finally: | |
1513 | stop_sigma_dut(sigma) | |
1514 | ||
1515 | def run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result, fail): | |
1516 | addr = dev[1].own_addr().replace(':', '') | |
1517 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1518 | res = dev[1].request(cmd) | |
1519 | if "FAIL" in res: | |
1520 | raise Exception("Failed to generate bootstrapping info") | |
1521 | id0 = int(res) | |
1522 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1523 | ||
1524 | cmd = "DPP_LISTEN 2437 role=enrollee" | |
1525 | if "OK" not in dev[1].request(cmd): | |
1526 | raise Exception("Failed to start listen operation") | |
1527 | ||
1528 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1529 | if "status,COMPLETE" not in res: | |
1530 | raise Exception("dev_exec_action did not succeed: " + res) | |
1531 | ||
14f8e081 | 1532 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr)) |
8c735316 JM |
1533 | if result not in res: |
1534 | raise Exception("Unexpected result: " + res) | |
1535 | if fail: | |
1536 | ev = dev[1].wait_event(["DPP-FAIL"], timeout=5) | |
1537 | if ev is None or fail not in ev: | |
1538 | raise Exception("Failure not reported correctly: " + str(ev)) | |
1539 | ||
1540 | dev[1].request("DPP_STOP_LISTEN") | |
1541 | dev[0].dump_monitor() | |
1542 | dev[1].dump_monitor() | |
1543 | ||
1544 | def test_sigma_dut_dpp_proto_responder(dev, apdev): | |
1545 | """sigma_dut DPP protocol testing - Responder""" | |
1546 | check_dpp_capab(dev[0]) | |
1547 | check_dpp_capab(dev[1]) | |
1548 | tests = [ ("MissingAttribute", "AuthenticationResponse", "DPPStatus", | |
1549 | "BootstrapResult,OK,AuthResult,Errorsent", | |
1550 | "Missing or invalid required DPP Status attribute"), | |
1551 | ("MissingAttribute", "ConfigurationRequest", "EnrolleeNonce", | |
1552 | "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent", | |
1553 | "Missing or invalid Enrollee Nonce attribute") ] | |
1554 | for step, frame, attr, result, fail in tests: | |
1555 | dev[0].request("FLUSH") | |
1556 | dev[1].request("FLUSH") | |
1557 | sigma = start_sigma_dut(dev[0].ifname) | |
1558 | try: | |
1559 | run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result, | |
1560 | fail) | |
1561 | finally: | |
1562 | stop_sigma_dut(sigma) | |
1563 | ||
1564 | def run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result, fail): | |
1565 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") | |
1566 | if "status,COMPLETE" not in res: | |
1567 | raise Exception("dev_exec_action did not succeed: " + res) | |
1568 | hex = res.split(',')[3] | |
1569 | uri = hex.decode('hex') | |
1570 | logger.info("URI from sigma_dut: " + uri) | |
1571 | ||
1572 | res = dev[1].request("DPP_QR_CODE " + uri) | |
1573 | if "FAIL" in res: | |
1574 | raise Exception("Failed to parse QR Code URI") | |
1575 | id1 = int(res) | |
1576 | ||
1577 | t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1)) | |
1578 | t.start() | |
14f8e081 | 1579 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr), timeout=10) |
8c735316 JM |
1580 | t.join() |
1581 | if result not in res: | |
1582 | raise Exception("Unexpected result: " + res) | |
1583 | if fail: | |
1584 | ev = dev[1].wait_event(["DPP-FAIL"], timeout=5) | |
1585 | if ev is None or fail not in ev: | |
1586 | raise Exception("Failure not reported correctly:" + str(ev)) | |
1587 | ||
1588 | dev[1].request("DPP_STOP_LISTEN") | |
1589 | dev[0].dump_monitor() | |
1590 | dev[1].dump_monitor() | |
1591 | ||
c79b9db0 JM |
1592 | def test_sigma_dut_dpp_proto_stop_at_initiator(dev, apdev): |
1593 | """sigma_dut DPP protocol testing - Stop at RX on Initiator""" | |
1594 | check_dpp_capab(dev[0]) | |
1595 | check_dpp_capab(dev[1]) | |
1596 | tests = [ ("AuthenticationResponse", | |
1597 | "BootstrapResult,OK,AuthResult,Errorsent", | |
1598 | None), | |
1599 | ("ConfigurationRequest", | |
1600 | "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent", | |
1601 | None)] | |
1602 | for frame, result, fail in tests: | |
1603 | dev[0].request("FLUSH") | |
1604 | dev[1].request("FLUSH") | |
1605 | sigma = start_sigma_dut(dev[0].ifname) | |
1606 | try: | |
1607 | run_sigma_dut_dpp_proto_stop_at_initiator(dev, frame, result, fail) | |
1608 | finally: | |
1609 | stop_sigma_dut(sigma) | |
1610 | ||
1611 | def run_sigma_dut_dpp_proto_stop_at_initiator(dev, frame, result, fail): | |
1612 | addr = dev[1].own_addr().replace(':', '') | |
1613 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1614 | res = dev[1].request(cmd) | |
1615 | if "FAIL" in res: | |
1616 | raise Exception("Failed to generate bootstrapping info") | |
1617 | id0 = int(res) | |
1618 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1619 | ||
1620 | cmd = "DPP_LISTEN 2437 role=enrollee" | |
1621 | if "OK" not in dev[1].request(cmd): | |
1622 | raise Exception("Failed to start listen operation") | |
1623 | ||
1624 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1625 | if "status,COMPLETE" not in res: | |
1626 | raise Exception("dev_exec_action did not succeed: " + res) | |
1627 | ||
1628 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,Timeout,DPPFrameType,%s" % (frame)) | |
1629 | if result not in res: | |
1630 | raise Exception("Unexpected result: " + res) | |
1631 | if fail: | |
1632 | ev = dev[1].wait_event(["DPP-FAIL"], timeout=5) | |
1633 | if ev is None or fail not in ev: | |
1634 | raise Exception("Failure not reported correctly: " + str(ev)) | |
1635 | ||
1636 | dev[1].request("DPP_STOP_LISTEN") | |
1637 | dev[0].dump_monitor() | |
1638 | dev[1].dump_monitor() | |
1639 | ||
1640 | def test_sigma_dut_dpp_proto_stop_at_responder(dev, apdev): | |
1641 | """sigma_dut DPP protocol testing - Stop at RX on Responder""" | |
1642 | check_dpp_capab(dev[0]) | |
1643 | check_dpp_capab(dev[1]) | |
1644 | tests = [ ("AuthenticationRequest", | |
1645 | "BootstrapResult,OK,AuthResult,Errorsent", | |
1646 | None), | |
1647 | ("AuthenticationConfirm", | |
1648 | "BootstrapResult,OK,AuthResult,Errorsent", | |
1649 | None) ] | |
1650 | for frame, result, fail in tests: | |
1651 | dev[0].request("FLUSH") | |
1652 | dev[1].request("FLUSH") | |
1653 | sigma = start_sigma_dut(dev[0].ifname) | |
1654 | try: | |
1655 | run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail) | |
1656 | finally: | |
1657 | stop_sigma_dut(sigma) | |
1658 | ||
1659 | def run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail): | |
1660 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") | |
1661 | if "status,COMPLETE" not in res: | |
1662 | raise Exception("dev_exec_action did not succeed: " + res) | |
1663 | hex = res.split(',')[3] | |
1664 | uri = hex.decode('hex') | |
1665 | logger.info("URI from sigma_dut: " + uri) | |
1666 | ||
1667 | res = dev[1].request("DPP_QR_CODE " + uri) | |
1668 | if "FAIL" in res: | |
1669 | raise Exception("Failed to parse QR Code URI") | |
1670 | id1 = int(res) | |
1671 | ||
1672 | t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1)) | |
1673 | t.start() | |
1674 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,Timeout,DPPFrameType,%s" % (frame), timeout=10) | |
1675 | t.join() | |
1676 | if result not in res: | |
1677 | raise Exception("Unexpected result: " + res) | |
1678 | if fail: | |
1679 | ev = dev[1].wait_event(["DPP-FAIL"], timeout=5) | |
1680 | if ev is None or fail not in ev: | |
1681 | raise Exception("Failure not reported correctly:" + str(ev)) | |
1682 | ||
1683 | dev[1].request("DPP_STOP_LISTEN") | |
1684 | dev[0].dump_monitor() | |
1685 | dev[1].dump_monitor() | |
1686 | ||
8c735316 JM |
1687 | def dpp_proto_init_pkex(dev): |
1688 | time.sleep(1) | |
1689 | logger.info("Starting DPP PKEX initiator/configurator in a thread") | |
1690 | cmd = "DPP_CONFIGURATOR_ADD" | |
1691 | res = dev.request(cmd); | |
1692 | if "FAIL" in res: | |
1693 | raise Exception("Failed to add configurator") | |
1694 | conf_id = int(res) | |
1695 | ||
1696 | cmd = "DPP_BOOTSTRAP_GEN type=pkex" | |
1697 | res = dev.request(cmd) | |
1698 | if "FAIL" in res: | |
1699 | raise Exception("Failed to generate bootstrapping info") | |
1700 | id = int(res) | |
1701 | ||
1702 | cmd = "DPP_PKEX_ADD own=%d init=1 conf=sta-dpp configurator=%d code=secret" % (id, conf_id) | |
1703 | if "FAIL" in dev.request(cmd): | |
1704 | raise Exception("Failed to initiate DPP PKEX") | |
1705 | ||
1706 | def test_sigma_dut_dpp_proto_initiator_pkex(dev, apdev): | |
1707 | """sigma_dut DPP protocol testing - Initiator (PKEX)""" | |
1708 | check_dpp_capab(dev[0]) | |
1709 | check_dpp_capab(dev[1]) | |
1710 | tests = [ ("InvalidValue", "PKEXCRRequest", "WrappedData", | |
1711 | "BootstrapResult,Errorsent", | |
1712 | None), | |
1713 | ("MissingAttribute", "PKEXExchangeRequest", "FiniteCyclicGroup", | |
1714 | "BootstrapResult,Errorsent", | |
1715 | "Missing or invalid Finite Cyclic Group attribute"), | |
1716 | ("MissingAttribute", "PKEXCRRequest", "BSKey", | |
1717 | "BootstrapResult,Errorsent", | |
1718 | "No valid peer bootstrapping key found") ] | |
1719 | for step, frame, attr, result, fail in tests: | |
1720 | dev[0].request("FLUSH") | |
1721 | dev[1].request("FLUSH") | |
1722 | sigma = start_sigma_dut(dev[0].ifname) | |
1723 | try: | |
1724 | run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr, | |
1725 | result, fail) | |
1726 | finally: | |
1727 | stop_sigma_dut(sigma) | |
1728 | ||
1729 | def run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr, result, fail): | |
1730 | cmd = "DPP_BOOTSTRAP_GEN type=pkex" | |
1731 | res = dev[1].request(cmd) | |
1732 | if "FAIL" in res: | |
1733 | raise Exception("Failed to generate bootstrapping info") | |
1734 | id1 = int(res) | |
1735 | ||
1736 | cmd = "DPP_PKEX_ADD own=%d code=secret" % (id1) | |
1737 | res = dev[1].request(cmd) | |
1738 | if "FAIL" in res: | |
1739 | raise Exception("Failed to set PKEX data (responder)") | |
1740 | ||
1741 | cmd = "DPP_LISTEN 2437 role=enrollee" | |
1742 | if "OK" not in dev[1].request(cmd): | |
1743 | raise Exception("Failed to start listen operation") | |
1744 | ||
14f8e081 | 1745 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCode,secret,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr)) |
8c735316 JM |
1746 | if result not in res: |
1747 | raise Exception("Unexpected result: " + res) | |
1748 | if fail: | |
1749 | ev = dev[1].wait_event(["DPP-FAIL"], timeout=5) | |
1750 | if ev is None or fail not in ev: | |
1751 | raise Exception("Failure not reported correctly: " + str(ev)) | |
1752 | ||
1753 | dev[1].request("DPP_STOP_LISTEN") | |
1754 | dev[0].dump_monitor() | |
1755 | dev[1].dump_monitor() | |
1756 | ||
1757 | def test_sigma_dut_dpp_proto_responder_pkex(dev, apdev): | |
1758 | """sigma_dut DPP protocol testing - Responder (PKEX)""" | |
1759 | check_dpp_capab(dev[0]) | |
1760 | check_dpp_capab(dev[1]) | |
1761 | tests = [ ("InvalidValue", "PKEXCRResponse", "WrappedData", | |
1762 | "BootstrapResult,Errorsent", | |
1763 | None), | |
1764 | ("MissingAttribute", "PKEXExchangeResponse", "DPPStatus", | |
1765 | "BootstrapResult,Errorsent", | |
1766 | "No DPP Status attribute"), | |
1767 | ("MissingAttribute", "PKEXCRResponse", "BSKey", | |
1768 | "BootstrapResult,Errorsent", | |
1769 | "No valid peer bootstrapping key found") ] | |
1770 | for step, frame, attr, result, fail in tests: | |
1771 | dev[0].request("FLUSH") | |
1772 | dev[1].request("FLUSH") | |
1773 | sigma = start_sigma_dut(dev[0].ifname) | |
1774 | try: | |
1775 | run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr, | |
1776 | result, fail) | |
1777 | finally: | |
1778 | stop_sigma_dut(sigma) | |
1779 | ||
1780 | def run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr, result, fail): | |
1781 | t = threading.Thread(target=dpp_proto_init_pkex, args=(dev[1],)) | |
1782 | t.start() | |
14f8e081 | 1783 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCode,secret,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr), timeout=10) |
8c735316 JM |
1784 | t.join() |
1785 | if result not in res: | |
1786 | raise Exception("Unexpected result: " + res) | |
1787 | if fail: | |
1788 | ev = dev[1].wait_event(["DPP-FAIL"], timeout=5) | |
1789 | if ev is None or fail not in ev: | |
1790 | raise Exception("Failure not reported correctly:" + str(ev)) | |
1791 | ||
1792 | dev[1].request("DPP_STOP_LISTEN") | |
1793 | dev[0].dump_monitor() | |
1794 | dev[1].dump_monitor() | |
a0604a42 JM |
1795 | |
1796 | def init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev): | |
1797 | check_dpp_capab(dev[0]) | |
1798 | check_dpp_capab(dev[1]) | |
1799 | ||
1800 | csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
1801 | csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708" | |
1802 | ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg" | |
1803 | ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b" | |
1804 | ||
1805 | params = { "ssid": "DPPNET01", | |
1806 | "wpa": "2", | |
1807 | "wpa_key_mgmt": "DPP", | |
1808 | "rsn_pairwise": "CCMP", | |
1809 | "dpp_connector": ap_connector, | |
1810 | "dpp_csign": csign_pub, | |
1811 | "dpp_netaccesskey": ap_netaccesskey } | |
1812 | try: | |
1813 | hapd = hostapd.add_ap(apdev[0], params) | |
1814 | except: | |
1815 | raise HwsimSkip("DPP not supported") | |
1816 | ||
1817 | dev[0].set("dpp_config_processing", "2") | |
1818 | ||
1819 | cmd = "DPP_CONFIGURATOR_ADD key=" + csign | |
1820 | res = dev[1].request(cmd); | |
1821 | if "FAIL" in res: | |
1822 | raise Exception("Failed to add configurator") | |
1823 | conf_id = int(res) | |
1824 | ||
1825 | addr = dev[1].own_addr().replace(':', '') | |
1826 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr | |
1827 | res = dev[1].request(cmd) | |
1828 | if "FAIL" in res: | |
1829 | raise Exception("Failed to generate bootstrapping info") | |
1830 | id0 = int(res) | |
1831 | uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) | |
1832 | ||
1833 | dev[1].set("dpp_configurator_params", | |
1834 | " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id)); | |
1835 | cmd = "DPP_LISTEN 2437 role=configurator" | |
1836 | if "OK" not in dev[1].request(cmd): | |
1837 | raise Exception("Failed to start listen operation") | |
1838 | ||
1839 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) | |
1840 | if "status,COMPLETE" not in res: | |
1841 | raise Exception("dev_exec_action did not succeed: " + res) | |
1842 | ||
1843 | def test_sigma_dut_dpp_proto_peer_disc_req(dev, apdev): | |
1844 | """sigma_dut DPP protocol testing - Peer Discovery Request""" | |
1845 | sigma = start_sigma_dut(dev[0].ifname) | |
1846 | try: | |
1847 | init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev) | |
1848 | ||
1849 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes,DPPStep,MissingAttribute,DPPFrameType,PeerDiscoveryRequest,DPPIEAttribute,TransactionID", timeout=10) | |
1850 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent" not in res: | |
1851 | raise Exception("Unexpected result: " + res) | |
1852 | finally: | |
1853 | dev[0].set("dpp_config_processing", "0") | |
1854 | stop_sigma_dut(sigma) | |
211b5d1b JM |
1855 | |
1856 | def test_sigma_dut_dpp_self_config(dev, apdev): | |
1857 | """sigma_dut DPP Configurator enrolling an AP and using self-configuration""" | |
1858 | check_dpp_capab(dev[0]) | |
1859 | ||
1860 | hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" }) | |
1861 | check_dpp_capab(hapd) | |
1862 | ||
1863 | sigma = start_sigma_dut(dev[0].ifname) | |
1864 | try: | |
1865 | dev[0].set("dpp_config_processing", "2") | |
1866 | addr = hapd.own_addr().replace(':', '') | |
1867 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr | |
1868 | res = hapd.request(cmd) | |
1869 | if "FAIL" in res: | |
1870 | raise Exception("Failed to generate bootstrapping info") | |
1871 | id = int(res) | |
1872 | uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id) | |
1873 | ||
1874 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri.encode('hex')) | |
1875 | if "status,COMPLETE" not in res: | |
1876 | raise Exception("dev_exec_action did not succeed: " + res) | |
1877 | ||
1878 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,AP,DPPBS,QR,DPPTimeout,6") | |
1879 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: | |
1880 | raise Exception("Unexpected result: " + res) | |
1881 | update_hapd_config(hapd) | |
1882 | ||
1883 | cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPCryptoIdentifier,P-256,DPPBS,QR,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPAuthDirection,Single,DPPConfIndex,1,DPPTimeout,6,DPPWaitForConnect,Yes,DPPSelfConfigure,Yes" | |
1884 | res = sigma_dut_cmd(cmd, timeout=10) | |
1885 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res: | |
1886 | raise Exception("Unexpected result: " + res) | |
1887 | finally: | |
1888 | stop_sigma_dut(sigma) | |
1889 | dev[0].set("dpp_config_processing", "0") | |
8b4adc38 JM |
1890 | |
1891 | def test_sigma_dut_ap_dpp_self_config(dev, apdev, params): | |
1892 | """sigma_dut DPP AP Configurator using self-configuration""" | |
1893 | logdir = os.path.join(params['logdir'], | |
1894 | "sigma_dut_ap_dpp_self_config.sigma-hostapd") | |
1895 | with HWSimRadio() as (radio, iface): | |
1896 | sigma = start_sigma_dut(iface, hostapd_logdir=logdir) | |
1897 | try: | |
1898 | run_sigma_dut_ap_dpp_self_config(dev, apdev) | |
1899 | finally: | |
1900 | stop_sigma_dut(sigma) | |
1901 | dev[0].set("dpp_config_processing", "0") | |
1902 | ||
1903 | def run_sigma_dut_ap_dpp_self_config(dev, apdev): | |
1904 | check_dpp_capab(dev[0]) | |
1905 | ||
1906 | sigma_dut_cmd_check("ap_reset_default,program,DPP") | |
1907 | ||
1908 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,AP,DPPBS,QR,DPPConfIndex,1,DPPSelfConfigure,Yes,DPPTimeout,6", timeout=10) | |
1909 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: | |
1910 | raise Exception("Unexpected result: " + res) | |
1911 | ||
1912 | dev[0].set("dpp_config_processing", "2") | |
1913 | ||
1914 | addr = dev[0].own_addr().replace(':', '') | |
1915 | cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/11 mac=" + addr | |
1916 | res = dev[0].request(cmd) | |
1917 | if "FAIL" in res: | |
1918 | raise Exception("Failed to generate bootstrapping info") | |
1919 | id = int(res) | |
1920 | uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id) | |
1921 | cmd = "DPP_LISTEN 2462 role=enrollee" | |
1922 | if "OK" not in dev[0].request(cmd): | |
1923 | raise Exception("Failed to start listen operation") | |
1924 | ||
1925 | res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri.encode('hex')) | |
1926 | if "status,COMPLETE" not in res: | |
1927 | raise Exception("dev_exec_action did not succeed: " + res) | |
1928 | cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6" | |
1929 | res = sigma_dut_cmd(cmd) | |
1930 | if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: | |
1931 | raise Exception("Unexpected result: " + res) | |
1932 | dev[0].wait_connected() | |
1933 | dev[0].request("DISCONNECT") | |
1934 | dev[0].wait_disconnected() | |
1935 | sigma_dut_cmd_check("ap_reset_default") | |
6923312d JM |
1936 | |
1937 | def test_sigma_dut_preconfigured_profile(dev, apdev): | |
1938 | """sigma_dut controlled connection using preconfigured profile""" | |
1939 | try: | |
1940 | run_sigma_dut_preconfigured_profile(dev, apdev) | |
1941 | finally: | |
1942 | dev[0].set("ignore_old_scan_res", "0") | |
1943 | ||
1944 | def run_sigma_dut_preconfigured_profile(dev, apdev): | |
1945 | ifname = dev[0].ifname | |
1946 | sigma = start_sigma_dut(ifname) | |
1947 | ||
1948 | params = hostapd.wpa2_params(ssid="test-psk", passphrase="12345678") | |
1949 | hapd = hostapd.add_ap(apdev[0], params) | |
1950 | dev[0].connect("test-psk", psk="12345678", scan_freq="2412", | |
1951 | only_add_network=True) | |
1952 | ||
1953 | sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname) | |
1954 | sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "test-psk")) | |
1955 | sigma_dut_wait_connected(ifname) | |
1956 | sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname) | |
1957 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
1958 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
1959 | ||
1960 | stop_sigma_dut(sigma) | |
ce83008c JM |
1961 | |
1962 | def test_sigma_dut_wps_pbc(dev, apdev): | |
1963 | """sigma_dut and WPS PBC Enrollee""" | |
1964 | try: | |
1965 | run_sigma_dut_wps_pbc(dev, apdev) | |
1966 | finally: | |
1967 | dev[0].set("ignore_old_scan_res", "0") | |
1968 | ||
1969 | def run_sigma_dut_wps_pbc(dev, apdev): | |
1970 | ssid = "test-wps-conf" | |
1971 | hapd = hostapd.add_ap(apdev[0], | |
1972 | { "ssid": "wps", "eap_server": "1", "wps_state": "2", | |
1973 | "wpa_passphrase": "12345678", "wpa": "2", | |
1974 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
1975 | hapd.request("WPS_PBC") | |
1976 | ||
1977 | ifname = dev[0].ifname | |
1978 | sigma = start_sigma_dut(ifname) | |
1979 | ||
1980 | cmd = "start_wps_registration,interface,%s" % ifname | |
1981 | cmd += ",WpsRole,Enrollee" | |
1982 | cmd += ",WpsConfigMethod,PBC" | |
1983 | sigma_dut_cmd_check(cmd, timeout=15) | |
1984 | ||
1985 | sigma_dut_cmd_check("sta_disconnect,interface," + ifname) | |
1986 | hapd.disable() | |
1987 | sigma_dut_cmd_check("sta_reset_default,interface," + ifname) | |
1988 | stop_sigma_dut(sigma) | |
1989 | dev[0].flush_scan_cache() |