test_dpp.py 70 KB

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