test_dpp.py 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. # Test cases for Device Provisioning Protocol (DPP)
  2. # Copyright (c) 2017, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import time
  9. import hostapd
  10. from utils import HwsimSkip
  11. def check_dpp_capab(dev):
  12. if "UNKNOWN COMMAND" in dev.request("DPP_BOOTSTRAP_GET_URI 0"):
  13. raise HwsimSkip("DPP not supported")
  14. def test_dpp_qr_code_parsing(dev, apdev):
  15. """DPP QR Code parsing"""
  16. check_dpp_capab(dev[0])
  17. id = []
  18. tests = [ "DPP:C:81/1,115/36;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkq/24e0rsrfMP9K1Tm8gx+ovP0I=;;",
  19. "DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
  20. "DPP:I:;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" ]
  21. for uri in tests:
  22. res = dev[0].request("DPP_QR_CODE " + uri)
  23. if "FAIL" in res:
  24. raise Exception("Failed to parse QR Code")
  25. id.append(int(res))
  26. uri2 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id[-1])
  27. if uri != uri2:
  28. raise Exception("Returned URI does not match")
  29. tests = [ "foo",
  30. "DPP:",
  31. "DPP:;;",
  32. "DPP:C:1/2;M:;K;;",
  33. "DPP:I:;M:01020304050;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" ]
  34. for t in tests:
  35. res = dev[0].request("DPP_QR_CODE " + t)
  36. if "FAIL" not in res:
  37. raise Exception("Accepted invalid QR Code: " + t)
  38. logger.info("ID: " + str(id))
  39. if id[0] == id[1] or id[0] == id[2] or id[1] == id[2]:
  40. raise Exception("Duplicate ID returned")
  41. if "FAIL" not in dev[0].request("DPP_BOOTSTRAP_REMOVE 12345678"):
  42. raise Exception("DPP_BOOTSTRAP_REMOVE accepted unexpectedly")
  43. if "OK" not in dev[0].request("DPP_BOOTSTRAP_REMOVE %d" % id[1]):
  44. raise Exception("DPP_BOOTSTRAP_REMOVE failed")
  45. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode")
  46. if "FAIL" in res:
  47. raise Exception("Failed to generate bootstrapping info")
  48. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % int(res))
  49. logger.info("Generated URI: " + uri)
  50. res = dev[0].request("DPP_QR_CODE " + uri)
  51. if "FAIL" in res:
  52. raise Exception("Failed to parse self-generated QR Code URI")
  53. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1,115/36 mac=010203040506 info=foo")
  54. if "FAIL" in res:
  55. raise Exception("Failed to generate bootstrapping info")
  56. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % int(res))
  57. logger.info("Generated URI: " + uri)
  58. res = dev[0].request("DPP_QR_CODE " + uri)
  59. if "FAIL" in res:
  60. raise Exception("Failed to parse self-generated QR Code URI")
  61. def test_dpp_qr_code_auth_broadcast(dev, apdev):
  62. """DPP QR Code and authentication exchange (broadcast)"""
  63. check_dpp_capab(dev[0])
  64. check_dpp_capab(dev[1])
  65. logger.info("dev0 displays QR Code")
  66. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1")
  67. if "FAIL" in res:
  68. raise Exception("Failed to generate bootstrapping info")
  69. id0 = int(res)
  70. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  71. logger.info("dev1 scans QR Code")
  72. res = dev[1].request("DPP_QR_CODE " + uri0)
  73. if "FAIL" in res:
  74. raise Exception("Failed to parse QR Code URI")
  75. id1 = int(res)
  76. logger.info("dev1 initiates DPP Authentication")
  77. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  78. raise Exception("Failed to start listen operation")
  79. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d" % id1):
  80. raise Exception("Failed to initiate DPP Authentication")
  81. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  82. if ev is None:
  83. raise Exception("DPP authentication did not succeed (Responder)")
  84. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  85. if ev is None:
  86. raise Exception("DPP authentication did not succeed (Initiator)")
  87. dev[0].request("DPP_STOP_LISTEN")
  88. def test_dpp_qr_code_auth_unicast(dev, apdev):
  89. """DPP QR Code and authentication exchange (unicast)"""
  90. run_dpp_qr_code_auth_unicast(dev, apdev, None)
  91. def test_dpp_qr_code_auth_unicast_ap_enrollee(dev, apdev):
  92. """DPP QR Code and authentication exchange (AP enrollee)"""
  93. run_dpp_qr_code_auth_unicast(dev, apdev, None, netrole="ap")
  94. def test_dpp_qr_code_curve_prime256v1(dev, apdev):
  95. """DPP QR Code and curve prime256v1"""
  96. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1")
  97. def test_dpp_qr_code_curve_secp384r1(dev, apdev):
  98. """DPP QR Code and curve secp384r1"""
  99. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1")
  100. def test_dpp_qr_code_curve_secp521r1(dev, apdev):
  101. """DPP QR Code and curve secp521r1"""
  102. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1")
  103. def test_dpp_qr_code_curve_brainpoolP256r1(dev, apdev):
  104. """DPP QR Code and curve brainpoolP256r1"""
  105. run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP256r1")
  106. def test_dpp_qr_code_curve_brainpoolP384r1(dev, apdev):
  107. """DPP QR Code and curve brainpoolP384r1"""
  108. run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP384r1")
  109. def test_dpp_qr_code_curve_brainpoolP512r1(dev, apdev):
  110. """DPP QR Code and curve brainpoolP512r1"""
  111. run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP512r1")
  112. def test_dpp_qr_code_set_key(dev, apdev):
  113. """DPP QR Code and fixed bootstrapping key"""
  114. run_dpp_qr_code_auth_unicast(dev, apdev, None, key="30770201010420e5143ac74682cc6869a830e8f5301a5fa569130ac329b1d7dd6f2a7495dbcbe1a00a06082a8648ce3d030107a144034200045e13e167c33dbc7d85541e5509600aa8139bbb3e39e25898992c5d01be92039ee2850f17e71506ded0d6b25677441eae249f8e225c68dd15a6354dca54006383")
  115. def run_dpp_qr_code_auth_unicast(dev, apdev, curve, netrole=None, key=None,
  116. require_conf_success=False, init_extra=None,
  117. require_conf_failure=False,
  118. configurator=False, conf_curve=None):
  119. check_dpp_capab(dev[0])
  120. check_dpp_capab(dev[1])
  121. if configurator:
  122. logger.info("Create configurator on dev1")
  123. cmd = "DPP_CONFIGURATOR_ADD"
  124. if conf_curve:
  125. cmd += " curve=" + conf_curve
  126. res = dev[1].request(cmd);
  127. if "FAIL" in res:
  128. raise Exception("Failed to add configurator")
  129. conf_id = int(res)
  130. logger.info("dev0 displays QR Code")
  131. addr = dev[0].own_addr().replace(':', '')
  132. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  133. if curve:
  134. cmd += " curve=" + curve
  135. if key:
  136. cmd += " key=" + key
  137. res = dev[0].request(cmd)
  138. if "FAIL" in res:
  139. raise Exception("Failed to generate bootstrapping info")
  140. id0 = int(res)
  141. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  142. logger.info("dev1 scans QR Code")
  143. res = dev[1].request("DPP_QR_CODE " + uri0)
  144. if "FAIL" in res:
  145. raise Exception("Failed to parse QR Code URI")
  146. id1 = int(res)
  147. logger.info("dev1 initiates DPP Authentication")
  148. cmd = "DPP_LISTEN 2412"
  149. if netrole:
  150. cmd += " netrole=" + netrole
  151. if "OK" not in dev[0].request(cmd):
  152. raise Exception("Failed to start listen operation")
  153. cmd = "DPP_AUTH_INIT peer=%d" % id1
  154. if init_extra:
  155. cmd += " " + init_extra
  156. if configurator:
  157. cmd += " configurator=%d" % conf_id
  158. if "OK" not in dev[1].request(cmd):
  159. raise Exception("Failed to initiate DPP Authentication")
  160. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  161. if ev is None:
  162. raise Exception("DPP authentication did not succeed (Responder)")
  163. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  164. if ev is None:
  165. raise Exception("DPP authentication did not succeed (Initiator)")
  166. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  167. if ev is None:
  168. raise Exception("DPP configuration not completed (Configurator)")
  169. ev = dev[0].wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  170. if ev is None:
  171. raise Exception("DPP configuration not completed (Enrollee)")
  172. if require_conf_success:
  173. if "DPP-CONF-FAILED" in ev:
  174. raise Exception("DPP configuration failed")
  175. if require_conf_failure:
  176. if "DPP-CONF-SUCCESS" in ev:
  177. raise Exception("DPP configuration succeeded unexpectedly")
  178. dev[0].request("DPP_STOP_LISTEN")
  179. dev[0].dump_monitor()
  180. dev[1].dump_monitor()
  181. def test_dpp_qr_code_auth_mutual(dev, apdev):
  182. """DPP QR Code and authentication exchange (mutual)"""
  183. check_dpp_capab(dev[0])
  184. check_dpp_capab(dev[1])
  185. logger.info("dev0 displays QR Code")
  186. addr = dev[0].own_addr().replace(':', '')
  187. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  188. if "FAIL" in res:
  189. raise Exception("Failed to generate bootstrapping info")
  190. id0 = int(res)
  191. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  192. logger.info("dev1 scans QR Code")
  193. res = dev[1].request("DPP_QR_CODE " + uri0)
  194. if "FAIL" in res:
  195. raise Exception("Failed to parse QR Code URI")
  196. id1 = int(res)
  197. logger.info("dev1 displays QR Code")
  198. addr = dev[1].own_addr().replace(':', '')
  199. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  200. if "FAIL" in res:
  201. raise Exception("Failed to generate bootstrapping info")
  202. id1b = int(res)
  203. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  204. logger.info("dev0 scans QR Code")
  205. res = dev[0].request("DPP_QR_CODE " + uri1b)
  206. if "FAIL" in res:
  207. raise Exception("Failed to parse QR Code URI")
  208. id0b = int(res)
  209. logger.info("dev1 initiates DPP Authentication")
  210. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  211. raise Exception("Failed to start listen operation")
  212. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b)):
  213. raise Exception("Failed to initiate DPP Authentication")
  214. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  215. if ev is None:
  216. raise Exception("DPP authentication did not succeed (Responder)")
  217. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  218. if ev is None:
  219. raise Exception("DPP authentication did not succeed (Initiator)")
  220. dev[0].request("DPP_STOP_LISTEN")
  221. def test_dpp_qr_code_auth_mutual2(dev, apdev):
  222. """DPP QR Code and authentication exchange (mutual2)"""
  223. check_dpp_capab(dev[0])
  224. check_dpp_capab(dev[1])
  225. logger.info("dev0 displays QR Code")
  226. addr = dev[0].own_addr().replace(':', '')
  227. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  228. if "FAIL" in res:
  229. raise Exception("Failed to generate bootstrapping info")
  230. id0 = int(res)
  231. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  232. logger.info("dev1 scans QR Code")
  233. res = dev[1].request("DPP_QR_CODE " + uri0)
  234. if "FAIL" in res:
  235. raise Exception("Failed to parse QR Code URI")
  236. id1 = int(res)
  237. logger.info("dev1 displays QR Code")
  238. addr = dev[1].own_addr().replace(':', '')
  239. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  240. if "FAIL" in res:
  241. raise Exception("Failed to generate bootstrapping info")
  242. id1b = int(res)
  243. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  244. logger.info("dev1 initiates DPP Authentication")
  245. if "OK" not in dev[0].request("DPP_LISTEN 2412 qr=mutual"):
  246. raise Exception("Failed to start listen operation")
  247. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b)):
  248. raise Exception("Failed to initiate DPP Authentication")
  249. ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
  250. if ev is None:
  251. raise Exception("Pending response not reported")
  252. ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
  253. if ev is None:
  254. raise Exception("QR Code scan for mutual authentication not requested")
  255. logger.info("dev0 scans QR Code")
  256. res = dev[0].request("DPP_QR_CODE " + uri1b)
  257. if "FAIL" in res:
  258. raise Exception("Failed to parse QR Code URI")
  259. id0b = int(res)
  260. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  261. if ev is None:
  262. raise Exception("DPP authentication did not succeed (Responder)")
  263. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  264. if ev is None:
  265. raise Exception("DPP authentication did not succeed (Initiator)")
  266. dev[0].request("DPP_STOP_LISTEN")
  267. def test_dpp_qr_code_auth_mutual_curve_mismatch(dev, apdev):
  268. """DPP QR Code and authentication exchange (mutual/mismatch)"""
  269. check_dpp_capab(dev[0])
  270. check_dpp_capab(dev[1])
  271. logger.info("dev0 displays QR Code")
  272. addr = dev[0].own_addr().replace(':', '')
  273. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  274. if "FAIL" in res:
  275. raise Exception("Failed to generate bootstrapping info")
  276. id0 = int(res)
  277. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  278. logger.info("dev1 scans QR Code")
  279. res = dev[1].request("DPP_QR_CODE " + uri0)
  280. if "FAIL" in res:
  281. raise Exception("Failed to parse QR Code URI")
  282. id1 = int(res)
  283. logger.info("dev1 displays QR Code")
  284. addr = dev[1].own_addr().replace(':', '')
  285. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr + " curve=secp384r1")
  286. if "FAIL" in res:
  287. raise Exception("Failed to generate bootstrapping info")
  288. id1b = int(res)
  289. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  290. logger.info("dev0 scans QR Code")
  291. res = dev[0].request("DPP_QR_CODE " + uri1b)
  292. if "FAIL" in res:
  293. raise Exception("Failed to parse QR Code URI")
  294. id0b = int(res)
  295. res = dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b))
  296. if "FAIL" not in res:
  297. raise Exception("DPP_AUTH_INIT accepted unexpectedly")
  298. def test_dpp_qr_code_listen_continue(dev, apdev):
  299. """DPP QR Code and listen operation needing continuation"""
  300. check_dpp_capab(dev[0])
  301. check_dpp_capab(dev[1])
  302. logger.info("dev0 displays QR Code")
  303. addr = dev[0].own_addr().replace(':', '')
  304. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  305. if "FAIL" in res:
  306. raise Exception("Failed to generate bootstrapping info")
  307. id0 = int(res)
  308. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  309. logger.info("dev1 scans QR Code")
  310. res = dev[1].request("DPP_QR_CODE " + uri0)
  311. if "FAIL" in res:
  312. raise Exception("Failed to parse QR Code URI")
  313. id1 = int(res)
  314. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  315. raise Exception("Failed to start listen operation")
  316. logger.info("Wait for listen to expire and get restarted")
  317. time.sleep(5.5)
  318. logger.info("dev1 initiates DPP Authentication")
  319. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d" % id1):
  320. raise Exception("Failed to initiate DPP Authentication")
  321. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  322. if ev is None:
  323. raise Exception("DPP authentication did not succeed (Responder)")
  324. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  325. if ev is None:
  326. raise Exception("DPP authentication did not succeed (Initiator)")
  327. dev[0].request("DPP_STOP_LISTEN")
  328. def test_dpp_qr_code_auth_initiator_enrollee(dev, apdev):
  329. """DPP QR Code and authentication exchange (Initiator in Enrollee role)"""
  330. check_dpp_capab(dev[0])
  331. check_dpp_capab(dev[1])
  332. dev[0].request("SET gas_address3 1")
  333. dev[1].request("SET gas_address3 1")
  334. logger.info("dev0 displays QR Code")
  335. addr = dev[0].own_addr().replace(':', '')
  336. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  337. if "FAIL" in res:
  338. raise Exception("Failed to generate bootstrapping info")
  339. id0 = int(res)
  340. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  341. logger.info("dev1 scans QR Code")
  342. res = dev[1].request("DPP_QR_CODE " + uri0)
  343. if "FAIL" in res:
  344. raise Exception("Failed to parse QR Code URI")
  345. id1 = int(res)
  346. logger.info("dev1 initiates DPP Authentication")
  347. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  348. raise Exception("Failed to start listen operation")
  349. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=enrollee" % id1):
  350. raise Exception("Failed to initiate DPP Authentication")
  351. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  352. if ev is None:
  353. raise Exception("DPP authentication did not succeed (Responder)")
  354. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  355. if ev is None:
  356. raise Exception("DPP authentication did not succeed (Initiator)")
  357. dev[0].request("DPP_STOP_LISTEN")
  358. def test_dpp_qr_code_auth_incompatible_roles(dev, apdev):
  359. """DPP QR Code and authentication exchange (incompatible roles)"""
  360. check_dpp_capab(dev[0])
  361. check_dpp_capab(dev[1])
  362. logger.info("dev0 displays QR Code")
  363. addr = dev[0].own_addr().replace(':', '')
  364. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  365. if "FAIL" in res:
  366. raise Exception("Failed to generate bootstrapping info")
  367. id0 = int(res)
  368. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  369. logger.info("dev1 scans QR Code")
  370. res = dev[1].request("DPP_QR_CODE " + uri0)
  371. if "FAIL" in res:
  372. raise Exception("Failed to parse QR Code URI")
  373. id1 = int(res)
  374. logger.info("dev1 initiates DPP Authentication")
  375. if "OK" not in dev[0].request("DPP_LISTEN 2412 role=enrollee"):
  376. raise Exception("Failed to start listen operation")
  377. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=enrollee" % id1):
  378. raise Exception("Failed to initiate DPP Authentication")
  379. ev = dev[1].wait_event(["DPP-NOT-COMPATIBLE"], timeout=5)
  380. if ev is None:
  381. raise Exception("DPP-NOT-COMPATIBLE event on initiator timed out")
  382. ev = dev[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout=1)
  383. if ev is None:
  384. raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
  385. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=configurator" % id1):
  386. raise Exception("Failed to initiate DPP Authentication")
  387. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  388. if ev is None:
  389. raise Exception("DPP authentication did not succeed (Responder)")
  390. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  391. if ev is None:
  392. raise Exception("DPP authentication did not succeed (Initiator)")
  393. dev[0].request("DPP_STOP_LISTEN")
  394. def test_dpp_config_legacy(dev, apdev):
  395. """DPP Config Object for legacy network using passphrase"""
  396. check_dpp_capab(dev[1])
  397. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}'
  398. dev[1].set("dpp_config_obj_override", conf)
  399. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  400. require_conf_success=True)
  401. def test_dpp_config_legacy_psk_hex(dev, apdev):
  402. """DPP Config Object for legacy network using PSK"""
  403. check_dpp_capab(dev[1])
  404. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"' + 32*"12" + '"}}'
  405. dev[1].set("dpp_config_obj_override", conf)
  406. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  407. require_conf_success=True)
  408. def test_dpp_config_fragmentation(dev, apdev):
  409. """DPP Config Object for legacy network requiring fragmentation"""
  410. check_dpp_capab(dev[1])
  411. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  412. dev[1].set("dpp_config_obj_override", conf)
  413. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  414. require_conf_success=True)
  415. def test_dpp_config_legacy_gen(dev, apdev):
  416. """Generate DPP Config Object for legacy network"""
  417. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  418. init_extra="conf=sta-psk pass=%s" % "passphrase".encode("hex"),
  419. require_conf_success=True)
  420. def test_dpp_config_dpp_gen_prime256v1(dev, apdev):
  421. """Generate DPP Config Object for DPP network (P-256)"""
  422. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  423. init_extra="conf=sta-dpp",
  424. require_conf_success=True,
  425. configurator=True)
  426. def test_dpp_config_dpp_gen_secp384r1(dev, apdev):
  427. """Generate DPP Config Object for DPP network (P-384)"""
  428. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  429. init_extra="conf=sta-dpp",
  430. require_conf_success=True,
  431. configurator=True)
  432. def test_dpp_config_dpp_gen_secp521r1(dev, apdev):
  433. """Generate DPP Config Object for DPP network (P-521)"""
  434. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  435. init_extra="conf=sta-dpp",
  436. require_conf_success=True,
  437. configurator=True)
  438. def test_dpp_config_dpp_gen_prime256v1_prime256v1(dev, apdev):
  439. """Generate DPP Config Object for DPP network (P-256 + P-256)"""
  440. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  441. init_extra="conf=sta-dpp",
  442. require_conf_success=True,
  443. configurator=True,
  444. conf_curve="prime256v1")
  445. def test_dpp_config_dpp_gen_prime256v1_secp384r1(dev, apdev):
  446. """Generate DPP Config Object for DPP network (P-256 + P-384)"""
  447. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  448. init_extra="conf=sta-dpp",
  449. require_conf_success=True,
  450. configurator=True,
  451. conf_curve="secp384r1")
  452. def test_dpp_config_dpp_gen_prime256v1_secp521r1(dev, apdev):
  453. """Generate DPP Config Object for DPP network (P-256 + P-521)"""
  454. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  455. init_extra="conf=sta-dpp",
  456. require_conf_success=True,
  457. configurator=True,
  458. conf_curve="secp521r1")
  459. def test_dpp_config_dpp_gen_secp384r1_prime256v1(dev, apdev):
  460. """Generate DPP Config Object for DPP network (P-384 + P-256)"""
  461. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  462. init_extra="conf=sta-dpp",
  463. require_conf_success=True,
  464. configurator=True,
  465. conf_curve="prime256v1")
  466. def test_dpp_config_dpp_gen_secp384r1_secp384r1(dev, apdev):
  467. """Generate DPP Config Object for DPP network (P-384 + P-384)"""
  468. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  469. init_extra="conf=sta-dpp",
  470. require_conf_success=True,
  471. configurator=True,
  472. conf_curve="secp384r1")
  473. def test_dpp_config_dpp_gen_secp384r1_secp521r1(dev, apdev):
  474. """Generate DPP Config Object for DPP network (P-384 + P-521)"""
  475. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  476. init_extra="conf=sta-dpp",
  477. require_conf_success=True,
  478. configurator=True,
  479. conf_curve="secp521r1")
  480. def test_dpp_config_dpp_gen_secp521r1_prime256v1(dev, apdev):
  481. """Generate DPP Config Object for DPP network (P-521 + P-256)"""
  482. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  483. init_extra="conf=sta-dpp",
  484. require_conf_success=True,
  485. configurator=True,
  486. conf_curve="prime256v1")
  487. def test_dpp_config_dpp_gen_secp521r1_secp384r1(dev, apdev):
  488. """Generate DPP Config Object for DPP network (P-521 + P-384)"""
  489. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  490. init_extra="conf=sta-dpp",
  491. require_conf_success=True,
  492. configurator=True,
  493. conf_curve="secp384r1")
  494. def test_dpp_config_dpp_gen_secp521r1_secp521r1(dev, apdev):
  495. """Generate DPP Config Object for DPP network (P-521 + P-521)"""
  496. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  497. init_extra="conf=sta-dpp",
  498. require_conf_success=True,
  499. configurator=True,
  500. conf_curve="secp521r1")
  501. def test_dpp_config_dpp_gen_expiry(dev, apdev):
  502. """Generate DPP Config Object for DPP network with expiry value"""
  503. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  504. init_extra="conf=sta-dpp expiry=%d" % (time.time() + 1000),
  505. require_conf_success=True,
  506. configurator=True)
  507. def test_dpp_config_dpp_gen_expired_key(dev, apdev):
  508. """Generate DPP Config Object for DPP network with expiry value"""
  509. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  510. init_extra="conf=sta-dpp expiry=%d" % (time.time() - 10),
  511. require_conf_failure=True,
  512. configurator=True)
  513. def test_dpp_config_dpp_override_prime256v1(dev, apdev):
  514. """DPP Config Object override (P-256)"""
  515. check_dpp_capab(dev[0])
  516. check_dpp_capab(dev[1])
  517. 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"}}}'
  518. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  519. dev[1].set("dpp_config_obj_override", conf)
  520. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  521. require_conf_success=True)
  522. def test_dpp_config_dpp_override_secp384r1(dev, apdev):
  523. """DPP Config Object override (P-384)"""
  524. check_dpp_capab(dev[0])
  525. check_dpp_capab(dev[1])
  526. 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"}}}'
  527. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  528. dev[1].set("dpp_config_obj_override", conf)
  529. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  530. require_conf_success=True)
  531. def test_dpp_config_dpp_override_secp521r1(dev, apdev):
  532. """DPP Config Object override (P-521)"""
  533. check_dpp_capab(dev[0])
  534. check_dpp_capab(dev[1])
  535. 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"}}}'
  536. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  537. dev[1].set("dpp_config_obj_override", conf)
  538. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  539. require_conf_success=True)
  540. def test_dpp_config_override_objects(dev, apdev):
  541. """Generate DPP Config Object and override objects)"""
  542. check_dpp_capab(dev[1])
  543. discovery = '{\n"ssid":"mywifi",\n"op_cl":81,\n"ch_list":\n[\n{"ch":1},\n{"ch":6},\n{"ch":11}\n]\n}'
  544. groups = '[\n {"groupId":"home","netRole":"sta"},\n {"groupId":"cottage","netRole":"sta"}\n]'
  545. devices = '[\n{"deviceId":"G1YaJYMbA9029ocP3BVCg5kj3yGHWYi3M2hJqyOmcxQ","netRole":"sta"},\n{"deviceId":"Azs-ksefien1CA8EYIliu6N6vGrTa3qowqCHKK8Iu0Y","netRole":"sta"}\n]'
  546. dev[1].set("dpp_discovery_override", discovery)
  547. dev[1].set("dpp_groups_override", groups)
  548. dev[1].set("dpp_devices_override", devices)
  549. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  550. init_extra="conf=sta-dpp",
  551. require_conf_success=True,
  552. configurator=True)
  553. def test_dpp_gas_timeout(dev, apdev):
  554. """DPP and GAS server timeout for a query"""
  555. check_dpp_capab(dev[0])
  556. check_dpp_capab(dev[1])
  557. logger.info("dev0 displays QR Code")
  558. addr = dev[0].own_addr().replace(':', '')
  559. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  560. res = dev[0].request(cmd)
  561. if "FAIL" in res:
  562. raise Exception("Failed to generate bootstrapping info")
  563. id0 = int(res)
  564. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  565. logger.info("dev1 scans QR Code")
  566. res = dev[1].request("DPP_QR_CODE " + uri0)
  567. if "FAIL" in res:
  568. raise Exception("Failed to parse QR Code URI")
  569. id1 = int(res)
  570. logger.info("dev1 initiates DPP Authentication")
  571. dev[0].set("ext_mgmt_frame_handling", "1")
  572. cmd = "DPP_LISTEN 2412"
  573. if "OK" not in dev[0].request(cmd):
  574. raise Exception("Failed to start listen operation")
  575. # Force GAS fragmentation
  576. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  577. dev[1].set("dpp_config_obj_override", conf)
  578. cmd = "DPP_AUTH_INIT peer=%d" % id1
  579. if "OK" not in dev[1].request(cmd):
  580. raise Exception("Failed to initiate DPP Authentication")
  581. # DPP Authentication Request
  582. msg = dev[0].mgmt_rx()
  583. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], msg['frame'].encode('hex'))):
  584. raise Exception("MGMT_RX_PROCESS failed")
  585. # DPP Authentication Confirmation
  586. msg = dev[0].mgmt_rx()
  587. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], msg['frame'].encode('hex'))):
  588. raise Exception("MGMT_RX_PROCESS failed")
  589. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  590. if ev is None:
  591. raise Exception("DPP authentication did not succeed (Responder)")
  592. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  593. if ev is None:
  594. raise Exception("DPP authentication did not succeed (Initiator)")
  595. # DPP Configuration Response (GAS Initial Response frame)
  596. msg = dev[0].mgmt_rx()
  597. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], msg['frame'].encode('hex'))):
  598. raise Exception("MGMT_RX_PROCESS failed")
  599. # GAS Comeback Response frame
  600. msg = dev[0].mgmt_rx()
  601. # Do not continue to force timeout on GAS server
  602. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  603. if ev is None:
  604. raise Exception("GAS result not reported (Enrollee)")
  605. if "result=TIMEOUT" not in ev:
  606. raise Exception("Unexpected GAS result (Enrollee): " + ev)
  607. dev[0].set("ext_mgmt_frame_handling", "0")
  608. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=15)
  609. if ev is None:
  610. raise Exception("DPP configuration failure not reported (Configurator)")
  611. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=1)
  612. if ev is None:
  613. raise Exception("DPP configuration failure not reported (Enrollee)")
  614. def test_dpp_akm_sha256(dev, apdev):
  615. """DPP AKM (SHA256)"""
  616. run_dpp_akm(dev, apdev, 32)
  617. def test_dpp_akm_sha384(dev, apdev):
  618. """DPP AKM (SHA384)"""
  619. run_dpp_akm(dev, apdev, 48)
  620. def test_dpp_akm_sha512(dev, apdev):
  621. """DPP AKM (SHA512)"""
  622. run_dpp_akm(dev, apdev, 64)
  623. def run_dpp_akm(dev, apdev, pmk_len):
  624. check_dpp_capab(dev[0])
  625. check_dpp_capab(dev[1])
  626. params = { "ssid": "dpp",
  627. "wpa": "2",
  628. "wpa_key_mgmt": "DPP",
  629. "rsn_pairwise": "CCMP" }
  630. try:
  631. hapd = hostapd.add_ap(apdev[0], params)
  632. except:
  633. raise HwsimSkip("DPP not supported")
  634. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  635. wait_connect=False)
  636. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=2)
  637. if not ev:
  638. raise Exception("Network mismatch not reported")
  639. dev[0].request("DISCONNECT")
  640. dev[0].dump_monitor()
  641. bssid = hapd.own_addr()
  642. pmkid = 16*'11'
  643. akmp = 2**23
  644. pmk = pmk_len*'22'
  645. cmd = "PMKSA_ADD %d %s %s %s 30240 43200 %d 0" % (id, bssid, pmkid, pmk, akmp)
  646. if "OK" not in dev[0].request(cmd):
  647. raise Exception("PMKSA_ADD failed (wpa_supplicant)")
  648. dev[0].select_network(id, freq="2412")
  649. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=2)
  650. dev[0].request("DISCONNECT")
  651. dev[0].dump_monitor()
  652. if not ev:
  653. raise Exception("Association attempt was not rejected")
  654. if "status_code=53" not in ev:
  655. raise Exception("Unexpected status code: " + ev)
  656. addr = dev[0].own_addr()
  657. cmd = "PMKSA_ADD %s %s %s 0 %d" % (addr, pmkid, pmk, akmp)
  658. if "OK" not in hapd.request(cmd):
  659. raise Exception("PMKSA_ADD failed (hostapd)")
  660. dev[0].select_network(id, freq="2412")
  661. dev[0].wait_connected()
  662. val = dev[0].get_status_field("key_mgmt")
  663. if val != "DPP":
  664. raise Exception("Unexpected key_mgmt: " + val)
  665. def test_dpp_network_introduction(dev, apdev):
  666. """DPP network introduction"""
  667. check_dpp_capab(dev[0])
  668. check_dpp_capab(dev[1])
  669. csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
  670. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
  671. ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
  672. sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
  673. sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
  674. params = { "ssid": "dpp",
  675. "wpa": "2",
  676. "wpa_key_mgmt": "DPP",
  677. "rsn_pairwise": "CCMP",
  678. "dpp_connector": ap_connector,
  679. "dpp_csign": csign,
  680. "dpp_netaccesskey": ap_netaccesskey }
  681. try:
  682. hapd = hostapd.add_ap(apdev[0], params)
  683. except:
  684. raise HwsimSkip("DPP not supported")
  685. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  686. dpp_csign=csign,
  687. dpp_connector=sta_connector,
  688. dpp_netaccesskey=sta_netaccesskey)
  689. val = dev[0].get_status_field("key_mgmt")
  690. if val != "DPP":
  691. raise Exception("Unexpected key_mgmt: " + val)
  692. def test_dpp_ap_config(dev, apdev):
  693. """DPP and AP configuration"""
  694. run_dpp_ap_config(dev, apdev)
  695. def test_dpp_ap_config_p256_p256(dev, apdev):
  696. """DPP and AP configuration (P-256 + P-256)"""
  697. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-256")
  698. def test_dpp_ap_config_p256_p384(dev, apdev):
  699. """DPP and AP configuration (P-256 + P-384)"""
  700. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-384")
  701. def test_dpp_ap_config_p256_p521(dev, apdev):
  702. """DPP and AP configuration (P-256 + P-521)"""
  703. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-521")
  704. def test_dpp_ap_config_p384_p256(dev, apdev):
  705. """DPP and AP configuration (P-384 + P-256)"""
  706. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-256")
  707. def test_dpp_ap_config_p384_p384(dev, apdev):
  708. """DPP and AP configuration (P-384 + P-384)"""
  709. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-384")
  710. def test_dpp_ap_config_p384_p521(dev, apdev):
  711. """DPP and AP configuration (P-384 + P-521)"""
  712. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-521")
  713. def test_dpp_ap_config_p521_p256(dev, apdev):
  714. """DPP and AP configuration (P-521 + P-256)"""
  715. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-256")
  716. def test_dpp_ap_config_p521_p384(dev, apdev):
  717. """DPP and AP configuration (P-521 + P-384)"""
  718. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-384")
  719. def test_dpp_ap_config_p521_p521(dev, apdev):
  720. """DPP and AP configuration (P-521 + P-521)"""
  721. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-521")
  722. def update_hapd_config(hapd):
  723. ev = hapd.wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  724. if ev is None:
  725. raise Exception("SSID not reported (AP)")
  726. ssid = ev.split(' ')[1]
  727. ev = hapd.wait_event(["DPP-CONNECTOR"], timeout=1)
  728. if ev is None:
  729. raise Exception("Connector not reported (AP)")
  730. connector = ev.split(' ')[1]
  731. ev = hapd.wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  732. if ev is None:
  733. raise Exception("C-sign-key not reported (AP)")
  734. p = ev.split(' ')
  735. csign = p[1]
  736. csign_expiry = p[2] if len(p) > 2 else None
  737. ev = hapd.wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  738. if ev is None:
  739. raise Exception("netAccessKey not reported (AP)")
  740. p = ev.split(' ')
  741. net_access_key = p[1]
  742. net_access_key_expiry = p[2] if len(p) > 2 else None
  743. logger.info("Update AP configuration to use key_mgmt=DPP")
  744. hapd.disable()
  745. hapd.set("ssid", ssid)
  746. hapd.set("wpa", "2")
  747. hapd.set("wpa_key_mgmt", "DPP")
  748. hapd.set("rsn_pairwise", "CCMP")
  749. hapd.set("dpp_connector", connector)
  750. hapd.set("dpp_csign", csign)
  751. if csign_expiry:
  752. hapd.set("dpp_csign_expiry", csign_expiry)
  753. hapd.set("dpp_netaccesskey", net_access_key)
  754. if net_access_key_expiry:
  755. hapd.set("dpp_netaccesskey_expiry", net_access_key_expiry)
  756. hapd.enable()
  757. def run_dpp_ap_config(dev, apdev, curve=None, conf_curve=None):
  758. check_dpp_capab(dev[0])
  759. check_dpp_capab(dev[1])
  760. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  761. check_dpp_capab(hapd)
  762. addr = hapd.own_addr().replace(':', '')
  763. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  764. if curve:
  765. cmd += " curve=" + curve
  766. res = hapd.request(cmd)
  767. if "FAIL" in res:
  768. raise Exception("Failed to generate bootstrapping info")
  769. id_h = int(res)
  770. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  771. cmd = "DPP_CONFIGURATOR_ADD expiry=%d" % (time.time() + 100000)
  772. if conf_curve:
  773. cmd += " curve=" + conf_curve
  774. res = dev[0].request(cmd);
  775. if "FAIL" in res:
  776. raise Exception("Failed to add configurator")
  777. conf_id = int(res)
  778. res = dev[0].request("DPP_QR_CODE " + uri)
  779. if "FAIL" in res:
  780. raise Exception("Failed to parse QR Code URI")
  781. id = int(res)
  782. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  783. if "OK" not in dev[0].request(cmd):
  784. raise Exception("Failed to initiate DPP Authentication")
  785. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  786. if ev is None:
  787. raise Exception("DPP authentication did not succeed (Responder)")
  788. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  789. if ev is None:
  790. raise Exception("DPP authentication did not succeed (Initiator)")
  791. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  792. if ev is None:
  793. raise Exception("DPP configuration not completed (Configurator)")
  794. ev = hapd.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  795. if ev is None:
  796. raise Exception("DPP configuration not completed (Enrollee)")
  797. if "DPP-CONF-FAILED" in ev:
  798. raise Exception("DPP configuration failed")
  799. update_hapd_config(hapd)
  800. addr = dev[1].own_addr().replace(':', '')
  801. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  802. if curve:
  803. cmd += " curve=" + curve
  804. res = dev[1].request(cmd)
  805. if "FAIL" in res:
  806. raise Exception("Failed to generate bootstrapping info")
  807. id1 = int(res)
  808. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  809. res = dev[0].request("DPP_QR_CODE " + uri1)
  810. if "FAIL" in res:
  811. raise Exception("Failed to parse QR Code URI")
  812. id0b = int(res)
  813. cmd = "DPP_LISTEN 2412"
  814. if "OK" not in dev[1].request(cmd):
  815. raise Exception("Failed to start listen operation")
  816. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id0b, conf_id)
  817. if "OK" not in dev[0].request(cmd):
  818. raise Exception("Failed to initiate DPP Authentication")
  819. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  820. if ev is None:
  821. raise Exception("DPP authentication did not succeed (Responder)")
  822. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  823. if ev is None:
  824. raise Exception("DPP authentication did not succeed (Initiator)")
  825. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  826. if ev is None:
  827. raise Exception("DPP configuration not completed (Configurator)")
  828. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  829. if ev is None:
  830. raise Exception("DPP configuration not completed (Enrollee)")
  831. dev[1].request("DPP_STOP_LISTEN")
  832. ev = dev[1].wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  833. if ev is None:
  834. raise Exception("SSID not reported")
  835. ssid = ev.split(' ')[1]
  836. ev = dev[1].wait_event(["DPP-CONNECTOR"], timeout=1)
  837. if ev is None:
  838. raise Exception("Connector not reported")
  839. connector = ev.split(' ')[1]
  840. ev = dev[1].wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  841. if ev is None:
  842. raise Exception("C-sign-key not reported")
  843. p = ev.split(' ')
  844. csign = p[1]
  845. csign_expiry = p[2] if len(p) > 2 else None
  846. ev = dev[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  847. if ev is None:
  848. raise Exception("netAccessKey not reported")
  849. p = ev.split(' ')
  850. net_access_key = p[1]
  851. net_access_key_expiry = p[2] if len(p) > 2 else None
  852. dev[1].dump_monitor()
  853. id = dev[1].connect(ssid, key_mgmt="DPP", scan_freq="2412",
  854. only_add_network=True)
  855. dev[1].set_network_quoted(id, "dpp_connector", connector)
  856. dev[1].set_network(id, "dpp_csign", csign)
  857. if csign_expiry:
  858. dev[1].set_network(id, "dpp_csign_expiry", csign_expiry)
  859. dev[1].set_network(id, "dpp_netaccesskey", net_access_key)
  860. if net_access_key_expiry:
  861. dev[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry)
  862. logger.info("Check data connection")
  863. dev[1].select_network(id, freq="2412")
  864. dev[1].wait_connected()
  865. def test_dpp_auto_connect_1(dev, apdev):
  866. """DPP and auto connect (1)"""
  867. try:
  868. run_dpp_auto_connect(dev, apdev, 1)
  869. finally:
  870. dev[0].set("dpp_config_processing", "0")
  871. def test_dpp_auto_connect_2(dev, apdev):
  872. """DPP and auto connect (2)"""
  873. try:
  874. run_dpp_auto_connect(dev, apdev, 2)
  875. finally:
  876. dev[0].set("dpp_config_processing", "0")
  877. def run_dpp_auto_connect(dev, apdev, processing):
  878. check_dpp_capab(dev[0])
  879. check_dpp_capab(dev[1])
  880. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  881. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  882. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  883. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  884. params = { "ssid": "test",
  885. "wpa": "2",
  886. "wpa_key_mgmt": "DPP",
  887. "rsn_pairwise": "CCMP",
  888. "dpp_connector": ap_connector,
  889. "dpp_csign": csign_pub,
  890. "dpp_netaccesskey": ap_netaccesskey }
  891. try:
  892. hapd = hostapd.add_ap(apdev[0], params)
  893. except:
  894. raise HwsimSkip("DPP not supported")
  895. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  896. res = dev[1].request(cmd)
  897. if "FAIL" in res:
  898. raise Exception("DPP_CONFIGURATOR_ADD failed")
  899. conf_id = int(res)
  900. dev[0].set("dpp_config_processing", str(processing))
  901. addr = dev[0].own_addr().replace(':', '')
  902. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  903. res = dev[0].request(cmd)
  904. if "FAIL" in res:
  905. raise Exception("Failed to generate bootstrapping info")
  906. id0 = int(res)
  907. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  908. res = dev[1].request("DPP_QR_CODE " + uri0)
  909. if "FAIL" in res:
  910. raise Exception("Failed to parse QR Code URI")
  911. id1 = int(res)
  912. cmd = "DPP_LISTEN 2412"
  913. if "OK" not in dev[0].request(cmd):
  914. raise Exception("Failed to start listen operation")
  915. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  916. if "OK" not in dev[1].request(cmd):
  917. raise Exception("Failed to initiate DPP Authentication")
  918. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  919. if ev is None:
  920. raise Exception("DPP configuration not completed (Configurator)")
  921. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  922. if ev is None:
  923. raise Exception("DPP configuration not completed (Enrollee)")
  924. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  925. if ev is None:
  926. raise Exception("DPP network profile not generated")
  927. id = ev.split(' ')[1]
  928. if processing == 1:
  929. dev[0].select_network(id, freq=2412)
  930. dev[0].wait_connected()
  931. def test_dpp_auto_connect_legacy(dev, apdev):
  932. """DPP and auto connect (legacy)"""
  933. try:
  934. run_dpp_auto_connect_legacy(dev, apdev)
  935. finally:
  936. dev[0].set("dpp_config_processing", "0")
  937. def run_dpp_auto_connect_legacy(dev, apdev):
  938. check_dpp_capab(dev[0])
  939. check_dpp_capab(dev[1])
  940. params = hostapd.wpa2_params(ssid="dpp-legacy",
  941. passphrase="secret passphrase")
  942. hapd = hostapd.add_ap(apdev[0], params)
  943. dev[0].set("dpp_config_processing", "2")
  944. addr = dev[0].own_addr().replace(':', '')
  945. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  946. res = dev[0].request(cmd)
  947. if "FAIL" in res:
  948. raise Exception("Failed to generate bootstrapping info")
  949. id0 = int(res)
  950. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  951. res = dev[1].request("DPP_QR_CODE " + uri0)
  952. if "FAIL" in res:
  953. raise Exception("Failed to parse QR Code URI")
  954. id1 = int(res)
  955. cmd = "DPP_LISTEN 2412"
  956. if "OK" not in dev[0].request(cmd):
  957. raise Exception("Failed to start listen operation")
  958. cmd = "DPP_AUTH_INIT peer=%d conf=sta-psk ssid=%s pass=%s" % (id1, "dpp-legacy".encode("hex"), "secret passphrase".encode("hex"))
  959. if "OK" not in dev[1].request(cmd):
  960. raise Exception("Failed to initiate DPP Authentication")
  961. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  962. if ev is None:
  963. raise Exception("DPP configuration not completed (Configurator)")
  964. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  965. if ev is None:
  966. raise Exception("DPP configuration not completed (Enrollee)")
  967. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  968. if ev is None:
  969. raise Exception("DPP network profile not generated")
  970. id = ev.split(' ')[1]
  971. dev[0].wait_connected()
  972. def test_dpp_qr_code_auth_responder_configurator(dev, apdev):
  973. """DPP QR Code and responder as the configurator"""
  974. check_dpp_capab(dev[0])
  975. check_dpp_capab(dev[1])
  976. cmd = "DPP_CONFIGURATOR_ADD"
  977. res = dev[0].request(cmd);
  978. if "FAIL" in res:
  979. raise Exception("Failed to add configurator")
  980. conf_id = int(res)
  981. addr = dev[0].own_addr().replace(':', '')
  982. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  983. res = dev[0].request(cmd)
  984. if "FAIL" in res:
  985. raise Exception("Failed to generate bootstrapping info")
  986. id0 = int(res)
  987. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  988. res = dev[1].request("DPP_QR_CODE " + uri0)
  989. if "FAIL" in res:
  990. raise Exception("Failed to parse QR Code URI")
  991. id1 = int(res)
  992. dev[0].set("dpp_configurator_params", " conf=sta-dpp configurator=%d" % conf_id);
  993. cmd = "DPP_LISTEN 2412 role=configurator"
  994. if "OK" not in dev[0].request(cmd):
  995. raise Exception("Failed to start listen operation")
  996. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  997. if "OK" not in dev[1].request(cmd):
  998. raise Exception("Failed to initiate DPP Authentication")
  999. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1000. if ev is None:
  1001. raise Exception("DPP authentication did not succeed (Responder)")
  1002. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1003. if ev is None:
  1004. raise Exception("DPP authentication did not succeed (Initiator)")
  1005. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1006. if ev is None:
  1007. raise Exception("DPP configuration not completed (Configurator)")
  1008. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1009. if ev is None:
  1010. raise Exception("DPP configuration not completed (Enrollee)")
  1011. dev[0].request("DPP_STOP_LISTEN")
  1012. dev[0].dump_monitor()
  1013. dev[1].dump_monitor()
  1014. def test_dpp_qr_code_hostapd_init(dev, apdev):
  1015. """DPP QR Code and hostapd as initiator"""
  1016. check_dpp_capab(dev[0])
  1017. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1018. "channel": "6" })
  1019. check_dpp_capab(hapd)
  1020. cmd = "DPP_CONFIGURATOR_ADD"
  1021. res = dev[0].request(cmd);
  1022. if "FAIL" in res:
  1023. raise Exception("Failed to add configurator")
  1024. conf_id = int(res)
  1025. addr = dev[0].own_addr().replace(':', '')
  1026. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1027. res = dev[0].request(cmd)
  1028. if "FAIL" in res:
  1029. raise Exception("Failed to generate bootstrapping info")
  1030. id0 = int(res)
  1031. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1032. dev[0].set("dpp_configurator_params",
  1033. " conf=ap-dpp configurator=%d" % conf_id);
  1034. cmd = "DPP_LISTEN 2437 role=configurator"
  1035. if "OK" not in dev[0].request(cmd):
  1036. raise Exception("Failed to start listen operation")
  1037. res = hapd.request("DPP_QR_CODE " + uri0)
  1038. if "FAIL" in res:
  1039. raise Exception("Failed to parse QR Code URI")
  1040. id1 = int(res)
  1041. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1042. if "OK" not in hapd.request(cmd):
  1043. raise Exception("Failed to initiate DPP Authentication")
  1044. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1045. if ev is None:
  1046. raise Exception("DPP authentication did not succeed (Responder)")
  1047. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1048. if ev is None:
  1049. raise Exception("DPP authentication did not succeed (Initiator)")
  1050. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1051. if ev is None:
  1052. raise Exception("DPP configuration not completed (Configurator)")
  1053. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1054. if ev is None:
  1055. raise Exception("DPP configuration not completed (Enrollee)")
  1056. dev[0].request("DPP_STOP_LISTEN")
  1057. dev[0].dump_monitor()
  1058. def test_dpp_pkex(dev, apdev):
  1059. """DPP and PKEX"""
  1060. run_dpp_pkex(dev, apdev)
  1061. def test_dpp_pkex_p256(dev, apdev):
  1062. """DPP and PKEX (P-256)"""
  1063. run_dpp_pkex(dev, apdev, "P-256")
  1064. def test_dpp_pkex_p384(dev, apdev):
  1065. """DPP and PKEX (P-384)"""
  1066. run_dpp_pkex(dev, apdev, "P-384")
  1067. def test_dpp_pkex_p521(dev, apdev):
  1068. """DPP and PKEX (P-521)"""
  1069. run_dpp_pkex(dev, apdev, "P-521")
  1070. def test_dpp_pkex_bp256(dev, apdev):
  1071. """DPP and PKEX (BP-256)"""
  1072. run_dpp_pkex(dev, apdev, "brainpoolP256r1")
  1073. def test_dpp_pkex_bp384(dev, apdev):
  1074. """DPP and PKEX (BP-384)"""
  1075. run_dpp_pkex(dev, apdev, "brainpoolP384r1")
  1076. def test_dpp_pkex_bp512(dev, apdev):
  1077. """DPP and PKEX (BP-512)"""
  1078. run_dpp_pkex(dev, apdev, "brainpoolP512r1")
  1079. def test_dpp_pkex_config(dev, apdev):
  1080. """DPP and PKEX with initiator as the configurator"""
  1081. check_dpp_capab(dev[1])
  1082. cmd = "DPP_CONFIGURATOR_ADD"
  1083. res = dev[1].request(cmd);
  1084. if "FAIL" in res:
  1085. raise Exception("Failed to add configurator")
  1086. conf_id = int(res)
  1087. run_dpp_pkex(dev, apdev,
  1088. init_extra="conf=sta-dpp configurator=%d" % (conf_id),
  1089. check_config=True)
  1090. def run_dpp_pkex(dev, apdev, curve=None, init_extra="", check_config=False):
  1091. check_dpp_capab(dev[0])
  1092. check_dpp_capab(dev[1])
  1093. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1094. if curve:
  1095. cmd += " curve=" + curve
  1096. res = dev[0].request(cmd)
  1097. if "FAIL" in res:
  1098. raise Exception("Failed to generate bootstrapping info")
  1099. id0 = int(res)
  1100. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1101. if curve:
  1102. cmd += " curve=" + curve
  1103. res = dev[1].request(cmd)
  1104. if "FAIL" in res:
  1105. raise Exception("Failed to generate bootstrapping info")
  1106. id1 = int(res)
  1107. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1108. res = dev[0].request(cmd)
  1109. if "FAIL" in res:
  1110. raise Exception("Failed to set PKEX data (responder)")
  1111. cmd = "DPP_LISTEN 2437"
  1112. if "OK" not in dev[0].request(cmd):
  1113. raise Exception("Failed to start listen operation")
  1114. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 %s code=secret" % (id1, init_extra)
  1115. res = dev[1].request(cmd)
  1116. if "FAIL" in res:
  1117. raise Exception("Failed to set PKEX data (initiator)")
  1118. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1119. if ev is None:
  1120. raise Exception("DPP authentication did not succeed (Initiator)")
  1121. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1122. if ev is None:
  1123. raise Exception("DPP authentication did not succeed (Responder)")
  1124. if check_config:
  1125. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1126. if ev is None:
  1127. raise Exception("DPP configuration not completed (Configurator)")
  1128. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1129. if ev is None:
  1130. raise Exception("DPP configuration not completed (Enrollee)")
  1131. def test_dpp_pkex_config2(dev, apdev):
  1132. """DPP and PKEX with responder as the configurator"""
  1133. check_dpp_capab(dev[0])
  1134. cmd = "DPP_CONFIGURATOR_ADD"
  1135. res = dev[0].request(cmd);
  1136. if "FAIL" in res:
  1137. raise Exception("Failed to add configurator")
  1138. conf_id = int(res)
  1139. dev[0].set("dpp_configurator_params",
  1140. " conf=sta-dpp configurator=%d" % conf_id);
  1141. run_dpp_pkex2(dev, apdev)
  1142. def run_dpp_pkex2(dev, apdev, curve=None, init_extra=""):
  1143. check_dpp_capab(dev[0])
  1144. check_dpp_capab(dev[1])
  1145. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1146. if curve:
  1147. cmd += " curve=" + curve
  1148. res = dev[0].request(cmd)
  1149. if "FAIL" in res:
  1150. raise Exception("Failed to generate bootstrapping info")
  1151. id0 = int(res)
  1152. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1153. if curve:
  1154. cmd += " curve=" + curve
  1155. res = dev[1].request(cmd)
  1156. if "FAIL" in res:
  1157. raise Exception("Failed to generate bootstrapping info")
  1158. id1 = int(res)
  1159. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1160. res = dev[0].request(cmd)
  1161. if "FAIL" in res:
  1162. raise Exception("Failed to set PKEX data (responder)")
  1163. cmd = "DPP_LISTEN 2437 role=configurator"
  1164. if "OK" not in dev[0].request(cmd):
  1165. raise Exception("Failed to start listen operation")
  1166. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee %s code=secret" % (id1, init_extra)
  1167. res = dev[1].request(cmd)
  1168. if "FAIL" in res:
  1169. raise Exception("Failed to set PKEX data (initiator)")
  1170. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1171. if ev is None:
  1172. raise Exception("DPP authentication did not succeed (Initiator)")
  1173. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1174. if ev is None:
  1175. raise Exception("DPP authentication did not succeed (Responder)")
  1176. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1177. if ev is None:
  1178. raise Exception("DPP configuration not completed (Configurator)")
  1179. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1180. if ev is None:
  1181. raise Exception("DPP configuration not completed (Enrollee)")
  1182. def test_dpp_pkex_hostapd_responder(dev, apdev):
  1183. """DPP PKEX with hostapd as responder"""
  1184. check_dpp_capab(dev[0])
  1185. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1186. "channel": "6" })
  1187. check_dpp_capab(hapd)
  1188. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1189. res = hapd.request(cmd)
  1190. if "FAIL" in res:
  1191. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1192. id_h = int(res)
  1193. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id_h)
  1194. res = hapd.request(cmd)
  1195. if "FAIL" in res:
  1196. raise Exception("Failed to set PKEX data (responder/hostapd)")
  1197. cmd = "DPP_CONFIGURATOR_ADD"
  1198. res = dev[0].request(cmd);
  1199. if "FAIL" in res:
  1200. raise Exception("Failed to add configurator")
  1201. conf_id = int(res)
  1202. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1203. res = dev[0].request(cmd)
  1204. if "FAIL" in res:
  1205. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1206. id0 = int(res)
  1207. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=ap-dpp configurator=%d code=secret" % (id0, conf_id)
  1208. res = dev[0].request(cmd)
  1209. if "FAIL" in res:
  1210. raise Exception("Failed to set PKEX data (initiator/wpa_supplicant)")
  1211. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1212. if ev is None:
  1213. raise Exception("DPP authentication did not succeed (Initiator)")
  1214. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1215. if ev is None:
  1216. raise Exception("DPP authentication did not succeed (Responder)")
  1217. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1218. if ev is None:
  1219. raise Exception("DPP configuration not completed (Configurator)")
  1220. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1221. if ev is None:
  1222. raise Exception("DPP configuration not completed (Enrollee)")
  1223. dev[0].request("DPP_STOP_LISTEN")
  1224. dev[0].dump_monitor()
  1225. def test_dpp_pkex_hostapd_initiator(dev, apdev):
  1226. """DPP PKEX with hostapd as initiator"""
  1227. check_dpp_capab(dev[0])
  1228. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1229. "channel": "6" })
  1230. check_dpp_capab(hapd)
  1231. cmd = "DPP_CONFIGURATOR_ADD"
  1232. res = dev[0].request(cmd);
  1233. if "FAIL" in res:
  1234. raise Exception("Failed to add configurator")
  1235. conf_id = int(res)
  1236. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1237. res = dev[0].request(cmd)
  1238. if "FAIL" in res:
  1239. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1240. id0 = int(res)
  1241. dev[0].set("dpp_configurator_params",
  1242. " conf=ap-dpp configurator=%d" % conf_id);
  1243. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1244. res = dev[0].request(cmd)
  1245. if "FAIL" in res:
  1246. raise Exception("Failed to set PKEX data (responder/wpa_supplicant)")
  1247. cmd = "DPP_LISTEN 2437 role=configurator"
  1248. if "OK" not in dev[0].request(cmd):
  1249. raise Exception("Failed to start listen operation")
  1250. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1251. res = hapd.request(cmd)
  1252. if "FAIL" in res:
  1253. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1254. id_h = int(res)
  1255. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee code=secret" % (id_h)
  1256. res = hapd.request(cmd)
  1257. if "FAIL" in res:
  1258. raise Exception("Failed to set PKEX data (initiator/hostapd)")
  1259. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1260. if ev is None:
  1261. raise Exception("DPP authentication did not succeed (Initiator)")
  1262. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1263. if ev is None:
  1264. raise Exception("DPP authentication did not succeed (Responder)")
  1265. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1266. if ev is None:
  1267. raise Exception("DPP configuration not completed (Configurator)")
  1268. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1269. if ev is None:
  1270. raise Exception("DPP configuration not completed (Enrollee)")
  1271. dev[0].request("DPP_STOP_LISTEN")
  1272. dev[0].dump_monitor()
  1273. def test_dpp_hostapd_configurator(dev, apdev):
  1274. """DPP with hostapd as configurator/initiator"""
  1275. check_dpp_capab(dev[0])
  1276. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1277. "channel": "1" })
  1278. check_dpp_capab(hapd)
  1279. cmd = "DPP_CONFIGURATOR_ADD"
  1280. res = hapd.request(cmd);
  1281. if "FAIL" in res:
  1282. raise Exception("Failed to add configurator")
  1283. conf_id = int(res)
  1284. addr = dev[0].own_addr().replace(':', '')
  1285. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1286. res = dev[0].request(cmd)
  1287. if "FAIL" in res:
  1288. raise Exception("Failed to generate bootstrapping info")
  1289. id0 = int(res)
  1290. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1291. res = hapd.request("DPP_QR_CODE " + uri0)
  1292. if "FAIL" in res:
  1293. raise Exception("Failed to parse QR Code URI")
  1294. id1 = int(res)
  1295. res = hapd.request("DPP_BOOTSTRAP_INFO %d" % id0)
  1296. if "FAIL" in res:
  1297. raise Exception("DPP_BOOTSTRAP_INFO failed")
  1298. if "type=QRCODE" not in res:
  1299. raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
  1300. if "mac_addr=" + dev[0].own_addr() not in res:
  1301. raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
  1302. cmd = "DPP_LISTEN 2412"
  1303. if "OK" not in dev[0].request(cmd):
  1304. raise Exception("Failed to start listen operation")
  1305. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1306. if "OK" not in hapd.request(cmd):
  1307. raise Exception("Failed to initiate DPP Authentication")
  1308. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1309. if ev is None:
  1310. raise Exception("DPP authentication did not succeed (Responder)")
  1311. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1312. if ev is None:
  1313. raise Exception("DPP authentication did not succeed (Initiator)")
  1314. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1315. if ev is None:
  1316. raise Exception("DPP configuration not completed (Configurator)")
  1317. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1318. if ev is None:
  1319. raise Exception("DPP configuration not completed (Enrollee)")
  1320. dev[0].request("DPP_STOP_LISTEN")
  1321. dev[0].dump_monitor()
  1322. def test_dpp_hostapd_configurator_responder(dev, apdev):
  1323. """DPP with hostapd as configurator/responder"""
  1324. check_dpp_capab(dev[0])
  1325. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1326. "channel": "1" })
  1327. check_dpp_capab(hapd)
  1328. cmd = "DPP_CONFIGURATOR_ADD"
  1329. res = hapd.request(cmd);
  1330. if "FAIL" in res:
  1331. raise Exception("Failed to add configurator")
  1332. conf_id = int(res)
  1333. hapd.set("dpp_configurator_params",
  1334. " conf=sta-dpp configurator=%d" % conf_id);
  1335. addr = hapd.own_addr().replace(':', '')
  1336. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1337. res = hapd.request(cmd)
  1338. if "FAIL" in res:
  1339. raise Exception("Failed to generate bootstrapping info")
  1340. id0 = int(res)
  1341. uri0 = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1342. res = dev[0].request("DPP_QR_CODE " + uri0)
  1343. if "FAIL" in res:
  1344. raise Exception("Failed to parse QR Code URI")
  1345. id1 = int(res)
  1346. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % (id1)
  1347. if "OK" not in dev[0].request(cmd):
  1348. raise Exception("Failed to initiate DPP Authentication")
  1349. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1350. if ev is None:
  1351. raise Exception("DPP authentication did not succeed (Responder)")
  1352. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1353. if ev is None:
  1354. raise Exception("DPP authentication did not succeed (Initiator)")
  1355. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1356. if ev is None:
  1357. raise Exception("DPP configuration not completed (Configurator)")
  1358. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1359. if ev is None:
  1360. raise Exception("DPP configuration not completed (Enrollee)")
  1361. dev[0].request("DPP_STOP_LISTEN")
  1362. dev[0].dump_monitor()
  1363. def test_dpp_own_config(dev, apdev):
  1364. """DPP configurator signing own connector"""
  1365. try:
  1366. run_dpp_own_config(dev, apdev)
  1367. finally:
  1368. dev[0].set("dpp_config_processing", "0")
  1369. def test_dpp_own_config_curve_mismatch(dev, apdev):
  1370. """DPP configurator signing own connector using mismatching curve"""
  1371. try:
  1372. run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
  1373. finally:
  1374. dev[0].set("dpp_config_processing", "0")
  1375. def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False):
  1376. check_dpp_capab(dev[0])
  1377. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1378. check_dpp_capab(hapd)
  1379. addr = hapd.own_addr().replace(':', '')
  1380. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1381. res = hapd.request(cmd)
  1382. if "FAIL" in res:
  1383. raise Exception("Failed to generate bootstrapping info")
  1384. id_h = int(res)
  1385. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1386. cmd = "DPP_CONFIGURATOR_ADD"
  1387. res = dev[0].request(cmd);
  1388. if "FAIL" in res:
  1389. raise Exception("Failed to add configurator")
  1390. conf_id = int(res)
  1391. res = dev[0].request("DPP_QR_CODE " + uri)
  1392. if "FAIL" in res:
  1393. raise Exception("Failed to parse QR Code URI")
  1394. id = int(res)
  1395. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1396. if "OK" not in dev[0].request(cmd):
  1397. raise Exception("Failed to initiate DPP Authentication")
  1398. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1399. if ev is None:
  1400. raise Exception("DPP authentication did not succeed (Responder)")
  1401. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1402. if ev is None:
  1403. raise Exception("DPP authentication did not succeed (Initiator)")
  1404. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1405. if ev is None:
  1406. raise Exception("DPP configuration not completed (Configurator)")
  1407. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1408. if ev is None:
  1409. raise Exception("DPP configuration not completed (Enrollee)")
  1410. update_hapd_config(hapd)
  1411. dev[0].set("dpp_config_processing", "1")
  1412. cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id)
  1413. if own_curve:
  1414. cmd += " curve=" + own_curve
  1415. res = dev[0].request(cmd)
  1416. if "FAIL" in res:
  1417. raise Exception("Failed to generate own configuration")
  1418. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1419. if ev is None:
  1420. raise Exception("DPP network profile not generated")
  1421. id = ev.split(' ')[1]
  1422. dev[0].select_network(id, freq="2412")
  1423. if expect_failure:
  1424. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1425. if ev is not None:
  1426. raise Exception("Unexpected connection");
  1427. dev[0].request("DISCONNECT")
  1428. else:
  1429. dev[0].wait_connected()