test_dpp.py 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  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. dev[1].set("dpp_discovery_override", discovery)
  546. dev[1].set("dpp_groups_override", groups)
  547. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  548. init_extra="conf=sta-dpp",
  549. require_conf_success=True,
  550. configurator=True)
  551. def test_dpp_gas_timeout(dev, apdev):
  552. """DPP and GAS server timeout for a query"""
  553. check_dpp_capab(dev[0])
  554. check_dpp_capab(dev[1])
  555. logger.info("dev0 displays QR Code")
  556. addr = dev[0].own_addr().replace(':', '')
  557. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  558. res = dev[0].request(cmd)
  559. if "FAIL" in res:
  560. raise Exception("Failed to generate bootstrapping info")
  561. id0 = int(res)
  562. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  563. logger.info("dev1 scans QR Code")
  564. res = dev[1].request("DPP_QR_CODE " + uri0)
  565. if "FAIL" in res:
  566. raise Exception("Failed to parse QR Code URI")
  567. id1 = int(res)
  568. logger.info("dev1 initiates DPP Authentication")
  569. dev[0].set("ext_mgmt_frame_handling", "1")
  570. cmd = "DPP_LISTEN 2412"
  571. if "OK" not in dev[0].request(cmd):
  572. raise Exception("Failed to start listen operation")
  573. # Force GAS fragmentation
  574. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  575. dev[1].set("dpp_config_obj_override", conf)
  576. cmd = "DPP_AUTH_INIT peer=%d" % id1
  577. if "OK" not in dev[1].request(cmd):
  578. raise Exception("Failed to initiate DPP Authentication")
  579. # DPP Authentication Request
  580. msg = dev[0].mgmt_rx()
  581. 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'))):
  582. raise Exception("MGMT_RX_PROCESS failed")
  583. # DPP Authentication Confirmation
  584. msg = dev[0].mgmt_rx()
  585. 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'))):
  586. raise Exception("MGMT_RX_PROCESS failed")
  587. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  588. if ev is None:
  589. raise Exception("DPP authentication did not succeed (Responder)")
  590. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  591. if ev is None:
  592. raise Exception("DPP authentication did not succeed (Initiator)")
  593. # DPP Configuration Response (GAS Initial Response frame)
  594. msg = dev[0].mgmt_rx()
  595. 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'))):
  596. raise Exception("MGMT_RX_PROCESS failed")
  597. # GAS Comeback Response frame
  598. msg = dev[0].mgmt_rx()
  599. # Do not continue to force timeout on GAS server
  600. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  601. if ev is None:
  602. raise Exception("GAS result not reported (Enrollee)")
  603. if "result=TIMEOUT" not in ev:
  604. raise Exception("Unexpected GAS result (Enrollee): " + ev)
  605. dev[0].set("ext_mgmt_frame_handling", "0")
  606. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=15)
  607. if ev is None:
  608. raise Exception("DPP configuration failure not reported (Configurator)")
  609. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=1)
  610. if ev is None:
  611. raise Exception("DPP configuration failure not reported (Enrollee)")
  612. def test_dpp_akm_sha256(dev, apdev):
  613. """DPP AKM (SHA256)"""
  614. run_dpp_akm(dev, apdev, 32)
  615. def test_dpp_akm_sha384(dev, apdev):
  616. """DPP AKM (SHA384)"""
  617. run_dpp_akm(dev, apdev, 48)
  618. def test_dpp_akm_sha512(dev, apdev):
  619. """DPP AKM (SHA512)"""
  620. run_dpp_akm(dev, apdev, 64)
  621. def run_dpp_akm(dev, apdev, pmk_len):
  622. check_dpp_capab(dev[0])
  623. check_dpp_capab(dev[1])
  624. params = { "ssid": "dpp",
  625. "wpa": "2",
  626. "wpa_key_mgmt": "DPP",
  627. "rsn_pairwise": "CCMP" }
  628. try:
  629. hapd = hostapd.add_ap(apdev[0], params)
  630. except:
  631. raise HwsimSkip("DPP not supported")
  632. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  633. wait_connect=False)
  634. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=2)
  635. if not ev:
  636. raise Exception("Network mismatch not reported")
  637. dev[0].request("DISCONNECT")
  638. dev[0].dump_monitor()
  639. bssid = hapd.own_addr()
  640. pmkid = 16*'11'
  641. akmp = 2**23
  642. pmk = pmk_len*'22'
  643. cmd = "PMKSA_ADD %d %s %s %s 30240 43200 %d 0" % (id, bssid, pmkid, pmk, akmp)
  644. if "OK" not in dev[0].request(cmd):
  645. raise Exception("PMKSA_ADD failed (wpa_supplicant)")
  646. dev[0].select_network(id, freq="2412")
  647. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=2)
  648. dev[0].request("DISCONNECT")
  649. dev[0].dump_monitor()
  650. if not ev:
  651. raise Exception("Association attempt was not rejected")
  652. if "status_code=53" not in ev:
  653. raise Exception("Unexpected status code: " + ev)
  654. addr = dev[0].own_addr()
  655. cmd = "PMKSA_ADD %s %s %s 0 %d" % (addr, pmkid, pmk, akmp)
  656. if "OK" not in hapd.request(cmd):
  657. raise Exception("PMKSA_ADD failed (hostapd)")
  658. dev[0].select_network(id, freq="2412")
  659. dev[0].wait_connected()
  660. val = dev[0].get_status_field("key_mgmt")
  661. if val != "DPP":
  662. raise Exception("Unexpected key_mgmt: " + val)
  663. def test_dpp_network_introduction(dev, apdev):
  664. """DPP network introduction"""
  665. check_dpp_capab(dev[0])
  666. check_dpp_capab(dev[1])
  667. csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
  668. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
  669. ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
  670. sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
  671. sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
  672. params = { "ssid": "dpp",
  673. "wpa": "2",
  674. "wpa_key_mgmt": "DPP",
  675. "rsn_pairwise": "CCMP",
  676. "dpp_connector": ap_connector,
  677. "dpp_csign": csign,
  678. "dpp_netaccesskey": ap_netaccesskey }
  679. try:
  680. hapd = hostapd.add_ap(apdev[0], params)
  681. except:
  682. raise HwsimSkip("DPP not supported")
  683. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  684. dpp_csign=csign,
  685. dpp_connector=sta_connector,
  686. dpp_netaccesskey=sta_netaccesskey)
  687. val = dev[0].get_status_field("key_mgmt")
  688. if val != "DPP":
  689. raise Exception("Unexpected key_mgmt: " + val)
  690. def test_dpp_ap_config(dev, apdev):
  691. """DPP and AP configuration"""
  692. run_dpp_ap_config(dev, apdev)
  693. def test_dpp_ap_config_p256_p256(dev, apdev):
  694. """DPP and AP configuration (P-256 + P-256)"""
  695. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-256")
  696. def test_dpp_ap_config_p256_p384(dev, apdev):
  697. """DPP and AP configuration (P-256 + P-384)"""
  698. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-384")
  699. def test_dpp_ap_config_p256_p521(dev, apdev):
  700. """DPP and AP configuration (P-256 + P-521)"""
  701. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-521")
  702. def test_dpp_ap_config_p384_p256(dev, apdev):
  703. """DPP and AP configuration (P-384 + P-256)"""
  704. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-256")
  705. def test_dpp_ap_config_p384_p384(dev, apdev):
  706. """DPP and AP configuration (P-384 + P-384)"""
  707. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-384")
  708. def test_dpp_ap_config_p384_p521(dev, apdev):
  709. """DPP and AP configuration (P-384 + P-521)"""
  710. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-521")
  711. def test_dpp_ap_config_p521_p256(dev, apdev):
  712. """DPP and AP configuration (P-521 + P-256)"""
  713. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-256")
  714. def test_dpp_ap_config_p521_p384(dev, apdev):
  715. """DPP and AP configuration (P-521 + P-384)"""
  716. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-384")
  717. def test_dpp_ap_config_p521_p521(dev, apdev):
  718. """DPP and AP configuration (P-521 + P-521)"""
  719. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-521")
  720. def update_hapd_config(hapd):
  721. ev = hapd.wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  722. if ev is None:
  723. raise Exception("SSID not reported (AP)")
  724. ssid = ev.split(' ')[1]
  725. ev = hapd.wait_event(["DPP-CONNECTOR"], timeout=1)
  726. if ev is None:
  727. raise Exception("Connector not reported (AP)")
  728. connector = ev.split(' ')[1]
  729. ev = hapd.wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  730. if ev is None:
  731. raise Exception("C-sign-key not reported (AP)")
  732. p = ev.split(' ')
  733. csign = p[1]
  734. csign_expiry = p[2] if len(p) > 2 else None
  735. ev = hapd.wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  736. if ev is None:
  737. raise Exception("netAccessKey not reported (AP)")
  738. p = ev.split(' ')
  739. net_access_key = p[1]
  740. net_access_key_expiry = p[2] if len(p) > 2 else None
  741. logger.info("Update AP configuration to use key_mgmt=DPP")
  742. hapd.disable()
  743. hapd.set("ssid", ssid)
  744. hapd.set("wpa", "2")
  745. hapd.set("wpa_key_mgmt", "DPP")
  746. hapd.set("rsn_pairwise", "CCMP")
  747. hapd.set("dpp_connector", connector)
  748. hapd.set("dpp_csign", csign)
  749. if csign_expiry:
  750. hapd.set("dpp_csign_expiry", csign_expiry)
  751. hapd.set("dpp_netaccesskey", net_access_key)
  752. if net_access_key_expiry:
  753. hapd.set("dpp_netaccesskey_expiry", net_access_key_expiry)
  754. hapd.enable()
  755. def run_dpp_ap_config(dev, apdev, curve=None, conf_curve=None):
  756. check_dpp_capab(dev[0])
  757. check_dpp_capab(dev[1])
  758. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  759. check_dpp_capab(hapd)
  760. addr = hapd.own_addr().replace(':', '')
  761. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  762. if curve:
  763. cmd += " curve=" + curve
  764. res = hapd.request(cmd)
  765. if "FAIL" in res:
  766. raise Exception("Failed to generate bootstrapping info")
  767. id_h = int(res)
  768. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  769. cmd = "DPP_CONFIGURATOR_ADD expiry=%d" % (time.time() + 100000)
  770. if conf_curve:
  771. cmd += " curve=" + conf_curve
  772. res = dev[0].request(cmd);
  773. if "FAIL" in res:
  774. raise Exception("Failed to add configurator")
  775. conf_id = int(res)
  776. res = dev[0].request("DPP_QR_CODE " + uri)
  777. if "FAIL" in res:
  778. raise Exception("Failed to parse QR Code URI")
  779. id = int(res)
  780. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  781. if "OK" not in dev[0].request(cmd):
  782. raise Exception("Failed to initiate DPP Authentication")
  783. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  784. if ev is None:
  785. raise Exception("DPP authentication did not succeed (Responder)")
  786. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  787. if ev is None:
  788. raise Exception("DPP authentication did not succeed (Initiator)")
  789. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  790. if ev is None:
  791. raise Exception("DPP configuration not completed (Configurator)")
  792. ev = hapd.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  793. if ev is None:
  794. raise Exception("DPP configuration not completed (Enrollee)")
  795. if "DPP-CONF-FAILED" in ev:
  796. raise Exception("DPP configuration failed")
  797. update_hapd_config(hapd)
  798. addr = dev[1].own_addr().replace(':', '')
  799. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  800. if curve:
  801. cmd += " curve=" + curve
  802. res = dev[1].request(cmd)
  803. if "FAIL" in res:
  804. raise Exception("Failed to generate bootstrapping info")
  805. id1 = int(res)
  806. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  807. res = dev[0].request("DPP_QR_CODE " + uri1)
  808. if "FAIL" in res:
  809. raise Exception("Failed to parse QR Code URI")
  810. id0b = int(res)
  811. cmd = "DPP_LISTEN 2412"
  812. if "OK" not in dev[1].request(cmd):
  813. raise Exception("Failed to start listen operation")
  814. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id0b, conf_id)
  815. if "OK" not in dev[0].request(cmd):
  816. raise Exception("Failed to initiate DPP Authentication")
  817. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  818. if ev is None:
  819. raise Exception("DPP authentication did not succeed (Responder)")
  820. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  821. if ev is None:
  822. raise Exception("DPP authentication did not succeed (Initiator)")
  823. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  824. if ev is None:
  825. raise Exception("DPP configuration not completed (Configurator)")
  826. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  827. if ev is None:
  828. raise Exception("DPP configuration not completed (Enrollee)")
  829. dev[1].request("DPP_STOP_LISTEN")
  830. ev = dev[1].wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  831. if ev is None:
  832. raise Exception("SSID not reported")
  833. ssid = ev.split(' ')[1]
  834. ev = dev[1].wait_event(["DPP-CONNECTOR"], timeout=1)
  835. if ev is None:
  836. raise Exception("Connector not reported")
  837. connector = ev.split(' ')[1]
  838. ev = dev[1].wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  839. if ev is None:
  840. raise Exception("C-sign-key not reported")
  841. p = ev.split(' ')
  842. csign = p[1]
  843. csign_expiry = p[2] if len(p) > 2 else None
  844. ev = dev[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  845. if ev is None:
  846. raise Exception("netAccessKey not reported")
  847. p = ev.split(' ')
  848. net_access_key = p[1]
  849. net_access_key_expiry = p[2] if len(p) > 2 else None
  850. dev[1].dump_monitor()
  851. id = dev[1].connect(ssid, key_mgmt="DPP", scan_freq="2412",
  852. only_add_network=True)
  853. dev[1].set_network_quoted(id, "dpp_connector", connector)
  854. dev[1].set_network(id, "dpp_csign", csign)
  855. if csign_expiry:
  856. dev[1].set_network(id, "dpp_csign_expiry", csign_expiry)
  857. dev[1].set_network(id, "dpp_netaccesskey", net_access_key)
  858. if net_access_key_expiry:
  859. dev[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry)
  860. logger.info("Check data connection")
  861. dev[1].select_network(id, freq="2412")
  862. dev[1].wait_connected()
  863. def test_dpp_auto_connect_1(dev, apdev):
  864. """DPP and auto connect (1)"""
  865. try:
  866. run_dpp_auto_connect(dev, apdev, 1)
  867. finally:
  868. dev[0].set("dpp_config_processing", "0")
  869. def test_dpp_auto_connect_2(dev, apdev):
  870. """DPP and auto connect (2)"""
  871. try:
  872. run_dpp_auto_connect(dev, apdev, 2)
  873. finally:
  874. dev[0].set("dpp_config_processing", "0")
  875. def run_dpp_auto_connect(dev, apdev, processing):
  876. check_dpp_capab(dev[0])
  877. check_dpp_capab(dev[1])
  878. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  879. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  880. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  881. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  882. params = { "ssid": "test",
  883. "wpa": "2",
  884. "wpa_key_mgmt": "DPP",
  885. "rsn_pairwise": "CCMP",
  886. "dpp_connector": ap_connector,
  887. "dpp_csign": csign_pub,
  888. "dpp_netaccesskey": ap_netaccesskey }
  889. try:
  890. hapd = hostapd.add_ap(apdev[0], params)
  891. except:
  892. raise HwsimSkip("DPP not supported")
  893. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  894. res = dev[1].request(cmd)
  895. if "FAIL" in res:
  896. raise Exception("DPP_CONFIGURATOR_ADD failed")
  897. conf_id = int(res)
  898. dev[0].set("dpp_config_processing", str(processing))
  899. addr = dev[0].own_addr().replace(':', '')
  900. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  901. res = dev[0].request(cmd)
  902. if "FAIL" in res:
  903. raise Exception("Failed to generate bootstrapping info")
  904. id0 = int(res)
  905. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  906. res = dev[1].request("DPP_QR_CODE " + uri0)
  907. if "FAIL" in res:
  908. raise Exception("Failed to parse QR Code URI")
  909. id1 = int(res)
  910. cmd = "DPP_LISTEN 2412"
  911. if "OK" not in dev[0].request(cmd):
  912. raise Exception("Failed to start listen operation")
  913. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  914. if "OK" not in dev[1].request(cmd):
  915. raise Exception("Failed to initiate DPP Authentication")
  916. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  917. if ev is None:
  918. raise Exception("DPP configuration not completed (Configurator)")
  919. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  920. if ev is None:
  921. raise Exception("DPP configuration not completed (Enrollee)")
  922. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  923. if ev is None:
  924. raise Exception("DPP network profile not generated")
  925. id = ev.split(' ')[1]
  926. if processing == 1:
  927. dev[0].select_network(id, freq=2412)
  928. dev[0].wait_connected()
  929. def test_dpp_auto_connect_legacy(dev, apdev):
  930. """DPP and auto connect (legacy)"""
  931. try:
  932. run_dpp_auto_connect_legacy(dev, apdev)
  933. finally:
  934. dev[0].set("dpp_config_processing", "0")
  935. def run_dpp_auto_connect_legacy(dev, apdev):
  936. check_dpp_capab(dev[0])
  937. check_dpp_capab(dev[1])
  938. params = hostapd.wpa2_params(ssid="dpp-legacy",
  939. passphrase="secret passphrase")
  940. hapd = hostapd.add_ap(apdev[0], params)
  941. dev[0].set("dpp_config_processing", "2")
  942. addr = dev[0].own_addr().replace(':', '')
  943. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  944. res = dev[0].request(cmd)
  945. if "FAIL" in res:
  946. raise Exception("Failed to generate bootstrapping info")
  947. id0 = int(res)
  948. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  949. res = dev[1].request("DPP_QR_CODE " + uri0)
  950. if "FAIL" in res:
  951. raise Exception("Failed to parse QR Code URI")
  952. id1 = int(res)
  953. cmd = "DPP_LISTEN 2412"
  954. if "OK" not in dev[0].request(cmd):
  955. raise Exception("Failed to start listen operation")
  956. cmd = "DPP_AUTH_INIT peer=%d conf=sta-psk ssid=%s pass=%s" % (id1, "dpp-legacy".encode("hex"), "secret passphrase".encode("hex"))
  957. if "OK" not in dev[1].request(cmd):
  958. raise Exception("Failed to initiate DPP Authentication")
  959. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  960. if ev is None:
  961. raise Exception("DPP configuration not completed (Configurator)")
  962. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  963. if ev is None:
  964. raise Exception("DPP configuration not completed (Enrollee)")
  965. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  966. if ev is None:
  967. raise Exception("DPP network profile not generated")
  968. id = ev.split(' ')[1]
  969. dev[0].wait_connected()
  970. def test_dpp_qr_code_auth_responder_configurator(dev, apdev):
  971. """DPP QR Code and responder as the configurator"""
  972. check_dpp_capab(dev[0])
  973. check_dpp_capab(dev[1])
  974. cmd = "DPP_CONFIGURATOR_ADD"
  975. res = dev[0].request(cmd);
  976. if "FAIL" in res:
  977. raise Exception("Failed to add configurator")
  978. conf_id = int(res)
  979. addr = dev[0].own_addr().replace(':', '')
  980. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  981. res = dev[0].request(cmd)
  982. if "FAIL" in res:
  983. raise Exception("Failed to generate bootstrapping info")
  984. id0 = int(res)
  985. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  986. res = dev[1].request("DPP_QR_CODE " + uri0)
  987. if "FAIL" in res:
  988. raise Exception("Failed to parse QR Code URI")
  989. id1 = int(res)
  990. dev[0].set("dpp_configurator_params", " conf=sta-dpp configurator=%d" % conf_id);
  991. cmd = "DPP_LISTEN 2412 role=configurator"
  992. if "OK" not in dev[0].request(cmd):
  993. raise Exception("Failed to start listen operation")
  994. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  995. if "OK" not in dev[1].request(cmd):
  996. raise Exception("Failed to initiate DPP Authentication")
  997. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  998. if ev is None:
  999. raise Exception("DPP authentication did not succeed (Responder)")
  1000. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1001. if ev is None:
  1002. raise Exception("DPP authentication did not succeed (Initiator)")
  1003. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1004. if ev is None:
  1005. raise Exception("DPP configuration not completed (Configurator)")
  1006. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1007. if ev is None:
  1008. raise Exception("DPP configuration not completed (Enrollee)")
  1009. dev[0].request("DPP_STOP_LISTEN")
  1010. dev[0].dump_monitor()
  1011. dev[1].dump_monitor()
  1012. def test_dpp_qr_code_hostapd_init(dev, apdev):
  1013. """DPP QR Code and hostapd as initiator"""
  1014. check_dpp_capab(dev[0])
  1015. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1016. "channel": "6" })
  1017. check_dpp_capab(hapd)
  1018. cmd = "DPP_CONFIGURATOR_ADD"
  1019. res = dev[0].request(cmd);
  1020. if "FAIL" in res:
  1021. raise Exception("Failed to add configurator")
  1022. conf_id = int(res)
  1023. addr = dev[0].own_addr().replace(':', '')
  1024. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1025. res = dev[0].request(cmd)
  1026. if "FAIL" in res:
  1027. raise Exception("Failed to generate bootstrapping info")
  1028. id0 = int(res)
  1029. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1030. dev[0].set("dpp_configurator_params",
  1031. " conf=ap-dpp configurator=%d" % conf_id);
  1032. cmd = "DPP_LISTEN 2437 role=configurator"
  1033. if "OK" not in dev[0].request(cmd):
  1034. raise Exception("Failed to start listen operation")
  1035. res = hapd.request("DPP_QR_CODE " + uri0)
  1036. if "FAIL" in res:
  1037. raise Exception("Failed to parse QR Code URI")
  1038. id1 = int(res)
  1039. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1040. if "OK" not in hapd.request(cmd):
  1041. raise Exception("Failed to initiate DPP Authentication")
  1042. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1043. if ev is None:
  1044. raise Exception("DPP authentication did not succeed (Responder)")
  1045. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1046. if ev is None:
  1047. raise Exception("DPP authentication did not succeed (Initiator)")
  1048. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1049. if ev is None:
  1050. raise Exception("DPP configuration not completed (Configurator)")
  1051. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1052. if ev is None:
  1053. raise Exception("DPP configuration not completed (Enrollee)")
  1054. dev[0].request("DPP_STOP_LISTEN")
  1055. dev[0].dump_monitor()
  1056. def test_dpp_pkex(dev, apdev):
  1057. """DPP and PKEX"""
  1058. run_dpp_pkex(dev, apdev)
  1059. def test_dpp_pkex_p256(dev, apdev):
  1060. """DPP and PKEX (P-256)"""
  1061. run_dpp_pkex(dev, apdev, "P-256")
  1062. def test_dpp_pkex_p384(dev, apdev):
  1063. """DPP and PKEX (P-384)"""
  1064. run_dpp_pkex(dev, apdev, "P-384")
  1065. def test_dpp_pkex_p521(dev, apdev):
  1066. """DPP and PKEX (P-521)"""
  1067. run_dpp_pkex(dev, apdev, "P-521")
  1068. def test_dpp_pkex_bp256(dev, apdev):
  1069. """DPP and PKEX (BP-256)"""
  1070. run_dpp_pkex(dev, apdev, "brainpoolP256r1")
  1071. def test_dpp_pkex_bp384(dev, apdev):
  1072. """DPP and PKEX (BP-384)"""
  1073. run_dpp_pkex(dev, apdev, "brainpoolP384r1")
  1074. def test_dpp_pkex_bp512(dev, apdev):
  1075. """DPP and PKEX (BP-512)"""
  1076. run_dpp_pkex(dev, apdev, "brainpoolP512r1")
  1077. def test_dpp_pkex_config(dev, apdev):
  1078. """DPP and PKEX with initiator as the configurator"""
  1079. check_dpp_capab(dev[1])
  1080. cmd = "DPP_CONFIGURATOR_ADD"
  1081. res = dev[1].request(cmd);
  1082. if "FAIL" in res:
  1083. raise Exception("Failed to add configurator")
  1084. conf_id = int(res)
  1085. run_dpp_pkex(dev, apdev,
  1086. init_extra="conf=sta-dpp configurator=%d" % (conf_id),
  1087. check_config=True)
  1088. def run_dpp_pkex(dev, apdev, curve=None, init_extra="", check_config=False):
  1089. check_dpp_capab(dev[0])
  1090. check_dpp_capab(dev[1])
  1091. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1092. if curve:
  1093. cmd += " curve=" + curve
  1094. res = dev[0].request(cmd)
  1095. if "FAIL" in res:
  1096. raise Exception("Failed to generate bootstrapping info")
  1097. id0 = int(res)
  1098. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1099. if curve:
  1100. cmd += " curve=" + curve
  1101. res = dev[1].request(cmd)
  1102. if "FAIL" in res:
  1103. raise Exception("Failed to generate bootstrapping info")
  1104. id1 = int(res)
  1105. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1106. res = dev[0].request(cmd)
  1107. if "FAIL" in res:
  1108. raise Exception("Failed to set PKEX data (responder)")
  1109. cmd = "DPP_LISTEN 2437"
  1110. if "OK" not in dev[0].request(cmd):
  1111. raise Exception("Failed to start listen operation")
  1112. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 %s code=secret" % (id1, init_extra)
  1113. res = dev[1].request(cmd)
  1114. if "FAIL" in res:
  1115. raise Exception("Failed to set PKEX data (initiator)")
  1116. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1117. if ev is None:
  1118. raise Exception("DPP authentication did not succeed (Initiator)")
  1119. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1120. if ev is None:
  1121. raise Exception("DPP authentication did not succeed (Responder)")
  1122. if check_config:
  1123. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1124. if ev is None:
  1125. raise Exception("DPP configuration not completed (Configurator)")
  1126. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1127. if ev is None:
  1128. raise Exception("DPP configuration not completed (Enrollee)")
  1129. def test_dpp_pkex_config2(dev, apdev):
  1130. """DPP and PKEX with responder as the configurator"""
  1131. check_dpp_capab(dev[0])
  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()