test_dpp.py 62 KB

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