test_dpp.py 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  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. cmd = "DPP_CONFIGURATOR_ADD"
  1082. res = dev[1].request(cmd);
  1083. if "FAIL" in res:
  1084. raise Exception("Failed to add configurator")
  1085. conf_id = int(res)
  1086. run_dpp_pkex(dev, apdev,
  1087. init_extra="conf=sta-dpp configurator=%d" % (conf_id),
  1088. check_config=True)
  1089. def run_dpp_pkex(dev, apdev, curve=None, init_extra="", check_config=False):
  1090. check_dpp_capab(dev[0])
  1091. check_dpp_capab(dev[1])
  1092. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1093. if curve:
  1094. cmd += " curve=" + curve
  1095. res = dev[0].request(cmd)
  1096. if "FAIL" in res:
  1097. raise Exception("Failed to generate bootstrapping info")
  1098. id0 = int(res)
  1099. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1100. if curve:
  1101. cmd += " curve=" + curve
  1102. res = dev[1].request(cmd)
  1103. if "FAIL" in res:
  1104. raise Exception("Failed to generate bootstrapping info")
  1105. id1 = int(res)
  1106. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1107. res = dev[0].request(cmd)
  1108. if "FAIL" in res:
  1109. raise Exception("Failed to set PKEX data (responder)")
  1110. cmd = "DPP_LISTEN 2437"
  1111. if "OK" not in dev[0].request(cmd):
  1112. raise Exception("Failed to start listen operation")
  1113. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 %s code=secret" % (id1, init_extra)
  1114. res = dev[1].request(cmd)
  1115. if "FAIL" in res:
  1116. raise Exception("Failed to set PKEX data (initiator)")
  1117. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1118. if ev is None:
  1119. raise Exception("DPP authentication did not succeed (Initiator)")
  1120. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1121. if ev is None:
  1122. raise Exception("DPP authentication did not succeed (Responder)")
  1123. if check_config:
  1124. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1125. if ev is None:
  1126. raise Exception("DPP configuration not completed (Configurator)")
  1127. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1128. if ev is None:
  1129. raise Exception("DPP configuration not completed (Enrollee)")
  1130. def test_dpp_pkex_config2(dev, apdev):
  1131. """DPP and PKEX with responder as the configurator"""
  1132. cmd = "DPP_CONFIGURATOR_ADD"
  1133. res = dev[0].request(cmd);
  1134. if "FAIL" in res:
  1135. raise Exception("Failed to add configurator")
  1136. conf_id = int(res)
  1137. dev[0].set("dpp_configurator_params",
  1138. " conf=sta-dpp configurator=%d" % conf_id);
  1139. run_dpp_pkex2(dev, apdev)
  1140. def run_dpp_pkex2(dev, apdev, curve=None, init_extra=""):
  1141. check_dpp_capab(dev[0])
  1142. check_dpp_capab(dev[1])
  1143. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1144. if curve:
  1145. cmd += " curve=" + curve
  1146. res = dev[0].request(cmd)
  1147. if "FAIL" in res:
  1148. raise Exception("Failed to generate bootstrapping info")
  1149. id0 = int(res)
  1150. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1151. if curve:
  1152. cmd += " curve=" + curve
  1153. res = dev[1].request(cmd)
  1154. if "FAIL" in res:
  1155. raise Exception("Failed to generate bootstrapping info")
  1156. id1 = int(res)
  1157. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1158. res = dev[0].request(cmd)
  1159. if "FAIL" in res:
  1160. raise Exception("Failed to set PKEX data (responder)")
  1161. cmd = "DPP_LISTEN 2437 role=configurator"
  1162. if "OK" not in dev[0].request(cmd):
  1163. raise Exception("Failed to start listen operation")
  1164. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee %s code=secret" % (id1, init_extra)
  1165. res = dev[1].request(cmd)
  1166. if "FAIL" in res:
  1167. raise Exception("Failed to set PKEX data (initiator)")
  1168. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1169. if ev is None:
  1170. raise Exception("DPP authentication did not succeed (Initiator)")
  1171. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1172. if ev is None:
  1173. raise Exception("DPP authentication did not succeed (Responder)")
  1174. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1175. if ev is None:
  1176. raise Exception("DPP configuration not completed (Configurator)")
  1177. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1178. if ev is None:
  1179. raise Exception("DPP configuration not completed (Enrollee)")
  1180. def test_dpp_pkex_hostapd_responder(dev, apdev):
  1181. """DPP PKEX with hostapd as responder"""
  1182. check_dpp_capab(dev[0])
  1183. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1184. "channel": "6" })
  1185. check_dpp_capab(hapd)
  1186. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1187. res = hapd.request(cmd)
  1188. if "FAIL" in res:
  1189. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1190. id_h = int(res)
  1191. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id_h)
  1192. res = hapd.request(cmd)
  1193. if "FAIL" in res:
  1194. raise Exception("Failed to set PKEX data (responder/hostapd)")
  1195. cmd = "DPP_CONFIGURATOR_ADD"
  1196. res = dev[0].request(cmd);
  1197. if "FAIL" in res:
  1198. raise Exception("Failed to add configurator")
  1199. conf_id = int(res)
  1200. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1201. res = dev[0].request(cmd)
  1202. if "FAIL" in res:
  1203. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1204. id0 = int(res)
  1205. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=ap-dpp configurator=%d code=secret" % (id0, conf_id)
  1206. res = dev[0].request(cmd)
  1207. if "FAIL" in res:
  1208. raise Exception("Failed to set PKEX data (initiator/wpa_supplicant)")
  1209. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1210. if ev is None:
  1211. raise Exception("DPP authentication did not succeed (Initiator)")
  1212. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1213. if ev is None:
  1214. raise Exception("DPP authentication did not succeed (Responder)")
  1215. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1216. if ev is None:
  1217. raise Exception("DPP configuration not completed (Configurator)")
  1218. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1219. if ev is None:
  1220. raise Exception("DPP configuration not completed (Enrollee)")
  1221. dev[0].request("DPP_STOP_LISTEN")
  1222. dev[0].dump_monitor()
  1223. def test_dpp_pkex_hostapd_initiator(dev, apdev):
  1224. """DPP PKEX with hostapd as initiator"""
  1225. check_dpp_capab(dev[0])
  1226. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1227. "channel": "6" })
  1228. check_dpp_capab(hapd)
  1229. cmd = "DPP_CONFIGURATOR_ADD"
  1230. res = dev[0].request(cmd);
  1231. if "FAIL" in res:
  1232. raise Exception("Failed to add configurator")
  1233. conf_id = int(res)
  1234. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1235. res = dev[0].request(cmd)
  1236. if "FAIL" in res:
  1237. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1238. id0 = int(res)
  1239. dev[0].set("dpp_configurator_params",
  1240. " conf=ap-dpp configurator=%d" % conf_id);
  1241. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1242. res = dev[0].request(cmd)
  1243. if "FAIL" in res:
  1244. raise Exception("Failed to set PKEX data (responder/wpa_supplicant)")
  1245. cmd = "DPP_LISTEN 2437 role=configurator"
  1246. if "OK" not in dev[0].request(cmd):
  1247. raise Exception("Failed to start listen operation")
  1248. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1249. res = hapd.request(cmd)
  1250. if "FAIL" in res:
  1251. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1252. id_h = int(res)
  1253. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee code=secret" % (id_h)
  1254. res = hapd.request(cmd)
  1255. if "FAIL" in res:
  1256. raise Exception("Failed to set PKEX data (initiator/hostapd)")
  1257. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1258. if ev is None:
  1259. raise Exception("DPP authentication did not succeed (Initiator)")
  1260. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1261. if ev is None:
  1262. raise Exception("DPP authentication did not succeed (Responder)")
  1263. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1264. if ev is None:
  1265. raise Exception("DPP configuration not completed (Configurator)")
  1266. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1267. if ev is None:
  1268. raise Exception("DPP configuration not completed (Enrollee)")
  1269. dev[0].request("DPP_STOP_LISTEN")
  1270. dev[0].dump_monitor()
  1271. def test_dpp_hostapd_configurator(dev, apdev):
  1272. """DPP with hostapd as configurator/initiator"""
  1273. check_dpp_capab(dev[0])
  1274. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1275. "channel": "1" })
  1276. check_dpp_capab(hapd)
  1277. cmd = "DPP_CONFIGURATOR_ADD"
  1278. res = hapd.request(cmd);
  1279. if "FAIL" in res:
  1280. raise Exception("Failed to add configurator")
  1281. conf_id = int(res)
  1282. addr = dev[0].own_addr().replace(':', '')
  1283. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1284. res = dev[0].request(cmd)
  1285. if "FAIL" in res:
  1286. raise Exception("Failed to generate bootstrapping info")
  1287. id0 = int(res)
  1288. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1289. res = hapd.request("DPP_QR_CODE " + uri0)
  1290. if "FAIL" in res:
  1291. raise Exception("Failed to parse QR Code URI")
  1292. id1 = int(res)
  1293. res = hapd.request("DPP_BOOTSTRAP_INFO %d" % id0)
  1294. if "FAIL" in res:
  1295. raise Exception("DPP_BOOTSTRAP_INFO failed")
  1296. if "type=QRCODE" not in res:
  1297. raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
  1298. if "mac_addr=" + dev[0].own_addr() not in res:
  1299. raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
  1300. cmd = "DPP_LISTEN 2412"
  1301. if "OK" not in dev[0].request(cmd):
  1302. raise Exception("Failed to start listen operation")
  1303. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1304. if "OK" not in hapd.request(cmd):
  1305. raise Exception("Failed to initiate DPP Authentication")
  1306. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1307. if ev is None:
  1308. raise Exception("DPP authentication did not succeed (Responder)")
  1309. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1310. if ev is None:
  1311. raise Exception("DPP authentication did not succeed (Initiator)")
  1312. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1313. if ev is None:
  1314. raise Exception("DPP configuration not completed (Configurator)")
  1315. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1316. if ev is None:
  1317. raise Exception("DPP configuration not completed (Enrollee)")
  1318. dev[0].request("DPP_STOP_LISTEN")
  1319. dev[0].dump_monitor()
  1320. def test_dpp_hostapd_configurator_responder(dev, apdev):
  1321. """DPP with hostapd as configurator/responder"""
  1322. check_dpp_capab(dev[0])
  1323. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1324. "channel": "1" })
  1325. check_dpp_capab(hapd)
  1326. cmd = "DPP_CONFIGURATOR_ADD"
  1327. res = hapd.request(cmd);
  1328. if "FAIL" in res:
  1329. raise Exception("Failed to add configurator")
  1330. conf_id = int(res)
  1331. hapd.set("dpp_configurator_params",
  1332. " conf=sta-dpp configurator=%d" % conf_id);
  1333. addr = hapd.own_addr().replace(':', '')
  1334. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1335. res = hapd.request(cmd)
  1336. if "FAIL" in res:
  1337. raise Exception("Failed to generate bootstrapping info")
  1338. id0 = int(res)
  1339. uri0 = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1340. res = dev[0].request("DPP_QR_CODE " + uri0)
  1341. if "FAIL" in res:
  1342. raise Exception("Failed to parse QR Code URI")
  1343. id1 = int(res)
  1344. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % (id1)
  1345. if "OK" not in dev[0].request(cmd):
  1346. raise Exception("Failed to initiate DPP Authentication")
  1347. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1348. if ev is None:
  1349. raise Exception("DPP authentication did not succeed (Responder)")
  1350. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1351. if ev is None:
  1352. raise Exception("DPP authentication did not succeed (Initiator)")
  1353. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1354. if ev is None:
  1355. raise Exception("DPP configuration not completed (Configurator)")
  1356. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1357. if ev is None:
  1358. raise Exception("DPP configuration not completed (Enrollee)")
  1359. dev[0].request("DPP_STOP_LISTEN")
  1360. dev[0].dump_monitor()
  1361. def test_dpp_own_config(dev, apdev):
  1362. """DPP configurator signing own connector"""
  1363. try:
  1364. run_dpp_own_config(dev, apdev)
  1365. finally:
  1366. dev[0].set("dpp_config_processing", "0")
  1367. def test_dpp_own_config_curve_mismatch(dev, apdev):
  1368. """DPP configurator signing own connector using mismatching curve"""
  1369. try:
  1370. run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
  1371. finally:
  1372. dev[0].set("dpp_config_processing", "0")
  1373. def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False):
  1374. check_dpp_capab(dev[0])
  1375. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1376. check_dpp_capab(hapd)
  1377. addr = hapd.own_addr().replace(':', '')
  1378. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1379. res = hapd.request(cmd)
  1380. if "FAIL" in res:
  1381. raise Exception("Failed to generate bootstrapping info")
  1382. id_h = int(res)
  1383. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1384. cmd = "DPP_CONFIGURATOR_ADD"
  1385. res = dev[0].request(cmd);
  1386. if "FAIL" in res:
  1387. raise Exception("Failed to add configurator")
  1388. conf_id = int(res)
  1389. res = dev[0].request("DPP_QR_CODE " + uri)
  1390. if "FAIL" in res:
  1391. raise Exception("Failed to parse QR Code URI")
  1392. id = int(res)
  1393. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1394. if "OK" not in dev[0].request(cmd):
  1395. raise Exception("Failed to initiate DPP Authentication")
  1396. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1397. if ev is None:
  1398. raise Exception("DPP authentication did not succeed (Responder)")
  1399. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1400. if ev is None:
  1401. raise Exception("DPP authentication did not succeed (Initiator)")
  1402. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1403. if ev is None:
  1404. raise Exception("DPP configuration not completed (Configurator)")
  1405. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1406. if ev is None:
  1407. raise Exception("DPP configuration not completed (Enrollee)")
  1408. update_hapd_config(hapd)
  1409. dev[0].set("dpp_config_processing", "1")
  1410. cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id)
  1411. if own_curve:
  1412. cmd += " curve=" + own_curve
  1413. res = dev[0].request(cmd)
  1414. if "FAIL" in res:
  1415. raise Exception("Failed to generate own configuration")
  1416. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1417. if ev is None:
  1418. raise Exception("DPP network profile not generated")
  1419. id = ev.split(' ')[1]
  1420. dev[0].select_network(id, freq="2412")
  1421. if expect_failure:
  1422. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1423. if ev is not None:
  1424. raise Exception("Unexpected connection");
  1425. dev[0].request("DISCONNECT")
  1426. else:
  1427. dev[0].wait_connected()