]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_dpp.py
tests: DPP QR Code and enrollee initiating with netrole specified
[thirdparty/hostap.git] / tests / hwsim / test_dpp.py
CommitLineData
d350084d
JM
1# Test cases for Device Provisioning Protocol (DPP)
2# Copyright (c) 2017, Qualcomm Atheros, Inc.
009b54be 3# Copyright (c) 2018-2019, The Linux Foundation
d350084d
JM
4#
5# This software may be distributed under the terms of the BSD license.
6# See README for more details.
7
30dda44d 8import base64
fd1534a2
JM
9import binascii
10import hashlib
d350084d
JM
11import logging
12logger = logging.getLogger()
7010f4be 13import os
b4928ff9 14import socket
fd1534a2 15import struct
4370ffc0 16import subprocess
d350084d
JM
17import time
18
19import hostapd
bbb42bf0 20import hwsim_utils
f94e677d 21from hwsim import HWSimRadio
818e3c94 22from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
ee8ef9ca 23from wpasupplicant import WpaSupplicant
4e9bcdeb 24from wlantest import WlantestCapture
d350084d 25
fd1534a2
JM
26try:
27 import OpenSSL
28 openssl_imported = True
29except ImportError:
30 openssl_imported = False
31
009b54be 32def check_dpp_capab(dev, brainpool=False, min_ver=1):
d350084d
JM
33 if "UNKNOWN COMMAND" in dev.request("DPP_BOOTSTRAP_GET_URI 0"):
34 raise HwsimSkip("DPP not supported")
d584946e
JM
35 if brainpool:
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)
8b6c834f 39 capa = dev.request("GET_CAPABILITY dpp")
009b54be 40 ver = 1
8b6c834f 41 if capa.startswith("DPP="):
009b54be
JM
42 ver = int(capa[4:])
43 if ver < min_ver:
44 raise HwsimSkip("DPP version %d not supported" % min_ver)
45 return ver
d350084d 46
203878d7
JM
47def wait_dpp_fail(dev, expected=None):
48 ev = dev.wait_event(["DPP-FAIL"], timeout=5)
49 if ev is None:
50 raise Exception("Failure not reported")
51 if expected and expected not in ev:
52 raise Exception("Unexpected result: " + ev)
53
d350084d
JM
54def test_dpp_qr_code_parsing(dev, apdev):
55 """DPP QR Code parsing"""
56 check_dpp_capab(dev[0])
57 id = []
58
fab49f61
JM
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=;;",
35814134
JM
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=;;",
fab49f61
JM
63 "DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
64 "DPP:I:;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;"]
d350084d 65 for uri in tests:
0422d06b 66 id.append(dev[0].dpp_qr_code(uri))
d350084d
JM
67
68 uri2 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id[-1])
69 if uri != uri2:
70 raise Exception("Returned URI does not match")
71
fab49f61
JM
72 tests = ["foo",
73 "DPP:",
74 "DPP:;;",
75 "DPP:C:1/2;M:;K;;",
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=;;"]
d350084d
JM
86 for t in tests:
87 res = dev[0].request("DPP_QR_CODE " + t)
88 if "FAIL" not in res:
89 raise Exception("Accepted invalid QR Code: " + t)
90
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")
94
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")
99
a5387062
JM
100 id = dev[0].dpp_bootstrap_gen()
101 uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
d350084d
JM
102 logger.info("Generated URI: " + uri)
103
0422d06b 104 dev[0].dpp_qr_code(uri)
d350084d 105
a5387062
JM
106 id = dev[0].dpp_bootstrap_gen(chan="81/1,115/36", mac="010203040506",
107 info="foo")
108 uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
d350084d
JM
109 logger.info("Generated URI: " + uri)
110
0422d06b 111 dev[0].dpp_qr_code(uri)
d350084d 112
d16be03b
JM
113def 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")
119
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")
123
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")
127
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")
131
fab49f61 132dpp_key_p256 = "30570201010420777fc55dc51e967c10ec051b91d860b5f1e6c934e48d5daffef98d032c64b170a00a06082a8648ce3d030107a124032200020c804188c7f85beb6e91070d2b3e5e39b90ca77b4d3c5251bc1844d6ca29dcad"
35818d3e
JM
133dpp_key_p384 = "307402010104302f56fdd83b5345cacb630eb7c22fa5ad5daba37307c95191e2a75756d137003bd8b32dbcb00eb5650c1eb499ecfcaec0a00706052b81040022a13403320003615ec2141b5b77aebb6523f8a012755f9a34405a8398d2ceeeebca7f5ce868bf55056cba4c4ec62fad3ed26dd29e0f23"
134dpp_key_p521 = "308198020101044200c8010d5357204c252551aaf4e210343111e503fd1dc615b257058997c49b6b643c975226e93be8181cca3d83a7072defd161dfbdf433c19abe1f2ad51867a05761a00706052b81040023a1460344000301cdf3608b1305fe34a1f976095dcf001182b9973354efe156291a66830292f9babd8f412ad462958663e7a75d1d0610abdfc3dd95d40669f7ab3bc001668cfb3b7c"
135dpp_key_bp256 = "3058020101042057133a676fb60bf2a3e6797e19833c7b0f89dc192ab99ab5fa377ae23a157765a00b06092b2403030208010107a12403220002945d9bf7ce30c9c1ac0ff21ca62b984d5bb80ff69d2be8c9716ab39a10d2caf0"
136dpp_key_bp384 = "307802010104304902df9f3033a9b7128554c0851dc7127c3573eed150671dae74c0013e9896a9b1c22b6f7d43d8a2ebb7cd474dc55039a00b06092b240303020801010ba13403320003623cb5e68787f351faababf3425161571560add2e6f9a306fcbffb507735bf955bb46dd20ba246b0d5cadce73e5bd6a6"
137dpp_key_bp512 = "30819802010104405803494226eb7e50bf0e90633f37e7e35d33f5fa502165eeba721d927f9f846caf12e925701d18e123abaaaf4a7edb4fc4de21ce18bc10c4d12e8b3439f74e40a00b06092b240303020801010da144034200033b086ccd47486522d35dc16fbb2229642c2e9e87897d45abbf21f9fb52acb5a6272b31d1b227c3e53720769cc16b4cb181b26cd0d35fe463218aaedf3b6ec00a"
138
139def test_dpp_qr_code_curves(dev, apdev):
140 """DPP QR Code and supported curves"""
141 check_dpp_capab(dev[0])
fab49f61
JM
142 tests = [("prime256v1", dpp_key_p256),
143 ("secp384r1", dpp_key_p384),
144 ("secp521r1", dpp_key_p521)]
35818d3e 145 for curve, hex in tests:
a5387062
JM
146 id = dev[0].dpp_bootstrap_gen(key=hex)
147 info = dev[0].request("DPP_BOOTSTRAP_INFO %d" % id)
35818d3e
JM
148 if "FAIL" in info:
149 raise Exception("Failed to get info for " + curve)
150 if "curve=" + curve not in info:
151 raise Exception("Curve mismatch for " + curve)
152
153def test_dpp_qr_code_curves_brainpool(dev, apdev):
154 """DPP QR Code and supported Brainpool curves"""
155 check_dpp_capab(dev[0], brainpool=True)
fab49f61
JM
156 tests = [("brainpoolP256r1", dpp_key_bp256),
157 ("brainpoolP384r1", dpp_key_bp384),
158 ("brainpoolP512r1", dpp_key_bp512)]
35818d3e 159 for curve, hex in tests:
a5387062
JM
160 id = dev[0].dpp_bootstrap_gen(key=hex)
161 info = dev[0].request("DPP_BOOTSTRAP_INFO %d" % id)
35818d3e
JM
162 if "FAIL" in info:
163 raise Exception("Failed to get info for " + curve)
164 if "curve=" + curve not in info:
165 raise Exception("Curve mismatch for " + curve)
166
e9bca5b8
JM
167def test_dpp_qr_code_unsupported_curve(dev, apdev):
168 """DPP QR Code and unsupported curve"""
169 check_dpp_capab(dev[0])
170
171 id = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode curve=unsupported")
172 if "FAIL" not in id:
173 raise Exception("Unsupported curve accepted")
174
fab49f61
JM
175 tests = ["30",
176 "305f02010104187f723ed9e1b41979ec5cd02eb82696efc76b40e277661049a00a06082a8648ce3d030101a134033200043f292614dea97c43f500f069e79ae9fb48f8b07369180de5eec8fa2bc9eea5af7a46dc335f52f10cb1c0e9464201d41b"]
e9bca5b8
JM
177 for hex in tests:
178 id = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode key=" + hex)
179 if "FAIL" not in id:
180 raise Exception("Unsupported/invalid curve accepted")
181
545bf954
JM
182def test_dpp_qr_code_keygen_fail(dev, apdev):
183 """DPP QR Code and keygen failure"""
184 check_dpp_capab(dev[0])
185
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")
189
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")
193
35818d3e
JM
194def 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)
198
35818d3e 199 bi = []
fab49f61
JM
200 for key in [dpp_key_p256, dpp_key_p384, dpp_key_p521,
201 dpp_key_bp256, dpp_key_bp384, dpp_key_bp512]:
a5387062
JM
202 id = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True, key=key)
203 info = dev[0].request("DPP_BOOTSTRAP_INFO %d" % id)
35818d3e
JM
204 for i in info.splitlines():
205 if '=' in i:
206 name, val = i.split('=')
207 if name == "curve":
208 curve = val
209 break
a5387062 210 uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
35818d3e
JM
211 bi.append((curve, uri))
212
213 for curve, uri in bi:
214 logger.info("Curve: " + curve)
215 logger.info("URI: " + uri)
216
7e009100 217 dev[0].dpp_listen(2412)
5725b3e3 218 dev[1].dpp_auth_init(uri=uri)
517f76b1
JM
219 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0],
220 allow_enrollee_failure=True, stop_responder=True,
221 stop_initiator=True)
35818d3e 222
d350084d
JM
223def 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")
a5387062 228 id0 = dev[0].dpp_bootstrap_gen(chan="81/1")
d350084d 229 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
5725b3e3 230 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 231 dev[0].dpp_listen(2412)
5725b3e3 232 dev[1].dpp_auth_init(uri=uri0)
517f76b1 233 wait_auth_success(dev[0], dev[1], stop_responder=True)
d350084d
JM
234
235def 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)
238
239def 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")
242
12cdfb4d
JM
243def run_dpp_configurator_enrollee(dev, apdev, conf_curve=None):
244 run_dpp_qr_code_auth_unicast(dev, apdev, None, netrole="configurator",
3e4b709f
JM
245 configurator=True, conf_curve=conf_curve,
246 conf="configurator")
12cdfb4d
JM
247 ev = dev[0].wait_event(["DPP-CONFIGURATOR-ID"], timeout=2)
248 if ev is None:
249 raise Exception("No Configurator instance added")
250
251def test_dpp_configurator_enrollee(dev, apdev):
252 """DPP Configurator enrolling"""
253 run_dpp_configurator_enrollee(dev, apdev)
254
255def test_dpp_configurator_enrollee_prime256v1(dev, apdev):
256 """DPP Configurator enrolling (prime256v1)"""
257 run_dpp_configurator_enrollee(dev, apdev, conf_curve="prime256v1")
258
259def test_dpp_configurator_enrollee_secp384r1(dev, apdev):
260 """DPP Configurator enrolling (secp384r1)"""
261 run_dpp_configurator_enrollee(dev, apdev, conf_curve="secp384r1")
262
263def test_dpp_configurator_enrollee_secp521r1(dev, apdev):
264 """DPP Configurator enrolling (secp521r1)"""
265 run_dpp_configurator_enrollee(dev, apdev, conf_curve="secp521r1")
266
267def test_dpp_configurator_enrollee_brainpoolP256r1(dev, apdev):
268 """DPP Configurator enrolling (brainpoolP256r1)"""
269 run_dpp_configurator_enrollee(dev, apdev, conf_curve="brainpoolP256r1")
270
271def test_dpp_configurator_enrollee_brainpoolP384r1(dev, apdev):
272 """DPP Configurator enrolling (brainpoolP384r1)"""
273 run_dpp_configurator_enrollee(dev, apdev, conf_curve="brainpoolP384r1")
274
275def test_dpp_configurator_enrollee_brainpoolP512r1(dev, apdev):
276 """DPP Configurator enrolling (brainpoolP512r1)"""
277 run_dpp_configurator_enrollee(dev, apdev, conf_curve="brainpoolP512r1")
278
d350084d
JM
279def test_dpp_qr_code_curve_prime256v1(dev, apdev):
280 """DPP QR Code and curve prime256v1"""
281 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1")
282
283def test_dpp_qr_code_curve_secp384r1(dev, apdev):
284 """DPP QR Code and curve secp384r1"""
285 run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1")
286
287def test_dpp_qr_code_curve_secp521r1(dev, apdev):
288 """DPP QR Code and curve secp521r1"""
289 run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1")
290
291def test_dpp_qr_code_curve_brainpoolP256r1(dev, apdev):
292 """DPP QR Code and curve brainpoolP256r1"""
293 run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP256r1")
294
295def test_dpp_qr_code_curve_brainpoolP384r1(dev, apdev):
296 """DPP QR Code and curve brainpoolP384r1"""
297 run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP384r1")
298
299def test_dpp_qr_code_curve_brainpoolP512r1(dev, apdev):
300 """DPP QR Code and curve brainpoolP512r1"""
301 run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP512r1")
302
303def test_dpp_qr_code_set_key(dev, apdev):
304 """DPP QR Code and fixed bootstrapping key"""
305 run_dpp_qr_code_auth_unicast(dev, apdev, None, key="30770201010420e5143ac74682cc6869a830e8f5301a5fa569130ac329b1d7dd6f2a7495dbcbe1a00a06082a8648ce3d030107a144034200045e13e167c33dbc7d85541e5509600aa8139bbb3e39e25898992c5d01be92039ee2850f17e71506ded0d6b25677441eae249f8e225c68dd15a6354dca54006383")
306
307def run_dpp_qr_code_auth_unicast(dev, apdev, curve, netrole=None, key=None,
308 require_conf_success=False, init_extra=None,
309 require_conf_failure=False,
3e4b709f
JM
310 configurator=False, conf_curve=None,
311 conf=None):
d584946e
JM
312 check_dpp_capab(dev[0], curve and "brainpool" in curve)
313 check_dpp_capab(dev[1], curve and "brainpool" in curve)
d350084d 314 if configurator:
e105110f 315 conf_id = dev[1].dpp_configurator_add(curve=conf_curve)
5725b3e3
JM
316 else:
317 conf_id = None
d350084d
JM
318
319 logger.info("dev0 displays QR Code")
a5387062 320 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True, curve=curve, key=key)
d350084d
JM
321 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
322
5725b3e3 323 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 324 dev[0].dpp_listen(2412, netrole=netrole)
3e4b709f
JM
325 dev[1].dpp_auth_init(uri=uri0, extra=init_extra, configurator=conf_id,
326 conf=conf)
517f76b1
JM
327 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0],
328 allow_enrollee_failure=True,
329 allow_configurator_failure=not require_conf_success,
330 require_configurator_failure=require_conf_failure,
331 stop_responder=True)
d350084d
JM
332
333def test_dpp_qr_code_auth_mutual(dev, apdev):
334 """DPP QR Code and authentication exchange (mutual)"""
335 check_dpp_capab(dev[0])
336 check_dpp_capab(dev[1])
337 logger.info("dev0 displays QR Code")
a5387062 338 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
d350084d
JM
339 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
340
d350084d 341 logger.info("dev1 displays QR Code")
a5387062 342 id1b = dev[1].dpp_bootstrap_gen(chan="81/1", mac=True)
d350084d
JM
343 uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
344
345 logger.info("dev0 scans QR Code")
0422d06b 346 id0b = dev[0].dpp_qr_code(uri1b)
d350084d 347
5725b3e3 348 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 349 dev[0].dpp_listen(2412)
5725b3e3 350 dev[1].dpp_auth_init(uri=uri0, own=id1b)
41dafe0c
JM
351
352 ev = dev[1].wait_event(["DPP-AUTH-DIRECTION"], timeout=5)
353 if ev is None:
354 raise Exception("DPP authentication direction not indicated (Initiator)")
355 if "mutual=1" not in ev:
356 raise Exception("Mutual authentication not used")
357
517f76b1 358 wait_auth_success(dev[0], dev[1], stop_responder=True)
d350084d
JM
359
360def test_dpp_qr_code_auth_mutual2(dev, apdev):
361 """DPP QR Code and authentication exchange (mutual2)"""
362 check_dpp_capab(dev[0])
363 check_dpp_capab(dev[1])
364 logger.info("dev0 displays QR Code")
a5387062 365 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
d350084d
JM
366 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
367
d350084d 368 logger.info("dev1 displays QR Code")
a5387062 369 id1b = dev[1].dpp_bootstrap_gen(chan="81/1", mac=True)
d350084d
JM
370 uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
371
5725b3e3 372 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 373 dev[0].dpp_listen(2412, qr="mutual")
5725b3e3 374 dev[1].dpp_auth_init(uri=uri0, own=id1b)
d350084d
JM
375
376 ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
377 if ev is None:
378 raise Exception("Pending response not reported")
379 ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
380 if ev is None:
381 raise Exception("QR Code scan for mutual authentication not requested")
382
383 logger.info("dev0 scans QR Code")
0422d06b 384 id0b = dev[0].dpp_qr_code(uri1b)
d350084d 385
41dafe0c
JM
386 ev = dev[1].wait_event(["DPP-AUTH-DIRECTION"], timeout=5)
387 if ev is None:
388 raise Exception("DPP authentication direction not indicated (Initiator)")
389 if "mutual=1" not in ev:
390 raise Exception("Mutual authentication not used")
391
517f76b1 392 wait_auth_success(dev[0], dev[1], stop_responder=True)
d350084d 393
cdef4e91
JM
394def test_dpp_qr_code_auth_mutual_p_256(dev, apdev):
395 """DPP QR Code and authentication exchange (mutual, autogen P-256)"""
396 run_dpp_qr_code_auth_mutual(dev, apdev, "P-256")
397
398def test_dpp_qr_code_auth_mutual_p_384(dev, apdev):
399 """DPP QR Code and authentication exchange (mutual, autogen P-384)"""
400 run_dpp_qr_code_auth_mutual(dev, apdev, "P-384")
401
402def test_dpp_qr_code_auth_mutual_p_521(dev, apdev):
403 """DPP QR Code and authentication exchange (mutual, autogen P-521)"""
404 run_dpp_qr_code_auth_mutual(dev, apdev, "P-521")
405
406def test_dpp_qr_code_auth_mutual_bp_256(dev, apdev):
407 """DPP QR Code and authentication exchange (mutual, autogen BP-256)"""
408 run_dpp_qr_code_auth_mutual(dev, apdev, "BP-256")
409
410def test_dpp_qr_code_auth_mutual_bp_384(dev, apdev):
411 """DPP QR Code and authentication exchange (mutual, autogen BP-384)"""
412 run_dpp_qr_code_auth_mutual(dev, apdev, "BP-384")
413
414def test_dpp_qr_code_auth_mutual_bp_512(dev, apdev):
415 """DPP QR Code and authentication exchange (mutual, autogen BP-512)"""
416 run_dpp_qr_code_auth_mutual(dev, apdev, "BP-512")
417
418def run_dpp_qr_code_auth_mutual(dev, apdev, curve):
419 check_dpp_capab(dev[0], curve and "BP-" in curve)
420 check_dpp_capab(dev[1], curve and "BP-" in curve)
421 logger.info("dev0 displays QR Code")
a5387062 422 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True, curve=curve)
cdef4e91 423 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
5725b3e3 424 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 425 dev[0].dpp_listen(2412, qr="mutual")
5725b3e3 426 dev[1].dpp_auth_init(uri=uri0)
cdef4e91
JM
427
428 ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
429 if ev is None:
430 raise Exception("Pending response not reported")
431 uri = ev.split(' ')[1]
432
433 ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
434 if ev is None:
435 raise Exception("QR Code scan for mutual authentication not requested")
436
437 logger.info("dev0 scans QR Code")
0422d06b 438 dev[0].dpp_qr_code(uri)
cdef4e91 439
41dafe0c
JM
440 ev = dev[1].wait_event(["DPP-AUTH-DIRECTION"], timeout=5)
441 if ev is None:
442 raise Exception("DPP authentication direction not indicated (Initiator)")
443 if "mutual=1" not in ev:
444 raise Exception("Mutual authentication not used")
445
517f76b1 446 wait_auth_success(dev[0], dev[1], stop_responder=True)
cdef4e91 447
ba37ba41
JM
448def test_dpp_auth_resp_retries(dev, apdev):
449 """DPP Authentication Response retries"""
450 check_dpp_capab(dev[0])
451 check_dpp_capab(dev[1])
452 dev[0].set("dpp_resp_max_tries", "3")
453 dev[0].set("dpp_resp_retry_time", "100")
454
455 logger.info("dev0 displays QR Code")
a5387062 456 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
ba37ba41 457 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
ba37ba41 458 logger.info("dev1 displays QR Code")
a5387062 459 id1b = dev[1].dpp_bootstrap_gen(chan="81/1", mac=True)
ba37ba41 460 uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
5725b3e3 461 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 462 dev[0].dpp_listen(2412, qr="mutual")
5725b3e3 463 dev[1].dpp_auth_init(uri=uri0, own=id1b)
ba37ba41
JM
464
465 ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
466 if ev is None:
467 raise Exception("Pending response not reported")
468 ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
469 if ev is None:
470 raise Exception("QR Code scan for mutual authentication not requested")
471
472 # Stop Initiator from listening to frames to force retransmission of the
473 # DPP Authentication Response frame with Status=0
474 dev[1].request("DPP_STOP_LISTEN")
475
476 dev[1].dump_monitor()
477 dev[0].dump_monitor()
478
479 logger.info("dev0 scans QR Code")
0422d06b 480 id0b = dev[0].dpp_qr_code(uri1b)
ba37ba41 481
dbdd445d 482 ev = dev[0].wait_event(["DPP-TX "], timeout=5)
ba37ba41
JM
483 if ev is None or "type=1" not in ev:
484 raise Exception("DPP Authentication Response not sent")
485 ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=5)
486 if ev is None:
487 raise Exception("TX status for DPP Authentication Response not reported")
488 if "result=no-ACK" not in ev:
489 raise Exception("Unexpected TX status for Authentication Response: " + ev)
490
dbdd445d 491 ev = dev[0].wait_event(["DPP-TX "], timeout=15)
ba37ba41
JM
492 if ev is None or "type=1" not in ev:
493 raise Exception("DPP Authentication Response retransmission not sent")
494
f7380b47
JM
495def test_dpp_qr_code_auth_mutual_not_used(dev, apdev):
496 """DPP QR Code and authentication exchange (mutual not used)"""
497 check_dpp_capab(dev[0])
498 check_dpp_capab(dev[1])
499 logger.info("dev0 displays QR Code")
a5387062 500 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
f7380b47 501 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
f7380b47 502 logger.info("dev1 displays QR Code")
a5387062 503 id1b = dev[1].dpp_bootstrap_gen(chan="81/1", mac=True)
f7380b47 504 uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
f7380b47 505 logger.info("dev0 does not scan QR Code")
5725b3e3 506 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 507 dev[0].dpp_listen(2412)
5725b3e3 508 dev[1].dpp_auth_init(uri=uri0, own=id1b)
41dafe0c
JM
509
510 ev = dev[1].wait_event(["DPP-AUTH-DIRECTION"], timeout=5)
511 if ev is None:
512 raise Exception("DPP authentication direction not indicated (Initiator)")
513 if "mutual=0" not in ev:
514 raise Exception("Mutual authentication not used")
515
517f76b1 516 wait_auth_success(dev[0], dev[1], stop_responder=True)
f7380b47 517
d350084d
JM
518def test_dpp_qr_code_auth_mutual_curve_mismatch(dev, apdev):
519 """DPP QR Code and authentication exchange (mutual/mismatch)"""
520 check_dpp_capab(dev[0])
521 check_dpp_capab(dev[1])
522 logger.info("dev0 displays QR Code")
a5387062 523 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
d350084d 524 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
d350084d 525 logger.info("dev1 displays QR Code")
a5387062 526 id1b = dev[1].dpp_bootstrap_gen(chan="81/1", mac=True, curve="secp384r1")
d350084d 527 uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
d350084d 528 logger.info("dev0 scans QR Code")
0422d06b 529 id0b = dev[0].dpp_qr_code(uri1b)
5725b3e3
JM
530 logger.info("dev1 scans QR Code")
531 dev[1].dpp_auth_init(uri=uri0, own=id1b, expect_fail=True)
d350084d 532
efa77d0a
JM
533def test_dpp_qr_code_auth_hostapd_mutual2(dev, apdev):
534 """DPP QR Code and authentication exchange (hostapd mutual2)"""
535 check_dpp_capab(dev[0])
fab49f61 536 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
efa77d0a 537 check_dpp_capab(hapd)
efa77d0a 538 logger.info("AP displays QR Code")
a5387062 539 id_h = hapd.dpp_bootstrap_gen(chan="81/1", mac=True)
efa77d0a 540 uri_h = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
efa77d0a 541 logger.info("dev0 displays QR Code")
a5387062 542 id0b = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
efa77d0a 543 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0b)
5725b3e3 544 logger.info("dev0 scans QR Code and initiates DPP Authentication")
7e009100 545 hapd.dpp_listen(2412, qr="mutual")
5725b3e3 546 dev[0].dpp_auth_init(uri=uri_h, own=id0b)
efa77d0a
JM
547
548 ev = dev[0].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
549 if ev is None:
550 raise Exception("Pending response not reported")
551 ev = hapd.wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
552 if ev is None:
553 raise Exception("QR Code scan for mutual authentication not requested")
554
555 logger.info("AP scans QR Code")
0422d06b 556 hapd.dpp_qr_code(uri0)
efa77d0a 557
517f76b1 558 wait_auth_success(hapd, dev[0], stop_responder=True)
efa77d0a 559
d350084d
JM
560def test_dpp_qr_code_listen_continue(dev, apdev):
561 """DPP QR Code and listen operation needing continuation"""
562 check_dpp_capab(dev[0])
563 check_dpp_capab(dev[1])
564 logger.info("dev0 displays QR Code")
a5387062 565 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
d350084d 566 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
7e009100 567 dev[0].dpp_listen(2412)
d350084d
JM
568 logger.info("Wait for listen to expire and get restarted")
569 time.sleep(5.5)
5725b3e3
JM
570 logger.info("dev1 scans QR Code and initiates DPP Authentication")
571 dev[1].dpp_auth_init(uri=uri0)
517f76b1 572 wait_auth_success(dev[0], dev[1], stop_responder=True)
d350084d
JM
573
574def test_dpp_qr_code_auth_initiator_enrollee(dev, apdev):
575 """DPP QR Code and authentication exchange (Initiator in Enrollee role)"""
f77d1062
JM
576 try:
577 run_dpp_qr_code_auth_initiator_enrollee(dev, apdev)
578 finally:
579 dev[0].set("gas_address3", "0")
580 dev[1].set("gas_address3", "0")
581
582def run_dpp_qr_code_auth_initiator_enrollee(dev, apdev):
d350084d
JM
583 check_dpp_capab(dev[0])
584 check_dpp_capab(dev[1])
585 dev[0].request("SET gas_address3 1")
586 dev[1].request("SET gas_address3 1")
587 logger.info("dev0 displays QR Code")
a5387062 588 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
d350084d 589 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
5725b3e3 590 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 591 dev[0].dpp_listen(2412)
5725b3e3 592 dev[1].dpp_auth_init(uri=uri0, role="enrollee")
517f76b1
JM
593 wait_auth_success(dev[0], dev[1], configurator=dev[0], enrollee=dev[1],
594 allow_enrollee_failure=True, stop_responder=True)
d350084d 595
51fbcad4
JM
596def test_dpp_qr_code_auth_initiator_either_1(dev, apdev):
597 """DPP QR Code and authentication exchange (Initiator in either role)"""
598 run_dpp_qr_code_auth_initiator_either(dev, apdev, None, dev[1], dev[0])
599
600def test_dpp_qr_code_auth_initiator_either_2(dev, apdev):
601 """DPP QR Code and authentication exchange (Initiator in either role)"""
602 run_dpp_qr_code_auth_initiator_either(dev, apdev, "enrollee",
603 dev[1], dev[0])
604
605def test_dpp_qr_code_auth_initiator_either_3(dev, apdev):
606 """DPP QR Code and authentication exchange (Initiator in either role)"""
607 run_dpp_qr_code_auth_initiator_either(dev, apdev, "configurator",
608 dev[0], dev[1])
609
610def run_dpp_qr_code_auth_initiator_either(dev, apdev, resp_role,
611 conf_dev, enrollee_dev):
612 check_dpp_capab(dev[0])
613 check_dpp_capab(dev[1])
614 logger.info("dev0 displays QR Code")
a5387062 615 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
51fbcad4 616 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
5725b3e3 617 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 618 dev[0].dpp_listen(2412, role=resp_role)
5725b3e3 619 dev[1].dpp_auth_init(uri=uri0, role="either")
517f76b1
JM
620 wait_auth_success(dev[0], dev[1], configurator=conf_dev,
621 enrollee=enrollee_dev, allow_enrollee_failure=True,
622 stop_responder=True)
51fbcad4 623
3710b58d 624def run_init_incompatible_roles(dev, role="enrollee"):
d350084d
JM
625 check_dpp_capab(dev[0])
626 check_dpp_capab(dev[1])
627 logger.info("dev0 displays QR Code")
a5387062 628 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
d350084d
JM
629 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
630
631 logger.info("dev1 scans QR Code")
0422d06b 632 id1 = dev[1].dpp_qr_code(uri0)
d350084d
JM
633
634 logger.info("dev1 initiates DPP Authentication")
7e009100 635 dev[0].dpp_listen(2412, role=role)
3710b58d
JM
636 return id1
637
638def test_dpp_qr_code_auth_incompatible_roles(dev, apdev):
639 """DPP QR Code and authentication exchange (incompatible roles)"""
640 id1 = run_init_incompatible_roles(dev)
5725b3e3 641 dev[1].dpp_auth_init(peer=id1, role="enrollee")
d350084d
JM
642 ev = dev[1].wait_event(["DPP-NOT-COMPATIBLE"], timeout=5)
643 if ev is None:
644 raise Exception("DPP-NOT-COMPATIBLE event on initiator timed out")
645 ev = dev[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout=1)
646 if ev is None:
647 raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
5725b3e3 648 dev[1].dpp_auth_init(peer=id1, role="configurator")
517f76b1 649 wait_auth_success(dev[0], dev[1], stop_responder=True)
d350084d 650
3710b58d
JM
651def test_dpp_qr_code_auth_incompatible_roles2(dev, apdev):
652 """DPP QR Code and authentication exchange (incompatible roles 2)"""
653 id1 = run_init_incompatible_roles(dev, role="configurator")
5725b3e3 654 dev[1].dpp_auth_init(peer=id1, role="configurator")
3710b58d
JM
655 ev = dev[1].wait_event(["DPP-NOT-COMPATIBLE"], timeout=5)
656 if ev is None:
657 raise Exception("DPP-NOT-COMPATIBLE event on initiator timed out")
658 ev = dev[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout=1)
659 if ev is None:
660 raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
661
662def test_dpp_qr_code_auth_incompatible_roles_failure(dev, apdev):
663 """DPP QR Code and authentication exchange (incompatible roles failure)"""
664 id1 = run_init_incompatible_roles(dev, role="configurator")
665 with alloc_fail(dev[0], 1, "dpp_auth_build_resp_status"):
5725b3e3 666 dev[1].dpp_auth_init(peer=id1, role="configurator")
3710b58d
JM
667 ev = dev[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout=1)
668 if ev is None:
669 raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
670
671def test_dpp_qr_code_auth_incompatible_roles_failure2(dev, apdev):
672 """DPP QR Code and authentication exchange (incompatible roles failure 2)"""
673 id1 = run_init_incompatible_roles(dev, role="configurator")
674 with alloc_fail(dev[1], 1, "dpp_auth_resp_rx_status"):
5725b3e3 675 dev[1].dpp_auth_init(peer=id1, role="configurator")
3710b58d
JM
676 wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
677
678def test_dpp_qr_code_auth_incompatible_roles_failure3(dev, apdev):
679 """DPP QR Code and authentication exchange (incompatible roles failure 3)"""
680 id1 = run_init_incompatible_roles(dev, role="configurator")
681 with fail_test(dev[1], 1, "dpp_auth_resp_rx_status"):
5725b3e3 682 dev[1].dpp_auth_init(peer=id1, role="configurator")
203878d7 683 wait_dpp_fail(dev[1], "AES-SIV decryption failed")
3710b58d 684
13dc368a
JM
685def test_dpp_qr_code_auth_neg_chan(dev, apdev):
686 """DPP QR Code and authentication exchange with requested different channel"""
687 check_dpp_capab(dev[0])
688 check_dpp_capab(dev[1])
e105110f 689 conf_id = dev[1].dpp_configurator_add()
13dc368a 690 logger.info("dev0 displays QR Code")
a5387062 691 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
13dc368a 692 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
5725b3e3 693 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 694 dev[0].dpp_listen(2412)
5725b3e3
JM
695 dev[1].dpp_auth_init(uri=uri0, conf="sta-dpp", neg_freq=2462,
696 configurator=conf_id)
13dc368a 697
dbdd445d 698 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
13dc368a
JM
699 if ev is None:
700 raise Exception("DPP Authentication Request not sent")
701 if "freq=2412 type=0" not in ev:
702 raise Exception("Unexpected TX data for Authentication Request: " + ev)
703
704 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
705 if ev is None:
706 raise Exception("DPP Authentication Request not received")
707 if "freq=2412 type=0" not in ev:
708 raise Exception("Unexpected RX data for Authentication Request: " + ev)
709
710 ev = dev[1].wait_event(["DPP-TX-STATUS"], timeout=5)
711 if ev is None:
712 raise Exception("TX status for DPP Authentication Request not reported")
713 if "freq=2412 result=SUCCESS" not in ev:
714 raise Exception("Unexpected TX status for Authentication Request: " + ev)
715
dbdd445d 716 ev = dev[0].wait_event(["DPP-TX "], timeout=5)
13dc368a
JM
717 if ev is None:
718 raise Exception("DPP Authentication Response not sent")
719 if "freq=2462 type=1" not in ev:
720 raise Exception("Unexpected TX data for Authentication Response: " + ev)
721
722 ev = dev[1].wait_event(["DPP-RX"], timeout=5)
723 if ev is None:
724 raise Exception("DPP Authentication Response not received")
725 if "freq=2462 type=1" not in ev:
726 raise Exception("Unexpected RX data for Authentication Response: " + ev)
727
728 ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=5)
729 if ev is None:
730 raise Exception("TX status for DPP Authentication Response not reported")
731 if "freq=2462 result=SUCCESS" not in ev:
732 raise Exception("Unexpected TX status for Authentication Response: " + ev)
733
dbdd445d 734 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
13dc368a
JM
735 if ev is None:
736 raise Exception("DPP Authentication Confirm not sent")
737 if "freq=2462 type=2" not in ev:
738 raise Exception("Unexpected TX data for Authentication Confirm: " + ev)
739
740 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
741 if ev is None:
742 raise Exception("DPP Authentication Confirm not received")
743 if "freq=2462 type=2" not in ev:
744 raise Exception("Unexpected RX data for Authentication Confirm: " + ev)
745
746 ev = dev[1].wait_event(["DPP-TX-STATUS"], timeout=5)
747 if ev is None:
748 raise Exception("TX status for DPP Authentication Confirm not reported")
749 if "freq=2462 result=SUCCESS" not in ev:
750 raise Exception("Unexpected TX status for Authentication Confirm: " + ev)
751
517f76b1
JM
752 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0],
753 stop_responder=True)
13dc368a 754
d350084d
JM
755def test_dpp_config_legacy(dev, apdev):
756 """DPP Config Object for legacy network using passphrase"""
757 check_dpp_capab(dev[1])
758 conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}'
759 dev[1].set("dpp_config_obj_override", conf)
760 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
761 require_conf_success=True)
762
763def test_dpp_config_legacy_psk_hex(dev, apdev):
764 """DPP Config Object for legacy network using PSK"""
765 check_dpp_capab(dev[1])
766 conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"' + 32*"12" + '"}}'
767 dev[1].set("dpp_config_obj_override", conf)
768 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
769 require_conf_success=True)
770
771def test_dpp_config_fragmentation(dev, apdev):
772 """DPP Config Object for legacy network requiring fragmentation"""
773 check_dpp_capab(dev[1])
774 conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
775 dev[1].set("dpp_config_obj_override", conf)
776 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
777 require_conf_success=True)
778
779def test_dpp_config_legacy_gen(dev, apdev):
780 """Generate DPP Config Object for legacy network"""
781 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
54c58f29 782 init_extra="conf=sta-psk pass=%s" % binascii.hexlify(b"passphrase").decode(),
d350084d
JM
783 require_conf_success=True)
784
e6a6de29
JM
785def test_dpp_config_legacy_gen_psk(dev, apdev):
786 """Generate DPP Config Object for legacy network (PSK)"""
787 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
788 init_extra="conf=sta-psk psk=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
789 require_conf_success=True)
790
d350084d
JM
791def test_dpp_config_dpp_gen_prime256v1(dev, apdev):
792 """Generate DPP Config Object for DPP network (P-256)"""
793 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
794 init_extra="conf=sta-dpp",
795 require_conf_success=True,
796 configurator=True)
797
798def test_dpp_config_dpp_gen_secp384r1(dev, apdev):
799 """Generate DPP Config Object for DPP network (P-384)"""
800 run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
801 init_extra="conf=sta-dpp",
802 require_conf_success=True,
803 configurator=True)
804
805def test_dpp_config_dpp_gen_secp521r1(dev, apdev):
806 """Generate DPP Config Object for DPP network (P-521)"""
807 run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
808 init_extra="conf=sta-dpp",
809 require_conf_success=True,
810 configurator=True)
811
812def test_dpp_config_dpp_gen_prime256v1_prime256v1(dev, apdev):
813 """Generate DPP Config Object for DPP network (P-256 + P-256)"""
814 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
815 init_extra="conf=sta-dpp",
816 require_conf_success=True,
817 configurator=True,
818 conf_curve="prime256v1")
819
820def test_dpp_config_dpp_gen_prime256v1_secp384r1(dev, apdev):
821 """Generate DPP Config Object for DPP network (P-256 + P-384)"""
822 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
823 init_extra="conf=sta-dpp",
824 require_conf_success=True,
825 configurator=True,
826 conf_curve="secp384r1")
827
828def test_dpp_config_dpp_gen_prime256v1_secp521r1(dev, apdev):
829 """Generate DPP Config Object for DPP network (P-256 + P-521)"""
830 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
831 init_extra="conf=sta-dpp",
832 require_conf_success=True,
833 configurator=True,
834 conf_curve="secp521r1")
835
836def test_dpp_config_dpp_gen_secp384r1_prime256v1(dev, apdev):
837 """Generate DPP Config Object for DPP network (P-384 + P-256)"""
838 run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
839 init_extra="conf=sta-dpp",
840 require_conf_success=True,
841 configurator=True,
842 conf_curve="prime256v1")
843
844def test_dpp_config_dpp_gen_secp384r1_secp384r1(dev, apdev):
845 """Generate DPP Config Object for DPP network (P-384 + P-384)"""
846 run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
847 init_extra="conf=sta-dpp",
848 require_conf_success=True,
849 configurator=True,
850 conf_curve="secp384r1")
851
852def test_dpp_config_dpp_gen_secp384r1_secp521r1(dev, apdev):
853 """Generate DPP Config Object for DPP network (P-384 + P-521)"""
854 run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
855 init_extra="conf=sta-dpp",
856 require_conf_success=True,
857 configurator=True,
858 conf_curve="secp521r1")
859
860def test_dpp_config_dpp_gen_secp521r1_prime256v1(dev, apdev):
861 """Generate DPP Config Object for DPP network (P-521 + P-256)"""
862 run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
863 init_extra="conf=sta-dpp",
864 require_conf_success=True,
865 configurator=True,
866 conf_curve="prime256v1")
867
868def test_dpp_config_dpp_gen_secp521r1_secp384r1(dev, apdev):
869 """Generate DPP Config Object for DPP network (P-521 + P-384)"""
870 run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
871 init_extra="conf=sta-dpp",
872 require_conf_success=True,
873 configurator=True,
874 conf_curve="secp384r1")
875
876def test_dpp_config_dpp_gen_secp521r1_secp521r1(dev, apdev):
877 """Generate DPP Config Object for DPP network (P-521 + P-521)"""
878 run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
879 init_extra="conf=sta-dpp",
880 require_conf_success=True,
881 configurator=True,
882 conf_curve="secp521r1")
883
884def test_dpp_config_dpp_gen_expiry(dev, apdev):
885 """Generate DPP Config Object for DPP network with expiry value"""
886 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
887 init_extra="conf=sta-dpp expiry=%d" % (time.time() + 1000),
888 require_conf_success=True,
889 configurator=True)
890
891def test_dpp_config_dpp_gen_expired_key(dev, apdev):
892 """Generate DPP Config Object for DPP network with expiry value"""
893 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
894 init_extra="conf=sta-dpp expiry=%d" % (time.time() - 10),
895 require_conf_failure=True,
896 configurator=True)
897
898def test_dpp_config_dpp_override_prime256v1(dev, apdev):
899 """DPP Config Object override (P-256)"""
900 check_dpp_capab(dev[0])
901 check_dpp_capab(dev[1])
902 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"}}}'
903 dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
904 dev[1].set("dpp_config_obj_override", conf)
905 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
906 require_conf_success=True)
907
908def test_dpp_config_dpp_override_secp384r1(dev, apdev):
909 """DPP Config Object override (P-384)"""
910 check_dpp_capab(dev[0])
911 check_dpp_capab(dev[1])
912 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"}}}'
913 dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
914 dev[1].set("dpp_config_obj_override", conf)
915 run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
916 require_conf_success=True)
917
918def test_dpp_config_dpp_override_secp521r1(dev, apdev):
919 """DPP Config Object override (P-521)"""
920 check_dpp_capab(dev[0])
921 check_dpp_capab(dev[1])
922 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"}}}'
923 dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
924 dev[1].set("dpp_config_obj_override", conf)
925 run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
926 require_conf_success=True)
927
928def test_dpp_config_override_objects(dev, apdev):
929 """Generate DPP Config Object and override objects)"""
930 check_dpp_capab(dev[1])
2e37b5fb 931 discovery = '{\n"ssid":"mywifi"\n}'
d350084d 932 groups = '[\n {"groupId":"home","netRole":"sta"},\n {"groupId":"cottage","netRole":"sta"}\n]'
d350084d
JM
933 dev[1].set("dpp_discovery_override", discovery)
934 dev[1].set("dpp_groups_override", groups)
d350084d
JM
935 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
936 init_extra="conf=sta-dpp",
937 require_conf_success=True,
938 configurator=True)
939
30dda44d
JM
940def build_conf_obj(kty="EC", crv="P-256",
941 x="W4-Y5N1Pkos3UWb9A5qme0KUYRtY3CVUpekx_MapZ9s",
942 y="Et-M4NSF4NGjvh2VCh4B1sJ9eSCZ4RNzP2DBdP137VE",
943 kid="TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU",
944 prot_hdr='{"typ":"dppCon","kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU","alg":"ES256"}',
945 signed_connector=None,
946 no_signed_connector=False,
947 csign=True):
948 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{'
949 conf += '"akm":"dpp",'
950
951 if signed_connector:
952 conn = signed_connector
953 conf += '"signedConnector":"%s",' % conn
954 elif not no_signed_connector:
955 payload = '{"groups":[{"groupId":"*","netRole":"sta"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
956 sign = "_sm6YswxMf6hJLVTyYoU1uYUeY2VVkUNjrzjSiEhY42StD_RWowStEE-9CRsdCvLmsTptZ72_g40vTFwdId20A"
c4e333fa
MH
957 conn = base64.urlsafe_b64encode(prot_hdr.encode()).decode().rstrip('=') + '.'
958 conn += base64.urlsafe_b64encode(payload.encode()).decode().rstrip('=') + '.'
30dda44d
JM
959 conn += sign
960 conf += '"signedConnector":"%s",' % conn
961
962 if csign:
963 conf += '"csign":{'
964 if kty:
965 conf += '"kty":"%s",' % kty
966 if crv:
967 conf += '"crv":"%s",' % crv
968 if x:
969 conf += '"x":"%s",' % x
970 if y:
971 conf += '"y":"%s",' % y
972 if kid:
973 conf += '"kid":"%s"' % kid
974 conf = conf.rstrip(',')
975 conf += '}'
976 else:
977 conf = conf.rstrip(',')
978
979 conf += '}}'
980
981 return conf
982
fd1534a2 983def run_dpp_config_error(dev, apdev, conf,
530b31ea
JM
984 skip_net_access_key_mismatch=True,
985 conf_failure=True):
30dda44d
JM
986 check_dpp_capab(dev[0])
987 check_dpp_capab(dev[1])
fd1534a2
JM
988 if skip_net_access_key_mismatch:
989 dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
30dda44d
JM
990 dev[1].set("dpp_config_obj_override", conf)
991 run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
530b31ea
JM
992 require_conf_success=not conf_failure,
993 require_conf_failure=conf_failure)
30dda44d
JM
994
995def test_dpp_config_jwk_error_no_kty(dev, apdev):
996 """DPP Config Object JWK error - no kty"""
997 run_dpp_config_error(dev, apdev, build_conf_obj(kty=None))
998
999def test_dpp_config_jwk_error_unexpected_kty(dev, apdev):
1000 """DPP Config Object JWK error - unexpected kty"""
1001 run_dpp_config_error(dev, apdev, build_conf_obj(kty="unknown"))
1002
1003def test_dpp_config_jwk_error_no_crv(dev, apdev):
1004 """DPP Config Object JWK error - no crv"""
1005 run_dpp_config_error(dev, apdev, build_conf_obj(crv=None))
1006
1007def test_dpp_config_jwk_error_unsupported_crv(dev, apdev):
1008 """DPP Config Object JWK error - unsupported curve"""
1009 run_dpp_config_error(dev, apdev, build_conf_obj(crv="unsupported"))
1010
1011def test_dpp_config_jwk_error_no_x(dev, apdev):
1012 """DPP Config Object JWK error - no x"""
1013 run_dpp_config_error(dev, apdev, build_conf_obj(x=None))
1014
1015def test_dpp_config_jwk_error_invalid_x(dev, apdev):
1016 """DPP Config Object JWK error - invalid x"""
1017 run_dpp_config_error(dev, apdev, build_conf_obj(x="MTIz"))
1018
1019def test_dpp_config_jwk_error_no_y(dev, apdev):
1020 """DPP Config Object JWK error - no y"""
1021 run_dpp_config_error(dev, apdev, build_conf_obj(y=None))
1022
1023def test_dpp_config_jwk_error_invalid_y(dev, apdev):
1024 """DPP Config Object JWK error - invalid y"""
1025 run_dpp_config_error(dev, apdev, build_conf_obj(y="MTIz"))
1026
1027def test_dpp_config_jwk_error_invalid_xy(dev, apdev):
1028 """DPP Config Object JWK error - invalid x,y"""
1029 conf = build_conf_obj(x="MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY",
1030 y="MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY")
1031 run_dpp_config_error(dev, apdev, conf)
1032
1033def test_dpp_config_jwk_error_no_kid(dev, apdev):
1034 """DPP Config Object JWK error - no kid"""
530b31ea
JM
1035 # csign kid is optional field, so this results in success
1036 run_dpp_config_error(dev, apdev, build_conf_obj(kid=None),
1037 conf_failure=False)
30dda44d
JM
1038
1039def test_dpp_config_jws_error_prot_hdr_not_an_object(dev, apdev):
1040 """DPP Config Object JWS error - protected header not an object"""
1041 run_dpp_config_error(dev, apdev, build_conf_obj(prot_hdr="1"))
1042
1043def test_dpp_config_jws_error_prot_hdr_no_typ(dev, apdev):
1044 """DPP Config Object JWS error - protected header - no typ"""
fab49f61 1045 prot_hdr = '{"kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU","alg":"ES256"}'
30dda44d
JM
1046 run_dpp_config_error(dev, apdev, build_conf_obj(prot_hdr=prot_hdr))
1047
1048def test_dpp_config_jws_error_prot_hdr_unsupported_typ(dev, apdev):
1049 """DPP Config Object JWS error - protected header - unsupported typ"""
fab49f61 1050 prot_hdr = '{"typ":"unsupported","kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU","alg":"ES256"}'
30dda44d
JM
1051 run_dpp_config_error(dev, apdev, build_conf_obj(prot_hdr=prot_hdr))
1052
1053def test_dpp_config_jws_error_prot_hdr_no_alg(dev, apdev):
1054 """DPP Config Object JWS error - protected header - no alg"""
fab49f61 1055 prot_hdr = '{"typ":"dppCon","kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU"}'
30dda44d
JM
1056 run_dpp_config_error(dev, apdev, build_conf_obj(prot_hdr=prot_hdr))
1057
1058def test_dpp_config_jws_error_prot_hdr_unexpected_alg(dev, apdev):
1059 """DPP Config Object JWS error - protected header - unexpected alg"""
fab49f61 1060 prot_hdr = '{"typ":"dppCon","kid":"TnGKjIlNZaatrEAYrbbjiB67rjkL_AGVWXO6q9hDJKU","alg":"unexpected"}'
30dda44d
JM
1061 run_dpp_config_error(dev, apdev, build_conf_obj(prot_hdr=prot_hdr))
1062
1063def test_dpp_config_jws_error_prot_hdr_no_kid(dev, apdev):
1064 """DPP Config Object JWS error - protected header - no kid"""
fab49f61 1065 prot_hdr = '{"typ":"dppCon","alg":"ES256"}'
30dda44d
JM
1066 run_dpp_config_error(dev, apdev, build_conf_obj(prot_hdr=prot_hdr))
1067
1068def test_dpp_config_jws_error_prot_hdr_unexpected_kid(dev, apdev):
1069 """DPP Config Object JWS error - protected header - unexpected kid"""
fab49f61 1070 prot_hdr = '{"typ":"dppCon","kid":"MTIz","alg":"ES256"}'
30dda44d
JM
1071 run_dpp_config_error(dev, apdev, build_conf_obj(prot_hdr=prot_hdr))
1072
1073def test_dpp_config_signed_connector_error_no_dot_1(dev, apdev):
1074 """DPP Config Object signedConnector error - no dot(1)"""
1075 conn = "MTIz"
1076 run_dpp_config_error(dev, apdev, build_conf_obj(signed_connector=conn))
1077
1078def test_dpp_config_signed_connector_error_no_dot_2(dev, apdev):
1079 """DPP Config Object signedConnector error - no dot(2)"""
1080 conn = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJUbkdLaklsTlphYXRyRUFZcmJiamlCNjdyamtMX0FHVldYTzZxOWhESktVIiwiYWxnIjoiRVMyNTYifQ.MTIz"
1081 run_dpp_config_error(dev, apdev, build_conf_obj(signed_connector=conn))
1082
1083def test_dpp_config_signed_connector_error_unexpected_signature_len(dev, apdev):
1084 """DPP Config Object signedConnector error - unexpected signature length"""
1085 conn = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJUbkdLaklsTlphYXRyRUFZcmJiamlCNjdyamtMX0FHVldYTzZxOWhESktVIiwiYWxnIjoiRVMyNTYifQ.MTIz.MTIz"
1086 run_dpp_config_error(dev, apdev, build_conf_obj(signed_connector=conn))
1087
1088def test_dpp_config_signed_connector_error_invalid_signature_der(dev, apdev):
1089 """DPP Config Object signedConnector error - invalid signature DER"""
1090 conn = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJUbkdLaklsTlphYXRyRUFZcmJiamlCNjdyamtMX0FHVldYTzZxOWhESktVIiwiYWxnIjoiRVMyNTYifQ.MTIz.MTI"
1091 run_dpp_config_error(dev, apdev, build_conf_obj(signed_connector=conn))
1092
1093def test_dpp_config_no_csign(dev, apdev):
1094 """DPP Config Object error - no csign"""
1095 run_dpp_config_error(dev, apdev, build_conf_obj(csign=False))
1096
1097def test_dpp_config_no_signed_connector(dev, apdev):
1098 """DPP Config Object error - no signedConnector"""
1099 run_dpp_config_error(dev, apdev, build_conf_obj(no_signed_connector=True))
1100
1101def test_dpp_config_unexpected_signed_connector_char(dev, apdev):
1102 """DPP Config Object error - unexpected signedConnector character"""
1103 run_dpp_config_error(dev, apdev, build_conf_obj(signed_connector='a\nb'))
1104
1105def test_dpp_config_root_not_an_object(dev, apdev):
1106 """DPP Config Object error - root not an object"""
1107 conf = "1"
1108 run_dpp_config_error(dev, apdev, conf)
1109
1110def test_dpp_config_no_wi_fi_tech(dev, apdev):
1111 """DPP Config Object error - no wi-fi_tech"""
1112 conf = "{}"
1113 run_dpp_config_error(dev, apdev, conf)
1114
1115def test_dpp_config_unsupported_wi_fi_tech(dev, apdev):
1116 """DPP Config Object error - unsupported wi-fi_tech"""
1117 conf = '{"wi-fi_tech":"unsupported"}'
1118 run_dpp_config_error(dev, apdev, conf)
1119
1120def test_dpp_config_no_discovery(dev, apdev):
1121 """DPP Config Object error - no discovery"""
1122 conf = '{"wi-fi_tech":"infra"}'
1123 run_dpp_config_error(dev, apdev, conf)
1124
1125def test_dpp_config_no_discovery_ssid(dev, apdev):
1126 """DPP Config Object error - no discovery::ssid"""
1127 conf = '{"wi-fi_tech":"infra","discovery":{}}'
1128 run_dpp_config_error(dev, apdev, conf)
1129
1130def test_dpp_config_too_long_discovery_ssid(dev, apdev):
1131 """DPP Config Object error - too long discovery::ssid"""
1132 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"%s"}}' % (33*'A')
1133 run_dpp_config_error(dev, apdev, conf)
1134
1135def test_dpp_config_no_cred(dev, apdev):
1136 """DPP Config Object error - no cred"""
1137 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"}}'
1138 run_dpp_config_error(dev, apdev, conf)
1139
1140def test_dpp_config_no_cred_akm(dev, apdev):
1141 """DPP Config Object error - no cred::akm"""
1142 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{}}'
1143 run_dpp_config_error(dev, apdev, conf)
1144
1145def test_dpp_config_unsupported_cred_akm(dev, apdev):
1146 """DPP Config Object error - unsupported cred::akm"""
1147 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"unsupported"}}'
1148 run_dpp_config_error(dev, apdev, conf)
1149
1150def test_dpp_config_error_legacy_no_pass(dev, apdev):
1151 """DPP Config Object legacy error - no pass/psk"""
1152 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk"}}'
1153 run_dpp_config_error(dev, apdev, conf)
1154
1155def test_dpp_config_error_legacy_too_short_pass(dev, apdev):
1156 """DPP Config Object legacy error - too short pass/psk"""
1157 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"1"}}'
1158 run_dpp_config_error(dev, apdev, conf)
1159
1160def test_dpp_config_error_legacy_too_long_pass(dev, apdev):
1161 """DPP Config Object legacy error - too long pass/psk"""
1162 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"%s"}}' % (64*'A')
1163 run_dpp_config_error(dev, apdev, conf)
1164
1165def test_dpp_config_error_legacy_psk_with_sae(dev, apdev):
1166 """DPP Config Object legacy error - psk_hex with SAE"""
1167 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"sae","psk_hex":"%s"}}' % (32*"12")
1168 run_dpp_config_error(dev, apdev, conf)
1169
1170def test_dpp_config_error_legacy_no_pass_for_sae(dev, apdev):
1171 """DPP Config Object legacy error - no pass for SAE"""
1172 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk+sae","psk_hex":"%s"}}' % (32*"12")
1173 run_dpp_config_error(dev, apdev, conf)
1174
1175def test_dpp_config_error_legacy_invalid_psk(dev, apdev):
1176 """DPP Config Object legacy error - invalid psk_hex"""
1177 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"%s"}}' % (32*"qa")
1178 run_dpp_config_error(dev, apdev, conf)
1179
1180def test_dpp_config_error_legacy_too_short_psk(dev, apdev):
1181 """DPP Config Object legacy error - too short psk_hex"""
1182 conf = '{"wi-fi_tech":"infra","discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"%s"}}' % (31*"12")
1183 run_dpp_config_error(dev, apdev, conf)
1184
421d658a
JM
1185def get_der_int_32(val):
1186 a, b = struct.unpack('BB', val[0:2])
1187 if a != 0x02:
1188 raise Exception("Invalid DER encoding of INTEGER")
1189 if b > len(val) - 2:
1190 raise Exception("Invalid length of INTEGER (truncated)")
1191 val = val[2:]
1192 if b == 32:
1193 r = val[0:32]
1194 elif b == 33:
1195 if val[0] != 0:
1196 raise Exception("Too large INTEGER (32)")
1197 r = val[1:33]
1198 elif b < 32:
1199 r = (32 - b) * b'\x00' + val[0:b]
1200 else:
1201 raise Exception("Invalid length of INTEGER (32): %d" % b)
1202 return r, val[b:]
1203
fd1534a2
JM
1204def ecdsa_sign(pkey, message, alg="sha256"):
1205 sign = OpenSSL.crypto.sign(pkey, message, alg)
421d658a 1206 logger.debug("sign=" + binascii.hexlify(sign).decode())
fab49f61 1207 a, b = struct.unpack('BB', sign[0:2])
fd1534a2
JM
1208 if a != 0x30:
1209 raise Exception("Invalid DER encoding of ECDSA signature")
1210 if b != len(sign) - 2:
1211 raise Exception("Invalid length of ECDSA signature")
1212 sign = sign[2:]
1213
421d658a
JM
1214 r, sign = get_der_int_32(sign)
1215 s, sign = get_der_int_32(sign)
fd1534a2
JM
1216 if len(sign) != 0:
1217 raise Exception("Extra data at the end of ECDSA signature")
1218
421d658a
JM
1219 logger.info("r=" + binascii.hexlify(r).decode())
1220 logger.info("s=" + binascii.hexlify(s).decode())
fd1534a2 1221 raw_sign = r + s
c4e333fa 1222 return base64.urlsafe_b64encode(raw_sign).decode().rstrip('=')
fd1534a2
JM
1223
1224p256_priv_key = """-----BEGIN EC PRIVATE KEY-----
1225MHcCAQEEIBVQij9ah629f1pu3tarDQGQvrzHgAkgYd1jHGiLxNajoAoGCCqGSM49
1226AwEHoUQDQgAEAC9d2/JirKu72F2qLuv5jEFMD1Cqu9EiyGk7cOzn/2DJ51p2mEoW
1227n03N6XRvTC+G7WPol9Ng97NAM2sK57+F/Q==
1228-----END EC PRIVATE KEY-----"""
1229p256_pub_key_x = binascii.unhexlify("002f5ddbf262acabbbd85daa2eebf98c414c0f50aabbd122c8693b70ece7ff60")
1230p256_pub_key_y = binascii.unhexlify("c9e75a76984a169f4dcde9746f4c2f86ed63e897d360f7b340336b0ae7bf85fd")
1231
1232def run_dpp_config_connector(dev, apdev, expiry=None, payload=None,
530b31ea
JM
1233 skip_net_access_key_mismatch=True,
1234 conf_failure=True):
fd1534a2
JM
1235 if not openssl_imported:
1236 raise HwsimSkip("OpenSSL python method not available")
1237 pkey = OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM,
1238 p256_priv_key)
c4e333fa
MH
1239 x = base64.urlsafe_b64encode(p256_pub_key_x).decode().rstrip('=')
1240 y = base64.urlsafe_b64encode(p256_pub_key_y).decode().rstrip('=')
fd1534a2 1241
c4e333fa
MH
1242 pubkey = b'\x04' + p256_pub_key_x + p256_pub_key_y
1243 kid = base64.urlsafe_b64encode(hashlib.sha256(pubkey).digest()).decode().rstrip('=')
fd1534a2
JM
1244
1245 prot_hdr = '{"typ":"dppCon","kid":"%s","alg":"ES256"}' % kid
1246
1247 if not payload:
1248 payload = '{"groups":[{"groupId":"*","netRole":"sta"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}'
1249 if expiry:
1250 payload += ',"expiry":"%s"' % expiry
1251 payload += '}'
c4e333fa
MH
1252 conn = base64.urlsafe_b64encode(prot_hdr.encode()).decode().rstrip('=') + '.'
1253 conn += base64.urlsafe_b64encode(payload.encode()).decode().rstrip('=')
fd1534a2
JM
1254 sign = ecdsa_sign(pkey, conn)
1255 conn += '.' + sign
1256 run_dpp_config_error(dev, apdev,
1257 build_conf_obj(x=x, y=y, signed_connector=conn),
530b31ea
JM
1258 skip_net_access_key_mismatch=skip_net_access_key_mismatch,
1259 conf_failure=conf_failure)
fd1534a2
JM
1260
1261def test_dpp_config_connector_error_ext_sign(dev, apdev):
1262 """DPP Config Object connector error - external signature calculation"""
530b31ea 1263 run_dpp_config_connector(dev, apdev, conf_failure=False)
fd1534a2
JM
1264
1265def test_dpp_config_connector_error_too_short_timestamp(dev, apdev):
1266 """DPP Config Object connector error - too short timestamp"""
1267 run_dpp_config_connector(dev, apdev, expiry="1")
1268
1269def test_dpp_config_connector_error_invalid_timestamp(dev, apdev):
1270 """DPP Config Object connector error - invalid timestamp"""
1271 run_dpp_config_connector(dev, apdev, expiry=19*"1")
1272
1273def test_dpp_config_connector_error_invalid_timestamp_date(dev, apdev):
1274 """DPP Config Object connector error - invalid timestamp date"""
1275 run_dpp_config_connector(dev, apdev, expiry="9999-99-99T99:99:99Z")
1276
1277def test_dpp_config_connector_error_invalid_time_zone(dev, apdev):
1278 """DPP Config Object connector error - invalid time zone"""
1279 run_dpp_config_connector(dev, apdev, expiry="2018-01-01T00:00:00*")
1280
1281def test_dpp_config_connector_error_invalid_time_zone_2(dev, apdev):
1282 """DPP Config Object connector error - invalid time zone 2"""
1283 run_dpp_config_connector(dev, apdev, expiry="2018-01-01T00:00:00+")
1284
1285def test_dpp_config_connector_error_expired_1(dev, apdev):
1286 """DPP Config Object connector error - expired 1"""
1287 run_dpp_config_connector(dev, apdev, expiry="2018-01-01T00:00:00")
1288
1289def test_dpp_config_connector_error_expired_2(dev, apdev):
1290 """DPP Config Object connector error - expired 2"""
1291 run_dpp_config_connector(dev, apdev, expiry="2018-01-01T00:00:00Z")
1292
1293def test_dpp_config_connector_error_expired_3(dev, apdev):
1294 """DPP Config Object connector error - expired 3"""
1295 run_dpp_config_connector(dev, apdev, expiry="2018-01-01T00:00:00+01")
1296
1297def test_dpp_config_connector_error_expired_4(dev, apdev):
1298 """DPP Config Object connector error - expired 4"""
1299 run_dpp_config_connector(dev, apdev, expiry="2018-01-01T00:00:00+01:02")
1300
1301def test_dpp_config_connector_error_expired_5(dev, apdev):
1302 """DPP Config Object connector error - expired 5"""
1303 run_dpp_config_connector(dev, apdev, expiry="2018-01-01T00:00:00-01")
1304
1305def test_dpp_config_connector_error_expired_6(dev, apdev):
1306 """DPP Config Object connector error - expired 6"""
1307 run_dpp_config_connector(dev, apdev, expiry="2018-01-01T00:00:00-01:02")
1308
1309def test_dpp_config_connector_error_no_groups(dev, apdev):
1310 """DPP Config Object connector error - no groups"""
1311 payload = '{"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1312 run_dpp_config_connector(dev, apdev, payload=payload)
1313
1314def test_dpp_config_connector_error_empty_groups(dev, apdev):
1315 """DPP Config Object connector error - empty groups"""
1316 payload = '{"groups":[],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1317 run_dpp_config_connector(dev, apdev, payload=payload)
1318
1319def test_dpp_config_connector_error_missing_group_id(dev, apdev):
1320 """DPP Config Object connector error - missing groupId"""
1321 payload = '{"groups":[{"netRole":"sta"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1322 run_dpp_config_connector(dev, apdev, payload=payload)
1323
1324def test_dpp_config_connector_error_missing_net_role(dev, apdev):
1325 """DPP Config Object connector error - missing netRole"""
1326 payload = '{"groups":[{"groupId":"*"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1327 run_dpp_config_connector(dev, apdev, payload=payload)
1328
1329def test_dpp_config_connector_error_missing_net_access_key(dev, apdev):
1330 """DPP Config Object connector error - missing netAccessKey"""
1331 payload = '{"groups":[{"groupId":"*","netRole":"sta"}]}'
1332 run_dpp_config_connector(dev, apdev, payload=payload)
1333
1334def test_dpp_config_connector_error_net_access_key_mismatch(dev, apdev):
1335 """DPP Config Object connector error - netAccessKey mismatch"""
1336 payload = '{"groups":[{"groupId":"*","netRole":"sta"}],"netAccessKey":{"kty":"EC","crv":"P-256","x":"aTF4JEGIPKSZ0Xv9zdCMjm-tn5XpMsYIVZ9wySAz1gI","y":"QGcHWA_6rbU9XDXAztoX-M5Q3suTnMaqEhULtn7SSXw"}}'
1337 run_dpp_config_connector(dev, apdev, payload=payload,
1338 skip_net_access_key_mismatch=False)
1339
d350084d
JM
1340def test_dpp_gas_timeout(dev, apdev):
1341 """DPP and GAS server timeout for a query"""
1342 check_dpp_capab(dev[0])
1343 check_dpp_capab(dev[1])
1344 logger.info("dev0 displays QR Code")
a5387062 1345 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
d350084d
JM
1346 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
1347
5725b3e3 1348 logger.info("dev1 scans QR Code and initiates DPP Authentication")
d350084d 1349 dev[0].set("ext_mgmt_frame_handling", "1")
7e009100 1350 dev[0].dpp_listen(2412)
d350084d
JM
1351
1352 # Force GAS fragmentation
1353 conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
1354 dev[1].set("dpp_config_obj_override", conf)
1355
5725b3e3 1356 dev[1].dpp_auth_init(uri=uri0)
d350084d
JM
1357
1358 # DPP Authentication Request
1359 msg = dev[0].mgmt_rx()
54c58f29
MH
1360 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
1361 msg['freq'], msg['datarate'], msg['ssi_signal'], binascii.hexlify(msg['frame']).decode())):
d350084d
JM
1362 raise Exception("MGMT_RX_PROCESS failed")
1363
1364 # DPP Authentication Confirmation
1365 msg = dev[0].mgmt_rx()
54c58f29
MH
1366 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
1367 msg['freq'], msg['datarate'], msg['ssi_signal'], binascii.hexlify(msg['frame']).decode())):
d350084d
JM
1368 raise Exception("MGMT_RX_PROCESS failed")
1369
517f76b1 1370 wait_auth_success(dev[0], dev[1])
d350084d
JM
1371
1372 # DPP Configuration Response (GAS Initial Response frame)
1373 msg = dev[0].mgmt_rx()
54c58f29
MH
1374 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
1375 msg['freq'], msg['datarate'], msg['ssi_signal'], binascii.hexlify(msg['frame']).decode())):
d350084d
JM
1376 raise Exception("MGMT_RX_PROCESS failed")
1377
1378 # GAS Comeback Response frame
1379 msg = dev[0].mgmt_rx()
1380 # Do not continue to force timeout on GAS server
1381
1382 ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
1383 if ev is None:
1384 raise Exception("GAS result not reported (Enrollee)")
1385 if "result=TIMEOUT" not in ev:
1386 raise Exception("Unexpected GAS result (Enrollee): " + ev)
1387 dev[0].set("ext_mgmt_frame_handling", "0")
1388
1389 ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=15)
1390 if ev is None:
1391 raise Exception("DPP configuration failure not reported (Configurator)")
1392
1393 ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=1)
1394 if ev is None:
1395 raise Exception("DPP configuration failure not reported (Enrollee)")
1396
1397def test_dpp_akm_sha256(dev, apdev):
1398 """DPP AKM (SHA256)"""
1399 run_dpp_akm(dev, apdev, 32)
1400
1401def test_dpp_akm_sha384(dev, apdev):
1402 """DPP AKM (SHA384)"""
1403 run_dpp_akm(dev, apdev, 48)
1404
1405def test_dpp_akm_sha512(dev, apdev):
1406 """DPP AKM (SHA512)"""
1407 run_dpp_akm(dev, apdev, 64)
1408
1409def run_dpp_akm(dev, apdev, pmk_len):
1410 check_dpp_capab(dev[0])
1411 check_dpp_capab(dev[1])
fab49f61
JM
1412 params = {"ssid": "dpp",
1413 "wpa": "2",
1414 "wpa_key_mgmt": "DPP",
1415 "rsn_pairwise": "CCMP",
1416 "ieee80211w": "2"}
d350084d
JM
1417 try:
1418 hapd = hostapd.add_ap(apdev[0], params)
1419 except:
1420 raise HwsimSkip("DPP not supported")
1421
299196c4 1422 id = dev[0].connect("dpp", key_mgmt="DPP", ieee80211w="2", scan_freq="2412",
d350084d
JM
1423 wait_connect=False)
1424 ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=2)
1425 if not ev:
1426 raise Exception("Network mismatch not reported")
1427 dev[0].request("DISCONNECT")
1428 dev[0].dump_monitor()
1429
1430 bssid = hapd.own_addr()
1431 pmkid = 16*'11'
1432 akmp = 2**23
1433 pmk = pmk_len*'22'
1434 cmd = "PMKSA_ADD %d %s %s %s 30240 43200 %d 0" % (id, bssid, pmkid, pmk, akmp)
1435 if "OK" not in dev[0].request(cmd):
1436 raise Exception("PMKSA_ADD failed (wpa_supplicant)")
1437 dev[0].select_network(id, freq="2412")
1438 ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=2)
1439 dev[0].request("DISCONNECT")
1440 dev[0].dump_monitor()
1441 if not ev:
1442 raise Exception("Association attempt was not rejected")
1443 if "status_code=53" not in ev:
1444 raise Exception("Unexpected status code: " + ev)
1445
1446 addr = dev[0].own_addr()
1447 cmd = "PMKSA_ADD %s %s %s 0 %d" % (addr, pmkid, pmk, akmp)
1448 if "OK" not in hapd.request(cmd):
1449 raise Exception("PMKSA_ADD failed (hostapd)")
1450
1451 dev[0].select_network(id, freq="2412")
1452 dev[0].wait_connected()
0f842044
JM
1453 val = dev[0].get_status_field("key_mgmt")
1454 if val != "DPP":
1455 raise Exception("Unexpected key_mgmt: " + val)
d350084d 1456
7e26f1bc
JM
1457params1_csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
1458params1_ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
1459params1_ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
1460params1_sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
1461params1_sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
1462
d350084d
JM
1463def test_dpp_network_introduction(dev, apdev):
1464 """DPP network introduction"""
1465 check_dpp_capab(dev[0])
1466 check_dpp_capab(dev[1])
1467
fab49f61
JM
1468 params = {"ssid": "dpp",
1469 "wpa": "2",
1470 "wpa_key_mgmt": "DPP",
1471 "ieee80211w": "2",
1472 "rsn_pairwise": "CCMP",
1473 "dpp_connector": params1_ap_connector,
1474 "dpp_csign": params1_csign,
1475 "dpp_netaccesskey": params1_ap_netaccesskey}
d350084d
JM
1476 try:
1477 hapd = hostapd.add_ap(apdev[0], params)
1478 except:
1479 raise HwsimSkip("DPP not supported")
1480
1481 id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
299196c4 1482 ieee80211w="2",
7e26f1bc
JM
1483 dpp_csign=params1_csign,
1484 dpp_connector=params1_sta_connector,
1485 dpp_netaccesskey=params1_sta_netaccesskey)
0f842044
JM
1486 val = dev[0].get_status_field("key_mgmt")
1487 if val != "DPP":
1488 raise Exception("Unexpected key_mgmt: " + val)
d350084d 1489
ba2d5f36
JM
1490def test_dpp_network_introduction_expired(dev, apdev):
1491 """DPP network introduction with expired netaccesskey"""
1492 check_dpp_capab(dev[0])
1493 check_dpp_capab(dev[1])
1494
1495 params = {"ssid": "dpp",
1496 "wpa": "2",
1497 "wpa_key_mgmt": "DPP",
1498 "ieee80211w": "2",
1499 "rsn_pairwise": "CCMP",
1500 "dpp_connector": params1_ap_connector,
1501 "dpp_csign": params1_csign,
1502 "dpp_netaccesskey": params1_ap_netaccesskey,
1503 "dpp_netaccesskey_expiry": "1565530889"}
1504 try:
1505 hapd = hostapd.add_ap(apdev[0], params)
1506 except:
1507 raise HwsimSkip("DPP not supported")
1508
1509 dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
1510 ieee80211w="2",
1511 dpp_csign=params1_csign,
1512 dpp_connector=params1_sta_connector,
1513 dpp_netaccesskey=params1_sta_netaccesskey,
1514 wait_connect=False)
1515 ev = hapd.wait_event(["DPP-RX"], timeout=10)
1516 if ev is None:
1517 raise Exception("No DPP Peer Discovery Request seen")
1518 if "type=5" not in ev:
1519 raise Exception("Unexpected DPP message received: " + ev)
1520 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
1521 dev[0].request("DISCONNECT")
1522 if ev:
1523 raise Exception("Connection reported")
1524
1525 hapd.disable()
1526 hapd.set("dpp_netaccesskey_expiry", "2565530889")
1527 hapd.enable()
1528 dev[0].request("RECONNECT")
1529 dev[0].wait_connected()
1530
e5b0b58b
JM
1531def test_dpp_and_sae_akm(dev, apdev):
1532 """DPP and SAE AKMs"""
1533 check_dpp_capab(dev[0])
1534 check_dpp_capab(dev[1])
1535 if "SAE" not in dev[1].get_capability("auth_alg"):
1536 raise HwsimSkip("SAE not supported")
1537
fab49f61
JM
1538 params = {"ssid": "dpp+sae",
1539 "wpa": "2",
1540 "wpa_key_mgmt": "DPP SAE",
1541 "ieee80211w": "2",
1542 "rsn_pairwise": "CCMP",
1543 "sae_password": "sae-password",
1544 "dpp_connector": params1_ap_connector,
1545 "dpp_csign": params1_csign,
1546 "dpp_netaccesskey": params1_ap_netaccesskey}
e5b0b58b
JM
1547 try:
1548 hapd = hostapd.add_ap(apdev[0], params)
1549 except:
1550 raise HwsimSkip("DPP not supported")
1551
1552 id = dev[0].connect("dpp+sae", key_mgmt="DPP", scan_freq="2412",
1553 ieee80211w="2",
7e26f1bc
JM
1554 dpp_csign=params1_csign,
1555 dpp_connector=params1_sta_connector,
1556 dpp_netaccesskey=params1_sta_netaccesskey)
e5b0b58b
JM
1557 val = dev[0].get_status_field("key_mgmt")
1558 if val != "DPP":
1559 raise Exception("Unexpected key_mgmt for DPP: " + val)
1560
c9ead82d 1561 dev[1].request("SET sae_groups ")
e5b0b58b
JM
1562 id = dev[1].connect("dpp+sae", key_mgmt="SAE", scan_freq="2412",
1563 ieee80211w="2", psk="sae-password")
1564 val = dev[1].get_status_field("key_mgmt")
1565 if val != "SAE":
1566 raise Exception("Unexpected key_mgmt for SAE: " + val)
1567
d350084d
JM
1568def test_dpp_ap_config(dev, apdev):
1569 """DPP and AP configuration"""
1570 run_dpp_ap_config(dev, apdev)
1571
1572def test_dpp_ap_config_p256_p256(dev, apdev):
1573 """DPP and AP configuration (P-256 + P-256)"""
1574 run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-256")
1575
1576def test_dpp_ap_config_p256_p384(dev, apdev):
1577 """DPP and AP configuration (P-256 + P-384)"""
1578 run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-384")
1579
1580def test_dpp_ap_config_p256_p521(dev, apdev):
1581 """DPP and AP configuration (P-256 + P-521)"""
1582 run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-521")
1583
1584def test_dpp_ap_config_p384_p256(dev, apdev):
1585 """DPP and AP configuration (P-384 + P-256)"""
1586 run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-256")
1587
1588def test_dpp_ap_config_p384_p384(dev, apdev):
1589 """DPP and AP configuration (P-384 + P-384)"""
1590 run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-384")
1591
1592def test_dpp_ap_config_p384_p521(dev, apdev):
1593 """DPP and AP configuration (P-384 + P-521)"""
1594 run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-521")
1595
1596def test_dpp_ap_config_p521_p256(dev, apdev):
1597 """DPP and AP configuration (P-521 + P-256)"""
1598 run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-256")
1599
1600def test_dpp_ap_config_p521_p384(dev, apdev):
1601 """DPP and AP configuration (P-521 + P-384)"""
1602 run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-384")
1603
1604def test_dpp_ap_config_p521_p521(dev, apdev):
1605 """DPP and AP configuration (P-521 + P-521)"""
1606 run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-521")
1607
84438350
JM
1608def test_dpp_ap_config_bp256_bp256(dev, apdev):
1609 """DPP and AP configuration (BP-256 + BP-256)"""
1610 run_dpp_ap_config(dev, apdev, curve="BP-256", conf_curve="BP-256")
1611
1612def test_dpp_ap_config_bp384_bp384(dev, apdev):
1613 """DPP and AP configuration (BP-384 + BP-384)"""
1614 run_dpp_ap_config(dev, apdev, curve="BP-384", conf_curve="BP-384")
1615
1616def test_dpp_ap_config_bp512_bp512(dev, apdev):
1617 """DPP and AP configuration (BP-512 + BP-512)"""
1618 run_dpp_ap_config(dev, apdev, curve="BP-512", conf_curve="BP-512")
1619
1620def test_dpp_ap_config_p256_bp256(dev, apdev):
1621 """DPP and AP configuration (P-256 + BP-256)"""
1622 run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="BP-256")
1623
1624def test_dpp_ap_config_bp256_p256(dev, apdev):
1625 """DPP and AP configuration (BP-256 + P-256)"""
1626 run_dpp_ap_config(dev, apdev, curve="BP-256", conf_curve="P-256")
1627
1628def test_dpp_ap_config_p521_bp512(dev, apdev):
1629 """DPP and AP configuration (P-521 + BP-512)"""
1630 run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="BP-512")
1631
1632def test_dpp_ap_config_bp512_p521(dev, apdev):
1633 """DPP and AP configuration (BP-512 + P-521)"""
1634 run_dpp_ap_config(dev, apdev, curve="BP-512", conf_curve="P-521")
1635
0c061630
JM
1636def test_dpp_ap_config_reconfig_configurator(dev, apdev):
1637 """DPP and AP configuration with Configurator reconfiguration"""
1638 run_dpp_ap_config(dev, apdev, reconf_configurator=True)
1639
854d0de3
JM
1640def update_hapd_config(hapd):
1641 ev = hapd.wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
1642 if ev is None:
1643 raise Exception("SSID not reported (AP)")
1644 ssid = ev.split(' ')[1]
1645
1646 ev = hapd.wait_event(["DPP-CONNECTOR"], timeout=1)
1647 if ev is None:
1648 raise Exception("Connector not reported (AP)")
1649 connector = ev.split(' ')[1]
1650
1651 ev = hapd.wait_event(["DPP-C-SIGN-KEY"], timeout=1)
1652 if ev is None:
1653 raise Exception("C-sign-key not reported (AP)")
1654 p = ev.split(' ')
1655 csign = p[1]
854d0de3
JM
1656
1657 ev = hapd.wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
1658 if ev is None:
1659 raise Exception("netAccessKey not reported (AP)")
1660 p = ev.split(' ')
1661 net_access_key = p[1]
1662 net_access_key_expiry = p[2] if len(p) > 2 else None
1663
1664 logger.info("Update AP configuration to use key_mgmt=DPP")
1665 hapd.disable()
1666 hapd.set("ssid", ssid)
e0cd7172 1667 hapd.set("utf8_ssid", "1")
854d0de3
JM
1668 hapd.set("wpa", "2")
1669 hapd.set("wpa_key_mgmt", "DPP")
299196c4 1670 hapd.set("ieee80211w", "2")
854d0de3
JM
1671 hapd.set("rsn_pairwise", "CCMP")
1672 hapd.set("dpp_connector", connector)
1673 hapd.set("dpp_csign", csign)
854d0de3
JM
1674 hapd.set("dpp_netaccesskey", net_access_key)
1675 if net_access_key_expiry:
1676 hapd.set("dpp_netaccesskey_expiry", net_access_key_expiry)
1677 hapd.enable()
1678
0c061630
JM
1679def run_dpp_ap_config(dev, apdev, curve=None, conf_curve=None,
1680 reconf_configurator=False):
d350084d
JM
1681 check_dpp_capab(dev[0])
1682 check_dpp_capab(dev[1])
fab49f61 1683 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
d350084d
JM
1684 check_dpp_capab(hapd)
1685
a5387062 1686 id_h = hapd.dpp_bootstrap_gen(chan="81/1", mac=True, curve=curve)
d350084d
JM
1687 uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
1688
e105110f 1689 conf_id = dev[0].dpp_configurator_add(curve=conf_curve)
d350084d 1690
0c061630
JM
1691 if reconf_configurator:
1692 csign = dev[0].request("DPP_CONFIGURATOR_GET_KEY %d" % conf_id)
1693 if "FAIL" in csign or len(csign) == 0:
1694 raise Exception("DPP_CONFIGURATOR_GET_KEY failed")
1695
5725b3e3 1696 dev[0].dpp_auth_init(uri=uri, conf="ap-dpp", configurator=conf_id)
517f76b1 1697 wait_auth_success(hapd, dev[0], configurator=dev[0], enrollee=hapd)
854d0de3 1698 update_hapd_config(hapd)
d350084d 1699
a5387062 1700 id1 = dev[1].dpp_bootstrap_gen(chan="81/1", mac=True, curve=curve)
d350084d
JM
1701 uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
1702
0c061630 1703 if reconf_configurator:
e105110f
JM
1704 dev[0].dpp_configurator_remove(conf_id)
1705 conf_id = dev[0].dpp_configurator_add(curve=conf_curve, key=csign)
0c061630 1706
7e009100 1707 dev[1].dpp_listen(2412)
5725b3e3 1708 dev[0].dpp_auth_init(uri=uri1, conf="sta-dpp", configurator=conf_id)
517f76b1
JM
1709 wait_auth_success(dev[1], dev[0], configurator=dev[0], enrollee=dev[1],
1710 stop_responder=True)
d350084d
JM
1711
1712 ev = dev[1].wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
1713 if ev is None:
1714 raise Exception("SSID not reported")
1715 ssid = ev.split(' ')[1]
1716
1717 ev = dev[1].wait_event(["DPP-CONNECTOR"], timeout=1)
1718 if ev is None:
1719 raise Exception("Connector not reported")
1720 connector = ev.split(' ')[1]
1721
1722 ev = dev[1].wait_event(["DPP-C-SIGN-KEY"], timeout=1)
1723 if ev is None:
1724 raise Exception("C-sign-key not reported")
1725 p = ev.split(' ')
1726 csign = p[1]
d350084d
JM
1727
1728 ev = dev[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
1729 if ev is None:
1730 raise Exception("netAccessKey not reported")
1731 p = ev.split(' ')
1732 net_access_key = p[1]
1733 net_access_key_expiry = p[2] if len(p) > 2 else None
1734
1735 dev[1].dump_monitor()
1736
299196c4 1737 id = dev[1].connect(ssid, key_mgmt="DPP", ieee80211w="2", scan_freq="2412",
d350084d
JM
1738 only_add_network=True)
1739 dev[1].set_network_quoted(id, "dpp_connector", connector)
1740 dev[1].set_network(id, "dpp_csign", csign)
d350084d
JM
1741 dev[1].set_network(id, "dpp_netaccesskey", net_access_key)
1742 if net_access_key_expiry:
1743 dev[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry)
1744
1745 logger.info("Check data connection")
1746 dev[1].select_network(id, freq="2412")
1747 dev[1].wait_connected()
cd29045b
JM
1748
1749def test_dpp_auto_connect_1(dev, apdev):
1750 """DPP and auto connect (1)"""
1751 try:
1752 run_dpp_auto_connect(dev, apdev, 1)
1753 finally:
5bf51d38 1754 dev[0].set("dpp_config_processing", "0", allow_fail=True)
cd29045b
JM
1755
1756def test_dpp_auto_connect_2(dev, apdev):
1757 """DPP and auto connect (2)"""
1758 try:
1759 run_dpp_auto_connect(dev, apdev, 2)
1760 finally:
5bf51d38 1761 dev[0].set("dpp_config_processing", "0", allow_fail=True)
cd29045b 1762
ee8ef9ca
JM
1763def test_dpp_auto_connect_2_connect_cmd(dev, apdev):
1764 """DPP and auto connect (2) using connect_cmd"""
1765 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1766 wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
fab49f61 1767 dev_new = [wpas, dev[1]]
ee8ef9ca
JM
1768 try:
1769 run_dpp_auto_connect(dev_new, apdev, 2)
1770 finally:
5bf51d38 1771 wpas.set("dpp_config_processing", "0", allow_fail=True)
ee8ef9ca 1772
cd29045b
JM
1773def run_dpp_auto_connect(dev, apdev, processing):
1774 check_dpp_capab(dev[0])
1775 check_dpp_capab(dev[1])
1776
1777 csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
1778 csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
1779 ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
1780 ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
1781
fab49f61
JM
1782 params = {"ssid": "test",
1783 "wpa": "2",
1784 "wpa_key_mgmt": "DPP",
1785 "ieee80211w": "2",
1786 "rsn_pairwise": "CCMP",
1787 "dpp_connector": ap_connector,
1788 "dpp_csign": csign_pub,
1789 "dpp_netaccesskey": ap_netaccesskey}
cd29045b
JM
1790 try:
1791 hapd = hostapd.add_ap(apdev[0], params)
1792 except:
1793 raise HwsimSkip("DPP not supported")
1794
e105110f 1795 conf_id = dev[1].dpp_configurator_add(key=csign)
cd29045b 1796 dev[0].set("dpp_config_processing", str(processing))
a5387062 1797 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
cd29045b 1798 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
7e009100 1799 dev[0].dpp_listen(2412)
5725b3e3
JM
1800 dev[1].dpp_auth_init(uri=uri0, conf="sta-dpp", configurator=conf_id)
1801 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0])
cd29045b
JM
1802 ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
1803 if ev is None:
1804 raise Exception("DPP network profile not generated")
1805 id = ev.split(' ')[1]
1806
1807 if processing == 1:
1808 dev[0].select_network(id, freq=2412)
1809
1810 dev[0].wait_connected()
bbb42bf0 1811 hwsim_utils.test_connectivity(dev[0], hapd)
cd29045b
JM
1812
1813def test_dpp_auto_connect_legacy(dev, apdev):
1814 """DPP and auto connect (legacy)"""
1815 try:
1816 run_dpp_auto_connect_legacy(dev, apdev)
1817 finally:
5bf51d38 1818 dev[0].set("dpp_config_processing", "0", allow_fail=True)
cd29045b 1819
ca6a2ac7
JM
1820def test_dpp_auto_connect_legacy_ssid_charset(dev, apdev):
1821 """DPP and auto connect (legacy, ssid_charset)"""
1822 try:
1823 run_dpp_auto_connect_legacy(dev, apdev, ssid_charset=12345)
1824 finally:
5bf51d38 1825 dev[0].set("dpp_config_processing", "0", allow_fail=True)
ca6a2ac7 1826
fce412d3
JM
1827def test_dpp_auto_connect_legacy_sae_1(dev, apdev):
1828 """DPP and auto connect (legacy SAE)"""
1829 try:
1830 run_dpp_auto_connect_legacy(dev, apdev, conf='sta-sae', psk_sae=True)
1831 finally:
5bf51d38 1832 dev[0].set("dpp_config_processing", "0", allow_fail=True)
fce412d3
JM
1833
1834def test_dpp_auto_connect_legacy_sae_2(dev, apdev):
1835 """DPP and auto connect (legacy SAE)"""
1836 try:
1837 run_dpp_auto_connect_legacy(dev, apdev, conf='sta-sae', sae_only=True)
1838 finally:
5bf51d38 1839 dev[0].set("dpp_config_processing", "0", allow_fail=True)
fce412d3
JM
1840
1841def test_dpp_auto_connect_legacy_psk_sae_1(dev, apdev):
1842 """DPP and auto connect (legacy PSK+SAE)"""
1843 try:
1844 run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk-sae',
1845 psk_sae=True)
1846 finally:
5bf51d38 1847 dev[0].set("dpp_config_processing", "0", allow_fail=True)
fce412d3
JM
1848
1849def test_dpp_auto_connect_legacy_psk_sae_2(dev, apdev):
1850 """DPP and auto connect (legacy PSK+SAE)"""
1851 try:
1852 run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk-sae',
1853 sae_only=True)
1854 finally:
5bf51d38 1855 dev[0].set("dpp_config_processing", "0", allow_fail=True)
fce412d3
JM
1856
1857def test_dpp_auto_connect_legacy_psk_sae_3(dev, apdev):
1858 """DPP and auto connect (legacy PSK+SAE)"""
1859 try:
1860 run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk-sae')
1861 finally:
5bf51d38 1862 dev[0].set("dpp_config_processing", "0", allow_fail=True)
fce412d3
JM
1863
1864def run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk',
ca6a2ac7 1865 ssid_charset=None,
fce412d3 1866 psk_sae=False, sae_only=False):
cd29045b
JM
1867 check_dpp_capab(dev[0])
1868 check_dpp_capab(dev[1])
1869
ede1f791
JM
1870 params = hostapd.wpa2_params(ssid="dpp-legacy",
1871 passphrase="secret passphrase")
fce412d3
JM
1872 if sae_only:
1873 params['wpa_key_mgmt'] = 'SAE'
2fec710a 1874 params['ieee80211w'] = '2'
fce412d3
JM
1875 elif psk_sae:
1876 params['wpa_key_mgmt'] = 'WPA-PSK SAE'
2fec710a
JM
1877 params['ieee80211w'] = '1'
1878 params['sae_require_mfp'] = '1'
fce412d3 1879
cd29045b
JM
1880 hapd = hostapd.add_ap(apdev[0], params)
1881
c9ead82d 1882 dev[0].request("SET sae_groups ")
cd29045b 1883 dev[0].set("dpp_config_processing", "2")
a5387062 1884 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
299196c4
JM
1885 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
1886
7e009100 1887 dev[0].dpp_listen(2412)
5725b3e3 1888 dev[1].dpp_auth_init(uri=uri0, conf=conf, ssid="dpp-legacy",
ca6a2ac7 1889 ssid_charset=ssid_charset,
5725b3e3
JM
1890 passphrase="secret passphrase")
1891 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0])
ca6a2ac7
JM
1892 if ssid_charset:
1893 ev = dev[0].wait_event(["DPP-CONFOBJ-SSID-CHARSET"], timeout=1)
1894 if ev is None:
1895 raise Exception("ssid_charset not reported")
1896 charset = ev.split(' ')[1]
1897 if charset != str(ssid_charset):
1898 raise Exception("Incorrect ssid_charset reported: " + ev)
299196c4
JM
1899 ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
1900 if ev is None:
1901 raise Exception("DPP network profile not generated")
1902 id = ev.split(' ')[1]
1903
1904 dev[0].wait_connected()
1905
1906def test_dpp_auto_connect_legacy_pmf_required(dev, apdev):
1907 """DPP and auto connect (legacy, PMF required)"""
1908 try:
1909 run_dpp_auto_connect_legacy_pmf_required(dev, apdev)
1910 finally:
5bf51d38 1911 dev[0].set("dpp_config_processing", "0", allow_fail=True)
299196c4
JM
1912
1913def run_dpp_auto_connect_legacy_pmf_required(dev, apdev):
1914 check_dpp_capab(dev[0])
1915 check_dpp_capab(dev[1])
1916
1917 params = hostapd.wpa2_params(ssid="dpp-legacy",
1918 passphrase="secret passphrase")
1919 params['wpa_key_mgmt'] = "WPA-PSK-SHA256"
1920 params['ieee80211w'] = "2"
1921 hapd = hostapd.add_ap(apdev[0], params)
1922
1923 dev[0].set("dpp_config_processing", "2")
a5387062 1924 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
cd29045b 1925 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
7e009100 1926 dev[0].dpp_listen(2412)
5725b3e3
JM
1927 dev[1].dpp_auth_init(uri=uri0, conf="sta-psk", ssid="dpp-legacy",
1928 passphrase="secret passphrase")
1929 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0])
cd29045b
JM
1930 ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
1931 if ev is None:
1932 raise Exception("DPP network profile not generated")
cd29045b 1933 dev[0].wait_connected()
34a5c762 1934
d86b86d0
JM
1935def test_dpp_qr_code_auth_responder_configurator(dev, apdev):
1936 """DPP QR Code and responder as the configurator"""
2697e85e
JM
1937 run_dpp_qr_code_auth_responder_configurator(dev, apdev, "")
1938
1939def test_dpp_qr_code_auth_responder_configurator_group_id(dev, apdev):
1940 """DPP QR Code and responder as the configurator with group_id)"""
1941 run_dpp_qr_code_auth_responder_configurator(dev, apdev,
1942 " group_id=test-group")
1943
1944def run_dpp_qr_code_auth_responder_configurator(dev, apdev, extra):
d86b86d0
JM
1945 check_dpp_capab(dev[0])
1946 check_dpp_capab(dev[1])
e105110f 1947 conf_id = dev[0].dpp_configurator_add()
a5387062 1948 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
d86b86d0 1949 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
2697e85e 1950 dev[0].set("dpp_configurator_params",
58be42b2 1951 " conf=sta-dpp configurator=%d%s" % (conf_id, extra))
7e009100 1952 dev[0].dpp_listen(2412, role="configurator")
5725b3e3 1953 dev[1].dpp_auth_init(uri=uri0, role="enrollee")
517f76b1
JM
1954 wait_auth_success(dev[0], dev[1], configurator=dev[0], enrollee=dev[1],
1955 stop_responder=True)
d86b86d0 1956
d299756e
JM
1957def test_dpp_qr_code_auth_enrollee_init_netrole(dev, apdev):
1958 """DPP QR Code and enrollee initiating with netrole specified"""
1959 check_dpp_capab(dev[0])
1960 check_dpp_capab(dev[1])
1961 conf_id = dev[0].dpp_configurator_add()
1962 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
1963 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
1964 dev[0].set("dpp_configurator_params",
1965 " conf=configurator configurator=%d" % conf_id)
1966 dev[0].dpp_listen(2412, role="configurator")
1967 dev[1].dpp_auth_init(uri=uri0, role="enrollee", netrole="configurator")
1968 wait_auth_success(dev[0], dev[1], configurator=dev[0], enrollee=dev[1],
1969 stop_responder=True)
1970 dev[0].dump_monitor()
1971 dev[1].dump_monitor()
1972
1973 # verify that netrole resets back to sta, if not explicitly stated
1974 dev[0].set("dpp_configurator_params",
1975 "conf=sta-dpp configurator=%d" % conf_id)
1976 dev[0].dpp_listen(2412, role="configurator")
1977 dev[1].dpp_auth_init(uri=uri0, role="enrollee")
1978 wait_auth_success(dev[0], dev[1], configurator=dev[0], enrollee=dev[1],
1979 stop_responder=True)
1980
359dc93d
JM
1981def test_dpp_qr_code_hostapd_init(dev, apdev):
1982 """DPP QR Code and hostapd as initiator"""
1983 check_dpp_capab(dev[0])
fab49f61
JM
1984 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured",
1985 "channel": "6"})
359dc93d 1986 check_dpp_capab(hapd)
e105110f 1987 conf_id = dev[0].dpp_configurator_add()
a5387062 1988 id0 = dev[0].dpp_bootstrap_gen(chan="81/6", mac=True)
359dc93d 1989 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
359dc93d 1990 dev[0].set("dpp_configurator_params",
58be42b2 1991 " conf=ap-dpp configurator=%d" % conf_id)
7e009100 1992 dev[0].dpp_listen(2437, role="configurator")
5725b3e3 1993 hapd.dpp_auth_init(uri=uri0, role="enrollee")
517f76b1
JM
1994 wait_auth_success(dev[0], hapd, configurator=dev[0], enrollee=hapd,
1995 stop_responder=True)
c8b19de2
JM
1996
1997def test_dpp_qr_code_hostapd_init_offchannel(dev, apdev):
1998 """DPP QR Code and hostapd as initiator (offchannel)"""
1999 run_dpp_qr_code_hostapd_init_offchannel(dev, apdev, None)
2000
2001def test_dpp_qr_code_hostapd_init_offchannel_neg_freq(dev, apdev):
2002 """DPP QR Code and hostapd as initiator (offchannel, neg_freq)"""
2003 run_dpp_qr_code_hostapd_init_offchannel(dev, apdev, "neg_freq=2437")
2004
2005def run_dpp_qr_code_hostapd_init_offchannel(dev, apdev, extra):
2006 check_dpp_capab(dev[0])
fab49f61
JM
2007 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured",
2008 "channel": "6"})
c8b19de2 2009 check_dpp_capab(hapd)
e105110f 2010 conf_id = dev[0].dpp_configurator_add()
a5387062 2011 id0 = dev[0].dpp_bootstrap_gen(chan="81/1,81/11", mac=True)
c8b19de2 2012 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
c8b19de2 2013 dev[0].set("dpp_configurator_params",
58be42b2 2014 " conf=ap-dpp configurator=%d" % conf_id)
7e009100 2015 dev[0].dpp_listen(2462, role="configurator")
5725b3e3 2016 hapd.dpp_auth_init(uri=uri0, role="enrollee", extra=extra)
517f76b1
JM
2017 wait_auth_success(dev[0], hapd, configurator=dev[0], enrollee=hapd,
2018 stop_responder=True)
359dc93d 2019
055cd397
JM
2020def test_dpp_test_vector_p_256(dev, apdev):
2021 """DPP P-256 test vector (mutual auth)"""
2022 check_dpp_capab(dev[0])
2023 check_dpp_capab(dev[1])
2024
2025 # Responder bootstrapping key
2026 priv = "54ce181a98525f217216f59b245f60e9df30ac7f6b26c939418cfc3c42d1afa0"
a5387062 2027 id0 = dev[0].dpp_bootstrap_gen(chan="81/11", mac=True, key="30310201010420" + priv + "a00a06082a8648ce3d030107")
055cd397
JM
2028 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
2029
2030 # Responder protocol keypair override
2031 priv = "f798ed2e19286f6a6efe210b1863badb99af2a14b497634dbfd2a97394fb5aa5"
2032 dev[0].set("dpp_protocol_key_override",
2033 "30310201010420" + priv + "a00a06082a8648ce3d030107")
2034
2035 dev[0].set("dpp_nonce_override", "3d0cfb011ca916d796f7029ff0b43393")
2036
2037 # Initiator bootstrapping key
2038 priv = "15b2a83c5a0a38b61f2aa8200ee4994b8afdc01c58507d10d0a38f7eedf051bb"
a5387062 2039 id1 = dev[1].dpp_bootstrap_gen(key="30310201010420" + priv + "a00a06082a8648ce3d030107")
055cd397
JM
2040 uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
2041
2042 # Initiator protocol keypair override
2043 priv = "a87de9afbb406c96e5f79a3df895ecac3ad406f95da66314c8cb3165e0c61783"
2044 dev[1].set("dpp_protocol_key_override",
2045 "30310201010420" + priv + "a00a06082a8648ce3d030107")
2046
2047 dev[1].set("dpp_nonce_override", "13f4602a16daeb69712263b9c46cba31")
2048
5725b3e3 2049 dev[0].dpp_qr_code(uri1)
7e009100 2050 dev[0].dpp_listen(2462, qr="mutual")
5725b3e3 2051 dev[1].dpp_auth_init(uri=uri0, own=id1, neg_freq=2412)
517f76b1 2052 wait_auth_success(dev[0], dev[1])
055cd397
JM
2053
2054def test_dpp_test_vector_p_256_b(dev, apdev):
2055 """DPP P-256 test vector (Responder-only auth)"""
2056 check_dpp_capab(dev[0])
2057 check_dpp_capab(dev[1])
2058
2059 # Responder bootstrapping key
2060 priv = "54ce181a98525f217216f59b245f60e9df30ac7f6b26c939418cfc3c42d1afa0"
a5387062 2061 id0 = dev[0].dpp_bootstrap_gen(chan="81/11", mac=True, key="30310201010420" + priv + "a00a06082a8648ce3d030107")
055cd397
JM
2062 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
2063
2064 # Responder protocol keypair override
2065 priv = "f798ed2e19286f6a6efe210b1863badb99af2a14b497634dbfd2a97394fb5aa5"
2066 dev[0].set("dpp_protocol_key_override",
2067 "30310201010420" + priv + "a00a06082a8648ce3d030107")
2068
2069 dev[0].set("dpp_nonce_override", "3d0cfb011ca916d796f7029ff0b43393")
2070
2071 # Initiator bootstrapping key
2072 priv = "15b2a83c5a0a38b61f2aa8200ee4994b8afdc01c58507d10d0a38f7eedf051bb"
a5387062 2073 id1 = dev[1].dpp_bootstrap_gen(key="30310201010420" + priv + "a00a06082a8648ce3d030107")
055cd397
JM
2074 uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
2075
2076 # Initiator protocol keypair override
2077 priv = "a87de9afbb406c96e5f79a3df895ecac3ad406f95da66314c8cb3165e0c61783"
2078 dev[1].set("dpp_protocol_key_override",
2079 "30310201010420" + priv + "a00a06082a8648ce3d030107")
2080
2081 dev[1].set("dpp_nonce_override", "13f4602a16daeb69712263b9c46cba31")
2082
7e009100 2083 dev[0].dpp_listen(2462)
5725b3e3 2084 dev[1].dpp_auth_init(uri=uri0, own=id1, neg_freq=2412)
517f76b1 2085 wait_auth_success(dev[0], dev[1])
055cd397 2086
9a3acf43
JM
2087def der_priv_key_p_521(priv):
2088 if len(priv) != 2 * 66:
2089 raise Exception("Unexpected der_priv_key_p_521 parameter: " + priv)
2090 der_prefix = "3081500201010442"
2091 der_postfix = "a00706052b81040023"
2092 return der_prefix + priv + der_postfix
2093
2094def test_dpp_test_vector_p_521(dev, apdev):
2095 """DPP P-521 test vector (mutual auth)"""
2096 check_dpp_capab(dev[0])
2097 check_dpp_capab(dev[1])
2098
2099 # Responder bootstrapping key
2100 priv = "0061e54f518cdf859735da3dd64c6f72c2f086f41a6fd52915152ea2fe0f24ddaecd8883730c9c9fd82cf7c043a41021696388cf5190b731dd83638bcd56d8b6c743"
a5387062
JM
2101 id0 = dev[0].dpp_bootstrap_gen(chan="81/11", mac=True,
2102 key=der_priv_key_p_521(priv))
9a3acf43
JM
2103 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
2104
2105 # Responder protocol keypair override
2106 priv = "01d8b7b17cd1b0a33f7c66fb4220999329cdaf4f8b44b2ffadde8ab8ed8abffa9f5358c5b1caae26709ca4fb78e52a4d08f2e4f24111a36a6f440d20a0000ff51597"
2107 dev[0].set("dpp_protocol_key_override", der_priv_key_p_521(priv))
2108
2109 dev[0].set("dpp_nonce_override",
2110 "d749a782012eb0a8595af30b2dfc8d0880d004ebddb55ecc5afbdef18c400e01")
2111
2112 # Initiator bootstrapping key
2113 priv = "0060c10df14af5ef27f6e362d31bdd9eeb44be77a323ba64b08f3f03d58b92cbfe05c182a91660caa081ca344243c47b5aa088bcdf738840eb35f0218b9f26881e02"
a5387062 2114 id1 = dev[1].dpp_bootstrap_gen(key=der_priv_key_p_521(priv))
9a3acf43
JM
2115 uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
2116
2117 # Initiator protocol keypair override
2118 priv = "019c1c08caaeec38fb931894699b095bc3ab8c1ec7ef0622d2e3eba821477c8c6fca41774f21166ad98aebda37c067d9aa08a8a2e1b5c44c61f2bae02a61f85d9661"
2119 dev[1].set("dpp_protocol_key_override", der_priv_key_p_521(priv))
2120
2121 dev[1].set("dpp_nonce_override",
2122 "de972af3847bec3ba2aedd9f5c21cfdec7bf0bc5fe8b276cbcd0267807fb15b0")
2123
5725b3e3 2124 dev[0].dpp_qr_code(uri1)
7e009100 2125 dev[0].dpp_listen(2462, qr="mutual")
5725b3e3 2126 dev[1].dpp_auth_init(uri=uri0, own=id1, neg_freq=2412)
517f76b1 2127 wait_auth_success(dev[0], dev[1])
9a3acf43 2128
34a5c762
JM
2129def test_dpp_pkex(dev, apdev):
2130 """DPP and PKEX"""
2131 run_dpp_pkex(dev, apdev)
2132
2133def test_dpp_pkex_p256(dev, apdev):
2134 """DPP and PKEX (P-256)"""
2135 run_dpp_pkex(dev, apdev, "P-256")
2136
2137def test_dpp_pkex_p384(dev, apdev):
2138 """DPP and PKEX (P-384)"""
2139 run_dpp_pkex(dev, apdev, "P-384")
2140
2141def test_dpp_pkex_p521(dev, apdev):
2142 """DPP and PKEX (P-521)"""
2143 run_dpp_pkex(dev, apdev, "P-521")
2144
2145def test_dpp_pkex_bp256(dev, apdev):
2146 """DPP and PKEX (BP-256)"""
2147 run_dpp_pkex(dev, apdev, "brainpoolP256r1")
2148
2149def test_dpp_pkex_bp384(dev, apdev):
2150 """DPP and PKEX (BP-384)"""
2151 run_dpp_pkex(dev, apdev, "brainpoolP384r1")
2152
2153def test_dpp_pkex_bp512(dev, apdev):
2154 """DPP and PKEX (BP-512)"""
2155 run_dpp_pkex(dev, apdev, "brainpoolP512r1")
2156
2157def test_dpp_pkex_config(dev, apdev):
2158 """DPP and PKEX with initiator as the configurator"""
4874f5ba 2159 check_dpp_capab(dev[1])
e105110f 2160 conf_id = dev[1].dpp_configurator_add()
34a5c762
JM
2161 run_dpp_pkex(dev, apdev,
2162 init_extra="conf=sta-dpp configurator=%d" % (conf_id),
2163 check_config=True)
2164
eb390abb
JM
2165def test_dpp_pkex_no_identifier(dev, apdev):
2166 """DPP and PKEX without identifier"""
2167 run_dpp_pkex(dev, apdev, identifier_i=None, identifier_r=None)
2168
2169def test_dpp_pkex_identifier_mismatch(dev, apdev):
2170 """DPP and PKEX with different identifiers"""
2171 run_dpp_pkex(dev, apdev, identifier_i="foo", identifier_r="bar",
2172 expect_no_resp=True)
2173
2174def test_dpp_pkex_identifier_mismatch2(dev, apdev):
2175 """DPP and PKEX with initiator using identifier and the responder not"""
2176 run_dpp_pkex(dev, apdev, identifier_i="foo", identifier_r=None,
2177 expect_no_resp=True)
2178
2179def test_dpp_pkex_identifier_mismatch3(dev, apdev):
2180 """DPP and PKEX with responder using identifier and the initiator not"""
2181 run_dpp_pkex(dev, apdev, identifier_i=None, identifier_r="bar",
2182 expect_no_resp=True)
2183
6d196e59 2184def run_dpp_pkex(dev, apdev, curve=None, init_extra=None, check_config=False,
eb390abb
JM
2185 identifier_i="test", identifier_r="test",
2186 expect_no_resp=False):
d584946e
JM
2187 check_dpp_capab(dev[0], curve and "brainpool" in curve)
2188 check_dpp_capab(dev[1], curve and "brainpool" in curve)
6d196e59
JM
2189 dev[0].dpp_pkex_resp(2437, identifier=identifier_r, code="secret",
2190 curve=curve)
2191 dev[1].dpp_pkex_init(identifier=identifier_i, code="secret", curve=curve,
2192 extra=init_extra)
34a5c762 2193
eb390abb
JM
2194 if expect_no_resp:
2195 ev = dev[0].wait_event(["DPP-RX"], timeout=10)
2196 if ev is None:
2197 raise Exception("DPP PKEX frame not received")
2198 ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=1)
2199 if ev is not None:
2200 raise Exception("DPP authentication succeeded")
2201 ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=0.1)
2202 if ev is not None:
2203 raise Exception("DPP authentication succeeded")
2204 return
2205
517f76b1
JM
2206 wait_auth_success(dev[0], dev[1],
2207 configurator=dev[1] if check_config else None,
2208 enrollee=dev[0] if check_config else None)
34a5c762 2209
4370ffc0
JM
2210def test_dpp_pkex_5ghz(dev, apdev):
2211 """DPP and PKEX on 5 GHz"""
2212 try:
2213 dev[0].request("SET country US")
2214 dev[1].request("SET country US")
2215 ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
2216 if ev is None:
2217 ev = dev[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"],
2218 timeout=1)
2219 run_dpp_pkex_5ghz(dev, apdev)
2220 finally:
2221 dev[0].request("SET country 00")
2222 dev[1].request("SET country 00")
2223 subprocess.call(['iw', 'reg', 'set', '00'])
ba3146e1 2224 time.sleep(0.1)
4370ffc0
JM
2225
2226def run_dpp_pkex_5ghz(dev, apdev):
2227 check_dpp_capab(dev[0])
2228 check_dpp_capab(dev[1])
6d196e59
JM
2229 dev[0].dpp_pkex_resp(5745, identifier="test", code="secret")
2230 dev[1].dpp_pkex_init(identifier="test", code="secret")
517f76b1 2231 wait_auth_success(dev[0], dev[1], timeout=20)
4370ffc0 2232
5da4b2f3
JM
2233def test_dpp_pkex_test_vector(dev, apdev):
2234 """DPP and PKEX (P-256) test vector"""
2235 check_dpp_capab(dev[0])
2236 check_dpp_capab(dev[1])
2d7aa8d5 2237
8f9d2b17
JM
2238 init_addr = "ac:64:91:f4:52:07"
2239 resp_addr = "6e:5e:ce:6e:f3:dd"
2d7aa8d5 2240
5da4b2f3
JM
2241 identifier = "joes_key"
2242 code = "thisisreallysecret"
2243
2d7aa8d5
JM
2244 # Initiator bootstrapping private key
2245 init_priv = "5941b51acfc702cdc1c347264beb2920db88eb1a0bf03a211868b1632233c269"
2246
2247 # Responder bootstrapping private key
2248 resp_priv = "2ae8956293f49986b6d0b8169a86805d9232babb5f6813fdfe96f19d59536c60"
2249
2250 # Initiator x/X keypair override
8f9d2b17 2251 init_x_priv = "8365c5ed93d751bef2d92b410dc6adfd95670889183fac1bd66759ad85c3187a"
2d7aa8d5
JM
2252
2253 # Responder y/Y keypair override
8f9d2b17 2254 resp_y_priv = "d98faa24d7dd3f592665d71a95c862bfd02c4c48acb0c515a41cbc6e929675ea"
2d7aa8d5
JM
2255
2256 p256_prefix = "30310201010420"
2257 p256_postfix = "a00a06082a8648ce3d030107"
2258
2259 dev[0].set("dpp_pkex_own_mac_override", resp_addr)
2260 dev[0].set("dpp_pkex_peer_mac_override", init_addr)
2261 dev[1].set("dpp_pkex_own_mac_override", init_addr)
2262 dev[1].set("dpp_pkex_peer_mac_override", resp_addr)
2263
5da4b2f3 2264 # Responder y/Y keypair override
5da4b2f3 2265 dev[0].set("dpp_pkex_ephemeral_key_override",
2d7aa8d5 2266 p256_prefix + resp_y_priv + p256_postfix)
5da4b2f3 2267
5da4b2f3 2268 # Initiator x/X keypair override
5da4b2f3 2269 dev[1].set("dpp_pkex_ephemeral_key_override",
2d7aa8d5 2270 p256_prefix + init_x_priv + p256_postfix)
5da4b2f3 2271
6d196e59
JM
2272 dev[0].dpp_pkex_resp(2437, identifier=identifier, code=code,
2273 key=p256_prefix + resp_priv + p256_postfix)
2274 dev[1].dpp_pkex_init(identifier=identifier, code=code,
2275 key=p256_prefix + init_priv + p256_postfix)
517f76b1 2276 wait_auth_success(dev[0], dev[1])
5da4b2f3 2277
d592d134
JM
2278def test_dpp_pkex_code_mismatch(dev, apdev):
2279 """DPP and PKEX with mismatching code"""
2280 check_dpp_capab(dev[0])
2281 check_dpp_capab(dev[1])
6d196e59
JM
2282 dev[0].dpp_pkex_resp(2437, identifier="test", code="secret")
2283 id1 = dev[1].dpp_pkex_init(identifier="test", code="unknown")
203878d7 2284 wait_dpp_fail(dev[0], "possible PKEX code mismatch")
84d53c77
JM
2285 dev[0].dump_monitor()
2286 dev[1].dump_monitor()
6d196e59 2287 dev[1].dpp_pkex_init(identifier="test", code="secret", use_id=id1)
517f76b1 2288 wait_auth_success(dev[0], dev[1])
84d53c77 2289
aa485b0e
JM
2290def test_dpp_pkex_code_mismatch_limit(dev, apdev):
2291 """DPP and PKEX with mismatching code limit"""
2292 check_dpp_capab(dev[0])
2293 check_dpp_capab(dev[1])
6d196e59 2294 dev[0].dpp_pkex_resp(2437, identifier="test", code="secret")
aa485b0e 2295
6d196e59 2296 id1 = None
aa485b0e
JM
2297 for i in range(5):
2298 dev[0].dump_monitor()
2299 dev[1].dump_monitor()
6d196e59
JM
2300 id1 = dev[1].dpp_pkex_init(identifier="test", code="unknown",
2301 use_id=id1)
203878d7 2302 wait_dpp_fail(dev[0], "possible PKEX code mismatch")
aa485b0e
JM
2303
2304 ev = dev[0].wait_event(["DPP-PKEX-T-LIMIT"], timeout=1)
2305 if ev is None:
2306 raise Exception("PKEX t limit not reported")
2307
dab56420
JM
2308def test_dpp_pkex_curve_mismatch(dev, apdev):
2309 """DPP and PKEX with mismatching curve"""
2310 check_dpp_capab(dev[0])
2311 check_dpp_capab(dev[1])
6d196e59
JM
2312 dev[0].dpp_pkex_resp(2437, identifier="test", code="secret", curve="P-256")
2313 dev[1].dpp_pkex_init(identifier="test", code="secret", curve="P-384")
203878d7
JM
2314 wait_dpp_fail(dev[0], "Mismatching PKEX curve: peer=20 own=19")
2315 wait_dpp_fail(dev[1], "Peer indicated mismatching PKEX group - proposed 19")
dab56420 2316
6026ed0d
JM
2317def test_dpp_pkex_curve_mismatch_failure(dev, apdev):
2318 """DPP and PKEX with mismatching curve (local failure)"""
2319 run_dpp_pkex_curve_mismatch_failure(dev, apdev, "=dpp_pkex_rx_exchange_req")
2320
2321def test_dpp_pkex_curve_mismatch_failure2(dev, apdev):
2322 """DPP and PKEX with mismatching curve (local failure 2)"""
2323 run_dpp_pkex_curve_mismatch_failure(dev, apdev,
2324 "dpp_pkex_build_exchange_resp")
2325
2326def run_dpp_pkex_curve_mismatch_failure(dev, apdev, func):
2327 check_dpp_capab(dev[0])
2328 check_dpp_capab(dev[1])
6d196e59 2329 dev[0].dpp_pkex_resp(2437, identifier="test", code="secret", curve="P-256")
6026ed0d
JM
2330
2331 with alloc_fail(dev[0], 1, func):
6d196e59 2332 dev[1].dpp_pkex_init(identifier="test", code="secret", curve="P-384")
6026ed0d
JM
2333
2334 ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
2335 if ev is None:
2336 raise Exception("Failure not reported (dev 0)")
2337 if "Mismatching PKEX curve: peer=20 own=19" not in ev:
2338 raise Exception("Unexpected result: " + ev)
203878d7 2339 wait_dpp_fail(dev[0], "Mismatching PKEX curve: peer=20 own=19")
6026ed0d 2340
a7758916
JM
2341def test_dpp_pkex_exchange_resp_processing_failure(dev, apdev):
2342 """DPP and PKEX with local failure in processing Exchange Resp"""
2343 check_dpp_capab(dev[0])
2344 check_dpp_capab(dev[1])
6d196e59 2345 dev[0].dpp_pkex_resp(2437, identifier="test", code="secret")
a7758916
JM
2346
2347 with fail_test(dev[1], 1, "dpp_pkex_derive_Qr;dpp_pkex_rx_exchange_resp"):
6d196e59 2348 dev[1].dpp_pkex_init(identifier="test", code="secret")
a7758916
JM
2349 wait_fail_trigger(dev[1], "GET_FAIL")
2350
24c4200d
JM
2351def test_dpp_pkex_commit_reveal_req_processing_failure(dev, apdev):
2352 """DPP and PKEX with local failure in processing Commit Reveal Req"""
2353 check_dpp_capab(dev[0])
2354 check_dpp_capab(dev[1])
6d196e59 2355 dev[0].dpp_pkex_resp(2437, identifier="test", code="secret")
24c4200d
JM
2356
2357 with alloc_fail(dev[0], 1,
2358 "dpp_get_pubkey_point;dpp_pkex_rx_commit_reveal_req"):
6d196e59 2359 dev[1].dpp_pkex_init(identifier="test", code="secret")
24c4200d
JM
2360 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
2361
34a5c762
JM
2362def test_dpp_pkex_config2(dev, apdev):
2363 """DPP and PKEX with responder as the configurator"""
4874f5ba 2364 check_dpp_capab(dev[0])
e105110f 2365 conf_id = dev[0].dpp_configurator_add()
34a5c762 2366 dev[0].set("dpp_configurator_params",
58be42b2 2367 " conf=sta-dpp configurator=%d" % conf_id)
34a5c762
JM
2368 run_dpp_pkex2(dev, apdev)
2369
2370def run_dpp_pkex2(dev, apdev, curve=None, init_extra=""):
2371 check_dpp_capab(dev[0])
2372 check_dpp_capab(dev[1])
6d196e59
JM
2373 dev[0].dpp_pkex_resp(2437, identifier="test", code="secret", curve=curve,
2374 listen_role="configurator")
2375 dev[1].dpp_pkex_init(identifier="test", code="secret", role="enrollee",
2376 curve=curve, extra=init_extra)
517f76b1 2377 wait_auth_success(dev[0], dev[1], configurator=dev[0], enrollee=dev[1])
163f76de 2378
169e341e
JM
2379def test_dpp_pkex_no_responder(dev, apdev):
2380 """DPP and PKEX with no responder (retry behavior)"""
2381 check_dpp_capab(dev[0])
6d196e59 2382 dev[0].dpp_pkex_init(identifier="test", code="secret")
169e341e 2383
5a5529c9
JM
2384 for i in range(15):
2385 ev = dev[0].wait_event(["DPP-TX ", "DPP-FAIL"], timeout=5)
2386 if ev is None:
2387 raise Exception("DPP PKEX failure not reported")
2388 if "DPP-FAIL" not in ev:
2389 continue
2390 if "No response from PKEX peer" not in ev:
2391 raise Exception("Unexpected failure reason: " + ev)
2392 break
169e341e
JM
2393
2394def test_dpp_pkex_after_retry(dev, apdev):
2395 """DPP and PKEX completing after retry"""
2396 check_dpp_capab(dev[0])
6d196e59 2397 dev[0].dpp_pkex_init(identifier="test", code="secret")
169e341e 2398 time.sleep(0.1)
6d196e59 2399 dev[1].dpp_pkex_resp(2437, identifier="test", code="secret")
517f76b1
JM
2400 wait_auth_success(dev[1], dev[0], configurator=dev[0], enrollee=dev[1],
2401 allow_enrollee_failure=True)
169e341e 2402
163f76de
JM
2403def test_dpp_pkex_hostapd_responder(dev, apdev):
2404 """DPP PKEX with hostapd as responder"""
2405 check_dpp_capab(dev[0])
fab49f61
JM
2406 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured",
2407 "channel": "6"})
163f76de 2408 check_dpp_capab(hapd)
6d196e59 2409 hapd.dpp_pkex_resp(2437, identifier="test", code="secret")
e105110f 2410 conf_id = dev[0].dpp_configurator_add()
6d196e59
JM
2411 dev[0].dpp_pkex_init(identifier="test", code="secret",
2412 extra="conf=ap-dpp configurator=%d" % conf_id)
517f76b1
JM
2413 wait_auth_success(hapd, dev[0], configurator=dev[0], enrollee=hapd,
2414 stop_initiator=True)
163f76de
JM
2415
2416def test_dpp_pkex_hostapd_initiator(dev, apdev):
2417 """DPP PKEX with hostapd as initiator"""
2418 check_dpp_capab(dev[0])
fab49f61
JM
2419 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured",
2420 "channel": "6"})
163f76de 2421 check_dpp_capab(hapd)
e105110f 2422 conf_id = dev[0].dpp_configurator_add()
163f76de 2423 dev[0].set("dpp_configurator_params",
58be42b2 2424 " conf=ap-dpp configurator=%d" % conf_id)
6d196e59
JM
2425 dev[0].dpp_pkex_resp(2437, identifier="test", code="secret",
2426 listen_role="configurator")
2427 hapd.dpp_pkex_init(identifier="test", code="secret", role="enrollee")
517f76b1
JM
2428 wait_auth_success(hapd, dev[0], configurator=dev[0], enrollee=hapd,
2429 stop_initiator=True)
0651dfb7
JM
2430
2431def test_dpp_hostapd_configurator(dev, apdev):
2432 """DPP with hostapd as configurator/initiator"""
2433 check_dpp_capab(dev[0])
fab49f61
JM
2434 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured",
2435 "channel": "1"})
0651dfb7 2436 check_dpp_capab(hapd)
e105110f 2437 conf_id = hapd.dpp_configurator_add()
a5387062 2438 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
0651dfb7 2439 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
0422d06b 2440 id1 = hapd.dpp_qr_code(uri0)
5725b3e3 2441 res = hapd.request("DPP_BOOTSTRAP_INFO %d" % id1)
97136c83
JM
2442 if "FAIL" in res:
2443 raise Exception("DPP_BOOTSTRAP_INFO failed")
2444 if "type=QRCODE" not in res:
2445 raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
2446 if "mac_addr=" + dev[0].own_addr() not in res:
2447 raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
7e009100 2448 dev[0].dpp_listen(2412)
5725b3e3 2449 hapd.dpp_auth_init(peer=id1, configurator=conf_id, conf="sta-dpp")
517f76b1
JM
2450 wait_auth_success(dev[0], hapd, configurator=hapd, enrollee=dev[0],
2451 stop_responder=True)
0651dfb7
JM
2452
2453def test_dpp_hostapd_configurator_responder(dev, apdev):
2454 """DPP with hostapd as configurator/responder"""
2455 check_dpp_capab(dev[0])
fab49f61
JM
2456 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured",
2457 "channel": "1"})
0651dfb7 2458 check_dpp_capab(hapd)
e105110f 2459 conf_id = hapd.dpp_configurator_add()
0651dfb7 2460 hapd.set("dpp_configurator_params",
58be42b2 2461 " conf=sta-dpp configurator=%d" % conf_id)
a5387062 2462 id0 = hapd.dpp_bootstrap_gen(chan="81/1", mac=True)
0651dfb7 2463 uri0 = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
5725b3e3 2464 dev[0].dpp_auth_init(uri=uri0, role="enrollee")
517f76b1
JM
2465 wait_auth_success(hapd, dev[0], configurator=hapd, enrollee=dev[0],
2466 stop_initiator=True)
854d0de3
JM
2467
2468def test_dpp_own_config(dev, apdev):
2469 """DPP configurator signing own connector"""
2470 try:
2471 run_dpp_own_config(dev, apdev)
2472 finally:
5bf51d38 2473 dev[0].set("dpp_config_processing", "0", allow_fail=True)
854d0de3 2474
2697e85e
JM
2475def test_dpp_own_config_group_id(dev, apdev):
2476 """DPP configurator signing own connector"""
2477 try:
2478 run_dpp_own_config(dev, apdev, extra=" group_id=test-group")
2479 finally:
5bf51d38 2480 dev[0].set("dpp_config_processing", "0", allow_fail=True)
2697e85e 2481
854d0de3
JM
2482def test_dpp_own_config_curve_mismatch(dev, apdev):
2483 """DPP configurator signing own connector using mismatching curve"""
2484 try:
2485 run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
2486 finally:
5bf51d38 2487 dev[0].set("dpp_config_processing", "0", allow_fail=True)
854d0de3 2488
2697e85e 2489def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False,
5725b3e3 2490 extra=None):
d584946e 2491 check_dpp_capab(dev[0], own_curve and "BP" in own_curve)
fab49f61 2492 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
854d0de3 2493 check_dpp_capab(hapd)
a5387062 2494 id_h = hapd.dpp_bootstrap_gen(chan="81/1", mac=True)
854d0de3 2495 uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
e105110f 2496 conf_id = dev[0].dpp_configurator_add()
5725b3e3
JM
2497 dev[0].dpp_auth_init(uri=uri, conf="ap-dpp", configurator=conf_id,
2498 extra=extra)
517f76b1 2499 wait_auth_success(hapd, dev[0], configurator=dev[0], enrollee=hapd)
854d0de3
JM
2500 update_hapd_config(hapd)
2501
2502 dev[0].set("dpp_config_processing", "1")
9552a736 2503 cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d%s" % (conf_id, extra)
854d0de3
JM
2504 if own_curve:
2505 cmd += " curve=" + own_curve
2506 res = dev[0].request(cmd)
2507 if "FAIL" in res:
2508 raise Exception("Failed to generate own configuration")
2509
2510 ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
2511 if ev is None:
2512 raise Exception("DPP network profile not generated")
2513 id = ev.split(' ')[1]
2514 dev[0].select_network(id, freq="2412")
2515 if expect_failure:
2516 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
2517 if ev is not None:
58be42b2 2518 raise Exception("Unexpected connection")
854d0de3
JM
2519 dev[0].request("DISCONNECT")
2520 else:
2521 dev[0].wait_connected()
a0e3e222 2522
73a7feb3
JM
2523def test_dpp_own_config_ap(dev, apdev):
2524 """DPP configurator (AP) signing own connector"""
2525 try:
2526 run_dpp_own_config_ap(dev, apdev)
2527 finally:
5bf51d38 2528 dev[0].set("dpp_config_processing", "0", allow_fail=True)
73a7feb3 2529
2697e85e
JM
2530def test_dpp_own_config_ap_group_id(dev, apdev):
2531 """DPP configurator (AP) signing own connector (group_id)"""
2532 try:
2533 run_dpp_own_config_ap(dev, apdev, extra=" group_id=test-group")
2534 finally:
5bf51d38 2535 dev[0].set("dpp_config_processing", "0", allow_fail=True)
2697e85e 2536
0c061630
JM
2537def test_dpp_own_config_ap_reconf(dev, apdev):
2538 """DPP configurator (AP) signing own connector and configurator reconf"""
2539 try:
2540 run_dpp_own_config_ap(dev, apdev)
2541 finally:
5bf51d38 2542 dev[0].set("dpp_config_processing", "0", allow_fail=True)
0c061630 2543
5725b3e3 2544def run_dpp_own_config_ap(dev, apdev, reconf_configurator=False, extra=None):
73a7feb3 2545 check_dpp_capab(dev[0])
fab49f61 2546 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
73a7feb3 2547 check_dpp_capab(hapd)
e105110f 2548 conf_id = hapd.dpp_configurator_add()
0c061630
JM
2549 if reconf_configurator:
2550 csign = hapd.request("DPP_CONFIGURATOR_GET_KEY %d" % conf_id)
2551 if "FAIL" in csign or len(csign) == 0:
2552 raise Exception("DPP_CONFIGURATOR_GET_KEY failed")
2553
9552a736 2554 cmd = "DPP_CONFIGURATOR_SIGN conf=ap-dpp configurator=%d%s" % (conf_id, extra)
73a7feb3
JM
2555 res = hapd.request(cmd)
2556 if "FAIL" in res:
2557 raise Exception("Failed to generate own configuration")
2558 update_hapd_config(hapd)
2559
0c061630 2560 if reconf_configurator:
e105110f
JM
2561 hapd.dpp_configurator_remove(conf_id)
2562 conf_id = hapd.dpp_configurator_add(key=csign)
0c061630 2563
a5387062 2564 id = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
73a7feb3 2565 uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
73a7feb3 2566 dev[0].set("dpp_config_processing", "2")
7e009100 2567 dev[0].dpp_listen(2412)
5725b3e3
JM
2568 hapd.dpp_auth_init(uri=uri, conf="sta-dpp", configurator=conf_id,
2569 extra=extra)
517f76b1 2570 wait_auth_success(dev[0], hapd, configurator=hapd, enrollee=dev[0])
73a7feb3
JM
2571 dev[0].wait_connected()
2572
d045b7a1
JM
2573def test_dpp_intro_mismatch(dev, apdev):
2574 """DPP network introduction mismatch cases"""
2575 try:
2576 wpas = None
2577 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
2578 wpas.interface_add("wlan5")
2579 check_dpp_capab(wpas)
2580 run_dpp_intro_mismatch(dev, apdev, wpas)
2581 finally:
5bf51d38
JM
2582 dev[0].set("dpp_config_processing", "0", allow_fail=True)
2583 dev[2].set("dpp_config_processing", "0", allow_fail=True)
d045b7a1 2584 if wpas:
5bf51d38 2585 wpas.set("dpp_config_processing", "0", allow_fail=True)
d045b7a1
JM
2586
2587def run_dpp_intro_mismatch(dev, apdev, wpas):
2588 check_dpp_capab(dev[0])
2589 check_dpp_capab(dev[1])
2590 check_dpp_capab(dev[2])
d045b7a1 2591 logger.info("Start AP in unconfigured state")
fab49f61 2592 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
d045b7a1 2593 check_dpp_capab(hapd)
a5387062 2594 id_h = hapd.dpp_bootstrap_gen(chan="81/1", mac=True)
d045b7a1 2595 uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
d045b7a1 2596 logger.info("Provision AP with DPP configuration")
e105110f 2597 conf_id = dev[1].dpp_configurator_add()
d045b7a1 2598 dev[1].set("dpp_groups_override", '[{"groupId":"a","netRole":"ap"}]')
5725b3e3 2599 dev[1].dpp_auth_init(uri=uri, conf="ap-dpp", configurator=conf_id)
d045b7a1
JM
2600 update_hapd_config(hapd)
2601
2602 logger.info("Provision STA0 with DPP Connector that has mismatching groupId")
2603 dev[0].set("dpp_config_processing", "2")
a5387062 2604 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
d045b7a1 2605 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
7e009100 2606 dev[0].dpp_listen(2412)
d045b7a1 2607 dev[1].set("dpp_groups_override", '[{"groupId":"b","netRole":"sta"}]')
5725b3e3
JM
2608 dev[1].dpp_auth_init(uri=uri0, conf="sta-dpp", configurator=conf_id)
2609 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0])
d045b7a1
JM
2610
2611 logger.info("Provision STA2 with DPP Connector that has mismatching C-sign-key")
2612 dev[2].set("dpp_config_processing", "2")
a5387062 2613 id2 = dev[2].dpp_bootstrap_gen(chan="81/1", mac=True)
d045b7a1 2614 uri2 = dev[2].request("DPP_BOOTSTRAP_GET_URI %d" % id2)
7e009100 2615 dev[2].dpp_listen(2412)
e105110f 2616 conf_id_2 = dev[1].dpp_configurator_add()
d045b7a1 2617 dev[1].set("dpp_groups_override", '')
5725b3e3
JM
2618 dev[1].dpp_auth_init(uri=uri2, conf="sta-dpp", configurator=conf_id_2)
2619 wait_auth_success(dev[2], dev[1], configurator=dev[1], enrollee=dev[2])
d045b7a1
JM
2620
2621 logger.info("Provision STA5 with DPP Connector that has mismatching netAccessKey EC group")
2622 wpas.set("dpp_config_processing", "2")
a5387062 2623 id5 = wpas.dpp_bootstrap_gen(chan="81/1", mac=True, curve="P-521")
d045b7a1 2624 uri5 = wpas.request("DPP_BOOTSTRAP_GET_URI %d" % id5)
7e009100 2625 wpas.dpp_listen(2412)
d045b7a1 2626 dev[1].set("dpp_groups_override", '')
5725b3e3
JM
2627 dev[1].dpp_auth_init(uri=uri5, conf="sta-dpp", configurator=conf_id)
2628 wait_auth_success(wpas, dev[1], configurator=dev[1], enrollee=wpas)
d045b7a1
JM
2629
2630 logger.info("Verify network introduction results")
2631 ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
2632 if ev is None:
2633 raise Exception("DPP network introduction result not seen on STA0")
2634 if "status=8" not in ev:
2635 raise Exception("Unexpected network introduction result on STA0: " + ev)
2636
2637 ev = dev[2].wait_event(["DPP-INTRO"], timeout=5)
2638 if ev is None:
2639 raise Exception("DPP network introduction result not seen on STA2")
2640 if "status=8" not in ev:
2641 raise Exception("Unexpected network introduction result on STA2: " + ev)
2642
2643 ev = wpas.wait_event(["DPP-INTRO"], timeout=10)
2644 if ev is None:
2645 raise Exception("DPP network introduction result not seen on STA5")
2646 if "status=7" not in ev:
2647 raise Exception("Unexpected network introduction result on STA5: " + ev)
2648
8968acda 2649def run_dpp_proto_init(dev, test_dev, test, mutual=False, unicast=True,
4e72b1de
JM
2650 listen=True, chan="81/1", init_enrollee=False,
2651 incompatible_roles=False):
a0e3e222
JM
2652 check_dpp_capab(dev[0])
2653 check_dpp_capab(dev[1])
2654 dev[test_dev].set("dpp_test", str(test))
c30517c6 2655 if init_enrollee:
e105110f 2656 conf_id = dev[0].dpp_configurator_add()
c30517c6 2657 else:
e105110f 2658 conf_id = dev[1].dpp_configurator_add()
a5387062 2659 id0 = dev[0].dpp_bootstrap_gen(chan=chan, mac=unicast)
a0e3e222
JM
2660 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
2661
a0e3e222 2662 if mutual:
a5387062 2663 id1b = dev[1].dpp_bootstrap_gen(chan="81/1", mac=True)
a0e3e222
JM
2664 uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
2665
0422d06b 2666 id0b = dev[0].dpp_qr_code(uri1b)
7e009100 2667 qr = "mutual"
47183df7 2668 else:
7e009100 2669 qr = None
47183df7 2670
c30517c6 2671 if init_enrollee:
4e72b1de 2672 if incompatible_roles:
7e009100 2673 role = "enrollee"
4e72b1de 2674 else:
7e009100 2675 role = "configurator"
c30517c6 2676 dev[0].set("dpp_configurator_params",
58be42b2 2677 " conf=sta-dpp configurator=%d" % conf_id)
4e72b1de 2678 elif incompatible_roles:
7e009100
JM
2679 role = "enrollee"
2680 else:
2681 role = None
c30517c6 2682
8968acda 2683 if listen:
7e009100 2684 dev[0].dpp_listen(2412, qr=qr, role=role)
a0e3e222 2685
5725b3e3
JM
2686 role = None
2687 configurator = None
2688 conf = None
2689 own = None
2690
c30517c6 2691 if init_enrollee:
5725b3e3 2692 role="enrollee"
c30517c6 2693 else:
5725b3e3
JM
2694 configurator=conf_id
2695 conf="sta-dpp"
4e72b1de 2696 if incompatible_roles:
5725b3e3 2697 role="enrollee"
a0e3e222 2698 if mutual:
5725b3e3
JM
2699 own = id1b
2700 dev[1].dpp_auth_init(uri=uri0, role=role, configurator=configurator,
2701 conf=conf, own=own)
a0e3e222
JM
2702
2703def test_dpp_proto_after_wrapped_data_auth_req(dev, apdev):
2704 """DPP protocol testing - attribute after Wrapped Data in Auth Req"""
2705 run_dpp_proto_init(dev, 1, 1)
2706 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
2707 if ev is None:
2708 raise Exception("DPP Authentication Request not seen")
2709 if "type=0" not in ev or "ignore=invalid-attributes" not in ev:
2710 raise Exception("Unexpected RX info: " + ev)
2711 ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
2712 if ev is not None:
2713 raise Exception("Unexpected DPP message seen")
2714
8968acda
JM
2715def test_dpp_auth_req_stop_after_ack(dev, apdev):
2716 """DPP initiator stopping after ACK, but no response"""
2717 run_dpp_proto_init(dev, 1, 1, listen=True)
2718 ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
2719 if ev is None:
2720 raise Exception("Authentication failure not reported")
2721
2722def test_dpp_auth_req_retries(dev, apdev):
2723 """DPP initiator retries with no ACK"""
92fe5f56 2724 check_dpp_capab(dev[1])
8968acda
JM
2725 dev[1].set("dpp_init_max_tries", "3")
2726 dev[1].set("dpp_init_retry_time", "1000")
2727 dev[1].set("dpp_resp_wait_time", "100")
2728 run_dpp_proto_init(dev, 1, 1, unicast=False, listen=False)
2729
2730 for i in range(3):
edac8087 2731 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
8968acda
JM
2732 if ev is None:
2733 raise Exception("Auth Req not sent (%d)" % i)
8968acda
JM
2734
2735 ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
2736 if ev is None:
2737 raise Exception("Authentication failure not reported")
2738
2739def test_dpp_auth_req_retries_multi_chan(dev, apdev):
2740 """DPP initiator retries with no ACK and multiple channels"""
92fe5f56 2741 check_dpp_capab(dev[1])
8968acda
JM
2742 dev[1].set("dpp_init_max_tries", "3")
2743 dev[1].set("dpp_init_retry_time", "1000")
2744 dev[1].set("dpp_resp_wait_time", "100")
2745 run_dpp_proto_init(dev, 1, 1, unicast=False, listen=False,
2746 chan="81/1,81/6,81/11")
2747
2748 for i in range(3 * 3):
edac8087 2749 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
8968acda
JM
2750 if ev is None:
2751 raise Exception("Auth Req not sent (%d)" % i)
8968acda
JM
2752
2753 ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
2754 if ev is None:
2755 raise Exception("Authentication failure not reported")
2756
a0e3e222
JM
2757def test_dpp_proto_after_wrapped_data_auth_resp(dev, apdev):
2758 """DPP protocol testing - attribute after Wrapped Data in Auth Resp"""
2759 run_dpp_proto_init(dev, 0, 2)
2760 ev = dev[1].wait_event(["DPP-RX"], timeout=5)
2761 if ev is None:
2762 raise Exception("DPP Authentication Response not seen")
2763 if "type=1" not in ev or "ignore=invalid-attributes" not in ev:
2764 raise Exception("Unexpected RX info: " + ev)
2765 ev = dev[0].wait_event(["DPP-RX"], timeout=1)
2766 if ev is None or "type=0" not in ev:
2767 raise Exception("DPP Authentication Request not seen")
2768 ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
2769 if ev is not None:
2770 raise Exception("Unexpected DPP message seen")
2771
2772def test_dpp_proto_after_wrapped_data_auth_conf(dev, apdev):
2773 """DPP protocol testing - attribute after Wrapped Data in Auth Conf"""
2774 run_dpp_proto_init(dev, 1, 3)
2775 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
2776 if ev is None or "type=0" not in ev:
2777 raise Exception("DPP Authentication Request not seen")
2778 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
2779 if ev is None:
2780 raise Exception("DPP Authentication Confirm not seen")
2781 if "type=2" not in ev or "ignore=invalid-attributes" not in ev:
2782 raise Exception("Unexpected RX info: " + ev)
2783
2784def test_dpp_proto_after_wrapped_data_conf_req(dev, apdev):
2785 """DPP protocol testing - attribute after Wrapped Data in Conf Req"""
2786 run_dpp_proto_init(dev, 0, 6)
2787 ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=10)
2788 if ev is None:
2789 raise Exception("DPP Configuration failure not seen")
2790
2791def test_dpp_proto_after_wrapped_data_conf_resp(dev, apdev):
2792 """DPP protocol testing - attribute after Wrapped Data in Conf Resp"""
2793 run_dpp_proto_init(dev, 1, 7)
2794 ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=10)
2795 if ev is None:
2796 raise Exception("DPP Configuration failure not seen")
2797
2798def test_dpp_proto_zero_i_capab(dev, apdev):
2799 """DPP protocol testing - zero I-capability in Auth Req"""
2800 run_dpp_proto_init(dev, 1, 8)
203878d7 2801 wait_dpp_fail(dev[0], "Invalid role in I-capabilities 0x00")
a0e3e222
JM
2802 ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
2803 if ev is not None:
2804 raise Exception("Unexpected DPP message seen")
2805
2806def test_dpp_proto_zero_r_capab(dev, apdev):
2807 """DPP protocol testing - zero R-capability in Auth Resp"""
2808 run_dpp_proto_init(dev, 0, 9)
203878d7 2809 wait_dpp_fail(dev[1], "Unexpected role in R-capabilities 0x00")
a0e3e222
JM
2810 ev = dev[0].wait_event(["DPP-RX"], timeout=1)
2811 if ev is None or "type=0" not in ev:
2812 raise Exception("DPP Authentication Request not seen")
2813 ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
2814 if ev is not None:
2815 raise Exception("Unexpected DPP message seen")
2816
47183df7
JM
2817def run_dpp_proto_auth_req_missing(dev, test, reason, mutual=False):
2818 run_dpp_proto_init(dev, 1, test, mutual=mutual)
203878d7 2819 wait_dpp_fail(dev[0], reason)
a0e3e222
JM
2820 ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
2821 if ev is not None:
2822 raise Exception("Unexpected DPP message seen")
2823
2824def test_dpp_proto_auth_req_no_r_bootstrap_key(dev, apdev):
2825 """DPP protocol testing - no R-bootstrap key in Auth Req"""
2826 run_dpp_proto_auth_req_missing(dev, 10, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
2827
47183df7
JM
2828def test_dpp_proto_auth_req_invalid_r_bootstrap_key(dev, apdev):
2829 """DPP protocol testing - invalid R-bootstrap key in Auth Req"""
2830 run_dpp_proto_auth_req_missing(dev, 68, "No matching own bootstrapping key found - ignore message")
2831
a0e3e222
JM
2832def test_dpp_proto_auth_req_no_i_bootstrap_key(dev, apdev):
2833 """DPP protocol testing - no I-bootstrap key in Auth Req"""
2834 run_dpp_proto_auth_req_missing(dev, 11, "Missing or invalid required Initiator Bootstrapping Key Hash attribute")
2835
47183df7
JM
2836def test_dpp_proto_auth_req_invalid_i_bootstrap_key(dev, apdev):
2837 """DPP protocol testing - invalid I-bootstrap key in Auth Req"""
2838 run_dpp_proto_init(dev, 1, 69, mutual=True)
2839 ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
2840 if ev is None:
2841 raise Exception("DPP scan request not seen")
2842 ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
2843 if ev is None:
2844 raise Exception("DPP response pending indivation not seen")
2845
a0e3e222
JM
2846def test_dpp_proto_auth_req_no_i_proto_key(dev, apdev):
2847 """DPP protocol testing - no I-proto key in Auth Req"""
2848 run_dpp_proto_auth_req_missing(dev, 12, "Missing required Initiator Protocol Key attribute")
2849
dc515328
JM
2850def test_dpp_proto_auth_req_invalid_i_proto_key(dev, apdev):
2851 """DPP protocol testing - invalid I-proto key in Auth Req"""
2852 run_dpp_proto_auth_req_missing(dev, 66, "Invalid Initiator Protocol Key")
2853
a0e3e222
JM
2854def test_dpp_proto_auth_req_no_i_nonce(dev, apdev):
2855 """DPP protocol testing - no I-nonce in Auth Req"""
2856 run_dpp_proto_auth_req_missing(dev, 13, "Missing or invalid I-nonce")
2857
af872d9d
JM
2858def test_dpp_proto_auth_req_invalid_i_nonce(dev, apdev):
2859 """DPP protocol testing - invalid I-nonce in Auth Req"""
2860 run_dpp_proto_auth_req_missing(dev, 81, "Missing or invalid I-nonce")
2861
a0e3e222
JM
2862def test_dpp_proto_auth_req_no_i_capab(dev, apdev):
2863 """DPP protocol testing - no I-capab in Auth Req"""
2864 run_dpp_proto_auth_req_missing(dev, 14, "Missing or invalid I-capab")
2865
2866def test_dpp_proto_auth_req_no_wrapped_data(dev, apdev):
2867 """DPP protocol testing - no Wrapped Data in Auth Req"""
2868 run_dpp_proto_auth_req_missing(dev, 15, "Missing or invalid required Wrapped Data attribute")
2869
4e72b1de
JM
2870def run_dpp_proto_auth_resp_missing(dev, test, reason,
2871 incompatible_roles=False):
2872 run_dpp_proto_init(dev, 0, test, mutual=True,
2873 incompatible_roles=incompatible_roles)
a0e3e222 2874 if reason is None:
3d5cfa0f
JM
2875 if incompatible_roles:
2876 ev = dev[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout=5)
2877 if ev is None:
2878 raise Exception("DPP-NOT-COMPATIBLE not reported")
a0e3e222
JM
2879 time.sleep(0.1)
2880 return
203878d7 2881 wait_dpp_fail(dev[1], reason)
a0e3e222
JM
2882 ev = dev[0].wait_event(["DPP-RX"], timeout=1)
2883 if ev is None or "type=0" not in ev:
2884 raise Exception("DPP Authentication Request not seen")
2885 ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
2886 if ev is not None:
2887 raise Exception("Unexpected DPP message seen")
2888
2889def test_dpp_proto_auth_resp_no_status(dev, apdev):
2890 """DPP protocol testing - no Status in Auth Resp"""
2891 run_dpp_proto_auth_resp_missing(dev, 16, "Missing or invalid required DPP Status attribute")
2892
4e72b1de
JM
2893def test_dpp_proto_auth_resp_status_no_status(dev, apdev):
2894 """DPP protocol testing - no Status in Auth Resp(status)"""
2895 run_dpp_proto_auth_resp_missing(dev, 16,
2896 "Missing or invalid required DPP Status attribute",
2897 incompatible_roles=True)
2898
655e82b1
JM
2899def test_dpp_proto_auth_resp_invalid_status(dev, apdev):
2900 """DPP protocol testing - invalid Status in Auth Resp"""
2901 run_dpp_proto_auth_resp_missing(dev, 74, "Responder reported failure")
2902
a0e3e222
JM
2903def test_dpp_proto_auth_resp_no_r_bootstrap_key(dev, apdev):
2904 """DPP protocol testing - no R-bootstrap key in Auth Resp"""
2905 run_dpp_proto_auth_resp_missing(dev, 17, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
2906
4e72b1de
JM
2907def test_dpp_proto_auth_resp_status_no_r_bootstrap_key(dev, apdev):
2908 """DPP protocol testing - no R-bootstrap key in Auth Resp(status)"""
2909 run_dpp_proto_auth_resp_missing(dev, 17,
2910 "Missing or invalid required Responder Bootstrapping Key Hash attribute",
2911 incompatible_roles=True)
2912
47183df7
JM
2913def test_dpp_proto_auth_resp_invalid_r_bootstrap_key(dev, apdev):
2914 """DPP protocol testing - invalid R-bootstrap key in Auth Resp"""
2915 run_dpp_proto_auth_resp_missing(dev, 70, "Unexpected Responder Bootstrapping Key Hash value")
2916
4e72b1de
JM
2917def test_dpp_proto_auth_resp_status_invalid_r_bootstrap_key(dev, apdev):
2918 """DPP protocol testing - invalid R-bootstrap key in Auth Resp(status)"""
2919 run_dpp_proto_auth_resp_missing(dev, 70,
2920 "Unexpected Responder Bootstrapping Key Hash value",
2921 incompatible_roles=True)
2922
a0e3e222
JM
2923def test_dpp_proto_auth_resp_no_i_bootstrap_key(dev, apdev):
2924 """DPP protocol testing - no I-bootstrap key in Auth Resp"""
2925 run_dpp_proto_auth_resp_missing(dev, 18, None)
2926
4e72b1de
JM
2927def test_dpp_proto_auth_resp_status_no_i_bootstrap_key(dev, apdev):
2928 """DPP protocol testing - no I-bootstrap key in Auth Resp(status)"""
2929 run_dpp_proto_auth_resp_missing(dev, 18, None, incompatible_roles=True)
2930
47183df7
JM
2931def test_dpp_proto_auth_resp_invalid_i_bootstrap_key(dev, apdev):
2932 """DPP protocol testing - invalid I-bootstrap key in Auth Resp"""
2933 run_dpp_proto_auth_resp_missing(dev, 71, "Initiator Bootstrapping Key Hash attribute did not match")
2934
4e72b1de
JM
2935def test_dpp_proto_auth_resp_status_invalid_i_bootstrap_key(dev, apdev):
2936 """DPP protocol testing - invalid I-bootstrap key in Auth Resp(status)"""
2937 run_dpp_proto_auth_resp_missing(dev, 71,
2938 "Initiator Bootstrapping Key Hash attribute did not match",
2939 incompatible_roles=True)
2940
a0e3e222
JM
2941def test_dpp_proto_auth_resp_no_r_proto_key(dev, apdev):
2942 """DPP protocol testing - no R-Proto Key in Auth Resp"""
2943 run_dpp_proto_auth_resp_missing(dev, 19, "Missing required Responder Protocol Key attribute")
2944
dc515328
JM
2945def test_dpp_proto_auth_resp_invalid_r_proto_key(dev, apdev):
2946 """DPP protocol testing - invalid R-Proto Key in Auth Resp"""
2947 run_dpp_proto_auth_resp_missing(dev, 67, "Invalid Responder Protocol Key")
2948
a0e3e222
JM
2949def test_dpp_proto_auth_resp_no_r_nonce(dev, apdev):
2950 """DPP protocol testing - no R-nonce in Auth Resp"""
2951 run_dpp_proto_auth_resp_missing(dev, 20, "Missing or invalid R-nonce")
2952
2953def test_dpp_proto_auth_resp_no_i_nonce(dev, apdev):
2954 """DPP protocol testing - no I-nonce in Auth Resp"""
2955 run_dpp_proto_auth_resp_missing(dev, 21, "Missing or invalid I-nonce")
2956
4e72b1de
JM
2957def test_dpp_proto_auth_resp_status_no_i_nonce(dev, apdev):
2958 """DPP protocol testing - no I-nonce in Auth Resp(status)"""
2959 run_dpp_proto_auth_resp_missing(dev, 21, "Missing or invalid I-nonce",
2960 incompatible_roles=True)
2961
a0e3e222
JM
2962def test_dpp_proto_auth_resp_no_r_capab(dev, apdev):
2963 """DPP protocol testing - no R-capab in Auth Resp"""
2964 run_dpp_proto_auth_resp_missing(dev, 22, "Missing or invalid R-capabilities")
2965
2966def test_dpp_proto_auth_resp_no_r_auth(dev, apdev):
2967 """DPP protocol testing - no R-auth in Auth Resp"""
2968 run_dpp_proto_auth_resp_missing(dev, 23, "Missing or invalid Secondary Wrapped Data")
2969
2970def test_dpp_proto_auth_resp_no_wrapped_data(dev, apdev):
2971 """DPP protocol testing - no Wrapped Data in Auth Resp"""
2972 run_dpp_proto_auth_resp_missing(dev, 24, "Missing or invalid required Wrapped Data attribute")
2973
ba0840c9
JM
2974def test_dpp_proto_auth_resp_i_nonce_mismatch(dev, apdev):
2975 """DPP protocol testing - I-nonce mismatch in Auth Resp"""
2976 run_dpp_proto_init(dev, 0, 30, mutual=True)
203878d7 2977 wait_dpp_fail(dev[1], "I-nonce mismatch")
ba0840c9
JM
2978 ev = dev[0].wait_event(["DPP-RX"], timeout=1)
2979 if ev is None or "type=0" not in ev:
2980 raise Exception("DPP Authentication Request not seen")
2981 ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
2982 if ev is not None:
2983 raise Exception("Unexpected DPP message seen")
2984
2985def test_dpp_proto_auth_resp_incompatible_r_capab(dev, apdev):
2986 """DPP protocol testing - Incompatible R-capab in Auth Resp"""
2987 run_dpp_proto_init(dev, 0, 31, mutual=True)
203878d7
JM
2988 wait_dpp_fail(dev[1], "Unexpected role in R-capabilities 0x02")
2989 wait_dpp_fail(dev[0], "Peer reported incompatible R-capab role")
ba0840c9
JM
2990
2991def test_dpp_proto_auth_resp_r_auth_mismatch(dev, apdev):
2992 """DPP protocol testing - R-auth mismatch in Auth Resp"""
2993 run_dpp_proto_init(dev, 0, 32, mutual=True)
203878d7
JM
2994 wait_dpp_fail(dev[1], "Mismatching Responder Authenticating Tag")
2995 wait_dpp_fail(dev[0], "Peer reported authentication failure")
ba0840c9 2996
4d38285b
JM
2997def test_dpp_proto_auth_resp_r_auth_mismatch_failure(dev, apdev):
2998 """DPP protocol testing - Auth Conf RX processing failure"""
2999 with alloc_fail(dev[0], 1, "dpp_auth_conf_rx_failure"):
3000 run_dpp_proto_init(dev, 0, 32, mutual=True)
203878d7 3001 wait_dpp_fail(dev[0], "Authentication failed")
4d38285b
JM
3002
3003def test_dpp_proto_auth_resp_r_auth_mismatch_failure2(dev, apdev):
3004 """DPP protocol testing - Auth Conf RX processing failure 2"""
3005 with fail_test(dev[0], 1, "dpp_auth_conf_rx_failure"):
3006 run_dpp_proto_init(dev, 0, 32, mutual=True)
203878d7 3007 wait_dpp_fail(dev[0], "AES-SIV decryption failed")
4d38285b 3008
b3a93f8f
JM
3009def run_dpp_proto_auth_conf_missing(dev, test, reason):
3010 run_dpp_proto_init(dev, 1, test, mutual=True)
3011 if reason is None:
3012 time.sleep(0.1)
3013 return
203878d7 3014 wait_dpp_fail(dev[0], reason)
b3a93f8f
JM
3015
3016def test_dpp_proto_auth_conf_no_status(dev, apdev):
3017 """DPP protocol testing - no Status in Auth Conf"""
3018 run_dpp_proto_auth_conf_missing(dev, 25, "Missing or invalid required DPP Status attribute")
3019
655e82b1
JM
3020def test_dpp_proto_auth_conf_invalid_status(dev, apdev):
3021 """DPP protocol testing - invalid Status in Auth Conf"""
3022 run_dpp_proto_auth_conf_missing(dev, 75, "Authentication failed")
3023
b3a93f8f
JM
3024def test_dpp_proto_auth_conf_no_r_bootstrap_key(dev, apdev):
3025 """DPP protocol testing - no R-bootstrap key in Auth Conf"""
3026 run_dpp_proto_auth_conf_missing(dev, 26, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
3027
47183df7
JM
3028def test_dpp_proto_auth_conf_invalid_r_bootstrap_key(dev, apdev):
3029 """DPP protocol testing - invalid R-bootstrap key in Auth Conf"""
3030 run_dpp_proto_auth_conf_missing(dev, 72, "Responder Bootstrapping Key Hash mismatch")
3031
b3a93f8f
JM
3032def test_dpp_proto_auth_conf_no_i_bootstrap_key(dev, apdev):
3033 """DPP protocol testing - no I-bootstrap key in Auth Conf"""
f7380b47 3034 run_dpp_proto_auth_conf_missing(dev, 27, "Missing Initiator Bootstrapping Key Hash attribute")
b3a93f8f 3035
47183df7
JM
3036def test_dpp_proto_auth_conf_invalid_i_bootstrap_key(dev, apdev):
3037 """DPP protocol testing - invalid I-bootstrap key in Auth Conf"""
3038 run_dpp_proto_auth_conf_missing(dev, 73, "Initiator Bootstrapping Key Hash mismatch")
3039
b3a93f8f
JM
3040def test_dpp_proto_auth_conf_no_i_auth(dev, apdev):
3041 """DPP protocol testing - no I-Auth in Auth Conf"""
3042 run_dpp_proto_auth_conf_missing(dev, 28, "Missing or invalid Initiator Authenticating Tag")
3043
3044def test_dpp_proto_auth_conf_no_wrapped_data(dev, apdev):
3045 """DPP protocol testing - no Wrapped Data in Auth Conf"""
3046 run_dpp_proto_auth_conf_missing(dev, 29, "Missing or invalid required Wrapped Data attribute")
3047
ba0840c9
JM
3048def test_dpp_proto_auth_conf_i_auth_mismatch(dev, apdev):
3049 """DPP protocol testing - I-auth mismatch in Auth Conf"""
3050 run_dpp_proto_init(dev, 1, 33, mutual=True)
203878d7 3051 wait_dpp_fail(dev[0], "Mismatching Initiator Authenticating Tag")
ba0840c9 3052
3eae3ee2
JM
3053def test_dpp_proto_auth_conf_replaced_by_resp(dev, apdev):
3054 """DPP protocol testing - Auth Conf replaced by Resp"""
3055 run_dpp_proto_init(dev, 1, 65, mutual=True)
203878d7 3056 wait_dpp_fail(dev[0], "Unexpected Authentication Response")
3eae3ee2 3057
bdf987b7
JM
3058def run_dpp_proto_conf_req_missing(dev, test, reason):
3059 run_dpp_proto_init(dev, 0, test)
203878d7 3060 wait_dpp_fail(dev[1], reason)
bdf987b7
JM
3061
3062def test_dpp_proto_conf_req_no_e_nonce(dev, apdev):
3063 """DPP protocol testing - no E-nonce in Conf Req"""
3064 run_dpp_proto_conf_req_missing(dev, 51,
3065 "Missing or invalid Enrollee Nonce attribute")
3066
5f170c99
JM
3067def test_dpp_proto_conf_req_invalid_e_nonce(dev, apdev):
3068 """DPP protocol testing - invalid E-nonce in Conf Req"""
3069 run_dpp_proto_conf_req_missing(dev, 83,
3070 "Missing or invalid Enrollee Nonce attribute")
3071
bdf987b7
JM
3072def test_dpp_proto_conf_req_no_config_attr_obj(dev, apdev):
3073 """DPP protocol testing - no Config Attr Obj in Conf Req"""
3074 run_dpp_proto_conf_req_missing(dev, 52,
3075 "Missing or invalid Config Attributes attribute")
3076
b0fda6b7
JM
3077def test_dpp_proto_conf_req_invalid_config_attr_obj(dev, apdev):
3078 """DPP protocol testing - invalid Config Attr Obj in Conf Req"""
3079 run_dpp_proto_conf_req_missing(dev, 76,
3080 "Unsupported wi-fi_tech")
3081
bdf987b7
JM
3082def test_dpp_proto_conf_req_no_wrapped_data(dev, apdev):
3083 """DPP protocol testing - no Wrapped Data in Conf Req"""
3084 run_dpp_proto_conf_req_missing(dev, 53,
3085 "Missing or invalid required Wrapped Data attribute")
3086
3087def run_dpp_proto_conf_resp_missing(dev, test, reason):
3088 run_dpp_proto_init(dev, 1, test)
203878d7 3089 wait_dpp_fail(dev[0], reason)
bdf987b7
JM
3090
3091def test_dpp_proto_conf_resp_no_e_nonce(dev, apdev):
3092 """DPP protocol testing - no E-nonce in Conf Resp"""
3093 run_dpp_proto_conf_resp_missing(dev, 54,
3094 "Missing or invalid Enrollee Nonce attribute")
3095
3096def test_dpp_proto_conf_resp_no_config_obj(dev, apdev):
3097 """DPP protocol testing - no Config Object in Conf Resp"""
3098 run_dpp_proto_conf_resp_missing(dev, 55,
3099 "Missing required Configuration Object attribute")
3100
3101def test_dpp_proto_conf_resp_no_status(dev, apdev):
3102 """DPP protocol testing - no Status in Conf Resp"""
3103 run_dpp_proto_conf_resp_missing(dev, 56,
3104 "Missing or invalid required DPP Status attribute")
3105
3106def test_dpp_proto_conf_resp_no_wrapped_data(dev, apdev):
3107 """DPP protocol testing - no Wrapped Data in Conf Resp"""
3108 run_dpp_proto_conf_resp_missing(dev, 57,
3109 "Missing or invalid required Wrapped Data attribute")
3110
686cfce9
JM
3111def test_dpp_proto_conf_resp_invalid_status(dev, apdev):
3112 """DPP protocol testing - invalid Status in Conf Resp"""
3113 run_dpp_proto_conf_resp_missing(dev, 58,
3114 "Configurator rejected configuration")
3115
3116def test_dpp_proto_conf_resp_e_nonce_mismatch(dev, apdev):
3117 """DPP protocol testing - E-nonce mismatch in Conf Resp"""
3118 run_dpp_proto_conf_resp_missing(dev, 59,
3119 "Enrollee Nonce mismatch")
3120
c30517c6
JM
3121def test_dpp_proto_stop_at_auth_req(dev, apdev):
3122 """DPP protocol testing - stop when receiving Auth Req"""
3123 run_dpp_proto_init(dev, 0, 87)
3124 ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
3125 if ev is None:
3126 raise Exception("Authentication init failure not reported")
3127
3128def test_dpp_proto_stop_at_auth_resp(dev, apdev):
3129 """DPP protocol testing - stop when receiving Auth Resp"""
3130 run_dpp_proto_init(dev, 1, 88)
3131
3132 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
3133 if ev is None:
3134 raise Exception("Auth Req TX not seen")
3135
3136 ev = dev[0].wait_event(["DPP-TX "], timeout=5)
3137 if ev is None:
3138 raise Exception("Auth Resp TX not seen")
3139
3140 ev = dev[1].wait_event(["DPP-TX "], timeout=0.1)
3141 if ev is not None:
3142 raise Exception("Unexpected Auth Conf TX")
3143
3144def test_dpp_proto_stop_at_auth_conf(dev, apdev):
3145 """DPP protocol testing - stop when receiving Auth Conf"""
3146 run_dpp_proto_init(dev, 0, 89, init_enrollee=True)
3147 ev = dev[1].wait_event(["GAS-QUERY-START"], timeout=10)
3148 if ev is None:
3149 raise Exception("Enrollee did not start GAS")
3150 ev = dev[1].wait_event(["GAS-QUERY-DONE"], timeout=10)
3151 if ev is None:
3152 raise Exception("Enrollee did not time out GAS")
3153 if "result=TIMEOUT" not in ev:
3154 raise Exception("Unexpected GAS result: " + ev)
3155
c63e69c3
JM
3156def test_dpp_proto_stop_at_auth_conf_tx(dev, apdev):
3157 """DPP protocol testing - stop when transmitting Auth Conf (Registrar)"""
3158 run_dpp_proto_init(dev, 1, 89, init_enrollee=True)
517f76b1 3159 wait_auth_success(dev[0], dev[1], timeout=10)
c63e69c3
JM
3160 ev = dev[1].wait_event(["GAS-QUERY-START"], timeout=0.1)
3161 if ev is not None:
3162 raise Exception("Unexpected GAS query")
3163
3164 # There is currently no timeout on GAS server side, so no event to wait for
3165 # in this case.
3166
3167def test_dpp_proto_stop_at_auth_conf_tx2(dev, apdev):
3168 """DPP protocol testing - stop when transmitting Auth Conf (Enrollee)"""
3169 run_dpp_proto_init(dev, 1, 89)
517f76b1 3170 wait_auth_success(dev[0], dev[1], timeout=10)
c63e69c3
JM
3171
3172 ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
3173 if ev is None or "result=TIMEOUT" not in ev:
3174 raise Exception("GAS query did not time out")
3175
c30517c6
JM
3176def test_dpp_proto_stop_at_conf_req(dev, apdev):
3177 """DPP protocol testing - stop when receiving Auth Req"""
3178 run_dpp_proto_init(dev, 1, 90)
3179 ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=10)
3180 if ev is None:
3181 raise Exception("Enrollee did not start GAS")
3182 ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
3183 if ev is None:
3184 raise Exception("Enrollee did not time out GAS")
3185 if "result=TIMEOUT" not in ev:
3186 raise Exception("Unexpected GAS result: " + ev)
3187
a0e3e222
JM
3188def run_dpp_proto_init_pkex(dev, test_dev, test):
3189 check_dpp_capab(dev[0])
3190 check_dpp_capab(dev[1])
3191 dev[test_dev].set("dpp_test", str(test))
6d196e59
JM
3192 dev[0].dpp_pkex_resp(2437, identifier="test", code="secret")
3193 dev[1].dpp_pkex_init(identifier="test", code="secret")
a0e3e222
JM
3194
3195def test_dpp_proto_after_wrapped_data_pkex_cr_req(dev, apdev):
3196 """DPP protocol testing - attribute after Wrapped Data in PKEX CR Req"""
3197 run_dpp_proto_init_pkex(dev, 1, 4)
3198 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
3199 if ev is None or "type=7" not in ev:
3200 raise Exception("PKEX Exchange Request not seen")
3201 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
3202 if ev is None or "type=9" not in ev:
3203 raise Exception("PKEX Commit-Reveal Request not seen")
3204 if "ignore=invalid-attributes" not in ev:
3205 raise Exception("Unexpected RX info: " + ev)
3206
3207def test_dpp_proto_after_wrapped_data_pkex_cr_resp(dev, apdev):
3208 """DPP protocol testing - attribute after Wrapped Data in PKEX CR Resp"""
3209 run_dpp_proto_init_pkex(dev, 0, 5)
3210 ev = dev[1].wait_event(["DPP-RX"], timeout=5)
3211 if ev is None or "type=8" not in ev:
3212 raise Exception("PKEX Exchange Response not seen")
3213 ev = dev[1].wait_event(["DPP-RX"], timeout=5)
3214 if ev is None or "type=10" not in ev:
3215 raise Exception("PKEX Commit-Reveal Response not seen")
3216 if "ignore=invalid-attributes" not in ev:
3217 raise Exception("Unexpected RX info: " + ev)
d5f89062
JM
3218
3219def run_dpp_proto_pkex_req_missing(dev, test, reason):
3220 run_dpp_proto_init_pkex(dev, 1, test)
203878d7 3221 wait_dpp_fail(dev[0], reason)
d5f89062
JM
3222
3223def run_dpp_proto_pkex_resp_missing(dev, test, reason):
3224 run_dpp_proto_init_pkex(dev, 0, test)
203878d7 3225 wait_dpp_fail(dev[1], reason)
d5f89062
JM
3226
3227def test_dpp_proto_pkex_exchange_req_no_finite_cyclic_group(dev, apdev):
3228 """DPP protocol testing - no Finite Cyclic Group in PKEX Exchange Request"""
3229 run_dpp_proto_pkex_req_missing(dev, 34,
3230 "Missing or invalid Finite Cyclic Group attribute")
3231
3232def test_dpp_proto_pkex_exchange_req_no_encrypted_key(dev, apdev):
3233 """DPP protocol testing - no Encrypted Key in PKEX Exchange Request"""
3234 run_dpp_proto_pkex_req_missing(dev, 35,
3235 "Missing Encrypted Key attribute")
3236
3237def test_dpp_proto_pkex_exchange_resp_no_status(dev, apdev):
3238 """DPP protocol testing - no Status in PKEX Exchange Response"""
3239 run_dpp_proto_pkex_resp_missing(dev, 36, "No DPP Status attribute")
3240
3241def test_dpp_proto_pkex_exchange_resp_no_encrypted_key(dev, apdev):
3242 """DPP protocol testing - no Encrypted Key in PKEX Exchange Response"""
3243 run_dpp_proto_pkex_resp_missing(dev, 37, "Missing Encrypted Key attribute")
3244
3245def test_dpp_proto_pkex_cr_req_no_bootstrap_key(dev, apdev):
3246 """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Request"""
3247 run_dpp_proto_pkex_req_missing(dev, 38,
3248 "No valid peer bootstrapping key found")
3249
3250def test_dpp_proto_pkex_cr_req_no_i_auth_tag(dev, apdev):
3251 """DPP protocol testing - no I-Auth Tag in PKEX Commit-Reveal Request"""
3252 run_dpp_proto_pkex_req_missing(dev, 39, "No valid u (I-Auth tag) found")
3253
3254def test_dpp_proto_pkex_cr_req_no_wrapped_data(dev, apdev):
3255 """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Request"""
3256 run_dpp_proto_pkex_req_missing(dev, 40, "Missing or invalid required Wrapped Data attribute")
3257
3258def test_dpp_proto_pkex_cr_resp_no_bootstrap_key(dev, apdev):
3259 """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Response"""
3260 run_dpp_proto_pkex_resp_missing(dev, 41,
3261 "No valid peer bootstrapping key found")
3262
3263def test_dpp_proto_pkex_cr_resp_no_r_auth_tag(dev, apdev):
3264 """DPP protocol testing - no R-Auth Tag in PKEX Commit-Reveal Response"""
3265 run_dpp_proto_pkex_resp_missing(dev, 42, "No valid v (R-Auth tag) found")
3266
3267def test_dpp_proto_pkex_cr_resp_no_wrapped_data(dev, apdev):
3268 """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Response"""
3269 run_dpp_proto_pkex_resp_missing(dev, 43, "Missing or invalid required Wrapped Data attribute")
dea2ab99
JM
3270
3271def test_dpp_proto_pkex_exchange_req_invalid_encrypted_key(dev, apdev):
3272 """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Request"""
3273 run_dpp_proto_pkex_req_missing(dev, 44,
3274 "Invalid Encrypted Key value")
3275
3276def test_dpp_proto_pkex_exchange_resp_invalid_encrypted_key(dev, apdev):
3277 """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Response"""
3278 run_dpp_proto_pkex_resp_missing(dev, 45,
3279 "Invalid Encrypted Key value")
230028a3
JM
3280
3281def test_dpp_proto_pkex_exchange_resp_invalid_status(dev, apdev):
3282 """DPP protocol testing - invalid Status in PKEX Exchange Response"""
3283 run_dpp_proto_pkex_resp_missing(dev, 46,
3284 "PKEX failed (peer indicated failure)")
fd4639aa
JM
3285
3286def test_dpp_proto_pkex_cr_req_invalid_bootstrap_key(dev, apdev):
3287 """DPP protocol testing - invalid Bootstrap Key in PKEX Commit-Reveal Request"""
3288 run_dpp_proto_pkex_req_missing(dev, 47,
3289 "Peer bootstrapping key is invalid")
3290
3291def test_dpp_proto_pkex_cr_resp_invalid_bootstrap_key(dev, apdev):
3292 """DPP protocol testing - invalid Bootstrap Key in PKEX Commit-Reveal Response"""
3293 run_dpp_proto_pkex_resp_missing(dev, 48,
3294 "Peer bootstrapping key is invalid")
c20d3ca8
JM
3295
3296def test_dpp_proto_pkex_cr_req_i_auth_tag_mismatch(dev, apdev):
3297 """DPP protocol testing - I-auth tag mismatch in PKEX Commit-Reveal Request"""
3298 run_dpp_proto_pkex_req_missing(dev, 49, "No valid u (I-Auth tag) found")
3299
3300def test_dpp_proto_pkex_cr_resp_r_auth_tag_mismatch(dev, apdev):
3301 """DPP protocol testing - R-auth tag mismatch in PKEX Commit-Reveal Response"""
3302 run_dpp_proto_pkex_resp_missing(dev, 50, "No valid v (R-Auth tag) found")
993eab91 3303
c30517c6
JM
3304def test_dpp_proto_stop_at_pkex_exchange_resp(dev, apdev):
3305 """DPP protocol testing - stop when receiving PKEX Exchange Response"""
3306 run_dpp_proto_init_pkex(dev, 1, 84)
3307
3308 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
3309 if ev is None:
3310 raise Exception("PKEX Exchange Req TX not seen")
3311
3312 ev = dev[0].wait_event(["DPP-TX "], timeout=5)
3313 if ev is None:
3314 raise Exception("PKEX Exchange Resp not seen")
3315
3316 ev = dev[1].wait_event(["DPP-TX "], timeout=0.1)
3317 if ev is not None:
3318 raise Exception("Unexpected PKEX CR Req TX")
3319
3320def test_dpp_proto_stop_at_pkex_cr_req(dev, apdev):
3321 """DPP protocol testing - stop when receiving PKEX CR Request"""
3322 run_dpp_proto_init_pkex(dev, 0, 85)
3323
3324 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
3325 if ev is None:
3326 raise Exception("PKEX Exchange Req TX not seen")
3327
3328 ev = dev[0].wait_event(["DPP-TX "], timeout=5)
3329 if ev is None:
3330 raise Exception("PKEX Exchange Resp not seen")
3331
3332 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
3333 if ev is None:
3334 raise Exception("PKEX CR Req TX not seen")
3335
3336 ev = dev[0].wait_event(["DPP-TX "], timeout=0.1)
3337 if ev is not None:
3338 raise Exception("Unexpected PKEX CR Resp TX")
3339
3340def test_dpp_proto_stop_at_pkex_cr_resp(dev, apdev):
3341 """DPP protocol testing - stop when receiving PKEX CR Response"""
3342 run_dpp_proto_init_pkex(dev, 1, 86)
3343
3344 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
3345 if ev is None:
3346 raise Exception("PKEX Exchange Req TX not seen")
3347
3348 ev = dev[0].wait_event(["DPP-TX "], timeout=5)
3349 if ev is None:
3350 raise Exception("PKEX Exchange Resp not seen")
3351
3352 ev = dev[1].wait_event(["DPP-TX "], timeout=5)
3353 if ev is None:
3354 raise Exception("PKEX CR Req TX not seen")
3355
3356 ev = dev[0].wait_event(["DPP-TX "], timeout=5)
3357 if ev is None:
3358 raise Exception("PKEX CR Resp TX not seen")
3359
3360 ev = dev[1].wait_event(["DPP-TX "], timeout=0.1)
3361 if ev is not None:
3362 raise Exception("Unexpected Auth Req TX")
3363
993eab91
JM
3364def test_dpp_proto_network_introduction(dev, apdev):
3365 """DPP protocol testing - network introduction"""
3366 check_dpp_capab(dev[0])
3367 check_dpp_capab(dev[1])
3368
fab49f61
JM
3369 params = {"ssid": "dpp",
3370 "wpa": "2",
3371 "wpa_key_mgmt": "DPP",
3372 "ieee80211w": "2",
3373 "rsn_pairwise": "CCMP",
3374 "dpp_connector": params1_ap_connector,
3375 "dpp_csign": params1_csign,
3376 "dpp_netaccesskey": params1_ap_netaccesskey}
993eab91
JM
3377 try:
3378 hapd = hostapd.add_ap(apdev[0], params)
3379 except:
3380 raise HwsimSkip("DPP not supported")
3381
fab49f61 3382 for test in [60, 61, 80, 82]:
993eab91
JM
3383 dev[0].set("dpp_test", str(test))
3384 dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412", ieee80211w="2",
7e26f1bc
JM
3385 dpp_csign=params1_csign,
3386 dpp_connector=params1_sta_connector,
3387 dpp_netaccesskey=params1_sta_netaccesskey,
3388 wait_connect=False)
993eab91 3389
dbdd445d 3390 ev = dev[0].wait_event(["DPP-TX "], timeout=10)
993eab91
JM
3391 if ev is None or "type=5" not in ev:
3392 raise Exception("Peer Discovery Request TX not reported")
3393 ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=2)
3394 if ev is None or "result=SUCCESS" not in ev:
3395 raise Exception("Peer Discovery Request TX status not reported")
3396
3397 ev = hapd.wait_event(["DPP-RX"], timeout=10)
3398 if ev is None or "type=5" not in ev:
3399 raise Exception("Peer Discovery Request RX not reported")
3400
de731ec2
JM
3401 if test == 80:
3402 ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
3403 if ev is None:
3404 raise Exception("DPP-INTRO not reported for test 80")
3405 if "status=7" not in ev:
3406 raise Exception("Unexpected result in test 80: " + ev)
3407
993eab91
JM
3408 dev[0].request("REMOVE_NETWORK all")
3409 dev[0].dump_monitor()
3410 hapd.dump_monitor()
3411 dev[0].set("dpp_test", "0")
3412
fab49f61 3413 for test in [62, 63, 64, 77, 78, 79]:
993eab91
JM
3414 hapd.set("dpp_test", str(test))
3415 dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412", ieee80211w="2",
7e26f1bc
JM
3416 dpp_csign=params1_csign,
3417 dpp_connector=params1_sta_connector,
3418 dpp_netaccesskey=params1_sta_netaccesskey,
3419 wait_connect=False)
993eab91
JM
3420
3421 ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
3422 if ev is None:
de731ec2
JM
3423 raise Exception("Peer introduction result not reported (test %d)" % test)
3424 if test == 77:
3425 if "fail=transaction_id_mismatch" not in ev:
3426 raise Exception("Connector validation failure not reported")
3427 elif test == 78:
3428 if "status=254" not in ev:
3429 raise Exception("Invalid status value not reported")
3430 elif test == 79:
3431 if "fail=peer_connector_validation_failed" not in ev:
3432 raise Exception("Connector validation failure not reported")
3433 elif "status=" in ev:
3434 raise Exception("Unexpected peer introduction result (test %d): " % test + ev)
993eab91
JM
3435
3436 dev[0].request("REMOVE_NETWORK all")
3437 dev[0].dump_monitor()
3438 hapd.dump_monitor()
3439 hapd.set("dpp_test", "0")
3440
3441 dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412", ieee80211w="2",
7e26f1bc
JM
3442 dpp_csign=params1_csign, dpp_connector=params1_sta_connector,
3443 dpp_netaccesskey=params1_sta_netaccesskey)
751f7f7c
JM
3444
3445def test_dpp_qr_code_no_chan_list_unicast(dev, apdev):
3446 """DPP QR Code and no channel list (unicast)"""
3447 run_dpp_qr_code_chan_list(dev, apdev, True, 2417, None)
3448
3449def test_dpp_qr_code_chan_list_unicast(dev, apdev):
3450 """DPP QR Code and 2.4 GHz channels (unicast)"""
3451 run_dpp_qr_code_chan_list(dev, apdev, True, 2417,
3452 "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")
3453
35814134
JM
3454def test_dpp_qr_code_chan_list_unicast2(dev, apdev):
3455 """DPP QR Code and 2.4 GHz channels (unicast 2)"""
3456 run_dpp_qr_code_chan_list(dev, apdev, True, 2417,
3457 "81/1,2,3,4,5,6,7,8,9,10,11,12,13")
3458
751f7f7c
JM
3459def test_dpp_qr_code_chan_list_no_peer_unicast(dev, apdev):
3460 """DPP QR Code and channel list and no peer (unicast)"""
3461 run_dpp_qr_code_chan_list(dev, apdev, True, 2417, "81/1,81/6,81/11",
3462 no_wait=True)
3463 ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
3464 if ev is None:
3465 raise Exception("Initiation failure not reported")
3466
3467def test_dpp_qr_code_no_chan_list_broadcast(dev, apdev):
3468 """DPP QR Code and no channel list (broadcast)"""
3469 run_dpp_qr_code_chan_list(dev, apdev, False, 2412, None)
3470
3471def test_dpp_qr_code_chan_list_broadcast(dev, apdev):
3472 """DPP QR Code and some 2.4 GHz channels (broadcast)"""
3473 run_dpp_qr_code_chan_list(dev, apdev, False, 2412, "81/1,81/6,81/11",
3474 timeout=10)
3475
3476def run_dpp_qr_code_chan_list(dev, apdev, unicast, listen_freq, chanlist,
3477 no_wait=False, timeout=5):
3478 check_dpp_capab(dev[0])
3479 check_dpp_capab(dev[1])
3480 dev[1].set("dpp_init_max_tries", "3")
3481 dev[1].set("dpp_init_retry_time", "100")
8968acda 3482 dev[1].set("dpp_resp_wait_time", "1000")
751f7f7c
JM
3483
3484 logger.info("dev0 displays QR Code")
a5387062 3485 id0 = dev[0].dpp_bootstrap_gen(chan=chanlist, mac=unicast)
751f7f7c 3486 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
5725b3e3 3487 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 3488 dev[0].dpp_listen(listen_freq)
5725b3e3 3489 dev[1].dpp_auth_init(uri=uri0)
751f7f7c
JM
3490 if no_wait:
3491 return
517f76b1
JM
3492 wait_auth_success(dev[0], dev[1], timeout=timeout, configurator=dev[1],
3493 enrollee=dev[0], allow_enrollee_failure=True,
3494 stop_responder=True)
751f7f7c
JM
3495
3496def test_dpp_qr_code_chan_list_no_match(dev, apdev):
3497 """DPP QR Code and no matching supported channel"""
3498 check_dpp_capab(dev[0])
3499 check_dpp_capab(dev[1])
a5387062 3500 id0 = dev[0].dpp_bootstrap_gen(chan="123/123")
751f7f7c 3501 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
5725b3e3 3502 dev[1].dpp_auth_init(uri=uri0, expect_fail=True)
818e3c94
JM
3503
3504def test_dpp_pkex_alloc_fail(dev, apdev):
3505 """DPP/PKEX and memory allocation failures"""
3506 check_dpp_capab(dev[0])
3507 check_dpp_capab(dev[1])
3508
fab49f61
JM
3509 tests = [(1, "=dpp_keygen_configurator"),
3510 (1, "base64_gen_encode;dpp_keygen_configurator")]
818e3c94
JM
3511 for count, func in tests:
3512 with alloc_fail(dev[1], count, func):
3513 cmd = "DPP_CONFIGURATOR_ADD"
58be42b2 3514 res = dev[1].request(cmd)
818e3c94
JM
3515 if "FAIL" not in res:
3516 raise Exception("Unexpected DPP_CONFIGURATOR_ADD success")
3517
e105110f 3518 conf_id = dev[1].dpp_configurator_add()
818e3c94 3519
6d196e59
JM
3520 id0 = None
3521 id1 = None
818e3c94
JM
3522
3523 # Local error cases on the Initiator
fab49f61
JM
3524 tests = [(1, "dpp_get_pubkey_point"),
3525 (1, "dpp_alloc_msg;dpp_pkex_build_exchange_req"),
3526 (1, "dpp_alloc_msg;dpp_pkex_build_commit_reveal_req"),
3527 (1, "dpp_alloc_msg;dpp_auth_build_req"),
3528 (1, "dpp_alloc_msg;dpp_auth_build_conf"),
3529 (1, "dpp_bootstrap_key_hash"),
3530 (1, "dpp_auth_init"),
269a7878 3531 (1, "dpp_alloc_auth"),
fab49f61 3532 (1, "=dpp_auth_resp_rx"),
fab49f61
JM
3533 (1, "dpp_build_conf_start"),
3534 (1, "dpp_build_conf_obj_dpp"),
3535 (2, "dpp_build_conf_obj_dpp"),
3536 (3, "dpp_build_conf_obj_dpp"),
3537 (4, "dpp_build_conf_obj_dpp"),
3538 (5, "dpp_build_conf_obj_dpp"),
3539 (6, "dpp_build_conf_obj_dpp"),
3540 (7, "dpp_build_conf_obj_dpp"),
3541 (8, "dpp_build_conf_obj_dpp"),
3542 (1, "dpp_conf_req_rx"),
3543 (2, "dpp_conf_req_rx"),
3544 (3, "dpp_conf_req_rx"),
3545 (4, "dpp_conf_req_rx"),
3546 (5, "dpp_conf_req_rx"),
3547 (6, "dpp_conf_req_rx"),
3548 (7, "dpp_conf_req_rx"),
3549 (1, "dpp_pkex_init"),
3550 (2, "dpp_pkex_init"),
3551 (3, "dpp_pkex_init"),
3552 (1, "dpp_pkex_derive_z"),
3553 (1, "=dpp_pkex_rx_commit_reveal_resp"),
3554 (1, "dpp_get_pubkey_point;dpp_build_jwk"),
3555 (2, "dpp_get_pubkey_point;dpp_build_jwk"),
3556 (1, "dpp_get_pubkey_point;dpp_auth_init")]
818e3c94
JM
3557 for count, func in tests:
3558 dev[0].request("DPP_STOP_LISTEN")
3559 dev[1].request("DPP_STOP_LISTEN")
3560 dev[0].dump_monitor()
3561 dev[1].dump_monitor()
6d196e59
JM
3562 id0 = dev[0].dpp_pkex_resp(2437, identifier="test", code="secret",
3563 use_id=id0)
818e3c94
JM
3564
3565 with alloc_fail(dev[1], count, func):
6d196e59
JM
3566 id1 = dev[1].dpp_pkex_init(identifier="test", code="secret",
3567 use_id=id1,
3568 extra="conf=sta-dpp configurator=%d" % conf_id,
3569 allow_fail=True)
8b5a4973 3570 wait_fail_trigger(dev[1], "GET_ALLOC_FAIL", max_iter=100)
818e3c94
JM
3571 ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=0.01)
3572 if ev:
3573 dev[0].request("DPP_STOP_LISTEN")
3574 dev[0].wait_event(["GAS-QUERY-DONE"], timeout=3)
3575
3576 # Local error cases on the Responder
fab49f61
JM
3577 tests = [(1, "dpp_get_pubkey_point"),
3578 (1, "dpp_alloc_msg;dpp_pkex_build_exchange_resp"),
3579 (1, "dpp_alloc_msg;dpp_pkex_build_commit_reveal_resp"),
3580 (1, "dpp_alloc_msg;dpp_auth_build_resp"),
3581 (1, "dpp_get_pubkey_point;dpp_auth_build_resp_ok"),
269a7878 3582 (1, "dpp_alloc_auth"),
fab49f61 3583 (1, "=dpp_auth_req_rx"),
fab49f61
JM
3584 (1, "=dpp_auth_conf_rx"),
3585 (1, "json_parse;dpp_parse_jws_prot_hdr"),
3586 (1, "json_get_member_base64url;dpp_parse_jws_prot_hdr"),
3587 (1, "json_get_member_base64url;dpp_parse_jwk"),
3588 (2, "json_get_member_base64url;dpp_parse_jwk"),
3589 (1, "json_parse;dpp_parse_connector"),
3590 (1, "dpp_parse_jwk;dpp_parse_connector"),
3591 (1, "dpp_parse_jwk;dpp_parse_cred_dpp"),
3592 (1, "dpp_get_pubkey_point;dpp_check_pubkey_match"),
3593 (1, "base64_gen_decode;dpp_process_signed_connector"),
3594 (1, "dpp_parse_jws_prot_hdr;dpp_process_signed_connector"),
3595 (2, "base64_gen_decode;dpp_process_signed_connector"),
3596 (3, "base64_gen_decode;dpp_process_signed_connector"),
3597 (4, "base64_gen_decode;dpp_process_signed_connector"),
3598 (1, "json_parse;dpp_parse_conf_obj"),
3599 (1, "dpp_conf_resp_rx"),
3600 (1, "=dpp_pkex_derive_z"),
3601 (1, "=dpp_pkex_rx_exchange_req"),
3602 (2, "=dpp_pkex_rx_exchange_req"),
3603 (3, "=dpp_pkex_rx_exchange_req"),
3604 (1, "=dpp_pkex_rx_commit_reveal_req"),
3605 (1, "dpp_get_pubkey_point;dpp_pkex_rx_commit_reveal_req"),
3606 (1, "dpp_bootstrap_key_hash")]
818e3c94
JM
3607 for count, func in tests:
3608 dev[0].request("DPP_STOP_LISTEN")
3609 dev[1].request("DPP_STOP_LISTEN")
3610 dev[0].dump_monitor()
3611 dev[1].dump_monitor()
6d196e59
JM
3612 id0 = dev[0].dpp_pkex_resp(2437, identifier="test", code="secret",
3613 use_id=id0)
818e3c94
JM
3614
3615 with alloc_fail(dev[0], count, func):
6d196e59
JM
3616 id1 = dev[1].dpp_pkex_init(identifier="test", code="secret",
3617 use_id=id1,
3618 extra="conf=sta-dpp configurator=%d" % conf_id)
8b5a4973 3619 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL", max_iter=100)
818e3c94
JM
3620 ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=0.01)
3621 if ev:
3622 dev[0].request("DPP_STOP_LISTEN")
3623 dev[0].wait_event(["GAS-QUERY-DONE"], timeout=3)
3624
3625def test_dpp_pkex_test_fail(dev, apdev):
3626 """DPP/PKEX and local failures"""
3627 check_dpp_capab(dev[0])
3628 check_dpp_capab(dev[1])
3629
fab49f61 3630 tests = [(1, "dpp_keygen_configurator")]
818e3c94
JM
3631 for count, func in tests:
3632 with fail_test(dev[1], count, func):
3633 cmd = "DPP_CONFIGURATOR_ADD"
58be42b2 3634 res = dev[1].request(cmd)
818e3c94
JM
3635 if "FAIL" not in res:
3636 raise Exception("Unexpected DPP_CONFIGURATOR_ADD success")
3637
fab49f61 3638 tests = [(1, "dpp_keygen")]
818e3c94
JM
3639 for count, func in tests:
3640 with fail_test(dev[1], count, func):
3641 cmd = "DPP_BOOTSTRAP_GEN type=pkex"
58be42b2 3642 res = dev[1].request(cmd)
818e3c94
JM
3643 if "FAIL" not in res:
3644 raise Exception("Unexpected DPP_BOOTSTRAP_GEN success")
3645
e105110f 3646 conf_id = dev[1].dpp_configurator_add()
818e3c94 3647
6d196e59
JM
3648 id0 = None
3649 id1 = None
818e3c94
JM
3650
3651 # Local error cases on the Initiator
fab49f61
JM
3652 tests = [(1, "aes_siv_encrypt;dpp_auth_build_req"),
3653 (1, "os_get_random;dpp_auth_init"),
3654 (1, "dpp_derive_k1;dpp_auth_init"),
3655 (1, "dpp_hkdf_expand;dpp_derive_k1;dpp_auth_init"),
3656 (1, "dpp_gen_i_auth;dpp_auth_build_conf"),
3657 (1, "aes_siv_encrypt;dpp_auth_build_conf"),
3658 (1, "dpp_derive_k2;dpp_auth_resp_rx"),
3659 (1, "dpp_hkdf_expand;dpp_derive_k2;dpp_auth_resp_rx"),
3660 (1, "dpp_derive_ke;dpp_auth_resp_rx"),
3661 (1, "dpp_hkdf_expand;dpp_derive_ke;dpp_auth_resp_rx"),
3662 (1, "dpp_gen_r_auth;dpp_auth_resp_rx"),
3663 (1, "aes_siv_encrypt;dpp_build_conf_resp"),
3664 (1, "dpp_pkex_derive_Qi;dpp_pkex_build_exchange_req"),
3665 (1, "aes_siv_encrypt;dpp_pkex_build_commit_reveal_req"),
3666 (1, "hmac_sha256_vector;dpp_pkex_rx_exchange_resp"),
3667 (1, "aes_siv_decrypt;dpp_pkex_rx_commit_reveal_resp"),
3668 (1, "hmac_sha256_vector;dpp_pkex_rx_commit_reveal_resp"),
3669 (1, "dpp_bootstrap_key_hash")]
818e3c94
JM
3670 for count, func in tests:
3671 dev[0].request("DPP_STOP_LISTEN")
3672 dev[1].request("DPP_STOP_LISTEN")
3673 dev[0].dump_monitor()
3674 dev[1].dump_monitor()
6d196e59
JM
3675 id0 = dev[0].dpp_pkex_resp(2437, identifier="test", code="secret",
3676 use_id=id0)
818e3c94
JM
3677
3678 with fail_test(dev[1], count, func):
6d196e59
JM
3679 id1 = dev[1].dpp_pkex_init(identifier="test", code="secret",
3680 use_id=id1,
3681 extra="conf=sta-dpp configurator=%d" % conf_id,
3682 allow_fail=True)
8b5a4973 3683 wait_fail_trigger(dev[1], "GET_FAIL", max_iter=100)
818e3c94
JM
3684 ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=0.01)
3685 if ev:
3686 dev[0].request("DPP_STOP_LISTEN")
3687 dev[0].wait_event(["GAS-QUERY-DONE"], timeout=3)
3688
3689 # Local error cases on the Responder
fab49f61
JM
3690 tests = [(1, "aes_siv_encrypt;dpp_auth_build_resp"),
3691 (1, "aes_siv_encrypt;dpp_auth_build_resp;dpp_auth_build_resp_ok"),
3692 (1, "os_get_random;dpp_build_conf_req"),
3693 (1, "aes_siv_encrypt;dpp_build_conf_req"),
3694 (1, "os_get_random;dpp_auth_build_resp_ok"),
3695 (1, "dpp_derive_k2;dpp_auth_build_resp_ok"),
3696 (1, "dpp_derive_ke;dpp_auth_build_resp_ok"),
3697 (1, "dpp_gen_r_auth;dpp_auth_build_resp_ok"),
3698 (1, "aes_siv_encrypt;dpp_auth_build_resp_ok"),
3699 (1, "dpp_derive_k1;dpp_auth_req_rx"),
3700 (1, "aes_siv_decrypt;dpp_auth_req_rx"),
3701 (1, "aes_siv_decrypt;dpp_auth_conf_rx"),
3702 (1, "dpp_gen_i_auth;dpp_auth_conf_rx"),
3703 (1, "dpp_check_pubkey_match"),
3704 (1, "aes_siv_decrypt;dpp_conf_resp_rx"),
3705 (1, "hmac_sha256_kdf;dpp_pkex_derive_z"),
3706 (1, "dpp_pkex_derive_Qi;dpp_pkex_rx_exchange_req"),
3707 (1, "dpp_pkex_derive_Qr;dpp_pkex_rx_exchange_req"),
3708 (1, "aes_siv_encrypt;dpp_pkex_build_commit_reveal_resp"),
3709 (1, "aes_siv_decrypt;dpp_pkex_rx_commit_reveal_req"),
3710 (1, "hmac_sha256_vector;dpp_pkex_rx_commit_reveal_req"),
3711 (2, "hmac_sha256_vector;dpp_pkex_rx_commit_reveal_req")]
818e3c94
JM
3712 for count, func in tests:
3713 dev[0].request("DPP_STOP_LISTEN")
3714 dev[1].request("DPP_STOP_LISTEN")
3715 dev[0].dump_monitor()
3716 dev[1].dump_monitor()
6d196e59
JM
3717 id0 = dev[0].dpp_pkex_resp(2437, identifier="test", code="secret",
3718 use_id=id0)
818e3c94
JM
3719
3720 with fail_test(dev[0], count, func):
6d196e59
JM
3721 id1 = dev[1].dpp_pkex_init(identifier="test", code="secret",
3722 use_id=id1,
3723 extra="conf=sta-dpp configurator=%d" % conf_id)
818e3c94
JM
3724 wait_fail_trigger(dev[0], "GET_FAIL", max_iter=100)
3725 ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=0.01)
3726 if ev:
3727 dev[0].request("DPP_STOP_LISTEN")
3728 dev[0].wait_event(["GAS-QUERY-DONE"], timeout=3)
f1e2d381
JM
3729
3730def test_dpp_keygen_configurator_error(dev, apdev):
3731 """DPP Configurator keygen error case"""
3732 check_dpp_capab(dev[0])
3733 if "FAIL" not in dev[0].request("DPP_CONFIGURATOR_ADD curve=unknown"):
3734 raise Exception("Unexpected success of invalid DPP_CONFIGURATOR_ADD")
a46b60c4
JM
3735
3736def rx_process_frame(dev):
3737 msg = dev.mgmt_rx()
8b6c834f
JM
3738 if msg is None:
3739 raise Exception("No management frame RX reported")
54c58f29
MH
3740 if "OK" not in dev.request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
3741 msg['freq'], msg['datarate'], msg['ssi_signal'], binascii.hexlify(msg['frame']).decode())):
a46b60c4 3742 raise Exception("MGMT_RX_PROCESS failed")
ba6ce9c6 3743 return msg
a46b60c4 3744
517f76b1
JM
3745def wait_auth_success(responder, initiator, configurator=None, enrollee=None,
3746 allow_enrollee_failure=False,
3747 allow_configurator_failure=False,
3748 require_configurator_failure=False,
3749 timeout=5, stop_responder=False, stop_initiator=False):
b256d939 3750 res = {}
517f76b1
JM
3751 ev = responder.wait_event(["DPP-AUTH-SUCCESS", "DPP-FAIL"], timeout=timeout)
3752 if ev is None or "DPP-AUTH-SUCCESS" not in ev:
a46b60c4 3753 raise Exception("DPP authentication did not succeed (Responder)")
517f76b1
JM
3754 ev = initiator.wait_event(["DPP-AUTH-SUCCESS", "DPP-FAIL"], timeout=5)
3755 if ev is None or "DPP-AUTH-SUCCESS" not in ev:
a46b60c4 3756 raise Exception("DPP authentication did not succeed (Initiator)")
517f76b1
JM
3757 if configurator:
3758 ev = configurator.wait_event(["DPP-CONF-SENT",
3759 "DPP-CONF-FAILED"], timeout=5)
3760 if ev is None:
3761 raise Exception("DPP configuration not completed (Configurator)")
3762 if "DPP-CONF-FAILED" in ev and not allow_configurator_failure:
19d4a5de 3763 raise Exception("DPP configuration did not succeed (Configurator)")
530b31ea
JM
3764 if "DPP-CONF-SENT" in ev and require_configurator_failure:
3765 raise Exception("DPP configuration succeeded (Configurator)")
b256d939
JM
3766 if "DPP-CONF-SENT" in ev and "wait_conn_status=1" in ev:
3767 res['wait_conn_status'] = True
517f76b1
JM
3768 if enrollee:
3769 ev = enrollee.wait_event(["DPP-CONF-RECEIVED",
3770 "DPP-CONF-FAILED"], timeout=5)
3771 if ev is None:
3772 raise Exception("DPP configuration not completed (Enrollee)")
3773 if "DPP-CONF-FAILED" in ev and not allow_enrollee_failure:
3774 raise Exception("DPP configuration did not succeed (Enrollee)")
3775 if stop_responder:
3776 responder.request("DPP_STOP_LISTEN")
3777 if stop_initiator:
3778 initiator.request("DPP_STOP_LISTEN")
b256d939 3779 return res
a46b60c4
JM
3780
3781def wait_conf_completion(configurator, enrollee):
3782 ev = configurator.wait_event(["DPP-CONF-SENT"], timeout=5)
3783 if ev is None:
3784 raise Exception("DPP configuration not completed (Configurator)")
3785 ev = enrollee.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"],
3786 timeout=5)
3787 if ev is None:
3788 raise Exception("DPP configuration not completed (Enrollee)")
3789
3790def start_dpp(dev):
a5387062 3791 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
a46b60c4
JM
3792 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
3793
a46b60c4
JM
3794 conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
3795 dev[0].set("dpp_config_obj_override", conf)
3796
3797 dev[0].set("ext_mgmt_frame_handling", "1")
7e009100 3798 dev[0].dpp_listen(2412)
5725b3e3 3799 dev[1].dpp_auth_init(uri=uri0, role="enrollee")
a46b60c4
JM
3800
3801def test_dpp_gas_timeout_handling(dev, apdev):
3802 """DPP and GAS timeout handling"""
3803 check_dpp_capab(dev[0])
3804 check_dpp_capab(dev[1])
3805 start_dpp(dev)
3806
3807 # DPP Authentication Request
3808 rx_process_frame(dev[0])
3809
3810 # DPP Authentication Confirmation
3811 rx_process_frame(dev[0])
3812
3813 wait_auth_success(dev[0], dev[1])
3814
3815 # DPP Configuration Request (GAS Initial Request frame)
3816 rx_process_frame(dev[0])
3817
3818 # DPP Configuration Request (GAS Comeback Request frame)
3819 rx_process_frame(dev[0])
3820
3821 # Wait for GAS timeout
3822 ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=5)
3823 if ev is None:
3824 raise Exception("DPP configuration not completed (Enrollee)")
3825
3826def test_dpp_gas_comeback_after_failure(dev, apdev):
3827 """DPP and GAS comeback after failure"""
3828 check_dpp_capab(dev[0])
3829 check_dpp_capab(dev[1])
3830 start_dpp(dev)
3831
3832 # DPP Authentication Request
3833 rx_process_frame(dev[0])
3834
3835 # DPP Authentication Confirmation
3836 rx_process_frame(dev[0])
3837
3838 wait_auth_success(dev[0], dev[1])
3839
3840 # DPP Configuration Request (GAS Initial Request frame)
3841 rx_process_frame(dev[0])
3842
3843 # DPP Configuration Request (GAS Comeback Request frame)
3844 msg = dev[0].mgmt_rx()
54c58f29 3845 frame = binascii.hexlify(msg['frame']).decode()
a46b60c4
JM
3846 with alloc_fail(dev[0], 1, "gas_build_comeback_resp;gas_server_handle_rx_comeback_req"):
3847 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame)):
3848 raise Exception("MGMT_RX_PROCESS failed")
3849 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
3850 # Try the same frame again - this is expected to fail since the response has
3851 # already been freed.
3852 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame)):
3853 raise Exception("MGMT_RX_PROCESS failed")
3854
3855 # DPP Configuration Request (GAS Comeback Request frame retry)
3856 msg = dev[0].mgmt_rx()
3857
3858def test_dpp_gas(dev, apdev):
3859 """DPP and GAS protocol testing"""
8b6c834f
JM
3860 ver0 = check_dpp_capab(dev[0])
3861 ver1 = check_dpp_capab(dev[1])
a46b60c4
JM
3862 start_dpp(dev)
3863
3864 # DPP Authentication Request
3865 rx_process_frame(dev[0])
3866
3867 # DPP Authentication Confirmation
3868 rx_process_frame(dev[0])
3869
3870 wait_auth_success(dev[0], dev[1])
3871
3872 # DPP Configuration Request (GAS Initial Request frame)
3873 msg = dev[0].mgmt_rx()
3874
3875 # Protected Dual of GAS Initial Request frame (dropped by GAS server)
54c58f29
MH
3876 if msg == None:
3877 raise Exception("MGMT_RX_PROCESS failed. <Please retry>")
3878 frame = binascii.hexlify(msg['frame'])
3879 frame = frame[0:48] + b"09" + frame[50:]
3880 frame = frame.decode()
a46b60c4
JM
3881 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame)):
3882 raise Exception("MGMT_RX_PROCESS failed")
3883
3884 with alloc_fail(dev[0], 1, "gas_server_send_resp"):
54c58f29 3885 frame = binascii.hexlify(msg['frame']).decode()
a46b60c4
JM
3886 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame)):
3887 raise Exception("MGMT_RX_PROCESS failed")
3888 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
3889
3890 with alloc_fail(dev[0], 1, "gas_build_initial_resp;gas_server_send_resp"):
54c58f29 3891 frame = binascii.hexlify(msg['frame']).decode()
a46b60c4
JM
3892 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame)):
3893 raise Exception("MGMT_RX_PROCESS failed")
3894 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
3895
3896 # Add extra data after Query Request field to trigger
3897 # "GAS: Ignored extra data after Query Request field"
54c58f29 3898 frame = binascii.hexlify(msg['frame']).decode() + "00"
a46b60c4
JM
3899 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame)):
3900 raise Exception("MGMT_RX_PROCESS failed")
3901
3902 # DPP Configuration Request (GAS Comeback Request frame)
3903 rx_process_frame(dev[0])
3904
3905 # DPP Configuration Request (GAS Comeback Request frame)
3906 rx_process_frame(dev[0])
3907
3908 # DPP Configuration Request (GAS Comeback Request frame)
3909 rx_process_frame(dev[0])
3910
8b6c834f
JM
3911 if ver0 >= 2 and ver1 >= 2:
3912 # DPP Configuration Result
3913 rx_process_frame(dev[0])
3914
a46b60c4 3915 wait_conf_completion(dev[0], dev[1])
01e39ba9
JM
3916
3917def test_dpp_truncated_attr(dev, apdev):
3918 """DPP and truncated attribute"""
3919 check_dpp_capab(dev[0])
3920 check_dpp_capab(dev[1])
3921 start_dpp(dev)
3922
3923 # DPP Authentication Request
3924 msg = dev[0].mgmt_rx()
3925 frame = msg['frame']
3926
3927 # DPP: Truncated message - not enough room for the attribute - dropped
54c58f29 3928 frame1 = binascii.hexlify(frame[0:36]).decode()
01e39ba9
JM
3929 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame1)):
3930 raise Exception("MGMT_RX_PROCESS failed")
3931 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
3932 if ev is None or "ignore=invalid-attributes" not in ev:
3933 raise Exception("Invalid attribute error not reported")
3934
3935 # DPP: Unexpected octets (3) after the last attribute
54c58f29 3936 frame2 = binascii.hexlify(frame).decode() + "000000"
01e39ba9
JM
3937 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame2)):
3938 raise Exception("MGMT_RX_PROCESS failed")
3939 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
3940 if ev is None or "ignore=invalid-attributes" not in ev:
3941 raise Exception("Invalid attribute error not reported")
f1042596
JM
3942
3943def test_dpp_bootstrap_key_autogen_issues(dev, apdev):
3944 """DPP bootstrap key autogen issues"""
3945 check_dpp_capab(dev[0])
3946 check_dpp_capab(dev[1])
3947
3948 logger.info("dev0 displays QR Code")
a5387062 3949 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
f1042596
JM
3950 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
3951
3952 logger.info("dev1 scans QR Code")
0422d06b 3953 id1 = dev[1].dpp_qr_code(uri0)
f1042596
JM
3954
3955 logger.info("dev1 initiates DPP Authentication")
7e009100 3956 dev[0].dpp_listen(2412)
f1042596 3957 with alloc_fail(dev[1], 1, "dpp_autogen_bootstrap_key"):
5725b3e3 3958 dev[1].dpp_auth_init(peer=id1, expect_fail=True)
2bbe6ad3 3959 with alloc_fail(dev[1], 1, "dpp_gen_uri;dpp_autogen_bootstrap_key"):
5725b3e3 3960 dev[1].dpp_auth_init(peer=id1, expect_fail=True)
f1042596 3961 with fail_test(dev[1], 1, "dpp_keygen;dpp_autogen_bootstrap_key"):
5725b3e3 3962 dev[1].dpp_auth_init(peer=id1, expect_fail=True)
f1042596 3963 dev[0].request("DPP_STOP_LISTEN")
14ea96db
JM
3964
3965def test_dpp_auth_resp_status_failure(dev, apdev):
3966 """DPP and Auth Resp(status) build failure"""
3967 with alloc_fail(dev[0], 1, "dpp_auth_build_resp"):
3968 run_dpp_proto_auth_resp_missing(dev, 99999, None,
3969 incompatible_roles=True)
4ea1915b
JM
3970
3971def test_dpp_auth_resp_aes_siv_issue(dev, apdev):
3972 """DPP Auth Resp AES-SIV issue"""
3973 check_dpp_capab(dev[0])
3974 check_dpp_capab(dev[1])
4ea1915b 3975 logger.info("dev0 displays QR Code")
a5387062 3976 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
4ea1915b 3977 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
5725b3e3 3978 logger.info("dev1 scans QR Code and initiates DPP Authentication")
7e009100 3979 dev[0].dpp_listen(2412)
4ea1915b 3980 with fail_test(dev[1], 1, "aes_siv_decrypt;dpp_auth_resp_rx"):
5725b3e3 3981 dev[1].dpp_auth_init(uri=uri0)
203878d7 3982 wait_dpp_fail(dev[1], "AES-SIV decryption failed")
4ea1915b 3983 dev[0].request("DPP_STOP_LISTEN")
77e4f012
JM
3984
3985def test_dpp_invalid_legacy_params(dev, apdev):
3986 """DPP invalid legacy parameters"""
3987 check_dpp_capab(dev[0])
3988 check_dpp_capab(dev[1])
a5387062 3989 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
77e4f012 3990 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
77e4f012 3991 # No pass/psk
5725b3e3
JM
3992 dev[1].dpp_auth_init(uri=uri0, conf="sta-psk", ssid="dpp-legacy",
3993 expect_fail=True)
77e4f012
JM
3994
3995def test_dpp_invalid_legacy_params2(dev, apdev):
3996 """DPP invalid legacy parameters 2"""
3997 check_dpp_capab(dev[0])
3998 check_dpp_capab(dev[1])
a5387062 3999 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
77e4f012 4000 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
77e4f012 4001 dev[0].set("dpp_configurator_params",
54c58f29 4002 " conf=sta-psk ssid=%s" % (binascii.hexlify(b"dpp-legacy").decode()))
7e009100 4003 dev[0].dpp_listen(2412, role="configurator")
5725b3e3 4004 dev[1].dpp_auth_init(uri=uri0, role="enrollee")
77e4f012 4005 # No pass/psk
77e4f012
JM
4006 ev = dev[0].wait_event(["DPP: Failed to set configurator parameters"],
4007 timeout=5)
4008 if ev is None:
4009 raise Exception("DPP configuration failure not reported")
88d4e0ba
JM
4010
4011def test_dpp_legacy_params_failure(dev, apdev):
4012 """DPP legacy parameters local failure"""
4013 check_dpp_capab(dev[0])
4014 check_dpp_capab(dev[1])
a5387062 4015 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
88d4e0ba 4016 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
7e009100 4017 dev[0].dpp_listen(2412)
88d4e0ba 4018 with alloc_fail(dev[1], 1, "dpp_build_conf_obj_legacy"):
5725b3e3
JM
4019 dev[1].dpp_auth_init(uri=uri0, conf="sta-psk", passphrase="passphrase",
4020 ssid="dpp-legacy")
88d4e0ba
JM
4021 ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=5)
4022 if ev is None:
4023 raise Exception("DPP configuration failure not reported")
1ddf1b34
JM
4024
4025def test_dpp_invalid_configurator_key(dev, apdev):
4026 """DPP invalid configurator key"""
4027 check_dpp_capab(dev[0])
4028
4029 if "FAIL" not in dev[0].request("DPP_CONFIGURATOR_ADD key=aa"):
4030 raise Exception("Invalid key accepted")
4031
4032 with alloc_fail(dev[0], 1, "dpp_keygen_configurator"):
4033 if "FAIL" not in dev[0].request("DPP_CONFIGURATOR_ADD key=" + dpp_key_p256):
4034 raise Exception("Error not reported")
4035
4036 with alloc_fail(dev[0], 1, "dpp_get_pubkey_point;dpp_keygen_configurator"):
4037 if "FAIL" not in dev[0].request("DPP_CONFIGURATOR_ADD key=" + dpp_key_p256):
4038 raise Exception("Error not reported")
4039
4040 with alloc_fail(dev[0], 1, "base64_gen_encode;dpp_keygen_configurator"):
4041 if "FAIL" not in dev[0].request("DPP_CONFIGURATOR_ADD key=" + dpp_key_p256):
4042 raise Exception("Error not reported")
4043
4044 with fail_test(dev[0], 1, "dpp_keygen_configurator"):
4045 if "FAIL" not in dev[0].request("DPP_CONFIGURATOR_ADD key=" + dpp_key_p256):
4046 raise Exception("Error not reported")
b856b943
JM
4047
4048def test_dpp_own_config_sign_fail(dev, apdev):
4049 """DPP own config signing failure"""
4050 check_dpp_capab(dev[0])
e105110f 4051 conf_id = dev[0].dpp_configurator_add()
fab49f61
JM
4052 tests = ["",
4053 " ",
4054 " conf=sta-dpp",
4055 " configurator=%d" % conf_id,
4056 " conf=sta-dpp configurator=%d curve=unsupported" % conf_id]
b856b943
JM
4057 for t in tests:
4058 if "FAIL" not in dev[0].request("DPP_CONFIGURATOR_SIGN " + t):
4059 raise Exception("Invalid command accepted: " + t)
5c6c42aa
JM
4060
4061def test_dpp_peer_intro_failures(dev, apdev):
4062 """DPP peer introduction failures"""
4063 try:
4064 run_dpp_peer_intro_failures(dev, apdev)
4065 finally:
5bf51d38 4066 dev[0].set("dpp_config_processing", "0", allow_fail=True)
5c6c42aa
JM
4067
4068def run_dpp_peer_intro_failures(dev, apdev):
4069 check_dpp_capab(dev[0])
fab49f61 4070 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
5c6c42aa
JM
4071 check_dpp_capab(hapd)
4072
e105110f 4073 conf_id = hapd.dpp_configurator_add(key=dpp_key_p256)
5c6c42aa
JM
4074 csign = hapd.request("DPP_CONFIGURATOR_GET_KEY %d" % conf_id)
4075 if "FAIL" in csign or len(csign) == 0:
4076 raise Exception("DPP_CONFIGURATOR_GET_KEY failed")
4077
e105110f 4078 conf_id2 = dev[0].dpp_configurator_add(key=csign)
5c6c42aa
JM
4079 csign2 = dev[0].request("DPP_CONFIGURATOR_GET_KEY %d" % conf_id2)
4080
4081 if csign != csign2:
4082 raise Exception("Unexpected difference in configurator key")
4083
4084 cmd = "DPP_CONFIGURATOR_SIGN conf=ap-dpp configurator=%d" % conf_id
4085 res = hapd.request(cmd)
4086 if "FAIL" in res:
4087 raise Exception("Failed to generate own configuration")
4088 update_hapd_config(hapd)
4089
4090 dev[0].set("dpp_config_processing", "1")
4091 cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % conf_id
4092 res = dev[0].request(cmd)
4093 if "FAIL" in res:
4094 raise Exception("Failed to generate own configuration")
4095 ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
4096 if ev is None:
4097 raise Exception("DPP network profile not generated")
4098 id = ev.split(' ')[1]
4099 dev[0].select_network(id, freq=2412)
4100 dev[0].wait_connected()
4101 dev[0].request("DISCONNECT")
4102 dev[0].wait_disconnected()
4103 dev[0].dump_monitor()
4104
fab49f61
JM
4105 tests = ["eyJ0eXAiOiJkcHBDb24iLCJraWQiOiIwTlNSNTlxRTc0alFfZTFLVGVPV1lYY1pTWnFUaDdNXzU0aHJPcFRpaFJnIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOltdLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiJiVmFMRGlBT09OQmFjcVFVN1pYamFBVEtEMVhhbDVlUExqOUZFZUl3VkN3IiwieSI6Il95c25JR1hTYjBvNEsyMWg0anZmSkZxMHdVNnlPNWp1VUFPd3FuM0dHVHMifX0.WgzZBOJaisWBRxvtXPbVYPXU7OIZxs6sZD-cPOLmJVTIYZKdMkSOMvP5b6si_j61FIrjhm43tmGq1P6cpoxB_g",
4106 "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiIwTlNSNTlxRTc0alFfZTFLVGVPV1lYY1pTWnFUaDdNXzU0aHJPcFRpaFJnIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7fV0sIm5ldEFjY2Vzc0tleSI6eyJrdHkiOiJFQyIsImNydiI6IlAtMjU2IiwieCI6IkJhY3BWSDNpNDBrZklNS0RHa1FFRzhCODBCaEk4cEFmTWpLbzM5NlFZT2ciLCJ5IjoiMjBDYjhDNjRsSjFzQzV2NXlKMnBFZXRRempxMjI4YVV2cHMxNmQ0M3EwQSJ9fQ.dG2y8VvZQJ5hfob8E5F2FAeR7Nd700qstYkxDgA2QfARaNMZ0_SfKfoG-yKXsIZNM-TvGBfACgfhagG9Oaw_Xw",
4107 "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiIwTlNSNTlxRTc0alFfZTFLVGVPV1lYY1pTWnFUaDdNXzU0aHJPcFRpaFJnIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiJkc2VmcmJWWlhad0RMWHRpLWlObDBBYkFIOXpqeFFKd0R1SUd5NzNuZGU0IiwieSI6IjZFQnExN3cwYW1fZlh1OUQ4UGxWYk9XZ2I3b19DcTUxWHlmSG8wcHJyeDQifX0.caBvdDUtXrhnS61-juVZ_2FQdprepv0yZjC04G4ERvLUpeX7cgu0Hp-A1aFDogP1PEFGpkaEdcAWRQnSSRiIKQ"]
5c6c42aa
JM
4108 for t in tests:
4109 dev[0].set_network_quoted(id, "dpp_connector", t)
4110 dev[0].select_network(id, freq=2412)
4111 ev = dev[0].wait_event(["DPP-INTRO"], timeout=5)
4112 if ev is None or "status=8" not in ev:
4113 raise Exception("Introduction failure not reported")
4114 dev[0].request("DISCONNECT")
4115 dev[0].dump_monitor()
7e26f1bc
JM
4116
4117def test_dpp_peer_intro_local_failures(dev, apdev):
4118 """DPP peer introduction local failures"""
4119 check_dpp_capab(dev[0])
4120 check_dpp_capab(dev[1])
4121
fab49f61
JM
4122 params = {"ssid": "dpp",
4123 "wpa": "2",
4124 "wpa_key_mgmt": "DPP",
4125 "ieee80211w": "2",
4126 "rsn_pairwise": "CCMP",
4127 "dpp_connector": params1_ap_connector,
4128 "dpp_csign": params1_csign,
4129 "dpp_netaccesskey": params1_ap_netaccesskey}
7e26f1bc
JM
4130 try:
4131 hapd = hostapd.add_ap(apdev[0], params)
4132 except:
4133 raise HwsimSkip("DPP not supported")
4134
fab49f61
JM
4135 tests = ["dpp_derive_pmk",
4136 "dpp_hkdf_expand;dpp_derive_pmk",
4137 "dpp_derive_pmkid"]
7e26f1bc
JM
4138 for func in tests:
4139 with fail_test(dev[0], 1, func):
4140 dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
4141 ieee80211w="2",
4142 dpp_csign=params1_csign,
4143 dpp_connector=params1_sta_connector,
4144 dpp_netaccesskey=params1_sta_netaccesskey,
4145 wait_connect=False)
4146 ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
4147 if ev is None or "fail=peer_connector_validation_failed" not in ev:
4148 raise Exception("Introduction failure not reported")
4149 dev[0].request("REMOVE_NETWORK all")
4150 dev[0].dump_monitor()
4151
fab49f61
JM
4152 tests = [(1, "base64_gen_decode;dpp_peer_intro"),
4153 (1, "json_parse;dpp_peer_intro"),
4154 (50, "json_parse;dpp_peer_intro"),
4155 (1, "=dpp_peer_intro"),
4156 (1, "dpp_parse_jwk")]
4157 for count, func in tests:
7e26f1bc
JM
4158 with alloc_fail(dev[0], count, func):
4159 dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
4160 ieee80211w="2",
4161 dpp_csign=params1_csign,
4162 dpp_connector=params1_sta_connector,
4163 dpp_netaccesskey=params1_sta_netaccesskey,
4164 wait_connect=False)
4165 ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
4166 if ev is None or "fail=peer_connector_validation_failed" not in ev:
4167 raise Exception("Introduction failure not reported")
4168 dev[0].request("REMOVE_NETWORK all")
4169 dev[0].dump_monitor()
4170
4171 parts = params1_ap_connector.split('.')
fab49f61 4172 for ap_connector in ['.'.join(parts[0:2]), '.'.join(parts[0:1])]:
7e26f1bc
JM
4173 hapd.set("dpp_connector", ap_connector)
4174 dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
4175 ieee80211w="2",
4176 dpp_csign=params1_csign,
4177 dpp_connector=params1_sta_connector,
4178 dpp_netaccesskey=params1_sta_netaccesskey,
4179 wait_connect=False)
4180 ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=10)
4181 if ev is None:
4182 raise Exception("No TX status reported")
4183 dev[0].request("REMOVE_NETWORK all")
4184 dev[0].dump_monitor()
4185
4186 hapd.set("dpp_netaccesskey", "00")
4187 dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
4188 ieee80211w="2",
4189 dpp_csign=params1_csign,
4190 dpp_connector=params1_sta_connector,
4191 dpp_netaccesskey=params1_sta_netaccesskey,
4192 wait_connect=False)
4193 ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=10)
4194 if ev is None:
4195 raise Exception("No TX status reported")
4196 dev[0].request("REMOVE_NETWORK all")
4197 dev[0].dump_monitor()
4198
4199 hapd.set("dpp_csign", "00")
4200 dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
4201 ieee80211w="2",
4202 dpp_csign=params1_csign,
4203 dpp_connector=params1_sta_connector,
4204 dpp_netaccesskey=params1_sta_netaccesskey,
4205 wait_connect=False)
4206 ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=10)
4207 if ev is None:
4208 raise Exception("No TX status reported")
4209 dev[0].request("REMOVE_NETWORK all")
d0e88871
JM
4210
4211def run_dpp_configurator_id_unknown(dev):
4212 check_dpp_capab(dev)
e105110f 4213 conf_id = dev.dpp_configurator_add()
d0e88871
JM
4214 if "FAIL" not in dev.request("DPP_CONFIGURATOR_GET_KEY %d" % (conf_id + 1)):
4215 raise Exception("DPP_CONFIGURATOR_GET_KEY with incorrect id accepted")
4216
4217 cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id + 1)
4218 if "FAIL" not in dev.request(cmd):
4219 raise Exception("DPP_CONFIGURATOR_SIGN with incorrect id accepted")
4220
4221def test_dpp_configurator_id_unknown(dev, apdev):
4222 """DPP and unknown configurator id"""
4223 run_dpp_configurator_id_unknown(dev[0])
fab49f61 4224 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
d0e88871 4225 run_dpp_configurator_id_unknown(hapd)
88c08a29 4226
5be5b816 4227def run_dpp_bootstrap_gen_failures(dev):
88c08a29
JM
4228 check_dpp_capab(dev)
4229
fab49f61
JM
4230 tests = ["type=unsupported",
4231 "type=qrcode chan=-1",
4232 "type=qrcode mac=a",
4233 "type=qrcode key=qq",
4234 "type=qrcode key=",
4235 "type=qrcode info=abc\tdef"]
88c08a29
JM
4236 for t in tests:
4237 if "FAIL" not in dev.request("DPP_BOOTSTRAP_GEN " + t):
4238 raise Exception("Command accepted unexpectedly")
4239
a5387062
JM
4240 id = dev.dpp_bootstrap_gen()
4241 uri = dev.request("DPP_BOOTSTRAP_GET_URI %d" % id)
88c08a29
JM
4242 if not uri.startswith("DPP:"):
4243 raise Exception("Could not get URI")
4244 if "FAIL" not in dev.request("DPP_BOOTSTRAP_GET_URI 0"):
4245 raise Exception("Failure not reported")
a5387062 4246 info = dev.request("DPP_BOOTSTRAP_INFO %d" % id)
88c08a29
JM
4247 if not info.startswith("type=QRCODE"):
4248 raise Exception("Could not get info")
4249 if "FAIL" not in dev.request("DPP_BOOTSTRAP_REMOVE 0"):
4250 raise Exception("Failure not reported")
4251 if "FAIL" in dev.request("DPP_BOOTSTRAP_REMOVE *"):
4252 raise Exception("Failed to remove bootstrap info")
a5387062 4253 if "FAIL" not in dev.request("DPP_BOOTSTRAP_GET_URI %d" % id):
88c08a29 4254 raise Exception("Failure not reported")
a5387062 4255 if "FAIL" not in dev.request("DPP_BOOTSTRAP_INFO %d" % id):
88c08a29
JM
4256 raise Exception("Failure not reported")
4257
5be5b816 4258 func = "dpp_bootstrap_gen"
88c08a29
JM
4259 with alloc_fail(dev, 1, "=" + func):
4260 if "FAIL" not in dev.request("DPP_BOOTSTRAP_GEN type=qrcode"):
4261 raise Exception("Command accepted unexpectedly")
4262
2bbe6ad3 4263 with alloc_fail(dev, 1, "dpp_gen_uri;dpp_bootstrap_gen"):
88c08a29
JM
4264 if "FAIL" not in dev.request("DPP_BOOTSTRAP_GEN type=qrcode"):
4265 raise Exception("Command accepted unexpectedly")
4266
4267 with alloc_fail(dev, 1, "get_param"):
4268 dev.request("DPP_BOOTSTRAP_GEN type=qrcode curve=foo")
4269
4270def test_dpp_bootstrap_gen_failures(dev, apdev):
4271 """DPP_BOOTSTRAP_GEN/REMOVE/GET_URI/INFO error cases"""
5be5b816 4272 run_dpp_bootstrap_gen_failures(dev[0])
fab49f61 4273 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
5be5b816 4274 run_dpp_bootstrap_gen_failures(hapd)
fe7c91f8
JM
4275
4276def test_dpp_listen_continue(dev, apdev):
4277 """DPP and continue listen state"""
4278 check_dpp_capab(dev[0])
4279 check_dpp_capab(dev[1])
a5387062
JM
4280 id = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
4281 uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
7e009100 4282 dev[0].dpp_listen(2412)
fe7c91f8 4283 time.sleep(5.1)
5725b3e3
JM
4284 dev[1].dpp_auth_init(uri=uri)
4285 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0],
4286 allow_enrollee_failure=True, stop_responder=True,
4287 stop_initiator=True)
d0cd2d1a
JM
4288
4289def test_dpp_network_addition_failure(dev, apdev):
4290 """DPP network addition failure"""
4291 try:
4292 run_dpp_network_addition_failure(dev, apdev)
4293 finally:
5bf51d38 4294 dev[0].set("dpp_config_processing", "0", allow_fail=True)
d0cd2d1a
JM
4295
4296def run_dpp_network_addition_failure(dev, apdev):
4297 check_dpp_capab(dev[0])
e105110f 4298 conf_id = dev[0].dpp_configurator_add()
d0cd2d1a
JM
4299 dev[0].set("dpp_config_processing", "1")
4300 cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % conf_id
fab49f61
JM
4301 tests = [(1, "=wpas_dpp_add_network"),
4302 (2, "=wpas_dpp_add_network"),
4303 (3, "=wpas_dpp_add_network"),
4304 (4, "=wpas_dpp_add_network"),
4305 (1, "wpa_config_add_network;wpas_dpp_add_network")]
4306 for count, func in tests:
d0cd2d1a
JM
4307 with alloc_fail(dev[0], count, func):
4308 res = dev[0].request(cmd)
8b6c834f
JM
4309 if "OK" in res:
4310 ev = dev[0].wait_event(["DPP-NET-ACCESS-KEY"], timeout=2)
4311 if ev is None:
4312 raise Exception("Config object not processed")
d0cd2d1a
JM
4313 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
4314 dev[0].dump_monitor()
4315
54c58f29 4316 cmd = "DPP_CONFIGURATOR_SIGN conf=sta-psk pass=%s configurator=%d" % (binascii.hexlify(b"passphrase").decode(), conf_id)
fab49f61
JM
4317 tests = [(1, "wpa_config_set_quoted;wpas_dpp_add_network")]
4318 for count, func in tests:
d0cd2d1a
JM
4319 with alloc_fail(dev[0], count, func):
4320 res = dev[0].request(cmd)
8b6c834f
JM
4321 if "OK" in res:
4322 ev = dev[0].wait_event(["DPP-NET-ACCESS-KEY"], timeout=2)
4323 if ev is None:
4324 raise Exception("Config object not processed")
d0cd2d1a
JM
4325 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
4326 dev[0].dump_monitor()
051c8cae
JM
4327
4328def test_dpp_two_initiators(dev, apdev):
4329 """DPP and two initiators"""
4330 check_dpp_capab(dev[0])
4331 check_dpp_capab(dev[1])
4332 check_dpp_capab(dev[2])
a5387062
JM
4333 id = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
4334 uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
7e009100 4335 dev[0].dpp_listen(2412)
5725b3e3 4336 dev[1].dpp_auth_init(uri=uri)
051c8cae
JM
4337 ev = dev[0].wait_event(["DPP-RX"], timeout=5)
4338 if ev is None:
4339 raise Exeption("No DPP Authentication Request seen")
5725b3e3 4340 dev[2].dpp_auth_init(uri=uri)
203878d7
JM
4341 wait_dpp_fail(dev[0],
4342 "DPP-FAIL Already in DPP authentication exchange - ignore new one")
051c8cae
JM
4343
4344 ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=2)
4345 if ev is None:
4346 raise Exception("DPP configuration result not seen (Enrollee)")
4347 ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=2)
4348 if ev is None:
4349 raise Exception("DPP configuration result not seen (Responder)")
4350
4351 dev[0].request("DPP_STOP_LISTEN")
4352 dev[1].request("DPP_STOP_LISTEN")
4353 dev[2].request("DPP_STOP_LISTEN")
7010f4be
JM
4354
4355def test_dpp_conf_file_update(dev, apdev, params):
4356 """DPP provisioning updating wpa_supplicant configuration file"""
4357 config = os.path.join(params['logdir'], 'dpp_conf_file_update.conf')
4358 with open(config, "w") as f:
4359 f.write("update_config=1\n")
4360 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
4361 wpas.interface_add("wlan5", config=config)
5bf51d38 4362 check_dpp_capab(wpas)
7010f4be 4363 wpas.set("dpp_config_processing", "1")
fab49f61 4364 run_dpp_qr_code_auth_unicast([wpas, dev[1]], apdev, None,
7010f4be
JM
4365 init_extra="conf=sta-dpp",
4366 require_conf_success=True,
4367 configurator=True)
4368 wpas.interface_remove("wlan5")
4369
4370 with open(config, "r") as f:
4371 res = f.read()
fab49f61
JM
4372 for i in ["network={", "dpp_connector=", "key_mgmt=DPP", "ieee80211w=2",
4373 "dpp_netaccesskey=", "dpp_csign="]:
7010f4be
JM
4374 if i not in res:
4375 raise Exception("Configuration file missing '%s'" % i)
4376
4377 wpas.interface_add("wlan5", config=config)
4378 if len(wpas.list_networks()) != 1:
4379 raise Exception("Unexpected number of networks")
ba6ce9c6
JM
4380
4381def test_dpp_duplicated_auth_resp(dev, apdev):
4382 """DPP and duplicated Authentication Response"""
4383 check_dpp_capab(dev[0])
4384 check_dpp_capab(dev[1])
ba6ce9c6
JM
4385 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
4386 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
ba6ce9c6
JM
4387 dev[0].set("ext_mgmt_frame_handling", "1")
4388 dev[1].set("ext_mgmt_frame_handling", "1")
7e009100 4389 dev[0].dpp_listen(2412)
5725b3e3 4390 dev[1].dpp_auth_init(uri=uri0)
ba6ce9c6
JM
4391
4392 # DPP Authentication Request
4393 rx_process_frame(dev[0])
4394
4395 # DPP Authentication Response
4396 msg = rx_process_frame(dev[1])
4397 frame = binascii.hexlify(msg['frame']).decode()
4398 # Duplicated frame
4399 if "OK" not in dev[1].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame)):
4400 raise Exception("MGMT_RX_PROCESS failed")
4401 # Modified frame - nonzero status
4402 if frame[2*32:2*37] != "0010010000":
4403 raise Exception("Could not find Status attribute")
4404 frame2 = frame[0:2*32] + "0010010001" + frame[2*37:]
4405 if "OK" not in dev[1].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame2)):
4406 raise Exception("MGMT_RX_PROCESS failed")
4407 frame2 = frame[0:2*32] + "00100100ff" + frame[2*37:]
4408 if "OK" not in dev[1].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], frame2)):
4409 raise Exception("MGMT_RX_PROCESS failed")
4410
4411 # DPP Authentication Confirmation
4412 rx_process_frame(dev[0])
4413
4414 wait_auth_success(dev[0], dev[1])
4415
4416 # DPP Configuration Request
4417 rx_process_frame(dev[1])
4418
4419 # DPP Configuration Response
4420 rx_process_frame(dev[0])
4421
4422 wait_conf_completion(dev[1], dev[0])
8ad1009e 4423
71281978
JM
4424def test_dpp_duplicated_auth_conf(dev, apdev):
4425 """DPP and duplicated Authentication Confirmation"""
4426 check_dpp_capab(dev[0])
4427 check_dpp_capab(dev[1])
4428 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
4429 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
4430 dev[0].set("ext_mgmt_frame_handling", "1")
4431 dev[1].set("ext_mgmt_frame_handling", "1")
4432 dev[0].dpp_listen(2412)
4433 dev[1].dpp_auth_init(uri=uri0)
4434
4435 # DPP Authentication Request
4436 rx_process_frame(dev[0])
4437
4438 # DPP Authentication Response
4439 rx_process_frame(dev[1])
4440
4441 # DPP Authentication Confirmation
4442 msg = rx_process_frame(dev[0])
4443 # Duplicated frame
4444 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())):
4445 raise Exception("MGMT_RX_PROCESS failed")
4446
4447 wait_auth_success(dev[0], dev[1])
4448
4449 # DPP Configuration Request
4450 rx_process_frame(dev[1])
4451
4452 # DPP Configuration Response
4453 rx_process_frame(dev[0])
4454
4455 wait_conf_completion(dev[1], dev[0])
4456
8ad1009e
JM
4457def test_dpp_enrollee_reject_config(dev, apdev):
4458 """DPP and Enrollee rejecting Config Object"""
4459 check_dpp_capab(dev[0])
4460 check_dpp_capab(dev[1])
4461 dev[0].set("dpp_test", "91")
8ad1009e
JM
4462 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
4463 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
7e009100 4464 dev[0].dpp_listen(2412)
5725b3e3
JM
4465 dev[1].dpp_auth_init(uri=uri0, conf="sta-sae", ssid="dpp-legacy",
4466 passphrase="secret passphrase")
4467 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0],
4468 allow_enrollee_failure=True,
4469 allow_configurator_failure=True)
8ad1009e
JM
4470
4471def test_dpp_enrollee_ap_reject_config(dev, apdev):
4472 """DPP and Enrollee AP rejecting Config Object"""
4473 check_dpp_capab(dev[0])
4474 check_dpp_capab(dev[1])
fab49f61 4475 hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
8ad1009e
JM
4476 check_dpp_capab(hapd)
4477 hapd.set("dpp_test", "91")
e105110f 4478 conf_id = dev[0].dpp_configurator_add()
8ad1009e
JM
4479 id_h = hapd.dpp_bootstrap_gen(chan="81/1", mac=True)
4480 uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
5725b3e3
JM
4481 dev[0].dpp_auth_init(uri=uri, conf="ap-dpp", configurator=conf_id)
4482 wait_auth_success(hapd, dev[0], configurator=dev[0], enrollee=hapd,
4483 allow_enrollee_failure=True,
4484 allow_configurator_failure=True)
009b54be
JM
4485
4486def test_dpp_legacy_and_dpp_akm(dev, apdev):
4487 """DPP and provisoning DPP and legacy AKMs"""
4488 try:
4489 run_dpp_legacy_and_dpp_akm(dev, apdev)
4490 finally:
5bf51d38 4491 dev[0].set("dpp_config_processing", "0", allow_fail=True)
009b54be
JM
4492
4493def run_dpp_legacy_and_dpp_akm(dev, apdev):
4494 check_dpp_capab(dev[0], min_ver=2)
4495 check_dpp_capab(dev[1], min_ver=2)
4496
4497 csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
4498 csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
4499 ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
4500 ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
4501
4502 ssid = "dpp-both"
4503 passphrase = "secret passphrase"
4504 params = {"ssid": ssid,
4505 "wpa": "2",
4506 "wpa_key_mgmt": "DPP WPA-PSK SAE",
4507 "ieee80211w": "1",
4508 "sae_require_mfp": '1',
4509 "rsn_pairwise": "CCMP",
4510 "wpa_passphrase": passphrase,
4511 "dpp_connector": ap_connector,
4512 "dpp_csign": csign_pub,
4513 "dpp_netaccesskey": ap_netaccesskey}
4514 try:
4515 hapd = hostapd.add_ap(apdev[0], params)
4516 except:
4517 raise HwsimSkip("DPP not supported")
4518
c9ead82d 4519 dev[0].request("SET sae_groups ")
e105110f 4520 conf_id = dev[1].dpp_configurator_add(key=csign)
009b54be
JM
4521 dev[0].set("dpp_config_processing", "1")
4522 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
4523 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
7e009100 4524 dev[0].dpp_listen(2412)
5725b3e3
JM
4525 dev[1].dpp_auth_init(uri=uri0, conf="sta-psk-sae-dpp", ssid=ssid,
4526 passphrase=passphrase, configurator=conf_id)
4527 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0],
4528 allow_enrollee_failure=True,
4529 allow_configurator_failure=True)
009b54be
JM
4530 ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
4531 if ev is None:
4532 raise Exception("DPP network profile not generated")
4533 id0 = ev.split(' ')[1]
4534
4535 key_mgmt = dev[0].get_network(id0, "key_mgmt").split(' ')
4536 for m in ["SAE", "WPA-PSK", "DPP"]:
4537 if m not in key_mgmt:
4538 raise Exception("%s missing from key_mgmt" % m)
4539
4540 dev[0].scan_for_bss(hapd.own_addr(), freq=2412)
4541 dev[0].select_network(id0, freq=2412)
4542 dev[0].wait_connected()
4543
4544 dev[0].request("DISCONNECT")
4545 dev[0].wait_disconnected()
4546 hapd.disable()
4547
4548 params = {"ssid": ssid,
4549 "wpa": "2",
4550 "wpa_key_mgmt": "WPA-PSK SAE",
4551 "ieee80211w": "1",
4552 "sae_require_mfp": '1',
4553 "rsn_pairwise": "CCMP",
4554 "wpa_passphrase": passphrase}
4555 hapd2 = hostapd.add_ap(apdev[1], params)
4556
4557 dev[0].request("BSS_FLUSH 0")
4558 dev[0].scan_for_bss(hapd2.own_addr(), freq=2412, force_scan=True,
4559 only_new=True)
4560 dev[0].select_network(id0, freq=2412)
4561 dev[0].wait_connected()
4562
4563 dev[0].request("DISCONNECT")
4564 dev[0].wait_disconnected()
5fbefcc6
JM
4565
4566def test_dpp_controller_relay(dev, apdev, params):
4567 """DPP Controller/Relay"""
4568 try:
4569 run_dpp_controller_relay(dev, apdev, params)
4570 finally:
5bf51d38 4571 dev[0].set("dpp_config_processing", "0", allow_fail=True)
5fbefcc6
JM
4572 dev[1].request("DPP_CONTROLLER_STOP")
4573
4574def run_dpp_controller_relay(dev, apdev, params):
4575 check_dpp_capab(dev[0])
4576 check_dpp_capab(dev[1])
4577 prefix = "dpp_controller_relay"
4578 cap_lo = os.path.join(params['logdir'], prefix + ".lo.pcap")
4579
4e9bcdeb 4580 wt = WlantestCapture('lo', cap_lo)
5fbefcc6
JM
4581
4582 # Controller
4583 conf_id = dev[1].dpp_configurator_add()
4584 dev[1].set("dpp_configurator_params",
4585 " conf=sta-dpp configurator=%d" % conf_id)
4586 id_c = dev[1].dpp_bootstrap_gen()
4587 uri_c = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
4588 res = dev[1].request("DPP_BOOTSTRAP_INFO %d" % id_c)
4589 pkhash = None
4590 for line in res.splitlines():
4591 name, value = line.split('=')
4592 if name == "pkhash":
4593 pkhash = value
4594 break
4595 if not pkhash:
4596 raise Exception("Could not fetch public key hash from Controller")
4597 if "OK" not in dev[1].request("DPP_CONTROLLER_START"):
4598 raise Exception("Failed to start Controller")
4599
4600 # Relay
4601 params = {"ssid": "unconfigured",
4602 "channel": "6",
4603 "dpp_controller": "ipaddr=127.0.0.1 pkhash=" + pkhash}
4604 relay = hostapd.add_ap(apdev[1], params)
4605 check_dpp_capab(relay)
4606
4607 # Enroll Relay to the network
4608 # TODO: Do this over TCP once direct Enrollee-over-TCP case is supported
4609 id_h = relay.dpp_bootstrap_gen(chan="81/6", mac=True)
4610 uri_r = relay.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
4611 dev[1].dpp_auth_init(uri=uri_r, conf="ap-dpp", configurator=conf_id)
4612 wait_auth_success(relay, dev[1], configurator=dev[1], enrollee=relay)
4613 update_hapd_config(relay)
4614
4615 # Initiate from Enrollee with broadcast DPP Authentication Request
4616 dev[0].set("dpp_config_processing", "2")
4617 dev[0].dpp_auth_init(uri=uri_c, role="enrollee")
4618 wait_auth_success(dev[1], dev[0], configurator=dev[1], enrollee=dev[0],
4619 allow_enrollee_failure=True,
4620 allow_configurator_failure=True)
4621 dev[0].wait_connected()
4622
4623 time.sleep(0.5)
4e9bcdeb 4624 wt.close()
5fbefcc6
JM
4625
4626def test_dpp_tcp(dev, apdev, params):
4627 """DPP over TCP"""
4628 prefix = "dpp_tcp"
4629 cap_lo = os.path.join(params['logdir'], prefix + ".lo.pcap")
4630 try:
4631 run_dpp_tcp(dev, apdev, cap_lo)
4632 finally:
4633 dev[1].request("DPP_CONTROLLER_STOP")
4634
4635def test_dpp_tcp_port(dev, apdev, params):
4636 """DPP over TCP and specified port"""
4637 prefix = "dpp_tcp_port"
4638 cap_lo = os.path.join(params['logdir'], prefix + ".lo.pcap")
4639 try:
4640 run_dpp_tcp(dev, apdev, cap_lo, port="23456")
4641 finally:
4642 dev[1].request("DPP_CONTROLLER_STOP")
4643
4644def run_dpp_tcp(dev, apdev, cap_lo, port=None):
4645 check_dpp_capab(dev[0])
4646 check_dpp_capab(dev[1])
4647
4e9bcdeb 4648 wt = WlantestCapture('lo', cap_lo)
5fbefcc6
JM
4649 time.sleep(1)
4650
4651 # Controller
4652 conf_id = dev[1].dpp_configurator_add()
4653 dev[1].set("dpp_configurator_params",
4654 " conf=sta-dpp configurator=%d" % conf_id)
4655 id_c = dev[1].dpp_bootstrap_gen()
4656 uri_c = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
4657 res = dev[1].request("DPP_BOOTSTRAP_INFO %d" % id_c)
4658 pkhash = None
4659 for line in res.splitlines():
4660 name, value = line.split('=')
4661 if name == "pkhash":
4662 pkhash = value
4663 break
4664 if not pkhash:
4665 raise Exception("Could not fetch public key hash from Controller")
4666 req = "DPP_CONTROLLER_START"
4667 if port:
4668 req += " tcp_port=" + port
4669 if "OK" not in dev[1].request(req):
4670 raise Exception("Failed to start Controller")
4671
4672 # Initiate from Enrollee with broadcast DPP Authentication Request
4673 dev[0].dpp_auth_init(uri=uri_c, role="enrollee", tcp_addr="127.0.0.1",
4674 tcp_port=port)
4675 wait_auth_success(dev[1], dev[0], configurator=dev[1], enrollee=dev[0],
4676 allow_enrollee_failure=True,
4677 allow_configurator_failure=True)
4678 time.sleep(0.5)
4e9bcdeb 4679 wt.close()
16149090
JM
4680
4681def test_dpp_tcp_controller_start_failure(dev, apdev, params):
4682 """DPP Controller startup failure"""
4683 check_dpp_capab(dev[0])
4684
4685 try:
4686 if "OK" not in dev[0].request("DPP_CONTROLLER_START"):
4687 raise Exception("Could not start Controller")
4688 if "OK" in dev[0].request("DPP_CONTROLLER_START"):
4689 raise Exception("Second Controller start not rejected")
4690 finally:
4691 dev[0].request("DPP_CONTROLLER_STOP")
4692
4693 tests = ["dpp_controller_start",
4694 "eloop_sock_table_add_sock;?eloop_register_sock;dpp_controller_start"]
4695 for func in tests:
4696 with alloc_fail(dev[0], 1, func):
4697 if "FAIL" not in dev[0].request("DPP_CONTROLLER_START"):
4698 raise Exception("Failure not reported during OOM")
4699
4700def test_dpp_tcp_init_failure(dev, apdev, params):
4701 """DPP TCP init failure"""
4702 check_dpp_capab(dev[0])
4703 check_dpp_capab(dev[1])
4704 id_c = dev[1].dpp_bootstrap_gen()
4705 uri_c = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
4706 peer = dev[0].dpp_qr_code(uri_c)
4707 tests = ["dpp_tcp_init",
4708 "eloop_sock_table_add_sock;?eloop_register_sock;dpp_tcp_init",
4709 "dpp_tcp_encaps"]
4710 cmd = "DPP_AUTH_INIT peer=%d tcp_addr=127.0.0.1" % peer
4711 for func in tests:
4712 with alloc_fail(dev[0], 1, func):
4713 if "FAIL" not in dev[0].request(cmd):
4714 raise Exception("DPP_AUTH_INIT accepted during OOM")
4715
4716def test_dpp_controller_rx_failure(dev, apdev, params):
4717 """DPP Controller RX failure"""
4718 check_dpp_capab(dev[0])
4719 check_dpp_capab(dev[1])
4720 try:
4721 run_dpp_controller_rx_failure(dev, apdev)
4722 finally:
4723 dev[0].request("DPP_CONTROLLER_STOP")
4724
4725def run_dpp_controller_rx_failure(dev, apdev):
4726 if "OK" not in dev[0].request("DPP_CONTROLLER_START"):
4727 raise Exception("Could not start Controller")
4728 id_c = dev[0].dpp_bootstrap_gen()
4729 uri_c = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
4730 peer = dev[1].dpp_qr_code(uri_c)
4731 tests = ["dpp_controller_tcp_cb",
4732 "eloop_sock_table_add_sock;?eloop_register_sock;dpp_controller_tcp_cb",
4733 "dpp_controller_rx",
4734 "dpp_controller_rx_auth_req",
4735 "wpabuf_alloc;=dpp_controller_rx_auth_req"]
4736 cmd = "DPP_AUTH_INIT peer=%d tcp_addr=127.0.0.1" % peer
4737 for func in tests:
4738 with alloc_fail(dev[0], 1, func):
4739 if "OK" not in dev[1].request(cmd):
4740 raise Exception("Failed to initiate TCP connection")
4741 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
b4928ff9
JM
4742
4743def test_dpp_controller_rx_errors(dev, apdev, params):
4744 """DPP Controller RX error cases"""
4745 check_dpp_capab(dev[0])
4746 check_dpp_capab(dev[1])
4747 try:
4748 run_dpp_controller_rx_errors(dev, apdev)
4749 finally:
4750 dev[0].request("DPP_CONTROLLER_STOP")
4751
4752def run_dpp_controller_rx_errors(dev, apdev):
4753 if "OK" not in dev[0].request("DPP_CONTROLLER_START"):
4754 raise Exception("Could not start Controller")
4755
4756 addr = ("127.0.0.1", 7871)
4757
4758 tests = [b"abc",
4759 b"abcd",
4760 b"\x00\x00\x00\x00",
4761 b"\x00\x00\x00\x01",
4762 b"\x00\x00\x00\x01\x09",
4763 b"\x00\x00\x00\x07\x09\x50\x6f\x9a\x1a\xff\xff",
4764 b"\x00\x00\x00\x07\x09\x50\x6f\x9a\x1a\x01\xff",
4765 b"\x00\x00\x00\x07\x09\x50\x6f\x9a\x1a\x01\x00",
4766 b"\x00\x00\x00\x08\x09\x50\x6f\x9a\x1a\x01\x00\xff",
4767 b"\x00\x00\x00\x01\x0a",
4768 b"\x00\x00\x00\x04\x0a\xff\xff\xff",
4769 b"\x00\x00\x00\x01\x0b",
4770 b"\x00\x00\x00\x08\x0b\xff\xff\xff\xff\xff\xff\xff",
4771 b"\x00\x00\x00\x08\x0b\xff\x00\x00\xff\xff\xff\xff",
4772 b"\x00\x00\x00\x08\x0b\xff\x00\x00\xff\xff\x6c\x00",
4773 b"\x00\x00\x00\x0a\x0b\xff\x00\x00\xff\xff\x6c\x02\xff\xff",
4774 b"\x00\x00\x00\x10\x0b\xff\x00\x00\xff\xff\x6c\x08\xff\xdd\x05\x50\x6f\x9a\x1a\x01",
4775 b"\x00\x00\x00\x12\x0b\xff\x00\x00\xff\xff\x6c\x08\xff\xdd\x05\x50\x6f\x9a\x1a\x01\x00\x00",
4776 b"\x00\x00\x00\x01\xff",
4777 b"\x00\x00\x00\x01\xff\xee"]
4778 #define WLAN_PA_GAS_INITIAL_REQ 10
4779 #define WLAN_PA_GAS_INITIAL_RESP 11
4780
4781 for t in tests:
4782 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
4783 socket.IPPROTO_TCP)
4784 sock.settimeout(0.1)
4785 sock.connect(addr)
4786 sock.send(t)
4787 sock.shutdown(1)
4788 try:
4789 sock.recv(10)
4790 except socket.timeout:
4791 pass
4792 sock.close()
b256d939
JM
4793
4794def test_dpp_conn_status_success(dev, apdev):
4795 """DPP connection status - success"""
4796 try:
4797 run_dpp_conn_status(dev, apdev)
4798 finally:
5bf51d38 4799 dev[0].set("dpp_config_processing", "0", allow_fail=True)
b256d939
JM
4800
4801def test_dpp_conn_status_wrong_passphrase(dev, apdev):
4802 """DPP connection status - wrong passphrase"""
4803 try:
4804 run_dpp_conn_status(dev, apdev, result=2)
4805 finally:
5bf51d38 4806 dev[0].set("dpp_config_processing", "0", allow_fail=True)
b256d939
JM
4807
4808def test_dpp_conn_status_no_ap(dev, apdev):
4809 """DPP connection status - no AP"""
4810 try:
4811 run_dpp_conn_status(dev, apdev, result=10)
4812 finally:
5bf51d38 4813 dev[0].set("dpp_config_processing", "0", allow_fail=True)
b256d939
JM
4814
4815def test_dpp_conn_status_connector_mismatch(dev, apdev):
4816 """DPP connection status - invalid Connector"""
4817 try:
4818 run_dpp_conn_status(dev, apdev, result=8)
4819 finally:
5bf51d38 4820 dev[0].set("dpp_config_processing", "0", allow_fail=True)
b256d939 4821
972edba1
JM
4822def test_dpp_conn_status_assoc_reject(dev, apdev):
4823 """DPP connection status - association rejection"""
4824 try:
4825 dev[0].request("TEST_ASSOC_IE 30020000")
4826 run_dpp_conn_status(dev, apdev, assoc_reject=True)
4827 finally:
5bf51d38 4828 dev[0].set("dpp_config_processing", "0", allow_fail=True)
972edba1
JM
4829
4830def run_dpp_conn_status(dev, apdev, result=0, assoc_reject=False):
b256d939
JM
4831 check_dpp_capab(dev[0], min_ver=2)
4832 check_dpp_capab(dev[1], min_ver=2)
4833
4834 if result != 10:
4835 if result == 7 or result == 8:
4836 params = {"ssid": "dpp-status",
4837 "wpa": "2",
4838 "wpa_key_mgmt": "DPP",
4839 "ieee80211w": "2",
4840 "rsn_pairwise": "CCMP",
4841 "dpp_connector": params1_ap_connector,
4842 "dpp_csign": params1_csign,
4843 "dpp_netaccesskey": params1_ap_netaccesskey}
4844 else:
4845 if result == 2:
4846 passphrase = "wrong passphrase"
4847 else:
4848 passphrase = "secret passphrase"
4849 params = hostapd.wpa2_params(ssid="dpp-status",
4850 passphrase=passphrase)
4851 try:
4852 hapd = hostapd.add_ap(apdev[0], params)
4853 except:
4854 raise HwsimSkip("DPP not supported")
4855
4856 dev[0].request("SET sae_groups ")
4857 dev[0].set("dpp_config_processing", "2")
4858 id0 = dev[0].dpp_bootstrap_gen(chan="81/1", mac=True)
4859 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
4860
4861 dev[0].dpp_listen(2412)
4862 if result == 7 or result == 8:
4863 conf = 'sta-dpp'
4864 passphrase = None
4865 configurator = dev[1].dpp_configurator_add()
4866 else:
4867 conf = 'sta-psk'
4868 passphrase = "secret passphrase"
4869 configurator = None
4870 dev[1].dpp_auth_init(uri=uri0, conf=conf, ssid="dpp-status",
4871 passphrase=passphrase, configurator=configurator,
4872 conn_status=True)
4873 res = wait_auth_success(dev[0], dev[1], configurator=dev[1],
4874 enrollee=dev[0])
4875 if 'wait_conn_status' not in res:
4876 raise Exception("Configurator did not request connection status")
4877
972edba1
JM
4878 if assoc_reject and result == 0:
4879 result = 2
b256d939
JM
4880 ev = dev[1].wait_event(["DPP-CONN-STATUS-RESULT"], timeout=20)
4881 if ev is None:
4882 raise Exception("No connection status reported")
4883 if "timeout" in ev:
4884 raise Exception("Connection status result timeout")
4885 if "result=%d" % result not in ev:
4886 raise Exception("Unexpected connection status result: " + ev)
4887 if "ssid=dpp-status" not in ev:
4888 raise Exception("SSID not reported")
4889
4890 if result == 0:
4891 dev[0].wait_connected()
4892 if result == 10 and "channel_list=" not in ev:
4893 raise Exception("Channel list not reported for no-AP")
11bbb7ec
JM
4894
4895def test_dpp_mud_url(dev, apdev):
4896 """DPP MUD URL"""
4897 check_dpp_capab(dev[0])
4898 try:
4899 dev[0].set("dpp_name", "Test Enrollee")
4900 dev[0].set("dpp_mud_url", "https://example.com/mud")
4901 run_dpp_qr_code_auth_unicast(dev, apdev, None)
4902 finally:
4903 dev[0].set("dpp_mud_url", "")
4904 dev[0].set("dpp_name", "Test")
4905
4906def test_dpp_mud_url_hostapd(dev, apdev):
4907 """DPP MUD URL from hostapd"""
4908 check_dpp_capab(dev[0])
4909 check_dpp_capab(dev[1])
4910 params = {"ssid": "unconfigured",
4911 "dpp_name": "AP Enrollee",
4912 "dpp_mud_url": "https://example.com/mud"}
4913 hapd = hostapd.add_ap(apdev[0], params)
4914 check_dpp_capab(hapd)
4915
4916 id_h = hapd.dpp_bootstrap_gen(chan="81/1", mac=True)
4917 uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
4918
4919 conf_id = dev[0].dpp_configurator_add()
4920 dev[0].dpp_auth_init(uri=uri, conf="ap-dpp", configurator=conf_id)
4921 wait_auth_success(hapd, dev[0], configurator=dev[0], enrollee=hapd)
4922 update_hapd_config(hapd)
4cab417a
JM
4923
4924def test_dpp_config_save(dev, apdev, params):
4925 """DPP configuration saving"""
4926 config = os.path.join(params['logdir'], 'dpp_config_save.conf')
4927 run_dpp_config_save(dev, apdev, config, "test", '"test"')
4928
4929def test_dpp_config_save2(dev, apdev, params):
4930 """DPP configuration saving (2)"""
4931 config = os.path.join(params['logdir'], 'dpp_config_save2.conf')
4932 run_dpp_config_save(dev, apdev, config, "\\u0001*", '012a')
4933
4934def test_dpp_config_save3(dev, apdev, params):
4935 """DPP configuration saving (3)"""
4936 config = os.path.join(params['logdir'], 'dpp_config_save3.conf')
4937 run_dpp_config_save(dev, apdev, config, "\\u0001*\\u00c2\\u00bc\\u00c3\\u009e\\u00c3\\u00bf", '012ac2bcc39ec3bf')
4938
4939def run_dpp_config_save(dev, apdev, config, conf_ssid, exp_ssid):
5bf51d38 4940 check_dpp_capab(dev[1])
4cab417a
JM
4941 with open(config, "w") as f:
4942 f.write("update_config=1\n" +
4943 "dpp_config_processing=1\n")
4944 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
4945 wpas.interface_add("wlan5", config=config)
4946 check_dpp_capab(wpas)
4947 conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"' + conf_ssid + '"},"cred":{"akm":"psk","pass":"secret passphrase"}}'
4948 dev[1].set("dpp_config_obj_override", conf)
4949 dpp_dev = [wpas, dev[1]]
4950 run_dpp_qr_code_auth_unicast(dpp_dev, apdev, "prime256v1",
4951 require_conf_success=True)
4952 if "OK" not in wpas.request("SAVE_CONFIG"):
4953 raise Exception("Failed to save configuration file")
4954 with open(config, "r") as f:
4955 data = f.read()
4956 logger.info("Saved configuration:\n" + data)
4957 if 'ssid=' + exp_ssid + '\n' not in data:
4958 raise Exception("SSID not saved")
4959 if 'psk="secret passphrase"' not in data:
4960 raise Exception("Passphtase not saved")
4a667b01
JM
4961
4962def test_dpp_nfc_uri(dev, apdev):
4963 """DPP bootstrapping via NFC URI record"""
4964 check_dpp_capab(dev[0])
4965 check_dpp_capab(dev[1])
4966
4967 id = dev[0].dpp_bootstrap_gen(type="nfc-uri", chan="81/1", mac=True)
4968 uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
4969 logger.info("Generated URI: " + uri)
4970 info = dev[0].request("DPP_BOOTSTRAP_INFO %d" % id)
4971 logger.info("Bootstrapping info:\n" + info)
4972 if "type=NFC-URI" not in info:
4973 raise Exception("Unexpected bootstrapping info contents")
4974
4975 dev[0].dpp_listen(2412)
4976 conf_id = dev[1].dpp_configurator_add()
4977 dev[1].dpp_auth_init(nfc_uri=uri, configurator=conf_id, conf="sta-dpp")
4978 wait_auth_success(dev[0], dev[1], configurator=dev[1], enrollee=dev[0])
f94e677d 4979
db1aa8f1
JM
4980def test_dpp_nfc_negotiated_handover(dev, apdev):
4981 """DPP bootstrapping via NFC negotiated handover"""
4982 run_dpp_nfc_negotiated_handover(dev, apdev)
4983
4984def test_dpp_nfc_negotiated_handover_diff_curve(dev, apdev):
4985 """DPP bootstrapping via NFC negotiated handover (different curve)"""
4986 run_dpp_nfc_negotiated_handover(dev, apdev, curve0="prime256v1",
4987 curve1="secp384r1")
4988
4989def run_dpp_nfc_negotiated_handover(dev, apdev, curve0=None, curve1=None):
4990 check_dpp_capab(dev[0])
4991 check_dpp_capab(dev[1])
4992
4993 id0 = dev[0].dpp_bootstrap_gen(type="nfc-uri", chan="81/6,11", mac=True,
4994 curve=curve0)
4995 uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
4996 logger.info("Generated URI[0]: " + uri0)
4997 id1 = dev[1].dpp_bootstrap_gen(type="nfc-uri", chan="81/1,6,11", mac=True,
4998 curve=curve1)
4999 uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
5000 logger.info("Generated URI[1]: " + uri1)
5001
5002 # dev[0] acting as NFC Handover Requestor
5003 # dev[1] acting as NFC Handover Selector
5004 res = dev[1].request("DPP_NFC_HANDOVER_REQ own=%d uri=%s" % (id1, uri0))
5005 if "FAIL" in res:
5006 raise Exception("Failed to process NFC Handover Request")
5007 info = dev[1].request("DPP_BOOTSTRAP_INFO %d" % id1)
5008 logger.info("Updated local bootstrapping info:\n" + info)
5009 freq = None
5010 for line in info.splitlines():
5011 if line.startswith("use_freq="):
5012 freq = int(line.split('=')[1])
5013 if freq is None:
5014 raise Exception("Selected channel not indicated")
5015 uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
5016 logger.info("Updated URI[1]: " + uri1)
5017 dev[1].dpp_listen(freq)
5018 res = dev[0].request("DPP_NFC_HANDOVER_SEL own=%d uri=%s" % (id0, uri1))
5019 if "FAIL" in res:
5020 raise Exception("Failed to process NFC Handover Select")
5021 peer = int(res)
5022
5023 conf_id = dev[0].dpp_configurator_add()
5024 dev[0].dpp_auth_init(peer=peer, own=id0, configurator=conf_id,
5025 conf="sta-dpp")
5026 wait_auth_success(dev[1], dev[0], configurator=dev[0], enrollee=dev[1])
5027
f94e677d
JM
5028def test_dpp_with_p2p_device(dev, apdev):
5029 """DPP exchange when driver uses a separate P2P Device interface"""
5030 check_dpp_capab(dev[0])
5031 with HWSimRadio(use_p2p_device=True) as (radio, iface):
5032 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
5033 wpas.interface_add(iface)
5034 check_dpp_capab(wpas)
5035 id1 = wpas.dpp_bootstrap_gen(chan="81/1", mac=True)
5036 uri1 = wpas.request("DPP_BOOTSTRAP_GET_URI %d" % id1)
5037 wpas.dpp_listen(2412)
5038 time.sleep(7)
5039 dev[0].dpp_auth_init(uri=uri1)
5040 wait_auth_success(wpas, dev[0], configurator=dev[0], enrollee=wpas,
5041 allow_enrollee_failure=True)