test_dpp.py 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  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. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  358. if ev is None:
  359. raise Exception("DPP configuration did not succeed (Configurator)")
  360. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=5)
  361. if ev is None:
  362. raise Exception("DPP configuration did not succeed (Enrollee)")
  363. dev[0].request("DPP_STOP_LISTEN")
  364. def test_dpp_qr_code_auth_incompatible_roles(dev, apdev):
  365. """DPP QR Code and authentication exchange (incompatible roles)"""
  366. check_dpp_capab(dev[0])
  367. check_dpp_capab(dev[1])
  368. logger.info("dev0 displays QR Code")
  369. addr = dev[0].own_addr().replace(':', '')
  370. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  371. if "FAIL" in res:
  372. raise Exception("Failed to generate bootstrapping info")
  373. id0 = int(res)
  374. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  375. logger.info("dev1 scans QR Code")
  376. res = dev[1].request("DPP_QR_CODE " + uri0)
  377. if "FAIL" in res:
  378. raise Exception("Failed to parse QR Code URI")
  379. id1 = int(res)
  380. logger.info("dev1 initiates DPP Authentication")
  381. if "OK" not in dev[0].request("DPP_LISTEN 2412 role=enrollee"):
  382. raise Exception("Failed to start listen operation")
  383. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=enrollee" % id1):
  384. raise Exception("Failed to initiate DPP Authentication")
  385. ev = dev[1].wait_event(["DPP-NOT-COMPATIBLE"], timeout=5)
  386. if ev is None:
  387. raise Exception("DPP-NOT-COMPATIBLE event on initiator timed out")
  388. ev = dev[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout=1)
  389. if ev is None:
  390. raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
  391. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=configurator" % id1):
  392. raise Exception("Failed to initiate DPP Authentication")
  393. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  394. if ev is None:
  395. raise Exception("DPP authentication did not succeed (Responder)")
  396. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  397. if ev is None:
  398. raise Exception("DPP authentication did not succeed (Initiator)")
  399. dev[0].request("DPP_STOP_LISTEN")
  400. def test_dpp_config_legacy(dev, apdev):
  401. """DPP Config Object for legacy network using passphrase"""
  402. check_dpp_capab(dev[1])
  403. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}'
  404. dev[1].set("dpp_config_obj_override", conf)
  405. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  406. require_conf_success=True)
  407. def test_dpp_config_legacy_psk_hex(dev, apdev):
  408. """DPP Config Object for legacy network using PSK"""
  409. check_dpp_capab(dev[1])
  410. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"' + 32*"12" + '"}}'
  411. dev[1].set("dpp_config_obj_override", conf)
  412. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  413. require_conf_success=True)
  414. def test_dpp_config_fragmentation(dev, apdev):
  415. """DPP Config Object for legacy network requiring fragmentation"""
  416. check_dpp_capab(dev[1])
  417. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  418. dev[1].set("dpp_config_obj_override", conf)
  419. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  420. require_conf_success=True)
  421. def test_dpp_config_legacy_gen(dev, apdev):
  422. """Generate DPP Config Object for legacy network"""
  423. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  424. init_extra="conf=sta-psk pass=%s" % "passphrase".encode("hex"),
  425. require_conf_success=True)
  426. def test_dpp_config_dpp_gen_prime256v1(dev, apdev):
  427. """Generate DPP Config Object for DPP network (P-256)"""
  428. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  429. init_extra="conf=sta-dpp",
  430. require_conf_success=True,
  431. configurator=True)
  432. def test_dpp_config_dpp_gen_secp384r1(dev, apdev):
  433. """Generate DPP Config Object for DPP network (P-384)"""
  434. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  435. init_extra="conf=sta-dpp",
  436. require_conf_success=True,
  437. configurator=True)
  438. def test_dpp_config_dpp_gen_secp521r1(dev, apdev):
  439. """Generate DPP Config Object for DPP network (P-521)"""
  440. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  441. init_extra="conf=sta-dpp",
  442. require_conf_success=True,
  443. configurator=True)
  444. def test_dpp_config_dpp_gen_prime256v1_prime256v1(dev, apdev):
  445. """Generate DPP Config Object for DPP network (P-256 + P-256)"""
  446. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  447. init_extra="conf=sta-dpp",
  448. require_conf_success=True,
  449. configurator=True,
  450. conf_curve="prime256v1")
  451. def test_dpp_config_dpp_gen_prime256v1_secp384r1(dev, apdev):
  452. """Generate DPP Config Object for DPP network (P-256 + P-384)"""
  453. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  454. init_extra="conf=sta-dpp",
  455. require_conf_success=True,
  456. configurator=True,
  457. conf_curve="secp384r1")
  458. def test_dpp_config_dpp_gen_prime256v1_secp521r1(dev, apdev):
  459. """Generate DPP Config Object for DPP network (P-256 + P-521)"""
  460. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  461. init_extra="conf=sta-dpp",
  462. require_conf_success=True,
  463. configurator=True,
  464. conf_curve="secp521r1")
  465. def test_dpp_config_dpp_gen_secp384r1_prime256v1(dev, apdev):
  466. """Generate DPP Config Object for DPP network (P-384 + P-256)"""
  467. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  468. init_extra="conf=sta-dpp",
  469. require_conf_success=True,
  470. configurator=True,
  471. conf_curve="prime256v1")
  472. def test_dpp_config_dpp_gen_secp384r1_secp384r1(dev, apdev):
  473. """Generate DPP Config Object for DPP network (P-384 + P-384)"""
  474. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  475. init_extra="conf=sta-dpp",
  476. require_conf_success=True,
  477. configurator=True,
  478. conf_curve="secp384r1")
  479. def test_dpp_config_dpp_gen_secp384r1_secp521r1(dev, apdev):
  480. """Generate DPP Config Object for DPP network (P-384 + P-521)"""
  481. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  482. init_extra="conf=sta-dpp",
  483. require_conf_success=True,
  484. configurator=True,
  485. conf_curve="secp521r1")
  486. def test_dpp_config_dpp_gen_secp521r1_prime256v1(dev, apdev):
  487. """Generate DPP Config Object for DPP network (P-521 + P-256)"""
  488. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  489. init_extra="conf=sta-dpp",
  490. require_conf_success=True,
  491. configurator=True,
  492. conf_curve="prime256v1")
  493. def test_dpp_config_dpp_gen_secp521r1_secp384r1(dev, apdev):
  494. """Generate DPP Config Object for DPP network (P-521 + P-384)"""
  495. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  496. init_extra="conf=sta-dpp",
  497. require_conf_success=True,
  498. configurator=True,
  499. conf_curve="secp384r1")
  500. def test_dpp_config_dpp_gen_secp521r1_secp521r1(dev, apdev):
  501. """Generate DPP Config Object for DPP network (P-521 + P-521)"""
  502. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  503. init_extra="conf=sta-dpp",
  504. require_conf_success=True,
  505. configurator=True,
  506. conf_curve="secp521r1")
  507. def test_dpp_config_dpp_gen_expiry(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() + 1000),
  511. require_conf_success=True,
  512. configurator=True)
  513. def test_dpp_config_dpp_gen_expired_key(dev, apdev):
  514. """Generate DPP Config Object for DPP network with expiry value"""
  515. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  516. init_extra="conf=sta-dpp expiry=%d" % (time.time() - 10),
  517. require_conf_failure=True,
  518. configurator=True)
  519. def test_dpp_config_dpp_override_prime256v1(dev, apdev):
  520. """DPP Config Object override (P-256)"""
  521. check_dpp_capab(dev[0])
  522. check_dpp_capab(dev[1])
  523. 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"}}}'
  524. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  525. dev[1].set("dpp_config_obj_override", conf)
  526. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  527. require_conf_success=True)
  528. def test_dpp_config_dpp_override_secp384r1(dev, apdev):
  529. """DPP Config Object override (P-384)"""
  530. check_dpp_capab(dev[0])
  531. check_dpp_capab(dev[1])
  532. 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"}}}'
  533. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  534. dev[1].set("dpp_config_obj_override", conf)
  535. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  536. require_conf_success=True)
  537. def test_dpp_config_dpp_override_secp521r1(dev, apdev):
  538. """DPP Config Object override (P-521)"""
  539. check_dpp_capab(dev[0])
  540. check_dpp_capab(dev[1])
  541. 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"}}}'
  542. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  543. dev[1].set("dpp_config_obj_override", conf)
  544. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  545. require_conf_success=True)
  546. def test_dpp_config_override_objects(dev, apdev):
  547. """Generate DPP Config Object and override objects)"""
  548. check_dpp_capab(dev[1])
  549. discovery = '{\n"ssid":"mywifi",\n"op_cl":81,\n"ch_list":\n[1,6]\n}'
  550. groups = '[\n {"groupId":"home","netRole":"sta"},\n {"groupId":"cottage","netRole":"sta"}\n]'
  551. dev[1].set("dpp_discovery_override", discovery)
  552. dev[1].set("dpp_groups_override", groups)
  553. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  554. init_extra="conf=sta-dpp",
  555. require_conf_success=True,
  556. configurator=True)
  557. def test_dpp_gas_timeout(dev, apdev):
  558. """DPP and GAS server timeout for a query"""
  559. check_dpp_capab(dev[0])
  560. check_dpp_capab(dev[1])
  561. logger.info("dev0 displays QR Code")
  562. addr = dev[0].own_addr().replace(':', '')
  563. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  564. res = dev[0].request(cmd)
  565. if "FAIL" in res:
  566. raise Exception("Failed to generate bootstrapping info")
  567. id0 = int(res)
  568. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  569. logger.info("dev1 scans QR Code")
  570. res = dev[1].request("DPP_QR_CODE " + uri0)
  571. if "FAIL" in res:
  572. raise Exception("Failed to parse QR Code URI")
  573. id1 = int(res)
  574. logger.info("dev1 initiates DPP Authentication")
  575. dev[0].set("ext_mgmt_frame_handling", "1")
  576. cmd = "DPP_LISTEN 2412"
  577. if "OK" not in dev[0].request(cmd):
  578. raise Exception("Failed to start listen operation")
  579. # Force GAS fragmentation
  580. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  581. dev[1].set("dpp_config_obj_override", conf)
  582. cmd = "DPP_AUTH_INIT peer=%d" % id1
  583. if "OK" not in dev[1].request(cmd):
  584. raise Exception("Failed to initiate DPP Authentication")
  585. # DPP Authentication Request
  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. # DPP Authentication Confirmation
  590. msg = dev[0].mgmt_rx()
  591. 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'))):
  592. raise Exception("MGMT_RX_PROCESS failed")
  593. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  594. if ev is None:
  595. raise Exception("DPP authentication did not succeed (Responder)")
  596. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  597. if ev is None:
  598. raise Exception("DPP authentication did not succeed (Initiator)")
  599. # DPP Configuration Response (GAS Initial Response frame)
  600. msg = dev[0].mgmt_rx()
  601. 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'))):
  602. raise Exception("MGMT_RX_PROCESS failed")
  603. # GAS Comeback Response frame
  604. msg = dev[0].mgmt_rx()
  605. # Do not continue to force timeout on GAS server
  606. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  607. if ev is None:
  608. raise Exception("GAS result not reported (Enrollee)")
  609. if "result=TIMEOUT" not in ev:
  610. raise Exception("Unexpected GAS result (Enrollee): " + ev)
  611. dev[0].set("ext_mgmt_frame_handling", "0")
  612. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=15)
  613. if ev is None:
  614. raise Exception("DPP configuration failure not reported (Configurator)")
  615. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=1)
  616. if ev is None:
  617. raise Exception("DPP configuration failure not reported (Enrollee)")
  618. def test_dpp_akm_sha256(dev, apdev):
  619. """DPP AKM (SHA256)"""
  620. run_dpp_akm(dev, apdev, 32)
  621. def test_dpp_akm_sha384(dev, apdev):
  622. """DPP AKM (SHA384)"""
  623. run_dpp_akm(dev, apdev, 48)
  624. def test_dpp_akm_sha512(dev, apdev):
  625. """DPP AKM (SHA512)"""
  626. run_dpp_akm(dev, apdev, 64)
  627. def run_dpp_akm(dev, apdev, pmk_len):
  628. check_dpp_capab(dev[0])
  629. check_dpp_capab(dev[1])
  630. params = { "ssid": "dpp",
  631. "wpa": "2",
  632. "wpa_key_mgmt": "DPP",
  633. "rsn_pairwise": "CCMP" }
  634. try:
  635. hapd = hostapd.add_ap(apdev[0], params)
  636. except:
  637. raise HwsimSkip("DPP not supported")
  638. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  639. wait_connect=False)
  640. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=2)
  641. if not ev:
  642. raise Exception("Network mismatch not reported")
  643. dev[0].request("DISCONNECT")
  644. dev[0].dump_monitor()
  645. bssid = hapd.own_addr()
  646. pmkid = 16*'11'
  647. akmp = 2**23
  648. pmk = pmk_len*'22'
  649. cmd = "PMKSA_ADD %d %s %s %s 30240 43200 %d 0" % (id, bssid, pmkid, pmk, akmp)
  650. if "OK" not in dev[0].request(cmd):
  651. raise Exception("PMKSA_ADD failed (wpa_supplicant)")
  652. dev[0].select_network(id, freq="2412")
  653. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=2)
  654. dev[0].request("DISCONNECT")
  655. dev[0].dump_monitor()
  656. if not ev:
  657. raise Exception("Association attempt was not rejected")
  658. if "status_code=53" not in ev:
  659. raise Exception("Unexpected status code: " + ev)
  660. addr = dev[0].own_addr()
  661. cmd = "PMKSA_ADD %s %s %s 0 %d" % (addr, pmkid, pmk, akmp)
  662. if "OK" not in hapd.request(cmd):
  663. raise Exception("PMKSA_ADD failed (hostapd)")
  664. dev[0].select_network(id, freq="2412")
  665. dev[0].wait_connected()
  666. val = dev[0].get_status_field("key_mgmt")
  667. if val != "DPP":
  668. raise Exception("Unexpected key_mgmt: " + val)
  669. def test_dpp_network_introduction(dev, apdev):
  670. """DPP network introduction"""
  671. check_dpp_capab(dev[0])
  672. check_dpp_capab(dev[1])
  673. csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
  674. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
  675. ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
  676. sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
  677. sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
  678. params = { "ssid": "dpp",
  679. "wpa": "2",
  680. "wpa_key_mgmt": "DPP",
  681. "rsn_pairwise": "CCMP",
  682. "dpp_connector": ap_connector,
  683. "dpp_csign": csign,
  684. "dpp_netaccesskey": ap_netaccesskey }
  685. try:
  686. hapd = hostapd.add_ap(apdev[0], params)
  687. except:
  688. raise HwsimSkip("DPP not supported")
  689. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  690. dpp_csign=csign,
  691. dpp_connector=sta_connector,
  692. dpp_netaccesskey=sta_netaccesskey)
  693. val = dev[0].get_status_field("key_mgmt")
  694. if val != "DPP":
  695. raise Exception("Unexpected key_mgmt: " + val)
  696. def test_dpp_ap_config(dev, apdev):
  697. """DPP and AP configuration"""
  698. run_dpp_ap_config(dev, apdev)
  699. def test_dpp_ap_config_p256_p256(dev, apdev):
  700. """DPP and AP configuration (P-256 + P-256)"""
  701. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-256")
  702. def test_dpp_ap_config_p256_p384(dev, apdev):
  703. """DPP and AP configuration (P-256 + P-384)"""
  704. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-384")
  705. def test_dpp_ap_config_p256_p521(dev, apdev):
  706. """DPP and AP configuration (P-256 + P-521)"""
  707. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-521")
  708. def test_dpp_ap_config_p384_p256(dev, apdev):
  709. """DPP and AP configuration (P-384 + P-256)"""
  710. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-256")
  711. def test_dpp_ap_config_p384_p384(dev, apdev):
  712. """DPP and AP configuration (P-384 + P-384)"""
  713. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-384")
  714. def test_dpp_ap_config_p384_p521(dev, apdev):
  715. """DPP and AP configuration (P-384 + P-521)"""
  716. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-521")
  717. def test_dpp_ap_config_p521_p256(dev, apdev):
  718. """DPP and AP configuration (P-521 + P-256)"""
  719. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-256")
  720. def test_dpp_ap_config_p521_p384(dev, apdev):
  721. """DPP and AP configuration (P-521 + P-384)"""
  722. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-384")
  723. def test_dpp_ap_config_p521_p521(dev, apdev):
  724. """DPP and AP configuration (P-521 + P-521)"""
  725. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-521")
  726. def update_hapd_config(hapd):
  727. ev = hapd.wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  728. if ev is None:
  729. raise Exception("SSID not reported (AP)")
  730. ssid = ev.split(' ')[1]
  731. ev = hapd.wait_event(["DPP-CONNECTOR"], timeout=1)
  732. if ev is None:
  733. raise Exception("Connector not reported (AP)")
  734. connector = ev.split(' ')[1]
  735. ev = hapd.wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  736. if ev is None:
  737. raise Exception("C-sign-key not reported (AP)")
  738. p = ev.split(' ')
  739. csign = p[1]
  740. csign_expiry = p[2] if len(p) > 2 else None
  741. ev = hapd.wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  742. if ev is None:
  743. raise Exception("netAccessKey not reported (AP)")
  744. p = ev.split(' ')
  745. net_access_key = p[1]
  746. net_access_key_expiry = p[2] if len(p) > 2 else None
  747. logger.info("Update AP configuration to use key_mgmt=DPP")
  748. hapd.disable()
  749. hapd.set("ssid", ssid)
  750. hapd.set("wpa", "2")
  751. hapd.set("wpa_key_mgmt", "DPP")
  752. hapd.set("rsn_pairwise", "CCMP")
  753. hapd.set("dpp_connector", connector)
  754. hapd.set("dpp_csign", csign)
  755. if csign_expiry:
  756. hapd.set("dpp_csign_expiry", csign_expiry)
  757. hapd.set("dpp_netaccesskey", net_access_key)
  758. if net_access_key_expiry:
  759. hapd.set("dpp_netaccesskey_expiry", net_access_key_expiry)
  760. hapd.enable()
  761. def run_dpp_ap_config(dev, apdev, curve=None, conf_curve=None):
  762. check_dpp_capab(dev[0])
  763. check_dpp_capab(dev[1])
  764. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  765. check_dpp_capab(hapd)
  766. addr = hapd.own_addr().replace(':', '')
  767. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  768. if curve:
  769. cmd += " curve=" + curve
  770. res = hapd.request(cmd)
  771. if "FAIL" in res:
  772. raise Exception("Failed to generate bootstrapping info")
  773. id_h = int(res)
  774. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  775. cmd = "DPP_CONFIGURATOR_ADD expiry=%d" % (time.time() + 100000)
  776. if conf_curve:
  777. cmd += " curve=" + conf_curve
  778. res = dev[0].request(cmd);
  779. if "FAIL" in res:
  780. raise Exception("Failed to add configurator")
  781. conf_id = int(res)
  782. res = dev[0].request("DPP_QR_CODE " + uri)
  783. if "FAIL" in res:
  784. raise Exception("Failed to parse QR Code URI")
  785. id = int(res)
  786. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  787. if "OK" not in dev[0].request(cmd):
  788. raise Exception("Failed to initiate DPP Authentication")
  789. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  790. if ev is None:
  791. raise Exception("DPP authentication did not succeed (Responder)")
  792. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  793. if ev is None:
  794. raise Exception("DPP authentication did not succeed (Initiator)")
  795. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  796. if ev is None:
  797. raise Exception("DPP configuration not completed (Configurator)")
  798. ev = hapd.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  799. if ev is None:
  800. raise Exception("DPP configuration not completed (Enrollee)")
  801. if "DPP-CONF-FAILED" in ev:
  802. raise Exception("DPP configuration failed")
  803. update_hapd_config(hapd)
  804. addr = dev[1].own_addr().replace(':', '')
  805. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  806. if curve:
  807. cmd += " curve=" + curve
  808. res = dev[1].request(cmd)
  809. if "FAIL" in res:
  810. raise Exception("Failed to generate bootstrapping info")
  811. id1 = int(res)
  812. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  813. res = dev[0].request("DPP_QR_CODE " + uri1)
  814. if "FAIL" in res:
  815. raise Exception("Failed to parse QR Code URI")
  816. id0b = int(res)
  817. cmd = "DPP_LISTEN 2412"
  818. if "OK" not in dev[1].request(cmd):
  819. raise Exception("Failed to start listen operation")
  820. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id0b, conf_id)
  821. if "OK" not in dev[0].request(cmd):
  822. raise Exception("Failed to initiate DPP Authentication")
  823. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  824. if ev is None:
  825. raise Exception("DPP authentication did not succeed (Responder)")
  826. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  827. if ev is None:
  828. raise Exception("DPP authentication did not succeed (Initiator)")
  829. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  830. if ev is None:
  831. raise Exception("DPP configuration not completed (Configurator)")
  832. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  833. if ev is None:
  834. raise Exception("DPP configuration not completed (Enrollee)")
  835. dev[1].request("DPP_STOP_LISTEN")
  836. ev = dev[1].wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  837. if ev is None:
  838. raise Exception("SSID not reported")
  839. ssid = ev.split(' ')[1]
  840. ev = dev[1].wait_event(["DPP-CONNECTOR"], timeout=1)
  841. if ev is None:
  842. raise Exception("Connector not reported")
  843. connector = ev.split(' ')[1]
  844. ev = dev[1].wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  845. if ev is None:
  846. raise Exception("C-sign-key not reported")
  847. p = ev.split(' ')
  848. csign = p[1]
  849. csign_expiry = p[2] if len(p) > 2 else None
  850. ev = dev[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  851. if ev is None:
  852. raise Exception("netAccessKey not reported")
  853. p = ev.split(' ')
  854. net_access_key = p[1]
  855. net_access_key_expiry = p[2] if len(p) > 2 else None
  856. dev[1].dump_monitor()
  857. id = dev[1].connect(ssid, key_mgmt="DPP", scan_freq="2412",
  858. only_add_network=True)
  859. dev[1].set_network_quoted(id, "dpp_connector", connector)
  860. dev[1].set_network(id, "dpp_csign", csign)
  861. if csign_expiry:
  862. dev[1].set_network(id, "dpp_csign_expiry", csign_expiry)
  863. dev[1].set_network(id, "dpp_netaccesskey", net_access_key)
  864. if net_access_key_expiry:
  865. dev[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry)
  866. logger.info("Check data connection")
  867. dev[1].select_network(id, freq="2412")
  868. dev[1].wait_connected()
  869. def test_dpp_auto_connect_1(dev, apdev):
  870. """DPP and auto connect (1)"""
  871. try:
  872. run_dpp_auto_connect(dev, apdev, 1)
  873. finally:
  874. dev[0].set("dpp_config_processing", "0")
  875. def test_dpp_auto_connect_2(dev, apdev):
  876. """DPP and auto connect (2)"""
  877. try:
  878. run_dpp_auto_connect(dev, apdev, 2)
  879. finally:
  880. dev[0].set("dpp_config_processing", "0")
  881. def run_dpp_auto_connect(dev, apdev, processing):
  882. check_dpp_capab(dev[0])
  883. check_dpp_capab(dev[1])
  884. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  885. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  886. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  887. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  888. params = { "ssid": "test",
  889. "wpa": "2",
  890. "wpa_key_mgmt": "DPP",
  891. "rsn_pairwise": "CCMP",
  892. "dpp_connector": ap_connector,
  893. "dpp_csign": csign_pub,
  894. "dpp_netaccesskey": ap_netaccesskey }
  895. try:
  896. hapd = hostapd.add_ap(apdev[0], params)
  897. except:
  898. raise HwsimSkip("DPP not supported")
  899. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  900. res = dev[1].request(cmd)
  901. if "FAIL" in res:
  902. raise Exception("DPP_CONFIGURATOR_ADD failed")
  903. conf_id = int(res)
  904. dev[0].set("dpp_config_processing", str(processing))
  905. addr = dev[0].own_addr().replace(':', '')
  906. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  907. res = dev[0].request(cmd)
  908. if "FAIL" in res:
  909. raise Exception("Failed to generate bootstrapping info")
  910. id0 = int(res)
  911. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  912. res = dev[1].request("DPP_QR_CODE " + uri0)
  913. if "FAIL" in res:
  914. raise Exception("Failed to parse QR Code URI")
  915. id1 = int(res)
  916. cmd = "DPP_LISTEN 2412"
  917. if "OK" not in dev[0].request(cmd):
  918. raise Exception("Failed to start listen operation")
  919. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  920. if "OK" not in dev[1].request(cmd):
  921. raise Exception("Failed to initiate DPP Authentication")
  922. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  923. if ev is None:
  924. raise Exception("DPP configuration not completed (Configurator)")
  925. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  926. if ev is None:
  927. raise Exception("DPP configuration not completed (Enrollee)")
  928. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  929. if ev is None:
  930. raise Exception("DPP network profile not generated")
  931. id = ev.split(' ')[1]
  932. if processing == 1:
  933. dev[0].select_network(id, freq=2412)
  934. dev[0].wait_connected()
  935. def test_dpp_auto_connect_legacy(dev, apdev):
  936. """DPP and auto connect (legacy)"""
  937. try:
  938. run_dpp_auto_connect_legacy(dev, apdev)
  939. finally:
  940. dev[0].set("dpp_config_processing", "0")
  941. def run_dpp_auto_connect_legacy(dev, apdev):
  942. check_dpp_capab(dev[0])
  943. check_dpp_capab(dev[1])
  944. params = hostapd.wpa2_params(ssid="dpp-legacy",
  945. passphrase="secret passphrase")
  946. hapd = hostapd.add_ap(apdev[0], params)
  947. dev[0].set("dpp_config_processing", "2")
  948. addr = dev[0].own_addr().replace(':', '')
  949. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  950. res = dev[0].request(cmd)
  951. if "FAIL" in res:
  952. raise Exception("Failed to generate bootstrapping info")
  953. id0 = int(res)
  954. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  955. res = dev[1].request("DPP_QR_CODE " + uri0)
  956. if "FAIL" in res:
  957. raise Exception("Failed to parse QR Code URI")
  958. id1 = int(res)
  959. cmd = "DPP_LISTEN 2412"
  960. if "OK" not in dev[0].request(cmd):
  961. raise Exception("Failed to start listen operation")
  962. cmd = "DPP_AUTH_INIT peer=%d conf=sta-psk ssid=%s pass=%s" % (id1, "dpp-legacy".encode("hex"), "secret passphrase".encode("hex"))
  963. if "OK" not in dev[1].request(cmd):
  964. raise Exception("Failed to initiate DPP Authentication")
  965. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  966. if ev is None:
  967. raise Exception("DPP configuration not completed (Configurator)")
  968. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  969. if ev is None:
  970. raise Exception("DPP configuration not completed (Enrollee)")
  971. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  972. if ev is None:
  973. raise Exception("DPP network profile not generated")
  974. id = ev.split(' ')[1]
  975. dev[0].wait_connected()
  976. def test_dpp_qr_code_auth_responder_configurator(dev, apdev):
  977. """DPP QR Code and responder as the configurator"""
  978. check_dpp_capab(dev[0])
  979. check_dpp_capab(dev[1])
  980. cmd = "DPP_CONFIGURATOR_ADD"
  981. res = dev[0].request(cmd);
  982. if "FAIL" in res:
  983. raise Exception("Failed to add configurator")
  984. conf_id = int(res)
  985. addr = dev[0].own_addr().replace(':', '')
  986. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  987. res = dev[0].request(cmd)
  988. if "FAIL" in res:
  989. raise Exception("Failed to generate bootstrapping info")
  990. id0 = int(res)
  991. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  992. res = dev[1].request("DPP_QR_CODE " + uri0)
  993. if "FAIL" in res:
  994. raise Exception("Failed to parse QR Code URI")
  995. id1 = int(res)
  996. dev[0].set("dpp_configurator_params", " conf=sta-dpp configurator=%d" % conf_id);
  997. cmd = "DPP_LISTEN 2412 role=configurator"
  998. if "OK" not in dev[0].request(cmd):
  999. raise Exception("Failed to start listen operation")
  1000. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1001. if "OK" not in dev[1].request(cmd):
  1002. raise Exception("Failed to initiate DPP Authentication")
  1003. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1004. if ev is None:
  1005. raise Exception("DPP authentication did not succeed (Responder)")
  1006. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1007. if ev is None:
  1008. raise Exception("DPP authentication did not succeed (Initiator)")
  1009. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1010. if ev is None:
  1011. raise Exception("DPP configuration not completed (Configurator)")
  1012. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1013. if ev is None:
  1014. raise Exception("DPP configuration not completed (Enrollee)")
  1015. dev[0].request("DPP_STOP_LISTEN")
  1016. dev[0].dump_monitor()
  1017. dev[1].dump_monitor()
  1018. def test_dpp_qr_code_hostapd_init(dev, apdev):
  1019. """DPP QR Code and hostapd as initiator"""
  1020. check_dpp_capab(dev[0])
  1021. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1022. "channel": "6" })
  1023. check_dpp_capab(hapd)
  1024. cmd = "DPP_CONFIGURATOR_ADD"
  1025. res = dev[0].request(cmd);
  1026. if "FAIL" in res:
  1027. raise Exception("Failed to add configurator")
  1028. conf_id = int(res)
  1029. addr = dev[0].own_addr().replace(':', '')
  1030. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1031. res = dev[0].request(cmd)
  1032. if "FAIL" in res:
  1033. raise Exception("Failed to generate bootstrapping info")
  1034. id0 = int(res)
  1035. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1036. dev[0].set("dpp_configurator_params",
  1037. " conf=ap-dpp configurator=%d" % conf_id);
  1038. cmd = "DPP_LISTEN 2437 role=configurator"
  1039. if "OK" not in dev[0].request(cmd):
  1040. raise Exception("Failed to start listen operation")
  1041. res = hapd.request("DPP_QR_CODE " + uri0)
  1042. if "FAIL" in res:
  1043. raise Exception("Failed to parse QR Code URI")
  1044. id1 = int(res)
  1045. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1046. if "OK" not in hapd.request(cmd):
  1047. raise Exception("Failed to initiate DPP Authentication")
  1048. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1049. if ev is None:
  1050. raise Exception("DPP authentication did not succeed (Responder)")
  1051. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1052. if ev is None:
  1053. raise Exception("DPP authentication did not succeed (Initiator)")
  1054. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1055. if ev is None:
  1056. raise Exception("DPP configuration not completed (Configurator)")
  1057. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1058. if ev is None:
  1059. raise Exception("DPP configuration not completed (Enrollee)")
  1060. dev[0].request("DPP_STOP_LISTEN")
  1061. dev[0].dump_monitor()
  1062. def test_dpp_pkex(dev, apdev):
  1063. """DPP and PKEX"""
  1064. run_dpp_pkex(dev, apdev)
  1065. def test_dpp_pkex_p256(dev, apdev):
  1066. """DPP and PKEX (P-256)"""
  1067. run_dpp_pkex(dev, apdev, "P-256")
  1068. def test_dpp_pkex_p384(dev, apdev):
  1069. """DPP and PKEX (P-384)"""
  1070. run_dpp_pkex(dev, apdev, "P-384")
  1071. def test_dpp_pkex_p521(dev, apdev):
  1072. """DPP and PKEX (P-521)"""
  1073. run_dpp_pkex(dev, apdev, "P-521")
  1074. def test_dpp_pkex_bp256(dev, apdev):
  1075. """DPP and PKEX (BP-256)"""
  1076. run_dpp_pkex(dev, apdev, "brainpoolP256r1")
  1077. def test_dpp_pkex_bp384(dev, apdev):
  1078. """DPP and PKEX (BP-384)"""
  1079. run_dpp_pkex(dev, apdev, "brainpoolP384r1")
  1080. def test_dpp_pkex_bp512(dev, apdev):
  1081. """DPP and PKEX (BP-512)"""
  1082. run_dpp_pkex(dev, apdev, "brainpoolP512r1")
  1083. def test_dpp_pkex_config(dev, apdev):
  1084. """DPP and PKEX with initiator as the configurator"""
  1085. check_dpp_capab(dev[1])
  1086. cmd = "DPP_CONFIGURATOR_ADD"
  1087. res = dev[1].request(cmd);
  1088. if "FAIL" in res:
  1089. raise Exception("Failed to add configurator")
  1090. conf_id = int(res)
  1091. run_dpp_pkex(dev, apdev,
  1092. init_extra="conf=sta-dpp configurator=%d" % (conf_id),
  1093. check_config=True)
  1094. def run_dpp_pkex(dev, apdev, curve=None, init_extra="", check_config=False):
  1095. check_dpp_capab(dev[0])
  1096. check_dpp_capab(dev[1])
  1097. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1098. if curve:
  1099. cmd += " curve=" + curve
  1100. res = dev[0].request(cmd)
  1101. if "FAIL" in res:
  1102. raise Exception("Failed to generate bootstrapping info")
  1103. id0 = int(res)
  1104. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1105. if curve:
  1106. cmd += " curve=" + curve
  1107. res = dev[1].request(cmd)
  1108. if "FAIL" in res:
  1109. raise Exception("Failed to generate bootstrapping info")
  1110. id1 = int(res)
  1111. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1112. res = dev[0].request(cmd)
  1113. if "FAIL" in res:
  1114. raise Exception("Failed to set PKEX data (responder)")
  1115. cmd = "DPP_LISTEN 2437"
  1116. if "OK" not in dev[0].request(cmd):
  1117. raise Exception("Failed to start listen operation")
  1118. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 %s code=secret" % (id1, init_extra)
  1119. res = dev[1].request(cmd)
  1120. if "FAIL" in res:
  1121. raise Exception("Failed to set PKEX data (initiator)")
  1122. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1123. if ev is None:
  1124. raise Exception("DPP authentication did not succeed (Initiator)")
  1125. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1126. if ev is None:
  1127. raise Exception("DPP authentication did not succeed (Responder)")
  1128. if check_config:
  1129. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1130. if ev is None:
  1131. raise Exception("DPP configuration not completed (Configurator)")
  1132. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1133. if ev is None:
  1134. raise Exception("DPP configuration not completed (Enrollee)")
  1135. def test_dpp_pkex_config2(dev, apdev):
  1136. """DPP and PKEX with responder as the configurator"""
  1137. check_dpp_capab(dev[0])
  1138. cmd = "DPP_CONFIGURATOR_ADD"
  1139. res = dev[0].request(cmd);
  1140. if "FAIL" in res:
  1141. raise Exception("Failed to add configurator")
  1142. conf_id = int(res)
  1143. dev[0].set("dpp_configurator_params",
  1144. " conf=sta-dpp configurator=%d" % conf_id);
  1145. run_dpp_pkex2(dev, apdev)
  1146. def run_dpp_pkex2(dev, apdev, curve=None, init_extra=""):
  1147. check_dpp_capab(dev[0])
  1148. check_dpp_capab(dev[1])
  1149. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1150. if curve:
  1151. cmd += " curve=" + curve
  1152. res = dev[0].request(cmd)
  1153. if "FAIL" in res:
  1154. raise Exception("Failed to generate bootstrapping info")
  1155. id0 = int(res)
  1156. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1157. if curve:
  1158. cmd += " curve=" + curve
  1159. res = dev[1].request(cmd)
  1160. if "FAIL" in res:
  1161. raise Exception("Failed to generate bootstrapping info")
  1162. id1 = int(res)
  1163. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1164. res = dev[0].request(cmd)
  1165. if "FAIL" in res:
  1166. raise Exception("Failed to set PKEX data (responder)")
  1167. cmd = "DPP_LISTEN 2437 role=configurator"
  1168. if "OK" not in dev[0].request(cmd):
  1169. raise Exception("Failed to start listen operation")
  1170. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee %s code=secret" % (id1, init_extra)
  1171. res = dev[1].request(cmd)
  1172. if "FAIL" in res:
  1173. raise Exception("Failed to set PKEX data (initiator)")
  1174. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1175. if ev is None:
  1176. raise Exception("DPP authentication did not succeed (Initiator)")
  1177. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1178. if ev is None:
  1179. raise Exception("DPP authentication did not succeed (Responder)")
  1180. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1181. if ev is None:
  1182. raise Exception("DPP configuration not completed (Configurator)")
  1183. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1184. if ev is None:
  1185. raise Exception("DPP configuration not completed (Enrollee)")
  1186. def test_dpp_pkex_hostapd_responder(dev, apdev):
  1187. """DPP PKEX with hostapd as responder"""
  1188. check_dpp_capab(dev[0])
  1189. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1190. "channel": "6" })
  1191. check_dpp_capab(hapd)
  1192. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1193. res = hapd.request(cmd)
  1194. if "FAIL" in res:
  1195. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1196. id_h = int(res)
  1197. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id_h)
  1198. res = hapd.request(cmd)
  1199. if "FAIL" in res:
  1200. raise Exception("Failed to set PKEX data (responder/hostapd)")
  1201. cmd = "DPP_CONFIGURATOR_ADD"
  1202. res = dev[0].request(cmd);
  1203. if "FAIL" in res:
  1204. raise Exception("Failed to add configurator")
  1205. conf_id = int(res)
  1206. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1207. res = dev[0].request(cmd)
  1208. if "FAIL" in res:
  1209. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1210. id0 = int(res)
  1211. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=ap-dpp configurator=%d code=secret" % (id0, conf_id)
  1212. res = dev[0].request(cmd)
  1213. if "FAIL" in res:
  1214. raise Exception("Failed to set PKEX data (initiator/wpa_supplicant)")
  1215. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1216. if ev is None:
  1217. raise Exception("DPP authentication did not succeed (Initiator)")
  1218. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1219. if ev is None:
  1220. raise Exception("DPP authentication did not succeed (Responder)")
  1221. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1222. if ev is None:
  1223. raise Exception("DPP configuration not completed (Configurator)")
  1224. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1225. if ev is None:
  1226. raise Exception("DPP configuration not completed (Enrollee)")
  1227. dev[0].request("DPP_STOP_LISTEN")
  1228. dev[0].dump_monitor()
  1229. def test_dpp_pkex_hostapd_initiator(dev, apdev):
  1230. """DPP PKEX with hostapd as initiator"""
  1231. check_dpp_capab(dev[0])
  1232. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1233. "channel": "6" })
  1234. check_dpp_capab(hapd)
  1235. cmd = "DPP_CONFIGURATOR_ADD"
  1236. res = dev[0].request(cmd);
  1237. if "FAIL" in res:
  1238. raise Exception("Failed to add configurator")
  1239. conf_id = int(res)
  1240. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1241. res = dev[0].request(cmd)
  1242. if "FAIL" in res:
  1243. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1244. id0 = int(res)
  1245. dev[0].set("dpp_configurator_params",
  1246. " conf=ap-dpp configurator=%d" % conf_id);
  1247. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1248. res = dev[0].request(cmd)
  1249. if "FAIL" in res:
  1250. raise Exception("Failed to set PKEX data (responder/wpa_supplicant)")
  1251. cmd = "DPP_LISTEN 2437 role=configurator"
  1252. if "OK" not in dev[0].request(cmd):
  1253. raise Exception("Failed to start listen operation")
  1254. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1255. res = hapd.request(cmd)
  1256. if "FAIL" in res:
  1257. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1258. id_h = int(res)
  1259. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee code=secret" % (id_h)
  1260. res = hapd.request(cmd)
  1261. if "FAIL" in res:
  1262. raise Exception("Failed to set PKEX data (initiator/hostapd)")
  1263. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1264. if ev is None:
  1265. raise Exception("DPP authentication did not succeed (Initiator)")
  1266. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1267. if ev is None:
  1268. raise Exception("DPP authentication did not succeed (Responder)")
  1269. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1270. if ev is None:
  1271. raise Exception("DPP configuration not completed (Configurator)")
  1272. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1273. if ev is None:
  1274. raise Exception("DPP configuration not completed (Enrollee)")
  1275. dev[0].request("DPP_STOP_LISTEN")
  1276. dev[0].dump_monitor()
  1277. def test_dpp_hostapd_configurator(dev, apdev):
  1278. """DPP with hostapd as configurator/initiator"""
  1279. check_dpp_capab(dev[0])
  1280. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1281. "channel": "1" })
  1282. check_dpp_capab(hapd)
  1283. cmd = "DPP_CONFIGURATOR_ADD"
  1284. res = hapd.request(cmd);
  1285. if "FAIL" in res:
  1286. raise Exception("Failed to add configurator")
  1287. conf_id = int(res)
  1288. addr = dev[0].own_addr().replace(':', '')
  1289. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1290. res = dev[0].request(cmd)
  1291. if "FAIL" in res:
  1292. raise Exception("Failed to generate bootstrapping info")
  1293. id0 = int(res)
  1294. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1295. res = hapd.request("DPP_QR_CODE " + uri0)
  1296. if "FAIL" in res:
  1297. raise Exception("Failed to parse QR Code URI")
  1298. id1 = int(res)
  1299. res = hapd.request("DPP_BOOTSTRAP_INFO %d" % id0)
  1300. if "FAIL" in res:
  1301. raise Exception("DPP_BOOTSTRAP_INFO failed")
  1302. if "type=QRCODE" not in res:
  1303. raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
  1304. if "mac_addr=" + dev[0].own_addr() not in res:
  1305. raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
  1306. cmd = "DPP_LISTEN 2412"
  1307. if "OK" not in dev[0].request(cmd):
  1308. raise Exception("Failed to start listen operation")
  1309. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1310. if "OK" not in hapd.request(cmd):
  1311. raise Exception("Failed to initiate DPP Authentication")
  1312. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1313. if ev is None:
  1314. raise Exception("DPP authentication did not succeed (Responder)")
  1315. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1316. if ev is None:
  1317. raise Exception("DPP authentication did not succeed (Initiator)")
  1318. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1319. if ev is None:
  1320. raise Exception("DPP configuration not completed (Configurator)")
  1321. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1322. if ev is None:
  1323. raise Exception("DPP configuration not completed (Enrollee)")
  1324. dev[0].request("DPP_STOP_LISTEN")
  1325. dev[0].dump_monitor()
  1326. def test_dpp_hostapd_configurator_responder(dev, apdev):
  1327. """DPP with hostapd as configurator/responder"""
  1328. check_dpp_capab(dev[0])
  1329. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1330. "channel": "1" })
  1331. check_dpp_capab(hapd)
  1332. cmd = "DPP_CONFIGURATOR_ADD"
  1333. res = hapd.request(cmd);
  1334. if "FAIL" in res:
  1335. raise Exception("Failed to add configurator")
  1336. conf_id = int(res)
  1337. hapd.set("dpp_configurator_params",
  1338. " conf=sta-dpp configurator=%d" % conf_id);
  1339. addr = hapd.own_addr().replace(':', '')
  1340. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1341. res = hapd.request(cmd)
  1342. if "FAIL" in res:
  1343. raise Exception("Failed to generate bootstrapping info")
  1344. id0 = int(res)
  1345. uri0 = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1346. res = dev[0].request("DPP_QR_CODE " + uri0)
  1347. if "FAIL" in res:
  1348. raise Exception("Failed to parse QR Code URI")
  1349. id1 = int(res)
  1350. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % (id1)
  1351. if "OK" not in dev[0].request(cmd):
  1352. raise Exception("Failed to initiate DPP Authentication")
  1353. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1354. if ev is None:
  1355. raise Exception("DPP authentication did not succeed (Responder)")
  1356. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1357. if ev is None:
  1358. raise Exception("DPP authentication did not succeed (Initiator)")
  1359. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1360. if ev is None:
  1361. raise Exception("DPP configuration not completed (Configurator)")
  1362. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1363. if ev is None:
  1364. raise Exception("DPP configuration not completed (Enrollee)")
  1365. dev[0].request("DPP_STOP_LISTEN")
  1366. dev[0].dump_monitor()
  1367. def test_dpp_own_config(dev, apdev):
  1368. """DPP configurator signing own connector"""
  1369. try:
  1370. run_dpp_own_config(dev, apdev)
  1371. finally:
  1372. dev[0].set("dpp_config_processing", "0")
  1373. def test_dpp_own_config_curve_mismatch(dev, apdev):
  1374. """DPP configurator signing own connector using mismatching curve"""
  1375. try:
  1376. run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
  1377. finally:
  1378. dev[0].set("dpp_config_processing", "0")
  1379. def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False):
  1380. check_dpp_capab(dev[0])
  1381. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1382. check_dpp_capab(hapd)
  1383. addr = hapd.own_addr().replace(':', '')
  1384. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1385. res = hapd.request(cmd)
  1386. if "FAIL" in res:
  1387. raise Exception("Failed to generate bootstrapping info")
  1388. id_h = int(res)
  1389. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1390. cmd = "DPP_CONFIGURATOR_ADD"
  1391. res = dev[0].request(cmd);
  1392. if "FAIL" in res:
  1393. raise Exception("Failed to add configurator")
  1394. conf_id = int(res)
  1395. res = dev[0].request("DPP_QR_CODE " + uri)
  1396. if "FAIL" in res:
  1397. raise Exception("Failed to parse QR Code URI")
  1398. id = int(res)
  1399. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1400. if "OK" not in dev[0].request(cmd):
  1401. raise Exception("Failed to initiate DPP Authentication")
  1402. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1403. if ev is None:
  1404. raise Exception("DPP authentication did not succeed (Responder)")
  1405. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1406. if ev is None:
  1407. raise Exception("DPP authentication did not succeed (Initiator)")
  1408. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1409. if ev is None:
  1410. raise Exception("DPP configuration not completed (Configurator)")
  1411. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1412. if ev is None:
  1413. raise Exception("DPP configuration not completed (Enrollee)")
  1414. update_hapd_config(hapd)
  1415. dev[0].set("dpp_config_processing", "1")
  1416. cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id)
  1417. if own_curve:
  1418. cmd += " curve=" + own_curve
  1419. res = dev[0].request(cmd)
  1420. if "FAIL" in res:
  1421. raise Exception("Failed to generate own configuration")
  1422. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1423. if ev is None:
  1424. raise Exception("DPP network profile not generated")
  1425. id = ev.split(' ')[1]
  1426. dev[0].select_network(id, freq="2412")
  1427. if expect_failure:
  1428. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1429. if ev is not None:
  1430. raise Exception("Unexpected connection");
  1431. dev[0].request("DISCONNECT")
  1432. else:
  1433. dev[0].wait_connected()