1 # Test cases for Device Provisioning Protocol (DPP)
2 # Copyright (c) 2017, Qualcomm Atheros, Inc.
3 # Copyright (c) 2018-2019, The Linux Foundation
5 # This software may be distributed under the terms of the BSD license.
6 # See README for more details.
12 logger
= logging
.getLogger()
21 from hwsim
import HWSimRadio
22 from utils
import HwsimSkip
, alloc_fail
, fail_test
, wait_fail_trigger
23 from wpasupplicant
import WpaSupplicant
24 from wlantest
import WlantestCapture
28 openssl_imported
= True
30 openssl_imported
= False
32 def check_dpp_capab(dev
, brainpool
=False, min_ver
=1):
33 if "UNKNOWN COMMAND" in dev
.request("DPP_BOOTSTRAP_GET_URI 0"):
34 raise HwsimSkip("DPP not supported")
36 tls
= dev
.request("GET tls_library")
37 if not tls
.startswith("OpenSSL") or "run=BoringSSL" in tls
:
38 raise HwsimSkip("Crypto library does not support Brainpool curves: " + tls
)
39 capa
= dev
.request("GET_CAPABILITY dpp")
41 if capa
.startswith("DPP="):
44 raise HwsimSkip("DPP version %d not supported" % min_ver
)
47 def wait_dpp_fail(dev
, expected
=None):
48 ev
= dev
.wait_event(["DPP-FAIL"], timeout
=5)
50 raise Exception("Failure not reported")
51 if expected
and expected
not in ev
:
52 raise Exception("Unexpected result: " + ev
)
54 def test_dpp_qr_code_parsing(dev
, apdev
):
55 """DPP QR Code parsing"""
56 check_dpp_capab(dev
[0])
59 tests
= ["DPP:C:81/1,115/36;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkq/24e0rsrfMP9K1Tm8gx+ovP0I=;;",
60 "DPP:C:81/1,81/2,81/3,81/4,81/5,81/6,81/7,81/8,81/9,81/10,81/11,81/12,81/13,82/14,83/1,83/2,83/3,83/4,83/5,83/6,83/7,83/8,83/9,84/5,84/6,84/7,84/8,84/9,84/10,84/11,84/12,84/13,115/36;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkq/24e0rsrfMP9K1Tm8gx+ovP0I=;;",
61 "DPP:C:81/1,2,3,4,5,6,7,8,9,10,11,12,13,82/14,83/1,2,3,4,5,6,7,8,9,84/5,6,7,8,9,10,11,12,13,115/36;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkq/24e0rsrfMP9K1Tm8gx+ovP0I=;;",
62 "DPP:C:81/1,2,3;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkq/24e0rsrfMP9K1Tm8gx+ovP0I=;;",
63 "DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
64 "DPP:I:;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;"]
66 id.append(dev
[0].dpp_qr_code(uri
))
68 uri2
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id[-1])
70 raise Exception("Returned URI does not match")
76 "DPP:I:;M:01020304050;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
77 "DPP:K:" + base64
.b64encode(b
"hello").decode() + ";;",
78 "DPP:K:MEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEXiJuIWt1Q/CPCkuULechh37UsXPmbUANOeN5U9sOQROE4o/NEFeFEejROHYwwehF;;",
79 "DPP:K:MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANNZaZA4T/kRDjnmpI1ACOJhAuTIIEk2KFOpS6XPpGF+EVr/ao3XemkE0/nzXmGaLzLqTUCJknSdxTnVPeWfCVsCAwEAAQ==;;",
80 "DPP:K:MIIBCjCB0wYHKoZIzj0CATCBxwIBATAkBgcqhkjOPQEBAhkA/////////////////////v//////////MEsEGP////////////////////7//////////AQYZCEFGeWcgOcPp+mrciQwSf643uzBRrmxAxUAMEWub8hCL2TtV5Uo04Eg6uEhltUEMQQYjagOsDCQ9ny/IOtDoYgA9P8K/YL/EBIHGSuV/8jaeGMQEe1rJM3Vc/l3oR55SBECGQD///////////////+Z3vg2FGvJsbTSKDECAQEDMgAEXiJuIWt1Q/CPCkuULechh37UsXPmbUANOeN5U9sOQROE4o/NEFeFEejROHYwwehF;;",
81 "DPP:I:foo\tbar;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
82 "DPP:C:1;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkqa24e0rsrfMP9K1Tm8gx+ovP0I=;;",
83 "DPP:C:81/1a;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkqa24e0rsrfMP9K1Tm8gx+ovP0I=;;",
84 "DPP:C:1/2000,81/-1;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkqa24e0rsrfMP9K1Tm8gx+ovP0I=;;",
85 "DPP:C:-1/1;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkqa24e0rsrfMP9K1Tm8gx+ovP0I=;;"]
87 res
= dev
[0].request("DPP_QR_CODE " + t
)
89 raise Exception("Accepted invalid QR Code: " + t
)
91 logger
.info("ID: " + str(id))
92 if id[0] == id[1] or id[0] == id[2] or id[1] == id[2]:
93 raise Exception("Duplicate ID returned")
95 if "FAIL" not in dev
[0].request("DPP_BOOTSTRAP_REMOVE 12345678"):
96 raise Exception("DPP_BOOTSTRAP_REMOVE accepted unexpectedly")
97 if "OK" not in dev
[0].request("DPP_BOOTSTRAP_REMOVE %d" % id[1]):
98 raise Exception("DPP_BOOTSTRAP_REMOVE failed")
100 id = dev
[0].dpp_bootstrap_gen()
101 uri
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
102 logger
.info("Generated URI: " + uri
)
104 dev
[0].dpp_qr_code(uri
)
106 id = dev
[0].dpp_bootstrap_gen(chan
="81/1,115/36", mac
="010203040506",
108 uri
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
109 logger
.info("Generated URI: " + uri
)
111 dev
[0].dpp_qr_code(uri
)
113 def test_dpp_qr_code_parsing_fail(dev
, apdev
):
114 """DPP QR Code parsing local failure"""
115 check_dpp_capab(dev
[0])
116 with
alloc_fail(dev
[0], 1, "dpp_parse_uri_info"):
117 if "FAIL" not in dev
[0].request("DPP_QR_CODE DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;"):
118 raise Exception("DPP_QR_CODE failure not reported")
120 with
alloc_fail(dev
[0], 1, "dpp_parse_uri_pk"):
121 if "FAIL" not in dev
[0].request("DPP_QR_CODE DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;"):
122 raise Exception("DPP_QR_CODE failure not reported")
124 with
fail_test(dev
[0], 1, "dpp_parse_uri_pk"):
125 if "FAIL" not in dev
[0].request("DPP_QR_CODE DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;"):
126 raise Exception("DPP_QR_CODE failure not reported")
128 with
alloc_fail(dev
[0], 1, "dpp_parse_uri"):
129 if "FAIL" not in dev
[0].request("DPP_QR_CODE DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;"):
130 raise Exception("DPP_QR_CODE failure not reported")
132 dpp_key_p256
= "30570201010420777fc55dc51e967c10ec051b91d860b5f1e6c934e48d5daffef98d032c64b170a00a06082a8648ce3d030107a124032200020c804188c7f85beb6e91070d2b3e5e39b90ca77b4d3c5251bc1844d6ca29dcad"
133 dpp_key_p384
= "307402010104302f56fdd83b5345cacb630eb7c22fa5ad5daba37307c95191e2a75756d137003bd8b32dbcb00eb5650c1eb499ecfcaec0a00706052b81040022a13403320003615ec2141b5b77aebb6523f8a012755f9a34405a8398d2ceeeebca7f5ce868bf55056cba4c4ec62fad3ed26dd29e0f23"
134 dpp_key_p521
= "308198020101044200c8010d5357204c252551aaf4e210343111e503fd1dc615b257058997c49b6b643c975226e93be8181cca3d83a7072defd161dfbdf433c19abe1f2ad51867a05761a00706052b81040023a1460344000301cdf3608b1305fe34a1f976095dcf001182b9973354efe156291a66830292f9babd8f412ad462958663e7a75d1d0610abdfc3dd95d40669f7ab3bc001668cfb3b7c"
135 dpp_key_bp256
= "3058020101042057133a676fb60bf2a3e6797e19833c7b0f89dc192ab99ab5fa377ae23a157765a00b06092b2403030208010107a12403220002945d9bf7ce30c9c1ac0ff21ca62b984d5bb80ff69d2be8c9716ab39a10d2caf0"
136 dpp_key_bp384
= "307802010104304902df9f3033a9b7128554c0851dc7127c3573eed150671dae74c0013e9896a9b1c22b6f7d43d8a2ebb7cd474dc55039a00b06092b240303020801010ba13403320003623cb5e68787f351faababf3425161571560add2e6f9a306fcbffb507735bf955bb46dd20ba246b0d5cadce73e5bd6a6"
137 dpp_key_bp512
= "30819802010104405803494226eb7e50bf0e90633f37e7e35d33f5fa502165eeba721d927f9f846caf12e925701d18e123abaaaf4a7edb4fc4de21ce18bc10c4d12e8b3439f74e40a00b06092b240303020801010da144034200033b086ccd47486522d35dc16fbb2229642c2e9e87897d45abbf21f9fb52acb5a6272b31d1b227c3e53720769cc16b4cb181b26cd0d35fe463218aaedf3b6ec00a"
139 def test_dpp_qr_code_curves(dev
, apdev
):
140 """DPP QR Code and supported curves"""
141 check_dpp_capab(dev
[0])
142 tests
= [("prime256v1", dpp_key_p256
),
143 ("secp384r1", dpp_key_p384
),
144 ("secp521r1", dpp_key_p521
)]
145 for curve
, hex in tests
:
146 id = dev
[0].dpp_bootstrap_gen(key
=hex)
147 info
= dev
[0].request("DPP_BOOTSTRAP_INFO %d" % id)
149 raise Exception("Failed to get info for " + curve
)
150 if "curve=" + curve
not in info
:
151 raise Exception("Curve mismatch for " + curve
)
153 def test_dpp_qr_code_curves_brainpool(dev
, apdev
):
154 """DPP QR Code and supported Brainpool curves"""
155 check_dpp_capab(dev
[0], brainpool
=True)
156 tests
= [("brainpoolP256r1", dpp_key_bp256
),
157 ("brainpoolP384r1", dpp_key_bp384
),
158 ("brainpoolP512r1", dpp_key_bp512
)]
159 for curve
, hex in tests
:
160 id = dev
[0].dpp_bootstrap_gen(key
=hex)
161 info
= dev
[0].request("DPP_BOOTSTRAP_INFO %d" % id)
163 raise Exception("Failed to get info for " + curve
)
164 if "curve=" + curve
not in info
:
165 raise Exception("Curve mismatch for " + curve
)
167 def test_dpp_qr_code_unsupported_curve(dev
, apdev
):
168 """DPP QR Code and unsupported curve"""
169 check_dpp_capab(dev
[0])
171 id = dev
[0].request("DPP_BOOTSTRAP_GEN type=qrcode curve=unsupported")
173 raise Exception("Unsupported curve accepted")
176 "305f02010104187f723ed9e1b41979ec5cd02eb82696efc76b40e277661049a00a06082a8648ce3d030101a134033200043f292614dea97c43f500f069e79ae9fb48f8b07369180de5eec8fa2bc9eea5af7a46dc335f52f10cb1c0e9464201d41b"]
178 id = dev
[0].request("DPP_BOOTSTRAP_GEN type=qrcode key=" + hex)
180 raise Exception("Unsupported/invalid curve accepted")
182 def test_dpp_qr_code_keygen_fail(dev
, apdev
):
183 """DPP QR Code and keygen failure"""
184 check_dpp_capab(dev
[0])
186 with
alloc_fail(dev
[0], 1, "dpp_bootstrap_key_der;dpp_keygen"):
187 if "FAIL" not in dev
[0].request("DPP_BOOTSTRAP_GEN type=qrcode"):
188 raise Exception("Failure not reported")
190 with
alloc_fail(dev
[0], 1, "base64_gen_encode;dpp_keygen"):
191 if "FAIL" not in dev
[0].request("DPP_BOOTSTRAP_GEN type=qrcode"):
192 raise Exception("Failure not reported")
194 def test_dpp_qr_code_curve_select(dev
, apdev
):
195 """DPP QR Code and curve selection"""
196 check_dpp_capab(dev
[0], brainpool
=True)
197 check_dpp_capab(dev
[1], brainpool
=True)
200 for key
in [dpp_key_p256
, dpp_key_p384
, dpp_key_p521
,
201 dpp_key_bp256
, dpp_key_bp384
, dpp_key_bp512
]:
202 id = dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True, key
=key
)
203 info
= dev
[0].request("DPP_BOOTSTRAP_INFO %d" % id)
204 for i
in info
.splitlines():
206 name
, val
= i
.split('=')
210 uri
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
211 bi
.append((curve
, uri
))
213 for curve
, uri
in bi
:
214 logger
.info("Curve: " + curve
)
215 logger
.info("URI: " + uri
)
217 dev
[0].dpp_listen(2412)
218 dev
[1].dpp_auth_init(uri
=uri
)
219 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0],
220 allow_enrollee_failure
=True, stop_responder
=True,
223 def test_dpp_qr_code_auth_broadcast(dev
, apdev
):
224 """DPP QR Code and authentication exchange (broadcast)"""
225 check_dpp_capab(dev
[0])
226 check_dpp_capab(dev
[1])
227 logger
.info("dev0 displays QR Code")
228 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1")
229 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
230 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
231 dev
[0].dpp_listen(2412)
232 dev
[1].dpp_auth_init(uri
=uri0
)
233 wait_auth_success(dev
[0], dev
[1], stop_responder
=True)
235 def test_dpp_qr_code_auth_unicast(dev
, apdev
):
236 """DPP QR Code and authentication exchange (unicast)"""
237 run_dpp_qr_code_auth_unicast(dev
, apdev
, None)
239 def test_dpp_qr_code_auth_unicast_ap_enrollee(dev
, apdev
):
240 """DPP QR Code and authentication exchange (AP enrollee)"""
241 run_dpp_qr_code_auth_unicast(dev
, apdev
, None, netrole
="ap")
243 def run_dpp_configurator_enrollee(dev
, apdev
, conf_curve
=None):
244 run_dpp_qr_code_auth_unicast(dev
, apdev
, None, netrole
="configurator",
245 configurator
=True, conf_curve
=conf_curve
)
246 ev
= dev
[0].wait_event(["DPP-CONFIGURATOR-ID"], timeout
=2)
248 raise Exception("No Configurator instance added")
250 def test_dpp_configurator_enrollee(dev
, apdev
):
251 """DPP Configurator enrolling"""
252 run_dpp_configurator_enrollee(dev
, apdev
)
254 def test_dpp_configurator_enrollee_prime256v1(dev
, apdev
):
255 """DPP Configurator enrolling (prime256v1)"""
256 run_dpp_configurator_enrollee(dev
, apdev
, conf_curve
="prime256v1")
258 def test_dpp_configurator_enrollee_secp384r1(dev
, apdev
):
259 """DPP Configurator enrolling (secp384r1)"""
260 run_dpp_configurator_enrollee(dev
, apdev
, conf_curve
="secp384r1")
262 def test_dpp_configurator_enrollee_secp521r1(dev
, apdev
):
263 """DPP Configurator enrolling (secp521r1)"""
264 run_dpp_configurator_enrollee(dev
, apdev
, conf_curve
="secp521r1")
266 def test_dpp_configurator_enrollee_brainpoolP256r1(dev
, apdev
):
267 """DPP Configurator enrolling (brainpoolP256r1)"""
268 run_dpp_configurator_enrollee(dev
, apdev
, conf_curve
="brainpoolP256r1")
270 def test_dpp_configurator_enrollee_brainpoolP384r1(dev
, apdev
):
271 """DPP Configurator enrolling (brainpoolP384r1)"""
272 run_dpp_configurator_enrollee(dev
, apdev
, conf_curve
="brainpoolP384r1")
274 def test_dpp_configurator_enrollee_brainpoolP512r1(dev
, apdev
):
275 """DPP Configurator enrolling (brainpoolP512r1)"""
276 run_dpp_configurator_enrollee(dev
, apdev
, conf_curve
="brainpoolP512r1")
278 def test_dpp_qr_code_curve_prime256v1(dev
, apdev
):
279 """DPP QR Code and curve prime256v1"""
280 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1")
282 def test_dpp_qr_code_curve_secp384r1(dev
, apdev
):
283 """DPP QR Code and curve secp384r1"""
284 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp384r1")
286 def test_dpp_qr_code_curve_secp521r1(dev
, apdev
):
287 """DPP QR Code and curve secp521r1"""
288 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp521r1")
290 def test_dpp_qr_code_curve_brainpoolP256r1(dev
, apdev
):
291 """DPP QR Code and curve brainpoolP256r1"""
292 run_dpp_qr_code_auth_unicast(dev
, apdev
, "brainpoolP256r1")
294 def test_dpp_qr_code_curve_brainpoolP384r1(dev
, apdev
):
295 """DPP QR Code and curve brainpoolP384r1"""
296 run_dpp_qr_code_auth_unicast(dev
, apdev
, "brainpoolP384r1")
298 def test_dpp_qr_code_curve_brainpoolP512r1(dev
, apdev
):
299 """DPP QR Code and curve brainpoolP512r1"""
300 run_dpp_qr_code_auth_unicast(dev
, apdev
, "brainpoolP512r1")
302 def test_dpp_qr_code_set_key(dev
, apdev
):
303 """DPP QR Code and fixed bootstrapping key"""
304 run_dpp_qr_code_auth_unicast(dev
, apdev
, None, key
="30770201010420e5143ac74682cc6869a830e8f5301a5fa569130ac329b1d7dd6f2a7495dbcbe1a00a06082a8648ce3d030107a144034200045e13e167c33dbc7d85541e5509600aa8139bbb3e39e25898992c5d01be92039ee2850f17e71506ded0d6b25677441eae249f8e225c68dd15a6354dca54006383")
306 def run_dpp_qr_code_auth_unicast(dev
, apdev
, curve
, netrole
=None, key
=None,
307 require_conf_success
=False, init_extra
=None,
308 require_conf_failure
=False,
309 configurator
=False, conf_curve
=None):
310 check_dpp_capab(dev
[0], curve
and "brainpool" in curve
)
311 check_dpp_capab(dev
[1], curve
and "brainpool" in curve
)
313 conf_id
= dev
[1].dpp_configurator_add(curve
=conf_curve
)
317 logger
.info("dev0 displays QR Code")
318 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True, curve
=curve
, key
=key
)
319 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
321 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
322 dev
[0].dpp_listen(2412, netrole
=netrole
)
323 dev
[1].dpp_auth_init(uri
=uri0
, extra
=init_extra
, configurator
=conf_id
)
324 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0],
325 allow_enrollee_failure
=True,
326 allow_configurator_failure
=not require_conf_success
,
327 require_configurator_failure
=require_conf_failure
,
330 def test_dpp_qr_code_auth_mutual(dev
, apdev
):
331 """DPP QR Code and authentication exchange (mutual)"""
332 check_dpp_capab(dev
[0])
333 check_dpp_capab(dev
[1])
334 logger
.info("dev0 displays QR Code")
335 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
336 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
338 logger
.info("dev1 displays QR Code")
339 id1b
= dev
[1].dpp_bootstrap_gen(chan
="81/1", mac
=True)
340 uri1b
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b
)
342 logger
.info("dev0 scans QR Code")
343 id0b
= dev
[0].dpp_qr_code(uri1b
)
345 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
346 dev
[0].dpp_listen(2412)
347 dev
[1].dpp_auth_init(uri
=uri0
, own
=id1b
)
349 ev
= dev
[1].wait_event(["DPP-AUTH-DIRECTION"], timeout
=5)
351 raise Exception("DPP authentication direction not indicated (Initiator)")
352 if "mutual=1" not in ev
:
353 raise Exception("Mutual authentication not used")
355 wait_auth_success(dev
[0], dev
[1], stop_responder
=True)
357 def test_dpp_qr_code_auth_mutual2(dev
, apdev
):
358 """DPP QR Code and authentication exchange (mutual2)"""
359 check_dpp_capab(dev
[0])
360 check_dpp_capab(dev
[1])
361 logger
.info("dev0 displays QR Code")
362 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
363 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
365 logger
.info("dev1 displays QR Code")
366 id1b
= dev
[1].dpp_bootstrap_gen(chan
="81/1", mac
=True)
367 uri1b
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b
)
369 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
370 dev
[0].dpp_listen(2412, qr
="mutual")
371 dev
[1].dpp_auth_init(uri
=uri0
, own
=id1b
)
373 ev
= dev
[1].wait_event(["DPP-RESPONSE-PENDING"], timeout
=5)
375 raise Exception("Pending response not reported")
376 ev
= dev
[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout
=5)
378 raise Exception("QR Code scan for mutual authentication not requested")
380 logger
.info("dev0 scans QR Code")
381 id0b
= dev
[0].dpp_qr_code(uri1b
)
383 ev
= dev
[1].wait_event(["DPP-AUTH-DIRECTION"], timeout
=5)
385 raise Exception("DPP authentication direction not indicated (Initiator)")
386 if "mutual=1" not in ev
:
387 raise Exception("Mutual authentication not used")
389 wait_auth_success(dev
[0], dev
[1], stop_responder
=True)
391 def test_dpp_qr_code_auth_mutual_p_256(dev
, apdev
):
392 """DPP QR Code and authentication exchange (mutual, autogen P-256)"""
393 run_dpp_qr_code_auth_mutual(dev
, apdev
, "P-256")
395 def test_dpp_qr_code_auth_mutual_p_384(dev
, apdev
):
396 """DPP QR Code and authentication exchange (mutual, autogen P-384)"""
397 run_dpp_qr_code_auth_mutual(dev
, apdev
, "P-384")
399 def test_dpp_qr_code_auth_mutual_p_521(dev
, apdev
):
400 """DPP QR Code and authentication exchange (mutual, autogen P-521)"""
401 run_dpp_qr_code_auth_mutual(dev
, apdev
, "P-521")
403 def test_dpp_qr_code_auth_mutual_bp_256(dev
, apdev
):
404 """DPP QR Code and authentication exchange (mutual, autogen BP-256)"""
405 run_dpp_qr_code_auth_mutual(dev
, apdev
, "BP-256")
407 def test_dpp_qr_code_auth_mutual_bp_384(dev
, apdev
):
408 """DPP QR Code and authentication exchange (mutual, autogen BP-384)"""
409 run_dpp_qr_code_auth_mutual(dev
, apdev
, "BP-384")
411 def test_dpp_qr_code_auth_mutual_bp_512(dev
, apdev
):
412 """DPP QR Code and authentication exchange (mutual, autogen BP-512)"""
413 run_dpp_qr_code_auth_mutual(dev
, apdev
, "BP-512")
415 def run_dpp_qr_code_auth_mutual(dev
, apdev
, curve
):
416 check_dpp_capab(dev
[0], curve
and "BP-" in curve
)
417 check_dpp_capab(dev
[1], curve
and "BP-" in curve
)
418 logger
.info("dev0 displays QR Code")
419 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True, curve
=curve
)
420 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
421 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
422 dev
[0].dpp_listen(2412, qr
="mutual")
423 dev
[1].dpp_auth_init(uri
=uri0
)
425 ev
= dev
[1].wait_event(["DPP-RESPONSE-PENDING"], timeout
=5)
427 raise Exception("Pending response not reported")
428 uri
= ev
.split(' ')[1]
430 ev
= dev
[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout
=5)
432 raise Exception("QR Code scan for mutual authentication not requested")
434 logger
.info("dev0 scans QR Code")
435 dev
[0].dpp_qr_code(uri
)
437 ev
= dev
[1].wait_event(["DPP-AUTH-DIRECTION"], timeout
=5)
439 raise Exception("DPP authentication direction not indicated (Initiator)")
440 if "mutual=1" not in ev
:
441 raise Exception("Mutual authentication not used")
443 wait_auth_success(dev
[0], dev
[1], stop_responder
=True)
445 def test_dpp_auth_resp_retries(dev
, apdev
):
446 """DPP Authentication Response retries"""
447 check_dpp_capab(dev
[0])
448 check_dpp_capab(dev
[1])
449 dev
[0].set("dpp_resp_max_tries", "3")
450 dev
[0].set("dpp_resp_retry_time", "100")
452 logger
.info("dev0 displays QR Code")
453 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
454 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
455 logger
.info("dev1 displays QR Code")
456 id1b
= dev
[1].dpp_bootstrap_gen(chan
="81/1", mac
=True)
457 uri1b
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b
)
458 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
459 dev
[0].dpp_listen(2412, qr
="mutual")
460 dev
[1].dpp_auth_init(uri
=uri0
, own
=id1b
)
462 ev
= dev
[1].wait_event(["DPP-RESPONSE-PENDING"], timeout
=5)
464 raise Exception("Pending response not reported")
465 ev
= dev
[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout
=5)
467 raise Exception("QR Code scan for mutual authentication not requested")
469 # Stop Initiator from listening to frames to force retransmission of the
470 # DPP Authentication Response frame with Status=0
471 dev
[1].request("DPP_STOP_LISTEN")
473 dev
[1].dump_monitor()
474 dev
[0].dump_monitor()
476 logger
.info("dev0 scans QR Code")
477 id0b
= dev
[0].dpp_qr_code(uri1b
)
479 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=5)
480 if ev
is None or "type=1" not in ev
:
481 raise Exception("DPP Authentication Response not sent")
482 ev
= dev
[0].wait_event(["DPP-TX-STATUS"], timeout
=5)
484 raise Exception("TX status for DPP Authentication Response not reported")
485 if "result=no-ACK" not in ev
:
486 raise Exception("Unexpected TX status for Authentication Response: " + ev
)
488 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=15)
489 if ev
is None or "type=1" not in ev
:
490 raise Exception("DPP Authentication Response retransmission not sent")
492 def test_dpp_qr_code_auth_mutual_not_used(dev
, apdev
):
493 """DPP QR Code and authentication exchange (mutual not used)"""
494 check_dpp_capab(dev
[0])
495 check_dpp_capab(dev
[1])
496 logger
.info("dev0 displays QR Code")
497 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
498 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
499 logger
.info("dev1 displays QR Code")
500 id1b
= dev
[1].dpp_bootstrap_gen(chan
="81/1", mac
=True)
501 uri1b
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b
)
502 logger
.info("dev0 does not scan QR Code")
503 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
504 dev
[0].dpp_listen(2412)
505 dev
[1].dpp_auth_init(uri
=uri0
, own
=id1b
)
507 ev
= dev
[1].wait_event(["DPP-AUTH-DIRECTION"], timeout
=5)
509 raise Exception("DPP authentication direction not indicated (Initiator)")
510 if "mutual=0" not in ev
:
511 raise Exception("Mutual authentication not used")
513 wait_auth_success(dev
[0], dev
[1], stop_responder
=True)
515 def test_dpp_qr_code_auth_mutual_curve_mismatch(dev
, apdev
):
516 """DPP QR Code and authentication exchange (mutual/mismatch)"""
517 check_dpp_capab(dev
[0])
518 check_dpp_capab(dev
[1])
519 logger
.info("dev0 displays QR Code")
520 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
521 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
522 logger
.info("dev1 displays QR Code")
523 id1b
= dev
[1].dpp_bootstrap_gen(chan
="81/1", mac
=True, curve
="secp384r1")
524 uri1b
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b
)
525 logger
.info("dev0 scans QR Code")
526 id0b
= dev
[0].dpp_qr_code(uri1b
)
527 logger
.info("dev1 scans QR Code")
528 dev
[1].dpp_auth_init(uri
=uri0
, own
=id1b
, expect_fail
=True)
530 def test_dpp_qr_code_auth_hostapd_mutual2(dev
, apdev
):
531 """DPP QR Code and authentication exchange (hostapd mutual2)"""
532 check_dpp_capab(dev
[0])
533 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured"})
534 check_dpp_capab(hapd
)
535 logger
.info("AP displays QR Code")
536 id_h
= hapd
.dpp_bootstrap_gen(chan
="81/1", mac
=True)
537 uri_h
= hapd
.request("DPP_BOOTSTRAP_GET_URI %d" % id_h
)
538 logger
.info("dev0 displays QR Code")
539 id0b
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
540 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0b
)
541 logger
.info("dev0 scans QR Code and initiates DPP Authentication")
542 hapd
.dpp_listen(2412, qr
="mutual")
543 dev
[0].dpp_auth_init(uri
=uri_h
, own
=id0b
)
545 ev
= dev
[0].wait_event(["DPP-RESPONSE-PENDING"], timeout
=5)
547 raise Exception("Pending response not reported")
548 ev
= hapd
.wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout
=5)
550 raise Exception("QR Code scan for mutual authentication not requested")
552 logger
.info("AP scans QR Code")
553 hapd
.dpp_qr_code(uri0
)
555 wait_auth_success(hapd
, dev
[0], stop_responder
=True)
557 def test_dpp_qr_code_listen_continue(dev
, apdev
):
558 """DPP QR Code and listen operation needing continuation"""
559 check_dpp_capab(dev
[0])
560 check_dpp_capab(dev
[1])
561 logger
.info("dev0 displays QR Code")
562 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
563 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
564 dev
[0].dpp_listen(2412)
565 logger
.info("Wait for listen to expire and get restarted")
567 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
568 dev
[1].dpp_auth_init(uri
=uri0
)
569 wait_auth_success(dev
[0], dev
[1], stop_responder
=True)
571 def test_dpp_qr_code_auth_initiator_enrollee(dev
, apdev
):
572 """DPP QR Code and authentication exchange (Initiator in Enrollee role)"""
574 run_dpp_qr_code_auth_initiator_enrollee(dev
, apdev
)
576 dev
[0].set("gas_address3", "0")
577 dev
[1].set("gas_address3", "0")
579 def run_dpp_qr_code_auth_initiator_enrollee(dev
, apdev
):
580 check_dpp_capab(dev
[0])
581 check_dpp_capab(dev
[1])
582 dev
[0].request("SET gas_address3 1")
583 dev
[1].request("SET gas_address3 1")
584 logger
.info("dev0 displays QR Code")
585 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
586 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
587 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
588 dev
[0].dpp_listen(2412)
589 dev
[1].dpp_auth_init(uri
=uri0
, role
="enrollee")
590 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[0], enrollee
=dev
[1],
591 allow_enrollee_failure
=True, stop_responder
=True)
593 def test_dpp_qr_code_auth_initiator_either_1(dev
, apdev
):
594 """DPP QR Code and authentication exchange (Initiator in either role)"""
595 run_dpp_qr_code_auth_initiator_either(dev
, apdev
, None, dev
[1], dev
[0])
597 def test_dpp_qr_code_auth_initiator_either_2(dev
, apdev
):
598 """DPP QR Code and authentication exchange (Initiator in either role)"""
599 run_dpp_qr_code_auth_initiator_either(dev
, apdev
, "enrollee",
602 def test_dpp_qr_code_auth_initiator_either_3(dev
, apdev
):
603 """DPP QR Code and authentication exchange (Initiator in either role)"""
604 run_dpp_qr_code_auth_initiator_either(dev
, apdev
, "configurator",
607 def run_dpp_qr_code_auth_initiator_either(dev
, apdev
, resp_role
,
608 conf_dev
, enrollee_dev
):
609 check_dpp_capab(dev
[0])
610 check_dpp_capab(dev
[1])
611 logger
.info("dev0 displays QR Code")
612 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
613 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
614 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
615 dev
[0].dpp_listen(2412, role
=resp_role
)
616 dev
[1].dpp_auth_init(uri
=uri0
, role
="either")
617 wait_auth_success(dev
[0], dev
[1], configurator
=conf_dev
,
618 enrollee
=enrollee_dev
, allow_enrollee_failure
=True,
621 def run_init_incompatible_roles(dev
, role
="enrollee"):
622 check_dpp_capab(dev
[0])
623 check_dpp_capab(dev
[1])
624 logger
.info("dev0 displays QR Code")
625 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
626 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
628 logger
.info("dev1 scans QR Code")
629 id1
= dev
[1].dpp_qr_code(uri0
)
631 logger
.info("dev1 initiates DPP Authentication")
632 dev
[0].dpp_listen(2412, role
=role
)
635 def test_dpp_qr_code_auth_incompatible_roles(dev
, apdev
):
636 """DPP QR Code and authentication exchange (incompatible roles)"""
637 id1
= run_init_incompatible_roles(dev
)
638 dev
[1].dpp_auth_init(peer
=id1
, role
="enrollee")
639 ev
= dev
[1].wait_event(["DPP-NOT-COMPATIBLE"], timeout
=5)
641 raise Exception("DPP-NOT-COMPATIBLE event on initiator timed out")
642 ev
= dev
[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout
=1)
644 raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
645 dev
[1].dpp_auth_init(peer
=id1
, role
="configurator")
646 wait_auth_success(dev
[0], dev
[1], stop_responder
=True)
648 def test_dpp_qr_code_auth_incompatible_roles2(dev
, apdev
):
649 """DPP QR Code and authentication exchange (incompatible roles 2)"""
650 id1
= run_init_incompatible_roles(dev
, role
="configurator")
651 dev
[1].dpp_auth_init(peer
=id1
, role
="configurator")
652 ev
= dev
[1].wait_event(["DPP-NOT-COMPATIBLE"], timeout
=5)
654 raise Exception("DPP-NOT-COMPATIBLE event on initiator timed out")
655 ev
= dev
[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout
=1)
657 raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
659 def test_dpp_qr_code_auth_incompatible_roles_failure(dev
, apdev
):
660 """DPP QR Code and authentication exchange (incompatible roles failure)"""
661 id1
= run_init_incompatible_roles(dev
, role
="configurator")
662 with
alloc_fail(dev
[0], 1, "dpp_auth_build_resp_status"):
663 dev
[1].dpp_auth_init(peer
=id1
, role
="configurator")
664 ev
= dev
[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout
=1)
666 raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
668 def test_dpp_qr_code_auth_incompatible_roles_failure2(dev
, apdev
):
669 """DPP QR Code and authentication exchange (incompatible roles failure 2)"""
670 id1
= run_init_incompatible_roles(dev
, role
="configurator")
671 with
alloc_fail(dev
[1], 1, "dpp_auth_resp_rx_status"):
672 dev
[1].dpp_auth_init(peer
=id1
, role
="configurator")
673 wait_fail_trigger(dev
[1], "GET_ALLOC_FAIL")
675 def test_dpp_qr_code_auth_incompatible_roles_failure3(dev
, apdev
):
676 """DPP QR Code and authentication exchange (incompatible roles failure 3)"""
677 id1
= run_init_incompatible_roles(dev
, role
="configurator")
678 with
fail_test(dev
[1], 1, "dpp_auth_resp_rx_status"):
679 dev
[1].dpp_auth_init(peer
=id1
, role
="configurator")
680 wait_dpp_fail(dev
[1], "AES-SIV decryption failed")
682 def test_dpp_qr_code_auth_neg_chan(dev
, apdev
):
683 """DPP QR Code and authentication exchange with requested different channel"""
684 check_dpp_capab(dev
[0])
685 check_dpp_capab(dev
[1])
686 conf_id
= dev
[1].dpp_configurator_add()
687 logger
.info("dev0 displays QR Code")
688 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
689 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
690 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
691 dev
[0].dpp_listen(2412)
692 dev
[1].dpp_auth_init(uri
=uri0
, conf
="sta-dpp", neg_freq
=2462,
693 configurator
=conf_id
)
695 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
697 raise Exception("DPP Authentication Request not sent")
698 if "freq=2412 type=0" not in ev
:
699 raise Exception("Unexpected TX data for Authentication Request: " + ev
)
701 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
703 raise Exception("DPP Authentication Request not received")
704 if "freq=2412 type=0" not in ev
:
705 raise Exception("Unexpected RX data for Authentication Request: " + ev
)
707 ev
= dev
[1].wait_event(["DPP-TX-STATUS"], timeout
=5)
709 raise Exception("TX status for DPP Authentication Request not reported")
710 if "freq=2412 result=SUCCESS" not in ev
:
711 raise Exception("Unexpected TX status for Authentication Request: " + ev
)
713 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=5)
715 raise Exception("DPP Authentication Response not sent")
716 if "freq=2462 type=1" not in ev
:
717 raise Exception("Unexpected TX data for Authentication Response: " + ev
)
719 ev
= dev
[1].wait_event(["DPP-RX"], timeout
=5)
721 raise Exception("DPP Authentication Response not received")
722 if "freq=2462 type=1" not in ev
:
723 raise Exception("Unexpected RX data for Authentication Response: " + ev
)
725 ev
= dev
[0].wait_event(["DPP-TX-STATUS"], timeout
=5)
727 raise Exception("TX status for DPP Authentication Response not reported")
728 if "freq=2462 result=SUCCESS" not in ev
:
729 raise Exception("Unexpected TX status for Authentication Response: " + ev
)
731 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
733 raise Exception("DPP Authentication Confirm not sent")
734 if "freq=2462 type=2" not in ev
:
735 raise Exception("Unexpected TX data for Authentication Confirm: " + ev
)
737 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
739 raise Exception("DPP Authentication Confirm not received")
740 if "freq=2462 type=2" not in ev
:
741 raise Exception("Unexpected RX data for Authentication Confirm: " + ev
)
743 ev
= dev
[1].wait_event(["DPP-TX-STATUS"], timeout
=5)
745 raise Exception("TX status for DPP Authentication Confirm not reported")
746 if "freq=2462 result=SUCCESS" not in ev
:
747 raise Exception("Unexpected TX status for Authentication Confirm: " + ev
)
749 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0],
752 def test_dpp_config_legacy(dev
, apdev
):
753 """DPP Config Object for legacy network using passphrase"""
754 check_dpp_capab(dev
[1])
755 conf
= '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}'
756 dev
[1].set("dpp_config_obj_override", conf
)
757 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
758 require_conf_success
=True)
760 def test_dpp_config_legacy_psk_hex(dev
, apdev
):
761 """DPP Config Object for legacy network using PSK"""
762 check_dpp_capab(dev
[1])
763 conf
= '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"' + 32*"12" + '"}}'
764 dev
[1].set("dpp_config_obj_override", conf
)
765 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
766 require_conf_success
=True)
768 def test_dpp_config_fragmentation(dev
, apdev
):
769 """DPP Config Object for legacy network requiring fragmentation"""
770 check_dpp_capab(dev
[1])
771 conf
= '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
772 dev
[1].set("dpp_config_obj_override", conf
)
773 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
774 require_conf_success
=True)
776 def test_dpp_config_legacy_gen(dev
, apdev
):
777 """Generate DPP Config Object for legacy network"""
778 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
779 init_extra
="conf=sta-psk pass=%s" % binascii
.hexlify(b
"passphrase").decode(),
780 require_conf_success
=True)
782 def test_dpp_config_legacy_gen_psk(dev
, apdev
):
783 """Generate DPP Config Object for legacy network (PSK)"""
784 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
785 init_extra
="conf=sta-psk psk=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
786 require_conf_success
=True)
788 def test_dpp_config_dpp_gen_prime256v1(dev
, apdev
):
789 """Generate DPP Config Object for DPP network (P-256)"""
790 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
791 init_extra
="conf=sta-dpp",
792 require_conf_success
=True,
795 def test_dpp_config_dpp_gen_secp384r1(dev
, apdev
):
796 """Generate DPP Config Object for DPP network (P-384)"""
797 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp384r1",
798 init_extra
="conf=sta-dpp",
799 require_conf_success
=True,
802 def test_dpp_config_dpp_gen_secp521r1(dev
, apdev
):
803 """Generate DPP Config Object for DPP network (P-521)"""
804 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp521r1",
805 init_extra
="conf=sta-dpp",
806 require_conf_success
=True,
809 def test_dpp_config_dpp_gen_prime256v1_prime256v1(dev
, apdev
):
810 """Generate DPP Config Object for DPP network (P-256 + P-256)"""
811 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
812 init_extra
="conf=sta-dpp",
813 require_conf_success
=True,
815 conf_curve
="prime256v1")
817 def test_dpp_config_dpp_gen_prime256v1_secp384r1(dev
, apdev
):
818 """Generate DPP Config Object for DPP network (P-256 + P-384)"""
819 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
820 init_extra
="conf=sta-dpp",
821 require_conf_success
=True,
823 conf_curve
="secp384r1")
825 def test_dpp_config_dpp_gen_prime256v1_secp521r1(dev
, apdev
):
826 """Generate DPP Config Object for DPP network (P-256 + P-521)"""
827 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
828 init_extra
="conf=sta-dpp",
829 require_conf_success
=True,
831 conf_curve
="secp521r1")
833 def test_dpp_config_dpp_gen_secp384r1_prime256v1(dev
, apdev
):
834 """Generate DPP Config Object for DPP network (P-384 + P-256)"""
835 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp384r1",
836 init_extra
="conf=sta-dpp",
837 require_conf_success
=True,
839 conf_curve
="prime256v1")
841 def test_dpp_config_dpp_gen_secp384r1_secp384r1(dev
, apdev
):
842 """Generate DPP Config Object for DPP network (P-384 + P-384)"""
843 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp384r1",
844 init_extra
="conf=sta-dpp",
845 require_conf_success
=True,
847 conf_curve
="secp384r1")
849 def test_dpp_config_dpp_gen_secp384r1_secp521r1(dev
, apdev
):
850 """Generate DPP Config Object for DPP network (P-384 + P-521)"""
851 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp384r1",
852 init_extra
="conf=sta-dpp",
853 require_conf_success
=True,
855 conf_curve
="secp521r1")
857 def test_dpp_config_dpp_gen_secp521r1_prime256v1(dev
, apdev
):
858 """Generate DPP Config Object for DPP network (P-521 + P-256)"""
859 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp521r1",
860 init_extra
="conf=sta-dpp",
861 require_conf_success
=True,
863 conf_curve
="prime256v1")
865 def test_dpp_config_dpp_gen_secp521r1_secp384r1(dev
, apdev
):
866 """Generate DPP Config Object for DPP network (P-521 + P-384)"""
867 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp521r1",
868 init_extra
="conf=sta-dpp",
869 require_conf_success
=True,
871 conf_curve
="secp384r1")
873 def test_dpp_config_dpp_gen_secp521r1_secp521r1(dev
, apdev
):
874 """Generate DPP Config Object for DPP network (P-521 + P-521)"""
875 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp521r1",
876 init_extra
="conf=sta-dpp",
877 require_conf_success
=True,
879 conf_curve
="secp521r1")
881 def test_dpp_config_dpp_gen_expiry(dev
, apdev
):
882 """Generate DPP Config Object for DPP network with expiry value"""
883 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
884 init_extra
="conf=sta-dpp expiry=%d" % (time
.time() + 1000),
885 require_conf_success
=True,
888 def test_dpp_config_dpp_gen_expired_key(dev
, apdev
):
889 """Generate DPP Config Object for DPP network with expiry value"""
890 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
891 init_extra
="conf=sta-dpp expiry=%d" % (time
.time() - 10),
892 require_conf_failure
=True,
895 def test_dpp_config_dpp_override_prime256v1(dev
, apdev
):
896 """DPP Config Object override (P-256)"""
897 check_dpp_capab(dev
[0])
898 check_dpp_capab(dev
[1])
899 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"dpp","signedConnector":"eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJUbkdLaklsTlphYXRyRUFZcmJiamlCNjdyamtMX0FHVldYTzZxOWhESktVIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiYVRGNEpFR0lQS1NaMFh2OXpkQ01qbS10bjVYcE1zWUlWWjl3eVNBejFnSSIsInkiOiJRR2NIV0FfNnJiVTlYRFhBenRvWC1NNVEzc3VUbk1hcUVoVUx0bjdTU1h3In19._sm6YswxMf6hJLVTyYoU1uYUeY2VVkUNjrzjSiEhY42StD_RWowStEE-9CRsdCvLmsTptZ72_g40vTFwdId20A","csign":{"kty":"EC","crv":"P-256","x":"W4-Y5N1Pkos3UWb9A5qme0KUYRtY3CVUpekx_MapZ9s","y":"Et-M4NSF4NGjvh2VCh4B1sJ9eSCZ4RNzP2DBdP137VE","kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU"}}}'
900 dev
[0].set("dpp_ignore_netaccesskey_mismatch", "1")
901 dev
[1].set("dpp_config_obj_override", conf
)
902 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
903 require_conf_success
=True)
905 def test_dpp_config_dpp_override_secp384r1(dev
, apdev
):
906 """DPP Config Object override (P-384)"""
907 check_dpp_capab(dev
[0])
908 check_dpp_capab(dev
[1])
909 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"dpp","signedConnector":"eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJabi1iMndjbjRLM2pGQklkYmhGZkpVTHJTXzdESS0yMWxFQi02R3gxNjl3IiwiYWxnIjoiRVMzODQifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0zODQiLCJ4IjoickdrSGg1UUZsOUtfWjdqYUZkVVhmbThoY1RTRjM1b25Xb1NIRXVsbVNzWW9oX1RXZGpoRjhiVGdiS0ZRN2tBViIsInkiOiJBbU1QVDA5VmFENWpGdzMwTUFKQlp2VkZXeGNlVVlKLXR5blQ0bVJ5N0xOZWxhZ0dEWHpfOExaRlpOU2FaNUdLIn19.Yn_F7m-bbOQ5PlaYQJ9-1qsuqYQ6V-rAv8nWw1COKiCYwwbt3WFBJ8DljY0dPrlg5CHJC4saXwkytpI-CpELW1yUdzYb4Lrun07d20Eo_g10ICyOl5sqQCAUElKMe_Xr","csign":{"kty":"EC","crv":"P-384","x":"dmTyXXiPV2Y8a01fujL-jo08gvzyby23XmzOtzjAiujKQZZgPJsbhfEKrZDlc6ey","y":"H5Z0av5c7bqInxYb2_OOJdNiMhVf3zlcULR0516ZZitOY4U31KhL4wl4KGV7g2XW","kid":"Zn-b2wcn4K3jFBIdbhFfJULrS_7DI-21lEB-6Gx169w"}}}'
910 dev
[0].set("dpp_ignore_netaccesskey_mismatch", "1")
911 dev
[1].set("dpp_config_obj_override", conf
)
912 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp384r1",
913 require_conf_success
=True)
915 def test_dpp_config_dpp_override_secp521r1(dev
, apdev
):
916 """DPP Config Object override (P-521)"""
917 check_dpp_capab(dev
[0])
918 check_dpp_capab(dev
[1])
919 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"dpp","signedConnector":"eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJMZkhKY3hnV2ZKcG1uS2IwenZRT0F2VDB2b0ZKc0JjZnBmYzgxY3Y5ZXFnIiwiYWxnIjoiRVM1MTIifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC01MjEiLCJ4IjoiQVJlUFBrMFNISkRRR2NWbnlmM3lfbTlaQllHNjFJeElIbDN1NkdwRHVhMkU1WVd4TE1BSUtMMnZuUGtlSGFVRXljRmZaZlpYZ2JlNkViUUxMVkRVUm1VUSIsInkiOiJBWUtaYlNwUkFFNjJVYm9YZ2c1ZWRBVENzbEpzTlpwcm9RR1dUcW9Md04weXkzQkVoT3ZRZmZrOWhaR2lKZ295TzFobXFRRVRrS0pXb2tIYTBCQUpLSGZtIn19.ACEZLyPk13cM_OFScpLoCElQ2t1sxq5z2d_W_3_QslTQQe5SFiH_o8ycL4632YLAH4RV0gZcMKKRMtZdHgBYHjkzASDqgY-_aYN2SBmpfl8hw0YdDlUJWX3DJf-ofqNAlTbnGmhpSg69cEAhFn41Xgvx2MdwYcPVncxxESVOtWl5zNLK","csign":{"kty":"EC","crv":"P-521","x":"ADiOI_YJOAipEXHB-SpGl4KqokX8m8h3BVYCc8dgiwssZ061-nIIY3O1SIO6Re4Jjfy53RPgzDG6jitOgOGLtzZs","y":"AZKggKaQi0ExutSpJAU3-lqDV03sBQLA9C7KabfWoAn8qD6Vk4jU0WAJdt-wBBTF9o1nVuiqS2OxMVYrxN4lOz79","kid":"LfHJcxgWfJpmnKb0zvQOAvT0voFJsBcfpfc81cv9eqg"}}}'
920 dev
[0].set("dpp_ignore_netaccesskey_mismatch", "1")
921 dev
[1].set("dpp_config_obj_override", conf
)
922 run_dpp_qr_code_auth_unicast(dev
, apdev
, "secp521r1",
923 require_conf_success
=True)
925 def test_dpp_config_override_objects(dev
, apdev
):
926 """Generate DPP Config Object and override objects)"""
927 check_dpp_capab(dev
[1])
928 discovery
= '{\n"ssid":"mywifi"\n}'
929 groups
= '[\n {"groupId":"home","netRole":"sta"},\n {"groupId":"cottage","netRole":"sta"}\n]'
930 dev
[1].set("dpp_discovery_override", discovery
)
931 dev
[1].set("dpp_groups_override", groups
)
932 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
933 init_extra
="conf=sta-dpp",
934 require_conf_success
=True,
937 def build_conf_obj(kty
="EC", crv
="P-256",
938 x
="W4-Y5N1Pkos3UWb9A5qme0KUYRtY3CVUpekx_MapZ9s",
939 y
="Et-M4NSF4NGjvh2VCh4B1sJ9eSCZ4RNzP2DBdP137VE",
940 kid
="TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU",
941 prot_hdr
='{"typ":"dppCon","kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU","alg":"ES256"}',
942 signed_connector
=None,
943 no_signed_connector
=False,
945 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{'
946 conf
+= '"akm":"dpp",'
949 conn
= signed_connector
950 conf
+= '"signedConnector":"%s",' % conn
951 elif not no_signed_connector
:
952 payload
= '{"groups":[{"groupId":"*","netRole":"sta"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
953 sign
= "_sm6YswxMf6hJLVTyYoU1uYUeY2VVkUNjrzjSiEhY42StD_RWowStEE-9CRsdCvLmsTptZ72_g40vTFwdId20A"
954 conn
= base64
.urlsafe_b64encode(prot_hdr
.encode()).decode().rstrip('=') + '.'
955 conn
+= base64
.urlsafe_b64encode(payload
.encode()).decode().rstrip('=') + '.'
957 conf
+= '"signedConnector":"%s",' % conn
962 conf
+= '"kty":"%s",' % kty
964 conf
+= '"crv":"%s",' % crv
966 conf
+= '"x":"%s",' % x
968 conf
+= '"y":"%s",' % y
970 conf
+= '"kid":"%s"' % kid
971 conf
= conf
.rstrip(',')
974 conf
= conf
.rstrip(',')
980 def run_dpp_config_error(dev
, apdev
, conf
,
981 skip_net_access_key_mismatch
=True,
983 check_dpp_capab(dev
[0])
984 check_dpp_capab(dev
[1])
985 if skip_net_access_key_mismatch
:
986 dev
[0].set("dpp_ignore_netaccesskey_mismatch", "1")
987 dev
[1].set("dpp_config_obj_override", conf
)
988 run_dpp_qr_code_auth_unicast(dev
, apdev
, "prime256v1",
989 require_conf_success
=not conf_failure
,
990 require_conf_failure
=conf_failure
)
992 def test_dpp_config_jwk_error_no_kty(dev
, apdev
):
993 """DPP Config Object JWK error - no kty"""
994 run_dpp_config_error(dev
, apdev
, build_conf_obj(kty
=None))
996 def test_dpp_config_jwk_error_unexpected_kty(dev
, apdev
):
997 """DPP Config Object JWK error - unexpected kty"""
998 run_dpp_config_error(dev
, apdev
, build_conf_obj(kty
="unknown"))
1000 def test_dpp_config_jwk_error_no_crv(dev
, apdev
):
1001 """DPP Config Object JWK error - no crv"""
1002 run_dpp_config_error(dev
, apdev
, build_conf_obj(crv
=None))
1004 def test_dpp_config_jwk_error_unsupported_crv(dev
, apdev
):
1005 """DPP Config Object JWK error - unsupported curve"""
1006 run_dpp_config_error(dev
, apdev
, build_conf_obj(crv
="unsupported"))
1008 def test_dpp_config_jwk_error_no_x(dev
, apdev
):
1009 """DPP Config Object JWK error - no x"""
1010 run_dpp_config_error(dev
, apdev
, build_conf_obj(x
=None))
1012 def test_dpp_config_jwk_error_invalid_x(dev
, apdev
):
1013 """DPP Config Object JWK error - invalid x"""
1014 run_dpp_config_error(dev
, apdev
, build_conf_obj(x
="MTIz"))
1016 def test_dpp_config_jwk_error_no_y(dev
, apdev
):
1017 """DPP Config Object JWK error - no y"""
1018 run_dpp_config_error(dev
, apdev
, build_conf_obj(y
=None))
1020 def test_dpp_config_jwk_error_invalid_y(dev
, apdev
):
1021 """DPP Config Object JWK error - invalid y"""
1022 run_dpp_config_error(dev
, apdev
, build_conf_obj(y
="MTIz"))
1024 def test_dpp_config_jwk_error_invalid_xy(dev
, apdev
):
1025 """DPP Config Object JWK error - invalid x,y"""
1026 conf
= build_conf_obj(x
="MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY",
1027 y
="MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY")
1028 run_dpp_config_error(dev
, apdev
, conf
)
1030 def test_dpp_config_jwk_error_no_kid(dev
, apdev
):
1031 """DPP Config Object JWK error - no kid"""
1032 # csign kid is optional field, so this results in success
1033 run_dpp_config_error(dev
, apdev
, build_conf_obj(kid
=None),
1036 def test_dpp_config_jws_error_prot_hdr_not_an_object(dev
, apdev
):
1037 """DPP Config Object JWS error - protected header not an object"""
1038 run_dpp_config_error(dev
, apdev
, build_conf_obj(prot_hdr
="1"))
1040 def test_dpp_config_jws_error_prot_hdr_no_typ(dev
, apdev
):
1041 """DPP Config Object JWS error - protected header - no typ"""
1042 prot_hdr
= '{"kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU","alg":"ES256"}'
1043 run_dpp_config_error(dev
, apdev
, build_conf_obj(prot_hdr
=prot_hdr
))
1045 def test_dpp_config_jws_error_prot_hdr_unsupported_typ(dev
, apdev
):
1046 """DPP Config Object JWS error - protected header - unsupported typ"""
1047 prot_hdr
= '{"typ":"unsupported","kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU","alg":"ES256"}'
1048 run_dpp_config_error(dev
, apdev
, build_conf_obj(prot_hdr
=prot_hdr
))
1050 def test_dpp_config_jws_error_prot_hdr_no_alg(dev
, apdev
):
1051 """DPP Config Object JWS error - protected header - no alg"""
1052 prot_hdr
= '{"typ":"dppCon","kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU"}'
1053 run_dpp_config_error(dev
, apdev
, build_conf_obj(prot_hdr
=prot_hdr
))
1055 def test_dpp_config_jws_error_prot_hdr_unexpected_alg(dev
, apdev
):
1056 """DPP Config Object JWS error - protected header - unexpected alg"""
1057 prot_hdr
= '{"typ":"dppCon","kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU","alg":"unexpected"}'
1058 run_dpp_config_error(dev
, apdev
, build_conf_obj(prot_hdr
=prot_hdr
))
1060 def test_dpp_config_jws_error_prot_hdr_no_kid(dev
, apdev
):
1061 """DPP Config Object JWS error - protected header - no kid"""
1062 prot_hdr
= '{"typ":"dppCon","alg":"ES256"}'
1063 run_dpp_config_error(dev
, apdev
, build_conf_obj(prot_hdr
=prot_hdr
))
1065 def test_dpp_config_jws_error_prot_hdr_unexpected_kid(dev
, apdev
):
1066 """DPP Config Object JWS error - protected header - unexpected kid"""
1067 prot_hdr
= '{"typ":"dppCon","kid":"MTIz","alg":"ES256"}'
1068 run_dpp_config_error(dev
, apdev
, build_conf_obj(prot_hdr
=prot_hdr
))
1070 def test_dpp_config_signed_connector_error_no_dot_1(dev
, apdev
):
1071 """DPP Config Object signedConnector error - no dot(1)"""
1073 run_dpp_config_error(dev
, apdev
, build_conf_obj(signed_connector
=conn
))
1075 def test_dpp_config_signed_connector_error_no_dot_2(dev
, apdev
):
1076 """DPP Config Object signedConnector error - no dot(2)"""
1077 conn
= "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJUbkdLaklsTlphYXRyRUFZcmJiamlCNjdyamtMX0FHVldYTzZxOWhESktVIiwiYWxnIjoiRVMyNTYifQ.MTIz"
1078 run_dpp_config_error(dev
, apdev
, build_conf_obj(signed_connector
=conn
))
1080 def test_dpp_config_signed_connector_error_unexpected_signature_len(dev
, apdev
):
1081 """DPP Config Object signedConnector error - unexpected signature length"""
1082 conn
= "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJUbkdLaklsTlphYXRyRUFZcmJiamlCNjdyamtMX0FHVldYTzZxOWhESktVIiwiYWxnIjoiRVMyNTYifQ.MTIz.MTIz"
1083 run_dpp_config_error(dev
, apdev
, build_conf_obj(signed_connector
=conn
))
1085 def test_dpp_config_signed_connector_error_invalid_signature_der(dev
, apdev
):
1086 """DPP Config Object signedConnector error - invalid signature DER"""
1087 conn
= "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJUbkdLaklsTlphYXRyRUFZcmJiamlCNjdyamtMX0FHVldYTzZxOWhESktVIiwiYWxnIjoiRVMyNTYifQ.MTIz.MTI"
1088 run_dpp_config_error(dev
, apdev
, build_conf_obj(signed_connector
=conn
))
1090 def test_dpp_config_no_csign(dev
, apdev
):
1091 """DPP Config Object error - no csign"""
1092 run_dpp_config_error(dev
, apdev
, build_conf_obj(csign
=False))
1094 def test_dpp_config_no_signed_connector(dev
, apdev
):
1095 """DPP Config Object error - no signedConnector"""
1096 run_dpp_config_error(dev
, apdev
, build_conf_obj(no_signed_connector
=True))
1098 def test_dpp_config_unexpected_signed_connector_char(dev
, apdev
):
1099 """DPP Config Object error - unexpected signedConnector character"""
1100 run_dpp_config_error(dev
, apdev
, build_conf_obj(signed_connector
='a\nb'))
1102 def test_dpp_config_root_not_an_object(dev
, apdev
):
1103 """DPP Config Object error - root not an object"""
1105 run_dpp_config_error(dev
, apdev
, conf
)
1107 def test_dpp_config_no_wi_fi_tech(dev
, apdev
):
1108 """DPP Config Object error - no wi-fi_tech"""
1110 run_dpp_config_error(dev
, apdev
, conf
)
1112 def test_dpp_config_unsupported_wi_fi_tech(dev
, apdev
):
1113 """DPP Config Object error - unsupported wi-fi_tech"""
1114 conf
= '{"wi-fi_tech":"unsupported"}'
1115 run_dpp_config_error(dev
, apdev
, conf
)
1117 def test_dpp_config_no_discovery(dev
, apdev
):
1118 """DPP Config Object error - no discovery"""
1119 conf
= '{"wi-fi_tech":"infra"}'
1120 run_dpp_config_error(dev
, apdev
, conf
)
1122 def test_dpp_config_no_discovery_ssid(dev
, apdev
):
1123 """DPP Config Object error - no discovery::ssid"""
1124 conf
= '{"wi-fi_tech":"infra","discovery":{}}'
1125 run_dpp_config_error(dev
, apdev
, conf
)
1127 def test_dpp_config_too_long_discovery_ssid(dev
, apdev
):
1128 """DPP Config Object error - too long discovery::ssid"""
1129 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"%s"}}' % (33*'A')
1130 run_dpp_config_error(dev
, apdev
, conf
)
1132 def test_dpp_config_no_cred(dev
, apdev
):
1133 """DPP Config Object error - no cred"""
1134 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"}}'
1135 run_dpp_config_error(dev
, apdev
, conf
)
1137 def test_dpp_config_no_cred_akm(dev
, apdev
):
1138 """DPP Config Object error - no cred::akm"""
1139 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{}}'
1140 run_dpp_config_error(dev
, apdev
, conf
)
1142 def test_dpp_config_unsupported_cred_akm(dev
, apdev
):
1143 """DPP Config Object error - unsupported cred::akm"""
1144 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"unsupported"}}'
1145 run_dpp_config_error(dev
, apdev
, conf
)
1147 def test_dpp_config_error_legacy_no_pass(dev
, apdev
):
1148 """DPP Config Object legacy error - no pass/psk"""
1149 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk"}}'
1150 run_dpp_config_error(dev
, apdev
, conf
)
1152 def test_dpp_config_error_legacy_too_short_pass(dev
, apdev
):
1153 """DPP Config Object legacy error - too short pass/psk"""
1154 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"1"}}'
1155 run_dpp_config_error(dev
, apdev
, conf
)
1157 def test_dpp_config_error_legacy_too_long_pass(dev
, apdev
):
1158 """DPP Config Object legacy error - too long pass/psk"""
1159 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"%s"}}' % (64*'A')
1160 run_dpp_config_error(dev
, apdev
, conf
)
1162 def test_dpp_config_error_legacy_psk_with_sae(dev
, apdev
):
1163 """DPP Config Object legacy error - psk_hex with SAE"""
1164 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"sae","psk_hex":"%s"}}' % (32*"12")
1165 run_dpp_config_error(dev
, apdev
, conf
)
1167 def test_dpp_config_error_legacy_no_pass_for_sae(dev
, apdev
):
1168 """DPP Config Object legacy error - no pass for SAE"""
1169 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk+sae","psk_hex":"%s"}}' % (32*"12")
1170 run_dpp_config_error(dev
, apdev
, conf
)
1172 def test_dpp_config_error_legacy_invalid_psk(dev
, apdev
):
1173 """DPP Config Object legacy error - invalid psk_hex"""
1174 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"%s"}}' % (32*"qa")
1175 run_dpp_config_error(dev
, apdev
, conf
)
1177 def test_dpp_config_error_legacy_too_short_psk(dev
, apdev
):
1178 """DPP Config Object legacy error - too short psk_hex"""
1179 conf
= '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"%s"}}' % (31*"12")
1180 run_dpp_config_error(dev
, apdev
, conf
)
1182 def get_der_int_32(val
):
1183 a
, b
= struct
.unpack('BB', val
[0:2])
1185 raise Exception("Invalid DER encoding of INTEGER")
1186 if b
> len(val
) - 2:
1187 raise Exception("Invalid length of INTEGER (truncated)")
1193 raise Exception("Too large INTEGER (32)")
1196 r
= (32 - b
) * b
'\x00' + val
[0:b
]
1198 raise Exception("Invalid length of INTEGER (32): %d" % b
)
1201 def ecdsa_sign(pkey
, message
, alg
="sha256"):
1202 sign
= OpenSSL
.crypto
.sign(pkey
, message
, alg
)
1203 logger
.debug("sign=" + binascii
.hexlify(sign
).decode())
1204 a
, b
= struct
.unpack('BB', sign
[0:2])
1206 raise Exception("Invalid DER encoding of ECDSA signature")
1207 if b
!= len(sign
) - 2:
1208 raise Exception("Invalid length of ECDSA signature")
1211 r
, sign
= get_der_int_32(sign
)
1212 s
, sign
= get_der_int_32(sign
)
1214 raise Exception("Extra data at the end of ECDSA signature")
1216 logger
.info("r=" + binascii
.hexlify(r
).decode())
1217 logger
.info("s=" + binascii
.hexlify(s
).decode())
1219 return base64
.urlsafe_b64encode(raw_sign
).decode().rstrip('=')
1221 p256_priv_key
= """-----BEGIN EC PRIVATE KEY-----
1222 MHcCAQEEIBVQij9ah629f1pu3tarDQGQvrzHgAkgYd1jHGiLxNajoAoGCCqGSM49
1223 AwEHoUQDQgAEAC9d2/JirKu72F2qLuv5jEFMD1Cqu9EiyGk7cOzn/2DJ51p2mEoW
1224 n03N6XRvTC+G7WPol9Ng97NAM2sK57+F/Q==
1225 -----END EC PRIVATE KEY-----"""
1226 p256_pub_key_x
= binascii
.unhexlify("002f5ddbf262acabbbd85daa2eebf98c414c0f50aabbd122c8693b70ece7ff60")
1227 p256_pub_key_y
= binascii
.unhexlify("c9e75a76984a169f4dcde9746f4c2f86ed63e897d360f7b340336b0ae7bf85fd")
1229 def run_dpp_config_connector(dev
, apdev
, expiry
=None, payload
=None,
1230 skip_net_access_key_mismatch
=True,
1232 if not openssl_imported
:
1233 raise HwsimSkip("OpenSSL python method not available")
1234 pkey
= OpenSSL
.crypto
.load_privatekey(OpenSSL
.crypto
.FILETYPE_PEM
,
1236 x
= base64
.urlsafe_b64encode(p256_pub_key_x
).decode().rstrip('=')
1237 y
= base64
.urlsafe_b64encode(p256_pub_key_y
).decode().rstrip('=')
1239 pubkey
= b
'\x04' + p256_pub_key_x
+ p256_pub_key_y
1240 kid
= base64
.urlsafe_b64encode(hashlib
.sha256(pubkey
).digest()).decode().rstrip('=')
1242 prot_hdr
= '{"typ":"dppCon","kid":"%s","alg":"ES256"}' % kid
1245 payload
= '{"groups":[{"groupId":"*","netRole":"sta"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}'
1247 payload
+= ',"expiry":"%s"' % expiry
1249 conn
= base64
.urlsafe_b64encode(prot_hdr
.encode()).decode().rstrip('=') + '.'
1250 conn
+= base64
.urlsafe_b64encode(payload
.encode()).decode().rstrip('=')
1251 sign
= ecdsa_sign(pkey
, conn
)
1253 run_dpp_config_error(dev
, apdev
,
1254 build_conf_obj(x
=x
, y
=y
, signed_connector
=conn
),
1255 skip_net_access_key_mismatch
=skip_net_access_key_mismatch
,
1256 conf_failure
=conf_failure
)
1258 def test_dpp_config_connector_error_ext_sign(dev
, apdev
):
1259 """DPP Config Object connector error - external signature calculation"""
1260 run_dpp_config_connector(dev
, apdev
, conf_failure
=False)
1262 def test_dpp_config_connector_error_too_short_timestamp(dev
, apdev
):
1263 """DPP Config Object connector error - too short timestamp"""
1264 run_dpp_config_connector(dev
, apdev
, expiry
="1")
1266 def test_dpp_config_connector_error_invalid_timestamp(dev
, apdev
):
1267 """DPP Config Object connector error - invalid timestamp"""
1268 run_dpp_config_connector(dev
, apdev
, expiry
=19*"1")
1270 def test_dpp_config_connector_error_invalid_timestamp_date(dev
, apdev
):
1271 """DPP Config Object connector error - invalid timestamp date"""
1272 run_dpp_config_connector(dev
, apdev
, expiry
="9999-99-99T99:99:99Z")
1274 def test_dpp_config_connector_error_invalid_time_zone(dev
, apdev
):
1275 """DPP Config Object connector error - invalid time zone"""
1276 run_dpp_config_connector(dev
, apdev
, expiry
="2018-01-01T00:00:00*")
1278 def test_dpp_config_connector_error_invalid_time_zone_2(dev
, apdev
):
1279 """DPP Config Object connector error - invalid time zone 2"""
1280 run_dpp_config_connector(dev
, apdev
, expiry
="2018-01-01T00:00:00+")
1282 def test_dpp_config_connector_error_expired_1(dev
, apdev
):
1283 """DPP Config Object connector error - expired 1"""
1284 run_dpp_config_connector(dev
, apdev
, expiry
="2018-01-01T00:00:00")
1286 def test_dpp_config_connector_error_expired_2(dev
, apdev
):
1287 """DPP Config Object connector error - expired 2"""
1288 run_dpp_config_connector(dev
, apdev
, expiry
="2018-01-01T00:00:00Z")
1290 def test_dpp_config_connector_error_expired_3(dev
, apdev
):
1291 """DPP Config Object connector error - expired 3"""
1292 run_dpp_config_connector(dev
, apdev
, expiry
="2018-01-01T00:00:00+01")
1294 def test_dpp_config_connector_error_expired_4(dev
, apdev
):
1295 """DPP Config Object connector error - expired 4"""
1296 run_dpp_config_connector(dev
, apdev
, expiry
="2018-01-01T00:00:00+01:02")
1298 def test_dpp_config_connector_error_expired_5(dev
, apdev
):
1299 """DPP Config Object connector error - expired 5"""
1300 run_dpp_config_connector(dev
, apdev
, expiry
="2018-01-01T00:00:00-01")
1302 def test_dpp_config_connector_error_expired_6(dev
, apdev
):
1303 """DPP Config Object connector error - expired 6"""
1304 run_dpp_config_connector(dev
, apdev
, expiry
="2018-01-01T00:00:00-01:02")
1306 def test_dpp_config_connector_error_no_groups(dev
, apdev
):
1307 """DPP Config Object connector error - no groups"""
1308 payload
= '{"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1309 run_dpp_config_connector(dev
, apdev
, payload
=payload
)
1311 def test_dpp_config_connector_error_empty_groups(dev
, apdev
):
1312 """DPP Config Object connector error - empty groups"""
1313 payload
= '{"groups":[],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1314 run_dpp_config_connector(dev
, apdev
, payload
=payload
)
1316 def test_dpp_config_connector_error_missing_group_id(dev
, apdev
):
1317 """DPP Config Object connector error - missing groupId"""
1318 payload
= '{"groups":[{"netRole":"sta"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1319 run_dpp_config_connector(dev
, apdev
, payload
=payload
)
1321 def test_dpp_config_connector_error_missing_net_role(dev
, apdev
):
1322 """DPP Config Object connector error - missing netRole"""
1323 payload
= '{"groups":[{"groupId":"*"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1324 run_dpp_config_connector(dev
, apdev
, payload
=payload
)
1326 def test_dpp_config_connector_error_missing_net_access_key(dev
, apdev
):
1327 """DPP Config Object connector error - missing netAccessKey"""
1328 payload
= '{"groups":[{"groupId":"*","netRole":"sta"}]}'
1329 run_dpp_config_connector(dev
, apdev
, payload
=payload
)
1331 def test_dpp_config_connector_error_net_access_key_mismatch(dev
, apdev
):
1332 """DPP Config Object connector error - netAccessKey mismatch"""
1333 payload
= '{"groups":[{"groupId":"*","netRole":"sta"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1334 run_dpp_config_connector(dev
, apdev
, payload
=payload
,
1335 skip_net_access_key_mismatch
=False)
1337 def test_dpp_gas_timeout(dev
, apdev
):
1338 """DPP and GAS server timeout for a query"""
1339 check_dpp_capab(dev
[0])
1340 check_dpp_capab(dev
[1])
1341 logger
.info("dev0 displays QR Code")
1342 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
1343 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
1345 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
1346 dev
[0].set("ext_mgmt_frame_handling", "1")
1347 dev
[0].dpp_listen(2412)
1349 # Force GAS fragmentation
1350 conf
= '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
1351 dev
[1].set("dpp_config_obj_override", conf
)
1353 dev
[1].dpp_auth_init(uri
=uri0
)
1355 # DPP Authentication Request
1356 msg
= dev
[0].mgmt_rx()
1357 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
1358 msg
['freq'], msg
['datarate'], msg
['ssi_signal'], binascii
.hexlify(msg
['frame']).decode())):
1359 raise Exception("MGMT_RX_PROCESS failed")
1361 # DPP Authentication Confirmation
1362 msg
= dev
[0].mgmt_rx()
1363 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
1364 msg
['freq'], msg
['datarate'], msg
['ssi_signal'], binascii
.hexlify(msg
['frame']).decode())):
1365 raise Exception("MGMT_RX_PROCESS failed")
1367 wait_auth_success(dev
[0], dev
[1])
1369 # DPP Configuration Response (GAS Initial Response frame)
1370 msg
= dev
[0].mgmt_rx()
1371 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
1372 msg
['freq'], msg
['datarate'], msg
['ssi_signal'], binascii
.hexlify(msg
['frame']).decode())):
1373 raise Exception("MGMT_RX_PROCESS failed")
1375 # GAS Comeback Response frame
1376 msg
= dev
[0].mgmt_rx()
1377 # Do not continue to force timeout on GAS server
1379 ev
= dev
[0].wait_event(["GAS-QUERY-DONE"], timeout
=10)
1381 raise Exception("GAS result not reported (Enrollee)")
1382 if "result=TIMEOUT" not in ev
:
1383 raise Exception("Unexpected GAS result (Enrollee): " + ev
)
1384 dev
[0].set("ext_mgmt_frame_handling", "0")
1386 ev
= dev
[1].wait_event(["DPP-CONF-FAILED"], timeout
=15)
1388 raise Exception("DPP configuration failure not reported (Configurator)")
1390 ev
= dev
[0].wait_event(["DPP-CONF-FAILED"], timeout
=1)
1392 raise Exception("DPP configuration failure not reported (Enrollee)")
1394 def test_dpp_akm_sha256(dev
, apdev
):
1395 """DPP AKM (SHA256)"""
1396 run_dpp_akm(dev
, apdev
, 32)
1398 def test_dpp_akm_sha384(dev
, apdev
):
1399 """DPP AKM (SHA384)"""
1400 run_dpp_akm(dev
, apdev
, 48)
1402 def test_dpp_akm_sha512(dev
, apdev
):
1403 """DPP AKM (SHA512)"""
1404 run_dpp_akm(dev
, apdev
, 64)
1406 def run_dpp_akm(dev
, apdev
, pmk_len
):
1407 check_dpp_capab(dev
[0])
1408 check_dpp_capab(dev
[1])
1409 params
= {"ssid": "dpp",
1411 "wpa_key_mgmt": "DPP",
1412 "rsn_pairwise": "CCMP",
1415 hapd
= hostapd
.add_ap(apdev
[0], params
)
1417 raise HwsimSkip("DPP not supported")
1419 id = dev
[0].connect("dpp", key_mgmt
="DPP", ieee80211w
="2", scan_freq
="2412",
1421 ev
= dev
[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout
=2)
1423 raise Exception("Network mismatch not reported")
1424 dev
[0].request("DISCONNECT")
1425 dev
[0].dump_monitor()
1427 bssid
= hapd
.own_addr()
1431 cmd
= "PMKSA_ADD %d %s %s %s 30240 43200 %d 0" % (id, bssid
, pmkid
, pmk
, akmp
)
1432 if "OK" not in dev
[0].request(cmd
):
1433 raise Exception("PMKSA_ADD failed (wpa_supplicant)")
1434 dev
[0].select_network(id, freq
="2412")
1435 ev
= dev
[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout
=2)
1436 dev
[0].request("DISCONNECT")
1437 dev
[0].dump_monitor()
1439 raise Exception("Association attempt was not rejected")
1440 if "status_code=53" not in ev
:
1441 raise Exception("Unexpected status code: " + ev
)
1443 addr
= dev
[0].own_addr()
1444 cmd
= "PMKSA_ADD %s %s %s 0 %d" % (addr
, pmkid
, pmk
, akmp
)
1445 if "OK" not in hapd
.request(cmd
):
1446 raise Exception("PMKSA_ADD failed (hostapd)")
1448 dev
[0].select_network(id, freq
="2412")
1449 dev
[0].wait_connected()
1450 val
= dev
[0].get_status_field("key_mgmt")
1452 raise Exception("Unexpected key_mgmt: " + val
)
1454 params1_csign
= "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
1455 params1_ap_connector
= "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
1456 params1_ap_netaccesskey
= "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
1457 params1_sta_connector
= "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
1458 params1_sta_netaccesskey
= "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
1460 def test_dpp_network_introduction(dev
, apdev
):
1461 """DPP network introduction"""
1462 check_dpp_capab(dev
[0])
1463 check_dpp_capab(dev
[1])
1465 params
= {"ssid": "dpp",
1467 "wpa_key_mgmt": "DPP",
1469 "rsn_pairwise": "CCMP",
1470 "dpp_connector": params1_ap_connector
,
1471 "dpp_csign": params1_csign
,
1472 "dpp_netaccesskey": params1_ap_netaccesskey
}
1474 hapd
= hostapd
.add_ap(apdev
[0], params
)
1476 raise HwsimSkip("DPP not supported")
1478 id = dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412",
1480 dpp_csign
=params1_csign
,
1481 dpp_connector
=params1_sta_connector
,
1482 dpp_netaccesskey
=params1_sta_netaccesskey
)
1483 val
= dev
[0].get_status_field("key_mgmt")
1485 raise Exception("Unexpected key_mgmt: " + val
)
1487 def test_dpp_network_introduction_expired(dev
, apdev
):
1488 """DPP network introduction with expired netaccesskey"""
1489 check_dpp_capab(dev
[0])
1490 check_dpp_capab(dev
[1])
1492 params
= {"ssid": "dpp",
1494 "wpa_key_mgmt": "DPP",
1496 "rsn_pairwise": "CCMP",
1497 "dpp_connector": params1_ap_connector
,
1498 "dpp_csign": params1_csign
,
1499 "dpp_netaccesskey": params1_ap_netaccesskey
,
1500 "dpp_netaccesskey_expiry": "1565530889"}
1502 hapd
= hostapd
.add_ap(apdev
[0], params
)
1504 raise HwsimSkip("DPP not supported")
1506 dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412",
1508 dpp_csign
=params1_csign
,
1509 dpp_connector
=params1_sta_connector
,
1510 dpp_netaccesskey
=params1_sta_netaccesskey
,
1512 ev
= hapd
.wait_event(["DPP-RX"], timeout
=10)
1514 raise Exception("No DPP Peer Discovery Request seen")
1515 if "type=5" not in ev
:
1516 raise Exception("Unexpected DPP message received: " + ev
)
1517 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=1)
1518 dev
[0].request("DISCONNECT")
1520 raise Exception("Connection reported")
1523 hapd
.set("dpp_netaccesskey_expiry", "2565530889")
1525 dev
[0].request("RECONNECT")
1526 dev
[0].wait_connected()
1528 def test_dpp_and_sae_akm(dev
, apdev
):
1529 """DPP and SAE AKMs"""
1530 check_dpp_capab(dev
[0])
1531 check_dpp_capab(dev
[1])
1532 if "SAE" not in dev
[1].get_capability("auth_alg"):
1533 raise HwsimSkip("SAE not supported")
1535 params
= {"ssid": "dpp+sae",
1537 "wpa_key_mgmt": "DPP SAE",
1539 "rsn_pairwise": "CCMP",
1540 "sae_password": "sae-password",
1541 "dpp_connector": params1_ap_connector
,
1542 "dpp_csign": params1_csign
,
1543 "dpp_netaccesskey": params1_ap_netaccesskey
}
1545 hapd
= hostapd
.add_ap(apdev
[0], params
)
1547 raise HwsimSkip("DPP not supported")
1549 id = dev
[0].connect("dpp+sae", key_mgmt
="DPP", scan_freq
="2412",
1551 dpp_csign
=params1_csign
,
1552 dpp_connector
=params1_sta_connector
,
1553 dpp_netaccesskey
=params1_sta_netaccesskey
)
1554 val
= dev
[0].get_status_field("key_mgmt")
1556 raise Exception("Unexpected key_mgmt for DPP: " + val
)
1558 dev
[1].request("SET sae_groups ")
1559 id = dev
[1].connect("dpp+sae", key_mgmt
="SAE", scan_freq
="2412",
1560 ieee80211w
="2", psk
="sae-password")
1561 val
= dev
[1].get_status_field("key_mgmt")
1563 raise Exception("Unexpected key_mgmt for SAE: " + val
)
1565 def test_dpp_ap_config(dev
, apdev
):
1566 """DPP and AP configuration"""
1567 run_dpp_ap_config(dev
, apdev
)
1569 def test_dpp_ap_config_p256_p256(dev
, apdev
):
1570 """DPP and AP configuration (P-256 + P-256)"""
1571 run_dpp_ap_config(dev
, apdev
, curve
="P-256", conf_curve
="P-256")
1573 def test_dpp_ap_config_p256_p384(dev
, apdev
):
1574 """DPP and AP configuration (P-256 + P-384)"""
1575 run_dpp_ap_config(dev
, apdev
, curve
="P-256", conf_curve
="P-384")
1577 def test_dpp_ap_config_p256_p521(dev
, apdev
):
1578 """DPP and AP configuration (P-256 + P-521)"""
1579 run_dpp_ap_config(dev
, apdev
, curve
="P-256", conf_curve
="P-521")
1581 def test_dpp_ap_config_p384_p256(dev
, apdev
):
1582 """DPP and AP configuration (P-384 + P-256)"""
1583 run_dpp_ap_config(dev
, apdev
, curve
="P-384", conf_curve
="P-256")
1585 def test_dpp_ap_config_p384_p384(dev
, apdev
):
1586 """DPP and AP configuration (P-384 + P-384)"""
1587 run_dpp_ap_config(dev
, apdev
, curve
="P-384", conf_curve
="P-384")
1589 def test_dpp_ap_config_p384_p521(dev
, apdev
):
1590 """DPP and AP configuration (P-384 + P-521)"""
1591 run_dpp_ap_config(dev
, apdev
, curve
="P-384", conf_curve
="P-521")
1593 def test_dpp_ap_config_p521_p256(dev
, apdev
):
1594 """DPP and AP configuration (P-521 + P-256)"""
1595 run_dpp_ap_config(dev
, apdev
, curve
="P-521", conf_curve
="P-256")
1597 def test_dpp_ap_config_p521_p384(dev
, apdev
):
1598 """DPP and AP configuration (P-521 + P-384)"""
1599 run_dpp_ap_config(dev
, apdev
, curve
="P-521", conf_curve
="P-384")
1601 def test_dpp_ap_config_p521_p521(dev
, apdev
):
1602 """DPP and AP configuration (P-521 + P-521)"""
1603 run_dpp_ap_config(dev
, apdev
, curve
="P-521", conf_curve
="P-521")
1605 def test_dpp_ap_config_bp256_bp256(dev
, apdev
):
1606 """DPP and AP configuration (BP-256 + BP-256)"""
1607 run_dpp_ap_config(dev
, apdev
, curve
="BP-256", conf_curve
="BP-256")
1609 def test_dpp_ap_config_bp384_bp384(dev
, apdev
):
1610 """DPP and AP configuration (BP-384 + BP-384)"""
1611 run_dpp_ap_config(dev
, apdev
, curve
="BP-384", conf_curve
="BP-384")
1613 def test_dpp_ap_config_bp512_bp512(dev
, apdev
):
1614 """DPP and AP configuration (BP-512 + BP-512)"""
1615 run_dpp_ap_config(dev
, apdev
, curve
="BP-512", conf_curve
="BP-512")
1617 def test_dpp_ap_config_p256_bp256(dev
, apdev
):
1618 """DPP and AP configuration (P-256 + BP-256)"""
1619 run_dpp_ap_config(dev
, apdev
, curve
="P-256", conf_curve
="BP-256")
1621 def test_dpp_ap_config_bp256_p256(dev
, apdev
):
1622 """DPP and AP configuration (BP-256 + P-256)"""
1623 run_dpp_ap_config(dev
, apdev
, curve
="BP-256", conf_curve
="P-256")
1625 def test_dpp_ap_config_p521_bp512(dev
, apdev
):
1626 """DPP and AP configuration (P-521 + BP-512)"""
1627 run_dpp_ap_config(dev
, apdev
, curve
="P-521", conf_curve
="BP-512")
1629 def test_dpp_ap_config_bp512_p521(dev
, apdev
):
1630 """DPP and AP configuration (BP-512 + P-521)"""
1631 run_dpp_ap_config(dev
, apdev
, curve
="BP-512", conf_curve
="P-521")
1633 def test_dpp_ap_config_reconfig_configurator(dev
, apdev
):
1634 """DPP and AP configuration with Configurator reconfiguration"""
1635 run_dpp_ap_config(dev
, apdev
, reconf_configurator
=True)
1637 def update_hapd_config(hapd
):
1638 ev
= hapd
.wait_event(["DPP-CONFOBJ-SSID"], timeout
=1)
1640 raise Exception("SSID not reported (AP)")
1641 ssid
= ev
.split(' ')[1]
1643 ev
= hapd
.wait_event(["DPP-CONNECTOR"], timeout
=1)
1645 raise Exception("Connector not reported (AP)")
1646 connector
= ev
.split(' ')[1]
1648 ev
= hapd
.wait_event(["DPP-C-SIGN-KEY"], timeout
=1)
1650 raise Exception("C-sign-key not reported (AP)")
1654 ev
= hapd
.wait_event(["DPP-NET-ACCESS-KEY"], timeout
=1)
1656 raise Exception("netAccessKey not reported (AP)")
1658 net_access_key
= p
[1]
1659 net_access_key_expiry
= p
[2] if len(p
) > 2 else None
1661 logger
.info("Update AP configuration to use key_mgmt=DPP")
1663 hapd
.set("ssid", ssid
)
1664 hapd
.set("utf8_ssid", "1")
1665 hapd
.set("wpa", "2")
1666 hapd
.set("wpa_key_mgmt", "DPP")
1667 hapd
.set("ieee80211w", "2")
1668 hapd
.set("rsn_pairwise", "CCMP")
1669 hapd
.set("dpp_connector", connector
)
1670 hapd
.set("dpp_csign", csign
)
1671 hapd
.set("dpp_netaccesskey", net_access_key
)
1672 if net_access_key_expiry
:
1673 hapd
.set("dpp_netaccesskey_expiry", net_access_key_expiry
)
1676 def run_dpp_ap_config(dev
, apdev
, curve
=None, conf_curve
=None,
1677 reconf_configurator
=False):
1678 check_dpp_capab(dev
[0])
1679 check_dpp_capab(dev
[1])
1680 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured"})
1681 check_dpp_capab(hapd
)
1683 id_h
= hapd
.dpp_bootstrap_gen(chan
="81/1", mac
=True, curve
=curve
)
1684 uri
= hapd
.request("DPP_BOOTSTRAP_GET_URI %d" % id_h
)
1686 conf_id
= dev
[0].dpp_configurator_add(curve
=conf_curve
)
1688 if reconf_configurator
:
1689 csign
= dev
[0].request("DPP_CONFIGURATOR_GET_KEY %d" % conf_id
)
1690 if "FAIL" in csign
or len(csign
) == 0:
1691 raise Exception("DPP_CONFIGURATOR_GET_KEY failed")
1693 dev
[0].dpp_auth_init(uri
=uri
, conf
="ap-dpp", configurator
=conf_id
)
1694 wait_auth_success(hapd
, dev
[0], configurator
=dev
[0], enrollee
=hapd
)
1695 update_hapd_config(hapd
)
1697 id1
= dev
[1].dpp_bootstrap_gen(chan
="81/1", mac
=True, curve
=curve
)
1698 uri1
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1
)
1700 if reconf_configurator
:
1701 dev
[0].dpp_configurator_remove(conf_id
)
1702 conf_id
= dev
[0].dpp_configurator_add(curve
=conf_curve
, key
=csign
)
1704 dev
[1].dpp_listen(2412)
1705 dev
[0].dpp_auth_init(uri
=uri1
, conf
="sta-dpp", configurator
=conf_id
)
1706 wait_auth_success(dev
[1], dev
[0], configurator
=dev
[0], enrollee
=dev
[1],
1707 stop_responder
=True)
1709 ev
= dev
[1].wait_event(["DPP-CONFOBJ-SSID"], timeout
=1)
1711 raise Exception("SSID not reported")
1712 ssid
= ev
.split(' ')[1]
1714 ev
= dev
[1].wait_event(["DPP-CONNECTOR"], timeout
=1)
1716 raise Exception("Connector not reported")
1717 connector
= ev
.split(' ')[1]
1719 ev
= dev
[1].wait_event(["DPP-C-SIGN-KEY"], timeout
=1)
1721 raise Exception("C-sign-key not reported")
1725 ev
= dev
[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout
=1)
1727 raise Exception("netAccessKey not reported")
1729 net_access_key
= p
[1]
1730 net_access_key_expiry
= p
[2] if len(p
) > 2 else None
1732 dev
[1].dump_monitor()
1734 id = dev
[1].connect(ssid
, key_mgmt
="DPP", ieee80211w
="2", scan_freq
="2412",
1735 only_add_network
=True)
1736 dev
[1].set_network_quoted(id, "dpp_connector", connector
)
1737 dev
[1].set_network(id, "dpp_csign", csign
)
1738 dev
[1].set_network(id, "dpp_netaccesskey", net_access_key
)
1739 if net_access_key_expiry
:
1740 dev
[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry
)
1742 logger
.info("Check data connection")
1743 dev
[1].select_network(id, freq
="2412")
1744 dev
[1].wait_connected()
1746 def test_dpp_auto_connect_1(dev
, apdev
):
1747 """DPP and auto connect (1)"""
1749 run_dpp_auto_connect(dev
, apdev
, 1)
1751 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1753 def test_dpp_auto_connect_2(dev
, apdev
):
1754 """DPP and auto connect (2)"""
1756 run_dpp_auto_connect(dev
, apdev
, 2)
1758 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1760 def test_dpp_auto_connect_2_connect_cmd(dev
, apdev
):
1761 """DPP and auto connect (2) using connect_cmd"""
1762 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
1763 wpas
.interface_add("wlan5", drv_params
="force_connect_cmd=1")
1764 dev_new
= [wpas
, dev
[1]]
1766 run_dpp_auto_connect(dev_new
, apdev
, 2)
1768 wpas
.set("dpp_config_processing", "0", allow_fail
=True)
1770 def run_dpp_auto_connect(dev
, apdev
, processing
):
1771 check_dpp_capab(dev
[0])
1772 check_dpp_capab(dev
[1])
1774 csign
= "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
1775 csign_pub
= "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
1776 ap_connector
= "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
1777 ap_netaccesskey
= "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
1779 params
= {"ssid": "test",
1781 "wpa_key_mgmt": "DPP",
1783 "rsn_pairwise": "CCMP",
1784 "dpp_connector": ap_connector
,
1785 "dpp_csign": csign_pub
,
1786 "dpp_netaccesskey": ap_netaccesskey
}
1788 hapd
= hostapd
.add_ap(apdev
[0], params
)
1790 raise HwsimSkip("DPP not supported")
1792 conf_id
= dev
[1].dpp_configurator_add(key
=csign
)
1793 dev
[0].set("dpp_config_processing", str(processing
))
1794 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
1795 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
1796 dev
[0].dpp_listen(2412)
1797 dev
[1].dpp_auth_init(uri
=uri0
, conf
="sta-dpp", configurator
=conf_id
)
1798 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0])
1799 ev
= dev
[0].wait_event(["DPP-NETWORK-ID"], timeout
=1)
1801 raise Exception("DPP network profile not generated")
1802 id = ev
.split(' ')[1]
1805 dev
[0].select_network(id, freq
=2412)
1807 dev
[0].wait_connected()
1808 hwsim_utils
.test_connectivity(dev
[0], hapd
)
1810 def test_dpp_auto_connect_legacy(dev
, apdev
):
1811 """DPP and auto connect (legacy)"""
1813 run_dpp_auto_connect_legacy(dev
, apdev
)
1815 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1817 def test_dpp_auto_connect_legacy_ssid_charset(dev
, apdev
):
1818 """DPP and auto connect (legacy, ssid_charset)"""
1820 run_dpp_auto_connect_legacy(dev
, apdev
, ssid_charset
=12345)
1822 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1824 def test_dpp_auto_connect_legacy_sae_1(dev
, apdev
):
1825 """DPP and auto connect (legacy SAE)"""
1827 run_dpp_auto_connect_legacy(dev
, apdev
, conf
='sta-sae', psk_sae
=True)
1829 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1831 def test_dpp_auto_connect_legacy_sae_2(dev
, apdev
):
1832 """DPP and auto connect (legacy SAE)"""
1834 run_dpp_auto_connect_legacy(dev
, apdev
, conf
='sta-sae', sae_only
=True)
1836 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1838 def test_dpp_auto_connect_legacy_psk_sae_1(dev
, apdev
):
1839 """DPP and auto connect (legacy PSK+SAE)"""
1841 run_dpp_auto_connect_legacy(dev
, apdev
, conf
='sta-psk-sae',
1844 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1846 def test_dpp_auto_connect_legacy_psk_sae_2(dev
, apdev
):
1847 """DPP and auto connect (legacy PSK+SAE)"""
1849 run_dpp_auto_connect_legacy(dev
, apdev
, conf
='sta-psk-sae',
1852 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1854 def test_dpp_auto_connect_legacy_psk_sae_3(dev
, apdev
):
1855 """DPP and auto connect (legacy PSK+SAE)"""
1857 run_dpp_auto_connect_legacy(dev
, apdev
, conf
='sta-psk-sae')
1859 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1861 def run_dpp_auto_connect_legacy(dev
, apdev
, conf
='sta-psk',
1863 psk_sae
=False, sae_only
=False):
1864 check_dpp_capab(dev
[0])
1865 check_dpp_capab(dev
[1])
1867 params
= hostapd
.wpa2_params(ssid
="dpp-legacy",
1868 passphrase
="secret passphrase")
1870 params
['wpa_key_mgmt'] = 'SAE'
1871 params
['ieee80211w'] = '2'
1873 params
['wpa_key_mgmt'] = 'WPA-PSK SAE'
1874 params
['ieee80211w'] = '1'
1875 params
['sae_require_mfp'] = '1'
1877 hapd
= hostapd
.add_ap(apdev
[0], params
)
1879 dev
[0].request("SET sae_groups ")
1880 dev
[0].set("dpp_config_processing", "2")
1881 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
1882 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
1884 dev
[0].dpp_listen(2412)
1885 dev
[1].dpp_auth_init(uri
=uri0
, conf
=conf
, ssid
="dpp-legacy",
1886 ssid_charset
=ssid_charset
,
1887 passphrase
="secret passphrase")
1888 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0])
1890 ev
= dev
[0].wait_event(["DPP-CONFOBJ-SSID-CHARSET"], timeout
=1)
1892 raise Exception("ssid_charset not reported")
1893 charset
= ev
.split(' ')[1]
1894 if charset
!= str(ssid_charset
):
1895 raise Exception("Incorrect ssid_charset reported: " + ev
)
1896 ev
= dev
[0].wait_event(["DPP-NETWORK-ID"], timeout
=1)
1898 raise Exception("DPP network profile not generated")
1899 id = ev
.split(' ')[1]
1901 dev
[0].wait_connected()
1903 def test_dpp_auto_connect_legacy_pmf_required(dev
, apdev
):
1904 """DPP and auto connect (legacy, PMF required)"""
1906 run_dpp_auto_connect_legacy_pmf_required(dev
, apdev
)
1908 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
1910 def run_dpp_auto_connect_legacy_pmf_required(dev
, apdev
):
1911 check_dpp_capab(dev
[0])
1912 check_dpp_capab(dev
[1])
1914 params
= hostapd
.wpa2_params(ssid
="dpp-legacy",
1915 passphrase
="secret passphrase")
1916 params
['wpa_key_mgmt'] = "WPA-PSK-SHA256"
1917 params
['ieee80211w'] = "2"
1918 hapd
= hostapd
.add_ap(apdev
[0], params
)
1920 dev
[0].set("dpp_config_processing", "2")
1921 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
1922 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
1923 dev
[0].dpp_listen(2412)
1924 dev
[1].dpp_auth_init(uri
=uri0
, conf
="sta-psk", ssid
="dpp-legacy",
1925 passphrase
="secret passphrase")
1926 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0])
1927 ev
= dev
[0].wait_event(["DPP-NETWORK-ID"], timeout
=1)
1929 raise Exception("DPP network profile not generated")
1930 dev
[0].wait_connected()
1932 def test_dpp_qr_code_auth_responder_configurator(dev
, apdev
):
1933 """DPP QR Code and responder as the configurator"""
1934 run_dpp_qr_code_auth_responder_configurator(dev
, apdev
, "")
1936 def test_dpp_qr_code_auth_responder_configurator_group_id(dev
, apdev
):
1937 """DPP QR Code and responder as the configurator with group_id)"""
1938 run_dpp_qr_code_auth_responder_configurator(dev
, apdev
,
1939 " group_id=test-group")
1941 def run_dpp_qr_code_auth_responder_configurator(dev
, apdev
, extra
):
1942 check_dpp_capab(dev
[0])
1943 check_dpp_capab(dev
[1])
1944 conf_id
= dev
[0].dpp_configurator_add()
1945 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
1946 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
1947 dev
[0].set("dpp_configurator_params",
1948 " conf=sta-dpp configurator=%d%s" % (conf_id
, extra
))
1949 dev
[0].dpp_listen(2412, role
="configurator")
1950 dev
[1].dpp_auth_init(uri
=uri0
, role
="enrollee")
1951 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[0], enrollee
=dev
[1],
1952 stop_responder
=True)
1954 def test_dpp_qr_code_hostapd_init(dev
, apdev
):
1955 """DPP QR Code and hostapd as initiator"""
1956 check_dpp_capab(dev
[0])
1957 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured",
1959 check_dpp_capab(hapd
)
1960 conf_id
= dev
[0].dpp_configurator_add()
1961 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/6", mac
=True)
1962 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
1963 dev
[0].set("dpp_configurator_params",
1964 " conf=ap-dpp configurator=%d" % conf_id
)
1965 dev
[0].dpp_listen(2437, role
="configurator")
1966 hapd
.dpp_auth_init(uri
=uri0
, role
="enrollee")
1967 wait_auth_success(dev
[0], hapd
, configurator
=dev
[0], enrollee
=hapd
,
1968 stop_responder
=True)
1970 def test_dpp_qr_code_hostapd_init_offchannel(dev
, apdev
):
1971 """DPP QR Code and hostapd as initiator (offchannel)"""
1972 run_dpp_qr_code_hostapd_init_offchannel(dev
, apdev
, None)
1974 def test_dpp_qr_code_hostapd_init_offchannel_neg_freq(dev
, apdev
):
1975 """DPP QR Code and hostapd as initiator (offchannel, neg_freq)"""
1976 run_dpp_qr_code_hostapd_init_offchannel(dev
, apdev
, "neg_freq=2437")
1978 def run_dpp_qr_code_hostapd_init_offchannel(dev
, apdev
, extra
):
1979 check_dpp_capab(dev
[0])
1980 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured",
1982 check_dpp_capab(hapd
)
1983 conf_id
= dev
[0].dpp_configurator_add()
1984 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1,81/11", mac
=True)
1985 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
1986 dev
[0].set("dpp_configurator_params",
1987 " conf=ap-dpp configurator=%d" % conf_id
)
1988 dev
[0].dpp_listen(2462, role
="configurator")
1989 hapd
.dpp_auth_init(uri
=uri0
, role
="enrollee", extra
=extra
)
1990 wait_auth_success(dev
[0], hapd
, configurator
=dev
[0], enrollee
=hapd
,
1991 stop_responder
=True)
1993 def test_dpp_test_vector_p_256(dev
, apdev
):
1994 """DPP P-256 test vector (mutual auth)"""
1995 check_dpp_capab(dev
[0])
1996 check_dpp_capab(dev
[1])
1998 # Responder bootstrapping key
1999 priv
= "54ce181a98525f217216f59b245f60e9df30ac7f6b26c939418cfc3c42d1afa0"
2000 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/11", mac
=True, key
="30310201010420" + priv
+ "a00a06082a8648ce3d030107")
2001 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
2003 # Responder protocol keypair override
2004 priv
= "f798ed2e19286f6a6efe210b1863badb99af2a14b497634dbfd2a97394fb5aa5"
2005 dev
[0].set("dpp_protocol_key_override",
2006 "30310201010420" + priv
+ "a00a06082a8648ce3d030107")
2008 dev
[0].set("dpp_nonce_override", "3d0cfb011ca916d796f7029ff0b43393")
2010 # Initiator bootstrapping key
2011 priv
= "15b2a83c5a0a38b61f2aa8200ee4994b8afdc01c58507d10d0a38f7eedf051bb"
2012 id1
= dev
[1].dpp_bootstrap_gen(key
="30310201010420" + priv
+ "a00a06082a8648ce3d030107")
2013 uri1
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1
)
2015 # Initiator protocol keypair override
2016 priv
= "a87de9afbb406c96e5f79a3df895ecac3ad406f95da66314c8cb3165e0c61783"
2017 dev
[1].set("dpp_protocol_key_override",
2018 "30310201010420" + priv
+ "a00a06082a8648ce3d030107")
2020 dev
[1].set("dpp_nonce_override", "13f4602a16daeb69712263b9c46cba31")
2022 dev
[0].dpp_qr_code(uri1
)
2023 dev
[0].dpp_listen(2462, qr
="mutual")
2024 dev
[1].dpp_auth_init(uri
=uri0
, own
=id1
, neg_freq
=2412)
2025 wait_auth_success(dev
[0], dev
[1])
2027 def test_dpp_test_vector_p_256_b(dev
, apdev
):
2028 """DPP P-256 test vector (Responder-only auth)"""
2029 check_dpp_capab(dev
[0])
2030 check_dpp_capab(dev
[1])
2032 # Responder bootstrapping key
2033 priv
= "54ce181a98525f217216f59b245f60e9df30ac7f6b26c939418cfc3c42d1afa0"
2034 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/11", mac
=True, key
="30310201010420" + priv
+ "a00a06082a8648ce3d030107")
2035 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
2037 # Responder protocol keypair override
2038 priv
= "f798ed2e19286f6a6efe210b1863badb99af2a14b497634dbfd2a97394fb5aa5"
2039 dev
[0].set("dpp_protocol_key_override",
2040 "30310201010420" + priv
+ "a00a06082a8648ce3d030107")
2042 dev
[0].set("dpp_nonce_override", "3d0cfb011ca916d796f7029ff0b43393")
2044 # Initiator bootstrapping key
2045 priv
= "15b2a83c5a0a38b61f2aa8200ee4994b8afdc01c58507d10d0a38f7eedf051bb"
2046 id1
= dev
[1].dpp_bootstrap_gen(key
="30310201010420" + priv
+ "a00a06082a8648ce3d030107")
2047 uri1
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1
)
2049 # Initiator protocol keypair override
2050 priv
= "a87de9afbb406c96e5f79a3df895ecac3ad406f95da66314c8cb3165e0c61783"
2051 dev
[1].set("dpp_protocol_key_override",
2052 "30310201010420" + priv
+ "a00a06082a8648ce3d030107")
2054 dev
[1].set("dpp_nonce_override", "13f4602a16daeb69712263b9c46cba31")
2056 dev
[0].dpp_listen(2462)
2057 dev
[1].dpp_auth_init(uri
=uri0
, own
=id1
, neg_freq
=2412)
2058 wait_auth_success(dev
[0], dev
[1])
2060 def der_priv_key_p_521(priv
):
2061 if len(priv
) != 2 * 66:
2062 raise Exception("Unexpected der_priv_key_p_521 parameter: " + priv
)
2063 der_prefix
= "3081500201010442"
2064 der_postfix
= "a00706052b81040023"
2065 return der_prefix
+ priv
+ der_postfix
2067 def test_dpp_test_vector_p_521(dev
, apdev
):
2068 """DPP P-521 test vector (mutual auth)"""
2069 check_dpp_capab(dev
[0])
2070 check_dpp_capab(dev
[1])
2072 # Responder bootstrapping key
2073 priv
= "0061e54f518cdf859735da3dd64c6f72c2f086f41a6fd52915152ea2fe0f24ddaecd8883730c9c9fd82cf7c043a41021696388cf5190b731dd83638bcd56d8b6c743"
2074 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/11", mac
=True,
2075 key
=der_priv_key_p_521(priv
))
2076 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
2078 # Responder protocol keypair override
2079 priv
= "01d8b7b17cd1b0a33f7c66fb4220999329cdaf4f8b44b2ffadde8ab8ed8abffa9f5358c5b1caae26709ca4fb78e52a4d08f2e4f24111a36a6f440d20a0000ff51597"
2080 dev
[0].set("dpp_protocol_key_override", der_priv_key_p_521(priv
))
2082 dev
[0].set("dpp_nonce_override",
2083 "d749a782012eb0a8595af30b2dfc8d0880d004ebddb55ecc5afbdef18c400e01")
2085 # Initiator bootstrapping key
2086 priv
= "0060c10df14af5ef27f6e362d31bdd9eeb44be77a323ba64b08f3f03d58b92cbfe05c182a91660caa081ca344243c47b5aa088bcdf738840eb35f0218b9f26881e02"
2087 id1
= dev
[1].dpp_bootstrap_gen(key
=der_priv_key_p_521(priv
))
2088 uri1
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1
)
2090 # Initiator protocol keypair override
2091 priv
= "019c1c08caaeec38fb931894699b095bc3ab8c1ec7ef0622d2e3eba821477c8c6fca41774f21166ad98aebda37c067d9aa08a8a2e1b5c44c61f2bae02a61f85d9661"
2092 dev
[1].set("dpp_protocol_key_override", der_priv_key_p_521(priv
))
2094 dev
[1].set("dpp_nonce_override",
2095 "de972af3847bec3ba2aedd9f5c21cfdec7bf0bc5fe8b276cbcd0267807fb15b0")
2097 dev
[0].dpp_qr_code(uri1
)
2098 dev
[0].dpp_listen(2462, qr
="mutual")
2099 dev
[1].dpp_auth_init(uri
=uri0
, own
=id1
, neg_freq
=2412)
2100 wait_auth_success(dev
[0], dev
[1])
2102 def test_dpp_pkex(dev
, apdev
):
2104 run_dpp_pkex(dev
, apdev
)
2106 def test_dpp_pkex_p256(dev
, apdev
):
2107 """DPP and PKEX (P-256)"""
2108 run_dpp_pkex(dev
, apdev
, "P-256")
2110 def test_dpp_pkex_p384(dev
, apdev
):
2111 """DPP and PKEX (P-384)"""
2112 run_dpp_pkex(dev
, apdev
, "P-384")
2114 def test_dpp_pkex_p521(dev
, apdev
):
2115 """DPP and PKEX (P-521)"""
2116 run_dpp_pkex(dev
, apdev
, "P-521")
2118 def test_dpp_pkex_bp256(dev
, apdev
):
2119 """DPP and PKEX (BP-256)"""
2120 run_dpp_pkex(dev
, apdev
, "brainpoolP256r1")
2122 def test_dpp_pkex_bp384(dev
, apdev
):
2123 """DPP and PKEX (BP-384)"""
2124 run_dpp_pkex(dev
, apdev
, "brainpoolP384r1")
2126 def test_dpp_pkex_bp512(dev
, apdev
):
2127 """DPP and PKEX (BP-512)"""
2128 run_dpp_pkex(dev
, apdev
, "brainpoolP512r1")
2130 def test_dpp_pkex_config(dev
, apdev
):
2131 """DPP and PKEX with initiator as the configurator"""
2132 check_dpp_capab(dev
[1])
2133 conf_id
= dev
[1].dpp_configurator_add()
2134 run_dpp_pkex(dev
, apdev
,
2135 init_extra
="conf=sta-dpp configurator=%d" % (conf_id
),
2138 def test_dpp_pkex_no_identifier(dev
, apdev
):
2139 """DPP and PKEX without identifier"""
2140 run_dpp_pkex(dev
, apdev
, identifier_i
=None, identifier_r
=None)
2142 def test_dpp_pkex_identifier_mismatch(dev
, apdev
):
2143 """DPP and PKEX with different identifiers"""
2144 run_dpp_pkex(dev
, apdev
, identifier_i
="foo", identifier_r
="bar",
2145 expect_no_resp
=True)
2147 def test_dpp_pkex_identifier_mismatch2(dev
, apdev
):
2148 """DPP and PKEX with initiator using identifier and the responder not"""
2149 run_dpp_pkex(dev
, apdev
, identifier_i
="foo", identifier_r
=None,
2150 expect_no_resp
=True)
2152 def test_dpp_pkex_identifier_mismatch3(dev
, apdev
):
2153 """DPP and PKEX with responder using identifier and the initiator not"""
2154 run_dpp_pkex(dev
, apdev
, identifier_i
=None, identifier_r
="bar",
2155 expect_no_resp
=True)
2157 def run_dpp_pkex(dev
, apdev
, curve
=None, init_extra
=None, check_config
=False,
2158 identifier_i
="test", identifier_r
="test",
2159 expect_no_resp
=False):
2160 check_dpp_capab(dev
[0], curve
and "brainpool" in curve
)
2161 check_dpp_capab(dev
[1], curve
and "brainpool" in curve
)
2162 dev
[0].dpp_pkex_resp(2437, identifier
=identifier_r
, code
="secret",
2164 dev
[1].dpp_pkex_init(identifier
=identifier_i
, code
="secret", curve
=curve
,
2168 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=10)
2170 raise Exception("DPP PKEX frame not received")
2171 ev
= dev
[1].wait_event(["DPP-AUTH-SUCCESS"], timeout
=1)
2173 raise Exception("DPP authentication succeeded")
2174 ev
= dev
[0].wait_event(["DPP-AUTH-SUCCESS"], timeout
=0.1)
2176 raise Exception("DPP authentication succeeded")
2179 wait_auth_success(dev
[0], dev
[1],
2180 configurator
=dev
[1] if check_config
else None,
2181 enrollee
=dev
[0] if check_config
else None)
2183 def test_dpp_pkex_5ghz(dev
, apdev
):
2184 """DPP and PKEX on 5 GHz"""
2186 dev
[0].request("SET country US")
2187 dev
[1].request("SET country US")
2188 ev
= dev
[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=1)
2190 ev
= dev
[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"],
2192 run_dpp_pkex_5ghz(dev
, apdev
)
2194 dev
[0].request("SET country 00")
2195 dev
[1].request("SET country 00")
2196 subprocess
.call(['iw', 'reg', 'set', '00'])
2199 def run_dpp_pkex_5ghz(dev
, apdev
):
2200 check_dpp_capab(dev
[0])
2201 check_dpp_capab(dev
[1])
2202 dev
[0].dpp_pkex_resp(5745, identifier
="test", code
="secret")
2203 dev
[1].dpp_pkex_init(identifier
="test", code
="secret")
2204 wait_auth_success(dev
[0], dev
[1], timeout
=20)
2206 def test_dpp_pkex_test_vector(dev
, apdev
):
2207 """DPP and PKEX (P-256) test vector"""
2208 check_dpp_capab(dev
[0])
2209 check_dpp_capab(dev
[1])
2211 init_addr
= "ac:64:91:f4:52:07"
2212 resp_addr
= "6e:5e:ce:6e:f3:dd"
2214 identifier
= "joes_key"
2215 code
= "thisisreallysecret"
2217 # Initiator bootstrapping private key
2218 init_priv
= "5941b51acfc702cdc1c347264beb2920db88eb1a0bf03a211868b1632233c269"
2220 # Responder bootstrapping private key
2221 resp_priv
= "2ae8956293f49986b6d0b8169a86805d9232babb5f6813fdfe96f19d59536c60"
2223 # Initiator x/X keypair override
2224 init_x_priv
= "8365c5ed93d751bef2d92b410dc6adfd95670889183fac1bd66759ad85c3187a"
2226 # Responder y/Y keypair override
2227 resp_y_priv
= "d98faa24d7dd3f592665d71a95c862bfd02c4c48acb0c515a41cbc6e929675ea"
2229 p256_prefix
= "30310201010420"
2230 p256_postfix
= "a00a06082a8648ce3d030107"
2232 dev
[0].set("dpp_pkex_own_mac_override", resp_addr
)
2233 dev
[0].set("dpp_pkex_peer_mac_override", init_addr
)
2234 dev
[1].set("dpp_pkex_own_mac_override", init_addr
)
2235 dev
[1].set("dpp_pkex_peer_mac_override", resp_addr
)
2237 # Responder y/Y keypair override
2238 dev
[0].set("dpp_pkex_ephemeral_key_override",
2239 p256_prefix
+ resp_y_priv
+ p256_postfix
)
2241 # Initiator x/X keypair override
2242 dev
[1].set("dpp_pkex_ephemeral_key_override",
2243 p256_prefix
+ init_x_priv
+ p256_postfix
)
2245 dev
[0].dpp_pkex_resp(2437, identifier
=identifier
, code
=code
,
2246 key
=p256_prefix
+ resp_priv
+ p256_postfix
)
2247 dev
[1].dpp_pkex_init(identifier
=identifier
, code
=code
,
2248 key
=p256_prefix
+ init_priv
+ p256_postfix
)
2249 wait_auth_success(dev
[0], dev
[1])
2251 def test_dpp_pkex_code_mismatch(dev
, apdev
):
2252 """DPP and PKEX with mismatching code"""
2253 check_dpp_capab(dev
[0])
2254 check_dpp_capab(dev
[1])
2255 dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret")
2256 id1
= dev
[1].dpp_pkex_init(identifier
="test", code
="unknown")
2257 wait_dpp_fail(dev
[0], "possible PKEX code mismatch")
2258 dev
[0].dump_monitor()
2259 dev
[1].dump_monitor()
2260 dev
[1].dpp_pkex_init(identifier
="test", code
="secret", use_id
=id1
)
2261 wait_auth_success(dev
[0], dev
[1])
2263 def test_dpp_pkex_code_mismatch_limit(dev
, apdev
):
2264 """DPP and PKEX with mismatching code limit"""
2265 check_dpp_capab(dev
[0])
2266 check_dpp_capab(dev
[1])
2267 dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret")
2271 dev
[0].dump_monitor()
2272 dev
[1].dump_monitor()
2273 id1
= dev
[1].dpp_pkex_init(identifier
="test", code
="unknown",
2275 wait_dpp_fail(dev
[0], "possible PKEX code mismatch")
2277 ev
= dev
[0].wait_event(["DPP-PKEX-T-LIMIT"], timeout
=1)
2279 raise Exception("PKEX t limit not reported")
2281 def test_dpp_pkex_curve_mismatch(dev
, apdev
):
2282 """DPP and PKEX with mismatching curve"""
2283 check_dpp_capab(dev
[0])
2284 check_dpp_capab(dev
[1])
2285 dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret", curve
="P-256")
2286 dev
[1].dpp_pkex_init(identifier
="test", code
="secret", curve
="P-384")
2287 wait_dpp_fail(dev
[0], "Mismatching PKEX curve: peer=20 own=19")
2288 wait_dpp_fail(dev
[1], "Peer indicated mismatching PKEX group - proposed 19")
2290 def test_dpp_pkex_curve_mismatch_failure(dev
, apdev
):
2291 """DPP and PKEX with mismatching curve (local failure)"""
2292 run_dpp_pkex_curve_mismatch_failure(dev
, apdev
, "=dpp_pkex_rx_exchange_req")
2294 def test_dpp_pkex_curve_mismatch_failure2(dev
, apdev
):
2295 """DPP and PKEX with mismatching curve (local failure 2)"""
2296 run_dpp_pkex_curve_mismatch_failure(dev
, apdev
,
2297 "dpp_pkex_build_exchange_resp")
2299 def run_dpp_pkex_curve_mismatch_failure(dev
, apdev
, func
):
2300 check_dpp_capab(dev
[0])
2301 check_dpp_capab(dev
[1])
2302 dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret", curve
="P-256")
2304 with
alloc_fail(dev
[0], 1, func
):
2305 dev
[1].dpp_pkex_init(identifier
="test", code
="secret", curve
="P-384")
2307 ev
= dev
[0].wait_event(["DPP-FAIL"], timeout
=5)
2309 raise Exception("Failure not reported (dev 0)")
2310 if "Mismatching PKEX curve: peer=20 own=19" not in ev
:
2311 raise Exception("Unexpected result: " + ev
)
2312 wait_dpp_fail(dev
[0], "Mismatching PKEX curve: peer=20 own=19")
2314 def test_dpp_pkex_exchange_resp_processing_failure(dev
, apdev
):
2315 """DPP and PKEX with local failure in processing Exchange Resp"""
2316 check_dpp_capab(dev
[0])
2317 check_dpp_capab(dev
[1])
2318 dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret")
2320 with
fail_test(dev
[1], 1, "dpp_pkex_derive_Qr;dpp_pkex_rx_exchange_resp"):
2321 dev
[1].dpp_pkex_init(identifier
="test", code
="secret")
2322 wait_fail_trigger(dev
[1], "GET_FAIL")
2324 def test_dpp_pkex_commit_reveal_req_processing_failure(dev
, apdev
):
2325 """DPP and PKEX with local failure in processing Commit Reveal Req"""
2326 check_dpp_capab(dev
[0])
2327 check_dpp_capab(dev
[1])
2328 dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret")
2330 with
alloc_fail(dev
[0], 1,
2331 "dpp_get_pubkey_point;dpp_pkex_rx_commit_reveal_req"):
2332 dev
[1].dpp_pkex_init(identifier
="test", code
="secret")
2333 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
2335 def test_dpp_pkex_config2(dev
, apdev
):
2336 """DPP and PKEX with responder as the configurator"""
2337 check_dpp_capab(dev
[0])
2338 conf_id
= dev
[0].dpp_configurator_add()
2339 dev
[0].set("dpp_configurator_params",
2340 " conf=sta-dpp configurator=%d" % conf_id
)
2341 run_dpp_pkex2(dev
, apdev
)
2343 def run_dpp_pkex2(dev
, apdev
, curve
=None, init_extra
=""):
2344 check_dpp_capab(dev
[0])
2345 check_dpp_capab(dev
[1])
2346 dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret", curve
=curve
,
2347 listen_role
="configurator")
2348 dev
[1].dpp_pkex_init(identifier
="test", code
="secret", role
="enrollee",
2349 curve
=curve
, extra
=init_extra
)
2350 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[0], enrollee
=dev
[1])
2352 def test_dpp_pkex_no_responder(dev
, apdev
):
2353 """DPP and PKEX with no responder (retry behavior)"""
2354 check_dpp_capab(dev
[0])
2355 dev
[0].dpp_pkex_init(identifier
="test", code
="secret")
2358 ev
= dev
[0].wait_event(["DPP-TX ", "DPP-FAIL"], timeout
=5)
2360 raise Exception("DPP PKEX failure not reported")
2361 if "DPP-FAIL" not in ev
:
2363 if "No response from PKEX peer" not in ev
:
2364 raise Exception("Unexpected failure reason: " + ev
)
2367 def test_dpp_pkex_after_retry(dev
, apdev
):
2368 """DPP and PKEX completing after retry"""
2369 check_dpp_capab(dev
[0])
2370 dev
[0].dpp_pkex_init(identifier
="test", code
="secret")
2372 dev
[1].dpp_pkex_resp(2437, identifier
="test", code
="secret")
2373 wait_auth_success(dev
[1], dev
[0], configurator
=dev
[0], enrollee
=dev
[1],
2374 allow_enrollee_failure
=True)
2376 def test_dpp_pkex_hostapd_responder(dev
, apdev
):
2377 """DPP PKEX with hostapd as responder"""
2378 check_dpp_capab(dev
[0])
2379 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured",
2381 check_dpp_capab(hapd
)
2382 hapd
.dpp_pkex_resp(2437, identifier
="test", code
="secret")
2383 conf_id
= dev
[0].dpp_configurator_add()
2384 dev
[0].dpp_pkex_init(identifier
="test", code
="secret",
2385 extra
="conf=ap-dpp configurator=%d" % conf_id
)
2386 wait_auth_success(hapd
, dev
[0], configurator
=dev
[0], enrollee
=hapd
,
2387 stop_initiator
=True)
2389 def test_dpp_pkex_hostapd_initiator(dev
, apdev
):
2390 """DPP PKEX with hostapd as initiator"""
2391 check_dpp_capab(dev
[0])
2392 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured",
2394 check_dpp_capab(hapd
)
2395 conf_id
= dev
[0].dpp_configurator_add()
2396 dev
[0].set("dpp_configurator_params",
2397 " conf=ap-dpp configurator=%d" % conf_id
)
2398 dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret",
2399 listen_role
="configurator")
2400 hapd
.dpp_pkex_init(identifier
="test", code
="secret", role
="enrollee")
2401 wait_auth_success(hapd
, dev
[0], configurator
=dev
[0], enrollee
=hapd
,
2402 stop_initiator
=True)
2404 def test_dpp_hostapd_configurator(dev
, apdev
):
2405 """DPP with hostapd as configurator/initiator"""
2406 check_dpp_capab(dev
[0])
2407 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured",
2409 check_dpp_capab(hapd
)
2410 conf_id
= hapd
.dpp_configurator_add()
2411 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
2412 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
2413 id1
= hapd
.dpp_qr_code(uri0
)
2414 res
= hapd
.request("DPP_BOOTSTRAP_INFO %d" % id1
)
2416 raise Exception("DPP_BOOTSTRAP_INFO failed")
2417 if "type=QRCODE" not in res
:
2418 raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
2419 if "mac_addr=" + dev
[0].own_addr() not in res
:
2420 raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
2421 dev
[0].dpp_listen(2412)
2422 hapd
.dpp_auth_init(peer
=id1
, configurator
=conf_id
, conf
="sta-dpp")
2423 wait_auth_success(dev
[0], hapd
, configurator
=hapd
, enrollee
=dev
[0],
2424 stop_responder
=True)
2426 def test_dpp_hostapd_configurator_responder(dev
, apdev
):
2427 """DPP with hostapd as configurator/responder"""
2428 check_dpp_capab(dev
[0])
2429 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured",
2431 check_dpp_capab(hapd
)
2432 conf_id
= hapd
.dpp_configurator_add()
2433 hapd
.set("dpp_configurator_params",
2434 " conf=sta-dpp configurator=%d" % conf_id
)
2435 id0
= hapd
.dpp_bootstrap_gen(chan
="81/1", mac
=True)
2436 uri0
= hapd
.request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
2437 dev
[0].dpp_auth_init(uri
=uri0
, role
="enrollee")
2438 wait_auth_success(hapd
, dev
[0], configurator
=hapd
, enrollee
=dev
[0],
2439 stop_initiator
=True)
2441 def test_dpp_own_config(dev
, apdev
):
2442 """DPP configurator signing own connector"""
2444 run_dpp_own_config(dev
, apdev
)
2446 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
2448 def test_dpp_own_config_group_id(dev
, apdev
):
2449 """DPP configurator signing own connector"""
2451 run_dpp_own_config(dev
, apdev
, extra
=" group_id=test-group")
2453 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
2455 def test_dpp_own_config_curve_mismatch(dev
, apdev
):
2456 """DPP configurator signing own connector using mismatching curve"""
2458 run_dpp_own_config(dev
, apdev
, own_curve
="BP-384", expect_failure
=True)
2460 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
2462 def run_dpp_own_config(dev
, apdev
, own_curve
=None, expect_failure
=False,
2464 check_dpp_capab(dev
[0], own_curve
and "BP" in own_curve
)
2465 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured"})
2466 check_dpp_capab(hapd
)
2467 id_h
= hapd
.dpp_bootstrap_gen(chan
="81/1", mac
=True)
2468 uri
= hapd
.request("DPP_BOOTSTRAP_GET_URI %d" % id_h
)
2469 conf_id
= dev
[0].dpp_configurator_add()
2470 dev
[0].dpp_auth_init(uri
=uri
, conf
="ap-dpp", configurator
=conf_id
,
2472 wait_auth_success(hapd
, dev
[0], configurator
=dev
[0], enrollee
=hapd
)
2473 update_hapd_config(hapd
)
2475 dev
[0].set("dpp_config_processing", "1")
2476 cmd
= "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d%s" % (conf_id
, extra
)
2478 cmd
+= " curve=" + own_curve
2479 res
= dev
[0].request(cmd
)
2481 raise Exception("Failed to generate own configuration")
2483 ev
= dev
[0].wait_event(["DPP-NETWORK-ID"], timeout
=1)
2485 raise Exception("DPP network profile not generated")
2486 id = ev
.split(' ')[1]
2487 dev
[0].select_network(id, freq
="2412")
2489 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=1)
2491 raise Exception("Unexpected connection")
2492 dev
[0].request("DISCONNECT")
2494 dev
[0].wait_connected()
2496 def test_dpp_own_config_ap(dev
, apdev
):
2497 """DPP configurator (AP) signing own connector"""
2499 run_dpp_own_config_ap(dev
, apdev
)
2501 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
2503 def test_dpp_own_config_ap_group_id(dev
, apdev
):
2504 """DPP configurator (AP) signing own connector (group_id)"""
2506 run_dpp_own_config_ap(dev
, apdev
, extra
=" group_id=test-group")
2508 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
2510 def test_dpp_own_config_ap_reconf(dev
, apdev
):
2511 """DPP configurator (AP) signing own connector and configurator reconf"""
2513 run_dpp_own_config_ap(dev
, apdev
)
2515 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
2517 def run_dpp_own_config_ap(dev
, apdev
, reconf_configurator
=False, extra
=None):
2518 check_dpp_capab(dev
[0])
2519 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured"})
2520 check_dpp_capab(hapd
)
2521 conf_id
= hapd
.dpp_configurator_add()
2522 if reconf_configurator
:
2523 csign
= hapd
.request("DPP_CONFIGURATOR_GET_KEY %d" % conf_id
)
2524 if "FAIL" in csign
or len(csign
) == 0:
2525 raise Exception("DPP_CONFIGURATOR_GET_KEY failed")
2527 cmd
= "DPP_CONFIGURATOR_SIGN conf=ap-dpp configurator=%d%s" % (conf_id
, extra
)
2528 res
= hapd
.request(cmd
)
2530 raise Exception("Failed to generate own configuration")
2531 update_hapd_config(hapd
)
2533 if reconf_configurator
:
2534 hapd
.dpp_configurator_remove(conf_id
)
2535 conf_id
= hapd
.dpp_configurator_add(key
=csign
)
2537 id = dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
2538 uri
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
2539 dev
[0].set("dpp_config_processing", "2")
2540 dev
[0].dpp_listen(2412)
2541 hapd
.dpp_auth_init(uri
=uri
, conf
="sta-dpp", configurator
=conf_id
,
2543 wait_auth_success(dev
[0], hapd
, configurator
=hapd
, enrollee
=dev
[0])
2544 dev
[0].wait_connected()
2546 def test_dpp_intro_mismatch(dev
, apdev
):
2547 """DPP network introduction mismatch cases"""
2550 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
2551 wpas
.interface_add("wlan5")
2552 check_dpp_capab(wpas
)
2553 run_dpp_intro_mismatch(dev
, apdev
, wpas
)
2555 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
2556 dev
[2].set("dpp_config_processing", "0", allow_fail
=True)
2558 wpas
.set("dpp_config_processing", "0", allow_fail
=True)
2560 def run_dpp_intro_mismatch(dev
, apdev
, wpas
):
2561 check_dpp_capab(dev
[0])
2562 check_dpp_capab(dev
[1])
2563 check_dpp_capab(dev
[2])
2564 logger
.info("Start AP in unconfigured state")
2565 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured"})
2566 check_dpp_capab(hapd
)
2567 id_h
= hapd
.dpp_bootstrap_gen(chan
="81/1", mac
=True)
2568 uri
= hapd
.request("DPP_BOOTSTRAP_GET_URI %d" % id_h
)
2569 logger
.info("Provision AP with DPP configuration")
2570 conf_id
= dev
[1].dpp_configurator_add()
2571 dev
[1].set("dpp_groups_override", '[{"groupId":"a","netRole":"ap"}]')
2572 dev
[1].dpp_auth_init(uri
=uri
, conf
="ap-dpp", configurator
=conf_id
)
2573 update_hapd_config(hapd
)
2575 logger
.info("Provision STA0 with DPP Connector that has mismatching groupId")
2576 dev
[0].set("dpp_config_processing", "2")
2577 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
2578 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
2579 dev
[0].dpp_listen(2412)
2580 dev
[1].set("dpp_groups_override", '[{"groupId":"b","netRole":"sta"}]')
2581 dev
[1].dpp_auth_init(uri
=uri0
, conf
="sta-dpp", configurator
=conf_id
)
2582 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0])
2584 logger
.info("Provision STA2 with DPP Connector that has mismatching C-sign-key")
2585 dev
[2].set("dpp_config_processing", "2")
2586 id2
= dev
[2].dpp_bootstrap_gen(chan
="81/1", mac
=True)
2587 uri2
= dev
[2].request("DPP_BOOTSTRAP_GET_URI %d" % id2
)
2588 dev
[2].dpp_listen(2412)
2589 conf_id_2
= dev
[1].dpp_configurator_add()
2590 dev
[1].set("dpp_groups_override", '')
2591 dev
[1].dpp_auth_init(uri
=uri2
, conf
="sta-dpp", configurator
=conf_id_2
)
2592 wait_auth_success(dev
[2], dev
[1], configurator
=dev
[1], enrollee
=dev
[2])
2594 logger
.info("Provision STA5 with DPP Connector that has mismatching netAccessKey EC group")
2595 wpas
.set("dpp_config_processing", "2")
2596 id5
= wpas
.dpp_bootstrap_gen(chan
="81/1", mac
=True, curve
="P-521")
2597 uri5
= wpas
.request("DPP_BOOTSTRAP_GET_URI %d" % id5
)
2598 wpas
.dpp_listen(2412)
2599 dev
[1].set("dpp_groups_override", '')
2600 dev
[1].dpp_auth_init(uri
=uri5
, conf
="sta-dpp", configurator
=conf_id
)
2601 wait_auth_success(wpas
, dev
[1], configurator
=dev
[1], enrollee
=wpas
)
2603 logger
.info("Verify network introduction results")
2604 ev
= dev
[0].wait_event(["DPP-INTRO"], timeout
=10)
2606 raise Exception("DPP network introduction result not seen on STA0")
2607 if "status=8" not in ev
:
2608 raise Exception("Unexpected network introduction result on STA0: " + ev
)
2610 ev
= dev
[2].wait_event(["DPP-INTRO"], timeout
=5)
2612 raise Exception("DPP network introduction result not seen on STA2")
2613 if "status=8" not in ev
:
2614 raise Exception("Unexpected network introduction result on STA2: " + ev
)
2616 ev
= wpas
.wait_event(["DPP-INTRO"], timeout
=10)
2618 raise Exception("DPP network introduction result not seen on STA5")
2619 if "status=7" not in ev
:
2620 raise Exception("Unexpected network introduction result on STA5: " + ev
)
2622 def run_dpp_proto_init(dev
, test_dev
, test
, mutual
=False, unicast
=True,
2623 listen
=True, chan
="81/1", init_enrollee
=False,
2624 incompatible_roles
=False):
2625 check_dpp_capab(dev
[0])
2626 check_dpp_capab(dev
[1])
2627 dev
[test_dev
].set("dpp_test", str(test
))
2629 conf_id
= dev
[0].dpp_configurator_add()
2631 conf_id
= dev
[1].dpp_configurator_add()
2632 id0
= dev
[0].dpp_bootstrap_gen(chan
=chan
, mac
=unicast
)
2633 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
2636 id1b
= dev
[1].dpp_bootstrap_gen(chan
="81/1", mac
=True)
2637 uri1b
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b
)
2639 id0b
= dev
[0].dpp_qr_code(uri1b
)
2645 if incompatible_roles
:
2648 role
= "configurator"
2649 dev
[0].set("dpp_configurator_params",
2650 " conf=sta-dpp configurator=%d" % conf_id
)
2651 elif incompatible_roles
:
2657 dev
[0].dpp_listen(2412, qr
=qr
, role
=role
)
2667 configurator
=conf_id
2669 if incompatible_roles
:
2673 dev
[1].dpp_auth_init(uri
=uri0
, role
=role
, configurator
=configurator
,
2676 def test_dpp_proto_after_wrapped_data_auth_req(dev
, apdev
):
2677 """DPP protocol testing - attribute after Wrapped Data in Auth Req"""
2678 run_dpp_proto_init(dev
, 1, 1)
2679 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
2681 raise Exception("DPP Authentication Request not seen")
2682 if "type=0" not in ev
or "ignore=invalid-attributes" not in ev
:
2683 raise Exception("Unexpected RX info: " + ev
)
2684 ev
= dev
[1].wait_event(["DPP-RX"], timeout
=0.1)
2686 raise Exception("Unexpected DPP message seen")
2688 def test_dpp_auth_req_stop_after_ack(dev
, apdev
):
2689 """DPP initiator stopping after ACK, but no response"""
2690 run_dpp_proto_init(dev
, 1, 1, listen
=True)
2691 ev
= dev
[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout
=5)
2693 raise Exception("Authentication failure not reported")
2695 def test_dpp_auth_req_retries(dev
, apdev
):
2696 """DPP initiator retries with no ACK"""
2697 check_dpp_capab(dev
[1])
2698 dev
[1].set("dpp_init_max_tries", "3")
2699 dev
[1].set("dpp_init_retry_time", "1000")
2700 dev
[1].set("dpp_resp_wait_time", "100")
2701 run_dpp_proto_init(dev
, 1, 1, unicast
=False, listen
=False)
2704 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
2706 raise Exception("Auth Req not sent (%d)" % i
)
2708 ev
= dev
[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout
=5)
2710 raise Exception("Authentication failure not reported")
2712 def test_dpp_auth_req_retries_multi_chan(dev
, apdev
):
2713 """DPP initiator retries with no ACK and multiple channels"""
2714 check_dpp_capab(dev
[1])
2715 dev
[1].set("dpp_init_max_tries", "3")
2716 dev
[1].set("dpp_init_retry_time", "1000")
2717 dev
[1].set("dpp_resp_wait_time", "100")
2718 run_dpp_proto_init(dev
, 1, 1, unicast
=False, listen
=False,
2719 chan
="81/1,81/6,81/11")
2721 for i
in range(3 * 3):
2722 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
2724 raise Exception("Auth Req not sent (%d)" % i
)
2726 ev
= dev
[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout
=5)
2728 raise Exception("Authentication failure not reported")
2730 def test_dpp_proto_after_wrapped_data_auth_resp(dev
, apdev
):
2731 """DPP protocol testing - attribute after Wrapped Data in Auth Resp"""
2732 run_dpp_proto_init(dev
, 0, 2)
2733 ev
= dev
[1].wait_event(["DPP-RX"], timeout
=5)
2735 raise Exception("DPP Authentication Response not seen")
2736 if "type=1" not in ev
or "ignore=invalid-attributes" not in ev
:
2737 raise Exception("Unexpected RX info: " + ev
)
2738 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=1)
2739 if ev
is None or "type=0" not in ev
:
2740 raise Exception("DPP Authentication Request not seen")
2741 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=0.1)
2743 raise Exception("Unexpected DPP message seen")
2745 def test_dpp_proto_after_wrapped_data_auth_conf(dev
, apdev
):
2746 """DPP protocol testing - attribute after Wrapped Data in Auth Conf"""
2747 run_dpp_proto_init(dev
, 1, 3)
2748 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
2749 if ev
is None or "type=0" not in ev
:
2750 raise Exception("DPP Authentication Request not seen")
2751 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
2753 raise Exception("DPP Authentication Confirm not seen")
2754 if "type=2" not in ev
or "ignore=invalid-attributes" not in ev
:
2755 raise Exception("Unexpected RX info: " + ev
)
2757 def test_dpp_proto_after_wrapped_data_conf_req(dev
, apdev
):
2758 """DPP protocol testing - attribute after Wrapped Data in Conf Req"""
2759 run_dpp_proto_init(dev
, 0, 6)
2760 ev
= dev
[1].wait_event(["DPP-CONF-FAILED"], timeout
=10)
2762 raise Exception("DPP Configuration failure not seen")
2764 def test_dpp_proto_after_wrapped_data_conf_resp(dev
, apdev
):
2765 """DPP protocol testing - attribute after Wrapped Data in Conf Resp"""
2766 run_dpp_proto_init(dev
, 1, 7)
2767 ev
= dev
[0].wait_event(["DPP-CONF-FAILED"], timeout
=10)
2769 raise Exception("DPP Configuration failure not seen")
2771 def test_dpp_proto_zero_i_capab(dev
, apdev
):
2772 """DPP protocol testing - zero I-capability in Auth Req"""
2773 run_dpp_proto_init(dev
, 1, 8)
2774 wait_dpp_fail(dev
[0], "Invalid role in I-capabilities 0x00")
2775 ev
= dev
[1].wait_event(["DPP-RX"], timeout
=0.1)
2777 raise Exception("Unexpected DPP message seen")
2779 def test_dpp_proto_zero_r_capab(dev
, apdev
):
2780 """DPP protocol testing - zero R-capability in Auth Resp"""
2781 run_dpp_proto_init(dev
, 0, 9)
2782 wait_dpp_fail(dev
[1], "Unexpected role in R-capabilities 0x00")
2783 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=1)
2784 if ev
is None or "type=0" not in ev
:
2785 raise Exception("DPP Authentication Request not seen")
2786 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=0.1)
2788 raise Exception("Unexpected DPP message seen")
2790 def run_dpp_proto_auth_req_missing(dev
, test
, reason
, mutual
=False):
2791 run_dpp_proto_init(dev
, 1, test
, mutual
=mutual
)
2792 wait_dpp_fail(dev
[0], reason
)
2793 ev
= dev
[1].wait_event(["DPP-RX"], timeout
=0.1)
2795 raise Exception("Unexpected DPP message seen")
2797 def test_dpp_proto_auth_req_no_r_bootstrap_key(dev
, apdev
):
2798 """DPP protocol testing - no R-bootstrap key in Auth Req"""
2799 run_dpp_proto_auth_req_missing(dev
, 10, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
2801 def test_dpp_proto_auth_req_invalid_r_bootstrap_key(dev
, apdev
):
2802 """DPP protocol testing - invalid R-bootstrap key in Auth Req"""
2803 run_dpp_proto_auth_req_missing(dev
, 68, "No matching own bootstrapping key found - ignore message")
2805 def test_dpp_proto_auth_req_no_i_bootstrap_key(dev
, apdev
):
2806 """DPP protocol testing - no I-bootstrap key in Auth Req"""
2807 run_dpp_proto_auth_req_missing(dev
, 11, "Missing or invalid required Initiator Bootstrapping Key Hash attribute")
2809 def test_dpp_proto_auth_req_invalid_i_bootstrap_key(dev
, apdev
):
2810 """DPP protocol testing - invalid I-bootstrap key in Auth Req"""
2811 run_dpp_proto_init(dev
, 1, 69, mutual
=True)
2812 ev
= dev
[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout
=5)
2814 raise Exception("DPP scan request not seen")
2815 ev
= dev
[1].wait_event(["DPP-RESPONSE-PENDING"], timeout
=5)
2817 raise Exception("DPP response pending indivation not seen")
2819 def test_dpp_proto_auth_req_no_i_proto_key(dev
, apdev
):
2820 """DPP protocol testing - no I-proto key in Auth Req"""
2821 run_dpp_proto_auth_req_missing(dev
, 12, "Missing required Initiator Protocol Key attribute")
2823 def test_dpp_proto_auth_req_invalid_i_proto_key(dev
, apdev
):
2824 """DPP protocol testing - invalid I-proto key in Auth Req"""
2825 run_dpp_proto_auth_req_missing(dev
, 66, "Invalid Initiator Protocol Key")
2827 def test_dpp_proto_auth_req_no_i_nonce(dev
, apdev
):
2828 """DPP protocol testing - no I-nonce in Auth Req"""
2829 run_dpp_proto_auth_req_missing(dev
, 13, "Missing or invalid I-nonce")
2831 def test_dpp_proto_auth_req_invalid_i_nonce(dev
, apdev
):
2832 """DPP protocol testing - invalid I-nonce in Auth Req"""
2833 run_dpp_proto_auth_req_missing(dev
, 81, "Missing or invalid I-nonce")
2835 def test_dpp_proto_auth_req_no_i_capab(dev
, apdev
):
2836 """DPP protocol testing - no I-capab in Auth Req"""
2837 run_dpp_proto_auth_req_missing(dev
, 14, "Missing or invalid I-capab")
2839 def test_dpp_proto_auth_req_no_wrapped_data(dev
, apdev
):
2840 """DPP protocol testing - no Wrapped Data in Auth Req"""
2841 run_dpp_proto_auth_req_missing(dev
, 15, "Missing or invalid required Wrapped Data attribute")
2843 def run_dpp_proto_auth_resp_missing(dev
, test
, reason
,
2844 incompatible_roles
=False):
2845 run_dpp_proto_init(dev
, 0, test
, mutual
=True,
2846 incompatible_roles
=incompatible_roles
)
2848 if incompatible_roles
:
2849 ev
= dev
[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout
=5)
2851 raise Exception("DPP-NOT-COMPATIBLE not reported")
2854 wait_dpp_fail(dev
[1], reason
)
2855 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=1)
2856 if ev
is None or "type=0" not in ev
:
2857 raise Exception("DPP Authentication Request not seen")
2858 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=0.1)
2860 raise Exception("Unexpected DPP message seen")
2862 def test_dpp_proto_auth_resp_no_status(dev
, apdev
):
2863 """DPP protocol testing - no Status in Auth Resp"""
2864 run_dpp_proto_auth_resp_missing(dev
, 16, "Missing or invalid required DPP Status attribute")
2866 def test_dpp_proto_auth_resp_status_no_status(dev
, apdev
):
2867 """DPP protocol testing - no Status in Auth Resp(status)"""
2868 run_dpp_proto_auth_resp_missing(dev
, 16,
2869 "Missing or invalid required DPP Status attribute",
2870 incompatible_roles
=True)
2872 def test_dpp_proto_auth_resp_invalid_status(dev
, apdev
):
2873 """DPP protocol testing - invalid Status in Auth Resp"""
2874 run_dpp_proto_auth_resp_missing(dev
, 74, "Responder reported failure")
2876 def test_dpp_proto_auth_resp_no_r_bootstrap_key(dev
, apdev
):
2877 """DPP protocol testing - no R-bootstrap key in Auth Resp"""
2878 run_dpp_proto_auth_resp_missing(dev
, 17, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
2880 def test_dpp_proto_auth_resp_status_no_r_bootstrap_key(dev
, apdev
):
2881 """DPP protocol testing - no R-bootstrap key in Auth Resp(status)"""
2882 run_dpp_proto_auth_resp_missing(dev
, 17,
2883 "Missing or invalid required Responder Bootstrapping Key Hash attribute",
2884 incompatible_roles
=True)
2886 def test_dpp_proto_auth_resp_invalid_r_bootstrap_key(dev
, apdev
):
2887 """DPP protocol testing - invalid R-bootstrap key in Auth Resp"""
2888 run_dpp_proto_auth_resp_missing(dev
, 70, "Unexpected Responder Bootstrapping Key Hash value")
2890 def test_dpp_proto_auth_resp_status_invalid_r_bootstrap_key(dev
, apdev
):
2891 """DPP protocol testing - invalid R-bootstrap key in Auth Resp(status)"""
2892 run_dpp_proto_auth_resp_missing(dev
, 70,
2893 "Unexpected Responder Bootstrapping Key Hash value",
2894 incompatible_roles
=True)
2896 def test_dpp_proto_auth_resp_no_i_bootstrap_key(dev
, apdev
):
2897 """DPP protocol testing - no I-bootstrap key in Auth Resp"""
2898 run_dpp_proto_auth_resp_missing(dev
, 18, None)
2900 def test_dpp_proto_auth_resp_status_no_i_bootstrap_key(dev
, apdev
):
2901 """DPP protocol testing - no I-bootstrap key in Auth Resp(status)"""
2902 run_dpp_proto_auth_resp_missing(dev
, 18, None, incompatible_roles
=True)
2904 def test_dpp_proto_auth_resp_invalid_i_bootstrap_key(dev
, apdev
):
2905 """DPP protocol testing - invalid I-bootstrap key in Auth Resp"""
2906 run_dpp_proto_auth_resp_missing(dev
, 71, "Initiator Bootstrapping Key Hash attribute did not match")
2908 def test_dpp_proto_auth_resp_status_invalid_i_bootstrap_key(dev
, apdev
):
2909 """DPP protocol testing - invalid I-bootstrap key in Auth Resp(status)"""
2910 run_dpp_proto_auth_resp_missing(dev
, 71,
2911 "Initiator Bootstrapping Key Hash attribute did not match",
2912 incompatible_roles
=True)
2914 def test_dpp_proto_auth_resp_no_r_proto_key(dev
, apdev
):
2915 """DPP protocol testing - no R-Proto Key in Auth Resp"""
2916 run_dpp_proto_auth_resp_missing(dev
, 19, "Missing required Responder Protocol Key attribute")
2918 def test_dpp_proto_auth_resp_invalid_r_proto_key(dev
, apdev
):
2919 """DPP protocol testing - invalid R-Proto Key in Auth Resp"""
2920 run_dpp_proto_auth_resp_missing(dev
, 67, "Invalid Responder Protocol Key")
2922 def test_dpp_proto_auth_resp_no_r_nonce(dev
, apdev
):
2923 """DPP protocol testing - no R-nonce in Auth Resp"""
2924 run_dpp_proto_auth_resp_missing(dev
, 20, "Missing or invalid R-nonce")
2926 def test_dpp_proto_auth_resp_no_i_nonce(dev
, apdev
):
2927 """DPP protocol testing - no I-nonce in Auth Resp"""
2928 run_dpp_proto_auth_resp_missing(dev
, 21, "Missing or invalid I-nonce")
2930 def test_dpp_proto_auth_resp_status_no_i_nonce(dev
, apdev
):
2931 """DPP protocol testing - no I-nonce in Auth Resp(status)"""
2932 run_dpp_proto_auth_resp_missing(dev
, 21, "Missing or invalid I-nonce",
2933 incompatible_roles
=True)
2935 def test_dpp_proto_auth_resp_no_r_capab(dev
, apdev
):
2936 """DPP protocol testing - no R-capab in Auth Resp"""
2937 run_dpp_proto_auth_resp_missing(dev
, 22, "Missing or invalid R-capabilities")
2939 def test_dpp_proto_auth_resp_no_r_auth(dev
, apdev
):
2940 """DPP protocol testing - no R-auth in Auth Resp"""
2941 run_dpp_proto_auth_resp_missing(dev
, 23, "Missing or invalid Secondary Wrapped Data")
2943 def test_dpp_proto_auth_resp_no_wrapped_data(dev
, apdev
):
2944 """DPP protocol testing - no Wrapped Data in Auth Resp"""
2945 run_dpp_proto_auth_resp_missing(dev
, 24, "Missing or invalid required Wrapped Data attribute")
2947 def test_dpp_proto_auth_resp_i_nonce_mismatch(dev
, apdev
):
2948 """DPP protocol testing - I-nonce mismatch in Auth Resp"""
2949 run_dpp_proto_init(dev
, 0, 30, mutual
=True)
2950 wait_dpp_fail(dev
[1], "I-nonce mismatch")
2951 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=1)
2952 if ev
is None or "type=0" not in ev
:
2953 raise Exception("DPP Authentication Request not seen")
2954 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=0.1)
2956 raise Exception("Unexpected DPP message seen")
2958 def test_dpp_proto_auth_resp_incompatible_r_capab(dev
, apdev
):
2959 """DPP protocol testing - Incompatible R-capab in Auth Resp"""
2960 run_dpp_proto_init(dev
, 0, 31, mutual
=True)
2961 wait_dpp_fail(dev
[1], "Unexpected role in R-capabilities 0x02")
2962 wait_dpp_fail(dev
[0], "Peer reported incompatible R-capab role")
2964 def test_dpp_proto_auth_resp_r_auth_mismatch(dev
, apdev
):
2965 """DPP protocol testing - R-auth mismatch in Auth Resp"""
2966 run_dpp_proto_init(dev
, 0, 32, mutual
=True)
2967 wait_dpp_fail(dev
[1], "Mismatching Responder Authenticating Tag")
2968 wait_dpp_fail(dev
[0], "Peer reported authentication failure")
2970 def test_dpp_proto_auth_resp_r_auth_mismatch_failure(dev
, apdev
):
2971 """DPP protocol testing - Auth Conf RX processing failure"""
2972 with
alloc_fail(dev
[0], 1, "dpp_auth_conf_rx_failure"):
2973 run_dpp_proto_init(dev
, 0, 32, mutual
=True)
2974 wait_dpp_fail(dev
[0], "Authentication failed")
2976 def test_dpp_proto_auth_resp_r_auth_mismatch_failure2(dev
, apdev
):
2977 """DPP protocol testing - Auth Conf RX processing failure 2"""
2978 with
fail_test(dev
[0], 1, "dpp_auth_conf_rx_failure"):
2979 run_dpp_proto_init(dev
, 0, 32, mutual
=True)
2980 wait_dpp_fail(dev
[0], "AES-SIV decryption failed")
2982 def run_dpp_proto_auth_conf_missing(dev
, test
, reason
):
2983 run_dpp_proto_init(dev
, 1, test
, mutual
=True)
2987 wait_dpp_fail(dev
[0], reason
)
2989 def test_dpp_proto_auth_conf_no_status(dev
, apdev
):
2990 """DPP protocol testing - no Status in Auth Conf"""
2991 run_dpp_proto_auth_conf_missing(dev
, 25, "Missing or invalid required DPP Status attribute")
2993 def test_dpp_proto_auth_conf_invalid_status(dev
, apdev
):
2994 """DPP protocol testing - invalid Status in Auth Conf"""
2995 run_dpp_proto_auth_conf_missing(dev
, 75, "Authentication failed")
2997 def test_dpp_proto_auth_conf_no_r_bootstrap_key(dev
, apdev
):
2998 """DPP protocol testing - no R-bootstrap key in Auth Conf"""
2999 run_dpp_proto_auth_conf_missing(dev
, 26, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
3001 def test_dpp_proto_auth_conf_invalid_r_bootstrap_key(dev
, apdev
):
3002 """DPP protocol testing - invalid R-bootstrap key in Auth Conf"""
3003 run_dpp_proto_auth_conf_missing(dev
, 72, "Responder Bootstrapping Key Hash mismatch")
3005 def test_dpp_proto_auth_conf_no_i_bootstrap_key(dev
, apdev
):
3006 """DPP protocol testing - no I-bootstrap key in Auth Conf"""
3007 run_dpp_proto_auth_conf_missing(dev
, 27, "Missing Initiator Bootstrapping Key Hash attribute")
3009 def test_dpp_proto_auth_conf_invalid_i_bootstrap_key(dev
, apdev
):
3010 """DPP protocol testing - invalid I-bootstrap key in Auth Conf"""
3011 run_dpp_proto_auth_conf_missing(dev
, 73, "Initiator Bootstrapping Key Hash mismatch")
3013 def test_dpp_proto_auth_conf_no_i_auth(dev
, apdev
):
3014 """DPP protocol testing - no I-Auth in Auth Conf"""
3015 run_dpp_proto_auth_conf_missing(dev
, 28, "Missing or invalid Initiator Authenticating Tag")
3017 def test_dpp_proto_auth_conf_no_wrapped_data(dev
, apdev
):
3018 """DPP protocol testing - no Wrapped Data in Auth Conf"""
3019 run_dpp_proto_auth_conf_missing(dev
, 29, "Missing or invalid required Wrapped Data attribute")
3021 def test_dpp_proto_auth_conf_i_auth_mismatch(dev
, apdev
):
3022 """DPP protocol testing - I-auth mismatch in Auth Conf"""
3023 run_dpp_proto_init(dev
, 1, 33, mutual
=True)
3024 wait_dpp_fail(dev
[0], "Mismatching Initiator Authenticating Tag")
3026 def test_dpp_proto_auth_conf_replaced_by_resp(dev
, apdev
):
3027 """DPP protocol testing - Auth Conf replaced by Resp"""
3028 run_dpp_proto_init(dev
, 1, 65, mutual
=True)
3029 wait_dpp_fail(dev
[0], "Unexpected Authentication Response")
3031 def run_dpp_proto_conf_req_missing(dev
, test
, reason
):
3032 run_dpp_proto_init(dev
, 0, test
)
3033 wait_dpp_fail(dev
[1], reason
)
3035 def test_dpp_proto_conf_req_no_e_nonce(dev
, apdev
):
3036 """DPP protocol testing - no E-nonce in Conf Req"""
3037 run_dpp_proto_conf_req_missing(dev
, 51,
3038 "Missing or invalid Enrollee Nonce attribute")
3040 def test_dpp_proto_conf_req_invalid_e_nonce(dev
, apdev
):
3041 """DPP protocol testing - invalid E-nonce in Conf Req"""
3042 run_dpp_proto_conf_req_missing(dev
, 83,
3043 "Missing or invalid Enrollee Nonce attribute")
3045 def test_dpp_proto_conf_req_no_config_attr_obj(dev
, apdev
):
3046 """DPP protocol testing - no Config Attr Obj in Conf Req"""
3047 run_dpp_proto_conf_req_missing(dev
, 52,
3048 "Missing or invalid Config Attributes attribute")
3050 def test_dpp_proto_conf_req_invalid_config_attr_obj(dev
, apdev
):
3051 """DPP protocol testing - invalid Config Attr Obj in Conf Req"""
3052 run_dpp_proto_conf_req_missing(dev
, 76,
3053 "Unsupported wi-fi_tech")
3055 def test_dpp_proto_conf_req_no_wrapped_data(dev
, apdev
):
3056 """DPP protocol testing - no Wrapped Data in Conf Req"""
3057 run_dpp_proto_conf_req_missing(dev
, 53,
3058 "Missing or invalid required Wrapped Data attribute")
3060 def run_dpp_proto_conf_resp_missing(dev
, test
, reason
):
3061 run_dpp_proto_init(dev
, 1, test
)
3062 wait_dpp_fail(dev
[0], reason
)
3064 def test_dpp_proto_conf_resp_no_e_nonce(dev
, apdev
):
3065 """DPP protocol testing - no E-nonce in Conf Resp"""
3066 run_dpp_proto_conf_resp_missing(dev
, 54,
3067 "Missing or invalid Enrollee Nonce attribute")
3069 def test_dpp_proto_conf_resp_no_config_obj(dev
, apdev
):
3070 """DPP protocol testing - no Config Object in Conf Resp"""
3071 run_dpp_proto_conf_resp_missing(dev
, 55,
3072 "Missing required Configuration Object attribute")
3074 def test_dpp_proto_conf_resp_no_status(dev
, apdev
):
3075 """DPP protocol testing - no Status in Conf Resp"""
3076 run_dpp_proto_conf_resp_missing(dev
, 56,
3077 "Missing or invalid required DPP Status attribute")
3079 def test_dpp_proto_conf_resp_no_wrapped_data(dev
, apdev
):
3080 """DPP protocol testing - no Wrapped Data in Conf Resp"""
3081 run_dpp_proto_conf_resp_missing(dev
, 57,
3082 "Missing or invalid required Wrapped Data attribute")
3084 def test_dpp_proto_conf_resp_invalid_status(dev
, apdev
):
3085 """DPP protocol testing - invalid Status in Conf Resp"""
3086 run_dpp_proto_conf_resp_missing(dev
, 58,
3087 "Configurator rejected configuration")
3089 def test_dpp_proto_conf_resp_e_nonce_mismatch(dev
, apdev
):
3090 """DPP protocol testing - E-nonce mismatch in Conf Resp"""
3091 run_dpp_proto_conf_resp_missing(dev
, 59,
3092 "Enrollee Nonce mismatch")
3094 def test_dpp_proto_stop_at_auth_req(dev
, apdev
):
3095 """DPP protocol testing - stop when receiving Auth Req"""
3096 run_dpp_proto_init(dev
, 0, 87)
3097 ev
= dev
[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout
=5)
3099 raise Exception("Authentication init failure not reported")
3101 def test_dpp_proto_stop_at_auth_resp(dev
, apdev
):
3102 """DPP protocol testing - stop when receiving Auth Resp"""
3103 run_dpp_proto_init(dev
, 1, 88)
3105 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
3107 raise Exception("Auth Req TX not seen")
3109 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=5)
3111 raise Exception("Auth Resp TX not seen")
3113 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=0.1)
3115 raise Exception("Unexpected Auth Conf TX")
3117 def test_dpp_proto_stop_at_auth_conf(dev
, apdev
):
3118 """DPP protocol testing - stop when receiving Auth Conf"""
3119 run_dpp_proto_init(dev
, 0, 89, init_enrollee
=True)
3120 ev
= dev
[1].wait_event(["GAS-QUERY-START"], timeout
=10)
3122 raise Exception("Enrollee did not start GAS")
3123 ev
= dev
[1].wait_event(["GAS-QUERY-DONE"], timeout
=10)
3125 raise Exception("Enrollee did not time out GAS")
3126 if "result=TIMEOUT" not in ev
:
3127 raise Exception("Unexpected GAS result: " + ev
)
3129 def test_dpp_proto_stop_at_auth_conf_tx(dev
, apdev
):
3130 """DPP protocol testing - stop when transmitting Auth Conf (Registrar)"""
3131 run_dpp_proto_init(dev
, 1, 89, init_enrollee
=True)
3132 wait_auth_success(dev
[0], dev
[1], timeout
=10)
3133 ev
= dev
[1].wait_event(["GAS-QUERY-START"], timeout
=0.1)
3135 raise Exception("Unexpected GAS query")
3137 # There is currently no timeout on GAS server side, so no event to wait for
3140 def test_dpp_proto_stop_at_auth_conf_tx2(dev
, apdev
):
3141 """DPP protocol testing - stop when transmitting Auth Conf (Enrollee)"""
3142 run_dpp_proto_init(dev
, 1, 89)
3143 wait_auth_success(dev
[0], dev
[1], timeout
=10)
3145 ev
= dev
[0].wait_event(["GAS-QUERY-DONE"], timeout
=5)
3146 if ev
is None or "result=TIMEOUT" not in ev
:
3147 raise Exception("GAS query did not time out")
3149 def test_dpp_proto_stop_at_conf_req(dev
, apdev
):
3150 """DPP protocol testing - stop when receiving Auth Req"""
3151 run_dpp_proto_init(dev
, 1, 90)
3152 ev
= dev
[0].wait_event(["GAS-QUERY-START"], timeout
=10)
3154 raise Exception("Enrollee did not start GAS")
3155 ev
= dev
[0].wait_event(["GAS-QUERY-DONE"], timeout
=10)
3157 raise Exception("Enrollee did not time out GAS")
3158 if "result=TIMEOUT" not in ev
:
3159 raise Exception("Unexpected GAS result: " + ev
)
3161 def run_dpp_proto_init_pkex(dev
, test_dev
, test
):
3162 check_dpp_capab(dev
[0])
3163 check_dpp_capab(dev
[1])
3164 dev
[test_dev
].set("dpp_test", str(test
))
3165 dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret")
3166 dev
[1].dpp_pkex_init(identifier
="test", code
="secret")
3168 def test_dpp_proto_after_wrapped_data_pkex_cr_req(dev
, apdev
):
3169 """DPP protocol testing - attribute after Wrapped Data in PKEX CR Req"""
3170 run_dpp_proto_init_pkex(dev
, 1, 4)
3171 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
3172 if ev
is None or "type=7" not in ev
:
3173 raise Exception("PKEX Exchange Request not seen")
3174 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
3175 if ev
is None or "type=9" not in ev
:
3176 raise Exception("PKEX Commit-Reveal Request not seen")
3177 if "ignore=invalid-attributes" not in ev
:
3178 raise Exception("Unexpected RX info: " + ev
)
3180 def test_dpp_proto_after_wrapped_data_pkex_cr_resp(dev
, apdev
):
3181 """DPP protocol testing - attribute after Wrapped Data in PKEX CR Resp"""
3182 run_dpp_proto_init_pkex(dev
, 0, 5)
3183 ev
= dev
[1].wait_event(["DPP-RX"], timeout
=5)
3184 if ev
is None or "type=8" not in ev
:
3185 raise Exception("PKEX Exchange Response not seen")
3186 ev
= dev
[1].wait_event(["DPP-RX"], timeout
=5)
3187 if ev
is None or "type=10" not in ev
:
3188 raise Exception("PKEX Commit-Reveal Response not seen")
3189 if "ignore=invalid-attributes" not in ev
:
3190 raise Exception("Unexpected RX info: " + ev
)
3192 def run_dpp_proto_pkex_req_missing(dev
, test
, reason
):
3193 run_dpp_proto_init_pkex(dev
, 1, test
)
3194 wait_dpp_fail(dev
[0], reason
)
3196 def run_dpp_proto_pkex_resp_missing(dev
, test
, reason
):
3197 run_dpp_proto_init_pkex(dev
, 0, test
)
3198 wait_dpp_fail(dev
[1], reason
)
3200 def test_dpp_proto_pkex_exchange_req_no_finite_cyclic_group(dev
, apdev
):
3201 """DPP protocol testing - no Finite Cyclic Group in PKEX Exchange Request"""
3202 run_dpp_proto_pkex_req_missing(dev
, 34,
3203 "Missing or invalid Finite Cyclic Group attribute")
3205 def test_dpp_proto_pkex_exchange_req_no_encrypted_key(dev
, apdev
):
3206 """DPP protocol testing - no Encrypted Key in PKEX Exchange Request"""
3207 run_dpp_proto_pkex_req_missing(dev
, 35,
3208 "Missing Encrypted Key attribute")
3210 def test_dpp_proto_pkex_exchange_resp_no_status(dev
, apdev
):
3211 """DPP protocol testing - no Status in PKEX Exchange Response"""
3212 run_dpp_proto_pkex_resp_missing(dev
, 36, "No DPP Status attribute")
3214 def test_dpp_proto_pkex_exchange_resp_no_encrypted_key(dev
, apdev
):
3215 """DPP protocol testing - no Encrypted Key in PKEX Exchange Response"""
3216 run_dpp_proto_pkex_resp_missing(dev
, 37, "Missing Encrypted Key attribute")
3218 def test_dpp_proto_pkex_cr_req_no_bootstrap_key(dev
, apdev
):
3219 """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Request"""
3220 run_dpp_proto_pkex_req_missing(dev
, 38,
3221 "No valid peer bootstrapping key found")
3223 def test_dpp_proto_pkex_cr_req_no_i_auth_tag(dev
, apdev
):
3224 """DPP protocol testing - no I-Auth Tag in PKEX Commit-Reveal Request"""
3225 run_dpp_proto_pkex_req_missing(dev
, 39, "No valid u (I-Auth tag) found")
3227 def test_dpp_proto_pkex_cr_req_no_wrapped_data(dev
, apdev
):
3228 """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Request"""
3229 run_dpp_proto_pkex_req_missing(dev
, 40, "Missing or invalid required Wrapped Data attribute")
3231 def test_dpp_proto_pkex_cr_resp_no_bootstrap_key(dev
, apdev
):
3232 """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Response"""
3233 run_dpp_proto_pkex_resp_missing(dev
, 41,
3234 "No valid peer bootstrapping key found")
3236 def test_dpp_proto_pkex_cr_resp_no_r_auth_tag(dev
, apdev
):
3237 """DPP protocol testing - no R-Auth Tag in PKEX Commit-Reveal Response"""
3238 run_dpp_proto_pkex_resp_missing(dev
, 42, "No valid v (R-Auth tag) found")
3240 def test_dpp_proto_pkex_cr_resp_no_wrapped_data(dev
, apdev
):
3241 """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Response"""
3242 run_dpp_proto_pkex_resp_missing(dev
, 43, "Missing or invalid required Wrapped Data attribute")
3244 def test_dpp_proto_pkex_exchange_req_invalid_encrypted_key(dev
, apdev
):
3245 """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Request"""
3246 run_dpp_proto_pkex_req_missing(dev
, 44,
3247 "Invalid Encrypted Key value")
3249 def test_dpp_proto_pkex_exchange_resp_invalid_encrypted_key(dev
, apdev
):
3250 """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Response"""
3251 run_dpp_proto_pkex_resp_missing(dev
, 45,
3252 "Invalid Encrypted Key value")
3254 def test_dpp_proto_pkex_exchange_resp_invalid_status(dev
, apdev
):
3255 """DPP protocol testing - invalid Status in PKEX Exchange Response"""
3256 run_dpp_proto_pkex_resp_missing(dev
, 46,
3257 "PKEX failed (peer indicated failure)")
3259 def test_dpp_proto_pkex_cr_req_invalid_bootstrap_key(dev
, apdev
):
3260 """DPP protocol testing - invalid Bootstrap Key in PKEX Commit-Reveal Request"""
3261 run_dpp_proto_pkex_req_missing(dev
, 47,
3262 "Peer bootstrapping key is invalid")
3264 def test_dpp_proto_pkex_cr_resp_invalid_bootstrap_key(dev
, apdev
):
3265 """DPP protocol testing - invalid Bootstrap Key in PKEX Commit-Reveal Response"""
3266 run_dpp_proto_pkex_resp_missing(dev
, 48,
3267 "Peer bootstrapping key is invalid")
3269 def test_dpp_proto_pkex_cr_req_i_auth_tag_mismatch(dev
, apdev
):
3270 """DPP protocol testing - I-auth tag mismatch in PKEX Commit-Reveal Request"""
3271 run_dpp_proto_pkex_req_missing(dev
, 49, "No valid u (I-Auth tag) found")
3273 def test_dpp_proto_pkex_cr_resp_r_auth_tag_mismatch(dev
, apdev
):
3274 """DPP protocol testing - R-auth tag mismatch in PKEX Commit-Reveal Response"""
3275 run_dpp_proto_pkex_resp_missing(dev
, 50, "No valid v (R-Auth tag) found")
3277 def test_dpp_proto_stop_at_pkex_exchange_resp(dev
, apdev
):
3278 """DPP protocol testing - stop when receiving PKEX Exchange Response"""
3279 run_dpp_proto_init_pkex(dev
, 1, 84)
3281 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
3283 raise Exception("PKEX Exchange Req TX not seen")
3285 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=5)
3287 raise Exception("PKEX Exchange Resp not seen")
3289 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=0.1)
3291 raise Exception("Unexpected PKEX CR Req TX")
3293 def test_dpp_proto_stop_at_pkex_cr_req(dev
, apdev
):
3294 """DPP protocol testing - stop when receiving PKEX CR Request"""
3295 run_dpp_proto_init_pkex(dev
, 0, 85)
3297 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
3299 raise Exception("PKEX Exchange Req TX not seen")
3301 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=5)
3303 raise Exception("PKEX Exchange Resp not seen")
3305 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
3307 raise Exception("PKEX CR Req TX not seen")
3309 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=0.1)
3311 raise Exception("Unexpected PKEX CR Resp TX")
3313 def test_dpp_proto_stop_at_pkex_cr_resp(dev
, apdev
):
3314 """DPP protocol testing - stop when receiving PKEX CR Response"""
3315 run_dpp_proto_init_pkex(dev
, 1, 86)
3317 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
3319 raise Exception("PKEX Exchange Req TX not seen")
3321 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=5)
3323 raise Exception("PKEX Exchange Resp not seen")
3325 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=5)
3327 raise Exception("PKEX CR Req TX not seen")
3329 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=5)
3331 raise Exception("PKEX CR Resp TX not seen")
3333 ev
= dev
[1].wait_event(["DPP-TX "], timeout
=0.1)
3335 raise Exception("Unexpected Auth Req TX")
3337 def test_dpp_proto_network_introduction(dev
, apdev
):
3338 """DPP protocol testing - network introduction"""
3339 check_dpp_capab(dev
[0])
3340 check_dpp_capab(dev
[1])
3342 params
= {"ssid": "dpp",
3344 "wpa_key_mgmt": "DPP",
3346 "rsn_pairwise": "CCMP",
3347 "dpp_connector": params1_ap_connector
,
3348 "dpp_csign": params1_csign
,
3349 "dpp_netaccesskey": params1_ap_netaccesskey
}
3351 hapd
= hostapd
.add_ap(apdev
[0], params
)
3353 raise HwsimSkip("DPP not supported")
3355 for test
in [60, 61, 80, 82]:
3356 dev
[0].set("dpp_test", str(test
))
3357 dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412", ieee80211w
="2",
3358 dpp_csign
=params1_csign
,
3359 dpp_connector
=params1_sta_connector
,
3360 dpp_netaccesskey
=params1_sta_netaccesskey
,
3363 ev
= dev
[0].wait_event(["DPP-TX "], timeout
=10)
3364 if ev
is None or "type=5" not in ev
:
3365 raise Exception("Peer Discovery Request TX not reported")
3366 ev
= dev
[0].wait_event(["DPP-TX-STATUS"], timeout
=2)
3367 if ev
is None or "result=SUCCESS" not in ev
:
3368 raise Exception("Peer Discovery Request TX status not reported")
3370 ev
= hapd
.wait_event(["DPP-RX"], timeout
=10)
3371 if ev
is None or "type=5" not in ev
:
3372 raise Exception("Peer Discovery Request RX not reported")
3375 ev
= dev
[0].wait_event(["DPP-INTRO"], timeout
=10)
3377 raise Exception("DPP-INTRO not reported for test 80")
3378 if "status=7" not in ev
:
3379 raise Exception("Unexpected result in test 80: " + ev
)
3381 dev
[0].request("REMOVE_NETWORK all")
3382 dev
[0].dump_monitor()
3384 dev
[0].set("dpp_test", "0")
3386 for test
in [62, 63, 64, 77, 78, 79]:
3387 hapd
.set("dpp_test", str(test
))
3388 dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412", ieee80211w
="2",
3389 dpp_csign
=params1_csign
,
3390 dpp_connector
=params1_sta_connector
,
3391 dpp_netaccesskey
=params1_sta_netaccesskey
,
3394 ev
= dev
[0].wait_event(["DPP-INTRO"], timeout
=10)
3396 raise Exception("Peer introduction result not reported (test %d)" % test
)
3398 if "fail=transaction_id_mismatch" not in ev
:
3399 raise Exception("Connector validation failure not reported")
3401 if "status=254" not in ev
:
3402 raise Exception("Invalid status value not reported")
3404 if "fail=peer_connector_validation_failed" not in ev
:
3405 raise Exception("Connector validation failure not reported")
3406 elif "status=" in ev
:
3407 raise Exception("Unexpected peer introduction result (test %d): " % test
+ ev
)
3409 dev
[0].request("REMOVE_NETWORK all")
3410 dev
[0].dump_monitor()
3412 hapd
.set("dpp_test", "0")
3414 dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412", ieee80211w
="2",
3415 dpp_csign
=params1_csign
, dpp_connector
=params1_sta_connector
,
3416 dpp_netaccesskey
=params1_sta_netaccesskey
)
3418 def test_dpp_qr_code_no_chan_list_unicast(dev
, apdev
):
3419 """DPP QR Code and no channel list (unicast)"""
3420 run_dpp_qr_code_chan_list(dev
, apdev
, True, 2417, None)
3422 def test_dpp_qr_code_chan_list_unicast(dev
, apdev
):
3423 """DPP QR Code and 2.4 GHz channels (unicast)"""
3424 run_dpp_qr_code_chan_list(dev
, apdev
, True, 2417,
3425 "81/1,81/2,81/3,81/4,81/5,81/6,81/7,81/8,81/9,81/10,81/11,81/12,81/13")
3427 def test_dpp_qr_code_chan_list_unicast2(dev
, apdev
):
3428 """DPP QR Code and 2.4 GHz channels (unicast 2)"""
3429 run_dpp_qr_code_chan_list(dev
, apdev
, True, 2417,
3430 "81/1,2,3,4,5,6,7,8,9,10,11,12,13")
3432 def test_dpp_qr_code_chan_list_no_peer_unicast(dev
, apdev
):
3433 """DPP QR Code and channel list and no peer (unicast)"""
3434 run_dpp_qr_code_chan_list(dev
, apdev
, True, 2417, "81/1,81/6,81/11",
3436 ev
= dev
[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout
=5)
3438 raise Exception("Initiation failure not reported")
3440 def test_dpp_qr_code_no_chan_list_broadcast(dev
, apdev
):
3441 """DPP QR Code and no channel list (broadcast)"""
3442 run_dpp_qr_code_chan_list(dev
, apdev
, False, 2412, None)
3444 def test_dpp_qr_code_chan_list_broadcast(dev
, apdev
):
3445 """DPP QR Code and some 2.4 GHz channels (broadcast)"""
3446 run_dpp_qr_code_chan_list(dev
, apdev
, False, 2412, "81/1,81/6,81/11",
3449 def run_dpp_qr_code_chan_list(dev
, apdev
, unicast
, listen_freq
, chanlist
,
3450 no_wait
=False, timeout
=5):
3451 check_dpp_capab(dev
[0])
3452 check_dpp_capab(dev
[1])
3453 dev
[1].set("dpp_init_max_tries", "3")
3454 dev
[1].set("dpp_init_retry_time", "100")
3455 dev
[1].set("dpp_resp_wait_time", "1000")
3457 logger
.info("dev0 displays QR Code")
3458 id0
= dev
[0].dpp_bootstrap_gen(chan
=chanlist
, mac
=unicast
)
3459 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
3460 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
3461 dev
[0].dpp_listen(listen_freq
)
3462 dev
[1].dpp_auth_init(uri
=uri0
)
3465 wait_auth_success(dev
[0], dev
[1], timeout
=timeout
, configurator
=dev
[1],
3466 enrollee
=dev
[0], allow_enrollee_failure
=True,
3467 stop_responder
=True)
3469 def test_dpp_qr_code_chan_list_no_match(dev
, apdev
):
3470 """DPP QR Code and no matching supported channel"""
3471 check_dpp_capab(dev
[0])
3472 check_dpp_capab(dev
[1])
3473 id0
= dev
[0].dpp_bootstrap_gen(chan
="123/123")
3474 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
3475 dev
[1].dpp_auth_init(uri
=uri0
, expect_fail
=True)
3477 def test_dpp_pkex_alloc_fail(dev
, apdev
):
3478 """DPP/PKEX and memory allocation failures"""
3479 check_dpp_capab(dev
[0])
3480 check_dpp_capab(dev
[1])
3482 tests
= [(1, "=dpp_keygen_configurator"),
3483 (1, "base64_gen_encode;dpp_keygen_configurator")]
3484 for count
, func
in tests
:
3485 with
alloc_fail(dev
[1], count
, func
):
3486 cmd
= "DPP_CONFIGURATOR_ADD"
3487 res
= dev
[1].request(cmd
)
3488 if "FAIL" not in res
:
3489 raise Exception("Unexpected DPP_CONFIGURATOR_ADD success")
3491 conf_id
= dev
[1].dpp_configurator_add()
3496 # Local error cases on the Initiator
3497 tests
= [(1, "dpp_get_pubkey_point"),
3498 (1, "dpp_alloc_msg;dpp_pkex_build_exchange_req"),
3499 (1, "dpp_alloc_msg;dpp_pkex_build_commit_reveal_req"),
3500 (1, "dpp_alloc_msg;dpp_auth_build_req"),
3501 (1, "dpp_alloc_msg;dpp_auth_build_conf"),
3502 (1, "dpp_bootstrap_key_hash"),
3503 (1, "dpp_auth_init"),
3504 (1, "dpp_alloc_auth"),
3505 (1, "=dpp_auth_resp_rx"),
3506 (1, "dpp_build_conf_start"),
3507 (1, "dpp_build_conf_obj_dpp"),
3508 (2, "dpp_build_conf_obj_dpp"),
3509 (3, "dpp_build_conf_obj_dpp"),
3510 (4, "dpp_build_conf_obj_dpp"),
3511 (5, "dpp_build_conf_obj_dpp"),
3512 (6, "dpp_build_conf_obj_dpp"),
3513 (7, "dpp_build_conf_obj_dpp"),
3514 (8, "dpp_build_conf_obj_dpp"),
3515 (1, "dpp_conf_req_rx"),
3516 (2, "dpp_conf_req_rx"),
3517 (3, "dpp_conf_req_rx"),
3518 (4, "dpp_conf_req_rx"),
3519 (5, "dpp_conf_req_rx"),
3520 (6, "dpp_conf_req_rx"),
3521 (7, "dpp_conf_req_rx"),
3522 (1, "dpp_pkex_init"),
3523 (2, "dpp_pkex_init"),
3524 (3, "dpp_pkex_init"),
3525 (1, "dpp_pkex_derive_z"),
3526 (1, "=dpp_pkex_rx_commit_reveal_resp"),
3527 (1, "dpp_get_pubkey_point;dpp_build_jwk"),
3528 (2, "dpp_get_pubkey_point;dpp_build_jwk"),
3529 (1, "dpp_get_pubkey_point;dpp_auth_init")]
3530 for count
, func
in tests
:
3531 dev
[0].request("DPP_STOP_LISTEN")
3532 dev
[1].request("DPP_STOP_LISTEN")
3533 dev
[0].dump_monitor()
3534 dev
[1].dump_monitor()
3535 id0
= dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret",
3538 with
alloc_fail(dev
[1], count
, func
):
3539 id1
= dev
[1].dpp_pkex_init(identifier
="test", code
="secret",
3541 extra
="conf=sta-dpp configurator=%d" % conf_id
,
3543 wait_fail_trigger(dev
[1], "GET_ALLOC_FAIL", max_iter
=100)
3544 ev
= dev
[0].wait_event(["GAS-QUERY-START"], timeout
=0.01)
3546 dev
[0].request("DPP_STOP_LISTEN")
3547 dev
[0].wait_event(["GAS-QUERY-DONE"], timeout
=3)
3549 # Local error cases on the Responder
3550 tests
= [(1, "dpp_get_pubkey_point"),
3551 (1, "dpp_alloc_msg;dpp_pkex_build_exchange_resp"),
3552 (1, "dpp_alloc_msg;dpp_pkex_build_commit_reveal_resp"),
3553 (1, "dpp_alloc_msg;dpp_auth_build_resp"),
3554 (1, "dpp_get_pubkey_point;dpp_auth_build_resp_ok"),
3555 (1, "dpp_alloc_auth"),
3556 (1, "=dpp_auth_req_rx"),
3557 (1, "=dpp_auth_conf_rx"),
3558 (1, "json_parse;dpp_parse_jws_prot_hdr"),
3559 (1, "json_get_member_base64url;dpp_parse_jws_prot_hdr"),
3560 (1, "json_get_member_base64url;dpp_parse_jwk"),
3561 (2, "json_get_member_base64url;dpp_parse_jwk"),
3562 (1, "json_parse;dpp_parse_connector"),
3563 (1, "dpp_parse_jwk;dpp_parse_connector"),
3564 (1, "dpp_parse_jwk;dpp_parse_cred_dpp"),
3565 (1, "dpp_get_pubkey_point;dpp_check_pubkey_match"),
3566 (1, "base64_gen_decode;dpp_process_signed_connector"),
3567 (1, "dpp_parse_jws_prot_hdr;dpp_process_signed_connector"),
3568 (2, "base64_gen_decode;dpp_process_signed_connector"),
3569 (3, "base64_gen_decode;dpp_process_signed_connector"),
3570 (4, "base64_gen_decode;dpp_process_signed_connector"),
3571 (1, "json_parse;dpp_parse_conf_obj"),
3572 (1, "dpp_conf_resp_rx"),
3573 (1, "=dpp_pkex_derive_z"),
3574 (1, "=dpp_pkex_rx_exchange_req"),
3575 (2, "=dpp_pkex_rx_exchange_req"),
3576 (3, "=dpp_pkex_rx_exchange_req"),
3577 (1, "=dpp_pkex_rx_commit_reveal_req"),
3578 (1, "dpp_get_pubkey_point;dpp_pkex_rx_commit_reveal_req"),
3579 (1, "dpp_bootstrap_key_hash")]
3580 for count
, func
in tests
:
3581 dev
[0].request("DPP_STOP_LISTEN")
3582 dev
[1].request("DPP_STOP_LISTEN")
3583 dev
[0].dump_monitor()
3584 dev
[1].dump_monitor()
3585 id0
= dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret",
3588 with
alloc_fail(dev
[0], count
, func
):
3589 id1
= dev
[1].dpp_pkex_init(identifier
="test", code
="secret",
3591 extra
="conf=sta-dpp configurator=%d" % conf_id
)
3592 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL", max_iter
=100)
3593 ev
= dev
[0].wait_event(["GAS-QUERY-START"], timeout
=0.01)
3595 dev
[0].request("DPP_STOP_LISTEN")
3596 dev
[0].wait_event(["GAS-QUERY-DONE"], timeout
=3)
3598 def test_dpp_pkex_test_fail(dev
, apdev
):
3599 """DPP/PKEX and local failures"""
3600 check_dpp_capab(dev
[0])
3601 check_dpp_capab(dev
[1])
3603 tests
= [(1, "dpp_keygen_configurator")]
3604 for count
, func
in tests
:
3605 with
fail_test(dev
[1], count
, func
):
3606 cmd
= "DPP_CONFIGURATOR_ADD"
3607 res
= dev
[1].request(cmd
)
3608 if "FAIL" not in res
:
3609 raise Exception("Unexpected DPP_CONFIGURATOR_ADD success")
3611 tests
= [(1, "dpp_keygen")]
3612 for count
, func
in tests
:
3613 with
fail_test(dev
[1], count
, func
):
3614 cmd
= "DPP_BOOTSTRAP_GEN type=pkex"
3615 res
= dev
[1].request(cmd
)
3616 if "FAIL" not in res
:
3617 raise Exception("Unexpected DPP_BOOTSTRAP_GEN success")
3619 conf_id
= dev
[1].dpp_configurator_add()
3624 # Local error cases on the Initiator
3625 tests
= [(1, "aes_siv_encrypt;dpp_auth_build_req"),
3626 (1, "os_get_random;dpp_auth_init"),
3627 (1, "dpp_derive_k1;dpp_auth_init"),
3628 (1, "dpp_hkdf_expand;dpp_derive_k1;dpp_auth_init"),
3629 (1, "dpp_gen_i_auth;dpp_auth_build_conf"),
3630 (1, "aes_siv_encrypt;dpp_auth_build_conf"),
3631 (1, "dpp_derive_k2;dpp_auth_resp_rx"),
3632 (1, "dpp_hkdf_expand;dpp_derive_k2;dpp_auth_resp_rx"),
3633 (1, "dpp_derive_ke;dpp_auth_resp_rx"),
3634 (1, "dpp_hkdf_expand;dpp_derive_ke;dpp_auth_resp_rx"),
3635 (1, "dpp_gen_r_auth;dpp_auth_resp_rx"),
3636 (1, "aes_siv_encrypt;dpp_build_conf_resp"),
3637 (1, "dpp_pkex_derive_Qi;dpp_pkex_build_exchange_req"),
3638 (1, "aes_siv_encrypt;dpp_pkex_build_commit_reveal_req"),
3639 (1, "hmac_sha256_vector;dpp_pkex_rx_exchange_resp"),
3640 (1, "aes_siv_decrypt;dpp_pkex_rx_commit_reveal_resp"),
3641 (1, "hmac_sha256_vector;dpp_pkex_rx_commit_reveal_resp"),
3642 (1, "dpp_bootstrap_key_hash")]
3643 for count
, func
in tests
:
3644 dev
[0].request("DPP_STOP_LISTEN")
3645 dev
[1].request("DPP_STOP_LISTEN")
3646 dev
[0].dump_monitor()
3647 dev
[1].dump_monitor()
3648 id0
= dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret",
3651 with
fail_test(dev
[1], count
, func
):
3652 id1
= dev
[1].dpp_pkex_init(identifier
="test", code
="secret",
3654 extra
="conf=sta-dpp configurator=%d" % conf_id
,
3656 wait_fail_trigger(dev
[1], "GET_FAIL", max_iter
=100)
3657 ev
= dev
[0].wait_event(["GAS-QUERY-START"], timeout
=0.01)
3659 dev
[0].request("DPP_STOP_LISTEN")
3660 dev
[0].wait_event(["GAS-QUERY-DONE"], timeout
=3)
3662 # Local error cases on the Responder
3663 tests
= [(1, "aes_siv_encrypt;dpp_auth_build_resp"),
3664 (1, "aes_siv_encrypt;dpp_auth_build_resp;dpp_auth_build_resp_ok"),
3665 (1, "os_get_random;dpp_build_conf_req"),
3666 (1, "aes_siv_encrypt;dpp_build_conf_req"),
3667 (1, "os_get_random;dpp_auth_build_resp_ok"),
3668 (1, "dpp_derive_k2;dpp_auth_build_resp_ok"),
3669 (1, "dpp_derive_ke;dpp_auth_build_resp_ok"),
3670 (1, "dpp_gen_r_auth;dpp_auth_build_resp_ok"),
3671 (1, "aes_siv_encrypt;dpp_auth_build_resp_ok"),
3672 (1, "dpp_derive_k1;dpp_auth_req_rx"),
3673 (1, "aes_siv_decrypt;dpp_auth_req_rx"),
3674 (1, "aes_siv_decrypt;dpp_auth_conf_rx"),
3675 (1, "dpp_gen_i_auth;dpp_auth_conf_rx"),
3676 (1, "dpp_check_pubkey_match"),
3677 (1, "aes_siv_decrypt;dpp_conf_resp_rx"),
3678 (1, "hmac_sha256_kdf;dpp_pkex_derive_z"),
3679 (1, "dpp_pkex_derive_Qi;dpp_pkex_rx_exchange_req"),
3680 (1, "dpp_pkex_derive_Qr;dpp_pkex_rx_exchange_req"),
3681 (1, "aes_siv_encrypt;dpp_pkex_build_commit_reveal_resp"),
3682 (1, "aes_siv_decrypt;dpp_pkex_rx_commit_reveal_req"),
3683 (1, "hmac_sha256_vector;dpp_pkex_rx_commit_reveal_req"),
3684 (2, "hmac_sha256_vector;dpp_pkex_rx_commit_reveal_req")]
3685 for count
, func
in tests
:
3686 dev
[0].request("DPP_STOP_LISTEN")
3687 dev
[1].request("DPP_STOP_LISTEN")
3688 dev
[0].dump_monitor()
3689 dev
[1].dump_monitor()
3690 id0
= dev
[0].dpp_pkex_resp(2437, identifier
="test", code
="secret",
3693 with
fail_test(dev
[0], count
, func
):
3694 id1
= dev
[1].dpp_pkex_init(identifier
="test", code
="secret",
3696 extra
="conf=sta-dpp configurator=%d" % conf_id
)
3697 wait_fail_trigger(dev
[0], "GET_FAIL", max_iter
=100)
3698 ev
= dev
[0].wait_event(["GAS-QUERY-START"], timeout
=0.01)
3700 dev
[0].request("DPP_STOP_LISTEN")
3701 dev
[0].wait_event(["GAS-QUERY-DONE"], timeout
=3)
3703 def test_dpp_keygen_configurator_error(dev
, apdev
):
3704 """DPP Configurator keygen error case"""
3705 check_dpp_capab(dev
[0])
3706 if "FAIL" not in dev
[0].request("DPP_CONFIGURATOR_ADD curve=unknown"):
3707 raise Exception("Unexpected success of invalid DPP_CONFIGURATOR_ADD")
3709 def rx_process_frame(dev
):
3712 raise Exception("No management frame RX reported")
3713 if "OK" not in dev
.request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
3714 msg
['freq'], msg
['datarate'], msg
['ssi_signal'], binascii
.hexlify(msg
['frame']).decode())):
3715 raise Exception("MGMT_RX_PROCESS failed")
3718 def wait_auth_success(responder
, initiator
, configurator
=None, enrollee
=None,
3719 allow_enrollee_failure
=False,
3720 allow_configurator_failure
=False,
3721 require_configurator_failure
=False,
3722 timeout
=5, stop_responder
=False, stop_initiator
=False):
3724 ev
= responder
.wait_event(["DPP-AUTH-SUCCESS", "DPP-FAIL"], timeout
=timeout
)
3725 if ev
is None or "DPP-AUTH-SUCCESS" not in ev
:
3726 raise Exception("DPP authentication did not succeed (Responder)")
3727 ev
= initiator
.wait_event(["DPP-AUTH-SUCCESS", "DPP-FAIL"], timeout
=5)
3728 if ev
is None or "DPP-AUTH-SUCCESS" not in ev
:
3729 raise Exception("DPP authentication did not succeed (Initiator)")
3731 ev
= configurator
.wait_event(["DPP-CONF-SENT",
3732 "DPP-CONF-FAILED"], timeout
=5)
3734 raise Exception("DPP configuration not completed (Configurator)")
3735 if "DPP-CONF-FAILED" in ev
and not allow_configurator_failure
:
3736 raise Exception("DPP configuration did not succeed (Configurator)")
3737 if "DPP-CONF-SENT" in ev
and require_configurator_failure
:
3738 raise Exception("DPP configuration succeeded (Configurator)")
3739 if "DPP-CONF-SENT" in ev
and "wait_conn_status=1" in ev
:
3740 res
['wait_conn_status'] = True
3742 ev
= enrollee
.wait_event(["DPP-CONF-RECEIVED",
3743 "DPP-CONF-FAILED"], timeout
=5)
3745 raise Exception("DPP configuration not completed (Enrollee)")
3746 if "DPP-CONF-FAILED" in ev
and not allow_enrollee_failure
:
3747 raise Exception("DPP configuration did not succeed (Enrollee)")
3749 responder
.request("DPP_STOP_LISTEN")
3751 initiator
.request("DPP_STOP_LISTEN")
3754 def wait_conf_completion(configurator
, enrollee
):
3755 ev
= configurator
.wait_event(["DPP-CONF-SENT"], timeout
=5)
3757 raise Exception("DPP configuration not completed (Configurator)")
3758 ev
= enrollee
.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"],
3761 raise Exception("DPP configuration not completed (Enrollee)")
3764 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
3765 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
3767 conf
= '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
3768 dev
[0].set("dpp_config_obj_override", conf
)
3770 dev
[0].set("ext_mgmt_frame_handling", "1")
3771 dev
[0].dpp_listen(2412)
3772 dev
[1].dpp_auth_init(uri
=uri0
, role
="enrollee")
3774 def test_dpp_gas_timeout_handling(dev
, apdev
):
3775 """DPP and GAS timeout handling"""
3776 check_dpp_capab(dev
[0])
3777 check_dpp_capab(dev
[1])
3780 # DPP Authentication Request
3781 rx_process_frame(dev
[0])
3783 # DPP Authentication Confirmation
3784 rx_process_frame(dev
[0])
3786 wait_auth_success(dev
[0], dev
[1])
3788 # DPP Configuration Request (GAS Initial Request frame)
3789 rx_process_frame(dev
[0])
3791 # DPP Configuration Request (GAS Comeback Request frame)
3792 rx_process_frame(dev
[0])
3794 # Wait for GAS timeout
3795 ev
= dev
[1].wait_event(["DPP-CONF-FAILED"], timeout
=5)
3797 raise Exception("DPP configuration not completed (Enrollee)")
3799 def test_dpp_gas_comeback_after_failure(dev
, apdev
):
3800 """DPP and GAS comeback after failure"""
3801 check_dpp_capab(dev
[0])
3802 check_dpp_capab(dev
[1])
3805 # DPP Authentication Request
3806 rx_process_frame(dev
[0])
3808 # DPP Authentication Confirmation
3809 rx_process_frame(dev
[0])
3811 wait_auth_success(dev
[0], dev
[1])
3813 # DPP Configuration Request (GAS Initial Request frame)
3814 rx_process_frame(dev
[0])
3816 # DPP Configuration Request (GAS Comeback Request frame)
3817 msg
= dev
[0].mgmt_rx()
3818 frame
= binascii
.hexlify(msg
['frame']).decode()
3819 with
alloc_fail(dev
[0], 1, "gas_build_comeback_resp;gas_server_handle_rx_comeback_req"):
3820 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame
)):
3821 raise Exception("MGMT_RX_PROCESS failed")
3822 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
3823 # Try the same frame again - this is expected to fail since the response has
3824 # already been freed.
3825 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame
)):
3826 raise Exception("MGMT_RX_PROCESS failed")
3828 # DPP Configuration Request (GAS Comeback Request frame retry)
3829 msg
= dev
[0].mgmt_rx()
3831 def test_dpp_gas(dev
, apdev
):
3832 """DPP and GAS protocol testing"""
3833 ver0
= check_dpp_capab(dev
[0])
3834 ver1
= check_dpp_capab(dev
[1])
3837 # DPP Authentication Request
3838 rx_process_frame(dev
[0])
3840 # DPP Authentication Confirmation
3841 rx_process_frame(dev
[0])
3843 wait_auth_success(dev
[0], dev
[1])
3845 # DPP Configuration Request (GAS Initial Request frame)
3846 msg
= dev
[0].mgmt_rx()
3848 # Protected Dual of GAS Initial Request frame (dropped by GAS server)
3850 raise Exception("MGMT_RX_PROCESS failed. <Please retry>")
3851 frame
= binascii
.hexlify(msg
['frame'])
3852 frame
= frame
[0:48] + b
"09" + frame
[50:]
3853 frame
= frame
.decode()
3854 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame
)):
3855 raise Exception("MGMT_RX_PROCESS failed")
3857 with
alloc_fail(dev
[0], 1, "gas_server_send_resp"):
3858 frame
= binascii
.hexlify(msg
['frame']).decode()
3859 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame
)):
3860 raise Exception("MGMT_RX_PROCESS failed")
3861 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
3863 with
alloc_fail(dev
[0], 1, "gas_build_initial_resp;gas_server_send_resp"):
3864 frame
= binascii
.hexlify(msg
['frame']).decode()
3865 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame
)):
3866 raise Exception("MGMT_RX_PROCESS failed")
3867 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
3869 # Add extra data after Query Request field to trigger
3870 # "GAS: Ignored extra data after Query Request field"
3871 frame
= binascii
.hexlify(msg
['frame']).decode() + "00"
3872 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame
)):
3873 raise Exception("MGMT_RX_PROCESS failed")
3875 # DPP Configuration Request (GAS Comeback Request frame)
3876 rx_process_frame(dev
[0])
3878 # DPP Configuration Request (GAS Comeback Request frame)
3879 rx_process_frame(dev
[0])
3881 # DPP Configuration Request (GAS Comeback Request frame)
3882 rx_process_frame(dev
[0])
3884 if ver0
>= 2 and ver1
>= 2:
3885 # DPP Configuration Result
3886 rx_process_frame(dev
[0])
3888 wait_conf_completion(dev
[0], dev
[1])
3890 def test_dpp_truncated_attr(dev
, apdev
):
3891 """DPP and truncated attribute"""
3892 check_dpp_capab(dev
[0])
3893 check_dpp_capab(dev
[1])
3896 # DPP Authentication Request
3897 msg
= dev
[0].mgmt_rx()
3898 frame
= msg
['frame']
3900 # DPP: Truncated message - not enough room for the attribute - dropped
3901 frame1
= binascii
.hexlify(frame
[0:36]).decode()
3902 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame1
)):
3903 raise Exception("MGMT_RX_PROCESS failed")
3904 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
3905 if ev
is None or "ignore=invalid-attributes" not in ev
:
3906 raise Exception("Invalid attribute error not reported")
3908 # DPP: Unexpected octets (3) after the last attribute
3909 frame2
= binascii
.hexlify(frame
).decode() + "000000"
3910 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame2
)):
3911 raise Exception("MGMT_RX_PROCESS failed")
3912 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
3913 if ev
is None or "ignore=invalid-attributes" not in ev
:
3914 raise Exception("Invalid attribute error not reported")
3916 def test_dpp_bootstrap_key_autogen_issues(dev
, apdev
):
3917 """DPP bootstrap key autogen issues"""
3918 check_dpp_capab(dev
[0])
3919 check_dpp_capab(dev
[1])
3921 logger
.info("dev0 displays QR Code")
3922 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
3923 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
3925 logger
.info("dev1 scans QR Code")
3926 id1
= dev
[1].dpp_qr_code(uri0
)
3928 logger
.info("dev1 initiates DPP Authentication")
3929 dev
[0].dpp_listen(2412)
3930 with
alloc_fail(dev
[1], 1, "dpp_autogen_bootstrap_key"):
3931 dev
[1].dpp_auth_init(peer
=id1
, expect_fail
=True)
3932 with
alloc_fail(dev
[1], 1, "dpp_gen_uri;dpp_autogen_bootstrap_key"):
3933 dev
[1].dpp_auth_init(peer
=id1
, expect_fail
=True)
3934 with
fail_test(dev
[1], 1, "dpp_keygen;dpp_autogen_bootstrap_key"):
3935 dev
[1].dpp_auth_init(peer
=id1
, expect_fail
=True)
3936 dev
[0].request("DPP_STOP_LISTEN")
3938 def test_dpp_auth_resp_status_failure(dev
, apdev
):
3939 """DPP and Auth Resp(status) build failure"""
3940 with
alloc_fail(dev
[0], 1, "dpp_auth_build_resp"):
3941 run_dpp_proto_auth_resp_missing(dev
, 99999, None,
3942 incompatible_roles
=True)
3944 def test_dpp_auth_resp_aes_siv_issue(dev
, apdev
):
3945 """DPP Auth Resp AES-SIV issue"""
3946 check_dpp_capab(dev
[0])
3947 check_dpp_capab(dev
[1])
3948 logger
.info("dev0 displays QR Code")
3949 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
3950 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
3951 logger
.info("dev1 scans QR Code and initiates DPP Authentication")
3952 dev
[0].dpp_listen(2412)
3953 with
fail_test(dev
[1], 1, "aes_siv_decrypt;dpp_auth_resp_rx"):
3954 dev
[1].dpp_auth_init(uri
=uri0
)
3955 wait_dpp_fail(dev
[1], "AES-SIV decryption failed")
3956 dev
[0].request("DPP_STOP_LISTEN")
3958 def test_dpp_invalid_legacy_params(dev
, apdev
):
3959 """DPP invalid legacy parameters"""
3960 check_dpp_capab(dev
[0])
3961 check_dpp_capab(dev
[1])
3962 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
3963 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
3965 dev
[1].dpp_auth_init(uri
=uri0
, conf
="sta-psk", ssid
="dpp-legacy",
3968 def test_dpp_invalid_legacy_params2(dev
, apdev
):
3969 """DPP invalid legacy parameters 2"""
3970 check_dpp_capab(dev
[0])
3971 check_dpp_capab(dev
[1])
3972 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
3973 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
3974 dev
[0].set("dpp_configurator_params",
3975 " conf=sta-psk ssid=%s" % (binascii
.hexlify(b
"dpp-legacy").decode()))
3976 dev
[0].dpp_listen(2412, role
="configurator")
3977 dev
[1].dpp_auth_init(uri
=uri0
, role
="enrollee")
3979 ev
= dev
[0].wait_event(["DPP: Failed to set configurator parameters"],
3982 raise Exception("DPP configuration failure not reported")
3984 def test_dpp_legacy_params_failure(dev
, apdev
):
3985 """DPP legacy parameters local failure"""
3986 check_dpp_capab(dev
[0])
3987 check_dpp_capab(dev
[1])
3988 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
3989 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
3990 dev
[0].dpp_listen(2412)
3991 with
alloc_fail(dev
[1], 1, "dpp_build_conf_obj_legacy"):
3992 dev
[1].dpp_auth_init(uri
=uri0
, conf
="sta-psk", passphrase
="passphrase",
3994 ev
= dev
[0].wait_event(["DPP-CONF-FAILED"], timeout
=5)
3996 raise Exception("DPP configuration failure not reported")
3998 def test_dpp_invalid_configurator_key(dev
, apdev
):
3999 """DPP invalid configurator key"""
4000 check_dpp_capab(dev
[0])
4002 if "FAIL" not in dev
[0].request("DPP_CONFIGURATOR_ADD key=aa"):
4003 raise Exception("Invalid key accepted")
4005 with
alloc_fail(dev
[0], 1, "dpp_keygen_configurator"):
4006 if "FAIL" not in dev
[0].request("DPP_CONFIGURATOR_ADD key=" + dpp_key_p256
):
4007 raise Exception("Error not reported")
4009 with
alloc_fail(dev
[0], 1, "dpp_get_pubkey_point;dpp_keygen_configurator"):
4010 if "FAIL" not in dev
[0].request("DPP_CONFIGURATOR_ADD key=" + dpp_key_p256
):
4011 raise Exception("Error not reported")
4013 with
alloc_fail(dev
[0], 1, "base64_gen_encode;dpp_keygen_configurator"):
4014 if "FAIL" not in dev
[0].request("DPP_CONFIGURATOR_ADD key=" + dpp_key_p256
):
4015 raise Exception("Error not reported")
4017 with
fail_test(dev
[0], 1, "dpp_keygen_configurator"):
4018 if "FAIL" not in dev
[0].request("DPP_CONFIGURATOR_ADD key=" + dpp_key_p256
):
4019 raise Exception("Error not reported")
4021 def test_dpp_own_config_sign_fail(dev
, apdev
):
4022 """DPP own config signing failure"""
4023 check_dpp_capab(dev
[0])
4024 conf_id
= dev
[0].dpp_configurator_add()
4028 " configurator=%d" % conf_id
,
4029 " conf=sta-dpp configurator=%d curve=unsupported" % conf_id
]
4031 if "FAIL" not in dev
[0].request("DPP_CONFIGURATOR_SIGN " + t
):
4032 raise Exception("Invalid command accepted: " + t
)
4034 def test_dpp_peer_intro_failures(dev
, apdev
):
4035 """DPP peer introduction failures"""
4037 run_dpp_peer_intro_failures(dev
, apdev
)
4039 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
4041 def run_dpp_peer_intro_failures(dev
, apdev
):
4042 check_dpp_capab(dev
[0])
4043 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured"})
4044 check_dpp_capab(hapd
)
4046 conf_id
= hapd
.dpp_configurator_add(key
=dpp_key_p256
)
4047 csign
= hapd
.request("DPP_CONFIGURATOR_GET_KEY %d" % conf_id
)
4048 if "FAIL" in csign
or len(csign
) == 0:
4049 raise Exception("DPP_CONFIGURATOR_GET_KEY failed")
4051 conf_id2
= dev
[0].dpp_configurator_add(key
=csign
)
4052 csign2
= dev
[0].request("DPP_CONFIGURATOR_GET_KEY %d" % conf_id2
)
4055 raise Exception("Unexpected difference in configurator key")
4057 cmd
= "DPP_CONFIGURATOR_SIGN conf=ap-dpp configurator=%d" % conf_id
4058 res
= hapd
.request(cmd
)
4060 raise Exception("Failed to generate own configuration")
4061 update_hapd_config(hapd
)
4063 dev
[0].set("dpp_config_processing", "1")
4064 cmd
= "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % conf_id
4065 res
= dev
[0].request(cmd
)
4067 raise Exception("Failed to generate own configuration")
4068 ev
= dev
[0].wait_event(["DPP-NETWORK-ID"], timeout
=1)
4070 raise Exception("DPP network profile not generated")
4071 id = ev
.split(' ')[1]
4072 dev
[0].select_network(id, freq
=2412)
4073 dev
[0].wait_connected()
4074 dev
[0].request("DISCONNECT")
4075 dev
[0].wait_disconnected()
4076 dev
[0].dump_monitor()
4078 tests
= ["eyJ0eXAiOiJkcHBDb24iLCJraWQiOiIwTlNSNTlxRTc0alFfZTFLVGVPV1lYY1pTWnFUaDdNXzU0aHJPcFRpaFJnIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOltdLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiJiVmFMRGlBT09OQmFjcVFVN1pYamFBVEtEMVhhbDVlUExqOUZFZUl3VkN3IiwieSI6Il95c25JR1hTYjBvNEsyMWg0anZmSkZxMHdVNnlPNWp1VUFPd3FuM0dHVHMifX0.WgzZBOJaisWBRxvtXPbVYPXU7OIZxs6sZD-cPOLmJVTIYZKdMkSOMvP5b6si_j61FIrjhm43tmGq1P6cpoxB_g",
4079 "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiIwTlNSNTlxRTc0alFfZTFLVGVPV1lYY1pTWnFUaDdNXzU0aHJPcFRpaFJnIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7fV0sIm5ldEFjY2Vzc0tleSI6eyJrdHkiOiJFQyIsImNydiI6IlAtMjU2IiwieCI6IkJhY3BWSDNpNDBrZklNS0RHa1FFRzhCODBCaEk4cEFmTWpLbzM5NlFZT2ciLCJ5IjoiMjBDYjhDNjRsSjFzQzV2NXlKMnBFZXRRempxMjI4YVV2cHMxNmQ0M3EwQSJ9fQ.dG2y8VvZQJ5hfob8E5F2FAeR7Nd700qstYkxDgA2QfARaNMZ0_SfKfoG-yKXsIZNM-TvGBfACgfhagG9Oaw_Xw",
4080 "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiIwTlNSNTlxRTc0alFfZTFLVGVPV1lYY1pTWnFUaDdNXzU0aHJPcFRpaFJnIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiJkc2VmcmJWWlhad0RMWHRpLWlObDBBYkFIOXpqeFFKd0R1SUd5NzNuZGU0IiwieSI6IjZFQnExN3cwYW1fZlh1OUQ4UGxWYk9XZ2I3b19DcTUxWHlmSG8wcHJyeDQifX0.caBvdDUtXrhnS61-juVZ_2FQdprepv0yZjC04G4ERvLUpeX7cgu0Hp-A1aFDogP1PEFGpkaEdcAWRQnSSRiIKQ"]
4082 dev
[0].set_network_quoted(id, "dpp_connector", t
)
4083 dev
[0].select_network(id, freq
=2412)
4084 ev
= dev
[0].wait_event(["DPP-INTRO"], timeout
=5)
4085 if ev
is None or "status=8" not in ev
:
4086 raise Exception("Introduction failure not reported")
4087 dev
[0].request("DISCONNECT")
4088 dev
[0].dump_monitor()
4090 def test_dpp_peer_intro_local_failures(dev
, apdev
):
4091 """DPP peer introduction local failures"""
4092 check_dpp_capab(dev
[0])
4093 check_dpp_capab(dev
[1])
4095 params
= {"ssid": "dpp",
4097 "wpa_key_mgmt": "DPP",
4099 "rsn_pairwise": "CCMP",
4100 "dpp_connector": params1_ap_connector
,
4101 "dpp_csign": params1_csign
,
4102 "dpp_netaccesskey": params1_ap_netaccesskey
}
4104 hapd
= hostapd
.add_ap(apdev
[0], params
)
4106 raise HwsimSkip("DPP not supported")
4108 tests
= ["dpp_derive_pmk",
4109 "dpp_hkdf_expand;dpp_derive_pmk",
4112 with
fail_test(dev
[0], 1, func
):
4113 dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412",
4115 dpp_csign
=params1_csign
,
4116 dpp_connector
=params1_sta_connector
,
4117 dpp_netaccesskey
=params1_sta_netaccesskey
,
4119 ev
= dev
[0].wait_event(["DPP-INTRO"], timeout
=10)
4120 if ev
is None or "fail=peer_connector_validation_failed" not in ev
:
4121 raise Exception("Introduction failure not reported")
4122 dev
[0].request("REMOVE_NETWORK all")
4123 dev
[0].dump_monitor()
4125 tests
= [(1, "base64_gen_decode;dpp_peer_intro"),
4126 (1, "json_parse;dpp_peer_intro"),
4127 (50, "json_parse;dpp_peer_intro"),
4128 (1, "=dpp_peer_intro"),
4129 (1, "dpp_parse_jwk")]
4130 for count
, func
in tests
:
4131 with
alloc_fail(dev
[0], count
, func
):
4132 dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412",
4134 dpp_csign
=params1_csign
,
4135 dpp_connector
=params1_sta_connector
,
4136 dpp_netaccesskey
=params1_sta_netaccesskey
,
4138 ev
= dev
[0].wait_event(["DPP-INTRO"], timeout
=10)
4139 if ev
is None or "fail=peer_connector_validation_failed" not in ev
:
4140 raise Exception("Introduction failure not reported")
4141 dev
[0].request("REMOVE_NETWORK all")
4142 dev
[0].dump_monitor()
4144 parts
= params1_ap_connector
.split('.')
4145 for ap_connector
in ['.'.join(parts
[0:2]), '.'.join(parts
[0:1])]:
4146 hapd
.set("dpp_connector", ap_connector
)
4147 dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412",
4149 dpp_csign
=params1_csign
,
4150 dpp_connector
=params1_sta_connector
,
4151 dpp_netaccesskey
=params1_sta_netaccesskey
,
4153 ev
= dev
[0].wait_event(["DPP-TX-STATUS"], timeout
=10)
4155 raise Exception("No TX status reported")
4156 dev
[0].request("REMOVE_NETWORK all")
4157 dev
[0].dump_monitor()
4159 hapd
.set("dpp_netaccesskey", "00")
4160 dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412",
4162 dpp_csign
=params1_csign
,
4163 dpp_connector
=params1_sta_connector
,
4164 dpp_netaccesskey
=params1_sta_netaccesskey
,
4166 ev
= dev
[0].wait_event(["DPP-TX-STATUS"], timeout
=10)
4168 raise Exception("No TX status reported")
4169 dev
[0].request("REMOVE_NETWORK all")
4170 dev
[0].dump_monitor()
4172 hapd
.set("dpp_csign", "00")
4173 dev
[0].connect("dpp", key_mgmt
="DPP", scan_freq
="2412",
4175 dpp_csign
=params1_csign
,
4176 dpp_connector
=params1_sta_connector
,
4177 dpp_netaccesskey
=params1_sta_netaccesskey
,
4179 ev
= dev
[0].wait_event(["DPP-TX-STATUS"], timeout
=10)
4181 raise Exception("No TX status reported")
4182 dev
[0].request("REMOVE_NETWORK all")
4184 def run_dpp_configurator_id_unknown(dev
):
4185 check_dpp_capab(dev
)
4186 conf_id
= dev
.dpp_configurator_add()
4187 if "FAIL" not in dev
.request("DPP_CONFIGURATOR_GET_KEY %d" % (conf_id
+ 1)):
4188 raise Exception("DPP_CONFIGURATOR_GET_KEY with incorrect id accepted")
4190 cmd
= "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id
+ 1)
4191 if "FAIL" not in dev
.request(cmd
):
4192 raise Exception("DPP_CONFIGURATOR_SIGN with incorrect id accepted")
4194 def test_dpp_configurator_id_unknown(dev
, apdev
):
4195 """DPP and unknown configurator id"""
4196 run_dpp_configurator_id_unknown(dev
[0])
4197 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured"})
4198 run_dpp_configurator_id_unknown(hapd
)
4200 def run_dpp_bootstrap_gen_failures(dev
):
4201 check_dpp_capab(dev
)
4203 tests
= ["type=unsupported",
4204 "type=qrcode chan=-1",
4205 "type=qrcode mac=a",
4206 "type=qrcode key=qq",
4208 "type=qrcode info=abc\tdef"]
4210 if "FAIL" not in dev
.request("DPP_BOOTSTRAP_GEN " + t
):
4211 raise Exception("Command accepted unexpectedly")
4213 id = dev
.dpp_bootstrap_gen()
4214 uri
= dev
.request("DPP_BOOTSTRAP_GET_URI %d" % id)
4215 if not uri
.startswith("DPP:"):
4216 raise Exception("Could not get URI")
4217 if "FAIL" not in dev
.request("DPP_BOOTSTRAP_GET_URI 0"):
4218 raise Exception("Failure not reported")
4219 info
= dev
.request("DPP_BOOTSTRAP_INFO %d" % id)
4220 if not info
.startswith("type=QRCODE"):
4221 raise Exception("Could not get info")
4222 if "FAIL" not in dev
.request("DPP_BOOTSTRAP_REMOVE 0"):
4223 raise Exception("Failure not reported")
4224 if "FAIL" in dev
.request("DPP_BOOTSTRAP_REMOVE *"):
4225 raise Exception("Failed to remove bootstrap info")
4226 if "FAIL" not in dev
.request("DPP_BOOTSTRAP_GET_URI %d" % id):
4227 raise Exception("Failure not reported")
4228 if "FAIL" not in dev
.request("DPP_BOOTSTRAP_INFO %d" % id):
4229 raise Exception("Failure not reported")
4231 func
= "dpp_bootstrap_gen"
4232 with
alloc_fail(dev
, 1, "=" + func
):
4233 if "FAIL" not in dev
.request("DPP_BOOTSTRAP_GEN type=qrcode"):
4234 raise Exception("Command accepted unexpectedly")
4236 with
alloc_fail(dev
, 1, "dpp_gen_uri;dpp_bootstrap_gen"):
4237 if "FAIL" not in dev
.request("DPP_BOOTSTRAP_GEN type=qrcode"):
4238 raise Exception("Command accepted unexpectedly")
4240 with
alloc_fail(dev
, 1, "get_param"):
4241 dev
.request("DPP_BOOTSTRAP_GEN type=qrcode curve=foo")
4243 def test_dpp_bootstrap_gen_failures(dev
, apdev
):
4244 """DPP_BOOTSTRAP_GEN/REMOVE/GET_URI/INFO error cases"""
4245 run_dpp_bootstrap_gen_failures(dev
[0])
4246 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured"})
4247 run_dpp_bootstrap_gen_failures(hapd
)
4249 def test_dpp_listen_continue(dev
, apdev
):
4250 """DPP and continue listen state"""
4251 check_dpp_capab(dev
[0])
4252 check_dpp_capab(dev
[1])
4253 id = dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
4254 uri
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
4255 dev
[0].dpp_listen(2412)
4257 dev
[1].dpp_auth_init(uri
=uri
)
4258 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0],
4259 allow_enrollee_failure
=True, stop_responder
=True,
4260 stop_initiator
=True)
4262 def test_dpp_network_addition_failure(dev
, apdev
):
4263 """DPP network addition failure"""
4265 run_dpp_network_addition_failure(dev
, apdev
)
4267 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
4269 def run_dpp_network_addition_failure(dev
, apdev
):
4270 check_dpp_capab(dev
[0])
4271 conf_id
= dev
[0].dpp_configurator_add()
4272 dev
[0].set("dpp_config_processing", "1")
4273 cmd
= "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % conf_id
4274 tests
= [(1, "=wpas_dpp_add_network"),
4275 (2, "=wpas_dpp_add_network"),
4276 (3, "=wpas_dpp_add_network"),
4277 (4, "=wpas_dpp_add_network"),
4278 (1, "wpa_config_add_network;wpas_dpp_add_network")]
4279 for count
, func
in tests
:
4280 with
alloc_fail(dev
[0], count
, func
):
4281 res
= dev
[0].request(cmd
)
4283 ev
= dev
[0].wait_event(["DPP-NET-ACCESS-KEY"], timeout
=2)
4285 raise Exception("Config object not processed")
4286 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
4287 dev
[0].dump_monitor()
4289 cmd
= "DPP_CONFIGURATOR_SIGN conf=sta-psk pass=%s configurator=%d" % (binascii
.hexlify(b
"passphrase").decode(), conf_id
)
4290 tests
= [(1, "wpa_config_set_quoted;wpas_dpp_add_network")]
4291 for count
, func
in tests
:
4292 with
alloc_fail(dev
[0], count
, func
):
4293 res
= dev
[0].request(cmd
)
4295 ev
= dev
[0].wait_event(["DPP-NET-ACCESS-KEY"], timeout
=2)
4297 raise Exception("Config object not processed")
4298 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
4299 dev
[0].dump_monitor()
4301 def test_dpp_two_initiators(dev
, apdev
):
4302 """DPP and two initiators"""
4303 check_dpp_capab(dev
[0])
4304 check_dpp_capab(dev
[1])
4305 check_dpp_capab(dev
[2])
4306 id = dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
4307 uri
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
4308 dev
[0].dpp_listen(2412)
4309 dev
[1].dpp_auth_init(uri
=uri
)
4310 ev
= dev
[0].wait_event(["DPP-RX"], timeout
=5)
4312 raise Exeption("No DPP Authentication Request seen")
4313 dev
[2].dpp_auth_init(uri
=uri
)
4314 wait_dpp_fail(dev
[0],
4315 "DPP-FAIL Already in DPP authentication exchange - ignore new one")
4317 ev
= dev
[0].wait_event(["DPP-CONF-FAILED"], timeout
=2)
4319 raise Exception("DPP configuration result not seen (Enrollee)")
4320 ev
= dev
[1].wait_event(["DPP-CONF-SENT"], timeout
=2)
4322 raise Exception("DPP configuration result not seen (Responder)")
4324 dev
[0].request("DPP_STOP_LISTEN")
4325 dev
[1].request("DPP_STOP_LISTEN")
4326 dev
[2].request("DPP_STOP_LISTEN")
4328 def test_dpp_conf_file_update(dev
, apdev
, params
):
4329 """DPP provisioning updating wpa_supplicant configuration file"""
4330 config
= os
.path
.join(params
['logdir'], 'dpp_conf_file_update.conf')
4331 with
open(config
, "w") as f
:
4332 f
.write("update_config=1\n")
4333 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
4334 wpas
.interface_add("wlan5", config
=config
)
4335 check_dpp_capab(wpas
)
4336 wpas
.set("dpp_config_processing", "1")
4337 run_dpp_qr_code_auth_unicast([wpas
, dev
[1]], apdev
, None,
4338 init_extra
="conf=sta-dpp",
4339 require_conf_success
=True,
4341 wpas
.interface_remove("wlan5")
4343 with
open(config
, "r") as f
:
4345 for i
in ["network={", "dpp_connector=", "key_mgmt=DPP", "ieee80211w=2",
4346 "dpp_netaccesskey=", "dpp_csign="]:
4348 raise Exception("Configuration file missing '%s'" % i
)
4350 wpas
.interface_add("wlan5", config
=config
)
4351 if len(wpas
.list_networks()) != 1:
4352 raise Exception("Unexpected number of networks")
4354 def test_dpp_duplicated_auth_resp(dev
, apdev
):
4355 """DPP and duplicated Authentication Response"""
4356 check_dpp_capab(dev
[0])
4357 check_dpp_capab(dev
[1])
4358 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
4359 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
4360 dev
[0].set("ext_mgmt_frame_handling", "1")
4361 dev
[1].set("ext_mgmt_frame_handling", "1")
4362 dev
[0].dpp_listen(2412)
4363 dev
[1].dpp_auth_init(uri
=uri0
)
4365 # DPP Authentication Request
4366 rx_process_frame(dev
[0])
4368 # DPP Authentication Response
4369 msg
= rx_process_frame(dev
[1])
4370 frame
= binascii
.hexlify(msg
['frame']).decode()
4372 if "OK" not in dev
[1].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame
)):
4373 raise Exception("MGMT_RX_PROCESS failed")
4374 # Modified frame - nonzero status
4375 if frame
[2*32:2*37] != "0010010000":
4376 raise Exception("Could not find Status attribute")
4377 frame2
= frame
[0:2*32] + "0010010001" + frame
[2*37:]
4378 if "OK" not in dev
[1].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame2
)):
4379 raise Exception("MGMT_RX_PROCESS failed")
4380 frame2
= frame
[0:2*32] + "00100100ff" + frame
[2*37:]
4381 if "OK" not in dev
[1].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], frame2
)):
4382 raise Exception("MGMT_RX_PROCESS failed")
4384 # DPP Authentication Confirmation
4385 rx_process_frame(dev
[0])
4387 wait_auth_success(dev
[0], dev
[1])
4389 # DPP Configuration Request
4390 rx_process_frame(dev
[1])
4392 # DPP Configuration Response
4393 rx_process_frame(dev
[0])
4395 wait_conf_completion(dev
[1], dev
[0])
4397 def test_dpp_duplicated_auth_conf(dev
, apdev
):
4398 """DPP and duplicated Authentication Confirmation"""
4399 check_dpp_capab(dev
[0])
4400 check_dpp_capab(dev
[1])
4401 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
4402 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
4403 dev
[0].set("ext_mgmt_frame_handling", "1")
4404 dev
[1].set("ext_mgmt_frame_handling", "1")
4405 dev
[0].dpp_listen(2412)
4406 dev
[1].dpp_auth_init(uri
=uri0
)
4408 # DPP Authentication Request
4409 rx_process_frame(dev
[0])
4411 # DPP Authentication Response
4412 rx_process_frame(dev
[1])
4414 # DPP Authentication Confirmation
4415 msg
= rx_process_frame(dev
[0])
4417 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg
['freq'], msg
['datarate'], msg
['ssi_signal'], binascii
.hexlify(msg
['frame']).decode())):
4418 raise Exception("MGMT_RX_PROCESS failed")
4420 wait_auth_success(dev
[0], dev
[1])
4422 # DPP Configuration Request
4423 rx_process_frame(dev
[1])
4425 # DPP Configuration Response
4426 rx_process_frame(dev
[0])
4428 wait_conf_completion(dev
[1], dev
[0])
4430 def test_dpp_enrollee_reject_config(dev
, apdev
):
4431 """DPP and Enrollee rejecting Config Object"""
4432 check_dpp_capab(dev
[0])
4433 check_dpp_capab(dev
[1])
4434 dev
[0].set("dpp_test", "91")
4435 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
4436 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
4437 dev
[0].dpp_listen(2412)
4438 dev
[1].dpp_auth_init(uri
=uri0
, conf
="sta-sae", ssid
="dpp-legacy",
4439 passphrase
="secret passphrase")
4440 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0],
4441 allow_enrollee_failure
=True,
4442 allow_configurator_failure
=True)
4444 def test_dpp_enrollee_ap_reject_config(dev
, apdev
):
4445 """DPP and Enrollee AP rejecting Config Object"""
4446 check_dpp_capab(dev
[0])
4447 check_dpp_capab(dev
[1])
4448 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "unconfigured"})
4449 check_dpp_capab(hapd
)
4450 hapd
.set("dpp_test", "91")
4451 conf_id
= dev
[0].dpp_configurator_add()
4452 id_h
= hapd
.dpp_bootstrap_gen(chan
="81/1", mac
=True)
4453 uri
= hapd
.request("DPP_BOOTSTRAP_GET_URI %d" % id_h
)
4454 dev
[0].dpp_auth_init(uri
=uri
, conf
="ap-dpp", configurator
=conf_id
)
4455 wait_auth_success(hapd
, dev
[0], configurator
=dev
[0], enrollee
=hapd
,
4456 allow_enrollee_failure
=True,
4457 allow_configurator_failure
=True)
4459 def test_dpp_legacy_and_dpp_akm(dev
, apdev
):
4460 """DPP and provisoning DPP and legacy AKMs"""
4462 run_dpp_legacy_and_dpp_akm(dev
, apdev
)
4464 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
4466 def run_dpp_legacy_and_dpp_akm(dev
, apdev
):
4467 check_dpp_capab(dev
[0], min_ver
=2)
4468 check_dpp_capab(dev
[1], min_ver
=2)
4470 csign
= "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
4471 csign_pub
= "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
4472 ap_connector
= "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
4473 ap_netaccesskey
= "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
4476 passphrase
= "secret passphrase"
4477 params
= {"ssid": ssid
,
4479 "wpa_key_mgmt": "DPP WPA-PSK SAE",
4481 "sae_require_mfp": '1',
4482 "rsn_pairwise": "CCMP",
4483 "wpa_passphrase": passphrase
,
4484 "dpp_connector": ap_connector
,
4485 "dpp_csign": csign_pub
,
4486 "dpp_netaccesskey": ap_netaccesskey
}
4488 hapd
= hostapd
.add_ap(apdev
[0], params
)
4490 raise HwsimSkip("DPP not supported")
4492 dev
[0].request("SET sae_groups ")
4493 conf_id
= dev
[1].dpp_configurator_add(key
=csign
)
4494 dev
[0].set("dpp_config_processing", "1")
4495 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
4496 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
4497 dev
[0].dpp_listen(2412)
4498 dev
[1].dpp_auth_init(uri
=uri0
, conf
="sta-psk-sae-dpp", ssid
=ssid
,
4499 passphrase
=passphrase
, configurator
=conf_id
)
4500 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0],
4501 allow_enrollee_failure
=True,
4502 allow_configurator_failure
=True)
4503 ev
= dev
[0].wait_event(["DPP-NETWORK-ID"], timeout
=1)
4505 raise Exception("DPP network profile not generated")
4506 id0
= ev
.split(' ')[1]
4508 key_mgmt
= dev
[0].get_network(id0
, "key_mgmt").split(' ')
4509 for m
in ["SAE", "WPA-PSK", "DPP"]:
4510 if m
not in key_mgmt
:
4511 raise Exception("%s missing from key_mgmt" % m
)
4513 dev
[0].scan_for_bss(hapd
.own_addr(), freq
=2412)
4514 dev
[0].select_network(id0
, freq
=2412)
4515 dev
[0].wait_connected()
4517 dev
[0].request("DISCONNECT")
4518 dev
[0].wait_disconnected()
4521 params
= {"ssid": ssid
,
4523 "wpa_key_mgmt": "WPA-PSK SAE",
4525 "sae_require_mfp": '1',
4526 "rsn_pairwise": "CCMP",
4527 "wpa_passphrase": passphrase
}
4528 hapd2
= hostapd
.add_ap(apdev
[1], params
)
4530 dev
[0].request("BSS_FLUSH 0")
4531 dev
[0].scan_for_bss(hapd2
.own_addr(), freq
=2412, force_scan
=True,
4533 dev
[0].select_network(id0
, freq
=2412)
4534 dev
[0].wait_connected()
4536 dev
[0].request("DISCONNECT")
4537 dev
[0].wait_disconnected()
4539 def test_dpp_controller_relay(dev
, apdev
, params
):
4540 """DPP Controller/Relay"""
4542 run_dpp_controller_relay(dev
, apdev
, params
)
4544 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
4545 dev
[1].request("DPP_CONTROLLER_STOP")
4547 def run_dpp_controller_relay(dev
, apdev
, params
):
4548 check_dpp_capab(dev
[0])
4549 check_dpp_capab(dev
[1])
4550 prefix
= "dpp_controller_relay"
4551 cap_lo
= os
.path
.join(params
['logdir'], prefix
+ ".lo.pcap")
4553 wt
= WlantestCapture('lo', cap_lo
)
4556 conf_id
= dev
[1].dpp_configurator_add()
4557 dev
[1].set("dpp_configurator_params",
4558 " conf=sta-dpp configurator=%d" % conf_id
)
4559 id_c
= dev
[1].dpp_bootstrap_gen()
4560 uri_c
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c
)
4561 res
= dev
[1].request("DPP_BOOTSTRAP_INFO %d" % id_c
)
4563 for line
in res
.splitlines():
4564 name
, value
= line
.split('=')
4565 if name
== "pkhash":
4569 raise Exception("Could not fetch public key hash from Controller")
4570 if "OK" not in dev
[1].request("DPP_CONTROLLER_START"):
4571 raise Exception("Failed to start Controller")
4574 params
= {"ssid": "unconfigured",
4576 "dpp_controller": "ipaddr=127.0.0.1 pkhash=" + pkhash
}
4577 relay
= hostapd
.add_ap(apdev
[1], params
)
4578 check_dpp_capab(relay
)
4580 # Enroll Relay to the network
4581 # TODO: Do this over TCP once direct Enrollee-over-TCP case is supported
4582 id_h
= relay
.dpp_bootstrap_gen(chan
="81/6", mac
=True)
4583 uri_r
= relay
.request("DPP_BOOTSTRAP_GET_URI %d" % id_h
)
4584 dev
[1].dpp_auth_init(uri
=uri_r
, conf
="ap-dpp", configurator
=conf_id
)
4585 wait_auth_success(relay
, dev
[1], configurator
=dev
[1], enrollee
=relay
)
4586 update_hapd_config(relay
)
4588 # Initiate from Enrollee with broadcast DPP Authentication Request
4589 dev
[0].set("dpp_config_processing", "2")
4590 dev
[0].dpp_auth_init(uri
=uri_c
, role
="enrollee")
4591 wait_auth_success(dev
[1], dev
[0], configurator
=dev
[1], enrollee
=dev
[0],
4592 allow_enrollee_failure
=True,
4593 allow_configurator_failure
=True)
4594 dev
[0].wait_connected()
4599 def test_dpp_tcp(dev
, apdev
, params
):
4602 cap_lo
= os
.path
.join(params
['logdir'], prefix
+ ".lo.pcap")
4604 run_dpp_tcp(dev
, apdev
, cap_lo
)
4606 dev
[1].request("DPP_CONTROLLER_STOP")
4608 def test_dpp_tcp_port(dev
, apdev
, params
):
4609 """DPP over TCP and specified port"""
4610 prefix
= "dpp_tcp_port"
4611 cap_lo
= os
.path
.join(params
['logdir'], prefix
+ ".lo.pcap")
4613 run_dpp_tcp(dev
, apdev
, cap_lo
, port
="23456")
4615 dev
[1].request("DPP_CONTROLLER_STOP")
4617 def run_dpp_tcp(dev
, apdev
, cap_lo
, port
=None):
4618 check_dpp_capab(dev
[0])
4619 check_dpp_capab(dev
[1])
4621 wt
= WlantestCapture('lo', cap_lo
)
4625 conf_id
= dev
[1].dpp_configurator_add()
4626 dev
[1].set("dpp_configurator_params",
4627 " conf=sta-dpp configurator=%d" % conf_id
)
4628 id_c
= dev
[1].dpp_bootstrap_gen()
4629 uri_c
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c
)
4630 res
= dev
[1].request("DPP_BOOTSTRAP_INFO %d" % id_c
)
4632 for line
in res
.splitlines():
4633 name
, value
= line
.split('=')
4634 if name
== "pkhash":
4638 raise Exception("Could not fetch public key hash from Controller")
4639 req
= "DPP_CONTROLLER_START"
4641 req
+= " tcp_port=" + port
4642 if "OK" not in dev
[1].request(req
):
4643 raise Exception("Failed to start Controller")
4645 # Initiate from Enrollee with broadcast DPP Authentication Request
4646 dev
[0].dpp_auth_init(uri
=uri_c
, role
="enrollee", tcp_addr
="127.0.0.1",
4648 wait_auth_success(dev
[1], dev
[0], configurator
=dev
[1], enrollee
=dev
[0],
4649 allow_enrollee_failure
=True,
4650 allow_configurator_failure
=True)
4654 def test_dpp_tcp_controller_start_failure(dev
, apdev
, params
):
4655 """DPP Controller startup failure"""
4656 check_dpp_capab(dev
[0])
4659 if "OK" not in dev
[0].request("DPP_CONTROLLER_START"):
4660 raise Exception("Could not start Controller")
4661 if "OK" in dev
[0].request("DPP_CONTROLLER_START"):
4662 raise Exception("Second Controller start not rejected")
4664 dev
[0].request("DPP_CONTROLLER_STOP")
4666 tests
= ["dpp_controller_start",
4667 "eloop_sock_table_add_sock;?eloop_register_sock;dpp_controller_start"]
4669 with
alloc_fail(dev
[0], 1, func
):
4670 if "FAIL" not in dev
[0].request("DPP_CONTROLLER_START"):
4671 raise Exception("Failure not reported during OOM")
4673 def test_dpp_tcp_init_failure(dev
, apdev
, params
):
4674 """DPP TCP init failure"""
4675 check_dpp_capab(dev
[0])
4676 check_dpp_capab(dev
[1])
4677 id_c
= dev
[1].dpp_bootstrap_gen()
4678 uri_c
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c
)
4679 peer
= dev
[0].dpp_qr_code(uri_c
)
4680 tests
= ["dpp_tcp_init",
4681 "eloop_sock_table_add_sock;?eloop_register_sock;dpp_tcp_init",
4683 cmd
= "DPP_AUTH_INIT peer=%d tcp_addr=127.0.0.1" % peer
4685 with
alloc_fail(dev
[0], 1, func
):
4686 if "FAIL" not in dev
[0].request(cmd
):
4687 raise Exception("DPP_AUTH_INIT accepted during OOM")
4689 def test_dpp_controller_rx_failure(dev
, apdev
, params
):
4690 """DPP Controller RX failure"""
4691 check_dpp_capab(dev
[0])
4692 check_dpp_capab(dev
[1])
4694 run_dpp_controller_rx_failure(dev
, apdev
)
4696 dev
[0].request("DPP_CONTROLLER_STOP")
4698 def run_dpp_controller_rx_failure(dev
, apdev
):
4699 if "OK" not in dev
[0].request("DPP_CONTROLLER_START"):
4700 raise Exception("Could not start Controller")
4701 id_c
= dev
[0].dpp_bootstrap_gen()
4702 uri_c
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id_c
)
4703 peer
= dev
[1].dpp_qr_code(uri_c
)
4704 tests
= ["dpp_controller_tcp_cb",
4705 "eloop_sock_table_add_sock;?eloop_register_sock;dpp_controller_tcp_cb",
4706 "dpp_controller_rx",
4707 "dpp_controller_rx_auth_req",
4708 "wpabuf_alloc;=dpp_controller_rx_auth_req"]
4709 cmd
= "DPP_AUTH_INIT peer=%d tcp_addr=127.0.0.1" % peer
4711 with
alloc_fail(dev
[0], 1, func
):
4712 if "OK" not in dev
[1].request(cmd
):
4713 raise Exception("Failed to initiate TCP connection")
4714 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
4716 def test_dpp_controller_rx_errors(dev
, apdev
, params
):
4717 """DPP Controller RX error cases"""
4718 check_dpp_capab(dev
[0])
4719 check_dpp_capab(dev
[1])
4721 run_dpp_controller_rx_errors(dev
, apdev
)
4723 dev
[0].request("DPP_CONTROLLER_STOP")
4725 def run_dpp_controller_rx_errors(dev
, apdev
):
4726 if "OK" not in dev
[0].request("DPP_CONTROLLER_START"):
4727 raise Exception("Could not start Controller")
4729 addr
= ("127.0.0.1", 7871)
4733 b
"\x00\x00\x00\x00",
4734 b
"\x00\x00\x00\x01",
4735 b
"\x00\x00\x00\x01\x09",
4736 b
"\x00\x00\x00\x07\x09\x50\x6f\x9a\x1a\xff\xff",
4737 b
"\x00\x00\x00\x07\x09\x50\x6f\x9a\x1a\x01\xff",
4738 b
"\x00\x00\x00\x07\x09\x50\x6f\x9a\x1a\x01\x00",
4739 b
"\x00\x00\x00\x08\x09\x50\x6f\x9a\x1a\x01\x00\xff",
4740 b
"\x00\x00\x00\x01\x0a",
4741 b
"\x00\x00\x00\x04\x0a\xff\xff\xff",
4742 b
"\x00\x00\x00\x01\x0b",
4743 b
"\x00\x00\x00\x08\x0b\xff\xff\xff\xff\xff\xff\xff",
4744 b
"\x00\x00\x00\x08\x0b\xff\x00\x00\xff\xff\xff\xff",
4745 b
"\x00\x00\x00\x08\x0b\xff\x00\x00\xff\xff\x6c\x00",
4746 b
"\x00\x00\x00\x0a\x0b\xff\x00\x00\xff\xff\x6c\x02\xff\xff",
4747 b
"\x00\x00\x00\x10\x0b\xff\x00\x00\xff\xff\x6c\x08\xff\xdd\x05\x50\x6f\x9a\x1a\x01",
4748 b
"\x00\x00\x00\x12\x0b\xff\x00\x00\xff\xff\x6c\x08\xff\xdd\x05\x50\x6f\x9a\x1a\x01\x00\x00",
4749 b
"\x00\x00\x00\x01\xff",
4750 b
"\x00\x00\x00\x01\xff\xee"]
4751 #define WLAN_PA_GAS_INITIAL_REQ 10
4752 #define WLAN_PA_GAS_INITIAL_RESP 11
4755 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
,
4757 sock
.settimeout(0.1)
4763 except socket
.timeout
:
4767 def test_dpp_conn_status_success(dev
, apdev
):
4768 """DPP connection status - success"""
4770 run_dpp_conn_status(dev
, apdev
)
4772 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
4774 def test_dpp_conn_status_wrong_passphrase(dev
, apdev
):
4775 """DPP connection status - wrong passphrase"""
4777 run_dpp_conn_status(dev
, apdev
, result
=2)
4779 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
4781 def test_dpp_conn_status_no_ap(dev
, apdev
):
4782 """DPP connection status - no AP"""
4784 run_dpp_conn_status(dev
, apdev
, result
=10)
4786 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
4788 def test_dpp_conn_status_connector_mismatch(dev
, apdev
):
4789 """DPP connection status - invalid Connector"""
4791 run_dpp_conn_status(dev
, apdev
, result
=8)
4793 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
4795 def test_dpp_conn_status_assoc_reject(dev
, apdev
):
4796 """DPP connection status - association rejection"""
4798 dev
[0].request("TEST_ASSOC_IE 30020000")
4799 run_dpp_conn_status(dev
, apdev
, assoc_reject
=True)
4801 dev
[0].set("dpp_config_processing", "0", allow_fail
=True)
4803 def run_dpp_conn_status(dev
, apdev
, result
=0, assoc_reject
=False):
4804 check_dpp_capab(dev
[0], min_ver
=2)
4805 check_dpp_capab(dev
[1], min_ver
=2)
4808 if result
== 7 or result
== 8:
4809 params
= {"ssid": "dpp-status",
4811 "wpa_key_mgmt": "DPP",
4813 "rsn_pairwise": "CCMP",
4814 "dpp_connector": params1_ap_connector
,
4815 "dpp_csign": params1_csign
,
4816 "dpp_netaccesskey": params1_ap_netaccesskey
}
4819 passphrase
= "wrong passphrase"
4821 passphrase
= "secret passphrase"
4822 params
= hostapd
.wpa2_params(ssid
="dpp-status",
4823 passphrase
=passphrase
)
4825 hapd
= hostapd
.add_ap(apdev
[0], params
)
4827 raise HwsimSkip("DPP not supported")
4829 dev
[0].request("SET sae_groups ")
4830 dev
[0].set("dpp_config_processing", "2")
4831 id0
= dev
[0].dpp_bootstrap_gen(chan
="81/1", mac
=True)
4832 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
4834 dev
[0].dpp_listen(2412)
4835 if result
== 7 or result
== 8:
4838 configurator
= dev
[1].dpp_configurator_add()
4841 passphrase
= "secret passphrase"
4843 dev
[1].dpp_auth_init(uri
=uri0
, conf
=conf
, ssid
="dpp-status",
4844 passphrase
=passphrase
, configurator
=configurator
,
4846 res
= wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1],
4848 if 'wait_conn_status' not in res
:
4849 raise Exception("Configurator did not request connection status")
4851 if assoc_reject
and result
== 0:
4853 ev
= dev
[1].wait_event(["DPP-CONN-STATUS-RESULT"], timeout
=20)
4855 raise Exception("No connection status reported")
4857 raise Exception("Connection status result timeout")
4858 if "result=%d" % result
not in ev
:
4859 raise Exception("Unexpected connection status result: " + ev
)
4860 if "ssid=dpp-status" not in ev
:
4861 raise Exception("SSID not reported")
4864 dev
[0].wait_connected()
4865 if result
== 10 and "channel_list=" not in ev
:
4866 raise Exception("Channel list not reported for no-AP")
4868 def test_dpp_mud_url(dev
, apdev
):
4870 check_dpp_capab(dev
[0])
4872 dev
[0].set("dpp_name", "Test Enrollee")
4873 dev
[0].set("dpp_mud_url", "https://example.com/mud")
4874 run_dpp_qr_code_auth_unicast(dev
, apdev
, None)
4876 dev
[0].set("dpp_mud_url", "")
4877 dev
[0].set("dpp_name", "Test")
4879 def test_dpp_mud_url_hostapd(dev
, apdev
):
4880 """DPP MUD URL from hostapd"""
4881 check_dpp_capab(dev
[0])
4882 check_dpp_capab(dev
[1])
4883 params
= {"ssid": "unconfigured",
4884 "dpp_name": "AP Enrollee",
4885 "dpp_mud_url": "https://example.com/mud"}
4886 hapd
= hostapd
.add_ap(apdev
[0], params
)
4887 check_dpp_capab(hapd
)
4889 id_h
= hapd
.dpp_bootstrap_gen(chan
="81/1", mac
=True)
4890 uri
= hapd
.request("DPP_BOOTSTRAP_GET_URI %d" % id_h
)
4892 conf_id
= dev
[0].dpp_configurator_add()
4893 dev
[0].dpp_auth_init(uri
=uri
, conf
="ap-dpp", configurator
=conf_id
)
4894 wait_auth_success(hapd
, dev
[0], configurator
=dev
[0], enrollee
=hapd
)
4895 update_hapd_config(hapd
)
4897 def test_dpp_config_save(dev
, apdev
, params
):
4898 """DPP configuration saving"""
4899 config
= os
.path
.join(params
['logdir'], 'dpp_config_save.conf')
4900 run_dpp_config_save(dev
, apdev
, config
, "test", '"test"')
4902 def test_dpp_config_save2(dev
, apdev
, params
):
4903 """DPP configuration saving (2)"""
4904 config
= os
.path
.join(params
['logdir'], 'dpp_config_save2.conf')
4905 run_dpp_config_save(dev
, apdev
, config
, "\\u0001*", '012a')
4907 def test_dpp_config_save3(dev
, apdev
, params
):
4908 """DPP configuration saving (3)"""
4909 config
= os
.path
.join(params
['logdir'], 'dpp_config_save3.conf')
4910 run_dpp_config_save(dev
, apdev
, config
, "\\u0001*\\u00c2\\u00bc\\u00c3\\u009e\\u00c3\\u00bf", '012ac2bcc39ec3bf')
4912 def run_dpp_config_save(dev
, apdev
, config
, conf_ssid
, exp_ssid
):
4913 check_dpp_capab(dev
[1])
4914 with
open(config
, "w") as f
:
4915 f
.write("update_config=1\n" +
4916 "dpp_config_processing=1\n")
4917 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
4918 wpas
.interface_add("wlan5", config
=config
)
4919 check_dpp_capab(wpas
)
4920 conf
= '{"wi-fi_tech":"infra", "discovery":{"ssid":"' + conf_ssid
+ '"},"cred":{"akm":"psk","pass":"secret passphrase"}}'
4921 dev
[1].set("dpp_config_obj_override", conf
)
4922 dpp_dev
= [wpas
, dev
[1]]
4923 run_dpp_qr_code_auth_unicast(dpp_dev
, apdev
, "prime256v1",
4924 require_conf_success
=True)
4925 if "OK" not in wpas
.request("SAVE_CONFIG"):
4926 raise Exception("Failed to save configuration file")
4927 with
open(config
, "r") as f
:
4929 logger
.info("Saved configuration:\n" + data
)
4930 if 'ssid=' + exp_ssid
+ '\n' not in data
:
4931 raise Exception("SSID not saved")
4932 if 'psk="secret passphrase"' not in data
:
4933 raise Exception("Passphtase not saved")
4935 def test_dpp_nfc_uri(dev
, apdev
):
4936 """DPP bootstrapping via NFC URI record"""
4937 check_dpp_capab(dev
[0])
4938 check_dpp_capab(dev
[1])
4940 id = dev
[0].dpp_bootstrap_gen(type="nfc-uri", chan
="81/1", mac
=True)
4941 uri
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
4942 logger
.info("Generated URI: " + uri
)
4943 info
= dev
[0].request("DPP_BOOTSTRAP_INFO %d" % id)
4944 logger
.info("Bootstrapping info:\n" + info
)
4945 if "type=NFC-URI" not in info
:
4946 raise Exception("Unexpected bootstrapping info contents")
4948 dev
[0].dpp_listen(2412)
4949 conf_id
= dev
[1].dpp_configurator_add()
4950 dev
[1].dpp_auth_init(nfc_uri
=uri
, configurator
=conf_id
, conf
="sta-dpp")
4951 wait_auth_success(dev
[0], dev
[1], configurator
=dev
[1], enrollee
=dev
[0])
4953 def test_dpp_nfc_negotiated_handover(dev
, apdev
):
4954 """DPP bootstrapping via NFC negotiated handover"""
4955 run_dpp_nfc_negotiated_handover(dev
, apdev
)
4957 def test_dpp_nfc_negotiated_handover_diff_curve(dev
, apdev
):
4958 """DPP bootstrapping via NFC negotiated handover (different curve)"""
4959 run_dpp_nfc_negotiated_handover(dev
, apdev
, curve0
="prime256v1",
4962 def run_dpp_nfc_negotiated_handover(dev
, apdev
, curve0
=None, curve1
=None):
4963 check_dpp_capab(dev
[0])
4964 check_dpp_capab(dev
[1])
4966 id0
= dev
[0].dpp_bootstrap_gen(type="nfc-uri", chan
="81/6,11", mac
=True,
4968 uri0
= dev
[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0
)
4969 logger
.info("Generated URI[0]: " + uri0
)
4970 id1
= dev
[1].dpp_bootstrap_gen(type="nfc-uri", chan
="81/1,6,11", mac
=True,
4972 uri1
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1
)
4973 logger
.info("Generated URI[1]: " + uri1
)
4975 # dev[0] acting as NFC Handover Requestor
4976 # dev[1] acting as NFC Handover Selector
4977 res
= dev
[1].request("DPP_NFC_HANDOVER_REQ own=%d uri=%s" % (id1
, uri0
))
4979 raise Exception("Failed to process NFC Handover Request")
4980 info
= dev
[1].request("DPP_BOOTSTRAP_INFO %d" % id1
)
4981 logger
.info("Updated local bootstrapping info:\n" + info
)
4983 for line
in info
.splitlines():
4984 if line
.startswith("use_freq="):
4985 freq
= int(line
.split('=')[1])
4987 raise Exception("Selected channel not indicated")
4988 uri1
= dev
[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1
)
4989 logger
.info("Updated URI[1]: " + uri1
)
4990 dev
[1].dpp_listen(freq
)
4991 res
= dev
[0].request("DPP_NFC_HANDOVER_SEL own=%d uri=%s" % (id0
, uri1
))
4993 raise Exception("Failed to process NFC Handover Select")
4996 conf_id
= dev
[0].dpp_configurator_add()
4997 dev
[0].dpp_auth_init(peer
=peer
, own
=id0
, configurator
=conf_id
,
4999 wait_auth_success(dev
[1], dev
[0], configurator
=dev
[0], enrollee
=dev
[1])
5001 def test_dpp_with_p2p_device(dev
, apdev
):
5002 """DPP exchange when driver uses a separate P2P Device interface"""
5003 check_dpp_capab(dev
[0])
5004 with
HWSimRadio(use_p2p_device
=True) as (radio
, iface
):
5005 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
5006 wpas
.interface_add(iface
)
5007 check_dpp_capab(wpas
)
5008 id1
= wpas
.dpp_bootstrap_gen(chan
="81/1", mac
=True)
5009 uri1
= wpas
.request("DPP_BOOTSTRAP_GET_URI %d" % id1
)
5010 wpas
.dpp_listen(2412)
5012 dev
[0].dpp_auth_init(uri
=uri1
)
5013 wait_auth_success(wpas
, dev
[0], configurator
=dev
[0], enrollee
=wpas
,
5014 allow_enrollee_failure
=True)